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("nZcandcut");
00054 if(itToCandCut!=mapOfPara.end() && itToCandCut->second.typeCode()=='I') return itToCandCut->second.getInt32();
00055 else{
00056 itToCandCut = mapOfPara.find("MinN");
00057 if(itToCandCut!=mapOfPara.end() && itToCandCut->second.typeCode()=='I') return itToCandCut->second.getInt32();
00058 else{
00059 itToCandCut = mapOfPara.find("minN");
00060 if(itToCandCut!=mapOfPara.end() && itToCandCut->second.typeCode()=='I') return itToCandCut->second.getInt32();
00061 else return -1;
00062 }
00063 }
00064 }
00065 }
00066 }
00067 }
00068 return -1;
00069 }
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 void trigTools::getActiveFilters(const HLTConfigProvider& hltConfig,std::vector<std::string>& activeFilters,std::vector<std::string>& activeEleFilters,std::vector<std::string>& activeEle2LegFilters,std::vector<std::string>& activePhoFilters,std::vector<std::string>& activePho2LegFilters)
00102 {
00103
00104 activeFilters.clear();
00105 activeEleFilters.clear();
00106 activeEle2LegFilters.clear();
00107 activePhoFilters.clear();
00108 activePho2LegFilters.clear();
00109
00110 for(size_t pathNr=0;pathNr<hltConfig.size();pathNr++){
00111 const std::string& pathName = hltConfig.triggerName(pathNr);
00112 if(pathName.find("HLT_")==0){
00113 if((pathName.find("Photon")==4 || pathName.find("Ele")==4 || pathName.find("EG")==4 || pathName.find("Activity")==4 || pathName.find("Physics")==4)
00114 && (pathName.find("Jet")==pathName.npos && pathName.find("Muon")==pathName.npos
00115 && pathName.find("Tau")==pathName.npos && pathName.find("HT")==pathName.npos
00116 && pathName.find("MR")==pathName.npos && pathName.find("LEITI")==pathName.npos
00117 && pathName.find("Jpsi")==pathName.npos && pathName.find("Ups")==pathName.npos ) ){
00118
00119 const std::vector<std::string>& filters = hltConfig.saveTagsModules(pathNr);
00120
00121
00122
00123
00124 if(!filters.empty()){
00125
00126 for(size_t filter=0;filter<filters.size();filter++){
00127 if(filters[filter].find("Filter")!=filters[filter].npos){
00128
00129 if(
00130 (filter<filters.size()-1 && trigTools::getMinNrObjsRequiredByFilter(filters[filter])==1 && trigTools::getMinNrObjsRequiredByFilter(filters[filter+1])==2)
00131 || (filter<filters.size()-1 && trigTools::getMinNrObjsRequiredByFilter(filters[filter])==1 && trigTools::getMinNrObjsRequiredByFilter(filters[filter+1])==1 && filters[filter+1].find("Mass")!=filters[filter+1].npos)
00132 || (filter<filters.size()-1 && trigTools::getMinNrObjsRequiredByFilter(filters[filter])==1 && trigTools::getMinNrObjsRequiredByFilter(filters[filter+1])==1 && filters[filter+1].find("FEM")!=filters[filter+1].npos)
00133 || (filter<filters.size()-1 && trigTools::getMinNrObjsRequiredByFilter(filters[filter])==1 && trigTools::getMinNrObjsRequiredByFilter(filters[filter+1])==1 && filters[filter+1].find("PFMT")!=filters[filter+1].npos)
00134 || filter==filters.size()-1 ){
00135 activeFilters.push_back(filters[filter]);
00136
00137 if(pathName.find("Photon")!=pathName.npos || pathName.find("Activity")!=pathName.npos || pathName.find("Physics")!=pathName.npos ){
00138 activePhoFilters.push_back(filters[filter]);
00139 int posPho = pathName.find("Pho")+1;
00140 if( pathName.find("Pho",posPho)!=pathName.npos || pathName.find("SC",posPho)!=pathName.npos ){
00141
00142 activePho2LegFilters.push_back(filters[filter]);
00143
00144 }
00145 }
00146 if(pathName.find("Ele")!=pathName.npos || pathName.find("Activity")!=pathName.npos || pathName.find("Physics")!=pathName.npos ){
00147 activeEleFilters.push_back(filters[filter]);
00148 int posEle = pathName.find("Ele")+1;
00149 if( pathName.find("Ele",posEle)!=pathName.npos || pathName.find("SC",posEle)!=pathName.npos ){
00150 if(
00151 (filter<filters.size()-1 && trigTools::getMinNrObjsRequiredByFilter(filters[filter])==1 && trigTools::getMinNrObjsRequiredByFilter(filters[filter+1])==2)
00152 || (filter<filters.size()-1 && trigTools::getMinNrObjsRequiredByFilter(filters[filter])==1 && trigTools::getMinNrObjsRequiredByFilter(filters[filter+1])==1 && filters[filter+1].find("Mass")!=filters[filter+1].npos)
00153 || (filter<filters.size()-1 && trigTools::getMinNrObjsRequiredByFilter(filters[filter])==1 && trigTools::getMinNrObjsRequiredByFilter(filters[filter+1])==1 && filters[filter+1].find("SC")!=filters[filter+1].npos)
00154 || (filter<filters.size()-1 && trigTools::getMinNrObjsRequiredByFilter(filters[filter])==1 && trigTools::getMinNrObjsRequiredByFilter(filters[filter+1])==1 && filters[filter+1].find("FEM")!=filters[filter+1].npos)
00155 ){
00156
00157 activeEle2LegFilters.push_back(filters[filter]+"::"+filters[filter+1]);
00158
00159 }
00160 }
00161 }
00162 }
00163 }
00164 }
00165
00166
00167 }
00168 }
00169 }
00170 }
00171
00172
00173
00174
00175 std::sort(activeFilters.begin(),activeFilters.end());
00176 std::sort(activeEleFilters.begin(),activeEleFilters.end());
00177 std::sort(activeEle2LegFilters.begin(),activeEle2LegFilters.end());
00178 std::sort(activePhoFilters.begin(),activePhoFilters.end());
00179 }
00180
00181
00182
00183
00184
00185 void trigTools::filterInactiveTriggers(std::vector<std::string>& namesToFilter,std::vector<std::string>& activeFilters)
00186 {
00187
00188 std::vector<std::string> filteredNames;
00189
00190
00191
00192
00193
00194
00195
00196
00197 filteredNames = activeFilters;
00198 namesToFilter.swap(filteredNames);
00199 }
00200
00201
00202 void trigTools::filterInactiveTightLooseTriggers(std::vector<std::string>& namesToFilter,const std::vector<std::string>& activeFilters)
00203 {
00204
00205 std::vector<std::string> filteredNames;
00206
00207 for(size_t inputFilterNr=0;inputFilterNr<namesToFilter.size();inputFilterNr++){
00208 std::vector<std::string> names;
00209 boost::split(names,namesToFilter[inputFilterNr],boost::is_any_of(std::string(":")));
00210 if(names.size()!=2) continue;
00211 if(std::binary_search(activeFilters.begin(),activeFilters.end(),names[0]) &&
00212 std::binary_search(activeFilters.begin(),activeFilters.end(),names[1])){
00213 filteredNames.push_back(namesToFilter[inputFilterNr]);
00214 }
00215 }
00216
00217 namesToFilter.swap(filteredNames);
00218 }
00219
00220
00221
00222 class StringPairCompare {
00223 public:
00224 bool operator()(const std::pair<std::string,std::string>&lhs,
00225 const std::pair<std::string,std::string>& rhs)const{return keyLess(lhs.first,rhs.first);}
00226 bool operator()(const std::pair<std::string,std::string>&lhs,
00227 const std::pair<std::string,std::string>::first_type& rhs)const{return keyLess(lhs.first,rhs);}
00228 bool operator()(const std::pair<std::string,std::string>::first_type &lhs,
00229 const std::pair<std::string,std::string>& rhs)const{return keyLess(lhs,rhs.first);}
00230 private:
00231 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;}
00232 };
00233
00234 void trigTools::translateFiltersToPathNames(const HLTConfigProvider& hltConfig,const std::vector<std::string>& filters,std::vector<std::string>& paths)
00235 {
00236
00237 paths.clear();
00238 std::vector<std::pair<std::string,std::string> > filtersAndPaths;
00239
00240 for(size_t pathNr=0;pathNr<hltConfig.size();pathNr++){
00241 const std::string& pathName = hltConfig.triggerName(pathNr);
00242 if(pathName.find("HLT_")==0){
00243
00244 std::string lastFilter;
00245 const std::vector<std::string>& pathFilters = hltConfig.moduleLabels(pathNr);
00246 if(!pathFilters.empty()){
00247 if(pathFilters.back()=="hltBoolEnd" && pathFilters.size()>=2){
00248
00249 filtersAndPaths.push_back(std::make_pair(pathFilters[pathFilters.size()-2],pathName));
00250 }else filtersAndPaths.push_back(std::make_pair(pathFilters.back(),pathName));
00251 }
00252 }
00253 }
00254
00255 std::sort(filtersAndPaths.begin(),filtersAndPaths.end(),StringPairCompare());
00256
00257 for(size_t filterNr=0;filterNr<filters.size();filterNr++){
00258 typedef std::vector<std::pair<std::string,std::string> >::const_iterator VecIt;
00259 std::pair<VecIt,VecIt> searchResult = std::equal_range(filtersAndPaths.begin(),filtersAndPaths.end(),filters[filterNr],StringPairCompare());
00260 if(searchResult.first!=searchResult.second) paths.push_back(searchResult.first->second);
00261 else paths.push_back(filters[filterNr]);
00262
00263
00264
00265 }
00266
00267 }
00268
00269 std::string trigTools::getL1SeedFilterOfPath(const HLTConfigProvider& hltConfig,const std::string& path)
00270 {
00271 const std::vector<std::string>& modules = hltConfig.moduleLabels(path);
00272
00273 for(size_t moduleNr=0;moduleNr<modules.size();moduleNr++){
00274 const std::string& moduleName=modules[moduleNr];
00275 if(moduleName.find("hltL1s")==0) return moduleName;
00276 }
00277 std::string dummy;
00278 return dummy;
00279
00280 }
00281
00282
00283 float trigTools::getEtThresFromName(const std::string& trigName)
00284 {
00285 size_t etStrPos = trigName.find("Et");
00286 while(etStrPos!=std::string::npos && trigName.find_first_of("1234567890",etStrPos)!=etStrPos+2){
00287 etStrPos = trigName.find("Et",etStrPos+1);
00288 }
00289 if(etStrPos!=std::string::npos && trigName.find_first_of("1234567890",etStrPos)==etStrPos+2){
00290 size_t endOfEtValStr = trigName.find_first_not_of("1234567890",etStrPos+2);
00291
00292 std::istringstream etValStr(trigName.substr(etStrPos+2,endOfEtValStr-etStrPos-2));
00293 float etVal;
00294 etValStr>> etVal;
00295 return etVal;
00296
00297 }
00298 return 0;
00299
00300 }
00301
00302
00303
00304 float trigTools::getSecondEtThresFromName(const std::string& trigName)
00305 {
00306 bool isEle=false,isPhoton=false,isEG=false,isEle2=false,isPhoton2=false,isEG2=false,isSC2=false;
00307 size_t etStrPos = trigName.npos;
00308 if( trigName.find("Ele")<trigName.find("Photon") && trigName.find("Ele")<trigName.find("EG") ){
00309 etStrPos=trigName.find("Ele");isEle=true; }
00310 else if( trigName.find("EG")<trigName.find("Photon") && trigName.find("EG")<trigName.find("Ele") ){
00311 etStrPos=trigName.find("EG");isEG=true; }
00312 else if( trigName.find("Photon")<trigName.find("Ele") && trigName.find("Photon")<trigName.find("EG") ){
00313 etStrPos=trigName.find("Photon");isPhoton=true; }
00314
00315
00316
00317
00318
00319 if(etStrPos!=trigName.npos
00320 && ( trigName.find("Ele",etStrPos+1)!=trigName.npos || trigName.find("EG",etStrPos+1)!=trigName.npos
00321 || trigName.find("Photon",etStrPos+1)!=trigName.npos || trigName.find("SC",etStrPos+1)!=trigName.npos)){
00322 if(trigName.find("Ele",etStrPos+1)<trigName.find("Photon",etStrPos+1) && trigName.find("Ele",etStrPos+1)<trigName.find("EG",etStrPos+1) && trigName.find("Ele",etStrPos+1)<trigName.find("SC",etStrPos+1) ){etStrPos=trigName.find("Ele",etStrPos+1);isEle2=true;}
00323 else if(trigName.find("EG",etStrPos+1)<trigName.find("Photon",etStrPos+1) && trigName.find("EG",etStrPos+1)<trigName.find("Ele",etStrPos+1) && trigName.find("EG",etStrPos+1)<trigName.find("SC",etStrPos+1)){etStrPos=trigName.find("EG",etStrPos+1);isEG2=true;}
00324 else if(trigName.find("Photon",etStrPos+1)<trigName.find("EG",etStrPos+1) && trigName.find("Photon",etStrPos+1)<trigName.find("Ele",etStrPos+1) && trigName.find("Photon",etStrPos+1)<trigName.find("SC",etStrPos+1)){etStrPos=trigName.find("Photon",etStrPos+1);isPhoton2=true;}
00325 else if(trigName.find("SC",etStrPos+1)<trigName.find("EG",etStrPos+1) && trigName.find("SC",etStrPos+1)<trigName.find("Ele",etStrPos+1) && trigName.find("SC",etStrPos+1)<trigName.find("Photon",etStrPos+1)){etStrPos=trigName.find("Photon",etStrPos+1);isSC2=true;}
00326
00327
00328 if(isEle2){
00329 if(etStrPos!=trigName.npos && trigName.find_first_of("1234567890",etStrPos)==etStrPos+3){
00330 size_t endOfEtValStr = trigName.find_first_not_of("1234567890",etStrPos+3);
00331
00332 std::istringstream etValStr(trigName.substr(etStrPos+3,endOfEtValStr-etStrPos-3));
00333 float etVal;
00334 etValStr>> etVal;
00335 return etVal;
00336 }
00337 }
00338 if(isEG2 || isSC2){
00339 if(etStrPos!=trigName.npos && trigName.find_first_of("1234567890",etStrPos)==etStrPos+2){
00340 size_t endOfEtValStr = trigName.find_first_not_of("1234567890",etStrPos+2);
00341
00342 std::istringstream etValStr(trigName.substr(etStrPos+2,endOfEtValStr-etStrPos-2));
00343 float etVal;
00344 etValStr>> etVal;
00345 return etVal;
00346 }
00347 }
00348
00349 if(isPhoton2){
00350 if(etStrPos!=trigName.npos && trigName.find_first_of("1234567890",etStrPos)==etStrPos+6){
00351 size_t endOfEtValStr = trigName.find_first_not_of("1234567890",etStrPos+6);
00352
00353 std::istringstream etValStr(trigName.substr(etStrPos+6,endOfEtValStr-etStrPos-6));
00354 float etVal;
00355 etValStr>> etVal;
00356 return etVal;
00357 }
00358 }
00359 }
00360 else if(etStrPos!=trigName.npos){
00361 if(isEle){
00362 if(etStrPos!=trigName.npos && trigName.find_first_of("1234567890",etStrPos)==etStrPos+3){
00363 size_t endOfEtValStr = trigName.find_first_not_of("1234567890",etStrPos+3);
00364
00365 std::istringstream etValStr(trigName.substr(etStrPos+3,endOfEtValStr-etStrPos-3));
00366 float etVal;
00367 etValStr>> etVal;
00368 return etVal;
00369 }
00370 }
00371 if(isEG){
00372 if(etStrPos!=trigName.npos && trigName.find_first_of("1234567890",etStrPos)==etStrPos+2){
00373 size_t endOfEtValStr = trigName.find_first_not_of("1234567890",etStrPos+2);
00374
00375 std::istringstream etValStr(trigName.substr(etStrPos+2,endOfEtValStr-etStrPos-2));
00376 float etVal;
00377 etValStr>> etVal;
00378 return etVal;
00379 }
00380 }
00381
00382 if(isPhoton){
00383 if(etStrPos!=trigName.npos && trigName.find_first_of("1234567890",etStrPos)==etStrPos+6){
00384 size_t endOfEtValStr = trigName.find_first_not_of("1234567890",etStrPos+6);
00385
00386 std::istringstream etValStr(trigName.substr(etStrPos+6,endOfEtValStr-etStrPos-6));
00387 float etVal;
00388 etValStr>> etVal;
00389 return etVal;
00390 }
00391 }
00392 }
00393
00394 return 0;
00395
00396 }