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 //
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=0;
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.size()==0 ) {
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 ) const {
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  //std::cout << "InOutConversionSeedFinder::getSecondCaloClusters" << "\n";
374 
375  Geom::Phi<float> theConvPhi(conversionPosition.phi() );
376 
377  for (unsigned i = 0; i < bcCollection_->size(); ++i ) {
378 
379  Geom::Phi<float> theBcPhi( bcCollection_->ptrAt(i)->position().phi() );
380  //std::cout<< "InOutConversionSeedFinder::getSecondCaloClusters BC energy " << bcCollection_->ptrAt(i)->energy() << " Calo cluster phi " << theBcPhi << " " << bcCollection_->ptrAt(i)->position().phi()<< " theConvPhi " << theConvPhi << "\n";
381 
382  // Require phi of cluster to be consistent with the conversion
383  // position and the track charge
384 
385 
386  if (fabs(theBcPhi-theConvPhi ) < .5 &&
387  ((charge<0 && theBcPhi-theConvPhi >-.5) ||
388  (charge>0 && theBcPhi-theConvPhi <.5))){
390 
391  //result.push_back(&(*bcItr));
392 
393  result.push_back(&(*(bcCollection_->ptrAt(i)) ));
394 
395  }
396 
397 
398 
399 
400  }
401 
402 
403 
404  return result;
405 
406 
407 }
408 
409 
410 
412  float transverseCurvature,
413  unsigned int startingLayer) const {
414 
415 
416  std::vector<const DetLayer*> allLayers=layerList();
417  //std::cout << "InOutConversionSeedFinder::findSeeds starting forward propagation from startingLayer " << startingLayer << "\n";
418 
419 
420  // create error matrix
422  m(0,0) = 0.1; m(1,1) = 0.0001 ; m(2,2) = 0.0001 ;
423  m(3,3) = 0.0001 ; m(4,4) = 0.001;
424 
425  // Make an FTS consistent with the start point, start direction and curvature
427  startingState.globalDirection(),
428  double(transverseCurvature), 0, &(*theMF_) ),
430  if (fts.momentum().mag2() == 0){
431  edm::LogWarning("FailedToInitiateSeeding")<< " initial FTS has a zero momentum, probably because of the zero field. ";
432  return;
433  }
434  //std::cout << " InOutConversionSeedFinder::findSeeds startingState R "<< startingState.globalPosition().perp() << " Z " << startingState.globalPosition().z() << " phi " << startingState.globalPosition().phi() << " position " << startingState.globalPosition() << "\n";
435  //std::cout << " InOutConversionSeedFinder::findSeeds Initial FTS charge " << fts.charge() << " curvature " << transverseCurvature << "\n";
436  //std::cout << " InOutConversionSeedFinder::findSeeds Initial FTS parameters " << fts << "\n";
437 
438 
439  //float dphi = 0.01;
440  float dphi = 0.03;
441  float zrange = 5.;
442  for( unsigned int ilayer = startingLayer; ilayer <= startingLayer+1 && (ilayer < allLayers.size()-2); ++ilayer) {
443  const DetLayer * layer = allLayers[ilayer];
444 
445 
446 
448  // if ( layer->location() == GeomDetEnumerators::barrel ) {const BarrelDetLayer * barrelLayer = dynamic_cast<const BarrelDetLayer*>(layer);
449  // //std::cout << "InOutConversionSeedFinder::findSeeds **** Barrel on layer " << ilayer << " R= " << barrelLayer->specificSurface().radius() << "\n";
450  // } else {
451  // const ForwardDetLayer * forwardLayer = dynamic_cast<const ForwardDetLayer*>(layer);
453  // }
454  // // end debug
455 
456 
457 
458  MeasurementEstimator * newEstimator=0;
459  if (layer->location() == GeomDetEnumerators::barrel ) {
460  //std::cout << "InOutConversionSeedFinder::findSeeds Barrel ilayer " << ilayer << "\n";
461  newEstimator = new ConversionBarrelEstimator(-dphi, dphi, -zrange, zrange);
462  }
463  else {
464  //std::cout << "InOutConversionSeedFinder::findSeeds Forward ilayer " << ilayer << "\n";
465  newEstimator = new ConversionForwardEstimator(-dphi, dphi, 15.);
466  }
467 
468 
469  theFirstMeasurements_.clear();
470  // Get measurements compatible with the FTS and Estimator
471  TSOS tsos(fts, layer->surface() );
472 
473  //std::cout << "InOutConversionSeedFinder::findSeed propagationDirection " << int(thePropagatorAlongMomentum_->propagationDirection() ) << "\n";
475  LayerMeasurements theLayerMeasurements_( *this->getMeasurementTracker(), *theTrackerData_ );
476 
477  theFirstMeasurements_ = theLayerMeasurements_.measurements( *layer, tsos, *thePropagatorAlongMomentum_, *newEstimator);
478 
479  delete newEstimator;
480  //std::cout << "InOutConversionSeedFinder::findSeeds Found " << theFirstMeasurements_.size() << " first hits" << "\n";
481 
482  if ( theFirstMeasurements_.size() == 1 ) { // only dummy hit found: start finding the seed from the innermost hit of the OutIn track
483 
484 
486  GlobalVector dir = startingState.globalDirection();
487  GlobalPoint back1mm = myPointer->recHit()->globalPosition();
488 
489  back1mm -= dir.unit()*0.1;
490  //std::cout << " InOutConversionSeedFinder:::findSeeds going to make the helix using back1mm " << back1mm << "\n";
491  ConversionFastHelix helix(bcPos, myPointer->recHit()->globalPosition(), back1mm, &(*theMF_));
492 
493  helix.stateAtVertex();
494  //std::cout << " InOutConversionSeedFinder:::findSeeds helix status " <<helix.isValid() << std::endl;
495  if ( !helix.isValid() ) continue;
496 
497  track2InitialMomentum_= helix.stateAtVertex().momentum();
498 
499  // Make a new FTS
501  myPointer->recHit()->globalPosition(), startingState.globalDirection(),
502  helix.stateAtVertex().transverseCurvature(), 0, &(*theMF_)),
504 
505 
508 
509 
510  } else {
511 
512 
513 
514  //Loop over compatible hits
515  int mea=0;
516  for(std::vector<TrajectoryMeasurement>::iterator tmItr = theFirstMeasurements_.begin(); tmItr !=theFirstMeasurements_.end(); ++tmItr) {
517 
518  mea++;
519 
520 
521  if (tmItr->recHit()->isValid() ) {
522  // Make a new helix as in fillClusterSeeds() but using the hit position
523  //std::cout << "InOutConversionSeedFinder::findSeeds hit R " << tmItr->recHit()->globalPosition().perp() << " Z " << tmItr->recHit()->globalPosition().z() << " " << tmItr->recHit()->globalPosition() << "\n";
525  GlobalVector dir = startingState.globalDirection();
526  GlobalPoint back1mm = tmItr->recHit()->globalPosition();
527 
528  back1mm -= dir.unit()*0.1;
529  //std::cout << " InOutConversionSeedFinder:::findSeeds going to make the helix using back1mm " << back1mm << "\n";
530  ConversionFastHelix helix(bcPos, tmItr->recHit()->globalPosition(), back1mm, &(*theMF_));
531 
532  helix.stateAtVertex();
533  //std::cout << " InOutConversionSeedFinder:::findSeeds helix status " <<helix.isValid() << std::endl;
534  if ( !helix.isValid() ) continue;
535 
536  track2InitialMomentum_= helix.stateAtVertex().momentum();
537 
538  //std::cout << "InOutConversionSeedFinder::findSeeds Updated estimatedPt = " << helix.stateAtVertex().momentum().perp() << " curvature " << helix.stateAtVertex().transverseCurvature() << "\n";
539  // << ", bcet = " << theBc->Et()
540  // << ", estimatedPt/bcet = " << estimatedPt/theBc->Et() << endl;
541 
542 
543  // Make a new FTS
545  tmItr->recHit()->globalPosition(), startingState.globalDirection(),
546  helix.stateAtVertex().transverseCurvature(), 0, &(*theMF_)),
548 
549  //std::cout << "InOutConversionSeedFinder::findSeeds new FTS charge " << newfts.charge() << "\n";
550 
551 
552  /*
553  // Soome diagnostic output
554  // may be useful - comparission of the basic cluster position
555  // with the ecal impact position of the track
556  TrajectoryStateOnSurface stateAtECAL
557  = forwardPropagator.propagate(newfts, ECALSurfaces::barrel());
558  if (!stateAtECAL.isValid() || abs(stateAtECAL.globalPosition().eta())>1.479) {
559  if (startingState.globalDirection().eta() > 0.) {
560  stateAtECAL = forwardPropagator.propagate(newfts,
561  ECALSurfaces::positiveEtaEndcap());
562  } else {
563  stateAtECAL = forwardPropagator.propagate(newfts,
564  ECALSurfaces::negativeEtaEndcap());
565  }
566  }
567  GlobalPoint ecalImpactPosition = stateAtECAL.isValid() ? stateAtECAL.globalPosition() : GlobalPoint(0.,0.,0.);
568  cout << "Projected fts positon at ECAL surface: " <<
569  ecalImpactPosition << " bc position: " << theBc->Position() << endl;
570  */
571 
572 
573  completeSeed(*tmItr, newfts, thePropagatorAlongMomentum_, ilayer+1);
574  completeSeed(*tmItr, newfts, thePropagatorAlongMomentum_, ilayer+2);
575 
576 
577  }
578 
579  }
580 
581  }
582 
583 
584  }
585 
586 
587 
588 }
589 
590 
591 
592 
593 
595  FreeTrajectoryState & fts, const Propagator* propagator, int ilayer) const {
596 
597  //std::cout<< "InOutConversionSeedFinder::completeSeed ilayer " << ilayer << "\n";
598  // A seed is made from 2 Trajectory Measuremennts. The 1st is the input
599  // argument m1. This routine looks for the 2nd measurement in layer ilayer
600  // Begin by making a new much stricter MeasurementEstimator based on the
601  // position errors of the 1st hit.
602  printLayer(ilayer);
603 
604  MeasurementEstimator * newEstimator;
605  std::vector<const DetLayer*> allLayers=layerList();
606  const DetLayer * layer = allLayers[ilayer];
607 
609  // if ( layer->location() == GeomDetEnumerators::barrel ) {const BarrelDetLayer * barrelLayer = dynamic_cast<const BarrelDetLayer*>(layer);
610  // //std::cout << "InOutConversionSeedFinder::completeSeed **** Barrel on layer " << ilayer << " R= " << barrelLayer->specificSurface().radius() << "\n";
611  // } else {
612  // const ForwardDetLayer * forwardLayer = dynamic_cast<const ForwardDetLayer*>(layer);
613  // //std::cout << "InOutConversionSeedFinder::completeSeed **** Forw on layer " << ilayer << " Z= " << forwardLayer->specificSurface().position().z() << "\n";
616 
617 
618 
619 
620  if (layer->location() == GeomDetEnumerators::barrel ) {
621 
622  float dz = sqrt(the2ndHitdznSigma_*the2ndHitdznSigma_*m1.recHit()->globalPositionError().czz()
624  newEstimator = new ConversionBarrelEstimator(-the2ndHitdphi_, the2ndHitdphi_, -dz, dz);
625 
626  }
627  else {
628  float m1dr = sqrt(m1.recHit()->localPositionError().yy());
629  float dr = sqrt(the2ndHitdznSigma_*the2ndHitdznSigma_*m1dr*m1dr
631 
632  newEstimator = new ConversionForwardEstimator(-the2ndHitdphi_, the2ndHitdphi_, dr);
633  }
634 
635 
636  //std::cout << "InOutConversionSeedFinder::completeSeed fts For the TSOS " << fts << "\n";
637 
638  TSOS tsos(fts, layer->surface() );
639 
640  if ( !tsos.isValid() ) {
641  //std::cout << "InOutConversionSeedFinder::completeSeed TSOS is not valid " << "\n";
642  }
643 
644  //std::cout << "InOutConversionSeedFinder::completeSeed TSOS " << tsos << "\n";
645  //std::cout << "InOutConversionSeedFinder::completeSeed propagationDirection " << int(propagator->propagationDirection() ) << "\n";
646  //std::cout << "InOutConversionSeedFinder::completeSeed pointer to estimator " << newEstimator << "\n";
647 
648  LayerMeasurements theLayerMeasurements_( *this->getMeasurementTracker(), *theTrackerData_ );
649  std::vector<TrajectoryMeasurement> measurements = theLayerMeasurements_.measurements( *layer, tsos, *propagator, *newEstimator);
650  //std::cout << "InOutConversionSeedFinder::completeSeed Found " << measurements.size() << " second hits " << "\n";
651  delete newEstimator;
652 
653  for(unsigned int i = 0; i < measurements.size(); ++i) {
654  if( measurements[i].recHit()->isValid() ) {
655  createSeed(m1, measurements[i]);
656  }
657  }
658 
659 
660 
661 
662 
663 
664 }
665 
666 
667 
669 
670  //std::cout << "InOutConversionSeedFinder::createSeed " << "\n";
671 
672  if ( m1.predictedState().isValid() ) {
673  GlobalTrajectoryParameters newgtp( m1.recHit()->globalPosition(), track2InitialMomentum_, track2Charge_, &(*theMF_) );
675  FreeTrajectoryState fts(newgtp, errors);
676 
677  TrajectoryStateOnSurface state1 = thePropagatorAlongMomentum_->propagate(fts, m1.recHit()->det()->surface());
678 
679  /*
680  //std::cout << "hit surface " << m1.recHit()->det()->surface().position() << "\n";
681  //std::cout << "prop to " << typeid( m1.recHit()->det()->surface() ).name() <<"\n";
682  //std::cout << "prop to first hit " << state1 << "\n";
683  //std::cout << "update to " << m1.recHit()->globalPosition() << "\n";
684  */
685 
686 
687 
688 
689  if ( state1.isValid() ) {
690 
691  TrajectoryStateOnSurface updatedState1 = theUpdator_.update(state1, *m1.recHit() );
692 
693  if ( updatedState1.isValid() ) {
694 
695  TrajectoryStateOnSurface state2 = thePropagatorAlongMomentum_->propagate(*updatedState1.freeTrajectoryState(), m2.recHit()->det()->surface());
696 
697  if ( state2.isValid() ) {
698 
699  TrajectoryStateOnSurface updatedState2 = theUpdator_.update(state2, *m2.recHit() );
700  TrajectoryMeasurement meas1(state1, updatedState1, m1.recHit() , m1.estimate(), m1.layer());
701  TrajectoryMeasurement meas2(state2, updatedState2, m2.recHit() , m2.estimate(), m2.layer());
702 
704  myHits.push_back(meas1.recHit()->hit()->clone());
705  myHits.push_back(meas2.recHit()->hit()->clone());
706 
707  //std::cout << "InOutConversionSeedFinder::createSeed new seed " << "\n";
709 
710 
711 
712  PTrajectoryStateOnDet const & ptsod= trajectoryStateTransform::persistentState(state2, meas2.recHit()->hit()->geographicalId().rawId() );
713  //std::cout << " InOutConversionSeedFinder::createSeed New seed parameters " << state2 << "\n";
714 
715 
716 
717  theSeeds_.push_back(TrajectorySeed( ptsod, myHits, alongMomentum ));
719 
720  //std::cout << "InOutConversionSeedFinder::createSeed New seed hit 1 R " << m1.recHit()->globalPosition().perp() << "\n";
721  //std::cout << "InOutConversionSeedFinder::createSeed New seed hit 2 R " << m2.recHit()->globalPosition().perp() << "\n";
722 
723  }
724  }
725  }
726  }
727 
728 
729 }
const Propagator * thePropagatorAlongMomentum_
T getParameter(std::string const &) const
tuple propagator
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:126
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)
ROOT::Math::SMatrixIdentity AlgebraicMatrixID
const CurvilinearTrajectoryError & curvilinearError() const
assert(m_qm.get())
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
std::vector< TrajectoryMeasurement > theFirstMeasurements_
TrajectorySeedCollection theSeeds_
const Propagator * thePropagatorOppositeToMomentum_
std::vector< Trajectory > inputTracks_
TrajectoryMeasurement * myPointer
tuple result
Definition: mps_fire.py:84
std::vector< const reco::CaloCluster * > getSecondCaloClusters(const GlobalPoint &conversionPosition, float charge) const
void startSeed(const FreeTrajectoryState *fts, const TrajectoryStateOnSurface &stateAtPreviousLayer, int charge, int layer) const
void push_back(D *&d)
Definition: OwnVector.h:290
TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const
Definition: KFUpdator.cc:75
FreeTrajectoryState const * freeTrajectoryState(bool withErrors=true) const
void printLayer(int i) const
T sqrt(T t)
Definition: SSEVec.h:18
const DetLayer * layer() const
const TrackingGeometry * theTrackerGeom_
edm::Handle< edm::View< reco::CaloCluster > > bcCollection_
void completeSeed(const TrajectoryMeasurement &m1, FreeTrajectoryState &fts, const Propagator *propagator, int ilayer) const
virtual const GeomDet * idToDet(DetId) const =0
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:53
InOutConversionSeedFinder(const edm::ParameterSet &config, edm::ConsumesCollector &&iC)
TrajectoryStateOnSurface const & updatedState() const
dbl *** dir
Definition: mlp_gen.cc:35
edm::Handle< MeasurementTrackerEvent > theTrackerData_
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