CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 }
31 
32 
34 }
35 
36 
37 void CosmicTrajectoryBuilder::init(const edm::EventSetup& es, bool seedplus){
38 
39 
40  //services
43 
44 
45 
46  if (seedplus) {
47  seed_plus=true;
50  else {
51  seed_plus=false;
54  }
55 
56  theUpdator= new KFUpdator();
58 
59 
61  std::string builderName = conf_.getParameter<std::string>("TTRHBuilder");
62  es.get<TransientRecHitRecord>().get(builderName,theBuilder);
63 
64 
65  RHBuilder= theBuilder.product();
66 
67 
68 
69 
71  *theUpdator,
72  *theEstimator) ;
73 
74 
76  *theUpdator,
77  *theEstimator);
78 
79 }
80 
82  const SiStripRecHit2DCollection &collstereo,
83  const SiStripRecHit2DCollection &collrphi ,
84  const SiStripMatchedRecHit2DCollection &collmatched,
85  const SiPixelRecHitCollection &collpixel,
86  const edm::EventSetup& es,
87  edm::Event& e,
88  vector<Trajectory> &trajoutput)
89 {
90 
91 
92 
93 
94  std::vector<Trajectory> trajSmooth;
95  std::vector<Trajectory>::iterator trajIter;
96 
97  TrajectorySeedCollection::const_iterator iseed;
98  unsigned int IS=0;
99  for(iseed=collseed.begin();iseed!=collseed.end();iseed++){
100  bool seedplus=((*iseed).direction()==alongMomentum);
101  init(es,seedplus);
102  hits.clear();
103  trajFit.clear();
104  trajSmooth.clear();
105  //order all the hits
106  vector<const TrackingRecHit*> allHits= SortHits(collstereo,collrphi,collmatched,collpixel,*iseed);
107  Trajectory startingTraj = createStartingTrajectory(*iseed);
108  AddHit(startingTraj,allHits);
109  for (trajIter=trajFit.begin(); trajIter!=trajFit.end();trajIter++){
110  trajSmooth=theSmoother->trajectories((*trajIter));
111  }
112  for (trajIter= trajSmooth.begin(); trajIter!=trajSmooth.end();trajIter++){
113  if((*trajIter).isValid()){
114  trajoutput.push_back((*trajIter));
115  }
116  }
117  delete theUpdator;
118  delete theEstimator;
119  delete thePropagator;
120  delete thePropagatorOp;
121  delete theFitter;
122  delete theSmoother;
123  //Only the first 30 seeds are considered
124  if (IS>30) return;
125  IS++;
126 
127  }
128 }
129 
131 {
132  Trajectory result( seed, seed.direction());
133  std::vector<TM> seedMeas = seedMeasurements(seed);
134  if ( !seedMeas.empty()) {
135  for (std::vector<TM>::const_iterator i=seedMeas.begin(); i!=seedMeas.end(); i++){
136  result.push(*i);
137  }
138  }
139 
140  return result;
141 }
142 
143 
144 std::vector<TrajectoryMeasurement>
146 {
147  std::vector<TrajectoryMeasurement> result;
148  TrajectorySeed::range hitRange = seed.recHits();
149  for (TrajectorySeed::const_iterator ihit = hitRange.first;
150  ihit != hitRange.second; ihit++) {
151  //RC TransientTrackingRecHit* recHit = RHBuilder->build(&(*ihit));
153  const GeomDet* hitGeomDet = (&(*tracker))->idToDet( ihit->geographicalId());
154  TSOS invalidState( new BasicSingleTrajectoryState( hitGeomDet->surface()));
155 
156  if (ihit == hitRange.second - 1) {
157  TSOS updatedState=startingTSOS(seed);
158  result.push_back(TM( invalidState, updatedState, recHit));
159 
160  }
161  else {
162  result.push_back(TM( invalidState, recHit));
163  }
164 
165  }
166 
167  return result;
168 }
169 
170 
171 
172 
173 
174 vector<const TrackingRecHit*>
176  const SiStripRecHit2DCollection &collrphi ,
177  const SiStripMatchedRecHit2DCollection &collmatched,
178  const SiPixelRecHitCollection &collpixel,
179  const TrajectorySeed &seed){
180 
181 
182  //The Hits with global y more than the seed are discarded
183  //The Hits correspondign to the seed are discarded
184  //At the end all the hits are sorted in y
185  vector<const TrackingRecHit*> allHits;
186 
188  TrajectorySeed::range hRange= seed.recHits();
190  float yref=0.;
191  for (ihit = hRange.first;
192  ihit != hRange.second; ihit++) {
193  yref=RHBuilder->build(&(*ihit))->globalPosition().y();
194  hits.push_back((RHBuilder->build(&(*ihit))));
195  LogDebug("CosmicTrackFinder")<<"SEED HITS"<<RHBuilder->build(&(*ihit))->globalPosition();
196  }
197 
198 
199  if ((&collpixel)!=0){
201  for(ipix=collpixel.data().begin();ipix!=collpixel.data().end();ipix++){
202  float ych= RHBuilder->build(&(*ipix))->globalPosition().y();
203  if ((seed_plus && (ych<yref)) || (!(seed_plus) && (ych>yref)))
204  allHits.push_back(&(*ipix));
205  }
206  }
207 
208 
209 
210  if ((&collrphi)!=0){
211  for(istrip=collrphi.data().begin();istrip!=collrphi.data().end();istrip++){
212  float ych= RHBuilder->build(&(*istrip))->globalPosition().y();
213  if ((seed_plus && (ych<yref)) || (!(seed_plus) && (ych>yref)))
214  allHits.push_back(&(*istrip));
215  }
216  }
217 
218 
219 
220 
221  if ((&collstereo)!=0){
222  for(istrip=collstereo.data().begin();istrip!=collstereo.data().end();istrip++){
223  float ych= RHBuilder->build(&(*istrip))->globalPosition().y();
224  if ((seed_plus && (ych<yref)) || (!(seed_plus) && (ych>yref)))
225  allHits.push_back(&(*istrip));
226  }
227  }
228 
229 // SiStripMatchedRecHit2DCollection::DataContainer::const_iterator istripm;
230 // if ((&collmatched)!=0){
231 // for(istripm=collmatched.data().begin();istripm!=collmatched.data().end();istripm++){
232 // float ych= RHBuilder->build(&(*istripm))->globalPosition().y();
233 // if ((seed_plus && (ych<yref)) || (!(seed_plus) && (ych>yref)))
234 // allHits.push_back(&(*istripm));
235 // }
236 // }
237 
238  if (seed_plus){
239  stable_sort(allHits.begin(),allHits.end(),CompareHitY_plus(*tracker));
240  }
241  else {
242  stable_sort(allHits.begin(),allHits.end(),CompareHitY(*tracker));
243  }
244 
245  return allHits;
246 }
247 
250 {
251  PTrajectoryStateOnDet pState( seed.startingState());
252  const GeomDet* gdet = (&(*tracker))->idToDet(DetId(pState.detId()));
253  TSOS State= trajectoryStateTransform::transientState( pState, &(gdet->surface()),
254  &(*magfield));
255  return State;
256 
257 }
258 
260  vector<const TrackingRecHit*>Hits){
261 
262 
263  unsigned int icosm2;
264  unsigned int ibestdet;
265  float chi2min;
266  for (unsigned int icosmhit=0;icosmhit<Hits.size();icosmhit++){
267  GlobalPoint gphit=RHBuilder->build(Hits[icosmhit])->globalPosition();
268  unsigned int iraw= Hits[icosmhit]->geographicalId().rawId();
269  LogDebug("CosmicTrackFinder")<<" HIT POSITION "<< gphit;
270  //RC TransientTrackingRecHit* tmphit=RHBuilder->build(Hits[icosmhit]);
273  tracker->idToDet(Hits[icosmhit]->geographicalId())->surface());
274 
275  //After propagating the trajectory to a detector,
276  //find the most compatible hit in the det
277  chi2min=20000000;
278  ibestdet=1000;
279  if (prSt.isValid()){
280  LocalPoint prLoc = prSt.localPosition();
281  LogDebug("CosmicTrackFinder") <<"STATE PROPAGATED AT DET "<<iraw<<" "<<prSt;
282  for(icosm2=icosmhit;icosm2<Hits.size();icosm2++){
283 
284  if (iraw==Hits[icosm2]->geographicalId().rawId()){
286  float contr= theEstimator->estimate(prSt, *tmphit).second;
287  if (contr<chi2min) {
288  chi2min=contr;
289  ibestdet=icosm2;
290  }
291  if (icosm2!=icosmhit) icosmhit++;
292 
293  }
294  else icosm2=Hits.size();
295  }
296 
297  if(chi2min<chi2cut)
298  LogDebug("CosmicTrackFinder")<<"Chi2 contribution for hit at "
299  <<RHBuilder->build(Hits[ibestdet])->globalPosition()
300  <<" is "<<chi2min;
301 
302  if(traj.foundHits()<3 &&(chi2min<chi2cut)){
303  //check on the first hit after the seed
304  GlobalVector ck=RHBuilder->build(Hits[ibestdet])->globalPosition()-
306  if ((abs(ck.x()/ck.y())>2)||(abs(ck.z()/ck.y())>2)) chi2min=300;
307  }
308  if (chi2min<chi2cut){
309  if ( abs(prLoc.x()) < 25 && abs(prLoc.y()) < 25 ){
310  TransientTrackingRecHit::RecHitPointer tmphitbestdet=RHBuilder->build(Hits[ibestdet]);
311  TSOS UpdatedState= theUpdator->update( prSt, *tmphitbestdet);
312  if (UpdatedState.isValid()){
313 
314  traj.push(TM(prSt,UpdatedState,RHBuilder->build(Hits[ibestdet])
315  , chi2min));
316  LogDebug("CosmicTrackFinder") <<
317  "STATE UPDATED WITH HIT AT POSITION "
318  <<tmphitbestdet->globalPosition()
319  <<UpdatedState<<" "
320  <<traj.chiSquared();
321 
322  hits.push_back(&(*tmphitbestdet));
323  }
324  }else LogDebug("CosmicTrackFinder")<<" Hits outside module surface "<< prLoc;
325  }else LogDebug("CosmicTrackFinder")<<" State can not be updated with hit at position " <<gphit;
326  }else LogDebug("CosmicTrackFinder")<<" State can not be propagated at det "<< iraw;
327  }
328 
329 
330 
331  if ( qualityFilter( traj)){
332  const TrajectorySeed& tmpseed=traj.seed();
334  tracker->idToDet((*hits.begin())->geographicalId())->surface()).isValid()){
335  TSOS startingState=
337  tracker->idToDet((*hits.begin())->geographicalId())->surface());
338 
339  trajFit = theFitter->fit(tmpseed,hits, startingState );
340  }
341  }
342 
343 }
344 
345 
346 bool
348  int ngoodhits=0;
349  if(geometry=="MTCC"){
350  std::vector< ConstReferenceCountingPointer< TransientTrackingRecHit> > hits= traj.recHits();
351  std::vector< ConstReferenceCountingPointer< TransientTrackingRecHit> >::const_iterator hit;
352  for(hit=hits.begin();hit!=hits.end();hit++){
353  unsigned int iid=(*hit)->hit()->geographicalId().rawId();
354  //CHECK FOR 3 hits r-phi
355  if(((iid>>0)&0x3)!=1) ngoodhits++;
356  }
357  }
358  else ngoodhits=traj.foundHits();
359 
360  if ( ngoodhits >= theMinHits) {
361  return true;
362  }
363  else {
364  return false;
365  }
366 }
#define LogDebug(id)
PropagationDirection direction() const
T getParameter(std::string const &) const
int foundHits() const
Definition: Trajectory.h:224
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:265
edm::ESHandle< MagneticField > magfield
edm::ESHandle< TrackerGeometry > tracker
PropagatorWithMaterial * thePropagatorOp
T y() const
Definition: PV3DBase.h:62
#define abs(x)
Definition: mlp_lapack.h:159
GlobalPoint globalPosition() const
std::vector< Trajectory > trajFit
ConstRecHitContainer recHits(bool splitting=false) const
Definition: Trajectory.cc:67
void init(const edm::EventSetup &es, bool)
const TransientTrackingRecHitBuilder * RHBuilder
virtual std::vector< Trajectory > trajectories(const Trajectory &aTraj) const
std::vector< TrajectoryMeasurement > seedMeasurements(const TrajectorySeed &seed) const
std::vector< TrajectorySeed > TrajectorySeedCollection
virtual std::vector< Trajectory > fit(const Trajectory &aTraj) const
recHitContainer::const_iterator const_iterator
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:181
T z() const
Definition: PV3DBase.h:63
tuple result
Definition: query.py:137
const KFTrajectorySmoother * theSmoother
data_type const * data(size_t cell) const
std::pair< const_iterator, const_iterator > range
TSOS startingTSOS(const TrajectorySeed &seed) const
TrajectoryStateOnSurface updatedState() const
void AddHit(Trajectory &traj, std::vector< const TrackingRecHit * >Hits)
virtual std::pair< bool, double > estimate(const TrajectoryStateOnSurface &, const TransientTrackingRecHit &) const
tuple conf
Definition: dbtoconf.py:185
virtual TrajectoryStateOnSurface propagate(const TrajectoryStateOnSurface &tsos, const Plane &plane) const
const KFTrajectoryFitter * theFitter
Definition: DetId.h:20
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:194
PTrajectoryStateOnDet const & startingState() const
int iseed
Definition: AMPTWrapper.h:124
TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet &ts, const Surface *surface, const MagneticField *field)
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.
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
range recHits() const
bool qualityFilter(Trajectory traj)
PropagatorWithMaterial * thePropagator
std::vector< const TrackingRecHit * > SortHits(const SiStripRecHit2DCollection &collstereo, const SiStripRecHit2DCollection &collrphi, const SiStripMatchedRecHit2DCollection &collmatched, const SiPixelRecHitCollection &collpixel, const TrajectorySeed &seed)
Chi2MeasurementEstimator * theEstimator
const BoundPlane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TransientTrackingRecHit &) const
Definition: KFUpdator.cc:10
Trajectory createStartingTrajectory(const TrajectorySeed &seed) const
CosmicTrajectoryBuilder(const edm::ParameterSet &conf)
TransientTrackingRecHit::RecHitContainer hits
T x() const
Definition: PV3DBase.h:61
void push(const TrajectoryMeasurement &tm)
Definition: Trajectory.cc:35
double chiSquared() const
Definition: Trajectory.h:242