Two functions in one script?

If I want to use the scaling inside another function such as Add, can I do it?
For example, can I write:

void M_LQ()

{
gROOT->Reset();

TCanvas *c1 = new TCanvas(“c1”, “Adding histos”, 10, 10, 800, 800);

TFile *f1 = new TFile("/afs/cern.ch/user/e/evgenia/testarea/12.0.6/PhysicsAnalysis/AnalysisCommon/UserAnalysis/run/tt1.root");
TFile *f2 = new TFile("/afs/cern.ch/user/e/evgenia/testarea/12.0.6/PhysicsAnalysis/AnalysisCommon/UserAnalysis/run/tt2.root");

void TH1::Scale(Double_t c1)
{
Double_t ent = fEntries;
Add(this,this,c1,0);
fEntries = ent;
}
TH1::AddDirectory(kFALSE);
TH1F h_common = (TH1F)f1.Get(“Muon/MLQ1”);
TH1F h_second = (TH1F)f2.Get(“Muon/MLQ1”);

h_common->Add(h_second);

h_common->Draw();
}

Which order should I use?

How can I save the output, not draw it, as a histo?

Hi,

Use a named macro - it allows you to have multiple functions in one file; see the users guide for names vs. unnamed macros. You cannot declare a function inside another function. You cannot re-declare a class’s (TH1 in your case) function, or declare a new one (please read a book on C++, you need to understand the basics of C++ before you can use ROOT). The users guide also shows how to save a histogram: just call TH1::Write().

Cheers, Axel.

I tested it and it doesn’t work!

What do I have to do?

Can I scale a whole root file or just a histo? How do I write the histo if it’s in tt1.root/Muon/ ?

Ok, thanks for replying!

I used h_common->Write(), but the root file I am using is not writable. How can I make it writable or what else do I have to do?

see documentation of TFile at: root.cern.ch/root/html/TFile.html#TFile:TFile

If option = NEW or CREATE create a new file and open it for writing, if the file already exists the file is not opened. = RECREATE create a new file, if the file already exists it will be overwritten. = UPDATE open an existing file for writing. if no file exists, it is created. = READ open an existing file for reading (default). = NET used by derived remote file access classes, not a user callable option = WEB used by derived remote http access class, not a user callable option If option = "" (default), READ is assumed.

Rene