Skip to content

Commit 985f120

Browse files
authored
Align AOD creation to changes in AP (#82)
- Add checker of compatibility with AP
1 parent 4029c11 commit 985f120

File tree

2 files changed

+242
-66
lines changed

2 files changed

+242
-66
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/usr/bin/env python3
2+
3+
# from ROOT import gROOT
4+
import wget
5+
import os
6+
7+
8+
def get_variable(f, v="TreeName"):
9+
variable = ""
10+
f = open(f)
11+
for i in f:
12+
if v in i:
13+
variable += " " + i.strip()
14+
continue
15+
if variable != "":
16+
variable += " " + i.strip()
17+
if ";" in variable:
18+
break
19+
return variable.replace(" ", "\n")
20+
21+
22+
def count_trees(f):
23+
f = open(f)
24+
t = []
25+
for i in f:
26+
if "->Branch(" in i:
27+
i = i.strip().split("->")[0]
28+
if i not in t:
29+
t.append(i)
30+
return t
31+
32+
33+
def check_tree(f1, f2, tn="Kinematics", verbose=True):
34+
print("Checking tree", tn, "in", f1, "and", f2)
35+
f1 = open(f1)
36+
f2 = open(f2)
37+
38+
def get(f):
39+
t = []
40+
for i in f:
41+
i = i.strip()
42+
i = i.replace(",", ", ").replace(" ", " ")
43+
if f"{tn}->Branch(" in i:
44+
i = i.replace("aod_track", "tracks")
45+
t.append(i)
46+
return t
47+
48+
t1 = get(f1)
49+
t2 = get(f2)
50+
r = t2
51+
for i in t1:
52+
if i in t2:
53+
r.pop(r.index(i))
54+
if len(r) > 0:
55+
print("Remaining", r)
56+
57+
58+
def count_structs(f):
59+
nw = " "
60+
if "AliAnalysisTaskAO2Dconverter" in f:
61+
nw = " "
62+
print("Checking", f)
63+
f = open(f)
64+
t = {}
65+
start = False
66+
dm = []
67+
for i in f:
68+
if "struct {" in i:
69+
start = True
70+
dm = []
71+
continue
72+
if start and "}" in i and not i.startswith(nw):
73+
if i not in t:
74+
t[i.replace("}", "").split(";")[0].strip().replace(
75+
"aod_track", "tracks")] = dm
76+
start = False
77+
elif start:
78+
i = i.strip()
79+
while " " in i:
80+
i = i.replace(" ", " ")
81+
if not i.startswith("//"):
82+
dm.append(i)
83+
return t
84+
85+
86+
def get_and_check(url, to_check="createO2tables.h"):
87+
filename = wget.download(url, out="/tmp/", bar=None)
88+
filename_header = wget.download(
89+
url.replace(".cxx", ".h"), out="/tmp/", bar=None)
90+
# print(get_variable(to_check))
91+
t1 = count_trees(to_check)
92+
s1 = count_structs(to_check)
93+
# print(s1)
94+
# print(get_variable(filename))
95+
t2 = count_trees(filename)
96+
s2 = count_structs(filename_header)
97+
# print(s2)
98+
99+
for i in s1:
100+
if i in s2:
101+
for j in s1[i]:
102+
if j not in s2[i]:
103+
print(j, "Not here")
104+
else:
105+
print(i, "not in s2")
106+
for i in t1:
107+
if i in ["tRICH", "tMID", "tFTOF"]:
108+
continue
109+
check_tree(to_check, filename, tn=i)
110+
if i not in t2:
111+
print("Tree", i, "is not in", t2)
112+
113+
os.remove(filename)
114+
os.remove(filename_header)
115+
116+
117+
get_and_check(
118+
"https://raw.githubusercontent.com/alisw/AliPhysics/master/RUN3/AliAnalysisTaskAO2Dconverter.cxx")

examples/aod/createO2tables.h

Lines changed: 124 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,67 @@ enum TreeIndex { // Index of the output trees
3737
const int fBasketSizeEvents = 1000000; // Maximum basket size of the trees for events
3838
const int fBasketSizeTracks = 10000000; // Maximum basket size of the trees for tracks
3939

40-
const TString TreeName[kTrees] = {"O2collision", "DbgEventExtra", "O2track", "O2trackcov", "O2trackextra", "O2fwdtrack", "O2fwdtrackcov", "O2calo", "O2calotrigger", "O2muoncluster", "O2zdc", "O2fv0a", "O2fv0c", "O2ft0", "O2fdd", "O2v0", "O2cascade", "O2tof", "O2mcparticle", "O2mccollision", "O2mctracklabel", "O2mccalolabel", "O2mccollisionlabel", "O2bc", "O2run2bcinfo", "O2origin", "O2hmpid", "O2rich", "O2mid", "O2ftof"};
41-
42-
const TString TreeTitle[kTrees] = {"Collision tree", "Collision extra", "Barrel tracks Parameters", "Barrel tracks Covariance", "Barrel tracks Extra", "Forward tracks Parameters", "Forward tracks Covariances", "Calorimeter cells", "Calorimeter triggers", "MUON clusters", "ZDC", "FV0A", "FV0C", "FT0", "FDD", "V0s", "Cascades", "TOF hits", "Kinematics", "MC collisions", "MC track labels", "MC calo labels", "MC collision labels", "BC info", "Run 2 BC Info", "DF ids", "HMPID info", "RICH info", "MID info", "Forward TOF info"};
40+
const TString TreeName[kTrees] = {"O2collision",
41+
"DbgEventExtra",
42+
"O2track",
43+
"O2trackcov",
44+
"O2trackextra",
45+
"O2fwdtrack",
46+
"O2fwdtrackcov",
47+
"O2calo",
48+
"O2calotrigger",
49+
"O2muoncluster",
50+
"O2zdc",
51+
"O2fv0a",
52+
"O2fv0c",
53+
"O2ft0",
54+
"O2fdd",
55+
"O2v0",
56+
"O2cascade",
57+
"O2tof",
58+
"O2mcparticle",
59+
"O2mccollision",
60+
"O2mctracklabel",
61+
"O2mccalolabel",
62+
"O2mccollisionlabel",
63+
"O2bc",
64+
"O2run2bcinfo",
65+
"O2origin",
66+
"O2hmpid",
67+
"O2rich",
68+
"O2mid",
69+
"O2ftof"};
70+
71+
const TString TreeTitle[kTrees] = {"Collision tree",
72+
"Collision extra",
73+
"Barrel tracks Parameters",
74+
"Barrel tracks Covariance",
75+
"Barrel tracks Extra",
76+
"Forward tracks Parameters",
77+
"Forward tracks Covariances",
78+
"Calorimeter cells",
79+
"Calorimeter triggers",
80+
"MUON clusters",
81+
"ZDC",
82+
"FV0A",
83+
"FV0C",
84+
"FT0",
85+
"FDD",
86+
"V0s",
87+
"Cascades",
88+
"TOF hits",
89+
"Kinematics",
90+
"MC collisions",
91+
"MC track labels",
92+
"MC calo labels",
93+
"MC collision labels",
94+
"BC info",
95+
"Run 2 BC Info",
96+
"DF ids",
97+
"HMPID info",
98+
"RICH info",
99+
"MID info",
100+
"Forward TOF info"};
43101

44102
TTree* Trees[kTrees] = {nullptr}; // Array of created TTrees
45103
TTree* CreateTree(TreeIndex t)
@@ -316,22 +374,22 @@ struct {
316374

317375
void MakeTreeO2rich()
318376
{
319-
TTree* t = CreateTree(kRICH);
320-
t->Branch("fIndexCollisions", &rich.fIndexCollisions, "fIndexCollisions/I");
321-
t->Branch("fIndexTracks", &rich.fIndexTracks, "fIndexTracks/I");
322-
t->Branch("fRICHSignal", &rich.fRICHSignal, "fRICHSignal/F");
323-
t->Branch("fRICHSignalError", &rich.fRICHSignalError, "fRICHSignalError/F");
324-
t->Branch("fRICHDeltaEl", &rich.fRICHDeltaEl, "fRICHDeltaEl/F");
325-
t->Branch("fRICHDeltaMu", &rich.fRICHDeltaMu, "fRICHDeltaMu/F");
326-
t->Branch("fRICHDeltaPi", &rich.fRICHDeltaPi, "fRICHDeltaPi/F");
327-
t->Branch("fRICHDeltaKa", &rich.fRICHDeltaKa, "fRICHDeltaKa/F");
328-
t->Branch("fRICHDeltaPr", &rich.fRICHDeltaPr, "fRICHDeltaPr/F");
329-
t->Branch("fRICHNsigmaEl", &rich.fRICHNsigmaEl, "fRICHNsigmaEl/F");
330-
t->Branch("fRICHNsigmaMu", &rich.fRICHNsigmaMu, "fRICHNsigmaMu/F");
331-
t->Branch("fRICHNsigmaPi", &rich.fRICHNsigmaPi, "fRICHNsigmaPi/F");
332-
t->Branch("fRICHNsigmaKa", &rich.fRICHNsigmaKa, "fRICHNsigmaKa/F");
333-
t->Branch("fRICHNsigmaPr", &rich.fRICHNsigmaPr, "fRICHNsigmaPr/F");
334-
t->SetBasketSize("*", fBasketSizeTracks);
377+
TTree* tRICH = CreateTree(kRICH);
378+
tRICH->Branch("fIndexCollisions", &rich.fIndexCollisions, "fIndexCollisions/I");
379+
tRICH->Branch("fIndexTracks", &rich.fIndexTracks, "fIndexTracks/I");
380+
tRICH->Branch("fRICHSignal", &rich.fRICHSignal, "fRICHSignal/F");
381+
tRICH->Branch("fRICHSignalError", &rich.fRICHSignalError, "fRICHSignalError/F");
382+
tRICH->Branch("fRICHDeltaEl", &rich.fRICHDeltaEl, "fRICHDeltaEl/F");
383+
tRICH->Branch("fRICHDeltaMu", &rich.fRICHDeltaMu, "fRICHDeltaMu/F");
384+
tRICH->Branch("fRICHDeltaPi", &rich.fRICHDeltaPi, "fRICHDeltaPi/F");
385+
tRICH->Branch("fRICHDeltaKa", &rich.fRICHDeltaKa, "fRICHDeltaKa/F");
386+
tRICH->Branch("fRICHDeltaPr", &rich.fRICHDeltaPr, "fRICHDeltaPr/F");
387+
tRICH->Branch("fRICHNsigmaEl", &rich.fRICHNsigmaEl, "fRICHNsigmaEl/F");
388+
tRICH->Branch("fRICHNsigmaMu", &rich.fRICHNsigmaMu, "fRICHNsigmaMu/F");
389+
tRICH->Branch("fRICHNsigmaPi", &rich.fRICHNsigmaPi, "fRICHNsigmaPi/F");
390+
tRICH->Branch("fRICHNsigmaKa", &rich.fRICHNsigmaKa, "fRICHNsigmaKa/F");
391+
tRICH->Branch("fRICHNsigmaPr", &rich.fRICHNsigmaPr, "fRICHNsigmaPr/F");
392+
tRICH->SetBasketSize("*", fBasketSizeTracks);
335393
}
336394

337395
struct {
@@ -343,11 +401,11 @@ struct {
343401

344402
void MakeTreeO2mid()
345403
{
346-
TTree* t = CreateTree(kMID);
347-
t->Branch("fIndexCollisions", &mid.fIndexCollisions, "fIndexCollisions/I");
348-
t->Branch("fIndexTracks", &mid.fIndexTracks, "fIndexTracks/I");
349-
t->Branch("fMIDIsMuon", &mid.fMIDIsMuon, "fMIDIsMuon/b");
350-
t->SetBasketSize("*", fBasketSizeTracks);
404+
TTree* tMID = CreateTree(kMID);
405+
tMID->Branch("fIndexCollisions", &mid.fIndexCollisions, "fIndexCollisions/I");
406+
tMID->Branch("fIndexTracks", &mid.fIndexTracks, "fIndexTracks/I");
407+
tMID->Branch("fMIDIsMuon", &mid.fMIDIsMuon, "fMIDIsMuon/b");
408+
tMID->SetBasketSize("*", fBasketSizeTracks);
351409
}
352410

353411
struct {
@@ -371,22 +429,22 @@ struct {
371429

372430
void MakeTreeO2ftof()
373431
{
374-
TTree* t = CreateTree(kFTOF);
375-
t->Branch("fIndexCollisions", &ftof.fIndexCollisions, "fIndexCollisions/I");
376-
t->Branch("fIndexTracks", &ftof.fIndexTracks, "fIndexTracks/I");
377-
t->Branch("fFTOFLength", &ftof.fFTOFLength, "fFTOFLength/F");
378-
t->Branch("fFTOFSignal", &ftof.fFTOFSignal, "fFTOFSignal/F");
379-
t->Branch("fFTOFDeltaEl", &ftof.fFTOFDeltaEl, "fFTOFDeltaEl/F");
380-
t->Branch("fFTOFDeltaMu", &ftof.fFTOFDeltaMu, "fFTOFDeltaMu/F");
381-
t->Branch("fFTOFDeltaPi", &ftof.fFTOFDeltaPi, "fFTOFDeltaPi/F");
382-
t->Branch("fFTOFDeltaKa", &ftof.fFTOFDeltaKa, "fFTOFDeltaKa/F");
383-
t->Branch("fFTOFDeltaPr", &ftof.fFTOFDeltaPr, "fFTOFDeltaPr/F");
384-
t->Branch("fFTOFNsigmaEl", &ftof.fFTOFNsigmaEl, "fFTOFNsigmaEl/F");
385-
t->Branch("fFTOFNsigmaMu", &ftof.fFTOFNsigmaMu, "fFTOFNsigmaMu/F");
386-
t->Branch("fFTOFNsigmaPi", &ftof.fFTOFNsigmaPi, "fFTOFNsigmaPi/F");
387-
t->Branch("fFTOFNsigmaKa", &ftof.fFTOFNsigmaKa, "fFTOFNsigmaKa/F");
388-
t->Branch("fFTOFNsigmaPr", &ftof.fFTOFNsigmaPr, "fFTOFNsigmaPr/F");
389-
t->SetBasketSize("*", fBasketSizeTracks);
432+
TTree* tFTOF = CreateTree(kFTOF);
433+
tFTOF->Branch("fIndexCollisions", &ftof.fIndexCollisions, "fIndexCollisions/I");
434+
tFTOF->Branch("fIndexTracks", &ftof.fIndexTracks, "fIndexTracks/I");
435+
tFTOF->Branch("fFTOFLength", &ftof.fFTOFLength, "fFTOFLength/F");
436+
tFTOF->Branch("fFTOFSignal", &ftof.fFTOFSignal, "fFTOFSignal/F");
437+
tFTOF->Branch("fFTOFDeltaEl", &ftof.fFTOFDeltaEl, "fFTOFDeltaEl/F");
438+
tFTOF->Branch("fFTOFDeltaMu", &ftof.fFTOFDeltaMu, "fFTOFDeltaMu/F");
439+
tFTOF->Branch("fFTOFDeltaPi", &ftof.fFTOFDeltaPi, "fFTOFDeltaPi/F");
440+
tFTOF->Branch("fFTOFDeltaKa", &ftof.fFTOFDeltaKa, "fFTOFDeltaKa/F");
441+
tFTOF->Branch("fFTOFDeltaPr", &ftof.fFTOFDeltaPr, "fFTOFDeltaPr/F");
442+
tFTOF->Branch("fFTOFNsigmaEl", &ftof.fFTOFNsigmaEl, "fFTOFNsigmaEl/F");
443+
tFTOF->Branch("fFTOFNsigmaMu", &ftof.fFTOFNsigmaMu, "fFTOFNsigmaMu/F");
444+
tFTOF->Branch("fFTOFNsigmaPi", &ftof.fFTOFNsigmaPi, "fFTOFNsigmaPi/F");
445+
tFTOF->Branch("fFTOFNsigmaKa", &ftof.fFTOFNsigmaKa, "fFTOFNsigmaKa/F");
446+
tFTOF->Branch("fFTOFNsigmaPr", &ftof.fFTOFNsigmaPr, "fFTOFNsigmaPr/F");
447+
tFTOF->SetBasketSize("*", fBasketSizeTracks);
390448
}
391449

392450
struct {
@@ -395,13 +453,13 @@ struct {
395453
Int_t fIndexMcCollisions = -1; /// The index of the MC collision vertex
396454

397455
// MC information (modified version of TParticle
398-
Int_t fPdgCode = -99999; /// PDG code of the particle
399-
Int_t fStatusCode = -99999; /// generation status code
400-
uint8_t fFlags = 0; /// See enum MCParticleFlags
401-
Int_t fMother0 = 0; /// Indices of the mother particles
402-
Int_t fMother1 = 0;
403-
Int_t fDaughter0 = 0; /// Indices of the daughter particles
404-
Int_t fDaughter1 = 0;
456+
Int_t fPdgCode = -99999; /// PDG code of the particle
457+
Int_t fStatusCode = -99999; /// generation status code
458+
uint8_t fFlags = 0; /// See enum MCParticleFlags
459+
Int_t fIndexMcParticles_Mother0 = 0; /// Indices of the mother particles
460+
Int_t fIndexMcParticles_Mother1 = 0;
461+
Int_t fIndexMcParticles_Daughter0 = 0; /// Indices of the daughter particles
462+
Int_t fIndexMcParticles_Daughter1 = 0;
405463
Float_t fWeight = 1; /// particle weight from the generator or ML
406464

407465
Float_t fPx = -999.f; /// x component of momentum
@@ -418,25 +476,25 @@ struct {
418476

419477
void MakeTreeO2mcparticle()
420478
{
421-
TTree* tKinematics = CreateTree(kMcParticle);
422-
tKinematics->Branch("fIndexMcCollisions", &mcparticle.fIndexMcCollisions, "fIndexMcCollisions/I");
423-
tKinematics->Branch("fPdgCode", &mcparticle.fPdgCode, "fPdgCode/I");
424-
tKinematics->Branch("fStatusCode", &mcparticle.fStatusCode, "fStatusCode/I");
425-
tKinematics->Branch("fFlags", &mcparticle.fFlags, "fFlags/b");
426-
tKinematics->Branch("fMother0", &mcparticle.fMother0, "fMother0/I");
427-
tKinematics->Branch("fMother1", &mcparticle.fMother1, "fMother1/I");
428-
tKinematics->Branch("fDaughter0", &mcparticle.fDaughter0, "fDaughter0/I");
429-
tKinematics->Branch("fDaughter1", &mcparticle.fDaughter1, "fDaughter1/I");
430-
tKinematics->Branch("fWeight", &mcparticle.fWeight, "fWeight/F");
431-
tKinematics->Branch("fPx", &mcparticle.fPx, "fPx/F");
432-
tKinematics->Branch("fPy", &mcparticle.fPy, "fPy/F");
433-
tKinematics->Branch("fPz", &mcparticle.fPz, "fPz/F");
434-
tKinematics->Branch("fE", &mcparticle.fE, "fE/F");
435-
tKinematics->Branch("fVx", &mcparticle.fVx, "fVx/F");
436-
tKinematics->Branch("fVy", &mcparticle.fVy, "fVy/F");
437-
tKinematics->Branch("fVz", &mcparticle.fVz, "fVz/F");
438-
tKinematics->Branch("fVt", &mcparticle.fVt, "fVt/F");
439-
tKinematics->SetBasketSize("*", fBasketSizeTracks);
479+
TTree* Kinematics = CreateTree(kMcParticle);
480+
Kinematics->Branch("fIndexMcCollisions", &mcparticle.fIndexMcCollisions, "fIndexMcCollisions/I");
481+
Kinematics->Branch("fPdgCode", &mcparticle.fPdgCode, "fPdgCode/I");
482+
Kinematics->Branch("fStatusCode", &mcparticle.fStatusCode, "fStatusCode/I");
483+
Kinematics->Branch("fFlags", &mcparticle.fFlags, "fFlags/b");
484+
Kinematics->Branch("fIndexMcParticles_Mother0", &mcparticle.fIndexMcParticles_Mother0, "fIndexMcParticles_Mother0/I");
485+
Kinematics->Branch("fIndexMcParticles_Mother1", &mcparticle.fIndexMcParticles_Mother1, "fIndexMcParticles_Mother1/I");
486+
Kinematics->Branch("fIndexMcParticles_Daughter0", &mcparticle.fIndexMcParticles_Daughter0, "fIndexMcParticles_Daughter0/I");
487+
Kinematics->Branch("fIndexMcParticles_Daughter1", &mcparticle.fIndexMcParticles_Daughter1, "fIndexMcParticles_Daughter1/I");
488+
Kinematics->Branch("fWeight", &mcparticle.fWeight, "fWeight/F");
489+
Kinematics->Branch("fPx", &mcparticle.fPx, "fPx/F");
490+
Kinematics->Branch("fPy", &mcparticle.fPy, "fPy/F");
491+
Kinematics->Branch("fPz", &mcparticle.fPz, "fPz/F");
492+
Kinematics->Branch("fE", &mcparticle.fE, "fE/F");
493+
Kinematics->Branch("fVx", &mcparticle.fVx, "fVx/F");
494+
Kinematics->Branch("fVy", &mcparticle.fVy, "fVy/F");
495+
Kinematics->Branch("fVz", &mcparticle.fVz, "fVz/F");
496+
Kinematics->Branch("fVt", &mcparticle.fVt, "fVt/F");
497+
Kinematics->SetBasketSize("*", fBasketSizeTracks);
440498
}
441499

442500
struct {

0 commit comments

Comments
 (0)