Belle II Software development
ReprocessorModule.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 <beast/analysis/modules/ReprocessorModule.h>
10
11#include <mdst/dataobjects/MCParticle.h>
12#include <framework/logging/Logger.h>
13
14#include <Math/Vector3D.h>
15
16//c++
17#include <string>
18
19using namespace std;
20using namespace Belle2;
21//using namespace reprocessor;
22
23//-----------------------------------------------------------------
24// Register the Module
25//-----------------------------------------------------------------
26REG_MODULE(Reprocessor);
27
28//-----------------------------------------------------------------
29// Implementation
30//-----------------------------------------------------------------
31
33{
34 // Set module properties
35 setDescription("Reprocessor module");
36
37 addParam("input_TPC_PDG", m_input_TPC_PDG, "Set the PDG particle to re-launch");
38 addParam("input_TPC_Ntimes", m_input_TPC_Ntimes, "Re-launch the PDG particle N times");
39 addParam("input_HE3_PDG", m_input_HE3_PDG, "Set the PDG particle to re-launch");
40 addParam("input_HE3_Ntimes", m_input_HE3_Ntimes, "Re-launch the PDG particle N times");
41}
42
44{
45}
46
48{
49 B2INFO("Reprocessor: Initializing");
50
52
53 m_evtMetaData.registerInDataStore();
54
55 MetaHits.isRequired();
56 mc_he3_parts.isOptional();
57 mc_tpc_parts.isOptional();
58}
59
61{
62}
63
65{
66 //skip events with no HE3G4 and TPCG4 particles stored
67 if (mc_he3_parts.getEntries() == 0 && mc_tpc_parts.getEntries() == 0 && m_input_TPC_Ntimes != 0 && m_input_HE3_Ntimes != 0) {
68 return;
69 }
70 if (mc_he3_parts.getEntries() == 0 && m_input_HE3_Ntimes != 0) {
71 return;
72 }
73 if (mc_tpc_parts.getEntries() == 0 && m_input_TPC_Ntimes != 0) {
74 return;
75 }
76
77 //Look at the meta data to extract IR rate and scattering ring section
78 double rate = 0;
79 for (const auto& MetaHit : MetaHits) {
80 rate = MetaHit.getrate();
81 }
82
83 if (m_input_HE3_Ntimes != 0 && m_input_TPC_Ntimes == 0) rate /= (double)m_input_HE3_Ntimes;
84 if (m_input_TPC_Ntimes != 0 && m_input_HE3_Ntimes == 0) rate /= (double)m_input_TPC_Ntimes;
85
86 // if not already existed, create MCParticles data store
87 StoreArray<MCParticle> MCParticles;
88 MCParticles.clear();
89
91 //evtMetaData.clear();
92 if (!evtMetaData.isValid()) evtMetaData.create();
93
94 if (m_input_TPC_Ntimes != 0) {
95 for (const auto& mcpart : mc_tpc_parts) { // start loop over all Tracks
96 const int PDG = mcpart.getPDG();
97 const double energy = mcpart.getEnergy();
98 ROOT::Math::XYZVector Momentum = mcpart.getMomentum();
99 ROOT::Math::XYZVector ProductionVertex = mcpart.getProductionVertex();
100 if (m_input_TPC_PDG == PDG) {
101 for (int i = 0; i < m_input_TPC_Ntimes; i ++) {
102 // store generated particle
103 MCParticle* particle = MCParticles.appendNew();
104 particle->setStatus(MCParticle::c_PrimaryParticle);
105 particle->setPDG(PDG);
106 particle->setMassFromPDG();
107 particle->setMomentum(ROOT::Math::XYZVector(Momentum));
108 particle->setProductionVertex(ROOT::Math::XYZVector(ProductionVertex));
109 particle->setProductionTime(0.0);
110 particle->setEnergy(energy);
111 particle->setValidVertex(true);
112 }
113 }
114 }
115 }
116
117 if (m_input_HE3_Ntimes != 0) {
118 for (const auto& mcpart : mc_he3_parts) { // start loop over all Tracks
119 const int PDG = mcpart.getPDG();
120 const double energy = mcpart.getEnergy();
121 ROOT::Math::XYZVector Momentum = mcpart.getMomentum();
122 ROOT::Math::XYZVector ProductionVertex = mcpart.getProductionVertex();
123 if (m_input_HE3_PDG == PDG) {
124 for (int i = 0; i < m_input_HE3_Ntimes; i ++) {
125 // store generated particle
126 MCParticle* particle = MCParticles.appendNew();
127 particle->setStatus(MCParticle::c_PrimaryParticle);
128 particle->setPDG(PDG);
129 particle->setMassFromPDG();
130 particle->setMomentum(ROOT::Math::XYZVector(Momentum));
131 particle->setProductionVertex(ROOT::Math::XYZVector(ProductionVertex));
132 particle->setProductionTime(0.0);
133 particle->setEnergy(energy);
134 particle->setValidVertex(true);
135 }
136 }
137 }
138 }
139
140 evtMetaData->setGeneratedWeight(rate);
141}
142
143
144
146{
147}
148
150{
151}
152
153
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
@ c_PrimaryParticle
bit 0: Particle is primary particle.
Definition: MCParticle.h:47
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
StoreArray< MCParticle > m_mcParticle
mc Particle Array
virtual ~ReprocessorModule()
Destructor.
int m_input_TPC_Ntimes
Set N times.
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
virtual void endRun() override
End-of-run action.
virtual void terminate() override
Termination action.
ReprocessorModule()
Constructor: Sets the description, the properties and the parameters of the module.
StoreObjPtr< EventMetaData > m_evtMetaData
event meta data Object pointer
virtual void beginRun() override
Called when entering a new run.
StoreArray< SADMetaHit > MetaHits
Array of SAD particles.
StoreArray< HE3G4TrackInfo > mc_he3_parts
Array of G4 particles crossing the He3 tubes.
StoreArray< TPCG4TrackInfo > mc_tpc_parts
Array of G4 particles crossing the uTPCs.
int m_input_HE3_Ntimes
Set N times.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
bool create(bool replace=false)
Create a default object in the data store.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:246
void clear() override
Delete all entries in this array.
Definition: StoreArray.h:207
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
bool isValid() const
Check whether the object was created.
Definition: StoreObjPtr.h:111
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:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:649
Abstract base class for different kinds of events.
STL namespace.