]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/macros/anaM.C
plotted delta pT for different cents
[u/mrichter/AliRoot.git] / PWG4 / macros / anaM.C
1 /* $Id$ */
2 //-------------------------------------------------
3 enum anaModes {mLocal, mGRID};
4 //mLocal    = 0: Analyze locally files in your computer
5 //mGRID     = 3: Analyze files on GRID
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 
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";
17
18 //---------------------------------------------------------------------------
19
20 const Bool_t kMC = kFALSE; //With real data kMC = kFALSE
21 TString kInputData = "ESD";//ESD, AOD, MC
22 TString kTreeName ;
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;
29
30 void anaM()
31 {
32   // Main
33   //--------------------------------------------------------------------
34   // Load analysis libraries
35   // Look at the method below, 
36   // change whatever you need for your analysis case
37   // ------------------------------------------------------------------
38   LoadLibraries() ;
39   
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" ;
46   else {
47     cout<<"Wrong  data type "<<kInputData<<endl;
48     break;
49   }
50   
51   TChain * chain   = new TChain(kTreeName) ;
52   
53         CreateChain(mode, chain);//, chainxs);  
54   cout<<"Chain created"<<endl;
55   
56   if( chain ){
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
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);
69     }
70     
71 //    // AOD output handler
72 //    AliAODHandler* aodoutHandler   = new AliAODHandler();
73 //    aodoutHandler->SetOutputFileName("AliAOD.root");
74 //    mgr->SetOutputEventHandler(aodoutHandler);
75     
76     //input
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"){
83       // ESD handler
84       printf("ESD MultiInput \n");
85       inpHandler = new AliMultiEventInputHandler(eventsInPool, 0);
86     }
87     if(kInputData == "AOD"){
88       // AOD handler
89       inpHandler = new AliMultiEventInputHandler(eventsInPool, 1);                
90     }
91     mgr->SetInputEventHandler(inpHandler);
92     cout<<"Input handler "<<mgr->GetInputEventHandler()<<endl;
93     mgr->SetEventPool(pool);
94     inpHandler->SetEventPool(pool);
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     
106     //-------------------------------------------------------------------------
107     //Define task, put here any other task that you want to use.
108     //-------------------------------------------------------------------------
109     
110     //correlation analysis
111     gROOT->LoadMacro("AddTaskPartCorrM.C");
112     
113     AliAnalysisTaskParticleCorrelationM *taskEMCAL = AddTaskPartCorrM(kInputData,"EMCAL",kFALSE);
114
115     mgr->AddTask(taskEMCAL);
116     
117     AliAnalysisTaskParticleCorrelationM *taskPHOS  = AddTaskPartCorrM(kInputData,"PHOS", kFALSE);
118
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      //-----------------------
128     // Run the analysis
129     //-----------------------    
130     //mgr->ResetAnalysis();
131     mgr->InitAnalysis();
132     mgr->PrintStatus();
133     mgr->StartAnalysis("mix",chain);
134     
135     cout <<" Analysis ended sucessfully "<< endl ;
136   }
137   else cout << "Chain was not produced ! "<<endl;
138   
139 }
140
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");
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{
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");
178   }
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.
187   
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());
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
225 void CreateChain(const anaModes mode, TChain * chain){//, TChain * chainxs){
226   //Fills chain with data
227   
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();
234   
235   //---------------------------------------
236   //Local files analysis
237   //---------------------------------------
238   if(mode == mLocal){
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)
242     
243     cout<<"INDIR : "<<kInDir<<endl;
244     cout<<"NFILES : "<<kFile<<endl;
245     cout<<"PATTERN: " <<kPattern<<endl;
246     
247     
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         }
261       }
262     }    
263     printf("number of entries # %lld \n", chain->GetEntries()) ;        
264   }// local files analysis
265   
266   //------------------------------
267   //GRID xml files
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://") ;
274     
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);
283     
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) ; 
291       
292     }
293   }// xml analysis
294   
295   gSystem->ChangeDirectory(ocwd.Data());
296 }