Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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!.\n";
0025     const std::string cutVariable = pathSpecificSettingSeglist.at(0);
0026     const std::string cutParameter = pathSpecificSettingSeglist.at(1);
0027 
0028     edm::ParameterSet rangeCutConfig;
0029     if (cutVariable == "absEtaMax" || cutVariable == "absEtaCut") {
0030       rangeCutConfig.addParameter<std::string>("rangeVar", "eta");
0031       rangeCutConfig.addParameter<std::vector<std::string>>("allowedRanges", {"-" + cutParameter + ":" + cutParameter});
0032     } else if (cutVariable == "absEtaMin") {
0033       rangeCutConfig.addParameter<std::string>("rangeVar", "eta");
0034       rangeCutConfig.addParameter<std::vector<std::string>>("allowedRanges",
0035                                                             {"-999:" + cutParameter, cutParameter + ":999"});
0036     } else if (cutVariable == "ptMax") {
0037       rangeCutConfig.addParameter<std::string>("rangeVar", "pt");
0038       rangeCutConfig.addParameter<std::vector<std::string>>("allowedRanges", {"0:" + cutParameter});
0039     } else if (cutVariable == "ptMin" || cutVariable == "ptCut") {
0040       rangeCutConfig.addParameter<std::string>("rangeVar", "pt");
0041       rangeCutConfig.addParameter<std::vector<std::string>>("allowedRanges", {cutParameter + ":999999"});
0042     } else if (cutVariable == "etMax") {
0043       rangeCutConfig.addParameter<std::string>("rangeVar", "et");
0044       rangeCutConfig.addParameter<std::vector<std::string>>("allowedRanges", {"0:" + cutParameter});
0045     } else if (cutVariable == "etMin" || cutVariable == "etCut") {
0046       rangeCutConfig.addParameter<std::string>("rangeVar", "et");
0047       rangeCutConfig.addParameter<std::vector<std::string>>("allowedRanges", {cutParameter + ":999999"});
0048     } else if (cutVariable == "region") {
0049       rangeCutConfig.addParameter<std::string>("rangeVar", "eta");
0050 
0051       // various predefined regions
0052       // multiple regions might used, which are then split by a plus sign
0053       std::stringstream cutParameterStream(cutParameter);
0054       std::string cutParameterSegment;
0055       std::vector<std::string> cutParameterSeglist;
0056       while (std::getline(cutParameterStream, cutParameterSegment, '+')) {
0057         cutParameterSeglist.push_back(cutParameterSegment);
0058       }
0059 
0060       for (const auto& region : cutParameterSeglist) {
0061         if (region == "EB") {
0062           rangeCutConfig.addParameter<std::vector<std::string>>("allowedRanges", {"-1.4442:1.4442"});
0063         } else if (region == "EE") {
0064           rangeCutConfig.addParameter<std::vector<std::string>>("allowedRanges", {"-999:-1.5660", "1.5660:999"});
0065         } else {
0066           throw cms::Exception("InputError") << "Region " + region + " not recognized.\n";
0067         }
0068       }
0069 
0070     } else if (cutVariable == "bins") {
0071       // sets of binnings are read from the user-input ones passed in the "binnings" VPset
0072 
0073       bool binningFound = false;
0074       bool binningUsed = false;
0075       for (const auto& binning : binnings) {
0076         if (binning.getParameter<std::string>("name") == cutParameter) {
0077           if (binning.getParameter<std::string>("vsVar") == vsVar) {
0078             if (binningUsed)
0079               throw cms::Exception("InputError")
0080                   << "Multiple different binnings set for a path, this does not make sense!.\n";
0081             pathSpecificBins_ = binning.getParameter<std::vector<double>>("binLowEdges");
0082             binningUsed = true;
0083           }
0084           binningFound = true;
0085         }
0086       }
0087       if (!binningFound)
0088         throw cms::Exception("InputError")
0089             << "Binning " << cutParameter << " not recognized! Please pass the definition to the module.\n";
0090 
0091     } else if (cutVariable == "tag") {
0092       tag_ = cutParameter;
0093     } else if (cutVariable == "autotag") {
0094       // autotag is only used if no manual tag is set
0095       if (tag_.empty())
0096         tag_ = cutParameter;
0097     } else {
0098       throw cms::Exception("InputError")
0099           << "Path-specific cut " + cutVariable +
0100                  " not recognized. The following options can be user: absEtaMax, absEtaCut, absEtaMin, ptMax, ptMin, "
0101                  "ptCut, etMax, etMin, etCut, region, bins and tag.\n";
0102     }
0103 
0104     if (!rangeCutConfig.empty())
0105       pathSpecificCutsVector_.push_back(rangeCutConfig);
0106   }
0107 }