FairRoot/PandaRoot
combine_ana.C
Go to the documentation of this file.
1 #include "TFile.h"
2 #include "TH1D.h"
3 #include "TCanvas.h"
4 #include "TStopwatch.h"
5 #include "TROOT.h"
6 #include "TSystem.h"
7 #include "TTree.h"
8 #include "TString.h"
9 
10 void SaveAndUpdateHisto(TH1D* currenthisto, TFile& storagefile)
11 {
12  if (storagefile.Get(currenthisto->GetName()) != 0) {
13  currenthisto->Add((TH1D*)storagefile.Get(currenthisto->GetName()));
14  }
15  //cout << currenthisto->GetName() << ": " << currenthisto->GetEntries() << endl;
16  currenthisto->Write();
17 }
18 
19 int combine_ana(TString infilename, TString outfilename="combined_psi3770.root")
20 {
21 
22 //TStopwatch timer;
23 //timer.Start();
24 
25 //gROOT->LoadMacro("$VMCWORKDIR/gconfig/rootlogon.C");rootlogon();
26 
27 TFile inputfile(infilename, "READ");
28 TList* mylist = inputfile.GetListOfKeys();
29 TListIter myiter(mylist);
30 TFile outputstorage(outfilename, "UPDATE");
31 TKey* mykey;
32 
33 //cout << mylist->GetEntries() << endl;
34 
35 int nHistos = 149;
36 TString histoClassName = "TH1D";
37 
38 if (mylist->GetEntries() != nHistos) {
39  cout << "Fatal Entry Mismatch: " << mylist->GetEntries() << endl;
40  return 1;
41 }
42 
43 outputstorage->cd();
44 
45 while (mykey = (TKey*)myiter()) {
46  if (histoClassName == TString(mykey->GetClassName())) {
47  TH1D* myhisto = (TH1D*)mykey->ReadObj();
48  SaveAndUpdateHisto(myhisto, outputstorage);
49  } else {
50  cout << "Ignored, not a histogram: " << mykey->GetName() << ", " << mykey->GetClassName() << endl;
51  }
52 }
53 
54 return 0;
55 
56 //timer.Stop();
57 //Double_t rtime = timer.RealTime();
58 //Double_t ctime = timer.CpuTime();
59 
60 //printf("RealTime=%f seconds, CpuTime=%f seconds\n",rtime,ctime);
61 
62 } // end macro
int combine_ana(TString infilename, TString outfilename="combined_psi3770.root")
Definition: combine_ana.C:19
void SaveAndUpdateHisto(TH1 *currenthisto, TFile &storagefile)