Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-02-13 02:58:34

0001 #include "Validation/HLTrigger/interface/HLTGenValPathSpecificSettingParser.h"
0002 
0003 HLTGenValPathSpecificSettingParser::HLTGenValPathSpecificSettingParser(std::string pathSpecificSettings,
0004                                                                        std::vector<edm::ParameterSet> binnings,
0005                                                                        std::string vsVar) {
0006   // splitting the cutstring
0007   std::stringstream pathSpecificSettingsStream(pathSpecificSettings);
0008   std::string pathSpecificSettingsSegment;
0009   std::vector<std::string> pathSpecificSettingsSeglist;
0010   while (std::getline(pathSpecificSettingsStream, pathSpecificSettingsSegment, ',')) {
0011     pathSpecificSettingsSeglist.push_back(pathSpecificSettingsSegment);
0012   }
0013 
0014   for (const auto& pathSpecificSetting : pathSpecificSettingsSeglist) {
0015     // each of these strings is expected to contain exactly one equal sign
0016     std::stringstream pathSpecificSettingStream(pathSpecificSetting);
0017     std::string pathSpecificSettingSegment;
0018     std::vector<std::string> pathSpecificSettingSeglist;
0019     while (std::getline(pathSpecificSettingStream, pathSpecificSettingSegment, '=')) {
0020       pathSpecificSettingSeglist.push_back(pathSpecificSettingSegment);
0021     }
0022     if (pathSpecificSettingSeglist.size() != 2)
0023       throw cms::Exception("InputError") << "Path-specific cuts could not be parsed. Make sure that each parameter "
0024                                             "contains exactly one equal sign!.\nCuts were \n"
0025                                          << pathSpecificSetting << "\nall cuts\n"
0026                                          << pathSpecificSettings;
0027     const std::string cutVariable = pathSpecificSettingSeglist.at(0);
0028     const std::string cutParameter = pathSpecificSettingSeglist.at(1);
0029 
0030     edm::ParameterSet rangeCutConfig;
0031     if (cutVariable == "absEtaMax" || cutVariable == "absEtaCut") {
0032       rangeCutConfig.addParameter<std::string>("rangeVar", "eta");
0033       rangeCutConfig.addParameter<std::vector<std::string>>("allowedRanges", {"-" + cutParameter + ":" + cutParameter});
0034     } else if (cutVariable == "absEtaMin") {
0035       rangeCutConfig.addParameter<std::string>("rangeVar", "eta");
0036       rangeCutConfig.addParameter<std::vector<std::string>>("allowedRanges",
0037                                                             {"-999:" + cutParameter, cutParameter + ":999"});
0038     } else if (cutVariable == "ptMax") {
0039       rangeCutConfig.addParameter<std::string>("rangeVar", "pt");
0040       rangeCutConfig.addParameter<std::vector<std::string>>("allowedRanges", {"0:" + cutParameter});
0041     } else if (cutVariable == "ptMin" || cutVariable == "ptCut") {
0042       rangeCutConfig.addParameter<std::string>("rangeVar", "pt");
0043       rangeCutConfig.addParameter<std::vector<std::string>>("allowedRanges", {cutParameter + ":999999"});
0044     } else if (cutVariable == "etMax") {
0045       rangeCutConfig.addParameter<std::string>("rangeVar", "et");
0046       rangeCutConfig.addParameter<std::vector<std::string>>("allowedRanges", {"0:" + cutParameter});
0047     } else if (cutVariable == "etMin" || cutVariable == "etCut") {
0048       rangeCutConfig.addParameter<std::string>("rangeVar", "et");
0049       rangeCutConfig.addParameter<std::vector<std::string>>("allowedRanges", {cutParameter + ":999999"});
0050     } else if (cutVariable == "minMass") {
0051       rangeCutConfig.addParameter<std::string>("rangeVar", "mass");
0052       rangeCutConfig.addParameter<std::vector<std::string>>("allowedRanges", {cutParameter + ":999999"});
0053     } else if (cutVariable == "region") {
0054       rangeCutConfig.addParameter<std::string>("rangeVar", "eta");
0055 
0056       // various predefined regions
0057       // multiple regions might used, which are then split by a plus sign
0058       std::stringstream cutParameterStream(cutParameter);
0059       std::string cutParameterSegment;
0060       std::vector<std::string> cutParameterSeglist;
0061       while (std::getline(cutParameterStream, cutParameterSegment, '+')) {
0062         cutParameterSeglist.push_back(cutParameterSegment);
0063       }
0064 
0065       for (const auto& region : cutParameterSeglist) {
0066         if (region == "EB") {
0067           rangeCutConfig.addParameter<std::vector<std::string>>("allowedRanges", {"-1.4442:1.4442"});
0068         } else if (region == "EE") {
0069           rangeCutConfig.addParameter<std::vector<std::string>>("allowedRanges", {"-2.5:-1.5660", "1.5660:2.5"});
0070         } else if (region == "EEFull") {
0071           rangeCutConfig.addParameter<std::vector<std::string>>("allowedRanges", {"-3.0:-1.5660", "1.5660:3.0"});
0072         } else {
0073           throw cms::Exception("InputError") << "Region " + region + " not recognized.\n";
0074         }
0075       }
0076 
0077     } else if (cutVariable == "bins") {
0078       // sets of binnings are read from the user-input ones passed in the "binnings" VPset
0079 
0080       bool binningFound = false;
0081       bool binningUsed = false;
0082       for (const auto& binning : binnings) {
0083         if (binning.getParameter<std::string>("name") == cutParameter) {
0084           if (binning.getParameter<std::string>("vsVar") == vsVar) {
0085             if (binningUsed)
0086               throw cms::Exception("InputError")
0087                   << "Multiple different binnings set for a path, this does not make sense!.\n";
0088             pathSpecificBins_ = binning.getParameter<std::vector<double>>("binLowEdges");
0089             binningUsed = true;
0090           }
0091           binningFound = true;
0092         }
0093       }
0094       if (!binningFound)
0095         throw cms::Exception("InputError")
0096             << "Binning " << cutParameter << " not recognized! Please pass the definition to the module.\n";
0097 
0098     } else if (cutVariable == "tag") {
0099       tag_ = cutParameter;
0100     } else if (cutVariable == "autotag") {
0101       // autotag is only used if no manual tag is set
0102       if (tag_.empty())
0103         tag_ = cutParameter;
0104     } else {
0105       throw cms::Exception("InputError")
0106           << "Path-specific cut " + cutVariable +
0107                  " not recognized. The following options can be user: absEtaMax, absEtaCut, absEtaMin, ptMax, ptMin, "
0108                  "ptCut, etMax, etMin, etCut, region, bins and tag.\n";
0109     }
0110 
0111     if (!rangeCutConfig.empty())
0112       pathSpecificCutsVector_.push_back(rangeCutConfig);
0113   }
0114 }