CMS 3D CMS Logo

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