00001 #include "DQMOffline/Trigger/interface/HLTTauDQMLitePathPlotter.h"
00002
00003 HLTTauDQMLitePathPlotter::HLTTauDQMLitePathPlotter( const edm::ParameterSet& ps, int etbins, int etabins, int phibins, double maxpt, bool ref, double dr, std::string dqmBaseFolder ) {
00004
00005 name_ = "HLTTauDQMLitePathPlotter";
00006
00007
00008 try {
00009 triggerEvent_ = ps.getUntrackedParameter<edm::InputTag>("TriggerEventObject");
00010 triggerTag_ = ps.getUntrackedParameter<std::string>("DQMFolder");
00011 triggerTagAlias_ = ps.getUntrackedParameter<std::string>("Alias","");
00012 filters_ = ps.getUntrackedParameter<std::vector<edm::ParameterSet> >("Filters");
00013 refTauPt_ = ps.getUntrackedParameter<double>("refTauPt",20);
00014 refLeptonPt_ = ps.getUntrackedParameter<double>("refLeptonPt",15);
00015 doRefAnalysis_ = ref;
00016 dqmBaseFolder_ = dqmBaseFolder;
00017 matchDeltaR_ = dr;
00018 maxEt_ = maxpt;
00019 binsEt_ = etbins;
00020 binsEta_ = etabins;
00021 binsPhi_ = phibins;
00022 validity_ = true;
00023 } catch ( cms::Exception &e ) {
00024 edm::LogInfo("HLTTauDQMLitePathPlotter::HLTTauDQMLitePathPlotter") << e.what() << std::endl;
00025 validity_ = false;
00026 return;
00027 }
00028
00029 for ( std::vector<edm::ParameterSet>::const_iterator iter = filters_.begin(); iter != filters_.end(); ++iter ) {
00030 HLTTauDQMPlotter::FilterObject tmp(*iter);
00031 if (tmp.isValid()) filterObjs_.push_back(tmp);
00032 }
00033
00034 if (store_) {
00035
00036 store_->setCurrentFolder(triggerTag());
00037 store_->removeContents();
00038
00039 accepted_events = store_->book1D("PathTriggerBits","Accepted Events per Path;;entries",filterObjs_.size(),0,filterObjs_.size());
00040
00041 for ( size_t k = 0; k < filterObjs_.size(); ++k ) {
00042 accepted_events->setBinLabel(k+1,filterObjs_[k].getAlias(),1);
00043 if ( filterObjs_[k].getNTriggeredTaus() >= 2 || (filterObjs_[k].getNTriggeredTaus() >= 1 && filterObjs_[k].getNTriggeredLeptons() >= 1) ) {
00044 mass_distribution.insert(std::make_pair(filterObjs_[k].getAlias(), store_->book1D(("mass_"+filterObjs_[k].getAlias()).c_str(),("Mass Distribution for "+filterObjs_[k].getAlias()).c_str(),100,0,500)));
00045 }
00046 }
00047
00048 if (doRefAnalysis_) {
00049 accepted_events_matched = store_->book1D("MatchedPathTriggerBits","Accepted+Matched Events per Path;;entries",filterObjs_.size(),0,filterObjs_.size());
00050 accepted_events_matched->getTH1F()->Sumw2();
00051
00052 for ( size_t k = 0; k < filterObjs_.size(); ++k ) {
00053 accepted_events_matched->setBinLabel(k+1,filterObjs_[k].getAlias(),1);
00054 }
00055 ref_events = store_->book1D("RefEvents","Reference Events per Path",filterObjs_.size(),0,filterObjs_.size());
00056 ref_events->getTH1F()->Sumw2();
00057
00058 for ( size_t k = 0; k < filterObjs_.size(); ++k ) {
00059 ref_events->setBinLabel(k+1,filterObjs_[k].getAlias(),1);
00060 }
00061 }
00062
00063 tauEt = store_->book1D("TrigTauEt","#tau E_{t}",binsEt_,0,maxEt_);
00064 tauEta = store_->book1D("TrigTauEta","#tau #eta",binsEta_,-2.5,2.5);
00065 tauPhi = store_->book1D("TrigTauPhi","#tau #phi",binsPhi_,-3.2,3.2);
00066
00067 if (doRefAnalysis_) {
00068 store_->setCurrentFolder(triggerTag()+"/EfficiencyHelpers");
00069 store_->removeContents();
00070
00071 tauEtEffNum = store_->book1D("TrigTauEtEffNum","#tau E_{T} Efficiency",binsEt_,0,maxEt_);
00072 tauEtEffNum->getTH1F()->Sumw2();
00073
00074 tauEtEffDenom = store_->book1D("TrigTauEtEffDenom","#tau E_{T} Denominator",binsEt_,0,maxEt_);
00075 tauEtEffDenom->getTH1F()->Sumw2();
00076
00077 tauEtaEffNum = store_->book1D("TrigTauEtaEffNum","#tau #eta Efficiency",binsEta_,-2.5,2.5);
00078 tauEtaEffNum->getTH1F()->Sumw2();
00079
00080 tauEtaEffDenom = store_->book1D("TrigTauEtaEffDenom","#tau #eta Denominator",binsEta_,-2.5,2.5);
00081 tauEtaEffDenom->getTH1F()->Sumw2();
00082
00083 tauPhiEffNum = store_->book1D("TrigTauPhiEffNum","#tau #phi Efficiency",binsPhi_,-3.2,3.2);
00084 tauPhiEffNum->getTH1F()->Sumw2();
00085
00086 tauPhiEffDenom = store_->book1D("TrigTauPhiEffDenom","#tau #phi Denominator",binsPhi_,-3.2,3.2);
00087 tauPhiEffDenom->getTH1F()->Sumw2();
00088 }
00089 }
00090 }
00091
00092 HLTTauDQMLitePathPlotter::~HLTTauDQMLitePathPlotter() {
00093 }
00094
00095
00096
00097
00098
00099 void HLTTauDQMLitePathPlotter::analyze( const edm::Event& iEvent, const edm::EventSetup& iSetup, const std::map<int,LVColl>& refC ) {
00100 std::vector<bool> isGoodReferenceEvent;
00101
00102 LV highestRefTau(0.,0.,0.,0.0001);
00103 LVColl triggeredTaus, refTaus, refElectrons, refMuons;
00104
00105 std::map<int,LVColl>::const_iterator iref;
00106
00107
00108 iref = refC.find(15);
00109 if ( iref != refC.end() ) {
00110 for ( LVColl::const_iterator lvi = iref->second.begin(); lvi != iref->second.end(); ++lvi ) {
00111 if ( lvi->Et() > highestRefTau.pt() ) {
00112 highestRefTau = *lvi;
00113 }
00114 }
00115 }
00116
00117
00118 if (doRefAnalysis_) {
00119 unsigned int highPtTaus = 0;
00120 unsigned int highPtElectrons = 0;
00121 unsigned int highPtMuons = 0;
00122
00123 std::map<int,LVColl>::const_iterator iref;
00124
00125
00126 iref = refC.find(15);
00127 if ( iref != refC.end() ) {
00128 for ( LVColl::const_iterator lvi = iref->second.begin(); lvi != iref->second.end(); ++lvi ) {
00129 if ( lvi->Et() > refTauPt_ ) {
00130 highPtTaus++;
00131 }
00132 refTaus.push_back(*lvi);
00133 }
00134 }
00135
00136 iref = refC.find(11);
00137 if ( iref != refC.end() ) {
00138 for ( LVColl::const_iterator lvi = iref->second.begin(); lvi != iref->second.end(); ++lvi ) {
00139 if ( lvi->Et() > refLeptonPt_ ) {
00140 highPtElectrons++;
00141 }
00142 refElectrons.push_back(*lvi);
00143 }
00144 }
00145
00146 iref = refC.find(13);
00147 if ( iref != refC.end() ) {
00148 for ( LVColl::const_iterator lvi = iref->second.begin(); lvi != iref->second.end(); ++lvi ) {
00149 if ( lvi->Et() > refLeptonPt_ ) {
00150 highPtMuons++;
00151 }
00152 refMuons.push_back(*lvi);
00153 }
00154 }
00155
00156 for ( size_t i = 0; i < filterObjs_.size(); ++i ) {
00157 bool tau_ok = true;
00158 bool leptons_ok = true;
00159
00160 if ( highPtTaus < filterObjs_[i].getNTriggeredTaus() ) tau_ok = false;
00161 if ( filterObjs_[i].leptonId() == 11 && highPtElectrons < filterObjs_[i].getNTriggeredLeptons() ) leptons_ok = false;
00162 if ( filterObjs_[i].leptonId() == 13 && highPtMuons < filterObjs_[i].getNTriggeredLeptons() ) leptons_ok = false;
00163
00164 if ( tau_ok && leptons_ok ) {
00165 ref_events->Fill(i+0.5);
00166 isGoodReferenceEvent.push_back(true);
00167 } else {
00168 isGoodReferenceEvent.push_back(false);
00169 }
00170 }
00171 }
00172
00173
00174 edm::Handle<trigger::TriggerEvent> trigEv;
00175 bool gotTEV = iEvent.getByLabel(triggerEvent_,trigEv) && trigEv.isValid();
00176
00177 if ( gotTEV ) {
00178
00179 for ( size_t i = 0; i < filterObjs_.size(); ++i ) {
00180 std::map<std::string, MonitorElement*>::iterator thisMassDist = mass_distribution.find(filterObjs_[i].getAlias());
00181 size_t ID = trigEv->filterIndex(filterObjs_[i].getFilterName());
00182 if ( ID != trigEv->sizeFilters() ) {
00183 LVColl leptons = getFilterCollection(ID,filterObjs_[i].getLeptonType(),*trigEv);
00184 LVColl taus = getFilterCollection(ID,filterObjs_[i].getTauType(),*trigEv);
00185
00186
00187 if ( filterObjs_[i].getNTriggeredTaus() == 1 && filterObjs_[i].getNTriggeredLeptons() == 0 ) {
00188 triggeredTaus = taus;
00189 }
00190
00191
00192 if ( leptons.size() >= filterObjs_[i].getNTriggeredLeptons() && taus.size() >= filterObjs_[i].getNTriggeredTaus() ) {
00193 accepted_events->Fill(i+0.5);
00194
00195
00196 if ( doRefAnalysis_ ) {
00197 if ( isGoodReferenceEvent.at(i) ) {
00198 size_t nT = 0;
00199 for ( size_t j = 0; j < taus.size(); ++j ) {
00200 if (match(taus[j],refTaus,matchDeltaR_).first) nT++;
00201 }
00202 size_t nL = 0;
00203 for ( size_t j = 0; j < leptons.size(); ++j ) {
00204 if (match(leptons[j],refElectrons,matchDeltaR_).first) nL++;
00205 if (match(leptons[j],refMuons,matchDeltaR_).first) nL++;
00206 }
00207 if ( nT >= filterObjs_[i].getNTriggeredTaus() && nL >= filterObjs_[i].getNTriggeredLeptons() ) {
00208 accepted_events_matched->Fill(i+0.5);
00209 if ( filterObjs_[i].getNTriggeredTaus() >= 2 && refTaus.size() >= 2 ) {
00210 if (thisMassDist != mass_distribution.end()) thisMassDist->second->Fill( (refTaus[0]+refTaus[1]).M() );
00211 } else if ( filterObjs_[i].getNTriggeredTaus() >= 1 && filterObjs_[i].getNTriggeredLeptons() >= 1 ) {
00212 if ( filterObjs_[i].leptonId() == 11 && refElectrons.size() >= 1 ) {
00213 if (thisMassDist != mass_distribution.end()) thisMassDist->second->Fill( (refTaus[0]+refElectrons[0]).M() );
00214 }
00215 if ( filterObjs_[i].leptonId() == 13 && refMuons.size() >= 1 ) {
00216 if (thisMassDist != mass_distribution.end()) thisMassDist->second->Fill( (refTaus[0]+refMuons[0]).M() );
00217 }
00218 }
00219 }
00220 }
00221 } else {
00222 if ( filterObjs_[i].getNTriggeredTaus() >= 2 ) {
00223 if (thisMassDist != mass_distribution.end()) thisMassDist->second->Fill( (taus[0]+taus[1]).M() );
00224 } else if ( filterObjs_[i].getNTriggeredTaus() >= 1 && filterObjs_[i].getNTriggeredLeptons() >= 1 ) {
00225 if (thisMassDist != mass_distribution.end()) thisMassDist->second->Fill( (taus[0]+leptons[0]).M() );
00226 }
00227 }
00228 }
00229 }
00230 }
00231
00232
00233 if ( triggeredTaus.size() > 0 ) {
00234 LV highestTriggeredTau(0.,0.,0.,0.0001);
00235 for ( unsigned int i = 0; i < triggeredTaus.size(); ++i ) {
00236 if ( triggeredTaus[i].pt() > highestTriggeredTau.pt() ) {
00237 highestTriggeredTau = triggeredTaus[i];
00238 }
00239 }
00240
00241 tauEt->Fill(highestTriggeredTau.pt());
00242 tauEta->Fill(highestTriggeredTau.eta());
00243 tauPhi->Fill(highestTriggeredTau.phi());
00244
00245 if ( doRefAnalysis_ && highestRefTau.pt() > 5.0 ) {
00246 tauEtEffDenom->Fill(highestRefTau.pt());
00247 tauEtaEffDenom->Fill(highestRefTau.eta());
00248 tauPhiEffDenom->Fill(highestRefTau.phi());
00249
00250 if ( ROOT::Math::VectorUtil::DeltaR(highestRefTau,highestTriggeredTau) < matchDeltaR_ ) {
00251 tauEtEffNum->Fill(highestRefTau.pt());
00252 tauEtaEffNum->Fill(highestRefTau.eta());
00253 tauPhiEffNum->Fill(highestRefTau.phi());
00254 }
00255 }
00256 }
00257 }
00258 }
00259
00260 LVColl HLTTauDQMLitePathPlotter::getObjectCollection( int id, const trigger::TriggerEvent& trigEv ) {
00261 trigger::TriggerObjectCollection triggerObjects;
00262 triggerObjects = trigEv.getObjects();
00263
00264 LVColl out;
00265 for ( unsigned int i = 0; i < triggerObjects.size(); ++i ) {
00266 if ( abs(triggerObjects[i].id()) == id ) {
00267 LV a(triggerObjects[i].px(),triggerObjects[i].py(),triggerObjects[i].pz(),triggerObjects[i].energy());
00268 out.push_back(a);
00269 }
00270 }
00271 return out;
00272 }
00273
00274 LVColl HLTTauDQMLitePathPlotter::getFilterCollection( size_t index, int id, const trigger::TriggerEvent& trigEv ) {
00275
00276 LVColl out;
00277
00278 const trigger::TriggerObjectCollection& TOC(trigEv.getObjects());
00279
00280
00281 if ( index != trigEv.sizeFilters() ) {
00282 const trigger::Keys& KEYS = trigEv.filterKeys(index);
00283 for ( size_t i = 0; i < KEYS.size(); ++i ) {
00284 const trigger::TriggerObject& TO(TOC[KEYS[i]]);
00285 LV a(TO.px(),TO.py(),TO.pz(),sqrt(TO.px()*TO.px()+TO.py()*TO.py()+TO.pz()*TO.pz()));
00286 out.push_back(a);
00287 }
00288 }
00289 return out;
00290 }