Belle II Software  release-05-02-19
ECLClusterPropertiesModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2018 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Frank Meier *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <ecl/modules/eclClusterProperties/ECLClusterPropertiesModule.h>
12 #include <ecl/geometry/ECLGeometryPar.h>
13 
14 using namespace Belle2;
15 using namespace ECL;
16 
17 //-----------------------------------------------------------------
18 // Register the Module
19 //-----------------------------------------------------------------
20 REG_MODULE(ECLClusterProperties)
21 
22 //-----------------------------------------------------------------
23 // Implementation
24 //-----------------------------------------------------------------
25 
27 {
28  // Set module properties
29  setDescription("This module calculates some properties of ECL clusters.");
30  setPropertyFlags(c_ParallelProcessingCertified);
31  // Parameter definitions
32  addParam("trackClusterRelationName", m_trackClusterRelationName, "Name of relation array between tracks and ECL clusters",
33  std::string("AngularDistance"));
34 }
35 
37 {
38 }
39 
41 {
42  m_tracks.isRequired();
43  m_eclShowers.isRequired();
44  m_eclClusters.isRequired();
45  m_eclCalDigits.isRequired();
46  m_extHits.isRequired();
47 }
48 
50 {
51  for (auto& shower : m_eclShowers) {
52  // compute the distance from shower COG and the closest extrapolated track
53  double dist = computeTrkMinDistance(shower, m_tracks);
54  shower.setMinTrkDistance(dist);
55  ECLCluster* cluster = shower.getRelatedFrom<ECLCluster>();
56  if (cluster != nullptr) {
57  cluster->setMinTrkDistance(float(dist));
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 {
76  double minDist(10000);
77  TVector3 cryCenter;
78  cryCenter.SetMagThetaPhi(shower.getR(), shower.getTheta(), shower.getPhi());
79  Const::ChargedStable hypothesis = Const::pion;
80  int pdgCode = abs(hypothesis.getPDGCode());
81  for (const auto& track : tracks) {
82  TVector3 trkpos(0, 0, 0);
83  for (const auto& extHit : track.getRelationsTo<ExtHit>()) {
84  if (abs(extHit.getPdgCode()) != pdgCode) continue;
85  if ((extHit.getDetectorID() != Const::EDetector::ECL)) continue;
86  if (extHit.getCopyID() == -1) continue;
87  trkpos = extHit.getPosition();
88  double distance = (cryCenter - trkpos).Mag();
89  if (distance < minDist) minDist = distance;
90  }
91  }
92  if (minDist > 9999) minDist = -1;
93  return minDist;
94 }
95 
96 void ECLClusterPropertiesModule::computeDepth(const ECLShower& shower, double& lTrk, double& lShower) const
97 {
98  lTrk = 0;
99  lShower = 0;
101  TVector3 avgDir(0, 0, 0), showerCenter, trkpos, trkdir;
102  showerCenter.SetMagThetaPhi(shower.getR(), shower.getTheta(), shower.getPhi());
103 
104  auto relatedDigitsPairs = shower.getRelationsTo<ECLCalDigit>();
105  for (unsigned int iRel = 0; iRel < relatedDigitsPairs.size(); iRel++) {
106  const auto aECLCalDigit = relatedDigitsPairs.object(iRel);
107  const auto weight = relatedDigitsPairs.weight(iRel);
108  double energy = weight * aECLCalDigit->getEnergy();
109  int cellid = aECLCalDigit->getCellId();
110  TVector3 cvec = geometry->GetCrystalVec(cellid - 1);
111  avgDir += energy * cvec;
112  }
113  const ECLCluster* cluster = shower.getRelatedFrom<ECLCluster>();
114  if (cluster == nullptr) return;
115  const Track* selectedTrk = nullptr;
116  double p = 0;
117  for (const auto& track : cluster->getRelationsFrom<Track>("", m_trackClusterRelationName)) {
118  const TrackFitResult* fit = track.getTrackFitResultWithClosestMass(Const::pion);
119  double cp = 0;
120  if (fit != 0) cp = fit->getMomentum().Mag();
121  if (cp > p) {
122  selectedTrk = &track;
123  p = cp;
124  }
125  }
126  if (selectedTrk == nullptr) return;
127  bool found(false);
128  for (const auto& extHit : selectedTrk->getRelationsTo<ExtHit>()) {
129  if ((extHit.getDetectorID() != Const::EDetector::ECL)) continue;
130  if (extHit.getStatus() != EXT_ENTER) continue;
131  if (extHit.getCopyID() == -1) continue;
132  trkpos = extHit.getPosition();
133  trkdir = extHit.getMomentum().Unit();
134  found = true;
135  break;
136  }
137  if (!found) return;
138  TVector3 w0 = showerCenter - trkpos;
139  double costh = avgDir.Unit() * trkdir;
140  double sin2th = 1 - costh * costh;
141  lShower = costh * (w0 * trkdir) - w0 * avgDir.Unit();
142  lShower /= sin2th;
143 
144  lTrk = w0 * trkdir - costh * (w0 * avgDir.Unit());
145  lTrk /= sin2th;
146 }
Belle2::ECLClusterPropertiesModule
This module calculates some properties of ECL clusters.
Definition: ECLClusterPropertiesModule.h:43
Belle2::ECLCalDigit
Class to store calibrated ECLDigits: ECLCalDigits.
Definition: ECLCalDigit.h:38
Belle2::ECLCluster
ECL cluster data.
Definition: ECLCluster.h:39
Belle2::ECLShower::getTheta
double getTheta() const
Get Theta.
Definition: ECLShower.h:296
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::Const::ParticleType::getPDGCode
int getPDGCode() const
PDG code.
Definition: Const.h:349
Belle2::ECLClusterPropertiesModule::event
virtual void event() override
Event loop.
Definition: ECLClusterPropertiesModule.cc:49
Belle2::ECLClusterPropertiesModule::computeTrkMinDistance
double computeTrkMinDistance(const ECLShower &, StoreArray< Track > &) const
Minimal distance between track and shower.
Definition: ECLClusterPropertiesModule.cc:74
Belle2::TrackFitResult
Values of the result of a track fit with a given particle hypothesis.
Definition: TrackFitResult.h:59
Belle2::RelationsInterface::getRelationsTo
RelationVector< TO > getRelationsTo(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from this object to another store array.
Definition: RelationsObject.h:199
Belle2::ECLClusterPropertiesModule::initialize
virtual void initialize() override
Initialize the required input arrays.
Definition: ECLClusterPropertiesModule.cc:40
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::ECL::ECLGeometryPar::Instance
static ECLGeometryPar * Instance()
Static method to get a reference to the ECLGeometryPar instance.
Definition: ECLGeometryPar.cc:151
Belle2::Const::pion
static const ChargedStable pion
charged pion particle
Definition: Const.h:535
Belle2::ECLShower::getPhi
double getPhi() const
Get Phi.
Definition: ECLShower.h:301
Belle2::ExtHit
Store one Ext hit as a ROOT object.
Definition: ExtHit.h:40
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::Const::ChargedStable
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:465
Belle2::ECL::ECLGeometryPar
The Class for ECL Geometry Parameters.
Definition: ECLGeometryPar.h:45
Belle2::ECLClusterPropertiesModule::~ECLClusterPropertiesModule
virtual ~ECLClusterPropertiesModule()
Destructor.
Definition: ECLClusterPropertiesModule.cc:36
Belle2::Track
Class that bundles various TrackFitResults.
Definition: Track.h:35
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
Belle2::ECLShower::getR
double getR() const
Get R.
Definition: ECLShower.h:306
Belle2::ECLClusterPropertiesModule::computeDepth
void computeDepth(const ECLShower &shower, double &lTrk, double &lShower) const
Computation of depths / distances.
Definition: ECLClusterPropertiesModule.cc:96
Belle2::RelationsInterface::getRelatedFrom
FROM * getRelatedFrom(const std::string &name="", const std::string &namedRelation="") const
Get the object from which this object has a relation.
Definition: RelationsObject.h:265
Belle2::ECLShower
Class to store ECL Showers.
Definition: ECLShower.h:42