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