Fix Coverity 24835
[u/mrichter/AliRoot.git] / PWG / DevNanoAOD / AddTaskSpectraAllChNanoAOD.C
1 AliAnalysisTaskSpectraAllChNanoAOD* AddTaskSpectraAllChAOD(
2                                                        Bool_t mc=kFALSE,
3                                                        Double_t CentCutMin=0,
4                                                        Double_t CentCutMax=100,
5                                                        Double_t QvecCutMin=0,
6                                                        Double_t QvecCutMax=100,
7                                                        Double_t EtaMin=-0.8,
8                                                        Double_t EtaMax=0.8,
9                                                        Double_t pt=50.,
10                                                        Double_t ptTofMatch=.6,
11                                                        UInt_t trkbit=1,
12                                                        Double_t DCA=100000,
13                                                        UInt_t minNclsTPC=70,
14                                                        Double_t nsigmacut=5.,
15                                                        Int_t PIDtype=3,
16                                                        TString opt=""){
17   
18   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
19   if (!mgr) 
20     {
21       ::Error("AddAliAnalysisTaskSpectraAllChAOD", "No analysis manager to connect to.");
22       return NULL;
23     }   
24   
25   // Check the analysis type using the event handlers connected to the analysis manager.
26   //==============================================================================
27   if (!mgr->GetInputEventHandler()) 
28     {
29       ::Error("AliAnalysisTaskSpectraAllChAOD", "This task requires an input event handler");
30       return NULL;
31     }   
32   
33   TString type = mgr->GetInputEventHandler()->GetDataType(); // can be "ESD" or "AOD"
34   if(type.Contains("ESD"))
35     {
36       ::Error("AliAnalysisTaskSpectraAllChAOD", "This task requires to run on AOD");
37       return NULL;
38     }
39   
40   AliSpectraAODTrackCuts  * trcuts = new AliSpectraAODTrackCuts(Form("TrackCuts%s",opt.Data()));  
41   trcuts->SetDCA(DCA);
42   trcuts->SetTrackBits(trkbit);
43   trcuts->SetPt(pt);
44   trcuts->SetPtTOFMatching(ptTofMatch);   
45   trcuts->SetEta(EtaMin,EtaMax);
46   trcuts->SetMinTPCcls(minNclsTPC);
47   trcuts->PrintCuts();
48   
49   AliSpectraAODEventCuts * evcuts = new AliSpectraAODEventCuts(Form("EventCuts%s",opt.Data()));
50   evcuts->SetQVectorCut(QvecCutMin,QvecCutMax);
51   evcuts->SetCentralityCutMax(CentCutMax);  
52   evcuts->SetCentralityCutMin(CentCutMin);
53   if(mc==1)evcuts->SetIsMC(kTRUE);
54   evcuts->PrintCuts();
55   
56   AliHelperPID *pid=new AliHelperPID();
57   pid->SetName(Form("HelperPID%s",opt.Data()));
58   pid->SetNSigmaCut(nsigmacut);
59   pid->SetPIDType(PIDtype);
60   if(PIDtype==3){
61     AliPIDCombined *pidc=new AliPIDCombined();
62     pidc->SetDefaultTPCPriors();
63     pid->SetPIDCombined(pidc);
64   }
65   
66   AliAnalysisTaskSpectraAllChNanoAOD *task = new AliAnalysisTaskSpectraAllChNanoAOD(Form("TaskAODSpectraCent%.0fto%.0f_QVec%.1fto%.1f_Eta%.1fto%.1f_TrBit%d%s", 
67                                                                                          CentCutMin,
68                                                                                          CentCutMax,
69                                                                                          QvecCutMin,
70                                                                                          QvecCutMax,
71                                                                                          EtaMin,
72                                                                                          EtaMax,
73                                                                                          trkbit,
74                                                                                          opt.Data()));
75   task->SetEventCuts(evcuts);
76   task->SetTrackCuts(trcuts);
77   task->SetHelperPID(pid);
78   if(mc==1)task->SetIsMC(kTRUE);
79   
80   TString outputFileName = AliAnalysisManager::GetCommonFileName();
81   
82   TString typeofdata=mc?"MC":"Data";
83   
84   outputFileName += Form(":SpectraESE_%s%s",typeofdata.Data(),opt.Data());
85   
86   cout<<"outputFileName:  "<<outputFileName<<endl;
87   AliAnalysisDataContainer *cinput = mgr->GetCommonInputContainer();      
88   AliAnalysisDataContainer *coutputpt1 = mgr->CreateContainer(Form("chist%s",opt.Data()),                      TList::Class(),     AliAnalysisManager::kOutputContainer,outputFileName);
89   AliAnalysisDataContainer *coutputpt2 = mgr->CreateContainer(Form("cvcut%s",opt.Data()), AliSpectraAODEventCuts::Class(),     AliAnalysisManager::kOutputContainer,outputFileName);
90   AliAnalysisDataContainer *coutputpt3 = mgr->CreateContainer(Form("ctcut%s",opt.Data()), AliSpectraAODTrackCuts::Class(),     AliAnalysisManager::kOutputContainer, outputFileName);
91   AliAnalysisDataContainer *coutputpt4 = mgr->CreateContainer(Form("cpid%s",opt.Data()),               AliHelperPID::Class(),     AliAnalysisManager::kOutputContainer, outputFileName);
92   mgr->AddTask(task);
93   
94   mgr->ConnectInput(task, 0, cinput);
95   mgr->ConnectOutput(task, 1, coutputpt1);
96   mgr->ConnectOutput(task, 2, coutputpt2);
97   mgr->ConnectOutput(task, 3, coutputpt3);
98   mgr->ConnectOutput(task, 4, coutputpt4);
99   
100   return task;
101 }