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  for(int wh=-2; wh<=2; wh++){
89  stringstream wheel; wheel << wh;
90  ibooker.setCurrentFolder(topHistoFolder + "/Wheel" + wheel.str());
91  string histoName = "numberOfSegments_W" + wheel.str();
92 
93  summaryHistos[wh] = ibooker.book2D(histoName.c_str(),histoName.c_str(),12,1,13,4,1,5);
94  summaryHistos[wh]->setAxisTitle("Sector",1);
95  summaryHistos[wh]->setBinLabel(1,"1",1);
96  summaryHistos[wh]->setBinLabel(2,"2",1);
97  summaryHistos[wh]->setBinLabel(3,"3",1);
98  summaryHistos[wh]->setBinLabel(4,"4",1);
99  summaryHistos[wh]->setBinLabel(5,"5",1);
100  summaryHistos[wh]->setBinLabel(6,"6",1);
101  summaryHistos[wh]->setBinLabel(7,"7",1);
102  summaryHistos[wh]->setBinLabel(8,"8",1);
103  summaryHistos[wh]->setBinLabel(9,"9",1);
104  summaryHistos[wh]->setBinLabel(10,"10",1);
105  summaryHistos[wh]->setBinLabel(11,"11",1);
106  summaryHistos[wh]->setBinLabel(12,"12",1);
107  summaryHistos[wh]->setBinLabel(1,"MB1",2);
108  summaryHistos[wh]->setBinLabel(2,"MB2",2);
109  summaryHistos[wh]->setBinLabel(3,"MB3",2);
110  summaryHistos[wh]->setBinLabel(4,"MB4",2);
111  }
112 
113  // loop over all the DT chambers & book the histos
114  const vector<const DTChamber*>& chambers = dtGeom->chambers();
115  vector<const DTChamber*>::const_iterator ch_it = chambers.begin();
116  vector<const DTChamber*>::const_iterator ch_end = chambers.end();
117  for (; ch_it != ch_end; ++ch_it) {
118  bookHistos(ibooker,(*ch_it)->id());
119  }
120 
121  // book sector time-evolution histos
122  int modeTimeHisto = 0;
123  if(!slideTimeBins) modeTimeHisto = 1;
124  for(int wheel = -2; wheel != 3; ++wheel) { // loop over wheels
125  for(int sector = 1; sector <= 12; ++sector) { // loop over sectors
126 
127  stringstream wheelstr; wheelstr << wheel;
128  stringstream sectorstr; sectorstr << sector;
129  string sectorHistoName = "NSegmPerEvent_W" + wheelstr.str()
130  + "_Sec" + sectorstr.str();
131  string sectorHistoTitle = "# segm. W" + wheelstr.str() + " Sect." + sectorstr.str();
132 
133  ibooker.setCurrentFolder(topHistoFolder + "/Wheel" + wheelstr.str() +
134  "/Sector" + sectorstr.str());
135 
136  histoTimeEvol[wheel][sector] = new DTTimeEvolutionHisto(ibooker,sectorHistoName,sectorHistoTitle,
137  nTimeBins,nLSTimeBin,slideTimeBins,modeTimeHisto);
138 
139  }
140  }
141 
143  else ibooker.setCurrentFolder("DT/EventInfo/");
144 
145  hNevtPerLS = new DTTimeEvolutionHisto(ibooker,"NevtPerLS","# evt.",nTimeBins,nLSTimeBin,slideTimeBins,2);
146 
147 }
148 
150 
151  nevents++;
153 
154  nEventsInLS++;
155  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << "[DTSegmentAnalysisTask] Analyze #Run: " << event.id().run()
156  << " #Event: " << event.id().event();
157  if(!(event.id().event()%1000))
158  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << "[DTSegmentAnalysisTask] Analyze #Run: " << event.id().run()
159  << " #Event: " << event.id().event();
160 
162  if(checkNoisyChannels) {
163  setup.get<DTStatusFlagRcd>().get(statusMap);
164  }
165 
166 
167  // -- 4D segment analysis -----------------------------------------------------
168 
169  // Get the 4D segment collection from the event
171  event.getByToken(recHits4DToken_, all4DSegments);
172 
173  if(!all4DSegments.isValid()) return;
174 
175  // Loop over all chambers containing a segment
176  DTRecSegment4DCollection::id_iterator chamberId;
177  for (chamberId = all4DSegments->id_begin();
178  chamberId != all4DSegments->id_end();
179  ++chamberId){
180  // Get the range for the corresponding ChamerId
181  DTRecSegment4DCollection::range range = all4DSegments->get(*chamberId);
182 
183  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << " Chamber: " << *chamberId << " has " << distance(range.first, range.second)
184  << " 4D segments";
185 
186  // Loop over the rechits of this ChamerId
187  for (DTRecSegment4DCollection::const_iterator segment4D = range.first;
188  segment4D!=range.second;
189  ++segment4D){
190 
191  //FOR NOISY CHANNELS////////////////////////////////
192  bool segmNoisy = false;
193  if(checkNoisyChannels) {
194 
195  if((*segment4D).hasPhi()){
196  const DTChamberRecSegment2D* phiSeg = (*segment4D).phiSegment();
197  vector<DTRecHit1D> phiHits = phiSeg->specificRecHits();
198  map<DTSuperLayerId,vector<DTRecHit1D> > hitsBySLMap;
199  for(vector<DTRecHit1D>::const_iterator hit = phiHits.begin();
200  hit != phiHits.end(); ++hit) {
201  DTWireId wireId = (*hit).wireId();
202 
203  // Check for noisy channels to skip them
204  bool isNoisy = false;
205  bool isFEMasked = false;
206  bool isTDCMasked = false;
207  bool isTrigMask = false;
208  bool isDead = false;
209  bool isNohv = false;
210  statusMap->cellStatus(wireId, isNoisy, isFEMasked, isTDCMasked, isTrigMask, isDead, isNohv);
211  if(isNoisy) {
212  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << "Wire: " << wireId << " is noisy, skipping!";
213  segmNoisy = true;
214  }
215  }
216  }
217 
218  if((*segment4D).hasZed()) {
219  const DTSLRecSegment2D* zSeg = (*segment4D).zSegment(); // zSeg lives in the SL RF
220  // Check for noisy channels to skip them
221  vector<DTRecHit1D> zHits = zSeg->specificRecHits();
222  for(vector<DTRecHit1D>::const_iterator hit = zHits.begin();
223  hit != zHits.end(); ++hit) {
224  DTWireId wireId = (*hit).wireId();
225  bool isNoisy = false;
226  bool isFEMasked = false;
227  bool isTDCMasked = false;
228  bool isTrigMask = false;
229  bool isDead = false;
230  bool isNohv = false;
231  statusMap->cellStatus(wireId, isNoisy, isFEMasked, isTDCMasked, isTrigMask, isDead, isNohv);
232  if(isNoisy) {
233  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << "Wire: " << wireId << " is noisy, skipping!";
234  segmNoisy = true;
235  }
236  }
237  }
238 
239  } // end of switch on noisy channels
240  if (segmNoisy) {
241  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask")<<"skipping the segment: it contains noisy cells";
242  continue;
243  }
244  //END FOR NOISY CHANNELS////////////////////////////////
245 
246  int nHits=0;
247  if((*segment4D).hasPhi())
248  nHits = (((*segment4D).phiSegment())->specificRecHits()).size();
249  if((*segment4D).hasZed())
250  nHits = nHits + ((((*segment4D).zSegment())->specificRecHits()).size());
251 
252  double anglePhiSegm(0.);
253  if( (*segment4D).hasPhi() ) {
254  double xdir = (*segment4D).phiSegment()->localDirection().x();
255  double zdir = (*segment4D).phiSegment()->localDirection().z();
256 
257  anglePhiSegm = atan(xdir/zdir)*180./TMath::Pi();
258  }
259  if( fabs(anglePhiSegm) > phiSegmCut ) continue;
260  // If the segment is in Wh+-2/SecX/MB1, get the DT chambers just above and check if there is a segment
261  // to validate the segment present in MB1
262  if( fabs((*chamberId).wheel()) == 2 && (*chamberId).station() == 1 ) {
263 
264  bool segmOk=false;
265  int mb(2);
266  while( mb < 4 ) {
267  DTChamberId checkMB((*chamberId).wheel(),mb,(*chamberId).sector());
268  DTRecSegment4DCollection::range ckrange = all4DSegments->get(checkMB);
269 
270  for (DTRecSegment4DCollection::const_iterator cksegment4D = ckrange.first;
271  cksegment4D!=ckrange.second;
272  ++cksegment4D){
273 
274  int nHits=0;
275  if((*cksegment4D).hasPhi())
276  nHits = (((*cksegment4D).phiSegment())->specificRecHits()).size();
277  if((*cksegment4D).hasZed())
278  nHits = nHits + ((((*cksegment4D).zSegment())->specificRecHits()).size());
279 
280  if( nHits >= nhitsCut ) segmOk=true;
281 
282  }
283  mb++;
284  }
285 
286  if( !segmOk ) continue;
287 
288  }
289  fillHistos(*chamberId,
290  nHits,
291  (*segment4D).chi2()/(*segment4D).degreesOfFreedom());
292  }
293  }
294 
295  // -----------------------------------------------------------------------------
296 }
297 
298 
299 // Book a set of histograms for a give chamber
301 
302  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << " Booking histos for chamber: " << chamberId;
303 
304 
305  // Compose the chamber name
306  stringstream wheel; wheel << chamberId.wheel();
307  stringstream station; station << chamberId.station();
308  stringstream sector; sector << chamberId.sector();
309 
310  string chamberHistoName =
311  "_W" + wheel.str() +
312  "_St" + station.str() +
313  "_Sec" + sector.str();
314 
315  ibooker.setCurrentFolder(topHistoFolder + "/Wheel" + wheel.str() +
316  "/Sector" + sector.str() +
317  "/Station" + station.str());
318 
319  // Create the monitor elements
320  vector<MonitorElement *> histos;
321  histos.push_back(ibooker.book1D("h4DSegmNHits"+chamberHistoName,
322  "# of hits per segment",
323  16, 0.5, 16.5));
324  if(detailedAnalysis){
325  histos.push_back(ibooker.book1D("h4DChi2"+chamberHistoName,
326  "4D Segment reduced Chi2",
327  20, 0, 20));
328  }
329  histosPerCh[chamberId] = histos;
330 }
331 
332 
333 // Fill a set of histograms for a give chamber
335  int nHits,
336  float chi2) {
337  int sector = chamberId.sector();
338  if(chamberId.sector()==13) {
339  sector = 4;
340  } else if(chamberId.sector()==14) {
341  sector = 10;
342  }
343 
344  summaryHistos[chamberId.wheel()]->Fill(sector,chamberId.station());
345  histoTimeEvol[chamberId.wheel()][sector]->accumulateValueTimeSlot(1);
346 
347  vector<MonitorElement *> histos = histosPerCh[chamberId];
348  histos[0]->Fill(nHits);
349  if(detailedAnalysis){
350  histos[1]->Fill(chi2);
351  }
352 
353 }
354 
355 
357 
359  // book sector time-evolution histos
360  for(int wheel = -2; wheel != 3; ++wheel) {
361  for(int sector = 1; sector <= 12; ++sector) {
362  histoTimeEvol[wheel][sector]->updateTimeSlot(lumiSeg.luminosityBlock(), nEventsInLS);
363  }
364  }
365 }
366 
367 
369  nEventsInLS = 0;
370 }
371 
372 
373 
374 // Local Variables:
375 // show-trailing-whitespace: t
376 // truncate-lines: t
377 // 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:273
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
const T & get() const
Definition: EventSetup.h:56
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:59
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:43