forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunCATrackingClusterNative.C
More file actions
136 lines (118 loc) · 4.83 KB
/
runCATrackingClusterNative.C
File metadata and controls
136 lines (118 loc) · 4.83 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
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#if !defined(__CLING__) || defined(__ROOTCLING__)
#include <fstream>
#include <iostream>
#include <vector>
#include "TSystem.h"
#include "TChain.h"
#include "TClonesArray.h"
#include "TFile.h"
#include "TROOT.h"
#include "TTree.h"
#include "DataFormatsTPC/ClusterNative.h"
#include "DataFormatsTPC/ClusterNativeHelper.h"
#include "DataFormatsTPC/Helpers.h"
#include "ReconstructionDataFormats/Track.h"
#include "SimulationDataFormat/MCCompLabel.h"
#include "SimulationDataFormat/MCTruthContainer.h"
#include "DataFormatsTPC/Constants.h"
#include "TPCReconstruction/TPCCATracking.h"
#include "DataFormatsTPC/TrackTPC.h"
#else
#pragma cling load("libTPCReconstruction")
#pragma cling load("libDataFormatsTPC")
#endif
using namespace o2::TPC;
using namespace o2::dataformats;
using namespace std;
using MCLabelContainer = MCTruthContainer<o2::MCCompLabel>;
// This is a prototype of a macro to test running the HLT O2 CA Tracking library on a root input file containg
// TClonesArray of clusters.
// It wraps the TPCCATracking class, forwwarding all parameters, which are passed as options.
int runCATrackingClusterNative(TString inputFile, TString outputFile, TString options = "")
{
if (inputFile.EqualTo("") || outputFile.EqualTo("")) {
printf("Filename missing\n");
return (1);
}
TPCCATracking tracker;
if (tracker.initialize(options.Data())) {
printf("Error initializing tracker\n");
return (0);
}
std::vector<ClusterNativeContainer> cont;
std::vector<MCLabelContainer> contMC;
bool doMC = true;
TFile fin(inputFile);
for (int i = 0; i < Constants::MAXSECTOR; i++) {
for (int j = 0; j < Constants::MAXGLOBALPADROW; j++) {
TString contName = Form("clusters_sector_%d_row_%d", i, j);
TObject* tmp = fin.FindObjectAny(contName);
if (tmp == nullptr) {
printf("Error reading clusters %s\n", contName.Data());
} else {
cont.emplace_back(std::move(*reinterpret_cast<ClusterNativeContainer*>(tmp)));
tmp = fin.FindObjectAny(Form("clustersMCTruth_sector_%d_row_%d", i, j));
if (tmp == nullptr) {
printf("Error, clustersMCTruth missing or clusters and clustersMCtruth out of sync! Disabling MC data\n");
doMC = false;
} else {
contMC.emplace_back(std::move(*reinterpret_cast<MCLabelContainer*>(tmp)));
}
}
}
}
fin.Close();
std::unique_ptr<ClusterNativeAccessFullTPC> clusters =
ClusterNativeHelper::createClusterNativeIndex(cont, doMC ? &contMC : nullptr);
vector<TrackTPC> tracks;
MCLabelContainer tracksMC;
TFile fout(outputFile, "recreate");
TTree tout("events", "events");
tout.Branch("Tracks", &tracks);
tout.Branch("TracksMCTruth", &tracksMC);
printf("Processing time frame\n");
if (tracker.runTracking(*clusters, &tracks, doMC ? &tracksMC : nullptr) == 0) {
printf("\tFound %d tracks\n", (int)tracks.size());
} else {
printf("\tError during tracking\n");
}
float artificialVDrift = tracker.getPseudoVDrift();
float tfReferenceLength = tracker.getTFReferenceLength();
// partial printout of 100 tracks
int step = tracks.size() / 100;
step = step < 1 ? 1 : step;
for (unsigned int i = 0; i < tracks.size(); i += step) {
// Loop over clusters
for (int j = tracks[i].getNClusterReferences() - 1; j >= 0; j--) {
// Get cluster references
uint8_t sector, row;
uint32_t clusterIndexInRow;
tracks[i].getClusterReference(j, sector, row, clusterIndexInRow);
const ClusterNative& cl = tracks[i].getCluster(j, *clusters, sector, row);
const ClusterNative& clLast = tracks[i].getCluster(0, *clusters);
// RS: TODO: account for possible A/C merged tracks
float sideFactor = tracks[i].hasASideClustersOnly() ? -1.f : 1.f;
printf(
"Track %d: Side %s Estimated timeVertex: %f, num clusters %d, innermost cluster: sector %d, row %d, "
"ClusterTime %f, TrackParam X %f Z %f --> T %f, LastClusterT: %f\n",
i, tracks[i].hasBothSidesClusters() ? "AC" : (tracks[i].hasASideClusters() ? "A" : "C"), tracks[i].getTime0(),
tracks[i].getNClusterReferences(), (int)sector, (int)row, cl.getTime(), tracks[i].getX(), tracks[i].getZ(),
tracks[i].getTime0() - sideFactor * tracks[i].getZ() / artificialVDrift, clLast.getTime());
break; // Reduce output in this example code
}
}
tout.Fill();
fout.Write();
fout.Close();
tracker.deinitialize();
return (0);
}