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  matchedrecHitsToken_ = consumes<SiStripMatchedRecHit2DCollection>(
38  conf_.getParameter<edm::InputTag>("matchedRecHits"));
39  rphirecHitsToken_ = consumes<SiStripRecHit2DCollection>(
40  conf_.getParameter<edm::InputTag>("rphirecHits"));
41  stereorecHitsToken_ = consumes<SiStripRecHit2DCollection>(
42  conf_.getParameter<edm::InputTag>("stereorecHits"));
43  pixelRecHitsToken_ = consumes<SiPixelRecHitCollection>(
44  conf_.getParameter<edm::InputTag>("pixelRecHits"));
45  seedToken_ = consumes<TrajectorySeedCollection>(
46  conf_.getParameter<edm::InputTag>("cosmicSeeds"));
47 
48  produces<TrackCandidateCollection>();
49  }
50 
51 
52  // Virtual destructor needed.
54 
55  // Functions that gets called by framework every event
57  {
58  using namespace std;
59 
60  // retrieve seeds
63 
64  //retrieve PixelRecHits
65  static const SiPixelRecHitCollection s_empty;
68  if (geometry!="MTCC" && (geometry!="CRACK" )) {
69  if( e.getByToken(pixelRecHitsToken_, pixelHits)) {
70  pixelHitCollection = pixelHits.product();
71  } else {
72  Labels l;
74  edm::LogWarning("CosmicTrackFinder")
75  << "Collection SiPixelRecHitCollection with InputTag "
76  << l.module
77  << " cannot be found, using empty collection of same type.";
78  }
79  }
80 
81 
82 
83 
84  //retrieve StripRecHits
86  e.getByToken(matchedrecHitsToken_, matchedrecHits);
88  e.getByToken(rphirecHitsToken_, rphirecHits);
90  e.getByToken(stereorecHitsToken_, stereorecHits);
91 
92  // Step B: create empty output collection
93  std::auto_ptr<TrackCandidateCollection> output(new TrackCandidateCollection);
94 
97  edm::LogVerbatim("CosmicTrackFinder") << "========== Cosmic Track Finder Info ==========";
98  edm::LogVerbatim("CosmicTrackFinder") << " Numbers of Seeds " << (*seed).size();
99  if((*seed).size()>0){
100 
101  std::vector<Trajectory> trajoutput;
102 
103 
104  const TransientTrackingRecHitBuilder * hitBuilder = nullptr;
105  if(geometry!="CRACK" ) {
107  *stereorecHits,
108  *rphirecHits,
109  *matchedrecHits,
111  es,
112  e,
113  trajoutput);
114  hitBuilder = cosmicTrajectoryBuilder_.hitBuilder();
115  } else {
117  *stereorecHits,
118  *rphirecHits,
119  *matchedrecHits,
121  es,
122  e,
123  trajoutput);
124  hitBuilder = crackTrajectoryBuilder_.hitBuilder();
125  }
126  assert(hitBuilder);
127  Traj2TrackHits t2t(hitBuilder,true);
128 
129  edm::LogVerbatim("CosmicTrackFinder") << " Numbers of Temp Trajectories " << trajoutput.size();
130  edm::LogVerbatim("CosmicTrackFinder") << "========== END Info ==========";
131  if(trajoutput.size()>0){
132 
133  // crazyness...
134  std::vector<Trajectory*> tmpTraj;
135  std::vector<Trajectory>::iterator itr;
136  for (itr=trajoutput.begin();itr!=trajoutput.end();itr++)tmpTraj.push_back(&(*itr));
137 
138  //The best track is selected
139  //FOR MTCC the criteria are:
140  //1)# of layers,2) # of Hits,3)Chi2
141  if (geometry=="MTCC") stable_sort(tmpTraj.begin(),tmpTraj.end(),CompareTrajLay());
142  else stable_sort(tmpTraj.begin(),tmpTraj.end(),CompareTrajChi());
143 
145 
146  const Trajectory theTraj = *(*tmpTraj.begin());
147  bool seedplus=(theTraj.seed().direction()==alongMomentum);
148 
149  // std::cout << "CosmicTrackFinder " <<"Reconstruction " << (seedplus ? "along" : "opposite to") << " momentum" << std::endl;
150  LogDebug("CosmicTrackFinder")<<"Reconstruction " << (seedplus ? "along" : "opposite to") << " momentum";
151 
152  /*
153  // === the convention is to save always final tracks with hits sorted *along* momentum
154  // --- this is NOT what was necessaraly happening before and not consistent with what done in standard CKF (this is a candidate not a track)
155  */
157  if(theTraj.direction() == alongMomentum) std::cout << "cosmic: along momentum... " << std::endl;
158  t2t(theTraj,recHits,useHitsSplitting_);
159  recHits.reverse(); // according to original code
160 
161  /*
162  Trajectory::RecHitContainer thits;
163  //it->recHitsV(thits);
164  theTraj.recHitsV(thits,useHitsSplitting_);
165  edm::OwnVector<TrackingRecHit> recHits;
166  recHits.reserve(thits.size());
167  // reverse hit order
168  for (Trajectory::RecHitContainer::const_iterator hitIt = thits.end()-1;
169  hitIt >= thits.begin(); hitIt--) {
170  recHits.push_back( (**hitIt).hit()->clone());
171  }
172  */
173 
174  TSOS firstState;
175  unsigned int firstId;
176 
177  // assume not along momentum....
178  firstState=theTraj.lastMeasurement().updatedState();
179  firstId = theTraj.lastMeasurement().recHitR().rawId();
180  //firstId = recHits.front().rawId();
181 
182  /*
183  cout << "firstState y, z: " << firstState.globalPosition().y()
184  << " , " << firstState.globalPosition().z() << endl;
185 
186  */
187 
189  TSOS startingState( firstState.localParameters(), LocalTrajectoryError(C),
190  firstState.surface(),
191  firstState.magneticField() );
192 
193  // protection againt invalid initial states
194  if (! firstState.isValid()) {
195  edm::LogWarning("CosmicTrackFinder") << "invalid innerState, will not make TrackCandidate";
196  edm::OrphanHandle<TrackCandidateCollection> rTrackCand = e.put(output);
197  return;
198  }
199 
200  // FIXME in case of slitting this can happen see CkfTrackCandidateMakerBase
201  if(firstId != recHits.front().rawId()){
202  edm::LogWarning("CosmicTrackFinder") <<"Mismatch in DetID of first hit: firstID= " <<firstId
203  << " DetId= " << recHits.front().geographicalId().rawId();
204  edm::OrphanHandle<TrackCandidateCollection> rTrackCand = e.put(output);
205  return;
206  }
207 
208  PTrajectoryStateOnDet const & state = trajectoryStateTransform::persistentState( startingState, firstId);
209 
210 
211  output->push_back(TrackCandidate(recHits,theTraj.seed(),state,theTraj.seedRef() ) );
212 
213  }
214 
215  }
216  edm::OrphanHandle<TrackCandidateCollection> rTrackCand = e.put(output);
217  }
218 }
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
const LocalTrajectoryParameters & localParameters() const
edm::EDGetTokenT< SiStripRecHit2DCollection > stereorecHitsToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
ROOT::Math::SMatrixIdentity AlgebraicMatrixID
assert(m_qm.get())
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_
edm::EDGetTokenT< SiPixelRecHitCollection > pixelRecHitsToken_
CosmicTrackFinder(const edm::ParameterSet &conf)
const TransientTrackingRecHitBuilder * hitBuilder() const
edm::EDGetTokenT< TrajectorySeedCollection > seedToken_
tuple conf
Definition: dbtoconf.py:185
edm::EDGetTokenT< SiStripMatchedRecHit2DCollection > matchedrecHitsToken_
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
edm::EDGetTokenT< SiStripRecHit2DCollection > rphirecHitsToken_
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
tuple cout
Definition: gather_cfg.py:121
DetId geographicalId() const
edm::ParameterSet conf_
reference front()
Definition: OwnVector.h:355
id_type rawId() const