CMS 3D CMS Logo

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