CMS 3D CMS Logo

Functions

egHLT::trigTools Namespace Reference

Functions

void filterInactiveTightLooseTriggers (std::vector< std::string > &namesToFilter, const std::vector< std::string > &activeFilters)
void filterInactiveTriggers (std::vector< std::string > &namesToFilter, const std::vector< std::string > &activeFilters)
void getActiveFilters (const HLTConfigProvider &hltConfig, std::vector< std::string > &activeFilters)
float getEtThresFromName (const std::string &trigName)
TrigCodes::TrigBitSet getFiltersPassed (const std::vector< std::pair< std::string, int > > &filters, const trigger::TriggerEvent *trigEvt, const std::string &hltTag)
std::string getL1SeedFilterOfPath (const HLTConfigProvider &hltConfig, const std::string &path)
int getMinNrObjsRequiredByFilter (const std::string &filterName)
template<class T >
void setFiltersObjPasses (std::vector< T > &objs, const std::vector< std::string > &filters, const std::vector< std::pair< std::string, std::string > > &l1PreAndSeedFilters, const TrigCodes::TrigBitSet &evtTrigBits, const trigger::TriggerEvent *trigEvt, const std::string &hltTag)
void translateFiltersToPathNames (const HLTConfigProvider &hltConfig, const std::vector< std::string > &filters, std::vector< std::string > &paths)

Function Documentation

void egHLT::trigTools::filterInactiveTightLooseTriggers ( std::vector< std::string > &  namesToFilter,
const std::vector< std::string > &  activeFilters 
)

Definition at line 107 of file EgHLTTrigTools.cc.

References h::names, and split.

Referenced by EgHLTOfflineClient::beginRun(), and EgHLTOfflineSource::filterTriggers().

{
  //tempory vector to store the filtered results
  std::vector<std::string> filteredNames;
  
  for(size_t inputFilterNr=0;inputFilterNr<namesToFilter.size();inputFilterNr++){
    std::vector<std::string> names;
    boost::split(names,namesToFilter[inputFilterNr],boost::is_any_of(std::string(":")));
    if(names.size()!=2) continue; //format incorrect, reject it
    if(std::binary_search(activeFilters.begin(),activeFilters.end(),names[0]) &&
       std::binary_search(activeFilters.begin(),activeFilters.end(),names[1])){ //both filters are valid
      filteredNames.push_back(namesToFilter[inputFilterNr]);
    }
  }
  
  namesToFilter.swap(filteredNames);
}
void egHLT::trigTools::filterInactiveTriggers ( std::vector< std::string > &  namesToFilter,
const std::vector< std::string > &  activeFilters 
)

Definition at line 92 of file EgHLTTrigTools.cc.

Referenced by EgHLTOfflineSummaryClient::beginRun(), EgHLTOfflineClient::beginRun(), and EgHLTOfflineSource::filterTriggers().

{
  //tempory vector to store the filtered results
  std::vector<std::string> filteredNames;
  
  for(size_t inputFilterNr=0;inputFilterNr<namesToFilter.size();inputFilterNr++){
    if(std::binary_search(activeFilters.begin(),activeFilters.end(),namesToFilter[inputFilterNr])){
      filteredNames.push_back(namesToFilter[inputFilterNr]);
    }
  }
  
  namesToFilter.swap(filteredNames);
}
void egHLT::trigTools::getActiveFilters ( const HLTConfigProvider hltConfig,
std::vector< std::string > &  activeFilters 
)

Definition at line 67 of file EgHLTTrigTools.cc.

References filters, HLTConfigProvider::moduleLabels(), pathName(), HLTConfigProvider::size(), python::multivaluedict::sort(), and HLTConfigProvider::triggerName().

Referenced by EgHLTOfflineSummaryClient::beginRun(), EgHLTOfflineClient::beginRun(), and EgHLTOfflineSource::filterTriggers().

