CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrajectorySeedProducer.cc
Go to the documentation of this file.
1 #include <memory>
2 
7 
15 
18 
20 
23 
26 
30 
33 
36 
37 //Propagator withMaterial
39 //analyticalpropagator
40 //#include "TrackingTools/GeomPropagators/interface/AnalyticalPropagator.h"
41 
42 
43 //
44 
45 //for debug only
46 //#define FAMOS_DEBUG
47 
49 {
50 
51  // The input tag for the beam spot
52  theBeamSpot = conf.getParameter<edm::InputTag>("beamSpot");
53 
54  // The name of the TrajectorySeed Collections
55  seedingAlgo = conf.getParameter<std::vector<std::string> >("seedingAlgo");
56  for ( unsigned i=0; i<seedingAlgo.size(); ++i )
57  produces<TrajectorySeedCollection>(seedingAlgo[i]);
58 
59  // The smallest true pT for a track candidate
60  pTMin = conf.getParameter<std::vector<double> >("pTMin");
61  if ( pTMin.size() != seedingAlgo.size() )
62  throw cms::Exception("FastSimulation/TrajectorySeedProducer ")
63  << " WARNING : pTMin does not have the proper size "
64  << std::endl;
65 
66  for ( unsigned i=0; i<pTMin.size(); ++i )
67  pTMin[i] *= pTMin[i]; // Cut is done of perp2() - CPU saver
68 
69  // The smallest number of Rec Hits for a track candidate
70  minRecHits = conf.getParameter<std::vector<unsigned int> >("minRecHits");
71  if ( minRecHits.size() != seedingAlgo.size() )
72  throw cms::Exception("FastSimulation/TrajectorySeedProducer ")
73  << " WARNING : minRecHits does not have the proper size "
74  << std::endl;
75  // Set the overall number hits to be checked
76  absMinRecHits = 0;
77  for ( unsigned ialgo=0; ialgo<minRecHits.size(); ++ialgo )
78  if ( minRecHits[ialgo] > absMinRecHits ) absMinRecHits = minRecHits[ialgo];
79 
80  // The smallest true impact parameters (d0 and z0) for a track candidate
81  maxD0 = conf.getParameter<std::vector<double> >("maxD0");
82  if ( maxD0.size() != seedingAlgo.size() )
83  throw cms::Exception("FastSimulation/TrajectorySeedProducer ")
84  << " WARNING : maxD0 does not have the proper size "
85  << std::endl;
86 
87  maxZ0 = conf.getParameter<std::vector<double> >("maxZ0");
88  if ( maxZ0.size() != seedingAlgo.size() )
89  throw cms::Exception("FastSimulation/TrajectorySeedProducer ")
90  << " WARNING : maxZ0 does not have the proper size "
91  << std::endl;
92 
93  // The name of the hit producer
94  hitProducer = conf.getParameter<edm::InputTag>("HitProducer");
95 
96  // The cuts for seed cleaning
97  seedCleaning = conf.getParameter<bool>("seedCleaning");
98 
99  // Number of hits needed for a seed
100  numberOfHits = conf.getParameter<std::vector<unsigned int> >("numberOfHits");
101  if ( numberOfHits.size() != seedingAlgo.size() )
102  throw cms::Exception("FastSimulation/TrajectorySeedProducer ")
103  << " WARNING : numberOfHits does not have the proper size "
104  << std::endl;
105 
106  //
108  conf.getParameter<std::vector<unsigned int> >("firstHitSubDetectorNumber");
109  if ( firstHitSubDetectorNumber.size() != seedingAlgo.size() )
110  throw cms::Exception("FastSimulation/TrajectorySeedProducer ")
111  << " WARNING : firstHitSubDetectorNumber does not have the proper size "
112  << std::endl;
113 
114  std::vector<unsigned int> firstSubDets =
115  conf.getParameter<std::vector<unsigned int> >("firstHitSubDetectors");
116  unsigned isub1 = 0;
117  unsigned check1 = 0;
118  firstHitSubDetectors.resize(seedingAlgo.size());
119  for ( unsigned ialgo=0; ialgo<firstHitSubDetectorNumber.size(); ++ialgo ) {
120  check1 += firstHitSubDetectorNumber[ialgo];
121  for ( unsigned idet=0; idet<firstHitSubDetectorNumber[ialgo]; ++idet ) {
122  firstHitSubDetectors[ialgo].push_back(firstSubDets[isub1++]);
123  }
124  }
125  if ( firstSubDets.size() != check1 )
126  throw cms::Exception("FastSimulation/TrajectorySeedProducer ")
127  << " WARNING : firstHitSubDetectors does not have the proper size (should be " << check1 << ")"
128  << std::endl;
129 
130 
132  conf.getParameter<std::vector<unsigned int> >("secondHitSubDetectorNumber");
133  if ( secondHitSubDetectorNumber.size() != seedingAlgo.size() )
134  throw cms::Exception("FastSimulation/TrajectorySeedProducer ")
135  << " WARNING : secondHitSubDetectorNumber does not have the proper size "
136  << std::endl;
137 
138  std::vector<unsigned int> secondSubDets =
139  conf.getParameter<std::vector<unsigned int> >("secondHitSubDetectors");
140  unsigned isub2 = 0;
141  unsigned check2 = 0;
142  secondHitSubDetectors.resize(seedingAlgo.size());
143  for ( unsigned ialgo=0; ialgo<secondHitSubDetectorNumber.size(); ++ialgo ) {
144  check2 += secondHitSubDetectorNumber[ialgo];
145  for ( unsigned idet=0; idet<secondHitSubDetectorNumber[ialgo]; ++idet ) {
146  secondHitSubDetectors[ialgo].push_back(secondSubDets[isub2++]);
147  }
148  }
149  if ( secondSubDets.size() != check2 )
150  throw cms::Exception("FastSimulation/TrajectorySeedProducer ")
151  << " WARNING : secondHitSubDetectors does not have the proper size (should be " << check2 << ")"
152  << std::endl;
153 
155  conf.getParameter<std::vector<unsigned int> >("thirdHitSubDetectorNumber");
156  if ( thirdHitSubDetectorNumber.size() != seedingAlgo.size() )
157  throw cms::Exception("FastSimulation/TrajectorySeedProducer ")
158  << " WARNING : thirdHitSubDetectorNumber does not have the proper size "
159  << std::endl;
160 
161  std::vector<unsigned int> thirdSubDets =
162  conf.getParameter<std::vector<unsigned int> >("thirdHitSubDetectors");
163  unsigned isub3 = 0;
164  unsigned check3 = 0;
165  thirdHitSubDetectors.resize(seedingAlgo.size());
166  for ( unsigned ialgo=0; ialgo<thirdHitSubDetectorNumber.size(); ++ialgo ) {
167  check3 += thirdHitSubDetectorNumber[ialgo];
168  for ( unsigned idet=0; idet<thirdHitSubDetectorNumber[ialgo]; ++idet ) {
169  thirdHitSubDetectors[ialgo].push_back(thirdSubDets[isub3++]);
170  }
171  }
172  if ( thirdSubDets.size() != check3 )
173  throw cms::Exception("FastSimulation/TrajectorySeedProducer ")
174  << " WARNING : thirdHitSubDetectors does not have the proper size (should be " << check3 << ")"
175  << std::endl;
176 
177  originRadius = conf.getParameter<std::vector<double> >("originRadius");
178  if ( originRadius.size() != seedingAlgo.size() )
179  throw cms::Exception("FastSimulation/TrajectorySeedProducer ")
180  << " WARNING : originRadius does not have the proper size "
181  << std::endl;
182 
183  originHalfLength = conf.getParameter<std::vector<double> >("originHalfLength");
184  if ( originHalfLength.size() != seedingAlgo.size() )
185  throw cms::Exception("FastSimulation/TrajectorySeedProducer ")
186  << " WARNING : originHalfLength does not have the proper size "
187  << std::endl;
188 
189  originpTMin = conf.getParameter<std::vector<double> >("originpTMin");
190  if ( originpTMin.size() != seedingAlgo.size() )
191  throw cms::Exception("FastSimulation/TrajectorySeedProducer ")
192  << " WARNING : originpTMin does not have the proper size "
193  << std::endl;
194 
195  primaryVertices = conf.getParameter<std::vector<edm::InputTag> >("primaryVertices");
196  if ( primaryVertices.size() != seedingAlgo.size() )
197  throw cms::Exception("FastSimulation/TrajectorySeedProducer ")
198  << " WARNING : primaryVertices does not have the proper size "
199  << std::endl;
200 
201  zVertexConstraint = conf.getParameter<std::vector<double> >("zVertexConstraint");
202  if ( zVertexConstraint.size() != seedingAlgo.size() )
203  throw cms::Exception("FastSimulation/TrajectorySeedProducer ")
204  << " WARNING : zVertexConstraint does not have the proper size "
205  << std::endl;
206 
207 
208 }
209 
210 
211 // Virtual destructor needed.
213 
214  if(thePropagator) delete thePropagator;
215 
216  // do nothing
217 #ifdef FAMOS_DEBUG
218  std::cout << "TrajectorySeedProducer destructed" << std::endl;
219 #endif
220 
221 }
222 
223 void
225 
226  //services
227  // es.get<TrackerRecoGeometryRecord>().get(theGeomSearchTracker);
228 
232 
233 
234  es.get<IdealMagneticFieldRecord>().get(magField);
235  es.get<TrackerDigiGeometryRecord>().get(geometry);
236  es.get<MagneticFieldMapRecord>().get(magFieldMap);
237 
238  theMagField = &(*magField);
239  theGeometry = &(*geometry);
240  theFieldMap = &(*magFieldMap);
241 
243 
244  const GlobalPoint g(0.,0.,0.);
245 
246 }
247 
248  // Functions that gets called by framework every event
249 void
251 
252 
253  // if( seedingAlgo[0] == "FourthPixelLessPairs") std::cout << "Seed producer in 4th iteration " << std::endl;
254 
255 #ifdef FAMOS_DEBUG
256  std::cout << "################################################################" << std::endl;
257  std::cout << " TrajectorySeedProducer produce init " << std::endl;
258 #endif
259 
260 
261 
262  unsigned nSimTracks = 0;
263  unsigned nTracksWithHits = 0;
264  unsigned nTracksWithPT = 0;
265  unsigned nTracksWithD0Z0 = 0;
266  // unsigned nTrackCandidates = 0;
267  PTrajectoryStateOnDet initialState;
268 
269  // Output
270  std::vector<TrajectorySeedCollection*>
271  output(seedingAlgo.size(),static_cast<TrajectorySeedCollection*>(0));
272  for ( unsigned ialgo=0; ialgo<seedingAlgo.size(); ++ialgo ) {
273  // std::auto_ptr<TrajectorySeedCollection> p(new TrajectorySeedCollection );
274  output[ialgo] = new TrajectorySeedCollection;
275  }
276 
277  // Beam spot
278  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
279  e.getByLabel(theBeamSpot,recoBeamSpotHandle);
280  math::XYZPoint BSPosition_ = recoBeamSpotHandle->position();
281 
282  //not used anymore. take the value from the py
283 
284  //double sigmaZ=recoBeamSpotHandle->sigmaZ();
285  //double sigmaZ0Error=recoBeamSpotHandle->sigmaZ0Error();
286  //double sigmaz0=sqrt(sigmaZ*sigmaZ+sigmaZ0Error*sigmaZ0Error);
287  x0 = BSPosition_.X();
288  y0 = BSPosition_.Y();
289  z0 = BSPosition_.Z();
290 
291  // SimTracks and SimVertices
293  e.getByLabel("famosSimHits",theSimTracks);
294 
296  e.getByLabel("famosSimHits",theSimVtx);
297 
298 #ifdef FAMOS_DEBUG
299  std::cout << " Step A: SimTracks found " << theSimTracks->size() << std::endl;
300 #endif
301 
302  // edm::Handle<SiTrackerGSRecHit2DCollection> theGSRecHits;
304  e.getByLabel(hitProducer, theGSRecHits);
305 
306  // No tracking attempted if no hits (but put an empty collection in the event)!
307 #ifdef FAMOS_DEBUG
308  std::cout << " Step B: Full GS RecHits found " << theGSRecHits->size() << std::endl;
309 #endif
310  if(theGSRecHits->size() == 0) {
311  for ( unsigned ialgo=0; ialgo<seedingAlgo.size(); ++ialgo ) {
312  std::auto_ptr<TrajectorySeedCollection> p(output[ialgo]);
313  e.put(p,seedingAlgo[ialgo]);
314  }
315  return;
316  }
317 
318  // Primary vertices
319  vertices = std::vector<const reco::VertexCollection*>
320  (seedingAlgo.size(),static_cast<const reco::VertexCollection*>(0));
321  for ( unsigned ialgo=0; ialgo<seedingAlgo.size(); ++ialgo ) {
322  //PAT Attempt!!!!
323 
324  //originHalfLength[ialgo] = 3.*sigmaz0; // Overrides the configuration
326  bool isVertexCollection = e.getByLabel(primaryVertices[ialgo],aHandle);
327  if (!isVertexCollection ) continue;
328  vertices[ialgo] = &(*aHandle);
329  }
330 
331 #ifdef FAMOS_DEBUG
332  std::cout << " Step C: Loop over the RecHits, track by track " << std::endl;
333 #endif
334 
335  // The vector of simTrack Id's carrying GSRecHits
336  const std::vector<unsigned> theSimTrackIds = theGSRecHits->ids();
337 
338  // loop over SimTrack Id's
339  for ( unsigned tkId=0; tkId != theSimTrackIds.size(); ++tkId ) {
340 
341 #ifdef FAMOS_DEBUG
342  std::cout << "Track number " << tkId << std::endl;
343 #endif
344 
345  ++nSimTracks;
346  unsigned simTrackId = theSimTrackIds[tkId];
347  const SimTrack& theSimTrack = (*theSimTracks)[simTrackId];
348 #ifdef FAMOS_DEBUG
349  std::cout << "Pt = " << std::sqrt(theSimTrack.momentum().Perp2())
350  << " eta " << theSimTrack.momentum().Eta()
351  << std::endl;
352 #endif
353 
354  // Check that the sim track comes from the main vertex (loose cut)
355  int vertexIndex = theSimTrack.vertIndex();
356  const SimVertex& theSimVertex = (*theSimVtx)[vertexIndex];
357 #ifdef FAMOS_DEBUG
358  std::cout << " o SimTrack " << theSimTrack << std::endl;
359  std::cout << " o SimVertex " << theSimVertex << std::endl;
360 #endif
361 
362  BaseParticlePropagator theParticle =
364  RawParticle(XYZTLorentzVector(theSimTrack.momentum().px(),
365  theSimTrack.momentum().py(),
366  theSimTrack.momentum().pz(),
367  theSimTrack.momentum().e()),
368  XYZTLorentzVector(theSimVertex.position().x(),
369  theSimVertex.position().y(),
370  theSimVertex.position().z(),
371  theSimVertex.position().t())),
372  0.,0.,4.);
373  theParticle.setCharge((*theSimTracks)[simTrackId].charge());
374 
375  SiTrackerGSMatchedRecHit2DCollection::range theRecHitRange = theGSRecHits->get(simTrackId);
376  SiTrackerGSMatchedRecHit2DCollection::const_iterator theRecHitRangeIteratorBegin = theRecHitRange.first;
377  SiTrackerGSMatchedRecHit2DCollection::const_iterator theRecHitRangeIteratorEnd = theRecHitRange.second;
382 
383  // Check the number of layers crossed
384  unsigned numberOfRecHits = 0;
385  TrackerRecHit previousHit, currentHit;
386  for ( iterRecHit = theRecHitRangeIteratorBegin;
387  iterRecHit != theRecHitRangeIteratorEnd;
388  ++iterRecHit) {
389  previousHit = currentHit;
390  currentHit = TrackerRecHit(&(*iterRecHit),theGeometry);
391  if ( currentHit.isOnTheSameLayer(previousHit) ) continue;
392  ++numberOfRecHits;
393  if ( numberOfRecHits == absMinRecHits ) break;
394  }
395 
396  // Loop on the successive seedings
397  for ( unsigned int ialgo = 0; ialgo < seedingAlgo.size(); ++ialgo ) {
398 
399 #ifdef FAMOS_DEBUG
400  std::cout << "Algo " << seedingAlgo[ialgo] << std::endl;
401 #endif
402 
403  // Request a minimum number of RecHits for the track to give a seed.
404 #ifdef FAMOS_DEBUG
405  std::cout << "The number of RecHits = " << numberOfRecHits << std::endl;
406 #endif
407  if ( numberOfRecHits < minRecHits[ialgo] ) continue;
408  ++nTracksWithHits;
409 
410  // Request a minimum pT for the sim track
411  if ( theSimTrack.momentum().Perp2() < pTMin[ialgo] ) continue;
412  ++nTracksWithPT;
413 
414  // Cut on sim track impact parameters
415  if ( theParticle.xyImpactParameter(x0,y0) > maxD0[ialgo] ) continue;
416  if ( fabs( theParticle.zImpactParameter(x0,y0) - z0 ) > maxZ0[ialgo] ) continue;
417  ++nTracksWithD0Z0;
418 
419  std::vector<TrackerRecHit >
420  theSeedHits(numberOfHits[ialgo],
421  static_cast<TrackerRecHit >(TrackerRecHit()));
422  TrackerRecHit& theSeedHits0 = theSeedHits[0];
423  TrackerRecHit& theSeedHits1 = theSeedHits[1];
424  TrackerRecHit& theSeedHits2 = theSeedHits[2];
425  bool compatible = false;
426  for ( iterRecHit1 = theRecHitRangeIteratorBegin; iterRecHit1 != theRecHitRangeIteratorEnd; ++iterRecHit1) {
427  theSeedHits[0] = TrackerRecHit(&(*iterRecHit1),theGeometry);
428 #ifdef FAMOS_DEBUG
429  std::cout << "The first hit position = " << theSeedHits0.globalPosition() << std::endl;
430  std::cout << "The first hit subDetId = " << theSeedHits0.subDetId() << std::endl;
431  std::cout << "The first hit layer = " << theSeedHits0.layerNumber() << std::endl;
432 #endif
433 
434  // Check if inside the requested detectors
435  bool isInside = theSeedHits0.subDetId() < firstHitSubDetectors[ialgo][0];
436  if ( isInside ) continue;
437 
438  // Check if on requested detectors
439  // bool isOndet = theSeedHits0.isOnRequestedDet(firstHitSubDetectors[ialgo]);
440  bool isOndet = theSeedHits0.isOnRequestedDet(firstHitSubDetectors[ialgo], seedingAlgo[ialgo]);
441  // if ( !isOndet ) break;
442  if ( !isOndet ) continue;
443 
444 #ifdef FAMOS_DEBUG
445  std::cout << "Apparently the first hit is on the requested detector! " << std::endl;
446 #endif
447  for ( iterRecHit2 = iterRecHit1+1; iterRecHit2 != theRecHitRangeIteratorEnd; ++iterRecHit2) {
448  theSeedHits[1] = TrackerRecHit(&(*iterRecHit2),theGeometry);
449 #ifdef FAMOS_DEBUG
450  std::cout << "The second hit position = " << theSeedHits1.globalPosition() << std::endl;
451  std::cout << "The second hit subDetId = " << theSeedHits1.subDetId() << std::endl;
452  std::cout << "The second hit layer = " << theSeedHits1.layerNumber() << std::endl;
453 #endif
454 
455  // Check if inside the requested detectors
456  isInside = theSeedHits1.subDetId() < secondHitSubDetectors[ialgo][0];
457  if ( isInside ) continue;
458 
459  // Check if on requested detectors
460  isOndet = theSeedHits1.isOnRequestedDet(secondHitSubDetectors[ialgo], seedingAlgo[ialgo]);
461  if ( !isOndet ) break;
462 
463  // Check if on the same layer as previous hit
464  if ( theSeedHits1.isOnTheSameLayer(theSeedHits0) ) continue;
465 
466 #ifdef FAMOS_DEBUG
467  std::cout << "Apparently the second hit is on the requested detector! " << std::endl;
468 #endif
469  GlobalPoint gpos1 = theSeedHits0.globalPosition();
470  GlobalPoint gpos2 = theSeedHits1.globalPosition();
471  bool forward = theSeedHits0.isForward();
472  double error = std::sqrt(theSeedHits0.largerError()+theSeedHits1.largerError());
473  // compatible = compatibleWithVertex(gpos1,gpos2,ialgo);
474  //added out of desperation
475  if(seedingAlgo[0] == "PixelLess" || seedingAlgo[0] == "TobTecLayerPairs"){
476  compatible = true;
477  //std::cout << "Algo " << seedingAlgo[0] << "Det/layer = " << theSeedHits0.subDetId() << "/" << theSeedHits0.layerNumber() << std::endl;
478  } else {
479  compatible = compatibleWithBeamAxis(gpos1,gpos2,error,forward,ialgo);
480  }
481 
482 #ifdef FAMOS_DEBUG
483  std::cout << "Algo" << seedingAlgo[0] << "\t Are the two hits compatible with the PV? " << compatible << std::endl;
484 #endif
485 
486  // Check if the pair is on the requested dets
487  if ( numberOfHits[ialgo] == 2 ) {
488 
489  if ( seedingAlgo[0] == "ThirdMixedPairs" ){
490  compatible = compatible && theSeedHits[0].makesAPairWith3rd(theSeedHits[1]);
491  /*
492  if(compatible) {
493  std::cout << "Seed producer in 3rd iteration" << std::endl;
494  std::cout << "The first hit position = " << theSeedHits0.globalPosition() << std::endl;
495  std::cout << "The first hit subDetId = " << theSeedHits0.subDetId() << std::endl;
496  std::cout << "The first hit layer = " << theSeedHits0.layerNumber() << std::endl;
497  std::cout << "The second hit position = " << theSeedHits1.globalPosition() << std::endl;
498  std::cout << "The second hit subDetId = " << theSeedHits1.subDetId() << std::endl;
499  std::cout << "The second hit layer = " << theSeedHits1.layerNumber() << std::endl;
500  }
501  */
502  } else {
503  compatible = compatible && theSeedHits[0].makesAPairWith(theSeedHits[1]);
504  //check
505  /*
506  if((seedingAlgo[0] == "PixelLess" || seedingAlgo[0] == "TobTecLayerPairs") && !compatible)
507  std::cout << "NOT Compatible " << seedingAlgo[0]
508  << "Hit 1 Det/layer/ring = " << theSeedHits0.subDetId() << "/" << theSeedHits0.layerNumber() << "/" << theSeedHits0.ringNumber()
509  << "\tHit 2 Det/layer/ring = " << theSeedHits1.subDetId() << "/" << theSeedHits1.layerNumber() << "/" << theSeedHits1.ringNumber() << std::endl;
510  */
511  }
512  }
513 
514  // Reject non suited pairs
515  if ( !compatible ) continue;
516 
517 #ifdef FAMOS_DEBUG
518  std::cout << "Pair kept! " << std::endl;
519 #endif
520 
521  // Leave here if only two hits are required.
522  if ( numberOfHits[ialgo] == 2 ) break;
523 
524  compatible = false;
525  // Check if there is a third satisfying hit otherwise
526  for ( iterRecHit3 = iterRecHit2+1; iterRecHit3 != theRecHitRangeIteratorEnd; ++iterRecHit3) {
527  theSeedHits[2] = TrackerRecHit(&(*iterRecHit3),theGeometry);
528 #ifdef FAMOS_DEBUG
529  std::cout << "The third hit position = " << theSeedHits2.globalPosition() << std::endl;
530  std::cout << "The third hit subDetId = " << theSeedHits2.subDetId() << std::endl;
531  std::cout << "The third hit layer = " << theSeedHits2.layerNumber() << std::endl;
532 #endif
533 
534  // Check if inside the requested detectors
535  isInside = theSeedHits2.subDetId() < thirdHitSubDetectors[ialgo][0];
536  if ( isInside ) continue;
537 
538  // Check if on requested detectors
539  isOndet = theSeedHits2.isOnRequestedDet(thirdHitSubDetectors[ialgo], seedingAlgo[ialgo]);
540  // if ( !isOndet ) break;
541  if ( !isOndet ) continue;
542 
543  // Check if on the same layer as previous hit
544  compatible = !(theSeedHits2.isOnTheSameLayer(theSeedHits1));
545 
546  // Check if the triplet is on the requested det combination
547  compatible = compatible && theSeedHits[0].makesATripletWith(theSeedHits[1],theSeedHits[2]);
548 
549 #ifdef FAMOS_DEBUG
550  if ( compatible )
551  std::cout << "Apparently the third hit is on the requested detector! " << std::endl;
552 #endif
553 
554  if ( compatible ) break;
555 
556  }
557 
558  if ( compatible ) break;
559 
560  }
561 
562  if ( compatible ) break;
563 
564  }
565 
566  // There is no compatible seed for this track with this seeding algorithm
567  // Go to next algo
568  if ( !compatible ) continue;
569 
570 #ifdef FAMOS_DEBUG
571  std::cout << "Preparing to create the TrajectorySeed" << std::endl;
572 #endif
573  // The seed is validated -> include in the collection
574  // 1) Create the vector of RecHits
576  for ( unsigned ih=0; ih<theSeedHits.size(); ++ih ) {
577  TrackingRecHit* aTrackingRecHit = theSeedHits[ih].hit()->clone();
578  recHits.push_back(aTrackingRecHit);
579  }
580 #ifdef FAMOS_DEBUG
581  std::cout << "with " << recHits.size() << " hits." << std::endl;
582 #endif
583 
584  // 2) Create the initial state
585  // a) origin vertex
586  GlobalPoint position((*theSimVtx)[vertexIndex].position().x(),
587  (*theSimVtx)[vertexIndex].position().y(),
588  (*theSimVtx)[vertexIndex].position().z());
589 
590  // b) initial momentum
591  GlobalVector momentum( (*theSimTracks)[simTrackId].momentum().x() ,
592  (*theSimTracks)[simTrackId].momentum().y() ,
593  (*theSimTracks)[simTrackId].momentum().z() );
594  // c) electric charge
595  float charge = (*theSimTracks)[simTrackId].charge();
596  // -> inital parameters
597  GlobalTrajectoryParameters initialParams(position,momentum,(int)charge,theMagField);
598  // -> large initial errors
599  AlgebraicSymMatrix55 errorMatrix= AlgebraicMatrixID();
600  // errorMatrix = errorMatrix * 10;
601 
602  //this line help the fit succeed in the case of pixelless tracks (4th and 5th iteration)
603  //for the future: probably the best thing is to use the mini-kalmanFilter
604  if(theSeedHits0.subDetId() !=1 || theSeedHits0.subDetId() !=2) errorMatrix = errorMatrix * 0.0000001;
605 
606 
607 
608 #ifdef FAMOS_DEBUG
609  std::cout << "TrajectorySeedProducer: SimTrack parameters " << std::endl;
610  std::cout << "\t\t pT = " << (*theSimTracks)[simTrackId].momentum().Pt() << std::endl;
611  std::cout << "\t\t eta = " << (*theSimTracks)[simTrackId].momentum().Eta() << std::endl;
612  std::cout << "\t\t phi = " << (*theSimTracks)[simTrackId].momentum().Phi() << std::endl;
613  std::cout << "TrajectorySeedProducer: AlgebraicSymMatrix " << errorMatrix << std::endl;
614 #endif
615  CurvilinearTrajectoryError initialError(errorMatrix);
616  // -> initial state
617  FreeTrajectoryState initialFTS(initialParams, initialError);
618 #ifdef FAMOS_DEBUG
619  std::cout << "TrajectorySeedProducer: FTS momentum " << initialFTS.momentum() << std::endl;
620 #endif
621  // const GeomDetUnit* initialLayer = theGeometry->idToDetUnit( recHits.front().geographicalId() );
622  const GeomDet* initialLayer = theGeometry->idToDet( recHits.front().geographicalId() );
623 
624  //this is wrong because the FTS is defined at vertex, and it need to be properly propagated.
625  // const TrajectoryStateOnSurface initialTSOS(initialFTS, initialLayer->surface());
626 
627  const TrajectoryStateOnSurface initialTSOS = thePropagator->propagate(initialFTS,initialLayer->surface()) ;
628  if (!initialTSOS.isValid()) continue;
629 
630 #ifdef FAMOS_DEBUG
631  std::cout << "TrajectorySeedProducer: TSOS global momentum " << initialTSOS.globalMomentum() << std::endl;
632  std::cout << "\t\t\tpT = " << initialTSOS.globalMomentum().perp() << std::endl;
633  std::cout << "\t\t\teta = " << initialTSOS.globalMomentum().eta() << std::endl;
634  std::cout << "\t\t\tphi = " << initialTSOS.globalMomentum().phi() << std::endl;
635  std::cout << "TrajectorySeedProducer: TSOS local momentum " << initialTSOS.localMomentum() << std::endl;
636  std::cout << "TrajectorySeedProducer: TSOS local error " << initialTSOS.localError().positionError() << std::endl;
637  std::cout << "TrajectorySeedProducer: TSOS local error matrix " << initialTSOS.localError().matrix() << std::endl;
638  std::cout << "TrajectorySeedProducer: TSOS surface side " << initialTSOS.surfaceSide() << std::endl;
639 #endif
640  stateOnDet(initialTSOS,
641  recHits.front().geographicalId().rawId(),
642  initialState);
643  // Create a new Trajectory Seed
644  output[ialgo]->push_back(TrajectorySeed(initialState, recHits, alongMomentum));
645 #ifdef FAMOS_DEBUG
646  std::cout << "Trajectory seed created ! " << std::endl;
647 #endif
648  break;
649  // End of the loop over seeding algorithms
650  }
651  // End on the loop over simtracks
652  }
653 
654  for ( unsigned ialgo=0; ialgo<seedingAlgo.size(); ++ialgo ) {
655  std::auto_ptr<TrajectorySeedCollection> p(output[ialgo]);
656  e.put(p,seedingAlgo[ialgo]);
657  }
658 
659 }
660 
661 // This is a copy of a method in
662 // TrackingTools/TrajectoryState/src/TrajectoryStateTransform.cc
663 // but it does not return a pointer (thus avoiding a memory leak)
664 // In addition, it's also CPU more efficient, because
665 // ts.localError().matrix() is not copied
666 void
668  unsigned int detid,
669  PTrajectoryStateOnDet& pts) const
670 {
671 
672  const AlgebraicSymMatrix55& m = ts.localError().matrix();
673 
674  int dim = 5;
675 
676  float localErrors[15];
677  int k = 0;
678  for (int i=0; i<dim; ++i) {
679  for (int j=0; j<=i; ++j) {
680  localErrors[k++] = m(i,j);
681  }
682  }
683  int surfaceSide = static_cast<int>(ts.surfaceSide());
684 
686  localErrors, detid,
687  surfaceSide);
688 }
689 
690 bool
692  GlobalPoint& gpos2,
693  double error,
694  bool forward,
695  unsigned algo) const {
696 
697  if ( !seedCleaning ) return true;
698 
699  // The hits 1 and 2 positions, in HepLorentzVector's
700  XYZTLorentzVector thePos1(gpos1.x(),gpos1.y(),gpos1.z(),0.);
701  XYZTLorentzVector thePos2(gpos2.x(),gpos2.y(),gpos2.z(),0.);
702 #ifdef FAMOS_DEBUG
703  std::cout << "ThePos1 = " << thePos1 << std::endl;
704  std::cout << "ThePos2 = " << thePos2 << std::endl;
705 #endif
706 
707 
708  // Create new particles that pass through the second hit with pT = ptMin
709  // and charge = +/-1
710 
711  // The momentum direction is by default joining the two hits
712  XYZTLorentzVector theMom2 = (thePos2-thePos1);
713 
714  // The corresponding RawParticle, with an (irrelevant) electric charge
715  // (The charge is determined in the next step)
716  ParticlePropagator myPart(theMom2,thePos2,1.,theFieldMap);
717 
721  bool intersect = myPart.propagateToBeamCylinder(thePos1,originRadius[algo]*1.);
722  if ( !intersect ) return false;
723 
724 #ifdef FAMOS_DEBUG
725  std::cout << "MyPart R = " << myPart.R() << "\t Z = " << myPart.Z()
726  << "\t pT = " << myPart.Pt() << std::endl;
727 #endif
728 
729  // Check if the constraints are satisfied
730  // 1. pT at cylinder with radius originRadius
731  if ( myPart.Pt() < originpTMin[algo] ) return false;
732 
733  // 2. Z compatible with beam spot size
734  if ( fabs(myPart.Z()-z0) > originHalfLength[algo] ) return false;
735 
736  // 3. Z compatible with one of the primary vertices (always the case if no primary vertex)
737  const reco::VertexCollection* theVertices = vertices[algo];
738  if (!theVertices) return true;
739  unsigned nVertices = theVertices->size();
740  if ( !nVertices || zVertexConstraint[algo] < 0. ) return true;
741  // Radii of the two hits with respect to the beam spot position
742  double R1 = std::sqrt ( (thePos1.X()-x0)*(thePos1.X()-x0)
743  + (thePos1.Y()-y0)*(thePos1.Y()-y0) );
744  double R2 = std::sqrt ( (thePos2.X()-x0)*(thePos2.X()-x0)
745  + (thePos2.Y()-y0)*(thePos2.Y()-y0) );
746  // Loop on primary vertices
747  for ( unsigned iv=0; iv<nVertices; ++iv ) {
748  // Z position of the primary vertex
749  double zV = (*theVertices)[iv].z();
750  // Constraints on the inner hit
751  double checkRZ1 = forward ?
752  (thePos1.Z()-zV+zVertexConstraint[algo]) / (thePos2.Z()-zV+zVertexConstraint[algo]) * R2 :
753  -zVertexConstraint[algo] + R1/R2*(thePos2.Z()-zV+zVertexConstraint[algo]);
754  double checkRZ2 = forward ?
755  (thePos1.Z()-zV-zVertexConstraint[algo])/(thePos2.Z()-zV-zVertexConstraint[algo]) * R2 :
756  +zVertexConstraint[algo] + R1/R2*(thePos2.Z()-zV-zVertexConstraint[algo]);
757  double checkRZmin = std::min(checkRZ1,checkRZ2)-3.*error;
758  double checkRZmax = std::max(checkRZ1,checkRZ2)+3.*error;
759  // Check if the innerhit is within bounds
760  bool compat = forward ?
761  checkRZmin < R1 && R1 < checkRZmax :
762  checkRZmin < thePos1.Z()-zV && thePos1.Z()-zV < checkRZmax;
763  // If it is, just return ok
764  if ( compat ) return compat;
765  }
766  // Otherwise, return not ok
767  return false;
768 
769 }
770 
bool compatibleWithBeamAxis(GlobalPoint &gpos1, GlobalPoint &gpos2, double error, bool forward, unsigned algo) const
void setCharge(float q)
set the MEASURED charge
Definition: RawParticle.cc:138
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
std::vector< unsigned > minRecHits
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:52
double zImpactParameter(double x0=0, double y0=0.) const
Longitudinal impact parameter.
std::vector< unsigned int > firstHitSubDetectorNumber
T perp() const
Definition: PV3DBase.h:71
TrajectorySeedProducer(const edm::ParameterSet &conf)
const LocalTrajectoryParameters & localParameters() const
virtual void beginRun(edm::Run &run, const edm::EventSetup &es)
ROOT::Math::SMatrixIdentity AlgebraicMatrixID
std::vector< double > pTMin
size_type size() const
Definition: OwnVector.h:247
Geom::Phi< T > phi() const
Definition: PV3DBase.h:68
T y() const
Definition: PV3DBase.h:62
bool propagateToBeamCylinder(const XYZTLorentzVector &v, double radius=0.)
virtual void produce(edm::Event &e, const edm::EventSetup &es)
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
#define min(a, b)
Definition: mlp_lapack.h:161
std::vector< double > originRadius
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
const MagneticFieldMap * theFieldMap
void stateOnDet(const TrajectoryStateOnSurface &ts, unsigned int detid, PTrajectoryStateOnDet &pts) const
A mere copy (without memory leak) of an existing tracking method.
std::vector< double > originpTMin
double charge(const std::vector< uint8_t > &Ampls)
GlobalPoint globalPosition() const
The global position.
Definition: TrackerRecHit.h:96
double largerError()
LocalError positionError() const
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
double double double z
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
bool isOnTheSameLayer(const TrackerRecHit &other) const
Check if two hits are on the same layer of the same subdetector.
std::vector< unsigned int > numberOfHits
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
LocalVector localMomentum() const
PropagatorWithMaterial * thePropagator
double R() const
vertex radius
Definition: RawParticle.h:277
static const double pts[33]
Definition: Constants.h:31
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:45
void push_back(D *&d)
Definition: OwnVector.h:273
std::vector< std::vector< unsigned int > > secondHitSubDetectors
std::vector< TrajectorySeed > TrajectorySeedCollection
const T & max(const T &a, const T &b)
std::vector< std::vector< unsigned int > > thirdHitSubDetectors
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
T sqrt(T t)
Definition: SSEVec.h:46
std::vector< double > zVertexConstraint
SurfaceSide surfaceSide() const
Position relative to material, defined relative to momentum vector.
T z() const
Definition: PV3DBase.h:63
double Z() const
z of vertex
Definition: RawParticle.h:275
int j
Definition: DBlmapReader.cc:9
const AlgebraicSymMatrix55 & matrix() const
const math::XYZTLorentzVectorD & position() const
Definition: CoreSimVertex.h:26
const LocalTrajectoryError & localError() const
const TrackerGeometry * theGeometry
virtual const GeomDet * idToDet(DetId) const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
GlobalVector momentum() const
tuple conf
Definition: dbtoconf.py:185
std::vector< unsigned int > thirdHitSubDetectorNumber
int k[5][pyjets_maxn]
virtual TrackingRecHit * clone() const =0
virtual TrajectoryStateOnSurface propagate(const TrajectoryStateOnSurface &tsos, const Plane &plane) const
int vertIndex() const
index of the vertex in the Event container (-1 if no vertex)
Definition: SimTrack.h:29
bool isForward() const
Is it a forward hit ?
Definition: TrackerRecHit.h:90
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:13
const T & get() const
Definition: EventSetup.h:55
std::vector< unsigned int > secondHitSubDetectorNumber
unsigned int layerNumber() const
The Layer Number.
Definition: TrackerRecHit.h:81
static bool intersect(Range &range, const Range &second)
T eta() const
Definition: PV3DBase.h:75
ESHandle< TrackerGeometry > geometry
bool isOnRequestedDet(const std::vector< unsigned int > &whichDet, const std::string &seedingAlgo) const
Check if the hit is on one of the requested detector.
GlobalVector globalMomentum() const
const BoundPlane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
std::vector< const reco::VertexCollection * > vertices
std::vector< double > originHalfLength
const math::XYZTLorentzVectorD & momentum() const
particle info...
Definition: CoreSimTrack.h:36
std::vector< double > maxZ0
unsigned int subDetId() const
The subdet Id.
Definition: TrackerRecHit.h:78
std::vector< std::string > seedingAlgo
tuple cout
Definition: gather_cfg.py:121
std::vector< edm::InputTag > primaryVertices
std::vector< std::vector< unsigned int > > firstHitSubDetectors
std::vector< double > maxD0
DetId geographicalId() const
LimitAlgo * algo
Definition: Combine.cc:60
Definition: DDAxes.h:10
T x() const
Definition: PV3DBase.h:61
reference front()
Definition: OwnVector.h:348
Definition: Run.h:33
double xyImpactParameter(double x0=0., double y0=0.) const
Transverse impact parameter.
math::XYZTLorentzVector XYZTLorentzVector
Definition: RawParticle.h:15
const MagneticField * theMagField