Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:13:18

0001 #ifndef DQMOFFLINE_TRIGGER_EGHLTTRIGTOOLS
0002 #define DQMOFFLINE_TRIGGER_EGHLTTRIGTOOLS
0003 
0004 #include "DQMOffline/Trigger/interface/EgHLTTrigCodes.h"
0005 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
0006 #include "DataFormats/Common/interface/Handle.h"
0007 #include "DataFormats/Math/interface/deltaR.h"
0008 #include <vector>
0009 
0010 class HLTConfigProvider;
0011 
0012 namespace egHLT {
0013 
0014   namespace trigTools {
0015     TrigCodes::TrigBitSet getFiltersPassed(const std::vector<std::pair<std::string, int> >& filters,
0016                                            const trigger::TriggerEvent* trigEvt,
0017                                            const std::string& hltTag,
0018                                            const TrigCodes& trigCodes);
0019 
0020     template <class T>
0021     void setFiltersObjPasses(std::vector<T>& objs,
0022                              const std::vector<std::string>& filters,
0023                              const std::vector<std::pair<std::string, std::string> >& l1PreAndSeedFilters,
0024                              const TrigCodes::TrigBitSet& evtTrigBits,
0025                              const TrigCodes& trigCodes,
0026                              const trigger::TriggerEvent* trigEvt,
0027                              const std::string& hltTag);
0028 
0029     template <class T, class U>
0030     void fillHLTposition(T& obj,
0031                          U& hltData,
0032                          const std::vector<std::string>& filters,
0033                          const trigger::TriggerEvent* trigEvt,
0034                          const std::string& hltTag);
0035     std::vector<int> getMinNrObjsRequiredByFilter(
0036         const std::vector<std::string>& filterName);  //slow function, call at begin job and cache results
0037 
0038     //reads hlt config and works out which are the active last filters stored in trigger summary, is sorted
0039     void getActiveFilters(const HLTConfigProvider& hltConfig,
0040                           std::vector<std::string>& activeFilters,
0041                           std::vector<std::string>& activeEleFilters,
0042                           std::vector<std::string>& activeEle2LegFilters,
0043                           std::vector<std::string>& activePhoFilters,
0044                           std::vector<std::string>& activePho2LegFilters);
0045     //---Morse test--------
0046     //void getPhoton30(const HLTConfigProvider& hltConfig,std::vector<std::string>& activeFilters);
0047     //------------------
0048     //filters a list of filternames removing any filters which are not in active filters, assumes active filters is sorted
0049     void filterInactiveTriggers(std::vector<std::string>& namesToFilter, std::vector<std::string>& activeFilters);
0050     //filters a list of filterName1:filterName2 removing any entry for which either filter is not in activeFilters, assumes active filters is sorted
0051     void filterInactiveTightLooseTriggers(std::vector<std::string>& namesToFilter,
0052                                           const std::vector<std::string>& activeFilters);
0053 
0054     void translateFiltersToPathNames(const HLTConfigProvider& hltConfig,
0055                                      const std::vector<std::string>& filters,
0056                                      std::vector<std::string>& paths);
0057     std::string getL1SeedFilterOfPath(const HLTConfigProvider& hltConfig, const std::string& path);
0058 
0059     //looks for string Et and then looks for a number after that (currently the standard of all E/g triggers)
0060     //returns 0 if unsuccessful
0061     float getEtThresFromName(const std::string& trigName);
0062     float getSecondEtThresFromName(const std::string& trigName);
0063   }  // namespace trigTools
0064 
0065   //I have the horrible feeling that I'm converting into an intermediatry format and then coverting back again
0066   //Okay how this works
0067   //1) create a TrigBitSet for each particle set to 0 initally
0068   //2) loop over each filter, for each particle that passes the filter, set the appropriate bit in the TrigBitSet
0069   //3) after that, loop over each particle setting that its TrigBitSet which has been calculated
0070   //4) because L1 pre-scaled paths are special, we only set those if an event wide trigger has been set
0071   template <class T>
0072   void trigTools::setFiltersObjPasses(std::vector<T>& particles,
0073                                       const std::vector<std::string>& filters,
0074                                       const std::vector<std::pair<std::string, std::string> >& l1PreAndSeedFilters,
0075                                       const TrigCodes::TrigBitSet& evtTrigBits,
0076                                       const TrigCodes& trigCodes,
0077                                       const trigger::TriggerEvent* trigEvt,
0078                                       const std::string& hltTag) {
0079     std::vector<TrigCodes::TrigBitSet> partTrigBits(particles.size());
0080     const double maxDeltaR = 0.1;
0081     for (const auto& filter : filters) {
0082       size_t filterNrInEvt = trigEvt->filterIndex(edm::InputTag(filter, "", hltTag));
0083       const TrigCodes::TrigBitSet filterCode = trigCodes.getCode(filter.c_str());
0084 
0085       if (filterNrInEvt < trigEvt->sizeFilters()) {  //filter found in event, something passes it
0086         const trigger::Keys& trigKeys = trigEvt->filterKeys(
0087             filterNrInEvt);  //trigger::Keys is actually a vector<uint16_t> holding the position of trigger objects in the trigger collection passing the filter
0088         const trigger::TriggerObjectCollection& trigObjColl(trigEvt->getObjects());
0089         for (size_t partNr = 0; partNr < particles.size(); partNr++) {
0090           for (unsigned short trigKey : trigKeys) {
0091             float trigObjEta = trigObjColl[trigKey].eta();
0092             float trigObjPhi = trigObjColl[trigKey].phi();
0093             if (reco::deltaR(particles[partNr].eta(), particles[partNr].phi(), trigObjEta, trigObjPhi) < maxDeltaR) {
0094               partTrigBits[partNr] |= filterCode;
0095             }  //end dR<maxDeltaR trig obj match test
0096           }    //end loop over all objects passing filter
0097         }      //end loop over particles
0098       }        //end check if filter is present
0099     }          //end loop over all filters
0100 
0101     //okay the first element is the key, the second is the filter that exists in trigger event
0102     for (const auto& l1PreAndSeedFilter : l1PreAndSeedFilters) {
0103       const TrigCodes::TrigBitSet filterCode = trigCodes.getCode(l1PreAndSeedFilter.first.c_str());
0104       if ((filterCode & evtTrigBits) == filterCode) {  //check that filter has fired in the event
0105 
0106         size_t filterNrInEvt = trigEvt->filterIndex(edm::InputTag(l1PreAndSeedFilter.second, "", hltTag));
0107 
0108         if (filterNrInEvt < trigEvt->sizeFilters()) {  //filter found in event, something passes it
0109           const trigger::Keys& trigKeys = trigEvt->filterKeys(
0110               filterNrInEvt);  //trigger::Keys is actually a vector<uint16_t> holding the position of trigger objects in the trigger collection passing the filter
0111           const trigger::TriggerObjectCollection& trigObjColl(trigEvt->getObjects());
0112           for (size_t partNr = 0; partNr < particles.size(); partNr++) {
0113             for (unsigned short trigKey : trigKeys) {
0114               float trigObjEta = trigObjColl[trigKey].eta();
0115               float trigObjPhi = trigObjColl[trigKey].phi();
0116               if (reco::deltaR(particles[partNr].eta(), particles[partNr].phi(), trigObjEta, trigObjPhi) < maxDeltaR) {
0117                 partTrigBits[partNr] |= filterCode;
0118               }  //end dR<maxDeltaR trig obj match test
0119             }    //end loop over all objects passing filter
0120           }      //end loop over particles
0121         }        //end check if filter is present
0122       }          //end check if path has fired in the event
0123     }            //end loop over all filters
0124 
0125     for (size_t partNr = 0; partNr < particles.size(); partNr++)
0126       particles[partNr].setTrigBits(partTrigBits[partNr]);
0127   }
0128 
0129   template <class T, class U>
0130   void trigTools::fillHLTposition(T& particle,
0131                                   U& hltData,
0132                                   const std::vector<std::string>& filters,
0133                                   const trigger::TriggerEvent* trigEvt,
0134                                   const std::string& hltTag) {
0135     std::vector<TrigCodes::TrigBitSet> partTrigBits(1);
0136     const double maxDeltaR = 0.1;
0137     for (const auto& filter : filters) {
0138       size_t filterNrInEvt = trigEvt->filterIndex(edm::InputTag(filter, "", hltTag));
0139       //const TrigCodes::TrigBitSet filterCode = trigCodes.getCode(filters[filterNrInVec].c_str());
0140       if (filterNrInEvt < trigEvt->sizeFilters()) {  //filter found in event, something passes it
0141         const trigger::Keys& trigKeys = trigEvt->filterKeys(
0142             filterNrInEvt);  //trigger::Keys is actually a vector<uint16_t> holding the position of trigger objects in the trigger collection passing the filter
0143         const trigger::TriggerObjectCollection& trigObjColl(trigEvt->getObjects());
0144         for (unsigned short trigKey : trigKeys) {
0145           float trigObjEta = trigObjColl[trigKey].eta();
0146           float trigObjPhi = trigObjColl[trigKey].phi();
0147           float trigObjE = trigObjColl[trigKey].energy();
0148           if (reco::deltaR(particle.superCluster()->eta(), particle.superCluster()->phi(), trigObjEta, trigObjPhi) <
0149               maxDeltaR) {
0150             hltData.HLTeta = trigObjEta;
0151             hltData.HLTphi = trigObjPhi;
0152             hltData.HLTenergy = trigObjE;
0153           }  //end dR<maxDeltaR trig obj match test
0154         }    //end loop over all objects passing filter`
0155       }      //end check if filter is present
0156     }        //end check if path has fired in the event
0157   }          //end loop over all filters
0158 
0159 }  // namespace egHLT
0160 
0161 #endif