Belle II Software development
SensitiveDetectorDebugHelper.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 <vxd/simulation/SensitiveDetectorDebugHelper.h>
10#include <framework/gearbox/Unit.h>
11#include <cassert>
12
13namespace Belle2 {
18 namespace VXD {
19
21 {
22 static SensitiveDetectorDebugHelper instance;
23 return instance;
24 }
25
27 {
28 m_file = new TFile("debug-vxdsensitivedetector.root", "RECREATE");
29 m_tree = new TTree("sensortraversal", "Debug info for VXD Sensitive Detector implementation");
30//Due to laziness, define some macros to create branches with less typing
31#define ADDBRANCH__(name,var,type) m_tree->Branch(#name,&m_info.var,#type)
32#define ADDBARRAY__(name,var,n,type) ADDBRANCH__(name,var,name[n]/type)
33#define ADDBRANCH(x,type) ADDBRANCH__(x,x,x/type)
34#define ADDBARRAY(x,n,type) ADDBARRAY__(x,x,n,type)
35 //and create all branches
36 ADDBRANCH(sensorID, I);
37 ADDBRANCH(pdg, I);
38 ADDBRANCH(contained, I);
39 ADDBRANCH(primary, I);
40 ADDBRANCH(length, D);
41 ADDBRANCH(stepN, I);
42 ADDBARRAY(stepInfo, stepN, D);
43 ADDBRANCH(trueN, I);
44 ADDBARRAY(trueInfo, trueN, D);
45 ADDBRANCH(edepN, I);
46 ADDBARRAY(edepInfo, edepN, D);
47 ADDBRANCH(simhitN, I);
48 ADDBARRAY(simhitInfo, simhitN, D);
49 }
51 {
52 m_info.sensorID = sensorID;
53 m_info.pdg = traversal.getPDGCode();
54 m_info.contained = traversal.isContained();
55 m_info.primary = traversal.isPrimary();
56 m_info.length = traversal.getLength();
57 m_info.stepN = 0;
58 m_info.trueN = 0;
59 m_info.edepN = 0;
60 m_info.simhitN = 0;
61
62 //add all steps if there is enough space
63 assert(traversal.size() <= MAX_STEPS);
64 for (const StepInformation& step : traversal) {
65 m_info.stepInfo[m_info.stepN + 0] = step.position.x();
66 m_info.stepInfo[m_info.stepN + 1] = step.position.y();
67 m_info.stepInfo[m_info.stepN + 2] = step.position.z();
68 m_info.stepInfo[m_info.stepN + 3] = step.momentum.x();
69 m_info.stepInfo[m_info.stepN + 4] = step.momentum.y();
70 m_info.stepInfo[m_info.stepN + 5] = step.momentum.z();
71 m_info.stepInfo[m_info.stepN + 6] = step.electrons;
72 m_info.stepInfo[m_info.stepN + 7] = step.time;
73 m_info.stepInfo[m_info.stepN + 8] = step.length;
75 }
76 }
77
79 {
80 m_info.trueInfo[0] = truehit->getEntryU();
81 m_info.trueInfo[1] = truehit->getEntryV();
82 m_info.trueInfo[2] = truehit->getEntryW();
83 m_info.trueInfo[3] = truehit->getU();
84 m_info.trueInfo[4] = truehit->getV();
85 m_info.trueInfo[5] = truehit->getW();
86 m_info.trueInfo[6] = truehit->getExitU();
87 m_info.trueInfo[7] = truehit->getExitV();
88 m_info.trueInfo[8] = truehit->getExitW();
89 m_info.trueInfo[9] = truehit->getEntryMomentum().X();
90 m_info.trueInfo[10] = truehit->getEntryMomentum().Y();
91 m_info.trueInfo[11] = truehit->getEntryMomentum().Z();
92 m_info.trueInfo[12] = truehit->getMomentum().X();
93 m_info.trueInfo[13] = truehit->getMomentum().Y();
94 m_info.trueInfo[14] = truehit->getMomentum().Z();
95 m_info.trueInfo[15] = truehit->getExitMomentum().X();
96 m_info.trueInfo[16] = truehit->getExitMomentum().Y();
97 m_info.trueInfo[17] = truehit->getExitMomentum().Z();
98 m_info.trueInfo[18] = truehit->getEnergyDep();
99 m_info.trueInfo[19] = truehit->getGlobalTime();
101 }
102
103 void SensitiveDetectorDebugHelper::addSimHit(const VXDSimHit* simhit, int startPoint, int endPoint)
104 {
106 m_info.simhitInfo[m_info.simhitN + 0] = simhit->getPosIn().X();
107 m_info.simhitInfo[m_info.simhitN + 1] = simhit->getPosIn().Y();
108 m_info.simhitInfo[m_info.simhitN + 2] = simhit->getPosIn().Z();
109 m_info.simhitInfo[m_info.simhitN + 3] = simhit->getPosOut().X();
110 m_info.simhitInfo[m_info.simhitN + 4] = simhit->getPosOut().Y();
111 m_info.simhitInfo[m_info.simhitN + 5] = simhit->getPosOut().Z();
113 m_info.simhitInfo[m_info.simhitN + 7] = startPoint;
114 m_info.simhitInfo[m_info.simhitN + 8] = endPoint;
115 //Add optimized energy deposition profile
117 for (auto step : simhit->getElectronProfile()) {
118 m_info.edepInfo[m_info.edepN] = step.first;
119 ++m_info.edepN;
120 m_info.edepInfo[m_info.edepN] = step.second;
121 ++m_info.edepN;
122 }
124 //And also add electron profile sampled by distance
125 for (auto step : simhit->getElectronsConstantDistance(50 * Unit::um)) {
126 m_info.edepInfo[m_info.edepN] = step.first;
127 ++m_info.edepN;
128 m_info.edepInfo[m_info.edepN] = step.second;
129 ++m_info.edepN;
130 }
132 //And sampled by electrons
133 for (auto step : simhit->getElectronsConstantNumber(1000)) {
134 m_info.edepInfo[m_info.edepN] = step.first;
135 ++m_info.edepN;
136 m_info.edepInfo[m_info.edepN] = step.second;
137 ++m_info.edepN;
138 }
141 }
142 }
144} //Belle2 namespace
Class to keep track of the traversal of the sensitive volume for one track.
int getPDGCode() const
get PDG code of the particle
bool isPrimary() const
return whether the track belongs to a primary particle
bool isContained() const
return whether the track was contained in the volume so far
double getLength() const
get flight length so far
static const double um
[micrometers]
Definition: Unit.h:71
Class VXDSimHit - Geant4 simulated hit for the VXD.
Definition: VXDSimHit.h:30
float getGlobalTime() const override
Return the time of the electron deposition.
Definition: VXDSimHit.h:78
ROOT::Math::XYZVector getPosOut() const
Return the end point of the electron deposition in local coordinates.
Definition: VXDSimHit.h:72
std::vector< std::pair< float, float > > getElectronsConstantDistance(double length) const
Get the electron deposition along constant stepsize.
Definition: VXDSimhit.cc:32
std::vector< std::pair< float, float > > getElectronProfile() const
Get the decoded electron profile.
Definition: VXDSimhit.cc:21
ROOT::Math::XYZVector getPosIn() const
Return the start point of the electron deposition in local coordinates.
Definition: VXDSimHit.h:70
std::vector< std::pair< float, float > > getElectronsConstantNumber(double electronsPerStep) const
Get the electron deposition with constant number of electrons between sampling points.
Definition: VXDSimhit.cc:66
Class VXDTrueHit - Records of tracks that either enter or leave the sensitive volume.
Definition: VXDTrueHit.h:36
ROOT::Math::XYZVector getExitMomentum() const
Return momentum at the endpoint of the track.
Definition: VXDTrueHit.h:100
float getV() const
Return local v coordinate of hit.
Definition: VXDTrueHit.h:76
float getGlobalTime() const
Return the time when the track reached its midpoint.
Definition: VXDTrueHit.h:94
float getEntryU() const
Return local u coordinate of hit when entering silicon.
Definition: VXDTrueHit.h:80
float getEnergyDep() const
Return energy deposited during traversal of sensor.
Definition: VXDTrueHit.h:92
float getExitW() const
Return local w coordinate of hit at the endpoint of the track.
Definition: VXDTrueHit.h:90
float getEntryW() const
Return local w coordinate of the start point of the track.
Definition: VXDTrueHit.h:84
float getW() const
Return local w coordinate of hit.
Definition: VXDTrueHit.h:78
ROOT::Math::XYZVector getEntryMomentum() const
Return momentum at the start point of the track.
Definition: VXDTrueHit.h:98
ROOT::Math::XYZVector getMomentum() const
Return momentum at the midpoint of the track.
Definition: VXDTrueHit.h:96
float getU() const
Return local u coordinate of hit.
Definition: VXDTrueHit.h:74
float getExitU() const
Return local u coordinate of hit at the endpoint of the track.
Definition: VXDTrueHit.h:86
float getExitV() const
Return local v coordinate of hit at the endpoint of the track.
Definition: VXDTrueHit.h:88
float getEntryV() const
Return local v coordinate of the start point of the track.
Definition: VXDTrueHit.h:82
Small helper class to facilitate debugging of VXD::SensitiveDetector implementation.
static SensitiveDetectorDebugHelper & getInstance()
Singleton class: get instance.
TTree * m_tree
ROOT Tree to write information to.
void addSimHit(const VXDSimHit *simhit, int startPoint, int endPoint)
Write the information normally used when creating SimHits to the entry.
void startTraversal(VxdID sensorID, const SensorTraversal &traversal)
Start writing a new sensor traversal: Geant4 steps will be added to the ROOT entry.
struct Belle2::VXD::SensitiveDetectorDebugHelper::info m_info
object to store all variables
@ MAX_HITS
assume maximum number of simhits per sensor traversal
@ MAX_STEPS
assume maximum number of steps per sensor traversal
SensitiveDetectorDebugHelper()
Singleton class: private constructor.
void addTrueHit(const VXDTrueHit *truehit)
Write the information normally used when creating TrueHits to the entry.
TFile * m_file
ROOT File to write information to.
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
Abstract base class for different kinds of events.
Simple struct to keep information about steps in the sensitive detector.
double stepInfo[SIZE_STEP *MAX_STEPS]
values for the step points
int sensorID
id of the sensor for the current track
int primary
whether or not the track is from a primary particle
double simhitInfo[SIZE_HITS *MAX_HITS]
values for the simhits
int contained
whether or not the track was contained in the senitive volume
double edepInfo[SIZE_EDEP *MAX_EDEP]
values for the energy deposition