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