]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGGA/CaloTrackCorrelations/macros/ana.C
fixes
[u/mrichter/AliRoot.git] / PWGGA / CaloTrackCorrelations / macros / ana.C
1 /* $Id:  $ */
2 //--------------------------------------------------
3 // Example macro to do analysis with the 
4 // analysis classes in CaloTrackCorrelations
5 // Can be executed with Root and AliRoot
6 //
7 // Pay attention to the options and definitions
8 // set in the lines below
9 //
10 //  Author : Gustavo Conesa Balbastre (INFN-LNF)
11 //
12 //-------------------------------------------------
13 enum anaModes {mLocal=0, mPROOF=1, mPlugin=2, mGRID=3};
14 //mLocal    = 0: Analyze locally files in your computer
15 //mPROOF    = 1: Analyze files on GRID with Plugin
16 //mPlugin   = 2: Analyze files on GRID with Plugin
17 //mGRID     = 3: Analyze files on GRID, jobs launched from aliensh
18
19 //---------------------------------------------------------------------------
20 // Settings to read locally several files, only for "mLocal" mode
21 // The different values are default, they can be set with environmental 
22 // variables: INDIR, PATTERN, NFILES, respectivelly
23
24 char * kInDir   = "/user/data/files/"; 
25 char * kPattern = ""; // Data are in files kInDir/kPattern+i 
26 Int_t  kFile    = 2; 
27
28 //---------------------------------------------------------------------------
29 // Dataset for proof analysis, mode=mPROOF
30 // char * kDataset = "/alice/vernet/PbPb_LHC10h_ESD";
31
32 char *  kDatasetPROOF     = "/alice/vernet/LHC11b_149646";
33 Int_t   kDatasetNMaxFiles = 20;
34 TString ccin2p3UserName   = "arbor" ;
35 TString alienUserName     = "narbor" ;
36
37 //---------------------------------------------------------------------------
38 // Collection file for grid analysis
39
40 char * kXML = "collection.xml";
41
42 //---------------------------------------------------------------------------
43 //Scale histograms from file. Change to kTRUE when xsection file exists
44 //Put name of file containing xsection 
45 //Put number of events per ESD file
46 //This is an specific case for normalization of Pythia files.
47 const char * kXSFileName = "pyxsec.root";
48
49 //---------------------------------------------------------------------------
50
51 //Set some default values, but used values are set in the code!
52
53 Bool_t  kMC        = kFALSE; //With real data kMC = kFALSE
54 TString kInputData = "ESD"; //ESD, AOD, MC, deltaAOD
55 Int_t   kYear      = 2011;
56 TString kCollision = "pp";
57 Bool_t  outAOD     = kFALSE; //Some tasks doesnt need it.
58 TString kTreeName;
59 TString kPass      = "";
60 char    kTrigger[1024];
61 Int_t   kRun       = 0;
62
63 //________________________
64 void ana(Int_t mode=mGRID)
65 {
66   // Main
67   
68   //--------------------------------------------------------------------
69   // Load analysis libraries
70   // Look at the method below, 
71   // change whatever you need for your analysis case
72   // ------------------------------------------------------------------
73   
74   LoadLibraries(mode) ;
75   //gSystem->ListLibraries();
76   
77   //-------------------------------------------------------------------------------------------------
78   //Create chain from ESD and from cross sections files, look below for options.
79   //-------------------------------------------------------------------------------------------------
80   
81   // Set kInputData and kTreeName looking to the kINDIR
82   
83   CheckInputData(mode);
84   
85   // Check global analysis settings  
86   
87   CheckEnvironmentVariables();
88   
89   printf("*********************************************\n");
90   printf("*** Input data < %s >, pass %s, tree < %s >, MC?  < %d > ***\n",kInputData.Data(),kPass.Data(),kTreeName.Data(),kMC);
91   printf("*********************************************\n");
92   
93   TChain * chain   = new TChain(kTreeName) ;
94   TChain * chainxs = new TChain("Xsection") ;
95   CreateChain(mode, chain, chainxs); 
96   
97   Double_t scale = -1;
98   printf("===== kMC %d, chainxs %p\n",kMC,chainxs);
99   if(kMC && chainxs && chainxs->GetEntries() > 0)
100   {
101     Int_t nfiles = chainxs->GetEntries();
102     
103     //Get the cross section
104     Double_t xsection = 0; 
105     Float_t ntrials   = 0;
106     
107     GetAverageXsection(chainxs, xsection, ntrials);
108     
109     Int_t    nEventsPerFile = chain->GetEntries() / nfiles;
110     
111     Double_t trials = ntrials / nEventsPerFile ;
112     
113     scale = xsection/trials;
114     
115     printf("Get Cross section : nfiles  %d, nevents %d, nevents per file %d \n",nfiles, chain->GetEntries(),nEventsPerFile);     
116     printf("                    ntrials %d, trials %2.2f, xs %2.2e, scale factor %2.2e\n", ntrials,trials,xsection,scale);
117     
118   } 
119   
120   printf("*********************************************\n");
121   printf("number of entries # %lld, skipped %d\n", chain->GetEntries()) ;       
122   printf("*********************************************\n");
123   
124   if(!chain)
125   { 
126     printf("STOP, no chain available\n"); 
127     return;
128   }
129   
130   AliLog::SetGlobalLogLevel(AliLog::kError);//Minimum prints on screen
131   
132   //------------------------------------------
133   //  Alien handler part
134   //------------------------------------------
135   AliAnalysisGrid *alienHandler=0x0;
136   if(mode==mPlugin)
137   {
138     // Create and configure the alien handler plugin
139     gROOT->LoadMacro("CreateAlienHandler.C");
140     alienHandler = CreateAlienHandler();
141     if (!alienHandler) return;
142   }  
143   
144   //--------------------------------------
145   // Make the analysis manager
146   //-------------------------------------
147   AliAnalysisManager *mgr  = new AliAnalysisManager("Manager", "Manager");
148   //AliAnalysisManager::SetUseProgressBar(kTRUE);
149   //mgr->SetSkipTerminate(kTRUE);
150   //mgr->SetNSysInfo(1);
151   
152   if(mode==mPlugin)
153   {
154     // Connect plugin to the analysis manager
155     mgr->SetGridHandler(alienHandler);
156   }
157   
158   // MC handler
159   if((kMC || kInputData == "MC") && !kInputData.Contains("AOD"))
160   {
161     AliMCEventHandler* mcHandler = new AliMCEventHandler();
162     mcHandler->SetReadTR(kFALSE);//Do not search TrackRef file
163     mgr->SetMCtruthEventHandler(mcHandler);
164     if( kInputData == "MC") 
165     {
166       cout<<"MC INPUT EVENT HANDLER"<<endl;
167       mgr->SetInputEventHandler(NULL);
168     }
169   }
170   
171   
172   // AOD output handler
173   if(kInputData!="deltaAOD" && outAOD)
174   {
175     cout<<"Init output handler"<<endl;
176     AliAODHandler* aodoutHandler   = new AliAODHandler();
177     aodoutHandler->SetOutputFileName("aod.root");
178     ////aodoutHandler->SetCreateNonStandardAOD();
179     mgr->SetOutputEventHandler(aodoutHandler);
180   }
181   
182   //input
183   
184   if(kInputData == "ESD")
185   {
186     // ESD handler
187     AliESDInputHandler *esdHandler = new AliESDInputHandler();
188     esdHandler->SetReadFriends(kFALSE);
189     mgr->SetInputEventHandler(esdHandler);
190     cout<<"ESD handler "<<mgr->GetInputEventHandler()<<endl;
191   }
192   else if(kInputData.Contains("AOD"))
193   {
194     // AOD handler
195     AliAODInputHandler *aodHandler = new AliAODInputHandler();
196     mgr->SetInputEventHandler(aodHandler);
197     if(kInputData == "deltaAOD") aodHandler->AddFriend("deltaAODCaloTrackCorr.root");
198     cout<<"AOD handler "<<mgr->GetInputEventHandler()<<endl;
199   }
200   
201   //mgr->RegisterExternalFile("deltaAODCaloTrackCorr.root");
202   //mgr->SetDebugLevel(1); // For debugging, do not uncomment if you want no messages.
203   
204   TString outputFile = AliAnalysisManager::GetCommonFileName(); 
205   
206   //-------------------------------------------------------------------------
207   // Define task, put here any other task that you want to use.
208   //-------------------------------------------------------------------------
209   
210   // Physics selection
211   if(kInputData=="ESD")
212   {
213     gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C"); 
214     AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(kMC); 
215   }
216   
217   // Centrality
218   if(kCollision=="PbPb")
219   {
220     gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
221     AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();
222   }
223   
224   // Simple event counting tasks
225   AliAnalysisTask* count    = AddTaskCounter("");   // All
226   //AliAnalysisTask* countmb  = AddTaskCounter("MB"); // Min Bias
227   AliAnalysisTask* countany = AddTaskCounter("Any"); 
228   AliAnalysisTask* countint = AddTaskCounter("AnyINT");// Min Bias
229   
230   if(!kMC)
231   {
232     AliAnalysisTask* countem1 = AddTaskCounter("EMC1"); // Trig Th > 1.5 GeV approx
233     AliAnalysisTask* countem7 = AddTaskCounter("EMC7"); // Trig Th > 4-5 GeV 
234     AliAnalysisTask* countemg = AddTaskCounter("EMCEGA"); 
235     AliAnalysisTask* countemj = AddTaskCounter("EMCEJE"); 
236     if(kCollision=="PbPb")
237     {
238       AliAnalysisTask* countcen = AddTaskCounter("Central"); 
239       AliAnalysisTask* countsce = AddTaskCounter("SemiCentral"); 
240       AliAnalysisTask* countphP = AddTaskCounter("PHOSPb"); 
241     }
242     else AliAnalysisTask* countphp = AddTaskCounter("PHOS");     
243   }
244   
245   // -----------------
246   // Photon conversion
247   // ----------------- 
248 /*  
249   if(kInputData=="ESD"){
250     printf("* Configure photon conversion analysis in macro \n");
251     TString arguments = "-run-on-train -use-own-xyz  -force-aod -mc-off ";
252     gROOT->LoadMacro("$ALICE_ROOT/PWGGA/GammaConversion/macros/ConfigGammaConversion.C");
253     AliAnalysisTaskGammaConversion * taskGammaConversion = 
254     ConfigGammaConversion(arguments,mgr->GetCommonInputContainer());
255     taskGammaConversion->SelectCollisionCandidates();
256     
257     // Gamma Conversion AOD to AODPWG4Particle
258     AliAnalysisTaskGCPartToPWG4Part * taskGCToPC = new AliAnalysisTaskGCPartToPWG4Part("GCPartToPWG4Part");
259     taskGCToPC->SetGammaCutId("90035620401003321022000000090");
260     mgr->AddTask(taskGCToPC);
261     mgr->ConnectInput  (taskGCToPC, 0, mgr->GetCommonInputContainer() );
262     mgr->ConnectOutput (taskGCToPC, 0, mgr->GetCommonOutputContainer()); 
263   }
264 */  
265   
266   Bool_t kPrint   = kFALSE;
267   Bool_t deltaAOD = kFALSE;
268   gROOT->LoadMacro("AddTaskCaloTrackCorr.C");   // $ALICE_ROOT/PWGGA/CaloTrackCorrelations/macros
269   gROOT->LoadMacro("$ALICE_ROOT/PWGGA/EMCALTasks/macros/AddTaskEMCALClusterize.C"); // $ALICE_ROOT/PWGGA/EMCALTasks/macros  
270   
271   //gROOT->LoadMacro("$ALICE_ROOT/PWGGA/CaloTrackCorrelations/macros/QA/AddTaskCalorimeterQA.C");  
272   //AliAnalysisTaskCaloTrackCorrelation * qatask = AddTaskCalorimeterQA(kInputData,kYear,kPrint,kMC); 
273   
274   //gROOT->LoadMacro("$ALICE_ROOT/PWGGA/EMCALTasks/macros/AddTaskEMCALTriggerQA.C");  
275   //AliAnalysisTaskEMCALTriggerQA * qatrigtask = AddTaskEMCALTriggerQA(); 
276   
277   // Calibration, bad map ...
278   
279   Bool_t calibEE = kTRUE; // It is set automatically, but here we force to use it or not in any case
280   Bool_t calibTT = kTRUE; // It is set automatically, but here we force to use it or not in any case
281   if(kRun < 122195 || (kRun > 126437 && kRun < 136851) || kMC) calibTT=kFALSE ; // Recalibration parameters not available for LHC10a,b,c,e,f,g
282   Bool_t badMap  = kTRUE; // It is set automatically, but here we force to use it or not in any case  
283   
284   if(kCollision=="pp")
285   {
286     printf("==================================== \n");
287     printf("CONFIGURE ANALYSIS FOR PP COLLISIONS \n");
288     printf("==================================== \n");
289     
290     Bool_t  clTM      = kTRUE;
291     Bool_t  reTM      = kFALSE; // Recalculate matches if not already done in clusterizer
292     Bool_t  anTM      = kTRUE;  // Remove matched
293     Bool_t  exo       = kTRUE;  // Remove exotic cells
294     Bool_t  clnonlin  = kTRUE;  // Apply non linearity (clusterization)
295     Bool_t  annonlin  = kFALSE; // Apply non linearity (analysis)
296     Int_t   minEcell  = 50;     // 50  MeV (10 MeV used in reconstruction)
297     Int_t   minEseed  = 100;    // 100 MeV
298     Int_t   dTime     = 0;      // default, 250 ns
299     Int_t   wTime     = 30;     // default 425 < T < 825 ns, careful if time calibration is on
300     Int_t   unfMinE   = 15;     // Remove cells with less than 15 MeV from cluster after unfolding
301     Int_t   unfFrac   = 1;      // Remove cells with less than 1% of cluster energy after unfolding
302
303     //Trigger
304     TString clTrigger   = "";   
305     TString anTrigger   = "EMC7";  
306     
307     if(kMC) 
308     {
309       clTrigger   = "";
310       anTrigger   = "";
311       dTime       = 0;      
312       wTime       = 0;    
313     }
314     
315     Bool_t  selectEvents = kFALSE; // Select events depending on V0, pile-up and vertex quality
316     Bool_t  qa     = kTRUE; // Do besides calorimeter QA analysis
317     Bool_t  hadron = kTRUE; // Do besides charged track correlations analysis    
318     
319     //Analysis with clusterizer V1
320     
321     TString arrayNameV1 = "";
322     
323     AliAnalysisTaskEMCALClusterize * clv1 = AddTaskEMCALClusterize(arrayNameV1,outAOD,kMC,exo,"V1",clTrigger, clTM,
324                                                                    minEcell,minEseed,dTime,wTime,unfMinE,unfFrac,
325                                                                    calibEE,badMap,calibTT,clnonlin);    
326     
327     printf("Name of clusterizer1 array: %s\n",arrayNameV1.Data());
328     
329     if(!kMC)
330     {
331       
332       AliAnalysisTaskCaloTrackCorrelation *anav1trig   = AddTaskCaloTrackCorr(kInputData, "EMCAL", kMC, selectEvents, exo, annonlin, outputFile.Data(), 
333                                                                               kYear,kCollision,anTrigger,arrayNameV1,reTM,anTM,
334                                                                               -1,-1, qa, hadron,calibEE,badMap,calibTT,deltaAOD,kPrint,scale);
335     }
336     
337     AliAnalysisTaskCaloTrackCorrelation *anav1mb     = AddTaskCaloTrackCorr(kInputData, "EMCAL", kMC, selectEvents, exo, annonlin, outputFile.Data(), 
338                                                                             kYear,kCollision,"AnyINT",arrayNameV1,reTM,anTM,
339                                                                             -1,-1, qa, hadron,calibEE,badMap,calibTT,deltaAOD,kPrint,scale);
340     
341     
342     
343     //Analysis with clusterizer V2
344     TString arrayNameV2 = "";
345     AliAnalysisTaskEMCALClusterize * clv2 = AddTaskEMCALClusterize(arrayNameV2,outAOD,kMC,exo,"V2",clTrigger, clTM,
346                                                                    minEcell,minEseed,dTime,wTime,
347                                                                    calibEE,badMap,calibTT,clnonlin);    
348     
349     printf("Name of clusterizer2 array: %s\n",arrayNameV2.Data());
350     
351     hadron = kFALSE;
352     if(!kMC)
353     {
354       
355       
356       AliAnalysisTaskCaloTrackCorrelation *anav2tr   = AddTaskCaloTrackCorr(kInputData, "EMCAL", kMC, selectEvents, exo, annonlin, outputFile.Data(), 
357                                                                             kYear,kCollision,anTrigger,arrayNameV2,reTM,anTM, 
358                                                                             -1,-1,qa,hadron,calibEE,badMap,calibTT,deltaAOD,kPrint,scale);
359     }
360     
361     
362     AliAnalysisTaskCaloTrackCorrelation *anav2mb     = AddTaskCaloTrackCorr(kInputData, "EMCAL", kMC, selectEvents, exo, annonlin, outputFile.Data(), 
363                                                                             kYear,kCollision,"AnyINT",arrayNameV2,reTM,anTM,
364                                                                             -1,-1, qa, hadron,calibEE,badMap,calibTT,deltaAOD,kPrint,scale);
365   }
366   
367   if(kCollision=="PbPb")
368   {
369     printf("====================================== \n");
370     printf("CONFIGURE ANALYSIS FOR PbPb COLLISIONS \n");
371     printf("====================================== \n");
372     
373     Bool_t  clTM      = kTRUE;
374     Bool_t  reTM      = kFALSE; // Recalculate matches if not already done in clusterizer
375     Bool_t  anTM      = kTRUE;  // Remove matched
376     Bool_t  exo       = kTRUE;  // Remove exotic cells
377     Bool_t  clnonlin  = kTRUE;  // Apply non linearity (clusterization)
378     Bool_t  annonlin  = kFALSE; // Apply non linearity (analysis)
379     Int_t   minEcell  = 150;    // 50  MeV (10 MeV used in reconstruction)
380     Int_t   minEseed  = 300;    // 100 MeV
381     Int_t   dTime     = 0;      // default, 250 ns
382     Int_t   wTime     = 0;      // default 425 < T < 825 ns
383     Int_t   unfMinE   = 15;     // Remove cells with less than 15 MeV from cluster after unfolding
384     Int_t   unfFrac   = 1;      // Remove cells with less than 1% of cluster energy after unfolding
385     
386     // Trigger
387     TString clTrigger = ""; 
388     TString anTrigger = "EMCGA";  
389     if(kMC) 
390     {
391       clTrigger = "";
392       anTrigger = "";
393       dTime       = 0;      
394       wTime       = 0;    
395     }
396     
397     Bool_t  selectEvents = kFALSE; // Select events depending on V0, pile-up and vertex quality
398     Bool_t  qa     = kTRUE; // Do besides calorimeter QA analysis
399     Bool_t  hadron = kTRUE; // Do besides charged track correlations analysis    
400     
401     //Analysis with clusterizer V1
402     
403     TString arrayNameV1 = "";
404     AliAnalysisTaskEMCALClusterize * clv1 = AddTaskEMCALClusterize(arrayNameV1,outAOD,kMC,exo,"V1",clTrigger, clTM,
405                                                                    minEcell,minEseed,dTime,wTime,unfMinE,unfFrac,
406                                                                    calibEE,badMap,calibTT,clnonlin);    
407     
408     printf("Name of clusterizer1 array: %s\n",arrayNameV1.Data());
409     
410     if(!kMC)
411     {
412       AliAnalysisTaskCaloTrackCorrelation *anav1c   = AddTaskCaloTrackCorr(kInputData, "EMCAL", kMC, selectEvents, exo, annonlin, outputFile.Data(), 
413                                                                            kYear,kCollision,anTrigger,arrayNameV1,reTM,anTM, 
414                                                                            0,20,qa,hadron,calibEE,badMap,calibTT,deltaAOD,kPrint);
415       AliAnalysisTaskCaloTrackCorrelation *anav1m   = AddTaskCaloTrackCorr(kInputData, "EMCAL", kMC, selectEvents, exo, annonlin, outputFile.Data(), 
416                                                                            kYear,kCollision,anTrigger,arrayNameV1,reTM,anTM,
417                                                                            20,40,qa,hadron,calibEE,badMap,calibTT,deltaAOD,kPrint);
418       AliAnalysisTaskCaloTrackCorrelation *anav1p   = AddTaskCaloTrackCorr(kInputData, "EMCAL", kMC,  selectEvents, exo, annonlin, outputFile.Data(), 
419                                                                            kYear,kCollision,anTrigger,arrayNameV1,reTM,anTM,
420                                                                            60,80,qa,hadron,calibEE,badMap,calibTT,deltaAOD,kPrint);
421     }
422     
423     //Analysis with clusterizer V2
424     
425     TString arrayNameV2 = "";
426     AliAnalysisTaskEMCALClusterize * clv2 = AddTaskEMCALClusterize(arrayNameV2,outAOD,kMC,exo,"V2",clTrigger, clTM,
427                                                                    minEcell,minEseed,dTime,wTime,unfMinE,unfFrac,
428                                                                    calibEE,badMap,calibTT,clnonlin);        
429     
430     printf("Name of clusterizer2 array: %s\n",arrayNameV2.Data());
431     
432     hadron = kFALSE;
433     
434     if(!kMC)
435     {
436       
437       AliAnalysisTaskCaloTrackCorrelation *anav2cT   = AddTaskCaloTrackCorr(kInputData, "EMCAL", kMC, selectEvents, exo, annonlin, outputFile.Data(), 
438                                                                             kYear,kCollision,anTrigger,arrayNameV2,reTM,anTM, 
439                                                                             0,20,qa,hadron,calibEE,badMap,calibTT,deltaAOD,kPrint);
440       AliAnalysisTaskCaloTrackCorrelation *anav2mT   = AddTaskCaloTrackCorr(kInputData, "EMCAL", kMC, selectEvents, exo, annonlin, outputFile.Data(), 
441                                                                             kYear,kCollision,anTrigger,arrayNameV2,reTM,anTM,
442                                                                             20,40,qa,hadron,calibEE,badMap,calibTT,deltaAOD,kPrint);
443       AliAnalysisTaskCaloTrackCorrelation *anav2pT   = AddTaskCaloTrackCorr(kInputData, "EMCAL", kMC, selectEvents, exo, annonlin, outputFile.Data(), 
444                                                                             kYear,kCollision,anTrigger,arrayNameV2,reTM,anTM,
445                                                                             60,80,qa,hadron,calibEE,badMap,calibTT,deltaAOD,kPrint);
446     }
447     
448     AliAnalysisTaskCaloTrackCorrelation *anav2cMB   = AddTaskCaloTrackCorr(kInputData, "EMCAL", kMC, selectEvents, exo, annonlin, outputFile.Data(), 
449                                                                            kYear,kCollision,"AnyINT",arrayNameV2,reTM,anTM, 
450                                                                            0,20,qa,hadron,calibEE,badMap,calibTT,deltaAOD,kPrint);
451     AliAnalysisTaskCaloTrackCorrelation *anav2mMB   = AddTaskCaloTrackCorr(kInputData, "EMCAL", kMC, selectEvents, exo, annonlin, outputFile.Data(), 
452                                                                            kYear,kCollision,"AnyINT",arrayNameV2,reTM,anTM,
453                                                                            20,40,qa,hadron,calibEE,badMap,calibTT,deltaAOD,kPrint);
454     AliAnalysisTaskCaloTrackCorrelation *anav2pMB   = AddTaskCaloTrackCorr(kInputData, "EMCAL", kMC, selectEvents, exo, annonlin, outputFile.Data(), 
455                                                                            kYear,kCollision,"AnyINT",arrayNameV2,reTM,anTM,
456                                                                            60,80,qa,hadron,calibEE,badMap,calibTT,deltaAOD,kPrint);
457     
458     
459   }
460   
461
462   
463   //-----------------------
464   // Run the analysis
465   //-----------------------    
466   mgr->InitAnalysis();
467   mgr->PrintStatus();
468   
469   if      (mode == mPlugin) mgr->StartAnalysis("grid");
470   else if (mode == mPROOF ) mgr->StartAnalysis("proof",chain);
471   else                      mgr->StartAnalysis("local",chain);
472   
473   cout <<" Analysis ended sucessfully "<< endl ;
474   
475 }
476
477 //_____________________________
478 void  LoadLibraries(Int_t mode)
479 {
480   
481   if (mode == mPROOF) {
482     //TProof::Mgr("ccalpmaster")->SetROOTVersion("ALICE_v5-27-06b");
483     gROOT->LoadMacro("/afs/in2p3.fr/group/alice/laf/EnableAliRootForLAF.C");
484     TProof* proof = EnableAliRootForLAF("ccaplmaster",nPROOFWorkers.Data(),ccin2p3UserName.Data(),alienUserName.Data(),"",kFALSE,kTRUE,kTRUE,"OADB:ANALYSIS:ANALYSISalice:AOD:ESD:CORRFW:STEERBase:EMCALUtils:PHOSUtils:PWGCaloTrackCorrBase:PWGGACaloTrackCorrelations:PWGGAEMCALTasks");
485     
486     //  TProof* proof = TProof::Open("ccaplmaster",Form("workers=%s",nPROOFWorkers.Data()));
487     
488     //     //proof->ClearPackages();
489     //     proof->UploadPackage("STEERBase");
490     //     proof->UploadPackage("ESD");
491     //     proof->UploadPackage("AOD");
492     //     proof->UploadPackage("ANALYSIS");
493     //     proof->UploadPackage("OADB");
494     //     proof->UploadPackage("ANALYSISalice");
495     //     proof->UploadPackage("CORRFW");
496     //     //proof->UploadPackage("JETAN");
497     //     proof->UploadPackage("PHOSUtils");
498     //     proof->UploadPackage("EMCALUtils");
499     //     proof->UploadPackage("PWGCaloTrackCorrBase");
500     //     proof->UploadPackage("PWGGACaloTrackCorrelations");
501     //     proof->UploadPackage("PWGGAEMCALTasks");
502     
503     //     proof->EnablePackage("STEERBase");
504     //     proof->EnablePackage("ESD");
505     //     proof->EnablePackage("AOD");
506     //     proof->EnablePackage("ANALYSIS");
507     //     proof->EnablePackage("OADB");
508     //     proof->EnablePackage("ANALYSISalice");
509     //     proof->EnablePackage("CORRFW");
510     //     //proof->EnablePackage("JETAN");
511     //     proof->EnablePackage("PHOSUtils");
512     //     proof->EnablePackage("EMCALUtils");
513     //     proof->EnablePackage("PWGCaloTrackCorrBase");
514     //     proof->EnablePackage("PWGGACaloTrackCorrelations");
515     //     proof->EnablePackage("PWGGAEMCALTasks");
516     return;
517   }  
518   
519   //--------------------------------------
520   // Load the needed libraries most of them already loaded by aliroot
521   //--------------------------------------
522   gSystem->Load("libTree.so");
523   gSystem->Load("libGeom.so");
524   gSystem->Load("libVMC.so");
525   gSystem->Load("libXMLIO.so");
526   gSystem->Load("libMatrix.so");
527   gSystem->Load("libPhysics.so");
528   gSystem->Load("libMinuit.so"); // Root + libraries to if reclusterization is done
529   
530   gSystem->Load("libSTEERBase.so");
531   gSystem->Load("libGui.so"); // Root + libraries to if reclusterization is done
532   gSystem->Load("libCDB.so"); // Root + libraries to if reclusterization is done
533   gSystem->Load("libESD.so"); // Root + libraries to if reclusterization is done
534   gSystem->Load("libAOD.so");
535   gSystem->Load("libRAWDatabase.so"); // Root + libraries to if reclusterization is done
536   gSystem->Load("libProof.so"); 
537   gSystem->Load("libOADB");
538   gSystem->Load("libANALYSIS.so");
539   gSystem->Load("libSTEER.so"); // Root + libraries to if reclusterization is done
540   
541   gSystem->Load("libRAWDatarec.so"); // Root + libraries to if reclusterization is done
542   gSystem->Load("libRAWDatasim.so"); // Root + libraries to if reclusterization is done
543   gSystem->Load("libVZERObase.so");  // Root + libraries to if reclusterization is done
544   gSystem->Load("libVZEROrec.so");   // Root + libraries to if reclusterization is done
545   
546   gSystem->Load("libEMCALUtils");
547   //SetupPar("EMCALUtils");
548   gSystem->Load("libEMCALraw");  // Root + libraries to if reclusterization is done
549   gSystem->Load("libEMCALbase"); // Root + libraries to if reclusterization is done
550   gSystem->Load("libEMCALsim");  // Root + libraries to if reclusterization is done
551   gSystem->Load("libEMCALrec");  // Root + libraries to if reclusterization is done
552   //SetupPar("EMCALraw");
553   //SetupPar("EMCALbase");
554   //SetupPar("EMCALsim");
555   //SetupPar("EMCALrec");
556   
557   gSystem->Load("libANALYSISalice.so");
558   //gSystem->Load("libTENDER.so"); 
559   //gSystem->Load("libTENDERSupplies.so");
560   
561   gSystem->Load("libPHOSUtils");
562   gSystem->Load("libEMCALUtils");
563   gSystem->Load("libPWGCaloTrackCorrBase");
564   gSystem->Load("libPWGGACaloTrackCorrelations");
565   gSystem->Load("libPWGGAEMCALTasks");
566   //SetupPar("PWGCaloTrackCorrBase");
567   //SetupPar("PWGGACaloTrackCorrelations");
568   //SetupPar("PWGGAEMCALTasks");
569   
570  
571   //gSystem->Load("libJETAN");
572   //gSystem->Load("FASTJETAN");
573   //gSystem->Load("PWGJE");
574
575   //gSystem->Load("libCORRFW.so");
576   //gSystem->Load("libPWGGAGammaConv.so"); 
577   //SetupPar("PWGGAGammaConv"); 
578   
579   // needed for plugin?
580   gSystem->AddIncludePath("-I$ALICE_ROOT");
581   gSystem->AddIncludePath("-I./");     
582   
583 }
584
585 //_________________________________
586 void SetupPar(char* pararchivename)
587 {
588   //Load par files, create analysis libraries
589   //For testing, if par file already decompressed and modified
590   //classes then do not decompress.
591   
592   TString cdir(Form("%s", gSystem->WorkingDirectory() )) ; 
593   TString parpar(Form("%s.par", pararchivename)) ; 
594   
595   if ( gSystem->AccessPathName(pararchivename) ) {  
596     TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
597     gROOT->ProcessLine(processline.Data());
598   }
599   
600   TString ocwd = gSystem->WorkingDirectory();
601   gSystem->ChangeDirectory(pararchivename);
602   
603   // check for BUILD.sh and execute
604   if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
605     printf("*******************************\n");
606     printf("*** Building PAR archive    ***\n");
607     cout<<pararchivename<<endl;
608     printf("*******************************\n");
609     
610     if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
611       Error("runProcess","Cannot Build the PAR Archive! - Abort!");
612       return -1;
613     }
614   }
615   // check for SETUP.C and execute
616   if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
617     printf("*******************************\n");
618     printf("*** Setup PAR archive       ***\n");
619     cout<<pararchivename<<endl;
620     printf("*******************************\n");
621     gROOT->Macro("PROOF-INF/SETUP.C");
622   }
623   
624   gSystem->ChangeDirectory(ocwd.Data());
625   printf("Current dir: %s\n", ocwd.Data());
626 }
627
628 //______________________________________
629 void CheckInputData(const anaModes mode)
630 {
631   //Sets input data and tree
632   
633   TString ocwd = gSystem->WorkingDirectory();
634   
635   //---------------------------------------
636   //Local files analysis
637   //---------------------------------------
638   if(mode == mLocal){    
639     //If you want to add several ESD files sitting in a common directory INDIR
640     //Specify as environmental variables the directory (INDIR), the number of files 
641     //to analyze (NFILES) and the pattern name of the directories with files (PATTERN)
642     
643     if(gSystem->Getenv("INDIR"))  
644       kInDir = gSystem->Getenv("INDIR") ; 
645     else cout<<"INDIR not set, use default: "<<kInDir<<endl;    
646     
647     TString sindir(kInDir);
648     if     (sindir.Contains("pass1")) kPass = "pass1";
649     else if(sindir.Contains("pass2")) kPass = "pass2";
650     else if(sindir.Contains("pass3")) kPass = "pass3";
651     
652     if(gSystem->Getenv("PATTERN"))   
653       kPattern = gSystem->Getenv("PATTERN") ; 
654     else  cout<<"PATTERN not set, use default: "<<kPattern<<endl;
655     
656     cout<<"INDIR   : "<<kInDir<<endl;
657     cout<<"NFILES  : "<<kFile<<endl;
658     
659     char fileE[120] ;   
660     char fileA[120] ;   
661     char fileG[120] ;
662     char fileEm[120] ;   
663     for (Int_t event = 0 ; event < kFile ; event++) {
664       sprintf(fileE,  "%s/%s%d/AliESDs.root",    kInDir,kPattern,event) ; 
665       sprintf(fileA,  "%s/%s%d/AliAOD.root",     kInDir,kPattern,event) ; 
666       sprintf(fileG,  "%s/%s%d/galice.root",     kInDir,kPattern,event) ; 
667       sprintf(fileEm, "%s/%s%d/embededAOD.root", kInDir,kPattern,event) ; 
668       
669       TFile * fESD = TFile::Open(fileE) ; 
670       TFile * fAOD = TFile::Open(fileA) ; 
671       
672       //Check if file exists and add it, if not skip it
673       if (fESD) 
674       {
675         kTreeName  = "esdTree";
676         kInputData = "ESD";
677         TFile * fG = TFile::Open(fileG);
678         if(fG) { kMC = kTRUE; fG->Close();}
679         else     kMC = kFALSE;
680         
681         // Get run number
682         TTree* esdTree = (TTree*)fESD->Get("esdTree");
683         AliESDEvent* esd = new AliESDEvent();
684         esd->ReadFromTree(esdTree);
685         esdTree->GetEvent(0);
686         kRun = esd->GetRunNumber();
687         
688         return;
689       }
690       else if(fAOD)
691       {
692         kTreeName  = "aodTree";
693         kInputData = "AOD";
694         if(((TTree*) fAOD->Get("aodTree"))->GetBranch("mcparticles")) kMC=kTRUE;
695         else kMC = kFALSE;
696         
697         // Get run number
698         TTree* aodTree = (TTree*)fAOD->Get("aodTree");
699         AliAODEvent* aod = new AliAODEvent();
700         aod->ReadFromTree(aodTree);
701         aodTree->GetEvent(0);
702         kRun = aod->GetRunNumber();
703         return;
704       }
705       else if(TFile::Open(fileEm))
706       {
707         kTreeName  = "aodTree";
708         kInputData = "AOD";
709         kMC        = kTRUE;
710         
711         return;
712       }
713       else if(TFile::Open(fileG))
714       {
715         kTreeName  = "TE";
716         kInputData = "MC";
717         kMC        = kTRUE;
718         return;
719       }
720     }
721     
722     if(fESD) fESD->Close();
723     if(fAOD) fAOD->Close();
724     
725   }// local files analysis
726   
727   //------------------------------
728   //GRID xml files
729   //-----------------------------
730   else if(mode == mGRID){
731     //Get colection file. It is specified by the environmental
732     //variable XML
733     
734     if(gSystem->Getenv("XML") )
735       kXML = gSystem->Getenv("XML");
736     else
737       sprintf(kXML, "collection.xml") ; 
738     
739     if (!TFile::Open(kXML)) {
740       printf("No collection file with name -- %s -- was found\n",kXML);
741       return ;
742     }
743     else cout<<"XML file "<<kXML<<endl;
744     
745     //Load necessary libraries and connect to the GRID
746     gSystem->Load("libNetx.so") ; 
747     gSystem->Load("libRAliEn.so"); 
748     TGrid::Connect("alien://") ;
749     
750     //Feed Grid with collection file
751     TGridCollection * collection = (TGridCollection*) TAlienCollection::Open(kXML);
752     if (! collection) {
753       AliError(Form("%s not found", kXML)) ; 
754       return kFALSE ; 
755     }
756     TGridResult* result = collection->GetGridResult("",0 ,0);
757     
758     for (Int_t index = 0; index < result->GetEntries(); index++) {
759       TString alienURL = result->GetKey(index, "turl") ; 
760       cout << "================== " << alienURL << endl ; 
761       
762       if     (alienURL.Contains("pass1")) kPass = "pass1";
763       else if(alienURL.Contains("pass2")) kPass = "pass2";
764       else if(alienURL.Contains("pass3")) kPass = "pass3";
765       
766       kRun = AliAnalysisManager::GetRunFromAlienPath(alienURL.Data());
767       printf("Run number from alien path = %d\n",kRun);
768       
769       TFile * fAOD = 0 ; 
770       //Check if file exists and add it, if not skip it
771       if (alienURL.Contains("AliESDs.root"))  
772       {
773         kTreeName  = "esdTree";
774         kInputData = "ESD";
775         alienURL.ReplaceAll("AliESDs.root","galice.root");
776         if(TFile::Open(alienURL)) kMC=kTRUE;
777         else kMC = kFALSE;
778         return;
779       }
780       else if(alienURL.Contains("AliAOD.root"))
781       {
782         kTreeName  = "aodTree";
783         kInputData = "AOD";
784         fAOD = TFile::Open(alienURL);
785         if(((TTree*) fAOD->Get("aodTree"))->GetBranch("mcparticles")) kMC=kTRUE;
786         else kMC = kFALSE;
787         return;
788       }
789       else if(alienURL.Contains("embededAOD.root"))
790       {
791         kTreeName  = "aodTree";
792         kInputData = "AOD";
793         kMC=kTRUE;
794         return;
795       }
796       else if(alienURL.Contains("galice.root"))
797       {
798         kTreeName  = "TE";
799         kInputData = "MC";
800         kMC=kTRUE;
801         return;
802       } 
803     }
804   }// xml analysis
805   //------------------------------
806   //PROOF files
807   //-----------------------------
808   else if(mode == mPROOF){
809     
810     TFileCollection* coll  = gProof->GetDataSet(kDatasetPROOF)->GetStagedSubset();
811     
812     TIter iter(coll->GetList());
813     
814     TFileInfo* fileInfo = 0;
815     while ((fileInfo = dynamic_cast<TFileInfo*> (iter())))
816     {
817       if (fileInfo->GetFirstUrl()) {
818         TString ProofURL = fileInfo->GetFirstUrl()->GetUrl();
819         cout << "================== " << ProofURL << endl ; 
820         
821         if     (ProofURL.Contains("pass1")) kPass = "pass1";
822         else if(ProofURL.Contains("pass2")) kPass = "pass2";
823         else if(ProofURL.Contains("pass3")) kPass = "pass3";
824         
825         kRun = AliAnalysisManager::GetRunFromAlienPath(ProofURL.Data());
826         printf("Run number from alien path = %d\n",kRun);
827         
828         TFile * fAOD = 0 ; 
829         //Check if file exists and add it, if not skip it
830         if (ProofURL.Contains("AliESDs.root"))  
831         {
832           kTreeName  = "esdTree";
833           kInputData = "ESD";
834           alienURL.ReplaceAll("AliESDs.root","galice.root");
835           if(TFile::Open(ProofURL)) kMC=kTRUE;
836           else kMC = kFALSE;
837           
838           return;
839         }
840         else if(ProofURL.Contains("AliAOD.root"))
841         {
842           kTreeName  = "aodTree";
843           kInputData = "AOD";
844           fAOD = TFile::Open(ProofURL);
845           if(((TTree*) fAOD->Get("aodTree"))->GetBranch("mcparticles")) kMC=kTRUE;
846           else kMC = kFALSE;
847           return;
848         }
849         else if(ProofURL.Contains("embededAOD.root"))
850         {
851           kTreeName  = "aodTree";
852           kInputData = "AOD";
853           kMC=kTRUE;
854           return;
855         }
856         else if(ProofURL.Contains("galice.root"))
857         {
858           kTreeName  = "TE";
859           kInputData = "MC";
860           kMC=kTRUE;
861           return;
862         } 
863       }
864     }
865   }// proof analysis
866   
867   gSystem->ChangeDirectory(ocwd.Data());
868   
869 }
870
871 //_____________________________________________________________________
872 void CreateChain(const anaModes mode, TChain * chain, TChain * chainxs)
873 {
874   //Fills chain with data
875   TString ocwd = gSystem->WorkingDirectory();
876   
877   //---------------------------------------
878   // Local files analysis
879   //---------------------------------------
880   if(mode == mLocal){    
881     //If you want to add several ESD files sitting in a common directory INDIR
882     //Specify as environmental variables the directory (INDIR), the number of files 
883     //to analyze (NFILES) and the pattern name of the directories with files (PATTERN)
884     
885     if(gSystem->Getenv("INDIR"))  
886       kInDir = gSystem->Getenv("INDIR") ; 
887     else cout<<"INDIR not set, use default: "<<kInDir<<endl;    
888     
889     if(gSystem->Getenv("PATTERN"))   
890       kPattern = gSystem->Getenv("PATTERN") ; 
891     else  cout<<"PATTERN not set, use default: "<<kPattern<<endl;
892     
893     if(gSystem->Getenv("NFILES"))
894       kFile = atoi(gSystem->Getenv("NFILES")) ;
895     else cout<<"NFILES not set, use default: "<<kFile<<endl;
896     
897     //Check if env variables are set and are correct
898     if ( kInDir  && kFile) {
899       printf("Get %d files from directory %s\n",kFile,kInDir);
900       if ( ! gSystem->cd(kInDir) ) {//check if ESDs directory exist
901         printf("%s does not exist\n", kInDir) ;
902         return ;
903       }
904       
905       //if(gSystem->Getenv("XSFILE"))  
906       //kXSFileName = gSystem->Getenv("XSFILE") ; 
907       //else cout<<" XS file name not set, use default: "<<kXSFileName<<endl;   
908       char * kGener = gSystem->Getenv("GENER");
909       if(kGener) {
910         cout<<"GENER "<<kGener<<endl;
911         if     (!strcmp(kGener,"PYTHIA")) kXSFileName = "pyxsec.root";
912         else if(!strcmp(kGener,"HERWIG")) kXSFileName = "hexsec.root";
913         else cout<<" UNKNOWN GENER, use default: "<<kXSFileName<<endl;
914       }
915       else cout<<" GENER not set, use default xs file name: "<<kXSFileName<<endl;
916       
917       cout<<"INDIR   : "<<kInDir     <<endl;
918       cout<<"NFILES  : "<<kFile      <<endl;
919       cout<<"PATTERN : "<<kPattern   <<endl;
920       cout<<"XSFILE  : "<<kXSFileName<<endl;
921       
922       TString datafile="";
923       if     (kInputData == "ESD")        datafile = "AliESDs.root" ;
924       else if(kInputData.Contains("AOD")) datafile = "AliAOD.root"  ;
925       else if(kInputData == "MC")         datafile = "galice.root"  ;
926       
927       //Loop on ESD/AOD/MC files, add them to chain
928       Int_t event =0;
929       Int_t skipped=0 ; 
930       char file[120] ;
931       char filexs[120] ;
932       
933       for (event = 0 ; event < kFile ; event++) {
934         sprintf(file,   "%s/%s%d/%s", kInDir,kPattern,event,datafile.Data()) ; 
935         sprintf(filexs, "%s/%s%d/%s", kInDir,kPattern,event,kXSFileName) ; 
936         TFile * fData = 0 ; 
937         //Check if file exists and add it, if not skip it
938         if ( fData = TFile::Open(file)) {
939           if ( fData->Get(kTreeName) ) { 
940             printf("++++ Adding %s\n", file) ;
941             chain->AddFile(file);
942             chainxs->Add(filexs) ; 
943           }
944         }
945         else { 
946           printf("---- Skipping %s\n", file) ;
947           skipped++ ;
948         }
949       }
950     }
951     else {
952       TString input = "AliESDs.root" ;
953       cout<<">>>>>> No list added, take a single file <<<<<<<<< "<<input<<endl;
954       chain->AddFile(input);
955     }
956     
957   }// local files analysis
958   
959   //------------------------------
960   // GRID xml files
961   //------------------------------
962   else if(mode == mGRID){
963     //Get colection file. It is specified by the environmental
964     //variable XML
965     
966     //Feed Grid with collection file
967     TGridCollection * collection = (TGridCollection*) TAlienCollection::Open(kXML);
968     if (! collection) {
969       AliError(Form("%s not found", kXML)) ; 
970       return kFALSE ; 
971     }
972     
973     TGridResult* result = collection->GetGridResult("",0 ,0);
974     
975     // Makes the ESD chain 
976     printf("*** Getting the Chain       ***\n");
977     for (Int_t index = 0; index < result->GetEntries(); index++) {
978       TString alienURL = result->GetKey(index, "turl") ; 
979       cout << "================== " << alienURL << endl ; 
980       chain->Add(alienURL) ; 
981       alienURL.ReplaceAll("AliESDs.root",kXSFileName);
982       chainxs->Add(alienURL) ; 
983     }
984   }// xml analysis
985   
986   //------------------------------
987   // PROOF
988   //------------------------------
989   else if (mode == mPROOF) {
990     
991     TFileCollection* ds= gProof->GetDataSet(kDatasetPROOF)->GetStagedSubset();
992     
993     gROOT->LoadMacro("/afs/in2p3.fr/group/alice/laf/dataset_management/CreateChainFromDataSet.C");
994     chain = CreateChainFromDataSet(ds, kTreeName , kDatasetNMaxFiles);
995     printf("chain has %d entries\n",chain->GetEntries());
996   }
997   
998   gSystem->ChangeDirectory(ocwd.Data());
999   
1000 }
1001
1002 //______________________________
1003 void CheckEnvironmentVariables()
1004 {
1005   
1006   sprintf(kTrigger,"");
1007   
1008   Bool_t bRecalibrate = kFALSE;
1009   Bool_t bBadChannel = kFALSE;
1010   
1011   for (int i=0; i< gApplication->Argc();i++){
1012     
1013 #ifdef VERBOSEARGS
1014     
1015     printf("Arg  %d:  %s\n",i,gApplication->Argv(i));
1016     
1017 #endif
1018     
1019     TString sRun = "";
1020     
1021     if (!(strcmp(gApplication->Argv(i),"--trigger")))
1022       sprintf(trigger,gApplication->Argv(i+1));
1023     
1024     if (!(strcmp(gApplication->Argv(i),"--recalibrate")))
1025       bRecalibrate = atoi(gApplication->Argv(i+1));
1026     
1027     if (!(strcmp(gApplication->Argv(i),"--badchannel")))
1028       bBadChannel = atoi(gApplication->Argv(i+1));
1029     
1030     if (!(strcmp(gApplication->Argv(i),"--run"))){
1031       sRun = gApplication->Argv(i+1);
1032       if(sRun.Contains("LHC10")) {
1033         kYear = 2010;
1034       }
1035       else {
1036         if(kRun <=0){
1037           kRun = atoi(gApplication->Argv(i+1));
1038         }
1039         else printf("** Run number already set  to %d, do not set to %d\n",kRun,atoi(gApplication->Argv(i+1)));
1040       }//numeric run
1041     }//--run available
1042     
1043   }// args loop
1044   
1045   if(!sRun.Contains("LHC10")){
1046     if     ( kRun < 140000) 
1047     {
1048       kYear = 2010;
1049       if( kRun >= 136851 ) kCollision = "PbPb";
1050     }
1051     else if( kRun < 170600)
1052     {
1053       kYear = 2011;
1054       if( kRun >= 166500 ) kCollision = "PbPb";
1055     }
1056     else 
1057     {
1058       kYear = 2012;
1059
1060     }
1061   }
1062   
1063   if(kMC) sprintf(kTrigger,"");
1064   
1065   printf("*********************************************\n");
1066   //printf("*** Settings trigger %s, recalibrate %d, remove bad channels %d, year %d, collision %s, run %d ***\n",
1067   //       kTrigger,bRecalibrate,bBadChannel, kYear,kCollision.Data(), kRun);
1068   printf("*** Settings year %d, collision %s, run %d ***\n",kYear,kCollision.Data(), kRun);
1069   printf("*********************************************\n");
1070   
1071 }
1072
1073 //_________________________________________________________________
1074 void GetAverageXsection(TTree * tree, Double_t & xs, Float_t & ntr)
1075 {
1076   // Read the PYTHIA statistics from the file pyxsec.root created by
1077   // the function WriteXsection():
1078   // integrated cross section (xsection) and
1079   // the  number of Pyevent() calls (ntrials)
1080   // and calculate the weight per one event xsection/ntrials
1081   // The spectrum calculated by a user should be
1082   // multiplied by this weight, something like this:
1083   // TH1F *userSpectrum ... // book and fill the spectrum
1084   // userSpectrum->Scale(weight)
1085   //
1086   // Yuri Kharlov 19 June 2007
1087   // Gustavo Conesa 15 April 2008
1088   Double_t xsection = 0;
1089   UInt_t    ntrials = 0;
1090   xs = 0;
1091   ntr = 0;
1092   
1093   Int_t nfiles =  tree->GetEntries()  ;
1094   if (tree && nfiles > 0) {
1095     tree->SetBranchAddress("xsection",&xsection);
1096     tree->SetBranchAddress("ntrials" ,&ntrials );
1097     for(Int_t i = 0; i < nfiles; i++){
1098       tree->GetEntry(i);
1099       xs  += xsection ;
1100       ntr += ntrials ;
1101       cout << "xsection " <<xsection<<" ntrials "<<ntrials<<endl; 
1102     }
1103     
1104     xs =   xs /  nfiles;
1105     ntr =  ntr / nfiles;
1106     cout << "-----------------------------------------------------------------"<<endl;
1107     cout << "Average of "<< nfiles<<" files: xsection " <<xs<<" ntrials "<<ntr<<endl; 
1108     cout << "-----------------------------------------------------------------"<<endl;
1109   } 
1110   else cout << " >>>> Empty tree !!!! <<<<< "<<endl;
1111   
1112 }
1113