CMS 3D CMS Logo

CosmicTrajectoryBuilder.cc
Go to the documentation of this file.
1 //
2 // Package: RecoTracker/SingleTrackPattern
3 // Class: CosmicTrajectoryBuilder
4 // Original Author: Michele Pioppi-INFN perugia
5 #include <vector>
6 #include <iostream>
7 #include <cmath>
8 
20 using namespace std;
22  //minimum number of hits per tracks
23 
24  theMinHits = conf.getParameter<int>("MinHits");
25  //cut on chi2
26  chi2cut = conf.getParameter<double>("Chi2Cut");
27  edm::LogInfo("CosmicTrackFinder") << "Minimum number of hits " << theMinHits << " Cut on Chi2= " << chi2cut;
28 
29  geometry = conf.getUntrackedParameter<std::string>("GeometricStructure", "STANDARD");
30  theBuilderName = conf.getParameter<std::string>("TTRHBuilder");
31 }
32 
34 
35 void CosmicTrajectoryBuilder::init(const edm::EventSetup &es, bool seedplus) {
36  // FIXME: this is a memory leak generator
37 
38  //services
41 
42  if (seedplus) {
43  seed_plus = true;
44  thePropagator = new PropagatorWithMaterial(alongMomentum, 0.1057, &(*magfield));
45  thePropagatorOp = new PropagatorWithMaterial(oppositeToMomentum, 0.1057, &(*magfield));
46  } else {
47  seed_plus = false;
48  thePropagator = new PropagatorWithMaterial(oppositeToMomentum, 0.1057, &(*magfield));
49  thePropagatorOp = new PropagatorWithMaterial(alongMomentum, 0.1057, &(*magfield));
50  }
51 
52  theUpdator = new KFUpdator();
53  theEstimator = new Chi2MeasurementEstimator(chi2cut);
54 
56  es.get<TransientRecHitRecord>().get(theBuilderName, theBuilder);
57 
58  RHBuilder = theBuilder.product();
59  hitCloner = static_cast<TkTransientTrackingRecHitBuilder const *>(RHBuilder)->cloner();
60 
61  theFitter = new KFTrajectoryFitter(*thePropagator, *theUpdator, *theEstimator);
62  theFitter->setHitCloner(&hitCloner);
63 
64  theSmoother = new KFTrajectorySmoother(*thePropagatorOp, *theUpdator, *theEstimator);
65  theSmoother->setHitCloner(&hitCloner);
66 }
67 
69  const SiStripRecHit2DCollection &collstereo,
70  const SiStripRecHit2DCollection &collrphi,
71  const SiStripMatchedRecHit2DCollection &collmatched,
72  const SiPixelRecHitCollection &collpixel,
73  const edm::EventSetup &es,
74  edm::Event &e,
75  vector<Trajectory> &trajoutput) {
76  std::vector<Trajectory> trajSmooth;
77  std::vector<Trajectory>::iterator trajIter;
78 
79  TrajectorySeedCollection::const_iterator iseed;
80  unsigned int IS = 0;
81  for (iseed = collseed.begin(); iseed != collseed.end(); iseed++) {
82  bool seedplus = ((*iseed).direction() == alongMomentum);
83  init(es, seedplus);
84  hits.clear();
85  trajFit.clear();
86  trajSmooth.clear();
87  //order all the hits
88  vector<const TrackingRecHit *> allHits = SortHits(collstereo, collrphi, collmatched, collpixel, *iseed);
89  Trajectory startingTraj = createStartingTrajectory(*iseed);
90  AddHit(startingTraj, allHits);
91  for (trajIter = trajFit.begin(); trajIter != trajFit.end(); trajIter++) {
92  trajSmooth = theSmoother->trajectories((*trajIter));
93  }
94  for (trajIter = trajSmooth.begin(); trajIter != trajSmooth.end(); trajIter++) {
95  if ((*trajIter).isValid()) {
96  trajoutput.push_back((*trajIter));
97  }
98  }
99  delete theUpdator;
100  delete theEstimator;
101  delete thePropagator;
102  delete thePropagatorOp;
103  delete theFitter;
104  delete theSmoother;
105  //Only the first 30 seeds are considered
106  if (IS > 30)
107  return;
108  IS++;
109  }
110 }
111 
113  Trajectory result(seed, seed.direction());
114  std::vector<TM> &&seedMeas = seedMeasurements(seed);
115  for (auto &i : seedMeas)
116  result.push(std::move(i));
117  return result;
118 }
119 
120 std::vector<TrajectoryMeasurement> CosmicTrajectoryBuilder::seedMeasurements(const TrajectorySeed &seed) const {
121  std::vector<TrajectoryMeasurement> result;
122  TrajectorySeed::range hitRange = seed.recHits();
123  for (TrajectorySeed::const_iterator ihit = hitRange.first; ihit != hitRange.second; ihit++) {
124  //RC TransientTrackingRecHit* recHit = RHBuilder->build(&(*ihit));
125  TransientTrackingRecHit::RecHitPointer recHit = RHBuilder->build(&(*ihit));
126  const GeomDet *hitGeomDet = (&(*tracker))->idToDet(ihit->geographicalId());
127  TSOS invalidState(new BasicSingleTrajectoryState(hitGeomDet->surface()));
128 
129  if (ihit == hitRange.second - 1) {
130  TSOS updatedState = startingTSOS(seed);
131  result.emplace_back(invalidState, updatedState, recHit);
132  } else {
133  result.emplace_back(invalidState, recHit);
134  }
135  }
136 
137  return result;
138 }
139 
140 vector<const TrackingRecHit *> CosmicTrajectoryBuilder::SortHits(const SiStripRecHit2DCollection &collstereo,
141  const SiStripRecHit2DCollection &collrphi,
142  const SiStripMatchedRecHit2DCollection &collmatched,
143  const SiPixelRecHitCollection &collpixel,
144  const TrajectorySeed &seed) {
145  //The Hits with global y more than the seed are discarded
146  //The Hits correspondign to the seed are discarded
147  //At the end all the hits are sorted in y
148  vector<const TrackingRecHit *> allHits;
149 
151  TrajectorySeed::range hRange = seed.recHits();
153  float yref = 0.;
154  for (ihit = hRange.first; ihit != hRange.second; ihit++) {
155  yref = RHBuilder->build(&(*ihit))->globalPosition().y();
156  hits.push_back((RHBuilder->build(&(*ihit))));
157  LogDebug("CosmicTrackFinder") << "SEED HITS" << RHBuilder->build(&(*ihit))->globalPosition();
158  }
159 
161  for (ipix = collpixel.data().begin(); ipix != collpixel.data().end(); ipix++) {
162  float ych = RHBuilder->build(&(*ipix))->globalPosition().y();
163  if ((seed_plus && (ych < yref)) || (!(seed_plus) && (ych > yref)))
164  allHits.push_back(&(*ipix));
165  }
166 
167  for (istrip = collrphi.data().begin(); istrip != collrphi.data().end(); istrip++) {
168  float ych = RHBuilder->build(&(*istrip))->globalPosition().y();
169  if ((seed_plus && (ych < yref)) || (!(seed_plus) && (ych > yref)))
170  allHits.push_back(&(*istrip));
171  }
172 
173  for (istrip = collstereo.data().begin(); istrip != collstereo.data().end(); istrip++) {
174  float ych = RHBuilder->build(&(*istrip))->globalPosition().y();
175  if ((seed_plus && (ych < yref)) || (!(seed_plus) && (ych > yref)))
176  allHits.push_back(&(*istrip));
177  }
178 
179  if (seed_plus)
180  stable_sort(allHits.begin(), allHits.end(), CompareHitY_plus(*tracker));
181  else
182  stable_sort(allHits.begin(), allHits.end(), CompareHitY(*tracker));
183 
184  return allHits;
185 }
186 
188  PTrajectoryStateOnDet pState(seed.startingState());
189  const GeomDet *gdet = (&(*tracker))->idToDet(DetId(pState.detId()));
190  TSOS State = trajectoryStateTransform::transientState(pState, &(gdet->surface()), &(*magfield));
191  return State;
192 }
193 
194 void CosmicTrajectoryBuilder::AddHit(Trajectory &traj, const vector<const TrackingRecHit *> &Hits) {
195  unsigned int icosm2;
196  unsigned int ibestdet;
197  float chi2min;
198  for (unsigned int icosmhit = 0; icosmhit < Hits.size(); icosmhit++) {
199  GlobalPoint gphit = RHBuilder->build(Hits[icosmhit])->globalPosition();
200  unsigned int iraw = Hits[icosmhit]->geographicalId().rawId();
201  LogDebug("CosmicTrackFinder") << " HIT POSITION " << gphit;
202  //RC TransientTrackingRecHit* tmphit=RHBuilder->build(Hits[icosmhit]);
203  TransientTrackingRecHit::RecHitPointer tmphit = RHBuilder->build(Hits[icosmhit]);
204  TSOS prSt = thePropagator->propagate(traj.lastMeasurement().updatedState(),
205  tracker->idToDet(Hits[icosmhit]->geographicalId())->surface());
206 
207  //After propagating the trajectory to a detector,
208  //find the most compatible hit in the det
209  chi2min = 20000000;
210  ibestdet = 1000;
211  if (prSt.isValid()) {
212  LocalPoint prLoc = prSt.localPosition();
213  LogDebug("CosmicTrackFinder") << "STATE PROPAGATED AT DET " << iraw << " " << prSt;
214  for (icosm2 = icosmhit; icosm2 < Hits.size(); icosm2++) {
215  if (iraw == Hits[icosm2]->geographicalId().rawId()) {
216  TransientTrackingRecHit::RecHitPointer tmphit = RHBuilder->build(Hits[icosm2]);
217  float contr = theEstimator->estimate(prSt, *tmphit).second;
218  if (contr < chi2min) {
219  chi2min = contr;
220  ibestdet = icosm2;
221  }
222  if (icosm2 != icosmhit)
223  icosmhit++;
224 
225  } else
226  icosm2 = Hits.size();
227  }
228 
229  if (chi2min < chi2cut)
230  LogDebug("CosmicTrackFinder") << "Chi2 contribution for hit at "
231  << RHBuilder->build(Hits[ibestdet])->globalPosition() << " is " << chi2min;
232 
233  if (traj.foundHits() < 3 && (chi2min < chi2cut)) {
234  //check on the first hit after the seed
235  GlobalVector ck = RHBuilder->build(Hits[ibestdet])->globalPosition() -
237  if ((abs(ck.x() / ck.y()) > 2) || (abs(ck.z() / ck.y()) > 2))
238  chi2min = 300;
239  }
240  if (chi2min < chi2cut) {
241  if (abs(prLoc.x()) < 25 && abs(prLoc.y()) < 25) {
242  TransientTrackingRecHit::RecHitPointer tmphitbestdet = RHBuilder->build(Hits[ibestdet]);
243  TSOS UpdatedState = theUpdator->update(prSt, *tmphitbestdet);
244  if (UpdatedState.isValid()) {
245  traj.push(TM(prSt, UpdatedState, RHBuilder->build(Hits[ibestdet]), chi2min));
246  LogDebug("CosmicTrackFinder") << "STATE UPDATED WITH HIT AT POSITION " << tmphitbestdet->globalPosition()
247  << UpdatedState << " " << traj.chiSquared();
248 
249  hits.push_back(tmphitbestdet);
250  }
251  } else
252  LogDebug("CosmicTrackFinder") << " Hits outside module surface " << prLoc;
253  } else
254  LogDebug("CosmicTrackFinder") << " State can not be updated with hit at position " << gphit;
255  } else
256  LogDebug("CosmicTrackFinder") << " State can not be propagated at det " << iraw;
257  }
258 
259  if (qualityFilter(traj)) {
260  const TrajectorySeed &tmpseed = traj.seed();
261  if (thePropagatorOp
262  ->propagate(traj.lastMeasurement().updatedState(),
263  tracker->idToDet((*hits.begin())->geographicalId())->surface())
264  .isValid()) {
265  TSOS startingState = thePropagatorOp->propagate(traj.lastMeasurement().updatedState(),
266  tracker->idToDet((*hits.begin())->geographicalId())->surface());
267 
268  trajFit = theFitter->fit(tmpseed, hits, startingState);
269  }
270  }
271 }
272 
274  int ngoodhits = 0;
275  if (geometry == "MTCC") {
276  auto hits = traj.recHits();
277  for (auto hit = hits.begin(); hit != hits.end(); hit++) {
278  unsigned int iid = (*hit)->hit()->geographicalId().rawId();
279  //CHECK FOR 3 hits r-phi
280  if (((iid >> 0) & 0x3) != 1)
281  ngoodhits++;
282  }
283  } else
284  ngoodhits = traj.foundHits();
285 
286  if (ngoodhits >= theMinHits) {
287  return true;
288  } else {
289  return false;
290  }
291 }
Vector3DBase
Definition: Vector3DBase.h:8
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
CosmicTrajectoryBuilder::AddHit
void AddHit(Trajectory &traj, const std::vector< const TrackingRecHit * > &Hits)
Definition: CosmicTrajectoryBuilder.cc:194
init
int init
Definition: HydjetWrapper.h:64
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
GeomDet
Definition: GeomDet.h:27
TrajectorySeedCollection
std::vector< TrajectorySeed > TrajectorySeedCollection
Definition: TrajectorySeedCollection.h:6
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
hcaldqm::flag::State
State
Definition: Flag.h:13
Trajectory::chiSquared
float chiSquared() const
Definition: Trajectory.h:241
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
TrajectorySeed::range
std::pair< const_iterator, const_iterator > range
Definition: TrajectorySeed.h:21
trackAssociatorByChi2_cfi.chi2cut
chi2cut
Definition: trackAssociatorByChi2_cfi.py:4
TransientRecHitRecord.h
TrajectoryStateOnSurface::globalPosition
GlobalPoint globalPosition() const
Definition: TrajectoryStateOnSurface.h:65
geometry
Definition: geometry.py:1
edm::LogInfo
Definition: MessageLogger.h:254
TransientRecHitRecord
Definition: TransientRecHitRecord.h:14
edmNew::DetSetVector::const_iterator
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
Definition: DetSetVectorNew.h:231
oppositeToMomentum
Definition: PropagationDirection.h:4
TrajectorySeed::const_iterator
recHitContainer::const_iterator const_iterator
Definition: TrajectorySeed.h:20
TransientTrackingRecHit.h
TrajectoryMeasurement::updatedState
TrajectoryStateOnSurface const & updatedState() const
Definition: TrajectoryMeasurement.h:184
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
TrackingRecHit::RecHitPointer
std::shared_ptr< TrackingRecHit const > RecHitPointer
Definition: TrackingRecHit.h:24
Trajectory::foundHits
int foundHits() const
Definition: Trajectory.h:206
CompareHitY_plus
Definition: CosmicTrajectoryBuilder.h:58
rpcPointValidation_cfi.recHit
recHit
Definition: rpcPointValidation_cfi.py:7
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
IdealMagneticFieldRecord
Definition: IdealMagneticFieldRecord.h:11
DetId
Definition: DetId.h:17
GeomDet::surface
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
PropagatorWithMaterial
Definition: PropagatorWithMaterial.h:25
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:15
Chi2MeasurementEstimator_cfi.Chi2MeasurementEstimator
Chi2MeasurementEstimator
Definition: Chi2MeasurementEstimator_cfi.py:5
TrajectoryStateWithArbitraryError.h
IdealMagneticFieldRecord.h
edm::ESHandle< TransientTrackingRecHitBuilder >
Point3DBase< float, GlobalTag >
BasicSingleTrajectoryState
Definition: BasicSingleTrajectoryState.h:10
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
CosmicTrajectoryBuilder::run
void run(const TrajectorySeedCollection &collseed, const SiStripRecHit2DCollection &collstereo, const SiStripRecHit2DCollection &collrphi, const SiStripMatchedRecHit2DCollection &collmatched, const SiPixelRecHitCollection &collpixel, const edm::EventSetup &es, edm::Event &e, std::vector< Trajectory > &trajoutput)
Runs the algorithm.
Definition: CosmicTrajectoryBuilder.cc:68
PbPb_ZMuSkimMuonDPG_cff.tracker
tracker
Definition: PbPb_ZMuSkimMuonDPG_cff.py:60
TrajectoryStateOnSurface::localPosition
LocalPoint localPosition() const
Definition: TrajectoryStateOnSurface.h:74
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
iseed
int iseed
Definition: AMPTWrapper.h:134
CosmicTrajectoryBuilder::init
void init(const edm::EventSetup &es, bool)
Definition: CosmicTrajectoryBuilder.cc:35
Trajectory::lastMeasurement
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:150
State
State
Definition: RPixErrorChecker.h:15
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
TrajectoryStateOnSurface::update
void update(const LocalTrajectoryParameters &p, const SurfaceType &aSurface, const MagneticField *field, SurfaceSide side=SurfaceSideDefinition::atCenterOfSurface)
Definition: TrajectoryStateOnSurface.cc:6
CosmicTrajectoryBuilder::SortHits
std::vector< const TrackingRecHit * > SortHits(const SiStripRecHit2DCollection &collstereo, const SiStripRecHit2DCollection &collrphi, const SiStripMatchedRecHit2DCollection &collmatched, const SiPixelRecHitCollection &collpixel, const TrajectorySeed &seed)
Definition: CosmicTrajectoryBuilder.cc:140
trajectoryStateTransform::transientState
TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet &ts, const Surface *surface, const MagneticField *field)
Definition: TrajectoryStateTransform.cc:35
CosmicTrajectoryBuilder::CosmicTrajectoryBuilder
CosmicTrajectoryBuilder(const edm::ParameterSet &conf)
Definition: CosmicTrajectoryBuilder.cc:21
CosmicTrajectoryBuilder::qualityFilter
bool qualityFilter(const Trajectory &traj)
Definition: CosmicTrajectoryBuilder.cc:273
edm::EventSetup
Definition: EventSetup.h:57
get
#define get
Trajectory::push
void push(const TrajectoryMeasurement &tm)
Definition: Trajectory.cc:50
CosmicTrajectoryBuilder::~CosmicTrajectoryBuilder
~CosmicTrajectoryBuilder()
Definition: CosmicTrajectoryBuilder.cc:33
CosmicTrajectoryBuilder.h
BasicSingleTrajectoryState.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Trajectory::recHits
ConstRecHitContainer recHits() const
Definition: Trajectory.h:186
edmNew::DetSetVector
Definition: DetSetNew.h:13
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
CosmicTrajectoryBuilder::seedMeasurements
std::vector< TrajectoryMeasurement > seedMeasurements(const TrajectorySeed &seed) const
Definition: CosmicTrajectoryBuilder.cc:120
Trajectory::firstMeasurement
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:166
edmNew::DetSetVector::data
data_type const * data(size_t cell) const
Definition: DetSetVectorNew.h:602
TrackInfoProducer_cfi.updatedState
updatedState
Definition: TrackInfoProducer_cfi.py:6
Trajectory
Definition: Trajectory.h:38
KFTrajectorySmoother
Definition: KFTrajectorySmoother.h:20
TrackingComponentsRecord.h
Trajectory::seed
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:263
TrajectorySeed
Definition: TrajectorySeed.h:17
mps_fire.result
result
Definition: mps_fire.py:303
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
CosmicTrajectoryBuilder::createStartingTrajectory
Trajectory createStartingTrajectory(const TrajectorySeed &seed) const
Definition: CosmicTrajectoryBuilder.cc:112
CompareHitY
Definition: CosmicTrajectoryBuilder.h:44
PTrajectoryStateOnDet
Definition: PTrajectoryStateOnDet.h:10
CosmicTrajectoryBuilder::startingTSOS
TSOS startingTSOS(const TrajectorySeed &seed) const
Definition: CosmicTrajectoryBuilder.cc:187
ParameterSet.h
OwnVector.h
edm::Event
Definition: Event.h:73
TrajectoryMeasurement
Definition: TrajectoryMeasurement.h:25
volumeBasedMagneticField_160812_cfi.magfield
magfield
Definition: volumeBasedMagneticField_160812_cfi.py:11
GlobalPoint.h
alongMomentum
Definition: PropagationDirection.h:4
KFUpdator
Definition: KFUpdator.h:32
TrajectoryStateOnSurface::isValid
bool isValid() const
Definition: TrajectoryStateOnSurface.h:54
SurveyInfoScenario_cff.seed
seed
Definition: SurveyInfoScenario_cff.py:295
hit
Definition: SiStripHitEffFromCalibTree.cc:88
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37