Project
Loading...
Searching...
No Matches
StandaloneAODProducer.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
13
18
22#include "Framework/Logger.h"
23#include "TFile.h"
24
34
35#include <vector>
36
37using namespace o2;
38using namespace o2::framework;
39
41
42template <typename TrackT>
43std::vector<TrackT>* fetchTracks(const char* filename, const char* treename, const char* branchname)
44{
45 TFile file(filename, "OPEN");
46 auto tree = (TTree*)file.Get(treename);
47 auto br = tree->GetBranch(branchname);
48 std::vector<TrackT>* tracks = nullptr;
49 br->SetAddress(&tracks);
50 br->GetEntry(0);
51 return tracks;
52}
53
54// fills the table of Monte Carlo collisions
55// these are the ones references in the digitizer context
57{
58
59 auto digitizationContext = mcreader.getDigitizationContext();
60 const auto& records = digitizationContext->getEventRecords();
61 const auto& parts = digitizationContext->getEventParts();
62
63 TableBuilder mcCollBuilder;
64 auto mcCollCursor = mcCollBuilder.cursor<o2::aod::McCollisions>();
65
66 // QUESTIONS:
67 // Well defined enumeration for Generator type?
68 // What to do with pile-up/embedded collision - which generator type?
69 // In the data model: What are "null / invalid" values or default values
70 // In the data model: What are the units?
71
72 // iterating over records gives us the time information
73 int index = 0;
74 for (auto& rec : records) {
75 // concrete header information is available via the parts and MCKineReader
76 auto time = rec.getTimeNS();
77 auto& colparts = parts[index];
78 // get event ID(s) and source ID(s)
79 // if there are more than one sources --> the generator might differ but vertex etc should be same
80 auto eventID = colparts[0].entryID;
81 auto sourceID = colparts[0].sourceID;
82
83 auto& header = mcreader.getMCEventHeader(eventID, sourceID);
84 //DECLARE_SOA_TABLE(McCollisions, "AOD", "MCCOLLISION", o2::soa::Index<>, mccollision::BCId,
85 // mccollision::GeneratorsID,
86 // mccollision::PosX, mccollision::PosY, mccollision::PosZ, mccollision::T, mccollision::Weight,
87 // mccollision::ImpactParameter);
88
89 mcCollCursor(0, 0 /*bcID*/, 0 /*genID*/, header.GetX(), header.GetY(), header.GetZ(), time, 1. /*weight*/, header.GetB(), 0.0);
90
91 index++;
92 }
93 auto mccoltable = mcCollBuilder.finalize();
94
95 TFile outfile("aod.root", "UPDATE");
96 {
97 TableToTree t2t(mccoltable, &outfile, aod::description_str(aod::signature<o2::aod::McCollisions::ref>()).data());
98 t2t.addAllBranches();
99 t2t.process();
100 }
101}
102
103// add vertices/collisions
105{
106 // open the file for vertices
107 TFile f("o2_primary_vertex.root", "OPEN");
108 auto t = (TTree*)f.Get("o2sim");
109
110 // fetch the tracks (these names are not following any convention!!)
111 auto tpctracks = fetchTracks<o2::tpc::TrackTPC>("tpctracks.root", "tpcrec", "TPCTracks");
112 auto itstracks = fetchTracks<o2::its::TrackITS>("o2trac_its.root", "o2sim", "ITSTrack");
113 auto itstpctracks = fetchTracks<o2::dataformats::TrackTPCITS>("o2match_itstpc.root", "matchTPCITS", "TPCITS");
114 LOG(info) << "FOUND " << tpctracks->size() << " TPC tracks";
115 LOG(info) << "FOUND " << itstracks->size() << " ITS tracks";
116 LOG(info) << "FOUND " << itstpctracks->size() << " ITCTPC tracks";
117
118 if (t) {
119 auto br = t->GetBranch("PrimaryVertex");
120 std::vector<o2::dataformats::PrimaryVertex>* vertices = nullptr;
121 br->SetAddress(&vertices);
122 br->GetEntry(0);
123
124 // this referes to actual tracks
125 auto indexbr = t->GetBranch("PVTrackIndices");
126 std::vector<GIndex>* vertexTrackIDs = nullptr;
127 indexbr->SetAddress(&vertexTrackIDs);
128 indexbr->GetEntry(0);
129
130 // this makes the connection of vertex to track indices
131 auto v2totrackrefbr = t->GetBranch("PV2TrackRefs");
132 std::vector<o2::dataformats::VtxTrackRef>* v2trackref = nullptr;
133 v2totrackrefbr->SetAddress(&v2trackref);
134 v2totrackrefbr->GetEntry(0);
135
136 if (vertices && vertexTrackIDs) {
137 TableBuilder collBuilder;
138 auto collCursor = collBuilder.cursor<o2::aod::Collisions>();
139
140 TableBuilder trackBuilder;
141 auto trackCursor = trackBuilder.cursor<o2::aod::StoredTracks>();
142
143 int index = 0;
144 for (auto& v : *vertices) {
145 //DECLARE_SOA_TABLE(Collisions, "AOD", "COLLISION", o2::soa::Index<>,
146 // collision::BCId, collision::PosX, collision::PosY, collision::PosZ,
147 // collision::CovXX, collision::CovXY, collision::CovXZ, collision::CovYY, collision::CovYZ, collision::CovZZ,
148 // collision::Chi2, collision::NumContrib, collision::CollisionTime, collision::CollisionTimeRes, collision::CollisionTimeMask);
149 int BCid = 0;
150 auto& cov = v.getCov();
151 auto& ts = v.getTimeStamp();
152
153 // TODO: figure out BC + CollisionTimeMask
154 collCursor(0, BCid, v.getX(), v.getY(), v.getZ(),
155 cov[0], cov[1], cov[2], cov[3], cov[4], cov[6],
156 v.getFlags(), v.getChi2(), v.getNContributors(), ts.getTimeStamp(), ts.getTimeStampError());
157
158 // get the track for each vertex and fill the tracks table
159 // now go over tracks via the indices
160 auto& trackref = (*v2trackref)[index];
161 int start = trackref.getFirstEntryOfSource(0);
162 int ntracks = trackref.getEntriesOfSource(0);
163 for (int ti = 0; ti < ntracks; ++ti) {
164 auto trackindex = (*vertexTrackIDs)[start + ti];
165
166 // now we need to fetch the actual track and fill the table
167 const auto source = trackindex.getSource();
168 o2::track::TrackParCov* track = nullptr;
170 track = &((*tpctracks)[trackindex.getIndex()]);
172 track = &((*itstracks)[trackindex.getIndex()]);
174 track = &((*itstpctracks)[trackindex.getIndex()]);
175 } else {
176 LOG(warning) << "Unsupported track source";
177 }
178
179 //DECLARE_SOA_TABLE_FULL(StoredTracks, "Tracks", "AOD", "TRACK:PAR",
180 // o2::soa::Index<>, track::CollisionId, track::TrackType,
181 // track::X, track::Alpha,
182 // track::Y, track::Z, track::Snp, track::Tgl,
183 // track::Signed1Pt,
184 // track::NormalizedPhi<track::RawPhi>,
185 // track::Px<track::Signed1Pt, track::Snp, track::Alpha>,
186 // track::Py<track::Signed1Pt, track::Snp, track::Alpha>,
187 // track::Pz<track::Signed1Pt, track::Tgl>,
188 // track::Charge<track::Signed1Pt>);
189
190 std::array<float, 3> pxpypz;
191 track->getPxPyPzGlo(pxpypz);
192 trackCursor(0, index, 0 /* CORRECT THIS */, track->getX(), track->getAlpha(), track->getY(), track->getZ(), track->getSnp(), track->getTgl(),
193 track->getPt() /*CHECK!!*/);
194 }
195 index++;
196 }
197 auto colltable = collBuilder.finalize();
198 auto tracktable = trackBuilder.finalize();
199
200 f.Close();
201 TFile outfile("aod.root", "RECREATE");
202 {
203 TableToTree t2t(colltable, &outfile, aod::description_str(aod::signature<o2::aod::Collisions::ref>()).data());
204 t2t.addAllBranches();
205 t2t.process();
206 }
207 {
208 TableToTree t2t(tracktable, &outfile, aod::description_str(aod::signature<o2::aod::StoredTracks::ref>()).data());
209 t2t.addAllBranches();
210 t2t.process();
211 }
212 }
213 }
214}
215
216// TODO: add MCparticles
217
218int main()
219{
221
222 o2::steer::MCKinematicsReader mcreader("collisioncontext.root");
223 fillMCollisionTable(mcreader);
224
225 return 0;
226}
std::vector< o2::soa::IndexRecord > records
int16_t time
Definition RawEventData.h:4
std::vector< std::string > header
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual Show related Highlight grid Show only individual collision Color clusters belonging to track objects Set line Enable drawing TPC data Enable drawing TOF data Enable drawing magnetic field Set field line step count Invert colors configStandalone Heavy OpenGL display display_heavy Show tracks with ITS contribution Show tracks with TOF contribution Enable propagation of loopers Show clusters at nominal x of pad row for early transformed data Split CE tracks when they cross the central Mark clusters Mark adjacent clusters Hide rejected tracks Apply filter on tracks to be displayed Separate increase X h configStandalone Camera window renderer OpenGL display display_camera Orient the camera such that the y axis is always upwards Full Screen MultiSample Anti Downsampling Anti Enable Vertical Sync Target frame or if the backend cannot limit to the refresh Use OpenGL indirect draws to reduce number of draw calls Display h configStandalone Vulkan display display_vulkan Have uniform buffers in host accessible device memory h configStandalone Internal display display_internal Number of updates the Qt GUI may send ahead of the last one the display has before it waits for the display Opacity of the console background Number of console lines the history is shortened to this when it reaches twice the size Time in seconds an info message fades out after setInfoTime h OpenGL display display Font size Do not use Freetype for font Renderer for event Frontend to use for event ROOT macros used as track filter Console script file
configStandalone rec
std::vector< o2::its::TrackITS > tracks
std::vector< TrackT > * fetchTracks(const char *filename, const char *treename, const char *branchname)
void fillCollisionAndTrackTable()
void fillMCollisionTable(o2::steer::MCKinematicsReader const &mcreader)
Definition of the ITS track.
Result of refitting TPC-ITS matched track.
Extention of GlobalTrackID by flags relevant for verter-track association.
Referenc on track indices contributing to the vertex, with possibility chose tracks from specific sou...
std::shared_ptr< arrow::Table > finalize()
std::shared_ptr< TTree > process()
std::vector< o2::InteractionTimeRecord > & getEventRecords(bool withQED=false)
DigitizationContext const * getDigitizationContext() const
o2::dataformats::MCEventHeader const & getMCEventHeader(int source, int event) const
retrieves the MCEventHeader for a given eventID and sourceID
const GLdouble * v
Definition glcorearb.h:832
GLuint index
Definition glcorearb.h:781
GLdouble f
Definition glcorearb.h:310
GLsizei GLsizei GLchar * source
Definition glcorearb.h:798
McCollisions_001 McCollisions
Collisions_001 Collisions
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
TrackParCovF TrackParCov
Definition Track.h:33
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string filename()
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))