Go to the documentation of this file.00001 #include "FWCore/Framework/interface/MakerMacros.h"
00002 #include "FWCore/Utilities/interface/InputTag.h"
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00005 #include "CommonTools/UtilAlgos/interface/SingleObjectSelector.h"
00006 #include "DataFormats/Common/interface/View.h"
00007 #include "DataFormats/Candidate/interface/Candidate.h"
00008 #include "FWCore/Common/interface/TriggerNames.h"
00009 #include "DataFormats/Common/interface/TriggerResults.h"
00010 #include "DataFormats/HLTReco/interface/TriggerObject.h"
00011 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
00012 #include "DataFormats/Math/interface/deltaR.h"
00013
00014
00015 #include <string>
00016 using namespace std;
00017 using namespace reco;
00018 namespace edm { class EventSetup; }
00019
00020 bool IsMuMatchedToHLTMu ( const reco::Candidate * dau, std::vector<reco::Particle> HLTMu , double DR, double DPtRel ) {
00021 unsigned int dim = HLTMu.size();
00022 unsigned int nPass=0;
00023 if (dim==0) return false;
00024 for (unsigned int k =0; k< dim; k++ ) {
00025 if ( (deltaR(HLTMu[k], *dau) < DR) && (fabs(HLTMu[k].pt() - dau->pt())/ HLTMu[k].pt()<DPtRel)){ nPass++ ;
00026 }
00027 }
00028 return (nPass>0);
00029 }
00030
00031 bool IsMuMatchedToHLTSingleMu ( const reco::Candidate * dau, reco::Particle HLTMu , double DR, double DPtRel ) {
00032 unsigned int nPass=0;
00033 if ( (deltaR(HLTMu, *dau) < DR) && (fabs(HLTMu.pt() - dau->pt())/ HLTMu.pt()<DPtRel)) {
00034 nPass++;
00035 }
00036 return (nPass>0);
00037 }
00038
00039
00040 class ZGoldenFilter {
00041
00042 public:
00043 ZGoldenFilter(const edm::ParameterSet& );
00044 bool operator()(const reco::Candidate & ) const;
00045 void newEvent (const edm::Event&, const edm::EventSetup&);
00046 edm::InputTag trigTag_;
00047 edm::InputTag trigEv_;
00048 std::string cond_ ;
00049 std::string hltPath_;
00050 std::string L3FilterName_;
00051 edm::Handle<edm::TriggerResults> triggerResults_;
00052 edm::TriggerNames const* trigNames_;
00053 edm::Handle< trigger::TriggerEvent > handleTriggerEvent_;
00054 double maxDPtRel_, maxDeltaR_ ;
00055 };
00056
00057 ZGoldenFilter::ZGoldenFilter(const edm::ParameterSet& cfg ) :
00058 trigTag_(cfg.getParameter<edm::InputTag> ("TrigTag")),
00059 trigEv_(cfg.getParameter<edm::InputTag> ("triggerEvent")),
00060 cond_(cfg.getParameter<std::string >("condition")),
00061 hltPath_(cfg.getParameter<std::string >("hltPath")),
00062 L3FilterName_(cfg.getParameter<std::string >("L3FilterName")),
00063 maxDPtRel_(cfg.getParameter<double>("maxDPtRel")),
00064 maxDeltaR_(cfg.getParameter<double>("maxDeltaR")){
00065 }
00066
00067 void ZGoldenFilter::newEvent(const edm::Event& ev, const edm::EventSetup& ){
00068
00069 if (!ev.getByLabel(trigTag_, triggerResults_)) {
00070 edm::LogWarning("") << ">>> TRIGGER collection does not exist !!!";
00071 return ;
00072 }
00073 ev.getByLabel(trigTag_, triggerResults_);
00074 trigNames_ = &ev.triggerNames(*triggerResults_);
00075 if ( ! ev.getByLabel( trigEv_, handleTriggerEvent_ ) ) {
00076 edm::LogError( "errorTriggerEventValid" ) << "trigger::TriggerEvent product with InputTag " << trigEv_.encode() << " not in event";
00077 return;
00078 }
00079 ev.getByLabel( trigEv_, handleTriggerEvent_ );
00080 }
00081
00082
00083
00084 bool ZGoldenFilter::operator()(const reco::Candidate & z) const {
00085
00086 assert(z.numberOfDaughters()==2);
00087 bool singleTrigFlag0 = false;
00088 bool singleTrigFlag1 = false;
00089 bool exactlyOneTriggerFlag = false;
00090 bool bothTriggerFlag = false;
00091 bool atLeastOneTriggerFlag=false;
00092 bool FirstTriggerFlag = false;
00093 bool globalisTriggerFlag =false;
00094 if((((cond_ !="exactlyOneMatched" && cond_!="atLeastOneMatched") && cond_ !="bothMatched") && cond_ != "firstMatched") && cond_ != "globalisMatched")
00095 throw edm::Exception(edm::errors::Configuration)
00096 << "Invalid condition type: " << cond_ << ". Valid types are:"
00097 << " exactlyOneMatched, atLeastOneMatched, bothMatched, firstMatched,globalisMatched\n";
00098 const reco::Candidate * dau0 = z.daughter(0);
00099 const reco::Candidate * dau1 = z.daughter(1);
00100 const trigger::TriggerObjectCollection & toc(handleTriggerEvent_->getObjects());
00101 unsigned int nMuHLT =0;
00102 std::vector<reco::Particle> HLTMuMatched;
00103 for ( unsigned int ia = 0; ia < handleTriggerEvent_->sizeFilters(); ++ ia) {
00104 std::string fullname = handleTriggerEvent_->filterTag(ia).encode();
00105 std::string name;
00106 size_t p = fullname.find_first_of(':');
00107 if ( p != std::string::npos) {
00108 name = fullname.substr(0, p);
00109 }
00110 else {
00111 name = fullname;
00112 }
00113 if ( &toc !=0 ) {
00114 const trigger::Keys & k = handleTriggerEvent_->filterKeys(ia);
00115 for (trigger::Keys::const_iterator ki = k.begin(); ki !=k.end(); ++ki ) {
00116 if (name == L3FilterName_ ) {
00117 HLTMuMatched.push_back(toc[*ki].particle());
00118 nMuHLT++;
00119 }
00120 }
00121 }
00122 }
00123
00124 bool trigger_fired = false;
00125 for (unsigned int i=0; i<triggerResults_->size(); i++) {
00126 std::string trigName = trigNames_->triggerName(i);
00127 if ( trigName == hltPath_ && triggerResults_->accept(i)) trigger_fired = true;
00128 }
00129 bool firstdismuon = (dau0->isGlobalMuon() ? true : false);
00130 bool firstdisStandAlone = (dau0->isStandAloneMuon() ? true : false);
00131 std::vector<bool> IsDau0Matched_;
00132 std::vector<bool> IsDau1Matched_;
00133 if(dau0 != 0){
00134
00135 singleTrigFlag0 = IsMuMatchedToHLTMu ( dau0, HLTMuMatched ,maxDeltaR_, maxDPtRel_ );
00136
00137 for (unsigned int y=0; y< HLTMuMatched.size(); y++ ){
00138 IsDau0Matched_.push_back( IsMuMatchedToHLTSingleMu ( dau0, HLTMuMatched[y] ,maxDeltaR_, maxDPtRel_ ));
00139 }
00140 }
00141 bool secondismuon = (dau1->isGlobalMuon() ? true : false);
00142 bool secondisStandAlone = (dau1->isStandAloneMuon() ? true : false);
00143 if(dau1 != 0 && (secondismuon ||secondisStandAlone) ){
00144 singleTrigFlag1 = IsMuMatchedToHLTMu ( dau1, HLTMuMatched ,maxDeltaR_, maxDPtRel_ );
00145 for (unsigned int y=0; y< HLTMuMatched.size(); y++ ){
00146 IsDau1Matched_.push_back( IsMuMatchedToHLTSingleMu ( dau1, HLTMuMatched[y] ,maxDeltaR_, maxDPtRel_ ));
00147 }
00148 }
00149 if ( (IsDau0Matched_.size() * IsDau1Matched_.size())!=0 ) {
00150 for (unsigned int y=0; y< IsDau1Matched_.size(); y++ ){
00151 if ( IsDau0Matched_[y]== true && IsDau1Matched_[y]== true ){
00152 std::cout<< "WARNING--> I'm matching the two muons to the same HLT muon....." << std::endl;}
00153 }
00154 }
00155 if(!singleTrigFlag0 && !singleTrigFlag1)return false;
00156 if((singleTrigFlag0 && singleTrigFlag1) && secondismuon ) bothTriggerFlag = true;
00157 if(((singleTrigFlag0 && !singleTrigFlag1) && secondismuon) || ((!singleTrigFlag0 && singleTrigFlag1) && secondismuon)) exactlyOneTriggerFlag = true;
00158 if((((singleTrigFlag0 && firstdismuon) && secondisStandAlone) && !secondismuon ) || (((singleTrigFlag1 && secondismuon) && firstdisStandAlone) && !firstdismuon))globalisTriggerFlag = true;
00159 if((singleTrigFlag0 && !singleTrigFlag1) && !secondismuon) FirstTriggerFlag = true;
00160 if((singleTrigFlag0 || singleTrigFlag1) && secondismuon) atLeastOneTriggerFlag=true;
00161 if(cond_=="exactlyOneMatched") return exactlyOneTriggerFlag;
00162 if(cond_=="atLeastOneMatched") return atLeastOneTriggerFlag;
00163 if(cond_=="bothMatched") return bothTriggerFlag;
00164 if(cond_=="firstMatched") return FirstTriggerFlag;
00165 if(cond_=="globalisMatched") return globalisTriggerFlag;
00166 return false;
00167 }
00168
00169
00170
00171 #include "CommonTools/UtilAlgos/interface/SingleObjectSelector.h"
00172 #include "CommonTools/UtilAlgos/interface/AndSelector.h"
00173 #include "CommonTools/UtilAlgos/interface/StringCutObjectSelector.h"
00174 #include "CommonTools/UtilAlgos/interface/EventSetupInitTrait.h"
00175
00176 EVENTSETUP_STD_INIT(ZGoldenFilter);
00177
00178
00179 typedef SingleObjectSelector<
00180 edm::View<reco::Candidate>,
00181 AndSelector< ZGoldenFilter, StringCutObjectSelector<reco::Candidate> >
00182 > ZGoldenSelectorAndFilter;
00183
00184
00185 DEFINE_FWK_MODULE( ZGoldenSelectorAndFilter );
00186