CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MuonDTDigis.cc
Go to the documentation of this file.
1 
7 #include "MuonDTDigis.h"
8 
9 #include <iostream>
10 #include <string>
11 
12 #include "TFile.h"
13 
15 
16 using namespace edm;
17 using namespace std;
18 
20  // ----------------------
21  // Get the debug parameter for verbose output
22  verbose_ = pset.getUntrackedParameter<bool>("verbose", false);
23 
24  // the name of the Digi collection
25  SimHitToken_ = consumes<edm::PSimHitContainer>(pset.getParameter<edm::InputTag>("SimHitLabel"));
26 
27  // the name of the Digi collection
28  DigiToken_ = consumes<DTDigiCollection>(pset.getParameter<edm::InputTag>(("DigiLabel")));
29 
30  hDigis_global = std::make_unique<hDigis>("Global");
31  hDigis_W0 = std::make_unique<hDigis>("Wheel0");
32  hDigis_W1 = std::make_unique<hDigis>("Wheel1");
33  hDigis_W2 = std::make_unique<hDigis>("Wheel2");
34  hAllHits = std::make_unique<hHits>("AllHits");
35 }
36 
38  if (verbose_)
39  cout << "[MuonDTDigis] Destructor called" << endl;
40 }
41 
43  edm::Run const &iRun,
44  edm::EventSetup const & /* iSetup */) {
45  meDigiTimeBox_ = nullptr;
46  meDigiTimeBox_wheel2m_ = nullptr;
47  meDigiTimeBox_wheel1m_ = nullptr;
48  meDigiTimeBox_wheel0_ = nullptr;
49  meDigiTimeBox_wheel1p_ = nullptr;
50  meDigiTimeBox_wheel2p_ = nullptr;
51  meDigiEfficiency_ = nullptr;
52  meDigiEfficiencyMu_ = nullptr;
53  meDoubleDigi_ = nullptr;
54  meSimvsDigi_ = nullptr;
55  meWire_DoubleDigi_ = nullptr;
56 
57  meMB1_sim_occup_ = nullptr;
58  meMB1_digi_occup_ = nullptr;
59  meMB2_sim_occup_ = nullptr;
60  meMB2_digi_occup_ = nullptr;
61  meMB3_sim_occup_ = nullptr;
62  meMB3_digi_occup_ = nullptr;
63  meMB4_sim_occup_ = nullptr;
64  meMB4_digi_occup_ = nullptr;
65 
66  meDigiHisto_ = nullptr;
67 
68  // ----------------------
69  // We go
70  // ----------------------
71 
72  Char_t histo_n[100];
73  Char_t histo_t[100];
74 
75  iBooker.setCurrentFolder("MuonDTDigisV/DTDigiValidationTask");
76 
77  sprintf(histo_n, "DigiTimeBox");
78  sprintf(histo_t, "Digi Time Box");
79  meDigiTimeBox_ = iBooker.book1D(histo_n, histo_t, 1536, 0, 1200);
80 
81  sprintf(histo_n, "DigiTimeBox_wheel2m");
82  sprintf(histo_t, "Digi Time Box wheel -2");
83  meDigiTimeBox_wheel2m_ = iBooker.book1D(histo_n, histo_t, 384, 0, 1200);
84 
85  sprintf(histo_n, "DigiTimeBox_wheel1m");
86  sprintf(histo_t, "Digi Time Box wheel -1");
87  meDigiTimeBox_wheel1m_ = iBooker.book1D(histo_n, histo_t, 384, 0, 1200);
88 
89  sprintf(histo_n, "DigiTimeBox_wheel0");
90  sprintf(histo_t, "Digi Time Box wheel 0");
91  meDigiTimeBox_wheel0_ = iBooker.book1D(histo_n, histo_t, 384, 0, 1200);
92 
93  sprintf(histo_n, "DigiTimeBox_wheel1p");
94  sprintf(histo_t, "Digi Time Box wheel 1");
95  meDigiTimeBox_wheel1p_ = iBooker.book1D(histo_n, histo_t, 384, 0, 1200);
96 
97  sprintf(histo_n, "DigiTimeBox_wheel2p");
98  sprintf(histo_t, "Digi Time Box wheel 2");
99  meDigiTimeBox_wheel2p_ = iBooker.book1D(histo_n, histo_t, 384, 0, 1200);
100 
101  sprintf(histo_n, "DigiEfficiencyMu");
102  sprintf(histo_t, "Ratio (#Digis Mu)/(#SimHits Mu)");
103  meDigiEfficiencyMu_ = iBooker.book1D(histo_n, histo_t, 100, 0., 5.);
104 
105  sprintf(histo_n, "DigiEfficiency");
106  sprintf(histo_t, "Ratio (#Digis)/(#SimHits)");
107  meDigiEfficiency_ = iBooker.book1D(histo_n, histo_t, 100, 0., 5.);
108 
109  sprintf(histo_n, "Number_Digi_per_layer");
110  sprintf(histo_t, "Number_Digi_per_layer");
111  meDoubleDigi_ = iBooker.book1D(histo_n, histo_t, 10, 0., 10.);
112 
113  sprintf(histo_n, "Number_simhit_vs_digi");
114  sprintf(histo_t, "Number_simhit_vs_digi");
115  meSimvsDigi_ = iBooker.book2D(histo_n, histo_t, 100, 0., 140., 100, 0., 140.);
116 
117  sprintf(histo_n, "Wire_Number_with_double_Digi");
118  sprintf(histo_t, "Wire_Number_with_double_Digi");
119  meWire_DoubleDigi_ = iBooker.book1D(histo_n, histo_t, 100, 0., 100.);
120 
121  sprintf(histo_n, "Simhit_occupancy_MB1");
122  sprintf(histo_t, "Simhit_occupancy_MB1");
123  meMB1_sim_occup_ = iBooker.book1D(histo_n, histo_t, 55, 0., 55.);
124 
125  sprintf(histo_n, "Digi_occupancy_MB1");
126  sprintf(histo_t, "Digi_occupancy_MB1");
127  meMB1_digi_occup_ = iBooker.book1D(histo_n, histo_t, 55, 0., 55.);
128 
129  sprintf(histo_n, "Simhit_occupancy_MB2");
130  sprintf(histo_t, "Simhit_occupancy_MB2");
131  meMB2_sim_occup_ = iBooker.book1D(histo_n, histo_t, 63, 0., 63.);
132 
133  sprintf(histo_n, "Digi_occupancy_MB2");
134  sprintf(histo_t, "Digi_occupancy_MB2");
135  meMB2_digi_occup_ = iBooker.book1D(histo_n, histo_t, 63, 0., 63.);
136 
137  sprintf(histo_n, "Simhit_occupancy_MB3");
138  sprintf(histo_t, "Simhit_occupancy_MB3");
139  meMB3_sim_occup_ = iBooker.book1D(histo_n, histo_t, 75, 0., 75.);
140 
141  sprintf(histo_n, "Digi_occupancy_MB3");
142  sprintf(histo_t, "Digi_occupancy_MB3");
143  meMB3_digi_occup_ = iBooker.book1D(histo_n, histo_t, 75, 0., 75.);
144 
145  sprintf(histo_n, "Simhit_occupancy_MB4");
146  sprintf(histo_t, "Simhit_occupancy_MB4");
147  meMB4_sim_occup_ = iBooker.book1D(histo_n, histo_t, 99, 0., 99.);
148 
149  sprintf(histo_n, "Digi_occupancy_MB4");
150  sprintf(histo_t, "Digi_occupancy_MB4");
151  meMB4_digi_occup_ = iBooker.book1D(histo_n, histo_t, 99, 0., 99.);
152 
153  // Begona's option
154  char stringcham[40];
155  for (int slnum = 1; slnum < 62; ++slnum) {
156  sprintf(stringcham, "DigiTimeBox_slid_%d", slnum);
157  meDigiHisto_ = iBooker.book1D(stringcham, stringcham, 100, 0, 1200);
158  meDigiTimeBox_SL_.push_back(meDigiHisto_);
159  }
160 }
161 
162 void MuonDTDigis::analyze(const Event &event, const EventSetup &eventSetup) {
163  if (verbose_)
164  cout << "--- [MuonDTDigis] Analysing Event: #Run: " << event.id().run() << " #Event: " << event.id().event()
165  << endl;
166 
167  // Get the DT Geometry
168  muonGeom = &eventSetup.getData(muonGeomToken_);
169 
170  // Get the Digi collection from the event
171  Handle<DTDigiCollection> dtDigis;
172  event.getByToken(DigiToken_, dtDigis);
173 
174  // Get simhits
176  event.getByToken(SimHitToken_, simHits);
177 
178  int num_mudigis;
179  int num_musimhits;
180  int num_digis;
181  int num_digis_layer;
182  int cham_num;
183  int wire_touched;
184  num_digis = 0;
185  num_mudigis = 0;
186  num_musimhits = 0;
187  DTWireIdMap wireMap;
188 
189  for (vector<PSimHit>::const_iterator hit = simHits->begin(); hit != simHits->end(); hit++) {
190  // Create the id of the wire, the simHits in the DT known also the wireId
191  DTWireId wireId(hit->detUnitId());
192  // cout << " PSimHits wire id " << wireId << " part type " <<
193  // hit->particleType() << endl;
194 
195  // Fill the map
196  wireMap[wireId].push_back(&(*hit));
197 
198  LocalPoint entryP = hit->entryPoint();
199  LocalPoint exitP = hit->exitPoint();
200  int partType = hit->particleType();
201  if (abs(partType) == 13)
202  num_musimhits++;
203 
204  if (wireId.station() == 1 && abs(partType) == 13)
205  meMB1_sim_occup_->Fill(wireId.wire());
206  if (wireId.station() == 2 && abs(partType) == 13)
207  meMB2_sim_occup_->Fill(wireId.wire());
208  if (wireId.station() == 3 && abs(partType) == 13)
209  meMB3_sim_occup_->Fill(wireId.wire());
210  if (wireId.station() == 4 && abs(partType) == 13)
211  meMB4_sim_occup_->Fill(wireId.wire());
212 
213  float path = (exitP - entryP).mag();
214  float path_x = fabs((exitP - entryP).x());
215 
216  hAllHits->Fill(entryP.x(),
217  exitP.x(),
218  entryP.y(),
219  exitP.y(),
220  entryP.z(),
221  exitP.z(),
222  path,
223  path_x,
224  partType,
225  hit->processType(),
226  hit->pabs());
227  }
228 
229  // cout << "num muon simhits " << num_musimhits << endl;
230 
232  for (detUnitIt = dtDigis->begin(); detUnitIt != dtDigis->end(); ++detUnitIt) {
233  const DTLayerId &id = (*detUnitIt).first;
234  const DTDigiCollection::Range &range = (*detUnitIt).second;
235 
236  num_digis_layer = 0;
237  cham_num = 0;
238  wire_touched = 0;
239 
240  // Loop over the digis of this DetUnit
241  for (DTDigiCollection::const_iterator digiIt = range.first; digiIt != range.second; ++digiIt) {
242  // cout<<" Wire: "<<(*digiIt).wire()<<endl
243  // <<" digi time (ns): "<<(*digiIt).time()<<endl;
244 
245  num_digis++;
246  num_digis_layer++;
247  if (num_digis_layer > 1) {
248  if ((*digiIt).wire() == wire_touched) {
249  meWire_DoubleDigi_->Fill((*digiIt).wire());
250  // cout << "old & new wire " << wire_touched << " " <<
251  // (*digiIt).wire() << endl;
252  }
253  }
254  wire_touched = (*digiIt).wire();
255 
256  meDigiTimeBox_->Fill((*digiIt).time());
257  if (id.wheel() == -2)
258  meDigiTimeBox_wheel2m_->Fill((*digiIt).time());
259  if (id.wheel() == -1)
260  meDigiTimeBox_wheel1m_->Fill((*digiIt).time());
261  if (id.wheel() == 0)
262  meDigiTimeBox_wheel0_->Fill((*digiIt).time());
263  if (id.wheel() == 1)
264  meDigiTimeBox_wheel1p_->Fill((*digiIt).time());
265  if (id.wheel() == 2)
266  meDigiTimeBox_wheel2p_->Fill((*digiIt).time());
267 
268  // Superlayer number and fill histo with digi timebox
269 
270  cham_num = (id.wheel() + 2) * 12 + (id.station() - 1) * 3 + id.superlayer();
271  // cout << " Histo number " << cham_num << endl;
272 
273  meDigiTimeBox_SL_[cham_num]->Fill((*digiIt).time());
274 
275  // cout << " size de digis " << (*digiIt).size() << endl;
276 
277  DTWireId wireId(id, (*digiIt).wire());
278  if (wireId.station() == 1)
279  meMB1_digi_occup_->Fill((*digiIt).wire());
280  if (wireId.station() == 2)
281  meMB2_digi_occup_->Fill((*digiIt).wire());
282  if (wireId.station() == 3)
283  meMB3_digi_occup_->Fill((*digiIt).wire());
284  if (wireId.station() == 4)
285  meMB4_digi_occup_->Fill((*digiIt).wire());
286 
287  int mu = 0;
288  float theta = 0;
289 
290  for (vector<const PSimHit *>::iterator hit = wireMap[wireId].begin(); hit != wireMap[wireId].end(); hit++)
291  if (abs((*hit)->particleType()) == 13) {
292  theta = atan((*hit)->momentumAtEntry().x() / (-(*hit)->momentumAtEntry().z())) * 180 / M_PI;
293  // cout<<"momentum x: "<<(*hit)->momentumAtEntry().x()<<endl
294  // <<"momentum z: "<<(*hit)->momentumAtEntry().z()<<endl
295  // <<"atan: "<<theta<<endl;
296  mu++;
297  }
298 
299  if (mu)
300  num_mudigis++;
301 
302  if (mu && theta) {
303  hDigis_global->Fill((*digiIt).time(), theta, id.superlayer());
304  // filling digi histos for wheel and for RZ and RPhi
305  WheelHistos(id.wheel())->Fill((*digiIt).time(), theta, id.superlayer());
306  }
307 
308  } // for digis in layer
309 
310  meDoubleDigi_->Fill((float)num_digis_layer);
311 
312  } // for layers
313 
314  // cout << "num_digis " << num_digis << "mu digis " << num_mudigis << endl;
315 
316  if (num_musimhits != 0) {
317  meDigiEfficiencyMu_->Fill((float)num_mudigis / (float)num_musimhits);
318  meDigiEfficiency_->Fill((float)num_digis / (float)num_musimhits);
319  }
320 
321  meSimvsDigi_->Fill((float)num_musimhits, (float)num_digis);
322  // cout<<"--------------"<<endl;
323 }
324 
326  switch (abs(wheel)) {
327  case 0:
328  return hDigis_W0.get();
329 
330  case 1:
331  return hDigis_W1.get();
332 
333  case 2:
334  return hDigis_W2.get();
335 
336  default:
337  return nullptr;
338  }
339 }
343 
MonitorElement * meDoubleDigi_
Definition: MuonDTDigis.h:84
T getUntrackedParameter(std::string const &, T const &) const
MonitorElement * meWire_DoubleDigi_
Definition: MuonDTDigis.h:86
std::vector< MonitorElement * > meDigiTimeBox_SL_
Definition: MuonDTDigis.h:97
MonitorElement * meDigiHisto_
Definition: MuonDTDigis.h:98
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Geom::Theta< T > theta() const
T y() const
Definition: PV3DBase.h:60
MonitorElement * meMB2_digi_occup_
Definition: MuonDTDigis.h:91
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: MuonDTDigis.cc:42
edm::EDGetTokenT< DTDigiCollection > DigiToken_
Definition: MuonDTDigis.h:67
MonitorElement * meMB3_sim_occup_
Definition: MuonDTDigis.h:92
std::map< DTWireId, std::vector< const PSimHit * > > DTWireIdMap
Definition: MuonDTDigis.h:64
MonitorElement * meDigiEfficiencyMu_
Definition: MuonDTDigis.h:83
const DTGeometry * muonGeom
Definition: MuonDTDigis.h:70
std::unique_ptr< hDigis > hDigis_global
Definition: MuonDTDigis.h:103
MonitorElement * meDigiTimeBox_wheel2m_
Definition: MuonDTDigis.h:77
const uint16_t range(const Frame &aFrame)
void Fill(long long x)
bool getData(T &iHolder) const
Definition: EventSetup.h:128
MonitorElement * meDigiTimeBox_wheel1m_
Definition: MuonDTDigis.h:78
MonitorElement * meDigiTimeBox_wheel0_
Definition: MuonDTDigis.h:79
edm::EDGetTokenT< edm::PSimHitContainer > SimHitToken_
Definition: MuonDTDigis.h:66
MonitorElement * meMB4_sim_occup_
Definition: MuonDTDigis.h:94
MonitorElement * meMB1_sim_occup_
Definition: MuonDTDigis.h:88
MonitorElement * meMB2_sim_occup_
Definition: MuonDTDigis.h:90
std::unique_ptr< hDigis > hDigis_W1
Definition: MuonDTDigis.h:105
MonitorElement * meMB3_digi_occup_
Definition: MuonDTDigis.h:93
T z() const
Definition: PV3DBase.h:61
std::unique_ptr< hDigis > hDigis_W0
Definition: MuonDTDigis.h:104
MonitorElement * meDigiTimeBox_
Definition: MuonDTDigis.h:76
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
MonitorElement * meDigiTimeBox_wheel1p_
Definition: MuonDTDigis.h:80
edm::ESGetToken< DTGeometry, MuonGeometryRecord > muonGeomToken_
Definition: MuonDTDigis.h:69
MonitorElement * meMB4_digi_occup_
Definition: MuonDTDigis.h:95
const int mu
Definition: Constants.h:22
std::unique_ptr< hHits > hAllHits
Definition: MuonDTDigis.h:107
hDigis * WheelHistos(int wheel)
Definition: MuonDTDigis.cc:325
#define M_PI
std::unique_ptr< hDigis > hDigis_W2
Definition: MuonDTDigis.h:106
MonitorElement * meSimvsDigi_
Definition: MuonDTDigis.h:85
~MuonDTDigis() override
Definition: MuonDTDigis.cc:37
std::pair< const_iterator, const_iterator > Range
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:177
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< DigiType >::const_iterator const_iterator
tuple simHits
Definition: trackerHits.py:16
MonitorElement * meDigiEfficiency_
Definition: MuonDTDigis.h:82
void Fill(double time, double theta, int sltype)
Definition: Histograms.h:90
tuple cout
Definition: gather_cfg.py:144
bool verbose_
Definition: MuonDTDigis.h:73
MonitorElement * meDigiTimeBox_wheel2p_
Definition: MuonDTDigis.h:81
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup) override
Definition: MuonDTDigis.cc:162
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
T x() const
Definition: PV3DBase.h:59
MonitorElement * meMB1_digi_occup_
Definition: MuonDTDigis.h:89
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
Definition: Run.h:45
MuonDTDigis(const edm::ParameterSet &pset)
Definition: MuonDTDigis.cc:19