File indexing completed on 2024-04-06 12:32:23
0001
0002
0003
0004
0005
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
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
0035
0036 verbosity %= 10;
0037
0038
0039 dbe = nullptr;
0040 dbe = edm::Service<DQMStore>().operator->();
0041
0042
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
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
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
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
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
0198
0199
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
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251 void GlobalHitsProdHistStripper::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) { return; }