15 #include "TPaveStats.h" 16 #include "TObjArray.h" 17 #include "TObjString.h" 32 void MergeRootfile( TDirectory *
target, TList *sourcelist, TList *labellist,
bool bigtext );
33 void nicePad(Int_t logx,Int_t logy);
38 void compareAlignments(TString namesandlabels=
"readFromFile", TString legendheader =
"", TString lefttitle =
"", TString righttitle =
"",
bool bigtext =
false)
40 cout <<
"Comparing using: >"<<namesandlabels<<
"<"<<endl;
44 gStyle->SetOptStat(111110);
45 gStyle->SetOptTitle(0);
47 Target = TFile::Open(
"result.root",
"RECREATE" );
51 int formatCounter = 1;
53 TObjArray *nameandlabelpairs = namesandlabels.Tokenize(
",");
54 for (Int_t
i = 0;
i < nameandlabelpairs->GetEntries(); ++
i) {
55 TObjArray *aFileLegPair = TString(nameandlabelpairs->At(
i)->GetName()).Tokenize(
"=");
57 if(aFileLegPair->GetEntries() == 2) {
58 TFile* currentFile = TFile::Open(aFileLegPair->At(0)->GetName());
59 if( currentFile !=
NULL && !currentFile->IsZombie() ){
61 if ( currentFile->Get(
"TrackerOfflineValidationStandalone/Pixel/P1PXBBarrel_1") ) {
62 cout <<
"phase 1" << endl;
64 }
else if ( currentFile->Get(
"TrackerOfflineValidationStandalone/Pixel/TPBBarrel_1") ) {
65 cout <<
"phase 0" << endl;
68 cout <<
"Unknown phase for file " << aFileLegPair->At(0)->GetName() << endl;
71 if(TString(aFileLegPair->At(1)->GetName()).Contains(
"|")){
72 TObjArray* formatedLegendEntry = TString(aFileLegPair->At(1)->GetName()).Tokenize(
"|");
73 LabelList->Add( formatedLegendEntry->At(0) );
74 if(formatedLegendEntry->GetEntries() > 1){
75 theColors.push_back(atoi(formatedLegendEntry->At(1)->GetName()));
77 if(formatedLegendEntry->GetEntries() > 2)
78 theStyles.push_back(atoi(formatedLegendEntry->At(2)->GetName()));
82 std::cout <<
"if you give a \"|\" in the legend name you will need to at least give a int for the color"<<std::endl;
92 std::cout <<
"Could not open: "<<aFileLegPair->At(0)->GetName()<<std::endl;
96 std::cout <<
"Please give file name and legend entry in the following form:\n" 97 <<
" filename1=legendentry1,filename2=legendentry2[|color[|style]]"<<std::endl;
131 if( sourcelist->GetSize() == 0){
132 std::cout<<
"Cowardly refuse to merge empty SourceList! " <<std::endl;
136 TString
path( (
char*)strstr( target->GetPath(),
":" ) );
139 TFile *first_source = (TFile*)sourcelist->First();
140 TObjString *first_label = (TObjString*)labellist->First();
142 first_source->cd( path );
143 TDirectory *current_sourcedir = gDirectory;
145 Bool_t
status = TH1::AddDirectoryStatus();
146 TH1::AddDirectory(kFALSE);
150 TIter nextkey( current_sourcedir->GetListOfKeys() );
151 TKey *
key, *oldkey=0;
152 while ( (key = (TKey*)nextkey())) {
155 if (oldkey && !strcmp(oldkey->GetName(),key->GetName()))
continue;
158 first_source->cd( path );
159 TObject *
obj = key->ReadObj();
161 auto itphase =
phases.begin();
162 int firstfilephase = *itphase;
164 if ( obj->IsA()->InheritsFrom(
TH1::Class() ) ) {
166 TCanvas
c(obj->GetName(),obj->GetName());
170 if(strstr(obj->ClassName() ,
"TH2") !=
NULL )
172 TH1 *h1 =
static_cast<TH1*
>(
obj);
175 TObjArray *histarray =
new TObjArray;
183 h1->GetYaxis()->SetTitleOffset(1.5);
184 if(strstr(h1->GetName(),
"summary") !=
NULL )
191 double max = h1->GetMaximum();
194 int power = (
int)(TMath::Log10(max / 100));
195 scale = 1/TMath::Power(10, power);
196 h1->GetYaxis()->SetTitle(((TString(h1->GetYaxis()->GetTitle()) +
" [#times 10^{") += (
int)power) +
"}]");
200 int nPlots = sourcelist->GetSize();
201 double legendY = 0.80;
202 if (nPlots > 3) { legendY -= 0.01 * (nPlots - 3); }
203 if (bigtext) { legendY -= 0.05; }
205 std::cerr <<
"Warning: Huge legend!" << std::endl;
208 TLegend
leg(0.17, legendY, 0.85, 0.88);
212 leg.AddEntry(h1,first_label->String().Data(),
"L");
213 leg.SetBorderSize(0);
214 leg.SetFillColor(10);
217 TFile *nextsource = (TFile*)sourcelist->After( first_source );
218 TObjString *nextlabel = (TObjString*)labellist->After( labellist->First() );
221 while ( nextsource ) {
224 bool wrongphase =
false;
227 if (firstfilephase != *itphase && path.Contains(
"TrackerOfflineValidationStandalone/Pixel")) {
233 nextsource->cd( path );
234 key2 = (TKey*)gDirectory->GetListOfKeys()->FindObject(h1->GetName());
238 TH1 *h2 = (TH1*)key2->ReadObj();
246 std::stringstream newname;
247 newname << h2->GetName() <<
q;
250 h2->SetName(newname.str().c_str());
251 if(strstr(newname.str().c_str(),
"summary") !=
NULL )
252 h2->DrawClone(
"x0*He1sames");
254 h2->DrawClone(
"sames");
256 h2->DrawClone(
"sames");
257 leg.AddEntry(
c.FindObject(h2->GetName()),nextlabel->String().Data(),
"L");
258 histarray->Add(
c.FindObject(h2->GetName()));
260 }
else if (wrongphase) {
263 std::cerr <<
"Histogram "<< key2->GetTitle() <<
" is not present in file " << nextsource->GetName() << std::endl;
266 nextsource = (TFile*)sourcelist->After( nextsource );
267 nextlabel = (TObjString*)labellist->After(nextlabel);
273 if(strstr(h1->GetName(),
"summary") ==
NULL )
288 for( std::vector< std::string >::const_iterator lowlevelit =
lowestlevels.begin(),
289 lowlevelitend =
lowestlevels.end(); lowlevelit != lowlevelitend; ++lowlevelit)
290 if( dirname.find(*lowlevelit) != std::string::npos )
295 TDirectory *newdir = target->mkdir( obj->GetName(), obj->GetTitle() );
306 cout <<
"Unknown object type, name: " 307 << obj->GetName() <<
" title: " << obj->GetTitle() << endl;
314 target->SaveSelf(kTRUE);
315 TH1::AddDirectory(status);
353 Double_t fStatsX1 = 0.85, fStatsX2 = 1., fStatsY1 = 0.77, fStatsY2 = 0.92;
356 Double_t x1 = fStatsX1, x2 = fStatsX2, y1 = fStatsY1, y2 = fStatsY2;
357 for (Int_t iH = 0; iH < hists->GetEntries(); ++iH) {
358 TH1 *
h =
static_cast<TH1*
>(hists->At(iH));
360 TObject *statObj = h->GetListOfFunctions()->FindObject(
"stats");
362 TPaveStats *stats =
static_cast<TPaveStats*
>(statObj);
363 stats->SetLineColor(static_cast<TH1*>(hists->At(iH))->GetLineColor());
364 stats->SetTextColor(static_cast<TH1*>(hists->At(iH))->GetLineColor());
365 stats->SetFillColor(10);
371 y1 = y2 - (fStatsY2 - fStatsY1);
373 y1 = fStatsY1; y2 = fStatsY2;
375 x1 = x2 - (fStatsX2 - fStatsX1);
377 x1 = fStatsX1, x2 = fStatsX2, y1 = fStatsY1, y2 = fStatsY2;
390 Double_t
min = 100000;
391 Double_t
max = -100000;
392 for (Int_t iH = 0; iH < hists->GetEntries(); ++iH) {
393 TH1 *
h =
static_cast<TH1*
>(hists->At(iH));
395 for(
int i = 1;
i <= h->GetNbinsX(); ++
i) {
396 if(h->GetBinContent(
i) + h->GetBinError(
i) >
max ) max = h->GetBinContent(
i) + h->GetBinError(
i);
397 if(h->GetBinContent(
i) - h->GetBinError(
i) <
min ) min = h->GetBinContent(
i) - h->GetBinError(
i);
401 TH1 *h_first =
static_cast<TH1*
>(hists->At(0));
402 h_first->SetMaximum(max*1.3);
405 h_first->SetMinimum(min);
407 h_first->SetMinimum(min-min*0.1);
std::vector< int > theStyles
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
void SetMinMaxRange(TObjArray *hists)
std::vector< int > phases
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)