CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 namespace cms {
27 
29  : cosmicTrajectoryBuilder_(conf, consumesCollector()), crackTrajectoryBuilder_(conf, consumesCollector()) {
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
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 
79  edm::LogVerbatim("CosmicTrackFinder") << "========== Cosmic Track Finder Info ==========";
80  edm::LogVerbatim("CosmicTrackFinder") << " Numbers of Seeds " << (*seed).size();
81  if (!(*seed).empty()) {
82  std::vector<Trajectory> trajoutput;
83 
84  const TransientTrackingRecHitBuilder* hitBuilder = nullptr;
85  if (geometry != "CRACK") {
87  *seed, *stereorecHits, *rphirecHits, *matchedrecHits, *pixelHitCollection, es, e, trajoutput);
88  hitBuilder = cosmicTrajectoryBuilder_.hitBuilder();
89  } else {
91  *seed, *stereorecHits, *rphirecHits, *matchedrecHits, *pixelHitCollection, es, e, trajoutput);
92  hitBuilder = crackTrajectoryBuilder_.hitBuilder();
93  }
94  assert(hitBuilder);
95  Traj2TrackHits t2t(hitBuilder, true);
96 
97  edm::LogVerbatim("CosmicTrackFinder") << " Numbers of Temp Trajectories " << trajoutput.size();
98  edm::LogVerbatim("CosmicTrackFinder") << "========== END Info ==========";
99  if (!trajoutput.empty()) {
100  // crazyness...
101  std::vector<Trajectory*> tmpTraj;
102  std::vector<Trajectory>::iterator itr;
103  for (itr = trajoutput.begin(); itr != trajoutput.end(); itr++)
104  tmpTraj.push_back(&(*itr));
105 
106  //The best track is selected
107  //FOR MTCC the criteria are:
108  //1)# of layers,2) # of Hits,3)Chi2
109  if (geometry == "MTCC")
110  stable_sort(tmpTraj.begin(), tmpTraj.end(), CompareTrajLay());
111  else
112  stable_sort(tmpTraj.begin(), tmpTraj.end(), CompareTrajChi());
113 
115 
116  const Trajectory theTraj = *(*tmpTraj.begin());
117  bool seedplus = (theTraj.seed().direction() == alongMomentum);
118 
119  // std::cout << "CosmicTrackFinder " <<"Reconstruction " << (seedplus ? "along" : "opposite to") << " momentum" << std::endl;
120  LogDebug("CosmicTrackFinder") << "Reconstruction " << (seedplus ? "along" : "opposite to") << " momentum";
121 
122  /*
123  // === the convention is to save always final tracks with hits sorted *along* momentum
124  // --- this is NOT what was necessaraly happening before and not consistent with what done in standard CKF (this is a candidate not a track)
125  */
127  if (theTraj.direction() == alongMomentum)
128  std::cout << "cosmic: along momentum... " << std::endl;
129  t2t(theTraj, recHits, useHitsSplitting_);
130  recHits.reverse(); // according to original code
131 
132  /*
133  Trajectory::RecHitContainer thits;
134  //it->recHitsV(thits);
135  theTraj.recHitsV(thits,useHitsSplitting_);
136  edm::OwnVector<TrackingRecHit> recHits;
137  recHits.reserve(thits.size());
138  // reverse hit order
139  for (Trajectory::RecHitContainer::const_iterator hitIt = thits.end()-1;
140  hitIt >= thits.begin(); hitIt--) {
141  recHits.push_back( (**hitIt).hit()->clone());
142  }
143  */
144 
145  TSOS firstState;
146  unsigned int firstId;
147 
148  // assume not along momentum....
149  firstState = theTraj.lastMeasurement().updatedState();
150  firstId = theTraj.lastMeasurement().recHitR().rawId();
151  //firstId = recHits.front().rawId();
152 
153  /*
154  cout << "firstState y, z: " << firstState.globalPosition().y()
155  << " , " << firstState.globalPosition().z() << endl;
156 
157  */
158 
160  TSOS startingState(
161  firstState.localParameters(), LocalTrajectoryError(C), firstState.surface(), firstState.magneticField());
162 
163  // protection againt invalid initial states
164  if (!firstState.isValid()) {
165  edm::LogWarning("CosmicTrackFinder") << "invalid innerState, will not make TrackCandidate";
167  return;
168  }
169 
170  // FIXME in case of slitting this can happen see CkfTrackCandidateMakerBase
171  if (firstId != recHits.front().rawId()) {
172  edm::LogWarning("CosmicTrackFinder") << "Mismatch in DetID of first hit: firstID= " << firstId
173  << " DetId= " << recHits.front().geographicalId().rawId();
175  return;
176  }
177 
179 
180  output->push_back(TrackCandidate(recHits, theTraj.seed(), state, theTraj.seedRef()));
181  }
182  }
184  }
185 } // namespace cms
Log< level::Info, true > LogVerbatim
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
const LocalTrajectoryParameters & localParameters() const
edm::EDGetTokenT< SiStripRecHit2DCollection > stereorecHitsToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
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)
assert(be >=bs)
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_
def move
Definition: eostools.py:511
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_
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_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
tuple cout
Definition: gather_cfg.py:144
DetId geographicalId() const
Log< level::Warning, false > LogWarning
reference front()
Definition: OwnVector.h:459
id_type rawId() const
#define LogDebug(id)