CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/Validation/GlobalHits/src/GlobalHitsProdHistStripper.cc

Go to the documentation of this file.
00001 
00010 #include "Validation/GlobalHits/interface/GlobalHitsProdHistStripper.h"
00011 #include "DQMServices/Core/interface/DQMStore.h"
00012 #include "DQMServices/Core/interface/MonitorElement.h"
00013 
00014 GlobalHitsProdHistStripper::GlobalHitsProdHistStripper(const 
00015                                                        edm::ParameterSet& 
00016                                                        iPSet) 
00017   : fName(""), verbosity(0), frequency(0), vtxunit(0), 
00018     getAllProvenances(false), printProvenanceInfo(false), outputfile(""),
00019     count(0)
00020 {
00021   std::string MsgLoggerCat = 
00022     "GlobalHitsProdHistStripper_GlobalHitsProdHistStripper";
00023 
00024   // get information from parameter set
00025   fName = iPSet.getUntrackedParameter<std::string>("Name");
00026   verbosity = iPSet.getUntrackedParameter<int>("Verbosity");
00027   frequency = iPSet.getUntrackedParameter<int>("Frequency");
00028   vtxunit = iPSet.getUntrackedParameter<int>("VtxUnit");
00029   outputfile = iPSet.getParameter<std::string>("OutputFile");
00030   doOutput = iPSet.getParameter<bool>("DoOutput");
00031   edm::ParameterSet m_Prov =
00032     iPSet.getParameter<edm::ParameterSet>("ProvenanceLookup");
00033   getAllProvenances = 
00034     m_Prov.getUntrackedParameter<bool>("GetAllProvenances");
00035   printProvenanceInfo = 
00036     m_Prov.getUntrackedParameter<bool>("PrintProvenanceInfo");
00037 
00038 
00039   // use value of first digit to determine default output level (inclusive)
00040   // 0 is none, 1 is basic, 2 is fill output, 3 is gather output
00041   verbosity %= 10;
00042 
00043   // get dqm info
00044   dbe = 0;
00045   dbe = edm::Service<DQMStore>().operator->();
00046   if (dbe) {
00047     if (verbosity > 0 ) {
00048       dbe->setVerbose(1);
00049     } else {
00050       dbe->setVerbose(0);
00051     }
00052   }
00053 
00054   if (dbe) {
00055     if (verbosity > 0 ) dbe->showDirStructure();
00056   }
00057 
00058   // print out Parameter Set information being used
00059   if (verbosity >= 0) {
00060     edm::LogInfo(MsgLoggerCat) 
00061       << "\n===============================\n"
00062       << "Initialized as EDAnalyzer with parameter values:\n"
00063       << "    Name           = " << fName << "\n"
00064       << "    Verbosity      = " << verbosity << "\n"
00065       << "    Frequency      = " << frequency << "\n"
00066       << "    VtxUnit        = " << vtxunit << "\n"
00067       << "    OutputFile     = " << outputfile << "\n"
00068       << "    DoOutput      = " << doOutput << "\n"
00069       << "    GetProv        = " << getAllProvenances << "\n"
00070       << "    PrintProv      = " << printProvenanceInfo << "\n"
00071       << "===============================\n";
00072   }
00073 
00074 }
00075 
00076 GlobalHitsProdHistStripper::~GlobalHitsProdHistStripper() 
00077 {
00078   if (doOutput)
00079     if (outputfile.size() != 0 && dbe) dbe->save(outputfile);
00080 }
00081 
00082 void GlobalHitsProdHistStripper::beginJob( void )
00083 {
00084   return;
00085 }
00086 
00087 void GlobalHitsProdHistStripper::endJob()
00088 {
00089   std::string MsgLoggerCat = "GlobalHitsProdHistStripper_endJob";
00090   if (verbosity >= 0)
00091     edm::LogInfo(MsgLoggerCat) 
00092       << "Terminating having processed " << count << " runs.";
00093   return;
00094 }
00095 
00096 void GlobalHitsProdHistStripper::beginRun(const edm::Run& iRun,
00097                                           const edm::EventSetup& iSetup)
00098 {
00099   std::string MsgLoggerCat = "GlobalHitsProdHistStripper_beginRun";
00100   // keep track of number of runs processed
00101   ++count;  
00102 
00103   int nrun = iRun.run();
00104 
00105   if (verbosity > 0) {
00106     edm::LogInfo(MsgLoggerCat)
00107       << "Processing run " << nrun << " (" << count << " runs total)";
00108   } else if (verbosity == 0) {
00109     if (nrun%frequency == 0 || count == 1) {
00110       edm::LogInfo(MsgLoggerCat)
00111         << "Processing run " << nrun << " (" << count << " runs total)";
00112     }
00113   }
00114 
00115   if (getAllProvenances) {
00116 
00117     std::vector<const edm::Provenance*> AllProv;
00118     iRun.getAllProvenance(AllProv);
00119 
00120     if (verbosity >= 0)
00121       edm::LogInfo(MsgLoggerCat)
00122         << "Number of Provenances = " << AllProv.size();
00123 
00124     if (printProvenanceInfo && (verbosity >= 0)) {
00125       TString eventout("\nProvenance info:\n");      
00126 
00127       for (unsigned int i = 0; i < AllProv.size(); ++i) {
00128         eventout += "\n       ******************************";
00129         eventout += "\n       Module       : ";
00130         eventout += AllProv[i]->moduleLabel();
00131         eventout += "\n       ProductID    : ";
00132         eventout += AllProv[i]->productID().id();
00133         eventout += "\n       ClassName    : ";
00134         eventout += AllProv[i]->className();
00135         eventout += "\n       InstanceName : ";
00136         eventout += AllProv[i]->productInstanceName();
00137         eventout += "\n       BranchName   : ";
00138         eventout += AllProv[i]->branchName();
00139       }
00140       eventout += "\n       ******************************\n";
00141       edm::LogInfo(MsgLoggerCat) << eventout << "\n";
00142       printProvenanceInfo = false;
00143     }
00144     getAllProvenances = false;
00145   }
00146 
00147   return;
00148 }
00149 
00150 void GlobalHitsProdHistStripper::endRun(const edm::Run& iRun,
00151                                         const edm::EventSetup& iSetup)
00152 {
00153   std::string MsgLoggerCat = "GlobalHitsProdHistStripper_endRun";
00154 
00155   edm::Handle<TH1F> histogram1D;
00156   std::vector<edm::Handle<TH1F> > allhistogram1D;
00157   iRun.getManyByType(allhistogram1D);
00158 
00159   me.resize(allhistogram1D.size());
00160 
00161   for (uint i = 0; i < allhistogram1D.size(); ++i) {
00162     histogram1D = allhistogram1D[i];
00163     if(!histogram1D.isValid()) {
00164       edm::LogWarning(MsgLoggerCat)
00165         << "Invalid histogram extracted from event.";
00166       continue;      
00167     }
00168 
00169     me[i] = 0;
00170 
00171     /*
00172     std::cout << "Extracting histogram: " << std::endl
00173               << "       Module       : "
00174               << (histogram1D.provenance()->product()).moduleLabel()
00175               << std::endl
00176               << "       ProductID    : "
00177               << (histogram1D.provenance()->product()).productID().id()
00178               << std::endl
00179               << "       ClassName    : "
00180               << (histogram1D.provenance()->product()).className()
00181               << std::endl
00182               << "       InstanceName : "
00183               << (histogram1D.provenance()->product()).productInstanceName()
00184               << std::endl
00185               << "       BranchName   : "
00186               << (histogram1D.provenance()->product()).branchName()
00187               << std::endl;
00188     */
00189 
00190     if ((histogram1D.provenance()->product()).moduleLabel()
00191         != "globalhitsprodhist") continue;
00192    
00193     std::string histname = histogram1D->GetName();
00194     
00195     std::string subhist1 = histname.substr(1,5);
00196     std::string subhist2 = histname.substr(1,4);
00197 
00198     if (dbe) {
00199       if (subhist1 == "CaloE" || subhist1 == "CaloP") {
00200         dbe->setCurrentFolder("GlobalHitsV/ECal");
00201       } else if (subhist1 == "CaloH") {
00202         dbe->setCurrentFolder("GlobalHitsV/HCal");
00203       } else if (subhist1 == "Geant" || subhist2 == "MCG4" ||
00204                  subhist1 == "MCRGP") {
00205         dbe->setCurrentFolder("GlobalHitsV/MCGeant");
00206       } else if (subhist2 == "Muon") {
00207         dbe->setCurrentFolder("GlobalHitsV/Muon");
00208       } else if (subhist1 == "Track") {
00209         dbe->setCurrentFolder("GlobalHitsV/Tracker");
00210       }
00211      
00212       me[i] = dbe->book1D(histname,histogram1D->GetTitle(),
00213                        histogram1D->GetXaxis()->GetNbins(),
00214                        histogram1D->GetXaxis()->GetXmin(),
00215                        histogram1D->GetXaxis()->GetXmax());
00216       me[i]->setAxisTitle(histogram1D->GetXaxis()->GetTitle(),1);
00217       me[i]->setAxisTitle(histogram1D->GetYaxis()->GetTitle(),2);
00218       
00219     }
00220     
00221     std::string mename = me[i]->getName();
00222     
00223     //std::cout << "Extracting histogram " << histname
00224     //        << " into MonitorElement " << mename
00225     //        << std::endl;
00226     
00227     for (Int_t x = 1; x <= histogram1D->GetXaxis()->GetNbins(); ++x) {
00228       Double_t binx = histogram1D->GetBinCenter(x);
00229       Double_t value = histogram1D->GetBinContent(x);
00230       me[i]->Fill(binx,value);
00231     }
00232   }
00233   return;
00234 }
00235     /*
00236     if (iter != monitorElements.end()) {
00237       
00238       std::string mename = iter->second->getName();
00239 
00240       std::cout << "Extracting histogram " << histname
00241                 << " into MonitorElement " << mename
00242                 << std::endl;
00243     
00244       if (histname == "hGeantTrkE" || histname == "hGeantTrkPt") {
00245         std::cout << "Information stored in histogram pointer:" 
00246                   << std::endl;
00247         std::cout << histname << ":" << std::endl;
00248         std::cout << "  Entries: " << histogram1D->GetEntries() 
00249                   << std::endl;
00250         std::cout << "  Mean: " << histogram1D->GetMean() << std::endl;
00251         std::cout << "  RMS: " << histogram1D->GetRMS() << std::endl;
00252       }
00253 
00254       for (Int_t x = 1; x <= histogram1D->GetXaxis()->GetNbins(); ++x) {
00255         Double_t binx = histogram1D->GetBinCenter(x);
00256         Double_t value = histogram1D->GetBinContent(x);
00257         iter->second->Fill(binx,value);
00258       }
00259      
00260       if (histname == "hGeantTrkE" || histname == "hGeantTrkPt") {
00261         std::cout << "Information stored in monitor element:" << std::endl;
00262         std::cout << mename << ":" << std::endl;
00263         std::cout << "  Entries: " 
00264                   << iter->second->getEntries() << std::endl;
00265         std::cout << "  Mean: " << iter->second->getMean() 
00266                   << std::endl;
00267         std::cout << "  RMS: " << iter->second->getRMS() 
00268                   << std::endl;
00269                   }
00270   } // find in map
00271 } // loop through getManyByType
00272 
00273   return;
00274 }
00275     */
00276 
00277 void GlobalHitsProdHistStripper::analyze(const edm::Event& iEvent, 
00278                                          const edm::EventSetup& iSetup)
00279 {
00280   return;
00281 }
00282 
00283