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