Belle II Software development
ARICHBackgroundModule.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// Own header.
9
10#include <arich/modules/arichBackground/ARICHBackgroundModule.h>
11
12#include <time.h>
13
14// Hit classes
15
16#include <simulation/dataobjects/BeamBackHit.h>
17#include <arich/dataobjects/ARICHSimHit.h>
18
19#include <mdst/dataobjects/MCParticle.h>
20
21// framework - DataStore
22#include <framework/datastore/RelationIndex.h>
23
24// framework aux
25#include <framework/logging/Logger.h>
26#include <framework/gearbox/Const.h>
27#include <framework/geometry/B2Vector3.h>
28
29using namespace boost;
30
31namespace Belle2 {
36 namespace arich {
37 //-----------------------------------------------------------------
39 //-----------------------------------------------------------------
40
41 REG_MODULE(ARICHBackground);
42
43
44 //-----------------------------------------------------------------
45 // Implementation
46 //-----------------------------------------------------------------
47
48 ARICHBackgroundModule::ARICHBackgroundModule() : Module(), m_phpos(TVector3()), m_phmom(TVector3()),
49 m_phVtx(TVector3()), m_phMmom(TVector3()), m_phMvtx(TVector3()), m_phPvtx(TVector3()), m_phPmom(TVector3()),
50 m_phGMvtx(TVector3()), m_phGMmom(TVector3()), m_modOrig(TVector3()), m_source(0), m_phPDG(0), m_phMPDG(0), m_phPPDG(0),
51 m_phGMPDG(0), m_type(0), m_edep(0.0), m_ttime(0.0), m_moduleID(0), m_phnw(0.0), m_trackLength(0.0), m_energy(0.0),
52 m_outputFile(NULL),
53 m_outputTree(NULL)
54 {
55 // Set description()
56 setDescription("ARICHBackground module. Used to extract information relevant for ARICH background from background files");
57
58 // Add parameters
59 addParam("FileName", m_filename, "output file name", std::string("mytree.root"));
60 addParam("BkgTag", m_bkgTag, "background type tag (appended to hits in the output tree", 0);
61
62 }
63
65 {
66
67 }
68
70 {
71 m_outputFile = new TFile(m_filename.c_str(), "RECREATE");
72
73 m_outputTree = new TTree("m_outputTree", "tree of arich background hits");
74 m_outputTree->Branch("source", &m_source, "m_source/I");
75 m_outputTree->Branch("phpos", "TVector3", &m_phpos);
76 m_outputTree->Branch("phmom", "TVector3", &m_phmom);
77 m_outputTree->Branch("phVtx", "TVector3", &m_phVtx);
78 m_outputTree->Branch("phMmom", "TVector3", &m_phMmom);
79 m_outputTree->Branch("phMvtx", "TVector3", &m_phMvtx);
80 m_outputTree->Branch("phPvtx", "TVector3", &m_phPvtx);
81 m_outputTree->Branch("phPmom", "TVector3", &m_phPmom);
82 m_outputTree->Branch("phGMvtx", "TVector3", &m_phGMvtx);
83 m_outputTree->Branch("phGMmom", "TVector3", &m_phGMmom);
84 m_outputTree->Branch("modOrig", "TVector3", &m_modOrig);
85 m_outputTree->Branch("phPDG", &m_phPDG, "m_phPDG/I");
86 m_outputTree->Branch("phMPDG", &m_phMPDG, "m_phMPDG/I");
87 m_outputTree->Branch("phPPDG", &m_phPPDG, "m_phPPDG/I");
88 m_outputTree->Branch("phGMPDG", &m_phGMPDG, "m_phGMPDG/I");
89 m_outputTree->Branch("type", &m_type, "m_type/I");
90 m_outputTree->Branch("edep", &m_edep, "m_edep/D");
91 m_outputTree->Branch("ttime", &m_ttime, "m_ttime/D");
92 m_outputTree->Branch("moduleID", &m_moduleID, "m_moduleID/I");
93 m_outputTree->Branch("phnw", &m_phnw, "m_phnw/D");
94 m_outputTree->Branch("trackLength", &m_trackLength, "m_trackLength/D");
95 m_outputTree->Branch("energy", &m_energy, "m_energy/D");
96
98 }
99
101 {
102 // Print run number
103 B2INFO("ARICHBackground: Processing. ");
104
105 }
106
108 {
109 for (const BeamBackHit& arichBeamBkgHit : m_BeamBackHits) {
110
111 int subdet = arichBeamBkgHit.getSubDet();
112 if (subdet != 4) continue;
113 m_type = 0;
114 if (arichBeamBkgHit.getIdentifier() == 1) m_type = 1;
115 m_edep = arichBeamBkgHit.getEnergyDeposit();
116 m_ttime = arichBeamBkgHit.getTime();
117 m_phPDG = arichBeamBkgHit.getPDG();
118 m_phpos = arichBeamBkgHit.getPosition();
119 m_phmom = arichBeamBkgHit.getMomentum();
120 m_moduleID = m_arichgp->getDetectorPlane().pointSlotID(m_phpos.X(), m_phpos.Y());
121 double r = m_arichgp->getDetectorPlane().getSlotR(m_moduleID);
122 double phi = m_arichgp->getDetectorPlane().getSlotPhi(m_moduleID);
123 m_modOrig = TVector3(r * cos(phi), r * sin(phi), 0);
124 m_energy = arichBeamBkgHit.getEnergy();
125
126 if (m_phPDG == Const::neutron.getPDGCode()) {
127 m_phnw = arichBeamBkgHit.getNeutronWeight();
128 m_trackLength = arichBeamBkgHit.getTrackLength();
129 }
130 m_phVtx = TVector3(0, 0, 0); m_phMvtx = TVector3(0, 0, 0); m_phMmom = TVector3(0, 0, 0);
131 m_phMPDG = -1; m_phPPDG = -1; m_phGMPDG = -1;
132 m_phPvtx = TVector3(0, 0, 0); m_phPmom = TVector3(0, 0, 0); m_phGMvtx = TVector3(0, 0, 0); m_phGMmom = TVector3(0, 0, 0);
133
135 if (relBeamBackHitToMCParticle.getFirstElementTo(arichBeamBkgHit)) {
136 const MCParticle* currParticle = relBeamBackHitToMCParticle.getFirstElementTo(arichBeamBkgHit)->from;
137 m_phVtx = B2Vector3D(currParticle->getVertex());
138 const MCParticle* mother = currParticle->getMother();
139 int mm = 0;
140 while (mother) {
141 if (mm == 0) {
142 m_phMPDG = mother->getPDG();
143 m_phMvtx = B2Vector3D(mother->getVertex());
144 m_phMmom = B2Vector3D(mother->getMomentum());
145 }
146 if (mm == 1) {
147 m_phGMPDG = mother->getPDG();
148 m_phGMvtx = B2Vector3D(mother->getVertex());
149 m_phGMmom = B2Vector3D(mother->getMomentum());
150 }
151 const MCParticle* pommother = mother->getMother();
152 if (!pommother) {
153 m_phPPDG = mother->getPDG();
154 m_phPvtx = B2Vector3D(mother->getVertex());
155 m_phPmom = B2Vector3D(mother->getMomentum());
156 }
157 mother = pommother;
158 mm++;
159 }
160
161 }
162 m_outputTree->Fill();
163 }
164
165 // these assignments are the same in every iteration of the loop
166 // so just assign them once outside the loop
167 m_type = 2;
168 m_phPDG = 0;
169 m_edep = 0;
170 for (const ARICHSimHit& arichsimhit : m_ARICHSimHits) {
171 m_moduleID = arichsimhit.getModuleID();
172 m_ttime = arichsimhit.getGlobalTime();
173
174 m_phVtx = TVector3(0, 0, 0); m_phMvtx = TVector3(0, 0, 0); m_phMmom = TVector3(0, 0, 0);
175 m_phMPDG = -1; m_phPPDG = -1; m_phGMPDG = -1; m_phmom = TVector3(0, 0, 0);
176 m_phPvtx = TVector3(0, 0, 0); m_phPmom = TVector3(0, 0, 0); m_phGMvtx = TVector3(0, 0, 0); m_phGMmom = TVector3(0, 0, 0);
178 if (relSimHitToMCParticle.getFirstElementTo(arichsimhit)) {
179 const MCParticle* currParticle = relSimHitToMCParticle.getFirstElementTo(arichsimhit)->from;
180 m_phVtx = B2Vector3D(currParticle->getVertex());
181 const MCParticle* mother = currParticle->getMother();
182 int mm = 0;
183 while (mother) {
184 if (mm == 0) {
185 m_phMPDG = mother->getPDG();
186 m_phMvtx = B2Vector3D(mother->getVertex());
187 m_phMmom = B2Vector3D(mother->getMomentum());
188 }
189 if (mm == 1) {
190 m_phGMPDG = mother->getPDG();
191 m_phGMvtx = B2Vector3D(mother->getVertex());
192 m_phGMmom = B2Vector3D(mother->getMomentum());
193 }
194 const MCParticle* pommother = mother->getMother();
195 if (!pommother) {
196 m_phPPDG = mother->getPDG();
197 m_phPvtx = B2Vector3D(mother->getVertex());
198 m_phPmom = B2Vector3D(mother->getMomentum());
199 }
200 mother = pommother;
201 mm++;
202 }
203
204 }
205 m_outputTree->Fill();
206 }
207 }
208
210 {
211 // Announce
212 B2INFO("ARICHBackground finished.");
213
214 //m_outputTree->Write();
215 m_outputFile->Write();
216 m_outputFile->Close();
217 }
218
219 } // end arich namespace
221} // end Belle2 namespace
Class ARICHSimHit - Geant4 simulated hit for ARICH.
Definition: ARICHSimHit.h:29
Class BeamBackHit - Stores hits from beam backgound simulation.
Definition: BeamBackHit.h:28
static const ParticleType neutron
neutron particle
Definition: Const.h:675
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
ROOT::Math::XYZVector getVertex() const
Return production vertex position, shorthand for getProductionVertex().
Definition: MCParticle.h:172
int getPDG() const
Return PDG code of particle.
Definition: MCParticle.h:101
ROOT::Math::XYZVector getMomentum() const
Return momentum.
Definition: MCParticle.h:187
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
Provides access to fast ( O(log n) ) bi-directional lookups on a specified relation.
Definition: RelationIndex.h:76
const Element * getFirstElementTo(const TO &to) const
Return a pointer to the first relation Element of the given object.
virtual void event()
Event processor.
ROOT::Math::XYZVector m_phPvtx
primary particle vertex
StoreArray< BeamBackHit > m_BeamBackHits
StoreArray for BeamBackHits.
virtual void initialize()
Initialize the Module.
virtual void beginRun()
Called when entering a new run.
int m_source
hit source (RBB_HER, ...)
DBObjPtr< ARICHGeometryConfig > m_arichgp
Geometry parametrization.
int m_phMPDG
hit particle mother PDG code
ROOT::Math::XYZVector m_phVtx
hit particle vertex position
ROOT::Math::XYZVector m_phPmom
primary particle momentum
StoreArray< ARICHSimHit > m_ARICHSimHits
StoreArray for ARICHSimHits.
int m_phGMPDG
hit particle grand mother PDG code
ROOT::Math::XYZVector m_phmom
hit momentum
virtual void terminate()
Termination action.
ROOT::Math::XYZVector m_phGMvtx
hit particle grand mother vertex
ROOT::Math::XYZVector m_phpos
hit position
int m_type
hit particle type; 0 hit in board, 1 hit in HAPD bottom, 2 photon hit
int m_phPPDG
hit particle primary PDG code
double m_trackLength
particle track length in hit volume
ROOT::Math::XYZVector m_modOrig
HAPD module position.
std::string m_filename
Output file name.
ROOT::Math::XYZVector m_phGMmom
hit particle grand mother momentum
StoreArray< MCParticle > m_MCParticles
StoreArray for MCParticles.
ROOT::Math::XYZVector m_phMvtx
hit particle mother vertex
ROOT::Math::XYZVector m_phMmom
hit particle mother momentum
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
B2Vector3< double > B2Vector3D
typedef for common usage with double
Definition: B2Vector3.h:516
MCParticle * getMother() const
Returns a pointer to the mother particle.
Definition: MCParticle.h:590
Abstract base class for different kinds of events.
const FROM * from
pointer of the element from which the relation points.