Belle II Software development
HitXPModule.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 <tracking/modules/trackingPerformanceEvaluation/HitXPModule.h>
10#include <framework/datastore/StoreArray.h>
11#include <framework/datastore/RelationArray.h>
12#include <mdst/dataobjects/MCParticle.h>
13#include <svd/dataobjects/SVDCluster.h>
14#include <svd/dataobjects/SVDTrueHit.h>
15#include <TFile.h>
16#include <tracking/dataobjects/RecoTrack.h>
17#include <tracking/dataobjects/hitXPDerivate.h>
18
19#include <string>
20
21using namespace Belle2;
22
23REG_MODULE(HitXP);
24
26{
27 setDescription("This module builds a ttree with true hit informations (momentum, position, PDGID, and track parameters hit per hit) running over simulated and reconstructed events.");
28
30 addParam("additionalTree", c_addTree,
31 "produce two additional tree with reduced date: selTree (track with at least one hit per layer), tiSelTree (track with one hit per layer)",
32 false);
33
34}
35
36
37HitXPModule::~HitXPModule()
38{
39}
40
41
42
44{
45
48 StoreArray<RecoTrack> storeRecoTracks("");
49 StoreArray<SVDCluster> storeClusters("");
50 StoreArray<SVDTrueHit> storeTrueHits("");
51 storeRecoTracks.isRequired();
52 storeClusters.isRequired();
53 storeTrueHits.isRequired();
54
55 RelationArray relClusterTrueHits(storeClusters, storeTrueHits);
56 RelationArray relClusterMCParticles(storeClusters, m_MCParticles);
57 RelationArray recoTracksToMCParticles(storeRecoTracks, m_MCParticles);
58
59
68 m_outputFile = new TFile("TFile_hitXP.root", "RECREATE");
69 m_tree = new TTree("TTree_hitXP", "TTree_hitXP");
70
71 m_tree->Branch("hitXP", &m_hitXP);
72 m_tree->Branch("trackNumber", &m_trackNumber);
73 m_tree->Branch("eventNumber", &m_eventNumber);
74 m_tree->Branch("numberHitPerTrack", &m_numberHitPerTrack);
75
78
79 //-------------------------------------------------------------------------------------------------//
80 //------------------------------------selected Tree creation--------------------------------------//
81 //-------------------------------------------------------------------------------------------------//
82 if (c_addTree) m_outputFileSel = new TFile("TFile_hitXPSel.root", "RECREATE");
83 m_treeSel = new TTree("TTree_hitXPSel", "TTree_hitXPSel");
84
85 m_treeSel->Branch("hitXP", &m_hitXPSel);
86 m_treeSel->Branch("trackNumber", &m_trackNumberSel);
87 m_treeSel->Branch("eventNumber", &m_eventNumberSel);
88 m_treeSel->Branch("numberHitPerTrack", &m_numberHitPerTrackSel);
89
90
91 //-------------------------------------------------------------------------------------------------//
92 //------------------------------------tight selected Tree creation--------------------------------------//
93 //-------------------------------------------------------------------------------------------------//
94 if (c_addTree) m_outputFileTiSel = new TFile("TFile_hitXPTiSel.root", "RECREATE");
95 m_treeTiSel = new TTree("TTree_hitXPTiSel", "TTree_hitXPTiSel");
96
97 m_treeTiSel->Branch("hitXP", &m_hitXPTiSel);
98 m_treeTiSel->Branch("trackNumber", &m_trackNumberTiSel);
99 m_treeTiSel->Branch("eventNumber", &m_eventNumberTiSel);
100 m_treeTiSel->Branch("numberHitPerTrack", &m_numberHitPerTrackTiSel);
101
102
103//-------------------------------------------------------------------------------------------------//
104//------------------------------------External Tree creation--------------------------------------//
105//-------------------------------------------------------------------------------------------------//
106
108 m_outputFileExt = new TFile("TFile_hitXP_ext.root", "RECREATE");
109 m_treeExt = new TTree("TTree_hitXP_ext", "TTree_hitXP_ext");
110
111 m_treeExt->Branch("positionEntryX", &m_EpositionEntryX);
112 m_treeExt->Branch("positionEntryY", &m_EpositionEntryY);
113 m_treeExt->Branch("positionEntryZ", &m_EpositionEntryZ);
114 m_treeExt->Branch("momentumEntryX", &m_EmomentumEntryX);
115 m_treeExt->Branch("momentumEntryY", &m_EmomentumEntryY);
116 m_treeExt->Branch("momentumEntryZ", &m_EmomentumEntryZ);
117 m_treeExt->Branch("positionLocalEntryX", &m_EpositionLocalEntryX);
118 m_treeExt->Branch("positionLocalEntryY", &m_EpositionLocalEntryY);
119 m_treeExt->Branch("positionLocalEntryZ", &m_EpositionLocalEntryZ);
120 m_treeExt->Branch("PDGID", &m_EPDGID);
121 m_treeExt->Branch("position0X", &m_Eposition0X);
122 m_treeExt->Branch("position0Y", &m_Eposition0Y);
123 m_treeExt->Branch("position0Z", &m_Eposition0Z);
124 m_treeExt->Branch("momentum0X", &m_Emomentum0X);
125 m_treeExt->Branch("momentum0Y", &m_Emomentum0Y);
126 m_treeExt->Branch("momentum0Z", &m_Emomentum0Z);
127 m_treeExt->Branch("time", &m_Etime);
128 m_treeExt->Branch("sensorSensor", &m_EsensorSensor);
129 m_treeExt->Branch("sensorLayer", &m_EsensorLayer);
130 m_treeExt->Branch("sensorLadder", &m_EsensorLadder);
131 m_treeExt->Branch("reconstructed", &m_Ereconstructed);
132 m_treeExt->Branch("clusterU", &m_EclusterU);
133 m_treeExt->Branch("clusterV", &m_EclusterV);
134 m_treeExt->Branch("charge", &m_Echarge);
135 m_treeExt->Branch("trackNumber", &m_EtrackNumber);
136 m_treeExt->Branch("eventNumber", &m_EeventNumber);
137 m_treeExt->Branch("numberHitPerTrack", &m_EnumberHitPerTrack);
138 m_treeExt->Branch("omegaEntry", &m_EomegaEntry);
139 m_treeExt->Branch("omega0", &m_Eomega0);
140 m_treeExt->Branch("d0Entry", &m_Ed0Entry);
141 m_treeExt->Branch("d00", &m_Ed00);
142 m_treeExt->Branch("phi0Entry", &m_Ephi0Entry);
143 m_treeExt->Branch("phi00", &m_Ephi00);
144 m_treeExt->Branch("z0Entry", &m_Ez0Entry);
145 m_treeExt->Branch("z00", &m_Ez00);
146 m_treeExt->Branch("tanlambdaEntry", &m_EtanlambdaEntry);
147 m_treeExt->Branch("tanlambda0", &m_Etanlambda0);
148 m_treeExt->Branch("primary", &m_Eprimary);
149
150}
151
153
155{
157 m_EeventNumber = m_eventIterator; //------------External Tree---------//
159
160
161 for (const MCParticle& particle : m_MCParticles) {
162 m_Eprimary = particle.getStatus();
163 for (const SVDTrueHit& hit : particle.getRelationsTo<SVDTrueHit>()) {
164 if (hit.getRelationsFrom<SVDCluster>().size() > 0) {
165 VxdID trueHitSensorID = hit.getSensorID();
166 const VXD::SensorInfoBase& sensorInfo = VXD::GeoCache::getInstance().getSensorInfo(trueHitSensorID);
167 const SVDCluster* cluster = hit.getRelationsFrom<SVDCluster>()[0];
168 hitXPDerivate entry(hit, *cluster, particle, sensorInfo);
169 int NClusterU = 0;
170 int NClusterV = 0;
171 for (SVDCluster Ncluster : hit.getRelationsFrom<SVDCluster>()) {
172 if (Ncluster.isUCluster()) NClusterU++;
173 else NClusterV++;
174 }
175 entry.setClusterU(NClusterU);
176 entry.setClusterV(NClusterV);
177
178 bool isReconstructed(false);
179 for (const RecoTrack& aRecoTrack : particle.getRelationsFrom<RecoTrack>())
180 isReconstructed |= aRecoTrack.hasSVDHits();
181 entry.setReconstructed(isReconstructed);
182 m_hitXPSet.insert(entry);
183 }
184 }
186 m_EtrackNumber = m_trackIterator; //----------------External Tree ----------------//
188
189 for (auto element : m_hitXPSet) {
190 m_hitXP.push_back(element);
191
192 //-----------------External Tree ---------------------------- //
193 m_EpositionEntryX.push_back(element.m_positionEntry.x());
194 m_EpositionEntryY.push_back(element.m_positionEntry.y());
195 m_EpositionEntryZ.push_back(element.m_positionEntry.z());
196 m_EmomentumEntryX.push_back(element.m_momentumEntry.x());
197 m_EmomentumEntryY.push_back(element.m_momentumEntry.y());
198 m_EmomentumEntryZ.push_back(element.m_momentumEntry.z());
199 m_EpositionLocalEntryX.push_back(element.m_positionLocalEntry.x());
200 m_EpositionLocalEntryY.push_back(element.m_positionLocalEntry.y());
201 m_EpositionLocalEntryZ.push_back(element.m_positionLocalEntry.z());
202 m_EPDGID.push_back(element.m_PDGID);
203 m_Eposition0X.push_back(element.m_position0.x());
204 m_Eposition0Y.push_back(element.m_position0.y());
205 m_Eposition0Z.push_back(element.m_position0.z());
206 m_Emomentum0X.push_back(element.m_momentum0.x());
207 m_Emomentum0Y.push_back(element.m_momentum0.y());
208 m_Emomentum0Z.push_back(element.m_momentum0.z());
209 m_Etime.push_back(element.m_time);
210 m_EsensorSensor.push_back(element.m_sensorSensor);
211 m_EsensorLayer.push_back(element.m_sensorLayer);
212 m_EsensorLadder.push_back(element.m_sensorLadder);
213 m_Ereconstructed.push_back(element.m_reconstructed);
214 m_EclusterU.push_back(element.m_clusterU);
215 m_EclusterV.push_back(element.m_clusterV);
216 m_Echarge.push_back(element.m_charge);
217 m_EomegaEntry.push_back(element.getOmegaEntry());
218 m_Eomega0.push_back(element.getOmega0());
219 m_Ed0Entry.push_back(element.getD0Entry());
220 m_Ed00.push_back(element.getD00());
221 m_Ephi0Entry.push_back(element.getPhi0Entry());
222 m_Ephi00.push_back(element.getPhi00());
223 m_Ez0Entry.push_back(element.getZ0Entry());
224 m_Ez00.push_back(element.getZ00());
225 m_EtanlambdaEntry.push_back(element.getTanLambdaEntry());
226 m_Etanlambda0.push_back(element.getTanLambda0());
227 }
229 m_EnumberHitPerTrack = m_hitXP.size(); //-------external tree--------------//
230
231
232 m_tree->Fill();
233
234 //-------external tree--------------//
235 m_treeExt->Fill();
236 m_EpositionEntryX.clear();
237 m_EpositionEntryY.clear();
238 m_EpositionEntryZ.clear();
239 m_EmomentumEntryX.clear();
240 m_EmomentumEntryY.clear();
241 m_EmomentumEntryZ.clear();
245 m_EPDGID.clear();
246 m_Eposition0X.clear();
247 m_Eposition0Y.clear();
248 m_Eposition0Z.clear();
249 m_Emomentum0X.clear();
250 m_Emomentum0Y.clear();
251 m_Emomentum0Z.clear();
252 m_Etime.clear();
253 m_EsensorSensor.clear();
254 m_EsensorLayer.clear();
255 m_EsensorLadder.clear();
256 m_Ereconstructed.clear();
257 m_EclusterU.clear();
258 m_EclusterV.clear();
259 m_Echarge.clear();
260 m_EomegaEntry.clear();
261 m_Eomega0.clear();
262 m_Ed0Entry.clear();
263 m_Ed00.clear();
264 m_Ephi0Entry.clear();
265 m_Ephi00.clear();
266 m_Ez0Entry.clear();
267 m_Ez00.clear();
268 m_EtanlambdaEntry.clear();
269 m_Etanlambda0.clear();
270
271
272
273 //-------------------------------------------------------------------------------------------------//
274 //------------------------------------Selected Tree creation--------------------------------------//
275 //-------------------------------------------------------------------------------------------------//
277 int f3 = 0, f4 = 0, f5 = 0, f6 = 0;
278 int layer_flag = 0;
279 unsigned int j = 0;
280 int brk = 0;
281 std::vector<hitXP> temp_hitXP;
282 while (j < m_hitXP.size() && brk == 0) {
283 if (m_hitXP[j].m_sensorLayer == 3) {
284 f3 = 1;
285 temp_hitXP.push_back(m_hitXP[j]);
286 j++;
287 while (j < m_hitXP.size() && brk == 0) {
288 if (m_hitXP[j].m_sensorLayer == 4) {
289 f4 = 1;
290 temp_hitXP.push_back(m_hitXP[j]);
291 j++;
292 while (j < m_hitXP.size() && brk == 0) {
293 if (m_hitXP[j].m_sensorLayer == 5) {
294 f5 = 1;
295 temp_hitXP.push_back(m_hitXP[j]);
296 j++;
297 while (j < m_hitXP.size() && brk == 0) {
298 if (m_hitXP[j].m_sensorLayer == 6) {
299 f6 = 1;
300 temp_hitXP.push_back(m_hitXP[j]);
301 brk = 1;
302 j++;
303 }
304 j++;
305 }
306 }
307 j++;
308 }
309 }
310 j++;
311 }
312 }
313 j++;
314 }
315 layer_flag = f3 * f4 * f5 * f6;
316 if (layer_flag != 0) {
317 int k;
318 for (k = 0; k < 4; k = k + 1) {
319 m_hitXPSel.push_back(temp_hitXP[k]);
320 }
324 m_treeSel->Fill();
325 m_hitXPSel.erase(m_hitXPSel.begin(), m_hitXPSel.end());
326 }
327
328
329
330 //-------------------------------------------------------------------------------------------------//
331 //------------------------------------Tight Selected Tree creation--------------------------------------//
332 //-------------------------------------------------------------------------------------------------//
334 if (m_numberHitPerTrack == 4 && m_hitXP[0].m_sensorLayer == 3 && m_hitXP[1].m_sensorLayer == 4
335 && m_hitXP[2].m_sensorLayer == 5 && m_hitXP[3].m_sensorLayer == 6) {
336 int h = 0;
337 for (h = 0; h < 4; h = h + 1) {
338 m_hitXPTiSel.push_back(m_hitXP[h]);
339 }
343 m_treeTiSel->Fill();
344 m_hitXPTiSel.erase(m_hitXPTiSel.begin(), m_hitXPTiSel.end());
345 }
346 m_hitXP.erase(m_hitXP.begin(), m_hitXP.end());
347 m_hitXPSet.clear();
348 }
349}
350
351
352
354{
355 m_outputFile->cd();
356 m_tree->Write();
357 m_outputFile->Close();
358
359 if (c_addTree) {
360 //-------------------------------------------------------------------------------------------------//
361 //------------------------------------selected Tree storage--------------------------------------//
362 //-------------------------------------------------------------------------------------------------//
363 m_outputFileSel->cd();
364 m_treeSel->Write();
365 m_outputFileSel->Close();
366
367
368 //-------------------------------------------------------------------------------------------------//
369 //------------------------------------tight selected Tree storage--------------------------------------//
370 //-------------------------------------------------------------------------------------------------//
371 m_outputFileTiSel->cd();
372 m_treeTiSel->Write();
373 m_outputFileTiSel->Close();
374 }
375
376
377 //-------------------------------------------------------------------------------------------------//
378 //------------------------------------external Tree storage--------------------------------------//
379 //-------------------------------------------------------------------------------------------------//
380 m_outputFileExt->cd();
381 m_treeExt->Write();
382 m_outputFileExt->Close();
383}
384
std::vector< double > m_EmomentumEntryX
exteral momentum at entry point, coordinate x
Definition: HitXPModule.h:97
std::vector< int > m_EclusterV
external flag of v-cluster
Definition: HitXPModule.h:116
TFile * m_outputFile
output file
Definition: HitXPModule.h:67
std::vector< double > m_EomegaEntry
external omega parameter at entry point
Definition: HitXPModule.h:121
std::vector< hitXP > m_hitXPSel
selected vector of hitXP
Definition: HitXPModule.h:80
TTree * m_treeTiSel
tight selected output tree
Definition: HitXPModule.h:85
TTree * m_tree
full output tree
Definition: HitXPModule.h:66
std::vector< double > m_Etanlambda0
external tanlambda parameter at IP
Definition: HitXPModule.h:130
std::vector< double > m_EtanlambdaEntry
external tanlambda parameter at entry point
Definition: HitXPModule.h:129
TTree * m_treeExt
external output tree
Definition: HitXPModule.h:93
std::vector< int > m_EPDGID
external PDGID
Definition: HitXPModule.h:103
std::vector< int > m_EsensorLayer
external layer of the hit
Definition: HitXPModule.h:112
int m_Eprimary
external flag for primary particles
Definition: HitXPModule.h:131
std::vector< double > m_EmomentumEntryY
exteral momentum at entry point, coordinate x
Definition: HitXPModule.h:98
void initialize() override
Initialize the Module.
Definition: HitXPModule.cc:43
int m_eventNumberTiSel
tight selected interative number of the event in the run
Definition: HitXPModule.h:89
bool c_addTree
parameter to produce additional tree
Definition: HitXPModule.h:70
void event() override
This method is the core of the module.
Definition: HitXPModule.cc:154
TFile * m_outputFileSel
selected output file
Definition: HitXPModule.h:79
TTree * m_treeSel
selected output tree
Definition: HitXPModule.h:78
std::vector< double > m_EpositionLocalEntryZ
exteral local position at entry point, coordinate z
Definition: HitXPModule.h:102
std::vector< int > m_Ereconstructed
external flag of track-reconstruction or not
Definition: HitXPModule.h:114
std::vector< double > m_EmomentumEntryZ
exteral momentum at entry point, coordinate x
Definition: HitXPModule.h:99
std::vector< double > m_Etime
external time of the hit
Definition: HitXPModule.h:110
void endRun() override
This method is called if the current run ends.
Definition: HitXPModule.cc:353
std::vector< double > m_Ephi0Entry
external phi0 parameter at entry point
Definition: HitXPModule.h:125
std::vector< double > m_Ed00
external d0 parameter at IP
Definition: HitXPModule.h:124
std::vector< int > m_EsensorSensor
external sensor of the hit
Definition: HitXPModule.h:111
int m_trackNumberSel
selected iterative number of the track in the run
Definition: HitXPModule.h:81
void terminate() override
This method is called at the end of the event processing.
Definition: HitXPModule.cc:385
std::vector< double > m_Emomentum0X
extral momentum at IP, coordinate x
Definition: HitXPModule.h:107
std::vector< double > m_Eposition0X
extral position at IP, coordinate x
Definition: HitXPModule.h:104
std::vector< double > m_EpositionLocalEntryY
exteral local position at entry point, coordinate y
Definition: HitXPModule.h:101
int m_trackIterator
iterator used to count track (m_trackNumber)
Definition: HitXPModule.h:75
std::vector< int > m_EsensorLadder
external ladder of the hit
Definition: HitXPModule.h:113
std::vector< double > m_EpositionLocalEntryX
exteral local position at entry point, coordinate x
Definition: HitXPModule.h:100
std::vector< double > m_Emomentum0Y
extral momentum at IP, coordinate y
Definition: HitXPModule.h:108
std::vector< int > m_EclusterU
external flag of u-cluster
Definition: HitXPModule.h:115
int m_EeventNumber
external iterator of event in the run
Definition: HitXPModule.h:119
std::vector< double > m_EpositionEntryX
exteral position at entry point, coordinate x
Definition: HitXPModule.h:94
int m_numberHitPerTrackTiSel
tight selected counter of the number of the hit for each track
Definition: HitXPModule.h:90
std::vector< hitXP > m_hitXPTiSel
tight selected vector of hitXP
Definition: HitXPModule.h:87
int m_eventNumber
interative number of the event in the run
Definition: HitXPModule.h:73
int m_numberHitPerTrack
counter of the number of the hit for each track
Definition: HitXPModule.h:74
TFile * m_outputFileTiSel
tight selected output file
Definition: HitXPModule.h:86
void beginRun() override
Called when entering a new run.
Definition: HitXPModule.cc:152
int m_trackNumber
iterative number of the track in the run
Definition: HitXPModule.h:72
std::set< hitXP, hitXP::timeCompare > m_hitXPSet
set of the hitXP, used to order tn time he hit
Definition: HitXPModule.h:69
TFile * m_outputFileExt
external output file
Definition: HitXPModule.h:92
std::vector< double > m_EpositionEntryZ
exteral position at entry point, coordinate z
Definition: HitXPModule.h:96
int m_eventNumberSel
selected interative number of the event in the run
Definition: HitXPModule.h:82
std::vector< double > m_Emomentum0Z
extral momentum at IP, coordinate z
Definition: HitXPModule.h:109
int m_trackNumberTiSel
tight selected iterative number of the track in the run
Definition: HitXPModule.h:88
std::vector< double > m_Ephi00
external phi0 parameter at IP
Definition: HitXPModule.h:126
std::vector< double > m_Echarge
external charge
Definition: HitXPModule.h:117
int m_numberHitPerTrackSel
selected counter of the number of the hit for each track
Definition: HitXPModule.h:83
std::vector< hitXP > m_hitXP
vector of the hitXP, used to fill the output tree
Definition: HitXPModule.h:68
int m_EtrackNumber
external iterator of track in the run
Definition: HitXPModule.h:118
std::vector< double > m_EpositionEntryY
exteral position at entry point, coordinate y
Definition: HitXPModule.h:95
int m_eventIterator
iterator used to count event number (m_eventNumber)
Definition: HitXPModule.h:76
std::vector< double > m_Ed0Entry
external d0 parameter at entry point
Definition: HitXPModule.h:123
StoreArray< MCParticle > m_MCParticles
MCParticles StoreArray.
Definition: HitXPModule.h:133
std::vector< double > m_Ez00
external z0 parameter at IP
Definition: HitXPModule.h:128
std::vector< double > m_Eomega0
external omega parameter at IP
Definition: HitXPModule.h:122
std::vector< double > m_Eposition0Z
extral position at IP, coordinate z
Definition: HitXPModule.h:106
int m_EnumberHitPerTrack
external numer of the hit for each track
Definition: HitXPModule.h:120
std::vector< double > m_Eposition0Y
extral position at IP, coordinate y
Definition: HitXPModule.h:105
std::vector< double > m_Ez0Entry
external z0 parameter at entry point
Definition: HitXPModule.h:127
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:79
Low-level class to create/modify relations between StoreArrays.
Definition: RelationArray.h:62
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
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
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.
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
This class is the derivate of HitXP, and complete it with a constructor that use all other complex ty...
Definition: hitXPDerivate.h:27
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:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.