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