Skip to content

Commit 34f84cc

Browse files
authored
Update AOD conversion to match latest O2 DM (#48)
- Add tree for counter of entries - Streamline Tree filling and writing - Save particle vertex position in cm - Cleanup default config file - Remove misleading eta max from configuration file - Add tool to compare too AODs
1 parent a753367 commit 34f84cc

File tree

5 files changed

+269
-200
lines changed

5 files changed

+269
-200
lines changed

examples/aod/createO2tables.C

Lines changed: 62 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,18 @@ void createO2tables(const char* inputFile = "delphes.root",
163163

164164
// create output
165165
auto fout = TFile::Open(outputFile, "RECREATE");
166-
TTree* tBC = MakeTreeO2bc();
167-
TTree* fTracks = MakeTreeO2track();
168-
TTree* fRICH = MakeTreeO2rich();
169-
TTree* tEvents = MakeTreeO2collision();
170-
TTree* tMCvtx = MakeTreeO2mccollision();
171-
TTree* tKinematics = MakeTreeO2mcparticle();
172-
TTree* tLabels = MakeTreeO2mctracklabel();
173-
TTree* tCollisionLabels = MakeTreeO2mccollisionlabel();
166+
// Make output Trees
167+
MakeTreeO2bc();
168+
MakeTreeO2track();
169+
MakeTreeO2trackCov();
170+
MakeTreeO2trackExtra();
171+
MakeTreeO2rich();
172+
MakeTreeO2collision();
173+
MakeTreeO2collisionExtra();
174+
MakeTreeO2mccollision();
175+
MakeTreeO2mcparticle();
176+
MakeTreeO2mctracklabel();
177+
MakeTreeO2mccollisionlabel();
174178

175179
const UInt_t mTrackX = 0xFFFFFFFF;
176180
const UInt_t mTrackAlpha = 0xFFFFFFFF;
@@ -181,20 +185,26 @@ void createO2tables(const char* inputFile = "delphes.root",
181185
const UInt_t mTrackCovOffDiag = 0xFFFFFFFF;
182186
const UInt_t mTrackSignal = 0xFFFFFFFF; // PID signals and track length
183187

188+
// Counters
184189
int fOffsetLabel = 0;
185190
int fTrackCounter = 0; // Counter for the track index, needed for derived tables e.g. RICH. To be incremented at every track filled!
186-
for (Int_t ientry = 0; ientry < numberOfEntries; ++ientry) {
191+
192+
for (Int_t ientry = 0; ientry < numberOfEntries; ++ientry) { // Loop over events
193+
// Adjust start indices for this event in all trees by adding the number of entries of the previous event
194+
for (auto i = 0; i < kTrees; ++i) {
195+
eventextra.fStart[i] += eventextra.fNentries[i];
196+
eventextra.fNentries[i] = 0;
197+
}
187198

188199
// Load selected branches with data from specified event
189200
treeReader->ReadEntry(ientry);
190201

191-
// loop over particles
192-
for (Int_t iparticle = 0; iparticle < particles->GetEntries(); ++iparticle) {
202+
for (Int_t iparticle = 0; iparticle < particles->GetEntries(); ++iparticle) { // Loop over particles
193203
auto particle = (GenParticle*)particles->At(iparticle);
194204

195205
particle->SetUniqueID(iparticle + fOffsetLabel); // not sure this is needed, to be sure
196206

197-
mcparticle.fMcCollisionsID = ientry + eventOffset;
207+
mcparticle.fIndexMcCollisions = ientry + eventOffset;
198208
mcparticle.fPdgCode = particle->PID;
199209
mcparticle.fStatusCode = particle->Status;
200210
mcparticle.fFlags = 0;
@@ -220,20 +230,20 @@ void createO2tables(const char* inputFile = "delphes.root",
220230
mcparticle.fPz = particle->Pz;
221231
mcparticle.fE = particle->E;
222232

223-
mcparticle.fVx = particle->X;
224-
mcparticle.fVy = particle->Y;
225-
mcparticle.fVz = particle->Z;
233+
mcparticle.fVx = particle->X * 0.1;
234+
mcparticle.fVy = particle->Y * 0.1;
235+
mcparticle.fVz = particle->Z * 0.1;
226236
mcparticle.fVt = particle->T;
227237

228-
tKinematics->Fill();
238+
FillTree(kMcParticle);
229239
}
230240
fOffsetLabel += particles->GetEntries();
231241

232242
// loop over tracks
233243
std::vector<TrackAlice3> tracks_for_vertexing;
234244
std::vector<o2::InteractionRecord> bcData;
235245
std::vector<Track*> tof_tracks;
236-
for (Int_t itrack = 0; itrack < tracks->GetEntries(); ++itrack) {
246+
for (Int_t itrack = 0; itrack < tracks->GetEntries(); ++itrack) { // Loop over tracks
237247

238248
// get track and corresponding particle
239249
auto track = (Track*)tracks->At(itrack);
@@ -248,12 +258,12 @@ void createO2tables(const char* inputFile = "delphes.root",
248258

249259
// fill the label tree
250260
Int_t alabel = particle->GetUniqueID();
251-
mctracklabel.fLabel = TMath::Abs(alabel);
252-
mctracklabel.fLabelMask = 0;
253-
tLabels->Fill();
261+
mctracklabel.fIndexMcParticles = TMath::Abs(alabel);
262+
mctracklabel.fMcMask = 0;
263+
FillTree(kMcTrackLabel);
254264

255265
// set track information
256-
mytracks.fCollisionsID = ientry + eventOffset;
266+
mytracks.fIndexCollisions = ientry + eventOffset;
257267
mytracks.fX = o2track.getX();
258268
mytracks.fAlpha = o2track.getAlpha();
259269
mytracks.fY = o2track.getY();
@@ -305,8 +315,8 @@ void createO2tables(const char* inputFile = "delphes.root",
305315
// check if has hit on RICH
306316
if (richdetector.hasRICH(*track)) {
307317
const auto measurement = richdetector.getMeasuredAngle(*track);
308-
rich.fCollisionsID = ientry + eventOffset;
309-
rich.fTracksID = fTrackCounter; // Index in the Track table
318+
rich.fIndexCollisions = ientry + eventOffset;
319+
rich.fIndexTracks = fTrackCounter; // Index in the Track table
310320
rich.fRICHSignal = measurement.first;
311321
rich.fRICHSignalError = measurement.second;
312322
std::array<float, 5> deltaangle, nsigma;
@@ -321,24 +331,30 @@ void createO2tables(const char* inputFile = "delphes.root",
321331
rich.fRICHNsigmaPi = nsigma[2];
322332
rich.fRICHNsigmaKa = nsigma[3];
323333
rich.fRICHNsigmaPr = nsigma[4];
324-
fRICH->Fill();
334+
FillTree(kRICH);
325335
}
326336
if (do_vertexing) {
327337
o2::InteractionRecord ir(ientry + eventOffset, 0);
328338
const float t = (ir.bc2ns() + gRandom->Gaus(0., 100.)) * 1e-3;
329339
tracks_for_vertexing.push_back(TrackAlice3{o2track, t, 100.f * 1e-3, TMath::Abs(alabel)});
330340
}
331-
fTracks->Fill();
341+
FillTree(kTracks);
342+
FillTree(kTracksCov);
343+
FillTree(kTracksExtra);
332344
fTrackCounter++;
333345
// fill histograms
334346
}
347+
if (eventextra.fNentries[kTracks] != eventextra.fNentries[kTracksCov] || eventextra.fNentries[kTracks] != eventextra.fNentries[kTracksExtra]) {
348+
Printf("Issue with the counters");
349+
return;
350+
}
335351

336352
// compute the event time
337353
std::array<float, 2> tzero;
338354
toflayer.eventTime(tof_tracks, tzero);
339355

340356
// fill collision information
341-
collision.fBCsID = ientry + eventOffset;
357+
collision.fIndexBCs = ientry + eventOffset;
342358
bc.fGlobalBC = ientry + eventOffset;
343359
if (do_vertexing) { // Performing vertexing
344360
o2::BunchFilling bcfill;
@@ -369,7 +385,7 @@ void createO2tables(const char* inputFile = "delphes.root",
369385
v2tRefs,
370386
gsl::span<const o2::MCCompLabel>{lblTracks},
371387
lblVtx);
372-
Printf("Found %i vertices with %zu tracks", n_vertices, tracks_for_vertexing.size());
388+
// Printf("Found %i vertices with %zu tracks", n_vertices, tracks_for_vertexing.size());
373389
if (n_vertices == 0) {
374390
collision.fPosX = 0.f;
375391
collision.fPosY = 0.f;
@@ -380,6 +396,7 @@ void createO2tables(const char* inputFile = "delphes.root",
380396
collision.fCovYY = 0.f;
381397
collision.fCovYZ = 0.f;
382398
collision.fCovZZ = 0.f;
399+
collision.fFlags = 0;
383400
collision.fChi2 = 0.01f;
384401
collision.fN = 0;
385402
} else {
@@ -392,6 +409,7 @@ void createO2tables(const char* inputFile = "delphes.root",
392409
collision.fCovYY = vertices[0].getSigmaY2();
393410
collision.fCovYZ = vertices[0].getSigmaYZ();
394411
collision.fCovZZ = vertices[0].getSigmaZ2();
412+
collision.fFlags = 0;
395413
collision.fChi2 = vertices[0].getChi2();
396414
collision.fN = vertices[0].getNContributors();
397415
}
@@ -405,40 +423,47 @@ void createO2tables(const char* inputFile = "delphes.root",
405423
collision.fCovYY = 0.f;
406424
collision.fCovYZ = 0.f;
407425
collision.fCovZZ = 0.f;
426+
collision.fFlags = 0;
408427
collision.fChi2 = 0.01f;
409428
collision.fN = tracks->GetEntries();
410429
}
411430
collision.fCollisionTime = tzero[0]; // [ns]
412431
collision.fCollisionTimeRes = tzero[1]; // [ns]
413-
tEvents->Fill();
414-
tBC->Fill();
432+
FillTree(kEvents);
433+
FillTree(kBC);
415434

416-
mccollision.fBCsID = ientry + eventOffset;
435+
mccollision.fIndexBCs = ientry + eventOffset;
417436
mccollision.fGeneratorsID = 0;
418437
mccollision.fPosX = 0.;
419438
mccollision.fPosY = 0.;
420439
mccollision.fPosZ = 0.;
421440
mccollision.fT = 0.;
422441
mccollision.fWeight = 0.;
423442
mccollision.fImpactParameter = 0.;
424-
tMCvtx->Fill();
443+
FillTree(kMcCollision);
425444

426-
mccollisionlabel.fLabel = ientry + eventOffset;
427-
mccollisionlabel.fLabelMask = 0;
428-
tCollisionLabels->Fill();
445+
mccollisionlabel.fIndexMcCollisions = ientry + eventOffset;
446+
mccollisionlabel.fMcMask = 0;
447+
FillTree(kMcCollisionLabel);
448+
449+
FillTree(kEventsExtra);
429450
}
430451

452+
Printf("Writing tables for %i events", eventextra.fStart[kEvents]);
431453
TString out_dir = outputFile;
432454
out_dir.ReplaceAll(".root", "");
433455
out_dir.ReplaceAll("AODRun5.", "");
434456
if (!out_dir.IsDec()) {
435-
out_dir = "TF_0";
457+
out_dir = "DF_0";
436458
} else {
437-
out_dir = Form("TF_%i", out_dir.Atoi());
459+
out_dir = Form("DF_%i", out_dir.Atoi());
438460
}
439461
fout->mkdir(out_dir);
440462
fout->cd(out_dir);
441-
TreeList->Write();
463+
for (int i = 0; i < kTrees; i++) {
464+
if (Trees[i])
465+
Trees[i]->Write();
466+
}
442467
fout->ls();
443468
fout->Close();
444469
}

0 commit comments

Comments
 (0)