test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
14 
16  fName(""), verbosity(0), label(""), getAllProvenances(false),
17  printProvenanceInfo(false), nRawGenPart(0), count(0)
18 
19 {
21  fName = iPSet.getUntrackedParameter<std::string>("Name");
22  verbosity = iPSet.getUntrackedParameter<int>("Verbosity");
23  label = iPSet.getParameter<std::string>("Label");
24  edm::ParameterSet m_Prov =
25  iPSet.getParameter<edm::ParameterSet>("ProvenanceLookup");
27  m_Prov.getUntrackedParameter<bool>("GetAllProvenances");
29  m_Prov.getUntrackedParameter<bool>("PrintProvenanceInfo");
30 
31  nRawGenPart = 0;
32 
34  DTHitsToken_ = consumes<edm::PSimHitContainer>(
35  iPSet.getParameter<edm::InputTag>("DTHitsSrc"));
36 
38 
39  if (verbosity) {
40  Labels 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 << "\n"
50  // << " CSCHitsSrc= " <<CSCHitsSrc_.label()
51  // << ":" << CSCHitsSrc_.instance() << "\n"
52  << " DTHitsSrc = " << l.module
53  << ":" << l.productInstance << "\n"
54  // << " RPCHitsSrc= " <<RPCHitsSrc_.label()
55  // << ":" << RPCHitsSrc_.instance() << "\n"
56  << "===============================\n";
57  }
58 
59  pow6=1000000.0;
60  mom4 =0.;
61  mom1 = 0;
62  costeta = 0.;
63  radius = 0;
64  sinteta = 0.;
65  globposx = 0.;
66  globposy = 0;
67  nummu_DT = 0;
68  nummu_CSC =0;
69  nummu_RPC=0;
70 }
71 
73 {
74 }
75 
76 void MuonSimHitsValidAnalyzer::bookHistograms(DQMStore::IBooker & iBooker, edm::Run const & iRun, edm::EventSetup const & /* iSetup */)
77 {
78  meAllDTHits =0 ;
79  meMuDTHits =0 ;
80  meToF =0 ;
81  meEnergyLoss =0 ;
82  meMomentumMB1 =0 ;
83  meMomentumMB4 =0 ;
84  meLossMomIron =0 ;
85  meLocalXvsZ =0 ;
86  meLocalXvsY =0 ;
87  meGlobalXvsZ =0 ;
88  meGlobalXvsY =0 ;
89  meGlobalXvsZWm2 =0 ;
90  meGlobalXvsZWm1 =0 ;
91  meGlobalXvsZW0 =0 ;
92  meGlobalXvsZWp1 =0 ;
93  meGlobalXvsZWp2 =0 ;
94  meGlobalXvsYWm2 =0 ;
95  meGlobalXvsYWm1 =0 ;
96  meGlobalXvsYW0 =0 ;
97  meGlobalXvsYWp1 =0 ;
98  meGlobalXvsYWp2 =0 ;
99  meWheelOccup =0 ;
100  meStationOccup =0 ;
101  meSectorOccup =0 ;
102  meSuperLOccup =0 ;
103  meLayerOccup =0 ;
104  meWireOccup =0 ;
105  mePathMuon =0 ;
106  meChamberOccup =0 ;
107  meHitRadius =0 ;
108  meCosTheta =0 ;
109  meGlobalEta =0 ;
110  meGlobalPhi =0 ;
111 
112  Char_t histo_n[100];
113  Char_t histo_t[100];
114 
115  iBooker.setCurrentFolder("MuonDTHitsV/DTHitsValidationTask");
116 
117  sprintf (histo_n, "Number_of_all_DT_hits" );
118  sprintf (histo_t, "Number_of_all_DT_hits" );
119  meAllDTHits = iBooker.book1D(histo_n, histo_t, 200, 1.0, 201.0) ;
120 
121  sprintf (histo_n, "Number_of_muon_DT_hits" );
122  sprintf (histo_t, "Number_of_muon_DT_hits" );
123  meMuDTHits = iBooker.book1D(histo_n, histo_t, 150, 1.0, 151.0);
124 
125  sprintf (histo_n, "Tof_of_hits " );
126  sprintf (histo_t, "Tof_of_hits " );
127  meToF = iBooker.book1D(histo_n, histo_t, 100, -0.5, 50.) ;
128 
129  sprintf (histo_n, "DT_energy_loss_keV" );
130  sprintf (histo_t, "DT_energy_loss_keV" );
131  meEnergyLoss = iBooker.book1D(histo_n, histo_t, 100, 0.0, 10.0);
132 
133  sprintf (histo_n, "Momentum_at_MB1" );
134  sprintf (histo_t, "Momentum_at_MB1" );
135  meMomentumMB1 = iBooker.book1D(histo_n, histo_t, 100, 10.0, 200.0);
136 
137  sprintf (histo_n, "Momentum_at_MB4" );
138  sprintf (histo_t, "Momentum_at_MB4" );
139  meMomentumMB4 = iBooker.book1D(histo_n, histo_t, 100, 10.0, 200.0) ;
140 
141  sprintf (histo_n, "Loss_of_muon_Momentum_in_Iron" );
142  sprintf (histo_t, "Loss_of_muon_Momentum_in_Iron" );
143  meLossMomIron = iBooker.book1D(histo_n, histo_t, 80, 0.0, 40.0) ;
144 
145  sprintf (histo_n, "Local_x-coord_vs_local_z-coord_of_muon_hit" );
146  sprintf (histo_t, "Local_x-coord_vs_local_z-coord_of_muon_hit" );
147  meLocalXvsZ = iBooker.book2D(histo_n, histo_t,100, -150., 150., 100, -0.8, 0.8 ) ;
148 
149  sprintf (histo_n, "local_x-coord_vs_local_y-coord_of_muon_hit" );
150  sprintf (histo_t, "local_x-coord_vs_local_y-coord_of_muon_hit" );
151  meLocalXvsY = iBooker.book2D(histo_n, histo_t, 100, -150., 150., 100, -150., 150. );
152 
153  sprintf (histo_n, "Global_x-coord_vs_global_z-coord_of_muon_hit" );
154  sprintf (histo_t, "Global_x-coord_vs_global_z-coord_of_muon_hit" );
155  meGlobalXvsZ = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800. ) ;
156 
157  sprintf (histo_n, "Global_x-coord_vs_global_y-coord_of_muon_hit" );
158  sprintf (histo_t, "Global_x-coord_vs_global_y-coord_of_muon_hit" );
159  meGlobalXvsY = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800. ) ;
160 
161  // New histos
162 
163  sprintf (histo_n, "Global_x-coord_vs_global_z-coord_of_muon_hit_w-2" );
164  sprintf (histo_t, "Global_x-coord_vs_global_z-coord_of_muon_hit_w-2" );
165  meGlobalXvsZWm2 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800. );
166 
167  sprintf (histo_n, "Global_x-coord_vs_global_y-coord_of_muon_hit_w-2" );
168  sprintf (histo_t, "Global_x-coord_vs_global_y-coord_of_muon_hit_w-2" );
169  meGlobalXvsYWm2 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800. );
170 
171  sprintf (histo_n, "Global_x-coord_vs_global_z-coord_of_muon_hit_w-1" );
172  sprintf (histo_t, "Global_x-coord_vs_global_z-coord_of_muon_hit_w-1" );
173  meGlobalXvsZWm1 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800. );
174 
175  sprintf (histo_n, "Global_x-coord_vs_global_y-coord_of_muon_hit_w-1" );
176  sprintf (histo_t, "Global_x-coord_vs_global_y-coord_of_muon_hit_w-1" );
177  meGlobalXvsYWm1 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800. );
178 
179  sprintf (histo_n, "Global_x-coord_vs_global_z-coord_of_muon_hit_w0" );
180  sprintf (histo_t, "Global_x-coord_vs_global_z-coord_of_muon_hit_w0" );
181  meGlobalXvsZW0 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800. );
182 
183  sprintf (histo_n, "Global_x-coord_vs_global_y-coord_of_muon_hit_w0" );
184  sprintf (histo_t, "Global_x-coord_vs_global_y-coord_of_muon_hit_w0" );
185  meGlobalXvsYW0 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800. );
186 
187  sprintf (histo_n, "Global_x-coord_vs_global_z-coord_of_muon_hit_w1" );
188  sprintf (histo_t, "Global_x-coord_vs_global_z-coord_of_muon_hit_w1" );
189  meGlobalXvsZWp1 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800. );
190 
191  sprintf (histo_n, "Global_x-coord_vs_global_y-coord_of_muon_hit_w1" );
192  sprintf (histo_t, "Global_x-coord_vs_global_y-coord_of_muon_hit_w1" );
193  meGlobalXvsYWp1 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800. );
194 
195  sprintf (histo_n, "Global_x-coord_vs_global_z-coord_of_muon_hit_w2" );
196  sprintf (histo_t, "Global_x-coord_vs_global_z-coord_of_muon_hit_w2" );
197  meGlobalXvsZWp2 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800. );
198 
199  sprintf (histo_n, "Global_x-coord_vs_global_y-coord_of_muon_hit_w2" );
200  sprintf (histo_t, "Global_x-coord_vs_global_y-coord_of_muon_hit_w2" );
201  meGlobalXvsYWp2 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800. );
202 
203  //
204 
205  sprintf (histo_n, "Wheel_occupancy" );
206  sprintf (histo_t, "Wheel_occupancy" );
207  meWheelOccup = iBooker.book1D(histo_n, histo_t, 10, -5.0, 5.0) ;
208 
209  sprintf (histo_n, "Station_occupancy" );
210  sprintf (histo_t, "Station_occupancy" );
211  meStationOccup = iBooker.book1D(histo_n, histo_t, 6, 0., 6.0) ;
212 
213  sprintf (histo_n, "Sector_occupancy" );
214  sprintf (histo_t, "Sector_occupancy" );
215  meSectorOccup = iBooker.book1D(histo_n, histo_t, 20, 0., 20.) ;
216 
217  sprintf (histo_n, "SuperLayer_occupancy" );
218  sprintf (histo_t, "SuperLayer_occupancy" );
219  meSuperLOccup = iBooker.book1D(histo_n, histo_t, 5, 0., 5.) ;
220 
221  sprintf (histo_n, "Layer_occupancy" );
222  sprintf (histo_t, "Layer_occupancy" );
223  meLayerOccup = iBooker.book1D(histo_n, histo_t,6, 0., 6.) ;
224 
225  sprintf (histo_n, "Wire_occupancy" );
226  sprintf (histo_t, "Wire_occupancy" );
227  meWireOccup = iBooker.book1D(histo_n, histo_t, 100, 0., 100.) ;
228 
229  sprintf (histo_n, "path_followed_by_muon" );
230  sprintf (histo_t, "path_followed_by_muon" );
231  mePathMuon = iBooker.book1D(histo_n, histo_t, 160, 0., 160.) ;
232 
233  sprintf (histo_n, "chamber_occupancy" );
234  sprintf (histo_t, "chamber_occupancy" );
235  meChamberOccup = iBooker.book1D(histo_n, histo_t, 251, 0., 251.) ;
236 
237  sprintf (histo_n, "radius_of_hit");
238  sprintf (histo_t, "radius_of_hit");
239  meHitRadius = iBooker.book1D(histo_n, histo_t, 100, 0., 1200. );
240 
241  sprintf (histo_n, "costheta_of_hit" );
242  sprintf (histo_t, "costheta_of_hit" );
243  meCosTheta = iBooker.book1D(histo_n, histo_t, 100, -1., 1.) ;
244 
245  sprintf (histo_n, "global_eta_of_hit" );
246  sprintf (histo_t, "global_eta_of_hit" );
247  meGlobalEta = iBooker.book1D(histo_n, histo_t, 60, -2.7, 2.7 );
248 
249  sprintf (histo_n, "global_phi_of_hit" );
250  sprintf (histo_t, "global_phi_of_hit" );
251  meGlobalPhi = iBooker.book1D(histo_n, histo_t, 60, -3.14, 3.14);
252 }
253 
255  const edm::EventSetup& iSetup)
256 {
258  ++count;
259 
261  edm::RunNumber_t nrun = iEvent.id().run();
262  edm::EventNumber_t nevt = iEvent.id().event();
263 
264  if (verbosity > 0) {
265  edm::LogInfo ("MuonSimHitsValidAnalyzer::analyze")
266  << "Processing run " << nrun << ", event " << nevt;
267  }
268 
270  if (getAllProvenances) {
271 
272  std::vector<const edm::StableProvenance*> AllProv;
273  iEvent.getAllStableProvenance(AllProv);
274 
275  if (verbosity > 0)
276  edm::LogInfo ("MuonSimHitsValidAnalyzer::analyze")
277  << "Number of Provenances = " << AllProv.size();
278 
279  if (printProvenanceInfo && (verbosity > 0)) {
280  TString eventout("\nProvenance info:\n");
281 
282  for (unsigned int i = 0; i < AllProv.size(); ++i) {
283  eventout += "\n ******************************";
284  eventout += "\n Module : ";
285  eventout += AllProv[i]->moduleLabel();
286  eventout += "\n ProductID : ";
287  eventout += AllProv[i]->productID().id();
288  eventout += "\n ClassName : ";
289  eventout += AllProv[i]->className();
290  eventout += "\n InstanceName : ";
291  eventout += AllProv[i]->productInstanceName();
292  eventout += "\n BranchName : ";
293  eventout += AllProv[i]->branchName();
294  }
295  eventout += " ******************************\n";
296  edm::LogInfo("MuonSimHitsValidAnalyzer::analyze") << eventout << "\n";
297  }
298  }
299 
300  fillDT(iEvent, iSetup);
301 
302  if (verbosity > 0)
303  edm::LogInfo ("MuonSimHitsValidAnalyzer::analyze")
304  << "Done gathering data from event.";
305 
306  return;
307 }
308 
310  const edm::EventSetup& iSetup)
311 {
312  TString eventout;
313  if (verbosity > 0)
314  eventout = "\nGathering DT info:";
315 
317  edm::PSimHitContainer::const_iterator itHit;
318 
321  edm::ESHandle<DTGeometry> theDTGeometry;
322  iSetup.get<MuonGeometryRecord>().get(theDTGeometry);
323  if (!theDTGeometry.isValid()) {
324  edm::LogWarning("MuonSimHitsValidAnalyzer::fillDT")
325  << "Unable to find MuonGeometryRecord for the DTGeometry in event!";
326  return;
327  }
328  const DTGeometry& theDTMuon(*theDTGeometry);
329 
331  edm::Handle<edm::PSimHitContainer> MuonDTContainer;
332  iEvent.getByToken(DTHitsToken_, MuonDTContainer);
333  if (!MuonDTContainer.isValid()) {
334  edm::LogWarning("MuonSimHitsValidAnalyzer::fillDT")
335  << "Unable to find MuonDTHits in event!";
336  return;
337  }
338 
339  touch1 = 0;
340  touch4 = 0;
341  nummu_DT = 0 ;
342 
343  meAllDTHits->Fill( MuonDTContainer->size() );
344 
346  int i = 0, j = 0;
347  for (itHit = MuonDTContainer->begin(); itHit != MuonDTContainer->end();
348  ++itHit) {
349 
350  ++i;
351 
353  DetId theDetUnitId(itHit->detUnitId());
354  int detector = theDetUnitId.det();
355  int subdetector = theDetUnitId.subdetId();
356 
358  if ((detector == dMuon) &&
359  (subdetector == sdMuonDT)) {
360 
362  const GeomDetUnit *theDet = theDTMuon.idToDetUnit(theDetUnitId);
363 
364  if (!theDet) {
365  edm::LogWarning("MuonSimHitsValidAnalyzer::fillDT")
366  << "Unable to get GeomDetUnit from theDTMuon for hit " << i;
367  continue;
368  }
369 
370  ++j;
371 
373  const BoundPlane& bsurf = theDet->surface();
374 
376 
377  if ( abs(itHit->particleType()) == 13 ) {
378 
379  nummu_DT++;
380  meToF->Fill( itHit->tof() );
381  meEnergyLoss->Fill( itHit->energyLoss()*pow6 );
382 
383  iden = itHit->detUnitId();
384 
385  wheel = ((iden>>15) & 0x7 ) -3 ;
386  station = ((iden>>22) & 0x7 ) ;
387  sector = ((iden>>18) & 0xf ) ;
388  superlayer = ((iden>>13) & 0x3 ) ;
389  layer = ((iden>>10) & 0x7 ) ;
390  wire = ((iden>>3) & 0x7f ) ;
391 
392  meWheelOccup->Fill((float)wheel);
393  meStationOccup->Fill((float) station);
394  meSectorOccup->Fill((float) sector);
395  meSuperLOccup->Fill((float) superlayer);
396  meLayerOccup->Fill((float) layer);
397  meWireOccup->Fill((float) wire);
398 
399  // Define a quantity to take into account station, splayer and layer being hit.
400  path = (station-1) * 40 + superlayer * 10 + layer;
401  mePathMuon->Fill((float) path);
402 
403  // Define a quantity to take into chamber being hit.
404  pathchamber = (wheel+2) * 50 + (station-1) * 12 + sector;
405  meChamberOccup->Fill((float) pathchamber);
406 
408  if (station == 1 )
409  {
410  if (touch1 == 0)
411  {
412  mom1=itHit->pabs();
414  touch1 = 1;
415  }
416  }
417 
419  if (station == 4 )
420  {
421  if ( touch4 == 0)
422  {
423  mom4=itHit->pabs();
424  touch4 = 1;
426  if (touch1 == 1 )
427  {
429  }
430  }
431  }
432 
434  meLocalXvsZ->Fill(itHit->localPosition().x(), itHit->localPosition().z() );
435 
437  meLocalXvsY->Fill(itHit->localPosition().x(), itHit->localPosition().y() );
438 
440 
441  globposz = bsurf.toGlobal(itHit->localPosition()).z();
442  globposeta = bsurf.toGlobal(itHit->localPosition()).eta();
443  globposphi = bsurf.toGlobal(itHit->localPosition()).phi();
444 
445  radius = globposz* ( 1.+ exp(-2.* globposeta) ) / ( 1. - exp(-2.* globposeta ) ) ;
446 
447  costeta = ( 1. - exp(-2.*globposeta) ) /( 1. + exp(-2.* globposeta) ) ;
448  sinteta = 2. * exp(-globposeta) /( 1. + exp(-2.*globposeta) );
449 
454 
457 
458 // New Histos
459  if (wheel == -2) {
462  }
463  if (wheel == -1) {
466  }
467  if (wheel == 0) {
470  }
471  if (wheel == 1) {
474  }
475  if (wheel == 2) {
478  }
479 //
481  meCosTheta->Fill(costeta);
484 
485  }
486  } else {
487  edm::LogWarning("MuonSimHitsValidAnalyzer::fillDT")
488  << "MuonDT PSimHit " << i
489  << " is expected to be (det,subdet) = ("
490  << dMuon << "," << sdMuonDT
491  << "); value returned is: ("
492  << detector << "," << subdetector << ")";
493  continue;
494  }
495  }
496 
497  if (verbosity > 1) {
498  eventout += "\n Number of DT muon Hits collected:......... ";
499  eventout += j;
500  }
501  meMuDTHits->Fill( (float) nummu_DT );
502 
503  if (verbosity > 0)
504  edm::LogInfo("MuonSimHitsValidAnalyzer::fillDT") << eventout << "\n";
505 return;
506 }
507 
508 
509 
RunNumber_t run() const
Definition: EventID.h:39
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
static const int sdMuonDT
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
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.
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
void Fill(long long x)
int iEvent
Definition: GenABIO.cc:230
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
bool isValid() const
Definition: HandleBase.h:75
char const * module
Definition: ProductLabels.h:5
Definition: DetId.h:18
MuonSimHitsValidAnalyzer(const edm::ParameterSet &)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:277
std::string fName
parameter information
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
const T & get() const
Definition: EventSetup.h:56
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
edm::EventID id() const
Definition: EventBase.h:58
char const * productInstance
Definition: ProductLabels.h:6
static const int dMuon
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
virtual const GeomDetUnit * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
Definition: DTGeometry.cc:71
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
unsigned int RunNumber_t
volatile std::atomic< bool > shutdown_flag false
bool isValid() const
Definition: ESHandle.h:47
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
unsigned int count
private statistics information
Definition: Run.h:42
void fillDT(const edm::Event &, const edm::EventSetup &)
void getAllStableProvenance(std::vector< StableProvenance const * > &provenances) const
Definition: Event.cc:96