00001 #include "DQMOffline/Trigger/interface/EgHLTTrigTools.h"
00002
00003 #include "FWCore/ParameterSet/interface/Registry.h"
00004
00005 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
00006
00007 #include <boost/algorithm/string.hpp>
00008 using namespace egHLT;
00009
00010 TrigCodes::TrigBitSet trigTools::getFiltersPassed(const std::vector<std::pair<std::string,int> >& filters,const trigger::TriggerEvent* trigEvt,const std::string& hltTag)
00011 {
00012 TrigCodes::TrigBitSet evtTrigs;
00013 for(size_t filterNrInVec=0;filterNrInVec<filters.size();filterNrInVec++){
00014 size_t filterNrInEvt = trigEvt->filterIndex(edm::InputTag(filters[filterNrInVec].first,"",hltTag).encode());
00015 const TrigCodes::TrigBitSet filterCode = TrigCodes::getCode(filters[filterNrInVec].first.c_str());
00016 if(filterNrInEvt<trigEvt->sizeFilters()){
00017 const trigger::Keys& trigKeys = trigEvt->filterKeys(filterNrInEvt);
00018 if(static_cast<int>(trigKeys.size())>=filters[filterNrInVec].second){
00019 evtTrigs |=filterCode;
00020 }
00021 }
00022 }
00023
00024
00025 return evtTrigs;
00026
00027 }
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 int trigTools::getMinNrObjsRequiredByFilter(const std::string& filterName)
00040 {
00041
00042
00043 const edm::pset::Registry* psetRegistry = edm::pset::Registry::instance();
00044 if(psetRegistry==NULL) return -1;
00045 for(edm::pset::Registry::const_iterator psetIt=psetRegistry->begin();psetIt!=psetRegistry->end();++psetIt){
00046 const std::map<std::string,edm::Entry>& mapOfPara = psetIt->second.tbl();
00047 const std::map<std::string,edm::Entry>::const_iterator itToModLabel = mapOfPara.find("@module_label");
00048 if(itToModLabel!=mapOfPara.end()){
00049 if(itToModLabel->second.getString()==filterName){
00050 std::map<std::string,edm::Entry>::const_iterator itToCandCut = mapOfPara.find("ncandcut");
00051 if(itToCandCut!=mapOfPara.end() && itToCandCut->second.typeCode()=='I') return itToCandCut->second.getInt32();
00052 else{
00053 itToCandCut = mapOfPara.find("MinN");
00054 if(itToCandCut!=mapOfPara.end() && itToCandCut->second.typeCode()=='I') return itToCandCut->second.getInt32();
00055 else return -1;
00056 }
00057 }
00058
00059 }
00060 }
00061 return -1;
00062 }
00063
00064
00065
00066
00067 void trigTools::getActiveFilters(const HLTConfigProvider& hltConfig,std::vector<std::string>& activeFilters)
00068 {
00069 activeFilters.clear();
00070
00071 for(size_t pathNr=0;pathNr<hltConfig.size();pathNr++){
00072 const std::string& pathName = hltConfig.triggerName(pathNr);
00073 if(pathName.find("HLT_")==0){
00074
00075 std::string lastFilter;
00076 const std::vector<std::string>& filters = hltConfig.moduleLabels(pathNr);
00077 if(!filters.empty()){
00078 if(filters.back()=="hltBoolEnd" && filters.size()>=2){
00079 activeFilters.push_back(filters[filters.size()-2]);
00080 }else activeFilters.push_back(filters.back());
00081 }
00082 }
00083 }
00084
00085 std::sort(activeFilters.begin(),activeFilters.end());
00086
00087 }
00088
00089
00090
00091
00092 void trigTools::filterInactiveTriggers(std::vector<std::string>& namesToFilter,const std::vector<std::string>& activeFilters)
00093 {
00094
00095 std::vector<std::string> filteredNames;
00096
00097 for(size_t inputFilterNr=0;inputFilterNr<namesToFilter.size();inputFilterNr++){
00098 if(std::binary_search(activeFilters.begin(),activeFilters.end(),namesToFilter[inputFilterNr])){
00099 filteredNames.push_back(namesToFilter[inputFilterNr]);
00100 }
00101 }
00102
00103 namesToFilter.swap(filteredNames);
00104 }
00105
00106
00107 void trigTools::filterInactiveTightLooseTriggers(std::vector<std::string>& namesToFilter,const std::vector<std::string>& activeFilters)
00108 {
00109
00110 std::vector<std::string> filteredNames;
00111
00112 for(size_t inputFilterNr=0;inputFilterNr<namesToFilter.size();inputFilterNr++){
00113 std::vector<std::string> names;
00114 boost::split(names,namesToFilter[inputFilterNr],boost::is_any_of(std::string(":")));
00115 if(names.size()!=2) continue;
00116 if(std::binary_search(activeFilters.begin(),activeFilters.end(),names[0]) &&
00117 std::binary_search(activeFilters.begin(),activeFilters.end(),names[1])){
00118 filteredNames.push_back(namesToFilter[inputFilterNr]);
00119 }
00120 }
00121
00122 namesToFilter.swap(filteredNames);
00123 }
00124
00125
00126
00127 class StringPairCompare {
00128 public:
00129 bool operator()(const std::pair<std::string,std::string>&lhs,
00130 const std::pair<std::string,std::string>& rhs)const{return keyLess(lhs.first,rhs.first);}
00131 bool operator()(const std::pair<std::string,std::string>&lhs,
00132 const std::pair<std::string,std::string>::first_type& rhs)const{return keyLess(lhs.first,rhs);}
00133 bool operator()(const std::pair<std::string,std::string>::first_type &lhs,
00134 const std::pair<std::string,std::string>& rhs)const{return keyLess(lhs,rhs.first);}
00135 private:
00136 bool keyLess(const std::pair<std::string,std::string>::first_type& k1,const std::pair<std::string,std::string>::first_type& k2)const{return k1<k2;}
00137 };
00138
00139 void trigTools::translateFiltersToPathNames(const HLTConfigProvider& hltConfig,const std::vector<std::string>& filters,std::vector<std::string>& paths)
00140 {
00141
00142 paths.clear();
00143 std::vector<std::pair<std::string,std::string> > filtersAndPaths;
00144
00145 for(size_t pathNr=0;pathNr<hltConfig.size();pathNr++){
00146 const std::string& pathName = hltConfig.triggerName(pathNr);
00147 if(pathName.find("HLT_")==0){
00148
00149 std::string lastFilter;
00150 const std::vector<std::string>& pathFilters = hltConfig.moduleLabels(pathNr);
00151 if(!pathFilters.empty()){
00152 if(pathFilters.back()=="hltBoolEnd" && pathFilters.size()>=2){
00153
00154 filtersAndPaths.push_back(std::make_pair(pathFilters[pathFilters.size()-2],pathName));
00155 }else filtersAndPaths.push_back(std::make_pair(pathFilters.back(),pathName));
00156 }
00157 }
00158 }
00159
00160 std::sort(filtersAndPaths.begin(),filtersAndPaths.end(),StringPairCompare());
00161
00162 for(size_t filterNr=0;filterNr<filters.size();filterNr++){
00163 typedef std::vector<std::pair<std::string,std::string> >::const_iterator VecIt;
00164 std::pair<VecIt,VecIt> searchResult = std::equal_range(filtersAndPaths.begin(),filtersAndPaths.end(),filters[filterNr],StringPairCompare());
00165 if(searchResult.first!=searchResult.second) paths.push_back(searchResult.first->second);
00166 else paths.push_back(filters[filterNr]);
00167
00168 }
00169
00170 }
00171
00172 std::string trigTools::getL1SeedFilterOfPath(const HLTConfigProvider& hltConfig,const std::string& path)
00173 {
00174 const std::vector<std::string>& modules = hltConfig.moduleLabels(path);
00175
00176 for(size_t moduleNr=0;moduleNr<modules.size();moduleNr++){
00177 const std::string& moduleName=modules[moduleNr];
00178 if(moduleName.find("hltL1s")==0) return moduleName;
00179 }
00180 std::string dummy;
00181 return dummy;
00182
00183 }
00184
00185
00186 float trigTools::getEtThresFromName(const std::string& trigName)
00187 {
00188 size_t etStrPos = trigName.find("Et");
00189 while(etStrPos!=std::string::npos && trigName.find_first_of("1234567890",etStrPos)!=etStrPos+2){
00190 etStrPos = trigName.find("Et",etStrPos+1);
00191 }
00192 if(etStrPos!=std::string::npos && trigName.find_first_of("1234567890",etStrPos)==etStrPos+2){
00193 size_t endOfEtValStr = trigName.find_first_not_of("1234567890",etStrPos+2);
00194
00195 std::istringstream etValStr(trigName.substr(etStrPos+2,endOfEtValStr-etStrPos-2));
00196 float etVal;
00197 etValStr>> etVal;
00198 return etVal;
00199
00200 }
00201 return 0;
00202
00203 }