CMS 3D CMS Logo

HitResol.cc
Go to the documentation of this file.
1 // Package: CalibTracker/SiStripHitResolution
3 // Class: HitResol
4 // Original Authors: Denis Gele and Kathryn Coldham (adapted from HitEff)
5 // modified by Khawla Jaffel for CPE studies
6 // ported to cmssw by M. Musich
7 //
9 
10 // system include files
11 #include <memory>
12 #include <string>
13 #include <iostream>
14 
15 // user includes
62 
63 // ROOT includes
64 #include "TMath.h"
65 #include "TH1F.h"
66 
67 //
68 // constructors and destructor
69 //
70 using namespace std;
72  : scalerToken_(consumes<LumiScalersCollection>(conf.getParameter<edm::InputTag>("lumiScalers"))),
73  combinatorialTracks_token_(
74  consumes<reco::TrackCollection>(conf.getParameter<edm::InputTag>("combinatorialTracks"))),
75  tjToken_(consumes<std::vector<Trajectory> >(conf.getParameter<edm::InputTag>("trajectories"))),
76  topoToken_(esConsumes()),
77  geomToken_(esConsumes()),
78  cpeToken_(esConsumes(edm::ESInputTag("", "StripCPEfromTrackAngle"))),
79  siStripQualityToken_(esConsumes()),
80  magFieldToken_(esConsumes()),
81  addLumi_(conf.getUntrackedParameter<bool>("addLumi", false)),
82  DEBUG_(conf.getParameter<bool>("Debug")),
83  cutOnTracks_(conf.getUntrackedParameter<bool>("cutOnTracks", false)),
84  momentumCut_(conf.getUntrackedParameter<double>("MomentumCut", 3.)),
85  compSettings_(conf.getUntrackedParameter<int>("CompressionSettings", -1)),
86  usePairsOnly_(conf.getUntrackedParameter<unsigned int>("UsePairsOnly", 1)),
87  layers_(conf.getParameter<int>("Layer")),
88  trackMultiplicityCut_(conf.getUntrackedParameter<unsigned int>("trackMultiplicity", 100)) {
89  usesResource(TFileService::kSharedResource);
90 }
91 
94  if (compSettings_ > 0) {
95  edm::LogInfo("SiStripHitResolution:HitResol") << "the compressions settings are:" << compSettings_ << std::endl;
96  fs->file().SetCompressionSettings(compSettings_);
97  }
98 
99  reso = fs->make<TTree>("reso", "tree hit pairs for resolution studies");
100  reso->Branch("momentum", &mymom, "momentum/F");
101  reso->Branch("numHits", &numHits, "numHits/I");
102  reso->Branch("trackChi2", &ProbTrackChi2, "trackChi2/F");
103  reso->Branch("detID1", &iidd1, "detID1/I");
104  reso->Branch("pitch1", &mypitch1, "pitch1/F");
105  reso->Branch("clusterW1", &clusterWidth, "clusterW1/I");
106  reso->Branch("expectedW1", &expWidth, "expectedW1/F");
107  reso->Branch("atEdge1", &atEdge, "atEdge1/F");
108  reso->Branch("simpleRes", &simpleRes, "simpleRes/F");
109  reso->Branch("detID2", &iidd2, "detID2/I");
110  reso->Branch("clusterW2", &clusterWidth_2, "clusterW2/I");
111  reso->Branch("expectedW2", &expWidth_2, "expectedW2/F");
112  reso->Branch("atEdge2", &atEdge_2, "atEdge2/F");
113  reso->Branch("pairPath", &pairPath, "pairPath/F");
114  reso->Branch("hitDX", &hitDX, "hitDX/F");
115  reso->Branch("trackDX", &trackDX, "trackDX/F");
116  reso->Branch("trackDXE", &trackDXE, "trackDXE/F");
117  reso->Branch("trackParamX", &trackParamX, "trackParamX/F");
118  reso->Branch("trackParamY", &trackParamY, "trackParamY/F");
119  reso->Branch("trackParamDXDZ", &trackParamDXDZ, "trackParamDXDZ/F");
120  reso->Branch("trackParamDYDZ", &trackParamDYDZ, "trackParamDYDZ/F");
121  reso->Branch("trackParamXE", &trackParamXE, "trackParamXE/F");
122  reso->Branch("trackParamYE", &trackParamYE, "trackParamYE/F");
123  reso->Branch("trackParamDXDZE", &trackParamDXDZE, "trackParamDXDZE/F");
124  reso->Branch("trackParamDYDZE", &trackParamDYDZE, "trackParamDYDZE/F");
125  reso->Branch("pairsOnly", &pairsOnly, "pairsOnly/I");
126  treso = fs->make<TTree>("treso", "tree tracks for resolution studies");
127  treso->Branch("track_momentum", &track_momentum, "track_momentum/F");
128  treso->Branch("track_pt", &track_pt, "track_pt/F");
129  treso->Branch("track_eta", &track_eta, "track_eta/F");
130  treso->Branch("track_phi", &track_phi, "track_phi/F");
131  treso->Branch("track_trackChi2", &track_trackChi2, "track_trackChi2/F");
132  treso->Branch("track_width", &expWidth, "track_width/F"); // from 1D HIT
133  treso->Branch("NumberOf_tracks", &NumberOf_tracks, "NumberOf_tracks/I");
134 
135  events = 0;
136  EventTrackCKF = 0;
137 
138  histos2d_["track_phi_vs_eta"] = new TH2F("track_phi_vs_eta", ";track phi;track eta", 60, -3.5, 3.5, 60, -3., 3.);
139  histos2d_["residual_vs_trackMomentum"] = new TH2F("residual_vs_trackMomentum",
140  ";track momentum [GeV]; x_{pred_track} - x_{reco_hit} [#mum]",
141  60,
142  0.,
143  10.,
144  60,
145  0.,
146  200.);
147  histos2d_["residual_vs_trackPt"] = new TH2F(
148  "residual_vs_trackPt", ";track p_{T}[GeV];x_{pred_track} - x_{reco_hit} [#mum]", 60, 0., 10., 60, 0., 200.);
149  histos2d_["residual_vs_trackEta"] =
150  new TH2F("residual_vs_trackEta", ";track #eta;x_{pred_track} - x_{reco_hit} [#mum]", 60, 0., 3., 60, 0., 200.);
151  histos2d_["residual_vs_trackPhi"] =
152  new TH2F("residual_vs_trackPhi", ";track #phi;x_{pred_track} - x_{reco_hit} [#mum]", 60, 0., 3.5, 60, 0., 200.);
153  histos2d_["residual_vs_expectedWidth"] = new TH2F(
154  "residual_vs_expectedWidth", ";track Width;x_{pred_track} - x_{reco_hit} [#mum]", 3, 0., 3., 60, 0., 200.);
155  histos2d_["numHits_vs_residual"] =
156  new TH2F("numHits_vs_residual", ";x_{pred_track} - x_{reco_hit} [#mum];N Hits", 60, 0., 200., 15, 0., 15.);
157 }
158 
160  //Retrieve tracker topology from geometry
161  const TrackerTopology* tTopo = &es.getData(topoToken_);
162 
163  LogDebug("SiStripHitResolution:HitResol") << "beginning analyze from HitResol" << endl;
164 
165  using namespace edm;
166  using namespace reco;
167 
168  // Step A: Get Inputs
169 
170  int run_nr = e.id().run();
171  int ev_nr = e.id().event();
172 
173  // get the tracks
174  edm::Handle<reco::TrackCollection> trackCollectionCKF;
175  e.getByToken(combinatorialTracks_token_, trackCollectionCKF);
176  const reco::TrackCollection* tracksCKF = trackCollectionCKF.product();
177 
178  // get the trajectory collection
179  edm::Handle<std::vector<Trajectory> > trajectoryCollectionHandle;
180  e.getByToken(tjToken_, trajectoryCollectionHandle);
181  const TrajectoryCollection* trajectoryCollection = trajectoryCollectionHandle.product();
182 
183  //get tracker geometry
185  const TrackerGeometry* tkgeom = &(*tracker);
186 
187  //get Cluster Parameter Estimator
189  const StripClusterParameterEstimator& stripcpe(*parameterestimator);
190 
191  // get the SiStripQuality records
193 
194  // get the magnetic field
195  const MagneticField* magField_ = &es.getData(magFieldToken_);
196 
197  events++;
198 
199  // List of variables for SiStripHitResolution ntuple
200  mymom = 0;
201  numHits = 0;
202  ProbTrackChi2 = 0;
203  iidd1 = 0;
204  mypitch1 = 0;
205  clusterWidth = 0;
206  expWidth = 0;
207  atEdge = 0;
208  simpleRes = 0;
209  iidd2 = 0;
210  clusterWidth_2 = 0;
211  expWidth_2 = 0;
212  atEdge_2 = 0;
213  pairPath = 0;
214  hitDX = 0;
215  trackDX = 0;
216  trackDXE = 0;
217  trackParamX = 0;
218  trackParamY = 0;
219  trackParamDXDZ = 0;
220  trackParamDYDZ = 0;
221  trackParamXE = 0;
222  trackParamYE = 0;
223  trackParamDXDZE = 0;
224  trackParamDYDZE = 0;
225  pairsOnly = 0;
226 
227  LogDebug("HitResol") << "Starting analysis, nrun nevent, tracksCKF->size(): " << run_nr << " " << ev_nr << " "
228  << tracksCKF->size() << std::endl;
229 
230  for (unsigned int iT = 0; iT < tracksCKF->size(); ++iT) {
231  track_momentum = tracksCKF->at(iT).p();
232  track_pt = tracksCKF->at(iT).p();
233  track_eta = tracksCKF->at(iT).eta();
234  track_phi = tracksCKF->at(iT).phi();
235  track_trackChi2 = ChiSquaredProbability((double)(tracksCKF->at(iT).chi2()), (double)(tracksCKF->at(iT).ndof()));
236  treso->Fill();
237  }
238 
239  histos2d_["track_phi_vs_eta"]->Fill(track_phi, track_eta);
240 
241  // loop over trajectories from refit
242  for (const auto& traj : *trajectoryCollection) {
243  const auto& TMeas = traj.measurements();
244  // Loop on each measurement and take it into consideration
245  //--------------------------------------------------------
246  for (auto itm = TMeas.cbegin(); itm != TMeas.cend(); ++itm) {
247  if (!itm->updatedState().isValid()) {
248  LogDebug("HitResol") << "trajectory measurement not valid" << std::endl;
249  continue;
250  }
251 
252  const TransientTrackingRecHit::ConstRecHitPointer mypointhit = itm->recHit();
253  const TrackingRecHit* myhit = (*itm->recHit()).hit();
254 
255  ProbTrackChi2 = 0;
256  numHits = 0;
257 
258  LogDebug("HitResol") << "TrackChi2 = "
259  << ChiSquaredProbability((double)(traj.chiSquared()), (double)(traj.ndof(false))) << "\n"
260  << "itm->updatedState().globalMomentum().perp(): "
261  << itm->updatedState().globalMomentum().perp() << "\n"
262  << "numhits " << traj.foundHits() << std::endl;
263 
264  numHits = traj.foundHits();
265  ProbTrackChi2 = ChiSquaredProbability((double)(traj.chiSquared()), (double)(traj.ndof(false)));
266 
267  mymom = itm->updatedState().globalMomentum().perp();
268 
269  //Now for the first hit
270  TrajectoryStateOnSurface mytsos = itm->updatedState();
271  const auto hit1 = itm->recHit();
272  DetId id1 = hit1->geographicalId();
273  if (id1.subdetId() < StripSubdetector::TIB || id1.subdetId() > StripSubdetector::TEC)
274  continue;
275 
276  if (hit1->isValid() && mymom > momentumCut_ &&
277  (id1.subdetId() >= StripSubdetector::TIB && id1.subdetId() <= StripSubdetector::TEC)) {
278  const auto stripdet = dynamic_cast<const StripGeomDetUnit*>(tkgeom->idToDetUnit(hit1->geographicalId()));
279  const StripTopology& Topo = stripdet->specificTopology();
280  int Nstrips = Topo.nstrips();
281  mypitch1 = stripdet->surface().bounds().width() / Topo.nstrips();
282 
283  const auto det = dynamic_cast<const StripGeomDetUnit*>(tkgeom->idToDetUnit(mypointhit->geographicalId()));
284 
285  TrajectoryStateOnSurface mytsos = itm->updatedState();
286  LocalVector trackDirection = mytsos.localDirection();
287  LocalVector drift = stripcpe.driftDirection(stripdet);
288 
289  const auto hit1d = dynamic_cast<const SiStripRecHit1D*>(myhit);
290 
291  if (hit1d) {
292  getSimHitRes(det, trackDirection, *hit1d, expWidth, &mypitch1, drift);
293  clusterWidth = hit1d->cluster()->amplitudes().size();
294  uint16_t firstStrip = hit1d->cluster()->firstStrip();
295  uint16_t lastStrip = firstStrip + (hit1d->cluster()->amplitudes()).size() - 1;
296  atEdge = (firstStrip == 0 || lastStrip == (Nstrips - 1));
297  }
298 
299  const auto hit2d = dynamic_cast<const SiStripRecHit2D*>(myhit);
300 
301  if (hit2d) {
302  getSimHitRes(det, trackDirection, *hit2d, expWidth, &mypitch1, drift);
303  clusterWidth = hit2d->cluster()->amplitudes().size();
304  uint16_t firstStrip = hit2d->cluster()->firstStrip();
305  uint16_t lastStrip = firstStrip + (hit2d->cluster()->amplitudes()).size() - 1;
306  atEdge = (firstStrip == 0 || lastStrip == (Nstrips - 1));
307  }
308 
309  simpleRes =
310  getSimpleRes(&(*itm)); // simple resolution by using the track re-fit forward and backward predicted state
311 
312  histos2d_["residual_vs_trackMomentum"]->Fill(itm->updatedState().globalMomentum().mag(),
313  simpleRes * 10000); // reso in cm *10000 == micro-meter
314  histos2d_["residual_vs_trackPt"]->Fill(mymom, simpleRes * 10000); // reso in cm *10000 == micro-meter
315  histos2d_["residual_vs_trackEta"]->Fill(itm->updatedState().globalMomentum().eta(), simpleRes * 10000);
316  histos2d_["residual_vs_trackPhi"]->Fill(itm->updatedState().globalMomentum().phi(), simpleRes * 10000);
317  histos2d_["residual_vs_expectedWidth"]->Fill(expWidth, simpleRes * 10000);
318  histos2d_["numHits_vs_residual"]->Fill(simpleRes * 10000, numHits);
319 
320  // Now to see if there is a match - pair method - hit in overlapping sensors
321  vector<TrajectoryMeasurement>::const_iterator itTraj2 = TMeas.end(); // last hit along the fitted track
322 
323  for (auto itmCompare = itm - 1;
324  // start to compare from the 5th hit
325  itmCompare >= TMeas.cbegin() && itmCompare > itm - 4;
326  --itmCompare) {
327  const auto hit2 = itmCompare->recHit();
328  if (!hit2->isValid())
329  continue;
330  DetId id2 = hit2->geographicalId();
331 
332  //must be from the same detector and layer
333  iidd1 = hit1->geographicalId().rawId();
334  iidd2 = hit2->geographicalId().rawId();
335  if (id1.subdetId() != id2.subdetId() || ::checkLayer(iidd1, tTopo) != ::checkLayer(iidd2, tTopo))
336  break;
337  //must both be stereo if one is
338  if (tTopo->isStereo(id1) != tTopo->isStereo(id2))
339  continue;
340  //A check i dont completely understand but might as well keep there
341  if (tTopo->glued(id1) == id1.rawId())
342  LogDebug("HitResol") << "BAD GLUED: Have glued layer with id = " << id1.rawId()
343  << " and glued id = " << tTopo->glued(id1) << " and stereo = " << tTopo->isStereo(id1)
344  << endl;
345  if (tTopo->glued(id2) == id2.rawId())
346  LogDebug("HitResol") << "BAD GLUED: Have glued layer with id = " << id2.rawId()
347  << " and glued id = " << tTopo->glued(id2) << " and stereo = " << tTopo->isStereo(id2)
348  << endl;
349 
350  itTraj2 = itmCompare;
351  break;
352  }
353 
354  if (itTraj2 == TMeas.cend()) {
355  } else {
356  LogDebug("HitResol") << "Found overlapping sensors " << std::endl;
358 
359  //We found one....let's fill in the truth info!
360  TrajectoryStateOnSurface tsos_2 = itTraj2->updatedState();
361  LocalVector trackDirection_2 = tsos_2.localDirection();
362  const auto myhit2 = itTraj2->recHit();
363  const auto myhit_2 = (*itTraj2->recHit()).hit();
364  const auto stripdet_2 = dynamic_cast<const StripGeomDetUnit*>(tkgeom->idToDetUnit(myhit2->geographicalId()));
365  const StripTopology& Topo_2 = stripdet_2->specificTopology();
366  int Nstrips_2 = Topo_2.nstrips();
367  float mypitch_2 = stripdet_2->surface().bounds().width() / Topo_2.nstrips();
368 
369  if (mypitch1 != mypitch_2)
370  return; // for PairsOnly
371 
372  const auto det_2 = dynamic_cast<const StripGeomDetUnit*>(tkgeom->idToDetUnit(myhit2->geographicalId()));
373 
374  LocalVector drift_2 = stripcpe.driftDirection(stripdet_2);
375 
376  const auto hit1d_2 = dynamic_cast<const SiStripRecHit1D*>(myhit_2);
377  if (hit1d_2) {
378  getSimHitRes(det_2, trackDirection_2, *hit1d_2, expWidth_2, &mypitch_2, drift_2);
379  clusterWidth_2 = hit1d_2->cluster()->amplitudes().size();
380  uint16_t firstStrip_2 = hit1d_2->cluster()->firstStrip();
381  uint16_t lastStrip_2 = firstStrip_2 + (hit1d_2->cluster()->amplitudes()).size() - 1;
382  atEdge_2 = (firstStrip_2 == 0 || lastStrip_2 == (Nstrips_2 - 1));
383  }
384 
385  const auto hit2d_2 = dynamic_cast<const SiStripRecHit2D*>(myhit_2);
386  if (hit2d_2) {
387  getSimHitRes(det_2, trackDirection_2, *hit2d_2, expWidth_2, &mypitch_2, drift_2);
388  clusterWidth_2 = hit2d_2->cluster()->amplitudes().size();
389  uint16_t firstStrip_2 = hit2d_2->cluster()->firstStrip();
390  uint16_t lastStrip_2 = firstStrip_2 + (hit2d_2->cluster()->amplitudes()).size() - 1;
391  atEdge_2 = (firstStrip_2 == 0 || lastStrip_2 == (Nstrips_2 - 1));
392  }
393 
394  // if(pairsOnly && (pitch != pitch2) ) fill = false;
395 
396  // Make AnalyticalPropagator to use in getPairParameters
397  AnalyticalPropagator mypropagator(magField_, anyDirection);
398 
399  if (!getPairParameters(&(*magField_),
400  mypropagator,
401  &(*itTraj2),
402  &(*itm),
403  pairPath,
404  hitDX,
405  trackDX,
406  trackDXE,
407  trackParamX,
408  trackParamY,
411  trackParamXE,
412  trackParamYE,
414  trackParamDYDZE)) {
415  } else {
416  LogDebug("HitResol") << " \n\n\n"
417  << " momentum " << mymom << "\n"
418  << " numHits " << numHits << "\n"
419  << " trackChi2 " << ProbTrackChi2 << "\n"
420  << " detID1 " << iidd1 << "\n"
421  << " pitch1 " << mypitch1 << "\n"
422  << " clusterW1 " << clusterWidth << "\n"
423  << " expectedW1 " << expWidth << "\n"
424  << " atEdge1 " << atEdge << "\n"
425  << " simpleRes " << simpleRes << "\n"
426  << " detID2 " << iidd2 << "\n"
427  << " clusterW2 " << clusterWidth_2 << "\n"
428  << " expectedW2 " << expWidth_2 << "\n"
429  << " atEdge2 " << atEdge_2 << "\n"
430  << " pairPath " << pairPath << "\n"
431  << " hitDX " << hitDX << "\n"
432  << " trackDX " << trackDX << "\n"
433  << " trackDXE " << trackDXE << "\n"
434  << " trackParamX " << trackParamX << "\n"
435  << " trackParamY " << trackParamY << "\n"
436  << " trackParamDXDZ " << trackParamDXDZ << "\n"
437  << " trackParamDYDZ " << trackParamDYDZ << "\n"
438  << " trackParamXE " << trackParamXE << "\n"
439  << " trackParamYE " << trackParamYE << "\n"
440  << " trackParamDXDZE" << trackParamDXDZE << "\n"
441  << " trackParamDYDZE" << trackParamDYDZE << std::endl;
442  reso->Fill();
443  }
444  } //itTraj2 != TMeas.end()
445  } //hit1->isValid()....
446  } // itm
447  } // it
448 }
449 
451  LogDebug("SiStripHitResolution:HitResol") << " Events Analysed " << events << endl;
452  LogDebug("SiStripHitResolution:HitResol") << " Number Of Tracked events " << EventTrackCKF << endl;
453 
454  reso->GetDirectory()->cd();
455  reso->Write();
456  treso->Write();
457 }
458 
460  double xx,
461  double xerr) {
462  double error = sqrt(parameters.second.xx() + xerr * xerr);
463  double separation = abs(parameters.first.x() - xx);
464  double consistency = separation / error;
465  return consistency;
466 }
467 
469  const LocalVector& trackdirection,
470  const TrackingRecHit& recHit,
471  float& trackWidth,
472  float* pitch,
473  LocalVector& drift) {
474  const auto stripdet = dynamic_cast<const StripGeomDetUnit*>(det);
475  const auto& topol = dynamic_cast<const StripTopology&>(stripdet->topology());
476 
477  LocalPoint position = recHit.localPosition();
478  (*pitch) = topol.localPitch(position);
479 
480  float anglealpha = 0;
481  if (trackdirection.z() != 0) {
482  anglealpha = atan(trackdirection.x() / trackdirection.z()) * TMath::RadToDeg();
483  }
484 
485  // LocalVector drift = stripcpe.driftDirection(stripdet);
486  float thickness = stripdet->surface().bounds().thickness();
487  float tanalpha = tan(anglealpha * TMath::DegToRad());
488  float tanalphaL = drift.x() / drift.z();
489  (trackWidth) = fabs((thickness / (*pitch)) * tanalpha - (thickness / (*pitch)) * tanalphaL);
490 }
491 
493  TrajectoryStateOnSurface theCombinedPredictedState;
494 
495  if (traj1->backwardPredictedState().isValid())
496  theCombinedPredictedState =
498  else
499  theCombinedPredictedState = traj1->forwardPredictedState();
500 
501  if (!theCombinedPredictedState.isValid()) {
502  return -100;
503  }
504 
505  const TransientTrackingRecHit::ConstRecHitPointer& firstRecHit = traj1->recHit();
506  double recHitX_1 = firstRecHit->localPosition().x();
507  return (theCombinedPredictedState.localPosition().x() - recHitX_1);
508 }
509 
510 //traj1 is the matched trajectory...traj2 is the original
513  const TrajectoryMeasurement* traj1,
514  const TrajectoryMeasurement* traj2,
515  float& pairPath,
516  float& hitDX,
517  float& trackDX,
518  float& trackDXE,
519  float& trackParamX,
520  float& trackParamY,
521  float& trackParamDXDZ,
522  float& trackParamDYDZ,
523  float& trackParamXE,
524  float& trackParamYE,
525  float& trackParamDXDZE,
526  float& trackParamDYDZE) {
527  pairPath = 0;
528  hitDX = 0;
529  trackDX = 0;
530  trackDXE = 0;
531 
532  trackParamX = 0;
533  trackParamY = 0;
534  trackParamDXDZ = 0;
535  trackParamDYDZ = 0;
536  trackParamXE = 0;
537  trackParamYE = 0;
538  trackParamDXDZE = 0;
539  trackParamDYDZE = 0;
540 
541  TrajectoryStateCombiner combiner_;
542 
543  // backward predicted state at module 1
544  const TrajectoryStateOnSurface& bwdPred1 = traj1->backwardPredictedState();
545  if (!bwdPred1.isValid())
546  return false;
547  LogDebug("HitResol") << "momentum from backward predicted state = " << bwdPred1.globalMomentum().mag() << endl;
548  // forward predicted state at module 2
549  const TrajectoryStateOnSurface& fwdPred2 = traj2->forwardPredictedState();
550  LogDebug("HitResol") << "momentum from forward predicted state = " << fwdPred2.globalMomentum().mag() << endl;
551  if (!fwdPred2.isValid())
552  return false;
553  // extrapolate fwdPred2 to module 1
554  TrajectoryStateOnSurface fwdPred2At1 = propagator.propagate(fwdPred2, bwdPred1.surface());
555  if (!fwdPred2At1.isValid())
556  return false;
557  // combine fwdPred2At1 with bwdPred1 (ref. state, best estimate without hits 1 and 2)
558  TrajectoryStateOnSurface comb1 = combiner_.combine(bwdPred1, fwdPred2At1);
559  if (!comb1.isValid())
560  return false;
561 
562  //
563  // propagation of reference parameters to module 2
564  //
565  std::pair<TrajectoryStateOnSurface, double> tsosWithS = propagator.propagateWithPath(comb1, fwdPred2.surface());
566  TrajectoryStateOnSurface comb1At2 = tsosWithS.first;
567  if (!comb1At2.isValid())
568  return false;
569  //distance of propagation from one surface to the next==could cut here
570  pairPath = tsosWithS.second;
571  if (TMath::Abs(pairPath) > 15)
572  return false; //cut to remove hit pairs > 15 cm apart
573 
574  // local parameters and errors on module 1
575  AlgebraicVector5 pars = comb1.localParameters().vector();
576  AlgebraicSymMatrix55 errs = comb1.localError().matrix();
577  //number 3 is predX
578  double predX1 = pars[3];
579  //track fitted parameters in local coordinates for position 0
580  (trackParamX) = pars[3];
581  (trackParamY) = pars[4];
582  (trackParamDXDZ) = pars[1];
583  (trackParamDYDZ) = pars[2];
584  (trackParamXE) = TMath::Sqrt(errs(3, 3));
585  (trackParamYE) = TMath::Sqrt(errs(4, 4));
586  (trackParamDXDZE) = TMath::Sqrt(errs(1, 1));
587  (trackParamDYDZE) = TMath::Sqrt(errs(2, 2));
588 
589  // local parameters and errors on module 2
590  pars = comb1At2.localParameters().vector();
591  errs = comb1At2.localError().matrix();
592  double predX2 = pars[3];
593 
597  JacobianLocalToCurvilinear jacLocToCurv(comb1.surface(), comb1.localParameters(), *magField_);
598  AnalyticalCurvilinearJacobian jacCurvToCurv(
599  comb1.globalParameters(), comb1At2.globalPosition(), comb1At2.globalMomentum(), tsosWithS.second);
600  JacobianCurvilinearToLocal jacCurvToLoc(comb1At2.surface(), comb1At2.localParameters(), *magField_);
601  // combined jacobian local-1-to-local-2
602  AlgebraicMatrix55 jacobian = jacLocToCurv.jacobian() * jacCurvToCurv.jacobian() * jacCurvToLoc.jacobian();
603  // covariance on module 1
604  AlgebraicSymMatrix55 covComb1 = comb1.localError().matrix();
605  // variance and correlations for predicted local_x on modules 1 and 2
606  double c00 = covComb1(3, 3);
607  double c10(0.);
608  double c11(0.);
609  for (int i = 1; i < 5; ++i) {
610  c10 += jacobian(3, i) * covComb1(i, 3);
611  for (int j = 1; j < 5; ++j)
612  c11 += jacobian(3, i) * covComb1(i, j) * jacobian(3, j);
613  }
614  // choose relative sign in order to minimize error on difference
615  double diff = c00 - 2 * fabs(c10) + c11;
616  diff = diff > 0 ? sqrt(diff) : -sqrt(-diff);
617  (trackDXE) = diff;
618  double relativeXSign_ = c10 > 0 ? -1 : 1;
619 
620  (trackDX) = predX1 + relativeXSign_ * predX2;
621 
622  double recHitX_1 = traj1->recHit()->localPosition().x();
623  double recHitX_2 = traj2->recHit()->localPosition().x();
624 
625  (hitDX) = recHitX_1 + relativeXSign_ * recHitX_2;
626 
627  return true;
628 }
629 
632  desc.add<edm::InputTag>("lumiScalers", edm::InputTag("scalersRawToDigi"));
633  desc.add<edm::InputTag>("combinatorialTracks", edm::InputTag("generalTracks"));
634  desc.add<edm::InputTag>("trajectories", edm::InputTag("generalTracks"));
635  desc.addUntracked<int>("CompressionSettings", -1);
636  desc.add<int>("Layer", 0);
637  desc.add<bool>("Debug", false);
638  desc.addUntracked<bool>("addLumi", false);
639  desc.addUntracked<bool>("cutOnTracks", false);
640  desc.addUntracked<unsigned int>("trackMultiplicity", 100);
641  desc.addUntracked<double>("MomentumCut", 3.);
642  desc.addUntracked<unsigned int>("UsePairsOnly", 1);
643  descriptions.addWithDefaultLabel(desc);
644 }
645 
646 //define this as a plug-in
std::pair< LocalPoint, LocalError > LocalValues
size
Write out results.
static const std::string kSharedResource
Definition: TFileService.h:76
double checkConsistency(const StripClusterParameterEstimator::LocalValues &parameters, double xx, double xerr)
Definition: HitResol.cc:459
int Nstrips_2
Definition: HitResol.h:160
static constexpr auto TEC
virtual int nstrips() const =0
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
float simpleRes
Definition: HitResol.h:137
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
int NumberOf_tracks
Definition: HitResol.h:109
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magFieldToken_
Definition: HitResol.h:82
int Nstrips
Definition: HitResol.h:159
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
const LocalTrajectoryError & localError() const
float trackDX
Definition: HitResol.h:139
float trackParamDYDZE
Definition: HitResol.h:148
HitResol(const edm::ParameterSet &conf)
Definition: HitResol.cc:71
float pairPath
Definition: HitResol.h:124
T z() const
Definition: PV3DBase.h:61
float track_trackChi2
Definition: HitResol.h:154
float trackParamDYDZ
Definition: HitResol.h:146
TrajectoryStateOnSurface const & forwardPredictedState() const
Access to forward predicted state (from fitter or builder)
int EventTrackCKF
Definition: HitResol.h:103
int numHits
Definition: HitResol.h:108
T const * product() const
Definition: Handle.h:70
LocalVector drift(const StripGeomDetUnit *, const MagneticField &, const SiStripLorentzAngle &)
Definition: ShallowTools.cc:36
const GlobalTrajectoryParameters & globalParameters() const
void endJob() override
Definition: HitResol.cc:450
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
float atEdge
Definition: HitResol.h:135
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepStd< double, 5, 5 > > AlgebraicMatrix55
float thickness
Definition: HitResol.h:131
const unsigned int usePairsOnly_
Definition: HitResol.h:90
const edm::EDGetTokenT< reco::TrackCollection > combinatorialTracks_token_
Definition: HitResol.h:73
const int compSettings_
Definition: HitResol.h:89
int events
Definition: HitResol.h:103
const LocalTrajectoryParameters & localParameters() const
bool isStereo(const DetId &id) const
const SurfaceType & surface() const
const edm::ESGetToken< SiStripQuality, SiStripQualityRcd > siStripQualityToken_
Definition: HitResol.h:81
float trackParamXE
Definition: HitResol.h:143
float trackParamX
Definition: HitResol.h:141
const edm::EDGetTokenT< std::vector< Trajectory > > tjToken_
Definition: HitResol.h:74
float trackParamYE
Definition: HitResol.h:144
T x() const
Definition: PV3DBase.h:59
bool getPairParameters(const MagneticField *magField_, AnalyticalPropagator &propagator, const TrajectoryMeasurement *traj1, const TrajectoryMeasurement *traj2, float &pairPath, float &hitDX, float &trackDX, float &trackDXE, float &trackParamX, float &trackParamY, float &trackParamDXDZ, float &trackParamDYDZ, float &trackParamXE, float &trackParamYE, float &trackParamDXDZE, float &trackParamDYDZE)
Definition: HitResol.cc:511
float trackDXE
Definition: HitResol.h:140
virtual LocalVector driftDirection(const StripGeomDetUnit *) const =0
GlobalPoint globalPosition() const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: HitResol.cc:630
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
Definition: HitResol.h:79
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
float track_eta
Definition: HitResol.h:151
void beginJob() override
Definition: HitResol.cc:92
T sqrt(T t)
Definition: SSEVec.h:19
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Definition: HitResol.cc:159
AlgebraicVector5 vector() const
float trackParamDXDZ
Definition: HitResol.h:145
LocalVector localDirection() const
unsigned int pairsOnly
Definition: HitResol.h:123
T mag() const
Definition: PV3DBase.h:64
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
TrajectoryStateOnSurface const & backwardPredictedState() const
Access to backward predicted state (from smoother)
ROOT::Math::SVector< double, 5 > AlgebraicVector5
float expWidth
Definition: HitResol.h:127
float ChiSquaredProbability(double chiSquared, double nrDOF)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
double getSimpleRes(const TrajectoryMeasurement *traj1)
Definition: HitResol.cc:492
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
std::map< TString, TH2F * > histos2d_
Definition: HitResol.h:97
float track_momentum
Definition: HitResol.h:149
float expWidth_2
Definition: HitResol.h:128
uint32_t glued(const DetId &id) const
Log< level::Info, false > LogInfo
const AlgebraicMatrix55 & jacobian() const
Definition: DetId.h:17
static constexpr auto TIB
std::vector< Trajectory > TrajectoryCollection
Definition: HitResol.h:62
TTree * treso
Definition: HitResol.h:96
float hitDX
Definition: HitResol.h:138
float trackWidth
Definition: HitResol.h:133
const edm::ESGetToken< StripClusterParameterEstimator, TkStripCPERecord > cpeToken_
Definition: HitResol.h:80
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
unsigned int iidd1
Definition: HitResol.h:121
GlobalVector globalMomentum() const
float ProbTrackChi2
Definition: HitResol.h:110
float trackParamDXDZE
Definition: HitResol.h:147
float track_pt
Definition: HitResol.h:150
fixed size matrix
HLT enums.
float mymom
Definition: HitResol.h:107
float track_phi
Definition: HitResol.h:153
static int position[264][3]
Definition: ReadPGInfo.cc:289
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoToken_
Definition: HitResol.h:78
unsigned int clusterWidth
Definition: HitResol.h:117
const AlgebraicSymMatrix55 & matrix() const
TTree * reso
Definition: HitResol.h:95
unsigned int iidd2
Definition: HitResol.h:122
float trackParamY
Definition: HitResol.h:142
std::vector< LumiScalers > LumiScalersCollection
Definition: LumiScalers.h:144
float atEdge_2
Definition: HitResol.h:136
unsigned int clusterWidth_2
Definition: HitResol.h:118
float mypitch1
Definition: HitResol.h:125
TSOS combine(const TSOS &pTsos1, const TSOS &pTsos2) const
const double momentumCut_
Definition: HitResol.h:88
void getSimHitRes(const GeomDetUnit *det, const LocalVector &trackdirection, const TrackingRecHit &recHit, float &trackWidth, float *pitch, LocalVector &drift)
Definition: HitResol.cc:468
ConstRecHitPointer const & recHit() const
#define LogDebug(id)