CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTNoiseTask.cc
Go to the documentation of this file.
1 
2 /*
3  * See header file for a description of this class.
4  *
5  * $Date: 2011/06/10 13:23:26 $
6  * $Revision: 1.20 $
7  * \authors G. Mila , G. Cerminara - INFN Torino
8  */
9 
10 #include "DTNoiseTask.h"
11 
12 // Framework
17 
19 
20 // Geometry
25 
26 // Digi
32 
33 // RecHit
35 
36 // Database
39 
40 #include <sstream>
41 #include <string>
42 
43 using namespace edm;
44 using namespace std;
45 
46 
47 
48 DTNoiseTask::DTNoiseTask(const ParameterSet& ps) : evtNumber(0) {
49 
50  LogVerbatim("DTNoiseTask") << "[DTNoiseTask]: Constructor"<<endl;
51 
53 
54  //switch for timeBox booking
55  doTimeBoxHistos = ps.getUntrackedParameter<bool>("doTbHistos", false);
56 
57  // The label to retrieve the digis
58  dtDigiLabel = ps.getParameter<InputTag>("dtDigiLabel");
59 
60  // the name of the 4D rec hits collection
61  theRecHits4DLabel = ps.getParameter<string>("recHits4DLabel");
62 
63  // switch for segment veto
64  doSegmentVeto = ps.getUntrackedParameter<bool>("doSegmentVeto", false);
65 
66  // safe margin (ns) between ttrig and beginning of counting area
67  safeMargin = ps.getUntrackedParameter<double>("safeMargin", 200.);
68 
69 }
70 
71 
72 
73 
75 
76 
77 
80 
81  LogVerbatim("DTNoiseTask") << "[DTNoiseTask]: BeginJob"<<endl;
82 
83 }
84 
85 
86 
89  const edm::EventSetup& context) {
90 
91  LogVerbatim("DTNoiseTask") <<"[DTNoiseTask]: Begin of LS transition"<<endl;
92 
93 }
94 
95 
96 
99 
100  evtNumber++;
102 
103  if(evtNumber%1000==0)
104  LogVerbatim("DTNoiseTask") <<"[DTNoiseTask]: Analyzing evt number :"<<evtNumber<<endl;
105 
106  // map of the chambers with at least 1 segment
107  std::map<DTChamberId, int> segmentsChId;
108 
109  // Get the 4D segment collection from the event
111  if(doSegmentVeto) {
112  e.getByLabel(theRecHits4DLabel, all4DSegments);
113 
114  // Loop over all chambers containing a segment and look for the number of segments
116  for (chamberId = all4DSegments->id_begin();
117  chamberId != all4DSegments->id_end();
118  ++chamberId){
119  segmentsChId[*chamberId]=1;
120  }
121  }
122 
123  // Get the digis from the event
125  e.getByLabel(dtDigiLabel, dtdigis);
126 
127  // LOOP OVER ALL THE DIGIS OF THE EVENT
129  for (dtLayerId_It=dtdigis->begin(); dtLayerId_It!=dtdigis->end(); ++dtLayerId_It){
130  for (DTDigiCollection::const_iterator digiIt = ((*dtLayerId_It).second).first;
131  digiIt!=((*dtLayerId_It).second).second; ++digiIt){
132 
133  //Check the TDC trigger width
134  int tdcTime = (*digiIt).countsTDC();
135  double upperLimit = tTrigStMap[(*dtLayerId_It).first.superlayerId().chamberId()]-safeMargin;
136  if(doTimeBoxHistos)
137  tbHistos[(*dtLayerId_It).first.superlayerId()]->Fill(tdcTime);
138  if(tdcTime>upperLimit)
139  continue;
140 
141  //Check the chamber has no 4D segments (optional)
142  if(doSegmentVeto &&
143  segmentsChId.find((*dtLayerId_It).first.superlayerId().chamberId())!=segmentsChId.end())
144  continue;
145 
146  // fill the occupancy histo
147  // FIXME: needs to be optimized: no need to rescale the histo for each digi
148  TH2F* noise_root = noiseHistos[(*dtLayerId_It).first.superlayerId().chamberId()]->getTH2F();
149  double normalization=0;
150  if(mapEvt.find((*dtLayerId_It).first.superlayerId().chamberId())!=mapEvt.end()) {
151  LogVerbatim("DTNoiseTask") << " Last fill: # of events: "
152  << mapEvt[(*dtLayerId_It).first.superlayerId().chamberId()]
153  << endl;
154  normalization = 1e-9*upperLimit*mapEvt[(*dtLayerId_It).first.superlayerId().chamberId()];
155  // revert back to # of entries
156  noise_root->Scale(normalization);
157  }
158  int yBin=(*dtLayerId_It).first.layer()+(4*((*dtLayerId_It).first.superlayerId().superlayer()-1));
159  noise_root->Fill((*digiIt).wire(),yBin);
160  // normalize the occupancy histo
161  mapEvt[(*dtLayerId_It).first.superlayerId().chamberId()] = evtNumber;
162  LogVerbatim("DTNoiseTask") << (*dtLayerId_It).first << " wire: " << (*digiIt).wire()
163  << " # counts: " << noise_root->GetBinContent((*digiIt).wire(),yBin)
164  << " Time interval: " << upperLimit
165  << " # of events: " << evtNumber << endl;;
166  normalization = double( 1e-9*upperLimit*mapEvt[(*dtLayerId_It).first.superlayerId().chamberId()]);
167  // update the rate
168  noise_root->Scale(1./normalization);
169  LogVerbatim("DTNoiseTask") << " noise rate: "
170  << noise_root->GetBinContent((*digiIt).wire(),yBin) << endl;
171  }
172  }
173 }
174 
175 
176 
179 
180 
182 
183  // set the folder
184  stringstream wheel; wheel << chId.wheel();
185  stringstream station; station << chId.station();
186  stringstream sector; sector << chId.sector();
187  dbe->setCurrentFolder("DT/05-Noise/Wheel" + wheel.str() +
188 // "/Station" + station.str() +
189  "/Sector" + sector.str());
190 
191  // Build the histo name
192  string histoName = string("NoiseRate")
193  + "_W" + wheel.str()
194  + "_St" + station.str()
195  + "_Sec" + sector.str() ;
196 
197  LogVerbatim("DTNoiseTask") << "[DTNoiseTask]: booking chamber histo:"<<endl;
198  LogVerbatim("DTNoiseTask") << " folder "<< "DT/05-Noise/Wheel" + wheel.str() +
199 // "/Station" + station.str() +
200  "/Sector" + sector.str() + "/"<<endl;
201  LogVerbatim("DTNoiseTask") << " histoName "<<histoName<<endl;
202 
203  // Get the chamber from the geometry
204  int nWires_max = 0;
205  const DTChamber* dtchamber = dtGeom->chamber(chId);
206  const vector<const DTSuperLayer*> superlayers = dtchamber->superLayers();
207 
208  // Loop over layers and find the max # of wires
209  for(vector<const DTSuperLayer*>::const_iterator sl = superlayers.begin();
210  sl != superlayers.end(); ++sl) { // loop over SLs
211  vector<const DTLayer*> layers = (*sl)->layers();
212  for(vector<const DTLayer*>::const_iterator lay = layers.begin();
213  lay != layers.end(); ++lay) { // loop over layers
214  int nWires = (*lay)->specificTopology().channels();
215  if(nWires > nWires_max) nWires_max = nWires;
216  }
217  }
218 
219  noiseHistos[chId] = dbe->book2D(histoName,"Noise rate (Hz) per channel", nWires_max,1, nWires_max+1,12,1,13);
220  noiseHistos[chId]->setAxisTitle("wire number",1);
221  noiseHistos[chId]->setBinLabel(1,"SL1-L1",2);
222  noiseHistos[chId]->setBinLabel(2,"SL1-L2",2);
223  noiseHistos[chId]->setBinLabel(3,"SL1-L3",2);
224  noiseHistos[chId]->setBinLabel(4,"SL1-L4",2);
225  noiseHistos[chId]->setBinLabel(5,"SL2-L1",2);
226  noiseHistos[chId]->setBinLabel(6,"SL2-L2",2);
227  noiseHistos[chId]->setBinLabel(7,"SL2-L3",2);
228  noiseHistos[chId]->setBinLabel(8,"SL2-L4",2);
229  noiseHistos[chId]->setBinLabel(9,"SL3-L1",2);
230  noiseHistos[chId]->setBinLabel(10,"SL3-L2",2);
231  noiseHistos[chId]->setBinLabel(11,"SL3-L3",2);
232  noiseHistos[chId]->setBinLabel(12,"SL3-L4",2);
233 
234 }
235 
236 
238 
239  // set the folder
240  stringstream wheel; wheel << slId.chamberId().wheel();
241  stringstream station; station << slId.chamberId().station();
242  stringstream sector; sector << slId.chamberId().sector();
243  stringstream superlayer; superlayer << slId.superlayer();
244  dbe->setCurrentFolder("DT/05-Noise/Wheel" + wheel.str() +
245  "/Station" + station.str() +
246  "/Sector" + sector.str());
247 
248  // Build the histo name
249  string histoName = string("TimeBox")
250  + "_W" + wheel.str()
251  + "_St" + station.str()
252  + "_Sec" + sector.str()
253  + "_SL" + superlayer.str();
254 
255  LogVerbatim("DTNoiseTask") <<"[DTNoiseTask]: booking SL histo:"<<endl;
256  LogVerbatim("DTNoiseTask") <<" folder "<< "DT/05-Noise/Wheel" + wheel.str() +
257  "/Station" + station.str() +
258  "/Sector" + sector.str() + "/" << endl;
259  LogVerbatim("DTNoiseTask") <<" histoName "<<histoName<<endl;
260 
261  tbHistos[slId] = dbe->book1D(histoName,"Time Box (TDC counts)", 1000, 0, 6000);
262 
263 }
264 
265 
267 
268  LogVerbatim("DTNoiseTask") <<"[DTNoiseTask]: Begin of run"<<endl;
269 
270  // tTrig Map
271  edm::ESHandle<DTTtrig> tTrigMap;
272  setup.get<DTTtrigRcd>().get(tTrigMap);
273 
274  // get the geometry
275  setup.get<MuonGeometryRecord>().get(dtGeom);
276 
277  dbe->setCurrentFolder("DT/EventInfo/Counters");
278  nEventMonitor = dbe->bookFloat("nProcessedEventsNoise");
279 
280  // Loop over all the chambers
281  vector<DTChamber*>::const_iterator ch_it = dtGeom->chambers().begin();
282  vector<DTChamber*>::const_iterator ch_end = dtGeom->chambers().end();
283  for (; ch_it != ch_end; ++ch_it) {
284  DTChamberId chId = (*ch_it)->id();
285  // histo booking
286  bookHistos(chId);
287  vector<const DTSuperLayer*>::const_iterator sl_it = (*ch_it)->superLayers().begin();
288  vector<const DTSuperLayer*>::const_iterator sl_end = (*ch_it)->superLayers().end();
289  // Loop over the SLs
290  for(; sl_it != sl_end; ++sl_it) {
291  DTSuperLayerId slId = (*sl_it)->id();
292  if(doTimeBoxHistos)
293  bookHistos(slId);
294  float tTrig, tTrigRMS, kFactor;
295  tTrigMap->get(slId, tTrig, tTrigRMS,kFactor,DTTimeUnits::ns);
296  // tTrig mapping per station
297  // check that the ttrig is the lowest of the 3 SLs
298  if(tTrigStMap.find(chId)==tTrigStMap.end() ||
299  (tTrigStMap.find(chId)!=tTrigStMap.end() && tTrig < tTrigStMap[chId]))
300  tTrigStMap[chId] = tTrig;
301  }
302  }
303 
304 
305 }
306 
308  LogVerbatim("DTNoiseTask") << "[DTNoiseTask]: End LS, update rates in all histos" << endl;
309 
310  // update the rate of all histos (usefull for histos with few entries: they are not updated very often
311  for(map<DTChamberId, MonitorElement*>::const_iterator meAndChamber = noiseHistos.begin();
312  meAndChamber != noiseHistos.end(); ++meAndChamber) {
313  DTChamberId chId = (*meAndChamber).first;
314  TH2F* noise_root = (*meAndChamber).second->getTH2F();
315  double upperLimit = tTrigStMap[chId]-safeMargin;
316 
317  double normalization=0;
318  if(mapEvt.find(chId) != mapEvt.end()) {
319  LogVerbatim("DTNoiseTask") << " Ch: " << chId << " Last fill: # of events: " << mapEvt[chId] << endl;
320  normalization = 1e-9*upperLimit*mapEvt[chId];
321  // revert back to # of entries
322  noise_root->Scale(normalization);
323  }
324  //check that event analyzed != 0 might happen oline
325  if (evtNumber) {
326  // set the # of events analyzed until this update
327  LogVerbatim("DTNoiseTask") << " Update for events: " << evtNumber << endl;
328  mapEvt[chId] = evtNumber;
329  // update the rate
330  normalization = double( 1e-9*upperLimit*evtNumber);
331  noise_root->Scale(1./normalization);
332  }
333  }
334 }
T getParameter(std::string const &) const
std::map< DTChamberId, int > mapEvt
Definition: DTNoiseTask.h:84
T getUntrackedParameter(std::string const &, T const &) const
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:717
edm::InputTag dtDigiLabel
Definition: DTNoiseTask.h:64
virtual ~DTNoiseTask()
Destructor.
Definition: DTNoiseTask.cc:74
DTChamberId chamberId() const
Return the corresponding ChamberId.
void beginJob()
BeginJob.
Definition: DTNoiseTask.cc:79
identifier iterator
Definition: RangeMap.h:138
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &setup)
Definition: DTNoiseTask.cc:307
MonitorElement * nEventMonitor
Definition: DTNoiseTask.h:89
MonitorElement * bookFloat(const char *name)
Book float.
Definition: DQMStore.cc:654
bool doSegmentVeto
Definition: DTNoiseTask.h:72
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context)
To reset the MEs.
Definition: DTNoiseTask.cc:88
void Fill(long long x)
U second(std::pair< T, U > const &p)
edm::ESHandle< DTGeometry > dtGeom
Definition: DTNoiseTask.h:75
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
Definition: DTNoiseTask.cc:98
const std::vector< const DTSuperLayer * > & superLayers() const
Return the superlayers in the chamber.
Definition: DTChamber.cc:62
void beginRun(const edm::Run &, const edm::EventSetup &)
Definition: DTNoiseTask.cc:266
void endJob()
Endjob.
Definition: DTNoiseTask.cc:178
double safeMargin
Definition: DTNoiseTask.h:92
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
std::map< DTSuperLayerId, MonitorElement * > tbHistos
Definition: DTNoiseTask.h:87
int superlayer() const
Return the superlayer number (deprecated method name)
const T & get() const
Definition: EventSetup.h:55
std::map< DTChamberId, double > tTrigStMap
Definition: DTNoiseTask.h:78
std::vector< DigiType >::const_iterator const_iterator
int sector() const
Definition: DTChamberId.h:63
DTNoiseTask(const edm::ParameterSet &ps)
Constructor.
Definition: DTNoiseTask.cc:48
bool doTimeBoxHistos
Definition: DTNoiseTask.h:68
std::map< DTChamberId, MonitorElement * > noiseHistos
Definition: DTNoiseTask.h:81
DQMStore * dbe
Definition: DTNoiseTask.h:74
int station() const
Return the station number.
Definition: DTChamberId.h:53
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
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:47
std::string theRecHits4DLabel
Definition: DTNoiseTask.h:70
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
void bookHistos(DTChamberId chId)
Definition: DTNoiseTask.cc:181
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429
Definition: Run.h:33