committing on behalf of Silvia... new macros for HFE analysis on the train (Markus
[u/mrichter/AliRoot.git] / PWG3 / hfe / macros / runElectronTask.C
CommitLineData
809a4336 1void SetupPar(char* pararchivename);
d2af20c5 2void SwitchBranches(TChain *c);
809a4336 3TChain * CreateXMLChain(char* xmlfile);
d2af20c5 4TChain * CreateAODChain(const char * name = 0x0);
809a4336 5
d2af20c5 6void runElectronTask(const char *treelist = 0x0, Bool_t hasMC = kTRUE){
809a4336 7 if(!treelist){
8 printf("Error: No ESD list specified\n");
9 return;
10 }
11 if(gSystem->Getenv("ALICE_ROOT")){
12 gSystem->Load("libANALYSIS");
13 gSystem->Load("libANALYSISalice");
14 gSystem->Load("libCORRFW");
15 }
16 else{
17 SetupPar("STEERBase");
18 SetupPar("ESD");
19 SetupPar("AOD");
20 SetupPar("ANALYSIS");
21 SetupPar("ANALYSISalice");
22 SetupPar("CORRFW");
d2af20c5 23 SetupPar("Util");
809a4336 24 }
d2af20c5 25 //SetupPar("HFE");
26 gSystem->Load("libHFE.so");
27// gROOT->LoadMacro("AliAnalysisTaskHFE.cxx++");
722347d8 28 // AliLog::SetGlobalLogLevel(AliLog::kError);
809a4336 29
30 // Make the ESD chain
31 TString treename = treelist;
d2af20c5 32 TChain *inputChain = 0x0;
33 Bool_t isAOD = kFALSE;
34 if(treename.EndsWith(".xml")){
809a4336 35 esdchain = CreateXMLChain(treelist);
d2af20c5 36 SwitchBranches(inputChain);
37 }else{
38 inputChain = CreateAODChain(treelist);
39 if(inputChain) isAOD = kTRUE;
40 else{
41 gROOT->LoadMacro("CreateESDChain.C");
42 inputChain = CreateESDChain(treelist, -1);
43 SwitchBranches(inputChain);
44 }
809a4336 45 }
d2af20c5 46
809a4336 47 // Start the Analysis Manager and Create Handlers
d2af20c5 48 AliAnalysisManager *hfeAnalysis = new AliAnalysisManager("Single Electron Analysis");
49 if(!isAOD) hfeAnalysis->SetInputEventHandler(new AliESDInputHandler);
50 else hfeAnalysis->SetInputEventHandler(new AliAODInputHandler);
51 if(hasMC && !isAOD) hfeAnalysis->SetMCtruthEventHandler(new AliMCEventHandler);
722347d8 52 AliHFEcuts *hfecuts = new AliHFEcuts;
53 hfecuts->CreateStandardCuts();
d2af20c5 54 AliAnalysisTaskHFE *task = new AliAnalysisTaskHFE;
55 if(hasMC) task->SetHasMCData();
56 if(isAOD) task->SetAODAnalysis();
722347d8 57 task->SetHFECuts(hfecuts);
554e120d 58 task->SetPIDStrategy(4);
722347d8 59 task->SetQAOn(AliAnalysisTaskHFE::kPIDqa);
60 task->SetQAOn(AliAnalysisTaskHFE::kMCqa);
d2af20c5 61 task->SwitchOnPlugin(AliAnalysisTaskHFE::kSecVtx);
62 //task->SwitchOnPlugin(AliAnalysisTaskHFE::kIsElecBackGround);
63 hfeAnalysis->AddTask(task);
64 task->ConnectInput(0, hfeAnalysis->GetCommonInputContainer());
65 task->ConnectOutput(1, hfeAnalysis->CreateContainer("nEvents", TH1I::Class(), AliAnalysisManager::kOutputContainer, "HFEtask.root"));
66 task->ConnectOutput(2, hfeAnalysis->CreateContainer("Results", TList::Class(), AliAnalysisManager::kOutputContainer, "HFEtask.root"));
67 task->ConnectOutput(3, hfeAnalysis->CreateContainer("QA", TList::Class(), AliAnalysisManager::kOutputContainer, "HFEtask.root"));
68 //task->ConnectOutput(3, hfeAnalysis->CreateContainer("QA-new", TList::Class(), AliAnalysisManager::kOutputContainer, "HFEtask.root"));
809a4336 69 // Run the Analysis
d2af20c5 70 if(hfeAnalysis->InitAnalysis()){
809a4336 71 TStopwatch timer;
72 timer.Start();
d2af20c5 73 hfeAnalysis->StartAnalysis("local", inputChain);
809a4336 74 timer.Stop();
75 timer.Print();
76 }
77}
78
79//____________________________________________
80TChain * CreateXMLChain(char* xmlfile)
81{
82
83 //TChain *chain = 0x0;
84 const char *chainname="esdTree";
85 TChain* chain = new TChain(chainname);
86
87 TString input =xmlfile;
88 cout<<" the input is::"<< xmlfile<<endl;
89
90 char kXML [1000];
91 if(gSystem->Getenv("XML") )
92 kXML = gSystem->Getenv("XML");
93 else
94 sprintf(kXML, xmlfile) ;
95
96 // sprintf(kXML, "collection.xml") ;
97
98 cout<<"XML file "<<kXML<<endl;
99
100 if (!TFile::Open(kXML)) {
101 printf("No collection file with name -- %s -- was found\n",kXML);
102 return ;
103 }
104 gSystem->Load("libNetx.so") ;
105 gSystem->Load("libRAliEn.so");
106 TGrid::Connect("alien://") ;
107
108
109
110 // TGridCollection * collection = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(\"%s\", 0)", kXML));
111 TGridCollection * collection = (TGridCollection*) TAlienCollection::Open(kXML);
112 if (! collection) {
113 AliError(Form("%s not found", kXML)) ;
114 return kFALSE ;
115 }
116 //collection->CheckIfOnline();
117
118 TGridResult* result = collection->GetGridResult("",0 ,0);
119
120 // TList* analysisfilelist = result->GetFileInfoList();
121
122 // Makes the ESD chain
123 printf("*** Getting the Chain ***\n");
124
125 for (Int_t index = 0; index < result->GetEntries(); index++) {
126 TString alienURL = result->GetKey(index, "turl") ;
127 cout << "================== " << alienURL << endl ;
128 chain->Add(alienURL) ;
129 //alienURL.ReplaceAll("AliESDs.root",kXSFileName);
130 // chainxs->Add(alienURL) ;
131 }
132
133
134 // chain->AddFileInfoList(analysisfilelist);
135 if (chain) chain->ls();
136 chain->SetBranchStatus("*Calo*",0);
137 chain->SetBranchStatus("*FMD*",0);
138 return chain;
139}
140
141//______________________________________________________________________________
d2af20c5 142TChain *CreateAODChain(const char * name){
143 if(!name) return NULL;
144 ifstream filelist(name);
145 string filename;
146 TChain *c = new TChain("aodTree");
147 Bool_t isAODlist = kTRUE;
148 while(getline(filelist,filename)){
149 if(!strstr(filename.c_str(), "AliAOD")){
150 isAODlist = kFALSE;
151 break;
152 }
153 c->Add(filename.c_str());
154 }
155 if(!isAODlist){
156 printf("No AOD anlysis");
157 delete c;
158 return NULL;
159 }
160 return c;
161}
162
163//______________________________________________________________________________
809a4336 164void SetupPar(char* pararchivename)
165{
166 if (pararchivename) {
167 char processline[1024];
168 sprintf(processline,".! tar xvzf %s.par",pararchivename);
169 gROOT->ProcessLine(processline);
170 TString ocwd = gSystem->WorkingDirectory();
171 gSystem->ChangeDirectory(pararchivename);
172
173 // check for BUILD.sh and execute
174 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
175 printf("*******************************\n");
176 printf("*** Building PAR archive ***\n");
177 printf("*******************************\n");
178
179 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
180 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
181 return -1;
182 }
183 }
184 // check for SETUP.C and execute
185 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
186 printf("*******************************\n");
187 printf("*** Setup PAR archive ***\n");
188 printf("*******************************\n");
189 gROOT->Macro("PROOF-INF/SETUP.C");
190 }
191
192 gSystem->ChangeDirectory(ocwd.Data());
193 printf("Current dir: %s\n", ocwd.Data());
194 }
195}
d2af20c5 196
197void SwitchBranches(TChain *c){
198 //esdchain->SetBranchStatus("*", 0);
199 c->SetBranchStatus("Calo*", 0);
200 c->SetBranchStatus("*FMD*", 1);
201 c->SetBranchStatus("Tracks", 1);
202}