forked from AliceO2Group/Run3AnalysisValidation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvertAO2D.C
More file actions
132 lines (124 loc) · 4.17 KB
/
convertAO2D.C
File metadata and controls
132 lines (124 loc) · 4.17 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
R__ADD_INCLUDE_PATH($ALICE_ROOT)
R__ADD_INCLUDE_PATH($ALICE_PHYSICS)
#include <ANALYSIS/macros/train/AddESDHandler.C>
#include <ANALYSIS/macros/train/AddMCHandler.C>
#include <OADB/COMMON/MULTIPLICITY/macros/AddTaskMultSelection.C>
#include <OADB/macros/AddTaskPhysicsSelection.C>
#include <ANALYSIS/macros/AddTaskPIDResponse.C>
#include <RUN3/AddTaskAO2Dconverter.C>
TChain* CreateChain(const char* xmlfile, const char* type = "ESD");
TChain* CreateLocalChain(const char* txtfile, const char* type, int nfiles);
Long64_t convertAO2D(TString listoffiles, bool ismc = 1, int nmaxevents = -1)
{
const char* anatype = "ESD";
if (ismc) {
std::cout << "I AM DOING MC" << std::endl;
}
// TGrid::Connect("alien:");
// Create the chain based on xml collection or txt file
// The entries in the txt file can be local paths or alien paths
TChain* chain = CreateLocalChain(listoffiles.Data(), anatype, -1);
if (!chain)
return -1;
chain->SetNotify(0x0);
ULong64_t nentries = chain->GetEntries();
if (nmaxevents != -1)
nentries = nmaxevents;
cout << nentries << " entries in the chain." << endl;
cout << nentries << " converted" << endl;
AliAnalysisManager* mgr = new AliAnalysisManager("AOD converter");
AliESDInputHandler* handler = AddESDHandler();
AddTaskMultSelection();
AddTaskPhysicsSelection(ismc);
AddTaskPIDResponse();
if (ismc)
AliMCEventHandler* handlerMC = AddMCHandler();
AliAnalysisTaskAO2Dconverter* converter = AddTaskAO2Dconverter("");
//converter->SelectCollisionCandidates(AliVEvent::kAny);
if (ismc)
converter->SetMCMode();
if (!mgr->InitAnalysis())
return -1;
//PH mgr->SetBit(AliAnalysisManager::kTrueNotify);
//mgr->SetRunFromPath(244918);
mgr->PrintStatus();
mgr->SetDebugLevel(1);
// mgr->StartAnalysis("localfile", chain, 123456789, 0);
return mgr->StartAnalysis("localfile", chain, nentries, 0);
}
TChain* CreateLocalChain(const char* txtfile, const char* type, int nfiles)
{
TString treename = type;
treename.ToLower();
treename += "Tree";
printf("***************************************\n");
printf(" Getting chain of trees %s\n", treename.Data());
printf("***************************************\n");
// Open the file
ifstream in;
in.open(txtfile);
Int_t count = 0;
// Read the input list of files and add them to the chain
TString line;
TChain* chain = new TChain(treename);
while (in.good()) {
in >> line;
if (line.IsNull() || line.BeginsWith("#"))
continue;
if (count++ == nfiles)
break;
TString esdFile(line);
TFile* file = TFile::Open(esdFile);
if (file && !file->IsZombie()) {
chain->Add(esdFile);
file->Close();
} else {
Error("GetChainforTestMode", "Skipping un-openable file: %s", esdFile.Data());
}
}
in.close();
if (!chain->GetListOfFiles()->GetEntries()) {
Error("CreateLocalChain", "No file from %s could be opened", txtfile);
delete chain;
return nullptr;
}
return chain;
}
//________________________________________________________________________________
TChain* CreateChain(const char* xmlfile, const char* type)
{
// Create a chain using url's from xml file
TString filename;
Int_t run = 0;
TString treename = type;
treename.ToLower();
treename += "Tree";
printf("***************************************\n");
printf(" Getting chain of trees %s\n", treename.Data());
printf("***************************************\n");
TGridCollection* coll = gGrid->OpenCollection(xmlfile);
if (!coll) {
::Error("CreateChain", "Cannot create an AliEn collection from %s", xmlfile);
return NULL;
}
AliAnalysisManager* mgr = AliAnalysisManager::GetAnalysisManager();
TChain* chain = new TChain(treename);
coll->Reset();
while (coll->Next()) {
filename = coll->GetTURL();
if (mgr) {
Int_t nrun = AliAnalysisManager::GetRunFromAlienPath(filename);
if (nrun && nrun != run) {
printf("### Run number detected from chain: %d\n", nrun);
mgr->SetRunFromPath(nrun);
run = nrun;
}
}
chain->Add(filename);
}
if (!chain->GetNtrees()) {
::Error("CreateChain", "No tree found from collection %s", xmlfile);
return NULL;
}
return chain;
}