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") ) {
63 }
else if ( currentFile->Get(
"TrackerOfflineValidationStandalone/Pixel/TPBBarrel_1") ) {
66 cout <<
"Unknown phase for file " << aFileLegPair->At(0)->GetName() << endl;
69 if(TString(aFileLegPair->At(1)->GetName()).Contains(
"|")){
70 TObjArray* formatedLegendEntry = TString(aFileLegPair->At(1)->GetName()).Tokenize(
"|");
71 LabelList->Add( formatedLegendEntry->At(0) );
72 if(formatedLegendEntry->GetEntries() > 1){
73 theColors.push_back(atoi(formatedLegendEntry->At(1)->GetName()));
75 if(formatedLegendEntry->GetEntries() > 2)
76 theStyles.push_back(atoi(formatedLegendEntry->At(2)->GetName())%100);
80 std::cout <<
"if you give a \"|\" in the legend name you will need to at least give a int for the color"<<std::endl;
90 std::cout <<
"Could not open: "<<aFileLegPair->At(0)->GetName()<<std::endl;
94 std::cout <<
"Please give file name and legend entry in the following form:\n"
95 <<
" filename1=legendentry1,filename2=legendentry2[|color[|style]]"<<std::endl;
129 if( sourcelist->GetSize() == 0){
130 std::cout<<
"Cowardly refuse to merge empty SourceList! " <<std::endl;
134 TString
path( (
char*)strstr(
target->GetPath(),
":" ) );
137 TFile *first_source = (TFile*)sourcelist->First();
138 TObjString *first_label = (TObjString*)labellist->First();
140 first_source->cd(
path );
141 TDirectory *current_sourcedir = gDirectory;
143 Bool_t
status = TH1::AddDirectoryStatus();
144 TH1::AddDirectory(kFALSE);
148 TIter nextkey( current_sourcedir->GetListOfKeys() );
149 TKey *
key, *oldkey=0;
150 while ( (
key = (TKey*)nextkey())) {
153 if (oldkey && !strcmp(oldkey->GetName(),
key->GetName()))
continue;
156 first_source->cd(
path );
157 TObject *
obj =
key->ReadObj();
159 auto itphase =
phases.begin();
160 int firstfilephase = *itphase;
164 TCanvas
c(
obj->GetName(),
obj->GetName());
168 if(strstr(
obj->ClassName() ,
"TH2") !=
NULL )
170 TH1 *h1 = static_cast<TH1*>(
obj);
173 TObjArray *histarray =
new TObjArray;
181 h1->GetYaxis()->SetTitleOffset(1.5);
182 if(strstr(h1->GetName(),
"summary") !=
NULL )
189 double max = h1->GetMaximum();
192 int power = (
int)(TMath::Log10(
max / 100));
193 scale = 1/TMath::Power(10, power);
194 h1->GetYaxis()->SetTitle(((TString(h1->GetYaxis()->GetTitle()) +
" [#times 10^{") += (
int)power) +
"}]");
198 int nPlots = sourcelist->GetSize();
199 double legendY = 0.80;
200 if (nPlots > 3) { legendY -= 0.01 * (nPlots - 3); }
201 if (bigtext) { legendY -= 0.05; }
203 std::cerr <<
"Warning: Huge legend!" << std::endl;
206 TLegend leg(0.17, legendY, 0.85, 0.88);
210 leg.AddEntry(h1,first_label->String().Data(),
"L");
211 leg.SetBorderSize(0);
212 leg.SetFillColor(10);
215 TFile *nextsource = (TFile*)sourcelist->After( first_source );
216 TObjString *nextlabel = (TObjString*)labellist->After( labellist->First() );
219 while ( nextsource ) {
222 bool wrongphase =
false;
225 if (firstfilephase != *itphase &&
path.Contains(
"TrackerOfflineValidationStandalone/Pixel")) {
231 nextsource->cd(
path );
232 key2 = (TKey*)gDirectory->GetListOfKeys()->FindObject(h1->GetName());
236 TH1 *h2 = (TH1*)key2->ReadObj();
244 std::stringstream newname;
245 newname << h2->GetName() <<
q;
248 h2->SetName(newname.str().c_str());
249 if(strstr(newname.str().c_str(),
"summary") !=
NULL )
250 h2->DrawClone(
"x0*He1sames");
252 h2->DrawClone(
"sames");
254 h2->DrawClone(
"sames");
255 leg.AddEntry(
c.FindObject(h2->GetName()),nextlabel->String().Data(),
"L");
256 histarray->Add(
c.FindObject(h2->GetName()));
258 }
else if (wrongphase) {
261 std::cerr <<
"Histogram "<< key2->GetTitle() <<
" is not present in file " << nextsource->GetName() << std::endl;
264 nextsource = (TFile*)sourcelist->After( nextsource );
265 nextlabel = (TObjString*)labellist->After(nextlabel);
271 if(strstr(h1->GetName(),
"summary") ==
NULL )
286 for( std::vector< std::string >::const_iterator lowlevelit =
lowestlevels.begin(),
287 lowlevelitend =
lowestlevels.end(); lowlevelit != lowlevelitend; ++lowlevelit)
288 if(
dirname.find(*lowlevelit) != std::string::npos )
293 TDirectory *newdir =
target->mkdir(
obj->GetName(),
obj->GetTitle() );
304 cout <<
"Unknown object type, name: "
305 <<
obj->GetName() <<
" title: " <<
obj->GetTitle() << endl;
313 TH1::AddDirectory(
status);
351 Double_t fStatsX1 = 0.85, fStatsX2 = 1., fStatsY1 = 0.77, fStatsY2 = 0.92;
354 Double_t
x1 = fStatsX1,
x2 = fStatsX2,
y1 = fStatsY1,
y2 = fStatsY2;
355 for (Int_t iH = 0; iH <
hists->GetEntries(); ++iH) {
356 TH1 *
h = static_cast<TH1*>(
hists->At(iH));
358 TObject *statObj =
h->GetListOfFunctions()->FindObject(
"stats");
360 TPaveStats *
stats = static_cast<TPaveStats*>(statObj);
361 stats->SetLineColor(static_cast<TH1*>(
hists->At(iH))->GetLineColor());
362 stats->SetTextColor(static_cast<TH1*>(
hists->At(iH))->GetLineColor());
363 stats->SetFillColor(10);
369 y1 =
y2 - (fStatsY2 - fStatsY1);
371 y1 = fStatsY1;
y2 = fStatsY2;
373 x1 =
x2 - (fStatsX2 - fStatsX1);
375 x1 = fStatsX1,
x2 = fStatsX2,
y1 = fStatsY1,
y2 = fStatsY2;
388 Double_t
min = 100000;
389 Double_t
max = -100000;
390 for (Int_t iH = 0; iH <
hists->GetEntries(); ++iH) {
391 TH1 *
h = static_cast<TH1*>(
hists->At(iH));
393 for(
int i = 1;
i <=
h->GetNbinsX(); ++
i) {
394 if(
h->GetBinContent(
i) +
h->GetBinError(
i) >
max )
max =
h->GetBinContent(
i) +
h->GetBinError(
i);
395 if(
h->GetBinContent(
i) -
h->GetBinError(
i) <
min )
min =
h->GetBinContent(
i) -
h->GetBinError(
i);
399 TH1 *h_first = static_cast<TH1*>(
hists->At(0));
400 h_first->SetMaximum(
max*1.3);
403 h_first->SetMinimum(
min);
405 h_first->SetMinimum(
min-
min*0.1);