CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 
14 #include "SimMuon/DTDigitizer/test/Histograms.h"
15 
16 using namespace edm;
17 using namespace std;
18 
20 
21  // ----------------------
22  // Get the debug parameter for verbose output
23  verbose_ = pset.getUntrackedParameter<bool>("verbose",false);
24 
25  // the name of the Digi collection
26  SimHitToken_ = consumes<edm::PSimHitContainer>(pset.getParameter<edm::InputTag>("SimHitLabel"));
27 
28  // the name of the Digi collection
29  DigiToken_ = consumes<DTDigiCollection> (pset.getParameter<edm::InputTag>(("DigiLabel")));
30 
31  // ----------------------
32  // DQM ROOT output
33  outputFile_ = pset.getUntrackedParameter<std::string>("outputFile", "");
34  if ( outputFile_.size() != 0 ) {
35  LogInfo("OutputInfo") << " DT Muon Digis Task histograms will be saved to '"
36  << outputFile_.c_str() << "'";
37  } else {
38  LogInfo("OutputInfo") << " DT Muon Digis Task histograms will NOT be saved";
39  }
40 
41  string::size_type loc = outputFile_.find( ".root", 0 );
42  std::string outputFile_more_plots_;
43  if( loc != string::npos ) {
44  outputFile_more_plots_ = outputFile_.substr(0,loc)+"_more_plots.root";
45  } else {
46  outputFile_more_plots_ = " DTDigis_more_plots.root";
47  }
48 
49  // Please, uncomment next lines if you want a secong root file with additional histos
50 
51  // file_more_plots = new TFile(outputFile_more_plots_.c_str(),"RECREATE");
52  // file_more_plots->cd();
53  // if(file_more_plots->IsOpen()) cout<<"File for additional plots: " << outputFile_more_plots_ << " open!"<<endl;
54  // else cout<<"*** Error in opening file for additional plots ***"<<endl;
55 
56  hDigis_global = new hDigis("Global");
57  hDigis_W0 = new hDigis("Wheel0");
58  hDigis_W1 = new hDigis("Wheel1");
59  hDigis_W2 = new hDigis("Wheel2");
60  hAllHits = new hHits("AllHits");
61 
62  // End of comment . See more in Destructor (~MuonDTDigis) method
63 
64 
65 
66  // ----------------------
67  // get hold of back-end interface
68  dbe_ = 0;
70  if ( dbe_ ) {
71  if ( verbose_ ) {
72  dbe_->setVerbose(1);
73  } else {
74  dbe_->setVerbose(0);
75  }
76  }
77  if ( dbe_ ) {
78  if ( verbose_ ) dbe_->showDirStructure();
79  }
80 
81  // ----------------------
82 
83  meDigiTimeBox_ = 0;
84  meDigiTimeBox_wheel2m_ = 0;
85  meDigiTimeBox_wheel1m_ = 0;
86  meDigiTimeBox_wheel0_ = 0;
87  meDigiTimeBox_wheel1p_ = 0;
88  meDigiTimeBox_wheel2p_ = 0;
89  meDigiEfficiency_ = 0;
90  meDigiEfficiencyMu_ = 0;
91  meDoubleDigi_ = 0;
92  meSimvsDigi_ = 0;
93  meWire_DoubleDigi_ = 0;
94 
95  meMB1_sim_occup_ = 0;
96  meMB1_digi_occup_ = 0;
97  meMB2_sim_occup_ = 0;
98  meMB2_digi_occup_ = 0;
99  meMB3_sim_occup_ = 0;
100  meMB3_digi_occup_ = 0;
101  meMB4_sim_occup_ = 0;
102  meMB4_digi_occup_ = 0;
103 
104  //meDigiTimeBox_SL_ = 0;
105  meDigiHisto_ = 0;
106 
107 
108  // ----------------------
109  // We go
110  // ----------------------
111 
112  Char_t histo_n[100];
113  Char_t histo_t[100];
114 
115  if ( dbe_ ) {
116  dbe_->setCurrentFolder("MuonDTDigisV/DTDigiValidationTask");
117 
118  sprintf (histo_n, "DigiTimeBox" );
119  sprintf (histo_t, "Digi Time Box" );
120  meDigiTimeBox_ = dbe_->book1D(histo_n, histo_t, 1536,0,1200);
121 
122  sprintf (histo_n, "DigiTimeBox_wheel2m" );
123  sprintf (histo_t, "Digi Time Box wheel -2" );
124  meDigiTimeBox_wheel2m_ = dbe_->book1D(histo_n, histo_t, 384,0,1200);
125 
126  sprintf (histo_n, "DigiTimeBox_wheel1m" );
127  sprintf (histo_t, "Digi Time Box wheel -1" );
128  meDigiTimeBox_wheel1m_ = dbe_->book1D(histo_n, histo_t, 384,0,1200);
129 
130  sprintf (histo_n, "DigiTimeBox_wheel0" );
131  sprintf (histo_t, "Digi Time Box wheel 0" );
132  meDigiTimeBox_wheel0_ = dbe_->book1D(histo_n, histo_t, 384,0,1200);
133 
134  sprintf (histo_n, "DigiTimeBox_wheel1p" );
135  sprintf (histo_t, "Digi Time Box wheel 1" );
136  meDigiTimeBox_wheel1p_ = dbe_->book1D(histo_n, histo_t, 384,0,1200);
137 
138  sprintf (histo_n, "DigiTimeBox_wheel2p" );
139  sprintf (histo_t, "Digi Time Box wheel 2" );
140  meDigiTimeBox_wheel2p_ = dbe_->book1D(histo_n, histo_t, 384,0,1200);
141 
142  sprintf (histo_n, "DigiEfficiencyMu" );
143  sprintf (histo_t, "Ratio (#Digis Mu)/(#SimHits Mu)" );
144  meDigiEfficiencyMu_ = dbe_->book1D(histo_n, histo_t, 100, 0., 5.);
145 
146  sprintf (histo_n, "DigiEfficiency" );
147  sprintf (histo_t, "Ratio (#Digis)/(#SimHits)" );
148  meDigiEfficiency_ = dbe_->book1D(histo_n, histo_t, 100, 0., 5.);
149 
150  sprintf (histo_n, "Number_Digi_per_layer" );
151  sprintf (histo_t, "Number_Digi_per_layer" );
152  meDoubleDigi_ = dbe_->book1D(histo_n, histo_t, 10,0.,10.);
153 
154  sprintf (histo_n, "Number_simhit_vs_digi" );
155  sprintf (histo_t, "Number_simhit_vs_digi" );
156  meSimvsDigi_ = dbe_->book2D(histo_n, histo_t, 100, 0., 140., 100, 0., 140.);
157 
158  sprintf (histo_n, "Wire_Number_with_double_Digi" );
159  sprintf (histo_t, "Wire_Number_with_double_Digi" );
160  meWire_DoubleDigi_ = dbe_->book1D(histo_n, histo_t, 100,0.,100.);
161 
162  sprintf (histo_n, "Simhit_occupancy_MB1" );
163  sprintf (histo_t, "Simhit_occupancy_MB1" );
164  meMB1_sim_occup_ = dbe_->book1D(histo_n, histo_t, 55, 0., 55. );
165 
166  sprintf (histo_n, "Digi_occupancy_MB1" );
167  sprintf (histo_t, "Digi_occupancy_MB1" );
168  meMB1_digi_occup_ = dbe_->book1D(histo_n, histo_t, 55, 0., 55. );
169 
170  sprintf (histo_n, "Simhit_occupancy_MB2" );
171  sprintf (histo_t, "Simhit_occupancy_MB2" );
172  meMB2_sim_occup_ = dbe_->book1D(histo_n, histo_t, 63, 0., 63. );
173 
174  sprintf (histo_n, "Digi_occupancy_MB2" );
175  sprintf (histo_t, "Digi_occupancy_MB2" );
176  meMB2_digi_occup_ = dbe_->book1D(histo_n, histo_t, 63, 0., 63. );
177 
178  sprintf (histo_n, "Simhit_occupancy_MB3" );
179  sprintf (histo_t, "Simhit_occupancy_MB3" );
180  meMB3_sim_occup_ = dbe_->book1D(histo_n, histo_t, 75, 0., 75. );
181 
182  sprintf (histo_n, "Digi_occupancy_MB3" );
183  sprintf (histo_t, "Digi_occupancy_MB3" );
184  meMB3_digi_occup_ = dbe_->book1D(histo_n, histo_t, 75, 0., 75. );
185 
186  sprintf (histo_n, "Simhit_occupancy_MB4" );
187  sprintf (histo_t, "Simhit_occupancy_MB4" );
188  meMB4_sim_occup_ = dbe_->book1D(histo_n, histo_t, 99, 0., 99. );
189 
190  sprintf (histo_n, "Digi_occupancy_MB4" );
191  sprintf (histo_t, "Digi_occupancy_MB4" );
192  meMB4_digi_occup_ = dbe_->book1D(histo_n, histo_t, 99, 0., 99. );
193 
194  // sprintf (histo_n, "" );
195  // sprintf (histo_t, "" );
196 
197  /*
198  // Other option
199  string histoTag = "DigiTimeBox_slid_";
200  for ( int wheel = -2; wheel <= +2; ++wheel ) {
201  for ( int station = 1; station <= 4; ++station ) {
202  for ( int superLayer = 1; superLayer <= 3; ++superLayer ) {
203  string histoName = histoTag
204  + "_W" + wheel.str()
205  + "_St" + station.str()
206  + "_SL" + superLayer.str();
207  // the booking is not yet done
208  }
209  }
210  }
211  */
212  // Begona's option
213  char stringcham[40];
214  for ( int slnum = 1; slnum < 62; ++slnum ) {
215  sprintf(stringcham, "DigiTimeBox_slid_%d", slnum) ;
216  meDigiHisto_ = dbe_->book1D(stringcham, stringcham, 100,0,1200);
217  meDigiTimeBox_SL_.push_back(meDigiHisto_);
218  }
219  }
220 
221 }
222 
224 
225  // Uncomment these next lines if you want additional plots in a second .root file
226 
227  // file_more_plots->cd();
228 
229  // hDigis_global->Write();
230 
231  // hDigis_W0->Write();
232  // hDigis_W1->Write();
233  // hDigis_W2->Write();
234  // hAllHits->Write();
235 
236  // file_more_plots->Close();
237 
238  // End of comment.
239 
240  if ( outputFile_.size() != 0 && dbe_ ) dbe_->save(outputFile_);
241 
242  if(verbose_)
243  cout << "[MuonDTDigis] Destructor called" << endl;
244 
245 }
246 
247 //void MuonDTDigis::endJob(void){
248 
249 //}
250 
251 void MuonDTDigis::analyze(const Event & event, const EventSetup& eventSetup){
252 
253  if(verbose_)
254  cout << "--- [MuonDTDigis] Analysing Event: #Run: " << event.id().run()
255  << " #Event: " << event.id().event() << endl;
256 
257  // Get the DT Geometry
258  ESHandle<DTGeometry> muonGeom;
259  eventSetup.get<MuonGeometryRecord>().get(muonGeom);
260 
261  // Get the Digi collection from the event
262  Handle<DTDigiCollection> dtDigis;
263  event.getByToken(DigiToken_, dtDigis);
264 
265  // Get simhits
267  event.getByToken(SimHitToken_, simHits);
268 
269  // For the PSimHit part generated by G4, for the 'simevent.root' type files
270  // event.getByLabel("SimG4Object","MuonDTHits",simHits);
271 
272 
273  int num_mudigis;
274  int num_musimhits;
275  int num_digis;
276  int num_digis_layer;
277  int cham_num ;
278  int wire_touched;
279  num_digis = 0;
280  num_mudigis = 0;
281  num_musimhits = 0;
282  DTWireIdMap wireMap;
283 
284  for(vector<PSimHit>::const_iterator hit = simHits->begin();
285  hit != simHits->end(); hit++){
286  // Create the id of the wire, the simHits in the DT known also the wireId
287  DTWireId wireId(hit->detUnitId());
288  // cout << " PSimHits wire id " << wireId << " part type " << hit->particleType() << endl;
289 
290  // Fill the map
291  wireMap[wireId].push_back(&(*hit));
292 
293  LocalPoint entryP = hit->entryPoint();
294  LocalPoint exitP = hit->exitPoint();
295  int partType = hit->particleType();
296  if ( abs(partType) == 13 ) num_musimhits++;
297 
298  if ( wireId.station() == 1 && abs(partType) == 13 ) meMB1_sim_occup_->Fill(wireId.wire());
299  if ( wireId.station() == 2 && abs(partType) == 13 ) meMB2_sim_occup_->Fill(wireId.wire());
300  if ( wireId.station() == 3 && abs(partType) == 13 ) meMB3_sim_occup_->Fill(wireId.wire());
301  if ( wireId.station() == 4 && abs(partType) == 13 ) meMB4_sim_occup_->Fill(wireId.wire());
302 
303 
304  float path = (exitP-entryP).mag();
305  float path_x = fabs((exitP-entryP).x());
306 
307  hAllHits->Fill(entryP.x(),exitP.x(),
308  entryP.y(),exitP.y(),
309  entryP.z(),exitP.z(),
310  path , path_x,
311  partType, hit->processType(),
312  hit->pabs());
313 
314  }
315 
316  // cout << "num muon simhits " << num_musimhits << endl;
317 
319  for (detUnitIt=dtDigis->begin();
320  detUnitIt!=dtDigis->end();
321  ++detUnitIt){
322 
323  const DTLayerId& id = (*detUnitIt).first;
324  const DTDigiCollection::Range& range = (*detUnitIt).second;
325 
326  num_digis_layer = 0 ;
327  cham_num = 0 ;
328  wire_touched = 0;
329 
330  // Loop over the digis of this DetUnit
331  for (DTDigiCollection::const_iterator digiIt = range.first;
332  digiIt!=range.second;
333  ++digiIt){
334  // cout<<" Wire: "<<(*digiIt).wire()<<endl
335  // <<" digi time (ns): "<<(*digiIt).time()<<endl;
336 
337  num_digis++;
338  num_digis_layer++;
339  if (num_digis_layer > 1 )
340  {
341  if ( (*digiIt).wire() == wire_touched )
342  {
343  meWire_DoubleDigi_->Fill((*digiIt).wire());
344  // cout << "old & new wire " << wire_touched << " " << (*digiIt).wire() << endl;
345  }
346  }
347  wire_touched = (*digiIt).wire();
348 
349  meDigiTimeBox_->Fill((*digiIt).time());
350  if (id.wheel() == -2 ) meDigiTimeBox_wheel2m_->Fill((*digiIt).time());
351  if (id.wheel() == -1 ) meDigiTimeBox_wheel1m_->Fill((*digiIt).time());
352  if (id.wheel() == 0 ) meDigiTimeBox_wheel0_ ->Fill((*digiIt).time());
353  if (id.wheel() == 1 ) meDigiTimeBox_wheel1p_->Fill((*digiIt).time());
354  if (id.wheel() == 2 ) meDigiTimeBox_wheel2p_->Fill((*digiIt).time());
355 
356  // Superlayer number and fill histo with digi timebox
357 
358  cham_num = (id.wheel() +2)*12 + (id.station() -1)*3 + id.superlayer();
359  // cout << " Histo number " << cham_num << endl;
360 
361  meDigiTimeBox_SL_[cham_num]->Fill((*digiIt).time());
362 
363  // cout << " size de digis " << (*digiIt).size() << endl;
364 
365  DTWireId wireId(id,(*digiIt).wire());
366  if (wireId.station() == 1 ) meMB1_digi_occup_->Fill((*digiIt).wire());
367  if (wireId.station() == 2 ) meMB2_digi_occup_->Fill((*digiIt).wire());
368  if (wireId.station() == 3 ) meMB3_digi_occup_->Fill((*digiIt).wire());
369  if (wireId.station() == 4 ) meMB4_digi_occup_->Fill((*digiIt).wire());
370 
371  int mu=0;
372  float theta = 0;
373 
374  for(vector<const PSimHit*>::iterator hit = wireMap[wireId].begin();
375  hit != wireMap[wireId].end(); hit++)
376  if( abs((*hit)->particleType()) == 13){
377  theta = atan( (*hit)->momentumAtEntry().x()/ (-(*hit)->momentumAtEntry().z()) )*180/M_PI;
378  // cout<<"momentum x: "<<(*hit)->momentumAtEntry().x()<<endl
379  // <<"momentum z: "<<(*hit)->momentumAtEntry().z()<<endl
380  // <<"atan: "<<theta<<endl;
381  mu++;
382  }
383 
384  if( mu ) num_mudigis++;
385 
386  if(mu && theta){
387  hDigis_global->Fill((*digiIt).time(),theta,id.superlayer());
388  //filling digi histos for wheel and for RZ and RPhi
389  WheelHistos(id.wheel())->Fill((*digiIt).time(),theta,id.superlayer());
390  }
391 
392  }// for digis in layer
393 
394  meDoubleDigi_->Fill( (float)num_digis_layer );
395 
396  }// for layers
397 
398  //cout << "num_digis " << num_digis << "mu digis " << num_mudigis << endl;
399 
400  if (num_musimhits != 0) {
401  meDigiEfficiencyMu_->Fill( (float)num_mudigis/(float)num_musimhits );
402  meDigiEfficiency_->Fill( (float)num_digis/(float)num_musimhits );
403  }
404 
405  meSimvsDigi_->Fill( (float)num_musimhits, (float)num_digis ) ;
406  // cout<<"--------------"<<endl;
407 
408 }
409 
410 hDigis* MuonDTDigis::WheelHistos(int wheel){
411  switch(abs(wheel)){
412 
413  case 0: return hDigis_W0;
414 
415  case 1: return hDigis_W1;
416 
417  case 2: return hDigis_W2;
418 
419  default: return NULL;
420  }
421 }
425 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup)
Definition: MuonDTDigis.cc:251
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:872
std::map< DTWireId, std::vector< const PSimHit * > > DTWireIdMap
Definition: MuonDTDigis.h:71
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Geom::Theta< T > theta() const
T y() const
Definition: PV3DBase.h:63
#define NULL
Definition: scimark2.h:8
DEFINE_FWK_MODULE(HiMixingModule)
uint16_t size_type
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
T z() const
Definition: PV3DBase.h:64
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
virtual ~MuonDTDigis()
Definition: MuonDTDigis.cc:223
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", const uint32_t run=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2296
const int mu
Definition: Constants.h:22
void setVerbose(unsigned level)
Definition: DQMStore.cc:548
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
hDigis * WheelHistos(int wheel)
Definition: MuonDTDigis.cc:410
DQMStore * dbe_
#define M_PI
Definition: BFit3D.cc:3
const T & get() const
Definition: EventSetup.h:55
std::vector< DTDigi >::const_iterator const_iterator
tuple simHits
Definition: trackerHits.py:16
#define begin
Definition: vmac.h:30
std::pair< const_iterator, const_iterator > Range
tuple cout
Definition: gather_cfg.py:121
void showDirStructure(void) const
Definition: DQMStore.cc:2961
Definition: DDAxes.h:10
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:1000
T x() const
Definition: PV3DBase.h:62
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:584
MuonDTDigis(const edm::ParameterSet &pset)
Definition: MuonDTDigis.cc:19