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