15 #include "TPaveStats.h"
16 #include "TObjArray.h"
17 #include "TObjString.h"
31 void MergeRootfile( TDirectory *
target, TList *sourcelist, TList *labellist,
bool bigtext );
32 void nicePad(Int_t logx,Int_t logy);
37 void compareAlignments(TString namesandlabels=
"readFromFile", TString legendheader =
"", TString lefttitle =
"", TString righttitle =
"",
bool bigtext =
false)
39 cout <<
"Comparing using: >"<<namesandlabels<<
"<"<<endl;
43 gStyle->SetOptStat(111110);
44 gStyle->SetOptTitle(0);
46 Target = TFile::Open(
"result.root",
"RECREATE" );
50 int formatCounter = 1;
52 TObjArray *nameandlabelpairs = namesandlabels.Tokenize(
",");
53 for (Int_t
i = 0;
i < nameandlabelpairs->GetEntries(); ++
i) {
54 TObjArray *aFileLegPair = TString(nameandlabelpairs->At(
i)->GetName()).Tokenize(
"=");
56 if(aFileLegPair->GetEntries() == 2) {
57 TFile* currentFile = TFile::Open(aFileLegPair->At(0)->GetName());
58 if( currentFile !=
NULL && !currentFile->IsZombie() ){
60 if(TString(aFileLegPair->At(1)->GetName()).Contains(
"|")){
61 TObjArray* formatedLegendEntry = TString(aFileLegPair->At(1)->GetName()).Tokenize(
"|");
62 LabelList->Add( formatedLegendEntry->At(0) );
63 if(formatedLegendEntry->GetEntries() > 1){
64 theColors.push_back(atoi(formatedLegendEntry->At(1)->GetName()));
66 if(formatedLegendEntry->GetEntries() > 2)
67 theStyles.push_back(atoi(formatedLegendEntry->At(2)->GetName()));
71 std::cout <<
"if you give a \"|\" in the legend name you will need to at least give a int for the color"<<std::endl;
81 std::cout <<
"Could not open: "<<aFileLegPair->At(0)->GetName()<<std::endl;
85 std::cout <<
"Please give file name and legend entry in the following form:\n"
86 <<
" filename1=legendentry1,filename2=legendentry2[|color[|style]]"<<std::endl;
117 if( sourcelist->GetSize() == 0){
118 std::cout<<
"Cowardly refuse to merge empty SourceList! " <<std::endl;
122 TString
path( (
char*)strstr( target->GetPath(),
":" ) );
125 TFile *first_source = (TFile*)sourcelist->First();
126 TObjString *first_label = (TObjString*)labellist->First();
128 first_source->cd( path );
129 TDirectory *current_sourcedir = gDirectory;
131 Bool_t
status = TH1::AddDirectoryStatus();
132 TH1::AddDirectory(kFALSE);
136 TIter nextkey( current_sourcedir->GetListOfKeys() );
137 TKey *
key, *oldkey=0;
138 while ( (key = (TKey*)nextkey())) {
141 if (oldkey && !strcmp(oldkey->GetName(),key->GetName()))
continue;
144 first_source->cd( path );
145 TObject *
obj = key->ReadObj();
147 if ( obj->IsA()->InheritsFrom( TH1::Class() ) ) {
149 TCanvas
c(obj->GetName(),obj->GetName());
153 if(strstr(obj->ClassName() ,
"TH2") !=
NULL )
155 TH1 *h1 =
static_cast<TH1*
>(
obj);
158 TObjArray *histarray =
new TObjArray;
166 h1->GetYaxis()->SetTitleOffset(1.5);
167 if(strstr(h1->GetName(),
"summary") !=
NULL )
174 double max = h1->GetMaximum();
177 int power = (int)(TMath::Log10(max / 100));
178 scale = 1/TMath::Power(10, power);
179 h1->GetYaxis()->SetTitle(((TString(h1->GetYaxis()->GetTitle()) +
" [#times 10^{") += (int)power) +
"}]");
183 int nPlots = sourcelist->GetSize();
184 double legendY = 0.80;
185 if (nPlots > 3) { legendY -= 0.01 * (nPlots - 3); }
186 if (bigtext) { legendY -= 0.05; }
188 std::cerr <<
"Warning: Huge legend!" << std::endl;
191 TLegend
leg(0.17, legendY, 0.85, 0.88);
195 leg.AddEntry(h1,first_label->String().Data(),
"L");
196 leg.SetBorderSize(0);
197 leg.SetFillColor(10);
200 TFile *nextsource = (TFile*)sourcelist->After( first_source );
201 TObjString *nextlabel = (TObjString*)labellist->After( labellist->First() );
204 while ( nextsource ) {
208 nextsource->cd( path );
209 TKey *key2 = (TKey*)gDirectory->GetListOfKeys()->FindObject(h1->GetName());
212 TH1 *h2 = (TH1*)key2->ReadObj();
220 std::stringstream newname;
221 newname << h2->GetName() <<
q;
224 h2->SetName(newname.str().c_str());
225 if(strstr(newname.str().c_str(),
"summary") !=
NULL )
226 h2->DrawClone(
"x0*He1sames");
228 h2->DrawClone(
"sames");
230 h2->DrawClone(
"sames");
231 leg.AddEntry(
c.FindObject(h2->GetName()),nextlabel->String().Data(),
"L");
232 histarray->Add(
c.FindObject(h2->GetName()));
235 std::cerr <<
"Histogram "<< key2->GetTitle() <<
" is not present in file " << nextsource->GetName() << std::endl;
238 nextsource = (TFile*)sourcelist->After( nextsource );
239 nextlabel = (TObjString*)labellist->After(nextlabel);
245 if(strstr(h1->GetName(),
"summary") ==
NULL )
256 }
else if ( obj->IsA()->InheritsFrom( TDirectory::Class() ) ) {
260 for( std::vector< std::string >::const_iterator lowlevelit =
lowestlevels.begin(),
261 lowlevelitend =
lowestlevels.end(); lowlevelit != lowlevelitend; ++lowlevelit)
262 if( dirname.find(*lowlevelit) != std::string::npos )
267 TDirectory *newdir = target->mkdir( obj->GetName(), obj->GetTitle() );
278 cout <<
"Unknown object type, name: "
279 << obj->GetName() <<
" title: " << obj->GetTitle() << endl;
286 target->SaveSelf(kTRUE);
287 TH1::AddDirectory(status);
325 Double_t fStatsX1 = 0.85, fStatsX2 = 1., fStatsY1 = 0.77, fStatsY2 = 0.92;
328 Double_t x1 = fStatsX1, x2 = fStatsX2, y1 = fStatsY1, y2 = fStatsY2;
329 for (Int_t iH = 0; iH < hists->GetEntries(); ++iH) {
330 TH1 *
h =
static_cast<TH1*
>(hists->At(iH));
332 TObject *statObj = h->GetListOfFunctions()->FindObject(
"stats");
333 if (statObj && statObj->InheritsFrom(TPaveStats::Class())) {
334 TPaveStats *stats =
static_cast<TPaveStats*
>(statObj);
335 stats->SetLineColor(static_cast<TH1*>(hists->At(iH))->GetLineColor());
336 stats->SetTextColor(static_cast<TH1*>(hists->At(iH))->GetLineColor());
337 stats->SetFillColor(10);
343 y1 = y2 - (fStatsY2 - fStatsY1);
345 y1 = fStatsY1; y2 = fStatsY2;
347 x1 = x2 - (fStatsX2 - fStatsX1);
349 x1 = fStatsX1, x2 = fStatsX2, y1 = fStatsY1, y2 = fStatsY2;
362 Double_t
min = 100000;
363 Double_t
max = -100000;
364 for (Int_t iH = 0; iH < hists->GetEntries(); ++iH) {
365 TH1 *
h =
static_cast<TH1*
>(hists->At(iH));
367 for(
int i = 1;
i <= h->GetNbinsX(); ++
i) {
368 if(h->GetBinContent(
i) + h->GetBinError(
i) >
max ) max = h->GetBinContent(
i) + h->GetBinError(
i);
369 if(h->GetBinContent(
i) - h->GetBinError(
i) <
min ) min = h->GetBinContent(
i) - h->GetBinError(
i);
373 TH1 *h_first =
static_cast<TH1*
>(hists->At(0));
374 h_first->SetMaximum(max*1.3);
377 h_first->SetMinimum(min);
379 h_first->SetMinimum(min-min*0.1);
std::vector< int > theStyles
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
std::vector< int > theColors
void ColourStatsBoxes(TObjArray *hists)
static void set(const PublicationStatus status, const Era era=NONE, const TString customTitle="", const TString customRightTitle="")
static void drawStandardTitle()
void MergeRootfile(TDirectory *target, TList *sourcelist, TList *labellist, bool bigtext)
static TString legendheader
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
void SetMinMaxRange(TObjArray *hists)
std::vector< std::string > lowestlevels
void compareAlignments(TString namesandlabels="readFromFile", TString legendheader="", TString lefttitle="", TString righttitle="", bool bigtext=false)
void nicePad(Int_t logx, Int_t logy)