CMS 3D CMS Logo

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