14 #include "TPaveStats.h"
15 #include "TObjArray.h"
16 #include "TObjString.h"
29 void nicePad(Int_t logx,Int_t logy);
36 cout <<
"Comparing using: >"<<namesandlabels<<
"<"<<endl;
38 gStyle->SetOptStat(111110);
39 gStyle->SetTitleFillColor(10);
40 gStyle->SetTitleBorderSize(0);
42 Target = TFile::Open(
"result.root",
"RECREATE" );
46 int formatCounter = 1;
48 TObjArray *nameandlabelpairs = namesandlabels.Tokenize(
",");
49 for (Int_t
i = 0;
i < nameandlabelpairs->GetEntries(); ++
i) {
50 TObjArray *aFileLegPair = TString(nameandlabelpairs->At(
i)->GetName()).Tokenize(
"=");
52 if(aFileLegPair->GetEntries() == 2) {
53 TFile* currentFile = TFile::Open(aFileLegPair->At(0)->GetName());
54 if( currentFile !=
NULL && !currentFile->IsZombie() ){
56 if(TString(aFileLegPair->At(1)->GetName()).Contains(
"|")){
57 TObjArray* formatedLegendEntry = TString(aFileLegPair->At(1)->GetName()).Tokenize(
"|");
58 LabelList->Add( formatedLegendEntry->At(0) );
59 if(formatedLegendEntry->GetEntries() > 1){
60 theColors.push_back(atoi(formatedLegendEntry->At(1)->GetName()));
62 if(formatedLegendEntry->GetEntries() > 2)
63 theStyles.push_back(atoi(formatedLegendEntry->At(2)->GetName()));
67 std::cout <<
"if you give a \"|\" in the legend name you will need to at least give a int for the color"<<std::endl;
77 std::cout <<
"Could not open: "<<aFileLegPair->At(0)->GetName()<<std::endl;
81 std::cout <<
"Please give file name and legend entry in the following form:\n"
82 <<
" filename1=legendentry1,filename2=legendentry2[|color[|style]]"<<std::endl;
113 if( sourcelist->GetSize() == 0){
114 std::cout<<
"Cowardly refuse to merge empty SourceList! " <<std::endl;
118 TString
path( (
char*)strstr( target->GetPath(),
":" ) );
121 TFile *first_source = (TFile*)sourcelist->First();
122 TObjString *first_label = (TObjString*)labellist->First();
124 first_source->cd( path );
125 TDirectory *current_sourcedir = gDirectory;
127 Bool_t
status = TH1::AddDirectoryStatus();
128 TH1::AddDirectory(kFALSE);
132 TIter nextkey( current_sourcedir->GetListOfKeys() );
133 TKey *
key, *oldkey=0;
134 while ( (key = (TKey*)nextkey())) {
137 if (oldkey && !strcmp(oldkey->GetName(),key->GetName()))
continue;
140 first_source->cd( path );
141 TObject *
obj = key->ReadObj();
143 if ( obj->IsA()->InheritsFrom( TH1::Class() ) ) {
145 TCanvas
c(obj->GetName(),obj->GetName(),500,500);
149 if(strstr(obj->ClassName() ,
"TH2") !=
NULL )
151 TH1 *h1 =
static_cast<TH1*
>(
obj);
154 TObjArray *histarray =
new TObjArray;
160 h1->GetYaxis()->SetTitleOffset(1.5);
161 if(strstr(h1->GetName(),
"summary") !=
NULL )
168 TLegend
leg(0.2,0.85,0.775,0.93);
169 leg.AddEntry(h1,first_label->String().Data(),
"L");
170 leg.SetBorderSize(0);
171 leg.SetFillColor(10);
174 TFile *nextsource = (TFile*)sourcelist->After( first_source );
175 TObjString *nextlabel = (TObjString*)labellist->After( labellist->First() );
178 while ( nextsource ) {
182 nextsource->cd( path );
183 TKey *key2 = (TKey*)gDirectory->GetListOfKeys()->FindObject(h1->GetName());
186 TH1 *h2 = (TH1*)key2->ReadObj();
194 std::stringstream newname;
195 newname << h2->GetName() <<
q;
197 h2->SetName(newname.str().c_str());
198 if(strstr(newname.str().c_str(),
"summary") !=
NULL )
199 h2->DrawClone(
"x0*He1sames");
201 h2->DrawClone(
"sames");
203 h2->DrawClone(
"sames");
204 leg.AddEntry(
c.FindObject(h2->GetName()),nextlabel->String().Data(),
"L");
205 histarray->Add(
c.FindObject(h2->GetName()));
208 std::cerr <<
"Histogram "<< key2->GetTitle() <<
" is not present in file " << nextsource->GetName() << std::endl;
211 nextsource = (TFile*)sourcelist->After( nextsource );
212 nextlabel = (TObjString*)labellist->After(nextlabel);
217 if(strstr(h1->GetName(),
"summary") ==
NULL )
227 }
else if ( obj->IsA()->InheritsFrom( TDirectory::Class() ) ) {
231 for( std::vector< std::string >::const_iterator lowlevelit =
lowestlevels.begin(),
232 lowlevelitend =
lowestlevels.end(); lowlevelit != lowlevelitend; ++lowlevelit)
233 if( dirname.find(*lowlevelit) != std::string::npos )
238 TDirectory *newdir = target->mkdir( obj->GetName(), obj->GetTitle() );
249 cout <<
"Unknown object type, name: "
250 << obj->GetName() <<
" title: " << obj->GetTitle() << endl;
257 target->SaveSelf(kTRUE);
258 TH1::AddDirectory(status);
266 gPad->SetBottomMargin(0.10);
267 gPad->SetRightMargin(0.1);
268 gPad->SetLeftMargin(0.15);
269 gPad->SetTopMargin(0.15);
294 Double_t fStatsX1 = 0.85, fStatsX2 = 1., fStatsY1 = 0.85, fStatsY2 = 1.;
297 Double_t x1 = fStatsX1, x2 = fStatsX2, y1 = fStatsY1, y2 = fStatsY2;
298 for (Int_t iH = 0; iH < hists->GetEntries(); ++iH) {
299 TH1 *
h =
static_cast<TH1*
>(hists->At(iH));
301 TObject *statObj = h->GetListOfFunctions()->FindObject(
"stats");
302 if (statObj && statObj->InheritsFrom(TPaveStats::Class())) {
303 TPaveStats *stats =
static_cast<TPaveStats*
>(statObj);
304 stats->SetLineColor(static_cast<TH1*>(hists->At(iH))->GetLineColor());
305 stats->SetTextColor(static_cast<TH1*>(hists->At(iH))->GetLineColor());
306 stats->SetFillColor(10);
312 y1 = y2 - (fStatsY2 - fStatsY1);
314 y1 = fStatsY1; y2 = fStatsY2;
316 x1 = x2 - (fStatsX2 - fStatsX1);
318 x1 = fStatsX1, x2 = fStatsX2, y1 = fStatsY1, y2 = fStatsY2;
330 Double_t
min = 100000;
331 Double_t
max = -100000;
332 for (Int_t iH = 0; iH < hists->GetEntries(); ++iH) {
333 TH1 *
h =
static_cast<TH1*
>(hists->At(iH));
335 for(
int i = 1;
i <= h->GetNbinsX(); ++
i) {
336 if(h->GetBinContent(
i) + h->GetBinError(
i) >
max ) max = h->GetBinContent(
i) + h->GetBinError(
i);
337 if(h->GetBinContent(
i) - h->GetBinError(
i) <
min ) min = h->GetBinContent(
i) - h->GetBinError(
i);
341 TH1 *h_first =
static_cast<TH1*
>(hists->At(0));
342 h_first->SetMaximum(max+max*0.1);
345 h_first->SetMinimum(min);
347 h_first->SetMinimum(min-min*0.1);
void compareAlignments(TString namesandlabels="readFromFile")
std::vector< int > theStyles
void MergeRootfile(TDirectory *target, TList *sourcelist, TList *labellist)
std::vector< int > theColors
void ColourStatsBoxes(TObjArray *hists)
tuple path
else: Piece not in the list, fine.
const T & max(const T &a, const T &b)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
void SetMinMaxRange(TObjArray *hists)
std::vector< std::string > lowestlevels
void nicePad(Int_t logx, Int_t logy)