Belle II Software  release-08-01-10
StudyMaterialEffectsModule.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 #include <tracking/modules/trackFinderVXDTests/StudyMaterialEffectsModule.h>
9 
10 #include <framework/pcore/ProcHandler.h>
11 #include <framework/logging/Logger.h>
12 
13 #include <mdst/dataobjects/MCParticle.h>
14 #include <svd/dataobjects/SVDCluster.h>
15 
16 #include <vxd/geometry/SensorInfoBase.h>
17 
18 #include <Math/Vector3D.h>
19 #include "TMath.h"
20 
21 using namespace Belle2;
22 
23 
24 REG_MODULE(StudyMaterialEffects);
25 
26 StudyMaterialEffectsModule::StudyMaterialEffectsModule() : Module(), m_tree("materialEffectsStudyOutput", DataStore::c_Persistent)
27 {
28  setDescription("StudyMaterialEffects- should be used with single track pGuns and without magnetic field.");
29 
31 }
32 
33 
35 {
36  m_spacePoints.isRequired("spacePoints");
37 
38  m_file = new TFile("materialStudy.root", "RECREATE");
39 
40  m_file->cd();
41 
42  m_tree.registerInDataStore();
43  m_tree.construct("materialEffectsStudyTree", "Raw data of two-hit-combinations for a sectorMap");
44 
45  m_tree->get().Branch("ResidualPhiL3L3", &(m_PhiL3L3));
46  m_tree->get().Branch("ResidualPhiL3L4", &(m_PhiL3L4));
47  m_tree->get().Branch("ResidualPhiL3L6", &(m_PhiL3L6));
48  m_tree->get().Branch("ResidualThetaL3L3", &(m_ThetaL3L3));
49  m_tree->get().Branch("ResidualThetaL3L4", &(m_ThetaL3L4));
50  m_tree->get().Branch("ResidualThetaL3L6", &(m_ThetaL3L6));
51  m_tree->get().Branch("ResidualScatterAngleL3L3", &(m_ScatterAngleL3L3));
52  m_tree->get().Branch("ResidualScatterAngleL3L4", &(m_ScatterAngleL3L4));
53  m_tree->get().Branch("ResidualcatterAngleL3L6", &(m_ScatterAngleL3L6));
54  m_tree->get().Branch("ResidualScatterAngleV2GradL3L3", &(m_ScatterAngleGradL3L3));
55  m_tree->get().Branch("ResidualScatterAngleV2GradL3L4", &(m_ScatterAngleGradL3L4));
56  m_tree->get().Branch("ResidualScatterAngleV2GradL3L6", &(m_ScatterAngleGradL3L6));
57  m_tree->get().Branch("ResidualScatterAngleV3GradL3L3", &(m_ScatterAngleV3GradL3L3));
58  m_tree->get().Branch("ResidualScatterAngleV3GradL3L4", &(m_ScatterAngleV3GradL3L4));
59  m_tree->get().Branch("ResidualScatterAngleV3GradL3L6", &(m_ScatterAngleV3GradL3L6));
60  m_tree->get().Branch("ResidualcatterAngleL3L6", &(m_ScatterAngleL3L6));
61  m_tree->get().Branch("ResidualXYL3L4", &(m_distXY));
62  m_tree->get().Branch("ResidualMomentumL3bL3e", &(m_deltaPL3L3));
63  m_tree->get().Branch("ResidualMomentumL3bL4b", &(m_deltaPL3L4));
64  m_tree->get().Branch("ResidualMomentumL3bL6e", &(m_deltaPL3L6));
65 
66  B2WARNING("StudyMaterialEffectsModule::initialize: nBranches: " << m_tree->get().GetNbranches());
67 }
68 
69 
70 
72 {
73  // position and momentum in global coordinates:
74  B2Vector3D l3HitPosBegin;
75  B2Vector3D l3HitPosEnd;
76  B2Vector3D l4HitPosBegin;
77  B2Vector3D l6HitPosEnd;
78  B2Vector3D l3MomentumBegin;
79  B2Vector3D l3MomentumEnd;
80  B2Vector3D l4MomentumBegin;
81  B2Vector3D l6MomentumEnd;
82 
83  bool wasFoundL3(false);
84  bool wasFoundL4(false);
85  bool wasFoundL6(false);
86 
87 
88  for (const auto& aSP : m_spacePoints) {
89  VxdID vxdID = aSP.getVxdID();
90  const SVDTrueHit* trueHit = getTrueHit(aSP);
91  if (trueHit == nullptr) continue;
92 
93  B2Vector3D entryHitPos = getGlobalPosition(trueHit, vxdID, true);
94  B2Vector3D exitHitPos = getGlobalPosition(trueHit, vxdID, false);
95  B2Vector3D entryMomentum = getGlobalMomentumVector(trueHit, vxdID, true);
96  B2Vector3D exitMomentum = getGlobalMomentumVector(trueHit, vxdID, false);
97  if (vxdID.getLayerNumber() == 3) {
98  l3HitPosBegin = entryHitPos;
99  l3HitPosEnd = exitHitPos;
100  l3MomentumBegin = entryMomentum;
101  l3MomentumEnd = exitMomentum;
102  wasFoundL3 = true;
103  }
104  if (vxdID.getLayerNumber() == 4) {
105  l4HitPosBegin = entryHitPos;
106  l4MomentumBegin = entryMomentum;
107  wasFoundL4 = true;
108  }
109  if (vxdID.getLayerNumber() == 6) {
110  l6HitPosEnd = exitHitPos;
111  l6MomentumEnd = exitMomentum;
112  wasFoundL6 = true;
113  }
114  }
115 
116  if (!wasFoundL3 or !wasFoundL4 or !wasFoundL6) return;
118 
119  m_PhiL3L3 = l3HitPosBegin.Phi() - l3HitPosEnd.Phi();
120  m_PhiL3L4 = l3HitPosBegin.Phi() - l4HitPosBegin.Phi();
121  m_PhiL3L6 = l3HitPosBegin.Phi() - l6HitPosEnd.Phi();
122 
123  m_ThetaL3L3 = l3HitPosBegin.Theta() - l3HitPosEnd.Theta();
124  m_ThetaL3L4 = l3HitPosBegin.Theta() - l4HitPosBegin.Theta();
125  m_ThetaL3L6 = l3HitPosBegin.Theta() - l6HitPosEnd.Theta();
126 
127  m_ScatterAngleL3L3 = sqrt(pow(m_ThetaL3L3, 2) + pow(m_PhiL3L3, 2));
128  m_ScatterAngleL3L4 = sqrt(pow(m_ThetaL3L4, 2) + pow(m_PhiL3L4, 2));
129  m_ScatterAngleL3L6 = sqrt(pow(m_ThetaL3L6, 2) + pow(m_PhiL3L6, 2));
130 
131  m_ScatterAngleGradL3L3 = (l3HitPosEnd - l3HitPosBegin).Angle(l3HitPosBegin) * 180. / TMath::Pi();
132  m_ScatterAngleGradL3L4 = (l4HitPosBegin - l3HitPosBegin).Angle(l3HitPosBegin) * 180. / TMath::Pi();
133  m_ScatterAngleGradL3L6 = (l6HitPosEnd - l3HitPosBegin).Angle(l3HitPosBegin) * 180. / TMath::Pi();
134 
135 
136  m_ScatterAngleV3GradL3L3 = l3MomentumEnd.Angle(l3MomentumBegin) * 180. / TMath::Pi();
137  m_ScatterAngleV3GradL3L4 = l4MomentumBegin.Angle(l3MomentumBegin) * 180. / TMath::Pi();
138  m_ScatterAngleV3GradL3L6 = l6MomentumEnd.Angle(l3MomentumBegin) * 180. / TMath::Pi();
139 
140 
141  m_distXY = (l3HitPosBegin - l4HitPosBegin).Perp();
142 
143  m_deltaPL3L3 = l3MomentumBegin.Mag() - l3MomentumEnd.Mag();
144  m_deltaPL3L4 = l3MomentumBegin.Mag() - l4MomentumBegin.Mag();
145  m_deltaPL3L6 = l3MomentumBegin.Mag() - l6MomentumEnd.Mag();
146 
147  m_tree->get().Fill();
148 }
149 
150 
151 
153 {
154  B2WARNING("StudyMaterialEffects: there were " << m_COUNTERsuccessfullEvents << " events with hits resulting in root output");
155  m_file->cd();
156 
158  //use TFile you created in initialize()
159  m_tree->write(m_file);
160  }
161 }
162 
163 
164 
166 {
168 
169  if (useEntry) {
170  B2Vector3D pos = aSensorInfo->pointToGlobal(ROOT::Math::XYZVector(trueHit->getEntryU(), trueHit->getEntryV(), 0), true);
171  return pos;
172  }
173  B2Vector3D pos = aSensorInfo->pointToGlobal(ROOT::Math::XYZVector(trueHit->getExitU(), trueHit->getExitV(), 0), true);
174  return pos;
175 }
176 
177 
178 
180 {
181 // const auto* aTrueHit = aSP.getRelationsTo<SVDCluster>("ALL")[0]->getRelationsTo<SVDTrueHit>("ALL")[0];;
182  const SVDTrueHit* aTrueHit = nullptr;
183  for (const SVDCluster& aCluster : aSP.getRelationsTo<SVDCluster>("ALL")) {
184  for (const MCParticle& aMcParticle : aCluster.getRelationsTo<MCParticle>("ALL")) {
185  if (aMcParticle.hasStatus(MCParticle::c_PrimaryParticle) == false) continue;
186 
187  aTrueHit = aCluster.getRelationsTo<SVDTrueHit>("ALL")[0];
188 // for (const auto* aTrueHit : aCluster.getRelationsTo<SVDTrueHit>("ALL")) {
189 //
190 // }
191  }
192  }
193  return aTrueHit;
194 }
195 
196 
198 {
200 
201  if (useEntry) {
202 // B2Vector3D mom = aSensorInfo->pointToGlobal(trueHit->getEntryMomentum());
203  return aSensorInfo->vectorToGlobal(trueHit->getEntryMomentum(), true);
204  }
205 // B2Vector3D pos = aSensorInfo->pointToGlobal(trueHit->getExitMomentum());
206  return aSensorInfo->vectorToGlobal(trueHit->getExitMomentum(), true);
207 }
DataType Phi() const
The azimuth angle.
Definition: B2Vector3.h:151
DataType Theta() const
The polar angle.
Definition: B2Vector3.h:153
DataType Mag() const
The magnitude (rho in spherical coordinate system).
Definition: B2Vector3.h:159
DataType Angle(const B2Vector3< DataType > &q) const
The angle w.r.t.
Definition: B2Vector3.h:302
In the store you can park objects that have to be accessed by various modules.
Definition: DataStore.h:51
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
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
@ c_TerminateInAllProcesses
When using parallel processing, call this module's terminate() function in all processes().
Definition: Module.h:83
static bool isOutputProcess()
Return true if the process is an output process.
Definition: ProcHandler.cc:232
static bool parallelProcessingUsed()
Returns true if multiple processes have been spawned, false in single-core mode.
Definition: ProcHandler.cc:226
RelationVector< TO > getRelationsTo(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from this object to another store array.
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition: SVDCluster.h:29
Class SVDTrueHit - Records of tracks that either enter or leave the sensitive volume.
Definition: SVDTrueHit.h:33
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
Definition: SpacePoint.h:42
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
double m_ScatterAngleL3L6
residual of hit.scatteringAngle (sqrt(theta^2 + phi^2)) between layer 3 begin and 6 end.
double m_deltaPL3L6
residual of hit.momentum between layer 3 begin and 6 end.
double m_distXY
residual of hit distance between layer 3 begin and 4 begin.
double m_ScatterAngleGradL3L6
residual of hit.scatteringAngle ((outerHit-innerHit).Angle(innerHit))*180/pi between layer 3 begin an...
B2Vector3D getGlobalPosition(const SVDTrueHit *trueHit, VxdID vxdID, bool useEntry)
takes SVDTrueHit and sensorID to get global position of the hit.
double m_ScatterAngleV3GradL3L4
residual of hit.scatteringAngle (outerHit.Momentum).Angle(innerHit.Momentum))*180/pi between layer 3 ...
B2Vector3D getGlobalMomentumVector(const SVDTrueHit *trueHit, VxdID vxdID, bool useEntry)
takes SVDTrueHit and sensorID to get global momentum of the hit.
void initialize() override
Init the module.
double m_PhiL3L6
residual of hit.phi between layer 3 begin and 6 end.
StoreArray< Belle2::SpacePoint > m_spacePoints
Space Points.
double m_PhiL3L4
residual of hit.phi between layer 3 begin and 4 begin.
const SVDTrueHit * getTrueHit(const SpacePoint &aSP)
takes SpacePoint to get the (first) corresponding trueHit connected to the same particle.
double m_ThetaL3L6
residual of hit.theta between layer 3 begin and 6 end.
double m_ScatterAngleGradL3L4
residual of hit.scatteringAngle ((outerHit-innerHit).Angle(innerHit))*180/pi between layer 3 begin an...
void terminate() override
Don't break the terminal.
int m_COUNTERsuccessfullEvents
Counter for successfully processed events.
double m_ScatterAngleL3L3
residual of hit.scatteringAngle (sqrt(theta^2 + phi^2)) between layer 3 begin and 3 end.
double m_PhiL3L3
residual of hit.phi between layer 3 begin and 3 end.
double m_deltaPL3L4
residual of hit.momentum between layer 3 begin and 4 begin.
TFile * m_file
a pointer to the file where the Tree shall be stored.
double m_ScatterAngleV3GradL3L6
residual of hit.scatteringAngle (outerHit.Momentum).Angle(innerHit.Momentum))*180/pi between layer 3 ...
double m_ScatterAngleL3L4
residual of hit.scatteringAngle (sqrt(theta^2 + phi^2)) between layer 3 begin and 4 begin.
double m_ThetaL3L3
residual of hit.theta between layer 3 begin and 3 end.
StoreObjPtr< RootMergeable< TTree > > m_tree
ROOT Tree.
double m_ScatterAngleGradL3L3
residual of hit.scatteringAngle ((outerHit-innerHit).Angle(innerHit))*180/pi between layer 3 begin an...
double m_ScatterAngleV3GradL3L3
residual of hit.scatteringAngle ((outerHit.Momentum).Angle(innerHit.Momentum))*180/pi between layer 3...
double m_ThetaL3L4
residual of hit.theta between layer 3 begin and 4 begin.
double m_deltaPL3L3
residual of hit.momentum between layer 3 begin and 3 end.
ROOT::Math::XYZVector getExitMomentum() const
Return momentum at the endpoint of the track.
Definition: VXDTrueHit.h:100
float getEntryU() const
Return local u coordinate of hit when entering silicon.
Definition: VXDTrueHit.h:80
ROOT::Math::XYZVector getEntryMomentum() const
Return momentum at the start point of the track.
Definition: VXDTrueHit.h:98
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
const SensorInfoBase & getSensorInfo(Belle2::VxdID id) const
Return a referecne to the SensorInfo of a given SensorID.
Definition: GeoCache.cc:67
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:214
Base class to provide Sensor Information for PXD and SVD.
ROOT::Math::XYZVector pointToGlobal(const ROOT::Math::XYZVector &local, bool reco=false) const
Convert a point from local to global coordinates.
ROOT::Math::XYZVector vectorToGlobal(const ROOT::Math::XYZVector &local, bool reco=false) const
Convert a vector from local to global coordinates.
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
baseType getLayerNumber() const
Get the layer id.
Definition: VxdID.h:96
REG_MODULE(arichBtest)
Register the Module.
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.