CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RoadSearchTrackCandidateMakerAlgorithm.cc
Go to the documentation of this file.
1 //
2 // Package: RecoTracker/RoadSearchTrackCandidateMaker
3 // Class: RoadSearchTrackCandidateMakerAlgorithm
4 //
5 // Description: Converts cleaned clouds into
6 // TrackCandidates using the
7 // TrajectoryBuilder framework
8 //
9 // Original Author: Oliver Gutsche, gutsche@fnal.gov
10 // Created: Wed Mar 15 13:00:00 UTC 2006
11 //
12 // $Author: innocent $
13 // $Date: 2011/12/23 08:13:37 $
14 // $Revision: 1.75 $
15 //
16 
17 #include <vector>
18 #include <iostream>
19 #include <cmath>
20 
22 
24 
28 
33 
36 
41 
47 
57 
68 
72 
74 
75  theNumHitCut = (unsigned int)conf_.getParameter<int>("NumHitCut");
76  theChi2Cut = conf_.getParameter<double>("HitChi2Cut");
77 
79  theUpdator = new KFUpdator();
81 
82  CosmicReco_ = conf_.getParameter<bool>("StraightLineNoBeamSpotCloud");
83  CosmicTrackMerging_ = conf_.getParameter<bool>("CosmicTrackMerging");
84  MinChunkLength_ = conf_.getParameter<int>("MinimumChunkLength");
85  nFoundMin_ = conf_.getParameter<int>("nFoundMin");
86 
87  initialVertexErrorXY_ = conf_.getParameter<double>("InitialVertexErrorXY");
88  splitMatchedHits_ = conf_.getParameter<bool>("SplitMatchedHits");
89  cosmicSeedPt_ = conf_.getParameter<double>("CosmicSeedPt");
90 
91  measurementTrackerName_ = conf_.getParameter<std::string>("MeasurementTrackerName");
92 
93  debug_ = false;
94  debugCosmics_ = false;
95 
96  maxPropagationDistance = 1000.0; // 10m
97 }
98 
100  delete theEstimator;
101  delete theUpdator;
102  delete theTrajectoryCleaner;
103  // delete theMeasurementTracker;
104 
105 }
106 
108  const edm::Event& e,
109  const edm::EventSetup& es,
111 {
112 
113  //
114  // right now, track candidates are just filled from cleaned
115  // clouds. The trajectory of the seed is taken as the initial
116  // trajectory for the final fit
117  //
118 
119  //
120  // get the transient builder
121  //
123  std::string builderName = conf_.getParameter<std::string>("TTRHBuilder");
124  es.get<TransientRecHitRecord>().get(builderName,theBuilder);
125  ttrhBuilder = theBuilder.product();
126 
127  edm::ESHandle<MeasurementTracker> measurementTrackerHandle;
128  es.get<CkfComponentsRecord>().get(measurementTrackerName_, measurementTrackerHandle);
129  theMeasurementTracker = measurementTrackerHandle.product();
130 
131  std::vector<Trajectory> FinalTrajectories;
132 
133 
134  // need this to sort recHits, sorting done after getting seed because propagationDirection is needed
135  // get tracker geometry
137  es.get<TrackerDigiGeometryRecord>().get(tracker);
138  trackerGeom = tracker.product();
139 
141  es.get<IdealMagneticFieldRecord>().get(magField_);
142  magField = magField_.product();
143 
144  NoFieldCosmic_ = (CosmicReco_ && (magField->inTesla(GlobalPoint(0,0,0)).mag() < 0.01));
145 
147  //const MeasurementTracker* theMeasurementTracker = new MeasurementTracker(es,mt_params); // will need this later
148 
152 
154 
155  //KFTrajectorySmoother theSmoother(*theRevPropagator, *theUpdator, *theEstimator);
157 
158  // get hit matcher
160 
161  //debug_ = true;
162  //if (input->size()>0) debug_ = true;
163 
164  LogDebug("RoadSearch") << "Clean Clouds input size: " << input->size();
165  if (debug_) std::cout << std::endl << std::endl
166  << "*** NEW EVENT: Clean Clouds input size: " << input->size() << std::endl;
167 
168  int i_c = 0;
169  for ( RoadSearchCloudCollection::const_iterator cloud = input->begin(); cloud != input->end(); ++cloud ) {
170 
171  // fill rechits from cloud into new
172  RoadSearchCloud::RecHitVector recHits = cloud->recHits();
173 
174  std::vector<Trajectory> CloudTrajectories;
175 
176  if (!CosmicReco_){
177  std::sort(recHits.begin(),recHits.end(),SortHitPointersByGlobalPosition(tracker.product(),alongMomentum));
178  }
179  else {
180  std::sort(recHits.begin(),recHits.end(),SortHitPointersByY(*tracker));
181  }
182 
183  const unsigned int nlost_max = 2;
184 
185  // make a list of layers in cloud and mark stereo layers
186 
187  const unsigned int max_layers = 128;
188 
189  // collect hits in cloud by layer
190  std::vector<std::pair<const DetLayer*, RoadSearchCloud::RecHitVector > > RecHitsByLayer;
191  std::map<const DetLayer*, int> cloud_layer_reference; // for debugging
192  std::map<const DetLayer*, int>::iterator hiter;
193  for(RoadSearchCloud::RecHitVector::const_iterator ihit = recHits.begin();
194  ihit != recHits.end(); ihit++) {
195  // only use useful layers
196  const DetLayer* thisLayer =
197  theMeasurementTracker->geometricSearchTracker()->detLayer((*ihit)->geographicalId());
198 
199  std::map<const DetLayer*, int>::const_iterator ilyr = cloud_layer_reference.find(thisLayer);
200  if (ilyr==cloud_layer_reference.end())
201  cloud_layer_reference.insert(std::make_pair( thisLayer, RecHitsByLayer.size()));
202 
203  if (!RecHitsByLayer.empty() && RecHitsByLayer.back().first == thisLayer) { // Same as previous layer
204  RecHitsByLayer.back().second.push_back(*ihit);
205  }
206  else { // check if this is a new layer
207  if (ilyr != cloud_layer_reference.end()){// Not a New Layer
208  int ilayer = ilyr->second;
209  (RecHitsByLayer.begin()+ilayer)->second.push_back(*ihit);
210  }
211  else{// New Layer
212  if (RecHitsByLayer.size() >= max_layers) break; // should never happen
213  lstereo[RecHitsByLayer.size()] = false;
214  if ((*ihit)->localPositionError().yy()<1.) lstereo[RecHitsByLayer.size()] = true;
216  rhc.push_back(*ihit);
217  RecHitsByLayer.push_back(std::make_pair(thisLayer, rhc));
218  }
219  }
220  }
221 
222  LogDebug("RoadSearch")<<"Cloud #"<<i_c<<" has "<<recHits.size()<<" hits in "<<RecHitsByLayer.size()<<" layers ";
223  if (debug_) std::cout <<"Cloud "<<i_c<<" has "<<recHits.size()<<" hits in " <<RecHitsByLayer.size() << " layers " <<std::endl;;
224  ++i_c;
225 
226  if (debug_){
227  int ntothit = 0;
228 
229  for (std::vector<std::pair<const DetLayer*, RoadSearchCloud::RecHitVector > >::iterator ilhv = RecHitsByLayer.begin();
230  ilhv != RecHitsByLayer.end(); ++ilhv) {
231  std::cout<<" Layer " << ilhv-RecHitsByLayer.begin() << " has " << ilhv->second.size() << " hits " << std::endl;
232  }
233  std::cout<<std::endl;
234  for (std::vector<std::pair<const DetLayer*, RoadSearchCloud::RecHitVector > >::iterator ilhv = RecHitsByLayer.begin();
235  ilhv != RecHitsByLayer.end(); ++ilhv) {
236  RoadSearchCloud::RecHitVector theLayerHits = ilhv->second;
237  for (RoadSearchCloud::RecHitVector::const_iterator ihit = theLayerHits.begin();
238  ihit != theLayerHits.end(); ++ihit) {
239 
240  GlobalPoint gp = trackerGeom->idToDet((*ihit)->geographicalId())->surface().toGlobal((*ihit)->localPosition());
241  if (CosmicReco_){
242  std::cout << " Hit "<< ntothit
243  << " x/y/z = "
244  << gp.x() << " " << gp.y() << " " << gp.z()
245  <<" in layer " << ilhv-RecHitsByLayer.begin()
246  << " is hit " << (ihit-theLayerHits.begin())+1
247  << " of " << theLayerHits.size() << std::endl;
248  }
249  else {
250  std::cout << " Hit "<< ntothit
251  << " r/z = "
252  << gp.perp() << " " << gp.z()
253  <<" in layer " << ilhv-RecHitsByLayer.begin()
254  << " is hit " << (ihit-theLayerHits.begin())+1
255  << " of " << theLayerHits.size() << std::endl;
256  }
257  ntothit++;
258  }
259  }
260  std::cout<<std::endl;
261  }
262 
263  // try to start from all layers until the chunk is too short
264  //
265 
266  for (std::vector<std::pair<const DetLayer*, RoadSearchCloud::RecHitVector > >::iterator ilyr0 = RecHitsByLayer.begin();
267  ilyr0 != RecHitsByLayer.end(); ++ilyr0) {
268 
269  unsigned int ilayer0 = (unsigned int)(ilyr0-RecHitsByLayer.begin());
270  if (ilayer0 > RecHitsByLayer.size()-MinChunkLength_) continue;
271 
272  std::vector<Trajectory> ChunkTrajectories;
273  std::vector<Trajectory> CleanChunks;
274  bool all_chunk_layers_used = false;
275 
276  if (debug_) std::cout << "*** START NEW CHUNK --> layer range (" << ilyr0-RecHitsByLayer.begin()
277  << "-" << RecHitsByLayer.size()-1 << ")";
278 
279  // collect hits from the starting layer
280  RoadSearchCloud::RecHitVector recHits_start = ilyr0->second;
281 
282  //
283  // Step 1: find small tracks (chunks) made of hits
284  // in layers with low occupancy
285  //
286 
287  // find layers with small number of hits
288  // TODO: try to keep earliest layers + at least one stereo layer
289  std::multimap<int, const DetLayer*> layer_map;
290  std::map<const DetLayer*, int> layer_reference; // for debugging
291  // skip starting layer, as it is always included
292  for (std::vector<std::pair<const DetLayer*, RoadSearchCloud::RecHitVector > >::iterator ilayer = ilyr0+1;
293  ilayer != RecHitsByLayer.end(); ++ilayer) {
294  layer_map.insert(std::make_pair(ilayer->second.size(), ilayer->first));
295  layer_reference.insert(std::make_pair(ilayer->first, ilayer-RecHitsByLayer.begin()));
296  }
297 
298  if (debug_) {
299  std::cout<<std::endl<<" Available layers are: " << std::endl;
300  for (std::multimap<int, const DetLayer*>::iterator ilm1 = layer_map.begin();
301  ilm1 != layer_map.end(); ++ilm1) {
302  std::map<const DetLayer*, int>::iterator ilr = layer_reference.find(ilm1->second);
303  if (ilr != layer_reference.end() && debug_)
304  std::cout << "Layer " << ilr->second << " with " << ilm1->first <<" hits" <<std::endl;;
305  }
306  }
307 
308  //const int max_middle_layers = 2;
309  std::set<const DetLayer*> the_good_layers;
310  std::vector<const DetLayer*> the_middle_layers;
311  RoadSearchCloud::RecHitVector the_recHits_middle;
312 
313  // bool StartLayers =
314  chooseStartingLayers(RecHitsByLayer,ilyr0,layer_map,the_good_layers,the_middle_layers,the_recHits_middle);
315  if (debug_) {
316  std::cout << " From new code... With " << the_good_layers.size() << " useful layers: ";
317  for (std::set<const DetLayer*>::iterator igl = the_good_layers.begin();
318  igl!= the_good_layers.end(); ++igl){
319  std::map<const DetLayer*, int>::iterator ilr = layer_reference.find(*igl);
320  if (ilr != layer_reference.end()) std::cout << " " << ilr->second;
321  }
322  std::cout << std::endl;
323  std::cout << " From new code... and middle layers: ";
324  for (std::vector<const DetLayer*>::iterator iml = the_middle_layers.begin();
325  iml!= the_middle_layers.end(); ++iml){
326  std::map<const DetLayer*, int>::iterator ilr = layer_reference.find(*iml);
327  if (ilr != layer_reference.end()) std::cout << " " << ilr->second;
328  }
329  std::cout << std::endl;
330  }
331  RoadSearchCloud::RecHitVector recHits_inner = recHits_start;
332  RoadSearchCloud::RecHitVector recHits_outer = the_recHits_middle;
333  std::set<const DetLayer*> good_layers = the_good_layers;
334  unsigned int ngoodlayers = good_layers.size();
335 
336  if (debug_)
337  std::cout<<"Found " << recHits_inner.size() << " inner hits and " << recHits_outer.size() << " outer hits" << std::endl;
338 
339  // collect hits in useful layers
340  std::vector<std::pair<const DetLayer*, RoadSearchCloud::RecHitVector > > goodHits;
341  // mark layers that will be skipped in first pass
342  std::set<const DetLayer*> skipped_layers;
343  std::map<int, const DetLayer*> skipped_layer_detmap;
344 
345 
346  goodHits.push_back(*ilyr0); // save hits from starting layer
347  // save hits from other good layers
348  for (std::vector<std::pair<const DetLayer*, RoadSearchCloud::RecHitVector > >::iterator ilyr = ilyr0+1;
349  ilyr != RecHitsByLayer.end(); ++ilyr) {
350  if (good_layers.find(ilyr->first) != good_layers.end()){
351  goodHits.push_back(*ilyr);
352  }
353  else {
354  skipped_layers.insert(ilyr->first);
355  std::map<const DetLayer*, int>::iterator ilr = layer_reference.find(ilyr->first);
356  if (ilr != layer_reference.end())
357  skipped_layer_detmap.insert(std::make_pair(ilr->second,ilyr->first));
358  else
359  if (debug_) std::cout<<"Couldn't find thisLayer to insert into map..."<<std::endl;
360  }
361  }
362 
363  // try various hit combinations
364  for (RoadSearchCloud::RecHitVector::const_iterator innerHit = recHits_inner.begin();
365  innerHit != recHits_inner.end(); ++innerHit) {
366 
367  const DetLayer* innerHitLayer =
368  theMeasurementTracker->geometricSearchTracker()->detLayer((*innerHit)->geographicalId());
369 
370 
371  RoadSearchCloud::RecHitVector::iterator middleHit, outerHit;
372  RoadSearchCloud::RecHitVector::iterator firstHit, lastHit;
373 
374  bool triplets = (CosmicReco_ && (magField->inTesla(GlobalPoint(0,0,0)).mag() > 0.01));
375 
376  if (!triplets){
377  firstHit = recHits_outer.begin();
378  lastHit = recHits_outer.end();
379  }
380  else if (triplets){
381  firstHit = recHits_outer.begin()+1;
382  lastHit = recHits_outer.end();
383  }
384 
385  for (RoadSearchCloud::RecHitVector::iterator outerHit = firstHit; outerHit != lastHit; ++outerHit) {
386 
387  const DetLayer* middleHitLayer = 0;
388  if (triplets){
389  middleHit = outerHit-1;
390  middleHitLayer = theMeasurementTracker->geometricSearchTracker()->detLayer((*middleHit)->geographicalId());
391  }
392  const DetLayer* outerHitLayer =
393  theMeasurementTracker->geometricSearchTracker()->detLayer((*outerHit)->geographicalId());
394  if (middleHitLayer == outerHitLayer) continue;
395 
397  if (!triplets){
398  if (debug_){
399  std::map<const DetLayer*, int>::iterator ilro = layer_reference.find(outerHitLayer);
400  if (ilro != layer_reference.end()) {
401  std::cout << "Try trajectory with Inner Hit on Layer " << ilayer0 << " and " ;
402  std::cout << "Outer Hit on Layer " << ilro->second << std::endl;
403  }
404  }
405  fts = initialTrajectory(es,*innerHit,*outerHit);
406  }
407  else if (triplets){
408  if (debug_){
409  std::map<const DetLayer*, int>::iterator ilrm = layer_reference.find(middleHitLayer);
410  std::map<const DetLayer*, int>::iterator ilro = layer_reference.find(outerHitLayer);
411  if (ilro != layer_reference.end() && ilrm != layer_reference.end()) {
412  std::cout << "Try trajectory with Hits on Layers " << ilayer0 << " , "
413  << ilrm->second << " and " << ilro->second << std::endl;
414  }
415  }
416  fts = initialTrajectoryFromTriplet(es,*innerHit,*middleHit,*outerHit);
417  }
418 
419  if (!fts.hasError()) continue;
420  if (debug_) std::cout<<"FTS: " << fts << std::endl;
421 
422  Trajectory seedTraj = createSeedTrajectory(fts,*innerHit,innerHitLayer);
423 
424  std::vector<Trajectory> rawTrajectories;
425  if (seedTraj.isValid() && !seedTraj.measurements().empty() ) rawTrajectories.push_back(seedTraj);//GC
426  //rawTrajectories.push_back(seedTraj);
427 
428  int ntested = 0;
429  // now loop on hits
430  std::vector<std::pair<const DetLayer*, RoadSearchCloud::RecHitVector > >::iterator ilyr_start = (goodHits.begin()+1);
431  for (std::vector<std::pair<const DetLayer*, RoadSearchCloud::RecHitVector > >::iterator ilhv = ilyr_start;
432  ilhv != goodHits.end(); ++ilhv) {
433  RoadSearchCloud::RecHitVector& hits = ilhv->second;
434  //std::vector<Trajectory> newTrajectories;
435  ++ntested;
436  if (debug_){
437  std::map<const DetLayer*, int>::iterator ilr = cloud_layer_reference.find(ilhv->first);
438  if (ilr != cloud_layer_reference.end())
439  std::cout << "extrapolating " << rawTrajectories.size()
440  << " trajectories to layer " << ilr->second
441  << " which has " << hits.size() << " hits " << std::endl;
442  }
443 
444  std::vector<Trajectory>newTrajectories;
445  for (std::vector<Trajectory>::const_iterator it = rawTrajectories.begin();
446  it != rawTrajectories.end(); it++) {
447  if (debug_) std::cout << "extrapolating Trajectory #" << it-rawTrajectories.begin() << std::endl;
448  if (it->direction()==alongMomentum) thePropagator = theAloPropagator;//GC
450 
451  std::vector<Trajectory> theTrajectories = extrapolateTrajectory(*it,hits,
452  innerHitLayer, *outerHit, outerHitLayer);
453  if (theTrajectories.empty()) {
454  if (debug_) std::cout<<" Could not add the hit in this layer " << std::endl;
455  if (debug_){
456  std::cout << " --> trajectory " << it-rawTrajectories.begin()
457  << " has "<<it->recHits().size()<<" hits after "
458  << (ilhv-ilyr_start+1) << " tested (ntested=" <<ntested<<") "
459  << " --> misses="<< (ilhv-ilyr_start+1)-(it->recHits().size()-1)
460  << " but there are " << (goodHits.end() - ilhv)
461  <<" more layers in first pass and "<< skipped_layers.size() <<" skipped layers " <<std::endl;
462 
463 
464  }
465  // layer missed
466  if ((ilhv-ilyr_start+1)-(it->recHits().size()-1) <= nlost_max){
467  newTrajectories.push_back(*it);
468  }
469  }
470  else{ // added hits in this layers
471  for (std::vector<Trajectory>::const_iterator it = theTrajectories.begin();
472  it != theTrajectories.end(); it++) {
473  newTrajectories.push_back(*it);
474  }
475  }
476  } // end loop over rawTrajectories
477  rawTrajectories = newTrajectories;
478  if (newTrajectories.empty()) break;
479  }
480  if (rawTrajectories.size()==0){
481  continue;
482  if (debug_) std::cout<<" --> yields ZERO raw trajectories!" << std::endl;
483  }
484  if (debug_){
485  for (std::vector<Trajectory>::const_iterator it = rawTrajectories.begin();
486  it != rawTrajectories.end(); it++) {
487  std::cout << " --> yields trajectory with "<<it->recHits().size()<<" hits with chi2="
488  <<it->chiSquared()<<" and is valid? "<<it->isValid() <<std::endl;
489  }
490  }
491  std::vector<Trajectory> rawCleaned;
492  theTrajectoryCleaner->clean(rawTrajectories);
493  for (std::vector<Trajectory>::const_iterator itr = rawTrajectories.begin();
494  itr != rawTrajectories.end(); ++itr) {
495  // see how many layers have been found
496  if (!itr->isValid()) continue;
497  std::set<const DetLayer*> used_layers;
498  Trajectory::DataContainer tmv = itr->measurements();
499  for (Trajectory::DataContainer::iterator itm = tmv.begin();
500  itm != tmv.end(); ++itm) {
502  if (!rh->isValid()) continue;
503  used_layers.insert(theMeasurementTracker->geometricSearchTracker()->detLayer(rh->geographicalId()));
504  }
505 
506  // need to subtract 1 from used_layers since it includes the starting layer
507  if (debug_) std::cout<<"Used " << (used_layers.size()-1) << " layers out of " << ngoodlayers
508  << " good layers, so " << ngoodlayers - (used_layers.size()-1) << " missed "
509  << std::endl;
510  if ((int)used_layers.size() < nFoundMin_) continue;
511  unsigned int nlostlayers = ngoodlayers - (used_layers.size()-1);
512  if (nlostlayers > nlost_max) continue;
513 
514  rawCleaned.push_back(*itr);
515 
516  }
517  if (!rawCleaned.empty()) {
518  ChunkTrajectories.insert(ChunkTrajectories.end(), rawCleaned.begin(), rawCleaned.end());
519  }
520  } // END LOOP OVER OUTER HITS
521  } // END LOOP OVER INNER HITS
522  // At this point we have made all the trajectories from the low occupancy layers
523  // We clean these trajectories first, and then try to add hits from the skipped layers
524 
525  // }
526  if (debug_) std::cout << "Clean the " << ChunkTrajectories.size()<<" trajectories for this chunk" << std::endl;
527  // clean the intermediate result
528  theTrajectoryCleaner->clean(ChunkTrajectories);
529  for (std::vector<Trajectory>::const_iterator it = ChunkTrajectories.begin();
530  it != ChunkTrajectories.end(); it++) {
531  if (it->isValid()) CleanChunks.push_back(*it);
532  }
533  if (debug_) std::cout <<"After cleaning there are " << CleanChunks.size() << " trajectories for this chunk" << std::endl;
534 
535 
536  // ********************* BEGIN NEW ADDITION
537 
538  //
539  // Step 2: recover measurements from busy layers
540  //
541 
542  std::vector<Trajectory> extendedChunks;
543 
544 
545  // see if there are layers that we skipped
546 
547  if (debug_){
548  if (skipped_layers.empty()) {
549  std::cout << "all layers were used in first pass" << std::endl;
550  } else {
551  std::cout << "There are " << skipped_layer_detmap.size() << " skipped layers:";
552  for (std::map<int, const DetLayer*>::const_iterator imap = skipped_layer_detmap.begin();
553  imap!=skipped_layer_detmap.end(); imap++){
554  std::cout<< " " <<imap->first;
555  }
556  std::cout << std::endl;
557  }
558  }
559 
560  for (std::vector<Trajectory>::const_iterator i = CleanChunks.begin();
561  i != CleanChunks.end(); i++) {
562  if (!(*i).isValid()) continue;
563  if (debug_) std::cout<< "Now process CleanChunk trajectory " << i-CleanChunks.begin() << std::endl;
564  bool all_layers_used = false;
565  if (skipped_layers.empty() && i->measurements().size() >= theNumHitCut) {
566  if (debug_) std::cout<<"The trajectory has " << i->measurements().size()
567  << " hits from a cloud of " << RecHitsByLayer.size()
568  << " layers and a chunk of " << (RecHitsByLayer.size() - ilayer0) << " layers " << std::endl;
569  extendedChunks.insert(extendedChunks.end(), *i);
570  if (i->measurements().size() >= (RecHitsByLayer.size() - ilayer0)){
571  all_layers_used = true;
572  break;
573  }
574  }
575  else {
576 
577  Trajectory temWptraj = *i;
578  Trajectory::DataContainer tmv = (*i).measurements();
579  if (tmv.size()+skipped_layer_detmap.size() < theNumHitCut) continue;
580 
581  // Debug dump of hits
582  if (debug_){
583  for (Trajectory::DataContainer::const_iterator ih=tmv.begin();
584  ih!=tmv.end();++ih){
586  const DetLayer* Layer =
587  theMeasurementTracker->geometricSearchTracker()->detLayer(rh->geographicalId());
588  std::map<const DetLayer*, int>::iterator ilr = cloud_layer_reference.find(Layer);
589  if (ilr != cloud_layer_reference.end())
590  std::cout << " Hit #"<<ih-tmv.begin() << " of " << tmv.size()
591  <<" is on Layer " << ilr->second << std::endl;
592  else
593  std::cout << " Layer for Hit #"<<ih-tmv.begin() <<" can't be found " << std::endl;
594  std::cout<<" updatedState:\n" << ih->updatedState() << std::endl;
595  std::cout<<" predictState:\n" << ih->predictedState() << std::endl;
596  }
597  }
598 
599  // Loop over the layers in the cloud
600 
601  std::set<const DetLayer*> final_layers;
602  Trajectory::DataContainer::const_iterator im = tmv.begin();
603  Trajectory::DataContainer::const_iterator im2 = tmv.begin();
604 
605  TrajectoryMeasurement firstMeasurement = i->firstMeasurement();
606  const DetLayer* firstDetLayer =
607  theMeasurementTracker->geometricSearchTracker()->detLayer(firstMeasurement.recHit()->geographicalId());
608 
609  std::vector<Trajectory> freshStartv = theSmoother->trajectories(*i);
610 
611  if(debug_) std::cout<<"Smoothing has returned " << freshStartv.size() <<" trajectory " << std::endl;
612  if (!freshStartv.empty()){
613  if(debug_) std::cout<< "Smoothing of trajectory " <<i-CleanChunks.begin() << " has succeeded with " << freshStartv.begin()->measurements().size() << " hits and a chi2 of " << freshStartv.begin()->chiSquared() <<" for " << freshStartv.begin()->ndof() << " DOF. Now add hits." <<std::endl;
614  } else {
615  if (debug_) std::cout<< "Smoothing of trajectory " <<i-CleanChunks.begin() <<" has failed"<<std::endl;
616  continue;
617  }
618 
619  Trajectory freshStart = *freshStartv.begin();
620  std::vector<TrajectoryMeasurement> freshStartTM = freshStart.measurements();
621 
622  if (debug_) {
623  for (std::vector<TrajectoryMeasurement>::const_iterator itm = freshStartTM.begin();itm != freshStartTM.end(); ++itm){
624  std::cout<<"Trajectory hit " << itm-freshStartTM.begin() <<" updatedState:\n" << itm->updatedState() << std::endl;
625  }
626  }
627 
628  TrajectoryStateOnSurface NewFirstTsos = freshStart.lastMeasurement().updatedState();
629  if(debug_) std::cout<<"NewFirstTSOS is valid? " << NewFirstTsos.isValid() << std::endl;
630  if(debug_) std::cout << " NewFirstTSOS:\n " << NewFirstTsos << std::endl;
632 
633  if(debug_) {
634  std::cout<< "First hit for fresh start on det " << rh->det() << ", r/phi/z = " << rh->globalPosition().perp() << " " << rh->globalPosition().phi() << " " << rh->globalPosition().z();
635  }
636 
637  PTrajectoryStateOnDet const & pFirstState = trajectoryStateTransform::persistentState(NewFirstTsos,
638  rh->geographicalId().rawId());
640  newHits.push_back(rh->hit()->clone());
641 
642  TrajectorySeed tmpseed = TrajectorySeed(pFirstState,
643  newHits,
644  i->direction());
645 
647  if (i->direction()==oppositeToMomentum) thePropagator = theRevPropagator;
648 
649 
650 
651  Trajectory newTrajectory(tmpseed,tmpseed.direction());
652 
653  const GeomDet* det = trackerGeom->idToDet(rh->geographicalId());
654  TrajectoryStateOnSurface invalidState(new BasicSingleTrajectoryState(det->surface()));
655  newTrajectory.push(TrajectoryMeasurement(invalidState, NewFirstTsos, rh, 0, firstDetLayer));
656  final_layers.insert(firstDetLayer);
657 
658  if(debug_) std::cout << "TRAJ is valid: " << newTrajectory.isValid() <<std::endl;
659 
660  TrajectoryStateOnSurface testTsos = newTrajectory.measurements().back().updatedState();
661 
662  if(debug_) {
663  std::cout << "testTSOS is valid!!" << testTsos.isValid() << std::endl;
664  std::cout << " testTSOS (x/y/z): " << testTsos.globalPosition().x()<< " / " << testTsos.globalPosition().y()<< " / " << testTsos.globalPosition().z() << std::endl;
665  std::cout << " local position x: " << testTsos.localPosition().x() << "+-" << sqrt(testTsos.localError().positionError().xx()) << std::endl;
666  }
667 
668  if (firstDetLayer != ilyr0->first){
669  if (debug_) std::cout<<"!!! ERROR !!! firstDetLayer ("<<firstDetLayer<<") != ilyr0 ( " <<ilyr0->first <<")"<< std::endl;
670  }
671  ++im;
672 
673  if (debug_){
674  std::map<const DetLayer*, int>::iterator ilr = cloud_layer_reference.find(firstDetLayer);
675  if (ilr != cloud_layer_reference.end() ){
676  std::cout << " First hit is on layer " << ilr->second << std::endl;
677  }
678  }
679  for (std::vector<std::pair<const DetLayer*, RoadSearchCloud::RecHitVector > >::iterator ilyr = ilyr0+1;
680  ilyr != RecHitsByLayer.end(); ++ilyr) {
681 
682  TrajectoryStateOnSurface predTsos;
683  TrajectoryStateOnSurface currTsos;
685 
686  if(debug_)
687  std::cout<<"Trajectory has " << newTrajectory.measurements().size() << " measurements with " << (RecHitsByLayer.end()-ilyr)
688  << " remaining layers " << std::endl;
689 
690  if (im != tmv.end()) im2 = im;
691  TransientTrackingRecHit::ConstRecHitPointer rh = im2->recHit(); // Current
692  if (rh->isValid() &&
693  theMeasurementTracker->geometricSearchTracker()->detLayer(rh->geographicalId()) == ilyr->first) {
694 
695  if (debug_) std::cout<<" Layer " << ilyr-RecHitsByLayer.begin() <<" has a good hit " << std::endl;
696  ++im;
697 
698  const GeomDet* det = trackerGeom->idToDet(rh->geographicalId());
699 
700  currTsos = newTrajectory.measurements().back().updatedState();
701  predTsos = thePropagator->propagate(currTsos, det->surface());
702  if (!predTsos.isValid()) continue;
703  GlobalVector propagationDistance = predTsos.globalPosition() - currTsos.globalPosition();
704  if (propagationDistance.mag() > maxPropagationDistance) continue;
706  if(debug_) {
707  std::cout << "Propagation distance2 is " << propagationDistance.mag() << std::endl;
708  std::cout << "predTSOS is valid!!" << std::endl;
709  std::cout << " predTSOS (x/y/z): " << predTsos.globalPosition().x()<< " / " << predTsos.globalPosition().y()<< " / " << predTsos.globalPosition().z() << std::endl;
710  std::cout << " local position x: " << predTsos.localPosition().x() << "+-" << sqrt(predTsos.localError().positionError().xx()) << std::endl;
711  std::cout << " local position y: " << predTsos.localPosition().y() << "+-" << sqrt(predTsos.localError().positionError().yy()) << std::endl;
712  std::cout << "currTSOS is valid!! " << currTsos.isValid() << std::endl;
713  std::cout << " currTSOS (x/y/z): " << currTsos.globalPosition().x()<< " / " << currTsos.globalPosition().y()<< " / " << currTsos.globalPosition().z() << std::endl;
714  std::cout << " local position x: " << currTsos.localPosition().x() << "+-" << sqrt(currTsos.localError().positionError().xx()) << std::endl;
715  std::cout << " local position y: " << currTsos.localPosition().y() << "+-" << sqrt(currTsos.localError().positionError().yy()) << std::endl;
716  }
717 
718  if (!est.first) {
719  if (debug_) std::cout<<"Failed to add one of the original hits on a low occupancy layer!!!!" << std::endl;
720  continue;
721  }
722  currTsos = theUpdator->update(predTsos, *rh);
723  tm = TrajectoryMeasurement(predTsos, currTsos, &(*rh),est.second,ilyr->first);
724 
725  const TrajectoryStateOnSurface theTSOS = newTrajectory.lastMeasurement().updatedState();
726 
727  //std::cout << "11TsosBefore (x/y/z): " << theTSOS.globalPosition().x()<< " / " << theTSOS.globalPosition().y()<< " / " << theTSOS.globalPosition().z() << std::endl;
728  //std::cout << " 11local position x: " << theTSOS.localPosition().x() << "+-" << sqrt(theTSOS.localError().positionError().xx()) << std::endl;
729  //std::cout << " 11local position y: " << theTSOS.localPosition().y() << "+-" << sqrt(theTSOS.localError().positionError().yy()) << std::endl;
730 
731 
732 
733  newTrajectory.push(tm,est.second);
734  final_layers.insert(ilyr->first);
735  }
736  else{
737  if (debug_) std::cout<<" Layer " << ilyr-RecHitsByLayer.begin() <<" is one of the skipped layers " << std::endl;
738 
739  //collect hits in the skipped layer
740  edm::OwnVector<TrackingRecHit> skipped_hits;
741  std::set<const GeomDet*> dets;
742  for (RoadSearchCloud::RecHitVector::const_iterator ih = ilyr->second.begin();
743  ih != ilyr->second.end(); ++ih) {
744  skipped_hits.push_back((*ih)->clone());
745  dets.insert(trackerGeom->idToDet((*ih)->geographicalId()));
746  }
747 
748  if(debug_){
749  std::cout<<" ---> probing missing hits (nh="<< skipped_hits.size() << ", nd=" << dets.size()
750  << ") in layer " << ilyr-RecHitsByLayer.begin() <<std::endl;
751  }
752 
753  const TrajectoryStateOnSurface theTSOS = newTrajectory.lastMeasurement().updatedState();
754 
755  //std::cout << "TsosBefore (x/y/z): " << theTSOS.globalPosition().x()<< " / " << theTSOS.globalPosition().y()<< " / " << theTSOS.globalPosition().z() << std::endl;
756  //std::cout << " local position x: " << theTSOS.localPosition().x() << "+-" << sqrt(theTSOS.localError().positionError().xx()) << std::endl;
757  //std::cout << " local position y: " << theTSOS.localPosition().y() << "+-" << sqrt(theTSOS.localError().positionError().yy()) << std::endl;
758 
759  std::vector<TrajectoryMeasurement> theGoodHits = FindBestHits(theTSOS,dets,theHitMatcher,skipped_hits);
760  if (!theGoodHits.empty()){
761  final_layers.insert(ilyr->first);
762  if (debug_) std::cout<<"Found " << theGoodHits.size() << " good hits to add" << std::endl;
763  for (std::vector<TrajectoryMeasurement>::const_iterator im=theGoodHits.begin();im!=theGoodHits.end();++im){
764  newTrajectory.push(*im,im->estimate());
765  }
766  }
767  }
768  } // END 2nd PASS LOOP OVER LAYERS IN CLOUD
769 
770  if (debug_) std::cout<<"Finished loop over layers in cloud. Trajectory now has " <<newTrajectory.measurements().size()
771  << " hits. " << std::endl;
772  if (debug_) std::cout<<"The trajectory has " << newTrajectory.measurements().size() <<" hits on " << final_layers.size()
773  << " layers from a cloud of " << RecHitsByLayer.size()
774  << " layers and a chunk of " << (RecHitsByLayer.size() - ilayer0) << " layers " << std::endl;
775  if (newTrajectory.measurements().size() >= theNumHitCut)
776  extendedChunks.insert(extendedChunks.end(), newTrajectory);
777  if (final_layers.size() >= (RecHitsByLayer.size() - ilayer0)){
778  if (debug_) std::cout<<"All layers of the chunk have been used..." << std::endl;
779  all_layers_used = true;
780  }
781  } // END ELSE TO RECOVER SKIPPED LAYERS
782  if (all_layers_used) {
783  if (debug_) std::cout << "All layers were used, so break....." << std::endl;
784  all_chunk_layers_used = true;
785  break;
786  }
787  if (debug_) std::cout<<"Going to next clean chunk....." << std::endl;
788  } // END LOOP OVER CLEAN CHUNKS
789  if (debug_) std::cout<< "Now Clean the " << extendedChunks.size() << " extended chunks " <<std::endl;
790  if (extendedChunks.size() > 1) theTrajectoryCleaner->clean(extendedChunks);
791  for (std::vector<Trajectory>::const_iterator it = extendedChunks.begin();
792  it != extendedChunks.end(); it++) {
793  if (it->isValid()) CloudTrajectories.push_back(*it);
794  }
795  if (all_chunk_layers_used) break;
796  }
797 
798  // ********************* END NEW ADDITION
799 
800  if (debug_) std::cout<< "Finished with the cloud, so clean the "
801  << CloudTrajectories.size() << " cloud trajectories "<<std::endl ;
802  theTrajectoryCleaner->clean(CloudTrajectories);
803  for (std::vector<Trajectory>::const_iterator it = CloudTrajectories.begin();
804  it != CloudTrajectories.end(); it++) {
805  if (it->isValid()) FinalTrajectories.push_back(*it);
806  }
807 
808  if (debug_) std::cout<<" Final trajectories now has size " << FinalTrajectories.size()<<std::endl ;
809 
810  } // End loop over Cloud Collection
811 
812 
813  if (debug_) std::cout<< " Finished loop over all clouds " <<std::endl;
814 
815  output = PrepareTrackCandidates(FinalTrajectories);
816 
817  delete theAloPropagator;
818  delete theRevPropagator;
820  delete theHitMatcher;
821  delete theSmoother;
822 
823  if (debug_ || debugCosmics_) std::cout<< "Found " << output.size() << " track candidate(s)."<<std::endl;
824 
825 }
826 
827 
828 //edm::OwnVector<TrackingRecHit>
829 std::vector<TrajectoryMeasurement>
831  const std::set<const GeomDet*>& theDets,
833 // edm::OwnVector<TrackingRecHit> *theBestHits)
834 {
835 
836  //edm::OwnVector<TrackingRecHit> theBestHits;
837  std::vector<TrajectoryMeasurement> theBestHits;
838 
839  // extrapolate to all detectors from the list
840  std::map<const GeomDet*, TrajectoryStateOnSurface> dmmap;
841  for (std::set<const GeomDet*>::iterator idet = theDets.begin();
842  idet != theDets.end(); ++idet) {
843  TrajectoryStateOnSurface predTsos = thePropagator->propagate(tsosBefore, (**idet).surface());
844  if (predTsos.isValid()) {
845  GlobalVector propagationDistance = predTsos.globalPosition() - tsosBefore.globalPosition();
846  if (propagationDistance.mag() > maxPropagationDistance) continue;
847  dmmap.insert(std::make_pair(*idet, predTsos));
848  }
849  }
850  // evaluate hit residuals
851  std::map<const GeomDet*, TrajectoryMeasurement> dtmmap;
853  ih != theHits.end(); ++ih) {
854  const GeomDet* det = trackerGeom->idToDet(ih->geographicalId());
855 
856  std::map<const GeomDet*, TrajectoryStateOnSurface>::iterator idm = dmmap.find(det);
857  if (idm == dmmap.end()) continue;
858  TrajectoryStateOnSurface predTsos = idm->second;
861 
862  // Take the best hit on a given Det
863  if (est.first) {
864  TrajectoryStateOnSurface currTsos = theUpdator->update(predTsos, *rhit);
865  std::map<const GeomDet*, TrajectoryMeasurement>::iterator idtm = dtmmap.find(det);
866  if (idtm == dtmmap.end()) {
867  TrajectoryMeasurement tm(predTsos, currTsos, &(*rhit),est.second,
868  theMeasurementTracker->geometricSearchTracker()->detLayer(ih->geographicalId()));
869  dtmmap.insert(std::make_pair(det, tm));
870  } else if (idtm->second.estimate() > est.second) {
871  dtmmap.erase(idtm);
872  TrajectoryMeasurement tm(predTsos, currTsos, &(*rhit),est.second,
873  theMeasurementTracker->geometricSearchTracker()->detLayer(ih->geographicalId()));
874  dtmmap.insert(std::make_pair(det, tm));
875  }
876  }
877  }
878 
879  if (!dtmmap.empty()) {
880  for (std::map<const GeomDet*, TrajectoryMeasurement>::iterator idtm = dtmmap.begin();
881  idtm != dtmmap.end(); ++idtm) {
882  TrajectoryMeasurement itm = idtm->second;
883  theBestHits.push_back(itm);
884  }
885  }
886 
887  return theBestHits;
888 }
889 
890 
891 std::vector<TrajectoryMeasurement>
893  const std::set<const GeomDet*>& theDets,
895 {
896 
897  std::vector<TrajectoryMeasurement> theBestHits;
898 
899  double bestchi = 10000.0;
900  // extrapolate to all detectors from the list
901  std::map<const GeomDet*, TrajectoryStateOnSurface> dmmap;
902  for (std::set<const GeomDet*>::iterator idet = theDets.begin();
903  idet != theDets.end(); ++idet) {
904  TrajectoryStateOnSurface predTsos = thePropagator->propagate(tsosBefore, (**idet).surface());
905  if (predTsos.isValid()) {
906  GlobalVector propagationDistance = predTsos.globalPosition() - tsosBefore.globalPosition();
907  if (propagationDistance.mag() > maxPropagationDistance) continue;
908  dmmap.insert(std::make_pair(*idet, predTsos));
909  }
910  }
911  // evaluate hit residuals
912  std::map<const GeomDet*, TrajectoryMeasurement> dtmmap;
914  ih != theHits.end(); ++ih) {
915  const GeomDet* det = trackerGeom->idToDet(ih->geographicalId());
916 
917  std::map<const GeomDet*, TrajectoryStateOnSurface>::iterator idm = dmmap.find(det);
918  if (idm == dmmap.end()) continue;
919  TrajectoryStateOnSurface predTsos = idm->second;
922 
923  // Take the best hit on any Det
924  if (est.first) {
925  TrajectoryStateOnSurface currTsos = theUpdator->update(predTsos, *rhit);
926  if (est.second < bestchi){
927  if(!theBestHits.empty()){
928  theBestHits.erase(theBestHits.begin());
929  }
930  bestchi = est.second;
931  TrajectoryMeasurement tm(predTsos, currTsos, &(*rhit),est.second,
932  theMeasurementTracker->geometricSearchTracker()->detLayer(ih->geographicalId()));
933  theBestHits.push_back(tm);
934  }
935  }
936  }
937 
938  if (theBestHits.empty()){
939  if (debug_) std::cout<< "no hits to add! " <<std::endl;
940  }
941  else{
942  for (std::vector<TrajectoryMeasurement>::const_iterator im=theBestHits.begin();im!=theBestHits.end();++im)
943  if (debug_) std::cout<<" Measurement on layer "
944  << theMeasurementTracker->geometricSearchTracker()->detLayer(im->recHit()->geographicalId())
945  << " with estimate " << im->estimate()<<std::endl ;
946  }
947 
948  return theBestHits;
949 }
950 
951 std::vector<TrajectoryMeasurement>
953  const std::set<const GeomDet*>& theDets,
954  const SiStripRecHitMatcher* theHitMatcher,
956 // edm::OwnVector<TrackingRecHit> *theBestHits)
957 {
958 
959 
960  std::vector<TrajectoryMeasurement> theBestHits;
961  //TrajectoryMeasurement* theBestTM = 0;
962  TrajectoryMeasurement theBestTM;
963  bool firstTM = true;
964 
965  // extrapolate to all detectors from the list
966  std::map<const GeomDet*, TrajectoryStateOnSurface> dmmap;
967  for (std::set<const GeomDet*>::iterator idet = theDets.begin();
968  idet != theDets.end(); ++idet) {
969  TrajectoryStateOnSurface predTsos = thePropagator->propagate(tsosBefore, (**idet).surface());
970  if (predTsos.isValid()) {
971  GlobalVector propagationDistance = predTsos.globalPosition() - tsosBefore.globalPosition();
972  if (propagationDistance.mag() > maxPropagationDistance) continue;
973  dmmap.insert(std::make_pair(*idet, predTsos));
974  }
975  }
976 
977  if(debug_) std::cout << "TRAJECTORY INTERSECTS " << dmmap.size() << " DETECTORS." << std::endl;
978 
979  // evaluate hit residuals
980  std::map<const GeomDet*, TrajectoryMeasurement> dtmmap;
981  for (edm::OwnVector<TrackingRecHit>::const_iterator ih = theHits.begin(); ih != theHits.end(); ++ih) {
982  const GeomDet* det = trackerGeom->idToDet(ih->geographicalId());
983  //if (*isl != theMeasurementTracker->geometricSearchTracker()->detLayer(ih->geographicalId()))
984  // std::cout <<" You don't know what you're doing !!!!" << std::endl;
985 
986  std::map<const GeomDet*, TrajectoryStateOnSurface>::iterator idm = dmmap.find(det);
987  if (idm == dmmap.end()) continue;
988  TrajectoryStateOnSurface predTsos = idm->second;
990 
991  const SiStripMatchedRecHit2D *origHit = dynamic_cast<const SiStripMatchedRecHit2D *>(&(*ih));
992  if (origHit !=0){
993  const GluedGeomDet *gdet = dynamic_cast<const GluedGeomDet*>(det);
994  const SiStripMatchedRecHit2D *corrHit = theHitMatcher->match(origHit,gdet,predTsos.localDirection());
995  if (corrHit!=0){
996  rhit = ttrhBuilder->build(&(*corrHit));
997  delete corrHit;
998  }
999  }
1000 
1001  if (debug_) {
1002  std::cout << "predTSOS (x/y/z): " << predTsos.globalPosition().x()<< " / " << predTsos.globalPosition().y()<< " / " << predTsos.globalPosition().z() << std::endl;
1003  std::cout << "local position x: " << predTsos.localPosition().x() << "+-" << sqrt(predTsos.localError().positionError().xx()) << std::endl;
1004  std::cout << "local position y: " << predTsos.localPosition().y() << "+-" << sqrt(predTsos.localError().positionError().yy()) << std::endl;
1005  std::cout << "rhit local position x: " << rhit->localPosition().x() << "+-" << sqrt(rhit->localPositionError().xx()) << std::endl;
1006  std::cout << "rhit local position y: " << rhit->localPosition().y() << "+-" << sqrt(rhit->localPositionError().yy()) << std::endl;
1007  }
1008 
1010  if (debug_) std::cout<< "hit " << ih-theHits.begin()
1011  << ": est = " << est.first << " " << est.second <<std::endl;
1012 
1013 
1014  // Take the best hit on a given Det
1015  if (est.first) {
1017  TrajectoryStateOnSurface currTsos = theUpdator->update(predTsos, *rhit);
1018  std::map<const GeomDet*, TrajectoryMeasurement>::iterator idtm = dtmmap.find(det);
1019  if (idtm == dtmmap.end()) {
1020  tm = TrajectoryMeasurement (predTsos, currTsos, &(*rhit),est.second,
1021  theMeasurementTracker->geometricSearchTracker()->detLayer(ih->geographicalId()));
1022  dtmmap.insert(std::make_pair(det, tm));
1023  } else if (idtm->second.estimate() > est.second) {
1024  dtmmap.erase(idtm);
1025  tm = TrajectoryMeasurement(predTsos, currTsos, &(*rhit),est.second,
1026  theMeasurementTracker->geometricSearchTracker()->detLayer(ih->geographicalId()));
1027  dtmmap.insert(std::make_pair(det, tm));
1028  }
1029  if ((firstTM)){
1030  theBestTM = tm;
1031  if (debug_) std::cout <<"Initialize best to " << theBestTM.estimate() << std::endl;
1032  firstTM = false;
1033  }
1034  else if (!firstTM) {
1035  if (debug_) std::cout << "Current best is " << theBestTM.estimate() << " while this hit is " << est.second;
1036  if (est.second < theBestTM.estimate()) {
1037  if (debug_) std::cout << " so replace it " ;
1038  theBestTM = tm;
1039  }
1040  if (debug_) std::cout << std::endl;
1041  }
1042  }
1043  }
1044  if (debug_) std::cout<< "Hits(Dets) to add: " << dtmmap.size() <<std::endl;
1045  if (!dtmmap.empty()) {
1046 
1047  std::vector<std::pair<TransientTrackingRecHit::ConstRecHitPointer, TrajectoryMeasurement*> > OverlapHits;
1048  for (std::map<const GeomDet*, TrajectoryMeasurement>::iterator idtm = dtmmap.begin();
1049  idtm != dtmmap.end(); ++idtm) {
1050  OverlapHits.push_back(std::make_pair(idtm->second.recHit(),&idtm->second));
1051 
1052  if (debug_) std::cout<<" Measurement on layer "
1053  << theMeasurementTracker->geometricSearchTracker()->detLayer(idtm->second.recHit()->geographicalId())
1054  << " with estimate " << idtm->second.estimate()<<std::endl ;
1055  }
1056  if (debug_)
1057  std::cout<<" Best Measurement is on layer "
1058  << theMeasurementTracker->geometricSearchTracker()->detLayer(theBestTM.recHit()->geographicalId())
1059  << " with estimate " << theBestTM.estimate()<<std::endl ;
1060 
1061 
1062  if (dtmmap.size()==1){ // only one hit so we can just return that one
1063  for (std::map<const GeomDet*, TrajectoryMeasurement>::iterator idtm = dtmmap.begin();
1064  idtm != dtmmap.end(); ++idtm) {
1065  TrajectoryMeasurement itm = idtm->second;
1066  if (debug_) std::cout<<" Measurement on layer "
1067  << theMeasurementTracker->geometricSearchTracker()->detLayer(itm.recHit()->geographicalId())
1068  << " with estimate " << itm.estimate()<<std::endl ;
1069  theBestHits.push_back(itm);
1070  }
1071  }
1072  else if (dtmmap.size()>=2) { // try for the overlaps -- first have to sort inside out
1073 
1074  if (debug_) std::cout<<"Unsorted OverlapHits has size " <<OverlapHits.size() << std::endl;
1075 
1076  for (std::vector<std::pair<TransientTrackingRecHit::ConstRecHitPointer,TrajectoryMeasurement*> >::iterator irh =OverlapHits.begin();
1077  irh!=OverlapHits.end();++irh){
1078  if (debug_) std::cout << "Hit " << irh-OverlapHits.begin()
1079  << " on det " << irh->first->det()
1080  << " detLayer "
1081  << theMeasurementTracker->geometricSearchTracker()->detLayer(irh->first->geographicalId())
1082  << ", r/phi/z = "
1083  << irh->first->globalPosition().perp() << " "
1084  << irh->first->globalPosition().phi() << " "
1085  << irh->first->globalPosition().z()
1086  << std::endl;
1087  }
1088 
1089  std::sort( OverlapHits.begin(),OverlapHits.end(),SortHitTrajectoryPairsByGlobalPosition());
1090  if (debug_) std::cout<<"Sorted OverlapHits has size " <<OverlapHits.size() << std::endl;
1091 
1092  float workingBestChi2 = 1000000.0;
1093  std::vector<TrajectoryMeasurement> workingBestHits;
1094 
1095  std::vector<std::pair<TransientTrackingRecHit::ConstRecHitPointer,TrajectoryMeasurement*> >::iterator irh1;
1096  std::vector<std::pair<TransientTrackingRecHit::ConstRecHitPointer,TrajectoryMeasurement*> >::iterator irh2;
1097  for (irh1 =OverlapHits.begin(); irh1!=--OverlapHits.end(); ++irh1){
1098  theBestHits.clear();
1099  float running_chi2=0;
1100  if (debug_) std::cout << "Hit " << irh1-OverlapHits.begin()
1101  << " on det " << irh1->first->det()
1102  << " detLayer "
1103  << theMeasurementTracker->geometricSearchTracker()->detLayer(irh1->first->geographicalId())
1104  << ", r/phi/z = "
1105 
1106  << irh1->first->globalPosition().perp() << " "
1107  << irh1->first->globalPosition().phi() << " "
1108  << irh1->first->globalPosition().z()
1109  << std::endl;
1110 
1111  TrajectoryStateOnSurface currTsos = irh1->second->updatedState();
1113  theBestHits.push_back(*(irh1->second));
1114  if (debug_) std::cout<<"Added first hit with chi2 = " << irh1->second->estimate() << std::endl;
1115  running_chi2 += irh1->second->estimate();
1116  for (irh2 = irh1; irh2!=OverlapHits.end(); ++irh2){
1117  if (irh2 == irh1) continue;
1119  const GeomDet* det = irh2->first->det();
1120  // extrapolate the trajectory to the next hit
1121  TrajectoryStateOnSurface predTsos = thePropagator->propagate(currTsos, det->surface());
1122  // test if matches
1123  if (predTsos.isValid()){
1125  if (debug_) std::cout<<"Added overlap hit with est = " << est.first << " " << est.second << std::endl;
1126  if (est.first){
1127  TrajectoryMeasurement tm(predTsos, currTsos, &(*rh),est.second,
1128  theMeasurementTracker->geometricSearchTracker()->detLayer(rh->geographicalId()));
1129  theBestHits.push_back(tm);
1130  running_chi2 += est.second ;
1131  }
1132  else { // couldn't add 2nd hit so return best single hit
1133  }
1134  }
1135 
1136  }
1137  if (theBestHits.size()==dtmmap.size()){ // added the best hit in every layer
1138  if (debug_) std::cout<<"Added all "<<theBestHits.size()<<" hits out of " << dtmmap.size() << std::endl;
1139  break;
1140  }
1141  // Didn't add hits from every Det
1142  if (theBestHits.size() < dtmmap.size()){
1143  if (debug_) std::cout<<"Added only "<<theBestHits.size()<<" hits out of " << dtmmap.size() << std::endl;
1144  // Take the combination with the most hits
1145  if (theBestHits.size() > workingBestHits.size()){
1146  if (debug_) std::cout<<"Current combo has more hits so replace best" << std::endl;
1147  workingBestHits = theBestHits;
1148  }
1149  // has same number of hits as best, so check chi2
1150  else if (theBestHits.size() == workingBestHits.size()){
1151  if (running_chi2< workingBestChi2){
1152  if (debug_) std::cout<<"Current combo has same # of hits but lower chi2 so replace best" << std::endl;
1153  workingBestHits = theBestHits;
1154  workingBestChi2 = running_chi2;
1155  }
1156  }
1157  }
1158  }
1159  if (theBestHits.size()<2){
1160  if (debug_) std::cout<<"Only one good hit in overlap"<<std::endl;
1161  if (debug_) std::cout<<" Added hit on layer on det "
1162  << theBestTM.recHit()->det()
1163  << " detLayer "
1164  << theMeasurementTracker->geometricSearchTracker()->detLayer(theBestTM.recHit()->geographicalId())
1165  << ", r/phi/z = "
1166  << theBestTM.recHit()->globalPosition().perp() << " "
1167  << theBestTM.recHit()->globalPosition().phi() << " "
1168  << theBestTM.recHit()->globalPosition().z()
1169  << " with estimate " << theBestTM.estimate()<<std::endl ;
1170  theBestHits.clear();
1171  theBestHits.push_back(theBestTM);
1172  }
1173 
1174  }
1175  else {
1176  if (debug_)std::cout << "ERROR: Unexpected size from DTMMAP = " << dtmmap.size() << std::endl;
1177  theBestHits.push_back(theBestTM);
1178  }
1179  }
1180 
1181  return theBestHits;
1182 }
1183 
1184 
1185 //bool RoadSearchTrackCandidateMakerAlgorithm::chooseStartingLayers( RoadSearchCloud::RecHitVector& recHits, int ilayer0,
1186 bool RoadSearchTrackCandidateMakerAlgorithm::chooseStartingLayers( std::vector<std::pair<const DetLayer*, RoadSearchCloud::RecHitVector > >& recHitsByLayer,
1187  //int ilayer0,
1188  std::vector<std::pair<const DetLayer*, RoadSearchCloud::RecHitVector > >::iterator ilyr0,
1189  const std::multimap<int, const DetLayer*>& layer_map,
1190  std::set<const DetLayer*>& good_layers,
1191  std::vector<const DetLayer*>& middle_layers ,
1192  RoadSearchCloud::RecHitVector& recHits_middle)
1193 {
1194  const unsigned int max_middle_layers = 2;
1195 
1196  // consider the best nFoundMin layers + other layers with only one hit
1197  // This has implications, based on the way we locate the hits.
1198  // For now, use only the low occupancy layers in the first pass
1199  //const int nfound_min = min_chunk_length-1;
1200  //const int nfound_min = 4;
1201  std::multimap<int, const DetLayer*>::const_iterator ilm = layer_map.begin();
1202  int ngoodlayers = 0;
1203  while (ilm != layer_map.end()) {
1204  if (ngoodlayers >= nFoundMin_ && ilm->first > 1) break;
1205  //if (ilm->first > 1) break;
1206  good_layers.insert(ilm->second);
1207  ++ngoodlayers;
1208  ++ilm;
1209  }
1210 
1211  // choose intermediate layers
1212  for (std::vector<std::pair<const DetLayer*, RoadSearchCloud::RecHitVector > >::iterator ilayer = ilyr0+1;
1213  ilayer != recHitsByLayer.end(); ++ilayer) {
1214  // only use useful layers
1215  if (good_layers.find(ilayer->first) == good_layers.end()) continue;
1216  // only use stereo layers
1217  if (!CosmicReco_ && !lstereo[ilayer-recHitsByLayer.begin()]) continue;
1218  middle_layers.push_back(ilayer->first);
1219  if (middle_layers.size() >= max_middle_layers) break;
1220  }
1221 
1222  for (std::vector<const DetLayer*>::iterator ml = middle_layers.begin();
1223  ml!=middle_layers.end();++ml){
1224  unsigned int middle_layers_found = 0;
1225  for (std::vector<std::pair<const DetLayer*, RoadSearchCloud::RecHitVector > >::iterator ilyr = recHitsByLayer.begin();
1226  ilyr != recHitsByLayer.end(); ++ilyr) {
1227  if (ilyr->first == *ml){
1228  for (RoadSearchCloud::RecHitVector::const_iterator ih = ilyr->second.begin();
1229  ih != ilyr->second.end(); ++ih) {
1230  recHits_middle.push_back(*ih);
1231  }
1232  ++middle_layers_found;
1233  }
1234  if (middle_layers_found == middle_layers.size()) continue;
1235  }
1236 
1237  }
1238  return (recHits_middle.size()>0);
1239 }
1240 
1242  const TrackingRecHit* theInnerHit,
1243  const TrackingRecHit* theOuterHit)
1244 {
1245  FreeTrajectoryState fts;
1246 
1247  GlobalPoint inner = trackerGeom->idToDet(theInnerHit->geographicalId())->surface().toGlobal(theInnerHit->localPosition());
1248  GlobalPoint outer = trackerGeom->idToDet(theOuterHit->geographicalId())->surface().toGlobal(theOuterHit->localPosition());
1249 
1250  LogDebug("RoadSearch") << "inner hit: r/phi/z = "<< inner.perp() << " " << inner.phi() << " " << inner.z() ;
1251  LogDebug("RoadSearch") << "outer hit: r/phi/z = "<< outer.perp() << " " << outer.phi() << " " << outer.z() ;
1252 
1253  // hits should be reasonably separated in r
1254  const double dRmin = 0.1; // cm
1255  if (outer.perp() - inner.perp() < dRmin) return fts;
1256  //GlobalPoint vertexPos(0,0,0);
1257  const double dr2 = initialVertexErrorXY_*initialVertexErrorXY_;
1258  //const double dr2 = 0.0015*0.0015;
1259  //const double dr2 = 0.2*0.2;
1260  const double dz2 = 5.3*5.3;
1261 
1262  // linear z extrapolation of two hits have to be inside tracker ( |z| < 275 cm)
1263  FastLine linearFit(outer, inner);
1264  double z_0 = -linearFit.c()/linearFit.n2();
1265  if ( std::abs(z_0) > 275 && !CosmicReco_ ) return fts;
1266 
1267  GlobalError vertexErr(dr2,
1268  0, dr2,
1269  0, 0, dz2);
1270  //TrivialVertex vtx( vertexPos, vertexErr);
1271  //FastHelix helix(outerHit.globalPosition(),
1272  // (*innerHit).globalPosition(),
1273  // vtx.position());
1274 
1275  double x0=0.0,y0=0.0,z0=0.0;
1276  double phi0 = -999.0;
1277  if (NoFieldCosmic_){
1278  phi0=atan2(outer.y()-inner.y(),outer.x()-inner.x());
1280  if (inner.y()<outer.y()){
1281  if (debug_) std::cout<<"Flipping direction!!!" << std::endl;
1282  thePropagator = theRevPropagator;
1283  phi0=phi0-M_PI;
1284  }
1285  double alpha=atan2(inner.y(),inner.x());
1286  double d1=sqrt(inner.x()*inner.x()+inner.y()*inner.y());
1287  double d0=-d1*sin(alpha-phi0); x0=d0*sin(phi0); y0=-d0*cos(phi0);
1288  double l1=0.0,l2=0.0;
1289  if (fabs(cos(phi0))>0.1){
1290  l1=(inner.x()-x0)/cos(phi0);l2=(outer.x()-x0)/cos(phi0);
1291  }else{
1292  l1=(inner.y()-y0)/sin(phi0);l2=(outer.y()-y0)/sin(phi0);
1293  }
1294  z0=(l2*inner.z()-l1*outer.z())/(l2-l1);
1295  }
1296  //FastHelix helix(outer, inner, vertexPos, es);
1297  FastHelix helix(outer, inner, GlobalPoint(x0,y0,z0), es);
1298  if (!NoFieldCosmic_ && !helix.isValid()) return fts;
1299 
1301  float zErr = vertexErr.czz();
1302  float transverseErr = vertexErr.cxx(); // assume equal cxx cyy
1303  C(3, 3) = transverseErr;
1304  C(4, 4) = zErr;
1305  CurvilinearTrajectoryError initialError(C);
1306 
1307  if (NoFieldCosmic_) {
1308  TrackCharge q = 1;
1309  FastLine flfit(outer, inner);
1310  double dzdr = -flfit.n1()/flfit.n2();
1311  if (inner.y()<outer.y()) dzdr*=-1;
1312 
1313  GlobalPoint XYZ0(x0,y0,z0);
1314  if (debug_) std::cout<<"Initial Point (x0/y0/z0): " << x0 <<'\t'<< y0 <<'\t'<< z0 << std::endl;
1315  GlobalVector PXYZ(cosmicSeedPt_*cos(phi0),
1316  cosmicSeedPt_*sin(phi0),
1317  cosmicSeedPt_*dzdr);
1318  GlobalTrajectoryParameters thePars(XYZ0,PXYZ,q,magField);
1320  CErr *= 5.0;
1321  // CErr(3,3) = (theInnerHit->localPositionError().yy()*theInnerHit->localPositionError().yy() +
1322  // theOuterHit->localPositionError().yy()*theOuterHit->localPositionError().yy());
1323  fts = FreeTrajectoryState(thePars,
1324  CartesianTrajectoryError(CErr));
1325  if (debug_) std::cout<<"\nInitial CError (dx/dy/dz): " << CErr(1,1) <<'\t'<< CErr(2,2) <<'\t'<< CErr(3,3) << std::endl;
1326  if (debug_) std::cout<<"\n\ninner dy = " << theInnerHit->localPositionError().yy() <<"\t\touter dy = " << theOuterHit->localPositionError().yy() << std::endl;
1327  }
1328  else {
1329  fts = FreeTrajectoryState( helix.stateAtVertex().parameters(), initialError);
1330  }
1331  // RoadSearchSeedFinderAlgorithm::initialError( *outerHit, *(*innerHit),
1332  // vertexPos, vertexErr));
1333 
1334  return fts;
1335 }
1336 
1338  const TrackingRecHit* theInnerHit,
1339  const TrackingRecHit* theMiddleHit,
1340  const TrackingRecHit* theOuterHit)
1341 {
1342  FreeTrajectoryState fts;
1343 
1344  GlobalPoint inner = trackerGeom->idToDet(theInnerHit->geographicalId())->surface().toGlobal(theInnerHit->localPosition());
1345  GlobalPoint middle= trackerGeom->idToDet(theMiddleHit->geographicalId())->surface().toGlobal(theMiddleHit->localPosition());
1346  GlobalPoint outer = trackerGeom->idToDet(theOuterHit->geographicalId())->surface().toGlobal(theOuterHit->localPosition());
1347 
1348  LogDebug("RoadSearch") << "inner hit: r/phi/z = "<< inner.perp() << " " << inner.phi() << " " << inner.z() ;
1349  LogDebug("RoadSearch") << "middlehit: r/phi/z = "<< inner.perp() << " " << inner.phi() << " " << inner.z() ;
1350  LogDebug("RoadSearch") << "outer hit: r/phi/z = "<< outer.perp() << " " << outer.phi() << " " << outer.z() ;
1351 
1352  // hits should be reasonably separated in r
1353  const double dRmin = 0.1; // cm
1354  if (outer.perp() - inner.perp() < dRmin) return fts;
1355  const double dr2 = initialVertexErrorXY_*initialVertexErrorXY_;
1356  const double dz2 = 5.3*5.3;
1357 
1358  // linear z extrapolation of two hits have to be inside tracker ( |z| < 275 cm)
1359  FastLine linearFit(outer, inner);
1360  double z_0 = -linearFit.c()/linearFit.n2();
1361  if ( std::abs(z_0) > 275 && !CosmicReco_ ) return fts;
1362 
1363 
1364  FastHelix helix(outer, middle, inner, es);
1365  // check that helix is OK
1366  if (!helix.isValid() ||
1367  std::isnan(helix.stateAtVertex().parameters().momentum().perp())) return fts;
1368  // simple cuts on pt and dz
1369  if (helix.stateAtVertex().parameters().momentum().perp() < 0.5 ||
1370  std::abs(helix.stateAtVertex().parameters().position().z()) > 550.0)
1371  return fts;
1372 
1374  float zErr = dz2;
1375  float transverseErr = dr2; // assume equal cxx cyy
1376  C(3, 3) = transverseErr;
1377  C(4, 4) = zErr;
1378  CurvilinearTrajectoryError initialError(C);
1379 
1380 
1383  float charge=helix.stateAtVertex().parameters().charge();
1384 
1385  if (CosmicReco_ && gv.y()>0){
1386  if (debug_) std::cout<<"Flipping direction!!!" << std::endl;
1388  gv=-1.*gv;
1389  charge=-1.*charge;
1390  }
1391 
1392  GlobalTrajectoryParameters Gtp(inner,gv,int(charge),&(*magField));
1393  fts = FreeTrajectoryState(Gtp, initialError);
1394 
1395  //fts = FreeTrajectoryState( helix.stateAtVertex().parameters(), initialError);
1396 
1397  return fts;
1398 }
1399 
1400 
1401 
1403  const TrackingRecHit* theInnerHit,
1404  const DetLayer* theInnerHitLayer)
1405 
1406 {
1407  Trajectory theSeedTrajectory;
1408 
1409  // Need to put the first hit on the trajectory
1410  const GeomDet* innerDet = trackerGeom->idToDet((theInnerHit)->geographicalId());
1411  const TrajectoryStateOnSurface innerState =
1412  thePropagator->propagate(fts,innerDet->surface());
1413  if ( !innerState.isValid() ||
1414  std::isnan(innerState.globalMomentum().perp())) {
1415  if (debug_) std::cout<<"*******DISASTER ********* seed doesn't make it to first hit!!!!!" << std::endl;
1416  return theSeedTrajectory;
1417  }
1419  // if this first hit is a matched hit, it should be updated for the trajectory
1420  const SiStripMatchedRecHit2D *origHit = dynamic_cast<const SiStripMatchedRecHit2D *>(theInnerHit);
1421  if (origHit !=0){
1422  const GluedGeomDet *gdet = dynamic_cast<const GluedGeomDet*>(innerDet);
1423  const SiStripMatchedRecHit2D *corrHit = theHitMatcher->match(origHit,gdet,innerState.localDirection());
1424  if (corrHit!=0){
1425  intrhit = ttrhBuilder->build(&(*corrHit));
1426  delete corrHit;
1427  }
1428  }
1429 
1430  MeasurementEstimator::HitReturnType est = theEstimator->estimate(innerState, *intrhit);
1431  if (!est.first) return theSeedTrajectory;
1432  TrajectoryStateOnSurface innerUpdated= theUpdator->update( innerState,*intrhit);
1433  if (debug_) std::cout<<"InnerUpdated: " << innerUpdated << std::endl;
1434  if (!innerUpdated.isValid() ||
1435  std::isnan(innerUpdated.globalMomentum().perp())) {
1436  if (debug_) std::cout<<"Trajectory updated with first hit is invalid!!!" << std::endl;
1437  return theSeedTrajectory;
1438  }
1439  TrajectoryMeasurement tm = TrajectoryMeasurement(innerState, innerUpdated, &(*intrhit),est.second,theInnerHitLayer);
1440 
1442  intrhit->geographicalId().rawId());
1443  edm::OwnVector<TrackingRecHit> newHitsTwo;
1444  newHitsTwo.push_back(intrhit->hit()->clone());
1445 
1446  TrajectorySeed tmpseedTwo = TrajectorySeed(pFirstStateTwo,
1447  newHitsTwo,
1448  alongMomentum);
1450  tmpseedTwo = TrajectorySeed(pFirstStateTwo,
1451  newHitsTwo,
1453  }
1454 
1455 
1456  //Trajectory seedTraj(tmpseedTwo, alongMomentum);
1457  theSeedTrajectory = Trajectory(tmpseedTwo, tmpseedTwo.direction());
1458 
1459  theSeedTrajectory.push(tm,est.second);
1460 
1461  return theSeedTrajectory;
1462 }
1463 
1464 
1465 
1467  RoadSearchCloud::RecHitVector& theLayerHits,
1468  const DetLayer* innerHitLayer,
1469  const TrackingRecHit* outerHit,
1470  const DetLayer* outerHitLayer)
1471 {
1472  std::vector<Trajectory> newTrajectories;
1473 
1474  for(RoadSearchCloud::RecHitVector::const_iterator ihit = theLayerHits.begin();
1475  ihit != theLayerHits.end(); ihit++) {
1476  Trajectory traj = theTrajectory;
1477  const DetLayer* thisLayer =
1478  theMeasurementTracker->geometricSearchTracker()->detLayer((*ihit)->geographicalId());
1479  if (thisLayer == innerHitLayer){
1480  // Right now we are assuming that ONLY single hit layers are in this initial collection
1481  //if (thisLayer == innerHitLayer && !(ihit->recHit() == innerHit->recHit())){
1482  // if (debug_) std::cout<<"On inner hit layer, but have wrong hit?!?!?" << std::endl;
1483  continue;
1484  }
1485  if (thisLayer == outerHitLayer){
1486  LocalPoint p1 = (*ihit)->localPosition();
1487  LocalPoint p2 = outerHit->localPosition();
1488  if (p1.x()!=p2.x() || p1.y()!=p2.y()) continue;
1489  }
1490  // extrapolate
1491 
1493 
1494  if (debug_){
1495  if (rhit->isValid()) {
1496  LogDebug("RoadSearch") << "RecHit " << ihit-theLayerHits.begin()
1497  << ", det " << rhit->det() << ", r/phi/z = "
1498  << rhit->globalPosition().perp() << " "
1499  << rhit->globalPosition().phi() << " "
1500  << rhit->globalPosition().z();
1501  } else {
1502  LogDebug("RoadSearch") << "RecHit " << ihit-theLayerHits.begin()
1503  << " (invalid)";
1504  }
1505  }
1506 
1507  const GeomDet* det = trackerGeom->idToDet(rhit->geographicalId());
1508 
1509  TrajectoryStateOnSurface predTsos;
1510  TrajectoryStateOnSurface currTsos;
1511 
1512  if (traj.measurements().empty()) {
1513  //predTsos = thePropagator->propagate(fts, det->surface());
1514  if (debug_) std::cout<<"BIG ERROR!!! How did we make it to here with no trajectory measurements?!?!?"<<std::endl;
1515  } else {
1516  currTsos = traj.measurements().back().updatedState();
1517  predTsos = thePropagator->propagate(currTsos, det->surface());
1518  }
1519  if (!predTsos.isValid()){
1520  continue;
1521  }
1522  GlobalVector propagationDistance = predTsos.globalPosition() - currTsos.globalPosition();
1523  if (propagationDistance.mag() > maxPropagationDistance) continue;
1524  if (debug_) {
1525  std::cout << "currTsos (x/y/z): "
1526  << currTsos.globalPosition().x() << " / "
1527  << currTsos.globalPosition().y() << " / "
1528  << currTsos.globalPosition().z() << std::endl;
1529  std::cout << "predTsos (x/y/z): "
1530  << predTsos.globalPosition().x() << " / "
1531  << predTsos.globalPosition().y() << " / "
1532  << predTsos.globalPosition().z() << std::endl;
1533  std::cout << "Propagation distance1 is " << propagationDistance.mag() << std::endl;
1534  }
1536  if (debug_){
1537  std::cout<< "trajectory at r/z=" << det->surface().position().perp()
1538  << " " << det->surface().position().z()
1539  << ", hit " << ihit-theLayerHits.begin()
1540  << " local prediction " << predTsos.localPosition().x()
1541  << " +- " << sqrt(predTsos.localError().positionError().xx())
1542  << ", hit at " << rhit->localPosition().x() << " +- " << sqrt(rhit->localPositionError().xx())
1543  << std::endl;
1544  }
1545 
1546  // update
1547  // first correct for angle
1548 
1549  const SiStripMatchedRecHit2D *origHit = dynamic_cast<const SiStripMatchedRecHit2D *>(*ihit);
1550  if (origHit !=0){
1551  const GluedGeomDet *gdet = dynamic_cast<const GluedGeomDet*>(rhit->det());
1552  const SiStripMatchedRecHit2D *corrHit = theHitMatcher->match(origHit,gdet,predTsos.localDirection());
1553  if (corrHit!=0){
1554  rhit = ttrhBuilder->build(&(*corrHit));
1555  delete corrHit;
1556  }
1557  }
1558 
1560  if (debug_) std::cout << "estimation: " << est.first << " " << est.second << std::endl;
1561  if (!est.first) continue;
1562  currTsos = theUpdator->update(predTsos, *rhit);
1563  tm = TrajectoryMeasurement(predTsos, currTsos, &(*rhit),est.second,thisLayer);
1564  traj.push(tm,est.second);
1565  newTrajectories.push_back(traj);
1566 
1567 
1568  }
1569 
1570  return newTrajectories;
1571 }
1572 
1573 
1575 {
1576 
1577  TrackCandidateCollection theCollection;
1578 
1579  theTrajectoryCleaner->clean(theTrajectories);
1580 
1581  //==========NEW CODE ==========
1582 
1583  if(CosmicTrackMerging_) {
1584 
1585  //generate vector of *valid* trajectories -> traj
1586  std::vector<Trajectory> traj;
1587 
1588  //keep track of trajectories which are used during merging
1589  std::vector<bool> trajUsed;
1590 
1591  for (std::vector<Trajectory>::iterator it = theTrajectories.begin(); it != theTrajectories.end(); ++it) {
1592  if (it->isValid()) {
1593  traj.push_back(*it);
1594  trajUsed.push_back(false);
1595  }
1596  }
1597 
1598  if(debugCosmics_) {
1599  std::cout << "==========ENTERING COSMIC MODE===========" << std::endl;
1600  // int t=0;
1601  for (std::vector<Trajectory>::iterator it = traj.begin(); it != traj.end(); it++) {
1602  std::cout << "Trajectory " << it-traj.begin() << " has "<<it->recHits().size()<<" hits and is valid: " << it->isValid() << std::endl;
1603  TransientTrackingRecHit::ConstRecHitContainer itHits = it->recHits();
1604 
1605 
1606  for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator rhit=itHits.begin(); rhit!=itHits.end(); ++rhit)
1607  std::cout << "-->good hit position: " << (*rhit)->globalPosition().x() << ", "
1608  << (*rhit)->globalPosition().y() << ", "<< (*rhit)->globalPosition().z() << std::endl;
1609 
1610  }
1611  }
1612 
1613  //double nested looop to find trajectories that match in phi
1614  for ( unsigned int i = 0; i < traj.size(); ++i) {
1615  if (trajUsed[i]) continue;
1616  for ( unsigned int j = i+1; j != traj.size(); ++j) {
1617  if (trajUsed[j]) continue;
1618 
1619  if (debugCosmics_) std::cout<< "Trajectory " <<i<< " has "<<traj[i].recHits().size()<<" hits with chi2=" << traj[i].chiSquared() << " and is valid"<<std::endl;
1620  if (debugCosmics_) std::cout<< "Trajectory " <<j<< " has "<<traj[j].recHits().size()<<" hits with chi2=" << traj[j].chiSquared() << " and is valid"<<std::endl;
1621 
1622  TrajectoryMeasurement firstTraj1 = traj[i].firstMeasurement();
1623  TrajectoryMeasurement firstTraj2 = traj[j].firstMeasurement();
1624  TrajectoryStateOnSurface firstTraj1TSOS = firstTraj1.updatedState();
1625  TrajectoryStateOnSurface firstTraj2TSOS = firstTraj2.updatedState();
1626 
1627 
1628  if(debugCosmics_)
1629  std::cout << "phi1: " << firstTraj1TSOS.globalMomentum().phi()
1630  << " phi2: " << firstTraj2TSOS.globalMomentum().phi()
1631  << " --> delta_phi: " << firstTraj1TSOS.globalMomentum().phi()-firstTraj2TSOS.globalMomentum().phi() << std::endl;
1632 
1633  //generate new trajectory if delta_phi<0.3
1634  //use phi of momentum vector associated to *innermost* hit of trajectories
1635  if( fabs(firstTraj1TSOS.globalMomentum().phi()-firstTraj2TSOS.globalMomentum().phi())<0.3 ) {
1636  if(debugCosmics_) std::cout << "-->match successful" << std::endl;
1637  } else {
1638  if(debugCosmics_) std::cout << "-->match not successful" << std::endl;
1639  }
1640  if( fabs(firstTraj1TSOS.globalMomentum().phi()-firstTraj2TSOS.globalMomentum().phi())>0.3 ) continue;
1641 
1642 
1643  //choose starting trajectory: use trajectory in lower hemisphere (with y<0) to start new combined trajectory
1644  //use y position of outermost hit
1645  TrajectoryMeasurement lastTraj1 = traj[i].lastMeasurement();
1646  TrajectoryMeasurement lastTraj2 = traj[j].lastMeasurement();
1647  TrajectoryStateOnSurface lastTraj1TSOS = lastTraj1.updatedState();
1648  TrajectoryStateOnSurface lastTraj2TSOS = lastTraj2.updatedState();
1649 
1650  if(debugCosmics_){
1651  std::cout<<"Traj1 first (x/y/z): "
1652  << firstTraj1TSOS.globalPosition().x() <<" / "
1653  << firstTraj1TSOS.globalPosition().y() <<" / "
1654  << firstTraj1TSOS.globalPosition().z()
1655  << " phi: " << firstTraj1TSOS.globalMomentum().phi() << std::endl;
1656  std::cout<<"Traj1 last (x/y/z): "
1657  << lastTraj1TSOS.globalPosition().x() <<" / "
1658  << lastTraj1TSOS.globalPosition().y() <<" / "
1659  << lastTraj1TSOS.globalPosition().z()
1660  << " phi: " << lastTraj1TSOS.globalMomentum().phi() << std::endl;
1661 
1662  std::cout<<"Traj2 first (x/y/z): "
1663  << firstTraj2TSOS.globalPosition().x() <<" / "
1664  << firstTraj2TSOS.globalPosition().y() <<" / "
1665  << firstTraj2TSOS.globalPosition().z()
1666  << " phi: " << firstTraj2TSOS.globalMomentum().phi() << std::endl;
1667  std::cout<<"Traj2 last (x/y/z): "
1668  << lastTraj2TSOS.globalPosition().x() <<" / "
1669  << lastTraj2TSOS.globalPosition().y() <<" / "
1670  << lastTraj2TSOS.globalPosition().z()
1671  << " phi: " << lastTraj2TSOS.globalMomentum().phi() << std::endl;
1672 
1673  }
1674 
1675  Trajectory *upperTrajectory, *lowerTrajectory;
1676 
1677  TrajectoryStateOnSurface lowerTSOS1,upperTSOS1;
1678  if (lastTraj1TSOS.globalPosition().y()<firstTraj1TSOS.globalPosition().y()) {
1679  lowerTSOS1=lastTraj1TSOS; upperTSOS1=firstTraj1TSOS;
1680  }
1681  else {
1682  lowerTSOS1=firstTraj1TSOS; upperTSOS1=lastTraj1TSOS;
1683  }
1684  TrajectoryStateOnSurface lowerTSOS2;
1685  if (lastTraj2TSOS.globalPosition().y()<firstTraj2TSOS.globalPosition().y()) lowerTSOS2=lastTraj2TSOS;
1686  else lowerTSOS2=firstTraj2TSOS;
1687  if(lowerTSOS1.globalPosition().y() > lowerTSOS2.globalPosition().y()) {
1688  if(debugCosmics_)
1689  std::cout << "-->case A: "<< lowerTSOS1.globalPosition().y() << " > " << lowerTSOS2.globalPosition().y() << std::endl;
1690 
1691  upperTrajectory = &(traj[i]);
1692  lowerTrajectory = &(traj[j]);
1693 
1694  } else {
1695  if(debugCosmics_)
1696  std::cout << "-->case B: "<< lowerTSOS1.globalPosition().y() << " < " << lowerTSOS2.globalPosition().y() << std::endl;
1697 
1698  upperTrajectory = &(traj[j]);
1699  lowerTrajectory = &(traj[i]);
1700  }
1701 
1702  std::vector<Trajectory> freshStartUpperTrajectory = theSmoother->trajectories(*upperTrajectory);
1703  std::vector<Trajectory> freshStartLowerTrajectory = theSmoother->trajectories(*lowerTrajectory);
1704  //--JR
1705  if (freshStartUpperTrajectory.empty() || freshStartLowerTrajectory .empty()){
1706  if (debugCosmics_) std::cout << " the smoother has failed."<<std::endl;
1707  continue;
1708  }
1709  //--JR
1710  TrajectoryStateOnSurface NewFirstTsos = freshStartUpperTrajectory.begin()->lastMeasurement().updatedState();
1711  TrajectoryStateOnSurface forwardTsos = freshStartUpperTrajectory.begin()->firstMeasurement().forwardPredictedState();
1712  TrajectoryStateOnSurface backwardTsos = freshStartUpperTrajectory.begin()->lastMeasurement().backwardPredictedState();
1713 
1714  Trajectory freshStartTrajectory = *freshStartUpperTrajectory.begin();
1715  if(debugCosmics_) std::cout << "seed hit updatedState: " << NewFirstTsos.globalMomentum().x() << ", " << NewFirstTsos.globalMomentum().y() << ", " << NewFirstTsos.globalMomentum().z() << std::endl;
1716  if(debugCosmics_) std::cout << "seed hit updatedState (pos x/y/z): " << NewFirstTsos.globalPosition().x() << ", " << NewFirstTsos.globalPosition().y() << ", " << NewFirstTsos.globalPosition().z() << std::endl;
1717  if(debugCosmics_) std::cout << "seed hit forwardPredictedState: " << forwardTsos.globalMomentum().x() << ", " << forwardTsos.globalMomentum().y() << ", " << forwardTsos.globalMomentum().z() << std::endl;
1718  if(debugCosmics_) std::cout << "seed hit forwardPredictedState (pos x/y/z): " << forwardTsos.globalPosition().x() << ", " << forwardTsos.globalPosition().y() << ", " << forwardTsos.globalPosition().z() << std::endl;
1719  if(debugCosmics_) std::cout << "seed hit backwardPredictedState: " << backwardTsos.globalMomentum().x() << ", " << backwardTsos.globalMomentum().y() << ", " << backwardTsos.globalMomentum().z() << std::endl;
1720  if(debugCosmics_) std::cout << "seed hit backwardPredictedState (pos x/y/z): " << backwardTsos.globalPosition().x() << ", " << backwardTsos.globalPosition().y() << ", " << backwardTsos.globalPosition().z() << std::endl;
1721 
1722  if(debugCosmics_) std::cout<<"#hits for upper trajectory: " << freshStartTrajectory.measurements().size() << std::endl;
1723 
1724  //loop over hits in upper trajectory and add them to lower trajectory
1726 
1727  if(debugCosmics_) std::cout << "loop over hits in lower trajectory..." << std::endl;
1728 
1729  bool addHitToFreshStartTrajectory = false;
1730  bool propagationFailed = false;
1731  int lostHits = 0;
1732  for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator rhit=ttHits.begin(); rhit!=ttHits.end(); ++rhit){
1733 
1734  if(debugCosmics_ && lostHits>0){
1735  std::cout << " Lost " << lostHits << " of " << ttHits.size() << " on lower trajectory " << std::endl;
1736  std::cout << " Lost " << ((float)lostHits/(float)ttHits.size()) << " of hits of on lower trajectory " << std::endl;
1737  }
1738  if ((float)lostHits/(float)ttHits.size() > 0.5) {
1739  propagationFailed = true;
1740  break;
1741  }
1742  if(debugCosmics_) std::cout << "-->hit position: " << (*rhit)->globalPosition().x() << ", " << (*rhit)->globalPosition().y() << ", "<< (*rhit)->globalPosition().z() << std::endl;
1743 
1744  TrajectoryStateOnSurface predTsos;
1745  TrajectoryStateOnSurface currTsos;
1747 
1749 
1750 
1751 
1752  /*
1753  if( rh->isValid() ) {
1754  if(debugCosmics_) std::cout << "-->hit is valid"<<std::endl;
1755  const GeomDet* det = trackerGeom->idToDet(rh->geographicalId());
1756 
1757  std::vector<TrajectoryMeasurement> measL = freshStartTrajectory.measurements();
1758  bool alreadyUsed = false;
1759  for (std::vector<TrajectoryMeasurement>::iterator mh=measL.begin();mh!=measL.end();++mh) {
1760  if (rh->geographicalId().rawId()==mh->recHit()->geographicalId().rawId()) {
1761  if (debugCosmics_) std::cout << "this hit is already in the trajectory, skip it" << std::endl;
1762  alreadyUsed = true;
1763  break;
1764  }
1765  }
1766  if (alreadyUsed) continue;
1767  //std::vector<TrajectoryMeasurement> measU = freshStartUpperTrajectory[0].measurements();
1768  if (freshStartTrajectory.direction()==0) {
1769  std::vector<TrajectoryMeasurement>::iterator ml;
1770  for (ml=measL.begin();ml!=measL.end();++ml) {
1771  if (debugCosmics_) std::cout << "hit y="<<ml->recHit()->globalPosition().y()
1772  << " tsos validity fwd="<<ml->forwardPredictedState().isValid()
1773  << " bwd="<<ml->backwardPredictedState().isValid()
1774  << " upd="<<ml->updatedState().isValid()
1775  <<std::endl;
1776  if (ml->recHit()->globalPosition().y()>(*rhit)->globalPosition().y() && ml!=measL.begin()) {
1777  break;
1778  }
1779  }
1780  if ((ml-1)->forwardPredictedState().isValid()) currTsos = (ml-1)->forwardPredictedState();
1781  else currTsos = (ml-1)->backwardPredictedState();
1782 
1783  if (debugCosmics_) std::cout << "currTsos y=" << currTsos.globalPosition().y() << std::endl;
1784  }
1785  else {
1786  std::vector<TrajectoryMeasurement>::reverse_iterator ml;
1787  for (ml=measL.rbegin();ml!=measL.rend();++ml) {
1788  if (debugCosmics_) std::cout << "hit y="<<ml->recHit()->globalPosition().y()
1789  << " tsos validity fwd="<<ml->forwardPredictedState().isValid()
1790  << " bwd="<<ml->backwardPredictedState().isValid()
1791  << " upd="<<ml->updatedState().isValid()
1792  <<std::endl;
1793  if (ml->recHit()->globalPosition().y()>(*rhit)->globalPosition().y() && ml!=measL.rbegin()) {
1794  break;
1795  }
1796  }
1797  if ((ml-1)->forwardPredictedState().isValid()) {
1798  currTsos = (ml-1)->forwardPredictedState();
1799  }
1800  else {
1801  currTsos = (ml-1)->backwardPredictedState();
1802  }
1803 
1804  if (debugCosmics_) std::cout << "reverse. currTsos y=" << currTsos.globalPosition().y() << std::endl;
1805  }
1806 
1807 
1808  }
1809  */
1810 
1811 
1812  if( rh->isValid() ) {
1813  if(debugCosmics_) std::cout << "-->hit is valid"<<std::endl;
1814  const GeomDet* det = trackerGeom->idToDet(rh->geographicalId());
1815  if( addHitToFreshStartTrajectory==false ) {
1816  //first hit from upper trajectory that is being added to lower trajectory requires usage of backwardPredictedState (of lower trajectory)
1817  currTsos = freshStartTrajectory.lastMeasurement().backwardPredictedState();
1818  } else {
1819  //remaining hits from upper trajectory that are being added to lower trajectory require usage of forwardPredictedState
1820  currTsos = freshStartTrajectory.lastMeasurement().forwardPredictedState();
1821  }
1822 
1823  if(debugCosmics_) std::cout << "current TSOS: " << currTsos.globalPosition().x() << ", " << currTsos.globalPosition().y() << ", " << currTsos.globalPosition().z() << ", " << std::endl;
1824 
1825  predTsos = theAloPropagator->propagate(currTsos, det->surface());
1826 
1827  if (!predTsos.isValid()) {
1828  if(debugCosmics_) std::cout<<"predTsos is not valid!" <<std::endl;
1829  //propagationFailed = true;
1830  ++lostHits;
1831  //break;
1832  continue;
1833  }
1834  GlobalVector propagationDistance = predTsos.globalPosition() - currTsos.globalPosition();
1835  if (propagationDistance.mag() > maxPropagationDistance) continue;
1836 
1837  if(debugCosmics_) std::cout << "predicted TSOS: " << predTsos.globalPosition().x() << ", " << predTsos.globalPosition().y() << ", " << predTsos.globalPosition().z() << ", " << std::endl;
1839  if (!est.first) {
1840  if(debugCosmics_) std::cout<<"Failed to add one of the original hits on a low occupancy layer!!!!" << std::endl;
1841  //propagationFailed = true;
1842  ++lostHits;
1843  //break;
1844  continue;
1845  }
1846 
1847  currTsos = theUpdator->update(predTsos, *rh);
1848  if(debugCosmics_) std::cout << "current updated TSOS: " << currTsos.globalPosition().x() << ", " << currTsos.globalPosition().y() << ", " << currTsos.globalPosition().z() << ", " << std::endl;
1849  tm = TrajectoryMeasurement(predTsos, currTsos,&(*rh),est.second,theMeasurementTracker->geometricSearchTracker()->detLayer(rh->geographicalId()));
1850  freshStartTrajectory.push(tm,est.second);
1851  addHitToFreshStartTrajectory=true;
1852 
1853  }
1854 
1855  if(debugCosmics_) std::cout<<"#hits for new trajectory (his from upper trajectory added): " << freshStartTrajectory.measurements().size() << std::endl;
1856  }
1857 
1858  if (propagationFailed) {
1859  if (debugCosmics_) std::cout<<"Propagation failed so go to next trajectory" << std::endl;
1860  continue;
1861  }
1862 
1863  //put final trajectory together
1864  if(debugCosmics_) std::cout << "put final trajectory together..." << std::endl;
1866  TransientTrackingRecHit::ConstRecHitContainer tttempHits = freshStartTrajectory.recHits(splitMatchedHits_);
1867 
1868  for (int k=tttempHits.size()-1; k>=0; k--) {
1869  if(debugCosmics_) std::cout << "-->good hit position: " << tttempHits[k]->globalPosition().x() << ", " << tttempHits[k]->globalPosition().y() << ", "<< tttempHits[k]->globalPosition().z() << std::endl;
1870  goodHits.push_back(tttempHits[k]->hit()->clone());
1871  }
1872  TrajectoryStateOnSurface firstState;
1873 
1874  // check if Trajectory from seed is on first hit of the cloud, if not, propagate
1875  // exclude if first state on first hit is not valid
1876  DetId FirstHitId = (*(freshStartTrajectory.recHits().end()-1))->geographicalId(); //was begin
1877 
1878  TrajectoryMeasurement maxYMeasurement = freshStartTrajectory.lastMeasurement();
1879  const GeomDet* det = trackerGeom->idToDet(FirstHitId);
1880  firstState = theAnalyticalPropagator->propagate(maxYMeasurement.updatedState(),det->surface());
1881  if (firstState.isValid() == false) continue;
1883 
1884  //generate new trajectory seed
1885  TrajectoryStateOnSurface firstTSOS = freshStartTrajectory.lastMeasurement().updatedState();
1886  if(debugCosmics_) std::cout << "generate new trajectory seed with hit (x/y/z): " << firstTSOS.globalPosition().x() << ", " << firstTSOS.globalPosition().y() << ", " << firstTSOS.globalPosition().z() << ", " << std::endl;
1887  TransientTrackingRecHit::ConstRecHitPointer rhit = freshStartTrajectory.lastMeasurement().recHit();
1888  PTrajectoryStateOnDet const & pFirstState = trajectoryStateTransform::persistentState(NewFirstTsos,rhit->geographicalId().rawId());
1890  newHits.push_back(rhit->hit()->clone());
1891  TrajectorySeed tmpseed = TrajectorySeed(pFirstState,newHits,alongMomentum);
1892 
1893  theCollection.push_back(TrackCandidate(goodHits,freshStartTrajectory.seed(),state));
1894 
1895  //trajectory usage
1896  trajUsed[i]=true;
1897  trajUsed[j]=true;
1898 
1899  } //for loop trajectory2
1900 
1901  } //for loop trajectory1
1902 
1903  //add all trajectories to the resulting vector if they have *not* been used by the trajectory merging algorithm
1904  for ( unsigned int i = 0; i < traj.size(); ++i) {
1905 
1906  if (trajUsed[i]==true) continue;
1907 
1908  if (debugCosmics_) std::cout<< "Trajectory (not merged) has "<<traj[i].recHits().size()<<" hits with chi2=" << traj[i].chiSquared() << " and is valid? "<< traj[i].isValid()<<std::endl;
1911  for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator rhit=ttHits.begin(); rhit!=ttHits.end(); ++rhit){
1912  goodHits.push_back((*rhit)->hit()->clone());
1913  }
1914  TrajectoryStateOnSurface firstState;
1915 
1916  // check if Trajectory from seed is on first hit of the cloud, if not, propagate
1917  // exclude if first state on first hit is not valid
1918  DetId FirstHitId = (*(traj[i].recHits().begin()))->geographicalId();
1919 
1920  // propagate back to first hit
1921  TrajectoryMeasurement firstMeasurement = traj[i].measurements()[0];
1922  const GeomDet* det = trackerGeom->idToDet(FirstHitId);
1923  firstState = theAnalyticalPropagator->propagate(firstMeasurement.updatedState(), det->surface());
1924  if (firstState.isValid()) {
1926  theCollection.push_back(TrackCandidate(goodHits,traj[i].seed(),state));
1927  }
1928  }
1929  if (debugCosmics_) std::cout << "Original collection had " << theTrajectories.size()
1930  << " candidates. Merged collection has " << theCollection.size() << std::endl;
1931  } //if(CosmicTrackMerging_)
1932 
1933 
1934  if(!CosmicTrackMerging_) {
1935  for (std::vector<Trajectory>::const_iterator it = theTrajectories.begin(); it != theTrajectories.end(); it++) {
1936  if (debug_) std::cout<< " Trajectory has "<<it->recHits().size()<<" hits with chi2=" << it->chiSquared() << " and is valid? "<<it->isValid()<<std::endl;
1937  if (it->isValid()){
1938 
1941  for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator rhit=ttHits.begin(); rhit!=ttHits.end(); ++rhit){
1942  goodHits.push_back((*rhit)->hit()->clone());
1943  }
1944  TrajectoryStateOnSurface firstState;
1945 
1946  // check if Trajectory from seed is on first hit of the cloud, if not, propagate
1947  // exclude if first state on first hit is not valid
1948  DetId FirstHitId = (*(it->recHits().begin()))->geographicalId();
1949 
1950  // propagate back to first hit
1951  TrajectoryMeasurement firstMeasurement = it->measurements()[0];
1952  const GeomDet* det = trackerGeom->idToDet(FirstHitId);
1953  firstState = theAnalyticalPropagator->propagate(firstMeasurement.updatedState(), det->surface());
1954  if (firstState.isValid() == false) continue;
1956  theCollection.push_back(TrackCandidate(goodHits,it->seed(),state));
1957  }
1958  }
1959  }
1960 
1961  return theCollection;
1962 }
#define LogDebug(id)
PropagationDirection direction() const
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
float xx() const
Definition: LocalError.h:24
FTS stateAtVertex() const
Definition: FastHelix.cc:7
float alpha
Definition: AMPTWrapper.h:95
std::vector< TrajectoryMeasurement > FindBestHit(const TrajectoryStateOnSurface &tsosBefore, const std::set< const GeomDet * > &theDets, edm::OwnVector< TrackingRecHit > &theHits)
bool isValid() const
Definition: FastHelix.h:73
T perp() const
Definition: PV3DBase.h:71
virtual PropagationDirection propagationDirection() const
Definition: Propagator.h:143
virtual void update(const edm::Event &) const =0
TrajectoryStateOnSurface propagate(const FreeTrajectoryState &fts, const Plane &plane) const
propagation to plane
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:265
const GlobalTrajectoryParameters & parameters() const
FreeTrajectoryState initialTrajectory(const edm::EventSetup &es, const TrackingRecHit *InnerHit, const TrackingRecHit *OuterHit)
virtual HitReturnType estimate(const TrajectoryStateOnSurface &ts, const TransientTrackingRecHit &hit) const =0
FreeTrajectoryState initialTrajectoryFromTriplet(const edm::EventSetup &es, const TrackingRecHit *InnerHit, const TrackingRecHit *MiddleHit, const TrackingRecHit *OuterHit)
void run(const RoadSearchCloudCollection *input, const edm::Event &e, const edm::EventSetup &es, TrackCandidateCollection &output)
Runs the algorithm.
TrajectoryStateOnSurface forwardPredictedState() const
Access to forward predicted state (from fitter or builder)
SiStripMatchedRecHit2D * match(const SiStripRecHit2D *monoRH, const SiStripRecHit2D *stereoRH, const GluedGeomDet *gluedDet, LocalVector trackdirection) const
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TransientTrackingRecHit &) const =0
LocalVector localDirection() const
ROOT::Math::SMatrixIdentity AlgebraicMatrixID
std::vector< Trajectory > extrapolateTrajectory(const Trajectory &inputTrajectory, RoadSearchCloud::RecHitVector &theLayerHits, const DetLayer *innerHitLayer, const TrackingRecHit *outerHit, const DetLayer *outerHitLayer)
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:47
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
std::vector< TrackCandidate > TrackCandidateCollection
ROOT::Math::SMatrix< double, 6, 6, ROOT::Math::MatRepSym< double, 6 > > AlgebraicSymMatrix66
size_type size() const
Definition: OwnVector.h:247
Geom::Phi< T > phi() const
Definition: PV3DBase.h:68
virtual void clean(TrajectoryPointerContainer &) const
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
T y() const
Definition: PV3DBase.h:62
#define abs(x)
Definition: mlp_lapack.h:159
GlobalPoint globalPosition() const
ConstRecHitPointer recHit() const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
std::vector< TrajectoryMeasurement > FindBestHitsByDet(const TrajectoryStateOnSurface &tsosBefore, const std::set< const GeomDet * > &theDets, edm::OwnVector< TrackingRecHit > &theHits)
double charge(const std::vector< uint8_t > &Ampls)
LocalError positionError() const
ConstRecHitContainer recHits(bool splitting=false) const
Definition: Trajectory.cc:67
iterator begin()
Definition: OwnVector.h:227
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
U second(std::pair< T, U > const &p)
virtual std::vector< Trajectory > trajectories(const Trajectory &aTraj) const
DataContainer const & measurements() const
Definition: Trajectory.h:203
int TrackCharge
Definition: TrackCharge.h:4
void push_back(D *&d)
Definition: OwnVector.h:273
std::vector< TrajectoryMeasurement > DataContainer
Definition: Trajectory.h:42
T mag() const
Definition: PV3DBase.h:66
float yy() const
Definition: LocalError.h:26
bool isnan(float x)
Definition: math.h:13
T sqrt(T t)
Definition: SSEVec.h:46
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:181
T z() const
Definition: PV3DBase.h:63
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
int j
Definition: DBlmapReader.cc:9
const DetLayer * detLayer(const DetId &id) const
obsolete method. Use idToLayer() instead.
Trajectory createSeedTrajectory(FreeTrajectoryState &fts, const TrackingRecHit *InnerHit, const DetLayer *innerHitLayer)
double n1() const
Definition: FastLine.h:28
TrajectoryStateOnSurface updatedState() const
const LocalTrajectoryError & localError() const
double p2[4]
Definition: TauolaWrapper.h:90
virtual const GeomDet * idToDet(DetId) const
tuple conf
Definition: dbtoconf.py:185
int k[5][pyjets_maxn]
virtual TrajectoryStateOnSurface propagate(const TrajectoryStateOnSurface &tsos, const Plane &plane) const
std::vector< ConstRecHitPointer > ConstRecHitContainer
Definition: DetId.h:20
std::pair< bool, double > HitReturnType
iterator end()
Definition: OwnVector.h:232
bool isValid() const
Definition: Trajectory.h:259
#define M_PI
Definition: BFit3D.cc:3
virtual LocalError localPositionError() const =0
const T & get() const
Definition: EventSetup.h:55
double c() const
Definition: FastLine.h:32
T const * product() const
Definition: ESHandle.h:62
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
char state
Definition: procUtils.cc:75
void linearFit(T const *__restrict__ x, T const *__restrict__ y, int ndat, T const *__restrict__ sigy2, T &slope, T &intercept, T &covss, T &covii, T &covsi)
Definition: LinearFit.h:26
double p1[4]
Definition: TauolaWrapper.h:89
std::vector< TrajectoryMeasurement > FindBestHits(const TrajectoryStateOnSurface &tsosBefore, const std::set< const GeomDet * > &theDets, const SiStripRecHitMatcher *theHitMatcher, edm::OwnVector< TrackingRecHit > &theHits)
GlobalVector globalMomentum() const
const BoundPlane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
double n2() const
Definition: FastLine.h:30
const Surface & surface() const
tuple cout
Definition: gather_cfg.py:121
std::vector< const TrackingRecHit * > RecHitVector
bool chooseStartingLayers(std::vector< std::pair< const DetLayer *, RoadSearchCloud::RecHitVector > > &RecHitsByLayer, std::vector< std::pair< const DetLayer *, RoadSearchCloud::RecHitVector > >::iterator ilyr0, const std::multimap< int, const DetLayer * > &layer_map, std::set< const DetLayer * > &good_layers, std::vector< const DetLayer * > &middle_layers, RoadSearchCloud::RecHitVector &recHits_middle)
DetId geographicalId() const
const GeometricSearchTracker * geometricSearchTracker() const
T x() const
Definition: PV3DBase.h:61
virtual LocalPoint localPosition() const =0
const PositionType & position() const
TrackCandidateCollection PrepareTrackCandidates(std::vector< Trajectory > &theTrajectories)
void push(const TrajectoryMeasurement &tm)
Definition: Trajectory.cc:35
std::vector< RoadSearchCloud > RoadSearchCloudCollection
TrajectoryStateOnSurface backwardPredictedState() const
Access to backward predicted state (from smoother)