Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:32:23

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