Migrating PWG2/SPECTRA/Fit to new PWG structure
[u/mrichter/AliRoot.git] / PWG0 / multPbPb / AddTaskMultPbPbTracksAllCentrality.C
1 AliAnalysisTaskMultPbTracks ** AddTaskMultPbPbTracksAllCentrality(TString outfilename, AliESDtrackCuts * esdTrackCuts = 0, AliAnalysisMultPbCentralitySelector * centr, Int_t ncentr, Float_t * minCentr, Float_t *maxCentr)
2 {
3   // TODO: add some parameters to set the centrality for this task, and maybe the name of the task
4   // TODO: shall I use the same file and different dirs for the different centralities?
5
6   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
7   if (!mgr) {
8     ::Error("AddTaskPhysicsSelection", "No analysis manager to connect to.");
9     return NULL;
10   }  
11   
12   // Check the analysis type using the event handlers connected to the analysis manager.
13   //==============================================================================
14   if (!mgr->GetInputEventHandler()) {
15     ::Error("AddTaskPhysicsSelection", "This task requires an input event handler");
16     return NULL;
17   }
18   TString inputDataType = mgr->GetInputEventHandler()->GetDataType(); // can be "ESD" or "AOD"
19   
20   if (inputDataType != "ESD") {
21     Printf("ERROR! This task can only run on ESDs!");
22   }
23
24   // Configure analysis
25   //===========================================================================
26     
27     
28   cout << "Booking " << ncentr << " Tasks" << endl;
29   AliAnalysisTaskMultPbTracks ** tasks = new AliAnalysisTaskMultPbTracks*[ncentr];
30   
31   for(Int_t icentr = 0; icentr < ncentr; icentr++){  
32
33     tasks[icentr] = new AliAnalysisTaskMultPbTracks(Form("TaskMultPbTracks_%d",icentr));
34     mgr->AddTask(tasks[icentr]);
35   
36     // Set Cuts
37     if (!esdTrackCuts)
38       {
39         printf("ERROR: esdTrackCuts could not be created\n");
40         return;
41       }  
42     tasks[icentr]->SetTrackCuts(esdTrackCuts);
43
44     // set centrality
45     AliAnalysisMultPbCentralitySelector * centrBin = (AliAnalysisMultPbCentralitySelector*) centr->Clone();
46     centrBin->SetMultRange(minCentr[icentr],maxCentr[icentr]);
47     tasks[icentr]->SetCentralitySelector(centrBin);
48
49     // TODO:
50     // IO into folders in a file?
51
52     // Set I/O
53     TString outfilenameCentr = outfilename;
54     outfilenameCentr.ReplaceAll(".root",Form("_%2.2d.root",icentr));
55     AliAnalysisDataContainer *cinput0 = mgr->GetCommonInputContainer();
56     AliAnalysisDataContainer *coutput1 = mgr->CreateContainer(Form("cmultPbTracksOutHM_%d",icentr),
57                                                               AliAnalysisMultPbTrackHistoManager::Class(),
58                                                               AliAnalysisManager::kOutputContainer,
59                                                               outfilenameCentr.Data());
60     AliAnalysisDataContainer *coutput2 = mgr->CreateContainer(Form("cmultPbTracksOutCT_%d",icentr),
61                                                               AliESDtrackCuts::Class(),
62                                                               AliAnalysisManager::kOutputContainer,
63                                                               outfilenameCentr.Data());
64     AliAnalysisDataContainer *coutput3 = mgr->CreateContainer(Form("cmultPbTracksOutCM_%d",icentr),
65                                                               AliAnalysisMultPbCentralitySelector::Class(),
66                                                               AliAnalysisManager::kOutputContainer,
67                                                               outfilenameCentr.Data());
68
69     mgr->ConnectInput(tasks[icentr], 0, mgr->GetCommonInputContainer());
70     mgr->ConnectOutput(tasks[icentr],1,coutput1);
71     mgr->ConnectOutput(tasks[icentr],2,coutput2);
72     mgr->ConnectOutput(tasks[icentr],3,coutput3);
73
74   }
75   return tasks;
76 }