CMS 3D CMS Logo

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