CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SeedGeneratorForCosmics.cc
Go to the documentation of this file.
7 void
9  const SiStripRecHit2DCollection &collrphi ,
10  const SiStripMatchedRecHit2DCollection &collmatched,
11  const edm::EventSetup& iSetup)
12 {
13  iSetup.get<IdealMagneticFieldRecord>().get(magfield);
14  iSetup.get<TrackerDigiGeometryRecord>().get(tracker);
17  theUpdator= new KFUpdator();
18 
19  // get the transient builder
20  //
21 
23 
24  iSetup.get<TransientRecHitRecord>().get(builderName,theBuilder);
25  TTTRHBuilder = theBuilder.product();
26  LogDebug("CosmicSeedFinder")<<" Hits built with "<<hitsforseeds<<" hits";
27 
28  CosmicLayerPairs cosmiclayers(geometry);
29 
30  cosmiclayers.init(collstereo,collrphi,collmatched,iSetup);
31  thePairGenerator=new CosmicHitPairGenerator(cosmiclayers,iSetup);
32  HitPairs.clear();
33  if ((hitsforseeds=="pairs")||(hitsforseeds=="pairsandtriplets")){
35  }
36 
37  CosmicLayerTriplets cosmiclayers2;
38  cosmiclayers2.init(collstereo,collrphi,collmatched,geometry,iSetup);
39  theTripletGenerator=new CosmicHitTripletGenerator(cosmiclayers2,iSetup);
40  HitTriplets.clear();
41  if ((hitsforseeds=="triplets")||(hitsforseeds=="pairsandtriplets")){
43  }
44 }
45 
47  conf_(conf),
48  maxSeeds_(conf.getParameter<int32_t>("maxSeeds"))
49 {
50 
51  float ptmin=conf_.getParameter<double>("ptMin");
52  float originradius=conf_.getParameter<double>("originRadius");
53  float halflength=conf_.getParameter<double>("originHalfLength");
54  float originz=conf_.getParameter<double>("originZPosition");
55  seedpt = conf_.getParameter<double>("SeedPt");
56 
57  builderName = conf_.getParameter<std::string>("TTRHBuilder");
58  geometry=conf_.getUntrackedParameter<std::string>("GeometricStructure","STANDARD");
59  region=GlobalTrackingRegion(ptmin,originradius,
60  halflength,originz);
61  hitsforseeds=conf_.getUntrackedParameter<std::string>("HitsForSeeds","pairs");
62  edm::LogInfo("SeedGeneratorForCosmics")<<" PtMin of track is "<<ptmin<<
63  " The Radius of the cylinder for seeds is "<<originradius <<"cm" << " The set Seed Momentum" << seedpt;
64 
65  //***top-bottom
66  positiveYOnly=conf_.getParameter<bool>("PositiveYOnly");
67  negativeYOnly=conf_.getParameter<bool>("NegativeYOnly");
68  //***
69 
70 
71 }
72 
74  seeds(output,iSetup,region);
75  delete thePairGenerator;
76  delete theTripletGenerator;
77  delete thePropagatorAl;
78  delete thePropagatorOp;
79  delete theUpdator;
80 }
82  const edm::EventSetup& iSetup,
83  const TrackingRegion& region){
84  LogDebug("CosmicSeedFinder")<<"Number of triplets "<<HitTriplets.size();
85  LogDebug("CosmicSeedFinder")<<"Number of pairs "<<HitPairs.size();
86 
87  for (unsigned int it=0;it<HitTriplets.size();it++){
88 
89  //const TrackingRecHit *hit = &(
90  // const TrackingRecHit* hit = it->hits();
91 
92  // GlobalPoint inner = tracker->idToDet(HitTriplets[it].inner().RecHit()->
93 // geographicalId())->surface().
94 // toGlobal(HitTriplets[it].inner().RecHit()->localPosition());
95  //const TrackingRecHit *innerhit = &(*HitTriplets[it].inner());
96  //const TrackingRecHit *middlehit = &(*HitTriplets[it].middle());
97 
98  GlobalPoint inner = tracker->idToDet((*(HitTriplets[it].inner())).geographicalId())->surface().
99  toGlobal((*(HitTriplets[it].inner())).localPosition());
100 
101  GlobalPoint middle = tracker->idToDet((*(HitTriplets[it].middle())).geographicalId())->surface().
102  toGlobal((*(HitTriplets[it].middle())).localPosition());
103 
104  GlobalPoint outer = tracker->idToDet((*(HitTriplets[it].outer())).geographicalId())->surface().
105  toGlobal((*(HitTriplets[it].outer())).localPosition());
106 
107  // SeedingHitSet::ConstRecHitPointer outrhit=TTTRHBuilder->build(HitPairs[is].outer())
108 
109  SeedingHitSet::ConstRecHitPointer outrhit= HitTriplets[it].outer();
110  //***top-bottom
111  SeedingHitSet::ConstRecHitPointer innrhit = HitTriplets[it].inner();
112  if (positiveYOnly && (outrhit->globalPosition().y()<0 || innrhit->globalPosition().y()<0
113  || outrhit->globalPosition().y() < innrhit->globalPosition().y()
114  ) ) continue;
115  if (negativeYOnly && (outrhit->globalPosition().y()>0 || innrhit->globalPosition().y()>0
116  || outrhit->globalPosition().y() > innrhit->globalPosition().y()
117  ) ) continue;
118  //***
119 
121  hits.push_back(HitTriplets[it].outer()->hit()->clone());
122  FastHelix helix(inner, middle, outer, magfield->nominalValue(), &(*magfield));
123  GlobalVector gv=helix.stateAtVertex().momentum();
124  float ch=helix.stateAtVertex().charge();
125  float Mom = sqrt( gv.x()*gv.x() + gv.y()*gv.y() + gv.z()*gv.z() );
126  if(Mom > 1000 || std::isnan(Mom)) continue; // ChangedByDaniele
127 
128  if (gv.y()>0){
129  gv=-1.*gv;
130  ch=-1.*ch;
131  }
132 
133  GlobalTrajectoryParameters Gtp(outer,
134  gv,int(ch),
135  &(*magfield));
136  FreeTrajectoryState CosmicSeed(Gtp,
138  if((outer.y()-inner.y())>0){
139  const TSOS outerState =
140  thePropagatorAl->propagate(CosmicSeed,
141  tracker->idToDet((*(HitTriplets[it].outer())).geographicalId())->surface());
142  if ( outerState.isValid()) {
143  LogDebug("CosmicSeedFinder") <<"outerState "<<outerState;
144  const TSOS outerUpdated= theUpdator->update( outerState,*outrhit);
145  if ( outerUpdated.isValid()) {
146  LogDebug("CosmicSeedFinder") <<"outerUpdated "<<outerUpdated;
147 
148  output.push_back(TrajectorySeed(trajectoryStateTransform::persistentState(outerUpdated,(*(HitTriplets[it].outer())).geographicalId().rawId())
149  ,hits,alongMomentum));
150 
151  if ((maxSeeds_ > 0) && (output.size() > size_t(maxSeeds_))) {
152  edm::LogError("TooManySeeds") << "Found too many seeds, bailing out.\n";
153  output.clear();
154  return false;
155  }
156  }
157  }
158  } else {
159  const TSOS outerState =
160  thePropagatorOp->propagate(CosmicSeed,
161  tracker->idToDet((*(HitTriplets[it].outer())).geographicalId())->surface());
162  if ( outerState.isValid()) {
163  LogDebug("CosmicSeedFinder") <<"outerState "<<outerState;
164  const TSOS outerUpdated= theUpdator->update( outerState,*outrhit);
165  if ( outerUpdated.isValid()) {
166  LogDebug("CosmicSeedFinder") <<"outerUpdated "<<outerUpdated;
167 
168  output.push_back(TrajectorySeed(trajectoryStateTransform::persistentState(outerUpdated,
169  (*(HitTriplets[it].outer())).geographicalId().rawId()),hits,oppositeToMomentum));
170 
171  if ((maxSeeds_ > 0) && (output.size() > size_t(maxSeeds_))) {
172  edm::LogError("TooManySeeds") << "Found too many seeds, bailing out.\n";
173  output.clear();
174  return false;
175  }
176  }
177  }
178  }
179  }
180 
181 
182  for(unsigned int is=0;is<HitPairs.size();is++){
183 
184 
185 
186  GlobalPoint inner = tracker->idToDet((*(HitPairs[is].inner())).geographicalId())->surface().toGlobal((*(HitPairs[is].inner())).localPosition());
187  GlobalPoint outer = tracker->idToDet((*(HitPairs[is].outer())).geographicalId())->surface().toGlobal((*(HitPairs[is].outer())).localPosition());
188 
189  LogDebug("CosmicSeedFinder") <<"inner point of the seed "<<inner <<" outer point of the seed "<<outer;
190  //RC const TransientTrackingRecHit* outrhit=TTTRHBuilder->build(HitPairs[is].outer().RecHit());
191  SeedingHitSet::ConstRecHitPointer outrhit = HitPairs[is].outer();
192  //***top-bottom
193  SeedingHitSet::ConstRecHitPointer innrhit = HitPairs[is].inner();
194  if (positiveYOnly && (outrhit->globalPosition().y()<0 || innrhit->globalPosition().y()<0
195  || outrhit->globalPosition().y() < innrhit->globalPosition().y()
196  ) ) continue;
197  if (negativeYOnly && (outrhit->globalPosition().y()>0 || innrhit->globalPosition().y()>0
198  || outrhit->globalPosition().y() > innrhit->globalPosition().y()
199  ) ) continue;
200  //***
201 
203  hits.push_back(HitPairs[is].outer()->hit()->clone());
204  // hits.push_back(HitPairs[is].inner()->clone());
205 
206  for (int i=0;i<2;i++){
207  //FIRST STATE IS CALCULATED CONSIDERING THAT THE CHARGE CAN BE POSITIVE OR NEGATIVE
208  int predsign=(2*i)-1;
209  if((outer.y()-inner.y())>0){
210  GlobalTrajectoryParameters Gtp(outer,
211  (inner-outer)*(seedpt/(inner-outer).mag()),
212  predsign,
213  &(*magfield));
214 
215  FreeTrajectoryState CosmicSeed(Gtp,
217 
218 
219  LogDebug("CosmicSeedFinder") << " FirstTSOS "<<CosmicSeed;
220  //First propagation
221  const TSOS outerState =
222  thePropagatorAl->propagate(CosmicSeed,
223  tracker->idToDet((*(HitPairs[is].outer())).geographicalId())->surface());
224  if ( outerState.isValid()) {
225  LogDebug("CosmicSeedFinder") <<"outerState "<<outerState;
226  const TSOS outerUpdated= theUpdator->update( outerState,*outrhit);
227  if ( outerUpdated.isValid()) {
228  LogDebug("CosmicSeedFinder") <<"outerUpdated "<<outerUpdated;
229 
230  PTrajectoryStateOnDet const & PTraj =
231  trajectoryStateTransform::persistentState(outerUpdated, (*(HitPairs[is].outer())).geographicalId().rawId());
232 
233  output.push_back( TrajectorySeed(PTraj,hits,alongMomentum));
234 
235  if ((maxSeeds_ > 0) && (output.size() > size_t(maxSeeds_))) {
236  edm::LogError("TooManySeeds") << "Found too many seeds, bailing out.\n";
237  output.clear();
238  return false;
239  }
240 
241  }else edm::LogWarning("CosmicSeedFinder") << " SeedForCosmics first update failed ";
242  }else edm::LogWarning("CosmicSeedFinder") << " SeedForCosmics first propagation failed ";
243 
244 
245  }
246  else{
247  GlobalTrajectoryParameters Gtp(outer,
248  (outer-inner)*(seedpt/(outer-inner).mag()),
249  predsign,
250  &(*magfield));
251  FreeTrajectoryState CosmicSeed(Gtp,
253  LogDebug("CosmicSeedFinder") << " FirstTSOS "<<CosmicSeed;
254  //First propagation
255  const TSOS outerState =
256  thePropagatorAl->propagate(CosmicSeed,
257  tracker->idToDet((*(HitPairs[is].outer())).geographicalId())->surface());
258  if ( outerState.isValid()) {
259 
260  LogDebug("CosmicSeedFinder") <<"outerState "<<outerState;
261  const TSOS outerUpdated= theUpdator->update( outerState,*outrhit);
262  if ( outerUpdated.isValid()) {
263  LogDebug("CosmicSeedFinder") <<"outerUpdated "<<outerUpdated;
264 
265  PTrajectoryStateOnDet const & PTraj =
266  trajectoryStateTransform::persistentState(outerUpdated,(*(HitPairs[is].outer())).geographicalId().rawId());
267 
268  output.push_back(TrajectorySeed(PTraj,hits,oppositeToMomentum));
269 
270  if ((maxSeeds_ > 0) && (output.size() > size_t(maxSeeds_))) {
271  edm::LogError("TooManySeeds") << "Found too many seeds, bailing out.\n";
272  output.clear();
273  return false;
274  }
275 
276  }else edm::LogWarning("CosmicSeedFinder") << " SeedForCosmics first update failed ";
277  }else edm::LogWarning("CosmicSeedFinder") << " SeedForCosmics first propagation failed ";
278  }
279 
280  }
281  }
282  return true;
283 }
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
virtual FreeTrajectoryState propagate(const FreeTrajectoryState &ftsStart, const GlobalPoint &pDest) const final
Definition: Propagator.h:119
int i
Definition: DBlmapReader.cc:9
edm::ESHandle< TrackerGeometry > tracker
void run(TrajectorySeedCollection &, const edm::EventSetup &c)
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
ROOT::Math::SMatrixIdentity AlgebraicMatrixID
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
T y() const
Definition: PV3DBase.h:63
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
virtual unsigned int size() const
virtual void hitPairs(const TrackingRegion &reg, OrderedHitPairs &prs, const edm::EventSetup &iSetup)
form base class
PropagatorWithMaterial * thePropagatorOp
CosmicHitTripletGenerator * theTripletGenerator
void init(const SiStripRecHit2DCollection &collstereo, const SiStripRecHit2DCollection &collrphi, const SiStripMatchedRecHit2DCollection &collmatched, std::string geometry, const edm::EventSetup &iSetup)
virtual void hitTriplets(const TrackingRegion &reg, OrderedHitTriplets &prs, const edm::EventSetup &iSetup)
form base class
CosmicHitPairGenerator * thePairGenerator
void push_back(D *&d)
Definition: OwnVector.h:280
BaseTrackerRecHit const * ConstRecHitPointer
Definition: SeedingHitSet.h:11
PropagatorWithMaterial * thePropagatorAl
TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const
Definition: KFUpdator.cc:75
std::vector< TrajectorySeed > TrajectorySeedCollection
bool isnan(float x)
Definition: math.h:13
T sqrt(T t)
Definition: SSEVec.h:48
bool seeds(TrajectorySeedCollection &output, const edm::EventSetup &c, const TrackingRegion &region)
void init(const SiStripRecHit2DCollection &collstereo, const SiStripRecHit2DCollection &collrphi, const SiStripMatchedRecHit2DCollection &collmatched, const edm::EventSetup &iSetup)
tuple conf
Definition: dbtoconf.py:185
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:86
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
double ptmin
Definition: HydjetWrapper.h:85
SeedGeneratorForCosmics(const edm::ParameterSet &conf)
virtual unsigned int size() const
const TransientTrackingRecHitBuilder * TTTRHBuilder
edm::ESHandle< MagneticField > magfield
void init(const SiStripRecHit2DCollection &collstereo, const SiStripRecHit2DCollection &collrphi, const SiStripMatchedRecHit2DCollection &collmatched, const edm::EventSetup &c)