]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/RESONANCES/macros/RunAnalysisPhi900GeV.C
Modified macros for phi analysis: improved pseudorapidity cut flexibility (A.Knospe)
[u/mrichter/AliRoot.git] / PWGLF / RESONANCES / macros / RunAnalysisPhi900GeV.C
1 //
2 // This is an example of steering macro for running RSN analysis task
3 // locally with a collection of files written in a text file
4 //
5 // Allowed inputs:
6 // - ESD + MC (MC is included automatically)
7 // - AOD
8 //
9 // All settings are specified as arguments in the main macro,
10 // which is at the end of this script.
11 //
12 void RunAnalysisPhi900GeV
13 (
14   Int_t       nReadFiles   = 2,
15   Int_t       nSkipFiles   = 0,
16   const char *dataType     = "900GeV_pass4_sim",
17   const char *inputSource  = "list.txt",
18   const char *outName1     = "Phi900GeV_all.root",
19   const char *outName2     = "Phi900GeV_true.root",
20   const char *outName3     = "Phi900GeV_info.root"
21 )
22 {
23   // convert the last argument into a BOOL variable
24   Bool_t isMC = kTRUE;
25   if (!strcmp(dataType, "900GeV_pass4_data")) isMC = kFALSE;
26   if (!strcmp(dataType, "7TeV_pass1_data")) isMC = kFALSE;
27
28   // message on aliroot version
29   cout << "*** ALIROOT PATH = " << gSystem->Getenv("ALICE_ROOT") << " ***" << endl;
30   cout << "*** MC " << (isMC ? "" : "NOT") << " INCLUDED ***" << endl;
31
32   // check extension of input to distinguish between XML and TXT
33   TString sInput(inputSource);
34   sInput.ToLower();
35   Bool_t isTXT = (!strcmp(sInput(sInput.Length() - 3, 3).Data(), "txt"));
36   cout << "Input = " << (isTXT ? "TXT" : "XML") << endl;
37
38   // load compiled libraries (for aliroot session)
39   gSystem->Load("libANALYSIS.so");
40   gSystem->Load("libANALYSISalice.so");
41   gSystem->Load("libPWG2resonances.so");
42
43   // if input is XML, connect to AliEn
44   if (!isTXT) TGrid::Connect("alien://");
45
46   // create analysis manager
47   AliAnalysisManager *mgr = new AliAnalysisManager("MyTaskManager");
48
49   // create handlers for input
50   AliESDInputHandler *esdHandler = new AliESDInputHandler();
51   mgr->SetInputEventHandler(esdHandler);
52   // if required, create also MC handler
53   if (isMC)
54   {
55     AliMCEventHandler *mcHandler  = new AliMCEventHandler();
56     mgr->SetMCtruthEventHandler(mcHandler);
57   }
58   
59   // add event selection for data
60   gROOT->LoadMacro("AddTaskPhysicsSelection.C");
61   AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(isMC);
62
63   // add task macro
64   AliRsnAnalysisPhi900GeV *task = new AliRsnAnalysisPhi900GeV("taskphi900gev");
65   task->SelectCollisionCandidates();
66   task->SetTPCparams(isMC);
67   task->SetMaxChi2(4.0);
68   task->SetMaxDCAr(0.5);
69   task->SetMaxDCAz(3.0);
70   task->SetMinNTPC(80);
71   task->SetUseMC(kFALSE);
72   if (!strcmp(dataType, "900GeV_pass4_data"))
73   {
74     task->SetTOFESD(kFALSE);
75     task->SetTOFSigma(130.0);
76     task->SetTOFSettings(AliTOFT0makerANA::kPass4);
77   }
78   if (!strcmp(dataType, "7TeV_pass1_data"))
79   {
80     task->SetTOFESD(kFALSE);
81     task->SetTOFSigma(130.0);
82     task->SetTOFSettings(AliTOFT0makerANA::kPass4);
83   }
84   else if (!strcmp(dataType, "900GeV_pass4_sim"))
85   {
86     task->SetTOFESD(kTRUE);
87     task->SetTOFSigma(130.0);
88     task->SetTOFSettings(AliTOFT0makerANA::kNone);
89   }
90   mgr->AddTask(task);
91   
92   // create containers for input/output
93   AliAnalysisDataContainer *out1 = mgr->CreateContainer("tracks", TTree::Class(), AliAnalysisManager::kOutputContainer, outName1);
94   AliAnalysisDataContainer *out2 = mgr->CreateContainer("rsn"   , TTree::Class(), AliAnalysisManager::kOutputContainer, outName2);
95   AliAnalysisDataContainer *out3 = mgr->CreateContainer("info"  , TList::Class(), AliAnalysisManager::kOutputContainer, outName3);
96   mgr->ConnectInput (task, 0, mgr->GetCommonInputContainer());
97   mgr->ConnectOutput(task, 1, out1);
98   mgr->ConnectOutput(task, 2, out2);
99   mgr->ConnectOutput(task, 3, out3);
100
101   // create TChain of input events
102   TChain *analysisChain = 0x0;
103   if (isTXT) analysisChain = CreateChainFromText(inputSource, "esdTree", nReadFiles, nSkipFiles);
104   else       analysisChain = CreateChainFromXML (inputSource, "esdTree", nReadFiles, nSkipFiles);
105
106   // start analysis
107   if (!analysisChain)
108   {
109     Error("runLocal", "Analysis chain not properly initialized");
110     return;
111   }
112   mgr->InitAnalysis();
113   mgr->PrintStatus();
114   if (isTXT) mgr->StartAnalysis("local", analysisChain);
115   else       mgr->StartAnalysis("alien", analysisChain);
116 }
117
118 //_________________________________________________________________________________________________
119 TChain* CreateChainFromXML
120 (const char *xmlFileName, const char *treeName, Int_t nread, Int_t nskip)
121 {
122 //
123 // Create a TChain with all required files listed into an XML collection.
124 // Necessary to run analysis in AliEn jobs.
125 // ---
126 // Arguments:
127 //  - xmlFileName = input list
128 //  - treeName    = "esdTree" or "aodTree"
129 //  - nread       = how many files to read (0 = all)
130 //  - nskip       = how many files to skip from beginning
131 //
132
133   // if nread argument is 0, it is disabled
134   if (nread == 0) nread = 1000000000;
135
136   // initialize output object
137   TChain *chain = new TChain(treeName);
138
139   // initialize the AliEn collection
140   TAlienCollection *myCollection = TAlienCollection::Open(xmlFileName);
141   if (!myCollection)
142   {
143     Error("CreateChainFromXML", "Cannot create an AliEn collection from %s", xmlFileName);
144     return 0x0;
145   }
146
147   // loop on collection
148   myCollection->Reset();
149   while (myCollection->Next())
150   {
151     // skip until reached required number of offset
152     if (nskip > 0) {--nskip; continue;}
153
154     // stop if required number of read files is reached
155     // otherwise update the counter
156     if (nread <= 0) break;
157     nread--;
158
159     // recovery file and add it
160     Info("CreateChainFromXML", Form("Adding: %s", myCollection->GetTURL("")));
161     chain->Add(myCollection->GetTURL(""));
162   }
163
164   return chain;
165 }
166
167 //_________________________________________________________________________________________________
168 TChain* CreateChainFromText(const char *fileName, const char *treeName, Int_t nread, Int_t nskip)
169 {
170 //
171 // Create a TChain with all required files listed into a text file.
172 // Necessary to run analysis in local jobs.
173 // ---
174 // Arguments:
175 //  - xmlFileName = input file list
176 //  - treeName    = "esdTree" or "aodTree"
177 //  - nread       = how many files to read (0 = all)
178 //  - nskip       = how many files to skip from beginning
179 //
180
181   // if third argument is 0, it is interpreted
182   // as "read all lines"
183   Bool_t readAll = (nread <= 0);
184   
185   // initialize output object
186   TChain* target = new TChain(treeName);
187   
188   // open text file
189   ifstream fileIn(fileName);
190   
191   // loop on collection
192   TString line;
193   while (fileIn.good())
194   {
195     fileIn >> line;
196     if (line.IsNull()) continue;
197     
198     // skip until reached required number of offset
199     if (nskip > 0) {--nskip; continue;}
200     
201     // stop if required number of read files is reached
202     // otherwise update the counter
203     if (!readAll && nread <= 0) break;
204     nread--;
205     
206     // add file
207     Info("CreateChainFromText", "Adding '%s'", line.Data());
208     target->Add(line.Data());
209   }
210   
211   return target;
212 }