TENDER becomes Tender
[u/mrichter/AliRoot.git] / PWGLF / SPECTRA / IdentifiedHighPt / grid / runAAF.C
CommitLineData
4ebdd20e 1/*
2How to debug:
3Check that AliRoot and ROOT versions are OK!
4
5to run:
6 export X509_CERT_DIR=$ALIEN_ROOT/globus/share/certificates
7 aliroot
8 .L runAAF.C
9
10 runAAF(10, "proof", "/alice/data/LHC10h_000137366_p2", 2)
11
12 runAAF(1, "local aod MC", "test_aod_mc.txt", 3)
13
14 runAAF(1, "grid aod off", "lhc10d", 3)
15
16
17 runAAF(5, "grid off MC1", "lhc10d", 3)
18
19 runAAF(1, "local esd PbPb", "test_esd.txt", 2) //ESDs local
20
21
22 runAAF(20, "grid esd term PbPb", "lhc10h", 2)
23
24To clean:
25 rm -f HighPtDeDx*
26 rm -f *.xml
27 rm -f *.root
28
29*/
30
31//UInt_t kTriggerInt=AliVEvent::kMB;
32//UInt_t *kTriggerInt=new UInt_t[2];
33//kTriggerInt[0]=AliVEvent::kMB;
34//kTriggerInt[1]=AliVEvent::kINT7;
35
36UInt_t kTriggerInt[2] = { AliVEvent::kMB, AliVEvent::kINT7 };
37Float_t minCent[6] = { 0.0, 5.0, 10.0, 20.0, 40.0, 60.0 };
38Float_t maxCent[6] = { 5.0, 10.0, 20.0, 40.0, 60.0, 80.0 };
39void runAAF(Int_t nFilesMax, char* type = "local", char* textFileName = "esd.txt", Int_t task = 2);
40TChain* CreateChainCAF(Int_t nFilesMax, TFileCollection* coll, char* treeName);
41//TChain* CreateChainCAF(Int_t nFilesMax, const char* label, const char* treeName, Bool_t AnalysisMC);
42TChain* CreateChainLocal(Int_t nFilesMax, char* filename, char* treeName);
43const Char_t* GetTreeName(Bool_t esdAna);
44
45//________________________________________________________________
46const Char_t* GetTreeName(Bool_t esdAna)
47{
48 if(esdAna)
49 return "esdTree";
50 else
51 return "aodTree";
52}
53
54//________________________________________________________________
55void runAAF(Int_t nFilesMax, char* type, char* textFileName, Int_t task)
56{
57 Int_t analysisMC = 0;
58 Bool_t debug = kTRUE;
59 Bool_t readTR = kFALSE;
60 Bool_t esdAna = kTRUE; // run ESD analysis (kTRUE) or AOD analysis (kFALSE)
61 Int_t runtype = -1;
62
63
64
65
66 if(strstr(type,"aod") != NULL) esdAna = kFALSE;; // AOD analysis
67
68 const Char_t* treeName = GetTreeName(esdAna);
69
70 if(strstr(type,"PbPb") != NULL) runtype = 2; // PbPb
71 if(strstr(type,"pp") != NULL) runtype = 3; // pp
72 if(strstr(type,"900") != NULL){ // 900GeV pp
73 if(runtype != -1){
74 printf("conflicting run types\n");
75 return;
76 }
77 runtype = 1;
78 }
79 if(runtype == -1) runtype = 0; // 7TeV pp
80
81 char *test;
82 test = strstr(type,"MC");
83 if(test != NULL){
84 analysisMC = kTRUE;
85 cout << "Test: " << test << endl;
86 if(sscanf(test,"MC%d",&analysisMC)){
87 // cout << "**************" << analysisMC << endl;
88 if(!analysisMC) analysisMC = 1;
89 }
90 }
91 cout << "MonteCarlo " << analysisMC << endl;
92
93 const char* alirootver = "v5-02-17-AN";
94 Int_t mode = -1; // mode 1: PROOF, 2: GRID, 0: LOCAL
95 printf("===================================================================\n");
96 if(strstr(type,"proof") != NULL){
97 if(mode != -1){
98 printf("===== CONFLICTING TYPES =====\n");
99 return;
100 }
101 mode = 1;
102 printf("=============== RUNNING ANALYSIS IN CAF MODE ================\n");
103 }
104 if(strstr(type,"grid") != NULL){
105 if(mode != -1){
106 printf("===== CONFLICTING TYPES =====\n");
107 return;
108 }
109 printf("=============== RUNNING ANALYSIS IN GRID MODE ================\n");
110 mode = 2;
111 }
112 if(strstr(type,"local") != NULL || mode<0){
113 if(mode != -1){
114 printf("===== CONFLICTING TYPES =====\n");
115 return;
116 }
117 printf("=============== RUNNING ANALYSIS IN LOCAL MODE ================\n");
118 mode = 0;
119 }
120
121 printf("===================================================================\n");
122 printf("===================================================================\n");
123 if (analysisMC) printf(":: use MC TRUE\n");
124 else printf(":: use MC FALSE\n");
125 if (readTR) printf(":: read TR TRUE\n");
126 else printf(":: read TR FALSE\n");
127 if (debug) printf(":: debugging TRUE\n");
128 else printf(":: debugging FALSE\n");
129
130 Char_t taskname[128];
131 Char_t taskname1[128];
132 Char_t taskname2[128];
133
134 switch(task){
135 case 1:
136 sprintf(taskname,"ChFluct");
137 break;
138 case 2:
139 sprintf(taskname,"HighPtDeDx");
140 break;
141 case 3:
142 sprintf(taskname,"HighPtDeDxV0");
143 break;
144 case 4:{
145 sprintf(taskname1,"HighPtDeDx");
146 sprintf(taskname2,"HighPtDeDxV0");
147 }
148 break;
149 default:
150 printf("Unknown task\n");
151 return;
152 }
153
154
155
156 Char_t nameouputfiles[1280]={0};
157 if(runtype ==2){
158 for(Int_t i=0;i<6;++i){
159 //Char_t tmpname[128]={0};
160 sprintf(nameouputfiles,"%s %s_Tree_%1.0f_%1.0f.root",nameouputfiles,taskname,minCent[i],maxCent[i]);
161
162 }
163 }
164 if(runtype ==3){
165 sprintf(nameouputfiles,"%s %s_Tree.root",taskname);
166 }
167 if(task==4){
168
169 if(runtype ==3){
170 sprintf(nameouputfiles,"%s_Tree.root %s_Tree.root",taskname1,taskname2);
171 }
172
173 }
174
175
176
177 cout<<"Files to be stored:"<<nameouputfiles<<endl;
178
179
180 // Load common libraries
181 gSystem->Load("libTree.so");
182 gSystem->Load("libPhysics.so");
183 gSystem->Load("libGeom.so");
184 gSystem->Load("libVMC.so");
185 gSystem->Load("libSTEERBase.so");
186 gSystem->Load("libESD.so");
187 gSystem->Load("libAOD.so");
188 gSystem->Load("libCDB.so");
189 gSystem->Load("libANALYSIS.so");
190 gSystem->Load("libANALYSISalice.so");
191 // tender
192 Bool_t v0tender = kTRUE;
193 if(v0tender) {
af472fff 194 gSystem->Load("libTender.so");
195 gSystem->Load("libTenderSupplies.so");
4ebdd20e 196 }
197
198 gROOT->ProcessLine(Form(".include %s/include", gSystem->ExpandPathName("$ALICE_ROOT")));
199
200
201 cout << "mode " << mode << ", type " << type << endl;
202
203 if (mode == 1){
204 cout << "Connecting to CAF..." << endl;
205 gEnv->SetValue("XSec.GSI.DelegProxy","2");
206
207 //const char* AAF = "pchristi@skaf.saske.sk";
208 const char* AAF = "aortizve@alice-caf.cern.ch";
209
210 if(strstr(type,"reset") != NULL)
211 TProof::Reset(AAF,kFALSE);
212 // TProof::Reset("pchristi@alice-caf.cern.ch",kTRUE);
213 // TProof::Open(AAF);
214 TProof::Open(AAF, "workers=10");
215
216 TList *list = new TList();
217 list->Add(new TNamed("ALIROOT_EXTRA_LIBS", "CDB"));
218
219 gProof->EnablePackage(Form("VO_ALICE@AliRoot::%s",alirootver), list);
220
221 cout << "Connected to " << AAF << endl;
222 }
223
224
225 // Load the analysis macro (old version); should be removed when the library will be decided
226 Char_t loadtask1[128];
227 Char_t loadtask2[128];
228 Char_t loadtask[128];
229
230 if(task==4){
231 sprintf(loadtask1,"AliAnalysisTask%s.cxx+", taskname1);
232 sprintf(loadtask2,"AliAnalysisTask%s.cxx+", taskname2);
233 }else{
234 sprintf(loadtask,"AliAnalysisTask%s.cxx+", taskname);
235 }
236
237 if(mode == 1){ // PROOF
238
239 // switch(task){
240 // case 1: // ch fluct
241 // break;
242 // case 2: // high pt dedx
243 //gProof->Load("DebugClasses.C++g");
244 // break;
245 // case 3: // high pt v0s
246 // gProof->Load("DebugClasses.C++g");
247 // break;
248 // default:
249 // printf("Unknown task\n");
250 // return;
251 // }
252
253 gProof->Load(loadtask);
254 }else{
255
256 switch(task){
257 case 1: // ch fluct
258 break;
259 case 2: // high pt dedx
260 gROOT->LoadMacro("DebugClasses.C++g");
261 break;
262 case 3: // high pt v0s
263 gROOT->LoadMacro("DebugClasses.C++g");
264 break;
265 case 4: // high pt v0s
266 gROOT->LoadMacro("DebugClasses.C++g");
267 break;
268 default:
269 printf("Unknown task\n");
270 return;
271 }
272
273 if(task==4){
274 gROOT->LoadMacro(loadtask1);
275 gROOT->LoadMacro(loadtask2);
276 }else{
277 gROOT->LoadMacro(loadtask);
278 }
279 }
280
281 // Make the analysis manager
282 AliAnalysisManager* mgr = new AliAnalysisManager("PID histos", "testing analysis");
283
284
285 // Dataset
286 switch(mode){
287 case 1: // PROOF
288 TFileCollection* proofColl = gProof->GetDataSet(textFileName);
289 TFileCollection* stagedColl = proofColl->GetStagedSubset();
290 TChain* chain = CreateChainCAF(nFilesMax, stagedColl, treeName);
291// TChain* chain = CreateChainCAF(nFilesMax, textFileName, treeName, analysisMC);
292 break;
293 case 2: // GRID
294 //gSystem->Setenv("alien_CLOSE_SE", "ALICE::GSI::SE2");
295 // gSystem->Setenv("alien_CLOSE_SE", "ALICE::NIHAM::FILE");
296 TGrid::Connect("alien://");
297 //gSystem->Setenv("alien_CLOSE_SE", "ALICE::GSI::SE2");
298 // gSystem->Setenv("alien_CLOSE_SE", "ALICE::NIHAM::FILE");
299
300 Char_t gridmode[64];
301 sprintf(gridmode, "full");
302 if(strstr(type,"term") != NULL)
303 sprintf(gridmode, "terminate");
304 if(strstr(type,"off") != NULL)
305 sprintf(gridmode, "offline");
306 if(strstr(type,"sub") != NULL)
307 sprintf(gridmode, "submit");
308 if(strstr(type,"test") != NULL)
309 sprintf(gridmode, "test");
310
311
312 gROOT->LoadMacro("CreateAlienHandler.C");
313 // AliAnalysisGrid *alienHandler = CreateAlienHandler(nFilesMax, analysisMC, runtype, taskname, gridmode);
314 AliAnalysisGrid *alienHandler = CreateAlienHandler(nFilesMax, analysisMC, esdAna, taskname1, nameouputfiles, gridmode, textFileName, alirootver, task);
315 if (!alienHandler) return;
316
317 // DOES NOT WORK BECAUSE THERE ARE NO GETTERS?
318 // // Here we can add extra files to the plugin
319 // switch(task){
320 // case 1: // ch fluct
321 // break;
322 // case 2: // high pt dedx
323 // alienHandler->SetAnalysisSource(Form("DebugClasses.C %s", alienHandler->GetAnalysisSource()));
324 // alienHandler->SetAdditionalLibs(Form("DebugClasses.C %s", alienHandler->GetAdditionalLibs()));
325 // break;
326 // case 3: // high pt v0s
327 // alienHandler->SetAnalysisSource(Form("DebugClasses.C %s", alienHandler->GetAnalysisSource()));
328 // alienHandler->SetAdditionalLibs(Form("DebugClasses.C %s", alienHandler->GetAdditionalLibs()));
329 // break;
330 // default:
331 // printf("Unknown task\n");
332 // return;
333 // }
334
335 // Connect plugin to the analysis manager
336 mgr->SetGridHandler(alienHandler);
337 break;
338 case 0: // LOCAL
339 // Process data - chain
340 AliXRDPROOFtoolkit tool;
341 TChain* chain = tool.MakeChain(textFileName,treeName, 0, 100);
342 chain->Lookup();
343 break;
344 default:
345 printf("Unknown mode");
346 return;
347 }
348
349 // ESD input handler
350 if(esdAna) {
351
352 AliESDInputHandler *esdHandler = new AliESDInputHandler();
353 mgr->SetInputEventHandler(esdHandler);
354 } else {
355
356 AliAODInputHandler* aodHandler = new AliAODInputHandler();
357 mgr->SetInputEventHandler(aodHandler);
358 }
359
360 // Monte Carlo handler
361 if (analysisMC) {
362 AliMCEventHandler* mcHandler = new AliMCEventHandler();
363 if(esdAna)
364 mgr->SetMCtruthEventHandler(mcHandler);
365 mcHandler->SetReadTR(readTR);
366 }
367
368 // Debug if needed
369 if (debug)
370 mgr->SetDebugLevel(3);
371
372 if(v0tender) {
373 // V0 tender for LHC10c pass 3
374 //========= Add tender to the ANALYSIS manager and set default storage =====
375 AliTender *tender=new AliTender("AnalysisTender");
376 tender->SetCheckEventSelection(kTRUE);
377 tender->SetDefaultCDBStorage("raw://");
378 mgr->AddTask(tender);
379 if (mgr->GetTasks()->First() != (TObject*)tender) {
380 ::Error("When setting the tender to check the event selection, it has to be the first wagon ! Aborting.");
381 return;
382 }
383
384 //========= Attach VZERO supply ======
385 AliVZEROTenderSupply *vzeroSupply=new AliVZEROTenderSupply("VZEROtender");
386 vzeroSupply->SetDebug(kFALSE);
387 tender->AddSupply(vzeroSupply);
388
389 //================================================
390 // data containers
391 //================================================
392
393 // define output containers, please use 'username'_'somename'
394 AliAnalysisDataContainer *coutputtender =
395 mgr->CreateContainer("tender_event", AliESDEvent::Class(),
396 AliAnalysisManager::kExchangeContainer,"default_tender");
397
398 // connect containers
399 mgr->ConnectInput (tender, 0, mgr->GetCommonInputContainer() );
400 mgr->ConnectOutput (tender, 1, coutputtender);
401 }
402
403 // ######### Centrality task ###############
404
405 cout<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"<<endl;
406 cout<<"esdAna="<<esdAna<<" runtype="<<runtype<<endl;
407
408 // ######### PHYSICS SELECTION ###############
409 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
410 AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection();
411 if (analysisMC) {
412 AliPhysicsSelection* physSel = physSelTask->GetPhysicsSelection();
413 physSel->SetAnalyzeMC();
414 }
415
416 if(esdAna && runtype==2) { // only for ESD and PbPb
417
418 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
419 AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();
420 //taskCentrality->SetPass(2);
421 if (analysisMC)
422 taskCentrality->SetMCInput();
423 }
424
425 // ######### PID task ###############
426
427 if(task!=4){
428 gROOT->LoadMacro(Form("AddTask%s.C", taskname));
429 AliAnalysisTask* taskPid = AddTask(analysisMC, taskname, runtype, kTriggerInt, minCent, maxCent);
430 }else{
431 cout<<"%%%%%%%%%%%% flag"<<endl;
432 gROOT->LoadMacro(Form("AddTask%s.C", taskname1));
433 AliAnalysisTask* taskPid = AddTask(analysisMC, taskname1, runtype, kTriggerInt, minCent, maxCent);
434
435 gROOT->LoadMacro(Form("AddTask%s.C", taskname2));
436 AliAnalysisTask* taskPid = AddTask(analysisMC, taskname2, runtype, kTriggerInt, minCent, maxCent);
437 }
438
439
440
441
442 // Run the analysis
443 if (mgr->InitAnalysis()){
444 mgr->PrintStatus();
445 switch(mode){
446 case 1: // PROOF
447 mgr->StartAnalysis("proof",chain);
448 break;
449 case 2: // GRID
450 mgr->StartAnalysis("grid");
451 break;
452 case 0:
453 mgr->StartAnalysis("local",chain);
454 break;
455 default:
456 printf("Unknown mode\n");
457 return;
458 }
459 }
460}
461
462
463//__________________________________________________________
464TChain* CreateChainCAF(Int_t nFilesMax, TFileCollection* coll, char* treeName)
465{
466 TIter iter(coll->GetList());
467
468 TChain* target = new TChain(treeName);
469
470 Int_t nFiles = 0;
471
472 TFileInfo* fileInfo = 0;
473 while ((fileInfo = dynamic_cast<TFileInfo*> (iter())) && (nFiles<nFilesMax || nFilesMax == 0)){
474 if (fileInfo->GetFirstUrl()) {
475 target->Add(fileInfo->GetFirstUrl()->GetUrl());
476 nFiles++;
477 }
478 }
479
480 Printf("Added %d files to chain", target->GetListOfFiles()->GetEntries());
481
482 return target;
483}
484
485
486// //__________________________________________________________
487// TChain* CreateChainCAF(Int_t nFilesMax, const char* label, const char* treeName, Bool_t AnalysisMC)
488// {
489
490// cout << "CreateChainCAF2" << endl;
491
492// TChain* target = new TChain(treeName);
493
494// Int_t nFiles = 0;
495// Char_t fileName[256];
496// sprintf(fileName,"%s.conf", label);
497
498// FILE* file = fopen(fileName,"r");
499// if(!file) {
500// cout << "File " << fileName << " not found!" << endl;
501// return;
502// }
503
504// Char_t dummy[128];
505// Char_t runperiodpattern[128];
506// if(AnalysisMC)
507// sprintf(runperiodpattern,"Run period MC%d: %s", AnalysisMC,"%s %s");
508// else
509// sprintf(runperiodpattern,"Run period: %s","%s %s");
510
511// cout << "Pattern: " << runperiodpattern << endl;
512
513// char runperiod[128], pass[64];
514// while (fgets(dummy,128,file) != NULL) {
515// Printf("line: %s", dummy);
516// Int_t run, a, b;
517// if(sscanf(dummy, runperiodpattern, &runperiod, &pass)){
518// Char_t tmp[128];
519// sscanf(pass,"pass%s",tmp);
520// sprintf(pass,"p%s",tmp);
521// continue;
522// }
523// if(sscanf(dummy,"Run: %d", &run)){
524// Char_t textFileName[256];
525// if(AnalysisMC)
526// sprintf(textFileName,"/alice/sim/%s_%d",runperiod, run, pass);
527// else
528// sprintf(textFileName,"/alice/data/%s_000%d_%s",runperiod, run, pass);
529
530// cout << "Collection: " << textFileName << endl;
531// TFileCollection* proofColl = gProof->GetDataSet(textFileName);
532// TFileCollection* stagedColl = proofColl->GetStagedSubset();
533// TIter iter(proofColl->GetList());
534
535// TFileInfo* fileInfo = 0;
536// while ((fileInfo = dynamic_cast<TFileInfo*> (iter())) && (nFiles<nFilesMax || nFilesMax <= 0)){
537// if (fileInfo->GetFirstUrl()) {
538// Printf("Adding %s", fileInfo->GetFirstUrl()->GetUrl());
539// target->Add(fileInfo->GetFirstUrl()->GetUrl());
540// nFiles++;
541// }
542// }
543
544// continue;
545// }
546// }
547
548
549
550
551// Printf("Added %d files to chain", target->GetListOfFiles()->GetEntries());
552
553// return target;
554// }
555
556//__________________________________________________________
557TChain* CreateChainLocal(Int_t nFilesMax, char* filename, char* treeName)
558{
559 // If file name ends in .root the chain will be created directly from that
560 // fileName, otherwise it will assume that it is a text file and create it
561 // from that.
562 //
563 // nFilesMax is only used for the text files
564 // nFilesMax=0 means add all files
565
566 TChain* chain = new TChain(treeName);
567
568 // Open the input stream
569 ifstream in;
570 in.open(filename);
571
572 Int_t nFiles = 0;
573
574 // Read the input list of files and add them to the chain
575 TString file;
576 while(in.good() && (nFiles<nFilesMax || nFilesMax<=0)) {
577 in >> file;
578 if (!file.Contains("root"))
579 continue; // protection
580
581 nFiles++;
582 chain->Add(file.Data());
583 }
584
585 in.close();
586
587 return chain;
588}
589
590
591
592
593/*
594
595 gEnv->SetValue("XSec.GSI.DelegProxy","2");
596 const char* AAF = "pchristi@alice-caf.cern.ch";
597 TProof::Open(AAF, "workers=10");
598 TList *list = new TList();
599 list->Add(new TNamed("ALIROOT_EXTRA_LIBS", "CDB"));
600 gProof->EnablePackage(Form("VO_ALICE@AliRoot::%s",alirootver), list);
601 const char* alirootver = "v4-21-20-AN";
602 gProof->EnablePackage(Form("VO_ALICE@AliRoot::%s",alirootver), list);
603 gProof->Load("AliAnalysisTaskHighPtDeDx.cxx++g")
604 AliAnalysisManager* mgr = new AliAnalysisManager("PID histos", "testing analysis");
605 TFileCollection* proofColl = gProof->GetDataSet("/alice/data/LHC10h_000137366_p2")
606 TFileCollection* stagedColl = proofColl->GetStagedSubset();
607 .L runAAF.C
608 TChain* chain = CreateChainCAF(10, stagedColl, "esdTree")
609 gSystem->Load("libTree.so");
610 gSystem->Load("libPhysics.so");
611 gSystem->Load("libGeom.so");
612 gSystem->Load("libVMC.so");
613 gSystem->Load("libSTEERBase.so");
614 gSystem->Load("libESD.so");
615 gSystem->Load("libAOD.so");
616 gSystem->Load("libCDB.so");
617 gSystem->Load("libANALYSIS.so");
618 gSystem->Load("libANALYSISalice.so");
619 gROOT->ProcessLine(Form(".include %s/include", gSystem->ExpandPathName("$ALICE_ROOT")));
620 AliAnalysisManager* mgr = new AliAnalysisManager("PID histos", "testing analysis");
621 AliESDInputHandler *esdHandler = new AliESDInputHandler();
622 mgr->SetInputEventHandler(esdHandler);
623 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
624 AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();
625
626 // ######### PID task ###############
627 gROOT->LoadMacro("AddTaskHighPtDeDx.C");
628 AliAnalysisTask* taskPid = AddTask(kFALSE, "testTask");
629
630
631 // ######### PHYSICS SELECTION ###############
632 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
633 AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection();
634 mgr->InitAnalysis()
635 mgr->PrintStatus();
636 mgr->StartAnalysis("proof",chain);
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655 */