Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:33:11

0001 #include <vector>
0002 #include <algorithm>
0003 #include "TMath.h"
0004 #include "macro/PlotHelpers.C"
0005 
0006 // Uncomment the following line for some extra debug information

0007 // #define DEBUG

0008 
0009 void IsoValHistoPublisher(const char* newFile = "NEW_FILE", const char* refFile = "REF_FILE") {
0010   cout << ">> Starting IsoValHistoPublisher(" << newFile << "," << refFile << ")..." << endl;
0011 
0012   //====  To be replaced from python3 ====================

0013 
0014   const char* dataType = "DATATYPE";
0015   const char* refLabel("REF_LABEL, REF_RELEASE REFSELECTION");
0016   const char* newLabel("NEW_LABEL, NEW_RELEASE NEWSELECTION");
0017 
0018   // ==== Initial settings and loads

0019   //gROOT->ProcessLine(".x HistoCompare_Tracks.C");

0020   //gROOT ->Reset();

0021   gROOT->SetBatch();
0022   gErrorIgnoreLevel = kWarning;  // Get rid of the info messages

0023 
0024   SetGlobalStyle();
0025 
0026   // ==== Some cleaning... is this needed?

0027   delete gROOT->GetListOfFiles()->FindObject(refFile);
0028   delete gROOT->GetListOfFiles()->FindObject(newFile);
0029 
0030   // ==== Opening files, moving to the right branch and getting the list of sub-branches

0031   cout << ">> Openning file, moving to the right branch and getting sub-branches..." << endl;
0032 
0033   cout << ">> Finding sources..." << endl;
0034   TFile* sfile = new TFile(newFile);
0035   TList* sl = getListOfBranches(dataType, sfile, "MuonIsolationV_inc");
0036   if (!sl) {
0037     cout << "ERROR: Could not find keys!!!" << endl;
0038     cerr << "ERROR: Could not find keys!!!" << endl;
0039     return;
0040   }
0041   TDirectory* sdir = gDirectory;
0042   for (unsigned int i = 0; i < sl->GetEntries(); i++)
0043     cout << "   + " << sl->At(i)->GetName() << endl;
0044 
0045   cout << ">> Finding references..." << endl;
0046   TFile* rfile = new TFile(refFile);
0047   TList* rl = getListOfBranches(dataType, rfile, "MuonIsolationV_inc");
0048   if (!rl) {
0049     cout << "ERROR: Could not find keys!!!" << endl;
0050     cerr << "ERROR: Could not find keys!!!" << endl;
0051     return;
0052   }
0053   TDirectory* rdir = gDirectory;
0054   for (unsigned int i = 0; i < sl->GetEntries(); i++)
0055     cout << "   + " << sl->At(i)->GetName() << endl;
0056 
0057   //==== Iterate now over histograms and collections

0058   cout << ">> Iterating over histograms and collections..." << endl;
0059 
0060   TIter iter_r(rl);
0061   TIter iter_s(sl);
0062   TKey* rKey = 0;
0063   TKey* sKey = 0;
0064   TString rcollname;
0065   TString scollname;
0066 
0067   while ((rKey = (TKey*)iter_r())) {
0068     TString myName = rKey->GetName();
0069 #ifdef DEBUG
0070     cout << "DEBUG: Checking key " << myName << endl;
0071 #endif
0072     rcollname = myName;
0073     sKey = (TKey*)iter_s();
0074     if (!sKey)
0075       continue;
0076     scollname = sKey->GetName();
0077     if ((rcollname != scollname) && (rcollname + "FS" != scollname) && (rcollname != scollname + "FS")) {
0078       cerr << "ERROR: Different collection names, please check: " << rcollname << " : " << scollname << endl;
0079       cout << "ERROR: Different collection names, please check: " << rcollname << " : " << scollname << endl;
0080       continue;
0081     }
0082 
0083     // ==== Now let's go for the plotting...

0084     cout << ">> Comparing plots in " << myName << "..." << endl;
0085     cerr << ">> Comparing plots in " << myName << "..." << endl;
0086     TString newDir("NEW_RELEASE/NEWSELECTION/NEW_LABEL/");
0087     newDir += myName;
0088     gSystem->mkdir(newDir, kTRUE);
0089 
0090     bool logy[] = {false, false, false, false};
0091     bool doKolmo[] = {true, true, true, true};
0092     Double_t norm[] = {0., 0., 0., 0.};
0093     //===== Tracker, ECAL Deposits

0094     const char* plots1[] = {"sumPt", "emEt", "sumPt_cd", "emEt_cd"};
0095     Plot4Histograms(newDir + "/muonIso1",
0096                     rdir,
0097                     sdir,
0098                     rcollname,
0099                     scollname,
0100                     "IsoHistos1",
0101                     "Tracker, ECAL Deposits",
0102                     refLabel,
0103                     newLabel,
0104                     plots1,
0105                     0,
0106                     logy,
0107                     doKolmo,
0108                     norm);
0109 
0110     //===== HCAL and HO Isolation Distributions

0111     const char* plots2[] = {"hadEt", "hoEt", "hadEt_cd", "hoEt_cd"};
0112     Plot4Histograms(newDir + "/muonIso2",
0113                     rdir,
0114                     sdir,
0115                     rcollname,
0116                     scollname,
0117                     "IsoHistos2",
0118                     "HCAL, HO Deposits",
0119                     refLabel,
0120                     newLabel,
0121                     plots2,
0122                     0,
0123                     logy,
0124                     doKolmo,
0125                     norm);
0126 
0127     //===== N_Tracks, N_Jets around #mu

0128     const char* plots3[] = {"nTracks", "nJets", "nTracks_cd", "nJets_cd"};
0129     Plot4Histograms(newDir + "/muonIso3",
0130                     rdir,
0131                     sdir,
0132                     rcollname,
0133                     scollname,
0134                     "IsoHistos3",
0135                     "Number of tracks, jets around #mu",
0136                     refLabel,
0137                     newLabel,
0138                     plots3,
0139                     0,
0140                     logy,
0141                     doKolmo,
0142                     norm);
0143 
0144     //===== avg Pt, weighted Et around #mu

0145     const char* plots4[] = {"avgPt", "weightedEt", "avgPt_cd", "weightedEt_cd"};
0146 
0147     Plot4Histograms(newDir + "/muonIso4",
0148                     rdir,
0149                     sdir,
0150                     rcollname,
0151                     scollname,
0152                     "IsoHistos4",
0153                     "Average p_{T}, weighted E_{T} aroun #mu",
0154                     refLabel,
0155                     newLabel,
0156                     plots4,
0157                     0,
0158                     logy,
0159                     doKolmo,
0160                     norm);
0161 
0162     //===== Tracker and CAL deposits vs muon pT

0163     const char* plots5[] = {"muonPt_sumPt", "muonPt_emEt", "muonPt_hadEt", "muonPt_hoEt"};
0164     Double_t norm2[] = {-999., -999., -999., -999.};
0165     Plot4Histograms(newDir + "/muonIso5",
0166                     rdir,
0167                     sdir,
0168                     rcollname,
0169                     scollname,
0170                     "IsoHistos5",
0171                     "Trk, CAL Isolations vs. #mu p_{T}",
0172                     refLabel,
0173                     newLabel,
0174                     plots5,
0175                     0,
0176                     logy,
0177                     doKolmo,
0178                     norm2);
0179 
0180     //===== NTracks, NJets, avgPt, weightedEt vs Muon pT

0181     const char* plots6[] = {"muonPt_nTracks", "muonPt_nJets", "muonPt_avgPt", "muonPt_weightedEt"};
0182     Plot4Histograms(newDir + "/muonIso6",
0183                     rdir,
0184                     sdir,
0185                     rcollname,
0186                     scollname,
0187                     "IsoHistos6",
0188                     "Other stuff vs #mu p_{T}",
0189                     refLabel,
0190                     newLabel,
0191                     plots6,
0192                     0,
0193                     logy,
0194                     doKolmo,
0195                     norm2);
0196 
0197     //// Merge pdf histograms together into larger files, and name them based on the collection names

0198     TString mergefile = "merged_iso.pdf";                  // File name where partial pdfs will be merged

0199     TString destfile = newDir + "/../" + myName + ".pdf";  // Destination file name

0200     TString gscommand = "gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=" + mergefile + " " + newDir +
0201                         "/muonIso1.pdf " + newDir + "/muonIso2.pdf " + newDir + "/muonIso3.pdf " + newDir +
0202                         "/muonIso4.pdf " + newDir + "/muonIso5.pdf " + newDir + "/muonIso6.pdf ";
0203     cout << ">> Merging partial pdfs to " << mergefile << "..." << endl;
0204 #ifdef DEBUG
0205     cout << "DEBUG: ...with command \"" << gscommand << "\"" << endl;
0206 #endif
0207     gSystem->Exec(gscommand);
0208     cout << ">> Moving " << mergefile << " to " << destfile << "..." << endl;
0209     gSystem->Rename(mergefile, destfile);
0210 
0211     cout << ">> Deleting partial pdf files" << endl;
0212     gSystem->Exec("rm -rf " + newDir + "/*.pdf");
0213     cout << "   ... Done" << endl;
0214   }  // end of "while loop"

0215 
0216   cout << ">> Removing the relval files from ROOT before closing..." << endl;
0217   gROOT->GetListOfFiles()->Remove(sfile);
0218   gROOT->GetListOfFiles()->Remove(rfile);
0219 
0220 #ifdef DEBUG
0221   cout << "DEBUG: Exiting!" << endl;
0222   cerr << "DEBUG: Exiting!" << endl;
0223 #endif
0224 }