CMS 3D CMS Logo

HcalIsoTrackAnalyzer.cc
Go to the documentation of this file.
1 // system include files
2 #include <string>
3 #include <vector>
4 
5 // Root objects
6 #include "TTree.h"
7 
10 
13 
19 
20 //#define EDM_ML_DEBUG
21 
22 class HcalIsoTrackAnalyzer : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
23 public:
24  explicit HcalIsoTrackAnalyzer(edm::ParameterSet const&);
25  ~HcalIsoTrackAnalyzer() override {}
26 
27  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
28 
29 private:
30  void analyze(edm::Event const&, edm::EventSetup const&) override;
31  void beginJob() override;
32  void beginRun(edm::Run const&, edm::EventSetup const&) override {}
33  void endRun(edm::Run const&, edm::EventSetup const&) override;
34 
35  const double pTrackLow_, pTrackHigh_;
36  const int useRaw_, dataType_;
38  const std::vector<int> debEvents_;
41  unsigned int nRun_, nRange_, nLow_, nHigh_;
42 
43  TTree *tree, *tree2;
49  double t_mindR1, t_mindR2;
55  std::vector<unsigned int> t_DetIds, t_DetIds1, t_DetIds3;
57  std::vector<bool> t_trgbits;
58 
59  unsigned int t_RunNo, t_EventNo;
63  std::vector<int> t_ietaAll, t_ietaGood, t_trackType;
64  std::vector<bool> t_hltbits;
65 };
66 
68  : pTrackLow_(iConfig.getParameter<double>("momentumLow")),
69  pTrackHigh_(iConfig.getParameter<double>("momentumHigh")),
70  useRaw_(iConfig.getUntrackedParameter<int>("useRaw", 0)),
71  dataType_(iConfig.getUntrackedParameter<int>("dataType", 0)),
72  labelIsoTkVar_(iConfig.getParameter<edm::InputTag>("isoTrackVarLabel")),
73  labelIsoTkEvt_(iConfig.getParameter<edm::InputTag>("isoTrackEvtLabel")),
74  debEvents_(iConfig.getParameter<std::vector<int>>("debugEvents")),
75  tokIsoTrkVar_(consumes<HcalIsoTrkCalibVariablesCollection>(labelIsoTkVar_)),
76  tokIsoTrkEvt_(consumes<HcalIsoTrkEventVariablesCollection>(labelIsoTkEvt_)),
77  nRun_(0),
78  nRange_(0),
79  nLow_(0),
80  nHigh_(0) {
81  usesResource(TFileService::kSharedResource);
82 
83  //now do whatever initialization is needed
84  edm::LogVerbatim("HcalIsoTrack") << "Labels used " << labelIsoTkVar_ << " " << labelIsoTkEvt_;
85 
86  edm::LogVerbatim("HcalIsoTrack") << "Parameters read from config file \n\t momentumLow_ " << pTrackLow_
87  << "\t momentumHigh_ " << pTrackHigh_ << "\t useRaw_ " << useRaw_
88  << "\t dataType_ " << dataType_ << " and " << debEvents_.size()
89  << " events to be debugged";
90 }
91 
93  t_Run = iEvent.id().run();
94  t_Event = iEvent.id().event();
96 #ifdef EDM_ML_DEBUG
97  bool debug = (debEvents_.empty())
98  ? true
99  : (std::find(debEvents_.begin(), debEvents_.end(), iEvent.id().event()) != debEvents_.end());
100  if (debug)
101  edm::LogVerbatim("HcalIsoTrack") << "Run " << t_Run << " Event " << t_Event << " type " << t_DataType
102  << " Luminosity " << iEvent.luminosityBlock() << " Bunch "
103  << iEvent.bunchCrossing();
104 #endif
105 
106  // Fill from IsoTrkCalibVariables collection
107  auto const& isotrkCalibColl = iEvent.getHandle(tokIsoTrkVar_);
108  if (isotrkCalibColl.isValid()) {
109  auto isotrkCalib = *isotrkCalibColl.product();
110 #ifdef EDM_ML_DEBUG
111  if (debug)
112  edm::LogVerbatim("HcalIsoTrack") << "Finds HcalIsoTrkCalibVariablesCollection with " << isotrkCalib.size()
113  << " entries";
114  int k(0);
115 #endif
116  for (const auto& itr : isotrkCalib) {
117  t_ieta = itr.ieta_;
118  t_iphi = itr.iphi_;
119  t_goodPV = itr.goodPV_;
120  t_nVtx = itr.nVtx_;
121  t_nTrk = itr.nTrk_;
122  t_EventWeight = itr.eventWeight_;
123  t_p = itr.p_;
124  t_pt = itr.pt_;
125  t_phi = itr.phi_;
126 #ifdef EDM_ML_DEBUG
127  ++k;
128  if (debug)
129  edm::LogVerbatim("HcalIsoTrack") << "Track " << k << " p:pt:phi " << t_p << ":" << t_pt << ":" << t_phi
130  << " nvtx:ntrk:goodPV:wt " << t_nVtx << ":" << t_nTrk << ":" << t_goodPV << ":"
131  << t_EventWeight << " ieta:iphi " << t_ieta << ":" << t_iphi;
132 #endif
133  t_l1pt = itr.l1pt_;
134  t_l1eta = itr.l1eta_;
135  t_l1phi = itr.l1phi_;
136  t_l3pt = itr.l3pt_;
137  t_l3eta = itr.l3eta_;
138  t_l3phi = itr.l3phi_;
139  t_mindR1 = itr.mindR1_;
140  t_mindR2 = itr.mindR2_;
141 #ifdef EDM_ML_DEBUG
142  if (debug)
143  edm::LogVerbatim("HcalIsoTrack") << "L1 pt:eta:phi " << t_l1pt << ":" << t_l1eta << ":" << t_l1phi
144  << " L3 pt:eta:phi " << t_l3pt << ":" << t_l3eta << ":" << t_l3phi << " R1:R2 "
145  << t_mindR1 << ":" << t_mindR2;
146 #endif
147  t_eMipDR = itr.eMipDR_[0];
148  t_eMipDR2 = itr.eMipDR_[1];
149  t_eMipDR3 = itr.eMipDR_[2];
150  t_eMipDR4 = itr.eMipDR_[3];
151  t_eMipDR5 = itr.eMipDR_[4];
152 #ifdef EDM_ML_DEBUG
153  if (debug)
154  edm::LogVerbatim("HcalIsoTrack") << "eMIPDR 1:2:3:4:5 " << t_eMipDR << ":" << t_eMipDR2 << ":" << t_eMipDR3
155  << ":" << t_eMipDR4 << ":" << t_eMipDR5;
156 #endif
157  t_hmaxNearP = itr.hmaxNearP_;
158  t_emaxNearP = itr.emaxNearP_;
159  t_eAnnular = itr.eAnnular_;
160  t_hAnnular = itr.hAnnular_;
161 #ifdef EDM_ML_DEBUG
162  if (debug)
163  edm::LogVerbatim("HcalIsoTrack") << "emaxNearP:hmaxNearP " << t_emaxNearP << ":" << t_hmaxNearP
164  << " eAnnlar:hAnnular" << t_eAnnular << ":" << t_hAnnular;
165 #endif
166  t_gentrackP = itr.gentrackP_;
167  t_rhoh = itr.rhoh_;
168  t_selectTk = itr.selectTk_;
169  t_qltyFlag = itr.qltyFlag_;
170  t_qltyMissFlag = itr.qltyMissFlag_;
171  t_qltyPVFlag = itr.qltyPVFlag_;
172 #ifdef EDM_ML_DEBUG
173  if (debug)
174  edm::LogVerbatim("HcalIsoTrack") << "gentrackP " << t_gentrackP << " rhoh " << t_rhoh
175  << " qltyFlag:qltyMissFlag:qltyPVFlag:selectTk " << t_qltyFlag << ":"
176  << t_qltyMissFlag << ":" << t_qltyPVFlag << ":" << t_selectTk;
177 #endif
178  t_trgbits = itr.trgbits_;
179  t_DetIds = itr.detIds_;
180  t_DetIds1 = itr.detIds1_;
181  t_DetIds3 = itr.detIds3_;
182  if (useRaw_ == 1) {
183  t_eHcal = itr.eHcalAux_;
184  t_eHcal10 = itr.eHcal10Aux_;
185  t_eHcal30 = itr.eHcal30Aux_;
186  t_HitEnergies = itr.hitEnergiesAux_;
187  t_HitEnergies1 = itr.hitEnergies1Aux_;
188  t_HitEnergies3 = itr.hitEnergies3Aux_;
189  } else if (useRaw_ == 2) {
190  t_eHcal = itr.eHcalRaw_;
191  t_eHcal10 = itr.eHcal10Raw_;
192  t_eHcal30 = itr.eHcal30Raw_;
193  t_HitEnergies = itr.hitEnergiesRaw_;
194  t_HitEnergies1 = itr.hitEnergies1Raw_;
195  t_HitEnergies3 = itr.hitEnergies3Raw_;
196  } else {
197  t_eHcal = itr.eHcal_;
198  t_eHcal10 = itr.eHcal10_;
199  t_eHcal30 = itr.eHcal30_;
200  t_HitEnergies = itr.hitEnergies_;
201  t_HitEnergies1 = itr.hitEnergies1_;
202  t_HitEnergies3 = itr.hitEnergies3_;
203  }
204 #ifdef EDM_ML_DEBUG
205  if (debug)
206  edm::LogVerbatim("HcalIsoTrack") << "eHcal:eHcal10:eHCal30 " << t_eHcal << ":" << t_eHcal10 << t_eHcal30;
207 #endif
208  tree->Fill();
209  edm::LogVerbatim("HcalIsoTrackX") << "Run " << t_Run << " Event " << t_Event << " p " << t_p;
210 
211  if (t_p < pTrackLow_) {
212  ++nLow_;
213  } else if (t_p < pTrackHigh_) {
214  ++nHigh_;
215  } else {
216  ++nRange_;
217  }
218  }
219  } else {
220  edm::LogVerbatim("HcalIsoTrack") << "Cannot find HcalIsoTrkCalibVariablesCollection";
221  }
222 
223  // Fill from IsoTrkEventVariables collection
224  auto const& isotrkEventColl = iEvent.getHandle(tokIsoTrkEvt_);
225  if (isotrkEventColl.isValid()) {
226  auto isotrkEvent = isotrkEventColl.product();
227 #ifdef EDM_ML_DEBUG
228  if (debug)
229  edm::LogVerbatim("HcalIsoTrack") << "Finds HcalIsoTrkEventVariablesCollection with " << isotrkEvent->size()
230  << " entries";
231 #endif
232  auto itr = isotrkEvent->begin();
233  if (itr != isotrkEvent->end()) {
234  t_RunNo = iEvent.id().run();
235  t_EventNo = iEvent.id().event();
236  t_TrigPass = itr->trigPass_;
237  t_TrigPassSel = itr->trigPassSel_;
238  t_L1Bit = itr->l1Bit_;
239  t_Tracks = itr->tracks_;
240  t_TracksProp = itr->tracksProp_;
241  t_TracksSaved = itr->tracksSaved_;
242  t_TracksLoose = itr->tracksLoose_;
243  t_TracksTight = itr->tracksTight_;
244  t_allvertex = itr->allvertex_;
245  t_ietaAll = itr->ietaAll_;
246  t_ietaGood = itr->ietaGood_;
247  t_trackType = itr->trackType_;
248  t_hltbits = itr->hltbits_;
249  tree2->Fill();
250  }
251  } else {
252  edm::LogVerbatim("HcalIsoTrack") << "Cannot find HcalIsoTrkEventVariablesCollections";
253  }
254 }
255 
258  tree = fs->make<TTree>("CalibTree", "CalibTree");
259 
260  tree->Branch("t_Run", &t_Run, "t_Run/I");
261  tree->Branch("t_Event", &t_Event, "t_Event/I");
262  tree->Branch("t_DataType", &t_DataType, "t_DataType/I");
263  tree->Branch("t_ieta", &t_ieta, "t_ieta/I");
264  tree->Branch("t_iphi", &t_iphi, "t_iphi/I");
265  tree->Branch("t_EventWeight", &t_EventWeight, "t_EventWeight/D");
266  tree->Branch("t_nVtx", &t_nVtx, "t_nVtx/I");
267  tree->Branch("t_nTrk", &t_nTrk, "t_nTrk/I");
268  tree->Branch("t_goodPV", &t_goodPV, "t_goodPV/I");
269  tree->Branch("t_l1pt", &t_l1pt, "t_l1pt/D");
270  tree->Branch("t_l1eta", &t_l1eta, "t_l1eta/D");
271  tree->Branch("t_l1phi", &t_l1phi, "t_l1phi/D");
272  tree->Branch("t_l3pt", &t_l3pt, "t_l3pt/D");
273  tree->Branch("t_l3eta", &t_l3eta, "t_l3eta/D");
274  tree->Branch("t_l3phi", &t_l3phi, "t_l3phi/D");
275  tree->Branch("t_p", &t_p, "t_p/D");
276  tree->Branch("t_pt", &t_pt, "t_pt/D");
277  tree->Branch("t_phi", &t_phi, "t_phi/D");
278  tree->Branch("t_mindR1", &t_mindR1, "t_mindR1/D");
279  tree->Branch("t_mindR2", &t_mindR2, "t_mindR2/D");
280  tree->Branch("t_eMipDR", &t_eMipDR, "t_eMipDR/D");
281  tree->Branch("t_eMipDR2", &t_eMipDR2, "t_eMipDR2/D");
282  tree->Branch("t_eMipDR3", &t_eMipDR3, "t_eMipDR3/D");
283  tree->Branch("t_eMipDR4", &t_eMipDR4, "t_eMipDR4/D");
284  tree->Branch("t_eMipDR5", &t_eMipDR5, "t_eMipDR5/D");
285  tree->Branch("t_eHcal", &t_eHcal, "t_eHcal/D");
286  tree->Branch("t_eHcal10", &t_eHcal10, "t_eHcal10/D");
287  tree->Branch("t_eHcal30", &t_eHcal30, "t_eHcal30/D");
288  tree->Branch("t_hmaxNearP", &t_hmaxNearP, "t_hmaxNearP/D");
289  tree->Branch("t_emaxNearP", &t_emaxNearP, "t_emaxNearP/D");
290  tree->Branch("t_eAnnular", &t_eAnnular, "t_eAnnular/D");
291  tree->Branch("t_hAnnular", &t_hAnnular, "t_hAnnular/D");
292  tree->Branch("t_rhoh", &t_rhoh, "t_rhoh/D");
293  tree->Branch("t_selectTk", &t_selectTk, "t_selectTk/O");
294  tree->Branch("t_qltyFlag", &t_qltyFlag, "t_qltyFlag/O");
295  tree->Branch("t_qltyMissFlag", &t_qltyMissFlag, "t_qltyMissFlag/O");
296  tree->Branch("t_qltyPVFlag", &t_qltyPVFlag, "t_qltyPVFlag/O");
297  tree->Branch("t_gentrackP", &t_gentrackP, "t_gentrackP/D");
298 
299  tree->Branch("t_DetIds", &t_DetIds);
300  tree->Branch("t_HitEnergies", &t_HitEnergies);
301  tree->Branch("t_trgbits", &t_trgbits);
302  tree->Branch("t_DetIds1", &t_DetIds1);
303  tree->Branch("t_DetIds3", &t_DetIds3);
304  tree->Branch("t_HitEnergies1", &t_HitEnergies1);
305  tree->Branch("t_HitEnergies3", &t_HitEnergies3);
306 
307  tree2 = fs->make<TTree>("EventInfo", "Event Information");
308 
309  tree2->Branch("t_RunNo", &t_RunNo, "t_RunNo/i");
310  tree2->Branch("t_EventNo", &t_EventNo, "t_EventNo/i");
311  tree2->Branch("t_Tracks", &t_Tracks, "t_Tracks/I");
312  tree2->Branch("t_TracksProp", &t_TracksProp, "t_TracksProp/I");
313  tree2->Branch("t_TracksSaved", &t_TracksSaved, "t_TracksSaved/I");
314  tree2->Branch("t_TracksLoose", &t_TracksLoose, "t_TracksLoose/I");
315  tree2->Branch("t_TracksTight", &t_TracksTight, "t_TracksTight/I");
316  tree2->Branch("t_TrigPass", &t_TrigPass, "t_TrigPass/O");
317  tree2->Branch("t_TrigPassSel", &t_TrigPassSel, "t_TrigPassSel/O");
318  tree2->Branch("t_L1Bit", &t_L1Bit, "t_L1Bit/O");
319  tree2->Branch("t_allvertex", &t_allvertex, "t_allvertex/I");
320  tree2->Branch("t_ietaAll", &t_ietaAll);
321  tree2->Branch("t_ietaGood", &t_ietaGood);
322  tree2->Branch("t_trackType", &t_trackType);
323  tree2->Branch("t_hltbits", &t_hltbits);
324 }
325 
326 // ------------ method called when starting to processes a run ------------
327 
328 // ------------ method called when ending the processing of a run ------------
330  nRun_++;
331  edm::LogVerbatim("HcalIsoTrack") << "endRun[" << nRun_ << "] " << iRun.run() << " with " << nLow_
332  << " events with p < " << pTrackLow_ << ", " << nHigh_ << " events with p > "
333  << pTrackHigh_ << ", and " << nRange_ << " events in the right momentum range";
334 }
335 
338  desc.add<double>("momentumLow", 40.0);
339  desc.add<double>("momentumHigh", 60.0);
340  desc.addUntracked<int>("useRaw", 0);
341  desc.addUntracked<int>("dataType", 0);
342  desc.add<edm::InputTag>("isoTrackVarLabel", edm::InputTag("alcaHcalIsotrkProducer", "HcalIsoTrack"));
343  desc.add<edm::InputTag>("isoTrackEvtLabel", edm::InputTag("alcaHcalIsotrkProducer", "HcalIsoTrackEvent"));
344  std::vector<int> events;
345  desc.add<std::vector<int>>("debugEvents", events);
346  descriptions.add("hcalIsoTrackAnalyzer", desc);
347 }
348 
349 //define this as a plug-in
static const std::string kSharedResource
Definition: TFileService.h:76
Log< level::Info, true > LogVerbatim
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< double > t_HitEnergies1
const std::vector< int > debEvents_
void beginRun(edm::Run const &, edm::EventSetup const &) override
std::vector< double > t_HitEnergies3
edm::EDGetTokenT< HcalIsoTrkEventVariablesCollection > tokIsoTrkEvt_
std::vector< int > t_ietaGood
void endRun(edm::Run const &, edm::EventSetup const &) override
std::vector< unsigned int > t_DetIds3
std::vector< unsigned int > t_DetIds
std::vector< double > t_HitEnergies
const edm::InputTag labelIsoTkEvt_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::vector< HcalIsoTrkEventVariables > HcalIsoTrkEventVariablesCollection
HcalIsoTrackAnalyzer(edm::ParameterSet const &)
int iEvent
Definition: GenABIO.cc:224
RunNumber_t run() const
Definition: RunBase.h:40
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< bool > t_trgbits
edm::EDGetTokenT< HcalIsoTrkCalibVariablesCollection > tokIsoTrkVar_
std::vector< int > t_ietaAll
#define debug
Definition: HDRShower.cc:19
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const edm::InputTag labelIsoTkVar_
std::vector< HcalIsoTrkCalibVariables > HcalIsoTrkCalibVariablesCollection
void analyze(edm::Event const &, edm::EventSetup const &) override
HLT enums.
std::vector< int > t_trackType
std::vector< bool > t_hltbits
Definition: tree.py:1
std::vector< unsigned int > t_DetIds1
int events
Definition: Run.h:45