CMS 3D CMS Logo

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