CMS 3D CMS Logo

MuonSimHitsValidAnalyzer.cc
Go to the documentation of this file.
2 
3 #include "TFile.h"
4 #include "TTree.h"
5 #include "TBranch.h"
6 #include "TH1F.h"
7 
8 #include <iostream>
9 #include <string>
10 
11 using namespace edm;
12 using namespace std;
13 
15  : fName(""),
16  verbosity(0),
17  label(""),
18  getAllProvenances(false),
19  printProvenanceInfo(false),
20  nRawGenPart(0),
21  count(0)
22 
23 {
25  fName = iPSet.getUntrackedParameter<std::string>("Name");
26  verbosity = iPSet.getUntrackedParameter<int>("Verbosity");
27  label = iPSet.getParameter<std::string>("Label");
28  edm::ParameterSet m_Prov = iPSet.getParameter<edm::ParameterSet>("ProvenanceLookup");
29  getAllProvenances = m_Prov.getUntrackedParameter<bool>("GetAllProvenances");
30  printProvenanceInfo = m_Prov.getUntrackedParameter<bool>("PrintProvenanceInfo");
31 
32  nRawGenPart = 0;
33 
35  DTHitsToken_ = consumes<edm::PSimHitContainer>(iPSet.getParameter<edm::InputTag>("DTHitsSrc"));
36 
38 
39  if (verbosity) {
40  Labels l;
41  labelsForToken(DTHitsToken_, l);
42  edm::LogInfo("MuonSimHitsValidAnalyzer::MuonSimHitsValidAnalyzer")
43  << "\n===============================\n"
44  << "Initialized as EDAnalyzer with parameter values:\n"
45  << " Name = " << fName << "\n"
46  << " Verbosity = " << verbosity << "\n"
47  << " Label = " << label << "\n"
48  << " GetProv = " << getAllProvenances << "\n"
49  << " PrintProv = " << printProvenanceInfo
50  << "\n"
51  // << " CSCHitsSrc= " <<CSCHitsSrc_.label()
52  // << ":" << CSCHitsSrc_.instance() << "\n"
53  << " DTHitsSrc = " << l.module << ":" << l.productInstance
54  << "\n"
55  // << " RPCHitsSrc= " <<RPCHitsSrc_.label()
56  // << ":" << RPCHitsSrc_.instance() << "\n"
57  << "===============================\n";
58  }
59 
60  pow6 = 1000000.0;
61  mom4 = 0.;
62  mom1 = 0;
63  costeta = 0.;
64  radius = 0;
65  sinteta = 0.;
66  globposx = 0.;
67  globposy = 0;
68  nummu_DT = 0;
69  nummu_CSC = 0;
70  nummu_RPC = 0;
71  geomToken_ = esConsumes<DTGeometry, MuonGeometryRecord>();
72 }
73 
75 
77  edm::Run const& iRun,
78  edm::EventSetup const& /* iSetup */) {
79  meAllDTHits = nullptr;
80  meMuDTHits = nullptr;
81  meToF = nullptr;
82  meEnergyLoss = nullptr;
83  meMomentumMB1 = nullptr;
84  meMomentumMB4 = nullptr;
85  meLossMomIron = nullptr;
86  meLocalXvsZ = nullptr;
87  meLocalXvsY = nullptr;
88  meGlobalXvsZ = nullptr;
89  meGlobalXvsY = nullptr;
90  meGlobalXvsZWm2 = nullptr;
91  meGlobalXvsZWm1 = nullptr;
92  meGlobalXvsZW0 = nullptr;
93  meGlobalXvsZWp1 = nullptr;
94  meGlobalXvsZWp2 = nullptr;
95  meGlobalXvsYWm2 = nullptr;
96  meGlobalXvsYWm1 = nullptr;
97  meGlobalXvsYW0 = nullptr;
98  meGlobalXvsYWp1 = nullptr;
99  meGlobalXvsYWp2 = nullptr;
100  meWheelOccup = nullptr;
101  meStationOccup = nullptr;
102  meSectorOccup = nullptr;
103  meSuperLOccup = nullptr;
104  meLayerOccup = nullptr;
105  meWireOccup = nullptr;
106  mePathMuon = nullptr;
107  meChamberOccup = nullptr;
108  meHitRadius = nullptr;
109  meCosTheta = nullptr;
110  meGlobalEta = nullptr;
111  meGlobalPhi = nullptr;
112 
113  Char_t histo_n[100];
114  Char_t histo_t[100];
115 
116  iBooker.setCurrentFolder("MuonDTHitsV/DTHitsValidationTask");
117 
118  sprintf(histo_n, "Number_of_all_DT_hits");
119  sprintf(histo_t, "Number_of_all_DT_hits");
120  meAllDTHits = iBooker.book1D(histo_n, histo_t, 200, 1.0, 201.0);
121 
122  sprintf(histo_n, "Number_of_muon_DT_hits");
123  sprintf(histo_t, "Number_of_muon_DT_hits");
124  meMuDTHits = iBooker.book1D(histo_n, histo_t, 150, 1.0, 151.0);
125 
126  sprintf(histo_n, "Tof_of_hits ");
127  sprintf(histo_t, "Tof_of_hits ");
128  meToF = iBooker.book1D(histo_n, histo_t, 100, -0.5, 50.);
129 
130  sprintf(histo_n, "DT_energy_loss_keV");
131  sprintf(histo_t, "DT_energy_loss_keV");
132  meEnergyLoss = iBooker.book1D(histo_n, histo_t, 100, 0.0, 10.0);
133 
134  sprintf(histo_n, "Momentum_at_MB1");
135  sprintf(histo_t, "Momentum_at_MB1");
136  meMomentumMB1 = iBooker.book1D(histo_n, histo_t, 100, 10.0, 200.0);
137 
138  sprintf(histo_n, "Momentum_at_MB4");
139  sprintf(histo_t, "Momentum_at_MB4");
140  meMomentumMB4 = iBooker.book1D(histo_n, histo_t, 100, 10.0, 200.0);
141 
142  sprintf(histo_n, "Loss_of_muon_Momentum_in_Iron");
143  sprintf(histo_t, "Loss_of_muon_Momentum_in_Iron");
144  meLossMomIron = iBooker.book1D(histo_n, histo_t, 80, 0.0, 40.0);
145 
146  sprintf(histo_n, "Local_x-coord_vs_local_z-coord_of_muon_hit");
147  sprintf(histo_t, "Local_x-coord_vs_local_z-coord_of_muon_hit");
148  meLocalXvsZ = iBooker.book2D(histo_n, histo_t, 100, -150., 150., 100, -0.8, 0.8);
149 
150  sprintf(histo_n, "local_x-coord_vs_local_y-coord_of_muon_hit");
151  sprintf(histo_t, "local_x-coord_vs_local_y-coord_of_muon_hit");
152  meLocalXvsY = iBooker.book2D(histo_n, histo_t, 100, -150., 150., 100, -150., 150.);
153 
154  sprintf(histo_n, "Global_x-coord_vs_global_z-coord_of_muon_hit");
155  sprintf(histo_t, "Global_x-coord_vs_global_z-coord_of_muon_hit");
156  meGlobalXvsZ = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800.);
157 
158  sprintf(histo_n, "Global_x-coord_vs_global_y-coord_of_muon_hit");
159  sprintf(histo_t, "Global_x-coord_vs_global_y-coord_of_muon_hit");
160  meGlobalXvsY = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800.);
161 
162  // New histos
163 
164  sprintf(histo_n, "Global_x-coord_vs_global_z-coord_of_muon_hit_w-2");
165  sprintf(histo_t, "Global_x-coord_vs_global_z-coord_of_muon_hit_w-2");
166  meGlobalXvsZWm2 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800.);
167 
168  sprintf(histo_n, "Global_x-coord_vs_global_y-coord_of_muon_hit_w-2");
169  sprintf(histo_t, "Global_x-coord_vs_global_y-coord_of_muon_hit_w-2");
170  meGlobalXvsYWm2 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800.);
171 
172  sprintf(histo_n, "Global_x-coord_vs_global_z-coord_of_muon_hit_w-1");
173  sprintf(histo_t, "Global_x-coord_vs_global_z-coord_of_muon_hit_w-1");
174  meGlobalXvsZWm1 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800.);
175 
176  sprintf(histo_n, "Global_x-coord_vs_global_y-coord_of_muon_hit_w-1");
177  sprintf(histo_t, "Global_x-coord_vs_global_y-coord_of_muon_hit_w-1");
178  meGlobalXvsYWm1 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800.);
179 
180  sprintf(histo_n, "Global_x-coord_vs_global_z-coord_of_muon_hit_w0");
181  sprintf(histo_t, "Global_x-coord_vs_global_z-coord_of_muon_hit_w0");
182  meGlobalXvsZW0 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800.);
183 
184  sprintf(histo_n, "Global_x-coord_vs_global_y-coord_of_muon_hit_w0");
185  sprintf(histo_t, "Global_x-coord_vs_global_y-coord_of_muon_hit_w0");
186  meGlobalXvsYW0 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800.);
187 
188  sprintf(histo_n, "Global_x-coord_vs_global_z-coord_of_muon_hit_w1");
189  sprintf(histo_t, "Global_x-coord_vs_global_z-coord_of_muon_hit_w1");
190  meGlobalXvsZWp1 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800.);
191 
192  sprintf(histo_n, "Global_x-coord_vs_global_y-coord_of_muon_hit_w1");
193  sprintf(histo_t, "Global_x-coord_vs_global_y-coord_of_muon_hit_w1");
194  meGlobalXvsYWp1 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800.);
195 
196  sprintf(histo_n, "Global_x-coord_vs_global_z-coord_of_muon_hit_w2");
197  sprintf(histo_t, "Global_x-coord_vs_global_z-coord_of_muon_hit_w2");
198  meGlobalXvsZWp2 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800.);
199 
200  sprintf(histo_n, "Global_x-coord_vs_global_y-coord_of_muon_hit_w2");
201  sprintf(histo_t, "Global_x-coord_vs_global_y-coord_of_muon_hit_w2");
202  meGlobalXvsYWp2 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800.);
203 
204  //
205 
206  sprintf(histo_n, "Wheel_occupancy");
207  sprintf(histo_t, "Wheel_occupancy");
208  meWheelOccup = iBooker.book1D(histo_n, histo_t, 10, -5.0, 5.0);
209 
210  sprintf(histo_n, "Station_occupancy");
211  sprintf(histo_t, "Station_occupancy");
212  meStationOccup = iBooker.book1D(histo_n, histo_t, 6, 0., 6.0);
213 
214  sprintf(histo_n, "Sector_occupancy");
215  sprintf(histo_t, "Sector_occupancy");
216  meSectorOccup = iBooker.book1D(histo_n, histo_t, 20, 0., 20.);
217 
218  sprintf(histo_n, "SuperLayer_occupancy");
219  sprintf(histo_t, "SuperLayer_occupancy");
220  meSuperLOccup = iBooker.book1D(histo_n, histo_t, 5, 0., 5.);
221 
222  sprintf(histo_n, "Layer_occupancy");
223  sprintf(histo_t, "Layer_occupancy");
224  meLayerOccup = iBooker.book1D(histo_n, histo_t, 6, 0., 6.);
225 
226  sprintf(histo_n, "Wire_occupancy");
227  sprintf(histo_t, "Wire_occupancy");
228  meWireOccup = iBooker.book1D(histo_n, histo_t, 100, 0., 100.);
229 
230  sprintf(histo_n, "path_followed_by_muon");
231  sprintf(histo_t, "path_followed_by_muon");
232  mePathMuon = iBooker.book1D(histo_n, histo_t, 160, 0., 160.);
233 
234  sprintf(histo_n, "chamber_occupancy");
235  sprintf(histo_t, "chamber_occupancy");
236  meChamberOccup = iBooker.book1D(histo_n, histo_t, 251, 0., 251.);
237 
238  sprintf(histo_n, "radius_of_hit");
239  sprintf(histo_t, "radius_of_hit");
240  meHitRadius = iBooker.book1D(histo_n, histo_t, 100, 0., 1200.);
241 
242  sprintf(histo_n, "costheta_of_hit");
243  sprintf(histo_t, "costheta_of_hit");
244  meCosTheta = iBooker.book1D(histo_n, histo_t, 100, -1., 1.);
245 
246  sprintf(histo_n, "global_eta_of_hit");
247  sprintf(histo_t, "global_eta_of_hit");
248  meGlobalEta = iBooker.book1D(histo_n, histo_t, 60, -2.7, 2.7);
249 
250  sprintf(histo_n, "global_phi_of_hit");
251  sprintf(histo_t, "global_phi_of_hit");
252  meGlobalPhi = iBooker.book1D(histo_n, histo_t, 60, -3.14, 3.14);
253 }
254 
257  ++count;
258 
260  edm::RunNumber_t nrun = iEvent.id().run();
261  edm::EventNumber_t nevt = iEvent.id().event();
262 
263  if (verbosity > 0) {
264  edm::LogInfo("MuonSimHitsValidAnalyzer::analyze") << "Processing run " << nrun << ", event " << nevt;
265  }
266 
268  if (getAllProvenances) {
269  std::vector<const edm::StableProvenance*> AllProv;
270  iEvent.getAllStableProvenance(AllProv);
271 
272  if (verbosity > 0)
273  edm::LogInfo("MuonSimHitsValidAnalyzer::analyze") << "Number of Provenances = " << AllProv.size();
274 
275  if (printProvenanceInfo && (verbosity > 0)) {
276  TString eventout("\nProvenance info:\n");
277 
278  for (unsigned int i = 0; i < AllProv.size(); ++i) {
279  eventout += "\n ******************************";
280  eventout += "\n Module : ";
281  eventout += AllProv[i]->moduleLabel();
282  eventout += "\n ProductID : ";
283  eventout += AllProv[i]->productID().id();
284  eventout += "\n ClassName : ";
285  eventout += AllProv[i]->className();
286  eventout += "\n InstanceName : ";
287  eventout += AllProv[i]->productInstanceName();
288  eventout += "\n BranchName : ";
289  eventout += AllProv[i]->branchName();
290  }
291  eventout += " ******************************\n";
292  edm::LogInfo("MuonSimHitsValidAnalyzer::analyze") << eventout << "\n";
293  }
294  }
295 
296  fillDT(iEvent, iSetup);
297 
298  if (verbosity > 0)
299  edm::LogInfo("MuonSimHitsValidAnalyzer::analyze") << "Done gathering data from event.";
300 
301  return;
302 }
303 
305  TString eventout;
306  if (verbosity > 0)
307  eventout = "\nGathering DT info:";
308 
310  edm::PSimHitContainer::const_iterator itHit;
311 
314  if (!hGeom.isValid()) {
315  edm::LogWarning("MuonSimHitsValidAnalyzer::fillDT")
316  << "Unable to find MuonGeometryRecord for the DTGeometry in event!";
317  return;
318  }
319  const DTGeometry& theDTMuon(*hGeom);
320 
322  edm::Handle<edm::PSimHitContainer> MuonDTContainer;
323  iEvent.getByToken(DTHitsToken_, MuonDTContainer);
324  if (!MuonDTContainer.isValid()) {
325  edm::LogWarning("MuonSimHitsValidAnalyzer::fillDT") << "Unable to find MuonDTHits in event!";
326  return;
327  }
328 
329  touch1 = 0;
330  touch4 = 0;
331  nummu_DT = 0;
332 
333  meAllDTHits->Fill(MuonDTContainer->size());
334 
336  int i = 0, j = 0;
337  for (itHit = MuonDTContainer->begin(); itHit != MuonDTContainer->end(); ++itHit) {
338  ++i;
339 
341  DetId theDetUnitId(itHit->detUnitId());
342  int detector = theDetUnitId.det();
343  int subdetector = theDetUnitId.subdetId();
344 
346  if ((detector == dMuon) && (subdetector == sdMuonDT)) {
348  const GeomDetUnit* theDet = theDTMuon.idToDetUnit(theDetUnitId);
349 
350  if (!theDet) {
351  edm::LogWarning("MuonSimHitsValidAnalyzer::fillDT") << "Unable to get GeomDetUnit from theDTMuon for hit " << i;
352  continue;
353  }
354 
355  ++j;
356 
358  const BoundPlane& bsurf = theDet->surface();
359 
361 
362  if (abs(itHit->particleType()) == 13) {
363  nummu_DT++;
364  meToF->Fill(itHit->tof());
365  meEnergyLoss->Fill(itHit->energyLoss() * pow6);
366 
367  iden = itHit->detUnitId();
368 
369  wheel = ((iden >> 15) & 0x7) - 3;
370  station = ((iden >> 22) & 0x7);
371  sector = ((iden >> 18) & 0xf);
372  superlayer = ((iden >> 13) & 0x3);
373  layer = ((iden >> 10) & 0x7);
374  wire = ((iden >> 3) & 0x7f);
375 
376  meWheelOccup->Fill((float)wheel);
377  meStationOccup->Fill((float)station);
378  meSectorOccup->Fill((float)sector);
379  meSuperLOccup->Fill((float)superlayer);
380  meLayerOccup->Fill((float)layer);
381  meWireOccup->Fill((float)wire);
382 
383  // Define a quantity to take into account station, splayer and layer being hit.
384  path = (station - 1) * 40 + superlayer * 10 + layer;
385  mePathMuon->Fill((float)path);
386 
387  // Define a quantity to take into chamber being hit.
388  pathchamber = (wheel + 2) * 50 + (station - 1) * 12 + sector;
390 
392  if (station == 1) {
393  if (touch1 == 0) {
394  mom1 = itHit->pabs();
396  touch1 = 1;
397  }
398  }
399 
401  if (station == 4) {
402  if (touch4 == 0) {
403  mom4 = itHit->pabs();
404  touch4 = 1;
406  if (touch1 == 1) {
408  }
409  }
410  }
411 
413  meLocalXvsZ->Fill(itHit->localPosition().x(), itHit->localPosition().z());
414 
416  meLocalXvsY->Fill(itHit->localPosition().x(), itHit->localPosition().y());
417 
419 
420  globposz = bsurf.toGlobal(itHit->localPosition()).z();
421  globposeta = bsurf.toGlobal(itHit->localPosition()).eta();
422  globposphi = bsurf.toGlobal(itHit->localPosition()).phi();
423 
424  radius = globposz * (1. + exp(-2. * globposeta)) / (1. - exp(-2. * globposeta));
425 
426  costeta = (1. - exp(-2. * globposeta)) / (1. + exp(-2. * globposeta));
427  sinteta = 2. * exp(-globposeta) / (1. + exp(-2. * globposeta));
428 
433 
436 
437  // New Histos
438  if (wheel == -2) {
441  }
442  if (wheel == -1) {
445  }
446  if (wheel == 0) {
449  }
450  if (wheel == 1) {
453  }
454  if (wheel == 2) {
457  }
458  //
463  }
464  } else {
465  edm::LogWarning("MuonSimHitsValidAnalyzer::fillDT")
466  << "MuonDT PSimHit " << i << " is expected to be (det,subdet) = (" << dMuon << "," << sdMuonDT
467  << "); value returned is: (" << detector << "," << subdetector << ")";
468  continue;
469  }
470  }
471 
472  if (verbosity > 1) {
473  eventout += "\n Number of DT muon Hits collected:......... ";
474  eventout += j;
475  }
476  meMuDTHits->Fill((float)nummu_DT);
477 
478  if (verbosity > 0)
479  edm::LogInfo("MuonSimHitsValidAnalyzer::fillDT") << eventout << "\n";
480  return;
481 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
static const int sdMuonDT
TString subdetector
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
unsigned long long EventNumber_t
edm::EDGetTokenT< edm::PSimHitContainer > DTHitsToken_
Input tags.
T getUntrackedParameter(std::string const &, T const &) const
void Fill(long long x)
char const * label
int iEvent
Definition: GenABIO.cc:224
edm::ESGetToken< DTGeometry, MuonGeometryRecord > geomToken_
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const GeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
Definition: DTGeometry.cc:75
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
const int verbosity
bool isValid() const
Definition: ESHandle.h:44
Log< level::Info, false > LogInfo
Definition: DetId.h:17
MuonSimHitsValidAnalyzer(const edm::ParameterSet &)
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
std::string fName
parameter information
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
bool isValid() const
Definition: HandleBase.h:70
static const int dMuon
HLT enums.
void analyze(const edm::Event &, const edm::EventSetup &) override
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
unsigned int RunNumber_t
Log< level::Warning, false > LogWarning
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
unsigned int count
private statistics information
Definition: Run.h:45
void fillDT(const edm::Event &, const edm::EventSetup &)