3 // Author: G. Balbastre
\r
4 // Modified by K. Read
\r
7 // After previously using mymerger.C to merge each PYHIA hard bin,
\r
8 // do the following to download one file per pt bin:
\r
9 // aliensh; cd <production name>/output/merged; cp histoss* file:
\r
10 // Then, adjust binlist below to reflect which histograms are non-empty.
\r
12 // root -b -x MergeFileInBins.C
\r
14 // Note: This macro overwrites the downloaded histograms with the same names.
\r
15 // It may be appropriate to make a backup of the histograms before running
\r
19 void MergeFileInBins()
\r
26 TString binlist = "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15";
\r
28 if (binlist.Length()) {
\r
29 arr = binlist.Tokenize(" ");
\r
32 while ((os=(TObjString*)next())) {
\r
33 printf("Rescaling histosscaled-merged%s.root\n",os->GetString().Data());
\r
35 //Rescale histograms
\r
36 sprintf(name,"histosscaled-merged%s.root",os->GetString().Data());
\r
37 mfile = new TFile(name,"read");
\r
38 list = (TList*) mfile->Get("histosscaled");
\r
42 Int_t split = ((TH1F*) list->FindObject("hCount"))->GetEntries();
\r
43 cout<<"scale with factor "<<split<< " histograms "<<list->GetEntries()<<endl;
\r
44 newlist = new TList();
\r
45 sprintf(name,"%s2",list->GetName());
\r
46 newlist->SetName(name);
\r
48 for(Int_t iter = 0; iter < list->GetEntries(); iter++){
\r
50 if(h && (h->GetName()!="hCount")){
\r
51 if ( !strncmp(h->ClassName(),"TH",2) ) {
\r
53 sprintf(name, "%s", h->GetName()) ;
\r
54 //cout<<iter<<" histo scaled : "<<name<<endl;
\r
55 TH1 * hout = dynamic_cast<TH1*> (h->Clone(name)) ;
\r
56 //if(fSumw2) hout->Sumw2();
\r
57 hout->Scale(1./split) ;
\r
58 newlist->Add(hout) ;
\r
63 sprintf(name,"histosscaled-merged%s.root",os->GetString().Data());
\r
64 sfile = new TFile(name,"recreate");
\r
67 cout<<name<<" has been recreated "<<endl;
\r
74 cout<<"Merge all bins "<<endl;
\r
77 sprintf(name,"TOTALhistosscaled.root");
\r
79 if (binlist.Length()) {
\r
81 arr = binlist.Tokenize(" ");
\r
84 while ((os=(TObjString*)next())) {
\r
85 printf("Adding bin histosscaled-merged%s.root\n",os->GetString().Data());
\r
86 sprintf(name,"histosscaled-merged%s.root",os->GetString().Data());
\r