Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:32:50

0001 /** \file GlobalHitsProdHistStripper.cc
0002  *
0003  *  See header file for description of class
0004  *
0005  *  \author M. Strang SUNY-Buffalo
0006  */
0007 
0008 #include "DQMServices/Core/interface/DQMStore.h"
0009 #include "Validation/GlobalHits/interface/GlobalHitsProdHistStripper.h"
0010 
0011 GlobalHitsProdHistStripper::GlobalHitsProdHistStripper(const edm::ParameterSet &iPSet)
0012     : fName(""),
0013       verbosity(0),
0014       frequency(0),
0015       vtxunit(0),
0016       getAllProvenances(false),
0017       printProvenanceInfo(false),
0018       outputfile(""),
0019       count(0) {
0020   std::string MsgLoggerCat = "GlobalHitsProdHistStripper_GlobalHitsProdHistStripper";
0021 
0022   // get information from parameter set
0023   fName = iPSet.getUntrackedParameter<std::string>("Name");
0024   verbosity = iPSet.getUntrackedParameter<int>("Verbosity");
0025   frequency = iPSet.getUntrackedParameter<int>("Frequency");
0026   vtxunit = iPSet.getUntrackedParameter<int>("VtxUnit");
0027   outputfile = iPSet.getParameter<std::string>("OutputFile");
0028   doOutput = iPSet.getParameter<bool>("DoOutput");
0029   edm::ParameterSet m_Prov = iPSet.getParameter<edm::ParameterSet>("ProvenanceLookup");
0030   getAllProvenances = m_Prov.getUntrackedParameter<bool>("GetAllProvenances");
0031   printProvenanceInfo = m_Prov.getUntrackedParameter<bool>("PrintProvenanceInfo");
0032 
0033   // use value of first digit to determine default output level (inclusive)
0034   // 0 is none, 1 is basic, 2 is fill output, 3 is gather output
0035   verbosity %= 10;
0036 
0037   // get dqm info
0038   dbe = nullptr;
0039   dbe = edm::Service<DQMStore>().operator->();
0040 
0041   // print out Parameter Set information being used
0042   if (verbosity >= 0) {
0043     edm::LogInfo(MsgLoggerCat) << "\n===============================\n"
0044                                << "Initialized as EDAnalyzer with parameter values:\n"
0045                                << "    Name           = " << fName << "\n"
0046                                << "    Verbosity      = " << verbosity << "\n"
0047                                << "    Frequency      = " << frequency << "\n"
0048                                << "    VtxUnit        = " << vtxunit << "\n"
0049                                << "    OutputFile     = " << outputfile << "\n"
0050                                << "    DoOutput      = " << doOutput << "\n"
0051                                << "    GetProv        = " << getAllProvenances << "\n"
0052                                << "    PrintProv      = " << printProvenanceInfo << "\n"
0053                                << "===============================\n";
0054   }
0055 }
0056 
0057 GlobalHitsProdHistStripper::~GlobalHitsProdHistStripper() {
0058   if (doOutput)
0059     if (!outputfile.empty() && dbe)
0060       dbe->save(outputfile);
0061 }
0062 
0063 void GlobalHitsProdHistStripper::beginJob(void) { return; }
0064 
0065 void GlobalHitsProdHistStripper::endJob() {
0066   std::string MsgLoggerCat = "GlobalHitsProdHistStripper_endJob";
0067   if (verbosity >= 0)
0068     edm::LogInfo(MsgLoggerCat) << "Terminating having processed " << count << " runs.";
0069   return;
0070 }
0071 
0072 void GlobalHitsProdHistStripper::beginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) {
0073   std::string MsgLoggerCat = "GlobalHitsProdHistStripper_beginRun";
0074   // keep track of number of runs processed
0075   ++count;
0076 
0077   int nrun = iRun.run();
0078 
0079   if (verbosity > 0) {
0080     edm::LogInfo(MsgLoggerCat) << "Processing run " << nrun << " (" << count << " runs total)";
0081   } else if (verbosity == 0) {
0082     if (nrun % frequency == 0 || count == 1) {
0083       edm::LogInfo(MsgLoggerCat) << "Processing run " << nrun << " (" << count << " runs total)";
0084     }
0085   }
0086 
0087   if (getAllProvenances) {
0088     std::vector<const edm::StableProvenance *> AllProv;
0089     iRun.getAllStableProvenance(AllProv);
0090 
0091     if (verbosity >= 0)
0092       edm::LogInfo(MsgLoggerCat) << "Number of Provenances = " << AllProv.size();
0093 
0094     if (printProvenanceInfo && (verbosity >= 0)) {
0095       TString eventout("\nProvenance info:\n");
0096 
0097       for (unsigned int i = 0; i < AllProv.size(); ++i) {
0098         eventout += "\n       ******************************";
0099         eventout += "\n       Module       : ";
0100         eventout += AllProv[i]->moduleLabel();
0101         eventout += "\n       ProductID    : ";
0102         eventout += AllProv[i]->productID().id();
0103         eventout += "\n       ClassName    : ";
0104         eventout += AllProv[i]->className();
0105         eventout += "\n       InstanceName : ";
0106         eventout += AllProv[i]->productInstanceName();
0107         eventout += "\n       BranchName   : ";
0108         eventout += AllProv[i]->branchName();
0109       }
0110       eventout += "\n       ******************************\n";
0111       edm::LogInfo(MsgLoggerCat) << eventout << "\n";
0112       printProvenanceInfo = false;
0113     }
0114     getAllProvenances = false;
0115   }
0116 
0117   return;
0118 }
0119 
0120 void GlobalHitsProdHistStripper::endRun(const edm::Run &iRun, const edm::EventSetup &iSetup) {
0121   std::string MsgLoggerCat = "GlobalHitsProdHistStripper_endRun";
0122 
0123   edm::Handle<TH1F> histogram1D;
0124   std::vector<edm::Handle<TH1F>> allhistogram1D;
0125   iRun.getManyByType(allhistogram1D);
0126 
0127   me.resize(allhistogram1D.size());
0128 
0129   for (uint i = 0; i < allhistogram1D.size(); ++i) {
0130     histogram1D = allhistogram1D[i];
0131     if (!histogram1D.isValid()) {
0132       edm::LogWarning(MsgLoggerCat) << "Invalid histogram extracted from event.";
0133       continue;
0134     }
0135 
0136     me[i] = nullptr;
0137 
0138     /*
0139     std::cout << "Extracting histogram: " << std::endl
0140               << "       Module       : "
0141               << (histogram1D.provenance()->branchDescription()).moduleLabel()
0142               << std::endl
0143               << "       ProductID    : "
0144               <<
0145     (histogram1D.provenance()->branchDescription()).productID().id()
0146               << std::endl
0147               << "       ClassName    : "
0148               << (histogram1D.provenance()->branchDescription()).className()
0149               << std::endl
0150               << "       InstanceName : "
0151               <<
0152     (histogram1D.provenance()->branchDescription()).productInstanceName()
0153               << std::endl
0154               << "       BranchName   : "
0155               << (histogram1D.provenance()->branchDescription()).branchName()
0156               << std::endl;
0157     */
0158 
0159     if ((histogram1D.provenance()->branchDescription()).moduleLabel() != "globalhitsprodhist")
0160       continue;
0161 
0162     std::string histname = histogram1D->GetName();
0163 
0164     std::string subhist1 = histname.substr(1, 5);
0165     std::string subhist2 = histname.substr(1, 4);
0166 
0167     if (dbe) {
0168       if (subhist1 == "CaloE" || subhist1 == "CaloP") {
0169         dbe->setCurrentFolder("GlobalHitsV/ECal");
0170       } else if (subhist1 == "CaloH") {
0171         dbe->setCurrentFolder("GlobalHitsV/HCal");
0172       } else if (subhist1 == "Geant" || subhist2 == "MCG4" || subhist1 == "MCRGP") {
0173         dbe->setCurrentFolder("GlobalHitsV/MCGeant");
0174       } else if (subhist2 == "Muon") {
0175         dbe->setCurrentFolder("GlobalHitsV/Muon");
0176       } else if (subhist1 == "Track") {
0177         dbe->setCurrentFolder("GlobalHitsV/Tracker");
0178       }
0179 
0180       me[i] = dbe->book1D(histname,
0181                           histogram1D->GetTitle(),
0182                           histogram1D->GetXaxis()->GetNbins(),
0183                           histogram1D->GetXaxis()->GetXmin(),
0184                           histogram1D->GetXaxis()->GetXmax());
0185       me[i]->setAxisTitle(histogram1D->GetXaxis()->GetTitle(), 1);
0186       me[i]->setAxisTitle(histogram1D->GetYaxis()->GetTitle(), 2);
0187     }
0188 
0189     std::string mename = me[i]->getName();
0190 
0191     // std::cout << "Extracting histogram " << histname
0192     //        << " into MonitorElement " << mename
0193     //        << std::endl;
0194 
0195     for (Int_t x = 1; x <= histogram1D->GetXaxis()->GetNbins(); ++x) {
0196       Double_t binx = histogram1D->GetBinCenter(x);
0197       Double_t value = histogram1D->GetBinContent(x);
0198       me[i]->Fill(binx, value);
0199     }
0200   }
0201   return;
0202 }
0203 /*
0204 if (iter != monitorElements.end()) {
0205 
0206   std::string mename = iter->second->getName();
0207 
0208   std::cout << "Extracting histogram " << histname
0209             << " into MonitorElement " << mename
0210             << std::endl;
0211 
0212   if (histname == "hGeantTrkE" || histname == "hGeantTrkPt") {
0213     std::cout << "Information stored in histogram pointer:"
0214               << std::endl;
0215     std::cout << histname << ":" << std::endl;
0216     std::cout << "  Entries: " << histogram1D->GetEntries()
0217               << std::endl;
0218     std::cout << "  Mean: " << histogram1D->GetMean() << std::endl;
0219     std::cout << "  RMS: " << histogram1D->GetRMS() << std::endl;
0220   }
0221 
0222   for (Int_t x = 1; x <= histogram1D->GetXaxis()->GetNbins(); ++x) {
0223     Double_t binx = histogram1D->GetBinCenter(x);
0224     Double_t value = histogram1D->GetBinContent(x);
0225     iter->second->Fill(binx,value);
0226   }
0227 
0228   if (histname == "hGeantTrkE" || histname == "hGeantTrkPt") {
0229     std::cout << "Information stored in monitor element:" << std::endl;
0230     std::cout << mename << ":" << std::endl;
0231     std::cout << "  Entries: "
0232               << iter->second->getEntries() << std::endl;
0233     std::cout << "  Mean: " << iter->second->getMean()
0234               << std::endl;
0235     std::cout << "  RMS: " << iter->second->getRMS()
0236               << std::endl;
0237               }
0238 } // find in map
0239 } // loop through getManyByType
0240 
0241 return;
0242 }
0243 */
0244 
0245 void GlobalHitsProdHistStripper::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) { return; }