-
Notifications
You must be signed in to change notification settings - Fork 0
/
runGloAlgTask.C
executable file
·170 lines (163 loc) · 5.93 KB
/
runGloAlgTask.C
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
TChain* CreateChainXML(const char *xmlfile);
TChain* CreateChainTXT(const char *txtfile);
Bool_t InputHandlerSetup(TString formatFr = "AliESDfriends.root");
Bool_t barrelFlag = kFALSE;
//====================================================================
void runGloAlgTask
(
TString data="wn.xml",
//TString data="algColl.txt",
Int_t nEvents=-1,
UInt_t trigSel = AliVEvent::kAny
)
{
//
if (!gGrid) {
TGrid::Connect("alien://");
if (!gGrid) {printf("Cannot connect\n");exit(1);}
}
//
gROOT->ProcessLine(Form(".include $ALICE_ROOT/include $ALICE_PHYSICS/include ./ %s",gSystem->pwd()));
gSystem->SetIncludePath(Form("-I$ROOTSYS/include -I$ALICE_ROOT/include -I$ALICE_PHYSICS/include -I./ -I%s",gSystem->pwd()));
printf("Include line: %s",gSystem->GetIncludePath());
//
if (gClassTable->GetID("AliAlgSteer")<0) {
gSystem->Load("libAlg.so");
}
//
gROOT->ProcessLine(".L AliGloAlgTask.cxx++g");
//
AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
if (!mgr) mgr = new AliAnalysisManager("mgr");
//
TChain *chain = data.EndsWith(".xml") ? CreateChainXML(data) : CreateChainTXT(data);
TString formatFr = "AliESDfriends.root";
if (barrelFlag) formatFr = "AliESDfriends_Barrel.root";
printf("Deduced friend name : %s\n",formatFr.Data());
//
InputHandlerSetup(formatFr.Data());
//
//================================================================================
// printf("Requesting physics selection in %s mode\n",useMC ? "MC":"Data");
// gROOT->LoadMacro("$ALICE_ROOT/../src/ANALYSIS/macros/AddTaskPhysicsSelection.C");
// AliPhysicsSelectionTask* physicsSelectionTask = AddTaskPhysicsSelection(useMC);
//==================================================================================
//
AliGloAlgTask *algTask = new AliGloAlgTask("alg");
//-------------------------------------------
algTask->SetTriggerSelection(trigSel);
algTask->SetConfMacroName("alignConf.C");
// algTask->SetConfMacroName("pedeF/alignConf.C");
algTask->SetIniParFileName("millepede.res");
// algTask->SetApplyMPSolAlignment(kTRUE);
//-------------------------------------------
AliAnalysisDataContainer *coutput1 =
mgr->CreateContainer("clist", TList::Class(),AliAnalysisManager::kOutputContainer,"mpStatOut.root");
mgr->AddTask(algTask);
//
mgr->ConnectInput(algTask, 0, mgr->GetCommonInputContainer());
mgr->ConnectOutput(algTask,1,coutput1);
//
if (!mgr->InitAnalysis()) return;
mgr->PrintStatus();
// Start analysis in grid.
if (nEvents<0) nEvents = chain->GetEntries();
mgr->StartAnalysis("localfile",chain,nEvents);
//
}
//________________________________________________________________
Bool_t InputHandlerSetup(TString esdFName)
{
AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
AliAnalysisDataContainer *cin = mgr->GetCommonInputContainer();
if (cin) return;
AliESDInputHandler *esdInputHandler =
dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
if (!esdInputHandler) {
Info("CustomAnalysisTaskInputSetup", "Creating esdInputHandler ...");
esdInputHandler = new AliESDInputHandler();
mgr->SetInputEventHandler(esdInputHandler);
}
esdInputHandler->SetFriendFileName(esdFName.Data());
// esdInputHandler->SetActiveBranches("ESDfriend*");
esdInputHandler->SetReadFriends(kTRUE);
return kTRUE;
}
//________________________________________________________________________________
TChain* CreateChainXML(const char *xmlfile)
{
// Create a chain using url's from xml file
TString filename;
Int_t run = 0;
TString treename = "esdTree";
printf("***************************************\n");
printf(" Getting chain of trees %s\n", treename.Data());
printf("***************************************\n");
TAlienCollection *coll = TAlienCollection::Open(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 (filename.EndsWith("Barrel.root")) barrelFlag = kTRUE;
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;
}
printf("Created chain with %d entries in %d trees from %s\n",chain->GetEntries(),chain->GetNtrees(),xmlfile);
return chain;
}
//________________________________________________________________________________
TChain* CreateChainTXT(const char* inpData)
{
const char* chName="esdTree";
TChain* chain = new TChain(chName);
//
TString inpDtStr = inpData;
if (inpDtStr.EndsWith(".root")) {
chain->AddFile(inpData);
}
else {
//
ifstream inpf(inpData);
if (!inpf.good()) {
printf("Failed on input filename %s\n",inpData);
return kFALSE;
}
//
TString flName;
flName.ReadLine(inpf);
while ( !flName.IsNull() ) {
flName = flName.Strip(TString::kBoth,' ');
if (flName.BeginsWith("//") || flName.BeginsWith("#")) {flName.ReadLine(inpf); continue;}
flName = flName.Strip(TString::kBoth,',');
flName = flName.Strip(TString::kBoth,'"');
if (flName.EndsWith("Barrel.root")) barrelFlag = kTRUE;
printf("Adding %s\n",flName.Data());
chain->AddFile(flName.Data());
flName.ReadLine(inpf);
}
}
//
int n = chain->GetEntries();
if (n<1) {
printf("Obtained chain is empty\n");
return kFALSE;
}
printf("Created chain with %d entries in %d trees from %s\n",chain->GetEntries(),chain->GetNtrees(),inpData);
return chain;
}