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  * \authors G. Mila , G. Cerminara - INFN Torino
6  */
7 
8 #include "DTNoiseTask.h"
9 
10 // Framework
15 
17 
18 // Geometry
23 
24 // Digi
28 
29 // Database
32 
33 #include <sstream>
34 #include <string>
35 
36 using namespace edm;
37 using namespace std;
38 
39 
40 
41 DTNoiseTask::DTNoiseTask(const ParameterSet& ps) : evtNumber(0) {
42 
43  LogVerbatim("DTNoiseTask") << "[DTNoiseTask]: Constructor"<<endl;
44 
46 
47  //switch for timeBox booking
48  doTimeBoxHistos = ps.getUntrackedParameter<bool>("doTbHistos", false);
49 
50  // The label to retrieve the digis
51  dtDigiToken_ = consumes<DTDigiCollection>(
52  ps.getParameter<InputTag>("dtDigiLabel"));
53 
54  // the name of the 4D rec hits collection
55  recHits4DToken_ = consumes<DTRecSegment4DCollection>(
56  edm::InputTag(ps.getParameter<string>("recHits4DLabel")));
57 
58  // switch for segment veto
59  doSegmentVeto = ps.getUntrackedParameter<bool>("doSegmentVeto", false);
60 
61  // safe margin (ns) between ttrig and beginning of counting area
62  safeMargin = ps.getUntrackedParameter<double>("safeMargin", 200.);
63 
64 }
65 
66 
67 
68 
70 
71 
72 
75 
76  LogVerbatim("DTNoiseTask") << "[DTNoiseTask]: BeginJob"<<endl;
77 
78 }
79 
80 
81 
84  const edm::EventSetup& context) {
85 
86  LogVerbatim("DTNoiseTask") <<"[DTNoiseTask]: Begin of LS transition"<<endl;
87 
88 }
89 
90 
91 
94 
95  evtNumber++;
97 
98  if(evtNumber%1000==0)
99  LogVerbatim("DTNoiseTask") <<"[DTNoiseTask]: Analyzing evt number :"<<evtNumber<<endl;
100 
101  // map of the chambers with at least 1 segment
102  std::map<DTChamberId, int> segmentsChId;
103 
104  // Get the 4D segment collection from the event
106  if(doSegmentVeto) {
107  e.getByToken(recHits4DToken_, all4DSegments);
108 
109  // Loop over all chambers containing a segment and look for the number of segments
110  DTRecSegment4DCollection::id_iterator chamberId;
111  for (chamberId = all4DSegments->id_begin();
112  chamberId != all4DSegments->id_end();
113  ++chamberId){
114  segmentsChId[*chamberId]=1;
115  }
116  }
117 
118  // Get the digis from the event
120  e.getByToken(dtDigiToken_, dtdigis);
121 
122  // LOOP OVER ALL THE DIGIS OF THE EVENT
124  for (dtLayerId_It=dtdigis->begin(); dtLayerId_It!=dtdigis->end(); ++dtLayerId_It){
125  for (DTDigiCollection::const_iterator digiIt = ((*dtLayerId_It).second).first;
126  digiIt!=((*dtLayerId_It).second).second; ++digiIt){
127 
128  //Check the TDC trigger width
129  int tdcTime = (*digiIt).countsTDC();
130  double upperLimit = tTrigStMap[(*dtLayerId_It).first.superlayerId().chamberId()]-safeMargin;
131  if(doTimeBoxHistos)
132  tbHistos[(*dtLayerId_It).first.superlayerId()]->Fill(tdcTime);
133  if(tdcTime>upperLimit)
134  continue;
135 
136  //Check the chamber has no 4D segments (optional)
137  if(doSegmentVeto &&
138  segmentsChId.find((*dtLayerId_It).first.superlayerId().chamberId())!=segmentsChId.end())
139  continue;
140 
141  // fill the occupancy histo
142  // FIXME: needs to be optimized: no need to rescale the histo for each digi
143  TH2F* noise_root = noiseHistos[(*dtLayerId_It).first.superlayerId().chamberId()]->getTH2F();
144  double normalization=0;
145  if(mapEvt.find((*dtLayerId_It).first.superlayerId().chamberId())!=mapEvt.end()) {
146  LogVerbatim("DTNoiseTask") << " Last fill: # of events: "
147  << mapEvt[(*dtLayerId_It).first.superlayerId().chamberId()]
148  << endl;
149  normalization = 1e-9*upperLimit*mapEvt[(*dtLayerId_It).first.superlayerId().chamberId()];
150  // revert back to # of entries
151  noise_root->Scale(normalization);
152  }
153  int yBin=(*dtLayerId_It).first.layer()+(4*((*dtLayerId_It).first.superlayerId().superlayer()-1));
154  noise_root->Fill((*digiIt).wire(),yBin);
155  // normalize the occupancy histo
156  mapEvt[(*dtLayerId_It).first.superlayerId().chamberId()] = evtNumber;
157  LogVerbatim("DTNoiseTask") << (*dtLayerId_It).first << " wire: " << (*digiIt).wire()
158  << " # counts: " << noise_root->GetBinContent((*digiIt).wire(),yBin)
159  << " Time interval: " << upperLimit
160  << " # of events: " << evtNumber << endl;;
161  normalization = double( 1e-9*upperLimit*mapEvt[(*dtLayerId_It).first.superlayerId().chamberId()]);
162  // update the rate
163  noise_root->Scale(1./normalization);
164  LogVerbatim("DTNoiseTask") << " noise rate: "
165  << noise_root->GetBinContent((*digiIt).wire(),yBin) << endl;
166  }
167  }
168 }
169 
170 
171 
174 
175 
177 
178  // set the folder
179  stringstream wheel; wheel << chId.wheel();
180  stringstream station; station << chId.station();
181  stringstream sector; sector << chId.sector();
182  dbe->setCurrentFolder("DT/05-Noise/Wheel" + wheel.str() +
183 // "/Station" + station.str() +
184  "/Sector" + sector.str());
185 
186  // Build the histo name
187  string histoName = string("NoiseRate")
188  + "_W" + wheel.str()
189  + "_St" + station.str()
190  + "_Sec" + sector.str() ;
191 
192  LogVerbatim("DTNoiseTask") << "[DTNoiseTask]: booking chamber histo:"<<endl;
193  LogVerbatim("DTNoiseTask") << " folder "<< "DT/05-Noise/Wheel" + wheel.str() +
194 // "/Station" + station.str() +
195  "/Sector" + sector.str() + "/"<<endl;
196  LogVerbatim("DTNoiseTask") << " histoName "<<histoName<<endl;
197 
198  // Get the chamber from the geometry
199  int nWires_max = 0;
200  const DTChamber* dtchamber = dtGeom->chamber(chId);
201  const vector<const DTSuperLayer*> superlayers = dtchamber->superLayers();
202 
203  // Loop over layers and find the max # of wires
204  for(vector<const DTSuperLayer*>::const_iterator sl = superlayers.begin();
205  sl != superlayers.end(); ++sl) { // loop over SLs
206  vector<const DTLayer*> layers = (*sl)->layers();
207  for(vector<const DTLayer*>::const_iterator lay = layers.begin();
208  lay != layers.end(); ++lay) { // loop over layers
209  int nWires = (*lay)->specificTopology().channels();
210  if(nWires > nWires_max) nWires_max = nWires;
211  }
212  }
213 
214  noiseHistos[chId] = dbe->book2D(histoName,"Noise rate (Hz) per channel", nWires_max,1, nWires_max+1,12,1,13);
215  noiseHistos[chId]->setAxisTitle("wire number",1);
216  noiseHistos[chId]->setBinLabel(1,"SL1-L1",2);
217  noiseHistos[chId]->setBinLabel(2,"SL1-L2",2);
218  noiseHistos[chId]->setBinLabel(3,"SL1-L3",2);
219  noiseHistos[chId]->setBinLabel(4,"SL1-L4",2);
220  noiseHistos[chId]->setBinLabel(5,"SL2-L1",2);
221  noiseHistos[chId]->setBinLabel(6,"SL2-L2",2);
222  noiseHistos[chId]->setBinLabel(7,"SL2-L3",2);
223  noiseHistos[chId]->setBinLabel(8,"SL2-L4",2);
224  noiseHistos[chId]->setBinLabel(9,"SL3-L1",2);
225  noiseHistos[chId]->setBinLabel(10,"SL3-L2",2);
226  noiseHistos[chId]->setBinLabel(11,"SL3-L3",2);
227  noiseHistos[chId]->setBinLabel(12,"SL3-L4",2);
228 
229 }
230 
231 
233 
234  // set the folder
235  stringstream wheel; wheel << slId.chamberId().wheel();
236  stringstream station; station << slId.chamberId().station();
237  stringstream sector; sector << slId.chamberId().sector();
238  stringstream superlayer; superlayer << slId.superlayer();
239  dbe->setCurrentFolder("DT/05-Noise/Wheel" + wheel.str() +
240  "/Station" + station.str() +
241  "/Sector" + sector.str());
242 
243  // Build the histo name
244  string histoName = string("TimeBox")
245  + "_W" + wheel.str()
246  + "_St" + station.str()
247  + "_Sec" + sector.str()
248  + "_SL" + superlayer.str();
249 
250  LogVerbatim("DTNoiseTask") <<"[DTNoiseTask]: booking SL histo:"<<endl;
251  LogVerbatim("DTNoiseTask") <<" folder "<< "DT/05-Noise/Wheel" + wheel.str() +
252  "/Station" + station.str() +
253  "/Sector" + sector.str() + "/" << endl;
254  LogVerbatim("DTNoiseTask") <<" histoName "<<histoName<<endl;
255 
256  tbHistos[slId] = dbe->book1D(histoName,"Time Box (TDC counts)", 1000, 0, 6000);
257 
258 }
259 
260 
262 
263  LogVerbatim("DTNoiseTask") <<"[DTNoiseTask]: Begin of run"<<endl;
264 
265  // tTrig Map
266  edm::ESHandle<DTTtrig> tTrigMap;
267  setup.get<DTTtrigRcd>().get(tTrigMap);
268 
269  // get the geometry
270  setup.get<MuonGeometryRecord>().get(dtGeom);
271 
272  dbe->setCurrentFolder("DT/EventInfo/Counters");
273  nEventMonitor = dbe->bookFloat("nProcessedEventsNoise");
274 
275  // Loop over all the chambers
276  vector<const DTChamber*>::const_iterator ch_it = dtGeom->chambers().begin();
277  vector<const 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 }
330 
331 // Local Variables:
332 // show-trailing-whitespace: t
333 // truncate-lines: t
334 // End:
T getParameter(std::string const &) const
std::map< DTChamberId, int > mapEvt
Definition: DTNoiseTask.h:87
T getUntrackedParameter(std::string const &, T const &) const
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:954
virtual ~DTNoiseTask()
Destructor.
Definition: DTNoiseTask.cc:69
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
tuple yBin
Definition: cuy.py:891
DTChamberId chamberId() const
Return the corresponding ChamberId.
void beginJob()
BeginJob.
Definition: DTNoiseTask.cc:74
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &setup)
Definition: DTNoiseTask.cc:302
MonitorElement * nEventMonitor
Definition: DTNoiseTask.h:92
MonitorElement * bookFloat(const char *name)
Book float.
Definition: DQMStore.cc:891
bool doSegmentVeto
Definition: DTNoiseTask.h:75
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context)
To reset the MEs.
Definition: DTNoiseTask.cc:83
void Fill(long long x)
U second(std::pair< T, U > const &p)
edm::ESHandle< DTGeometry > dtGeom
Definition: DTNoiseTask.h:78
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
Definition: DTNoiseTask.cc:93
const std::vector< const DTSuperLayer * > & superLayers() const
Return the superlayers in the chamber.
Definition: DTChamber.cc:60
edm::EDGetTokenT< DTRecSegment4DCollection > recHits4DToken_
Definition: DTNoiseTask.h:73
void beginRun(const edm::Run &, const edm::EventSetup &)
Definition: DTNoiseTask.cc:261
edm::EDGetTokenT< DTDigiCollection > dtDigiToken_
Definition: DTNoiseTask.h:67
void endJob()
Endjob.
Definition: DTNoiseTask.cc:173
double safeMargin
Definition: DTNoiseTask.h:95
std::map< DTSuperLayerId, MonitorElement * > tbHistos
Definition: DTNoiseTask.h:90
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:81
std::vector< DTDigi >::const_iterator const_iterator
int sector() const
Definition: DTChamberId.h:61
DTNoiseTask(const edm::ParameterSet &ps)
Constructor.
Definition: DTNoiseTask.cc:41
bool doTimeBoxHistos
Definition: DTNoiseTask.h:71
std::map< DTChamberId, MonitorElement * > noiseHistos
Definition: DTNoiseTask.h:84
DQMStore * dbe
Definition: DTNoiseTask.h:77
int station() const
Return the station number.
Definition: DTChamberId.h:51
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:1082
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
void bookHistos(DTChamberId chId)
Definition: DTNoiseTask.cc:176
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:667
Definition: Run.h:41