CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTDigiForNoiseTask.cc
Go to the documentation of this file.
1  /*
2  * \file DTDigiForNoiseTask.cc
3  *
4  * $Date: 2011/11/12 09:18:41 $
5  * $Revision: 1.11 $
6  * \author G. Mila - INFN Torino
7  *
8  */
9 
11 
12 // Framework
14 
15 // Digis
20 
21 // Geometry
26 
29 
30 #include <stdio.h>
31 #include <sstream>
32 #include <math.h>
33 
34 using namespace edm;
35 using namespace std;
36 
37 
39 
40  debug = ps.getUntrackedParameter<bool>("debug", false);
41  if(debug)
42  cout<<"[DTDigiForNoiseTask]: Constructor"<<endl;
43 
44  parameters = ps;
45 
46  dbe = edm::Service<DQMStore>().operator->();
47 
48 }
49 
50 
52 
53  if(debug)
54  cout << "DTDigiForNoiseTask: analyzed " << nevents << " events" << endl;
55 
56 }
57 
58 
60 
61  if(debug)
62  cout<<"[DTDigiForNoiseTask] endjob called!"<<endl;
63 
64  dbe->rmdir("DT/DTDigiForNoiseTask");
65 
66 }
67 
68 
70 
71  if(debug)
72  cout<<"[DTDigiForNoiseTask]: BeginJob"<<endl;
73 
74  nevents = 0;
75 
76 }
77 
79 
80  if(debug)
81  cout<<"[DTDigiForNoiseTask]: BeginRun"<<endl;
82 
83  // Get the geometry
84  context.get<MuonGeometryRecord>().get(muonGeom);
85 
86 }
87 
89 
90  if(debug)
91  cout<<"[DTDigiForNoiseTask]: Begin of LS transition"<<endl;
92 
93  if(lumiSeg.id().luminosityBlock()%parameters.getUntrackedParameter<int>("ResetCycle", 3) == 0) {
94  for(map< DTLayerId, MonitorElement* > ::const_iterator histo = digiHistos.begin();
95  histo != digiHistos.end();
96  histo++) {
97  (*histo).second->Reset();
98  }
99  }
100 
101 }
102 
103 
105 
106  if (debug) cout<<"[DTDigiForNoiseTask]: booking"<<endl;
107 
108  const DTSuperLayerId dtSLId = lId.superlayerId();
109  const DTChamberId dtChId = dtSLId.chamberId();
110  stringstream layer; layer << lId.layer();
111  stringstream superLayer; superLayer << dtSLId.superlayer();
112  stringstream wheel; wheel << dtChId.wheel();
113  stringstream station; station << dtChId.station();
114  stringstream sector; sector << dtChId.sector();
115 
116  dbe->setCurrentFolder("DT/DTDigiForNoiseTask/Wheel" + wheel.str() +
117  "/Station" + station.str() +
118  "/Sector" + sector.str() + "/DigiPerEvent");
119 
120  if (debug){
121  cout<<"[DTDigiForNoiseTask]: folder "<< "DT/DTDigiTask/Wheel" + wheel.str() +
122  "/Station" + station.str() +
123  "/Sector" + sector.str() + "/DigiPerEvent"<<endl;
124  }
125 
126  string histoName =
127  "DigiPerEvent_W" + wheel.str()
128  + "_St" + station.str()
129  + "_Sec" + sector.str()
130  + "_SL" + superLayer.str()
131  + "_L" + layer.str();
132 
133  if (debug) cout<<"[DTDigiTask]: histoName "<<histoName<<endl;
134 
135  const DTTopology& dtTopo = muonGeom->layer(lId)->specificTopology();
136  const int firstWire = dtTopo.firstChannel();
137  const int lastWire = dtTopo.lastChannel();
138  int nWires = lastWire-firstWire+1;
139 
140  digiHistos[lId] = dbe->book2D(histoName,histoName,nWires,firstWire,lastWire,10,-0.5,9.5);
141 
142 }
143 
144 
146 
147  nevents++;
148  // cout << "events: " << nevents << endl;
149  if (nevents%1000 == 0 && debug) {}
150 
152  e.getByLabel("dtunpacker", dtdigis);
153 
154  std::map< int,int > DigiPerWirePerEvent;
155 
156  // Loop over all the chambers
157  vector<DTChamber*>::const_iterator ch_it = muonGeom->chambers().begin();
158  vector<DTChamber*>::const_iterator ch_end = muonGeom->chambers().end();
159  // Loop over the SLs
160  for (; ch_it != ch_end; ++ch_it) {
161  // DTChamberId ch = (*ch_it)->id();
162  vector<const DTSuperLayer*>::const_iterator sl_it = (*ch_it)->superLayers().begin();
163  vector<const DTSuperLayer*>::const_iterator sl_end = (*ch_it)->superLayers().end();
164  // Loop over the SLs
165  for(; sl_it != sl_end; ++sl_it) {
166  vector<const DTLayer*>::const_iterator l_it = (*sl_it)->layers().begin();
167  vector<const DTLayer*>::const_iterator l_end = (*sl_it)->layers().end();
168  // Loop over the Ls
169  for(; l_it != l_end; ++l_it) {
170  DTLayerId layerId = (*l_it)->id();
171 
172  DTDigiCollection::Range layerDigi= dtdigis->get(layerId);
173  if(layerDigi.first != layerDigi.second){
174 
175  const DTTopology& dtTopo = muonGeom->layer(layerId)->specificTopology();
176  const int firstWire = dtTopo.firstChannel();
177  const int lastWire = dtTopo.lastChannel();
178 
179  if (digiHistos.find(layerId) == digiHistos.end())
180  bookHistos(layerId);
181 
182  if (digiHistos.find(layerId) != digiHistos.end()){
183  for (int wire=firstWire; wire-lastWire <= 0; wire++) {
184  DigiPerWirePerEvent[wire]= 0;
185  }
186 
187  for (DTDigiCollection::const_iterator digi = layerDigi.first;
188  digi!=layerDigi.second;
189  ++digi){
190  DigiPerWirePerEvent[(*digi).wire()]+=1;
191  }
192 
193  for (int wire=firstWire; wire-lastWire<=0; wire++) {
194  digiHistos.find(layerId)->second->Fill(wire,DigiPerWirePerEvent[wire]);
195  }
196  }
197  }
198 
199  } //Loop Ls
200  } //Loop SLs
201  } //Loop over chambers
202 
203 }
LuminosityBlockID id() const
T getUntrackedParameter(std::string const &, T const &) const
dictionary parameters
Definition: Parameters.py:2
void beginJob()
BeginJob.
DTChamberId chamberId() const
Return the corresponding ChamberId.
void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &context)
To reset the MEs.
int layer() const
Return the layer number.
Definition: DTLayerId.h:55
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:61
int firstChannel() const
Returns the wire number of the first wire.
Definition: DTTopology.h:80
void bookHistos()
Definition: Histogram.h:33
int lastChannel() const
Returns the wire number of the last wire.
Definition: DTTopology.h:82
void bookHistos(const DTLayerId &dtSL)
Book the ME.
int nevents
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
virtual ~DTDigiForNoiseTask()
Destructor.
int superlayer() const
Return the superlayer number (deprecated method name)
const T & get() const
Definition: EventSetup.h:55
LuminosityBlockNumber_t luminosityBlock() const
std::vector< DigiType >::const_iterator const_iterator
int sector() const
Definition: DTChamberId.h:63
void beginRun(const edm::Run &, const edm::EventSetup &)
BeginRun.
std::pair< const_iterator, const_iterator > Range
tuple cout
Definition: gather_cfg.py:121
DTDigiForNoiseTask(const edm::ParameterSet &ps)
Constructor.
int station() const
Return the station number.
Definition: DTChamberId.h:53
#define debug
Definition: MEtoEDMFormat.h:34
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:47
Definition: Run.h:33