CMS 3D CMS Logo

InOutConversionSeedFinder.cc
Go to the documentation of this file.
4 
6 
7 // Field
8 //
10 // Geometry
11 //
16 
17 //
18 //
19 //
20 
22  ConversionSeedFinder( conf,iC ), conf_(conf)
23 {
24 
25 
26  // std::cout << " InOutConversionSeedFinder CTOR " << "\n";
27 
28  maxNumberOfInOutSeedsPerInputTrack_ = conf_.getParameter<int>("maxNumOfSeedsInOut");
29  //the2ndHitdphi_ = 0.008;
30  the2ndHitdphi_ = 0.01;
31  the2ndHitdzConst_ = 5.;
32  the2ndHitdznSigma_ = 2.;
33 
34 
35 }
36 
37 
38 
40  //std::cout << " InOutConversionSeedFinder DTOR " << "\n";
41 }
42 
43 
44 
46 
47 
48  //std::cout << " InOutConversionSeedFinder::makeSeeds() " << "\n";
49  theSeeds_.clear();
50  //std::cout << " Check Calo cluster collection size " << allBC->size() << "\n";
51  bcCollection_= allBC;
52 
53 
54  findLayers();
55 
56 
58  //std::cout << "Built vector of seeds of size " << theSeeds_.size() << "\n" ;
59 
60 
61  theOutInTracks_.clear();
62  inputTracks_.clear();
63  theFirstMeasurements_.clear();
64 
65 }
66 
67 
69 
70  std::vector<Trajectory>::const_iterator outInTrackItr;
71 
72  //std::cout << " InOutConversionSeedFinder::fillClusterSeeds outInTracks_.size " << theOutInTracks_.size() << "\n";
73  //Start looking for seeds for both of the 2 best tracks from the inward tracking
74 
76  /*
77  for(outInTrackItr = theOutInTracks_.begin(); outInTrackItr != theOutInTracks_.end(); ++outInTrackItr) {
78 
79 
80  //std::cout << " InOutConversionSeedFinder::fillClusterSeeds out in input track hits " << (*outInTrackItr).foundHits() << "\n";
81  DetId tmpId = DetId( (*outInTrackItr).seed().startingState().detId());
82  const GeomDet* tmpDet = this->getMeasurementTracker()->geomTracker()->idToDet( tmpId );
83  GlobalVector gv = tmpDet->surface().toGlobal( (*outInTrackItr).seed().startingState().parameters().momentum() );
84 
85 
86  //std::cout << " InOutConversionSeedFinder::fillClusterSeed was built from seed position " <<gv << " charge " << (*outInTrackItr).seed().startingState().parameters().charge() << "\n";
87 
88  Trajectory::DataContainer m= outInTrackItr->measurements();
89  int nHit=0;
90  for (Trajectory::DataContainer::iterator itm = m.begin(); itm != m.end(); ++itm) {
91  if ( itm->recHit()->isValid() ) {
92  nHit++;
93  //std::cout << nHit << ") Valid RecHit global position " << itm->recHit()->globalPosition() << " R " << itm->recHit()->globalPosition().perp() << " phi " << itm->recHit()->globalPosition().phi() << " eta " << itm->recHit()->globalPosition().eta() << "\n";
94  }
95 
96  }
97 
98  }
99 
100  */
101 
102 
103  //Start looking for seeds for both of the 2 best tracks from the inward tracking
104  for(outInTrackItr = theOutInTracks_.begin(); outInTrackItr != theOutInTracks_.end(); ++outInTrackItr) {
105  //std::cout << " InOutConversionSeedFinder::fillClusterSeeds out in input track hits " << (*outInTrackItr).foundHits() << "\n";
107 
108  //Find the first valid hit of the track
109  // Measurements are ordered according to the direction in which the trajectories were built
110  std::vector<TrajectoryMeasurement> measurements = (*outInTrackItr).measurements();
111 
112  std::vector<const DetLayer*> allLayers=layerList();
113 
114  //std::cout << " InOutConversionSeedFinder::fill clusterSeed allLayers.size " << allLayers.size() << "\n";
115  for(unsigned int i = 0; i < allLayers.size(); ++i) {
116  //std::cout << " allLayers " << allLayers[i] << "\n";
117  printLayer(i);
118  }
119 
120 
121 
122  std::vector<const DetLayer*> myLayers;
123  myLayers.clear();
124  std::vector<TrajectoryMeasurement>::reverse_iterator measurementItr;
125  std::vector<TrajectoryMeasurement*> myItr;
126  // TrajectoryMeasurement* myPointer=0;
127  myPointer=nullptr;
128  //std::cout << " InOutConversionSeedFinder::fillClusterSeeds measurements.size " << measurements.size() <<"\n";
129 
130  for(measurementItr = measurements.rbegin() ; measurementItr != measurements.rend(); ++measurementItr) {
131 
132 
133  if( (*measurementItr).recHit()->isValid()) {
134 
135  //std::cout << " InOutConversionSeedFinder::fillClusterSeeds measurement on layer " << measurementItr->layer() << " " <<&(*measurementItr) << " position " << measurementItr->recHit()->globalPosition() << " R " << sqrt( measurementItr->recHit()->globalPosition().x()*measurementItr->recHit()->globalPosition().x() + measurementItr->recHit()->globalPosition().y()*measurementItr->recHit()->globalPosition().y() ) << " Z " << measurementItr->recHit()->globalPosition().z() << " phi " << measurementItr->recHit()->globalPosition().phi() << "\n";
136 
137 
138  myLayers.push_back( measurementItr->layer() ) ;
139  myItr.push_back( &(*measurementItr) );
140 
141 
142  }
143  }
144 
145 
146 
147  //std::cout << " InOutConversionSeedFinder::fillClusterSeed myLayers.size " << myLayers.size() << "\n";
148  // for( unsigned int i = 0; i < myLayers.size(); ++i) {
150  // }
151 
152 
153  if ( myItr.empty() ) {
154  //std::cout << "HORRENDOUS ERROR! No meas on track!" << "\n";
155  }
156  unsigned int ilayer;
157  for(ilayer = 0; ilayer < allLayers.size(); ++ilayer) {
158  //std::cout << " allLayers in the search loop " << allLayers[ilayer] << " " << myLayers[0] << "\n";
159  if ( allLayers[ilayer] == myLayers[0]) {
160 
161  myPointer=myItr[0];
162 
163  //std::cout << " allLayers in the search loop allLayers[ilayer] == myLayers[0]) " << allLayers[ilayer] << " " << myLayers[0] << " myPointer " << myPointer << "\n";
164 
165  //std::cout << "Layer " << ilayer << " contains the first valid measurement " << "\n";
166  printLayer(ilayer);
167 
168  if ( (myLayers[0])->location() == GeomDetEnumerators::barrel ) {
169  // const BarrelDetLayer * barrelLayer = dynamic_cast<const BarrelDetLayer*>(myLayers[0]);
170  //std::cout << " InOutConversionSeedFinder::fillClusterSeeds **** firstHit found in Barrel on layer " << ilayer << " R= " << barrelLayer->specificSurface().radius() << "\n";
171  } else {
172  //const ForwardDetLayer * forwardLayer = dynamic_cast<const ForwardDetLayer*>(myLayers[0]);
173  //std::cout << " InOutwardConversionSeedFinder::fillClusterSeeds **** firstHit found in Forw on layer " << ilayer << " Z= " << forwardLayer->specificSurface().position().z() << "\n";
174  }
175 
176 
177  break;
178 
179  } else if ( allLayers[ilayer] == myLayers[1] ) {
180  myPointer=myItr[1];
181 
182  //std::cout << " allLayers in the search loop allLayers[ilayer] == myLayers[1]) " << allLayers[ilayer] << " " << myLayers[1] << " myPointer " << myPointer << "\n";
183 
184  //std::cout << "Layer " << ilayer << " contains the first innermost valid measurement " << "\n";
185  if ( (myLayers[1])->location() == GeomDetEnumerators::barrel ) {
186  // const BarrelDetLayer * barrelLayer = dynamic_cast<const BarrelDetLayer*>(myLayers[1]);
187  //std::cout << " InOutConversionSeedFinder::fillClusterSeeds **** 2ndHit found in Barrel on layer " << ilayer << " R= " << barrelLayer->specificSurface().radius() << "\n";
188  } else {
189  //const ForwardDetLayer * forwardLayer = dynamic_cast<const ForwardDetLayer*>(myLayers[1]);
190  //std::cout << " InOutwardConversionSeedFinder::fillClusterSeeds **** 2ndHitfound on forw layer " << ilayer << " Z= " << forwardLayer->specificSurface().position().z() << "\n";
191  }
192 
193 
194 
195  break;
196 
197  }
198  }
199 
200 
201 
202  if(ilayer == allLayers.size()) {
203  //std::cout << "InOutConversionSeedFinder::fillClusterSeeds ERROR could not find layer on list" << "\n";
204  return;
205  }
206 
207  //PropagatorWithMaterial reversePropagator(oppositeToMomentum, 0.000511, &(*theMF_) );
208  assert(myPointer);
210 
211  //std::cout << " InOutConversionSeedFinder::fillClusterSeeds First FTS charge " << fts->charge() << " Position " << fts->position() << " momentum " << fts->momentum() << " R " << sqrt(fts->position().x()*fts->position().x() + fts->position().y()* fts->position().y() ) << " Z " << fts->position().z() << " phi " << fts->position().phi() << " fts parameters " << fts->parameters() << "\n";
212 
213 
214  while (ilayer > 0) {
215 
216  //std::cout << " InOutConversionSeedFinder::fillClusterSeeds looking for 2nd seed from layer " << ilayer << "\n";
217 
218  // if ( (allLayers[ilayer])->location() == GeomDetEnumerators::barrel ) {const BarrelDetLayer * barrelLayer = dynamic_cast<const BarrelDetLayer*>(allLayers[ilayer]);
219  //std::cout << " InOutConversionSeedFinder::fillClusterSeeds **** Barrel on layer " << ilayer << " R= " << barrelLayer->specificSurface().radius() << "\n";
220  // } else {
221  //const ForwardDetLayer * forwardLayer = dynamic_cast<const ForwardDetLayer*>(allLayers[ilayer]);
222  //std::cout << " InOutConversionSeedFinder::fillClusterSeeds **** Forw on layer " << ilayer << " Z= " << forwardLayer->specificSurface().position().z() << "\n";
223  // }
224 
225 
226  const DetLayer * previousLayer = allLayers[ilayer];
227  TrajectoryStateOnSurface stateAtPreviousLayer;
228  //std::cout << " InOutConversionSeedFinder::fillClusterSeeds previousLayer->surface() position before " <<allLayers[ilayer] << " " << previousLayer->surface().position() << " layer location " << previousLayer->location() << "\n";
229  // Propagate to the previous layer
230  // The present layer is actually included in the loop so that a partner can be searched for
231  // Applying the propagator to the same layer does not do any harm. It simply does nothing
232 
233  // const Propagator& newProp=thePropagatorOppositeToMomentum_;
234  //std::cout << " InOutConversionSeedFinder::fillClusterSeeds reversepropagator direction " << thePropagatorOppositeToMomentum_->propagationDirection() << "\n";
235  if (ilayer-1>0) {
236 
237  if ( allLayers[ilayer] == myLayers[0] ) {
238  //std::cout << " innermost hit R " << myPointer->recHit()->globalPosition().perp() << " Z " << myPointer->recHit()->globalPosition().z() << " phi " <<myPointer->recHit()->globalPosition().phi() << "\n";
239  //std::cout << " surface R " << theTrackerGeom_->idToDet( myPointer->recHit() ->geographicalId())->surface().position().perp() << " Z " << theTrackerGeom_->idToDet( myPointer->recHit() ->geographicalId())->surface().position().z() << " phi " << theTrackerGeom_->idToDet( myPointer->recHit() ->geographicalId())->surface().position().phi() << "\n";
240 
241  stateAtPreviousLayer= thePropagatorOppositeToMomentum_->propagate(*fts, theTrackerGeom_->idToDet( myPointer->recHit() ->geographicalId())->surface() );
242 
243  } else {
244 
245  stateAtPreviousLayer= thePropagatorOppositeToMomentum_->propagate(*fts, previousLayer->surface() );
246  //std::cout << " InOutConversionSeedFinder::fillClusterSeeds previousLayer->surface() position after " << previousLayer->surface().position() << " layer location " << previousLayer->location() << "\n";
247 
248  }
249 
250  } else if ( ilayer-1==0) {
251 
252 
255 
256  //stateAtPreviousLayer= thePropagatorOppositeToMomentum_->propagate(*fts, theTrackerGeom_->idToDet( myPointer->recHit() ->geographicalId())->surface() );
257  stateAtPreviousLayer= thePropagatorOppositeToMomentum_->propagate(*fts, previousLayer->surface() );
258 
259  }
260 
261  if(!stateAtPreviousLayer.isValid()) {
262  //std::cout << "InOutConversionSeedFinder::fillClusterSeeds ERROR:could not propagate back to layer " << ilayer << "\n";
264  } else {
265  //std::cout << "InOutConversionSeedFinder::fillClusterSeeds stateAtPreviousLayer is valid. Propagating back to layer " << ilayer << "\n";
266  //std::cout << "InOutConversionSeedFinder::fillClusterSeeds stateAtPreviousLayer R " << stateAtPreviousLayer.globalPosition().perp() << " Z " << stateAtPreviousLayer.globalPosition().z() << " phi " << stateAtPreviousLayer.globalPosition().phi() << "\n";
267 
268  startSeed(fts, stateAtPreviousLayer, -1, ilayer );
269 
270 
271  }
272 
273  --ilayer;
274 
275  }
276 
277  if ( ilayer == 0) {
278 
279 
280  // if ( (allLayers[ilayer])->location() == GeomDetEnumerators::barrel ) {const BarrelDetLayer * barrelLayer = dynamic_cast<const BarrelDetLayer*>(allLayers[ilayer]);
281  // //std::cout << " InOutConversionSeedFinder::fillClusterSeeds **** Barrel on layer " << ilayer << " R= " << barrelLayer->specificSurface().radius() << "\n";
282  // } else {
283  //const ForwardDetLayer * forwardLayer = dynamic_cast<const ForwardDetLayer*>(allLayers[ilayer]);
284  //std::cout << " InOutConversionSeedFinder::fillClusterSeeds **** Forw on layer " << ilayer << " Z= " << forwardLayer->specificSurface().position().z() << "\n";
285  // }
286  const DetLayer * previousLayer = allLayers[ilayer];
287  TrajectoryStateOnSurface stateAtPreviousLayer;
288  stateAtPreviousLayer= thePropagatorOppositeToMomentum_->propagate(*fts, previousLayer->surface() );
289 
290  if(!stateAtPreviousLayer.isValid()) {
291  //std::cout << "InOutConversionSeedFinder::fillClusterSeeds ERROR:could not propagate back to layer " << ilayer << "\n";
293  } else {
294  //std::cout << "InOutConversionSeedFinder::fillClusterSeeds stateAtPreviousLayer is valid. Propagating back to layer " << ilayer << "\n";
295  //std::cout << "InOutConversionSeedFinder::fillClusterSeeds stateAtPreviousLayer R " << stateAtPreviousLayer.globalPosition().perp() << " Z " << stateAtPreviousLayer.globalPosition().z() << " phi " << stateAtPreviousLayer.globalPosition().phi() << "\n";
296 
297  startSeed(fts, stateAtPreviousLayer, -1, ilayer );
298  }
299 
300 
301  }
302 
303 
304 
305 
306  } // End loop over Out In tracks
307 
308 
309 
310 }
311 
312 
313 
314 void InOutConversionSeedFinder::startSeed( const FreeTrajectoryState * fts, const TrajectoryStateOnSurface & stateAtPreviousLayer, int charge, int ilayer ) {
315 
316  //std::cout << "InOutConversionSeedFinder::startSeed ilayer " << ilayer << "\n";
317  // Get a list of basic clusters that are consistent with a track
318  // starting at the assumed conversion point with opp. charge to the
319  // inward track. Loop over these basic clusters.
320  track2Charge_ = charge*fts->charge();
321  std::vector<const reco::CaloCluster*> bcVec;
322  //std::cout << "InOutConversionSeedFinder::startSeed charge assumed for the in-out track " << track2Charge_ << "\n";
323 
324  // Geom::Phi<float> theConvPhi( stateAtPreviousLayer.globalPosition().phi());
325  //std::cout << "InOutConversionSeedFinder::startSeed stateAtPreviousLayer phi " << stateAtPreviousLayer.globalPosition().phi() << " R " << stateAtPreviousLayer.globalPosition().perp() << " Z " << stateAtPreviousLayer.globalPosition().z() << "\n";
326 
327  bcVec = getSecondCaloClusters(stateAtPreviousLayer.globalPosition(),track2Charge_);
328 
329  std::vector<const reco::CaloCluster*>::iterator bcItr;
330  //std::cout << "InOutConversionSeedFinder::startSeed bcVec.size " << bcVec.size() << "\n";
331 
332  // debug
333  // for(bcItr = bcVec.begin(); bcItr != bcVec.end(); ++bcItr) {
334  // //std::cout << "InOutConversionSeedFinder::startSeed list of bc eta " << (*bcItr)->position().eta() << " phi " << (*bcItr)->position().phi() << " x " << (*bcItr)->position().x() << " y " << (*bcItr)->position().y() << " z " << (*bcItr)->position().z() << "\n";
335  // }
336 
337 
338  for(bcItr = bcVec.begin(); bcItr != bcVec.end(); ++bcItr) {
339 
340  theSecondBC_ = **bcItr;
341  GlobalPoint bcPos((theSecondBC_.position()).x(),
342  (theSecondBC_.position()).y(),
343  (theSecondBC_.position()).z());
344 
345  //std::cout << "InOutConversionSeedFinder::startSeed for bc position x " << bcPos.x() << " y " << bcPos.y() << " z " << bcPos.z() << " eta " << bcPos.eta() << " phi " << bcPos.phi() << "\n";
346  GlobalVector dir = stateAtPreviousLayer.globalDirection();
347  GlobalPoint back1mm = stateAtPreviousLayer.globalPosition();
348  //std::cout << "InOutConversionSeedFinder::startSeed stateAtPreviousLayer.globalPosition() " << back1mm << "\n";
349 
350  back1mm -= dir.unit()*0.1;
351  //std::cout << " InOutConversionSeedFinder:::startSeed going to make the helix using back1mm " << back1mm <<"\n";
352  ConversionFastHelix helix(bcPos, stateAtPreviousLayer.globalPosition(), back1mm, &(*theMF_));
353  helix.stateAtVertex();
354 
355  //std::cout << " InOutConversionSeedFinder:::startSeed helix status " <<helix.isValid() << std::endl;
356  if ( !helix.isValid() ) continue;
357  findSeeds(stateAtPreviousLayer, helix.stateAtVertex().transverseCurvature(), ilayer);
358 
359 
360  }
361 
362 
363 
364 }
365 
366 
367 
368 std::vector<const reco::CaloCluster*> InOutConversionSeedFinder::getSecondCaloClusters(const GlobalPoint & conversionPosition, float charge) const {
369 
370 
371  std::vector<const reco::CaloCluster*> result;
372 
373  Geom::Phi<float> convPhi(conversionPosition.phi() );
374 
375  for(auto const& bc : *bcCollection_)
376  {
377  Geom::Phi<float> bcPhi( bc.position().phi() );
378 
379  // Require phi of cluster to be consistent with the conversion position and the track charge
380 
381  if (std::abs(bcPhi-convPhi ) < .5 &&
382  ((charge<0 && bcPhi-convPhi >-.5) ||
383  (charge>0 && bcPhi-convPhi <.5))) result.push_back(&bc);
384  }
385 
386  return result;
387 }
388 
389 
390 
392  float transverseCurvature,
393  unsigned int startingLayer) {
394 
395 
396  std::vector<const DetLayer*> allLayers=layerList();
397  //std::cout << "InOutConversionSeedFinder::findSeeds starting forward propagation from startingLayer " << startingLayer << "\n";
398 
399 
400  // create error matrix
402  m(0,0) = 0.1; m(1,1) = 0.0001 ; m(2,2) = 0.0001 ;
403  m(3,3) = 0.0001 ; m(4,4) = 0.001;
404 
405  // Make an FTS consistent with the start point, start direction and curvature
407  startingState.globalDirection(),
408  double(transverseCurvature), 0, &(*theMF_) ),
410  if (fts.momentum().mag2() == 0){
411  edm::LogWarning("FailedToInitiateSeeding")<< " initial FTS has a zero momentum, probably because of the zero field. ";
412  return;
413  }
414  //std::cout << " InOutConversionSeedFinder::findSeeds startingState R "<< startingState.globalPosition().perp() << " Z " << startingState.globalPosition().z() << " phi " << startingState.globalPosition().phi() << " position " << startingState.globalPosition() << "\n";
415  //std::cout << " InOutConversionSeedFinder::findSeeds Initial FTS charge " << fts.charge() << " curvature " << transverseCurvature << "\n";
416  //std::cout << " InOutConversionSeedFinder::findSeeds Initial FTS parameters " << fts << "\n";
417 
418 
419  //float dphi = 0.01;
420  float dphi = 0.03;
421  float zrange = 5.;
422  for( unsigned int ilayer = startingLayer; ilayer <= startingLayer+1 && (ilayer < allLayers.size()-2); ++ilayer) {
423  const DetLayer * layer = allLayers[ilayer];
424 
425 
426 
428  // if ( layer->location() == GeomDetEnumerators::barrel ) {const BarrelDetLayer * barrelLayer = dynamic_cast<const BarrelDetLayer*>(layer);
429  // //std::cout << "InOutConversionSeedFinder::findSeeds **** Barrel on layer " << ilayer << " R= " << barrelLayer->specificSurface().radius() << "\n";
430  // } else {
431  // const ForwardDetLayer * forwardLayer = dynamic_cast<const ForwardDetLayer*>(layer);
433  // }
434  // // end debug
435 
436 
437 
438  MeasurementEstimator * newEstimator=nullptr;
439  if (layer->location() == GeomDetEnumerators::barrel ) {
440  //std::cout << "InOutConversionSeedFinder::findSeeds Barrel ilayer " << ilayer << "\n";
441  newEstimator = new ConversionBarrelEstimator(-dphi, dphi, -zrange, zrange);
442  }
443  else {
444  //std::cout << "InOutConversionSeedFinder::findSeeds Forward ilayer " << ilayer << "\n";
445  newEstimator = new ConversionForwardEstimator(-dphi, dphi, 15.);
446  }
447 
448 
449  theFirstMeasurements_.clear();
450  // Get measurements compatible with the FTS and Estimator
451  TSOS tsos(fts, layer->surface() );
452 
453  //std::cout << "InOutConversionSeedFinder::findSeed propagationDirection " << int(thePropagatorAlongMomentum_->propagationDirection() ) << "\n";
455  LayerMeasurements theLayerMeasurements_( *this->getMeasurementTracker(), *theTrackerData_ );
456 
457  theFirstMeasurements_ = theLayerMeasurements_.measurements( *layer, tsos, *thePropagatorAlongMomentum_, *newEstimator);
458 
459  delete newEstimator;
460  //std::cout << "InOutConversionSeedFinder::findSeeds Found " << theFirstMeasurements_.size() << " first hits" << "\n";
461 
462  if ( theFirstMeasurements_.size() == 1 ) { // only dummy hit found: start finding the seed from the innermost hit of the OutIn track
463 
464 
466  GlobalVector dir = startingState.globalDirection();
467  GlobalPoint back1mm = myPointer->recHit()->globalPosition();
468 
469  back1mm -= dir.unit()*0.1;
470  //std::cout << " InOutConversionSeedFinder:::findSeeds going to make the helix using back1mm " << back1mm << "\n";
471  ConversionFastHelix helix(bcPos, myPointer->recHit()->globalPosition(), back1mm, &(*theMF_));
472 
473  helix.stateAtVertex();
474  //std::cout << " InOutConversionSeedFinder:::findSeeds helix status " <<helix.isValid() << std::endl;
475  if ( !helix.isValid() ) continue;
476 
477  track2InitialMomentum_= helix.stateAtVertex().momentum();
478 
479  // Make a new FTS
481  myPointer->recHit()->globalPosition(), startingState.globalDirection(),
482  helix.stateAtVertex().transverseCurvature(), 0, &(*theMF_)),
484 
485 
488 
489 
490  } else {
491 
492 
493 
494  //Loop over compatible hits
495  int mea=0;
496  for(std::vector<TrajectoryMeasurement>::iterator tmItr = theFirstMeasurements_.begin(); tmItr !=theFirstMeasurements_.end(); ++tmItr) {
497 
498  mea++;
499 
500 
501  if (tmItr->recHit()->isValid() ) {
502  // Make a new helix as in fillClusterSeeds() but using the hit position
503  //std::cout << "InOutConversionSeedFinder::findSeeds hit R " << tmItr->recHit()->globalPosition().perp() << " Z " << tmItr->recHit()->globalPosition().z() << " " << tmItr->recHit()->globalPosition() << "\n";
505  GlobalVector dir = startingState.globalDirection();
506  GlobalPoint back1mm = tmItr->recHit()->globalPosition();
507 
508  back1mm -= dir.unit()*0.1;
509  //std::cout << " InOutConversionSeedFinder:::findSeeds going to make the helix using back1mm " << back1mm << "\n";
510  ConversionFastHelix helix(bcPos, tmItr->recHit()->globalPosition(), back1mm, &(*theMF_));
511 
512  helix.stateAtVertex();
513  //std::cout << " InOutConversionSeedFinder:::findSeeds helix status " <<helix.isValid() << std::endl;
514  if ( !helix.isValid() ) continue;
515 
516  track2InitialMomentum_= helix.stateAtVertex().momentum();
517 
518  //std::cout << "InOutConversionSeedFinder::findSeeds Updated estimatedPt = " << helix.stateAtVertex().momentum().perp() << " curvature " << helix.stateAtVertex().transverseCurvature() << "\n";
519  // << ", bcet = " << theBc->Et()
520  // << ", estimatedPt/bcet = " << estimatedPt/theBc->Et() << endl;
521 
522 
523  // Make a new FTS
525  tmItr->recHit()->globalPosition(), startingState.globalDirection(),
526  helix.stateAtVertex().transverseCurvature(), 0, &(*theMF_)),
528 
529  //std::cout << "InOutConversionSeedFinder::findSeeds new FTS charge " << newfts.charge() << "\n";
530 
531 
532  /*
533  // Soome diagnostic output
534  // may be useful - comparission of the basic cluster position
535  // with the ecal impact position of the track
536  TrajectoryStateOnSurface stateAtECAL
537  = forwardPropagator.propagate(newfts, ECALSurfaces::barrel());
538  if (!stateAtECAL.isValid() || abs(stateAtECAL.globalPosition().eta())>1.479) {
539  if (startingState.globalDirection().eta() > 0.) {
540  stateAtECAL = forwardPropagator.propagate(newfts,
541  ECALSurfaces::positiveEtaEndcap());
542  } else {
543  stateAtECAL = forwardPropagator.propagate(newfts,
544  ECALSurfaces::negativeEtaEndcap());
545  }
546  }
547  GlobalPoint ecalImpactPosition = stateAtECAL.isValid() ? stateAtECAL.globalPosition() : GlobalPoint(0.,0.,0.);
548  cout << "Projected fts positon at ECAL surface: " <<
549  ecalImpactPosition << " bc position: " << theBc->Position() << endl;
550  */
551 
552 
553  completeSeed(*tmItr, newfts, thePropagatorAlongMomentum_, ilayer+1);
554  completeSeed(*tmItr, newfts, thePropagatorAlongMomentum_, ilayer+2);
555 
556 
557  }
558 
559  }
560 
561  }
562 
563 
564  }
565 
566 
567 
568 }
569 
570 
571 
572 
573 
575  const FreeTrajectoryState & fts, const Propagator* propagator, int ilayer) {
576 
577  //std::cout<< "InOutConversionSeedFinder::completeSeed ilayer " << ilayer << "\n";
578  // A seed is made from 2 Trajectory Measuremennts. The 1st is the input
579  // argument m1. This routine looks for the 2nd measurement in layer ilayer
580  // Begin by making a new much stricter MeasurementEstimator based on the
581  // position errors of the 1st hit.
582  printLayer(ilayer);
583 
584  MeasurementEstimator * newEstimator;
585  std::vector<const DetLayer*> allLayers=layerList();
586  const DetLayer * layer = allLayers[ilayer];
587 
589  // if ( layer->location() == GeomDetEnumerators::barrel ) {const BarrelDetLayer * barrelLayer = dynamic_cast<const BarrelDetLayer*>(layer);
590  // //std::cout << "InOutConversionSeedFinder::completeSeed **** Barrel on layer " << ilayer << " R= " << barrelLayer->specificSurface().radius() << "\n";
591  // } else {
592  // const ForwardDetLayer * forwardLayer = dynamic_cast<const ForwardDetLayer*>(layer);
593  // //std::cout << "InOutConversionSeedFinder::completeSeed **** Forw on layer " << ilayer << " Z= " << forwardLayer->specificSurface().position().z() << "\n";
596 
597 
598 
599 
600  if (layer->location() == GeomDetEnumerators::barrel ) {
601 
602  float dz = sqrt(the2ndHitdznSigma_*the2ndHitdznSigma_*m1.recHit()->globalPositionError().czz()
604  newEstimator = new ConversionBarrelEstimator(-the2ndHitdphi_, the2ndHitdphi_, -dz, dz);
605 
606  }
607  else {
608  float m1dr = sqrt(m1.recHit()->localPositionError().yy());
609  float dr = sqrt(the2ndHitdznSigma_*the2ndHitdznSigma_*m1dr*m1dr
611 
612  newEstimator = new ConversionForwardEstimator(-the2ndHitdphi_, the2ndHitdphi_, dr);
613  }
614 
615 
616  //std::cout << "InOutConversionSeedFinder::completeSeed fts For the TSOS " << fts << "\n";
617 
618  TSOS tsos(fts, layer->surface() );
619 
620  if ( !tsos.isValid() ) {
621  //std::cout << "InOutConversionSeedFinder::completeSeed TSOS is not valid " << "\n";
622  }
623 
624  //std::cout << "InOutConversionSeedFinder::completeSeed TSOS " << tsos << "\n";
625  //std::cout << "InOutConversionSeedFinder::completeSeed propagationDirection " << int(propagator->propagationDirection() ) << "\n";
626  //std::cout << "InOutConversionSeedFinder::completeSeed pointer to estimator " << newEstimator << "\n";
627 
628  LayerMeasurements theLayerMeasurements_( *this->getMeasurementTracker(), *theTrackerData_ );
629  std::vector<TrajectoryMeasurement> measurements = theLayerMeasurements_.measurements( *layer, tsos, *propagator, *newEstimator);
630  //std::cout << "InOutConversionSeedFinder::completeSeed Found " << measurements.size() << " second hits " << "\n";
631  delete newEstimator;
632 
633  for(unsigned int i = 0; i < measurements.size(); ++i) {
634  if( measurements[i].recHit()->isValid() ) {
635  createSeed(m1, measurements[i]);
636  }
637  }
638 
639 
640 
641 
642 
643 
644 }
645 
646 
647 
649 
650  //std::cout << "InOutConversionSeedFinder::createSeed " << "\n";
651 
652  if ( m1.predictedState().isValid() ) {
653  GlobalTrajectoryParameters newgtp( m1.recHit()->globalPosition(), track2InitialMomentum_, track2Charge_, &(*theMF_) );
655  FreeTrajectoryState fts(newgtp, errors);
656 
657  TrajectoryStateOnSurface state1 = thePropagatorAlongMomentum_->propagate(fts, m1.recHit()->det()->surface());
658 
659  /*
660  //std::cout << "hit surface " << m1.recHit()->det()->surface().position() << "\n";
661  //std::cout << "prop to " << typeid( m1.recHit()->det()->surface() ).name() <<"\n";
662  //std::cout << "prop to first hit " << state1 << "\n";
663  //std::cout << "update to " << m1.recHit()->globalPosition() << "\n";
664  */
665 
666 
667 
668 
669  if ( state1.isValid() ) {
670 
671  TrajectoryStateOnSurface updatedState1 = theUpdator_.update(state1, *m1.recHit() );
672 
673  if ( updatedState1.isValid() ) {
674 
675  TrajectoryStateOnSurface state2 = thePropagatorAlongMomentum_->propagate(*updatedState1.freeTrajectoryState(), m2.recHit()->det()->surface());
676 
677  if ( state2.isValid() ) {
678 
679  TrajectoryStateOnSurface updatedState2 = theUpdator_.update(state2, *m2.recHit() );
680  TrajectoryMeasurement meas1(state1, updatedState1, m1.recHit() , m1.estimate(), m1.layer());
681  TrajectoryMeasurement meas2(state2, updatedState2, m2.recHit() , m2.estimate(), m2.layer());
682 
684  myHits.push_back(meas1.recHit()->hit()->clone());
685  myHits.push_back(meas2.recHit()->hit()->clone());
686 
687  //std::cout << "InOutConversionSeedFinder::createSeed new seed " << "\n";
689 
690 
691 
692  PTrajectoryStateOnDet const & ptsod= trajectoryStateTransform::persistentState(state2, meas2.recHit()->hit()->geographicalId().rawId() );
693  //std::cout << " InOutConversionSeedFinder::createSeed New seed parameters " << state2 << "\n";
694 
695 
696 
697  theSeeds_.push_back(TrajectorySeed( ptsod, myHits, alongMomentum ));
699 
700  //std::cout << "InOutConversionSeedFinder::createSeed New seed hit 1 R " << m1.recHit()->globalPosition().perp() << "\n";
701  //std::cout << "InOutConversionSeedFinder::createSeed New seed hit 2 R " << m2.recHit()->globalPosition().perp() << "\n";
702 
703  }
704  }
705  }
706  }
707 
708 
709 }
const Propagator * thePropagatorAlongMomentum_
T getParameter(std::string const &) const
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:131
std::vector< TrajectoryMeasurement > measurements(const DetLayer &layer, const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
std::vector< const DetLayer * > const & layerList() const
const MeasurementTracker * getMeasurementTracker() const
TrajectoryStateOnSurface const & predictedState() const
ConstRecHitPointer const & recHit() const
ROOT::Math::SMatrixIdentity AlgebraicMatrixID
const CurvilinearTrajectoryError & curvilinearError() const
virtual Location location() const =0
Which part of the detector (barrel, endcap)
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
GlobalPoint globalPosition() const
virtual const GeomDet * idToDet(DetId) const =0
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
void createSeed(const TrajectoryMeasurement &m1, const TrajectoryMeasurement &m2)
TrackCharge charge() const
std::vector< TrajectoryMeasurement > theFirstMeasurements_
TrajectorySeedCollection theSeeds_
const Propagator * thePropagatorOppositeToMomentum_
std::vector< Trajectory > inputTracks_
TrajectoryMeasurement * myPointer
std::vector< const reco::CaloCluster * > getSecondCaloClusters(const GlobalPoint &conversionPosition, float charge) const
void push_back(D *&d)
Definition: OwnVector.h:290
TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const override
Definition: KFUpdator.cc:169
FreeTrajectoryState const * freeTrajectoryState(bool withErrors=true) const
void printLayer(int i) const
T sqrt(T t)
Definition: SSEVec.h:18
void makeSeeds(const edm::Handle< edm::View< reco::CaloCluster > > &allBc) override
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const DetLayer * layer() const
virtual const BoundSurface & surface() const =0
The surface of the GeometricSearchDet.
const TrackingGeometry * theTrackerGeom_
edm::Handle< edm::View< reco::CaloCluster > > bcCollection_
void startSeed(const FreeTrajectoryState *fts, const TrajectoryStateOnSurface &stateAtPreviousLayer, int charge, int layer)
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:53
void completeSeed(const TrajectoryMeasurement &m1, const FreeTrajectoryState &fts, const Propagator *propagator, int ilayer)
InOutConversionSeedFinder(const edm::ParameterSet &config, edm::ConsumesCollector &&iC)
TrajectoryStateOnSurface const & updatedState() const
Definition: errors.py:1
dbl *** dir
Definition: mlp_gen.cc:35
edm::Handle< MeasurementTrackerEvent > theTrackerData_
virtual void findSeeds(const TrajectoryStateOnSurface &startingState, float signedpt, unsigned int startingLayer)
std::vector< Trajectory > theOutInTracks_
GlobalVector globalDirection() const