forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_trac_its.C
More file actions
183 lines (154 loc) · 6.31 KB
/
Copy pathrun_trac_its.C
File metadata and controls
183 lines (154 loc) · 6.31 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
#if !defined(__CLING__) || defined(__ROOTCLING__)
#include <memory>
#include <string>
#include <TChain.h>
#include <TFile.h>
#include <TTree.h>
#include <TGeoGlobalMagField.h>
#include <TStopwatch.h>
#include <FairEventHeader.h>
#include <FairGeoParSet.h>
#include <FairLogger.h>
#include <FairMCEventHeader.h>
#include "DetectorsCommonDataFormats/DetID.h"
#include "DataFormatsITSMFT/Cluster.h"
#include "DataFormatsITSMFT/ROFRecord.h"
#include "DataFormatsParameters/GRPObject.h"
#include "DetectorsBase/GeometryManager.h"
#include "DetectorsBase/Propagator.h"
#include "Field/MagneticField.h"
#include "ITSBase/GeometryTGeo.h"
#include "ITSReconstruction/CookedTracker.h"
#include "MathUtils/Utils.h"
#include "SimulationDataFormat/MCCompLabel.h"
#include "SimulationDataFormat/MCTruthContainer.h"
#include "ReconstructionDataFormats/Vertex.h"
#endif
#include "ITStracking/ROframe.h"
#include "ITStracking/IOUtils.h"
#include "ITStracking/Vertexer.h"
#include "ITStracking/VertexerTraits.h"
using MCLabCont = o2::dataformats::MCTruthContainer<o2::MCCompLabel>;
using Vertex = o2::dataformats::Vertex<o2::dataformats::TimeStamp<int>>;
void run_trac_its(std::string path = "./", std::string outputfile = "o2trac_its.root",
std::string inputClustersITS = "o2clus_its.root", std::string inputGeom = "O2geometry.root",
std::string inputGRP = "o2sim_grp.root", std::string simfilename = "o2sim.root")
{
FairLogger* logger = FairLogger::GetLogger();
logger->SetLogVerbosityLevel("LOW");
logger->SetLogScreenLevel("INFO");
// Setup timer
TStopwatch timer;
if (path.back() != '/') {
path += '/';
}
//-------- init geometry and field --------//
const auto grp = o2::parameters::GRPObject::loadFrom(path + inputGRP);
if (!grp) {
LOG(FATAL) << "Cannot run w/o GRP object" << FairLogger::endl;
}
bool isITS = grp->isDetReadOut(o2::detectors::DetID::ITS);
if (!isITS) {
LOG(WARNING) << "ITS is not in the readoute" << FairLogger::endl;
return;
}
bool isContITS = grp->isDetContinuousReadOut(o2::detectors::DetID::ITS);
LOG(INFO) << "ITS is in " << (isContITS ? "CONTINUOS" : "TRIGGERED") << " readout mode" << FairLogger::endl;
o2::base::GeometryManager::loadGeometry(path + inputGeom, "FAIRGeom");
auto gman = o2::its::GeometryTGeo::Instance();
gman->fillMatrixCache(o2::utils::bit2Mask(o2::TransformType::T2GRot)); // request cached transforms
o2::base::Propagator::initFieldFromGRP(grp);
auto field = static_cast<o2::field::MagneticField*>(TGeoGlobalMagField::Instance()->GetField());
if (!field) {
LOG(FATAL) << "Failed to load ma" << FairLogger::endl;
}
//>>>---------- attach input data --------------->>>
TChain itsClusters("o2sim");
itsClusters.AddFile((path + inputClustersITS).data());
if (!itsClusters.GetBranch("ITSCluster")) {
LOG(FATAL) << "Did not find ITS clusters branch ITSCluster in the input tree" << FairLogger::endl;
}
std::vector<o2::itsmft::Cluster>* clusters = nullptr;
itsClusters.SetBranchAddress("ITSCluster", &clusters);
std::vector<o2::itsmft::Cluster> allClusters;
MCLabCont* labels = nullptr;
if (!itsClusters.GetBranch("ITSClusterMCTruth")) {
LOG(WARNING) << "Did not find ITS clusters branch ITSClusterMCTruth in the input tree" << FairLogger::endl;
} else {
itsClusters.SetBranchAddress("ITSClusterMCTruth", &labels);
}
MCLabCont allLabels;
TChain itsClustersROF("ITSClustersROF");
itsClustersROF.AddFile((path + inputClustersITS).data());
if (!itsClustersROF.GetBranch("ITSClustersROF")) {
LOG(FATAL) << "Did not find ITS clusters branch ITSClustersROF in the input tree" << FairLogger::endl;
}
std::vector<o2::itsmft::ROFRecord>* rofs = nullptr;
itsClustersROF.SetBranchAddress("ITSClustersROF", &rofs);
itsClustersROF.GetEntry(0);
//<<<---------- attach input data ---------------<<<
//>>>--------- create/attach output ------------->>>
// create/attach output tree
TFile outFile((path + outputfile).data(), "recreate");
TTree outTree("o2sim", "Cooked ITS Tracks");
std::vector<o2::its::TrackITS> tracksITS, *tracksITSPtr = &tracksITS;
std::vector<int> trackClIdx, *trackClIdxPtr = &trackClIdx;
MCLabCont trackLabels, *trackLabelsPtr = &trackLabels;
outTree.Branch("ITSTrack", &tracksITSPtr);
outTree.Branch("ITSTrackClusIdx", &trackClIdxPtr);
outTree.Branch("ITSTrackMCTruth", &trackLabelsPtr);
TTree treeROF("ITSTracksROF", "ROF records tree");
treeROF.Branch("ITSTracksROF", &rofs);
//<<<--------- create/attach output -------------<<<
//=================== INIT ==================
Int_t n = 1; // Number of threads
Bool_t mcTruth = kTRUE; // kFALSE if no comparison with MC is needed
o2::its::CookedTracker tracker(n);
tracker.setContinuousMode(isContITS);
tracker.setBz(field->solenoidField()); // in kG
tracker.setGeometry(gman);
if (mcTruth)
tracker.setMCTruthContainers(&allLabels, trackLabelsPtr);
//===========================================
// Load all clusters into a single vector
int prevEntry = -1;
int offset = 0;
for (auto& rof : *rofs) {
int entry = rof.getROFEntry().getEvent();
if (entry > prevEntry) { // In principal, there should be just one entry...
if (itsClusters.GetEntry(entry) <= 0) {
LOG(ERROR) << "ITSDigitReader: empty digit entry, or read error !";
return;
}
prevEntry = entry;
offset = allClusters.size();
std::copy(clusters->begin(), clusters->end(), std::back_inserter(allClusters));
allLabels.mergeAtBack(*labels);
}
rof.getROFEntry().setEvent(0);
int index = rof.getROFEntry().getIndex();
rof.getROFEntry().setIndex(index + offset);
std::cout << "entry nclusters offset " << entry << ' ' << clusters->size() << ' ' << offset << '\n';
}
o2::its::VertexerTraits vertexerTraits;
o2::its::Vertexer vertexer(&vertexerTraits);
o2::its::ROframe event(0);
for (auto& rof : *rofs) {
o2::its::IOUtils::loadROFrameData(rof, event, &allClusters, &allLabels);
vertexer.clustersToVertices(event);
auto vertices = vertexer.exportVertices();
if (vertices.empty()) {
vertices.emplace_back();
}
tracker.setVertices(vertices);
tracker.process(allClusters, tracksITS, trackClIdx, rof);
}
outTree.Fill();
treeROF.Fill();
outFile.cd();
outTree.Write();
treeROF.Write();
outFile.Close();
timer.Stop();
timer.Print();
}