forked from mcoquet642/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckTOFMatching.C
More file actions
239 lines (220 loc) · 11.6 KB
/
Copy pathcheckTOFMatching.C
File metadata and controls
239 lines (220 loc) · 11.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#if !defined(__CLING__) || defined(__ROOTCLING__)
#include "TFile.h"
#include "TTree.h"
#include "GlobalTracking/MatchTOF.h"
#include "ReconstructionDataFormats/TrackTPCITS.h"
#include "SimulationDataFormat/MCTruthContainer.h"
#include "SimulationDataFormat/MCCompLabel.h"
#endif
void checkTOFMatching()
{
// macro to check the matching TOF-ITSTPC tracks
// getting TOF info
TFile* fmatchTOF = new TFile("o2match_tof.root");
TTree* matchTOF = (TTree*)fmatchTOF->Get("matchTOF");
std::vector<o2::dataformats::MatchInfoTOF>* TOFMatchInfo;
TOFMatchInfo = new std::vector<o2::dataformats::MatchInfoTOF>;
matchTOF->SetBranchAddress("TOFMatchInfo", &TOFMatchInfo);
// getting the ITSTPCtracks
TFile* fmatchITSTPC = new TFile("o2match_itstpc.root");
TTree* matchTPCITS = (TTree*)fmatchITSTPC->Get("matchTPCITS");
std::vector<o2::dataformats::TrackTPCITS>* mTracksArrayInp = new std::vector<o2::dataformats::TrackTPCITS>;
matchTPCITS->SetBranchAddress("TPCITS", &mTracksArrayInp);
// getting the TPC tracks
TFile* ftracksTPC = new TFile("tpctracks.root");
TTree* tpcTree = (TTree*)ftracksTPC->Get("events");
std::vector<o2::tpc::TrackTPC>* mTPCTracksArrayInp = new std::vector<o2::tpc::TrackTPC>;
tpcTree->SetBranchAddress("Tracks", &mTPCTracksArrayInp);
o2::dataformats::MCTruthContainer<o2::MCCompLabel>* mcTPC = new o2::dataformats::MCTruthContainer<o2::MCCompLabel>();
tpcTree->SetBranchAddress("TracksMCTruth", &mcTPC);
// getting the ITS tracks
TFile* ftracksITS = new TFile("o2trac_its.root");
TTree* itsTree = (TTree*)ftracksITS->Get("o2sim");
std::vector<o2::its::TrackITS>* mITSTracksArrayInp = new std::vector<o2::its::TrackITS>;
itsTree->SetBranchAddress("ITSTrack", &mITSTracksArrayInp);
o2::dataformats::MCTruthContainer<o2::MCCompLabel>* mcITS = new o2::dataformats::MCTruthContainer<o2::MCCompLabel>();
itsTree->SetBranchAddress("ITSTrackMCTruth", &mcITS);
// getting the TOF clusters
TFile* fclustersTOF = new TFile("tofclusters.root");
TTree* tofClTree = (TTree*)fclustersTOF->Get("o2sim");
std::vector<o2::tof::Cluster>* mTOFClustersArrayInp = new std::vector<o2::tof::Cluster>;
tofClTree->SetBranchAddress("TOFCluster", &mTOFClustersArrayInp);
o2::dataformats::MCTruthContainer<o2::MCCompLabel>* mcTOF = new o2::dataformats::MCTruthContainer<o2::MCCompLabel>();
tofClTree->SetBranchAddress("TOFClusterMCTruth", &mcTOF);
tpcTree->GetEntry(0);
tofClTree->GetEntry(0);
int nMatches = 0;
int nGoodMatches = 0;
int nBadMatches = 0;
itsTree->GetEntry(0);
// now looping over the entries in the matching tree
for (int ientry = 0; ientry < matchTOF->GetEntries(); ientry++) {
matchTOF->GetEvent(ientry);
matchTPCITS->GetEntry(ientry);
// now looping over the matched tracks
nMatches += TOFMatchInfo->size();
for (int imatch = 0; imatch < TOFMatchInfo->size(); imatch++) {
int indexITSTPCtrack = TOFMatchInfo->at(imatch).getTrackIndex();
o2::dataformats::MatchInfoTOF infoTOF = TOFMatchInfo->at(imatch);
int tofClIndex = infoTOF.getTOFClIndex();
float chi2 = infoTOF.getChi2();
Printf("\nentry in tree %d, matching %d, indexITSTPCtrack = %d, tofClIndex = %d, chi2 = %f", ientry, imatch, indexITSTPCtrack, tofClIndex, chi2);
// o2::MCCompLabel label = mcTOF->getElement(mcTOF->getMCTruthHeader(tofClIndex).index);
const auto& labelsTOF = mcTOF->getLabels(tofClIndex);
int trackIdTOF;
int eventIdTOF;
int sourceIdTOF;
for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++) {
Printf("TOF label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTOF[ilabel].getTrackID(), labelsTOF[ilabel].getEventID(), labelsTOF[ilabel].getSourceID());
if (ilabel == 0) {
trackIdTOF = labelsTOF[ilabel].getTrackID();
eventIdTOF = labelsTOF[ilabel].getEventID();
sourceIdTOF = labelsTOF[ilabel].getSourceID();
}
}
o2::tof::Cluster tofCluster = mTOFClustersArrayInp->at(tofClIndex);
int nContributingChannels = tofCluster.getNumOfContributingChannels();
int mainContributingChannel = tofCluster.getMainContributingChannel();
Printf("The TOF cluster has %d contributing channels, and the main one is %d", nContributingChannels, mainContributingChannel);
int* indices = new int();
o2::tof::Geo::getVolumeIndices(mainContributingChannel, indices);
Printf("Indices of main contributing channel are %d, %d, %d, %d, %d", indices[0], indices[1], indices[2], indices[3], indices[4]);
bool isUpLeft = tofCluster.isAdditionalChannelSet(o2::tof::Cluster::kUpLeft);
bool isUp = tofCluster.isAdditionalChannelSet(o2::tof::Cluster::kUp);
bool isUpRight = tofCluster.isAdditionalChannelSet(o2::tof::Cluster::kUpRight);
bool isRight = tofCluster.isAdditionalChannelSet(o2::tof::Cluster::kRight);
bool isDownRight = tofCluster.isAdditionalChannelSet(o2::tof::Cluster::kDownRight);
bool isDown = tofCluster.isAdditionalChannelSet(o2::tof::Cluster::kDown);
bool isDownLeft = tofCluster.isAdditionalChannelSet(o2::tof::Cluster::kDownLeft);
bool isLeft = tofCluster.isAdditionalChannelSet(o2::tof::Cluster::kLeft);
Printf("isUpLeft = %d, isUp = %d, isUpRight = %d, isRight = %d, isDownRight = %d, isDown = %d, isDownLeft = %d, isLeft = %d", isUpLeft, isUp, isUpRight, isRight, isDownRight, isDown, isDownLeft, isLeft);
int* indexCont = new int();
indexCont[0] = indices[0];
indexCont[1] = indices[1];
indexCont[2] = indices[2];
indexCont[3] = indices[3];
indexCont[4] = indices[4];
int numberOfSecondaryContributingChannels = 0;
int secondaryContributingChannel = -1;
if (isDown) {
indexCont[3]--;
numberOfSecondaryContributingChannels++;
secondaryContributingChannel = o2::tof::Geo::getIndex(indexCont);
Printf("secondaryContributingChannel[down] = %d", secondaryContributingChannel);
indexCont[3] = indices[3];
}
if (isDownRight) {
indexCont[3]--;
indexCont[4]++;
numberOfSecondaryContributingChannels++;
secondaryContributingChannel = o2::tof::Geo::getIndex(indexCont);
Printf("secondaryContributingChannel[downright] = %d", secondaryContributingChannel);
indexCont[3] = indices[3];
indexCont[4] = indices[4];
}
if (isDownLeft) {
indexCont[3]--;
indexCont[4]--;
numberOfSecondaryContributingChannels++;
secondaryContributingChannel = o2::tof::Geo::getIndex(indexCont);
Printf("secondaryContributingChannel[downleft] = %d", secondaryContributingChannel);
indexCont[3] = indices[3];
indexCont[4] = indices[4];
}
if (isUp) {
indexCont[3]++;
numberOfSecondaryContributingChannels++;
secondaryContributingChannel = o2::tof::Geo::getIndex(indexCont);
Printf("secondaryContributingChannel[up] = %d", secondaryContributingChannel);
indexCont[3] = indices[3];
}
if (isUpRight) {
indexCont[3]++;
indexCont[4]++;
numberOfSecondaryContributingChannels++;
secondaryContributingChannel = o2::tof::Geo::getIndex(indexCont);
Printf("secondaryContributingChannel[upright] = %d", secondaryContributingChannel);
indexCont[3] = indices[3];
indexCont[4] = indices[4];
}
if (isUpLeft) { // increase padZ
indexCont[3]++;
indexCont[4]--;
numberOfSecondaryContributingChannels++;
secondaryContributingChannel = o2::tof::Geo::getIndex(indexCont);
Printf("secondaryContributingChannel[upleft] = %d", secondaryContributingChannel);
indexCont[3] = indices[3];
indexCont[4] = indices[4];
}
if (isRight) { // increase padX
indexCont[4]++;
numberOfSecondaryContributingChannels++;
secondaryContributingChannel = o2::tof::Geo::getIndex(indexCont);
Printf("secondaryContributingChannel[right] = %d", secondaryContributingChannel);
indexCont[4] = indices[4];
}
if (isLeft) { // decrease padX
indexCont[4]--;
numberOfSecondaryContributingChannels++;
secondaryContributingChannel = o2::tof::Geo::getIndex(indexCont);
Printf("secondaryContributingChannel[left] = %d", secondaryContributingChannel);
indexCont[4] = indices[4];
}
Printf("Total number of secondary channels= %d", numberOfSecondaryContributingChannels);
o2::dataformats::TrackTPCITS trackITSTPC = mTracksArrayInp->at(indexITSTPCtrack);
const auto evIdxTPC = trackITSTPC.getRefTPC();
Printf("matched TPCtrack index = %d", evIdxTPC);
const auto evIdxITS = trackITSTPC.getRefITS();
Printf("matched ITStrack index = %d", evIdxITS);
// getting the TPC labels
const auto& labelsTPC = mcTPC->getLabels(evIdxTPC);
for (int ilabel = 0; ilabel < labelsTPC.size(); ilabel++) {
Printf("TPC label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTPC[ilabel].getTrackID(), labelsTPC[ilabel].getEventID(), labelsTPC[ilabel].getSourceID());
}
// getting the ITS labels
const auto& labelsITS = mcITS->getLabels(evIdxITS);
for (int ilabel = 0; ilabel < labelsITS.size(); ilabel++) {
Printf("ITS label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsITS[ilabel].getTrackID(), labelsITS[ilabel].getEventID(), labelsITS[ilabel].getSourceID());
}
bool bMatched = kFALSE;
for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++) {
if ((abs(labelsTPC[0].getTrackID()) == labelsTOF[ilabel].getTrackID() && labelsTPC[0].getEventID() == labelsTOF[ilabel].getEventID() && labelsTPC[0].getSourceID() == labelsTOF[ilabel].getSourceID()) || (labelsITS[0].getTrackID() == labelsTOF[ilabel].getTrackID() && labelsITS[0].getEventID() == labelsTOF[ilabel].getEventID() && labelsITS[0].getSourceID() == labelsTOF[ilabel].getSourceID())) {
nGoodMatches++;
bMatched = kTRUE;
break;
}
}
if (!bMatched)
nBadMatches++;
bool TPCfound = false;
bool ITSfound = false;
for (int i = 0; i < mTracksArrayInp->size(); i++) {
o2::dataformats::TrackTPCITS trackITSTPC = mTracksArrayInp->at(i);
const auto evIdxTPCcheck = trackITSTPC.getRefTPC();
const auto evIdxITScheck = trackITSTPC.getRefITS();
const auto& labelsTPCcheck = mcTPC->getLabels(evIdxTPCcheck);
for (int ilabel = 0; ilabel < labelsTPCcheck.size(); ilabel++) {
if (abs(labelsTPCcheck[ilabel].getTrackID()) == trackIdTOF && labelsTPCcheck[ilabel].getEventID() == eventIdTOF && labelsTPCcheck[ilabel].getSourceID() == sourceIdTOF) {
Printf("The TPC track that should have been matched to TOF is number %d", i);
TPCfound = true;
}
}
const auto& labelsITScheck = mcITS->getLabels(evIdxITScheck);
for (int ilabel = 0; ilabel < labelsITScheck.size(); ilabel++) {
if (labelsITScheck[ilabel].getTrackID() == trackIdTOF && labelsITScheck[ilabel].getEventID() == eventIdTOF && labelsITScheck[ilabel].getSourceID() == sourceIdTOF) {
Printf("The ITS track that should have been matched to TOF is number %d", i);
ITSfound = true;
}
}
}
if (!TPCfound)
Printf("There is no TPC track found that should have corresponded to this TOF cluster!");
if (!ITSfound)
Printf("There is no ITS track found that should have corresponded to this TOF cluster!");
}
}
Printf("Number of matches = %d", nMatches);
Printf("Number of GOOD matches = %d (%.2f)", nGoodMatches, (float)nGoodMatches / nMatches);
Printf("Number of BAD matches = %d (%.2f)", nBadMatches, (float)nBadMatches / nMatches);
return;
}