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