2 //-------------------------------------------------
3 enum anaModes {mLocal, mGRID};
4 //mLocal = 0: Analyze locally files in your computer
5 //mGRID = 3: Analyze files on GRID
7 //---------------------------------------------------------------------------
8 //Settings to read locally several files, only for "mLocal" mode
9 //The different values are default, they can be set with environmental
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
13 Int_t kFile = 1; // Number of files
14 //---------------------------------------------------------------------------
15 //Collection file for grid analysis
16 char * kXML = "collection.xml";
18 //---------------------------------------------------------------------------
20 const Bool_t kMC = kFALSE; //With real data kMC = kFALSE
21 TString kInputData = "ESD";//ESD, AOD, MC
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
33 //--------------------------------------------------------------------
34 // Load analysis libraries
35 // Look at the method below,
36 // change whatever you need for your analysis case
37 // ------------------------------------------------------------------
40 //-------------------------------------------------------------------------------------------------
41 //Create chain from ESD and from cross sections files, look below for options.
42 //-------------------------------------------------------------------------------------------------
43 if(kInputData == "ESD") kTreeName = "esdTree" ;
44 else if(kInputData == "AOD") kTreeName = "aodTree" ;
45 else if (kInputData == "MC") kTreeName = "TE" ;
47 cout<<"Wrong data type "<<kInputData<<endl;
51 TChain * chain = new TChain(kTreeName) ;
53 CreateChain(mode, chain);//, chainxs);
54 cout<<"Chain created"<<endl;
57 AliLog::SetGlobalLogLevel(AliLog::kError);//Minimum prints on screen
59 //--------------------------------------
60 // Make the analysis manager
61 //-------------------------------------
62 AliAnalysisManager *mgr = new AliAnalysisManager("Manager", "Manager");
64 if( (kMC && (kInputData == "ESD")) || kInputData == "MC"){
65 AliMCEventHandler* mcHandler = new AliMCEventHandler();
66 mcHandler->SetReadTR(kFALSE);//Do not search TrackRef file
67 mgr->SetMCtruthEventHandler(mcHandler);
68 if( kInputData == "MC") mgr->SetInputEventHandler(NULL);
71 // // AOD output handler
72 // AliAODHandler* aodoutHandler = new AliAODHandler();
73 // aodoutHandler->SetOutputFileName("AliAOD.root");
74 // mgr->SetOutputEventHandler(aodoutHandler);
77 Int_t maxiterations = 1;
78 AliEventPoolLoop* pool = new AliEventPoolLoop(maxiterations);
79 pool->SetChain(chain);
80 Int_t eventsInPool = 10;
81 AliMultiEventInputHandler *inpHandler = NULL ;
82 if(kInputData == "ESD"){
84 printf("ESD MultiInput \n");
85 inpHandler = new AliMultiEventInputHandler(eventsInPool, 0);
87 if(kInputData == "AOD"){
89 inpHandler = new AliMultiEventInputHandler(eventsInPool, 1);
91 mgr->SetInputEventHandler(inpHandler);
92 cout<<"Input handler "<<mgr->GetInputEventHandler()<<endl;
93 mgr->SetEventPool(pool);
94 inpHandler->SetEventPool(pool);
96 //mgr->SetDebugLevel(-1); // For debugging, do not uncomment if you want no messages.
98 // select triigger events for physics run
101 // gROOT->LoadMacro("AddTaskPhysicsSelection.C");
102 // AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection();
103 // mgr->AddTask(physSelTask);
106 //-------------------------------------------------------------------------
107 //Define task, put here any other task that you want to use.
108 //-------------------------------------------------------------------------
110 //correlation analysis
111 gROOT->LoadMacro("AddTaskPartCorrM.C");
113 AliAnalysisTaskParticleCorrelationM *taskEMCAL = AddTaskPartCorrM(kInputData,"EMCAL",kFALSE);
115 mgr->AddTask(taskEMCAL);
117 AliAnalysisTaskParticleCorrelationM *taskPHOS = AddTaskPartCorrM(kInputData,"PHOS", kFALSE);
119 mgr->AddTask(taskPHOS);
121 //gROOT->LoadMacro("AddTaskChargeCorr.C");
122 AliAnalysisTaskParticleCorrelationM *taskCharge = AddTaskPartCorrM(kInputData, "CTS",kFALSE);
124 // taskCharge->SelectCollisionCandidates();
125 mgr->AddTask(taskCharge);
127 //-----------------------
129 //-----------------------
130 //mgr->ResetAnalysis();
133 mgr->StartAnalysis("mix",chain);
135 cout <<" Analysis ended sucessfully "<< endl ;
137 else cout << "Chain was not produced ! "<<endl;
141 void LoadLibraries() {
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");
150 //--------------------------------------------------------
151 //If you want to use root and par files from aliroot
152 //--------------------------------------------------------
153 SetupPar("STEERBase");
156 SetupPar("ANALYSIS");
157 SetupPar("ANALYSISalice");
158 SetupPar("PHOSUtils");
159 SetupPar("EMCALUtils");
161 SetupPar("PWG4PartCorrBase");
162 SetupPar("PWG4PartCorrDep");
165 //--------------------------------------------------------
166 // If you want to use already compiled libraries
167 // in the aliroot distribution
168 //--------------------------------------------------------
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");
182 void SetupPar(char* pararchivename)
184 //Load par files, create analysis libraries
185 //For testing, if par file already decompressed and modified
186 //classes then do not decompress.
188 TString cdir(Form("%s", gSystem->WorkingDirectory() )) ;
189 TString parpar(Form("%s.par", pararchivename)) ;
190 if ( gSystem->AccessPathName(pararchivename) ) {
191 TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
192 gROOT->ProcessLine(processline.Data());
195 TString ocwd = gSystem->WorkingDirectory();
196 gSystem->ChangeDirectory(pararchivename);
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");
205 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
206 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
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");
219 gSystem->ChangeDirectory(ocwd.Data());
220 printf("Current dir: %s\n", ocwd.Data());
225 void CreateChain(const anaModes mode, TChain * chain){//, TChain * chainxs){
226 //Fills chain with data
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" ;
233 TString ocwd = gSystem->WorkingDirectory();
235 //---------------------------------------
236 //Local files analysis
237 //---------------------------------------
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)
243 cout<<"INDIR : "<<kInDir<<endl;
244 cout<<"NFILES : "<<kFile<<endl;
245 cout<<"PATTERN: " <<kPattern<<endl;
248 //Loop on ESD files, add them to chain
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);
263 printf("number of entries # %lld \n", chain->GetEntries()) ;
264 }// local files analysis
266 //------------------------------
268 //-----------------------------
269 else if(mode == mGRID){
270 //Load necessary libraries and connect to the GRID
271 gSystem->Load("libNetx.so") ;
272 gSystem->Load("libRAliEn.so");
273 TGrid::Connect("alien://") ;
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);
279 AliError(Form("%s not found", kXML)) ;
282 TGridResult* result = collection->GetGridResult("",0 ,0);
284 // Makes the ESD chain
285 printf("*** Getting the Chain ***\n");
286 Int_t nEventsPerFile = 0;
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) ;
295 gSystem->ChangeDirectory(ocwd.Data());