Belle II Software  release-05-02-19
StudyMaterialEffectsModule.cc
1 #include <tracking/modules/trackFinderVXDTests/StudyMaterialEffectsModule.h>
2 
3 #include <framework/pcore/ProcHandler.h>
4 #include <framework/logging/Logger.h>
5 
6 #include <mdst/dataobjects/MCParticle.h>
7 #include <svd/dataobjects/SVDCluster.h>
8 
9 #include <vxd/geometry/SensorInfoBase.h>
10 
11 #include <TVector3.h>
12 #include "TMath.h"
13 
14 
15 using namespace std;
16 using namespace Belle2;
17 
18 
19 REG_MODULE(StudyMaterialEffects)
20 
21 StudyMaterialEffectsModule::StudyMaterialEffectsModule() : Module(), m_tree("materialEffectsStudyOutput" , DataStore::c_Persistent)
22 {
23  setDescription("StudyMaterialEffects- should be used with single track pGuns and without magnetic field.");
24 
25  setPropertyFlags(c_ParallelProcessingCertified | c_TerminateInAllProcesses);
26 }
27 
28 
29 void StudyMaterialEffectsModule::initialize()
30 {
31  m_spacePoints.isRequired("spacePoints");
32 
33  m_file = new TFile("materialStudy.root", "RECREATE");
34 
35  m_file->cd();
36 
37  m_tree.registerInDataStore();
38  m_tree.construct("materialEffectsStudyTree", "Raw data of two-hit-combinations for a sectorMap");
39 
40  m_tree->get().Branch("ResidualPhiL3L3", &(m_PhiL3L3));
41  m_tree->get().Branch("ResidualPhiL3L4", &(m_PhiL3L4));
42  m_tree->get().Branch("ResidualPhiL3L6", &(m_PhiL3L6));
43  m_tree->get().Branch("ResidualThetaL3L3", &(m_ThetaL3L3));
44  m_tree->get().Branch("ResidualThetaL3L4", &(m_ThetaL3L4));
45  m_tree->get().Branch("ResidualThetaL3L6", &(m_ThetaL3L6));
46  m_tree->get().Branch("ResidualScatterAngleL3L3", &(m_ScatterAngleL3L3));
47  m_tree->get().Branch("ResidualScatterAngleL3L4", &(m_ScatterAngleL3L4));
48  m_tree->get().Branch("ResidualcatterAngleL3L6", &(m_ScatterAngleL3L6));
49  m_tree->get().Branch("ResidualScatterAngleV2GradL3L3", &(m_ScatterAngleGradL3L3));
50  m_tree->get().Branch("ResidualScatterAngleV2GradL3L4", &(m_ScatterAngleGradL3L4));
51  m_tree->get().Branch("ResidualScatterAngleV2GradL3L6", &(m_ScatterAngleGradL3L6));
52  m_tree->get().Branch("ResidualScatterAngleV3GradL3L3", &(m_ScatterAngleV3GradL3L3));
53  m_tree->get().Branch("ResidualScatterAngleV3GradL3L4", &(m_ScatterAngleV3GradL3L4));
54  m_tree->get().Branch("ResidualScatterAngleV3GradL3L6", &(m_ScatterAngleV3GradL3L6));
55  m_tree->get().Branch("ResidualcatterAngleL3L6", &(m_ScatterAngleL3L6));
56  m_tree->get().Branch("ResidualXYL3L4", &(m_distXY));
57  m_tree->get().Branch("ResidualMomentumL3bL3e", &(m_deltaPL3L3));
58  m_tree->get().Branch("ResidualMomentumL3bL4b", &(m_deltaPL3L4));
59  m_tree->get().Branch("ResidualMomentumL3bL6e", &(m_deltaPL3L6));
60 
61  B2WARNING("StudyMaterialEffectsModule::initialize: nBranches: " << m_tree->get().GetNbranches());
62 }
63 
64 
65 
66 void StudyMaterialEffectsModule::event()
67 {
68  // position and momentum in global coordinates:
69  B2Vector3D l3HitPosBegin;
70  B2Vector3D l3HitPosEnd;
71  B2Vector3D l4HitPosBegin;
72  B2Vector3D l6HitPosEnd;
73  B2Vector3D l3MomentumBegin;
74  B2Vector3D l3MomentumEnd;
75  B2Vector3D l4MomentumBegin;
76  B2Vector3D l6MomentumEnd;
77 
78  bool wasFoundL3(false);
79  bool wasFoundL4(false);
80  bool wasFoundL6(false);
81 
82 
83  for (const auto& aSP : m_spacePoints) {
84  VxdID vxdID = aSP.getVxdID();
85  const SVDTrueHit* trueHit = getTrueHit(aSP);
86  if (trueHit == nullptr) continue;
87 
88  B2Vector3D entryHitPos = getGlobalPosition(trueHit, vxdID, true);
89  B2Vector3D exitHitPos = getGlobalPosition(trueHit, vxdID, false);
90  B2Vector3D entryMomentum = getGlobalMomentumVector(trueHit, vxdID, true);
91  B2Vector3D exitMomentum = getGlobalMomentumVector(trueHit, vxdID, false);
92  if (vxdID.getLayerNumber() == 3) {
93  l3HitPosBegin = entryHitPos;
94  l3HitPosEnd = exitHitPos;
95  l3MomentumBegin = entryMomentum;
96  l3MomentumEnd = exitMomentum;
97  wasFoundL3 = true;
98  }
99  if (vxdID.getLayerNumber() == 4) {
100  l4HitPosBegin = entryHitPos;
101  l4MomentumBegin = entryMomentum;
102  wasFoundL4 = true;
103  }
104  if (vxdID.getLayerNumber() == 6) {
105  l6HitPosEnd = exitHitPos;
106  l6MomentumEnd = exitMomentum;
107  wasFoundL6 = true;
108  }
109  }
110 
111  if (!wasFoundL3 or !wasFoundL4 or !wasFoundL6) return;
112  m_COUNTERsuccessfullEvents++;
113 
114  m_PhiL3L3 = l3HitPosBegin.Phi() - l3HitPosEnd.Phi();
115  m_PhiL3L4 = l3HitPosBegin.Phi() - l4HitPosBegin.Phi();
116  m_PhiL3L6 = l3HitPosBegin.Phi() - l6HitPosEnd.Phi();
117 
118  m_ThetaL3L3 = l3HitPosBegin.Theta() - l3HitPosEnd.Theta();
119  m_ThetaL3L4 = l3HitPosBegin.Theta() - l4HitPosBegin.Theta();
120  m_ThetaL3L6 = l3HitPosBegin.Theta() - l6HitPosEnd.Theta();
121 
122  m_ScatterAngleL3L3 = sqrt(pow(m_ThetaL3L3, 2) + pow(m_PhiL3L3, 2));
123  m_ScatterAngleL3L4 = sqrt(pow(m_ThetaL3L4, 2) + pow(m_PhiL3L4, 2));
124  m_ScatterAngleL3L6 = sqrt(pow(m_ThetaL3L6, 2) + pow(m_PhiL3L6, 2));
125 
126  m_ScatterAngleGradL3L3 = (l3HitPosEnd - l3HitPosBegin).Angle(l3HitPosBegin) * 180. / TMath::Pi();
127  m_ScatterAngleGradL3L4 = (l4HitPosBegin - l3HitPosBegin).Angle(l3HitPosBegin) * 180. / TMath::Pi();
128  m_ScatterAngleGradL3L6 = (l6HitPosEnd - l3HitPosBegin).Angle(l3HitPosBegin) * 180. / TMath::Pi();
129 
130 
131  m_ScatterAngleV3GradL3L3 = l3MomentumEnd.Angle(l3MomentumBegin) * 180. / TMath::Pi();
132  m_ScatterAngleV3GradL3L4 = l4MomentumBegin.Angle(l3MomentumBegin) * 180. / TMath::Pi();
133  m_ScatterAngleV3GradL3L6 = l6MomentumEnd.Angle(l3MomentumBegin) * 180. / TMath::Pi();
134 
135 
136  m_distXY = (l3HitPosBegin - l4HitPosBegin).Perp();
137 
138  m_deltaPL3L3 = l3MomentumBegin.Mag() - l3MomentumEnd.Mag();
139  m_deltaPL3L4 = l3MomentumBegin.Mag() - l4MomentumBegin.Mag();
140  m_deltaPL3L6 = l3MomentumBegin.Mag() - l6MomentumEnd.Mag();
141 
142  m_tree->get().Fill();
143 }
144 
145 
146 
147 void StudyMaterialEffectsModule::terminate()
148 {
149  B2WARNING("StudyMaterialEffects: there were " << m_COUNTERsuccessfullEvents << " events with hits resulting in root output");
150  m_file->cd();
151 
152  if (!ProcHandler::parallelProcessingUsed() or ProcHandler::isOutputProcess()) {
153  //use TFile you created in initialize()
154  m_tree->write(m_file);
155  }
156 }
157 
158 
159 
160 B2Vector3D StudyMaterialEffectsModule::getGlobalPosition(const SVDTrueHit* trueHit, VxdID vxdID, bool useEntry)
161 {
162  const Belle2::VXD::SensorInfoBase* aSensorInfo = &VXD::GeoCache::getInstance().getSensorInfo(vxdID);
163 
164  if (useEntry) {
165  B2Vector3D pos = aSensorInfo->pointToGlobal(TVector3(trueHit->getEntryU(), trueHit->getEntryV(), 0), true);
166  return pos;
167  }
168  B2Vector3D pos = aSensorInfo->pointToGlobal(TVector3(trueHit->getExitU(), trueHit->getExitV(), 0), true);
169  return pos;
170 }
171 
172 
173 
174 const SVDTrueHit* StudyMaterialEffectsModule::getTrueHit(const SpacePoint& aSP)
175 {
176 // const auto* aTrueHit = aSP.getRelationsTo<SVDCluster>("ALL")[0]->getRelationsTo<SVDTrueHit>("ALL")[0];;
177  const SVDTrueHit* aTrueHit = nullptr;
178  for (const SVDCluster& aCluster : aSP.getRelationsTo<SVDCluster>("ALL")) {
179  for (const MCParticle& aMcParticle : aCluster.getRelationsTo<MCParticle>("ALL")) {
180  if (aMcParticle.hasStatus(MCParticle::c_PrimaryParticle) == false) continue;
181 
182  aTrueHit = aCluster.getRelationsTo<SVDTrueHit>("ALL")[0];
183 // for (const auto* aTrueHit : aCluster.getRelationsTo<SVDTrueHit>("ALL")) {
184 //
185 // }
186  }
187  }
188  return aTrueHit;
189 }
190 
191 
192 B2Vector3D StudyMaterialEffectsModule::getGlobalMomentumVector(const SVDTrueHit* trueHit, VxdID vxdID, bool useEntry)
193 {
194  const Belle2::VXD::SensorInfoBase* aSensorInfo = &VXD::GeoCache::getInstance().getSensorInfo(vxdID);
195 
196  if (useEntry) {
197 // B2Vector3D mom = aSensorInfo->pointToGlobal(trueHit->getEntryMomentum());
198  return aSensorInfo->vectorToGlobal(trueHit->getEntryMomentum(), true);
199  }
200 // B2Vector3D pos = aSensorInfo->pointToGlobal(trueHit->getExitMomentum());
201  return aSensorInfo->vectorToGlobal(trueHit->getExitMomentum(), true);
202 }
Belle2::VxdID
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:43
Belle2::VXDTrueHit::getExitU
float getExitU() const
Return local u coordinate of hit at the endpoint of the track.
Definition: VXDTrueHit.h:88
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::VXDTrueHit::getEntryV
float getEntryV() const
Return local v coordinate of the start point of the track.
Definition: VXDTrueHit.h:84
Belle2::B2Vector3::Angle
DataType Angle(const B2Vector3< DataType > &q) const
The angle w.r.t.
Definition: B2Vector3.h:301
Belle2::VXD::SensorInfoBase::vectorToGlobal
TVector3 vectorToGlobal(const TVector3 &local, bool reco=false) const
Convert a vector from local to global coordinates.
Definition: SensorInfoBase.h:383
Belle2::SVDTrueHit
Class SVDTrueHit - Records of tracks that either enter or leave the sensitive volume.
Definition: SVDTrueHit.h:35
Belle2::VXD::SensorInfoBase
Base class to provide Sensor Information for PXD and SVD.
Definition: SensorInfoBase.h:40
Belle2::RelationsInterface::getRelationsTo
RelationVector< TO > getRelationsTo(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from this object to another store array.
Definition: RelationsObject.h:199
Belle2::SpacePoint
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
Definition: SpacePoint.h:52
Belle2::B2Vector3< double >
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::StudyMaterialEffectsModule
StudyMaterialEffectsModule.
Definition: StudyMaterialEffectsModule.h:25
Belle2::B2Vector3::Phi
DataType Phi() const
The azimuth angle.
Definition: B2Vector3.h:150
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::VXDTrueHit::getExitV
float getExitV() const
Return local v coordinate of hit at the endpoint of the track.
Definition: VXDTrueHit.h:90
Belle2::VXDTrueHit::getEntryMomentum
TVector3 getEntryMomentum() const
Return momentum at the start point of the track.
Definition: VXDTrueHit.h:100
Belle2::VXD::SensorInfoBase::pointToGlobal
TVector3 pointToGlobal(const TVector3 &local, bool reco=false) const
Convert a point from local to global coordinates.
Definition: SensorInfoBase.h:373
Belle2::VXDTrueHit::getEntryU
float getEntryU() const
Return local u coordinate of hit when entering silicon.
Definition: VXDTrueHit.h:82
Belle2::SVDCluster
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition: SVDCluster.h:38
Belle2::VXDTrueHit::getExitMomentum
TVector3 getExitMomentum() const
Return momentum at the endpoint of the track.
Definition: VXDTrueHit.h:102
Belle2::MCParticle
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:43
Belle2::VxdID::getLayerNumber
baseType getLayerNumber() const
Get the layer id.
Definition: VxdID.h:106
Belle2::B2Vector3::Theta
DataType Theta() const
The polar angle.
Definition: B2Vector3.h:152
Belle2::DataStore
In the store you can park objects that have to be accessed by various modules.
Definition: DataStore.h:53
Belle2::B2Vector3::Mag
DataType Mag() const
The magnitude (rho in spherical coordinate system).
Definition: B2Vector3.h:158