CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CosmicParametersDefinerForTP.cc
Go to the documentation of this file.
13 #include "SimTracker/TrackAssociatorESProducer/src/TrackAssociatorByPositionESProducer.hh"
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()-bs->x0(),v.y()-bs->y0(),v.z()-bs->z0());
189  }
190  else {
191  edm::LogVerbatim("CosmicParametersDefinerForTP")
192  <<"*** WARNING in CosmicParametersDefinerForTP::vertex: tsAtClosestApproach is not valid." <<"\n";
193  }
194  edm::LogVerbatim("CosmicParametersDefinerForTP")
195  <<"\t \t FINAL State extrap. at PCA: radius = "
196  <<sqrt(vertex.x()*vertex.x()+vertex.y()*vertex.y())<<", z = "<<vertex.z()<<"\n";
197 
198  return vertex;
199  }
200 
201  edm::LogVerbatim("CosmicParametersDefinerForTP")
202  <<"*** WARNING in CosmicParametersDefinerForTP::vertex: NOT found the innermost TP point" <<"\n";
203  edm::LogVerbatim("CosmicParametersDefinerForTP")
204  <<"*** FINAL Reference VERTEX TP V(x,y,z) = "<<vertex.x()<<vertex.y()<<vertex.z()<<"\n";
205 
206  return vertex;
207 }
208 
209 
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:114
T perp() const
Definition: PV3DBase.h:72
static bool simHitTPAssociationListGreater(SimHitTPPair i, SimHitTPPair j)
virtual TrackingParticle::Vector momentum(const edm::Event &iEvent, const edm::EventSetup &iSetup, const TrackingParticleRef &tpr) const override
T y() const
Definition: PV3DBase.h:63
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:40
math::XYZPointD Point
point in the space
int TrackCharge
Definition: TrackCharge.h:4
int iEvent
Definition: GenABIO.cc:230
T sqrt(T t)
Definition: SSEVec.h:48
T z() const
Definition: PV3DBase.h:64
bool isValid() const
Definition: HandleBase.h:75
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:405
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:55
virtual TrackingParticle::Point vertex(const edm::Event &iEvent, const edm::EventSetup &iSetup, const TrackingParticleRef &tpr) const override
edm::Ref< edm::PSimHitContainer > TrackPSimHitRef
math::XYZVectorD Vector
point in the space
T x() const
Definition: PV3DBase.h:62
edm::Handle< SimHitTPAssociationProducer::SimHitTPAssociationList > simHitsTPAssoc