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