Belle II Software  release-08-01-10
ECLTrimShowersAndDigitsModule.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/eclTrimShowersAndDigits/ECLTrimShowersAndDigitsModule.h>
10 #include <mdst/dataobjects/ECLCluster.h>
11 #include <ecl/dataobjects/ECLCalDigit.h>
12 #include <ecl/dataobjects/ECLShower.h>
13 #include <mdst/dataobjects/MCParticle.h>
14 #include <framework/datastore/DataStore.h>
15 
16 #include <iostream>
17 
18 using namespace std;
19 using namespace Belle2;
20 
21 
22 //-----------------------------------------------------------------
23 //..Register the Module
24 REG_MODULE(ECLTrimShowersAndDigits);
25 
26 
27 //-----------------------------------------------------------------
28 //..Implementation
29 ECLTrimShowersAndDigitsModule::ECLTrimShowersAndDigitsModule() : Module()
30 {
31  // Set module properties
32  setDescription("Create trimmed ECLCalDigit and ECLShower dataobjects");
33 
34 }
35 
36 
37 //-----------------------------------------------------------------
38 //..Initialize
40 {
41 
42  //..Required data objects
43  m_eclClusterArray.isRequired();
44  m_eclShowerArray.isRequired();
45  m_eclCalDigitArray.isRequired();
46 
47  //..Define the reduced data objects
49  m_selectedShowers.inheritAllRelations();
50 
52  m_selectedDigits.inheritAllRelations();
53 }
54 
55 
56 //-----------------------------------------------------------------
57 //..Event
59 {
60 
61  //..ECLCluster containing the maximum MC true energy. Based on clusterTotalMCMatchWeight.
62  const int nCluster = m_eclClusterArray.getEntries();
63  double clusterMaxMCE = 0.;
64  maxCellID = 9999; // valid cellIDs are [0, 8735]
65  for (int i = 0; i < nCluster; i++) {
67 
68  const auto clusterMCRelations = m_eclClusterArray[i]->getRelationsWith<MCParticle>();
69  double mcE = 0.;
70  for (unsigned int ir = 0; ir < clusterMCRelations.size(); ++ir) {
71  mcE += clusterMCRelations.weight(ir);
72  }
73  if (mcE > clusterMaxMCE) {
74  clusterMaxMCE = mcE;
75  maxCellID = m_eclClusterArray[i]->getMaxECellId();
76  }
77  }
78  }
79 
80  //..Only interested in events with a single MCParticle; more than that means
81  // a conversion happened.
82  const int nMC = m_mcParticleArray.getEntries();
83  if (nMC != 1) {maxCellID = 9999;}
84 
85  //..Select the matching ECLShower
86  m_selectedShowers.select([this](const ECLShower * shower) {
87  return this->selectShower(shower);
88  });
89 
90  //..Select matching ECLCalDigits
91  m_selectedDigits.select([this](const ECLCalDigit * digit) {
92  return this->selectDigit(digit);
93  });
94 }
95 
96 //-----------------------------------------------------------------
97 //..Terminate
99 {
100 }
101 
102 //-----------------------------------------------------------------
103 //..Select the ECLShowers to keep
105 {
106  //..ECLShower must be a photon hypothesis and be related to correct ECLCluster
107  bool returnValue = false;
108  const auto clusterShowerRelations = shower->getRelationsWith<ECLCluster>();
109  if (clusterShowerRelations.size() > 0 and shower->getHypothesisId() == ECLShower::c_nPhotons) {
110  const auto cluster = clusterShowerRelations.object(0);
111  const unsigned short cellID = cluster->getMaxECellId();
112  if (cellID == maxCellID) {returnValue = true;}
113  }
114  return returnValue;
115 }
116 
117 //-----------------------------------------------------------------
118 //..Select the ECLCalDigits to keep
120 {
121  //..ECLCalDigit must be related to the correct ECLCluster (identified by cellID)
122  bool returnValue = false;
123  const auto clusterDigitRelations = digit->getRelationsWith<ECLCluster>();
124  for (unsigned int ir = 0; ir < clusterDigitRelations.size(); ++ir) {
125  const auto cluster = clusterDigitRelations.object(ir);
126  const unsigned short cellID = cluster->getMaxECellId();
127  if (cellID == maxCellID) {returnValue = true;}
128  }
129  return returnValue;
130 }
@ c_WriteOut
Object/array should be saved by output modules.
Definition: DataStore.h:70
Class to store calibrated ECLDigits: ECLCalDigits.
Definition: ECLCalDigit.h:23
ECL cluster data.
Definition: ECLCluster.h:27
@ c_nPhotons
CR is split into n photons (N1)
Class to store ECL Showers.
Definition: ECLShower.h:30
int getHypothesisId() const
Get Hypothesis Id.
Definition: ECLShower.h:277
@ c_nPhotons
CR is split into n photons (N1)
Definition: ECLShower.h:42
StoreArray< MCParticle > m_mcParticleArray
Array of MCParticles.
StoreArray< ECLShower > m_eclShowerArray
Array of ECLShowers.
std::string m_DigitArrayName
Name of new ECLCalDigit StoreArray.
virtual void initialize() override
Register input and output data.
StoreArray< ECLCluster > m_eclClusterArray
Array of ECLClusters.
bool selectShower(const ECLShower *shower)
keep the ECLShower or not
std::string m_ShowerArrayName
Name of new ECLShower StoreArray.
bool selectDigit(const ECLCalDigit *digit)
keep the ECLCalDigit or not
StoreArray< ECLCalDigit > m_eclCalDigitArray
Array of ECLCalDigits.
SelectSubset< ECLCalDigit > m_selectedDigits
selected ECLCalDigits
unsigned short maxCellID
used to identify the cluster of interest
SelectSubset< ECLShower > m_selectedShowers
selected ECLShowers
A Class to store the Monte Carlo particle information.
Definition: MCParticle.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
RelationVector< T > getRelationsWith(const std::string &name="", const std::string &namedRelation="") const
Get the relations between this object and another store array.
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
#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.