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