CMS 3D CMS Logo

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 namespace cms {
27 
29  : cosmicTrajectoryBuilder_(conf), crackTrajectoryBuilder_(conf) {
30  geometry = conf.getUntrackedParameter<std::string>("GeometricStructure", "STANDARD");
31  useHitsSplitting_ = conf.getParameter<bool>("useHitsSplitting");
33  consumes<SiStripMatchedRecHit2DCollection>(conf.getParameter<edm::InputTag>("matchedRecHits"));
34  rphirecHitsToken_ = consumes<SiStripRecHit2DCollection>(conf.getParameter<edm::InputTag>("rphirecHits"));
35  stereorecHitsToken_ = consumes<SiStripRecHit2DCollection>(conf.getParameter<edm::InputTag>("stereorecHits"));
36  pixelRecHitsToken_ = consumes<SiPixelRecHitCollection>(conf.getParameter<edm::InputTag>("pixelRecHits"));
37  seedToken_ = consumes<TrajectorySeedCollection>(conf.getParameter<edm::InputTag>("cosmicSeeds"));
38 
39  produces<TrackCandidateCollection>();
40  }
41 
42  // Virtual destructor needed.
44 
45  // Functions that gets called by framework every event
47  using namespace std;
48 
49  // retrieve seeds
51  e.getByToken(seedToken_, seed);
52 
53  //retrieve PixelRecHits
54  static const SiPixelRecHitCollection s_empty;
57  if (geometry != "MTCC" && (geometry != "CRACK")) {
58  if (e.getByToken(pixelRecHitsToken_, pixelHits)) {
59  pixelHitCollection = pixelHits.product();
60  } else {
61  Labels l;
62  labelsForToken(pixelRecHitsToken_, l);
63  edm::LogWarning("CosmicTrackFinder") << "Collection SiPixelRecHitCollection with InputTag " << l.module
64  << " cannot be found, using empty collection of same type.";
65  }
66  }
67 
68  //retrieve StripRecHits
70  e.getByToken(matchedrecHitsToken_, matchedrecHits);
72  e.getByToken(rphirecHitsToken_, rphirecHits);
74  e.getByToken(stereorecHitsToken_, stereorecHits);
75 
76  // Step B: create empty output collection
77  auto output = std::make_unique<TrackCandidateCollection>();
78 
80  es.get<TrackerDigiGeometryRecord>().get(tracker);
81  edm::LogVerbatim("CosmicTrackFinder") << "========== Cosmic Track Finder Info ==========";
82  edm::LogVerbatim("CosmicTrackFinder") << " Numbers of Seeds " << (*seed).size();
83  if (!(*seed).empty()) {
84  std::vector<Trajectory> trajoutput;
85 
86  const TransientTrackingRecHitBuilder* hitBuilder = nullptr;
87  if (geometry != "CRACK") {
89  *seed, *stereorecHits, *rphirecHits, *matchedrecHits, *pixelHitCollection, es, e, trajoutput);
90  hitBuilder = cosmicTrajectoryBuilder_.hitBuilder();
91  } else {
93  *seed, *stereorecHits, *rphirecHits, *matchedrecHits, *pixelHitCollection, es, e, trajoutput);
94  hitBuilder = crackTrajectoryBuilder_.hitBuilder();
95  }
96  assert(hitBuilder);
97  Traj2TrackHits t2t(hitBuilder, true);
98 
99  edm::LogVerbatim("CosmicTrackFinder") << " Numbers of Temp Trajectories " << trajoutput.size();
100  edm::LogVerbatim("CosmicTrackFinder") << "========== END Info ==========";
101  if (!trajoutput.empty()) {
102  // crazyness...
103  std::vector<Trajectory*> tmpTraj;
104  std::vector<Trajectory>::iterator itr;
105  for (itr = trajoutput.begin(); itr != trajoutput.end(); itr++)
106  tmpTraj.push_back(&(*itr));
107 
108  //The best track is selected
109  //FOR MTCC the criteria are:
110  //1)# of layers,2) # of Hits,3)Chi2
111  if (geometry == "MTCC")
112  stable_sort(tmpTraj.begin(), tmpTraj.end(), CompareTrajLay());
113  else
114  stable_sort(tmpTraj.begin(), tmpTraj.end(), CompareTrajChi());
115 
117 
118  const Trajectory theTraj = *(*tmpTraj.begin());
119  bool seedplus = (theTraj.seed().direction() == alongMomentum);
120 
121  // std::cout << "CosmicTrackFinder " <<"Reconstruction " << (seedplus ? "along" : "opposite to") << " momentum" << std::endl;
122  LogDebug("CosmicTrackFinder") << "Reconstruction " << (seedplus ? "along" : "opposite to") << " momentum";
123 
124  /*
125  // === the convention is to save always final tracks with hits sorted *along* momentum
126  // --- this is NOT what was necessaraly happening before and not consistent with what done in standard CKF (this is a candidate not a track)
127  */
129  if (theTraj.direction() == alongMomentum)
130  std::cout << "cosmic: along momentum... " << std::endl;
131  t2t(theTraj, recHits, useHitsSplitting_);
132  recHits.reverse(); // according to original code
133 
134  /*
135  Trajectory::RecHitContainer thits;
136  //it->recHitsV(thits);
137  theTraj.recHitsV(thits,useHitsSplitting_);
138  edm::OwnVector<TrackingRecHit> recHits;
139  recHits.reserve(thits.size());
140  // reverse hit order
141  for (Trajectory::RecHitContainer::const_iterator hitIt = thits.end()-1;
142  hitIt >= thits.begin(); hitIt--) {
143  recHits.push_back( (**hitIt).hit()->clone());
144  }
145  */
146 
147  TSOS firstState;
148  unsigned int firstId;
149 
150  // assume not along momentum....
151  firstState = theTraj.lastMeasurement().updatedState();
152  firstId = theTraj.lastMeasurement().recHitR().rawId();
153  //firstId = recHits.front().rawId();
154 
155  /*
156  cout << "firstState y, z: " << firstState.globalPosition().y()
157  << " , " << firstState.globalPosition().z() << endl;
158 
159  */
160 
162  TSOS startingState(
163  firstState.localParameters(), LocalTrajectoryError(C), firstState.surface(), firstState.magneticField());
164 
165  // protection againt invalid initial states
166  if (!firstState.isValid()) {
167  edm::LogWarning("CosmicTrackFinder") << "invalid innerState, will not make TrackCandidate";
169  return;
170  }
171 
172  // FIXME in case of slitting this can happen see CkfTrackCandidateMakerBase
173  if (firstId != recHits.front().rawId()) {
174  edm::LogWarning("CosmicTrackFinder") << "Mismatch in DetID of first hit: firstID= " << firstId
175  << " DetId= " << recHits.front().geographicalId().rawId();
177  return;
178  }
179 
180  PTrajectoryStateOnDet const& state = trajectoryStateTransform::persistentState(startingState, firstId);
181 
182  output->push_back(TrackCandidate(recHits, theTraj.seed(), state, theTraj.seedRef()));
183  }
184  }
186  }
187 } // namespace cms
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
const LocalTrajectoryParameters & localParameters() const
edm::EDGetTokenT< SiStripRecHit2DCollection > stereorecHitsToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
ROOT::Math::SMatrixIdentity AlgebraicMatrixID
CosmicTrajectoryBuilder cosmicTrajectoryBuilder_
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
const MagneticField * magneticField() const
const TransientTrackingRecHitBuilder * hitBuilder() const
void reverse()
Definition: OwnVector.h:204
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.
CRackTrajectoryBuilder crackTrajectoryBuilder_
edm::EDGetTokenT< SiPixelRecHitCollection > pixelRecHitsToken_
void produce(edm::Event &e, const edm::EventSetup &c) override
CosmicTrackFinder(const edm::ParameterSet &conf)
const TransientTrackingRecHitBuilder * hitBuilder() const
edm::EDGetTokenT< TrajectorySeedCollection > seedToken_
Namespace of DDCMS conversion namespace.
T const * product() const
Definition: Handle.h:69
edm::EDGetTokenT< SiStripMatchedRecHit2DCollection > matchedrecHitsToken_
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.
edm::EDGetTokenT< SiStripRecHit2DCollection > rphirecHitsToken_
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
T get() const
Definition: EventSetup.h:73
DetId geographicalId() const
reference front()
Definition: OwnVector.h:459
def move(src, dest)
Definition: eostools.py:511
id_type rawId() const