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 <boost/foreach.hpp>
18#include <string>
19#include <fstream>
20
21using namespace std;
22using namespace Belle2;
23//using namespace reprocessor;
24
25//-----------------------------------------------------------------
26// Register the Module
27//-----------------------------------------------------------------
28REG_MODULE(Reprocessor);
29
30//-----------------------------------------------------------------
31// Implementation
32//-----------------------------------------------------------------
33
35{
36 // Set module properties
37 setDescription("Reprocessor module");
38
39 addParam("input_TPC_PDG", m_input_TPC_PDG, "Set the PDG particle to re-launch");
40 addParam("input_TPC_Ntimes", m_input_TPC_Ntimes, "Re-launch the PDG particle N times");
41 addParam("input_HE3_PDG", m_input_HE3_PDG, "Set the PDG particle to re-launch");
42 addParam("input_HE3_Ntimes", m_input_HE3_Ntimes, "Re-launch the PDG particle N times");
43}
44
46{
47}
48
50{
51 B2INFO("Reprocessor: Initializing");
52
54
55 m_evtMetaData.registerInDataStore();
56
57 MetaHits.isRequired();
58 mc_he3_parts.isOptional();
59 mc_tpc_parts.isOptional();
60}
61
63{
64}
65
67{
68 //skip events with no HE3G4 and TPCG4 particles stored
69 if (mc_he3_parts.getEntries() == 0 && mc_tpc_parts.getEntries() == 0 && m_input_TPC_Ntimes != 0 && m_input_HE3_Ntimes != 0) {
70 return;
71 }
72 if (mc_he3_parts.getEntries() == 0 && m_input_HE3_Ntimes != 0) {
73 return;
74 }
75 if (mc_tpc_parts.getEntries() == 0 && m_input_TPC_Ntimes != 0) {
76 return;
77 }
78
79 //Look at the meta data to extract IR rate and scattering ring section
80 double rate = 0;
81 for (const auto& MetaHit : MetaHits) {
82 rate = MetaHit.getrate();
83 }
84
85 if (m_input_HE3_Ntimes != 0 && m_input_TPC_Ntimes == 0) rate /= (double)m_input_HE3_Ntimes;
86 if (m_input_TPC_Ntimes != 0 && m_input_HE3_Ntimes == 0) rate /= (double)m_input_TPC_Ntimes;
87
88 // if not already existed, create MCParticles data store
89 StoreArray<MCParticle> MCParticles;
90 MCParticles.clear();
91
93 //evtMetaData.clear();
94 if (!evtMetaData.isValid()) evtMetaData.create();
95
96 if (m_input_TPC_Ntimes != 0) {
97 for (const auto& mcpart : mc_tpc_parts) { // start loop over all Tracks
98 const int PDG = mcpart.getPDG();
99 const double energy = mcpart.getEnergy();
100 ROOT::Math::XYZVector Momentum = mcpart.getMomentum();
101 ROOT::Math::XYZVector ProductionVertex = mcpart.getProductionVertex();
102 if (m_input_TPC_PDG == PDG) {
103 for (int i = 0; i < m_input_TPC_Ntimes; i ++) {
104 // store generated particle
105 MCParticle* particle = MCParticles.appendNew();
106 particle->setStatus(MCParticle::c_PrimaryParticle);
107 particle->setPDG(PDG);
108 particle->setMassFromPDG();
109 particle->setMomentum(ROOT::Math::XYZVector(Momentum));
110 particle->setProductionVertex(ROOT::Math::XYZVector(ProductionVertex));
111 particle->setProductionTime(0.0);
112 particle->setEnergy(energy);
113 particle->setValidVertex(true);
114 }
115 }
116 }
117 }
118
119 if (m_input_HE3_Ntimes != 0) {
120 for (const auto& mcpart : mc_he3_parts) { // start loop over all Tracks
121 const int PDG = mcpart.getPDG();
122 const double energy = mcpart.getEnergy();
123 ROOT::Math::XYZVector Momentum = mcpart.getMomentum();
124 ROOT::Math::XYZVector ProductionVertex = mcpart.getProductionVertex();
125 if (m_input_HE3_PDG == PDG) {
126 for (int i = 0; i < m_input_HE3_Ntimes; i ++) {
127 // store generated particle
128 MCParticle* particle = MCParticles.appendNew();
129 particle->setStatus(MCParticle::c_PrimaryParticle);
130 particle->setPDG(PDG);
131 particle->setMassFromPDG();
132 particle->setMomentum(ROOT::Math::XYZVector(Momentum));
133 particle->setProductionVertex(ROOT::Math::XYZVector(ProductionVertex));
134 particle->setProductionTime(0.0);
135 particle->setEnergy(energy);
136 particle->setValidVertex(true);
137 }
138 }
139 }
140 }
141
142 evtMetaData->setGeneratedWeight(rate);
143}
144
145
146
148{
149}
150
152{
153}
154
155
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:560
#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.
STL namespace.