Belle II Software development
CDCCKFEclSeedCreator.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#include <tracking/ckf/cdc/findlets/CDCCKFEclSeedCreator.h>
9
10#include <tracking/trackFindingCDC/utilities/StringManipulation.h>
11
12#include <tracking/dataobjects/RecoTrack.h>
13#include <tracking/ckf/cdc/entities/CDCCKFState.h>
14
15#include <framework/core/ModuleParamList.h>
16
17#include <ecl/dataobjects/ECLShower.h>
18
19#include <framework/gearbox/Const.h>
20#include <framework/geometry/VectorUtil.h>
21
22using namespace Belle2;
23
28
29void CDCCKFEclSeedCreator::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
30{
31 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "inputECLshowersStoreArrayName"),
33 "StoreArray name of the input Shower Store Array.");
34
35 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "eclSeedRecoTrackStoreArrayName"),
37 "StoreArray name of the output Track Store Array.");
38
39 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "minimalEnRequirementCluster"),
41 "Minimal energy requirement for the input clusters",
43
44 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "restrictToForwardSeeds"),
46 "Don't do Ecl seeding in central region to save computing time",
48
49 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "tanLambdaForwardNeg"),
51 "Up to which (neg) tanLambda value should the seeding be performed",
53
54 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "tanLambdaForwardPos"),
56 "Up to which (pos) tanLambda value should the seeding be performed",
58
59 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "showerDepth"),
61 "Don't do Ecl seeding in central region to save computing time",
63}
64
76
77void CDCCKFEclSeedCreator::apply(std::vector<CDCCKFPath>& seeds)
78{
79 // loop over all showers and create seed objects
80 for (auto& shower : m_inputECLshowers) {
81 if (shower.getHypothesisId() != ECLShower::c_nPhotons) {
82 continue;
83 }
84
85 const double Eclus = shower.getEnergy();
86 if (Eclus < m_param_minimalEnRequirement) {
87 continue;
88 }
89
90 // Get shower position, momentum
91 const double thetaClus = shower.getTheta();
92 const double phiClus = shower.getPhi();
93 const double rClus = shower.getR();
94
95 const double sinTheta = sin(thetaClus);
96 const double cosTheta = cos(thetaClus);
97 const double sinPhi = sin(phiClus);
98 const double cosPhi = cos(phiClus);
99
100 ROOT::Math::XYZVector pos(rClus * sinTheta * cosPhi, rClus * sinTheta * sinPhi, rClus * cosTheta);
101 const double tanLambda = pos.Z() / pos.Rho();
102
103 // restrict to forward seeds
105 if (tanLambda > m_param_tanLambdaForwardNeg && tanLambda < m_param_tanLambdaForwardPos) {
106 continue;
107 }
108 }
109
110 // Correction if shower is assumed to start in a certain depth
111 pos = pos - m_param_showerDepth / pos.R() * pos;
112
113 ROOT::Math::XYZVector mom = Eclus / pos.R() * pos;
114
115 // Calculate helix trajectory for negative and positive charge seeds
116 // Find center of circular trajectory
117 // factor 1. for charge // speed of light in [cm per ns] // const magnetic field
118 double rad = std::abs(mom.Rho() / (Const::speedOfLight * 1e-4 * 1. * 1.5));
119
120 // Particle would not be able to reach ECL (underestimation of shower energy)
121 if (2. * rad < pos.Rho()) {
122 rad = pos.Rho() / 2.0 + 1.0;
123 }
124
125 // Use pq formula (center of circle has to be on perpendicular line through center of line between (0,0) and seed position)
126 double q = pos.Rho();
127 double y3 = pos.Y() / 2.0;
128 double x3 = pos.X() / 2.0;
129
130 double basex = sqrt(rad * rad - q * q / 4.0) * (-pos.Y()) / q;
131 double basey = sqrt(rad * rad - q * q / 4.0) * pos.X() / q;
132
133 double centerx1 = x3 + basex;
134 double centery1 = y3 + basey;
135 double centerx2 = x3 - basex;
136 double centery2 = y3 - basey;
137
138 // vectors for tangent at seed position (perpendicular to radius at seed position)
139 double momx1 = pos.Y() - centery1;
140 double momy1 = - (pos.X() - centerx1);
141 double momx2 = pos.Y() - centery2;
142 double momy2 = - (pos.X() - centerx2);
143
144 // two solutions (pointing toward and away from center)
145 // make sure that particle moves inwards
146 if (momx1 * pos.X() + momy1 * pos.Y() < 0) {
147 momx1 = -momx1;
148 momy1 = -momy1;
149 }
150 if (momx2 * pos.X() + momy2 * pos.Y() < 0) {
151 momx2 = -momx2;
152 momy2 = -momy2;
153 }
154
155 // scale to unit length
156 double mom1abs = sqrt(momx1 * momx1 + momy1 * momy1);
157 double mom2abs = sqrt(momx2 * momx2 + momy2 * momy2);
158 momx1 = momx1 / mom1abs;
159 momy1 = momy1 / mom1abs;
160 momx2 = momx2 / mom2abs;
161 momy2 = momy2 / mom2abs;
162
163 ROOT::Math::XYZVector mom1(momx1 * mom.Rho(), momy1 * mom.Rho(), mom.Z());
164 ROOT::Math::XYZVector mom2(momx2 * mom.Rho(), momy2 * mom.Rho(), mom.Z());
165
166 // Pick the right momentum for positive/negative charge
167 // Use cross product if momentum vector is (counter)clockwise wrt position vector
168 bool clockwise1 = true;
169 bool clockwise2 = true;
170 if (pos.Y() * mom1.X() - pos.X() * mom1.Y() > 0) {
171 clockwise1 = false;
172 }
173 if (pos.Y() * mom2.X() - pos.X() * mom2.Y() > 0) {
174 clockwise2 = false;
175 }
176
177 if (clockwise1 == clockwise2) {
178 B2WARNING("Something went wrong during helix extrapolation. Skipping track.");
179 continue;
180 }
181
182 ROOT::Math::XYZVector mompos;
183 ROOT::Math::XYZVector momneg;
184 if (clockwise1) {
185 mompos = mom2;
186 momneg = mom1;
187 } else {
188 mompos = mom1;
189 momneg = mom2;
190 }
191
192 // electron and positron hypothesis
193 RecoTrack* eclSeedNeg = m_eclSeedRecoTracks.appendNew(pos, momneg, -1);
194 eclSeedNeg->addRelationTo(&shower);
195 RecoTrack* eclSeedPos = m_eclSeedRecoTracks.appendNew(pos, mompos, +1);
196 eclSeedPos->addRelationTo(&shower);
197
198 // define MeasuredStateOnPlane (use pion hypothesis)
199 genfit::AbsTrackRep* repNeg = RecoTrackGenfitAccess::createOrReturnRKTrackRep(*eclSeedNeg, -Const::pion.getPDGCode());
200 genfit::MeasuredStateOnPlane msopNeg(repNeg);
201 genfit::AbsTrackRep* repPos = RecoTrackGenfitAccess::createOrReturnRKTrackRep(*eclSeedPos, Const::pion.getPDGCode());
202 genfit::MeasuredStateOnPlane msopPos(repPos);
203
204 // set position, momentum, cov, sharedPlanePtr
205 TMatrixDSym cov(6);
206 double covArray[6];
207 shower.getCovarianceMatrixAsArray(covArray);
208
209 // Calculate uncertainties on position from ECLShower
210 double dx2 = rClus * cosTheta * cosPhi * rClus * cosTheta * cosPhi * covArray[5]
211 + rClus * sinTheta * sinPhi * rClus * sinTheta * sinPhi * covArray[2];
212 double dy2 = rClus * cosTheta * sinPhi * rClus * cosTheta * sinPhi * covArray[5]
213 + rClus * sinTheta * cosPhi * rClus * sinTheta * cosPhi * covArray[2];
214 double dz2 = rClus * sinTheta * rClus * sinTheta * covArray[5];
215
216 double dpx2 = std::abs(mom1.X() - mom2.X()) / 4.0 * std::abs(mom1.X() - mom2.X()) / 4.0;
217 double dpy2 = std::abs(mom1.Y() - mom2.Y()) / 4.0 * std::abs(mom1.Y() - mom2.Y()) / 4.0;
218 double dpz2 = 0.25 * 0.25 * mom.Z() * mom.Z();
219
220 cov(0, 0) = dx2;
221 cov(1, 1) = dy2;
222 cov(2, 2) = dz2;
223 cov(3, 3) = dpx2;
224 cov(4, 4) = dpy2;
225 cov(5, 5) = dpz2;
226
227 // set properties of genfit objects
228 genfit::SharedPlanePtr planeNeg(new genfit::DetPlane(XYZToTVector(pos), XYZToTVector(pos)));
229 genfit::SharedPlanePtr planePos(new genfit::DetPlane(XYZToTVector(pos), XYZToTVector(pos)));
230 msopNeg.setPosMomCov(XYZToTVector(pos), XYZToTVector(momneg), cov);
231 msopNeg.setPlane(planeNeg);
232 msopPos.setPosMomCov(XYZToTVector(pos), XYZToTVector(mompos), cov);
233 msopPos.setPlane(planePos);
234
235 // create CDCCKF states
236 CDCCKFState seedStateNeg(eclSeedNeg, msopNeg);
237 seeds.push_back({seedStateNeg});
238 CDCCKFState seedStatePos(eclSeedPos, msopPos);
239 seeds.push_back({seedStatePos});
240 }
241}
StoreArray< ECLShower > m_inputECLshowers
Input ECL Showers Store Array.
CDCCKFEclSeedCreator()
Add the subfindlets.
bool m_param_restrictToForwardSeeds
Don't do Ecl seeding in central region to save computing time.
void apply(std::vector< CDCCKFPath > &seeds) override
Load in the reco tracks and the hits.
double m_param_minimalEnRequirement
Minimal pt requirement.
void initialize() override
Create the store arrays.
std::string m_param_inputEclShowerStoreArrayName
StoreArray name of the input Ecl Shower Store Array.
std::string m_param_eclSeedRecoTrackStoreArrayName
StoreArray name of the output Track Store Array.
StoreArray< RecoTrack > m_eclSeedRecoTracks
Output Reco Tracks Store Array.
double m_param_tanLambdaForwardNeg
Up to which (neg) tanLambda value should the seeding be performed.
double m_param_tanLambdaForwardPos
Up to which (pos) tanLambda value should the seeding be performed.
TrackFindingCDC::Findlet< CDCCKFPath > Super
Parent class.
double m_param_showerDepth
Correction if the shower is assumed to start in a certain depth.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) override
Expose the parameters of the sub findlets.
Define states for CKF algorithm, which can be seed track or CDC wire hit.
Definition CDCCKFState.h:24
static const ChargedStable pion
charged pion particle
Definition Const.h:661
static const double speedOfLight
[cm/ns]
Definition Const.h:695
@ c_nPhotons
CR is split into n photons (N1)
Definition ECLShower.h:42
The Module parameter list class.
static genfit::AbsTrackRep * createOrReturnRKTrackRep(RecoTrack &recoTrack, int PDGcode)
Checks if a TrackRap for the PDG id of the RecoTrack (and its charge conjugate) does already exit and...
Definition RecoTrack.cc:409
This is the Reconstruction Event-Data Model Track.
Definition RecoTrack.h:79
static void registerRequiredRelations(StoreArray< RecoTrack > &recoTracks, std::string const &pxdHitsStoreArrayName="", std::string const &svdHitsStoreArrayName="", std::string const &cdcHitsStoreArrayName="", std::string const &bklmHitsStoreArrayName="", std::string const &eklmHitsStoreArrayName="", std::string const &recoHitInformationStoreArrayName="")
Convenience method which registers all relations required to fully use a RecoTrack.
Definition RecoTrack.cc:53
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).
static constexpr auto XYZToTVector
Helper function to convert XYZVector to TVector3.
Definition VectorUtil.h:24
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
double sqrt(double a)
sqrt for double
Definition beamHelpers.h:28
Abstract base class for different kinds of events.