CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTEfficiencyTask.cc
Go to the documentation of this file.
1 
2 
3 /*
4  * See header file for a description of this class.
5  *
6  * $Date: 2011/11/12 09:18:42 $
7  * $Revision: 1.17 $
8  * \author G. Mila - INFN Torino
9  */
10 
11 
12 #include "DTEfficiencyTask.h"
13 
14 
15 // Framework
21 
24 
25 //Geometry
28 
29 //RecHit
33 
36 
37 #include <iterator>
38 
39 using namespace edm;
40 using namespace std;
41 
42 
44 
45  debug = pset.getUntrackedParameter<bool>("debug",false);
46 
47  // Get the DQM needed services
48  theDbe = edm::Service<DQMStore>().operator->();
49  theDbe->setCurrentFolder("DT/DTEfficiencyTask");
50 
51  parameters = pset;
52 }
53 
54 
56 }
57 
58 
60  // the name of the 4D rec hits collection
61  theRecHits4DLabel = parameters.getParameter<string>("recHits4DLabel");
62  // the name of the rechits collection
63  theRecHitLabel = parameters.getParameter<string>("recHitLabel");
64 }
65 
66 
68 
69 
70  if(lumiSeg.id().luminosityBlock()%parameters.getUntrackedParameter<int>("ResetCycle", 3) == 0) {
71  for(map<DTLayerId, vector<MonitorElement*> > ::const_iterator histo = histosPerL.begin();
72  histo != histosPerL.end();
73  histo++) {
74  int size = (*histo).second.size();
75  for(int i=0; i<size; i++){
76  (*histo).second[i]->Reset();
77  }
78  }
79  }
80 
81 }
82 
83 
85  theDbe->rmdir("DT/DTEfficiencyTask");
86 }
87 
88 
90 
91 
92  if(debug)
93  cout << "[DTEfficiencyTask] Analyze #Run: " << event.id().run()
94  << " #Event: " << event.id().event() << endl;
95 
96 
97  // Get the 4D segment collection from the event
99  event.getByLabel(theRecHits4DLabel, all4DSegments);
100 
101  // Get the rechit collection from the event
102  Handle<DTRecHitCollection> dtRecHits;
103  event.getByLabel(theRecHitLabel, dtRecHits);
104 
105  // Get the DT Geometry
106  ESHandle<DTGeometry> dtGeom;
107  setup.get<MuonGeometryRecord>().get(dtGeom);
108 
109  // Loop over all chambers containing a segment
111  for (chamberId = all4DSegments->id_begin();
112  chamberId != all4DSegments->id_end();
113  ++chamberId) {
114 
115  // Get the chamber
116  const DTChamber* chamber = dtGeom->chamber(*chamberId);
117 
118  // Get all 1D RecHits to be used for searches of hits not associated to segments and map them by wire
119  const vector<const DTSuperLayer*> SLayers = chamber->superLayers();
120  map<DTWireId, int> wireAnd1DRecHits;
121  for(vector<const DTSuperLayer*>::const_iterator superlayer = SLayers.begin();
122  superlayer != SLayers.end();
123  superlayer++) {
124  DTRecHitCollection::range range = dtRecHits->get(DTRangeMapAccessor::layersBySuperLayer((*superlayer)->id()));
125  // Loop over the rechits of this ChamberId
126  for (DTRecHitCollection::const_iterator rechit = range.first;
127  rechit!=range.second;
128  ++rechit){
129  wireAnd1DRecHits[(*rechit).wireId()] = (*rechit).wireId().wire();
130  }
131  }
132 
133 
134  // Get the 4D segment range for the corresponding ChamerId
135  DTRecSegment4DCollection::range range = all4DSegments->get(*chamberId);
136  int nsegm = distance(range.first, range.second);
137  if(debug)
138  cout << " Chamber: " << *chamberId << " has " << nsegm
139  << " 4D segments" << endl;
140 
141 
142  // Loop over the rechits of this ChamerId
143  for (DTRecSegment4DCollection::const_iterator segment4D = range.first;
144  segment4D!=range.second;
145  ++segment4D) {
146  if(debug)
147  cout << " == RecSegment dimension: " << (*segment4D).dimension() << endl;
148 
149  // If Statio != 4 skip RecHits with dimension != 4
150  // For the Station 4 consider 2D RecHits
151  if((*chamberId).station() != 4 && (*segment4D).dimension() != 4) {
152  if(debug)
153  cout << "[DTEfficiencyTask]***Warning: RecSegment dimension is not 4 but "
154  << (*segment4D).dimension() << ", skipping!" << endl;
155  continue;
156  } else if((*chamberId).station() == 4 && (*segment4D).dimension() != 2) {
157  if(debug)
158  cout << "[DTEfficiencyTask]***Warning: RecSegment dimension is not 2 but "
159  << (*segment4D).dimension() << ", skipping!" << endl;
160  continue;
161  }
162 
163  vector<DTRecHit1D> recHits1D;
164  bool rPhi = false;
165  bool rZ = false;
166 
167  // Get 1D RecHits and select only events with 7 or 8 hits in phi and 3 or 4 hits in theta (if any)
168  const DTChamberRecSegment2D* phiSeg = (*segment4D).phiSegment();
169  vector<DTRecHit1D> phiRecHits = phiSeg->specificRecHits();
170  rPhi = true;
171  if(phiRecHits.size() < 7 || phiRecHits.size() > 8 ) {
172  if(debug)
173  cout << "[DTEfficiencyTask] Phi segments has: " << phiRecHits.size()
174  << " hits, skipping" << endl; // FIXME: info output
175  continue;
176  }
177  copy(phiRecHits.begin(), phiRecHits.end(), back_inserter(recHits1D));
178  const DTSLRecSegment2D* zSeg = 0;
179  if((*segment4D).dimension() == 4) {
180  rZ = true;
181  zSeg = (*segment4D).zSegment();
182  vector<DTRecHit1D> zRecHits = zSeg->specificRecHits();
183  if(zRecHits.size() < 3 || zRecHits.size() > 4 ) {
184  if(debug)
185  cout << "[DTEfficiencyTask] Theta segments has: " << zRecHits.size()
186  << " hits, skipping" << endl; // FIXME: info output
187  continue;
188  }
189  copy(zRecHits.begin(), zRecHits.end(), back_inserter(recHits1D));
190  }
191 
192  // Skip the segment if it has more than 1 hit on the same layer
193  vector<DTWireId> wireMap;
194  for(vector<DTRecHit1D>::const_iterator recHit1D = recHits1D.begin();
195  recHit1D != recHits1D.end();
196  recHit1D++) {
197  wireMap.push_back((*recHit1D).wireId());
198  }
199 
200  bool hitsOnSameLayer = false;
201  for(vector<DTWireId>::const_iterator channelId = wireMap.begin();
202  channelId != wireMap.end(); channelId++) {
203  vector<DTWireId>::const_iterator next = channelId;
204  next++;
205  for(vector<DTWireId>::const_iterator ite = next; ite != wireMap.end(); ite++) {
206  if((*channelId).layerId() == (*ite).layerId()) {
207  hitsOnSameLayer = true;
208  }
209  }
210  }
211  if(hitsOnSameLayer) {
212  if(debug)
213  cout << "[DTEfficiencyTask] This RecHit has 2 hits on the same layer, skipping!" << endl;
214  continue;
215  }
216 
217 
218  // Select 2D segments with angle smaller than 45 deg
219  LocalVector phiDirectionInChamber = (*phiSeg).localDirection();
220  if(rPhi && fabs(phiDirectionInChamber.x()/phiDirectionInChamber.z()) > 1) {
221  if(debug) {
222  cout << " RPhi segment has angle > 45 deg, skipping! " << endl;
223  cout << " Theta = " << phiDirectionInChamber.theta() << endl;
224  }
225  continue;
226  }
227  if(rZ) {
228  LocalVector zDirectionInChamber = (*zSeg).localDirection();
229  if(fabs(zDirectionInChamber.y()/zDirectionInChamber.z()) > 1) {
230  if(debug){
231  cout << " RZ segment has angle > 45 deg, skipping! " << endl;
232  cout << " Theta = " << zDirectionInChamber.theta() << endl;
233  }
234  continue;
235  }
236  }
237 
238 
239  // Skip if the 4D segment has only 10 hits
240  if(recHits1D.size() == 10) {
241  if(debug)
242  cout << "[DTEfficiencyTask] 4D Segment with only 10 hits, skipping!" << endl;
243  continue;
244  }
245 
246 
247  // Analyse the case of 11 recHits for MB1,MB2,MB3 and of 7 recHits for MB4
248  if((rPhi && recHits1D.size() == 7) || (rZ && recHits1D.size() == 11)) {
249 
250  if(debug) {
251  if(rPhi && recHits1D.size() == 7)
252  cout << "[DTEfficiencyTask] MB4 Segment with only 7 hits!" << endl;
253  if(rZ && recHits1D.size() == 11)
254  cout << "[DTEfficiencyTask] 4D Segment with only 11 hits!" << endl;
255  }
256 
257  // Find the layer without RecHits ----------------------------------------
258  const vector<const DTSuperLayer*> SupLayers = chamber->superLayers();
259  map<DTLayerId, bool> layerMap;
260  map<DTWireId, float> wireAndPosInChamberAtLayerZ;
261  // Loop over layers and wires to fill a map
262  for(vector<const DTSuperLayer*>::const_iterator superlayer = SupLayers.begin();
263  superlayer != SupLayers.end();
264  superlayer++) {
265  const vector<const DTLayer*> Layers = (*superlayer)->layers();
266  for(vector<const DTLayer*>::const_iterator layer = Layers.begin();
267  layer != Layers.end();
268  layer++) {
269  layerMap.insert(make_pair((*layer)->id(), false));
270  const int firstWire = dtGeom->layer((*layer)->id())->specificTopology().firstChannel();
271  const int lastWire = dtGeom->layer((*layer)->id())->specificTopology().lastChannel();
272  for(int i=firstWire; i - lastWire <= 0; i++) {
273  DTWireId wireId((*layer)->id(), i);
274  float wireX = (*layer)->specificTopology().wirePosition(wireId.wire());
275  LocalPoint wirePosInLay(wireX,0,0);
276  GlobalPoint wirePosGlob = (*layer)->toGlobal(wirePosInLay);
277  LocalPoint wirePosInChamber = chamber->toLocal(wirePosGlob);
278  if((*superlayer)->id().superlayer() == 1 || (*superlayer)->id().superlayer() == 3) {
279  wireAndPosInChamberAtLayerZ.insert(make_pair(wireId, wirePosInChamber.x()));
280  } else {
281  wireAndPosInChamberAtLayerZ.insert(make_pair(wireId, wirePosInChamber.y()));
282  }
283  }
284  }
285  }
286 
287  // Loop over segment 1D RecHit
288  map<DTLayerId, int> NumWireMap;
289  for(vector<DTRecHit1D>::const_iterator recHit = recHits1D.begin();
290  recHit != recHits1D.end();
291  recHit++) {
292  layerMap[(*recHit).wireId().layerId()]= true;
293  NumWireMap[(*recHit).wireId().layerId()]= (*recHit).wireId().wire();
294  }
295 
296  DTLayerId missLayerId;
297  //Loop over the map and find the layer without hits
298  for(map<DTLayerId, bool>::const_iterator iter = layerMap.begin();
299  iter != layerMap.end(); iter++) {
300  if(!(*iter).second) missLayerId = (*iter).first;
301  }
302  if(debug)
303  cout << "[DTEfficiencyTask] Layer without recHits is: " << missLayerId << endl;
304  // -------------------------------------------------------
305 
306 
307 
308  const DTLayer* missLayer = chamber->layer(missLayerId);
309 
310  LocalPoint missLayerPosInChamber = chamber->toLocal(missLayer->toGlobal(LocalPoint(0,0,0)));
311 
312  // Segment position at Wire z in chamber local frame
313  LocalPoint segPosAtZLayer = (*segment4D).localPosition()
314  + (*segment4D).localDirection()*missLayerPosInChamber.z()/cos((*segment4D).localDirection().theta());
315 
316  DTWireId missWireId;
317 
318  // Find the id of the cell without hit ---------------------------------------------------
319  for(map<DTWireId, float>::const_iterator wireAndPos = wireAndPosInChamberAtLayerZ.begin();
320  wireAndPos != wireAndPosInChamberAtLayerZ.end();
321  wireAndPos++) {
322  DTWireId wireId = (*wireAndPos).first;
323  if(wireId.layerId() == missLayerId) {
324  if(missLayerId.superlayerId().superlayer() == 1 || missLayerId.superlayerId().superlayer() == 3 ) {
325  if(fabs(segPosAtZLayer.x() - (*wireAndPos).second) < 2.1)
326  missWireId = wireId;
327  } else {
328  if(fabs(segPosAtZLayer.y() - (*wireAndPos).second) < 2.1)
329  missWireId = wireId;
330  }
331  }
332  }
333  if(debug)
334  cout << "[DTEfficiencyTask] Cell without hit is: " << missWireId << endl;
335  // ----------------------------------------------------------
336 
337 
338  bool foundUnAssRechit = false;
339 
340  // Look for unassociated hits in this cell
341  if(wireAnd1DRecHits.find(missWireId) != wireAnd1DRecHits.end()) {
342  if(debug)
343  cout << "[DTEfficiencyTask] Unassociated Hit found!" << endl;
344  foundUnAssRechit = true;
345  }
346 
347 
348  for(map<DTLayerId, bool>::const_iterator iter = layerMap.begin();
349  iter != layerMap.end(); iter++) {
350  if((*iter).second)
351  fillHistos((*iter).first, dtGeom->layer((*iter).first)->specificTopology().firstChannel(), dtGeom->layer((*iter).first)->specificTopology().lastChannel(), NumWireMap[(*iter).first]);
352  else
353  fillHistos((*iter).first, dtGeom->layer((*iter).first)->specificTopology().firstChannel(), dtGeom->layer((*iter).first)->specificTopology().lastChannel(), missWireId.wire(), foundUnAssRechit);
354  }
355 
356  } // End of the loop for segment with 7 or 11 recHits
357 
358  if((rPhi && recHits1D.size() == 8) || (rZ && recHits1D.size() == 12)) {
359  map<DTLayerId, int> NumWireMap;
360  DTLayerId LayerID;
361  for(vector<DTRecHit1D>::const_iterator recHit = recHits1D.begin();
362  recHit != recHits1D.end();
363  recHit++) {
364  LayerID = (*recHit).wireId().layerId();
365  NumWireMap[LayerID]= (*recHit).wireId().wire();
366  }
367  for(map<DTLayerId, int>::const_iterator iter = NumWireMap.begin();
368  iter != NumWireMap.end(); iter++) {
369  fillHistos((*iter).first, dtGeom->layer((*iter).first)->specificTopology().firstChannel(), dtGeom->layer((*iter).first)->specificTopology().lastChannel(), NumWireMap[(*iter).first]);
370  }
371  }
372 
373  } // End of loop over the 4D segments inside a sigle chamber
374  } // End of loop over all tha chamber with at least a 4D segment in the event
375 }
376 
377 
378 // Book a set of histograms for a given Layer
379 void DTEfficiencyTask::bookHistos(DTLayerId lId, int firstWire, int lastWire) {
380  if(debug)
381  cout << " Booking histos for L: " << lId << endl;
382 
383  // Compose the chamber name
384  stringstream wheel; wheel << lId.superlayerId().chamberId().wheel();
385  stringstream station; station << lId.superlayerId().chamberId().station();
386  stringstream sector; sector << lId.superlayerId().chamberId().sector();
387  stringstream superLayer; superLayer << lId.superlayerId().superlayer();
388  stringstream layer; layer << lId.layer();
389 
390  string lHistoName =
391  "_W" + wheel.str() +
392  "_St" + station.str() +
393  "_Sec" + sector.str() +
394  "_SL" + superLayer.str()+
395  "_L" + layer.str();
396 
397  theDbe->setCurrentFolder("DT/DTEfficiencyTask/Wheel" + wheel.str() +
398  "/Station" + station.str() +
399  "/Sector" + sector.str() +
400  "/SuperLayer" +superLayer.str());
401  // Create the monitor elements
402  vector<MonitorElement *> histos;
403  // histo for hits associated to the 4D reconstructed segment
404  histos.push_back(theDbe->book1D("hEffOccupancy"+lHistoName, "4D segments recHits occupancy",lastWire-firstWire+1, firstWire-0.5, lastWire+0.5));
405  // histo for hits not associated to the segment
406  histos.push_back(theDbe->book1D("hEffUnassOccupancy"+lHistoName, "4D segments recHits and Hits not associated occupancy",lastWire-firstWire+1, firstWire-0.5, lastWire+0.5));
407  // histo for cells associated to the 4D reconstructed segment
408  histos.push_back(theDbe->book1D("hRecSegmOccupancy"+lHistoName, "4D segments cells occupancy",lastWire-firstWire+1, firstWire-0.5, lastWire+0.5));
409 
410  histosPerL[lId] = histos;
411 }
412 
413 
414 // Fill a set of histograms for a given Layer
416  int firstWire, int lastWire,
417  int numWire) {
418  if(histosPerL.find(lId) == histosPerL.end()){
419  bookHistos(lId, firstWire, lastWire);
420  }
421  vector<MonitorElement *> histos = histosPerL[lId];
422  histos[0]->Fill(numWire);
423  histos[1]->Fill(numWire);
424  histos[2]->Fill(numWire);
425 }
426 
427 // Fill a set of histograms for a given Layer
429  int firstWire, int lastWire,
430  int missingWire,
431  bool unassHit) {
432  if(histosPerL.find(lId) == histosPerL.end()){
433  bookHistos(lId, firstWire, lastWire);
434  }
435  vector<MonitorElement *> histos = histosPerL[lId];
436  if(unassHit)
437  histos[1]->Fill(missingWire);
438  histos[2]->Fill(missingWire);
439 }
LuminosityBlockID id() const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
dictionary parameters
Definition: Parameters.py:2
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:52
void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &context)
To reset the MEs.
DTChamberId chamberId() const
Return the corresponding ChamberId.
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:47
static std::pair< DTLayerId, DTSuperLayerIdComparator > layersBySuperLayer(DTSuperLayerId slId)
Access by SL objects written into a RangeMap by layer.
T y() const
Definition: PV3DBase.h:63
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:62
const DTLayer * layer(DTLayerId id) const
Return the layer corresponding to the given id.
Definition: DTChamber.cc:82
identifier iterator
Definition: RangeMap.h:138
int layer() const
Return the layer number.
Definition: DTLayerId.h:55
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:61
void fillHistos(DTLayerId lId, int firstWire, int lastWire, int numWire)
dictionary map
Definition: Association.py:205
void bookHistos()
Definition: Histogram.h:33
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:45
const std::vector< const DTSuperLayer * > & superLayers() const
Return the superlayers in the chamber.
Definition: DTChamber.cc:62
void beginJob()
BeginJob.
T z() const
Definition: PV3DBase.h:64
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
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
void bookHistos(DTLayerId lId, int fisrtWire, int lastWire)
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
virtual ~DTEfficiencyTask()
Destructor.
int superlayer() const
Return the superlayer number (deprecated method name)
void analyze(const edm::Event &event, const edm::EventSetup &setup)
const T & get() const
Definition: EventSetup.h:55
LuminosityBlockNumber_t luminosityBlock() const
void endJob()
Endjob.
DTLayerId layerId() const
Return the corresponding LayerId.
Definition: DTWireId.h:64
DTEfficiencyTask(const edm::ParameterSet &pset)
Constructor.
int sector() const
Definition: DTChamberId.h:63
tuple cout
Definition: gather_cfg.py:121
int station() const
Return the station number.
Definition: DTChamberId.h:53
#define debug
Definition: MEtoEDMFormat.h:34
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:47
T x() const
Definition: PV3DBase.h:62
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
tuple size
Write out results.