Belle II Software  release-08-01-10
ECLClusterPropertiesModule.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 
9 /* Own header. */
10 #include <ecl/modules/eclClusterProperties/ECLClusterPropertiesModule.h>
11 
12 /* ECL headers. */
13 #include <ecl/geometry/ECLGeometryPar.h>
14 
15 /* Basf2 headers. */
16 #include <framework/geometry/VectorUtil.h>
17 
18 /* ROOT headers. */
19 #include <Math/Vector3D.h>
20 
21 using namespace Belle2;
22 using namespace ECL;
23 
24 //-----------------------------------------------------------------
25 // Register the Module
26 //-----------------------------------------------------------------
27 REG_MODULE(ECLClusterProperties);
28 
29 //-----------------------------------------------------------------
30 // Implementation
31 //-----------------------------------------------------------------
32 
34 {
35  // Set module properties
36  setDescription("This module calculates some properties of ECL clusters.");
38  // Parameter definitions
39  addParam("trackClusterRelationName", m_trackClusterRelationName, "Name of relation array between tracks and ECL clusters",
40  std::string("AngularDistance"));
41 }
42 
44 {
45 }
46 
48 {
49  m_tracks.isRequired();
50  m_eclShowers.isRequired();
51  m_eclClusters.isRequired();
52  m_eclCalDigits.isRequired();
53  m_extHits.isRequired();
54 }
55 
57 {
58  for (auto& shower : m_eclShowers) {
59  // compute the distance from shower COG and the closest extrapolated track
60  unsigned short trackID = std::numeric_limits<unsigned short>::max();
61  double dist = computeTrkMinDistance(shower, m_tracks, trackID);
62  shower.setMinTrkDistance(dist);
63  ECLCluster* cluster = shower.getRelatedFrom<ECLCluster>();
64  if (cluster != nullptr) {
65  cluster->setMinTrkDistance(float(dist));
66  cluster->setMinTrkDistanceID(trackID);
67  // compute path lenghts on the energy weighted average crystals
68  // direction and on the extrapolated track direction corresponding to
69  // the minimum distance among the two lines. if more than one track is
70  // related to a cluster the one with the highest momentum is used
71  if (cluster->isTrack()) {
72  double lTrk, lShower;
73  computeDepth(shower, lTrk, lShower);
74  B2DEBUG(29, "shower depth: ltrk = " << lTrk << " lShower = " << lShower);
75  shower.setTrkDepth(lTrk);
76  shower.setShowerDepth(lShower);
77  cluster->setdeltaL(lTrk);
78  }
79  }
80  }
81 }
82 
84  unsigned short& trackID) const
85 {
86  double minDist(10000);
87  ROOT::Math::XYZVector cryCenter;
88  VectorUtil::setMagThetaPhi(
89  cryCenter, shower.getR(), shower.getTheta(), shower.getPhi());
90  Const::ChargedStable hypothesis = Const::pion;
91  int pdgCode = abs(hypothesis.getPDGCode());
92  for (const auto& track : tracks) {
93  ROOT::Math::XYZVector trkpos;
94  for (const auto& extHit : track.getRelationsTo<ExtHit>()) {
95  if (abs(extHit.getPdgCode()) != pdgCode) continue;
96  if ((extHit.getDetectorID() != Const::EDetector::ECL)) continue;
97  if (extHit.getCopyID() == -1) continue;
98  trkpos = extHit.getPosition();
99  double distance = (cryCenter - trkpos).R();
100  if (distance < minDist) {
101  trackID = track.getArrayIndex();
102  minDist = distance;
103  }
104  }
105  }
106  if (minDist > 9999) minDist = -1;
107  return minDist;
108 }
109 
110 void ECLClusterPropertiesModule::computeDepth(const ECLShower& shower, double& lTrk, double& lShower) const
111 {
112  lTrk = 0;
113  lShower = 0;
115  ROOT::Math::XYZVector avgDir(0, 0, 0), showerCenter, trkpos, trkdir;
116  VectorUtil::setMagThetaPhi(
117  showerCenter, shower.getR(), shower.getTheta(), shower.getPhi());
118 
119  auto relatedDigitsPairs = shower.getRelationsTo<ECLCalDigit>();
120  for (unsigned int iRel = 0; iRel < relatedDigitsPairs.size(); iRel++) {
121  const auto aECLCalDigit = relatedDigitsPairs.object(iRel);
122  const auto weight = relatedDigitsPairs.weight(iRel);
123  double energy = weight * aECLCalDigit->getEnergy();
124  int cellid = aECLCalDigit->getCellId();
125  ROOT::Math::XYZVector cvec = geometry->GetCrystalVec(cellid - 1);
126  avgDir += energy * cvec;
127  }
128  const ECLCluster* cluster = shower.getRelatedFrom<ECLCluster>();
129  if (cluster == nullptr) return;
130  const Track* selectedTrk = nullptr;
131  double p = 0;
132  for (const auto& track : cluster->getRelationsFrom<Track>("", m_trackClusterRelationName)) {
133  const TrackFitResult* fit = track.getTrackFitResultWithClosestMass(Const::pion);
134  double cp = 0;
135  if (fit != 0) cp = fit->getMomentum().R();
136  if (cp > p) {
137  selectedTrk = &track;
138  p = cp;
139  }
140  }
141  if (selectedTrk == nullptr) return;
142  bool found(false);
143  for (const auto& extHit : selectedTrk->getRelationsTo<ExtHit>()) {
144  if ((extHit.getDetectorID() != Const::EDetector::ECL)) continue;
145  if (extHit.getStatus() != EXT_ENTER) continue;
146  if (extHit.getCopyID() == -1) continue;
147  trkpos = extHit.getPosition();
148  trkdir = extHit.getMomentum().Unit();
149  found = true;
150  break;
151  }
152  if (!found) return;
153  ROOT::Math::XYZVector w0 = showerCenter - trkpos;
154  double costh = avgDir.Unit().Dot(trkdir);
155  double sin2th = 1 - costh * costh;
156  lShower = costh * w0.Dot(trkdir) - w0.Dot(avgDir.Unit());
157  lShower /= sin2th;
158 
159  lTrk = w0.Dot(trkdir) - costh * w0.Dot(avgDir.Unit());
160  lTrk /= sin2th;
161 }
double R
typedef autogenerated by FFTW
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:580
int getPDGCode() const
PDG code.
Definition: Const.h:464
static const ChargedStable pion
charged pion particle
Definition: Const.h:652
Class to store calibrated ECLDigits: ECLCalDigits.
Definition: ECLCalDigit.h:23
std::string m_trackClusterRelationName
name of relation array between tracks and ECL clusters
StoreArray< ECLShower > m_eclShowers
Required input array of ECLShowers.
virtual void initialize() override
Initialize the required input arrays.
virtual void event() override
Event loop.
void computeDepth(const ECLShower &shower, double &lTrk, double &lShower) const
Computation of depths / distances.
StoreArray< Track > m_tracks
Required input array of Tracks.
StoreArray< ECLCluster > m_eclClusters
Required input array of ECLClusters.
double computeTrkMinDistance(const ECLShower &, StoreArray< Track > &, unsigned short &trackID) const
Minimal distance between track and shower.
ECLClusterPropertiesModule()
Constructor: Sets the description, the properties and the parameters of the module.
StoreArray< ExtHit > m_extHits
Required input array of ExtHits.
StoreArray< ECLCalDigit > m_eclCalDigits
Required input array of ECLCalDigits.
ECL cluster data.
Definition: ECLCluster.h:27
Class to store ECL Showers.
Definition: ECLShower.h:30
double getPhi() const
Get Phi.
Definition: ECLShower.h:302
double getR() const
Get R.
Definition: ECLShower.h:307
double getTheta() const
Get Theta.
Definition: ECLShower.h:297
The Class for ECL Geometry Parameters.
static ECLGeometryPar * Instance()
Static method to get a reference to the ECLGeometryPar instance.
Store one Ext hit as a ROOT object.
Definition: ExtHit.h:32
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
RelationVector< TO > getRelationsTo(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from this object to another store array.
FROM * getRelatedFrom(const std::string &name="", const std::string &namedRelation="") const
Get the object from which this object has a relation.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
Values of the result of a track fit with a given particle hypothesis.
Class that bundles various TrackFitResults.
Definition: Track.h:25
REG_MODULE(arichBtest)
Register the Module.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
Abstract base class for different kinds of events.