]>
Commit | Line | Data |
---|---|---|
c8fe2783 | 1 | /* $Id$ */ |
c8fe2783 | 2 | //------------------------------------------------- |
2244659d | 3 | enum anaModes {mLocal, mGRID}; |
4 | //mLocal = 0: Analyze locally files in your computer | |
5 | //mGRID = 3: Analyze files on GRID | |
c8fe2783 | 6 | |
7 | //--------------------------------------------------------------------------- | |
8 | //Settings to read locally several files, only for "mLocal" mode | |
9 | //The different values are default, they can be set with environmental | |
2244659d | 10 | //variables: INDIR, PATTERN, NFILES, respectively |
11 | char * kInDir = "/Users/ymao/group/ana/7TeV/corr"; | |
12 | char * kPattern = ""; // Data are in files kInDir/kPattern+i | |
c8fe2783 | 13 | Int_t kFile = 1; // Number of files |
14 | //--------------------------------------------------------------------------- | |
15 | //Collection file for grid analysis | |
16 | char * kXML = "collection.xml"; | |
2244659d | 17 | |
c8fe2783 | 18 | //--------------------------------------------------------------------------- |
19 | ||
20 | const Bool_t kMC = kFALSE; //With real data kMC = kFALSE | |
2244659d | 21 | TString kInputData = "ESD";//ESD, AOD, MC |
c8fe2783 | 22 | TString kTreeName ; |
2244659d | 23 | const TString calorimeter = "EMCAL" ; |
24 | const Bool_t kUsePAR = kFALSE; //set to kFALSE for libraries | |
25 | //const Bool_t kUsePAR = kTRUE; //set to kFALSE for libraries | |
26 | const Bool_t kDoESDFilter = kFALSE; //filter the tracks from the esd | |
27 | ||
28 | Int_t mode = mGRID; | |
c8fe2783 | 29 | |
2244659d | 30 | void anaM() |
c8fe2783 | 31 | { |
32 | // Main | |
c8fe2783 | 33 | //-------------------------------------------------------------------- |
34 | // Load analysis libraries | |
35 | // Look at the method below, | |
36 | // change whatever you need for your analysis case | |
37 | // ------------------------------------------------------------------ | |
2244659d | 38 | LoadLibraries() ; |
c8fe2783 | 39 | |
40 | //------------------------------------------------------------------------------------------------- | |
41 | //Create chain from ESD and from cross sections files, look below for options. | |
2244659d | 42 | //------------------------------------------------------------------------------------------------- |
c8fe2783 | 43 | if(kInputData == "ESD") kTreeName = "esdTree" ; |
44 | else if(kInputData == "AOD") kTreeName = "aodTree" ; | |
45 | else if (kInputData == "MC") kTreeName = "TE" ; | |
46 | else { | |
47 | cout<<"Wrong data type "<<kInputData<<endl; | |
48 | break; | |
49 | } | |
2244659d | 50 | |
51 | TChain * chain = new TChain(kTreeName) ; | |
52 | ||
53 | CreateChain(mode, chain);//, chainxs); | |
54 | cout<<"Chain created"<<endl; | |
55 | ||
56 | if( chain ){ | |
c8fe2783 | 57 | AliLog::SetGlobalLogLevel(AliLog::kError);//Minimum prints on screen |
58 | ||
59 | //-------------------------------------- | |
60 | // Make the analysis manager | |
61 | //------------------------------------- | |
62 | AliAnalysisManager *mgr = new AliAnalysisManager("Manager", "Manager"); | |
63 | // MC handler | |
2244659d | 64 | if( (kMC && (kInputData == "ESD")) || kInputData == "MC"){ |
c8fe2783 | 65 | AliMCEventHandler* mcHandler = new AliMCEventHandler(); |
66 | mcHandler->SetReadTR(kFALSE);//Do not search TrackRef file | |
67 | mgr->SetMCtruthEventHandler(mcHandler); | |
2244659d | 68 | if( kInputData == "MC") mgr->SetInputEventHandler(NULL); |
c8fe2783 | 69 | } |
2244659d | 70 | |
71 | // // AOD output handler | |
72 | // AliAODHandler* aodoutHandler = new AliAODHandler(); | |
73 | // aodoutHandler->SetOutputFileName("AliAOD.root"); | |
74 | // mgr->SetOutputEventHandler(aodoutHandler); | |
c8fe2783 | 75 | |
76 | //input | |
77 | Int_t maxiterations = 1; | |
78 | AliEventPoolLoop* pool = new AliEventPoolLoop(maxiterations); | |
79 | pool->SetChain(chain); | |
2244659d | 80 | Int_t eventsInPool = 10; |
c8fe2783 | 81 | AliMultiEventInputHandler *inpHandler = NULL ; |
82 | if(kInputData == "ESD"){ | |
83 | // ESD handler | |
8e3bc7b6 | 84 | printf("ESD MultiInput \n"); |
85 | inpHandler = new AliMultiEventInputHandler(eventsInPool, 0); | |
c8fe2783 | 86 | } |
87 | if(kInputData == "AOD"){ | |
88 | // AOD handler | |
8e3bc7b6 | 89 | inpHandler = new AliMultiEventInputHandler(eventsInPool, 1); |
c8fe2783 | 90 | } |
91 | mgr->SetInputEventHandler(inpHandler); | |
92 | cout<<"Input handler "<<mgr->GetInputEventHandler()<<endl; | |
93 | mgr->SetEventPool(pool); | |
94 | inpHandler->SetEventPool(pool); | |
2244659d | 95 | |
96 | //mgr->SetDebugLevel(-1); // For debugging, do not uncomment if you want no messages. | |
97 | ||
98 | // select triigger events for physics run | |
99 | ||
100 | // if(!kMC){ | |
101 | // gROOT->LoadMacro("AddTaskPhysicsSelection.C"); | |
102 | // AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(); | |
103 | // mgr->AddTask(physSelTask); | |
104 | // } | |
105 | ||
c8fe2783 | 106 | //------------------------------------------------------------------------- |
107 | //Define task, put here any other task that you want to use. | |
108 | //------------------------------------------------------------------------- | |
2244659d | 109 | |
110 | //correlation analysis | |
c8fe2783 | 111 | gROOT->LoadMacro("AddTaskPartCorrM.C"); |
2244659d | 112 | |
113 | AliAnalysisTaskParticleCorrelationM *taskEMCAL = AddTaskPartCorrM(kInputData,"EMCAL",kFALSE); | |
c8fe2783 | 114 | |
2244659d | 115 | mgr->AddTask(taskEMCAL); |
116 | ||
117 | AliAnalysisTaskParticleCorrelationM *taskPHOS = AddTaskPartCorrM(kInputData,"PHOS", kFALSE); | |
c8fe2783 | 118 | |
2244659d | 119 | mgr->AddTask(taskPHOS); |
120 | ||
121 | //gROOT->LoadMacro("AddTaskChargeCorr.C"); | |
122 | AliAnalysisTaskParticleCorrelationM *taskCharge = AddTaskPartCorrM(kInputData, "CTS",kFALSE); | |
123 | // if(!kMC) | |
124 | // taskCharge->SelectCollisionCandidates(); | |
125 | mgr->AddTask(taskCharge); | |
126 | ||
127 | //----------------------- | |
c8fe2783 | 128 | // Run the analysis |
129 | //----------------------- | |
2244659d | 130 | //mgr->ResetAnalysis(); |
c8fe2783 | 131 | mgr->InitAnalysis(); |
132 | mgr->PrintStatus(); | |
2244659d | 133 | mgr->StartAnalysis("mix",chain); |
134 | ||
135 | cout <<" Analysis ended sucessfully "<< endl ; | |
c8fe2783 | 136 | } |
137 | else cout << "Chain was not produced ! "<<endl; | |
138 | ||
139 | } | |
140 | ||
2244659d | 141 | void LoadLibraries() { |
c8fe2783 | 142 | //-------------------------------------- |
143 | // Load the needed libraries most of them already loaded by aliroot | |
144 | //-------------------------------------- | |
145 | gSystem->Load("libTree.so"); | |
146 | gSystem->Load("libGeom.so"); | |
147 | gSystem->Load("libVMC.so"); | |
148 | gSystem->Load("libXMLIO.so"); | |
2244659d | 149 | if(kUsePAR){ |
150 | //-------------------------------------------------------- | |
151 | //If you want to use root and par files from aliroot | |
152 | //-------------------------------------------------------- | |
153 | SetupPar("STEERBase"); | |
154 | SetupPar("ESD"); | |
155 | SetupPar("AOD"); | |
156 | SetupPar("ANALYSIS"); | |
157 | SetupPar("ANALYSISalice"); | |
158 | SetupPar("PHOSUtils"); | |
159 | SetupPar("EMCALUtils"); | |
160 | ||
161 | SetupPar("PWG4PartCorrBase"); | |
162 | SetupPar("PWG4PartCorrDep"); | |
163 | } | |
164 | else{ | |
c8fe2783 | 165 | //-------------------------------------------------------- |
166 | // If you want to use already compiled libraries | |
167 | // in the aliroot distribution | |
168 | //-------------------------------------------------------- | |
2244659d | 169 | gSystem->Load("libSTEERBase"); |
170 | gSystem->Load("libESD"); | |
171 | gSystem->Load("libAOD"); | |
172 | gSystem->Load("libANALYSIS"); | |
173 | gSystem->Load("libANALYSISalice"); | |
174 | gSystem->Load("libPHOSUtils"); | |
175 | gSystem->Load("libEMCALUtils"); | |
176 | gSystem->Load("libPWG4PartCorrBase"); | |
177 | gSystem->Load("libPWG4PartCorrDep"); | |
c8fe2783 | 178 | } |
c8fe2783 | 179 | |
180 | } | |
181 | ||
182 | void SetupPar(char* pararchivename) | |
183 | { | |
184 | //Load par files, create analysis libraries | |
185 | //For testing, if par file already decompressed and modified | |
186 | //classes then do not decompress. | |
2244659d | 187 | |
c8fe2783 | 188 | TString cdir(Form("%s", gSystem->WorkingDirectory() )) ; |
189 | TString parpar(Form("%s.par", pararchivename)) ; | |
c8fe2783 | 190 | if ( gSystem->AccessPathName(pararchivename) ) { |
191 | TString processline = Form(".! tar xvzf %s",parpar.Data()) ; | |
192 | gROOT->ProcessLine(processline.Data()); | |
193 | } | |
194 | ||
195 | TString ocwd = gSystem->WorkingDirectory(); | |
196 | gSystem->ChangeDirectory(pararchivename); | |
197 | ||
198 | // check for BUILD.sh and execute | |
199 | if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) { | |
200 | printf("*******************************\n"); | |
201 | printf("*** Building PAR archive ***\n"); | |
202 | cout<<pararchivename<<endl; | |
203 | printf("*******************************\n"); | |
204 | ||
205 | if (gSystem->Exec("PROOF-INF/BUILD.sh")) { | |
206 | Error("runProcess","Cannot Build the PAR Archive! - Abort!"); | |
207 | return -1; | |
208 | } | |
209 | } | |
210 | // check for SETUP.C and execute | |
211 | if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) { | |
212 | printf("*******************************\n"); | |
213 | printf("*** Setup PAR archive ***\n"); | |
214 | cout<<pararchivename<<endl; | |
215 | printf("*******************************\n"); | |
216 | gROOT->Macro("PROOF-INF/SETUP.C"); | |
217 | } | |
218 | ||
219 | gSystem->ChangeDirectory(ocwd.Data()); | |
220 | printf("Current dir: %s\n", ocwd.Data()); | |
221 | } | |
222 | ||
223 | ||
224 | ||
2244659d | 225 | void CreateChain(const anaModes mode, TChain * chain){//, TChain * chainxs){ |
c8fe2783 | 226 | //Fills chain with data |
c8fe2783 | 227 | |
2244659d | 228 | TString datafileName=""; |
229 | if(kInputData == "ESD") datafileName = "AliESDs.root" ; | |
230 | else if(kInputData == "AOD") datafileName = "AliAOD.root" ; | |
231 | else if(kInputData == "MC") datafileName = "galice.root" ; | |
232 | ||
233 | TString ocwd = gSystem->WorkingDirectory(); | |
c8fe2783 | 234 | |
235 | //--------------------------------------- | |
236 | //Local files analysis | |
237 | //--------------------------------------- | |
2244659d | 238 | if(mode == mLocal){ |
c8fe2783 | 239 | //If you want to add several ESD files sitting in a common directory INDIR |
240 | //Specify as environmental variables the directory (INDIR), the number of files | |
241 | //to analyze (NFILES) and the pattern name of the directories with files (PATTERN) | |
c8fe2783 | 242 | |
2244659d | 243 | cout<<"INDIR : "<<kInDir<<endl; |
244 | cout<<"NFILES : "<<kFile<<endl; | |
245 | cout<<"PATTERN: " <<kPattern<<endl; | |
c8fe2783 | 246 | |
c8fe2783 | 247 | |
2244659d | 248 | //Loop on ESD files, add them to chain |
249 | TString FileName ; | |
250 | for (Int_t iFile = 0 ; iFile < kFile ; iFile++) { | |
251 | FileName = Form("%s/%s%d/%s", kInDir,kPattern,iFile,datafileName.Data()) ; | |
252 | //cout << "FileName: " << FileName <<endl ; | |
253 | TFile * dataFile = 0 ; | |
254 | //Check if file exists and add it, if not skip it | |
255 | if ( dataFile = TFile::Open(FileName.Data())) { | |
256 | if ( dataFile->Get(kTreeName) ) { | |
257 | Int_t nEventsPerFile = ((TTree*) dataFile->Get(kTreeName)) ->GetEntries(); | |
258 | printf(" ++++ Adding %s, with %d events \n", FileName.Data(), nEventsPerFile) ; | |
259 | chain->AddFile(FileName); | |
260 | } | |
c8fe2783 | 261 | } |
2244659d | 262 | } |
263 | printf("number of entries # %lld \n", chain->GetEntries()) ; | |
c8fe2783 | 264 | }// local files analysis |
265 | ||
266 | //------------------------------ | |
267 | //GRID xml files | |
268 | //----------------------------- | |
269 | else if(mode == mGRID){ | |
c8fe2783 | 270 | //Load necessary libraries and connect to the GRID |
271 | gSystem->Load("libNetx.so") ; | |
272 | gSystem->Load("libRAliEn.so"); | |
273 | TGrid::Connect("alien://") ; | |
2244659d | 274 | |
c8fe2783 | 275 | //Feed Grid with collection file |
276 | //TGridCollection * collection = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(\"%s\", 0)", kXML)); | |
277 | TGridCollection * collection = (TGridCollection*) TAlienCollection::Open(kXML); | |
278 | if (! collection) { | |
279 | AliError(Form("%s not found", kXML)) ; | |
280 | return kFALSE ; | |
281 | } | |
282 | TGridResult* result = collection->GetGridResult("",0 ,0); | |
2244659d | 283 | |
c8fe2783 | 284 | // Makes the ESD chain |
285 | printf("*** Getting the Chain ***\n"); | |
2244659d | 286 | Int_t nEventsPerFile = 0; |
c8fe2783 | 287 | for (Int_t index = 0; index < result->GetEntries(); index++) { |
288 | TString alienURL = result->GetKey(index, "turl") ; | |
289 | cout << "================== " << alienURL << endl ; | |
290 | chain->Add(alienURL) ; | |
2244659d | 291 | |
c8fe2783 | 292 | } |
293 | }// xml analysis | |
294 | ||
295 | gSystem->ChangeDirectory(ocwd.Data()); | |
296 | } |