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: 2010/01/05 10:14:40 $
6  * $Revision: 1.27 $
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 
40 using namespace edm;
41 using namespace std;
42 
43 DTSegmentAnalysisTask::DTSegmentAnalysisTask(const edm::ParameterSet& pset) : nEventsInLS(0), hNevtPerLS(0) {
44 
45  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << "[DTSegmentAnalysisTask] Constructor called!";
46 
47  // switch for detailed analysis
48  detailedAnalysis = pset.getUntrackedParameter<bool>("detailedAnalysis","false");
49  // the name of the 4D rec hits collection
50  theRecHits4DLabel = pset.getParameter<string>("recHits4DLabel");
51  // Get the map of noisy channels
52  checkNoisyChannels = pset.getUntrackedParameter<bool>("checkNoisyChannels","false");
53  // # of bins in the time histos
54  nTimeBins = pset.getUntrackedParameter<int>("nTimeBins",100);
55  // # of LS per bin in the time histos
56  nLSTimeBin = pset.getUntrackedParameter<int>("nLSTimeBin",2);
57  // switch on/off sliding bins in time histos
58  slideTimeBins = pset.getUntrackedParameter<bool>("slideTimeBins",true);
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  // loop over all the DT chambers & book the histos
82  vector<DTChamber*> chambers = dtGeom->chambers();
83  vector<DTChamber*>::const_iterator ch_it = chambers.begin();
84  vector<DTChamber*>::const_iterator ch_end = chambers.end();
85  for (; ch_it != ch_end; ++ch_it) {
86  bookHistos((*ch_it)->id());
87  }
88 
89  // book sector time-evolution histos
90  int modeTimeHisto = 0;
91  if(!slideTimeBins) modeTimeHisto = 1;
92  for(int wheel = -2; wheel != 3; ++wheel) { // loop over wheels
93  for(int sector = 1; sector <= 12; ++sector) { // loop over sectors
94  stringstream wheelstr; wheelstr << wheel;
95  stringstream sectorstr; sectorstr << sector;
96  string sectorHistoName = "NSegmPerEvent_W" + wheelstr.str()
97  + "_Sec" + sectorstr.str();
98  string sectorHistoTitle = "# segm. W" + wheelstr.str() + " Sect." + sectorstr.str();
99 
100  theDbe->setCurrentFolder(topHistoFolder + "/Wheel" + wheelstr.str() +
101  "/Sector" + sectorstr.str());
102  histoTimeEvol[wheel][sector] = new DTTimeEvolutionHisto(&(*theDbe),sectorHistoName,sectorHistoTitle,
103  nTimeBins,nLSTimeBin,slideTimeBins,modeTimeHisto);
104  }
105  }
106 
108  else theDbe->setCurrentFolder("DT/EventInfo/");
109 
110  hNevtPerLS = new DTTimeEvolutionHisto(&(*theDbe),"NevtPerLS","# evt.",nTimeBins,nLSTimeBin,slideTimeBins,2);
111 
112 }
113 
114 
116 
117  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") <<"[DTSegmentAnalysisTask] endjob called!";
118 
119  delete hNevtPerLS;
120  //theDbe->save("testMonitoring.root");
121 
122 }
123 
124 
125 
127  nEventsInLS++;
128  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << "[DTSegmentAnalysisTask] Analyze #Run: " << event.id().run()
129  << " #Event: " << event.id().event();
130  if(!(event.id().event()%1000))
131  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << "[DTSegmentAnalysisTask] Analyze #Run: " << event.id().run()
132  << " #Event: " << event.id().event();
133 
135  if(checkNoisyChannels) {
136  setup.get<DTStatusFlagRcd>().get(statusMap);
137  }
138 
139 
140  // -- 4D segment analysis -----------------------------------------------------
141 
142  // Get the 4D segment collection from the event
144  event.getByLabel(theRecHits4DLabel, all4DSegments);
145 
146  if(!all4DSegments.isValid()) return;
147 
148  // Loop over all chambers containing a segment
150  for (chamberId = all4DSegments->id_begin();
151  chamberId != all4DSegments->id_end();
152  ++chamberId){
153  // Get the range for the corresponding ChamerId
154  DTRecSegment4DCollection::range range = all4DSegments->get(*chamberId);
155 
156  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << " Chamber: " << *chamberId << " has " << distance(range.first, range.second)
157  << " 4D segments";
158 
159  // Loop over the rechits of this ChamerId
160  for (DTRecSegment4DCollection::const_iterator segment4D = range.first;
161  segment4D!=range.second;
162  ++segment4D){
163 
164  //FOR NOISY CHANNELS////////////////////////////////
165  bool segmNoisy = false;
166  if(checkNoisyChannels) {
167 
168  if((*segment4D).hasPhi()){
169  const DTChamberRecSegment2D* phiSeg = (*segment4D).phiSegment();
170  vector<DTRecHit1D> phiHits = phiSeg->specificRecHits();
171  map<DTSuperLayerId,vector<DTRecHit1D> > hitsBySLMap;
172  for(vector<DTRecHit1D>::const_iterator hit = phiHits.begin();
173  hit != phiHits.end(); ++hit) {
174  DTWireId wireId = (*hit).wireId();
175 
176  // Check for noisy channels to skip them
177  bool isNoisy = false;
178  bool isFEMasked = false;
179  bool isTDCMasked = false;
180  bool isTrigMask = false;
181  bool isDead = false;
182  bool isNohv = false;
183  statusMap->cellStatus(wireId, isNoisy, isFEMasked, isTDCMasked, isTrigMask, isDead, isNohv);
184  if(isNoisy) {
185  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << "Wire: " << wireId << " is noisy, skipping!";
186  segmNoisy = true;
187  }
188  }
189  }
190 
191  if((*segment4D).hasZed()) {
192  const DTSLRecSegment2D* zSeg = (*segment4D).zSegment(); // zSeg lives in the SL RF
193  // Check for noisy channels to skip them
194  vector<DTRecHit1D> zHits = zSeg->specificRecHits();
195  for(vector<DTRecHit1D>::const_iterator hit = zHits.begin();
196  hit != zHits.end(); ++hit) {
197  DTWireId wireId = (*hit).wireId();
198  bool isNoisy = false;
199  bool isFEMasked = false;
200  bool isTDCMasked = false;
201  bool isTrigMask = false;
202  bool isDead = false;
203  bool isNohv = false;
204  statusMap->cellStatus(wireId, isNoisy, isFEMasked, isTDCMasked, isTrigMask, isDead, isNohv);
205  if(isNoisy) {
206  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << "Wire: " << wireId << " is noisy, skipping!";
207  segmNoisy = true;
208  }
209  }
210  }
211 
212  } // end of switch on noisy channels
213  if (segmNoisy) {
214  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask")<<"skipping the segment: it contains noisy cells";
215  continue;
216  }
217  //END FOR NOISY CHANNELS////////////////////////////////
218 
219  int nHits=0;
220  LocalPoint segment4DLocalPos = (*segment4D).localPosition();
221  LocalVector segment4DLocalDirection = (*segment4D).localDirection();
222  if((*segment4D).hasPhi())
223  nHits = (((*segment4D).phiSegment())->specificRecHits()).size();
224  if((*segment4D).hasZed())
225  nHits = nHits + ((((*segment4D).zSegment())->specificRecHits()).size());
226 
227  fillHistos(*chamberId,
228  nHits,
229  (*segment4D).chi2()/(*segment4D).degreesOfFreedom());
230  }
231  }
232 
233  // -----------------------------------------------------------------------------
234 }
235 
236 
237 // Book a set of histograms for a give chamber
239 
240  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << " Booking histos for chamber: " << chamberId;
241 
242 
243  // Compose the chamber name
244  stringstream wheel; wheel << chamberId.wheel();
245  stringstream station; station << chamberId.station();
246  stringstream sector; sector << chamberId.sector();
247 
248  string chamberHistoName =
249  "_W" + wheel.str() +
250  "_St" + station.str() +
251  "_Sec" + sector.str();
252 
253 
254  for(int wh=-2; wh<=2; wh++){
255  stringstream wheel; wheel << wh;
256  theDbe->setCurrentFolder(topHistoFolder + "/Wheel" + wheel.str());
257  string histoName = "numberOfSegments_W" + wheel.str();
258  summaryHistos[wh] = theDbe->book2D(histoName.c_str(),histoName.c_str(),12,1,13,4,1,5);
259  summaryHistos[wh]->setAxisTitle("Sector",1);
260  summaryHistos[wh]->setBinLabel(1,"1",1);
261  summaryHistos[wh]->setBinLabel(2,"2",1);
262  summaryHistos[wh]->setBinLabel(3,"3",1);
263  summaryHistos[wh]->setBinLabel(4,"4",1);
264  summaryHistos[wh]->setBinLabel(5,"5",1);
265  summaryHistos[wh]->setBinLabel(6,"6",1);
266  summaryHistos[wh]->setBinLabel(7,"7",1);
267  summaryHistos[wh]->setBinLabel(8,"8",1);
268  summaryHistos[wh]->setBinLabel(9,"9",1);
269  summaryHistos[wh]->setBinLabel(10,"10",1);
270  summaryHistos[wh]->setBinLabel(11,"11",1);
271  summaryHistos[wh]->setBinLabel(12,"12",1);
272  summaryHistos[wh]->setBinLabel(1,"MB1",2);
273  summaryHistos[wh]->setBinLabel(2,"MB2",2);
274  summaryHistos[wh]->setBinLabel(3,"MB3",2);
275  summaryHistos[wh]->setBinLabel(4,"MB4",2);
276  }
277 
278 
279  theDbe->setCurrentFolder(topHistoFolder + "/Wheel" + wheel.str() +
280  "/Sector" + sector.str() +
281  "/Station" + station.str());
282 
283  // Create the monitor elements
284  vector<MonitorElement *> histos;
285  histos.push_back(theDbe->book1D("h4DSegmNHits"+chamberHistoName,
286  "# of hits per segment",
287  16, 0.5, 16.5));
288  if(detailedAnalysis){
289  histos.push_back(theDbe->book1D("h4DChi2"+chamberHistoName,
290  "4D Segment reduced Chi2",
291  20, 0, 20));
292  }
293  histosPerCh[chamberId] = histos;
294 }
295 
296 
297 // Fill a set of histograms for a give chamber
299  int nHits,
300  float chi2) {
301  int sector = chamberId.sector();
302  if(chamberId.sector()==13) {
303  sector = 4;
304  } else if(chamberId.sector()==14) {
305  sector = 10;
306  }
307 
308  summaryHistos[chamberId.wheel()]->Fill(sector,chamberId.station());
309  histoTimeEvol[chamberId.wheel()][sector]->accumulateValueTimeSlot(1);
310 
311  vector<MonitorElement *> histos = histosPerCh[chamberId];
312  histos[0]->Fill(nHits);
313  if(detailedAnalysis){
314  histos[1]->Fill(chi2);
315  }
316 
317 }
318 
319 
321 
323  // book sector time-evolution histos
324  for(int wheel = -2; wheel != 3; ++wheel) {
325  for(int sector = 1; sector <= 12; ++sector) {
326  histoTimeEvol[wheel][sector]->updateTimeSlot(lumiSeg.luminosityBlock(), nEventsInLS);
327  }
328  }
329 }
330 
331 
333  nEventsInLS = 0;
334 }
335 
336 
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:53
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:514
DTTimeEvolutionHisto * hNevtPerLS
identifier iterator
Definition: RangeMap.h:139
static char chambers[TOTALCHAMBERS][20]
Definition: ReadPGInfo.cc:243
std::map< int, MonitorElement * > summaryHistos
std::map< DTChamberId, std::vector< MonitorElement * > > histosPerCh
LuminosityBlockNumber_t luminosityBlock() const
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:46
edm::ESHandle< DTGeometry > dtGeom
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.
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
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:642
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:232
Definition: Run.h:32
void bookHistos(DTChamberId chamberId)