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  auto const &hitRange = seed.recHits();
123  for (auto ihit = hitRange.begin(); ihit != hitRange.end(); 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.end() - 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  float yref = 0.;
152  for (auto const &recHit : seed.recHits()) {
153  yref = RHBuilder->build(&recHit)->globalPosition().y();
154  hits.push_back((RHBuilder->build(&recHit)));
155  LogDebug("CosmicTrackFinder") << "SEED HITS" << RHBuilder->build(&recHit)->globalPosition();
156  }
157 
159  for (ipix = collpixel.data().begin(); ipix != collpixel.data().end(); ipix++) {
160  float ych = RHBuilder->build(&(*ipix))->globalPosition().y();
161  if ((seed_plus && (ych < yref)) || (!(seed_plus) && (ych > yref)))
162  allHits.push_back(&(*ipix));
163  }
164 
165  for (istrip = collrphi.data().begin(); istrip != collrphi.data().end(); istrip++) {
166  float ych = RHBuilder->build(&(*istrip))->globalPosition().y();
167  if ((seed_plus && (ych < yref)) || (!(seed_plus) && (ych > yref)))
168  allHits.push_back(&(*istrip));
169  }
170 
171  for (istrip = collstereo.data().begin(); istrip != collstereo.data().end(); istrip++) {
172  float ych = RHBuilder->build(&(*istrip))->globalPosition().y();
173  if ((seed_plus && (ych < yref)) || (!(seed_plus) && (ych > yref)))
174  allHits.push_back(&(*istrip));
175  }
176 
177  if (seed_plus)
178  stable_sort(allHits.begin(), allHits.end(), CompareHitY_plus(*tracker));
179  else
180  stable_sort(allHits.begin(), allHits.end(), CompareHitY(*tracker));
181 
182  return allHits;
183 }
184 
186  PTrajectoryStateOnDet pState(seed.startingState());
187  const GeomDet *gdet = (&(*tracker))->idToDet(DetId(pState.detId()));
188  TSOS State = trajectoryStateTransform::transientState(pState, &(gdet->surface()), &(*magfield));
189  return State;
190 }
191 
192 void CosmicTrajectoryBuilder::AddHit(Trajectory &traj, const vector<const TrackingRecHit *> &Hits) {
193  unsigned int icosm2;
194  unsigned int ibestdet;
195  float chi2min;
196  for (unsigned int icosmhit = 0; icosmhit < Hits.size(); icosmhit++) {
197  GlobalPoint gphit = RHBuilder->build(Hits[icosmhit])->globalPosition();
198  unsigned int iraw = Hits[icosmhit]->geographicalId().rawId();
199  LogDebug("CosmicTrackFinder") << " HIT POSITION " << gphit;
200  //RC TransientTrackingRecHit* tmphit=RHBuilder->build(Hits[icosmhit]);
201  TransientTrackingRecHit::RecHitPointer tmphit = RHBuilder->build(Hits[icosmhit]);
202  TSOS prSt = thePropagator->propagate(traj.lastMeasurement().updatedState(),
203  tracker->idToDet(Hits[icosmhit]->geographicalId())->surface());
204 
205  //After propagating the trajectory to a detector,
206  //find the most compatible hit in the det
207  chi2min = 20000000;
208  ibestdet = 1000;
209  if (prSt.isValid()) {
210  LocalPoint prLoc = prSt.localPosition();
211  LogDebug("CosmicTrackFinder") << "STATE PROPAGATED AT DET " << iraw << " " << prSt;
212  for (icosm2 = icosmhit; icosm2 < Hits.size(); icosm2++) {
213  if (iraw == Hits[icosm2]->geographicalId().rawId()) {
214  TransientTrackingRecHit::RecHitPointer tmphit = RHBuilder->build(Hits[icosm2]);
215  float contr = theEstimator->estimate(prSt, *tmphit).second;
216  if (contr < chi2min) {
217  chi2min = contr;
218  ibestdet = icosm2;
219  }
220  if (icosm2 != icosmhit)
221  icosmhit++;
222 
223  } else
224  icosm2 = Hits.size();
225  }
226 
227  if (chi2min < chi2cut)
228  LogDebug("CosmicTrackFinder") << "Chi2 contribution for hit at "
229  << RHBuilder->build(Hits[ibestdet])->globalPosition() << " is " << chi2min;
230 
231  if (traj.foundHits() < 3 && (chi2min < chi2cut)) {
232  //check on the first hit after the seed
233  GlobalVector ck = RHBuilder->build(Hits[ibestdet])->globalPosition() -
235  if ((abs(ck.x() / ck.y()) > 2) || (abs(ck.z() / ck.y()) > 2))
236  chi2min = 300;
237  }
238  if (chi2min < chi2cut) {
239  if (abs(prLoc.x()) < 25 && abs(prLoc.y()) < 25) {
240  TransientTrackingRecHit::RecHitPointer tmphitbestdet = RHBuilder->build(Hits[ibestdet]);
241  TSOS UpdatedState = theUpdator->update(prSt, *tmphitbestdet);
242  if (UpdatedState.isValid()) {
243  traj.push(TM(prSt, UpdatedState, RHBuilder->build(Hits[ibestdet]), chi2min));
244  LogDebug("CosmicTrackFinder") << "STATE UPDATED WITH HIT AT POSITION " << tmphitbestdet->globalPosition()
245  << UpdatedState << " " << traj.chiSquared();
246 
247  hits.push_back(tmphitbestdet);
248  }
249  } else
250  LogDebug("CosmicTrackFinder") << " Hits outside module surface " << prLoc;
251  } else
252  LogDebug("CosmicTrackFinder") << " State can not be updated with hit at position " << gphit;
253  } else
254  LogDebug("CosmicTrackFinder") << " State can not be propagated at det " << iraw;
255  }
256 
257  if (qualityFilter(traj)) {
258  const TrajectorySeed &tmpseed = traj.seed();
259  if (thePropagatorOp
260  ->propagate(traj.lastMeasurement().updatedState(),
261  tracker->idToDet((*hits.begin())->geographicalId())->surface())
262  .isValid()) {
263  TSOS startingState = thePropagatorOp->propagate(traj.lastMeasurement().updatedState(),
264  tracker->idToDet((*hits.begin())->geographicalId())->surface());
265 
266  trajFit = theFitter->fit(tmpseed, hits, startingState);
267  }
268  }
269 }
270 
272  int ngoodhits = 0;
273  if (geometry == "MTCC") {
274  auto hits = traj.recHits();
275  for (auto hit = hits.begin(); hit != hits.end(); hit++) {
276  unsigned int iid = (*hit)->hit()->geographicalId().rawId();
277  //CHECK FOR 3 hits r-phi
278  if (((iid >> 0) & 0x3) != 1)
279  ngoodhits++;
280  }
281  } else
282  ngoodhits = traj.foundHits();
283 
284  if (ngoodhits >= theMinHits) {
285  return true;
286  } else {
287  return false;
288  }
289 }
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:192
init
int init
Definition: HydjetWrapper.h:64
mps_fire.i
i
Definition: mps_fire.py:428
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
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
TransientRecHitRecord
Definition: TransientRecHitRecord.h:14
edmNew::DetSetVector::const_iterator
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
Definition: DetSetVectorNew.h:197
oppositeToMomentum
Definition: PropagationDirection.h:4
TransientTrackingRecHit.h
TrajectoryMeasurement::updatedState
TrajectoryStateOnSurface const & updatedState() const
Definition: TrajectoryMeasurement.h:184
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
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
fileCollector.seed
seed
Definition: fileCollector.py:127
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:87
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:16
Chi2MeasurementEstimator_cfi.Chi2MeasurementEstimator
Chi2MeasurementEstimator
Definition: Chi2MeasurementEstimator_cfi.py:5
TrajectoryStateWithArbitraryError.h
IdealMagneticFieldRecord.h
edm::ESHandle< TransientTrackingRecHitBuilder >
Point3DBase< float, GlobalTag >
sistrip::SpyUtilities::isValid
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
Definition: SiStripSpyUtilities.cc:124
BasicSingleTrajectoryState
Definition: BasicSingleTrajectoryState.h:10
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:233
edm::ParameterSet
Definition: ParameterSet.h:47
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:271
edm::EventSetup
Definition: EventSetup.h:58
get
#define get
Trajectory::push
void push(const TrajectoryMeasurement &tm)
Definition: Trajectory.cc:50
CosmicTrajectoryBuilder::~CosmicTrajectoryBuilder
~CosmicTrajectoryBuilder()
Definition: CosmicTrajectoryBuilder.cc:33
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
CosmicTrajectoryBuilder.h
BasicSingleTrajectoryState.h
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:575
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:18
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
mps_fire.result
result
Definition: mps_fire.py:311
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:185
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
hit
Definition: SiStripHitEffFromCalibTree.cc:88
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37