CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CosmicParametersDefinerForTP.cc
Go to the documentation of this file.
12 
14 
16  : ParametersDefinerForTP(edm::InputTag("offlineBeamSpot"), iC), geometryToken_(iC.esConsumes()) {}
18 
20  const edm::EventSetup &iSetup,
21  const TrackingParticleRef &tpr) const {
22  // to add a new implementation for cosmic. For the moment, it is just as for
23  // the base class:
24  using namespace edm;
25  using namespace std;
26  using namespace reco;
27 
28  auto const &bs = iEvent.get(bsToken_);
29  auto const &geometry = iSetup.getData(geometryToken_);
30  auto const &mf = iSetup.getData(mfToken_);
31 
32  GlobalVector finalGV(0, 0, 0);
33  GlobalPoint finalGP(0, 0, 0);
34  double radius(9999);
35  bool found(false);
37 
38  edm::LogVerbatim("CosmicParametersDefinerForTP") << "\t in CosmicParametersDefinerForTP::momentum";
39  edm::LogVerbatim("CosmicParametersDefinerForTP")
40  << "\t \t Original TP state: pt = " << tpr->pt() << ", pz = " << tpr->pz();
41 
42  if (simHitsTPAssoc.isValid() == 0) {
43  LogError("TrackAssociation") << "Invalid handle!";
44  return momentum;
45  }
46  std::pair<TrackingParticleRef, TrackPSimHitRef> clusterTPpairWithDummyTP(
47  tpr,
48  TrackPSimHitRef()); // SimHit is dummy: for simHitTPAssociationListGreater
49  // sorting only the cluster is needed
50  auto range = std::equal_range(simHitsTPAssoc->begin(),
51  simHitsTPAssoc->end(),
52  clusterTPpairWithDummyTP,
54  for (auto ip = range.first; ip != range.second; ++ip) {
55  TrackPSimHitRef it = ip->second;
56  const GeomDet *tmpDet = geometry.idToDet(DetId(it->detUnitId()));
57  if (!tmpDet) {
58  edm::LogVerbatim("CosmicParametersDefinerForTP")
59  << "***WARNING in CosmicParametersDefinerForTP::momentum: no GeomDet "
60  "for: "
61  << it->detUnitId() << ". Skipping it."
62  << "\n";
63  continue;
64  }
65 
66  LocalVector lv = it->momentumAtEntry();
67  Local3DPoint lp = it->localPosition();
68  GlobalVector gv = tmpDet->surface().toGlobal(lv);
69  GlobalPoint gp = tmpDet->surface().toGlobal(lp);
70 
71  // discard hits related to low energy debris from the primary particle
72  if (it->processType() != 0)
73  continue;
74 
75  if (gp.perp() < radius) {
76  found = true;
77  radius = gp.perp();
78  finalGV = gv;
79  finalGP = gp;
80  }
81  }
82 
83  edm::LogVerbatim("CosmicParametersDefinerForTP")
84  // <<"\t FINAL State at InnerMost Hit: Radius = "<< finalGP.perp() << ",
85  // z = "<< finalGP.z()
86  // <<", pt = "<< finalGV.perp() << ", pz = "<< finalGV.z();
87  << "\t \t FINAL State at InnerMost Hit: pt = " << finalGV.perp() << ", pz = " << finalGV.z();
88 
89  if (found) {
90  FreeTrajectoryState ftsAtProduction(finalGP, finalGV, TrackCharge(tpr->charge()), &mf);
91  TSCBLBuilderNoMaterial tscblBuilder;
92  TrajectoryStateClosestToBeamLine tsAtClosestApproach =
93  tscblBuilder(ftsAtProduction, bs); // as in TrackProducerAlgorithm
94 
95  if (tsAtClosestApproach.isValid()) {
96  GlobalVector p = tsAtClosestApproach.trackStateAtPCA().momentum();
97  momentum = TrackingParticle::Vector(p.x(), p.y(), p.z());
98  } else {
99  edm::LogVerbatim("CosmicParametersDefinerForTP") << "*** WARNING in CosmicParametersDefinerForTP::momentum: "
100  "tsAtClosestApproach is not valid."
101  << "\n";
102  }
103 
104  edm::LogVerbatim("CosmicParametersDefinerForTP")
105  << "\t \t FINAL State extrap. at PCA: pt = " << sqrt(momentum.x() * momentum.x() + momentum.y() * momentum.y())
106  << ", pz = " << momentum.z() << "\n";
107 
108  return momentum;
109  }
110 
111  edm::LogVerbatim("CosmicParametersDefinerForTP")
112  << "*** WARNING in CosmicParametersDefinerForTP::momentum: NOT found the "
113  "innermost TP point"
114  << "\n";
115  edm::LogVerbatim("CosmicParametersDefinerForTP")
116  << "*** FINAL Reference MOMENTUM TP (px,py,pz) = " << momentum.x() << momentum.y() << momentum.z() << "\n";
117  return momentum;
118 }
119 
121  const edm::EventSetup &iSetup,
122  const TrackingParticleRef &tpr) const {
123  using namespace edm;
124  using namespace std;
125  using namespace reco;
126 
127  auto const &bs = iEvent.get(bsToken_);
128  auto const &geometry = iSetup.getData(geometryToken_);
129  auto const &mf = iSetup.getData(mfToken_);
130 
131  GlobalVector finalGV(0, 0, 0);
132  GlobalPoint finalGP(0, 0, 0);
133  double radius(9999);
134  bool found(false);
136 
137  edm::LogVerbatim("CosmicParametersDefinerForTP") << "\t in CosmicParametersDefinerForTP::vertex";
138  edm::LogVerbatim("CosmicParametersDefinerForTP")
139  << "\t \t Original TP state: radius = "
140  << sqrt(tpr->vertex().x() * tpr->vertex().x() + tpr->vertex().y() * tpr->vertex().y())
141  << ", z = " << tpr->vertex().z();
142 
143  if (simHitsTPAssoc.isValid() == 0) {
144  LogError("TrackAssociation") << "Invalid handle!";
145  return vertex;
146  }
147  std::pair<TrackingParticleRef, TrackPSimHitRef> clusterTPpairWithDummyTP(
148  tpr,
149  TrackPSimHitRef()); // SimHit is dummy: for simHitTPAssociationListGreater
150  // sorting only the cluster is needed
151  auto range = std::equal_range(simHitsTPAssoc->begin(),
152  simHitsTPAssoc->end(),
153  clusterTPpairWithDummyTP,
155  for (auto ip = range.first; ip != range.second; ++ip) {
156  TrackPSimHitRef it = ip->second;
157  const GeomDet *tmpDet = geometry.idToDet(DetId(it->detUnitId()));
158  if (!tmpDet) {
159  edm::LogVerbatim("CosmicParametersDefinerForTP")
160  << "***WARNING in CosmicParametersDefinerForTP::vertex: no GeomDet "
161  "for: "
162  << it->detUnitId() << ". Skipping it."
163  << "\n";
164  continue;
165  }
166 
167  LocalVector lv = it->momentumAtEntry();
168  Local3DPoint lp = it->localPosition();
169  GlobalVector gv = tmpDet->surface().toGlobal(lv);
170  GlobalPoint gp = tmpDet->surface().toGlobal(lp);
171 
172  // discard hits related to low energy debris from the primary particle
173  if (it->processType() != 0)
174  continue;
175 
176  if (gp.perp() < radius) {
177  found = true;
178  radius = gp.perp();
179  finalGV = gv;
180  finalGP = gp;
181  }
182  }
183  edm::LogVerbatim("CosmicParametersDefinerForTP")
184  << "\t \t FINAL State at InnerMost Hit: radius = " << finalGP.perp() << ", z = " << finalGP.z();
185 
186  if (found) {
187  FreeTrajectoryState ftsAtProduction(finalGP, finalGV, TrackCharge(tpr->charge()), &mf);
188  TSCBLBuilderNoMaterial tscblBuilder;
189  TrajectoryStateClosestToBeamLine tsAtClosestApproach =
190  tscblBuilder(ftsAtProduction, bs); // as in TrackProducerAlgorithm
191 
192  if (tsAtClosestApproach.isValid()) {
193  GlobalPoint v = tsAtClosestApproach.trackStateAtPCA().position();
194  vertex = TrackingParticle::Point(v.x(), v.y(), v.z());
195  } else {
196  // to preserve old behaviour
197  // would be better to flag this somehow to allow ignoring in downstream
198  vertex = TrackingParticle::Point(bs.x0(), bs.y0(), bs.z0());
199  edm::LogVerbatim("CosmicParametersDefinerForTP") << "*** WARNING in CosmicParametersDefinerForTP::vertex: "
200  "tsAtClosestApproach is not valid."
201  << "\n";
202  }
203  edm::LogVerbatim("CosmicParametersDefinerForTP")
204  << "\t \t FINAL State extrap. at PCA: radius = " << sqrt(vertex.x() * vertex.x() + vertex.y() * vertex.y())
205  << ", z = " << vertex.z() << "\n";
206 
207  return vertex;
208  }
209 
210  edm::LogVerbatim("CosmicParametersDefinerForTP")
211  << "*** WARNING in CosmicParametersDefinerForTP::vertex: NOT found the "
212  "innermost TP point"
213  << "\n";
214  edm::LogVerbatim("CosmicParametersDefinerForTP")
215  << "*** FINAL Reference VERTEX TP V(x,y,z) = " << vertex.x() << vertex.y() << vertex.z() << "\n";
216 
217  return vertex;
218 }
Log< level::Info, true > LogVerbatim
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:79
T perp() const
Definition: PV3DBase.h:69
static bool simHitTPAssociationListGreater(SimHitTPPair i, SimHitTPPair j)
TrackingParticle::Vector momentum(const edm::Event &iEvent, const edm::EventSetup &iSetup, const TrackingParticleRef &tpr) const override
T y() const
Definition: PV3DBase.h:60
const edm::EDGetTokenT< reco::BeamSpot > bsToken_
Log< level::Error, false > LogError
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
const uint16_t range(const Frame &aFrame)
math::XYZPointD Point
point in the space
bool getData(T &iHolder) const
Definition: EventSetup.h:128
int TrackCharge
Definition: TrackCharge.h:4
int iEvent
Definition: GenABIO.cc:224
CosmicParametersDefinerForTP(edm::ConsumesCollector iC)
T sqrt(T t)
Definition: SSEVec.h:19
T z() const
Definition: PV3DBase.h:61
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:346
bool isValid() const
Definition: HandleBase.h:70
const edm::ESGetToken< GlobalTrackingGeometry, GlobalTrackingGeometryRecord > geometryToken_
GlobalVector momentum() const
Definition: DetId.h:17
GlobalPoint position() const
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > mfToken_
~CosmicParametersDefinerForTP() override
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:59
edm::Handle< SimHitTPAssociationProducer::SimHitTPAssociationList > simHitsTPAssoc
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283