test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTCalibValidation.cc
Go to the documentation of this file.
1 
2 /*
3  * See header file for a description of this class.
4  *
5  * \author G. Mila - INFN Torino
6  */
7 
9 
10 // Framework
18 
19 //Geometry
22 
23 //RecHit
26 
27 
28 #include <iterator>
29 
30 using namespace edm;
31 using namespace std;
32 
33 
35 
36  parameters = pset;
37 
38  //FR the following was previously in the beginJob
39 
40  // the name of the rechits collection at step 1
41  recHits1DToken_ = consumes<DTRecHitCollection>(
42  edm::InputTag(parameters.getUntrackedParameter<string>("recHits1DLabel")));
43  // the name of the 2D segments
44  segment2DToken_ = consumes<DTRecSegment2DCollection>(
45  edm::InputTag(parameters.getUntrackedParameter<string>("segment2DLabel")));
46  // the name of the 4D segments
47  segment4DToken_ = consumes<DTRecSegment4DCollection>(
48  edm::InputTag(parameters.getUntrackedParameter<string>("segment4DLabel")));
49  // the counter of segments not used to compute residuals
50  wrongSegment = 0;
51  // the counter of segments used to compute residuals
52  rightSegment = 0;
53  // the analysis type
54  detailedAnalysis = parameters.getUntrackedParameter<bool>("detailedAnalysis",false);
55 
56  nevent=0;
57 
58 }
59 
60 
62 
63  //FR the following was previously in the endJob
64 
65  LogVerbatim("DTCalibValidation") << "Segments used to compute residuals: " << rightSegment;
66  LogVerbatim("DTCalibValidation") << "Segments not used to compute residuals: " << wrongSegment;
67 
68 }
69 
71 
72  // get the geometry
73  setup.get<MuonGeometryRecord>().get(dtGeom);
74 
75  }
76 
78 
79  ++nevent;
80  LogTrace("DTCalibValidation") << "[DTCalibValidation] Analyze #Run: " << event.id().run()
81  << " #Event: " << nevent;
82 
83  // RecHit mapping at Step 1 -------------------------------
84  map<DTWireId,vector<DTRecHit1DPair> > recHitsPerWire_1S;
85 
86  // RecHit mapping at Step 2 ------------------------------
87  map<DTWireId,vector<DTRecHit1D> > recHitsPerWire_2S;
88 
89  if(detailedAnalysis){
90  LogTrace("DTCalibValidation") << " -- DTRecHit S1: begin analysis:";
91  // Get the rechit collection from the event
93  event.getByToken(recHits1DToken_, dtRecHits);
94  recHitsPerWire_1S = map1DRecHitsPerWire(dtRecHits.product());
95 
96  LogTrace("DTCalibValidation") << " -- DTRecHit S2: begin analysis:";
97  // Get the 2D rechits from the event
99  event.getByToken(segment2DToken_, segment2Ds);
100  recHitsPerWire_2S = map1DRecHitsPerWire(segment2Ds.product());
101  }
102 
103  // RecHit mapping at Step 3 ---------------------------------
104  LogTrace("DTCalibValidation") << " -- DTRecHit S3: begin analysis:";
105  // Get the 4D rechits from the event
107  event.getByToken(segment4DToken_, segment4Ds);
108  map<DTWireId,vector<DTRecHit1D> > recHitsPerWire_3S = map1DRecHitsPerWire(segment4Ds.product());
109 
110 
111  // Loop over all 4D segments
112  for(DTRecSegment4DCollection::const_iterator segment = segment4Ds->begin();
113  segment != segment4Ds->end();
114  ++segment) {
115 
116  if(detailedAnalysis){
117  LogTrace("DTCalibValidation") << "Anlysis on recHit at step 1";
118  compute(dtGeom.product(), (*segment), recHitsPerWire_1S, 1);
119 
120  LogTrace("DTCalibValidation") << "Anlysis on recHit at step 2";
121  compute(dtGeom.product(), (*segment), recHitsPerWire_2S, 2);
122  }
123 
124  LogTrace("DTCalibValidation") << "Anlysis on recHit at step 3";
125  compute(dtGeom.product(), (*segment), recHitsPerWire_3S, 3);
126  }
127 
128 }
129 
130 
131 // Return a map between DTRecHit1DPair and wireId
132 map<DTWireId, vector<DTRecHit1DPair> >
134  map<DTWireId, vector<DTRecHit1DPair> > ret;
135 
136  for(DTRecHitCollection::const_iterator rechit = dt1DRecHitPairs->begin();
137  rechit != dt1DRecHitPairs->end(); ++rechit) {
138  ret[(*rechit).wireId()].push_back(*rechit);
139  }
140 
141  return ret;
142 }
143 
144 
145 // Return a map between DTRecHit1D at S2 and wireId
146 map<DTWireId, vector<DTRecHit1D> >
148  map<DTWireId, vector<DTRecHit1D> > ret;
149 
150  // Loop over all 2D segments
151  for(DTRecSegment2DCollection::const_iterator segment = segment2Ds->begin();
152  segment != segment2Ds->end();
153  ++segment) {
154  vector<DTRecHit1D> component1DHits= (*segment).specificRecHits();
155  // Loop over all component 1D hits
156  for(vector<DTRecHit1D>::const_iterator hit = component1DHits.begin();
157  hit != component1DHits.end(); ++hit) {
158  ret[(*hit).wireId()].push_back(*hit);
159  }
160  }
161  return ret;
162 }
163 
164 // Return a map between DTRecHit1D at S3 and wireId
165 map<DTWireId, std::vector<DTRecHit1D> >
167  map<DTWireId, vector<DTRecHit1D> > ret;
168  // Loop over all 4D segments
169  for(DTRecSegment4DCollection::const_iterator segment = segment4Ds->begin();
170  segment != segment4Ds->end();
171  ++segment) {
172  // Get component 2D segments
173  vector<const TrackingRecHit*> segment2Ds = (*segment).recHits();
174  // Loop over 2D segments:
175  for(vector<const TrackingRecHit*>::const_iterator segment2D = segment2Ds.begin();
176  segment2D != segment2Ds.end();
177  ++segment2D) {
178  // Get 1D component rechits
179  vector<const TrackingRecHit*> hits = (*segment2D)->recHits();
180  // Loop over them
181  for(vector<const TrackingRecHit*>::const_iterator hit = hits.begin();
182  hit != hits.end(); ++hit) {
183  const DTRecHit1D* hit1D = dynamic_cast<const DTRecHit1D*>(*hit);
184  ret[hit1D->wireId()].push_back(*hit1D);
185  }
186  }
187  }
188 
189  return ret;
190 }
191 
192 
193 
194 // Find the RecHit closest to the segment4D
195 template <typename type>
196 const type*
198  DTWireId wireId,
199  const vector<type>& recHits,
200  const float segmDist) {
201  float res = 99999;
202  const type* theBestRecHit = 0;
203  // Loop over RecHits within the cell
204  for(typename vector<type>::const_iterator recHit = recHits.begin();
205  recHit != recHits.end();
206  ++recHit) {
207  float distTmp = recHitDistFromWire(*recHit, layer);
208  if(fabs(distTmp-segmDist) < res) {
209  res = fabs(distTmp-segmDist);
210  theBestRecHit = &(*recHit);
211  }
212  } // End of loop over RecHits within the cell
213 
214  return theBestRecHit;
215 }
216 
217 
218 // Compute the distance from wire (cm) of a hits in a DTRecHit1DPair
219 float
221  return fabs(hitPair.localPosition(DTEnums::Left).x() -
222  hitPair.localPosition(DTEnums::Right).x())/2.;
223 }
224 
225 
226 // Compute the distance from wire (cm) of a hits in a DTRecHit1D
227 float
229  return fabs(recHit.localPosition().x() - layer->specificTopology().wirePosition(recHit.wireId().wire()));
230 
231 }
232 
233 // Compute the position (cm) of a hits in a DTRecHit1DPair
234 float
235 DTCalibValidation::recHitPosition(const DTRecHit1DPair& hitPair, const DTLayer* layer, const DTChamber* chamber, float segmentPos, int sl) {
236 
237  // Get the layer and the wire position
238  GlobalPoint hitPosGlob_right = layer->toGlobal(hitPair.localPosition(DTEnums::Right));
239  LocalPoint hitPosInChamber_right = chamber->toLocal(hitPosGlob_right);
240  GlobalPoint hitPosGlob_left = layer->toGlobal(hitPair.localPosition(DTEnums::Left));
241  LocalPoint hitPosInChamber_left = chamber->toLocal(hitPosGlob_left);
242 
243  float recHitPos=-1;
244  if(sl != 2){
245  if(fabs(hitPosInChamber_left.x()-segmentPos)<fabs(hitPosInChamber_right.x()-segmentPos))
246  recHitPos = hitPosInChamber_left.x();
247  else
248  recHitPos = hitPosInChamber_right.x();
249  }
250  else{
251  if(fabs(hitPosInChamber_left.y()-segmentPos)<fabs(hitPosInChamber_right.y()-segmentPos))
252  recHitPos = hitPosInChamber_left.y();
253  else
254  recHitPos = hitPosInChamber_right.y();
255  }
256 
257  return recHitPos;
258 }
259 
260 
261 // Compute the position (cm) of a hits in a DTRecHit1D
262 float
263 DTCalibValidation::recHitPosition(const DTRecHit1D& recHit, const DTLayer* layer, const DTChamber* chamber, float segmentPos, int sl) {
264 
265  // Get the layer and the wire position
266  GlobalPoint recHitPosGlob = layer->toGlobal(recHit.localPosition());
267  LocalPoint recHitPosInChamber = chamber->toLocal(recHitPosGlob);
268 
269  float recHitPos = -1;
270  if(sl != 2)
271  recHitPos = recHitPosInChamber.x();
272  else
273  recHitPos = recHitPosInChamber.y();
274 
275  return recHitPos;
276 
277 }
278 
279 // Compute the residuals
280 template <typename type>
282  const DTRecSegment4D& segment,
283  const std::map<DTWireId, std::vector<type> >& recHitsPerWire,
284  int step) {
285  bool computeResidual = true;
286 
287  // Get all 1D RecHits at step 3 within the 4D segment
288  vector<DTRecHit1D> recHits1D_S3;
289 
290  // Get 1D RecHits at Step 3 and select only events with
291  // 8 hits in phi and 4 hits in theta (if any)
292  const DTChamberRecSegment2D* phiSeg = segment.phiSegment();
293  if(phiSeg){
294  vector<DTRecHit1D> phiRecHits = phiSeg->specificRecHits();
295  if(phiRecHits.size() != 8) {
296  LogTrace("DTCalibValidation") << "[DTCalibValidation] Phi segments has: " << phiRecHits.size()
297  << " hits, skipping"; // FIXME: info output
298  computeResidual = false;
299  }
300  copy(phiRecHits.begin(), phiRecHits.end(), back_inserter(recHits1D_S3));
301  }
302  if(!phiSeg){
303  LogTrace("DTCalibValidation") << " [DTCalibValidation] 4D segment has not the phi segment! ";
304  computeResidual = false;
305  }
306 
307  if(segment.dimension() == 4) {
308  const DTSLRecSegment2D* zSeg = segment.zSegment();
309  if(zSeg){
310  vector<DTRecHit1D> zRecHits = zSeg->specificRecHits();
311  if(zRecHits.size() != 4) {
312  LogTrace("DTCalibValidation") << "[DTCalibValidation] Theta segments has: " << zRecHits.size()
313  << " hits, skipping"; // FIXME: info output
314  computeResidual = false;
315  }
316  copy(zRecHits.begin(), zRecHits.end(), back_inserter(recHits1D_S3));
317  }
318  if(!zSeg){
319  LogTrace("DTCalibValidation") << " [DTCalibValidation] 4D segment has not the z segment! ";
320  computeResidual = false;
321  }
322  }
323 
324  if(!computeResidual)
325  ++wrongSegment;
326  if(computeResidual){
327  ++rightSegment;
328  // Loop over 1D RecHit inside 4D segment
329  for(vector<DTRecHit1D>::const_iterator recHit1D = recHits1D_S3.begin();
330  recHit1D != recHits1D_S3.end();
331  ++recHit1D) {
332  const DTWireId wireId = (*recHit1D).wireId();
333 
334  // Get the layer and the wire position
335  const DTLayer* layer = dtGeom->layer(wireId);
336  float wireX = layer->specificTopology().wirePosition(wireId.wire());
337 
338  // Extrapolate the segment to the z of the wire
339  // Get wire position in chamber RF
340  // (y and z must be those of the hit to be coherent in the transf. of RF in case of rotations of the layer alignment)
341  LocalPoint wirePosInLay(wireX,(*recHit1D).localPosition().y(),(*recHit1D).localPosition().z());
342  GlobalPoint wirePosGlob = layer->toGlobal(wirePosInLay);
343  const DTChamber* chamber = dtGeom->chamber((*recHit1D).wireId().layerId().chamberId());
344  LocalPoint wirePosInChamber = chamber->toLocal(wirePosGlob);
345 
346  // Segment position at Wire z in chamber local frame
347  LocalPoint segPosAtZWire = segment.localPosition()
348  + segment.localDirection()*wirePosInChamber.z()/cos(segment.localDirection().theta());
349 
350  // Compute the distance of the segment from the wire
351  int sl = wireId.superlayer();
352  float SegmDistance = -1;
353  if(sl == 1 || sl == 3) {
354  // RPhi SL
355  SegmDistance = fabs(wirePosInChamber.x() - segPosAtZWire.x());
356  LogTrace("DTCalibValidation") << "SegmDistance: " << SegmDistance;
357  } else if(sl == 2) {
358  // RZ SL
359  SegmDistance = fabs(segPosAtZWire.y() - wirePosInChamber.y());
360  LogTrace("DTCalibValidation") << "SegmDistance: " << SegmDistance;
361  }
362  if(SegmDistance > 2.1)
363  LogTrace("DTCalibValidation") << " Warning: dist segment-wire: " << SegmDistance;
364 
365  // Look for RecHits in the same cell
366  if(recHitsPerWire.find(wireId) == recHitsPerWire.end()) {
367  LogTrace("DTCalibValidation") << " No RecHit found at Step: " << step << " in cell: " << wireId;
368  } else {
369  vector<type> recHits = recHitsPerWire.at(wireId);
370  LogTrace("DTCalibValidation") << " " << recHits.size() << " RecHits, Step " << step << " in channel: " << wireId;
371 
372  // Get the layer
373  const DTLayer* layer = dtGeom->layer(wireId);
374  // Find the best RecHits
375  const type* theBestRecHit = findBestRecHit(layer, wireId, recHits, SegmDistance);
376  // Compute the distance of the recHit from the wire
377  float recHitWireDist = recHitDistFromWire(*theBestRecHit, layer);
378  LogTrace("DTCalibValidation") << "recHitWireDist: " << recHitWireDist;
379 
380  // Compute the residuals
381  float residualOnDistance = recHitWireDist - SegmDistance;
382  LogTrace("DTCalibValidation") << "WireId: " << wireId << " ResidualOnDistance: " << residualOnDistance;
383  float residualOnPosition = -1;
384  float recHitPos = -1;
385  if(sl == 1 || sl == 3) {
386  recHitPos = recHitPosition(*theBestRecHit, layer, chamber, segPosAtZWire.x(), sl);
387  residualOnPosition = recHitPos - segPosAtZWire.x();
388  }
389  else{
390  recHitPos = recHitPosition(*theBestRecHit, layer, chamber, segPosAtZWire.y(), sl);
391  residualOnPosition = recHitPos - segPosAtZWire.y();
392  }
393  LogTrace("DTCalibValidation") << "WireId: " << wireId << " ResidualOnPosition: " << residualOnPosition;
394 
395  // Fill the histos
396  if(sl == 1 || sl == 3)
397  fillHistos(wireId.superlayerId(), SegmDistance, residualOnDistance, (wirePosInChamber.x() - segPosAtZWire.x()), residualOnPosition, step);
398  else
399  fillHistos(wireId.superlayerId(), SegmDistance, residualOnDistance, (wirePosInChamber.y() - segPosAtZWire.y()), residualOnPosition, step);
400 
401  }
402  }
403  }
404 
405 }
406 
407 
408 void DTCalibValidation::bookHistograms(DQMStore::IBooker & ibooker, edm::Run const & iRun, edm::EventSetup const & iSetup) {
409 
410  //FR substitute the DQMStore instance by ibooker
411  ibooker.setCurrentFolder("DT/DTCalibValidation");
412 
413  DTSuperLayerId slId;
414 
415  // Loop over all the chambers
416  vector<const DTChamber*>::const_iterator ch_it = dtGeom->chambers().begin();
417  vector<const DTChamber*>::const_iterator ch_end = dtGeom->chambers().end();
418  for (; ch_it != ch_end; ++ch_it) {
419  vector<const DTSuperLayer*>::const_iterator sl_it = (*ch_it)->superLayers().begin();
420  vector<const DTSuperLayer*>::const_iterator sl_end = (*ch_it)->superLayers().end();
421  // Loop over the SLs
422  for(; sl_it != sl_end; ++sl_it) {
423  slId = (*sl_it)->id();
424 
425  int firstStep=1;
426  if(!detailedAnalysis) firstStep=3;
427  // Loop over the 3 steps
428  for(int step = firstStep; step <= 3; ++step) {
429 
430  LogTrace("DTCalibValidation") << " Booking histos for SL: " << slId;
431 
432  // Compose the chamber name
433  stringstream wheel; wheel << slId.wheel();
434  stringstream station; station << slId.station();
435  stringstream sector; sector << slId.sector();
436  stringstream superLayer; superLayer << slId.superlayer();
437  // Define the step
438  stringstream Step; Step << step;
439 
440 
441  string slHistoName =
442  "_STEP" + Step.str() +
443  "_W" + wheel.str() +
444  "_St" + station.str() +
445  "_Sec" + sector.str() +
446  "_SL" + superLayer.str();
447 
448  ibooker.setCurrentFolder("DT/DTCalibValidation/Wheel" + wheel.str() +
449  "/Station" + station.str() +
450  "/Sector" + sector.str());
451  // Create the monitor elements
452  vector<MonitorElement *> histos;
453  // Note the order matters
454  histos.push_back(ibooker.book1D("hResDist"+slHistoName,
455  "Residuals on the distance from wire (rec_hit - segm_extr) (cm)",
456  200, -0.4, 0.4));
457  histos.push_back(ibooker.book2D("hResDistVsDist"+slHistoName,
458  "Residuals on the distance (cm) from wire (rec_hit - segm_extr) vs distance (cm)",
459  100, 0, 2.5, 200, -0.4, 0.4));
460  if(detailedAnalysis){
461  histos.push_back(ibooker.book1D("hResPos"+slHistoName,
462  "Residuals on the position from wire (rec_hit - segm_extr) (cm)",
463  200, -0.4, 0.4));
464  histos.push_back(ibooker.book2D("hResPosVsPos"+slHistoName,
465  "Residuals on the position (cm) from wire (rec_hit - segm_extr) vs distance (cm)",
466  200, -2.5, 2.5, 200, -0.4, 0.4));
467  }
468 
469  histosPerSL[make_pair(slId, step)] = histos;
470  }
471  }
472  }
473 }
474 
475 
476 // Fill a set of histograms for a given SL
478  float distance,
479  float residualOnDistance,
480  float position,
481  float residualOnPosition,
482  int step) {
483  // FIXME: optimization of the number of searches
484  vector<MonitorElement *> histos = histosPerSL[make_pair(slId,step)];
485  histos[0]->Fill(residualOnDistance);
486  histos[1]->Fill(distance, residualOnDistance);
487  if(detailedAnalysis){
488  histos[2]->Fill(residualOnPosition);
489  histos[3]->Fill(position, residualOnPosition);
490  }
491 }
492 
493 
494 // Local Variables:
495 // show-trailing-whitespace: t
496 // truncate-lines: t
497 // End:
type
Definition: HCALResponse.h:21
float wirePosition(int wireNumber) const
Returns the x position in the layer of a given wire number.
Definition: DTTopology.cc:86
tuple ret
prodAgent to be discontinued
float recHitDistFromWire(const DTRecHit1DPair &hitPair, const DTLayer *layer)
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &)
const DTChamberRecSegment2D * phiSegment() const
The superPhi segment: 0 if no phi projection available.
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:54
T y() const
Definition: PV3DBase.h:63
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:69
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
const DTLayer * layer(DTLayerId id) const
Return a layer given its id.
Definition: DTGeometry.cc:110
int nevent
Definition: AMPTWrapper.h:74
virtual LocalVector localDirection() const
Local direction in Chamber frame.
void compute(const DTGeometry *dtGeom, const DTRecSegment4D &segment, const std::map< DTWireId, std::vector< type > > &recHitsPerWire, int step)
const DTTopology & specificTopology() const
Definition: DTLayer.cc:42
T z() const
Definition: PV3DBase.h:64
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
std::map< DTWireId, std::vector< DTRecHit1DPair > > map1DRecHitsPerWire(const DTRecHitCollection *dt1DRecHitPairs)
void fillHistos(DTSuperLayerId slId, float distance, float residualOnDistance, float position, float residualOnPosition, int step)
void analyze(const edm::Event &event, const edm::EventSetup &setup)
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
virtual LocalPoint localPosition() const
Local position in Chamber frame.
#define LogTrace(id)
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
virtual int dimension() const
Dimension (in parameter space)
void dqmBeginRun(const edm::Run &r, const edm::EventSetup &c)
BeginRun.
virtual LocalPoint localPosition() const
Return the 3-dimensional local position.
Definition: DTRecHit1D.h:60
int wire() const
Return the wire number.
Definition: DTWireId.h:56
int superlayer() const
Return the superlayer number (deprecated method name)
const DTSLRecSegment2D * zSegment() const
The Z segment: 0 if not zed projection available.
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:276
T const * product() const
Definition: Handle.h:81
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
virtual ~DTCalibValidation()
Destructor.
const T & get() const
Definition: EventSetup.h:56
const DTChamber * chamber(DTChamberId id) const
Return a DTChamber given its id.
Definition: DTGeometry.cc:100
int sector() const
Definition: DTChamberId.h:61
static int position[264][3]
Definition: ReadPGInfo.cc:509
DTCalibValidation(const edm::ParameterSet &pset)
Constructor.
int station() const
Return the station number.
Definition: DTChamberId.h:51
float recHitPosition(const DTRecHit1DPair &hitPair, const DTLayer *layer, const DTChamber *chamber, float segmPos, int sl)
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45
T x() const
Definition: PV3DBase.h:62
Definition: Run.h:43
virtual LocalPoint localPosition() const
const type * findBestRecHit(const DTLayer *layer, DTWireId wireId, const std::vector< type > &recHits, const float simHitDist)
DTWireId wireId() const
Return the wireId.
Definition: DTRecHit1D.h:107