CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTSegmentAnalysisTask.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author G. Cerminara - INFN Torino
5  * revised by G. Mila - INFN Torino
6  */
7 
9 
10 // Framework
17 
21 
22 //Geometry
27 
30 
32 
33 #include <iterator>
34 #include <TMath.h>
35 
36 using namespace edm;
37 using namespace std;
38 
39 DTSegmentAnalysisTask::DTSegmentAnalysisTask(const edm::ParameterSet& pset) : nevents(0) , nEventsInLS(0), hNevtPerLS(0) {
40 
41  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << "[DTSegmentAnalysisTask] Constructor called!";
42 
43  // switch for detailed analysis
44  detailedAnalysis = pset.getUntrackedParameter<bool>("detailedAnalysis",false);
45  // the name of the 4D rec hits collection
46  recHits4DToken_ = consumes<DTRecSegment4DCollection>(
47  edm::InputTag(pset.getParameter<string>("recHits4DLabel")));
48  // Get the map of noisy channels
49  checkNoisyChannels = pset.getUntrackedParameter<bool>("checkNoisyChannels",false);
50  // # of bins in the time histos
51  nTimeBins = pset.getUntrackedParameter<int>("nTimeBins",100);
52  // # of LS per bin in the time histos
53  nLSTimeBin = pset.getUntrackedParameter<int>("nLSTimeBin",2);
54  // switch on/off sliding bins in time histos
55  slideTimeBins = pset.getUntrackedParameter<bool>("slideTimeBins",true);
56  phiSegmCut = pset.getUntrackedParameter<double>("phiSegmCut",30.);
57  nhitsCut = pset.getUntrackedParameter<int>("nhitsCut",12);
58 
59  // top folder for the histograms in DQMStore
60  topHistoFolder = pset.getUntrackedParameter<string>("topHistoFolder","DT/02-Segments");
61  // hlt DQM mode
62  hltDQMMode = pset.getUntrackedParameter<bool>("hltDQMMode",false);
63 
64 }
65 
66 
68  //FR moved fron endjob
69  delete hNevtPerLS;
70  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << "[DTSegmentAnalysisTask] Destructor called!";
71 }
72 
73 
75 
76  // Get the DT Geometry
77  context.get<MuonGeometryRecord>().get(dtGeom);
78 
79 }
80 
81 void DTSegmentAnalysisTask::bookHistograms(DQMStore::IBooker & ibooker, edm::Run const & iRun, edm::EventSetup const & context) {
82 
83  if (!hltDQMMode) {
84  ibooker.setCurrentFolder("DT/EventInfo/Counters");
85  nEventMonitor = ibooker.bookFloat("nProcessedEventsSegment");
86  }
87 
88  // loop over all the DT chambers & book the histos
89  const vector<const DTChamber*>& chambers = dtGeom->chambers();
90  vector<const DTChamber*>::const_iterator ch_it = chambers.begin();
91  vector<const DTChamber*>::const_iterator ch_end = chambers.end();
92  for (; ch_it != ch_end; ++ch_it) {
93  bookHistos(ibooker,(*ch_it)->id());
94  }
95 
96  // book sector time-evolution histos
97  int modeTimeHisto = 0;
98  if(!slideTimeBins) modeTimeHisto = 1;
99  for(int wheel = -2; wheel != 3; ++wheel) { // loop over wheels
100  for(int sector = 1; sector <= 12; ++sector) { // loop over sectors
101 
102  stringstream wheelstr; wheelstr << wheel;
103  stringstream sectorstr; sectorstr << sector;
104  string sectorHistoName = "NSegmPerEvent_W" + wheelstr.str()
105  + "_Sec" + sectorstr.str();
106  string sectorHistoTitle = "# segm. W" + wheelstr.str() + " Sect." + sectorstr.str();
107 
108  ibooker.setCurrentFolder(topHistoFolder + "/Wheel" + wheelstr.str() +
109  "/Sector" + sectorstr.str());
110 
111  histoTimeEvol[wheel][sector] = new DTTimeEvolutionHisto(ibooker,sectorHistoName,sectorHistoTitle,
112  nTimeBins,nLSTimeBin,slideTimeBins,modeTimeHisto);
113 
114  }
115  }
116 
118  else ibooker.setCurrentFolder("DT/EventInfo/");
119 
120  hNevtPerLS = new DTTimeEvolutionHisto(ibooker,"NevtPerLS","# evt.",nTimeBins,nLSTimeBin,slideTimeBins,2);
121 
122 }
123 
125 
126  nevents++;
128 
129  nEventsInLS++;
130  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << "[DTSegmentAnalysisTask] Analyze #Run: " << event.id().run()
131  << " #Event: " << event.id().event();
132  if(!(event.id().event()%1000))
133  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << "[DTSegmentAnalysisTask] Analyze #Run: " << event.id().run()
134  << " #Event: " << event.id().event();
135 
137  if(checkNoisyChannels) {
138  setup.get<DTStatusFlagRcd>().get(statusMap);
139  }
140 
141 
142  // -- 4D segment analysis -----------------------------------------------------
143 
144  // Get the 4D segment collection from the event
146  event.getByToken(recHits4DToken_, all4DSegments);
147 
148  if(!all4DSegments.isValid()) return;
149 
150  // Loop over all chambers containing a segment
151  DTRecSegment4DCollection::id_iterator chamberId;
152  for (chamberId = all4DSegments->id_begin();
153  chamberId != all4DSegments->id_end();
154  ++chamberId){
155  // Get the range for the corresponding ChamerId
156  DTRecSegment4DCollection::range range = all4DSegments->get(*chamberId);
157 
158  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << " Chamber: " << *chamberId << " has " << distance(range.first, range.second)
159  << " 4D segments";
160 
161  // Loop over the rechits of this ChamerId
162  for (DTRecSegment4DCollection::const_iterator segment4D = range.first;
163  segment4D!=range.second;
164  ++segment4D){
165 
166  //FOR NOISY CHANNELS////////////////////////////////
167  bool segmNoisy = false;
168  if(checkNoisyChannels) {
169 
170  if((*segment4D).hasPhi()){
171  const DTChamberRecSegment2D* phiSeg = (*segment4D).phiSegment();
172  vector<DTRecHit1D> phiHits = phiSeg->specificRecHits();
173  map<DTSuperLayerId,vector<DTRecHit1D> > hitsBySLMap;
174  for(vector<DTRecHit1D>::const_iterator hit = phiHits.begin();
175  hit != phiHits.end(); ++hit) {
176  DTWireId wireId = (*hit).wireId();
177 
178  // Check for noisy channels to skip them
179  bool isNoisy = false;
180  bool isFEMasked = false;
181  bool isTDCMasked = false;
182  bool isTrigMask = false;
183  bool isDead = false;
184  bool isNohv = false;
185  statusMap->cellStatus(wireId, isNoisy, isFEMasked, isTDCMasked, isTrigMask, isDead, isNohv);
186  if(isNoisy) {
187  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << "Wire: " << wireId << " is noisy, skipping!";
188  segmNoisy = true;
189  }
190  }
191  }
192 
193  if((*segment4D).hasZed()) {
194  const DTSLRecSegment2D* zSeg = (*segment4D).zSegment(); // zSeg lives in the SL RF
195  // Check for noisy channels to skip them
196  vector<DTRecHit1D> zHits = zSeg->specificRecHits();
197  for(vector<DTRecHit1D>::const_iterator hit = zHits.begin();
198  hit != zHits.end(); ++hit) {
199  DTWireId wireId = (*hit).wireId();
200  bool isNoisy = false;
201  bool isFEMasked = false;
202  bool isTDCMasked = false;
203  bool isTrigMask = false;
204  bool isDead = false;
205  bool isNohv = false;
206  statusMap->cellStatus(wireId, isNoisy, isFEMasked, isTDCMasked, isTrigMask, isDead, isNohv);
207  if(isNoisy) {
208  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << "Wire: " << wireId << " is noisy, skipping!";
209  segmNoisy = true;
210  }
211  }
212  }
213 
214  } // end of switch on noisy channels
215  if (segmNoisy) {
216  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask")<<"skipping the segment: it contains noisy cells";
217  continue;
218  }
219  //END FOR NOISY CHANNELS////////////////////////////////
220 
221  int nHits=0;
222  if((*segment4D).hasPhi())
223  nHits = (((*segment4D).phiSegment())->specificRecHits()).size();
224  if((*segment4D).hasZed())
225  nHits = nHits + ((((*segment4D).zSegment())->specificRecHits()).size());
226 
227  double anglePhiSegm(0.);
228  if( (*segment4D).hasPhi() ) {
229  double xdir = (*segment4D).phiSegment()->localDirection().x();
230  double zdir = (*segment4D).phiSegment()->localDirection().z();
231 
232  anglePhiSegm = atan(xdir/zdir)*180./TMath::Pi();
233  }
234  if( fabs(anglePhiSegm) > phiSegmCut ) continue;
235  // If the segment is in Wh+-2/SecX/MB1, get the DT chambers just above and check if there is a segment
236  // to validate the segment present in MB1
237  if( fabs((*chamberId).wheel()) == 2 && (*chamberId).station() == 1 ) {
238 
239  bool segmOk=false;
240  int mb(2);
241  while( mb < 4 ) {
242  DTChamberId checkMB((*chamberId).wheel(),mb,(*chamberId).sector());
243  DTRecSegment4DCollection::range ckrange = all4DSegments->get(checkMB);
244 
245  for (DTRecSegment4DCollection::const_iterator cksegment4D = ckrange.first;
246  cksegment4D!=ckrange.second;
247  ++cksegment4D){
248 
249  int nHits=0;
250  if((*cksegment4D).hasPhi())
251  nHits = (((*cksegment4D).phiSegment())->specificRecHits()).size();
252  if((*cksegment4D).hasZed())
253  nHits = nHits + ((((*cksegment4D).zSegment())->specificRecHits()).size());
254 
255  if( nHits >= nhitsCut ) segmOk=true;
256 
257  }
258  mb++;
259  }
260 
261  if( !segmOk ) continue;
262 
263  }
264  fillHistos(*chamberId,
265  nHits,
266  (*segment4D).chi2()/(*segment4D).degreesOfFreedom());
267  }
268  }
269 
270  // -----------------------------------------------------------------------------
271 }
272 
273 
274 // Book a set of histograms for a give chamber
276 
277  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << " Booking histos for chamber: " << chamberId;
278 
279 
280  // Compose the chamber name
281  stringstream wheel; wheel << chamberId.wheel();
282  stringstream station; station << chamberId.station();
283  stringstream sector; sector << chamberId.sector();
284 
285  string chamberHistoName =
286  "_W" + wheel.str() +
287  "_St" + station.str() +
288  "_Sec" + sector.str();
289 
290 
291  for(int wh=-2; wh<=2; wh++){
292  stringstream wheel; wheel << wh;
293  ibooker.setCurrentFolder(topHistoFolder + "/Wheel" + wheel.str());
294  string histoName = "numberOfSegments_W" + wheel.str();
295 
296  summaryHistos[wh] = ibooker.book2D(histoName.c_str(),histoName.c_str(),12,1,13,4,1,5);
297  summaryHistos[wh]->setAxisTitle("Sector",1);
298  summaryHistos[wh]->setBinLabel(1,"1",1);
299  summaryHistos[wh]->setBinLabel(2,"2",1);
300  summaryHistos[wh]->setBinLabel(3,"3",1);
301  summaryHistos[wh]->setBinLabel(4,"4",1);
302  summaryHistos[wh]->setBinLabel(5,"5",1);
303  summaryHistos[wh]->setBinLabel(6,"6",1);
304  summaryHistos[wh]->setBinLabel(7,"7",1);
305  summaryHistos[wh]->setBinLabel(8,"8",1);
306  summaryHistos[wh]->setBinLabel(9,"9",1);
307  summaryHistos[wh]->setBinLabel(10,"10",1);
308  summaryHistos[wh]->setBinLabel(11,"11",1);
309  summaryHistos[wh]->setBinLabel(12,"12",1);
310  summaryHistos[wh]->setBinLabel(1,"MB1",2);
311  summaryHistos[wh]->setBinLabel(2,"MB2",2);
312  summaryHistos[wh]->setBinLabel(3,"MB3",2);
313  summaryHistos[wh]->setBinLabel(4,"MB4",2);
314  }
315 
316 
317  ibooker.setCurrentFolder(topHistoFolder + "/Wheel" + wheel.str() +
318  "/Sector" + sector.str() +
319  "/Station" + station.str());
320 
321  // Create the monitor elements
322  vector<MonitorElement *> histos;
323  histos.push_back(ibooker.book1D("h4DSegmNHits"+chamberHistoName,
324  "# of hits per segment",
325  16, 0.5, 16.5));
326  if(detailedAnalysis){
327  histos.push_back(ibooker.book1D("h4DChi2"+chamberHistoName,
328  "4D Segment reduced Chi2",
329  20, 0, 20));
330  }
331  histosPerCh[chamberId] = histos;
332 }
333 
334 
335 // Fill a set of histograms for a give chamber
337  int nHits,
338  float chi2) {
339  int sector = chamberId.sector();
340  if(chamberId.sector()==13) {
341  sector = 4;
342  } else if(chamberId.sector()==14) {
343  sector = 10;
344  }
345 
346  summaryHistos[chamberId.wheel()]->Fill(sector,chamberId.station());
347  histoTimeEvol[chamberId.wheel()][sector]->accumulateValueTimeSlot(1);
348 
349  vector<MonitorElement *> histos = histosPerCh[chamberId];
350  histos[0]->Fill(nHits);
351  if(detailedAnalysis){
352  histos[1]->Fill(chi2);
353  }
354 
355 }
356 
357 
359 
361  // book sector time-evolution histos
362  for(int wheel = -2; wheel != 3; ++wheel) {
363  for(int sector = 1; sector <= 12; ++sector) {
364  histoTimeEvol[wheel][sector]->updateTimeSlot(lumiSeg.luminosityBlock(), nEventsInLS);
365  }
366  }
367 }
368 
369 
371  nEventsInLS = 0;
372 }
373 
374 
375 
376 // Local Variables:
377 // show-trailing-whitespace: t
378 // truncate-lines: t
379 // End:
const double Pi
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
void fillHistos(DTChamberId chamberId, int nHits, float chi2)
T getUntrackedParameter(std::string const &, T const &) const
void analyze(const edm::Event &event, const edm::EventSetup &setup)
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
DTTimeEvolutionHisto * hNevtPerLS
std::map< int, MonitorElement * > summaryHistos
std::map< DTChamberId, std::vector< MonitorElement * > > histosPerCh
void Fill(long long x)
LuminosityBlockNumber_t luminosityBlock() const
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
void bookHistos(DQMStore::IBooker &ibooker, DTChamberId chamberId)
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
edm::ESHandle< DTGeometry > dtGeom
void dqmBeginRun(const edm::Run &, const edm::EventSetup &)
BeginRun.
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
bool isValid() const
Definition: HandleBase.h:75
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &eSetup)
Summary.
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
const T & get() const
Definition: EventSetup.h:55
void updateTimeSlot(int ls, int nEventsInLS)
virtual ~DTSegmentAnalysisTask()
Destructor.
MonitorElement * nEventMonitor
std::map< int, std::map< int, DTTimeEvolutionHisto * > > histoTimeEvol
edm::EventID id() const
Definition: EventBase.h:60
int sector() const
Definition: DTChamberId.h:61
MonitorElement * bookFloat(Args &&...args)
Definition: DQMStore.h:109
int station() const
Return the station number.
Definition: DTChamberId.h:51
static char chambers[264][20]
Definition: ReadPGInfo.cc:243
edm::EDGetTokenT< DTRecSegment4DCollection > recHits4DToken_
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &eSetup)
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
tuple size
Write out results.
DTSegmentAnalysisTask(const edm::ParameterSet &pset)
Constructor.
Definition: Run.h:41