CMS 3D CMS Logo

StudyTriggerHLT.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: IsolatedParticles
4 // Class: StudyTriggerHLT
5 //
13 //
14 // Original Author: Sunanda Banerjee
15 // Created: Thu Mar 4 18:52:02 CST 2011
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 #include <string>
22 
23 // Root objects
24 #include "TH1.h"
25 #include "TH2.h"
26 
27 // user include files
30 
35 
54 
55 class StudyTriggerHLT : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
56 public:
57  explicit StudyTriggerHLT(const edm::ParameterSet&);
58  ~StudyTriggerHLT() override {}
59 
60  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
61 
62 private:
63  void analyze(edm::Event const&, edm::EventSetup const&) override;
64  void beginJob() override;
65  void beginRun(edm::Run const&, edm::EventSetup const&) override;
66  void endRun(edm::Run const&, edm::EventSetup const&) override;
69 
71 
72  // ----------member data ---------------------------
75  const int verbosity_;
76  const std::vector<std::string> trigNames_, newNames_;
80  std::vector<std::string> HLTNames_;
83 
88  std::vector<bool> mediumMuon_;
90  TH2I* h_nHLTvsRN;
91  std::vector<TH1I*> h_HLTAccepts;
92  TH1D *h_pt, *h_eta, *h_phi, *h_dr1, *h_dr2, *h_dr3;
93  int nRun_;
94 };
95 
97  : verbosity_(iConfig.getParameter<int>("verbosity")),
98  triggerEvent_(edm::InputTag("hltTriggerSummaryAOD", "", "HLT")),
99  theTriggerResultsLabel_(edm::InputTag("TriggerResults", "", "HLT")),
100  labelMuon_(iConfig.getParameter<edm::InputTag>("labelMuon")),
101  labelGenTrack_(iConfig.getParameter<edm::InputTag>("labelTrack")),
102  theTrackQuality_(iConfig.getParameter<std::string>("trackQuality")),
103  nRun_(0) {
104  usesResource(TFileService::kSharedResource);
106 
107  // define tokens for access
108  tok_trigEvt = consumes<trigger::TriggerEvent>(triggerEvent_);
109  tok_trigRes = consumes<edm::TriggerResults>(theTriggerResultsLabel_);
110  tok_Muon_ = consumes<reco::MuonCollection>(labelMuon_);
111  tok_genTrack_ = consumes<reco::TrackCollection>(labelGenTrack_);
112 
113  edm::LogVerbatim("StudyHLT") << "Verbosity " << verbosity_ << " Trigger labels " << triggerEvent_ << " and "
114  << theTriggerResultsLabel_ << " Labels used: Track " << labelGenTrack_ << " Muon "
115  << labelMuon_ << " Track Quality " << theTrackQuality_;
116 
117  firstEvent_ = true;
118  changed_ = false;
119 }
120 
123  desc.add<int>("verbosity", 0);
124  desc.add<edm::InputTag>("labelMuon", edm::InputTag("muons", "", "RECO"));
125  desc.add<edm::InputTag>("labelTrack", edm::InputTag("generalTracks", "", "RECO"));
126  desc.add<std::string>("trackQuality", "highPurity");
127  descriptions.add("studyTriggerHLT", desc);
128 }
129 
131  int RunNo = iEvent.id().run();
132  int EvtNo = iEvent.id().event();
133 
134  if (verbosity_ > 0)
135  edm::LogVerbatim("StudyHLT") << "RunNo " << RunNo << " EvtNo " << EvtNo << " Lumi " << iEvent.luminosityBlock()
136  << " Bunch " << iEvent.bunchCrossing();
137 
139  edm::Handle<trigger::TriggerEvent> triggerEventHandle;
140  iEvent.getByToken(tok_trigEvt, triggerEventHandle);
141 
142  if (!triggerEventHandle.isValid()) {
143  edm::LogWarning("StudyHLT") << "Error! Can't get the product " << triggerEvent_.label();
144  } else {
145  triggerEvent = *(triggerEventHandle.product());
146 
149  iEvent.getByToken(tok_trigRes, triggerResults);
150 
151  if (triggerResults.isValid()) {
152  h_nHLT->Fill(triggerResults->size());
153  h_nHLTvsRN->Fill(RunNo, triggerResults->size());
154 
155  const edm::TriggerNames& triggerNames = iEvent.triggerNames(*triggerResults);
156  const std::vector<std::string>& triggerNames_ = triggerNames.triggerNames();
157  for (unsigned int iHLT = 0; iHLT < triggerResults->size(); iHLT++) {
158  int ipos = -1;
159  std::string newtriggerName = truncate_str(triggerNames_[iHLT]);
160  for (unsigned int i = 0; i < HLTNames_.size(); ++i) {
161  if (newtriggerName == HLTNames_[i]) {
162  ipos = i + 1;
163  break;
164  }
165  }
166  if (ipos < 0) {
167  HLTNames_.push_back(newtriggerName);
168  ipos = (int)(HLTNames_.size());
169  if (ipos <= h_HLTAccept->GetNbinsX())
170  h_HLTAccept->GetXaxis()->SetBinLabel(ipos, newtriggerName.c_str());
171  }
172  if ((int)(iHLT + 1) > h_HLTAccepts[nRun_]->GetNbinsX()) {
173  edm::LogVerbatim("StudyHLT") << "Wrong trigger " << RunNo << " Event " << EvtNo << " Hlt " << iHLT;
174  } else {
175  if (firstEvent_)
176  h_HLTAccepts[nRun_]->GetXaxis()->SetBinLabel(iHLT + 1, newtriggerName.c_str());
177  }
178  int hlt = triggerResults->accept(iHLT);
179  if (hlt) {
180  h_HLTAccepts[nRun_]->Fill(iHLT + 1);
181  h_HLTAccept->Fill(ipos);
182  }
183  }
184  }
185  }
186  firstEvent_ = false;
187 
188  double globalMin = 1000;
189  edm::Handle<reco::MuonCollection> muonEventHandle;
190  iEvent.getByToken(tok_Muon_, muonEventHandle);
191  edm::Handle<reco::TrackCollection> trackEventHandle;
192  iEvent.getByToken(tok_genTrack_, trackEventHandle);
193  edm::LogVerbatim("StudyHLT") << "Muon Handle " << muonEventHandle.isValid() << " Track Handle "
194  << trackEventHandle.isValid();
195  for (reco::TrackCollection::const_iterator track1 = trackEventHandle->begin(); track1 != trackEventHandle->end();
196  ++track1) {
197  double localMin = 1000;
198  if (muonEventHandle.isValid()) {
199  for (reco::MuonCollection::const_iterator recMuon = muonEventHandle->begin(); recMuon != muonEventHandle->end();
200  ++recMuon) {
201  if (((recMuon->isPFMuon()) && (recMuon->isGlobalMuon() || recMuon->isTrackerMuon())) &&
202  (recMuon->innerTrack()->validFraction() > 0.49)) {
203  double chiGlobal = ((recMuon->globalTrack().isNonnull()) ? recMuon->globalTrack()->normalizedChi2() : 999);
204  bool goodGlob =
205  (recMuon->isGlobalMuon() && chiGlobal < 3 && recMuon->combinedQuality().chi2LocalPosition < 12 &&
206  recMuon->combinedQuality().trkKink < 20);
207  if (muon::segmentCompatibility(*recMuon) > (goodGlob ? 0.303 : 0.451)) {
208  double dr = reco::deltaR(track1->eta(), track1->phi(), recMuon->eta(), recMuon->phi());
209  if (dr < localMin) {
210  localMin = dr;
211  if (localMin < globalMin)
212  globalMin = localMin;
213  }
214  }
215  }
216  }
217  }
218  h_pt->Fill(track1->pt());
219  h_eta->Fill(track1->eta());
220  h_phi->Fill(track1->phi());
221  h_dr1->Fill(localMin);
222  if (track1->quality(trackQuality_))
223  h_dr3->Fill(localMin);
224  edm::LogVerbatim("StudyHLT") << "Track pT " << track1->pt() << " eta " << track1->eta() << " phi " << track1->phi()
225  << " minimum distance " << localMin;
226  }
227  edm::LogVerbatim("StudyHLT") << "GlobalMinimum = " << globalMin;
228  h_dr2->Fill(globalMin);
229 }
230 
232  // Book histograms
233  h_nHLT = fs_->make<TH1I>("h_nHLT", "size of trigger Names", 1000, 0, 1000);
234  h_HLTAccept = fs_->make<TH1I>("h_HLTAccept", "HLT Accepts for all runs", 500, 0, 500);
235  for (int i = 1; i <= 500; ++i)
236  h_HLTAccept->GetXaxis()->SetBinLabel(i, " ");
237  h_nHLTvsRN = fs_->make<TH2I>("h_nHLTvsRN", "size of trigger Names vs RunNo", 300, 319200, 319500, 100, 400, 500);
238  h_pt = fs_->make<TH1D>("h_pt", "p_{t}", 50, 0, 20);
239  h_pt->Sumw2();
240  h_eta = fs_->make<TH1D>("h_eta", "#eta", 50, -3, 3);
241  h_eta->Sumw2();
242  h_phi = fs_->make<TH1D>("h_phi", "#phi", 50, -10, 10);
243  h_phi->Sumw2();
244  h_dr1 = fs_->make<TH1D>("dR1", "#Delta R (Track)", 1000, 0, 0.1);
245  h_dr1->Sumw2();
246  h_dr2 = fs_->make<TH1D>("dR2", "#Delta R (Global)", 3000, 0, 0.000003);
247  h_dr2->Sumw2();
248  h_dr3 = fs_->make<TH1D>("dR3", "#Delta R (Good Track)", 1000, 0, 0.1);
249  h_dr3->Sumw2();
250 }
251 
252 // ------------ method called when starting to processes a run ------------
253 void StudyTriggerHLT::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
254  char hname[100], htit[400];
255  edm::LogVerbatim("StudyHLT") << "Run[" << nRun_ << "] " << iRun.run() << " hltconfig.init "
256  << hltConfig_.init(iRun, iSetup, "HLT", changed_);
257  sprintf(hname, "h_HLTAccepts_%i", iRun.run());
258  sprintf(htit, "HLT Accepts for Run No %i", iRun.run());
259  TH1I* hnew = fs_->make<TH1I>(hname, htit, 500, 0, 500);
260  for (int i = 1; i <= 500; ++i)
261  hnew->GetXaxis()->SetBinLabel(i, " ");
262  h_HLTAccepts.push_back(hnew);
263  edm::LogVerbatim("StudyHLT") << "beginRun " << iRun.run();
264  firstEvent_ = true;
265  changed_ = false;
266 }
267 
268 // ------------ method called when ending the processing of a run ------------
270  ++nRun_;
271  edm::LogVerbatim("StudyHLT") << "endRun[" << nRun_ << "] " << iRun.run();
272 }
273 
275  std::string truncated_str(str);
276  int length = str.length();
277  for (int i = 0; i < length - 2; i++) {
278  if (str[i] == '_' && str[i + 1] == 'v' && isdigit(str.at(i + 2))) {
279  int z = i + 1;
280  truncated_str = str.substr(0, z);
281  }
282  }
283  return (truncated_str);
284 }
285 
StudyTriggerHLT::tok_Muon_
edm::EDGetTokenT< reco::MuonCollection > tok_Muon_
Definition: StudyTriggerHLT.cc:86
StudyTriggerHLT::beginLuminosityBlock
virtual void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
Definition: StudyTriggerHLT.cc:67
EDAnalyzer.h
mps_fire.i
i
Definition: mps_fire.py:428
StudyTriggerHLT::mediumMuon_
std::vector< bool > mediumMuon_
Definition: StudyTriggerHLT.cc:88
Muon.h
MessageLogger.h
edm::Handle::product
T const * product() const
Definition: Handle.h:70
TriggerResults.h
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
muon::segmentCompatibility
float segmentCompatibility(const reco::Muon &muon, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
Definition: MuonSelectors.cc:61
edm::Run
Definition: Run.h:45
StudyTriggerHLT::verbosity_
const int verbosity_
Definition: StudyTriggerHLT.cc:75
TriggerEvent.h
edm::EDGetTokenT< trigger::TriggerEvent >
TrackBase.h
edm
HLT enums.
Definition: AlignableModifier.h:19
StudyTriggerHLT::h_HLTAccepts
std::vector< TH1I * > h_HLTAccepts
Definition: StudyTriggerHLT.cc:91
StudyTriggerHLT::triggerEvent_
const edm::InputTag triggerEvent_
Definition: StudyTriggerHLT.cc:77
StudyTriggerHLT::hltConfig_
HLTConfigProvider hltConfig_
Definition: StudyTriggerHLT.cc:73
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
triggerResults
static const std::string triggerResults
Definition: EdmProvDump.cc:45
StudyTriggerHLT::tok_genTrack_
edm::EDGetTokenT< reco::TrackCollection > tok_genTrack_
Definition: StudyTriggerHLT.cc:87
StudyTriggerHLT::newNames_
const std::vector< std::string > newNames_
Definition: StudyTriggerHLT.cc:76
reco::TrackBase::TrackQuality
TrackQuality
track quality
Definition: TrackBase.h:150
StudyTriggerHLT::h_dr1
TH1D * h_dr1
Definition: StudyTriggerHLT.cc:92
StudyTriggerHLT::theTrackQuality_
const std::string theTrackQuality_
Definition: StudyTriggerHLT.cc:79
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
StudyTriggerHLT::StudyTriggerHLT
StudyTriggerHLT(const edm::ParameterSet &)
Definition: StudyTriggerHLT.cc:96
edm::Handle< trigger::TriggerEvent >
StudyTriggerHLT::endRun
void endRun(edm::Run const &, edm::EventSetup const &) override
Definition: StudyTriggerHLT.cc:269
edm::RunBase::run
RunNumber_t run() const
Definition: RunBase.h:40
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
StudyTriggerHLT::h_phi
TH1D * h_phi
Definition: StudyTriggerHLT.cc:92
StudyTriggerHLT::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: StudyTriggerHLT.cc:121
StudyTriggerHLT::labelGenTrack_
const edm::InputTag labelGenTrack_
Definition: StudyTriggerHLT.cc:78
StudyTriggerHLT::h_HLTCorr
TH1I * h_HLTCorr
Definition: StudyTriggerHLT.cc:89
StudyTriggerHLT::trackQuality_
reco::TrackBase::TrackQuality trackQuality_
Definition: StudyTriggerHLT.cc:82
StudyTriggerHLT::analyze
void analyze(edm::Event const &, edm::EventSetup const &) override
Definition: StudyTriggerHLT.cc:130
edm::InputTag::label
std::string const & label() const
Definition: InputTag.h:36
MakerMacros.h
Track.h
TrackFwd.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
StudyTriggerHLT
Definition: StudyTriggerHLT.cc:55
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
StudyTriggerHLT::trigNames_
const std::vector< std::string > trigNames_
Definition: StudyTriggerHLT.cc:76
StudyTriggerHLT::tok_trigEvt
edm::EDGetTokenT< trigger::TriggerEvent > tok_trigEvt
Definition: StudyTriggerHLT.cc:84
L1TEGammaOffline_cfi.triggerNames
triggerNames
Definition: L1TEGammaOffline_cfi.py:40
MuonSelectors.h
Service.h
MuonFwd.h
StudyTriggerHLT::fs_
edm::Service< TFileService > fs_
Definition: StudyTriggerHLT.cc:74
DDAxes::z
StudyTriggerHLT::HLTNames_
std::vector< std::string > HLTNames_
Definition: StudyTriggerHLT.cc:80
str
#define str(s)
Definition: TestProcessor.cc:51
StudyTriggerHLT::endLuminosityBlock
virtual void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
Definition: StudyTriggerHLT.cc:68
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
StudyTriggerHLT::h_HLTAccept
TH1I * h_HLTAccept
Definition: StudyTriggerHLT.cc:89
TFileService.h
StudyTriggerHLT::h_dr3
TH1D * h_dr3
Definition: StudyTriggerHLT.cc:92
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
deltaR.h
TrackSelection.h
StudyTriggerHLT::h_nHLTvsRN
TH2I * h_nHLTvsRN
Definition: StudyTriggerHLT.cc:90
StudyTriggerHLT::beginJob
void beginJob() override
Definition: StudyTriggerHLT.cc:231
edm::Service< TFileService >
createfilelist.int
int
Definition: createfilelist.py:10
TriggerNames.h
iEvent
int iEvent
Definition: GenABIO.cc:224
StudyTriggerHLT::h_dr2
TH1D * h_dr2
Definition: StudyTriggerHLT.cc:92
StudyTriggerHLT::tok_trigRes
edm::EDGetTokenT< edm::TriggerResults > tok_trigRes
Definition: StudyTriggerHLT.cc:85
StudyTriggerHLT::h_nHLT
TH1I * h_nHLT
Definition: StudyTriggerHLT.cc:89
StudyTriggerHLT::~StudyTriggerHLT
~StudyTriggerHLT() override
Definition: StudyTriggerHLT.cc:58
edm::EventSetup
Definition: EventSetup.h:57
trigger::TriggerEvent
The single EDProduct to be saved for each event (AOD case)
Definition: TriggerEvent.h:25
HLTConfigProvider.h
StudyTriggerHLT::nRun_
int nRun_
Definition: StudyTriggerHLT.cc:93
HitPattern.h
PDWG_DiPhoton_SD_cff.triggerEvent
triggerEvent
Definition: PDWG_DiPhoton_SD_cff.py:39
TriggerObject.h
reco::TrackBase::qualityByName
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:126
StudyTriggerHLT::labelMuon_
const edm::InputTag labelMuon_
Definition: StudyTriggerHLT.cc:78
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
HLTConfigProvider
Definition: HLTConfigProvider.h:29
std
Definition: JetResolutionObject.h:76
HLTConfigProvider::init
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d'tor
Definition: HLTConfigProvider.cc:36
Frameworkfwd.h
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
flavorHistoryFilter_cfi.dr
dr
Definition: flavorHistoryFilter_cfi.py:37
TFileService::kSharedResource
static const std::string kSharedResource
Definition: TFileService.h:76
edm::TriggerNames
Definition: TriggerNames.h:55
StudyTriggerHLT::changed_
bool changed_
Definition: StudyTriggerHLT.cc:81
reco::deltaR
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
StudyTriggerHLT::firstEvent_
bool firstEvent_
Definition: StudyTriggerHLT.cc:81
StudyTriggerHLT::h_pt
TH1D * h_pt
Definition: StudyTriggerHLT.cc:92
StudyTriggerHLT::truncate_str
std::string truncate_str(const std::string &)
Definition: StudyTriggerHLT.cc:274
ParameterSet.h
StudyTriggerHLT::h_eta
TH1D * h_eta
Definition: StudyTriggerHLT.cc:92
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
StudyTriggerHLT::beginRun
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: StudyTriggerHLT.cc:253
edm::InputTag
Definition: InputTag.h:15
L1GlobalTriggerReadoutRecord.h
EcalChannelStatusRcd.h
TFileService::make
T * make(const Args &... args) const
make new ROOT object
Definition: TFileService.h:64
StudyTriggerHLT::theTriggerResultsLabel_
const edm::InputTag theTriggerResultsLabel_
Definition: StudyTriggerHLT.cc:77
ValidationMatrix.hlt
hlt
Definition: ValidationMatrix.py:459