CMS 3D CMS Logo

HcalHBHENewMuonAnalyzer.cc
Go to the documentation of this file.
1 #include <fstream>
2 #include <vector>
3 #include <TTree.h>
4 
5 // user include files
15 
17 
18 //#define EDM_ML_DEBUG
19 
20 class HcalHBHENewMuonAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
21 public:
23  ~HcalHBHENewMuonAnalyzer() override = default;
24 
25  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
26 
27 private:
28  void beginJob() override;
29  void analyze(edm::Event const&, edm::EventSetup const&) override;
30 
31  // ----------member data ---------------------------
33  const int useRaw_;
34  const int maxDepth_;
35  int kount_;
36 
38 
40  static const int depthMax_ = 7;
41  TTree* tree_;
43  unsigned int goodVertex_;
75  std::vector<std::string> all_triggers_;
76  std::vector<int> hltresults_;
78 };
79 
81  : labelHBHEMuonVar_(iConfig.getParameter<edm::InputTag>("hbheMuonLabel")),
82  useRaw_(iConfig.getParameter<int>("useRaw")),
83  maxDepth_(iConfig.getUntrackedParameter<int>("maxDepth", 7)),
84  tokHBHEMuonVar_(consumes<HcalHBHEMuonVariablesCollection>(labelHBHEMuonVar_)) {
85  usesResource(TFileService::kSharedResource);
86  //now do what ever initialization is needed
87  kount_ = 0;
88 
89  edm::LogVerbatim("HBHEMuon") << "Parameters read from config file \n\t maxDepth__ " << maxDepth_ << "\n\t Labels "
91 }
92 
93 //
94 // member functions
95 //
96 
97 // ------------ method called for each event ------------
99  ++kount_;
100  runNumber_ = iEvent.id().run();
101  eventNumber_ = iEvent.id().event();
102  lumiNumber_ = iEvent.id().luminosityBlock();
103  bxNumber_ = iEvent.bunchCrossing();
104 #ifdef EDM_ML_DEBUG
105  edm::LogVerbatim("HBHEMuon") << "Run " << runNumber_ << " Event " << eventNumber_ << " Lumi " << lumiNumber_ << " BX "
106  << bxNumber_ << std::endl;
107 #endif
108 
109  auto const& hbheMuonColl = iEvent.getHandle(tokHBHEMuonVar_);
110  if (hbheMuonColl.isValid()) {
111  for (const auto& itr : (*(hbheMuonColl.product()))) {
112  goodVertex_ = itr.goodVertex_;
113  muon_is_good_ = itr.muonGood_;
114  muon_global_ = itr.muonGlobal_;
115  muon_tracker_ = itr.muonTracker_;
116  muon_is_tight_ = itr.muonTight_;
117  muon_is_medium_ = itr.muonMedium_;
118  ptGlob_ = itr.ptGlob_;
119  etaGlob_ = itr.etaGlob_;
120  phiGlob_ = itr.phiGlob_;
121  energyMuon_ = itr.energyMuon_;
122  pMuon_ = itr.pMuon_;
123  muon_trkKink_ = itr.muonTrkKink_;
124  muon_chi2LocalPosition_ = itr.muonChi2LocalPosition_;
125  muon_segComp_ = itr.muonSegComp_;
126  trackerLayer_ = itr.trackerLayer_;
127  numPixelLayers_ = itr.numPixelLayers_;
128  tight_PixelHits_ = itr.tightPixelHits_;
129  innerTrack_ = itr.innerTrack_;
130  outerTrack_ = itr.outerTrack_;
131  globalTrack_ = itr.globalTrack_;
132  chiTracker_ = itr.chiTracker_;
133  dxyTracker_ = itr.dxyTracker_;
134  dzTracker_ = itr.dzTracker_;
135  innerTrackpt_ = itr.innerTrackPt_;
136  innerTracketa_ = itr.innerTrackEta_;
137  innerTrackphi_ = itr.innerTrackPhi_;
138  tight_validFraction_ = itr.tightValidFraction_;
139  outerTrackChi_ = itr.outerTrackChi_;
140  outerTrackPt_ = itr.outerTrackPt_;
141  outerTrackEta_ = itr.outerTrackEta_;
142  outerTrackPhi_ = itr.outerTrackPhi_;
143  outerTrackHits_ = itr.outerTrackHits_;
144  outerTrackRHits_ = itr.outerTrackRHits_;
145  globalTrckPt_ = itr.globalTrackPt_;
146  globalTrckEta_ = itr.globalTrackEta_;
147  globalTrckPhi_ = itr.globalTrackPhi_;
148  globalMuonHits_ = itr.globalMuonHits_;
149  matchedStat_ = itr.matchedStat_;
150  chiGlobal_ = itr.chiGlobal_;
151  tight_LongPara_ = itr.tightLongPara_;
152  tight_TransImpara_ = itr.tightTransImpara_;
153  isolationR04_ = itr.isolationR04_;
154  isolationR03_ = itr.isolationR03_;
155  ecalEnergy_ = itr.ecalEnergy_;
156  hcalEnergy_ = itr.hcalEnergy_;
157  hoEnergy_ = itr.hoEnergy_;
158  matchedId_ = itr.matchedId_;
159  hcalHot_ = itr.hcalHot_;
160  ecal3x3Energy_ = itr.ecal3x3Energy_;
161  ecalDetId_ = itr.ecalDetId_;
162  hcalDetId_ = itr.hcalDetId_;
163  ehcalDetId_ = itr.ehcalDetId_;
164  hcal_ieta_ = itr.hcalIeta_;
165  hcal_iphi_ = itr.hcalIphi_;
166  if (useRaw_ == 1)
167  hcal1x1Energy_ = itr.hcal1x1EnergyAux_;
168  else if (useRaw_ == 2)
169  hcal1x1Energy_ = itr.hcal1x1EnergyRaw_;
170  else
171  hcal1x1Energy_ = itr.hcal1x1Energy_;
172  for (unsigned int i = 0; i < itr.hcalDepthEnergy_.size(); ++i) {
173  hcalDepthActiveLength_[i] = itr.hcalDepthActiveLength_[i];
174  hcalDepthActiveLengthHot_[i] = itr.hcalDepthActiveLengthHot_[i];
175  if (useRaw_ == 1) {
176  hcalDepthEnergy_[i] = itr.hcalDepthEnergyAux_[i];
177  hcalDepthEnergyHot_[i] = itr.hcalDepthEnergyHotAux_[i];
178  hcalDepthEnergyCorr_[i] = itr.hcalDepthEnergyCorrAux_[i];
179  hcalDepthEnergyHotCorr_[i] = itr.hcalDepthEnergyHotCorrAux_[i];
180  hcalDepthChargeHot_[i] = itr.hcalDepthChargeHotAux_[i];
181  hcalDepthChargeHotBG_[i] = itr.hcalDepthChargeHotBGAux_[i];
182  } else if (useRaw_ == 2) {
183  hcalDepthEnergy_[i] = itr.hcalDepthEnergyRaw_[i];
184  hcalDepthEnergyHot_[i] = itr.hcalDepthEnergyHotRaw_[i];
185  hcalDepthEnergyCorr_[i] = itr.hcalDepthEnergyCorrRaw_[i];
186  hcalDepthEnergyHotCorr_[i] = itr.hcalDepthEnergyHotCorrRaw_[i];
187  hcalDepthChargeHot_[i] = itr.hcalDepthChargeHotRaw_[i];
188  hcalDepthChargeHotBG_[i] = itr.hcalDepthChargeHotBGRaw_[i];
189  } else {
190  hcalDepthEnergy_[i] = itr.hcalDepthEnergy_[i];
191  hcalDepthEnergyHot_[i] = itr.hcalDepthEnergyHot_[i];
192  hcalDepthEnergyCorr_[i] = itr.hcalDepthEnergyCorr_[i];
193  hcalDepthEnergyHotCorr_[i] = itr.hcalDepthEnergyHotCorr_[i];
194  hcalDepthChargeHot_[i] = itr.hcalDepthChargeHot_[i];
195  hcalDepthChargeHotBG_[i] = itr.hcalDepthChargeHotBG_[i];
196  }
197  hcalDepthMatch_[i] = itr.hcalDepthMatch_[i];
198  hcalDepthMatchHot_[i] = itr.hcalDepthMatchHot_[i];
199  }
200  hcalActiveLength_ = itr.hcalActiveLength_;
201  hcalActiveLengthHot_ = itr.hcalActiveLengthHot_;
202  all_triggers_ = itr.allTriggers_;
203  hltresults_ = itr.hltResults_;
204  tree_->Fill();
205  }
206  }
207 }
208 
209 // ------------ method called once each job just before starting event loop ------------
212  tree_ = fs->make<TTree>("TREE", "TREE");
213  tree_->Branch("Event_No", &eventNumber_);
214  tree_->Branch("Run_No", &runNumber_);
215  tree_->Branch("LumiNumber", &lumiNumber_);
216  tree_->Branch("BXNumber", &bxNumber_);
217  tree_->Branch("GoodVertex", &goodVertex_);
218  tree_->Branch("PF_Muon", &muon_is_good_);
219  tree_->Branch("Global_Muon", &muon_global_);
220  tree_->Branch("Tracker_muon", &muon_tracker_);
221  tree_->Branch("MuonIsTight", &muon_is_tight_);
222  tree_->Branch("MuonIsMedium", &muon_is_medium_);
223  tree_->Branch("pt_of_muon", &ptGlob_);
224  tree_->Branch("eta_of_muon", &etaGlob_);
225  tree_->Branch("phi_of_muon", &phiGlob_);
226  tree_->Branch("energy_of_muon", &energyMuon_);
227  tree_->Branch("p_of_muon", &pMuon_);
228  tree_->Branch("muon_trkKink", &muon_trkKink_);
229  tree_->Branch("muon_chi2LocalPosition", &muon_chi2LocalPosition_);
230  tree_->Branch("muon_segComp", &muon_segComp_);
231 
232  tree_->Branch("TrackerLayer", &trackerLayer_);
233  tree_->Branch("NumPixelLayers", &numPixelLayers_);
234  tree_->Branch("InnerTrackPixelHits", &tight_PixelHits_);
235  tree_->Branch("innerTrack", &innerTrack_);
236  tree_->Branch("chiTracker", &chiTracker_);
237  tree_->Branch("DxyTracker", &dxyTracker_);
238  tree_->Branch("DzTracker", &dzTracker_);
239  tree_->Branch("innerTrackpt", &innerTrackpt_);
240  tree_->Branch("innerTracketa", &innerTracketa_);
241  tree_->Branch("innerTrackphi", &innerTrackphi_);
242  tree_->Branch("tight_validFraction", &tight_validFraction_);
243 
244  tree_->Branch("OuterTrack", &outerTrack_);
245  tree_->Branch("OuterTrackChi", &outerTrackChi_);
246  tree_->Branch("OuterTrackPt", &outerTrackPt_);
247  tree_->Branch("OuterTrackEta", &outerTrackEta_);
248  tree_->Branch("OuterTrackPhi", &outerTrackPhi_);
249  tree_->Branch("OuterTrackHits", &outerTrackHits_);
250  tree_->Branch("OuterTrackRHits", &outerTrackRHits_);
251 
252  tree_->Branch("GlobalTrack", &globalTrack_);
253  tree_->Branch("GlobalTrckPt", &globalTrckPt_);
254  tree_->Branch("GlobalTrckEta", &globalTrckEta_);
255  tree_->Branch("GlobalTrckPhi", &globalTrckPhi_);
256  tree_->Branch("Global_Muon_Hits", &globalMuonHits_);
257  tree_->Branch("MatchedStations", &matchedStat_);
258  tree_->Branch("GlobTrack_Chi", &chiGlobal_);
259  tree_->Branch("Tight_LongitudinalImpactparameter", &tight_LongPara_);
260  tree_->Branch("Tight_TransImpactparameter", &tight_TransImpara_);
261 
262  tree_->Branch("IsolationR04", &isolationR04_);
263  tree_->Branch("IsolationR03", &isolationR03_);
264  tree_->Branch("ecal_3into3", &ecalEnergy_);
265  tree_->Branch("hcal_3into3", &hcalEnergy_);
266  tree_->Branch("tracker_3into3", &hoEnergy_);
267 
268  tree_->Branch("matchedId", &matchedId_);
269  tree_->Branch("hcal_cellHot", &hcalHot_);
270 
271  tree_->Branch("ecal_3x3", &ecal3x3Energy_);
272  tree_->Branch("hcal_1x1", &hcal1x1Energy_);
273  tree_->Branch("ecal_detID", &ecalDetId_);
274  tree_->Branch("hcal_detID", &hcalDetId_);
275  tree_->Branch("ehcal_detID", &ehcalDetId_);
276  tree_->Branch("hcal_ieta", &hcal_ieta_);
277  tree_->Branch("hcal_iphi", &hcal_iphi_);
278 
279  char name[100];
280  for (int k = 0; k < maxDepth_; ++k) {
281  sprintf(name, "hcal_edepth%d", (k + 1));
282  tree_->Branch(name, &hcalDepthEnergy_[k]);
283  sprintf(name, "hcal_activeL%d", (k + 1));
284  tree_->Branch(name, &hcalDepthActiveLength_[k]);
285  sprintf(name, "hcal_edepthHot%d", (k + 1));
286  tree_->Branch(name, &hcalDepthEnergyHot_[k]);
287  sprintf(name, "hcal_activeHotL%d", (k + 1));
289  sprintf(name, "hcal_cdepthHot%d", (k + 1));
290  tree_->Branch(name, &hcalDepthChargeHot_[k]);
291  sprintf(name, "hcal_cdepthHotBG%d", (k + 1));
292  tree_->Branch(name, &hcalDepthChargeHotBG_[k]);
293  sprintf(name, "hcal_edepthCorrect%d", (k + 1));
294  tree_->Branch(name, &hcalDepthEnergyCorr_[k]);
295  sprintf(name, "hcal_edepthHotCorrect%d", (k + 1));
296  tree_->Branch(name, &hcalDepthEnergyHotCorr_[k]);
297  sprintf(name, "hcal_depthMatch%d", (k + 1));
298  tree_->Branch(name, &hcalDepthMatch_[k]);
299  sprintf(name, "hcal_depthMatchHot%d", (k + 1));
300  tree_->Branch(name, &hcalDepthMatchHot_[k]);
301  }
302 
303  tree_->Branch("activeLength", &hcalActiveLength_);
304  tree_->Branch("activeLengthHot", &hcalActiveLengthHot_);
305 
306  tree_->Branch("hltresults", &hltresults_);
307  tree_->Branch("all_triggers", &all_triggers_);
308 }
309 
310 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
313  desc.add<edm::InputTag>("hbheMuonLabel", edm::InputTag("alcaHcalHBHEMuonProducer", "hbheMuon"));
314  desc.add<int>("useRaw", 0);
315  desc.addUntracked<int>("maxDepth", 7);
316  descriptions.add("hcalHBHEMuonAnalysis", desc);
317 }
318 
319 //define this as a plug-in
321 
static const std::string kSharedResource
Definition: TFileService.h:76
Log< level::Info, true > LogVerbatim
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
HcalHBHENewMuonAnalyzer(const edm::ParameterSet &)
std::vector< HcalHBHEMuonVariables > HcalHBHEMuonVariablesCollection
double hcalDepthEnergyHot_[depthMax_]
double hcalDepthEnergyCorr_[depthMax_]
int iEvent
Definition: GenABIO.cc:224
double hcalDepthChargeHotBG_[depthMax_]
const edm::InputTag labelHBHEMuonVar_
const edm::EDGetTokenT< HcalHBHEMuonVariablesCollection > tokHBHEMuonVar_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
double hcalDepthActiveLength_[depthMax_]
std::vector< std::string > all_triggers_
void analyze(edm::Event const &, edm::EventSetup const &) override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
double hcalDepthActiveLengthHot_[depthMax_]
HLT enums.
~HcalHBHENewMuonAnalyzer() override=default
double hcalDepthChargeHot_[depthMax_]
double hcalDepthEnergyHotCorr_[depthMax_]