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: 2010/01/05 10:14:40 $
6  * $Revision: 1.18 $
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++;
101  if(evtNumber%1000==0)
102  LogVerbatim("DTNoiseTask") <<"[DTNoiseTask]: Analyzing evt number :"<<evtNumber<<endl;
103 
104  // map of the chambers with at least 1 segment
105  std::map<DTChamberId, int> segmentsChId;
106 
107  // Get the 4D segment collection from the event
109  if(doSegmentVeto) {
110  e.getByLabel(theRecHits4DLabel, all4DSegments);
111 
112  // Loop over all chambers containing a segment and look for the number of segments
114  for (chamberId = all4DSegments->id_begin();
115  chamberId != all4DSegments->id_end();
116  ++chamberId){
117  segmentsChId[*chamberId]=1;
118  }
119  }
120 
121  // Get the digis from the event
123  e.getByLabel(dtDigiLabel, dtdigis);
124 
125  // LOOP OVER ALL THE DIGIS OF THE EVENT
127  for (dtLayerId_It=dtdigis->begin(); dtLayerId_It!=dtdigis->end(); ++dtLayerId_It){
128  for (DTDigiCollection::const_iterator digiIt = ((*dtLayerId_It).second).first;
129  digiIt!=((*dtLayerId_It).second).second; ++digiIt){
130 
131  //Check the TDC trigger width
132  int tdcTime = (*digiIt).countsTDC();
133  double upperLimit = tTrigStMap[(*dtLayerId_It).first.superlayerId().chamberId()]-safeMargin;
134  if(doTimeBoxHistos)
135  tbHistos[(*dtLayerId_It).first.superlayerId()]->Fill(tdcTime);
136  if(tdcTime>upperLimit)
137  continue;
138 
139  //Check the chamber has no 4D segments (optional)
140  if(doSegmentVeto &&
141  segmentsChId.find((*dtLayerId_It).first.superlayerId().chamberId())!=segmentsChId.end())
142  continue;
143 
144  // fill the occupancy histo
145  // FIXME: needs to be optimized: no need to rescale the histo for each digi
146  TH2F* noise_root = noiseHistos[(*dtLayerId_It).first.superlayerId().chamberId()]->getTH2F();
147  double normalization=0;
148  if(mapEvt.find((*dtLayerId_It).first.superlayerId().chamberId())!=mapEvt.end()) {
149  LogVerbatim("DTNoiseTask") << " Last fill: # of events: "
150  << mapEvt[(*dtLayerId_It).first.superlayerId().chamberId()]
151  << endl;
152  normalization = 1e-9*upperLimit*mapEvt[(*dtLayerId_It).first.superlayerId().chamberId()];
153  // revert back to # of entries
154  noise_root->Scale(normalization);
155  }
156  int yBin=(*dtLayerId_It).first.layer()+(4*((*dtLayerId_It).first.superlayerId().superlayer()-1));
157  noise_root->Fill((*digiIt).wire(),yBin);
158  // normalize the occupancy histo
159  mapEvt[(*dtLayerId_It).first.superlayerId().chamberId()] = evtNumber;
160  LogVerbatim("DTNoiseTask") << (*dtLayerId_It).first << " wire: " << (*digiIt).wire()
161  << " # counts: " << noise_root->GetBinContent((*digiIt).wire(),yBin)
162  << " Time interval: " << upperLimit
163  << " # of events: " << evtNumber << endl;;
164  normalization = double( 1e-9*upperLimit*mapEvt[(*dtLayerId_It).first.superlayerId().chamberId()]);
165  // update the rate
166  noise_root->Scale(1./normalization);
167  LogVerbatim("DTNoiseTask") << " noise rate: "
168  << noise_root->GetBinContent((*digiIt).wire(),yBin) << endl;
169  }
170  }
171 }
172 
173 
174 
177 
178 
180 
181  // set the folder
182  stringstream wheel; wheel << chId.wheel();
183  stringstream station; station << chId.station();
184  stringstream sector; sector << chId.sector();
185  dbe->setCurrentFolder("DT/05-Noise/Wheel" + wheel.str() +
186 // "/Station" + station.str() +
187  "/Sector" + sector.str());
188 
189  // Build the histo name
190  string histoName = string("NoiseRate")
191  + "_W" + wheel.str()
192  + "_St" + station.str()
193  + "_Sec" + sector.str() ;
194 
195  LogVerbatim("DTNoiseTask") << "[DTNoiseTask]: booking chamber histo:"<<endl;
196  LogVerbatim("DTNoiseTask") << " folder "<< "DT/05-Noise/Wheel" + wheel.str() +
197 // "/Station" + station.str() +
198  "/Sector" + sector.str() + "/"<<endl;
199  LogVerbatim("DTNoiseTask") << " histoName "<<histoName<<endl;
200 
201  // Get the chamber from the geometry
202  int nWires_max = 0;
203  const DTChamber* dtchamber = dtGeom->chamber(chId);
204  const vector<const DTSuperLayer*> superlayers = dtchamber->superLayers();
205 
206  // Loop over layers and find the max # of wires
207  for(vector<const DTSuperLayer*>::const_iterator sl = superlayers.begin();
208  sl != superlayers.end(); ++sl) { // loop over SLs
209  vector<const DTLayer*> layers = (*sl)->layers();
210  for(vector<const DTLayer*>::const_iterator lay = layers.begin();
211  lay != layers.end(); ++lay) { // loop over layers
212  int nWires = (*lay)->specificTopology().channels();
213  if(nWires > nWires_max) nWires_max = nWires;
214  }
215  }
216 
217  noiseHistos[chId] = dbe->book2D(histoName,"Noise rate (Hz) per channel", nWires_max,1, nWires_max+1,12,1,13);
218  noiseHistos[chId]->setAxisTitle("wire number",1);
219  noiseHistos[chId]->setBinLabel(1,"SL1-L1",2);
220  noiseHistos[chId]->setBinLabel(2,"SL1-L2",2);
221  noiseHistos[chId]->setBinLabel(3,"SL1-L3",2);
222  noiseHistos[chId]->setBinLabel(4,"SL1-L4",2);
223  noiseHistos[chId]->setBinLabel(5,"SL2-L1",2);
224  noiseHistos[chId]->setBinLabel(6,"SL2-L2",2);
225  noiseHistos[chId]->setBinLabel(7,"SL2-L3",2);
226  noiseHistos[chId]->setBinLabel(8,"SL2-L4",2);
227  noiseHistos[chId]->setBinLabel(9,"SL3-L1",2);
228  noiseHistos[chId]->setBinLabel(10,"SL3-L2",2);
229  noiseHistos[chId]->setBinLabel(11,"SL3-L3",2);
230  noiseHistos[chId]->setBinLabel(12,"SL3-L4",2);
231 
232 }
233 
234 
236 
237  // set the folder
238  stringstream wheel; wheel << slId.chamberId().wheel();
239  stringstream station; station << slId.chamberId().station();
240  stringstream sector; sector << slId.chamberId().sector();
241  stringstream superlayer; superlayer << slId.superlayer();
242  dbe->setCurrentFolder("DT/05-Noise/Wheel" + wheel.str() +
243  "/Station" + station.str() +
244  "/Sector" + sector.str());
245 
246  // Build the histo name
247  string histoName = string("TimeBox")
248  + "_W" + wheel.str()
249  + "_St" + station.str()
250  + "_Sec" + sector.str()
251  + "_SL" + superlayer.str();
252 
253  LogVerbatim("DTNoiseTask") <<"[DTNoiseTask]: booking SL histo:"<<endl;
254  LogVerbatim("DTNoiseTask") <<" folder "<< "DT/05-Noise/Wheel" + wheel.str() +
255  "/Station" + station.str() +
256  "/Sector" + sector.str() + "/" << endl;
257  LogVerbatim("DTNoiseTask") <<" histoName "<<histoName<<endl;
258 
259  tbHistos[slId] = dbe->book1D(histoName,"Time Box (TDC counts)", 1000, 0, 6000);
260 
261 }
262 
263 
265 
266  LogVerbatim("DTNoiseTask") <<"[DTNoiseTask]: Begin of run"<<endl;
267 
268  // tTrig Map
269  edm::ESHandle<DTTtrig> tTrigMap;
270  setup.get<DTTtrigRcd>().get(tTrigMap);
271 
272  // get the geometry
273  setup.get<MuonGeometryRecord>().get(dtGeom);
274 
275  // Loop over all the chambers
276  vector<DTChamber*>::const_iterator ch_it = dtGeom->chambers().begin();
277  vector<DTChamber*>::const_iterator ch_end = dtGeom->chambers().end();
278  for (; ch_it != ch_end; ++ch_it) {
279  DTChamberId chId = (*ch_it)->id();
280  // histo booking
281  bookHistos(chId);
282  vector<const DTSuperLayer*>::const_iterator sl_it = (*ch_it)->superLayers().begin();
283  vector<const DTSuperLayer*>::const_iterator sl_end = (*ch_it)->superLayers().end();
284  // Loop over the SLs
285  for(; sl_it != sl_end; ++sl_it) {
286  DTSuperLayerId slId = (*sl_it)->id();
287  if(doTimeBoxHistos)
288  bookHistos(slId);
289  float tTrig, tTrigRMS, kFactor;
290  tTrigMap->get(slId, tTrig, tTrigRMS,kFactor,DTTimeUnits::ns);
291  // tTrig mapping per station
292  // check that the ttrig is the lowest of the 3 SLs
293  if(tTrigStMap.find(chId)==tTrigStMap.end() ||
294  (tTrigStMap.find(chId)!=tTrigStMap.end() && tTrig < tTrigStMap[chId]))
295  tTrigStMap[chId] = tTrig;
296  }
297  }
298 
299 
300 }
301 
303  LogVerbatim("DTNoiseTask") << "[DTNoiseTask]: End LS, update rates in all histos" << endl;
304 
305  // update the rate of all histos (usefull for histos with few entries: they are not updated very often
306  for(map<DTChamberId, MonitorElement*>::const_iterator meAndChamber = noiseHistos.begin();
307  meAndChamber != noiseHistos.end(); ++meAndChamber) {
308  DTChamberId chId = (*meAndChamber).first;
309  TH2F* noise_root = (*meAndChamber).second->getTH2F();
310  double upperLimit = tTrigStMap[chId]-safeMargin;
311 
312  double normalization=0;
313  if(mapEvt.find(chId) != mapEvt.end()) {
314  LogVerbatim("DTNoiseTask") << " Ch: " << chId << " Last fill: # of events: " << mapEvt[chId] << endl;
315  normalization = 1e-9*upperLimit*mapEvt[chId];
316  // revert back to # of entries
317  noise_root->Scale(normalization);
318  }
319  //check that event analyzed != 0 might happen oline
320  if (evtNumber) {
321  // set the # of events analyzed until this update
322  LogVerbatim("DTNoiseTask") << " Update for events: " << evtNumber << endl;
323  mapEvt[chId] = evtNumber;
324  // update the rate
325  normalization = double( 1e-9*upperLimit*evtNumber);
326  noise_root->Scale(1./normalization);
327  }
328  }
329 }
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:514
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:139
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &setup)
Definition: DTNoiseTask.cc:302
bool doSegmentVeto
Definition: DTNoiseTask.h:72
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context)
To reset the MEs.
Definition: DTNoiseTask.cc:88
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:264
void endJob()
Endjob.
Definition: DTNoiseTask.cc:176
double safeMargin
Definition: DTNoiseTask.h:90
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
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:642
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:179
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:232
Definition: Run.h:32