CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OverlapValidation.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Alignment/OfflineValidation
4 // Class: OverlapValidation
5 //
11 //
12 // Original Authors: Wolfgang Adam, Keith Ulmer
13 // Created: Thu Oct 11 14:53:32 CEST 2007
14 // $Id: OverlapValidation.cc,v 1.16 2009/11/04 19:40:27 kaulmer Exp $
15 //
16 //
17 
18 // system include files
19 #include <memory>
20 
21 // user include files
24 
31 
39 
43 
49 
67 
77 #include "TFile.h"
78 #include "TTree.h"
79 
80 #include <vector>
81 #include <utility>
82 
83 using namespace std;
84 //
85 // class decleration
86 //
87 
89 public:
90  explicit OverlapValidation(const edm::ParameterSet&);
91  ~OverlapValidation() override;
92 
93 private:
94  typedef vector<Trajectory> TrajectoryCollection;
95 
98  void analyze(const edm::Event&, const edm::EventSetup&) override;
99  void endJob() override;
100 
101  virtual void analyzeTrajectory(const Trajectory&,
102  const Propagator&,
104  const TrackerTopology* const tTopo);
105  int layerFromId(const DetId&, const TrackerTopology* const tTopo) const;
106 
107  // ----------member data ---------------------------
108 
112 
116  bool doSimHit_;
119 
121  int overlapCounts_[3];
122 
123  TTree* rootTree_;
126  const bool addExtraBranches_;
127  const int minHitsCut_;
128  const float chi2ProbCut_;
129 
132  unsigned short hitCounts_[2];
133  float chi2_[2];
134  unsigned int overlapIds_[2];
135  float predictedPositions_[3][2];
136  float predictedLocalParameters_[5][2];
137  float predictedLocalErrors_[5][2];
142  float hitPositions_[2];
143  float hitErrors_[2];
144  float hitPositionsY_[2];
145  float hitErrorsY_[2];
146  float simHitPositions_[2];
147  float simHitPositionsY_[2];
148  float clusterWidthX_[2];
149  float clusterWidthY_[2];
150  float clusterSize_[2];
152  int edge_[2];
153 
154  vector<bool> acceptLayer;
155  float momentum_;
158 
159  //added by Heshy and Jared
160  float moduleX_[2];
161  float moduleY_[2];
162  float moduleZ_[2];
163  int subdetID;
167  //added by Jason
168  float localxdotglobalphi_[2];
169  float localxdotglobalr_[2];
170  float localxdotglobalz_[2];
171  float localxdotglobalx_[2];
172  float localxdotglobaly_[2];
173  float localydotglobalphi_[2];
174  float localydotglobalr_[2];
175  float localydotglobalz_[2];
176  float localydotglobalx_[2];
177  float localydotglobaly_[2];
178 };
179 
180 //
181 // constants, enums and typedefs
182 //
183 
184 //
185 // static data member definitions
186 //
187 
188 using std::vector;
189 //
190 // constructors and destructor
191 //
193  : geomToken_(esConsumes()),
194  magFieldToken_(esConsumes()),
195  topoToken_(esConsumes()),
196  config_(iConfig),
197  rootTree_(nullptr),
198  FileInPath_(SiStripDetInfoFileReader::kDefaultFile),
199  compressionSettings_(iConfig.getUntrackedParameter<int>("compressionSettings", -1)),
200  addExtraBranches_(false),
201  minHitsCut_(6),
202  chi2ProbCut_(0.001) {
204  //now do what ever initialization is needed
205  trajectoryTag_ = iConfig.getParameter<edm::InputTag>("trajectories");
207  doSimHit_ = iConfig.getParameter<bool>("associateStrip");
209 
210  overlapCounts_[0] = 0; // #trajectories
211  overlapCounts_[1] = 0; // #hits
212  overlapCounts_[2] = 0; // #overlap hits
213  acceptLayer.resize(7, false);
214  acceptLayer[PixelSubdetector::PixelBarrel] = iConfig.getParameter<bool>("usePXB");
215  acceptLayer[PixelSubdetector::PixelEndcap] = iConfig.getParameter<bool>("usePXF");
216  acceptLayer[StripSubdetector::TIB] = iConfig.getParameter<bool>("useTIB");
217  acceptLayer[StripSubdetector::TOB] = iConfig.getParameter<bool>("useTOB");
218  acceptLayer[StripSubdetector::TID] = iConfig.getParameter<bool>("useTID");
219  acceptLayer[StripSubdetector::TEC] = iConfig.getParameter<bool>("useTEC");
220  barrelOnly_ = iConfig.getParameter<bool>("barrelOnly");
221 
223  //
224  // root output
225  //
226  if (compressionSettings_ > 0) {
227  fs->file().SetCompressionSettings(compressionSettings_);
228  }
229 
230  rootTree_ = fs->make<TTree>("Overlaps", "Overlaps");
231  if (addExtraBranches_) {
232  rootTree_->Branch("hitCounts", hitCounts_, "found/s:lost/s");
233  rootTree_->Branch("chi2", chi2_, "chi2/F:ndf/F");
234  rootTree_->Branch("path", &overlapPath_, "path/F");
235  }
236  rootTree_->Branch("layer", &layer_, "layer/i");
237  rootTree_->Branch("detids", overlapIds_, "id[2]/i");
238  rootTree_->Branch("predPos", predictedPositions_, "gX[2]/F:gY[2]/F:gZ[2]/F");
239  rootTree_->Branch("predPar", predictedLocalParameters_, "predQP[2]/F:predDX[2]/F:predDY[2]/F:predX[2]/F:predY[2]/F");
240  rootTree_->Branch("predErr", predictedLocalErrors_, "predEQP[2]/F:predEDX[2]/F:predEDY[2]/F:predEX[2]/F:predEY[2]/F");
241  rootTree_->Branch("predEDeltaX", &predictedDeltaXError_, "sigDeltaX/F");
242  rootTree_->Branch("predEDeltaY", &predictedDeltaYError_, "sigDeltaY/F");
243  rootTree_->Branch("relSignX", &relativeXSign_, "relSignX/B");
244  rootTree_->Branch("relSignY", &relativeYSign_, "relSignY/B");
245  rootTree_->Branch("hitX", hitPositions_, "hitX[2]/F");
246  rootTree_->Branch("hitEX", hitErrors_, "hitEX[2]/F");
247  rootTree_->Branch("hitY", hitPositionsY_, "hitY[2]/F");
248  rootTree_->Branch("hitEY", hitErrorsY_, "hitEY[2]/F");
249  if (addExtraBranches_) {
250  rootTree_->Branch("simX", simHitPositions_, "simX[2]/F");
251  rootTree_->Branch("simY", simHitPositionsY_, "simY[2]/F");
252  rootTree_->Branch("clusterSize", clusterSize_, "clusterSize[2]/F");
253  rootTree_->Branch("clusterWidthX", clusterWidthX_, "clusterWidthX[2]/F");
254  rootTree_->Branch("clusterWidthY", clusterWidthY_, "clusterWidthY[2]/F");
255  rootTree_->Branch("clusterCharge", clusterCharge_, "clusterCharge[2]/i");
256  rootTree_->Branch("edge", edge_, "edge[2]/I");
257  }
258  rootTree_->Branch("momentum", &momentum_, "momentum/F");
259  rootTree_->Branch("run", &run_, "run/i");
260  rootTree_->Branch("event", &event_, "event/i");
261  rootTree_->Branch("subdetID", &subdetID, "subdetID/I");
262  rootTree_->Branch("moduleX", moduleX_, "moduleX[2]/F");
263  rootTree_->Branch("moduleY", moduleY_, "moduleY[2]/F");
264  rootTree_->Branch("moduleZ", moduleZ_, "moduleZ[2]/F");
265  rootTree_->Branch("localxdotglobalphi", localxdotglobalphi_, "localxdotglobalphi[2]/F");
266  rootTree_->Branch("localxdotglobalr", localxdotglobalr_, "localxdotglobalr[2]/F");
267  rootTree_->Branch("localxdotglobalz", localxdotglobalz_, "localxdotglobalz[2]/F");
268  rootTree_->Branch("localxdotglobalx", localxdotglobalx_, "localxdotglobalx[2]/F");
269  rootTree_->Branch("localxdotglobaly", localxdotglobaly_, "localxdotglobaly[2]/F");
270  rootTree_->Branch("localydotglobalphi", localydotglobalphi_, "localydotglobalphi[2]/F");
271  rootTree_->Branch("localydotglobalr", localydotglobalr_, "localydotglobalr[2]/F");
272  rootTree_->Branch("localydotglobalz", localydotglobalz_, "localydotglobalz[2]/F");
273  rootTree_->Branch("localydotglobalx", localydotglobalx_, "localydotglobalx[2]/F");
274  rootTree_->Branch("localydotglobaly", localydotglobaly_, "localydotglobaly[2]/F");
275 }
276 
278  edm::LogWarning w("Overlaps");
279  // do anything here that needs to be done at desctruction time
280  // (e.g. close files, deallocate resources etc.)
281 
282  w << "Counters =";
283  w << " Number of tracks: " << overlapCounts_[0];
284  w << " Number of valid hits: " << overlapCounts_[1];
285  w << " Number of overlaps: " << overlapCounts_[2];
286 }
287 
288 //
289 // member functions
290 //
291 
292 // ------------ method called to for each event ------------
294  using namespace edm;
295  //
296  // mag field & search tracker
297  //
298  magField_ = &iSetup.getData(magFieldToken_);
299  //
300  // propagator
301  //
303  //
304  // geometry
305  //
307  //
308  // make associator for SimHits
309  //
310  TrackerHitAssociator* associator;
311  if (doSimHit_) {
313  associator = new TrackerHitAssociator(iEvent, hitassociatorconfig);
314  } else {
315  associator = nullptr;
316  }
317 
318  //if(doSimHit_) associator = new TrackerHitAssociator(iEvent, config_); else associator = 0;
319 
320  //
321  // trajectories (from refit)
322  //
323  //typedef vector<Trajectory> TrajectoryCollection;
324  edm::Handle<TrajectoryCollection> trajectoryCollectionHandle;
325  iEvent.getByToken(trajectoryToken_, trajectoryCollectionHandle);
326  const TrajectoryCollection* const trajectoryCollection = trajectoryCollectionHandle.product();
327 
328  //
329  // loop over trajectories from refit
330  const TrackerTopology* const tTopo = &iSetup.getData(topoToken_);
331  for (const auto& trajectory : *trajectoryCollection)
332  analyzeTrajectory(trajectory, propagator, *associator, tTopo);
333 
334  run_ = iEvent.id().run();
335  event_ = iEvent.id().event();
336 }
337 
339  const Propagator& propagator,
340  TrackerHitAssociator& associator,
341  const TrackerTopology* const tTopo) {
342  typedef std::pair<const TrajectoryMeasurement*, const TrajectoryMeasurement*> Overlap;
343  typedef vector<Overlap> OverlapContainer;
344  ++overlapCounts_[0];
345 
346  OverlapContainer overlapHits;
347 
348  // quality cuts on trajectory
349  // min. # hits / matched hits
350 
351  if (trajectory.foundHits() < minHitsCut_)
352  return;
353  if (ChiSquaredProbability((double)(trajectory.chiSquared()), (double)(trajectory.ndof(false))) < chi2ProbCut_)
354  return;
355  //
356  // loop over measurements in the trajectory and calculate residuals
357  //
358 
359  vector<TrajectoryMeasurement> measurements(trajectory.measurements());
360  for (vector<TrajectoryMeasurement>::const_iterator itm = measurements.begin(); itm != measurements.end(); ++itm) {
361  //
362  // skip "invalid" (i.e. missing) hits
363  //
364  ConstRecHitPointer hit = itm->recHit();
365  DetId id = hit->geographicalId();
366  int layer(layerFromId(id, tTopo));
367  int subDet = id.subdetId();
368 
369  if (!hit->isValid()) {
370  edm::LogVerbatim("OverlapValidation") << "Invalid";
371  continue;
372  }
373  if (barrelOnly_ && (subDet == StripSubdetector::TID || subDet == StripSubdetector::TEC))
374  return;
375 
376  //edm::LogVerbatim("OverlapValidation") << "Check " <<subDet << ", layer = " << layer<<" stereo: "<< ((subDet > 2)?(SiStripDetId(id).stereo()):2);
377  //cout << "Check SubID " <<subDet << ", layer = " << layer<<" stereo: "<< ((subDet > 2)?(SiStripDetId(id).stereo()):2) << endl;
378 
379  //
380  // check for overlap: same subdet-id && layer number for
381  // two consecutive hits
382  //
383  ++overlapCounts_[1];
384  if ((layer != -1) && (acceptLayer[subDet])) {
385  for (vector<TrajectoryMeasurement>::const_iterator itmCompare = itm - 1;
386  itmCompare >= measurements.begin() && itmCompare > itm - 4;
387  --itmCompare) {
388  DetId compareId = itmCompare->recHit()->geographicalId();
389 
390  if (subDet != compareId.subdetId() || layer != layerFromId(compareId, tTopo))
391  break;
392  if (!itmCompare->recHit()->isValid())
393  continue;
394  if ((subDet == PixelSubdetector::PixelBarrel || subDet == PixelSubdetector::PixelEndcap) ||
395  (SiStripDetId(id).stereo() == SiStripDetId(compareId).stereo())) {
396  overlapHits.push_back(std::make_pair(&(*itmCompare), &(*itm)));
397  //edm::LogVerbatim("OverlapValidation") << "adding pair "<< ((subDet > 2)?(SiStripDetId(id).stereo()) : 2)
398  // << " from layer = " << layer;
399  //cout << "adding pair "<< ((subDet > 2)?(SiStripDetId(id).stereo()) : 2) << " from subDet = " << subDet << " and layer = " << layer;
400  //cout << " \t"<<run_<< "\t"<<event_<<"\t";
401  //cout << min(id.rawId(),compareId.rawId())<<"\t"<<max(id.rawId(),compareId.rawId())<<endl;
402  if (SiStripDetId(id).glued() == id.rawId())
403  edm::LogInfo("Overlaps") << "BAD GLUED: Have glued layer with id = " << id.rawId()
404  << " and glued id = " << SiStripDetId(id).glued()
405  << " and stereo = " << SiStripDetId(id).stereo() << endl;
406  if (SiStripDetId(compareId).glued() == compareId.rawId())
407  edm::LogInfo("Overlaps") << "BAD GLUED: Have glued layer with id = " << compareId.rawId()
408  << " and glued id = " << SiStripDetId(compareId).glued()
409  << " and stereo = " << SiStripDetId(compareId).stereo() << endl;
410  break;
411  }
412  }
413  }
414  }
415 
416  //
417  // Loop over all overlap pairs.
418  //
419  hitCounts_[0] = trajectory.foundHits();
420  hitCounts_[1] = trajectory.lostHits();
421  chi2_[0] = trajectory.chiSquared();
422  chi2_[1] = trajectory.ndof(false);
423 
424  for (const auto& overlapHit : overlapHits) {
425  //
426  // create reference state @ module 1 (no info from overlap hits)
427  //
428  ++overlapCounts_[2];
429  // backward predicted state at module 1
430  TrajectoryStateOnSurface bwdPred1 = overlapHit.first->backwardPredictedState();
431  if (!bwdPred1.isValid())
432  continue;
433  //cout << "momentum from backward predicted state = " << bwdPred1.globalMomentum().mag() << endl;
434  // forward predicted state at module 2
435  TrajectoryStateOnSurface fwdPred2 = overlapHit.second->forwardPredictedState();
436  //cout << "momentum from forward predicted state = " << fwdPred2.globalMomentum().mag() << endl;
437  if (!fwdPred2.isValid())
438  continue;
439  // extrapolate fwdPred2 to module 1
440  TrajectoryStateOnSurface fwdPred2At1 = propagator.propagate(fwdPred2, bwdPred1.surface());
441  if (!fwdPred2At1.isValid())
442  continue;
443  // combine fwdPred2At1 with bwdPred1 (ref. state, best estimate without hits 1 and 2)
444  TrajectoryStateOnSurface comb1 = combiner_.combine(bwdPred1, fwdPred2At1);
445  if (!comb1.isValid())
446  continue;
447  //
448  // propagation of reference parameters to module 2
449  //
450  std::pair<TrajectoryStateOnSurface, double> tsosWithS = propagator.propagateWithPath(comb1, fwdPred2.surface());
451  TrajectoryStateOnSurface comb1At2 = tsosWithS.first;
452  if (!comb1At2.isValid())
453  continue;
454  //distance of propagation from one surface to the next==could cut here
455  overlapPath_ = tsosWithS.second;
456  if (abs(overlapPath_) > 15)
457  continue; //cut to remove hit pairs > 15 cm apart
458  // global position on module 1
460  predictedPositions_[0][0] = position.x();
461  predictedPositions_[1][0] = position.y();
462  predictedPositions_[2][0] = position.z();
463  momentum_ = comb1.globalMomentum().mag();
464  //cout << "momentum from combination = " << momentum_ << endl;
465  //cout << "magnetic field from TSOS = " << comb1.magneticField()->inTesla(position).mag() << endl;
466  // local parameters and errors on module 1
467  AlgebraicVector5 pars = comb1.localParameters().vector();
468  AlgebraicSymMatrix55 errs = comb1.localError().matrix();
469  for (int i = 0; i < 5; ++i) {
470  predictedLocalParameters_[i][0] = pars[i];
471  predictedLocalErrors_[i][0] = sqrt(errs(i, i));
472  }
473  // global position on module 2
474  position = comb1At2.globalPosition();
475  predictedPositions_[0][1] = position.x();
476  predictedPositions_[1][1] = position.y();
477  predictedPositions_[2][1] = position.z();
478  // local parameters and errors on module 2
479  pars = comb1At2.localParameters().vector();
480  errs = comb1At2.localError().matrix();
481  for (int i = 0; i < 5; ++i) {
482  predictedLocalParameters_[i][1] = pars[i];
483  predictedLocalErrors_[i][1] = sqrt(errs(i, i));
484  }
485 
486  //print out local errors in X to check
487  //cout << "Predicted local error in X at 1 = " << predictedLocalErrors_[3][0] << " and predicted local error in X at 2 is = " << predictedLocalErrors_[3][1] << endl;
488  //cout << "Predicted local error in Y at 1 = " << predictedLocalErrors_[4][0] << " and predicted local error in Y at 2 is = " << predictedLocalErrors_[4][1] << endl;
489 
490  //
491  // jacobians (local-to-global@1,global 1-2,global-to-local@2)
492  //
493  JacobianLocalToCurvilinear jacLocToCurv(comb1.surface(), comb1.localParameters(), *magField_);
494  AnalyticalCurvilinearJacobian jacCurvToCurv(
495  comb1.globalParameters(), comb1At2.globalPosition(), comb1At2.globalMomentum(), tsosWithS.second);
496  JacobianCurvilinearToLocal jacCurvToLoc(comb1At2.surface(), comb1At2.localParameters(), *magField_);
497  // combined jacobian local-1-to-local-2
498  AlgebraicMatrix55 jacobian = jacLocToCurv.jacobian() * jacCurvToCurv.jacobian() * jacCurvToLoc.jacobian();
499  // covariance on module 1
500  AlgebraicSymMatrix55 covComb1 = comb1.localError().matrix();
501  // variance and correlations for predicted local_x on modules 1 and 2
502  double c00 = covComb1(3, 3);
503  double c10(0.);
504  double c11(0.);
505  for (int i = 1; i < 5; ++i) {
506  c10 += jacobian(3, i) * covComb1(i, 3);
507  for (int j = 1; j < 5; ++j)
508  c11 += jacobian(3, i) * covComb1(i, j) * jacobian(3, j);
509  }
510  // choose relative sign in order to minimize error on difference
511  double diff = c00 - 2 * fabs(c10) + c11;
512  diff = diff > 0 ? sqrt(diff) : -sqrt(-diff);
514  relativeXSign_ = c10 > 0 ? -1 : 1;
515  //
516  // now find variance and correlations for predicted local_y
517  double c00Y = covComb1(4, 4);
518  double c10Y(0.);
519  double c11Y(0.);
520  for (int i = 1; i < 5; ++i) {
521  c10Y += jacobian(4, i) * covComb1(i, 4);
522  for (int j = 1; j < 5; ++j)
523  c11Y += jacobian(4, i) * covComb1(i, j) * jacobian(4, j);
524  }
525  double diffY = c00Y - 2 * fabs(c10Y) + c11Y;
526  diffY = diffY > 0 ? sqrt(diffY) : -sqrt(-diffY);
527  predictedDeltaYError_ = diffY;
528  relativeYSign_ = c10Y > 0 ? -1 : 1;
529 
530  // information on modules and hits
531  overlapIds_[0] = overlapHit.first->recHit()->geographicalId().rawId();
532  overlapIds_[1] = overlapHit.second->recHit()->geographicalId().rawId();
533 
534  //added by Heshy and Jared
535  moduleX_[0] = overlapHit.first->recHit()->det()->surface().position().x();
536  moduleX_[1] = overlapHit.second->recHit()->det()->surface().position().x();
537  moduleY_[0] = overlapHit.first->recHit()->det()->surface().position().y();
538  moduleY_[1] = overlapHit.second->recHit()->det()->surface().position().y();
539  moduleZ_[0] = overlapHit.first->recHit()->det()->surface().position().z();
540  moduleZ_[1] = overlapHit.second->recHit()->det()->surface().position().z();
541  subdetID = overlapHit.first->recHit()->geographicalId().subdetId();
542  localxdotglobalphi_[0] = overlapHit.first->recHit()->det()->surface().toGlobal(onezero).phi() -
543  overlapHit.first->recHit()->det()->surface().toGlobal(zerozero).phi();
544  localxdotglobalphi_[1] = overlapHit.second->recHit()->det()->surface().toGlobal(onezero).phi() -
545  overlapHit.second->recHit()->det()->surface().toGlobal(zerozero).phi();
546  //added by Jason
547  localxdotglobalr_[0] = overlapHit.first->recHit()->det()->surface().toGlobal(onezero).perp() -
548  overlapHit.first->recHit()->det()->surface().toGlobal(zerozero).perp();
549  localxdotglobalr_[1] = overlapHit.second->recHit()->det()->surface().toGlobal(onezero).perp() -
550  overlapHit.second->recHit()->det()->surface().toGlobal(zerozero).perp();
551  localxdotglobalz_[0] = overlapHit.first->recHit()->det()->surface().toGlobal(onezero).z() -
552  overlapHit.first->recHit()->det()->surface().toGlobal(zerozero).z();
553  localxdotglobalz_[1] = overlapHit.second->recHit()->det()->surface().toGlobal(onezero).z() -
554  overlapHit.second->recHit()->det()->surface().toGlobal(zerozero).z();
555  localxdotglobalx_[0] = overlapHit.first->recHit()->det()->surface().toGlobal(onezero).x() -
556  overlapHit.first->recHit()->det()->surface().toGlobal(zerozero).x();
557  localxdotglobalx_[1] = overlapHit.second->recHit()->det()->surface().toGlobal(onezero).x() -
558  overlapHit.second->recHit()->det()->surface().toGlobal(zerozero).x();
559  localxdotglobaly_[0] = overlapHit.first->recHit()->det()->surface().toGlobal(onezero).y() -
560  overlapHit.first->recHit()->det()->surface().toGlobal(zerozero).y();
561  localxdotglobaly_[1] = overlapHit.second->recHit()->det()->surface().toGlobal(onezero).y() -
562  overlapHit.second->recHit()->det()->surface().toGlobal(zerozero).y();
563  localydotglobalr_[0] = overlapHit.first->recHit()->det()->surface().toGlobal(zeroone).perp() -
564  overlapHit.first->recHit()->det()->surface().toGlobal(zerozero).perp();
565  localydotglobalr_[1] = overlapHit.second->recHit()->det()->surface().toGlobal(zeroone).perp() -
566  overlapHit.second->recHit()->det()->surface().toGlobal(zerozero).perp();
567  localydotglobalz_[0] = overlapHit.first->recHit()->det()->surface().toGlobal(zeroone).z() -
568  overlapHit.first->recHit()->det()->surface().toGlobal(zerozero).z();
569  localydotglobalz_[1] = overlapHit.second->recHit()->det()->surface().toGlobal(zeroone).z() -
570  overlapHit.second->recHit()->det()->surface().toGlobal(zerozero).z();
571  localydotglobalx_[0] = overlapHit.first->recHit()->det()->surface().toGlobal(zeroone).x() -
572  overlapHit.first->recHit()->det()->surface().toGlobal(zerozero).x();
573  localydotglobalx_[1] = overlapHit.second->recHit()->det()->surface().toGlobal(zeroone).x() -
574  overlapHit.second->recHit()->det()->surface().toGlobal(zerozero).x();
575  localydotglobaly_[0] = overlapHit.first->recHit()->det()->surface().toGlobal(zeroone).y() -
576  overlapHit.first->recHit()->det()->surface().toGlobal(zerozero).y();
577  localydotglobaly_[1] = overlapHit.second->recHit()->det()->surface().toGlobal(zeroone).y() -
578  overlapHit.second->recHit()->det()->surface().toGlobal(zerozero).y();
579  localydotglobalphi_[0] = overlapHit.first->recHit()->det()->surface().toGlobal(zeroone).phi() -
580  overlapHit.first->recHit()->det()->surface().toGlobal(zerozero).phi();
581  localydotglobalphi_[1] = overlapHit.second->recHit()->det()->surface().toGlobal(zeroone).phi() -
582  overlapHit.second->recHit()->det()->surface().toGlobal(zerozero).phi();
583 
584  if (overlapHit.first->recHit()->geographicalId().subdetId() == StripSubdetector::TIB)
585  layer_ = layerFromId(overlapHit.first->recHit()->geographicalId().rawId(), tTopo);
586  else if (overlapHit.first->recHit()->geographicalId().subdetId() == StripSubdetector::TOB)
587  layer_ = layerFromId(overlapHit.first->recHit()->geographicalId().rawId(), tTopo) + 4;
588  else if (overlapHit.first->recHit()->geographicalId().subdetId() == StripSubdetector::TID)
589  layer_ = layerFromId(overlapHit.first->recHit()->geographicalId().rawId(), tTopo) + 10;
590  else if (overlapHit.first->recHit()->geographicalId().subdetId() == StripSubdetector::TEC)
591  layer_ = layerFromId(overlapHit.first->recHit()->geographicalId().rawId(), tTopo) + 13;
592  else if (overlapHit.first->recHit()->geographicalId().subdetId() == PixelSubdetector::PixelBarrel)
593  layer_ = layerFromId(overlapHit.first->recHit()->geographicalId().rawId(), tTopo) + 20;
594  else if (overlapHit.first->recHit()->geographicalId().subdetId() == PixelSubdetector::PixelEndcap)
595  layer_ = layerFromId(overlapHit.first->recHit()->geographicalId().rawId(), tTopo) + 30;
596  else
597  layer_ = 99;
598 
599  if (overlapIds_[0] == SiStripDetId(overlapHit.first->recHit()->geographicalId()).glued())
600  edm::LogWarning("Overlaps") << "BAD GLUED: First Id = " << overlapIds_[0] << " has glued = "
601  << SiStripDetId(overlapHit.first->recHit()->geographicalId()).glued()
602  << " and stereo = "
603  << SiStripDetId(overlapHit.first->recHit()->geographicalId()).stereo() << endl;
604  if (overlapIds_[1] == SiStripDetId(overlapHit.second->recHit()->geographicalId()).glued())
605  edm::LogWarning("Overlaps") << "BAD GLUED: Second Id = " << overlapIds_[1] << " has glued = "
606  << SiStripDetId(overlapHit.second->recHit()->geographicalId()).glued()
607  << " and stereo = "
608  << SiStripDetId(overlapHit.second->recHit()->geographicalId()).stereo() << endl;
609 
610  const TransientTrackingRecHit::ConstRecHitPointer firstRecHit = overlapHit.first->recHit();
611  const TransientTrackingRecHit::ConstRecHitPointer secondRecHit = overlapHit.second->recHit();
612  hitPositions_[0] = firstRecHit->localPosition().x();
613  hitErrors_[0] = sqrt(firstRecHit->localPositionError().xx());
614  hitPositions_[1] = secondRecHit->localPosition().x();
615  hitErrors_[1] = sqrt(secondRecHit->localPositionError().xx());
616 
617  hitPositionsY_[0] = firstRecHit->localPosition().y();
618  hitErrorsY_[0] = sqrt(firstRecHit->localPositionError().yy());
619  hitPositionsY_[1] = secondRecHit->localPosition().y();
620  hitErrorsY_[1] = sqrt(secondRecHit->localPositionError().yy());
621 
622  //cout << "printing local X hit position and error for the overlap hits. Hit 1 = " << hitPositions_[0] << "+-" << hitErrors_[0] << " and hit 2 is " << hitPositions_[1] << "+-" << hitErrors_[1] << endl;
623 
624  DetId id1 = overlapHit.first->recHit()->geographicalId();
625  DetId id2 = overlapHit.second->recHit()->geographicalId();
626  int layer1 = layerFromId(id1, tTopo);
627  int subDet1 = id1.subdetId();
628  int layer2 = layerFromId(id2, tTopo);
629  int subDet2 = id2.subdetId();
630  if (abs(hitPositions_[0]) > 5)
631  edm::LogInfo("Overlaps") << "BAD: Bad hit position: Id = " << id1.rawId()
632  << " stereo = " << SiStripDetId(id1).stereo()
633  << " glued = " << SiStripDetId(id1).glued() << " from subdet = " << subDet1
634  << " and layer = " << layer1 << endl;
635  if (abs(hitPositions_[1]) > 5)
636  edm::LogInfo("Overlaps") << "BAD: Bad hit position: Id = " << id2.rawId()
637  << " stereo = " << SiStripDetId(id2).stereo()
638  << " glued = " << SiStripDetId(id2).glued() << " from subdet = " << subDet2
639  << " and layer = " << layer2 << endl;
640 
641  // get track momentum
642  momentum_ = comb1.globalMomentum().mag();
643 
644  // get cluster size
645  if (!(subDet1 == PixelSubdetector::PixelBarrel || subDet1 == PixelSubdetector::PixelEndcap)) { //strip
646  const TransientTrackingRecHit::ConstRecHitPointer thit1 = overlapHit.first->recHit();
647  const SiStripRecHit1D* hit1 = dynamic_cast<const SiStripRecHit1D*>((*thit1).hit());
648  if (hit1) {
649  //check cluster width
650  const SiStripRecHit1D::ClusterRef& cluster1 = hit1->cluster();
651  clusterSize_[0] = (cluster1->amplitudes()).size();
652  clusterWidthX_[0] = (cluster1->amplitudes()).size();
653  clusterWidthY_[0] = -1;
654 
655  //check if cluster at edge of sensor
656  uint16_t firstStrip = cluster1->firstStrip();
657  uint16_t lastStrip = firstStrip + (cluster1->amplitudes()).size() - 1;
658  unsigned short Nstrips;
659  Nstrips = detInfo_.getNumberOfApvsAndStripLength(id1).first * 128;
660  bool atEdge = false;
661  if (firstStrip == 0 || lastStrip == (Nstrips - 1))
662  atEdge = true;
663  if (atEdge)
664  edge_[0] = 1;
665  else
666  edge_[0] = -1;
667 
668  // get cluster total charge
669  const auto& stripCharges = cluster1->amplitudes();
670  uint16_t charge = 0;
671  for (uint i = 0; i < stripCharges.size(); i++) {
672  charge += stripCharges[i];
673  }
674  clusterCharge_[0] = charge;
675  }
676 
677  const TransientTrackingRecHit::ConstRecHitPointer thit2 = overlapHit.second->recHit();
678  const SiStripRecHit1D* hit2 = dynamic_cast<const SiStripRecHit1D*>((*thit2).hit());
679  if (hit2) {
680  const SiStripRecHit1D::ClusterRef& cluster2 = hit2->cluster();
681  clusterSize_[1] = (cluster2->amplitudes()).size();
682  clusterWidthX_[1] = (cluster2->amplitudes()).size();
683  clusterWidthY_[1] = -1;
684 
685  uint16_t firstStrip = cluster2->firstStrip();
686  uint16_t lastStrip = firstStrip + (cluster2->amplitudes()).size() - 1;
687  unsigned short Nstrips;
688  Nstrips = detInfo_.getNumberOfApvsAndStripLength(id2).first * 128;
689  bool atEdge = false;
690  if (firstStrip == 0 || lastStrip == (Nstrips - 1))
691  atEdge = true;
692  if (atEdge)
693  edge_[1] = 1;
694  else
695  edge_[1] = -1;
696 
697  // get cluster total charge
698  const auto& stripCharges = cluster2->amplitudes();
699  uint16_t charge = 0;
700  for (uint i = 0; i < stripCharges.size(); i++) {
701  charge += stripCharges[i];
702  }
703  clusterCharge_[1] = charge;
704  }
705  //cout << "strip cluster size2 = " << clusterWidthX_[0] << " and size 2 = " << clusterWidthX_[1] << endl;
706  }
707 
708  if (subDet2 == PixelSubdetector::PixelBarrel || subDet2 == PixelSubdetector::PixelEndcap) { //pixel
709 
710  const TransientTrackingRecHit::ConstRecHitPointer thit1 = overlapHit.first->recHit();
711  const SiPixelRecHit* recHitPix1 = dynamic_cast<const SiPixelRecHit*>((*thit1).hit());
712  if (recHitPix1) {
713  // check for cluster size and width
714  SiPixelRecHit::ClusterRef const& cluster1 = recHitPix1->cluster();
715 
716  clusterSize_[0] = cluster1->size();
717  clusterWidthX_[0] = cluster1->sizeX();
718  clusterWidthY_[0] = cluster1->sizeY();
719 
720  // check for cluster at edge
721  const PixelGeomDetUnit* theGeomDet = dynamic_cast<const PixelGeomDetUnit*>((*trackerGeometry_).idToDet(id1));
722  const PixelTopology* topol = (&(theGeomDet->specificTopology()));
723 
724  int minPixelRow = cluster1->minPixelRow(); //x
725  int maxPixelRow = cluster1->maxPixelRow();
726  int minPixelCol = cluster1->minPixelCol(); //y
727  int maxPixelCol = cluster1->maxPixelCol();
728 
729  bool edgeHitX = (topol->isItEdgePixelInX(minPixelRow)) || (topol->isItEdgePixelInX(maxPixelRow));
730  bool edgeHitY = (topol->isItEdgePixelInY(minPixelCol)) || (topol->isItEdgePixelInY(maxPixelCol));
731  if (edgeHitX || edgeHitY)
732  edge_[0] = 1;
733  else
734  edge_[0] = -1;
735 
736  clusterCharge_[0] = (uint)cluster1->charge();
737 
738  } else {
739  edm::LogWarning("Overlaps") << "didn't find pixel cluster" << endl;
740  continue;
741  }
742 
743  const TransientTrackingRecHit::ConstRecHitPointer thit2 = overlapHit.second->recHit();
744  const SiPixelRecHit* recHitPix2 = dynamic_cast<const SiPixelRecHit*>((*thit2).hit());
745  if (recHitPix2) {
746  SiPixelRecHit::ClusterRef const& cluster2 = recHitPix2->cluster();
747 
748  clusterSize_[1] = cluster2->size();
749  clusterWidthX_[1] = cluster2->sizeX();
750  clusterWidthY_[1] = cluster2->sizeY();
751  //cout << "second pixel cluster is " << clusterSize_[1] << " pixels with x width = " << clusterWidthX_[1] << " and y width = " << clusterWidthY_[1] << endl;
752 
753  const PixelGeomDetUnit* theGeomDet = dynamic_cast<const PixelGeomDetUnit*>((*trackerGeometry_).idToDet(id2));
754  const PixelTopology* topol = (&(theGeomDet->specificTopology()));
755 
756  int minPixelRow = cluster2->minPixelRow(); //x
757  int maxPixelRow = cluster2->maxPixelRow();
758  int minPixelCol = cluster2->minPixelCol(); //y
759  int maxPixelCol = cluster2->maxPixelCol();
760 
761  bool edgeHitX = (topol->isItEdgePixelInX(minPixelRow)) || (topol->isItEdgePixelInX(maxPixelRow));
762  bool edgeHitY = (topol->isItEdgePixelInY(minPixelCol)) || (topol->isItEdgePixelInY(maxPixelCol));
763  if (edgeHitX || edgeHitY)
764  edge_[1] = 1;
765  else
766  edge_[1] = -1;
767 
768  clusterCharge_[1] = (uint)cluster2->charge();
769 
770  } else {
771  edm::LogWarning("Overlaps") << "didn't find pixel cluster" << endl;
772  continue;
773  }
774  }
775 
776  //also check for edge pixels
777 
778  //try writing out the SimHit info (for MC only)
779  if (doSimHit_) {
780  std::vector<PSimHit> psimHits1;
781  std::vector<PSimHit> psimHits2;
782  //calculate layer
783  DetId id = overlapHit.first->recHit()->geographicalId();
784  int layer(-1);
785  layer = layerFromId(id, tTopo);
786  int subDet = id.subdetId();
787  edm::LogVerbatim("OverlapValidation") << "Subdet = " << subDet << " ; layer = " << layer;
788 
789  psimHits1 = associator.associateHit(*(firstRecHit->hit()));
790  edm::LogVerbatim("OverlapValidation") << "single hit ";
791  edm::LogVerbatim("OverlapValidation") << "length of psimHits1: " << psimHits1.size();
792  if (!psimHits1.empty()) {
793  float closest_dist = 99999.9;
794  std::vector<PSimHit>::const_iterator closest_simhit = psimHits1.begin();
795  for (std::vector<PSimHit>::const_iterator m = psimHits1.begin(); m < psimHits1.end(); m++) {
796  //find closest simHit to the recHit
797  float simX = (*m).localPosition().x();
798  float dist = fabs(simX - (overlapHit.first->recHit()->localPosition().x()));
799  edm::LogVerbatim("OverlapValidation")
800  << "simHit1 simX = " << simX << " hitX = " << overlapHit.first->recHit()->localPosition().x()
801  << " distX = " << dist << " layer = " << layer;
802  if (dist < closest_dist) {
803  //cout << "found newest closest dist for simhit1" << endl;
804  closest_dist = dist;
805  closest_simhit = m;
806  }
807  }
808  //if glued layer, convert sim hit position to matchedhit surface
809  //layer index from 1-4 for TIB, 1-6 for TOB
810  // Are the sim hits on the glued layers or are they split???
811  if (subDet > 2 && !SiStripDetId(id).glued()) {
812  const GluedGeomDet* gluedDet =
813  (const GluedGeomDet*)(*trackerGeometry_).idToDet((*firstRecHit).hit()->geographicalId());
814  const StripGeomDetUnit* stripDet = (StripGeomDetUnit*)gluedDet->monoDet();
815  GlobalPoint gp = stripDet->surface().toGlobal((*closest_simhit).localPosition());
816  LocalPoint lp = gluedDet->surface().toLocal(gp);
817  LocalVector localdirection = (*closest_simhit).localDirection();
818  GlobalVector globaldirection = stripDet->surface().toGlobal(localdirection);
819  LocalVector direction = gluedDet->surface().toLocal(globaldirection);
820  float scale = -lp.z() / direction.z();
821  LocalPoint projectedPos = lp + scale * direction;
822  simHitPositions_[0] = projectedPos.x();
823  edm::LogVerbatim("OverlapValidation") << "simhit position from matched layer = " << simHitPositions_[0];
824  simHitPositionsY_[0] = projectedPos.y();
825  } else {
826  simHitPositions_[0] = (*closest_simhit).localPosition().x();
827  simHitPositionsY_[0] = (*closest_simhit).localPosition().y();
828  edm::LogVerbatim("OverlapValidation") << "simhit position from non-matched layer = " << simHitPositions_[0];
829  }
830  edm::LogVerbatim("OverlapValidation") << "hit position = " << hitPositions_[0];
831  } else {
832  simHitPositions_[0] = -99.;
833  simHitPositionsY_[0] = -99.;
834  //cout << " filling simHitX: " << -99 << endl;
835  }
836 
837  psimHits2 = associator.associateHit(*(secondRecHit->hit()));
838  if (!psimHits2.empty()) {
839  float closest_dist = 99999.9;
840  std::vector<PSimHit>::const_iterator closest_simhit = psimHits2.begin();
841  for (std::vector<PSimHit>::const_iterator m = psimHits2.begin(); m < psimHits2.end(); m++) {
842  float simX = (*m).localPosition().x();
843  float dist = fabs(simX - (overlapHit.second->recHit()->localPosition().x()));
844  if (dist < closest_dist) {
845  closest_dist = dist;
846  closest_simhit = m;
847  }
848  }
849  //if glued layer, convert sim hit position to matchedhit surface
850  // if no sim hits on matched layers then this section can be removed
851  if (subDet > 2 && !SiStripDetId(id).glued()) {
852  const GluedGeomDet* gluedDet =
853  (const GluedGeomDet*)(*trackerGeometry_).idToDet((*secondRecHit).hit()->geographicalId());
854  const StripGeomDetUnit* stripDet = (StripGeomDetUnit*)gluedDet->monoDet();
855  GlobalPoint gp = stripDet->surface().toGlobal((*closest_simhit).localPosition());
856  LocalPoint lp = gluedDet->surface().toLocal(gp);
857  LocalVector localdirection = (*closest_simhit).localDirection();
858  GlobalVector globaldirection = stripDet->surface().toGlobal(localdirection);
859  LocalVector direction = gluedDet->surface().toLocal(globaldirection);
860  float scale = -lp.z() / direction.z();
861  LocalPoint projectedPos = lp + scale * direction;
862  simHitPositions_[1] = projectedPos.x();
863  simHitPositionsY_[1] = projectedPos.y();
864  } else {
865  simHitPositions_[1] = (*closest_simhit).localPosition().x();
866  simHitPositionsY_[1] = (*closest_simhit).localPosition().y();
867  }
868  } else {
869  simHitPositions_[1] = -99.;
870  simHitPositionsY_[1] = -99.;
871  }
872  }
873  rootTree_->Fill();
874  }
875 }
876 
877 int OverlapValidation::layerFromId(const DetId& id, const TrackerTopology* const tTopo) const {
878  TrackerAlignableId aliid;
879  std::pair<int, int> subdetandlayer = aliid.typeAndLayerFromDetId(id, tTopo);
880  int layer = subdetandlayer.second;
881 
882  return layer;
883 }
884 
886  if (rootTree_) {
887  rootTree_->GetDirectory()->cd();
888  rootTree_->Write();
889  delete rootTree_;
890  }
891 }
892 
893 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:38
ClusterRef cluster() const
edm::InputTag trajectoryTag_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Log< level::Info, true > LogVerbatim
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:79
const Point2DBase< float, LocalTag > zerozero
EventNumber_t event() const
Definition: EventID.h:40
static constexpr auto TEC
int foundHits() const
Definition: Trajectory.h:206
tuple propagator
int lostHits() const
Definition: Trajectory.h:217
TrajectoryStateCombiner combiner_
edm::EDGetTokenT< TrajectoryCollection > trajectoryToken_
unsigned int overlapIds_[2]
~OverlapValidation() override
std::pair< int, int > typeAndLayerFromDetId(const DetId &detId, const TrackerTopology *tTopo) const
void endJob() override
vector< bool > acceptLayer
const GeomDetUnit * monoDet() const
Definition: GluedGeomDet.h:19
uint32_t stereo() const
Definition: SiStripDetId.h:168
const LocalTrajectoryParameters & localParameters() const
const bool addExtraBranches_
TSOS combine(const TSOS &pTsos1, const TSOS &pTsos2) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
float predictedPositions_[3][2]
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const Point2DBase< float, LocalTag > onezero
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
T y() const
Definition: PV3DBase.h:60
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepStd< double, 5, 5 > > AlgebraicMatrix55
GlobalPoint globalPosition() const
const Point2DBase< float, LocalTag > zeroone
unsigned short hitCounts_[2]
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
void analyze(const edm::Event &, const edm::EventSetup &) override
constexpr std::array< uint8_t, layerIndexSize > layer
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoToken_
const MagneticField * magField_
bool getData(T &iHolder) const
Definition: EventSetup.h:122
DataContainer const & measurements() const
Definition: Trajectory.h:178
AlgebraicVector5 vector() const
virtual bool isItEdgePixelInX(int ixbin) const =0
int iEvent
Definition: GenABIO.cc:224
const SurfaceType & surface() const
T mag() const
Definition: PV3DBase.h:64
virtual void analyzeTrajectory(const Trajectory &, const Propagator &, TrackerHitAssociator &, const TrackerTopology *const tTopo)
SiStripDetInfo detInfo_
int layerFromId(const DetId &, const TrackerTopology *const tTopo) const
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
vector< Trajectory > TrajectoryCollection
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
T sqrt(T t)
Definition: SSEVec.h:19
LocalPoint toLocal(const GlobalPoint &gp) const
T z() const
Definition: PV3DBase.h:61
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ROOT::Math::SVector< double, 5 > AlgebraicVector5
float ChiSquaredProbability(double chiSquared, double nrDOF)
const AlgebraicSymMatrix55 & matrix() const
const std::pair< unsigned short, double > getNumberOfApvsAndStripLength(uint32_t detId) const
const TrackerGeometry * trackerGeometry_
SiStripDetInfo read(std::string filePath)
float predictedLocalErrors_[5][2]
const LocalTrajectoryError & localError() const
static constexpr auto TOB
virtual std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &, const Surface &) const final
Definition: Propagator.cc:10
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magFieldToken_
Log< level::Info, false > LogInfo
Detector identifier class for the strip tracker.
Definition: SiStripDetId.h:18
OverlapValidation(const edm::ParameterSet &)
TransientTrackingRecHit::ConstRecHitPointer ConstRecHitPointer
Definition: DetId.h:17
uint32_t glued() const
Definition: SiStripDetId.h:163
int ndof(bool bon=true) const
Definition: Trajectory.cc:97
float predictedLocalParameters_[5][2]
static const char clusterCharge_[]
static constexpr auto TIB
const GlobalTrajectoryParameters & globalParameters() const
edm::FileInPath FileInPath_
ClusterRef cluster() const
Definition: SiPixelRecHit.h:47
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
const int compressionSettings_
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:50
float chiSquared() const
Definition: Trajectory.h:241
edm::ParameterSet config_
edm::EventID id() const
Definition: EventBase.h:59
virtual bool isItEdgePixelInY(int iybin) const =0
GlobalVector globalMomentum() const
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
static int position[264][3]
Definition: ReadPGInfo.cc:289
void event_()
const AlgebraicMatrix55 & jacobian() const
std::string fullPath() const
Definition: FileInPath.cc:161
std::vector< PSimHit > associateHit(const TrackingRecHit &thit) const
static constexpr char const *const kDefaultFile
T w() const
Log< level::Warning, false > LogWarning
T x() const
Definition: PV3DBase.h:59
static constexpr auto TID
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
tuple size
Write out results.
Our base class.
Definition: SiPixelRecHit.h:23