CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CosmicTrackFinder.cc
Go to the documentation of this file.
1 // Package: RecoTracker/SingleTrackPattern
2 // Class: CosmicTrackFinder
3 // Original Author: Michele Pioppi-INFN perugia
4 #include <memory>
5 #include <string>
6 
23 
25 
26 
27 namespace cms
28 {
29 
31  cosmicTrajectoryBuilder_(conf) ,
32  crackTrajectoryBuilder_(conf) ,
33  conf_(conf)
34  {
35  geometry=conf_.getUntrackedParameter<std::string>("GeometricStructure","STANDARD");
36  useHitsSplitting_=conf.getParameter<bool>("useHitsSplitting");
37  produces<TrackCandidateCollection>();
38  }
39 
40 
41  // Virtual destructor needed.
43 
44  // Functions that gets called by framework every event
46  {
47  using namespace std ;
48  edm::InputTag matchedrecHitsTag = conf_.getParameter<edm::InputTag>("matchedRecHits");
49  edm::InputTag rphirecHitsTag = conf_.getParameter<edm::InputTag>("rphirecHits");
50  edm::InputTag stereorecHitsTag = conf_.getParameter<edm::InputTag>("stereorecHits");
51  edm::InputTag pixelRecHitsTag = conf_.getParameter<edm::InputTag>("pixelRecHits");
52 
53 
54  edm::InputTag seedTag = conf_.getParameter<edm::InputTag>("cosmicSeeds");
55  // retrieve seeds
57  e.getByLabel(seedTag,seed);
58 
59  //retrieve PixelRecHits
60  static const SiPixelRecHitCollection s_empty;
61  const SiPixelRecHitCollection *pixelHitCollection = &s_empty;
63  if (geometry!="MTCC" && (geometry!="CRACK" )) {
64  if( e.getByLabel(pixelRecHitsTag, pixelHits)) {
65  pixelHitCollection = pixelHits.product();
66  } else {
67  edm::LogWarning("CosmicTrackFinder") << "Collection SiPixelRecHitCollection with InputTag " << pixelRecHitsTag << " cannot be found, using empty collection of same type.";
68  }
69  }
70 
71 
72 
73 
74  //retrieve StripRecHits
76  e.getByLabel( matchedrecHitsTag ,matchedrecHits);
78  e.getByLabel( rphirecHitsTag ,rphirecHits);
80  e.getByLabel( stereorecHitsTag, stereorecHits);
81 
82  // Step B: create empty output collection
83  std::auto_ptr<TrackCandidateCollection> output(new TrackCandidateCollection);
84 
87  edm::LogVerbatim("CosmicTrackFinder") << "========== Cosmic Track Finder Info ==========";
88  edm::LogVerbatim("CosmicTrackFinder") << " Numbers of Seeds " << (*seed).size();
89  if((*seed).size()>0){
90 
91  std::vector<Trajectory> trajoutput;
92 
93 
94  const TransientTrackingRecHitBuilder * hitBuilder = nullptr;
95  if(geometry!="CRACK" ) {
97  *stereorecHits,
98  *rphirecHits,
99  *matchedrecHits,
100  *pixelHitCollection,
101  es,
102  e,
103  trajoutput);
104  hitBuilder = cosmicTrajectoryBuilder_.hitBuilder();
105  } else {
107  *stereorecHits,
108  *rphirecHits,
109  *matchedrecHits,
110  *pixelHitCollection,
111  es,
112  e,
113  trajoutput);
114  hitBuilder = crackTrajectoryBuilder_.hitBuilder();
115  }
116  assert(hitBuilder);
117  Traj2TrackHits t2t(hitBuilder,true);
118 
119  edm::LogVerbatim("CosmicTrackFinder") << " Numbers of Temp Trajectories " << trajoutput.size();
120  edm::LogVerbatim("CosmicTrackFinder") << "========== END Info ==========";
121  if(trajoutput.size()>0){
122 
123  // crazyness...
124  std::vector<Trajectory*> tmpTraj;
125  std::vector<Trajectory>::iterator itr;
126  for (itr=trajoutput.begin();itr!=trajoutput.end();itr++)tmpTraj.push_back(&(*itr));
127 
128  //The best track is selected
129  //FOR MTCC the criteria are:
130  //1)# of layers,2) # of Hits,3)Chi2
131  if (geometry=="MTCC") stable_sort(tmpTraj.begin(),tmpTraj.end(),CompareTrajLay());
132  else stable_sort(tmpTraj.begin(),tmpTraj.end(),CompareTrajChi());
133 
135 
136  const Trajectory theTraj = *(*tmpTraj.begin());
137  bool seedplus=(theTraj.seed().direction()==alongMomentum);
138 
139  // std::cout << "CosmicTrackFinder " <<"Reconstruction " << (seedplus ? "along" : "opposite to") << " momentum" << std::endl;
140  LogDebug("CosmicTrackFinder")<<"Reconstruction " << (seedplus ? "along" : "opposite to") << " momentum";
141 
142  /*
143  // === the convention is to save always final tracks with hits sorted *along* momentum
144  // --- this is NOT what was necessaraly happening before and not consistent with what done in standard CKF (this is a candidate not a track)
145  */
147  if(theTraj.direction() == alongMomentum) std::cout << "cosmic: along momentum... " << std::endl;
148  t2t(theTraj,recHits,useHitsSplitting_);
149  recHits.reverse(); // according to original code
150 
151  /*
152  Trajectory::RecHitContainer thits;
153  //it->recHitsV(thits);
154  theTraj.recHitsV(thits,useHitsSplitting_);
155  edm::OwnVector<TrackingRecHit> recHits;
156  recHits.reserve(thits.size());
157  // reverse hit order
158  for (Trajectory::RecHitContainer::const_iterator hitIt = thits.end()-1;
159  hitIt >= thits.begin(); hitIt--) {
160  recHits.push_back( (**hitIt).hit()->clone());
161  }
162  */
163 
164  TSOS firstState;
165  unsigned int firstId;
166 
167  // assume not along momentum....
168  firstState=theTraj.lastMeasurement().updatedState();
169  firstId = theTraj.lastMeasurement().recHitR().rawId();
170  //firstId = recHits.front().rawId();
171 
172  /*
173  cout << "firstState y, z: " << firstState.globalPosition().y()
174  << " , " << firstState.globalPosition().z() << endl;
175 
176  */
177 
179  TSOS startingState( firstState.localParameters(), LocalTrajectoryError(C),
180  firstState.surface(),
181  firstState.magneticField() );
182 
183  // protection againt invalid initial states
184  if (! firstState.isValid()) {
185  edm::LogWarning("CosmicTrackFinder") << "invalid innerState, will not make TrackCandidate";
186  edm::OrphanHandle<TrackCandidateCollection> rTrackCand = e.put(output);
187  return;
188  }
189 
190  // FIXME in case of slitting this can happen see CkfTrackCandidateMakerBase
191  if(firstId != recHits.front().rawId()){
192  edm::LogWarning("CosmicTrackFinder") <<"Mismatch in DetID of first hit: firstID= " <<firstId
193  << " DetId= " << recHits.front().geographicalId().rawId();
194  edm::OrphanHandle<TrackCandidateCollection> rTrackCand = e.put(output);
195  return;
196  }
197 
198  PTrajectoryStateOnDet const & state = trajectoryStateTransform::persistentState( startingState, firstId);
199 
200 
201  output->push_back(TrackCandidate(recHits,theTraj.seed(),state,theTraj.seedRef() ) );
202 
203  }
204 
205  }
206  edm::OrphanHandle<TrackCandidateCollection> rTrackCand = e.put(output);
207  }
208 }
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
const LocalTrajectoryParameters & localParameters() const
ROOT::Math::SMatrixIdentity AlgebraicMatrixID
std::vector< TrackCandidate > TrackCandidateCollection
CosmicTrajectoryBuilder cosmicTrajectoryBuilder_
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
const MagneticField * magneticField() const
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
const TransientTrackingRecHitBuilder * hitBuilder() const
void reverse()
Definition: OwnVector.h:149
const SurfaceType & surface() const
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.
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
CRackTrajectoryBuilder crackTrajectoryBuilder_
CosmicTrackFinder(const edm::ParameterSet &conf)
const TransientTrackingRecHitBuilder * hitBuilder() const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:402
tuple conf
Definition: dbtoconf.py:185
T const * product() const
Definition: Handle.h:81
virtual void produce(edm::Event &e, const edm::EventSetup &c)
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
tuple cout
Definition: gather_cfg.py:121
DetId geographicalId() const
edm::ParameterSet conf_
reference front()
Definition: OwnVector.h:355
id_type rawId() const