File indexing completed on 2024-04-06 12:33:12
0001 #include <vector>
0002 #include <algorithm>
0003 #include "TMath.h"
0004 #include "macro/PlotHelpers.C"
0005
0006
0007
0008
0009 TList* GetListOfBranches(const char* dataType, TFile* file) {
0010 if (TString(dataType) == "HLT") {
0011 if (file->cd("DQMData/Run 1/HLT"))
0012 file->cd("DQMData/Run 1/HLT/Run summary/Muon/MultiTrack");
0013 else
0014 file->cd("DQMData/HLT/Muon/MultiTrack");
0015 } else if (TString(dataType) == "RECO") {
0016 if (file->cd("DQMData/Run 1/RecoMuonV"))
0017 file->cd("DQMData/Run 1/RecoMuonV/Run summary/MultiTrack");
0018 else if (file->cd("DQMData/Run 1/Muons/Run summary/RecoMuonV"))
0019 file->cd("DQMData/Run 1/Muons/Run summary/RecoMuonV/MultiTrack");
0020 else
0021 file->cd("DQMData/RecoMuonV/MultiTrack");
0022 } else {
0023 cout << "ERROR: Data type " << dataType << " not allowed: only RECO and HLT are considered" << endl;
0024 return 0;
0025 }
0026
0027 TDirectory* dir = gDirectory;
0028 TList* sl = GetListOfDirectories(dir);
0029
0030 if (sl->GetSize() == 0) {
0031 cout << "ERROR: No DQM muon reco histos found in NEW file " << endl;
0032 delete sl;
0033 return 0;
0034 }
0035
0036 return sl;
0037 }
0038
0039 void TrackValHistoPublisher(const char* newFile = "NEW_FILE", const char* refFile = "REF_FILE") {
0040 cout << ">> Starting TrackValHistoPublisher(" << newFile << "," << refFile << ")..." << endl;
0041
0042
0043
0044 const char* dataType = "DATATYPE";
0045 const char* refLabel("REF_LABEL, REF_RELEASE REFSELECTION");
0046 const char* newLabel("NEW_LABEL, NEW_RELEASE NEWSELECTION");
0047
0048
0049
0050
0051 gROOT->SetBatch();
0052 gErrorIgnoreLevel = kWarning;
0053
0054 SetGlobalStyle();
0055
0056 Float_t maxPT;
0057 TString File = newFile;
0058 if (File.Contains("SingleMuPt1000") || File.Contains("WpM") || File.Contains("ZpMM"))
0059 maxPT = 1400.;
0060 else if (File.Contains("SingleMuPt100")) {
0061 maxPT = 400.;
0062 } else if (File.Contains("SingleMuPt10")) {
0063 maxPT = 70.;
0064 } else
0065 maxPT = 400.;
0066
0067 bool ctf = 1;
0068
0069 bool resol = false;
0070
0071
0072 delete gROOT->GetListOfFiles()->FindObject(refFile);
0073 delete gROOT->GetListOfFiles()->FindObject(newFile);
0074
0075
0076 cout << ">> Openning file, moving to the right branch and getting sub-branches..." << endl;
0077
0078 cout << ">> Finding sources..." << endl;
0079 TFile* sfile = new TFile(newFile);
0080 TList* sl = GetListOfBranches(dataType, sfile);
0081 if (!sl) {
0082 cout << "ERROR: Could not find keys!!!" << endl;
0083 cerr << "ERROR: Could not find keys!!!" << endl;
0084 return;
0085 }
0086 TDirectory* sdir = gDirectory;
0087 for (unsigned int i = 0; i < sl->GetEntries(); i++)
0088 cout << " + " << sl->At(i)->GetName() << endl;
0089
0090 cout << ">> Finding references..." << endl;
0091 TFile* rfile = new TFile(refFile);
0092 TList* rl = GetListOfBranches(dataType, rfile);
0093 if (!rl) {
0094 cout << "ERROR: Could not find keys!!!" << endl;
0095 cerr << "ERROR: Could not find keys!!!" << endl;
0096 return;
0097 }
0098 TDirectory* rdir = gDirectory;
0099 for (unsigned int i = 0; i < sl->GetEntries(); i++)
0100 cout << " + " << sl->At(i)->GetName() << endl;
0101
0102
0103 cout << ">> Find if the collection has muon associator or track associator..." << endl;
0104 bool hasOnlyMuonAssociatorInRef = true;
0105 bool hasOnlyMuonAssociatorInSig = true;
0106 bool hasOnlyTrackAssociatorInRef = true;
0107 bool hasOnlyTrackAssociatorInSig = true;
0108 TIter iter_r0(rl);
0109 TIter iter_s0(sl);
0110 TKey* rKey = 0;
0111 TKey* sKey = 0;
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133 bool considerOnlyMuonAssociator = hasOnlyMuonAssociatorInRef || hasOnlyMuonAssociatorInSig;
0134
0135 cout << " + Has Only Muon Associator (reference): " << hasOnlyMuonAssociatorInRef << endl;
0136 cout << " + Has Only Muon Associator (signal): " << hasOnlyMuonAssociatorInSig << endl;
0137 cout << " + Has Only Track Associator (reference): " << hasOnlyTrackAssociatorInRef << endl;
0138 cout << " + Has Only Track Associator (signal): " << hasOnlyTrackAssociatorInSig << endl;
0139 cout << " + Consider only Muon Associator: " << considerOnlyMuonAssociator << endl;
0140
0141
0142 cout << ">> Iterating over histograms and collections..." << endl;
0143
0144 TIter iter_r(rl);
0145 TIter iter_s(sl);
0146 TString scollname;
0147 TString rcollname;
0148
0149 TKey* myNext2 = 0;
0150 while ((rKey = (TKey*)iter_r())) {
0151 TString myName = rKey->GetName();
0152 #ifdef DEBUG
0153 cout << "DEBUG: Checking key " << myName << endl;
0154 #endif
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169 rcollname = myName;
0170
0171 if (myNext2) {
0172 sKey = myNext2;
0173 myNext2 = 0;
0174 } else {
0175 sKey = (TKey*)iter_s();
0176 }
0177 if (!sKey)
0178 continue;
0179 TString myName2 = sKey->GetName();
0180
0181
0182 if (myName2 != myName) {
0183 myNext2 = (TKey*)iter_s();
0184 TKey* myTemp = sKey;
0185 sKey = myNext2;
0186 myName2 = sKey->GetName();
0187 myNext2 = myTemp;
0188 if (myName2 != myName) {
0189 myNext2 = (TKey*)iter_s();
0190 TKey* myTemp = sKey;
0191 sKey = myNext2;
0192 myName2 = sKey->GetName();
0193 myNext2 = myTemp;
0194 }
0195 }
0196
0197 scollname = myName2;
0198 #ifdef DEBUG
0199 cout << "DEBUG: Comparing " << rcollname << " and " << scollname << endl;
0200 #endif
0201 if ((myName == myName2) || (myName + "FS" == myName2) || (myName == myName2 + "FS") ||
0202 (myName.Contains("extractedGlobalMuons") && myName2.Contains("globalMuons")) ||
0203 (myName.Contains("globalMuons") && myName2.Contains("extractedGlobalMuons"))) {
0204 rcollname = rKey->GetName();
0205 scollname = sKey->GetName();
0206 } else if ((rcollname != scollname) && (rcollname + "FS" != scollname) && (rcollname != scollname + "FS")) {
0207 bool goodAsWell = false;
0208 if (rcollname.BeginsWith("StandAloneMuons_UpdAtVtx") && scollname.BeginsWith("StandAloneMuons_UpdAtVtx")) {
0209 if (rcollname.Contains("MuonAssociation") == scollname.Contains("MuonAssociation")) {
0210 }
0211 goodAsWell = true;
0212 }
0213 if (rcollname.BeginsWith("hltL2Muons_UpdAtVtx") && scollname.BeginsWith("hltL2Muons_UpdAtVtx")) {
0214 if (rcollname.Contains("MuonAssociation") == scollname.Contains("MuonAssociation")) {
0215 }
0216 goodAsWell = true;
0217 }
0218 if (rcollname.BeginsWith("hltL3Tk") && scollname.BeginsWith("hltL3Tk")) {
0219 if (rcollname.Contains("MuonAssociation") == scollname.Contains("MuonAssociation")) {
0220 }
0221 goodAsWell = true;
0222 }
0223
0224
0225 if (!goodAsWell) {
0226 if (rcollname.Contains("SET") && !scollname.Contains("SET")) {
0227 while (rcollname.Contains("SET")) {
0228 if ((rKey = (TKey*)iter_r()))
0229 rcollname = rKey->GetName();
0230 }
0231 } else if (scollname.Contains("SET") && !rcollname.Contains("SET")) {
0232 while (scollname.Contains("SET")) {
0233 if ((sKey = (TKey*)iter_s()))
0234 scollname = sKey->GetName();
0235 }
0236 }
0237
0238 if (rcollname.Contains("dyt") && !scollname.Contains("dyt")) {
0239 while (rcollname.Contains("dyt")) {
0240 if ((rKey = (TKey*)iter_r()))
0241 rcollname = rKey->GetName();
0242 }
0243 } else if (scollname.Contains("dyt") && !rcollname.Contains("dyt")) {
0244 while (scollname.Contains("dyt")) {
0245 if ((sKey = (TKey*)iter_s()))
0246 scollname = sKey->GetName();
0247 }
0248 }
0249
0250 if (rcollname.Contains("refitted") && !scollname.Contains("refitted")) {
0251 while (rcollname.Contains("refitted")) {
0252 if ((rKey = (TKey*)iter_r()))
0253 rcollname = rKey->GetName();
0254 }
0255 } else if (scollname.Contains("refitted") && !rcollname.Contains("refitted")) {
0256 while (scollname.Contains("refitted")) {
0257 if ((sKey = (TKey*)iter_s()))
0258 scollname = sKey->GetName();
0259 }
0260 }
0261
0262 if ((rcollname != scollname) && (rcollname + "FS" != scollname) && (rcollname != scollname + "FS")) {
0263 cout << " Different collection names, please check: " << rcollname << " : " << scollname << endl;
0264 continue;
0265 } else {
0266
0267 myName = rKey->GetName();
0268 }
0269 }
0270 }
0271
0272
0273
0274
0275 TString newDir("NEW_RELEASE/NEWSELECTION/NEW_LABEL/");
0276 newDir += myName;
0277 gSystem->mkdir(newDir, kTRUE);
0278
0279 bool logyfalse[] = {false, false, false, false, false, false};
0280 bool doKolmo[] = {true, true, true, true, true, true};
0281 Double_t norm[] = {-999., -999., -999., -999., -999., -999.};
0282 Double_t minx[] = {-1E100, -1E100, 5., 5., -1E100, -1E100};
0283 Double_t maxx[] = {-1E100, -1E100, maxPT, maxPT, -1E100, -1E100};
0284 Double_t miny[] = {0.5, -1E100, 0, -1E100, 0.5, -1E100};
0285 Double_t maxy[] = {1.0125, -1E100, 1.025, -1E100, 1.0125, -1E100};
0286
0287
0288
0289
0290
0291 if (ctf) {
0292
0293
0294 const char* plots0[] = {"effic", "fakerate", "efficPt", "fakeratePt"};
0295 const char* plotsl0[] = {"efficiency vs #eta", "fakerate vs #eta", "efficiency vs Pt", "fakerate vs Pt"};
0296 bool logy0[] = {false, false, false, false};
0297 Plot4Histograms(newDir + "/building",
0298 rdir,
0299 sdir,
0300 rcollname,
0301 scollname,
0302 "Seeds",
0303 "Efficiency Vs Pt and Vs #eta",
0304 refLabel,
0305 newLabel,
0306 plots0,
0307 plotsl0,
0308 logy0,
0309 doKolmo,
0310 norm,
0311 0,
0312 minx,
0313 maxx,
0314 miny,
0315 maxy);
0316 cout << "HICE EL HISTO " << endl;
0317
0318 const char* plots1[] = {"effic_vs_hit", "fakerate_vs_hit", "effic_vs_phi", "fakerate_vs_phi"};
0319 const char* plotsl1[] = {"efficiency vs hits", "fakerate vs hits", "efficiency vs #phi", "fakerate vs #phi"};
0320 bool logy[] = {false, false, false, false};
0321 Plot4Histograms(newDir + "/building2",
0322 rdir,
0323 sdir,
0324 rcollname,
0325 scollname,
0326 "Seeds2",
0327 "Efficiency vs hits and #phi",
0328 refLabel,
0329 newLabel,
0330 plots1,
0331 plotsl1,
0332 logy,
0333 doKolmo,
0334 norm,
0335 0,
0336 minx,
0337 maxx,
0338 miny,
0339 maxy);
0340 cout << "HICE EL HISTO " << endl;
0341
0342
0343 const char* plots2[] = {"hits_eta", "hits", "num_simul_pT", "num_reco_pT"};
0344 const char* plotsl2[] = {
0345 "nhits vs eta", "number of hits per track", "Number of Pt Simulated", "Pt of Reco tracks"};
0346 Double_t norm2[] = {0., 0., 0., 0., 0., 0.};
0347
0348
0349
0350
0351 Plot4Histograms(newDir + "/hitsAndPt",
0352 rdir,
0353 sdir,
0354 rcollname,
0355 scollname,
0356 "hits",
0357 "Pt",
0358 refLabel,
0359 newLabel,
0360 plots2,
0361 plotsl2,
0362 logyfalse,
0363 doKolmo,
0364 norm2,
0365 0,
0366 minx,
0367 maxx);
0368
0369
0370 bool logy3[] = {false, true, false, true};
0371 bool doKolmo3[] = {true, true, true, true};
0372 const char* plots3[] = {"chi2", "chi2_prob", "chi2mean", "ptres_vs_eta_Mean"};
0373 Plot4Histograms(newDir + "/tuning",
0374 rdir,
0375 sdir,
0376 rcollname,
0377 scollname,
0378 "IsoHistos2",
0379 "HCAL, HO Deposits",
0380 refLabel,
0381 newLabel,
0382 plots3,
0383 0,
0384 logy3,
0385 doKolmo3,
0386 norm2,
0387 0);
0388
0389
0390 const char* plots4[] = {"pullPt", "pullQoverp", "pullPhi", "pullTheta", "pullDxy", "pullDz"};
0391 const char* plotsl4[] = {"Pt Pull", "Q/P Pull", "#Phi Pull", "#theta Pull", "Dxy Pull", "Dz Pull"};
0392
0393
0394
0395
0396 Plot6Histograms(newDir + "/Pulls",
0397 rdir,
0398 sdir,
0399 rcollname,
0400 scollname,
0401 "Pullsdis",
0402 "Pull Distributions",
0403 refLabel,
0404 newLabel,
0405 plots4,
0406 plotsl4,
0407 logyfalse,
0408 doKolmo,
0409 norm2,
0410 0);
0411
0412
0413 const char* plots5[] = {
0414 "ptres_vs_eta", "etares_vs_eta", "phires_vs_eta", "cotThetares_vs_eta", "dxyres_vs_eta", "dzres_vs_eta"};
0415 const char* plotsl5[] = {"p_{t} resolution",
0416 "#eta resolution",
0417 "#Phi resolution",
0418 "cot(#theta) resolution",
0419 "Dxy resolution",
0420 "Dz resolution"};
0421
0422
0423
0424
0425
0426 resol = true;
0427 Plot6Histograms(newDir + "/residuals",
0428 rdir,
0429 sdir,
0430 rcollname,
0431 scollname,
0432 "residualdis",
0433 "residuals vs Pt",
0434 refLabel,
0435 newLabel,
0436 plots5,
0437 plotsl5,
0438 logyfalse,
0439 doKolmo,
0440 norm2,
0441 &resol);
0442
0443
0444 const char* plots6[] = {"phires_vs_eta_Sigma",
0445 "cotThetares_vs_eta_Sigma",
0446 "dxyres_vs_eta_Sigma",
0447 "dzres_vs_eta_Sigma",
0448 "ptres_vs_eta_Sigma"};
0449 const char* plotsl6[] = {"#sigma(#delta #phi) [rad]",
0450 "#sigma(#delta cot(#theta))",
0451 "#sigma(#delta d_{0}) [cm]",
0452 "#sigma(#delta z_{0}) [cm]",
0453 "#sigma(#delta p_{t}/p_{t})"};
0454
0455
0456
0457
0458 Plot5Histograms(newDir + "/residualsEta",
0459 rdir,
0460 sdir,
0461 rcollname,
0462 scollname,
0463 "residualsdisEta",
0464 "residuals vs Eta",
0465 refLabel,
0466 newLabel,
0467 plots6,
0468 plotsl6,
0469 logyfalse,
0470 doKolmo,
0471 norm,
0472 0);
0473
0474
0475
0476 const char* plots7[] = {"phires_vs_eta_Mean",
0477 "cotThetares_vs_eta_Mean",
0478 "dxyres_vs_eta_Mean",
0479 "dzres_vs_eta_Mean",
0480 "ptres_vs_eta_Mean"};
0481 const char* plotsl7[] = {
0482 "#delta #phi [rad]", "#delta cot(#theta)", "#delta d_{0} [cm]", "#delta z_{0} [cm]", "#delta p_{t}/p_{t}"};
0483
0484
0485
0486
0487 Plot5Histograms(newDir + "/meanvaluesEta",
0488 rdir,
0489 sdir,
0490 rcollname,
0491 scollname,
0492 "meanvaluesEtadis",
0493 "mean values vs eta",
0494 refLabel,
0495 newLabel,
0496 plots7,
0497 plotsl7,
0498 logyfalse,
0499 doKolmo,
0500 norm,
0501 0);
0502
0503
0504
0505
0506 const char* plots8[] = {"phires_vs_pt_Sigma",
0507 "cotThetares_vs_pt_Sigma",
0508 "dxyres_vs_pt_Sigma",
0509 "dzres_vs_pt_Sigma",
0510 "ptres_vs_pt_Sigma",
0511 "ptres_vs_pt_Sigma"};
0512 const char* plotsl8[] = {"#sigma(#delta #phi) [rad]",
0513 "#sigma(#delta cot(#theta))",
0514 "#sigma(#delta d_{0}) [cm]",
0515 "#sigma(#delta z_{0}) [cm]",
0516 "#sigma(#delta p_{t}/p_{t})"};
0517 Double_t minx8[] = {5., 5., 5., 5., 5., 5.};
0518 Double_t maxx8[] = {maxPT, maxPT, maxPT, maxPT, maxPT, maxPT};
0519
0520
0521 Plot5Histograms(newDir + "/resolutionsPt",
0522 rdir,
0523 sdir,
0524 rcollname,
0525 scollname,
0526 "resolutionsPtdis",
0527 "resolution vs pt",
0528 refLabel,
0529 newLabel,
0530 plots8,
0531 plotsl8,
0532 logyfalse,
0533 doKolmo,
0534 norm,
0535 0,
0536 minx8,
0537 maxx8);
0538
0539 }
0540
0541
0542 TString mergefile = "merged_tracks.pdf";
0543 TString destfile = newDir + "/../" + myName + ".pdf";
0544 TString gscommand = "gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=" + mergefile + " " + newDir +
0545 "/building.pdf " + newDir + "/building2.pdf " + newDir + "/hitsAndPt.pdf " + newDir +
0546 "/tuning.pdf " + newDir + "/Pulls.pdf " + newDir + "/residuals.pdf " + newDir +
0547 "/residualsEta.pdf " + newDir + "/meanvaluesEta.pdf " + newDir + "/resolutionsPt.pdf ";
0548
0549 cout << ">> Merging partial pdfs to " << mergefile << "..." << endl;
0550 #ifdef DEBUG
0551 cout << "DEBUG: ...with command \"" << gscommand << "\"" << endl;
0552 #endif
0553 gSystem->Exec(gscommand);
0554 cout << ">> Moving " << mergefile << " to " << destfile << "..." << endl;
0555 gSystem->Rename(mergefile, destfile);
0556
0557 cout << ">> Deleting partial pdf files" << endl;
0558 gSystem->Exec("rm -rf " + newDir + "/*.pdf");
0559 cout << " ... Done" << endl;
0560 }
0561
0562 cout << ">> Removing the relval files from ROOT before closing..." << endl;
0563 gROOT->GetListOfFiles()->Remove(sfile);
0564 gROOT->GetListOfFiles()->Remove(rfile);
0565
0566 #ifdef DEBUG
0567 cout << "DEBUG: Exiting!" << endl;
0568 cerr << "DEBUG: Exiting!" << endl;
0569 #endif
0570 }