{
  activeFilters.clear();

  for(size_t pathNr=0;pathNr<hltConfig.size();pathNr++){
    const std::string& pathName = hltConfig.triggerName(pathNr);
    if(pathName.find("HLT_")==0){ //hlt path as they all start with HLT_XXXX
  
      std::string lastFilter;
      const std::vector<std::string>& filters = hltConfig.moduleLabels(pathNr);
      if(!filters.empty()){
        if(filters.back()=="hltBoolEnd" && filters.size()>=2){
          activeFilters.push_back(filters[filters.size()-2]); //2nd to last element is the last filter, useally the case as last is hltBool except for ES bits
        }else activeFilters.push_back(filters.back());
      }
    }//end hlt path check
  }//end path loop over

  std::sort(activeFilters.begin(),activeFilters.end());
  
}
float egHLT::trigTools::getEtThresFromName ( const std::string &  trigName)

Definition at line 186 of file EgHLTTrigTools.cc.

Referenced by egHLT::MonElemFuncs::addTightLooseTrigHist(), and egHLT::MonElemFuncs::initTrigTagProbeHists().

{
  size_t etStrPos = trigName.find("Et");
  while(etStrPos!=std::string::npos && trigName.find_first_of("1234567890",etStrPos)!=etStrPos+2){
    etStrPos = trigName.find("Et",etStrPos+1);  
  }
  if(etStrPos!=std::string::npos && trigName.find_first_of("1234567890",etStrPos)==etStrPos+2){
    size_t endOfEtValStr = trigName.find_first_not_of("1234567890",etStrPos+2);  

    std::istringstream etValStr(trigName.substr(etStrPos+2,endOfEtValStr-etStrPos-2));
    float etVal;
    etValStr>> etVal;
    return etVal;
    
  }
  return 0;

}
TrigCodes::TrigBitSet egHLT::trigTools::getFiltersPassed ( const std::vector< std::pair< std::string, int > > &  filters,
const trigger::TriggerEvent trigEvt,
const std::string &  hltTag 
)

Definition at line 10 of file EgHLTTrigTools.cc.

References alcaDQMUpload::encode(), trigger::TriggerEvent::filterIndex(), trigger::TriggerEvent::filterKeys(), filters, first, egHLT::TrigCodes::getCode(), and edm::second().

Referenced by egHLT::OffHelper::setTrigInfo().

{
  TrigCodes::TrigBitSet evtTrigs;
  for(size_t filterNrInVec=0;filterNrInVec<filters.size();filterNrInVec++){
    size_t filterNrInEvt = trigEvt->filterIndex(edm::InputTag(filters[filterNrInVec].first,"",hltTag).encode());
    const TrigCodes::TrigBitSet filterCode = TrigCodes::getCode(filters[filterNrInVec].first.c_str());
    if(filterNrInEvt<trigEvt->sizeFilters()){ //filter found in event, however this only means that something passed the previous filter
      const trigger::Keys& trigKeys = trigEvt->filterKeys(filterNrInEvt);
      if(static_cast<int>(trigKeys.size())>=filters[filterNrInVec].second){
        evtTrigs |=filterCode; //filter was passed
      }
    }//end check if filter is present
  }//end loop over all filters


  return evtTrigs;

}
std::string egHLT::trigTools::getL1SeedFilterOfPath ( const HLTConfigProvider hltConfig,
const std::string &  path 
)

Definition at line 172 of file EgHLTTrigTools.cc.

References HLTConfigProvider::moduleLabels().

Referenced by egHLT::OffHelper::setupTriggers().

{
  const std::vector<std::string>& modules = hltConfig.moduleLabels(path);

  for(size_t moduleNr=0;moduleNr<modules.size();moduleNr++){
    const std::string& moduleName=modules[moduleNr]; 
    if(moduleName.find("hltL1s")==0) return moduleName; //found l1 seed module
  }
  std::string dummy;
  return dummy;

}
int egHLT::trigTools::getMinNrObjsRequiredByFilter ( const std::string &  filterName)

Definition at line 39 of file EgHLTTrigTools.cc.

