Belle II Software  release-06-02-00
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 #include <ecl/modules/eclClusterProperties/ECLClusterPropertiesModule.h>
10 #include <ecl/geometry/ECLGeometryPar.h>
11 
12 using namespace Belle2;
13 using namespace ECL;
14 
15 //-----------------------------------------------------------------
16 // Register the Module
17 //-----------------------------------------------------------------
18 REG_MODULE(ECLClusterProperties)
19 
20 //-----------------------------------------------------------------
21 // Implementation
22 //-----------------------------------------------------------------
23 
25 {
26  // Set module properties
27  setDescription("This module calculates some properties of ECL clusters.");
28  setPropertyFlags(c_ParallelProcessingCertified);
29  // Parameter definitions
30  addParam("trackClusterRelationName", m_trackClusterRelationName, "Name of relation array between tracks and ECL clusters",
31  std::string("AngularDistance"));
32 }
33 
35 {
36 }
37 
39 {
40  m_tracks.isRequired();
41  m_eclShowers.isRequired();
42  m_eclClusters.isRequired();
43  m_eclCalDigits.isRequired();
44  m_extHits.isRequired();
45 }
46 
48 {
49  for (auto& shower : m_eclShowers) {
50  // compute the distance from shower COG and the closest extrapolated track
51  unsigned short trackID = std::numeric_limits<unsigned short>::max();
52  double dist = computeTrkMinDistance(shower, m_tracks, trackID);
53  shower.setMinTrkDistance(dist);
54  ECLCluster* cluster = shower.getRelatedFrom<ECLCluster>();
55  if (cluster != nullptr) {
56  cluster->setMinTrkDistance(float(dist));
57  cluster->setMinTrkDistanceID(trackID);
58  // compute path lenghts on the energy weighted average crystals
59  // direction and on the extrapolated track direction corresponding to
60  // the minimum distance among the two lines. if more than one track is
61  // related to a cluster the one with the highest momentum is used
62  if (cluster->isTrack()) {
63  double lTrk, lShower;
64  computeDepth(shower, lTrk, lShower);
65  B2DEBUG(29, "shower depth: ltrk = " << lTrk << " lShower = " << lShower);
66  shower.setTrkDepth(lTrk);
67  shower.setShowerDepth(lShower);
68  cluster->setdeltaL(lTrk);
69  }
70  }
71  }
72 }
73 
75  unsigned short& trackID) const
76 {
77  double minDist(10000);
78  TVector3 cryCenter;
79  cryCenter.SetMagThetaPhi(shower.getR(), shower.getTheta(), shower.getPhi());
80  Const::ChargedStable hypothesis = Const::pion;
81  int pdgCode = abs(hypothesis.getPDGCode());
82  for (const auto& track : tracks) {
83  TVector3 trkpos(0, 0, 0);
84  for (const auto& extHit : track.getRelationsTo<ExtHit>()) {
85  if (abs(extHit.getPdgCode()) != pdgCode) continue;
86  if ((extHit.getDetectorID() != Const::EDetector::ECL)) continue;
87  if (extHit.getCopyID() == -1) continue;
88  trkpos = extHit.getPosition();
89  double distance = (cryCenter - trkpos).Mag();
90  if (distance < minDist) {
91  trackID = track.getArrayIndex();
92  minDist = distance;
93  }
94  }
95  }
96  if (minDist > 9999) minDist = -1;
97  return minDist;
98 }
99 
100 void ECLClusterPropertiesModule::computeDepth(const ECLShower& shower, double& lTrk, double& lShower) const
101 {
102  lTrk = 0;
103  lShower = 0;
105  TVector3 avgDir(0, 0, 0), showerCenter, trkpos, trkdir;
106  showerCenter.SetMagThetaPhi(shower.getR(), shower.getTheta(), shower.getPhi());
107 
108  auto relatedDigitsPairs = shower.getRelationsTo<ECLCalDigit>();
109  for (unsigned int iRel = 0; iRel < relatedDigitsPairs.size(); iRel++) {
110  const auto aECLCalDigit = relatedDigitsPairs.object(iRel);
111  const auto weight = relatedDigitsPairs.weight(iRel);
112  double energy = weight * aECLCalDigit->getEnergy();
113  int cellid = aECLCalDigit->getCellId();
114  TVector3 cvec = geometry->GetCrystalVec(cellid - 1);
115  avgDir += energy * cvec;
116  }
117  const ECLCluster* cluster = shower.getRelatedFrom<ECLCluster>();
118  if (cluster == nullptr) return;
119  const Track* selectedTrk = nullptr;
120  double p = 0;
121  for (const auto& track : cluster->getRelationsFrom<Track>("", m_trackClusterRelationName)) {
122  const TrackFitResult* fit = track.getTrackFitResultWithClosestMass(Const::pion);
123  double cp = 0;
124  if (fit != 0) cp = fit->getMomentum().Mag();
125  if (cp > p) {
126  selectedTrk = &track;
127  p = cp;
128  }
129  }
130  if (selectedTrk == nullptr) return;
131  bool found(false);
132  for (const auto& extHit : selectedTrk->getRelationsTo<ExtHit>()) {
133  if ((extHit.getDetectorID() != Const::EDetector::ECL)) continue;
134  if (extHit.getStatus() != EXT_ENTER) continue;
135  if (extHit.getCopyID() == -1) continue;
136  trkpos = extHit.getPosition();
137  trkdir = extHit.getMomentum().Unit();
138  found = true;
139  break;
140  }
141  if (!found) return;
142  TVector3 w0 = showerCenter - trkpos;
143  double costh = avgDir.Unit() * trkdir;
144  double sin2th = 1 - costh * costh;
145  lShower = costh * (w0 * trkdir) - w0 * avgDir.Unit();
146  lShower /= sin2th;
147 
148  lTrk = w0 * trkdir - costh * (w0 * avgDir.Unit());
149  lTrk /= sin2th;
150 }
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:470
int getPDGCode() const
PDG code.
Definition: Const.h:354
static const ChargedStable pion
charged pion particle
Definition: Const.h:542
Class to store calibrated ECLDigits: ECLCalDigits.
Definition: ECLCalDigit.h:23
This module calculates some properties of ECL clusters.
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.
double computeTrkMinDistance(const ECLShower &, StoreArray< Track > &, unsigned short &trackID) const
Minimal distance between track and shower.
ECL cluster data.
Definition: ECLCluster.h:27
Class to store ECL Showers.
Definition: ECLShower.h:25
double getPhi() const
Get Phi.
Definition: ECLShower.h:284
double getR() const
Get R.
Definition: ECLShower.h:289
double getTheta() const
Get Theta.
Definition: ECLShower.h:279
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:30
Base class for Modules.
Definition: Module.h:72
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
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.