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 
24 
25 namespace cms
26 {
27 
29  cosmicTrajectoryBuilder_(conf) ,
30  crackTrajectoryBuilder_(conf) ,
31  conf_(conf)
32  {
33  geometry=conf_.getUntrackedParameter<std::string>("GeometricStructure","STANDARD");
34  useHitsSplitting_=conf.getParameter<bool>("useHitsSplitting");
35  produces<TrackCandidateCollection>();
36  }
37 
38 
39  // Virtual destructor needed.
41 
42  // Functions that gets called by framework every event
44  {
45  using namespace std ;
46  edm::InputTag matchedrecHitsTag = conf_.getParameter<edm::InputTag>("matchedRecHits");
47  edm::InputTag rphirecHitsTag = conf_.getParameter<edm::InputTag>("rphirecHits");
48  edm::InputTag stereorecHitsTag = conf_.getParameter<edm::InputTag>("stereorecHits");
49  edm::InputTag pixelRecHitsTag = conf_.getParameter<edm::InputTag>("pixelRecHits");
50 
51 
52  edm::InputTag seedTag = conf_.getParameter<edm::InputTag>("cosmicSeeds");
53  // retrieve seeds
55  e.getByLabel(seedTag,seed);
56 
57  //retrieve PixelRecHits
58  static const SiPixelRecHitCollection s_empty;
59  const SiPixelRecHitCollection *pixelHitCollection = &s_empty;
61  if (geometry!="MTCC" && (geometry!="CRACK" )) {
62  if( e.getByLabel(pixelRecHitsTag, pixelHits)) {
63  pixelHitCollection = pixelHits.product();
64  } else {
65  edm::LogWarning("CosmicTrackFinder") << "Collection SiPixelRecHitCollection with InputTag " << pixelRecHitsTag << " cannot be found, using empty collection of same type.";
66  }
67  }
68 
69 
70 
71 
72  //retrieve StripRecHits
74  e.getByLabel( matchedrecHitsTag ,matchedrecHits);
76  e.getByLabel( rphirecHitsTag ,rphirecHits);
78  e.getByLabel( stereorecHitsTag, stereorecHits);
79 
80  // Step B: create empty output collection
81  std::auto_ptr<TrackCandidateCollection> output(new TrackCandidateCollection);
82 
85  edm::LogVerbatim("CosmicTrackFinder") << "========== Cosmic Track Finder Info ==========";
86  edm::LogVerbatim("CosmicTrackFinder") << " Numbers of Seeds " << (*seed).size();
87  if((*seed).size()>0){
88 
89  std::vector<Trajectory> trajoutput;
90 
91  if(geometry!="CRACK" ) {
93  *stereorecHits,
94  *rphirecHits,
95  *matchedrecHits,
96  *pixelHitCollection,
97  es,
98  e,
99  trajoutput);
100  } else {
102  *stereorecHits,
103  *rphirecHits,
104  *matchedrecHits,
105  *pixelHitCollection,
106  es,
107  e,
108  trajoutput);
109  }
110 
111  edm::LogVerbatim("CosmicTrackFinder") << " Numbers of Temp Trajectories " << trajoutput.size();
112  edm::LogVerbatim("CosmicTrackFinder") << "========== END Info ==========";
113  if(trajoutput.size()>0){
114  std::vector<Trajectory*> tmpTraj;
115  std::vector<Trajectory>::iterator itr;
116  for (itr=trajoutput.begin();itr!=trajoutput.end();itr++)tmpTraj.push_back(&(*itr));
117 
118  //The best track is selected
119  //FOR MTCC the criteria are:
120  //1)# of layers,2) # of Hits,3)Chi2
121  if (geometry=="MTCC") stable_sort(tmpTraj.begin(),tmpTraj.end(),CompareTrajLay());
122  else stable_sort(tmpTraj.begin(),tmpTraj.end(),CompareTrajChi());
123 
124 
125 
126  const Trajectory theTraj = *(*tmpTraj.begin());
127  bool seedplus=(theTraj.seed().direction()==alongMomentum);
128  //PropagationDirection seedDir =theTraj.seed().direction();
129 
130  if (seedplus)
131  LogDebug("CosmicTrackFinder")<<"Reconstruction along momentum ";
132  else
133  LogDebug("CosmicTrackFinder")<<"Reconstruction opposite to momentum";
134 
135  /*
136  // === the convention is to save always final tracks with hits sorted *along* momentum
137  */
138 
140  //it->recHitsV(thits);
141  theTraj.recHitsV(thits,useHitsSplitting_);
143  recHits.reserve(thits.size());
144 
145  // reverse hit order
146  for (Trajectory::RecHitContainer::const_iterator hitIt = thits.end()-1;
147  hitIt >= thits.begin(); hitIt--) {
148  recHits.push_back( (**hitIt).hit()->clone());
149  }
150 
151  TSOS firstState;
152  unsigned int firstId;
153 
154  firstState=theTraj.lastMeasurement().updatedState();
155  firstId = theTraj.lastMeasurement().recHit()->geographicalId().rawId();
156 
157  /*
158  cout << "firstState y, z: " << firstState.globalPosition().y()
159  << " , " << firstState.globalPosition().z() << endl;
160 
161  */
162 
164  TSOS startingState( firstState.localParameters(), LocalTrajectoryError(C),
165  firstState.surface(),
166  firstState.magneticField() );
167 
168  // protection againt invalid initial states
169  if (! firstState.isValid()) {
170  edm::LogWarning("CosmicTrackFinder") << "invalid innerState, will not make TrackCandidate";
171  edm::OrphanHandle<TrackCandidateCollection> rTrackCand = e.put(output);
172  return;
173  }
174 
175  if(firstId != recHits.front().geographicalId().rawId()){
176  edm::LogWarning("CosmicTrackFinder") <<"Mismatch in DetID of first hit: firstID= " <<firstId
177  << " DetId= " << recHits.front().geographicalId().rawId();
178  edm::OrphanHandle<TrackCandidateCollection> rTrackCand = e.put(output);
179  return;
180  }
181 
182  PTrajectoryStateOnDet const & state = trajectoryStateTransform::persistentState( startingState, firstId);
183 
184 
185  output->push_back(TrackCandidate(recHits,theTraj.seed(),state,theTraj.seedRef() ) );
186 
187  }
188 
189  }
190  edm::OrphanHandle<TrackCandidateCollection> rTrackCand = e.put(output);
191  }
192 }
#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:45
void push_back(D *&d)
Definition: OwnVector.h:273
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:94
CRackTrajectoryBuilder crackTrajectoryBuilder_
CosmicTrackFinder(const edm::ParameterSet &conf)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
tuple conf
Definition: dbtoconf.py:185
ConstRecHitContainer RecHitContainer
Definition: Trajectory.h:44
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
T const * product() const
Definition: Handle.h:74
char state
Definition: procUtils.cc:75
DetId geographicalId() const
edm::ParameterSet conf_
reference front()
Definition: OwnVector.h:348
void reserve(size_t)
Definition: OwnVector.h:267