CMS 3D CMS Logo

CosmicParametersDefinerForTP.cc
Go to the documentation of this file.
20 
22 
23 
26  // to add a new implementation for cosmic. For the moment, it is just as for the base class:
27  using namespace edm;
28  using namespace std;
29  using namespace reco;
30 
32  iSetup.get<TrackerDigiGeometryRecord>().get(tracker);
34  iSetup.get<GlobalTrackingGeometryRecord>().get(theGeometry);
35 
37  iSetup.get<IdealMagneticFieldRecord>().get(theMF);
38 
40  iEvent.getByLabel(InputTag("offlineBeamSpot"),bs);
41 
42  GlobalVector finalGV(0,0,0);
43  GlobalPoint finalGP(0,0,0);
44  double radius(9999);
45  bool found(0);
47 
48  edm::LogVerbatim("CosmicParametersDefinerForTP")<<"\t in CosmicParametersDefinerForTP::momentum";
49  edm::LogVerbatim("CosmicParametersDefinerForTP")
50  <<"\t \t Original TP state: pt = "<<tpr->pt()<<", pz = "<<tpr->pz();
51 
52  if (simHitsTPAssoc.isValid()==0) {
53  LogError("TrackAssociation") << "Invalid handle!";
54  return momentum;
55  }
56  std::pair<TrackingParticleRef, TrackPSimHitRef> clusterTPpairWithDummyTP(tpr,TrackPSimHitRef());//SimHit is dummy: for simHitTPAssociationListGreater
57  // sorting only the cluster is needed
58  auto range = std::equal_range(simHitsTPAssoc->begin(), simHitsTPAssoc->end(),
60  for(auto ip = range.first; ip != range.second; ++ip) {
61  TrackPSimHitRef it = ip->second;
62  const GeomDet* tmpDet = theGeometry->idToDet( DetId(it->detUnitId()) ) ;
63  if (!tmpDet) {
64  edm::LogVerbatim("CosmicParametersDefinerForTP")
65  <<"***WARNING in CosmicParametersDefinerForTP::momentum: no GeomDet for: "<<it->detUnitId()<<". Skipping it."<<"\n";
66  continue;
67  }
68 
69  LocalVector lv = it->momentumAtEntry();
70  Local3DPoint lp = it->localPosition ();
71  GlobalVector gv = tmpDet->surface().toGlobal( lv );
72  GlobalPoint gp = tmpDet->surface().toGlobal( lp );
73 
74  // discard hits related to low energy debris from the primary particle
75  if (it->processType()!=0) continue;
76 
77  if(gp.perp()<radius){
78  found=true;
79  radius = gp.perp();
80  finalGV = gv;
81  finalGP = gp;
82  }
83  }
84 
85  edm::LogVerbatim("CosmicParametersDefinerForTP")
86  // <<"\t FINAL State at InnerMost Hit: Radius = "<< finalGP.perp() << ", z = "<< finalGP.z()
87  // <<", pt = "<< finalGV.perp() << ", pz = "<< finalGV.z();
88  <<"\t \t FINAL State at InnerMost Hit: pt = "<< finalGV.perp() << ", pz = "<< finalGV.z();
89 
90  if(found)
91  {
92  FreeTrajectoryState ftsAtProduction(finalGP,finalGV,TrackCharge(tpr->charge()),theMF.product());
93  TSCBLBuilderNoMaterial tscblBuilder;
94  TrajectoryStateClosestToBeamLine tsAtClosestApproach = tscblBuilder(ftsAtProduction,*bs);//as in TrackProducerAlgorithm
95 
96  if(tsAtClosestApproach.isValid()){
97  GlobalVector p = tsAtClosestApproach.trackStateAtPCA().momentum();
98  momentum = TrackingParticle::Vector(p.x(), p.y(), p.z());
99  }
100  else {
101  edm::LogVerbatim("CosmicParametersDefinerForTP")
102  <<"*** WARNING in CosmicParametersDefinerForTP::momentum: tsAtClosestApproach is not valid." <<"\n";
103  }
104 
105  edm::LogVerbatim("CosmicParametersDefinerForTP")
106  <<"\t \t FINAL State extrap. at PCA: pt = "<< sqrt(momentum.x()*momentum.x()+momentum.y()*momentum.y()) << ", pz = "<< momentum.z() <<"\n";
107 
108  return momentum;
109  }
110 
111  edm::LogVerbatim("CosmicParametersDefinerForTP")
112  <<"*** WARNING in CosmicParametersDefinerForTP::momentum: NOT found the innermost TP point" <<"\n";
113  edm::LogVerbatim("CosmicParametersDefinerForTP")
114  <<"*** FINAL Reference MOMENTUM TP (px,py,pz) = "<<momentum.x()<<momentum.y()<<momentum.z()<<"\n";
115  return momentum;
116 }
117 
119 
120  using namespace edm;
121  using namespace std;
122  using namespace reco;
123 
125  iSetup.get<TrackerDigiGeometryRecord>().get(tracker);
127  iSetup.get<GlobalTrackingGeometryRecord>().get(theGeometry);
128 
130  iSetup.get<IdealMagneticFieldRecord>().get(theMF);
131 
133  iEvent.getByLabel(InputTag("offlineBeamSpot"),bs);
134 
135  GlobalVector finalGV(0,0,0);
136  GlobalPoint finalGP(0,0,0);
137  double radius(9999);
138  bool found(0);
140 
141  edm::LogVerbatim("CosmicParametersDefinerForTP")<<"\t in CosmicParametersDefinerForTP::vertex";
142  edm::LogVerbatim("CosmicParametersDefinerForTP")
143  <<"\t \t Original TP state: radius = "<<sqrt(tpr->vertex().x()*tpr->vertex().x()+tpr->vertex().y()*tpr->vertex().y())<<", z = "<<tpr->vertex().z();
144 
145  if (simHitsTPAssoc.isValid()==0) {
146  LogError("TrackAssociation") << "Invalid handle!";
147  return vertex;
148  }
149  std::pair<TrackingParticleRef, TrackPSimHitRef> clusterTPpairWithDummyTP(tpr,TrackPSimHitRef());//SimHit is dummy: for simHitTPAssociationListGreater
150  // sorting only the cluster is needed
151  auto range = std::equal_range(simHitsTPAssoc->begin(), simHitsTPAssoc->end(),
153  for(auto ip = range.first; ip != range.second; ++ip) {
154  TrackPSimHitRef it = ip->second;
155  const GeomDet* tmpDet = theGeometry->idToDet( DetId(it->detUnitId()) ) ;
156  if (!tmpDet) {
157  edm::LogVerbatim("CosmicParametersDefinerForTP")
158  <<"***WARNING in CosmicParametersDefinerForTP::vertex: no GeomDet for: "<<it->detUnitId()<<". Skipping it."<<"\n";
159  continue;
160  }
161 
162  LocalVector lv = it->momentumAtEntry();
163  Local3DPoint lp = it->localPosition ();
164  GlobalVector gv = tmpDet->surface().toGlobal( lv );
165  GlobalPoint gp = tmpDet->surface().toGlobal( lp );
166 
167  // discard hits related to low energy debris from the primary particle
168  if (it->processType()!=0) continue;
169 
170  if(gp.perp()<radius){
171  found=true;
172  radius = gp.perp();
173  finalGV = gv;
174  finalGP = gp;
175  }
176  }
177  edm::LogVerbatim("CosmicParametersDefinerForTP")
178  <<"\t \t FINAL State at InnerMost Hit: radius = "<< finalGP.perp() << ", z = "<< finalGP.z();
179 
180  if(found)
181  {
182  FreeTrajectoryState ftsAtProduction(finalGP,finalGV,TrackCharge(tpr->charge()),theMF.product());
183  TSCBLBuilderNoMaterial tscblBuilder;
184  TrajectoryStateClosestToBeamLine tsAtClosestApproach = tscblBuilder(ftsAtProduction,*bs);//as in TrackProducerAlgorithm
185 
186  if(tsAtClosestApproach.isValid()){
187  GlobalPoint v = tsAtClosestApproach.trackStateAtPCA().position();
188  vertex = TrackingParticle::Point(v.x(), v.y(), v.z());
189  }
190  else {
191  // to preserve old behaviour
192  // would be better to flag this somehow to allow ignoring in downstream
193  vertex = TrackingParticle::Point(bs->x0(), bs->y0(), bs->z0());
194  edm::LogVerbatim("CosmicParametersDefinerForTP")
195  <<"*** WARNING in CosmicParametersDefinerForTP::vertex: tsAtClosestApproach is not valid." <<"\n";
196  }
197  edm::LogVerbatim("CosmicParametersDefinerForTP")
198  <<"\t \t FINAL State extrap. at PCA: radius = "
199  <<sqrt(vertex.x()*vertex.x()+vertex.y()*vertex.y())<<", z = "<<vertex.z()<<"\n";
200 
201  return vertex;
202  }
203 
204  edm::LogVerbatim("CosmicParametersDefinerForTP")
205  <<"*** WARNING in CosmicParametersDefinerForTP::vertex: NOT found the innermost TP point" <<"\n";
206  edm::LogVerbatim("CosmicParametersDefinerForTP")
207  <<"*** FINAL Reference VERTEX TP V(x,y,z) = "<<vertex.x()<<vertex.y()<<vertex.z()<<"\n";
208 
209  return vertex;
210 }
211 
212 
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:106
double z0() const
z coordinate
Definition: BeamSpot.h:68
T perp() const
Definition: PV3DBase.h:72
static bool simHitTPAssociationListGreater(SimHitTPPair i, SimHitTPPair j)
T y() const
Definition: PV3DBase.h:63
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
math::XYZPointD Point
point in the space
int TrackCharge
Definition: TrackCharge.h:4
virtual const GeomDet * idToDet(DetId) const
int iEvent
Definition: GenABIO.cc:230
virtual TrackingParticle::Point vertex(const edm::Event &iEvent, const edm::EventSetup &iSetup, const TrackingParticleRef &tpr) const override
T sqrt(T t)
Definition: SSEVec.h:18
virtual TrackingParticle::Vector momentum(const edm::Event &iEvent, const edm::EventSetup &iSetup, const TrackingParticleRef &tpr) const override
T z() const
Definition: PV3DBase.h:64
bool isValid() const
Definition: HandleBase.h:74
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:416
GlobalVector momentum() const
#define TYPELOOKUP_DATA_REG(_dataclass_)
Definition: typelookup.h:96
Definition: DetId.h:18
GlobalPoint position() const
const T & get() const
Definition: EventSetup.h:56
fixed size matrix
HLT enums.
double y0() const
y coordinate
Definition: BeamSpot.h:66
edm::Ref< edm::PSimHitContainer > TrackPSimHitRef
math::XYZVectorD Vector
point in the space
T x() const
Definition: PV3DBase.h:62
T const * product() const
Definition: ESHandle.h:86
edm::Handle< SimHitTPAssociationProducer::SimHitTPAssociationList > simHitsTPAssoc
double x0() const
x coordinate
Definition: BeamSpot.h:64