CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DQMOffline/Trigger/interface/EgHLTTrigTools.h

Go to the documentation of this file.
00001 #ifndef DQMOFFLINE_TRIGGER_EGHLTTRIGTOOLS
00002 #define DQMOFFLINE_TRIGGER_EGHLTTRIGTOOLS
00003 
00004 #include "DQMOffline/Trigger/interface/EgHLTTrigCodes.h"
00005 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
00006 #include "DataFormats/Common/interface/Handle.h"
00007 #include "DataFormats/Math/interface/deltaR.h"
00008 
00009 class HLTConfigProvider;
00010 
00011 namespace egHLT {
00012   
00013   namespace trigTools {
00014     TrigCodes::TrigBitSet getFiltersPassed(const std::vector<std::pair<std::string,int> >& filters,const trigger::TriggerEvent* trigEvt,const std::string& hltTag);
00015     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 );
00016     int getMinNrObjsRequiredByFilter(const std::string& filterName); //slow function, call at begin job and cache results
00017 
00018     //reads hlt config and works out which are the active last filters stored in trigger summary, is sorted
00019     void getActiveFilters(const HLTConfigProvider& hltConfig,std::vector<std::string>& activeFilters);
00020     //---Morse test--------
00021     //void getPhoton30(const HLTConfigProvider& hltConfig,std::vector<std::string>& activeFilters);
00022     //------------------
00023     //filters a list of filternames removing any filters which are not in active filters, assumes active filters is sorted
00024     void filterInactiveTriggers(std::vector<std::string>& namesToFilter,const std::vector<std::string>& activeFilters);
00025     //filters a list of filterName1:filterName2 removing any entry for which either filter is not in activeFilters, assumes active filters is sorted
00026     void filterInactiveTightLooseTriggers(std::vector<std::string>& namesToFilter,const std::vector<std::string>& activeFilters);
00027 
00028     void translateFiltersToPathNames(const HLTConfigProvider& hltConfig,const std::vector<std::string>& filters,std::vector<std::string>& paths);
00029     std::string getL1SeedFilterOfPath(const HLTConfigProvider& hltConfig,const std::string& path);
00030 
00031     //looks for string Et and then looks for a number after that (currently the standard of all E/g triggers)
00032     //returns 0 if unsuccessful
00033     float getEtThresFromName(const std::string& trigName);
00034   }
00035   
00036   //I have the horrible feeling that I'm converting into an intermediatry format and then coverting back again
00037   //Okay how this works
00038   //1) create a TrigBitSet for each particle set to 0 initally
00039   //2) loop over each filter, for each particle that passes the filter, set the appropriate bit in the TrigBitSet
00040   //3) after that, loop over each particle setting that its TrigBitSet which has been calculated
00041   //4) because L1 pre-scaled paths are special, we only set those if an event wide trigger has been set
00042   template <class T>
00043   void trigTools::setFiltersObjPasses(std::vector<T>& particles,const std::vector<std::string>& filters,
00044                                       const std::vector<std::pair<std::string,std::string> >& l1PreAndSeedFilters,
00045                                       const TrigCodes::TrigBitSet& evtTrigBits,
00046                                       const trigger::TriggerEvent* trigEvt,const std::string& hltTag)
00047   {
00048     std::vector<TrigCodes::TrigBitSet> partTrigBits(particles.size());
00049     const double maxDeltaR=0.1;
00050     for(size_t filterNrInVec=0;filterNrInVec<filters.size();filterNrInVec++){
00051       size_t filterNrInEvt = trigEvt->filterIndex(edm::InputTag(filters[filterNrInVec],"",hltTag).encode());
00052       const TrigCodes::TrigBitSet filterCode = TrigCodes::getCode(filters[filterNrInVec].c_str());
00053       
00054       if(filterNrInEvt<trigEvt->sizeFilters()){ //filter found in event, something passes it
00055         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
00056         const trigger::TriggerObjectCollection & trigObjColl(trigEvt->getObjects());
00057         for(size_t partNr=0;partNr<particles.size();partNr++){
00058           for(trigger::Keys::const_iterator keyIt=trigKeys.begin();keyIt!=trigKeys.end();++keyIt){
00059             float trigObjEta = trigObjColl[*keyIt].eta();
00060             float trigObjPhi = trigObjColl[*keyIt].phi();
00061             if (reco::deltaR(particles[partNr].eta(),particles[partNr].phi(),trigObjEta,trigObjPhi) < maxDeltaR){
00062             partTrigBits[partNr] |= filterCode;
00063             }//end dR<maxDeltaR trig obj match test
00064           }//end loop over all objects passing filter
00065         }//end loop over particles
00066       }//end check if filter is present
00067     }//end loop over all filters
00068     
00069     //okay the first element is the key, the second is the filter that exists in trigger event
00070     for(size_t l1FilterNrInVec=0;l1FilterNrInVec<l1PreAndSeedFilters.size();l1FilterNrInVec++){
00071       const TrigCodes::TrigBitSet filterCode = TrigCodes::getCode(l1PreAndSeedFilters[l1FilterNrInVec].first.c_str());
00072       if((filterCode&evtTrigBits)==filterCode){ //check that filter has fired in the event
00073    
00074         size_t filterNrInEvt = trigEvt->filterIndex(edm::InputTag(l1PreAndSeedFilters[l1FilterNrInVec].second,"",hltTag).encode());
00075         
00076         if(filterNrInEvt<trigEvt->sizeFilters()){ //filter found in event, something passes it
00077           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
00078           const trigger::TriggerObjectCollection & trigObjColl(trigEvt->getObjects());
00079           for(size_t partNr=0;partNr<particles.size();partNr++){
00080             for(trigger::Keys::const_iterator keyIt=trigKeys.begin();keyIt!=trigKeys.end();++keyIt){
00081               float trigObjEta = trigObjColl[*keyIt].eta();
00082               float trigObjPhi = trigObjColl[*keyIt].phi();
00083               if (reco::deltaR(particles[partNr].eta(),particles[partNr].phi(),trigObjEta,trigObjPhi) < maxDeltaR){
00084                 partTrigBits[partNr] |= filterCode;
00085               }//end dR<maxDeltaR trig obj match test
00086             }//end loop over all objects passing filter
00087           }//end loop over particles
00088         }//end check if filter is present
00089       }//end check if path has fired in the event
00090     }//end loop over all filters 
00091     
00092     for(size_t partNr=0;partNr<particles.size();partNr++) particles[partNr].setTrigBits(partTrigBits[partNr]);
00093     
00094   }
00095 }  
00096 #endif
00097