Back to home page

Project CMSSW displayed by LXR

 
 

    


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 //Uncomment the following line to get some more output
0007 //#define DEBUG 1
0008 
0009 void SeedValHistoPublisher(const char* newFile = "NEW_FILE", const char* refFile = "REF_FILE") {
0010   cout << ">> Starting SeedValHistoPublisher(" << 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, "Seeds");
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, "Seeds");
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   //==== Get the number of events for the normalization:
0058   cout << ">> Find out number of events for normalization..." << endl;
0059   TH1F *sevt, *revt;
0060   sdir->GetObject("RecoMuonV/RecoMuon_TrackAssoc/Muons/NMuon", sevt);
0061   rdir->GetObject("RecoMuonV/RecoMuon_TrackAssoc/Muons/NMuon", revt);
0062 
0063   /*  if (sevt && revt) {
0064     if (revt->GetEntries()>0) 
0065       norm = sevt->GetEntries()/revt->GetEntries();
0066   }
0067   else {  
0068     cerr << "WARNING: Missing seed normalization histos" << endl; 
0069     cout << "WARNING: Missing seed normalization histos" << endl; 
0070   }
0071   cout << "   + NORM = " << norm << endl;
0072   */
0073 
0074   //==== Iterate now over histograms and collections
0075   cout << ">> Iterating over histograms and collections..." << endl;
0076   TIter iter_r(rl);
0077   TIter iter_s(sl);
0078   TKey* rKey = 0;
0079   TKey* sKey = 0;
0080   TString rcollname;
0081   TString scollname;
0082 
0083   while ((rKey = (TKey*)iter_r())) {
0084     TString myName = rKey->GetName();
0085 #ifdef DEBUG
0086     cout << "DEBUG: Checking key " << myName << endl;
0087 #endif
0088     rcollname = myName;
0089     sKey = (TKey*)iter_s();
0090     if (!sKey)
0091       continue;
0092     scollname = sKey->GetName();
0093     if ((rcollname != scollname) && (rcollname + "FS" != scollname) && (rcollname != scollname + "FS")) {
0094       cerr << "ERROR: Different collection names, please check: " << rcollname << " : " << scollname << endl;
0095       cout << "ERROR: Different collection names, please check: " << rcollname << " : " << scollname << endl;
0096       continue;
0097     }
0098 
0099     // ==== Now let's go for the plotting...
0100     cout << ">> Comparing plots in " << myName << "..." << endl;
0101     cerr << ">> Comparing plots in " << myName << "..." << endl;
0102     TString newDir("NEW_RELEASE/NEWSELECTION/NEW_LABEL/");
0103     newDir += myName;
0104     gSystem->mkdir(newDir, kTRUE);
0105 
0106     bool logy[] = {false, true, false, true};
0107     bool doKolmo[] = {true, true, true, true};
0108     Double_t norm[] = {0., 0., 0., 0., 0., 0.};
0109     /*
0110     const char* plots [] = {"", "", "", ""};
0111     const char* plotsl[] = {"", "", "", ""};
0112     Plot4Histograms(newDir + "/muonIso1",
0113             rdir, sdir, 
0114             rcollname, scollname,
0115             "", "",
0116             refLabel, newLabel,
0117             plots, plotsl,
0118             logy, doKolmo);
0119     */
0120 
0121     //===== muon seeds plots, first page:
0122     const char* plots1[] = {"seedEta_", "seedEtaErr_", "seedPhi_", "seedPhiErr_"};
0123     const char* plotsl1[] = {"seed #eta", "seed #eta error", "seed #phi", "seed #phi error"};
0124     Plot4Histograms(newDir + "/muonSeed1",
0125                     rdir,
0126                     sdir,
0127                     rcollname,
0128                     scollname,
0129                     "Seeds1",
0130                     "Seeds eta and phi",
0131                     refLabel,
0132                     newLabel,
0133                     plots1,
0134                     plotsl1,
0135                     logy,
0136                     doKolmo,
0137                     norm);
0138 
0139     // ====== muon seeds plots, second page:
0140     // NOTE: Originally in one page, now split in two pages
0141     // const char* plots2 [] = {"seedPt_", "seedPtErrOverPt_", "seedPz_", "seedPzErrOverPz_"};
0142     // const char* plotsl2[] = {"seed P_{T}", "seed P_{T} Err/P_{T}", "seed P_{Z}", "seed P_{Z} Err/P_{Z}"};
0143     // Plot4Histograms(newDir + "/muonSeed2",
0144     //          rdir, sdir,
0145     //          rcollname, scollname,
0146     //          "Seeds2", "Seeds momenta",
0147     //          refLabel, newLabel,
0148     //          plots2, plotsl2,
0149     //          logy, doKolmo, norm);
0150 
0151     // const char* plots3 [] = {"NumberOfRecHitsPerSeed_", "seedPErrOverP_", "", ""};
0152     // const char* plotsl3[] = {"Nr RecHits per seed", "seed P Err/P", "", ""};
0153     // Plot4Histograms(newDir + "/muonSeed3",
0154     //          rdir, sdir,
0155     //          rcollname, scollname,
0156     //          "Seeds3", "Seeds hits and momentum",
0157     //          refLabel, newLabel,
0158     //          plots3, plotsl3,
0159     //          logy, doKolmo);
0160 
0161     bool logy2[] = {false, true, false, true, false, true};
0162     bool doKolmo2[] = {true, true, true, true, true, true};
0163     const char* plots2[] = {
0164         "seedPt_", "seedPtErrOverPt_", "seedPz_", "seedPzErrOverPz_", "NumberOfRecHitsPerSeed_", "seedPErrOverP_"};
0165     const char* plotsl2[] = {"seed P_{T}",
0166                              "seed P_{T} Err/P_{T}",
0167                              "seed P_{Z}",
0168                              "seed P_{Z} Err/P_{Z}",
0169                              "Nr RecHits per seed",
0170                              "seed P Err/P"};
0171     Plot6Histograms(newDir + "/muonSeed2",
0172                     rdir,
0173                     sdir,
0174                     rcollname,
0175                     scollname,
0176                     "Seeds2",
0177                     "Seeds momenta and hits",
0178                     refLabel,
0179                     newLabel,
0180                     plots2,
0181                     plotsl2,
0182                     logy2,
0183                     doKolmo2,
0184                     norm);
0185 
0186     //// Merge pdf histograms together into larger files, and name them based on the collection names
0187     TString mergefile = "merged_seed.pdf";                 // File name where partial pdfs will be merged
0188     TString destfile = newDir + "/../" + myName + ".pdf";  // Destination file name
0189     TString gscommand = "gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=" + mergefile + " " + newDir +
0190                         "/muonSeed1.pdf " + newDir + "/muonSeed2.pdf ";
0191     //      + newDir + "/muonSeed3.pdf ";
0192     cout << ">> Merging partial pdfs to " << mergefile << "..." << endl;
0193 #ifdef DEBUG
0194     cout << "DEBUG: ...with command \"" << gscommand << "\"" << endl;
0195 #endif
0196     gSystem->Exec(gscommand);
0197     cout << ">> Moving " << mergefile << " to " << destfile << "..." << endl;
0198     gSystem->Rename(mergefile, destfile);
0199 
0200     cout << ">> Deleting partial pdf files" << endl;
0201     gSystem->Exec("rm -r " + newDir + "/*.pdf");
0202     cout << "   ... Done" << endl;
0203 
0204   }  // end of "while loop"
0205 
0206   cout << ">> Removing the relval files from ROOT before closing..." << endl;
0207   gROOT->GetListOfFiles()->Remove(sfile);
0208   gROOT->GetListOfFiles()->Remove(rfile);
0209 
0210 #ifdef DEBUG
0211   cout << "DEBUG: Exiting!" << endl;
0212   cerr << "DEBUG: Exiting!" << endl;
0213 #endif
0214 }