Skip to content

Commit 4b12f88

Browse files
Benedikt Volkelchiarazampolli
authored andcommitted
Update analysis WF
* Add analysis for tracking efficiency * Introduce possibility of post processing of analysis results
1 parent 3378d51 commit 4b12f88

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

MC/analysis_testing/o2dpg_analysis_test_workflow.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@
8484
spec.loader.exec_module(o2dpg_workflow_utils)
8585
from o2dpg_workflow_utils import createTask, dump_workflow
8686

87+
#######################
88+
# ANALYSIS definition #
89+
#######################
90+
8791
# some commong definitions
8892
ANALYSIS_LABEL = "Analysis"
8993
ANALYSIS_LABEL_MERGED = f"{ANALYSIS_LABEL}Merged"
@@ -153,6 +157,11 @@
153157
# "valid_for": [ANALYSIS_VALID_MC],
154158
# "cmd": "o2-analysis-mm-vertexing-fwd {CONFIG} {AOD}"}
155159
# ANALYSES.append(analysis_PWGMMFwdVertexing)
160+
analysis_PWGMMMDnDeta = {"name": "PWGMMMDnDeta",
161+
"expected_output": ["AnalysisResults.root"],
162+
"valid_for": [ANALYSIS_VALID_MC],
163+
"cmd": "o2-analysis-timestamp {CONFIG} | o2-analysis-track-propagation {CONFIG} | o2-analysis-event-selection {CONFIG} | o2-analysis-mm-particles-to-tracks {CONFIG} | o2-analysis-mm-dndeta {CONFIG} {AOD}"}
164+
ANALYSES.append(analysis_PWGMMMDnDeta)
156165

157166
def make_merged_analysis(*analysis_names, accept_data_or_mc=ANALYSIS_VALID_MC):
158167
"""merge CMD / DPL piping to one large pipe
@@ -249,6 +258,38 @@ def create_ana_task(name, cmd, output_dir, *, needs=None, shmsegmentsize="--shm-
249258
task['cmd'] = f"{cmd} {shmsegmentsize} {aodmemoryratelimit} {readers} {extraarguments}"
250259
return task
251260

261+
def add_analysis_post_processing_tasks(workflow):
262+
"""add post-processing step to analysis tasks if possible
263+
264+
Args:
265+
workflow: list
266+
current list of tasks
267+
"""
268+
analyses_to_add_for = {}
269+
# collect analyses in current workflow
270+
for task in workflow:
271+
if ANALYSIS_LABEL in task["labels"] or ANALYSIS_LABEL_MERGED in task["labels"]:
272+
analyses_to_add_for[task["name"]] = task
273+
274+
for ana in ANALYSES:
275+
if not ana["expected_output"]:
276+
continue
277+
ana_name_raw = ana["name"]
278+
post_processing_macro = join(O2DPG_ROOT, "MC", "analysis_testing", "post_processing", f"{ana_name_raw}.C")
279+
if not exists(post_processing_macro):
280+
continue
281+
ana_name = full_ana_name(ana_name_raw)
282+
if ana_name not in analyses_to_add_for:
283+
continue
284+
pot_ana = analyses_to_add_for[ana_name]
285+
cwd = pot_ana["cwd"]
286+
needs = [ana_name]
287+
task = createTask(name=f"{ANALYSIS_LABEL}_post_processing_{ana_name_raw}", cwd=join(cwd, "post_processing"), lab=[ANALYSIS_LABEL, f"{ANALYSIS_LABEL}PostProcessing", ana_name_raw], cpu=1, mem='2000', needs=needs)
288+
input_files = ",".join([f"../{eo}" for eo in ana["expected_output"]])
289+
cmd = f"\\(\\\"{input_files}\\\",\\\"./\\\"\\)"
290+
task["cmd"] = f"root -l -b -q {post_processing_macro}{cmd}"
291+
workflow.append(task)
292+
252293
def add_analysis_tasks(workflow, input_aod="./AO2D.root", output_dir="./Analysis", *, analyses_only=None, is_mc=True, add_merged_task=False, config=None, needs=None):
253294
"""Add default analyses to user workflow
254295
@@ -286,6 +327,8 @@ def add_analysis_tasks(workflow, input_aod="./AO2D.root", output_dir="./Analysis
286327
task = create_ana_task(ana["name"], ana["cmd"].format(CONFIG=f"--configuration {configuration}", AOD=f"--aod-file {input_aod}"), output_dir, needs=needs, is_mc=is_mc)
287328
task["labels"].append(ANALYSIS_LABEL_MERGED)
288329
workflow.append(task)
330+
# append potential post-processing
331+
add_analysis_post_processing_tasks(workflow)
289332

290333
def add_analysis_qc_upload_tasks(workflow, period_name, run_number, pass_name):
291334
"""add o2-qc-upload-root-objects to specified analysis tasks
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
void PWGMMMDnDeta(const char* inputFiles, const char* outDir)
2+
{
3+
// filenames are given as one string where the file names are separated by ","
4+
std::stringstream toSplit(inputFiles);
5+
std::string token;
6+
std::vector<std::string> tokenList;
7+
std::string thisFile;
8+
9+
while (std::getline(toSplit, token, ',')) {
10+
if (token.find("AnalysisResults.root") != std::string::npos) {
11+
thisFile = token;
12+
break;
13+
}
14+
}
15+
16+
if (thisFile.empty()) {
17+
// nothing to post-process
18+
return;
19+
}
20+
TFile f(thisFile.c_str(), "UPDATE");
21+
if (f.IsZombie()) {
22+
std::cout << "Cannot open file " << thisFile << " for post-processing\n";
23+
return;
24+
}
25+
auto hPT = (TH1*)f.Get("pseudorapidity-density/Tracks/Control/PtEfficiency");
26+
auto hPTGen = (TH1*)f.Get("pseudorapidity-density/Tracks/Control/PtGen");
27+
hPT->SetDirectory(nullptr);
28+
hPTGen->SetDirectory(nullptr);
29+
auto hPTTrackingEff = (TH1*)hPT->Clone("trackingEfficiency");
30+
hPTTrackingEff->SetDirectory(nullptr);
31+
32+
hPTTrackingEff->Divide(hPTTrackingEff, hPTGen, 1, 1, "b");
33+
hPTTrackingEff->SetTitle("tracking efficiency");
34+
35+
auto d = f.mkdir("O2DPG-post-processing");
36+
d->WriteTObject(hPTTrackingEff);
37+
f.Write();
38+
f.Close();
39+
}

MC/config/analysis_testing/json/analysis-testing-mc.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,5 +430,29 @@
430430
},
431431
"check-mc-particles-indices": {
432432
"debugMode": "0"
433+
},
434+
"particles-to-tracks": {
435+
"processIndexing": "true"
436+
},
437+
"pseudorapidity-density": {
438+
"estimatorEta": "1",
439+
"useEvSel": "false",
440+
"useDCAZ": "false",
441+
"useDCAXY": "false",
442+
"usePtDCAXY": "false",
443+
"maxDCAXY": "2.4",
444+
"maxDCAZ": "3.2",
445+
"usePhiCut": "false",
446+
"exclusionPhi": {
447+
"values": [
448+
[
449+
"4",
450+
"5"
451+
]
452+
]
453+
},
454+
"processTagging": "true",
455+
"processTrackEfficiency": "true",
456+
"processGen": "true"
433457
}
434458
}

0 commit comments

Comments
 (0)