References edm::detail::ThreadSafeRegistry< KEY, T, E >::begin(), edm::detail::ThreadSafeRegistry< KEY, T, E >::end(), reco_skim_cfg_mod::filterName, edm::detail::ThreadSafeRegistry< KEY, T, E >::instance(), and NULL.

Referenced by egHLT::OffHelper::setupTriggers().

{
 
  //will return out of for loop once its found it to save time
  const edm::pset::Registry* psetRegistry = edm::pset::Registry::instance();
  if(psetRegistry==NULL) return -1;
  for(edm::pset::Registry::const_iterator psetIt=psetRegistry->begin();psetIt!=psetRegistry->end();++psetIt){ //loop over every pset for every module ever run
    const std::map<std::string,edm::Entry>& mapOfPara  = psetIt->second.tbl(); //contains the parameter name and value for all the parameters of the pset
    const std::map<std::string,edm::Entry>::const_iterator itToModLabel = mapOfPara.find("@module_label"); 
    if(itToModLabel!=mapOfPara.end()){
      if(itToModLabel->second.getString()==filterName){ //moduleName is the filter name, we have found filter, we will now return something
        std::map<std::string,edm::Entry>::const_iterator itToCandCut = mapOfPara.find("ncandcut");
        if(itToCandCut!=mapOfPara.end() && itToCandCut->second.typeCode()=='I') return itToCandCut->second.getInt32();
        else{ //checks if MinN exists and is int32, if not return -1
          itToCandCut = mapOfPara.find("MinN");
          if(itToCandCut!=mapOfPara.end() && itToCandCut->second.typeCode()=='I') return itToCandCut->second.getInt32();
          else return -1;
        }
      }
      
    }
  }
  return -1;
}
template<class T >
void egHLT::trigTools::setFiltersObjPasses ( std::vector< T > &  objs,
const std::vector< std::string > &  filters,
const std::vector< std::pair< std::string, std::string > > &  l1PreAndSeedFilters,
const TrigCodes::TrigBitSet &  evtTrigBits,
const trigger::TriggerEvent trigEvt,
const std::string &  hltTag 
)

Definition at line 40 of file EgHLTTrigTools.h.

References reco::deltaR(), alcaDQMUpload::encode(), eta(), trigger::TriggerEvent::filterIndex(), trigger::TriggerEvent::filterKeys(), first, egHLT::TrigCodes::getCode(), trigger::TriggerEvent::getObjects(), phi, and edm::second().

