Belle II Software  release-05-02-19
ReprocessorModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Igal Jaegle *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <beast/analysis/modules/ReprocessorModule.h>
12 
13 #include <mdst/dataobjects/MCParticle.h>
14 #include <framework/logging/Logger.h>
15 
16 //c++
17 #include <boost/foreach.hpp>
18 #include <string>
19 #include <fstream>
20 
21 using namespace std;
22 using namespace Belle2;
23 //using namespace reprocessor;
24 
25 //-----------------------------------------------------------------
26 // Register the Module
27 //-----------------------------------------------------------------
28 REG_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 
45 ReprocessorModule::~ReprocessorModule()
46 {
47 }
48 
49 void ReprocessorModule::initialize()
50 {
51  B2INFO("Reprocessor: Initializing");
52 
53  m_mcParticle.registerInDataStore();
54 
55  m_evtMetaData.registerInDataStore();
56 
57  MetaHits.isRequired();
58  mc_he3_parts.isOptional();
59  mc_tpc_parts.isOptional();
60 }
61 
62 void ReprocessorModule::beginRun()
63 {
64 }
65 
66 void ReprocessorModule::event()
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 
92  StoreObjPtr<EventMetaData> evtMetaData;
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  TVector3 Momentum = mcpart.getMomentum();
101  TVector3 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(Momentum);
110  particle->setProductionVertex(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  TVector3 Momentum = mcpart.getMomentum();
124  TVector3 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(Momentum);
133  particle->setProductionVertex(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 
147 void ReprocessorModule::endRun()
148 {
149 }
150 
151 void ReprocessorModule::terminate()
152 {
153 }
154 
155 
Belle2::StoreArray::appendNew
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:256
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::StoreArray::clear
void clear() override
Delete all entries in this array.
Definition: StoreArray.h:217
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::MCParticle
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:43
Belle2::StoreArray< MCParticle >
Belle2::ReprocessorModule
Reprocessor Module.
Definition: ReprocessorModule.h:48
Belle2::StoreObjPtr::isValid
bool isValid() const
Check whether the object was created.
Definition: StoreObjPtr.h:120