00001 #include "DQMOffline/Trigger/interface/EgammaHLTOffline.h"
00002
00003 #include "DQMOffline/Trigger/interface/EleHLTPathMon.h"
00004 #include "DQMOffline/Trigger/interface/EleHLTFilterMon.h"
00005 #include "DQMOffline/Trigger/interface/EgHLTOffData.h"
00006 #include "DQMOffline/Trigger/interface/DebugFuncs.h"
00007 #include "DQMOffline/Trigger/interface/MonElemContainer.h"
00008 #include "DQMOffline/Trigger/interface/EgHLTDQMCut.h"
00009 #include "DQMOffline/Trigger/interface/MonElemFuncs.h"
00010
00011 #include "DataFormats/Common/interface/Handle.h"
00012
00013 #include "DataFormats/HLTReco/interface/TriggerObject.h"
00014 #include "FWCore/Framework/interface/TriggerNames.h"
00015 #include "FWCore/Framework/interface/Run.h"
00016
00017 #include "DataFormats/HLTReco/interface/TriggerTypeDefs.h"
00018 #include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
00019 #include "DataFormats/EgammaCandidates/interface/Photon.h"
00020
00021 #include "PhysicsTools/Utilities/interface/deltaR.h"
00022
00023 EgammaHLTOffline::EgammaHLTOffline(const edm::ParameterSet& iConfig)
00024 {
00025 dbe_ = edm::Service<DQMStore>().operator->();
00026 if (!dbe_) {
00027 edm::LogInfo("EgammaHLTOffline") << "unable to get DQMStore service?";
00028 }
00029 if(iConfig.getUntrackedParameter<bool>("DQMStore", false)) {
00030 dbe_->setVerbose(0);
00031 }
00032
00033 triggerSummaryLabel_ = iConfig.getParameter<edm::InputTag>("triggerSummaryLabel");
00034 eleHLTPathNames_ = iConfig.getParameter<std::vector<std::string> >("eleHLTPathNames");
00035 eleHLTFilterNames_ = iConfig.getParameter<std::vector<std::string> >("eleHLTFilterNames");
00036
00037
00038 namesFiltersUsed_.clear();
00039 for(size_t pathNr=0;pathNr<eleHLTPathNames_.size();pathNr++){
00040 for(size_t filterNr=0;filterNr<eleHLTFilterNames_.size();filterNr++){
00041 namesFiltersUsed_.push_back(eleHLTPathNames_[pathNr]+eleHLTFilterNames_[filterNr]);
00042 }
00043 }
00044 namesFiltersUsed_.push_back("hltL1NonIsoHLTNonIsoSinglePhotonEt15TrackIsolFilter");
00045 TrigCodes::setCodes(namesFiltersUsed_);
00046
00047 dirName_=iConfig.getParameter<std::string>("DQMDirName");
00048
00049 if(dbe_) dbe_->setCurrentFolder(dirName_);
00050
00051 egHelper_.setup(iConfig);
00052 }
00053
00054
00055 EgammaHLTOffline::~EgammaHLTOffline()
00056 {
00057
00058 for(size_t i=0;i<elePathMonHists_.size();i++){
00059 delete elePathMonHists_[i];
00060 }
00061 }
00062
00063 void EgammaHLTOffline::beginJob(const edm::EventSetup& iSetup)
00064 {
00065 for(size_t i=0;i<eleHLTPathNames_.size();i++) addTrigPath(eleHLTPathNames_[i]);
00066
00067 std::string tightTrig("hltL1NonIsoHLTNonIsoSingleElectronEt15TrackIsolFilter");
00068
00069 std::string looseTrig("hltL1NonIsoHLTNonIsoSinglePhotonEt15TrackIsolFilter");
00070
00071
00072 int stdCutCode = CutCodes::getCode("detEta:crack:sigmaEtaEta:hadem:dPhiIn:dEtaIn");
00073 eleMonElems_.push_back(new MonElemContainer<EgHLTOffEle>("passLooseTrig_passTightTrig","",
00074
00075 new EgEleTrigCut<EgHLTOffEle>(TrigCodes::getCode(tightTrig+":"+looseTrig),EgEleTrigCut<EgHLTOffEle>::AND)));
00076
00077
00078 eleMonElems_.push_back(new MonElemContainer<EgHLTOffEle>("passLooseTrig_failTightTrig","",
00079
00080 new EgEleTrigCut<EgHLTOffEle>(TrigCodes::getCode(looseTrig),EgEleTrigCut<EgHLTOffEle>::AND,TrigCodes::getCode(tightTrig))));
00081
00082 for(size_t i=0;i<eleMonElems_.size();i++){
00083 MonElemFuncs::initStdEleHists(eleMonElems_[i]->monElems(),tightTrig+"_"+eleMonElems_[i]->name());
00084 }
00085
00086
00087
00088
00089 for(size_t pathNr=0;pathNr<eleHLTPathNames_.size();pathNr++){
00090 for(size_t filterNr=0;filterNr<eleHLTFilterNames_.size();filterNr++){
00091
00092 std::string trigName(eleHLTPathNames_[pathNr]+eleHLTFilterNames_[filterNr]);
00093 int stdCutCode = CutCodes::getCode("detEta:crack:sigmaEtaEta:hadem:dPhiIn:dEtaIn");
00094 MonElemContainer<EgHLTOffEle>* monElemCont = new MonElemContainer<EgHLTOffEle>("trigTagProbe","Trigger Tag and Probe",new EgTrigTagProbeCut(TrigCodes::getCode(trigName),stdCutCode,&EgHLTOffEle::cutCode));
00095 MonElemFuncs::initStdEleCutHists(monElemCont->cutMonElems(),trigName+"_"+monElemCont->name()+"_all",new EgGreaterCut<EgHLTOffEle,float>(15.,&EgHLTOffEle::etSC));
00096 MonElemFuncs::initStdEleCutHists(monElemCont->cutMonElems(),trigName+"_"+monElemCont->name()+"_pass",&(*(new EgMultiCut<EgHLTOffEle>) << new EgGreaterCut<EgHLTOffEle,float>(15.,&EgHLTOffEle::etSC) << new EgEleTrigCut<EgHLTOffEle>(TrigCodes::getCode(trigName),EgEleTrigCut<EgHLTOffEle>::AND)));
00097 eleMonElems_.push_back(monElemCont);
00098 }
00099 }
00100
00101
00102
00103
00104
00105
00106
00107 }
00108
00109 void EgammaHLTOffline::endJob()
00110 {
00111
00112 }
00113
00114 void EgammaHLTOffline::beginRun(const edm::Run& run, const edm::EventSetup& c)
00115 {
00116
00117 }
00118
00119
00120 void EgammaHLTOffline::endRun(const edm::Run& run, const edm::EventSetup& c)
00121 {
00122
00123 }
00124
00125
00126 void EgammaHLTOffline::analyze(const edm::Event& iEvent,const edm::EventSetup& iSetup)
00127 {
00128 const double weight=1.;
00129
00130
00131
00132
00133
00134 edm::Handle<trigger::TriggerEvent> triggerObj;
00135 iEvent.getByLabel(triggerSummaryLabel_,triggerObj);
00136 if(!triggerObj.isValid()) {
00137 edm::LogInfo("EgammaHLTOffline") << "Summary HLT objects not found, skipping event";
00138 return;
00139 }
00140
00141 edm::Handle<reco::PixelMatchGsfElectronCollection> gsfElectrons;
00142 iEvent.getByLabel("pixelMatchGsfElectrons",gsfElectrons);
00143 if(!gsfElectrons.isValid()) {
00144 edm::LogInfo("EgammaHLTOffline") << "gsfElectrons not found,skipping event";
00145 return;
00146 }
00147
00148 egHelper_.getHandles(iEvent,iSetup);
00149
00150 std::vector<EgHLTOffEle> egHLTOffEles;
00151 egHelper_.fillEgHLTOffEleVec(gsfElectrons,egHLTOffEles);
00152
00153 std::vector<std::vector<int> > filtersElePasses;
00154 TrigCodes::TrigBitSet evtTrigBits = setFiltersElePasses(egHLTOffEles,namesFiltersUsed_,triggerObj);
00155
00156 EgHLTOffData evtData;
00157 evtData.trigEvt = triggerObj;
00158 evtData.eles = &egHLTOffEles;
00159 evtData.filtersElePasses = &filtersElePasses;
00160 evtData.evtTrigBits = evtTrigBits;
00161 evtData.jets = egHelper_.jets();
00162
00163
00164
00165
00166
00167
00168
00169
00170 for(size_t pathNr=0;pathNr<elePathMonHists_.size();pathNr++){
00171 elePathMonHists_[pathNr]->fill(evtData,weight);
00172 }
00173
00174 for(size_t monElemNr=0;monElemNr<eleMonElems_.size();monElemNr++){
00175 const std::vector<EgHLTOffEle>& eles = *evtData.eles;
00176 for(size_t eleNr=0;eleNr<eles.size();eleNr++){
00177 eleMonElems_[monElemNr]->fill(eles[eleNr],evtData,weight);
00178 }
00179 }
00180 }
00181
00182
00183 void EgammaHLTOffline::addTrigPath(const std::string& name)
00184 {
00185 EleHLTPathMon* pathMon = new EleHLTPathMon(name);
00186 pathMon->addFilters(eleHLTFilterNames_);
00187 elePathMonHists_.push_back(pathMon);
00188 std::sort(elePathMonHists_.begin(),elePathMonHists_.end(),EleHLTFilterMon::ptrLess<EleHLTPathMon>());
00189 }
00190
00191
00192
00193
00194
00195
00196
00197 TrigCodes::TrigBitSet EgammaHLTOffline::setFiltersElePasses(std::vector<EgHLTOffEle>& eles,const std::vector<std::string>& filters,edm::Handle<trigger::TriggerEvent> trigEvt)
00198 {
00199 TrigCodes::TrigBitSet evtTrigs;
00200 std::vector<TrigCodes::TrigBitSet> eleTrigBits(eles.size());
00201 const double maxDeltaR=0.3;
00202 for(size_t filterNrInVec=0;filterNrInVec<filters.size();filterNrInVec++){
00203 size_t filterNrInEvt = trigEvt->filterIndex(edm::InputTag(filters[filterNrInVec],"","HLT").encode());
00204 const TrigCodes::TrigBitSet filterCode = TrigCodes::getCode(filters[filterNrInVec].c_str());
00205
00206 if(filterNrInEvt<trigEvt->sizeFilters()){
00207 evtTrigs |=filterCode;
00208 const trigger::Keys& trigKeys = trigEvt->filterKeys(filterNrInEvt);
00209 const trigger::TriggerObjectCollection & trigObjColl(trigEvt->getObjects());
00210 for(size_t eleNr=0;eleNr<eles.size();eleNr++){
00211 for(trigger::Keys::const_iterator keyIt=trigKeys.begin();keyIt!=trigKeys.end();++keyIt){
00212 float trigObjEta = trigObjColl[*keyIt].eta();
00213 float trigObjPhi = trigObjColl[*keyIt].phi();
00214 if (reco::deltaR(eles[eleNr].eta(),eles[eleNr].phi(),trigObjEta,trigObjPhi) < maxDeltaR){
00215 eleTrigBits[eleNr] |= filterCode;
00216 }
00217 }
00218 }
00219 }
00220 }
00221
00222 for(size_t eleNr=0;eleNr<eles.size();eleNr++) eles[eleNr].setTrigBits(eleTrigBits[eleNr]);
00223
00224 return evtTrigs;
00225
00226 }
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 void EgammaHLTOffline::obtainFiltersElePasses(const std::vector<EgHLTOffEle>& eles,const std::vector<std::string>& filters,edm::Handle<trigger::TriggerEvent> trigEvt,std::vector<std::vector<int> >& filtersElePasses)
00238 {
00239
00240 std::vector<std::vector<int> > dummyVec(eles.size());
00241 filtersElePasses.swap(dummyVec);
00242
00243 const double maxDeltaR=0.3;
00244 for(size_t filterNrInVec=0;filterNrInVec<filters.size();filterNrInVec++){
00245 size_t filterNrInEvt = trigEvt->filterIndex(edm::InputTag(filters[filterNrInVec],"","HLT").encode());
00246
00247 if(filterNrInEvt<trigEvt->sizeFilters()){
00248 const trigger::Keys& trigKeys = trigEvt->filterKeys(filterNrInEvt);
00249 const trigger::TriggerObjectCollection & trigObjColl(trigEvt->getObjects());
00250 for(size_t eleNr=0;eleNr<eles.size();eleNr++){
00251 for(trigger::Keys::const_iterator keyIt=trigKeys.begin();keyIt!=trigKeys.end();++keyIt){
00252 float trigObjEta = trigObjColl[*keyIt].eta();
00253 float trigObjPhi = trigObjColl[*keyIt].phi();
00254 if (reco::deltaR(eles[eleNr].eta(),eles[eleNr].phi(),trigObjEta,trigObjPhi) < maxDeltaR){
00255 filtersElePasses[eleNr].push_back(filterNrInEvt);
00256 }
00257 }
00258 }
00259 }
00260 }
00261
00262
00263 for(size_t i=0;i<filtersElePasses.size();i++) std::sort(filtersElePasses[i].begin(),filtersElePasses[i].end());
00264 }
00265
00266 void EgammaHLTOffline::filterNamesUsed(std::vector<std::string>& filterNames)
00267 {
00268 filterNames.clear();
00269 for(size_t pathNr=0;pathNr<elePathMonHists_.size();pathNr++){
00270 std::vector<std::string> pathFilters = elePathMonHists_[pathNr]->getFilterNames();
00271 for(size_t i=0;i<pathFilters.size();i++) filterNames.push_back(pathFilters[i]);
00272 }
00273 }