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
00086 std::sort(activeFilters.begin(),activeFilters.end());
00087
00088 }
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 void trigTools::filterInactiveTriggers(std::vector<std::string>& namesToFilter,const std::vector<std::string>& activeFilters)
00122 {
00123
00124 std::vector<std::string> filteredNames;
00125
00126 for(size_t inputFilterNr=0;inputFilterNr<namesToFilter.size();inputFilterNr++){
00127 if(std::binary_search(activeFilters.begin(),activeFilters.end(),namesToFilter[inputFilterNr])){
00128 filteredNames.push_back(namesToFilter[inputFilterNr]);
00129 }
00130 }
00131
00132 namesToFilter.swap(filteredNames);
00133 }
00134
00135
00136 void trigTools::filterInactiveTightLooseTriggers(std::vector<std::string>& namesToFilter,const std::vector<std::string>& activeFilters)
00137 {
00138
00139 std::vector<std::string> filteredNames;
00140
00141 for(size_t inputFilterNr=0;inputFilterNr<namesToFilter.size();inputFilterNr++){
00142 std::vector<std::string> names;
00143 boost::split(names,namesToFilter[inputFilterNr],boost::is_any_of(std::string(":")));
00144 if(names.size()!=2) continue;
00145 if(std::binary_search(activeFilters.begin(),activeFilters.end(),names[0]) &&
00146 std::binary_search(activeFilters.begin(),activeFilters.end(),names[1])){
00147 filteredNames.push_back(namesToFilter[inputFilterNr]);
00148 }
00149 }
00150
00151 namesToFilter.swap(filteredNames);
00152 }
00153
00154
00155
00156 class StringPairCompare {
00157 public:
00158 bool operator()(const std::pair<std::string,std::string>&lhs,
00159 const std::pair<std::string,std::string>& rhs)const{return keyLess(lhs.first,rhs.first);}
00160 bool operator()(const std::pair<std::string,std::string>&lhs,
00161 const std::pair<std::string,std::string>::first_type& rhs)const{return keyLess(lhs.first,rhs);}
00162 bool operator()(const std::pair<std::string,std::string>::first_type &lhs,
00163 const std::pair<std::string,std::string>& rhs)const{return keyLess(lhs,rhs.first);}
00164 private:
00165 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;}
00166 };
00167
00168 void trigTools::translateFiltersToPathNames(const HLTConfigProvider& hltConfig,const std::vector<std::string>& filters,std::vector<std::string>& paths)
00169 {
00170
00171 paths.clear();
00172 std::vector<std::pair<std::string,std::string> > filtersAndPaths;
00173
00174 for(size_t pathNr=0;pathNr<hltConfig.size();pathNr++){
00175 const std::string& pathName = hltConfig.triggerName(pathNr);
00176 if(pathName.find("HLT_")==0){
00177
00178 std::string lastFilter;
00179 const std::vector<std::string>& pathFilters = hltConfig.moduleLabels(pathNr);
00180 if(!pathFilters.empty()){
00181 if(pathFilters.back()=="hltBoolEnd" && pathFilters.size()>=2){
00182
00183 filtersAndPaths.push_back(std::make_pair(pathFilters[pathFilters.size()-2],pathName));
00184 }else filtersAndPaths.push_back(std::make_pair(pathFilters.back(),pathName));
00185 }
00186 }
00187 }
00188
00189 std::sort(filtersAndPaths.begin(),filtersAndPaths.end(),StringPairCompare());
00190
00191 for(size_t filterNr=0;filterNr<filters.size();filterNr++){
00192 typedef std::vector<std::pair<std::string,std::string> >::const_iterator VecIt;
00193 std::pair<VecIt,VecIt> searchResult = std::equal_range(filtersAndPaths.begin(),filtersAndPaths.end(),filters[filterNr],StringPairCompare());
00194 if(searchResult.first!=searchResult.second) paths.push_back(searchResult.first->second);
00195 else paths.push_back(filters[filterNr]);
00196
00197
00198
00199 }
00200
00201 }
00202
00203 std::string trigTools::getL1SeedFilterOfPath(const HLTConfigProvider& hltConfig,const std::string& path)
00204 {
00205 const std::vector<std::string>& modules = hltConfig.moduleLabels(path);
00206
00207 for(size_t moduleNr=0;moduleNr<modules.size();moduleNr++){
00208 const std::string& moduleName=modules[moduleNr];
00209 if(moduleName.find("hltL1s")==0) return moduleName;
00210 }
00211 std::string dummy;
00212 return dummy;
00213
00214 }
00215
00216
00217 float trigTools::getEtThresFromName(const std::string& trigName)
00218 {
00219 size_t etStrPos = trigName.find("Et");
00220 while(etStrPos!=std::string::npos && trigName.find_first_of("1234567890",etStrPos)!=etStrPos+2){
00221 etStrPos = trigName.find("Et",etStrPos+1);
00222 }
00223 if(etStrPos!=std::string::npos && trigName.find_first_of("1234567890",etStrPos)==etStrPos+2){
00224 size_t endOfEtValStr = trigName.find_first_not_of("1234567890",etStrPos+2);
00225
00226 std::istringstream etValStr(trigName.substr(etStrPos+2,endOfEtValStr-etStrPos-2));
00227 float etVal;
00228 etValStr>> etVal;
00229 return etVal;
00230
00231 }
00232 return 0;
00233
00234 }