CMS 3D CMS Logo

MuonAlignment.cc
Go to the documentation of this file.
1 
2 /*
3  * DQM muon alignment analysis monitoring
4  *
5  * \author J. Fernandez - Univ. Oviedo <Javier.Fernandez@cern.ch>
6  */
7 
9 
11  metname = "MuonAlignment";
12 
13  LogTrace(metname) << "[MuonAlignment] Constructor called!" << std::endl;
14 
15  parameters = pSet;
16 
17  theMuonCollectionLabel = consumes<reco::TrackCollection>(parameters.getParameter<edm::InputTag>("MuonCollection"));
18 
20  consumes<DTRecSegment4DCollection>(parameters.getParameter<edm::InputTag>("RecHits4DDTCollectionTag"));
22  consumes<CSCSegmentCollection>(parameters.getParameter<edm::InputTag>("RecHits4DCSCCollectionTag"));
23 
24  resLocalXRangeStation1 = parameters.getUntrackedParameter<double>("resLocalXRangeStation1");
25  resLocalXRangeStation2 = parameters.getUntrackedParameter<double>("resLocalXRangeStation2");
26  resLocalXRangeStation3 = parameters.getUntrackedParameter<double>("resLocalXRangeStation3");
27  resLocalXRangeStation4 = parameters.getUntrackedParameter<double>("resLocalXRangeStation4");
28  resLocalYRangeStation1 = parameters.getUntrackedParameter<double>("resLocalYRangeStation1");
29  resLocalYRangeStation2 = parameters.getUntrackedParameter<double>("resLocalYRangeStation2");
30  resLocalYRangeStation3 = parameters.getUntrackedParameter<double>("resLocalYRangeStation3");
31  resLocalYRangeStation4 = parameters.getUntrackedParameter<double>("resLocalYRangeStation4");
32  resPhiRange = parameters.getUntrackedParameter<double>("resPhiRange");
33  resThetaRange = parameters.getUntrackedParameter<double>("resThetaRange");
34 
35  meanPositionRange = parameters.getUntrackedParameter<double>("meanPositionRange");
36  rmsPositionRange = parameters.getUntrackedParameter<double>("rmsPositionRange");
37  meanAngleRange = parameters.getUntrackedParameter<double>("meanAngleRange");
38  rmsAngleRange = parameters.getUntrackedParameter<double>("rmsAngleRange");
39 
40  nbins = parameters.getUntrackedParameter<unsigned int>("nbins");
41  min1DTrackRecHitSize = parameters.getUntrackedParameter<unsigned int>("min1DTrackRecHitSize");
42  min4DTrackSegmentSize = parameters.getUntrackedParameter<unsigned int>("min4DTrackSegmentSize");
43 
44  doDT = parameters.getUntrackedParameter<bool>("doDT");
45  doCSC = parameters.getUntrackedParameter<bool>("doCSC");
46  doSummary = parameters.getUntrackedParameter<bool>("doSummary");
47 
48  numberOfTracks = 0;
49  numberOfHits = 0;
50 
51  MEFolderName = parameters.getParameter<std::string>("FolderName");
52  topFolder << MEFolderName + "/Alignment/Muon";
53 }
54 
56 
58  LogTrace(metname) << "[MuonAlignment] Parameters initialization";
59 
60  if (!(doDT || doCSC)) {
61  edm::LogError("MuonAlignment") << " Error!! At least one Muon subsystem "
62  "(DT or CSC) must be monitorized!!"
63  << std::endl;
64  edm::LogError("MuonAlignment") << " Please enable doDT or doCSC to True in your python cfg file!!!" << std::endl;
65  exit(1);
66  }
67 
69 
70  if (doSummary) {
71  if (doDT) {
72  dbe->setCurrentFolder(topFolder.str() + "/DT");
74  "hLocalPositionDT", "Local DT position (cm) absolute MEAN residuals;Sector;;cm", 14, 1, 15, 40, 0, 40);
76  "hLocalAngleDT", "Local DT angle (rad) absolute MEAN residuals;Sector;;rad", 14, 1, 15, 40, 0, 40);
78  dbe->book2D("hLocalPositionRmsDT", "Local DT position (cm) RMS residuals;Sector;;cm", 14, 1, 15, 40, 0, 40);
80  dbe->book2D("hLocalAngleRmsDT", "Local DT angle (rad) RMS residuals;Sector;;rad", 14, 1, 15, 40, 0, 40);
81 
82  hLocalXMeanDT = dbe->book1D("hLocalXMeanDT",
83  "Distribution of absolute MEAN Local X (cm) residuals "
84  "for DT;<X> (cm);number of chambers",
85  100,
86  0,
88  hLocalXRmsDT = dbe->book1D("hLocalXRmsDT",
89  "Distribution of RMS Local X (cm) residuals "
90  "for DT;X RMS (cm);number of chambers",
91  100,
92  0,
94  hLocalYMeanDT = dbe->book1D("hLocalYMeanDT",
95  "Distribution of absolute MEAN Local Y (cm) residuals "
96  "for DT;<Y> (cm);number of chambers",
97  100,
98  0,
100  hLocalYRmsDT = dbe->book1D("hLocalYRmsDT",
101  "Distribution of RMS Local Y (cm) residuals "
102  "for DT;Y RMS (cm);number of chambers",
103  100,
104  0,
106 
107  hLocalPhiMeanDT = dbe->book1D("hLocalPhiMeanDT",
108  "Distribution of MEAN #phi (rad) residuals "
109  "for DT;<#phi>(rad);number of chambers",
110  100,
113  hLocalPhiRmsDT = dbe->book1D("hLocalPhiRmsDT",
114  "Distribution of RMS #phi (rad) residuals "
115  "for DT;#phi RMS (rad);number of chambers",
116  100,
117  0,
118  rmsAngleRange);
119  hLocalThetaMeanDT = dbe->book1D("hLocalThetaMeanDT",
120  "Distribution of MEAN #theta (rad) residuals for "
121  "DT;<#theta>(rad);number of chambers",
122  100,
125  hLocalThetaRmsDT = dbe->book1D("hLocalThetaRmsDT",
126  "Distribution of RMS #theta (rad) residuals for "
127  "DT;#theta RMS (rad);number of chambers",
128  100,
129  0,
130  rmsAngleRange);
131  }
132 
133  if (doCSC) {
134  dbe->setCurrentFolder(topFolder.str() + "/CSC");
136  "hLocalPositionCSC", "Local CSC position (cm) absolute MEAN residuals;Sector;;cm", 36, 1, 37, 40, 0, 40);
138  "hLocalAngleCSC", "Local CSC angle (rad) absolute MEAN residuals;Sector;;rad", 36, 1, 37, 40, 0, 40);
140  dbe->book2D("hLocalPositionRmsCSC", "Local CSC position (cm) RMS residuals;Sector;;cm", 36, 1, 37, 40, 0, 40);
142  dbe->book2D("hLocalAngleRmsCSC", "Local CSC angle (rad) RMS residuals;Sector;;rad", 36, 1, 37, 40, 0, 40);
143 
144  hLocalXMeanCSC = dbe->book1D("hLocalXMeanCSC",
145  "Distribution of absolute MEAN Local X (cm) residuals "
146  "for CSC;<X> (cm);number of chambers",
147  100,
148  0,
150  hLocalXRmsCSC = dbe->book1D("hLocalXRmsCSC",
151  "Distribution of RMS Local X (cm) residuals "
152  "for CSC;X RMS (cm);number of chambers",
153  100,
154  0,
156  hLocalYMeanCSC = dbe->book1D("hLocalYMeanCSC",
157  "Distribution of absolute MEAN Local Y (cm) residuals "
158  "for CSC;<Y> (cm);number of chambers",
159  100,
160  0,
162  hLocalYRmsCSC = dbe->book1D("hLocalYRmsCSC",
163  "Distribution of RMS Local Y (cm) residuals "
164  "for CSC;Y RMS (cm);number of chambers",
165  100,
166  0,
168 
169  hLocalPhiMeanCSC = dbe->book1D("hLocalPhiMeanCSC",
170  "Distribution of absolute MEAN #phi (rad) residuals for "
171  "CSC;<#phi>(rad);number of chambers",
172  100,
173  0,
175  hLocalPhiRmsCSC = dbe->book1D("hLocalPhiRmsCSC",
176  "Distribution of RMS #phi (rad) residuals "
177  "for CSC;#phi RMS (rad);number of chambers",
178  100,
179  0,
180  rmsAngleRange);
181  hLocalThetaMeanCSC = dbe->book1D("hLocalThetaMeanCSC",
182  "Distribution of absolute MEAN #theta (rad) residuals "
183  "for CSC;<#theta>(rad);number of chambers",
184  100,
185  0,
187  hLocalThetaRmsCSC = dbe->book1D("hLocalThetaRmsCSC",
188  "Distribution of RMS #theta (rad) residuals for "
189  "CSC;#theta RMS (rad);number of chambers",
190  100,
191  0,
192  rmsAngleRange);
193  }
194  }
195 
196  // Chamber individual histograms
197  // I need to create all of them even if they are empty to allow proper root
198  // merging
199 
200  // variables for histos ranges
201  double rangeX = 0, rangeY = 0;
202  std::string nameOfHistoLocalX, nameOfHistoLocalY, nameOfHistoLocalPhi, nameOfHistoLocalTheta;
203 
204  for (int station = -4; station < 5; station++) {
205  // This piece of code calculates the range of the residuals
206  switch (abs(station)) {
207  case 1: {
208  rangeX = resLocalXRangeStation1;
209  rangeY = resLocalYRangeStation1;
210  } break;
211  case 2: {
212  rangeX = resLocalXRangeStation2;
213  rangeY = resLocalYRangeStation2;
214  } break;
215  case 3: {
216  rangeX = resLocalXRangeStation3;
217  rangeY = resLocalYRangeStation3;
218  } break;
219  case 4: {
220  rangeX = resLocalXRangeStation4;
221  rangeY = resLocalYRangeStation4;
222  } break;
223  default:
224  break;
225  }
226  if (doDT) {
227  if (station > 0) {
228  for (int wheel = -2; wheel < 3; wheel++) {
229  for (int sector = 1; sector < 15; sector++) {
230  if (!((sector == 13 || sector == 14) && station != 4)) {
231  std::stringstream Wheel;
232  Wheel << wheel;
233  std::stringstream Station;
234  Station << station;
235  std::stringstream Sector;
236  Sector << sector;
237 
238  nameOfHistoLocalX = "ResidualLocalX_W" + Wheel.str() + "MB" + Station.str() + "S" + Sector.str();
239  nameOfHistoLocalPhi = "ResidualLocalPhi_W" + Wheel.str() + "MB" + Station.str() + "S" + Sector.str();
240  nameOfHistoLocalTheta = "ResidualLocalTheta_W" + Wheel.str() + "MB" + Station.str() + "S" + Sector.str();
241  nameOfHistoLocalY = "ResidualLocalY_W" + Wheel.str() + "MB" + Station.str() + "S" + Sector.str();
242 
243  dbe->setCurrentFolder(topFolder.str() + "/DT/Wheel" + Wheel.str() + "/Station" + Station.str() +
244  "/Sector" + Sector.str());
245 
246  // Create ME and push histos into their respective vectors
247 
248  MonitorElement *histoLocalX = dbe->book1D(nameOfHistoLocalX, nameOfHistoLocalX, nbins, -rangeX, rangeX);
249  unitsLocalX.push_back(histoLocalX);
250  MonitorElement *histoLocalPhi =
251  dbe->book1D(nameOfHistoLocalPhi, nameOfHistoLocalPhi, nbins, -resPhiRange, resPhiRange);
252  unitsLocalPhi.push_back(histoLocalPhi);
253  MonitorElement *histoLocalTheta =
254  dbe->book1D(nameOfHistoLocalTheta, nameOfHistoLocalTheta, nbins, -resThetaRange, resThetaRange);
255  unitsLocalTheta.push_back(histoLocalTheta);
256  MonitorElement *histoLocalY = dbe->book1D(nameOfHistoLocalY, nameOfHistoLocalY, nbins, -rangeY, rangeY);
257  unitsLocalY.push_back(histoLocalY);
258  }
259  }
260  }
261  } // station>0
262  } // doDT
263 
264  if (doCSC) {
265  if (station != 0) {
266  for (int ring = 1; ring < 5; ring++) {
267  for (int chamber = 1; chamber < 37; chamber++) {
268  if (!(((abs(station) == 2 || abs(station) == 3 || abs(station) == 4) && ring == 1 && chamber > 18) ||
269  ((abs(station) == 2 || abs(station) == 3 || abs(station) == 4) && ring > 2))) {
270  std::stringstream Ring;
271  Ring << ring;
272  std::stringstream Station;
273  Station << station;
274  std::stringstream Chamber;
275  Chamber << chamber;
276 
277  nameOfHistoLocalX = "ResidualLocalX_ME" + Station.str() + "R" + Ring.str() + "C" + Chamber.str();
278  nameOfHistoLocalPhi = "ResidualLocalPhi_ME" + Station.str() + "R" + Ring.str() + "C" + Chamber.str();
279  nameOfHistoLocalTheta = "ResidualLocalTheta_ME" + Station.str() + "R" + Ring.str() + "C" + Chamber.str();
280  nameOfHistoLocalY = "ResidualLocalY_ME" + Station.str() + "R" + Ring.str() + "C" + Chamber.str();
281 
282  dbe->setCurrentFolder(topFolder.str() + "/CSC/Station" + Station.str() + "/Ring" + Ring.str() +
283  "/Chamber" + Chamber.str());
284 
285  // Create ME and push histos into their respective vectors
286 
287  MonitorElement *histoLocalX = dbe->book1D(nameOfHistoLocalX, nameOfHistoLocalX, nbins, -rangeX, rangeX);
288  unitsLocalX.push_back(histoLocalX);
289  MonitorElement *histoLocalPhi =
290  dbe->book1D(nameOfHistoLocalPhi, nameOfHistoLocalPhi, nbins, -resPhiRange, resPhiRange);
291  unitsLocalPhi.push_back(histoLocalPhi);
292  MonitorElement *histoLocalTheta =
293  dbe->book1D(nameOfHistoLocalTheta, nameOfHistoLocalTheta, nbins, -resThetaRange, resThetaRange);
294  unitsLocalTheta.push_back(histoLocalTheta);
295  MonitorElement *histoLocalY = dbe->book1D(nameOfHistoLocalY, nameOfHistoLocalY, nbins, -rangeY, rangeY);
296  unitsLocalY.push_back(histoLocalY);
297  }
298  }
299  }
300  } // station!=0
301  } // doCSC
302 
303  } // loop on stations
304 }
305 
307  LogTrace(metname) << "[MuonAlignment] Analysis of event # ";
308 
309  edm::ESHandle<MagneticField> theMGField;
310  iSetup.get<IdealMagneticFieldRecord>().get(theMGField);
311 
312  edm::ESHandle<GlobalTrackingGeometry> theTrackingGeometry;
313  iSetup.get<GlobalTrackingGeometryRecord>().get(theTrackingGeometry);
314 
315  edm::ESHandle<Propagator> thePropagatorOpp;
316  iSetup.get<TrackingComponentsRecord>().get("SmartPropagatorOpposite", thePropagatorOpp);
317 
318  edm::ESHandle<Propagator> thePropagatorAlo;
319  iSetup.get<TrackingComponentsRecord>().get("SmartPropagator", thePropagatorAlo);
320 
321  // edm::ESHandle<Propagator> thePropagator;
322  // iSetup.get<TrackingComponentsRecord>().get(
323  // "SmartPropagatorAnyOpposite", thePropagator );
324 
325  // Get the RecoMuons collection from the event
327  iEvent.getByToken(theMuonCollectionLabel, muons);
328 
329  // Get the 4D DTSegments
331  iEvent.getByToken(theRecHits4DTagDT, all4DSegmentsDT);
333 
334  // Get the 4D CSCSegments
335  edm::Handle<CSCSegmentCollection> all4DSegmentsCSC;
336  iEvent.getByToken(theRecHits4DTagCSC, all4DSegmentsCSC);
338 
339  // Vectors used to perform the matching between Segments and hits from Track
340  intDVector indexCollectionDT;
341  intDVector indexCollectionCSC;
342 
343  // thePropagator = new SteppingHelixPropagator(&*theMGField,
344  // alongMomentum);
345 
346  int countTracks = 0;
347  reco::TrackCollection::const_iterator muon;
348  for (muon = muons->begin(); muon != muons->end(); ++muon) {
349  // if(muon->isGlobalMuon()){
350  // if(muon->isStandAloneMuon()){
351 
352  int countPoints = 0;
353 
354  // reco::TrackRef trackTR = muon->innerTrack();
355  // reco::TrackRef trackSA = muon->outerTrack();
356  // reco::TrackRef trackSA = muon;
357 
358  if (muon->recHitsSize() > (min1DTrackRecHitSize - 1)) {
359  // reco::TransientTrack tTrackTR( *trackTR, &*theMGField,
360  // theTrackingGeometry );
361  reco::TransientTrack tTrackSA(*muon, &*theMGField, theTrackingGeometry);
362 
363  // Adapted code for muonCosmics
364 
365  Double_t innerPerpSA = tTrackSA.innermostMeasurementState().globalPosition().perp();
366  Double_t outerPerpSA = tTrackSA.outermostMeasurementState().globalPosition().perp();
367 
369  // PropagationDirection propagationDir=alongMomentum;
370  const Propagator *thePropagator;
371 
372  // Define which kind of reco track is used
373  if ((outerPerpSA - innerPerpSA) > 0) {
374  trackRefitterType = "LHCLike";
375  innerTSOS = tTrackSA.innermostMeasurementState();
376  thePropagator = thePropagatorAlo.product();
377  // propagationDir = alongMomentum;
378 
379  } else { // if ((outerPerpSA-innerPerpSA) < 0 ) {
380 
381  trackRefitterType = "CosmicLike";
382  innerTSOS = tTrackSA.outermostMeasurementState();
383  thePropagator = thePropagatorOpp.product();
384  // propagationDir = oppositeToMomentum;
385  }
386 
387  RecHitVector my4DTrack = this->doMatching(
388  *muon, all4DSegmentsDT, all4DSegmentsCSC, &indexCollectionDT, &indexCollectionCSC, theTrackingGeometry);
389 
390  // cut in number of segments
391  if (my4DTrack.size() > (min4DTrackSegmentSize - 1)) {
392  // start propagation
393  // TrajectoryStateOnSurface innerTSOS = track.impactPointState();
394  // TrajectoryStateOnSurface innerTSOS =
395  // track.innermostMeasurementState();
396 
397  // If the state is valid
398  if (innerTSOS.isValid()) {
399  // Loop over Associated segments
400  for (RecHitVector::iterator rechit = my4DTrack.begin(); rechit != my4DTrack.end(); ++rechit) {
401  const GeomDet *geomDet = theTrackingGeometry->idToDet((*rechit)->geographicalId());
402  // Otherwise the propagator could throw an exception
403  const Plane *pDest = dynamic_cast<const Plane *>(&geomDet->surface());
404  const Cylinder *cDest = dynamic_cast<const Cylinder *>(&geomDet->surface());
405 
406  if (pDest != nullptr || cDest != nullptr) {
407  // Propagator
408  //*updatePropagator=thePropagator->clone();
409  // updatePropagator->setPropagationDirection(propagationDir);
410  TrajectoryStateOnSurface destiny = thePropagator->propagate(*(innerTSOS.freeState()), geomDet->surface());
411 
412  if (!destiny.isValid() || !destiny.hasError())
413  continue;
414 
415  const long rawId = (*rechit)->geographicalId().rawId();
416  int position = -1;
417 
418  DetId myDet(rawId);
419  int det = myDet.subdetId();
420  int wheel = 0, station = 0, sector = 0;
421  int endcap = 0, ring = 0, chamber = 0;
422  bool goAhead = (det == 1 && doDT) || (det == 2 && doCSC);
423 
424  double residualLocalX = 0, residualLocalPhi = 0, residualLocalY = 0, residualLocalTheta = 0;
425 
426  // Fill generic histograms
427  // If it's a DT
428  if (det == 1 && doDT) {
429  DTChamberId myChamber(rawId);
430  wheel = myChamber.wheel();
431  station = myChamber.station();
432  sector = myChamber.sector();
433 
434  residualLocalX = (*rechit)->localPosition().x() - destiny.localPosition().x();
435 
436  residualLocalPhi = atan2(((RecSegment *)(*rechit))->localDirection().z(),
437  ((RecSegment *)(*rechit))->localDirection().x()) -
438  atan2(destiny.localDirection().z(), destiny.localDirection().x());
439  if (station != 4) {
440  residualLocalY = (*rechit)->localPosition().y() - destiny.localPosition().y();
441 
442  residualLocalTheta = atan2(((RecSegment *)(*rechit))->localDirection().z(),
443  ((RecSegment *)(*rechit))->localDirection().y()) -
444  atan2(destiny.localDirection().z(), destiny.localDirection().y());
445  }
446 
447  } else if (det == 2 && doCSC) {
448  CSCDetId myChamber(rawId);
449  endcap = myChamber.endcap();
450  station = myChamber.station();
451  if (endcap == 2)
452  station = -station;
453  ring = myChamber.ring();
454  chamber = myChamber.chamber();
455 
456  residualLocalX = (*rechit)->localPosition().x() - destiny.localPosition().x();
457 
458  residualLocalY = (*rechit)->localPosition().y() - destiny.localPosition().y();
459 
460  residualLocalPhi = atan2(((RecSegment *)(*rechit))->localDirection().y(),
461  ((RecSegment *)(*rechit))->localDirection().x()) -
462  atan2(destiny.localDirection().y(), destiny.localDirection().x());
463 
464  residualLocalTheta = atan2(((RecSegment *)(*rechit))->localDirection().y(),
465  ((RecSegment *)(*rechit))->localDirection().z()) -
466  atan2(destiny.localDirection().y(), destiny.localDirection().z());
467 
468  } else {
469  residualLocalX = 0, residualLocalPhi = 0, residualLocalY = 0, residualLocalTheta = 0;
470  }
471 
472  // Fill individual chamber histograms
473 
474  std::string nameOfHistoLocalX;
475 
476  if (det == 1 && doDT) { // DT
477  std::stringstream Wheel;
478  Wheel << wheel;
479  std::stringstream Station;
480  Station << station;
481  std::stringstream Sector;
482  Sector << sector;
483 
484  nameOfHistoLocalX = "ResidualLocalX_W" + Wheel.str() + "MB" + Station.str() + "S" + Sector.str();
485 
486  } else if (det == 2 && doCSC) { // CSC
487  std::stringstream Ring;
488  Ring << ring;
489  std::stringstream Station;
490  Station << station;
491  std::stringstream Chamber;
492  Chamber << chamber;
493 
494  nameOfHistoLocalX = "ResidualLocalX_ME" + Station.str() + "R" + Ring.str() + "C" + Chamber.str();
495  }
496 
497  if (goAhead) {
498  for (unsigned int i = 0; i < unitsLocalX.size(); i++) {
499  if (nameOfHistoLocalX == unitsLocalX[i]->getName()) {
500  position = i;
501  break;
502  }
503  }
504 
505  if (trackRefitterType == "CosmicLike") { // problem with angle convention in reverse
506  // extrapolation
507  residualLocalPhi += 3.1416;
508  residualLocalTheta += 3.1416;
509  }
510 
511  unitsLocalX.at(position)->Fill(residualLocalX);
512  unitsLocalPhi.at(position)->Fill(residualLocalPhi);
513 
514  if (det == 1 && station != 4) {
515  unitsLocalY.at(position)->Fill(residualLocalY);
516  unitsLocalTheta.at(position)->Fill(residualLocalTheta);
517  }
518 
519  else if (det == 2) {
520  unitsLocalY.at(position)->Fill(residualLocalY);
521  unitsLocalTheta.at(position)->Fill(residualLocalTheta);
522  }
523 
524  countPoints++;
525  // if at least one point from this track is used, count this
526  // track
527  if (countPoints == 1)
528  countTracks++;
529  }
530 
531  innerTSOS = destiny;
532 
533  // delete thePropagator;
534 
535  } else {
536  edm::LogError("MuonAlignment") << " Error!! Exception in propagator catched" << std::endl;
537  continue;
538  }
539 
540  } // loop over my4DTrack
541  } // TSOS was valid
542 
543  } // cut in at least 4 segments
544 
545  } // end cut in RecHitsSize>36
546  numberOfHits = numberOfHits + countPoints;
547  // } //Muon is GlobalMuon
548  } // loop over Muons
549  numberOfTracks = numberOfTracks + countTracks;
550 
551  // delete thePropagator;
552 
553  // else edm::LogError("MuonAlignment")<<"Error!! Specified MuonCollection
554  //"<< theMuonTrackCollectionLabel <<" is not present in event.
555  // ProductNotFound!!"<<std::endl;
556 }
557 
559  edm::Handle<DTRecSegment4DCollection> &all4DSegmentsDT,
560  edm::Handle<CSCSegmentCollection> &all4DSegmentsCSC,
561  intDVector *indexCollectionDT,
562  intDVector *indexCollectionCSC,
563  edm::ESHandle<GlobalTrackingGeometry> &theTrackingGeometry) {
566 
567  std::vector<int> positionDT;
568  std::vector<int> positionCSC;
569  RecHitVector my4DTrack;
570 
571  // Loop over the hits of the track
572  for (unsigned int counter = 0; counter != staTrack.recHitsSize() - 1; counter++) {
573  TrackingRecHitRef myRef = staTrack.recHit(counter);
574  const TrackingRecHit *rechit = myRef.get();
575  const GeomDet *geomDet = theTrackingGeometry->idToDet(rechit->geographicalId());
576 
577  // It's a DT Hit
578  if (geomDet->subDetector() == GeomDetEnumerators::DT) {
579  // Take the layer associated to this hit
580  DTLayerId myLayer(rechit->geographicalId().rawId());
581 
582  int NumberOfDTSegment = 0;
583  // Loop over segments
584  for (segmentDT = all4DSegmentsDT->begin(); segmentDT != all4DSegmentsDT->end(); ++segmentDT) {
585  // By default the chamber associated to this Segment is new
586  bool isNewChamber = true;
587 
588  // Loop over segments already included in the vector of segments in the
589  // actual track
590  for (std::vector<int>::iterator positionIt = positionDT.begin(); positionIt != positionDT.end(); positionIt++) {
591  // If this segment has been used before isNewChamber = false
592  if (NumberOfDTSegment == *positionIt)
593  isNewChamber = false;
594  }
595 
596  // Loop over vectors of segments associated to previous tracks
597  for (std::vector<std::vector<int>>::iterator collect = indexCollectionDT->begin();
598  collect != indexCollectionDT->end();
599  ++collect) {
600  // Loop over segments associated to a track
601  for (std::vector<int>::iterator positionIt = (*collect).begin(); positionIt != (*collect).end();
602  positionIt++) {
603  // If this segment was used in a previos track then isNewChamber =
604  // false
605  if (NumberOfDTSegment == *positionIt)
606  isNewChamber = false;
607  }
608  }
609 
610  // If the chamber is new
611  if (isNewChamber) {
612  DTChamberId myChamber((*segmentDT).geographicalId().rawId());
613  // If the layer of the hit belongs to the chamber of the 4D Segment
614  if (myLayer.wheel() == myChamber.wheel() && myLayer.station() == myChamber.station() &&
615  myLayer.sector() == myChamber.sector()) {
616  // push position of the segment and tracking rechit
617  positionDT.push_back(NumberOfDTSegment);
618  my4DTrack.push_back((TrackingRecHit *)&(*segmentDT));
619  }
620  }
621  NumberOfDTSegment++;
622  }
623  // In case is a CSC
624  } else if (geomDet->subDetector() == GeomDetEnumerators::CSC) {
625  // Take the layer associated to this hit
626  CSCDetId myLayer(rechit->geographicalId().rawId());
627 
628  int NumberOfCSCSegment = 0;
629  // Loop over 4Dsegments
630  for (segmentCSC = all4DSegmentsCSC->begin(); segmentCSC != all4DSegmentsCSC->end(); segmentCSC++) {
631  // By default the chamber associated to the segment is new
632  bool isNewChamber = true;
633 
634  // Loop over segments in the current track
635  for (std::vector<int>::iterator positionIt = positionCSC.begin(); positionIt != positionCSC.end();
636  positionIt++) {
637  // If this segment has been used then newchamber = false
638  if (NumberOfCSCSegment == *positionIt)
639  isNewChamber = false;
640  }
641  // Loop over vectors of segments in previous tracks
642  for (std::vector<std::vector<int>>::iterator collect = indexCollectionCSC->begin();
643  collect != indexCollectionCSC->end();
644  ++collect) {
645  // Loop over segments in a track
646  for (std::vector<int>::iterator positionIt = (*collect).begin(); positionIt != (*collect).end();
647  positionIt++) {
648  // If the segment was used in a previous track isNewChamber = false
649  if (NumberOfCSCSegment == *positionIt)
650  isNewChamber = false;
651  }
652  }
653  // If the chamber is new
654  if (isNewChamber) {
655  CSCDetId myChamber((*segmentCSC).geographicalId().rawId());
656  // If the chambers are the same
657  if (myLayer.chamberId() == myChamber.chamberId()) {
658  // push
659  positionCSC.push_back(NumberOfCSCSegment);
660  my4DTrack.push_back((TrackingRecHit *)&(*segmentCSC));
661  }
662  }
663  NumberOfCSCSegment++;
664  }
665  }
666  }
667 
668  indexCollectionDT->push_back(positionDT);
669  indexCollectionCSC->push_back(positionCSC);
670 
671  if (trackRefitterType == "CosmicLike") {
672  std::reverse(my4DTrack.begin(), my4DTrack.end());
673  }
674  return my4DTrack;
675 }
676 
678  LogTrace(metname) << "[MuonAlignment] Saving the histos";
679  bool outputMEsInRootFile = parameters.getParameter<bool>("OutputMEsInRootFile");
680  std::string outputFileName = parameters.getParameter<std::string>("OutputFileName");
681 
682  edm::LogInfo("MuonAlignment") << "Number of Tracks considered for residuals: " << numberOfTracks << std::endl
683  << std::endl;
684  edm::LogInfo("MuonAlignment") << "Number of Hits considered for residuals: " << numberOfHits << std::endl
685  << std::endl;
686 
687  if (doSummary) {
688  char binLabel[15];
689 
690  // check if ME still there (and not killed by MEtoEDM for memory saving)
691  if (dbe) {
692  // check existence of first histo in the list
693  if (!dbe->get(topFolder.str() + "/DT/hLocalPositionDT"))
694  return;
695  } else
696  return;
697 
698  for (unsigned int i = 0; i < unitsLocalX.size(); i++) {
699  if (unitsLocalX[i]->getEntries() != 0) {
700  TString nameHistoLocalX = unitsLocalX[i]->getName();
701 
702  TString nameHistoLocalPhi = unitsLocalPhi[i]->getName();
703 
704  TString nameHistoLocalTheta = unitsLocalTheta[i]->getName();
705 
706  TString nameHistoLocalY = unitsLocalY[i]->getName();
707 
708  if (nameHistoLocalX.Contains("MB")) // HistoLocalX DT
709  {
710  int wheel, station, sector;
711 
712  sscanf(nameHistoLocalX, "ResidualLocalX_W%dMB%1dS%d", &wheel, &station, &sector);
713 
714  Int_t nstation = station - 1;
715  Int_t nwheel = wheel + 2;
716 
717  Double_t Mean = unitsLocalX[i]->getMean();
718  Double_t Error = unitsLocalX[i]->getMeanError();
719 
720  Int_t ybin = 1 + nwheel * 8 + nstation * 2;
721  hLocalPositionDT->setBinContent(sector, ybin, fabs(Mean));
722  snprintf(binLabel, sizeof(binLabel), "MB%d/%d_X", wheel, station);
723  hLocalPositionDT->setBinLabel(ybin, binLabel, 2);
724  hLocalPositionRmsDT->setBinContent(sector, ybin, Error);
725  hLocalPositionRmsDT->setBinLabel(ybin, binLabel, 2);
726 
727  hLocalXMeanDT->Fill(fabs(Mean));
728  hLocalXRmsDT->Fill(Error);
729  }
730 
731  if (nameHistoLocalX.Contains("ME")) // HistoLocalX CSC
732  {
733  int station, ring, chamber;
734 
735  sscanf(nameHistoLocalX, "ResidualLocalX_ME%dR%1dC%d", &station, &ring, &chamber);
736 
737  Double_t Mean = unitsLocalX[i]->getMean();
738  Double_t Error = unitsLocalX[i]->getMeanError();
739 
740  Int_t ybin = abs(station) * 2 + ring;
741  if (abs(station) == 1)
742  ybin = ring;
743  if (station > 0)
744  ybin = ybin + 10;
745  else
746  ybin = 11 - ybin;
747  ybin = 2 * ybin - 1;
748  hLocalPositionCSC->setBinContent(chamber, ybin, fabs(Mean));
749  snprintf(binLabel, sizeof(binLabel), "ME%d/%d_X", station, ring);
750  hLocalPositionCSC->setBinLabel(ybin, binLabel, 2);
751  hLocalPositionRmsCSC->setBinContent(chamber, ybin, Error);
752  hLocalPositionRmsCSC->setBinLabel(ybin, binLabel, 2);
753 
754  hLocalXMeanCSC->Fill(fabs(Mean));
755  hLocalXRmsCSC->Fill(Error);
756  }
757 
758  if (nameHistoLocalTheta.Contains("MB")) // HistoLocalTheta DT
759  {
760  int wheel, station, sector;
761 
762  sscanf(nameHistoLocalTheta, "ResidualLocalTheta_W%dMB%1dS%d", &wheel, &station, &sector);
763 
764  if (station != 4) {
765  Int_t nstation = station - 1;
766  Int_t nwheel = wheel + 2;
767 
768  Double_t Mean = unitsLocalTheta[i]->getMean();
769  Double_t Error = unitsLocalTheta[i]->getMeanError();
770 
771  Int_t ybin = 2 + nwheel * 8 + nstation * 2;
772  hLocalAngleDT->setBinContent(sector, ybin, fabs(Mean));
773  snprintf(binLabel, sizeof(binLabel), "MB%d/%d_#theta", wheel, station);
774  hLocalAngleDT->setBinLabel(ybin, binLabel, 2);
775  hLocalAngleRmsDT->setBinContent(sector, ybin, Error);
776  hLocalAngleRmsDT->setBinLabel(ybin, binLabel, 2);
777 
778  hLocalThetaMeanDT->Fill(fabs(Mean));
779  hLocalThetaRmsDT->Fill(Error);
780  }
781  }
782 
783  if (nameHistoLocalPhi.Contains("MB")) // HistoLocalPhi DT
784  {
785  int wheel, station, sector;
786 
787  sscanf(nameHistoLocalPhi, "ResidualLocalPhi_W%dMB%1dS%d", &wheel, &station, &sector);
788 
789  Int_t nstation = station - 1;
790  Int_t nwheel = wheel + 2;
791 
792  Double_t Mean = unitsLocalPhi[i]->getMean();
793  Double_t Error = unitsLocalPhi[i]->getMeanError();
794 
795  Int_t ybin = 1 + nwheel * 8 + nstation * 2;
796  hLocalAngleDT->setBinContent(sector, ybin, fabs(Mean));
797  snprintf(binLabel, sizeof(binLabel), "MB%d/%d_#phi", wheel, station);
798  hLocalAngleDT->setBinLabel(ybin, binLabel, 2);
799  hLocalAngleRmsDT->setBinContent(sector, ybin, Error);
800  hLocalAngleRmsDT->setBinLabel(ybin, binLabel, 2);
801 
802  hLocalPhiMeanDT->Fill(fabs(Mean));
803  hLocalPhiRmsDT->Fill(Error);
804  }
805 
806  if (nameHistoLocalPhi.Contains("ME")) // HistoLocalPhi CSC
807  {
808  int station, ring, chamber;
809 
810  sscanf(nameHistoLocalPhi, "ResidualLocalPhi_ME%dR%1dC%d", &station, &ring, &chamber);
811 
812  Double_t Mean = unitsLocalPhi[i]->getMean();
813  Double_t Error = unitsLocalPhi[i]->getMeanError();
814 
815  Int_t ybin = abs(station) * 2 + ring;
816  if (abs(station) == 1)
817  ybin = ring;
818  if (station > 0)
819  ybin = ybin + 10;
820  else
821  ybin = 11 - ybin;
822  ybin = 2 * ybin - 1;
823  hLocalAngleCSC->setBinContent(chamber, ybin, fabs(Mean));
824  snprintf(binLabel, sizeof(binLabel), "ME%d/%d_#phi", station, ring);
825  hLocalAngleCSC->setBinLabel(ybin, binLabel, 2);
826  hLocalAngleRmsCSC->setBinContent(chamber, ybin, Error);
827  hLocalAngleRmsCSC->setBinLabel(ybin, binLabel, 2);
828 
829  hLocalPhiMeanCSC->Fill(fabs(Mean));
830  hLocalPhiRmsCSC->Fill(Error);
831  }
832 
833  if (nameHistoLocalTheta.Contains("ME")) // HistoLocalTheta CSC
834  {
835  int station, ring, chamber;
836 
837  sscanf(nameHistoLocalTheta, "ResidualLocalTheta_ME%dR%1dC%d", &station, &ring, &chamber);
838 
839  Double_t Mean = unitsLocalTheta[i]->getMean();
840  Double_t Error = unitsLocalTheta[i]->getMeanError();
841 
842  Int_t ybin = abs(station) * 2 + ring;
843  if (abs(station) == 1)
844  ybin = ring;
845  if (station > 0)
846  ybin = ybin + 10;
847  else
848  ybin = 11 - ybin;
849  ybin = 2 * ybin;
850  hLocalAngleCSC->setBinContent(chamber, ybin, fabs(Mean));
851  snprintf(binLabel, sizeof(binLabel), "ME%d/%d_#theta", station, ring);
852  hLocalAngleCSC->setBinLabel(ybin, binLabel, 2);
853  hLocalAngleRmsCSC->setBinContent(chamber, ybin, Error);
854  hLocalAngleRmsCSC->setBinLabel(ybin, binLabel, 2);
855 
856  hLocalThetaMeanCSC->Fill(fabs(Mean));
857  hLocalThetaRmsCSC->Fill(Error);
858  }
859 
860  if (nameHistoLocalY.Contains("MB")) // HistoLocalY DT
861  {
862  int wheel, station, sector;
863 
864  sscanf(nameHistoLocalY, "ResidualLocalY_W%dMB%1dS%d", &wheel, &station, &sector);
865 
866  if (station != 4) {
867  Int_t nstation = station - 1;
868  Int_t nwheel = wheel + 2;
869 
870  Double_t Mean = unitsLocalY[i]->getMean();
871  Double_t Error = unitsLocalY[i]->getMeanError();
872 
873  Int_t ybin = 2 + nwheel * 8 + nstation * 2;
874  hLocalPositionDT->setBinContent(sector, ybin, fabs(Mean));
875  snprintf(binLabel, sizeof(binLabel), "MB%d/%d_Y", wheel, station);
876  hLocalPositionDT->setBinLabel(ybin, binLabel, 2);
877  hLocalPositionRmsDT->setBinContent(sector, ybin, Error);
878  hLocalPositionRmsDT->setBinLabel(ybin, binLabel, 2);
879 
880  hLocalYMeanDT->Fill(fabs(Mean));
881  hLocalYRmsDT->Fill(Error);
882  }
883  }
884 
885  if (nameHistoLocalY.Contains("ME")) // HistoLocalY CSC
886  {
887  int station, ring, chamber;
888 
889  sscanf(nameHistoLocalY, "ResidualLocalY_ME%dR%1dC%d", &station, &ring, &chamber);
890 
891  Double_t Mean = unitsLocalY[i]->getMean();
892  Double_t Error = unitsLocalY[i]->getMeanError();
893 
894  Int_t ybin = abs(station) * 2 + ring;
895  if (abs(station) == 1)
896  ybin = ring;
897  if (station > 0)
898  ybin = ybin + 10;
899  else
900  ybin = 11 - ybin;
901  ybin = 2 * ybin;
902  hLocalPositionCSC->setBinContent(chamber, ybin, fabs(Mean));
903  snprintf(binLabel, sizeof(binLabel), "ME%d/%d_Y", station, ring);
904  hLocalPositionCSC->setBinLabel(ybin, binLabel, 2);
905  hLocalPositionRmsCSC->setBinContent(chamber, ybin, Error);
906  hLocalPositionRmsCSC->setBinLabel(ybin, binLabel, 2);
907 
908  hLocalYMeanCSC->Fill(fabs(Mean));
909  hLocalYRmsCSC->Fill(Error);
910  }
911  } // check in # entries
912  } // loop on vector of histos
913  } // doSummary
914 
915  if (outputMEsInRootFile) {
916  // dbe->showDirStructure();
917  dbe->save(outputFileName);
918  }
919 }
MonitorElement * hLocalPhiRmsDT
Definition: MuonAlignment.h:96
MonitorElement * book2D(char_string const &name, char_string const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:1173
edm::EDGetTokenT< CSCSegmentCollection > theRecHits4DTagCSC
int chamber() const
Definition: CSCDetId.h:68
std::vector< MonitorElement * > unitsLocalX
edm::ErrorSummaryEntry Error
MonitorElement * hLocalPositionRmsDT
Definition: MuonAlignment.h:87
void analyze(const edm::Event &, const edm::EventSetup &) override
Get the analysis.
MonitorElement * hLocalThetaMeanCSC
MonitorElement * hLocalYMeanDT
Definition: MuonAlignment.h:93
void beginJob() override
Inizialize parameters for histo binning.
void setBinContent(int binx, double content)
set content of bin (1-D)
RecHitVector doMatching(const reco::Track &, edm::Handle< DTRecSegment4DCollection > &, edm::Handle< CSCSegmentCollection > &, intDVector *, intDVector *, edm::ESHandle< GlobalTrackingGeometry > &)
MonitorElement * hLocalPhiRmsCSC
double resLocalYRangeStation2
T perp() const
Definition: PV3DBase.h:72
DQMStore * dbe
Definition: MuonAlignment.h:84
MonitorElement * hLocalYRmsCSC
MonitorElement * hLocalPositionCSC
double resLocalXRangeStation1
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
MonitorElement * hLocalXMeanDT
Definition: MuonAlignment.h:91
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
Definition: Track.h:124
LocalVector localDirection() const
double resLocalYRangeStation1
std::string trackRefitterType
double resPhiRange
MonitorElement * hLocalPhiMeanDT
Definition: MuonAlignment.h:95
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
T y() const
Definition: PV3DBase.h:63
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
GlobalPoint globalPosition() const
edm::EDGetTokenT< reco::TrackCollection > theMuonCollectionLabel
MonitorElement * book1D(char_string const &name, char_string const &title, int const nchX, double const lowX, double const highX)
Book 1D histogram.
Definition: DQMStore.cc:1098
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
double meanAngleRange
Definition: Plane.h:17
std::vector< TrackingRecHit * > RecHitVector
MuonAlignment(const edm::EventSetup &iSetup)
double resThetaRange
TrajectoryStateOnSurface innermostMeasurementState() const
void endJob(void) override
Save the histos.
MonitorElement * hLocalAngleRmsCSC
void Fill(long long x)
int endcap() const
Definition: CSCDetId.h:93
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
int iEvent
Definition: GenABIO.cc:224
std::string MEFolderName
MonitorElement * hLocalAngleRmsDT
Definition: MuonAlignment.h:89
double resLocalXRangeStation2
MonitorElement * get(std::string const &path) const
get ME from full pathname (e.g. "my/long/dir/my_histo")
Definition: DQMStore.cc:1613
FreeTrajectoryState const * freeState(bool withErrors=true) const
T z() const
Definition: PV3DBase.h:64
std::string metname
MonitorElement * hLocalAngleDT
Definition: MuonAlignment.h:88
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
MonitorElement * hLocalThetaRmsDT
Definition: MuonAlignment.h:98
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< MonitorElement * > unitsLocalTheta
MonitorElement * hLocalYRmsDT
Definition: MuonAlignment.h:94
MonitorElement * hLocalThetaRmsCSC
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:243
TrajectoryStateOnSurface outermostMeasurementState() const
MonitorElement * hLocalXMeanCSC
MonitorElement * hLocalYMeanCSC
#define LogTrace(id)
unsigned int nbins
std::vector< MonitorElement * > unitsLocalPhi
double rmsPositionRange
int ring() const
Definition: CSCDetId.h:75
Definition: DetId.h:18
std::vector< std::vector< int > > intDVector
TString getName(TString structure, int layer, TString geometry)
Definition: DMRtrends.cc:167
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:571
double rmsAngleRange
std::vector< MonitorElement * > unitsLocalY
MonitorElement * hLocalPhiMeanCSC
edm::EDGetTokenT< DTRecSegment4DCollection > theRecHits4DTagDT
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:53
MonitorElement * hLocalAngleCSC
double resLocalYRangeStation3
void save(std::string const &filename, std::string const &path="", std::string const &pattern="", std::string const &rewrite="", uint32_t run=0, uint32_t lumi=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, std::string const &fileupdate="RECREATE")
Definition: DQMStore.cc:2465
MonitorElement * hLocalXRmsDT
Definition: MuonAlignment.h:92
unsigned int min1DTrackRecHitSize
double resLocalYRangeStation4
double meanPositionRange
int sector() const
Definition: DTChamberId.h:61
MonitorElement * hLocalPositionRmsCSC
static int position[264][3]
Definition: ReadPGInfo.cc:509
TrackingRecHitRef recHit(size_t i) const
Get i-th hit on the track.
Definition: Track.h:119
T get() const
Definition: EventSetup.h:71
const GeomDet * idToDet(DetId) const override
int station() const
Definition: CSCDetId.h:86
DetId geographicalId() const
MonitorElement * hLocalXRmsCSC
int station() const
Return the station number.
Definition: DTChamberId.h:51
unsigned int min4DTrackSegmentSize
virtual SubDetector subDetector() const
Which subdetector.
Definition: GeomDet.cc:44
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45
std::stringstream topFolder
T x() const
Definition: PV3DBase.h:62
T const * product() const
Definition: ESHandle.h:86
MonitorElement * hLocalThetaMeanDT
Definition: MuonAlignment.h:97
MonitorElement * hLocalPositionDT
Definition: MuonAlignment.h:86
double resLocalXRangeStation4
double resLocalXRangeStation3