00001 #include "StudyHLT.h"
00002
00003
00004 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00005 #include "DataFormats/Luminosity/interface/LumiDetails.h"
00006 #include "DataFormats/Common/interface/TriggerResults.h"
00007 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
00008 #include "DataFormats/HLTReco/interface/TriggerObject.h"
00009 #include "FWCore/Common/interface/TriggerNames.h"
00010
00011 #include "DataFormats/DetId/interface/DetId.h"
00012 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00013 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00014 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00015 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00016 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00017
00018 #include "Calibration/IsolatedParticles/interface/FindCaloHit.h"
00019 #include "Calibration/IsolatedParticles/interface/CaloPropagateTrack.h"
00020 #include "Calibration/IsolatedParticles/interface/ChargeIsolation.h"
00021 #include "Calibration/IsolatedParticles/interface/eECALMatrix.h"
00022 #include "Calibration/IsolatedParticles/interface/eHCALMatrix.h"
00023
00024 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00025 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00026 #include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h"
00027 #include "Geometry/CaloTopology/interface/CaloSubdetectorTopology.h"
00028 #include "Geometry/CaloTopology/interface/HcalTopology.h"
00029 #include "Geometry/CaloTopology/interface/CaloTopology.h"
00030
00031 #include "MagneticField/Engine/interface/MagneticField.h"
00032 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00033 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
00034 #include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h"
00035 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgo.h"
00036 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgoRcd.h"
00037
00038 StudyHLT::StudyHLT(const edm::ParameterSet& iConfig) : nRun(0) {
00039 verbosity = iConfig.getUntrackedParameter<int>("Verbosity",0);
00040 trigNames = iConfig.getUntrackedParameter<std::vector<std::string> >("Triggers");
00041 theTrackQuality = iConfig.getUntrackedParameter<std::string>("TrackQuality","highPurity");
00042 reco::TrackBase::TrackQuality trackQuality_=reco::TrackBase::qualityByName(theTrackQuality);
00043 selectionParameters.minPt = iConfig.getUntrackedParameter<double>("MinTrackPt", 10.0);
00044 selectionParameters.minQuality = trackQuality_;
00045 selectionParameters.maxDxyPV = iConfig.getUntrackedParameter<double>("MaxDxyPV", 0.2);
00046 selectionParameters.maxDzPV = iConfig.getUntrackedParameter<double>("MaxDzPV", 5.0);
00047 selectionParameters.maxChi2 = iConfig.getUntrackedParameter<double>("MaxChi2", 5.0);
00048 selectionParameters.maxDpOverP = iConfig.getUntrackedParameter<double>("MaxDpOverP", 0.1);
00049 selectionParameters.minOuterHit = iConfig.getUntrackedParameter<int>("MinOuterHit", 4);
00050 selectionParameters.minLayerCrossed = iConfig.getUntrackedParameter<int>("MinLayerCrossed", 8);
00051 selectionParameters.maxInMiss = iConfig.getUntrackedParameter<int>("MaxInMiss", 0);
00052 selectionParameters.maxOutMiss = iConfig.getUntrackedParameter<int>("MaxOutMiss", 0);
00053 minTrackP = iConfig.getUntrackedParameter<double>("MinTrackP", 1.0);
00054 maxTrackEta = iConfig.getUntrackedParameter<double>("MaxTrackEta", 2.5);
00055 tMinE_ = iConfig.getUntrackedParameter<double>("TimeMinCutECAL", -500.);
00056 tMaxE_ = iConfig.getUntrackedParameter<double>("TimeMaxCutECAL", 500.);
00057 tMinH_ = iConfig.getUntrackedParameter<double>("TimeMinCutHCAL", -500.);
00058 tMaxH_ = iConfig.getUntrackedParameter<double>("TimeMaxCutHCAL", 500.);
00059 }
00060
00061 StudyHLT::~StudyHLT(){
00062 }
00063
00064 void StudyHLT::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
00065 if (verbosity > 0) std::cout << "Event starts====================================" << std::endl;
00066 int RunNo = iEvent.id().run();
00067 int EvtNo = iEvent.id().event();
00068 int Lumi = iEvent.luminosityBlock();
00069 int Bunch = iEvent.bunchCrossing();
00070
00071 edm::InputTag lumiProducer("LumiProducer", "", "RECO");
00072 edm::Handle<LumiDetails> Lumid;
00073 iEvent.getLuminosityBlock().getByLabel("lumiProducer",Lumid);
00074
00075 float mybxlumi=-1;
00076 if (Lumid.isValid())
00077 mybxlumi=Lumid->lumiValue(LumiDetails::kOCC1,iEvent.bunchCrossing())*6.37;
00078
00079 if (verbosity > 0)
00080 std::cout << "RunNo " << RunNo << " EvtNo " << EvtNo << " Lumi " << Lumi
00081 << " Bunch " << Bunch << " mybxlumi " << mybxlumi << std::endl;
00082
00083 edm::InputTag triggerEvent_ ("hltTriggerSummaryAOD","","HLT");
00084 trigger::TriggerEvent triggerEvent;
00085 edm::Handle<trigger::TriggerEvent> triggerEventHandle;
00086 iEvent.getByLabel(triggerEvent_,triggerEventHandle);
00087
00088 if (!triggerEventHandle.isValid())
00089 std::cout << "Error! Can't get the product "<< triggerEvent_.label() << std::endl;
00090 else {
00091 triggerEvent = *(triggerEventHandle.product());
00092
00094 edm::InputTag theTriggerResultsLabel ("TriggerResults","","HLT");
00095 edm::Handle<edm::TriggerResults> triggerResults;
00096 iEvent.getByLabel( theTriggerResultsLabel, triggerResults);
00097
00098 if (triggerResults.isValid()) {
00099 h_nHLT->Fill(triggerResults->size());
00100 h_nHLTvsRN->Fill(RunNo, triggerResults->size());
00101
00102 const edm::TriggerNames & triggerNames = iEvent.triggerNames(*triggerResults);
00103 const std::vector<std::string> & triggerNames_ = triggerNames.triggerNames();
00104 bool ok(false);
00105 for (unsigned int iHLT=0; iHLT<triggerResults->size(); iHLT++) {
00106
00107
00108 int ipos=-1;
00109 for (unsigned int i=0; i<HLTNames.size(); ++i) {
00110 if (triggerNames_[iHLT] == HLTNames[i]) {
00111 ipos = i;
00112 break;
00113 }
00114 }
00115 if (ipos < 0) {
00116 ipos = (int)(HLTNames.size()+1);
00117 HLTNames.push_back(triggerNames_[iHLT]);
00118 h_HLTAccept->GetXaxis()->SetBinLabel(ipos+1,triggerNames_[iHLT].c_str());
00119 }
00120 if (firstEvent) h_HLTAccepts[nRun]->GetXaxis()->SetBinLabel(iHLT+1, triggerNames_[iHLT].c_str());
00121 int hlt = triggerResults->accept(iHLT);
00122 if (hlt) {
00123 h_HLTAccepts[nRun]->Fill(iHLT+1);
00124 h_HLTAccept->Fill(ipos+1);
00125 }
00126 if (iHLT >= 499) std::cout << "Wrong trigger " << RunNo << " Event " << EvtNo << " Hlt " << iHLT << std::endl;
00127 for (unsigned int i=0; i<trigNames.size(); ++i) {
00128 if (triggerNames_[iHLT].find(trigNames[i].c_str())!=std::string::npos) {
00129 if(verbosity) std::cout << triggerNames_[iHLT] << std::endl;
00130 if (hlt > 0) ok = true;
00131 }
00132 }
00133 }
00134 if (ok) {
00135
00136 edm::ESHandle<CaloGeometry> pG;
00137 iSetup.get<CaloGeometryRecord>().get(pG);
00138 const CaloGeometry* geo = pG.product();
00139
00140 edm::ESHandle<CaloTopology> theCaloTopology;
00141 iSetup.get<CaloTopologyRecord>().get(theCaloTopology);
00142 const CaloTopology *caloTopology = theCaloTopology.product();
00143
00144 edm::ESHandle<HcalTopology> htopo;
00145 iSetup.get<IdealGeometryRecord>().get(htopo);
00146 const HcalTopology* theHBHETopology = htopo.product();
00147
00148 edm::ESHandle<MagneticField> bFieldH;
00149 iSetup.get<IdealMagneticFieldRecord>().get(bFieldH);
00150 const MagneticField *bField = bFieldH.product();
00151
00152 edm::ESHandle<EcalChannelStatus> ecalChStatus;
00153 iSetup.get<EcalChannelStatusRcd>().get(ecalChStatus);
00154 const EcalChannelStatus* theEcalChStatus = ecalChStatus.product();
00155
00156 edm::Handle<reco::TrackCollection> trkCollection;
00157 iEvent.getByLabel("generalTracks", trkCollection);
00158 reco::TrackCollection::const_iterator trkItr;
00159 int ntrk = 0;
00160 for (trkItr=trkCollection->begin(); trkItr != trkCollection->end(); ++trkItr,++ntrk) {
00161 const reco::Track* pTrack = &(*trkItr);
00162 double pt1 = pTrack->pt();
00163 double p1 = pTrack->p();
00164 double eta1 = pTrack->momentum().eta();
00165 double phi1 = pTrack->momentum().phi();
00166 bool quality = pTrack->quality(selectionParameters.minQuality);
00167 fillTrack(0, pt1,p1,eta1,phi1);
00168 if (quality) fillTrack(1, pt1,p1,eta1,phi1);
00169 }
00170 h_ntrk[0]->Fill(ntrk);
00171
00172 std::vector<spr::propagatedTrackID> trkCaloDets;
00173 spr::propagateCALO(trkCollection, geo, bField, theTrackQuality, trkCaloDets, false);
00174 std::vector<spr::propagatedTrackID>::const_iterator trkDetItr;
00175 for (trkDetItr = trkCaloDets.begin(),ntrk=0; trkDetItr != trkCaloDets.end(); trkDetItr++,ntrk++) {
00176 const reco::Track* pTrack = &(*(trkDetItr->trkItr));
00177 double pt1 = pTrack->pt();
00178 double p1 = pTrack->p();
00179 double eta1 = pTrack->momentum().eta();
00180 double phi1 = pTrack->momentum().phi();
00181 if(verbosity > 0) std::cout << "track (p/pt/eta/phi/okEcal) : " << p1 << "/" << pt1 << "/" << eta1 << "/" << phi1 << "/" << trkDetItr->okECAL << std::endl;
00182 fillTrack(2, pt1,p1,eta1,phi1);
00183
00184 if (pt1>minTrackP && std::abs(eta1)<maxTrackEta && trkDetItr->okECAL) {
00185 fillTrack(3, pt1,p1,eta1,phi1);
00186 double maxNearP31x31 = spr::chargeIsolationEcal(ntrk, trkCaloDets, geo, caloTopology, 15, 15);
00187
00188 edm::ESHandle<EcalSeverityLevelAlgo> sevlv;
00189 iSetup.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
00190
00191 edm::Handle<EcalRecHitCollection> barrelRecHitsHandle;
00192 edm::Handle<EcalRecHitCollection> endcapRecHitsHandle;
00193 iEvent.getByLabel("ecalRecHit","EcalRecHitsEB",barrelRecHitsHandle);
00194 iEvent.getByLabel("ecalRecHit","EcalRecHitsEE",endcapRecHitsHandle);
00195
00196 std::pair<double, bool> e11x11P, e15x15P;
00197 const DetId isoCell = trkDetItr->detIdECAL;
00198 e11x11P = spr::eECALmatrix(isoCell,barrelRecHitsHandle,endcapRecHitsHandle, *theEcalChStatus, geo, caloTopology,sevlv.product(),5,5, 0.060, 0.300, tMinE_,tMaxE_);
00199 e15x15P = spr::eECALmatrix(isoCell,barrelRecHitsHandle,endcapRecHitsHandle, *theEcalChStatus, geo, caloTopology,sevlv.product(),7,7, 0.060, 0.300, tMinE_,tMaxE_);
00200
00201 double maxNearHcalP7x7 = spr::chargeIsolationHcal(ntrk, trkCaloDets, theHBHETopology, 3,3);
00202 double h5x5=0, h7x7=0;
00203 fillIsolation(0, maxNearP31x31,e11x11P.first,e15x15P.first);
00204 if(verbosity > 0) std::cout << "Accepted Tracks reaching Ecal maxNearP31x31/e11x11P/e15x15P/okHCAL " << maxNearP31x31 << "/" << e11x11P.first << "/" << e15x15P.first << "/" << trkDetItr->okHCAL << std::endl;
00205
00206 if (trkDetItr->okHCAL) {
00207 edm::Handle<HBHERecHitCollection> hbhe;
00208 iEvent.getByLabel("hbhereco", hbhe);
00209
00210 const DetId ClosestCell(trkDetItr->detIdHCAL);
00211
00212 h5x5 = spr::eHCALmatrix(theHBHETopology, ClosestCell, hbhe,2,2, false, true, -100.0, -100.0, -100.0, -100.0, tMinH_,tMaxH_);
00213 h7x7 = spr::eHCALmatrix(theHBHETopology, ClosestCell, hbhe,3,3, false, true, -100.0, -100.0, -100.0, -100.0, tMinH_,tMaxH_);
00214 fillIsolation(1, maxNearHcalP7x7,h5x5,h7x7);
00215 if(verbosity) std::cout << "Tracks Reaching Hcal maxNearHcalP7x7/h5x5/h7x7 " << maxNearHcalP7x7 << "/" << h5x5 << "/" << h7x7 << std::endl;
00216 }
00217 if (maxNearP31x31 < 0) {
00218 fillTrack(4, pt1,p1,eta1,phi1);
00219 if (maxNearHcalP7x7 < 0) {
00220 fillTrack(5, pt1,p1,eta1,phi1);
00221 if (e11x11P.second && e15x15P.second && (e15x15P.first-e11x11P.first)<2.0) {
00222 fillTrack(6, pt1,p1,eta1,phi1);
00223 if (h7x7-h5x5 < 2.0) {
00224 fillTrack(7, pt1,p1,eta1,phi1);
00225 }
00226 }
00227 }
00228 }
00229 }
00230 }
00231 h_ntrk[1]->Fill(ntrk);
00232 }
00233 }
00234 }
00235 firstEvent = false;
00236 }
00237
00238 void StudyHLT::beginJob() {
00239 h_nHLT = fs->make<TH1I>("h_nHLT" , "size of trigger Names", 1000, 0, 1000);
00240 h_HLTAccept = fs->make<TH1I>("h_HLTAccept", "HLT Accepts for all runs", 500, 0, 500);
00241 h_nHLTvsRN = fs->make<TH2I>("h_nHLTvsRN" , "size of trigger Names vs RunNo", 2168, 190949, 193116, 100, 400, 500);
00242
00243 char hname[50], htit[100];
00244 std::string CollectionNames[2] = {"Reco", "Propagated"};
00245 for(unsigned int i=0; i<2; i++) {
00246 sprintf(hname, "h_nTrk_%s", CollectionNames[i].c_str());
00247 sprintf(htit, "Number of %s tracks", CollectionNames[i].c_str());
00248 h_ntrk[i] = fs->make<TH1I>(hname, htit, 500, 0, 500);
00249 }
00250 std::string TrkNames[8] = {"All", "Quality", "NoIso", "okEcal", "EcalCharIso", "HcalCharIso", "EcalNeutIso", "HcalNeutIso"};
00251 for(unsigned int i=0; i<8; i++) {
00252 sprintf(hname, "h_pt_%s", TrkNames[i].c_str());
00253 sprintf(htit, "p_{T} of %s tracks", TrkNames[i].c_str());
00254 h_pt[i] = fs->make<TH1D>(hname, htit, 400, 0, 200.0);
00255 h_pt[i]->Sumw2();
00256
00257 sprintf(hname, "h_p_%s", TrkNames[i].c_str());
00258 sprintf(htit, "Momentum of %s tracks", TrkNames[i].c_str());
00259 h_p[i] = fs->make<TH1D>(hname, htit, 400, 0, 200.0);
00260 h_p[i]->Sumw2();
00261
00262 sprintf(hname, "h_eta_%s", TrkNames[i].c_str());
00263 sprintf(htit, "Eta of %s tracks", TrkNames[i].c_str());
00264 h_eta[i] = fs->make<TH1D>(hname, htit, 60, -3.0, 3.0);
00265 h_eta[i]->Sumw2();
00266
00267 sprintf(hname, "h_phi_%s", TrkNames[i].c_str());
00268 sprintf(htit, "Phi of %s tracks", TrkNames[i].c_str());
00269 h_phi[i] = fs->make<TH1D>(hname, htit, 100, -3.15, 3.15);
00270 h_phi[i]->Sumw2();
00271 }
00272 std::string IsolationNames[2] = {"Ecal", "Hcal"};
00273 for(unsigned int i=0; i<2; i++) {
00274 sprintf(hname, "h_maxNearP_%s", IsolationNames[i].c_str());
00275 sprintf(htit, "Energy in ChargeIso region for %s", IsolationNames[i].c_str());
00276 h_maxNearP[i] = fs->make<TH1D>(hname, htit, 120, -1.5, 10.5);
00277 h_maxNearP[i]->Sumw2();
00278
00279 sprintf(hname, "h_ene1_%s", IsolationNames[i].c_str());
00280 sprintf(htit, "Energy in smaller cone for %s", IsolationNames[i].c_str());
00281 h_ene1[i] = fs->make<TH1D>(hname, htit, 400, 0.0, 200.0);
00282 h_ene1[i]->Sumw2();
00283
00284 sprintf(hname, "h_ene2_%s", IsolationNames[i].c_str());
00285 sprintf(htit, "Energy in bigger cone for %s", IsolationNames[i].c_str());
00286 h_ene2[i] = fs->make<TH1D>(hname, htit, 400, 0.0, 200.0);
00287 h_ene2[i]->Sumw2();
00288
00289 sprintf(hname, "h_ediff_%s", IsolationNames[i].c_str());
00290 sprintf(htit, "Energy in NeutralIso region for %s", IsolationNames[i].c_str());
00291 h_ediff[i] = fs->make<TH1D>(hname, htit, 100, -0.5, 19.5);
00292 h_ediff[i]->Sumw2();
00293 }
00294 }
00295
00296 void StudyHLT::endJob() {}
00297
00298
00299 void StudyHLT::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
00300 char hname[100], htit[100];
00301 std::cout << "Run[" << nRun << "] " << iRun.run() << " hltconfig.init "
00302 << hltConfig_.init(iRun,iSetup,"HLT",changed) << std::endl;
00303 sprintf(hname, "h_HLTAccepts_%i", iRun.run());
00304 sprintf(htit, "HLT Accepts for Run No %i", iRun.run());
00305 TH1I *hnew = fs->make<TH1I>(hname, htit, 500, 0, 500);
00306 h_HLTAccepts.push_back(hnew);
00307 std::cout << "beginrun " << iRun.run() << std::endl;
00308 firstEvent = true;
00309 }
00310
00311
00312 void StudyHLT::endRun(edm::Run const& iRun, edm::EventSetup const&) {
00313 nRun++;
00314 std::cout << "endrun[" << nRun << "] " << iRun.run() << std::endl;
00315 }
00316
00317
00318 void StudyHLT::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) {}
00319
00320 void StudyHLT::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) {}
00321
00322 void StudyHLT::fillTrack(int i, double pt, double p, double eta, double phi){
00323 h_pt[i]->Fill(pt);
00324 h_p[i]->Fill(p);
00325 h_eta[i]->Fill(eta);
00326 h_phi[i]->Fill(phi);
00327 }
00328
00329 void StudyHLT::fillIsolation(int i, double emaxnearP, double eneutIso1, double eneutIso2){
00330 h_maxNearP[i]->Fill(emaxnearP);
00331 h_ene1[i]->Fill(eneutIso1);
00332 h_ene2[i]->Fill(eneutIso2);
00333 h_ediff[i]->Fill(eneutIso2-eneutIso1);
00334 }
00335
00336 DEFINE_FWK_MODULE(StudyHLT);
00337