File indexing completed on 2025-02-13 02:58:34
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include <memory>
0017 #include <chrono>
0018 #include <ctime>
0019
0020
0021 #include "FWCore/Framework/interface/Event.h"
0022 #include "FWCore/Framework/interface/MakerMacros.h"
0023
0024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0025 #include "FWCore/Utilities/interface/InputTag.h"
0026
0027
0028 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
0029
0030
0031 #include "DataFormats/METReco/interface/GenMETCollection.h"
0032 #include "DataFormats/METReco/interface/GenMET.h"
0033
0034
0035 #include "FWCore/ServiceRegistry/interface/Service.h"
0036 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0037
0038
0039 #include "DQMOffline/Trigger/interface/FunctionDefs.h"
0040
0041
0042 #include "Validation/HLTrigger/interface/HLTGenValHistCollPath.h"
0043
0044
0045 #include "DQMServices/Core/interface/DQMStore.h"
0046 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0047
0048
0049 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0050 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
0051
0052
0053 #include "Validation/HLTrigger/interface/HLTGenValObject.h"
0054 #include "Validation/HLTrigger/interface/HLTGenValObjectMgr.h"
0055
0056 class HLTGenValSource : public DQMEDAnalyzer {
0057 public:
0058 explicit HLTGenValSource(const edm::ParameterSet&);
0059 ~HLTGenValSource() override = default;
0060 HLTGenValSource(const HLTGenValSource&) = delete;
0061 HLTGenValSource& operator=(const HLTGenValSource&) = delete;
0062
0063 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0064
0065 private:
0066 void analyze(const edm::Event&, const edm::EventSetup&) override;
0067 void bookHistograms(DQMStore::IBooker&, edm::Run const& run, edm::EventSetup const& c) override;
0068 void dqmBeginRun(const edm::Run&, const edm::EventSetup&) override;
0069 void initCfgs(const edm::Run&, const edm::EventSetup&);
0070
0071
0072 std::vector<HLTGenValObject> getObjectCollection(const edm::Event&);
0073 std::vector<HLTGenValObject> getGenParticles(const edm::Event&);
0074 reco::GenParticle getLastCopyPreFSR(reco::GenParticle part);
0075 reco::GenParticle getLastCopy(reco::GenParticle part);
0076 bool passGenJetID(const reco::GenJet& jet);
0077
0078
0079 HLTGenValObjectMgr genObjMgr_;
0080
0081 const edm::EDGetTokenT<trigger::TriggerEvent> trigEventToken_;
0082
0083 bool initalised_;
0084 bool booked_;
0085
0086
0087 std::string objType_;
0088 std::string dirName_;
0089 std::vector<edm::ParameterSet> histConfigs_;
0090 std::vector<edm::ParameterSet> histConfigs2D_;
0091 std::vector<edm::ParameterSet> binnings_;
0092 std::string hltProcessName_;
0093 std::string sampleLabel_;
0094
0095
0096
0097 std::string infoString_ = "{";
0098
0099
0100 std::vector<HLTGenValHistCollPath> collectionPath_;
0101
0102
0103 HLTConfigProvider hltConfig_;
0104
0105
0106 std::vector<std::string> hltPathsToCheck_;
0107 std::vector<std::string> hltPaths_;
0108 std::vector<std::string> hltPathSpecificCuts_;
0109 double dR2limit_;
0110 bool doOnlyLastFilter_;
0111 };
0112
0113 HLTGenValSource::HLTGenValSource(const edm::ParameterSet& iConfig)
0114 : genObjMgr_(iConfig.getParameter<edm::ParameterSet>("genConfig"), consumesCollector()),
0115 trigEventToken_(consumes<trigger::TriggerEvent>(iConfig.getParameter<edm::InputTag>("trigEvent"))),
0116 initalised_(false),
0117 booked_(false)
0118
0119 {
0120
0121 histConfigs_ = iConfig.getParameterSetVector("histConfigs");
0122 histConfigs2D_ = iConfig.getParameterSetVector("histConfigs2D");
0123 binnings_ = iConfig.getParameterSetVector("binnings");
0124
0125
0126 dirName_ = iConfig.getParameter<std::string>("dqmDirName");
0127 objType_ = iConfig.getParameter<std::string>("objType");
0128 dR2limit_ = iConfig.getParameter<double>("dR2limit");
0129 doOnlyLastFilter_ = iConfig.getParameter<bool>("doOnlyLastFilter");
0130 hltProcessName_ = iConfig.getParameter<std::string>("hltProcessName");
0131 sampleLabel_ = iConfig.getParameter<std::string>("sampleLabel");
0132 hltPathsToCheck_ = iConfig.getParameter<std::vector<std::string>>("hltPathsToCheck");
0133 }
0134
0135 void HLTGenValSource::initCfgs(const edm::Run& iRun, const edm::EventSetup& iSetup) {
0136
0137 auto t = std::time(nullptr);
0138 auto tm = *std::localtime(&t);
0139
0140
0141 std::ostringstream timeStringStream;
0142 timeStringStream << std::put_time(&tm, "%d-%m-%Y %H-%M-%S");
0143 auto timeString = timeStringStream.str();
0144 infoString_ += "\"date & time\":\"" + timeString + "\",";
0145
0146 std::string cmsswVersion;
0147 const edm::ProcessHistory& processHistory = iRun.processHistory();
0148 for (const auto& process : processHistory) {
0149 if (process.processName() == hltProcessName_) {
0150 cmsswVersion = process.releaseVersion();
0151 break;
0152 }
0153 }
0154 if (cmsswVersion.empty()) {
0155 cmsswVersion =
0156 "\"" + std::string(std::getenv("CMSSW_VERSION")) + "\"";
0157 }
0158 infoString_ += std::string("\"CMSSW release\":") + cmsswVersion + ",";
0159 infoString_ += std::string("\"sample label\":\"") + sampleLabel_ + "\",";
0160
0161
0162 bool changedConfig;
0163 if (!hltConfig_.init(iRun, iSetup, hltProcessName_, changedConfig)) {
0164 edm::LogError("HLTGenValSource") << "Initialization of HLTConfigProvider failed!";
0165 return;
0166 }
0167
0168
0169 infoString_ += std::string("\"global tag\":\"") + hltConfig_.globalTag() + "\",";
0170
0171
0172 infoString_ += std::string("\"HLT ConfDB table\":\"") + hltConfig_.tableName() + "\"}";
0173
0174
0175 std::vector<std::string> notFoundPaths;
0176 for (auto const& pathToCheck : hltPathsToCheck_) {
0177
0178
0179 std::string cleanedPathToCheck;
0180 std::string pathSpecificCuts = "";
0181 if (pathToCheck.find(':') != std::string::npos) {
0182
0183 std::stringstream hltPathToCheckInputStream(pathToCheck);
0184 std::string hltPathToCheckInputSegment;
0185 std::vector<std::string> hltPathToCheckInputSeglist;
0186 while (std::getline(hltPathToCheckInputStream, hltPathToCheckInputSegment, ':')) {
0187 hltPathToCheckInputSeglist.push_back(hltPathToCheckInputSegment);
0188 }
0189
0190
0191 if (hltPathToCheckInputSeglist.size() != 2)
0192 throw cms::Exception("InputError")
0193 << "Path string " << pathToCheck
0194 << " can not be properly split into path and cuts: please use exactly one colon!.\n";
0195
0196
0197 cleanedPathToCheck = hltPathToCheckInputSeglist.at(0);
0198
0199
0200 pathSpecificCuts = hltPathToCheckInputSeglist.at(1);
0201
0202 } else {
0203 cleanedPathToCheck = pathToCheck;
0204 }
0205
0206 bool pathfound = false;
0207 for (auto const& pathFromConfig : hltConfig_.triggerNames()) {
0208 if (pathFromConfig.find(cleanedPathToCheck) != std::string::npos) {
0209 hltPaths_.push_back(pathFromConfig);
0210
0211
0212 int count = std::count(hltPaths_.begin(), hltPaths_.end(), pathFromConfig);
0213 if (count > 1) {
0214 pathSpecificCuts += std::string(",autotag=v") + std::to_string(count);
0215 }
0216 hltPathSpecificCuts_.push_back(pathSpecificCuts);
0217 pathfound = true;
0218 }
0219 }
0220 if (!pathfound)
0221 notFoundPaths.push_back(cleanedPathToCheck);
0222 }
0223 if (!notFoundPaths.empty()) {
0224
0225 std::string notFoundPathsMessage = "";
0226 for (const auto& path : notFoundPaths)
0227 notFoundPathsMessage += "- " + path + "\n";
0228 edm::LogError("HLTGenValSource") << "The following paths could not be found and will not be used: \n"
0229 << notFoundPathsMessage << std::endl;
0230 }
0231
0232
0233
0234
0235 edm::ParameterSet pathCollConfig;
0236 pathCollConfig.addParameter<std::string>("objType", objType_);
0237 pathCollConfig.addParameter<double>("dR2limit", dR2limit_);
0238 pathCollConfig.addParameter<bool>("doOnlyLastFilter", doOnlyLastFilter_);
0239 pathCollConfig.addParameter<std::string>("hltProcessName", hltProcessName_);
0240
0241
0242 for (const auto& path : hltPaths_) {
0243 edm::ParameterSet pathCollConfigStep = pathCollConfig;
0244 pathCollConfigStep.addParameter<std::string>("triggerPath", path);
0245 collectionPath_.emplace_back(HLTGenValHistCollPath(pathCollConfigStep, hltConfig_));
0246 }
0247 initalised_ = true;
0248 }
0249
0250 void HLTGenValSource::dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
0251 if (!initalised_)
0252 initCfgs(iRun, iSetup);
0253 }
0254
0255
0256 void HLTGenValSource::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0257
0258 const std::vector<HLTGenValObject> objects = genObjMgr_.getGenValObjects(iEvent, objType_);
0259
0260
0261 edm::Handle<trigger::TriggerEvent> triggerEvent;
0262 iEvent.getByToken(trigEventToken_, triggerEvent);
0263
0264
0265 for (const auto& object : objects) {
0266 for (auto& collection_path : collectionPath_) {
0267 collection_path.fillHists(object, triggerEvent);
0268 }
0269 }
0270 }
0271
0272
0273 void HLTGenValSource::bookHistograms(DQMStore::IBooker& iBooker, const edm::Run& run, const edm::EventSetup& setup) {
0274 iBooker.setCurrentFolder(dirName_);
0275 iBooker.bookString("HLTGenValInfo", infoString_);
0276
0277
0278 for (long unsigned int i = 0; i < collectionPath_.size(); i++) {
0279 std::vector<edm::ParameterSet> histConfigs = histConfigs_;
0280 for (auto& histConfig : histConfigs) {
0281 histConfig.addParameter<std::string>("pathSpecificCuts", hltPathSpecificCuts_.at(i));
0282 histConfig.addParameter<std::vector<edm::ParameterSet>>("binnings",
0283 binnings_);
0284 }
0285
0286 collectionPath_.at(i).bookHists(iBooker, histConfigs, histConfigs2D_);
0287 }
0288 booked_ = true;
0289 }
0290
0291
0292 void HLTGenValSource::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0293 edm::ParameterSetDescription desc;
0294
0295
0296 desc.add<std::string>(
0297 "objType");
0298 desc.add<std::vector<std::string>>(
0299 "hltPathsToCheck");
0300 desc.add<std::string>("dqmDirName", "HLTGenVal");
0301 desc.add<std::string>("hltProcessName", "HLT");
0302 desc.add<std::string>("sampleLabel", "");
0303 desc.add<double>("dR2limit", 0.1);
0304 desc.add<bool>("doOnlyLastFilter", false);
0305
0306 desc.add<edm::ParameterSetDescription>("genConfig", HLTGenValObjectMgr::makePSetDescription());
0307 desc.add<edm::InputTag>("trigEvent", edm::InputTag("hltTriggerSummaryAOD"));
0308
0309
0310
0311
0312
0313 edm::ParameterSetDescription histConfig;
0314 histConfig.add<std::string>("vsVar");
0315 histConfig.add<std::vector<double>>("binLowEdges");
0316 histConfig.addVPSet(
0317 "rangeCuts", VarRangeCut<HLTGenValObject>::makePSetDescription(), std::vector<edm::ParameterSet>());
0318
0319
0320 std::vector<edm::ParameterSet> histConfigDefaults;
0321
0322 edm::ParameterSet histConfigDefault0;
0323 histConfigDefault0.addParameter<std::string>("vsVar", "pt");
0324 std::vector<double> defaultPtBinning{0, 5, 10, 12.5, 15, 17.5, 20, 22.5, 25, 30, 35, 40,
0325 45, 50, 60, 80, 100, 150, 200, 250, 300, 350, 400};
0326 histConfigDefault0.addParameter<std::vector<double>>("binLowEdges", defaultPtBinning);
0327 histConfigDefaults.push_back(histConfigDefault0);
0328
0329 edm::ParameterSet histConfigDefault1;
0330 histConfigDefault1.addParameter<std::string>("vsVar", "eta");
0331 std::vector<double> defaultetaBinning{-10, -8, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 8, 10};
0332 histConfigDefault1.addParameter<std::vector<double>>("binLowEdges", defaultetaBinning);
0333 histConfigDefaults.push_back(histConfigDefault1);
0334
0335 desc.addVPSet("histConfigs", histConfig, histConfigDefaults);
0336
0337
0338 edm::ParameterSetDescription histConfig2D;
0339 histConfig2D.add<std::string>("vsVarX");
0340 histConfig2D.add<std::string>("vsVarY");
0341 histConfig2D.add<std::vector<double>>("binLowEdgesX");
0342 histConfig2D.add<std::vector<double>>("binLowEdgesY");
0343 histConfig2D.addVPSet(
0344 "rangeCuts", VarRangeCut<HLTGenValObject>::makePSetDescription(), std::vector<edm::ParameterSet>());
0345
0346 std::vector<edm::ParameterSet> histConfigDefaults2D;
0347
0348 edm::ParameterSet histConfigDefault2D0;
0349 histConfigDefault2D0.addParameter<std::string>("vsVarX", "pt");
0350 histConfigDefault2D0.addParameter<std::string>("vsVarY", "eta");
0351 histConfigDefault2D0.addParameter<std::vector<double>>("binLowEdgesX", defaultPtBinning);
0352 histConfigDefault2D0.addParameter<std::vector<double>>("binLowEdgesY", defaultetaBinning);
0353
0354 histConfigDefaults2D.push_back(histConfigDefault2D0);
0355
0356 desc.addVPSet("histConfigs2D", histConfig2D, histConfigDefaults2D);
0357
0358
0359
0360 edm::ParameterSetDescription binningConfig;
0361 binningConfig.add<std::string>("name");
0362 binningConfig.add<std::string>("vsVar");
0363 binningConfig.add<std::vector<double>>("binLowEdges");
0364
0365
0366 std::vector<edm::ParameterSet> binningConfigDefaults;
0367
0368 desc.addVPSet("binnings", binningConfig, binningConfigDefaults);
0369
0370 descriptions.addDefault(desc);
0371 }
0372
0373
0374 DEFINE_FWK_MODULE(HLTGenValSource);