Referenced by egHLT::OffHelper::setTrigInfo().

  {
    std::vector<TrigCodes::TrigBitSet> partTrigBits(particles.size());
    const double maxDeltaR=0.1;
    for(size_t filterNrInVec=0;filterNrInVec<filters.size();filterNrInVec++){
      size_t filterNrInEvt = trigEvt->filterIndex(edm::InputTag(filters[filterNrInVec],"",hltTag).encode());
      const TrigCodes::TrigBitSet filterCode = TrigCodes::getCode(filters[filterNrInVec].c_str());
      
      if(filterNrInEvt<trigEvt->sizeFilters()){ //filter found in event, something passes it
        const trigger::Keys& trigKeys = trigEvt->filterKeys(filterNrInEvt);  //trigger::Keys is actually a vector<uint16_t> holding the position of trigger objects in the trigger collection passing the filter
        const trigger::TriggerObjectCollection & trigObjColl(trigEvt->getObjects());
        for(size_t partNr=0;partNr<particles.size();partNr++){
          for(trigger::Keys::const_iterator keyIt=trigKeys.begin();keyIt!=trigKeys.end();++keyIt){
            float trigObjEta = trigObjColl[*keyIt].eta();
            float trigObjPhi = trigObjColl[*keyIt].phi();
            if (reco::deltaR(particles[partNr].eta(),particles[partNr].phi(),trigObjEta,trigObjPhi) < maxDeltaR){
            partTrigBits[partNr] |= filterCode;
            }//end dR<maxDeltaR trig obj match test
          }//end loop over all objects passing filter
        }//end loop over particles
      }//end check if filter is present
    }//end loop over all filters
    
    //okay the first element is the key, the second is the filter that exists in trigger event
    for(size_t l1FilterNrInVec=0;l1FilterNrInVec<l1PreAndSeedFilters.size();l1FilterNrInVec++){
      const TrigCodes::TrigBitSet filterCode = TrigCodes::getCode(l1PreAndSeedFilters[l1FilterNrInVec].first.c_str());
      if((filterCode&evtTrigBits)==filterCode){ //check that filter has fired in the event
   
        size_t filterNrInEvt = trigEvt->filterIndex(edm::InputTag(l1PreAndSeedFilters[l1FilterNrInVec].second,"",hltTag).encode());
        
        if(filterNrInEvt<trigEvt->sizeFilters()){ //filter found in event, something passes it
          const trigger::Keys& trigKeys = trigEvt->filterKeys(filterNrInEvt);  //trigger::Keys is actually a vector<uint16_t> holding the position of trigger objects in the trigger collection passing the filter
          const trigger::TriggerObjectCollection & trigObjColl(trigEvt->getObjects());
          for(size_t partNr=0;partNr<particles.size();partNr++){
            for(trigger::Keys::const_iterator keyIt=trigKeys.begin();keyIt!=trigKeys.end();++keyIt){
              float trigObjEta = trigObjColl[*keyIt].eta();
              float trigObjPhi = trigObjColl[*keyIt].phi();
              if (reco::deltaR(particles[partNr].eta(),particles[partNr].phi(),trigObjEta,trigObjPhi) < maxDeltaR){
                partTrigBits[partNr] |= filterCode;
              }//end dR<maxDeltaR trig obj match test
            }//end loop over all objects passing filter
          }//end loop over particles
        }//end check if filter is present
      }//end check if path has fired in the event
    }//end loop over all filters 
    
    for(size_t partNr=0;partNr<particles.size();partNr++) particles[partNr].setTrigBits(partTrigBits[partNr]);
    
  }
void egHLT::trigTools::translateFiltersToPathNames ( const HLTConfigProvider hltConfig,
const std::vector< std::string > &  filters,
std::vector< std::string > &  paths 
)

Definition at line 139 of file EgHLTTrigTools.cc.

References HLTConfigProvider::moduleLabels(), pathName(), HLTConfigProvider::size(), python::multivaluedict::sort(), and HLTConfigProvider::triggerName().

Referenced by EgHLTOfflineSummaryClient::beginRun(), and egHLT::OffHelper::setupTriggers().

{
  
  paths.clear();
  std::vector<std::pair<std::string,std::string> > filtersAndPaths;

  for(size_t pathNr=0;pathNr<hltConfig.size();pathNr++){
    const std::string& pathName = hltConfig.triggerName(pathNr);
    if(pathName.find("HLT_")==0){ //hlt path as they all start with HLT_XXXX
  
      std::string lastFilter;
      const std::vector<std::string>& pathFilters = hltConfig.moduleLabels(pathNr);
      if(!pathFilters.empty()){
        if(pathFilters.back()=="hltBoolEnd" && pathFilters.size()>=2){
          //2nd to last element is the last filter, useally the case as last is hltBool except for ES bits
          filtersAndPaths.push_back(std::make_pair(pathFilters[pathFilters.size()-2],pathName));
        }else filtersAndPaths.push_back(std::make_pair(pathFilters.back(),pathName));
      }
    }//end hlt path check
  }//end path loop over

  std::sort(filtersAndPaths.begin(),filtersAndPaths.end(),StringPairCompare());
  
  for(size_t filterNr=0;filterNr<filters.size();filterNr++){
    typedef std::vector<std::pair<std::string,std::string> >::const_iterator VecIt;
    std::pair<VecIt,VecIt> searchResult = std::equal_range(filtersAndPaths.begin(),filtersAndPaths.end(),filters[filterNr],StringPairCompare());
    if(searchResult.first!=searchResult.second) paths.push_back(searchResult.first->second);
    else paths.push_back(filters[filterNr]);//if cant find the path, just  write the filter
 
  }

}