1 #include "compareRootFiles.hh"
16 compareRootFiles::compareRootFiles(
string decayName,
string newFileName,
string oldFileName,
19 _decayName = decayName;
20 _newFileName = newFileName;
21 _oldFileName = oldFileName;
22 _description = description;
24 _newFile =
new TFile(newFileName.c_str(),
"read");
25 _oldFile =
new TFile(oldFileName.c_str(),
"read");
27 gROOT->SetStyle(
"Plain");
28 gStyle->SetOptStat(0);
30 _theCanvas =
new TCanvas(
"theCanvas",
"", 900, 700);
32 _theCanvas->UseCurrentStyle();
34 _emptyHist =
new TH1D(
"",
"", 10, 0.0, 0.0);
40 compareRootFiles::~compareRootFiles() {
47 void compareRootFiles::getMtmPlots() {
52 vector<TH1D*> newHistVect, oldHistVect;
54 vector<int> leptonInts;
55 leptonInts.push_back(0); leptonInts.push_back(1);
56 TH1D* newLeptMtmHist = getMtmHist(_newFile,
"newLeptMtmHist", leptonInts);
57 TH1D* oldLeptMtmHist = getMtmHist(_oldFile,
"oldLeptMtmHist", leptonInts);
58 newHistVect.push_back(newLeptMtmHist);
59 oldHistVect.push_back(oldLeptMtmHist);
62 pionInts.push_back(2); pionInts.push_back(3);
63 TH1D* newPionMtmHist = getMtmHist(_newFile,
"newPionMtmHist", pionInts);
64 TH1D* oldPionMtmHist = getMtmHist(_oldFile,
"oldPionMtmHist", pionInts);
65 newHistVect.push_back(newPionMtmHist);
66 oldHistVect.push_back(oldPionMtmHist);
69 kaonInts.push_back(4); kaonInts.push_back(5);
70 TH1D* newKaonMtmHist = getMtmHist(_newFile,
"newKaonMtmHist", kaonInts);
71 TH1D* oldKaonMtmHist = getMtmHist(_oldFile,
"oldKaonMtmHist", kaonInts);
72 newHistVect.push_back(newKaonMtmHist);
73 oldHistVect.push_back(oldKaonMtmHist);
75 vector<int> charmInts;
76 charmInts.push_back(6); charmInts.push_back(7);
77 TH1D* newCharmMtmHist = getMtmHist(_newFile,
"newCharmMtmHist", charmInts);
78 TH1D* oldCharmMtmHist = getMtmHist(_oldFile,
"oldCharmMtmHist", charmInts);
79 newHistVect.push_back(newCharmMtmHist);
80 oldHistVect.push_back(oldCharmMtmHist);
82 vector<int> baryonInts;
83 baryonInts.push_back(8); baryonInts.push_back(9);
84 TH1D* newBaryonMtmHist = getMtmHist(_newFile,
"newBaryonMtmHist", baryonInts);
85 TH1D* oldBaryonMtmHist = getMtmHist(_oldFile,
"oldBaryonMtmHist", baryonInts);
86 newHistVect.push_back(newBaryonMtmHist);
87 oldHistVect.push_back(oldBaryonMtmHist);
89 vector<int> otherInts;
90 otherInts.push_back(10);
91 TH1D* newOtherMtmHist = getMtmHist(_newFile,
"newOtherMtmHist", otherInts);
92 TH1D* oldOtherMtmHist = getMtmHist(_oldFile,
"oldOtherMtmHist", otherInts);
93 newHistVect.push_back(newOtherMtmHist);
94 oldHistVect.push_back(oldOtherMtmHist);
97 _theCanvas->UseCurrentStyle();
102 int colours[6] = {1, 2, 4, 6, 8, 28};
103 string histLabels[6] = {
"Leptons,#gamma",
"Pions",
"Kaons",
"D+,D-,D0",
104 "Light/strange baryons",
"Other"};
106 TLegend* theLegend =
new TLegend(0.7, 0.7, 0.9, 0.9);
107 theLegend->SetFillColor(kWhite);
109 double newHistMax(0.0), oldHistMax(0.0);
110 int newHistMaxInt(0), oldHistMaxInt(0);
112 double totalNewFreq(0.0), totalOldFreq(0.0);
115 int nHistVect = newHistVect.size();
116 for (iHist = 0; iHist < nHistVect; iHist++) {
118 TH1D* newHist = newHistVect[iHist];
119 string labelName = histLabels[iHist];
120 theLegend->AddEntry(newHist, labelName.c_str(),
"lpf");
122 int colour = colours[iHist];
123 newHist->SetLineColor(colour);
125 double theNewHistMax = newHist->GetMaximum();
126 if (theNewHistMax > newHistMax) {
127 newHistMax = theNewHistMax;
128 newHistMaxInt = iHist;
131 totalNewFreq += newHist->Integral();
133 TH1D* oldHist = oldHistVect[iHist];
134 oldHist->SetLineStyle(kDashed);
135 oldHist->SetLineColor(colour);
137 double theOldHistMax = oldHist->GetMaximum();
138 if (theOldHistMax > oldHistMax) {
139 oldHistMax = theOldHistMax;
140 oldHistMaxInt = iHist;
143 totalOldFreq += oldHist->Integral();
147 double newScale = 1.0/totalNewFreq;
148 double oldScale = 1.0/totalOldFreq;
150 if (newHistMax > oldHistMax) {
152 TH1D* newFirstHist = newHistVect[newHistMaxInt];
154 TAxis* xAxis = newFirstHist->GetXaxis();
155 double dx = xAxis->GetBinWidth(1)*1000.0;
157 sprintf(dxChar,
"Normalised frequency/%.0f (MeV/c)", dx);
159 newFirstHist->SetXTitle(
"p (GeV/c)");
160 newFirstHist->SetYTitle(dxChar);
161 newFirstHist->SetTitleOffset(1.25,
"Y");
162 newFirstHist->Scale(newScale);
163 newFirstHist->Draw();
165 for (iHist = 0; iHist < nHistVect; iHist++) {
167 if (iHist != newHistMaxInt) {
168 TH1D* otherNewHist = newHistVect[iHist];
169 otherNewHist->Scale(newScale);
170 otherNewHist->Draw(
"same");
174 TH1D *otherOldHist = oldHistVect[iHist];
175 otherOldHist->Scale(oldScale);
176 otherOldHist->Draw(
"same");
182 TH1D* oldFirstHist = oldHistVect[oldHistMaxInt];
184 TAxis* xAxis = oldFirstHist->GetXaxis();
185 double dx = xAxis->GetBinWidth(1)*1000.0;
187 sprintf(dxChar,
"Normalised frequency/%.0f (MeV/c)", dx);
189 oldFirstHist->SetXTitle(
"p (GeV/c)");
190 oldFirstHist->SetYTitle(dxChar);
191 oldFirstHist->SetTitleOffset(1.25,
"Y");
192 oldFirstHist->Scale(oldScale);
193 oldFirstHist->Draw();
195 for (iHist = 0; iHist < nHistVect; iHist++) {
197 if (iHist != oldHistMaxInt) {
198 TH1D* otherOldHist = oldHistVect[iHist];
199 otherOldHist->Scale(oldScale);
200 otherOldHist->Draw(
"same");
203 TH1D* otherNewHist = newHistVect[iHist];
204 otherNewHist->Scale(newScale);
205 otherNewHist->Draw(
"same");
213 TText* text =
new TText();
214 text->SetTextSize(0.03);
215 text->DrawTextNDC(0.1, 0.95,
"New version = solid lines");
216 text->DrawTextNDC(0.1, 0.915,
"Old version = dotted lines");
217 TLatex* latexString =
new TLatex();
218 latexString->SetTextSize(0.03);
219 latexString->SetNDC();
220 latexString->DrawLatex(0.5, 0.92, _description.c_str());
222 string gifFileName(
"gifFiles/");
223 gifFileName.append(_decayName); gifFileName.append(
"_mtmHist.gif");
224 _theCanvas->Print(gifFileName.c_str());
230 void compareRootFiles::getPartIdPlots() {
232 TH1D* newPartIdHist = getPartIdHist(_newFile,
"newPartIdHist");
233 TH1D* oldPartIdHist = getPartIdHist(_oldFile,
"oldPartIdHist");
236 _theCanvas->UseCurrentStyle();
240 double newPartIdMax = newPartIdHist->GetMaximum();
241 double oldPartIdMax = oldPartIdHist->GetMaximum();
243 oldPartIdHist->SetLineStyle(kDashed);
245 if (newPartIdMax > oldPartIdMax) {
247 newPartIdHist->SetXTitle(
"");
248 newPartIdHist->SetYTitle(
"Normalised frequency");
249 newPartIdHist->SetTitleOffset(1.25,
"Y");
251 newPartIdHist->Draw();
252 oldPartIdHist->Draw(
"same");
256 oldPartIdHist->SetXTitle(
"");
257 oldPartIdHist->SetYTitle(
"Normalised frequency");
258 oldPartIdHist->SetTitleOffset(1.25,
"Y");
260 oldPartIdHist->Draw();
261 newPartIdHist->Draw(
"same");
265 TLatex* latex =
new TLatex();
266 latex->SetTextAngle(90.0);
268 latex->SetTextSize(0.035);
269 latex->DrawLatex(0.5, 0,
"Leptons");
271 latex->SetTextSize(0.045);
272 latex->DrawLatex(1.5, 0,
"#gamma");
273 latex->DrawLatex(2.5, 0,
"#pi^{#pm}");
274 latex->DrawLatex(3.5, 0,
"#pi^{0}");
275 latex->DrawLatex(4.5, 0,
"K^{#pm}");
276 latex->DrawLatex(5.5, 0,
"K^{0}");
277 latex->DrawLatex(6.5, 0,
"D^{#pm}");
278 latex->DrawLatex(7.5, 0,
"D^{0}");
280 latex->SetTextSize(0.035);
281 latex->DrawLatex(8.4, 0,
"Light"); latex->DrawLatex(8.75, 0,
"baryons");
282 latex->DrawLatex(9.4, 0,
"Strange"); latex->DrawLatex(9.75, 0,
"baryons");
284 latex->DrawLatex(10.5, 0,
"Other");
286 TText* text =
new TText();
287 text->SetTextSize(0.03);
288 text->DrawTextNDC(0.1, 0.95,
"New version = solid lines");
289 text->DrawTextNDC(0.1, 0.915,
"Old version = dotted lines");
290 TLatex* latexString =
new TLatex();
291 latexString->SetTextSize(0.03);
292 latexString->SetNDC();
293 latexString->DrawLatex(0.5, 0.92, _description.c_str());
295 string gifFileName(
"gifFiles/");
296 gifFileName.append(_decayName); gifFileName.append(
"_partIdHist.gif");
297 _theCanvas->Print(gifFileName.c_str());
303 void compareRootFiles::getAllIdPlots() {
305 TH1D* newAllIdHist = getAllIdHist(_newFile,
"newAllIdHist");
306 TH1D* oldAllIdHist = getAllIdHist(_oldFile,
"oldAllIdHist");
309 _theCanvas->UseCurrentStyle();
313 double newAllIdMax = newAllIdHist->GetMaximum();
314 double oldAllIdMax = oldAllIdHist->GetMaximum();
316 oldAllIdHist->SetLineStyle(kDashed);
318 if (newAllIdMax > oldAllIdMax) {
320 newAllIdHist->SetXTitle(
"PDG Id");
321 newAllIdHist->SetYTitle(
"Normalised frequency");
322 newAllIdHist->SetTitleOffset(1.25,
"Y");
324 newAllIdHist->Draw();
325 oldAllIdHist->Draw(
"same");
329 oldAllIdHist->SetXTitle(
"PDG Id");
330 oldAllIdHist->SetYTitle(
"Normalised frequency");
331 oldAllIdHist->SetTitleOffset(1.25,
"Y");
333 oldAllIdHist->Draw();
334 newAllIdHist->Draw(
"same");
338 TText* text =
new TText();
339 text->SetTextSize(0.03);
340 text->DrawTextNDC(0.1, 0.95,
"New version = solid lines");
341 text->DrawTextNDC(0.1, 0.915,
"Old version = dotted lines");
342 TLatex* latexString =
new TLatex();
343 latexString->SetTextSize(0.03);
344 latexString->SetNDC();
345 latexString->DrawLatex(0.5, 0.92, _description.c_str());
347 string gifFileName(
"gifFiles/");
348 gifFileName.append(_decayName); gifFileName.append(
"_allIdHist.gif");
349 _theCanvas->Print(gifFileName.c_str());
355 void compareRootFiles::getNDaugPlots() {
357 TH1D* newDaugHist = getDaugHist(_newFile,
"newDaugHist");
358 TH1D* oldDaugHist = getDaugHist(_oldFile,
"oldDaugHist");
361 _theCanvas->UseCurrentStyle();
364 double newDaugMax = newDaugHist->GetMaximum();
365 double oldDaugMax = oldDaugHist->GetMaximum();
367 oldDaugHist->SetLineStyle(kDashed);
369 if (newDaugMax > oldDaugMax) {
371 newDaugHist->SetXTitle(
"nDaughters");
372 newDaugHist->SetYTitle(
"Normalised frequency");
373 newDaugHist->SetTitleOffset(1.25,
"Y");
376 oldDaugHist->Draw(
"same");
380 oldDaugHist->SetXTitle(
"nDaughters");
381 oldDaugHist->SetYTitle(
"Normalised frequency");
382 oldDaugHist->SetTitleOffset(1.25,
"Y");
385 newDaugHist->Draw(
"same");
389 TText* text =
new TText();
390 text->SetTextSize(0.03);
391 text->DrawTextNDC(0.1, 0.95,
"New version = solid lines");
392 text->DrawTextNDC(0.1, 0.915,
"Old version = dotted lines");
393 TLatex* latexString =
new TLatex();
394 latexString->SetTextSize(0.03);
395 latexString->SetNDC();
396 latexString->DrawLatex(0.5, 0.92, _description.c_str());
398 string gifFileName(
"gifFiles/");
399 gifFileName.append(_decayName); gifFileName.append(
"_daugHist.gif");
400 _theCanvas->Print(gifFileName.c_str());
404 TH1D* compareRootFiles::getMtmHist(TFile* theFile,
string histName, vector<int> groupInts) {
411 TTree* theTree =
dynamic_cast<TTree*
>(theFile->Get(
"Data"));
419 theTree->SetBranchAddress(
"id", &
id);
420 theTree->SetBranchAddress(
"p", &p);
422 double pMax = theTree->GetMaximum(
"p");
423 TH1D* mtmHist =
new TH1D(histName.c_str(),
"", 100, 0.0, pMax*1.1);
426 int nEntries = theTree->GetEntries();
427 for (i = 0; i < nEntries; i++) {
429 theTree->GetEntry(i);
430 int testInt = this->getPartGroup(
id);
433 vector<int>::iterator iter;
434 for (iter = groupInts.begin(); iter != groupInts.end(); ++iter) {
435 int groupInt = *iter;
437 if (groupInt == testInt) {
450 TH1D* compareRootFiles::getPartIdHist(TFile* theFile,
string histName) {
461 TTree* theTree =
dynamic_cast<TTree*
>(theFile->Get(
"Data"));
468 theTree->SetBranchAddress(
"id", &
id);
470 int nGroupMax = _nGroupMax;
471 vector<double> partNumbers(nGroupMax);
473 for (iP = 0; iP < nGroupMax; iP++) {
474 partNumbers[iP] = 0.0;
478 int nEntries = theTree->GetEntries();
479 for (i = 0; i < nEntries; i++) {
481 theTree->GetEntry(i);
483 int groupInt = this->getPartGroup(
id);
484 if (groupInt >= 0 && groupInt < nGroupMax) {
485 partNumbers[groupInt] += 1.0;
490 TH1D* idHist =
new TH1D(histName.c_str(),
"", nGroupMax, 0, nGroupMax);
491 idHist->SetMinimum(1);
493 for (iP = 0; iP < nGroupMax; iP++) {
495 double total = partNumbers[iP];
496 idHist->Fill(iP, total);
500 idHist->Scale(1.0/(nEntries*1.0));
501 idHist->SetMaximum(1.0);
507 int compareRootFiles::getPartGroup(
int PDGId) {
511 int absPDGId = std::abs(PDGId);
513 if (absPDGId >= 11 && absPDGId <= 16) {
515 }
else if (absPDGId == 22) {
517 }
else if (absPDGId == 211) {
519 }
else if (absPDGId == 111) {
521 }
else if (absPDGId == 321) {
523 }
else if (absPDGId == 311 || absPDGId == 130 || absPDGId == 310) {
525 }
else if (absPDGId == 411) {
527 }
else if (absPDGId == 421) {
529 }
else if (absPDGId == 2212 || absPDGId == 2112 || absPDGId == 2224 ||
530 absPDGId == 2214 || absPDGId == 2114 || absPDGId == 1114) {
532 }
else if (absPDGId >= 3112 && absPDGId <= 3334) {
534 }
else if (absPDGId != 0) {
542 TH1D* compareRootFiles::getAllIdHist(TFile* theFile,
string histName) {
549 TTree* theTree =
dynamic_cast<TTree*
>(theFile->Get(
"Data"));
556 theTree->SetBranchAddress(
"id", &
id);
560 TH1D* idHist =
new TH1D(histName.c_str(),
"", 100, -idMax, idMax);
562 int nEntries = theTree->GetEntries();
563 cout<<
"Number of entries = "<<nEntries<<endl;
565 for (i = 0; i < nEntries; i++) {
567 theTree->GetEntry(i);
572 double nIdScale = idHist->Integral();
573 idHist->Scale(1.0/nIdScale);
574 idHist->SetMaximum(1.0);
580 TH1D* compareRootFiles::getDaugHist(TFile* theFile,
string histName) {
587 TTree* nDaugTree =
dynamic_cast<TTree*
>(theFile->Get(
"nDaugTree"));
588 if (nDaugTree == 0) {
594 nDaugTree->SetBranchAddress(
"nDaug", &nDaug);
596 int nDaugMax = (int) nDaugTree->GetMaximum(
"nDaug");
597 int nDaugLimit = nDaugMax + 2;
599 TH1D* nDaugHist =
new TH1D(histName.c_str(),
"", nDaugLimit, 0, nDaugLimit);
601 int nEntries = nDaugTree->GetEntries();
602 cout<<
"Number of entries = "<<nEntries<<endl;
604 for (i = 0; i < nEntries; i++) {
606 nDaugTree->GetEntry(i);
609 nDaugHist->Fill(nDaug);
614 double nDaugScale = nDaugHist->Integral();
615 nDaugHist->Scale(1.0/nDaugScale);
617 cout<<
"nDaugScale = "<<nDaugScale<<endl;
623 int main(
int argc,
char** argv) {
625 string decayName(
"UpsilonDecay1");
626 if (argc > 1) {decayName = argv[1];}
628 string newRootFile(
"rootFiles/newUpsilonDecay1.root");
629 if (argc > 2) {newRootFile = argv[2];}
631 string oldRootFile(
"rootFiles/oldUpsilonDecay1.root");
632 if (argc > 3) {oldRootFile = argv[3];}
634 string description(
"Example description");
635 if (argc > 4) {description = argv[4];}
637 compareRootFiles myCompareRootFiles(decayName, newRootFile, oldRootFile, description);
639 myCompareRootFiles.getNDaugPlots();
640 myCompareRootFiles.getAllIdPlots();
641 myCompareRootFiles.getPartIdPlots();
642 myCompareRootFiles.getMtmPlots();