afdd9713ae4e579cd30a63658913e92ca6b966bf
[u/mrichter/AliRoot.git] / PWGGA / GammaConv / macros / AddTask_Resolution.C
1 void AddTask_Resolution(        TString V0ReaderEventCutNumber  = "8000000",
2                                                         TString V0ReaderPhotonCutNumber = "060084001001500000000",
3                                                         TString TaskEventCutnumber              = "8000011",
4                                                         TString TaskPhotonCutnumber     = "092092170008260400000",
5                                                         Bool_t IsMC = kTRUE, 
6                                                         Int_t IsHeavyIon = 0, 
7                                                         TString cutnumberAODBranch = "0000000060084001001500000",
8                                                         Bool_t doEtaShiftV0Reader = kFALSE 
9                        ){
10         
11         //get the current analysis manager
12         // ================= Load Librariers =================================
13         gSystem->Load("libCore.so");  
14         gSystem->Load("libTree.so");
15         gSystem->Load("libGeom.so");
16         gSystem->Load("libVMC.so");
17         gSystem->Load("libPhysics.so");
18         gSystem->Load("libMinuit");
19         gSystem->Load("libSTEERBase");
20         gSystem->Load("libESD");
21         gSystem->Load("libAOD");
22         gSystem->Load("libANALYSIS");
23         gSystem->Load("libANALYSISalice");  
24         gSystem->Load("libPWGGAGammaConv.so");
25         gSystem->Load("libCDB.so");
26         gSystem->Load("libSTEER.so");
27         gSystem->Load("libSTEERBase.so");
28         gSystem->Load("libTENDER.so");
29         gSystem->Load("libTENDERSupplies.so");
30                 
31         // ================== GetAnalysisManager ===============================
32         AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
33         if (!mgr) {
34                 Error(Form("AddTask_GammaConvV1_%i",trainConfig), "No analysis manager found.");
35                 return ;
36         }
37
38         // ================== GetInputEventHandler =============================
39         AliVEventHandler *inputHandler=mgr->GetInputEventHandler();
40         
41         //========= Add PID Reponse to ANALYSIS manager ====
42         if(!(AliPIDResponse*)mgr->GetTask("PIDResponseTask")){
43                 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDResponse.C");
44                 AddTaskPIDResponse(isMC);
45         }
46
47         AliAnalysisDataContainer *cinput = mgr->GetCommonInputContainer();
48         if( !(AliV0ReaderV1*)mgr->GetTask("V0ReaderV1") ){
49                 AliV0ReaderV1 *fV0ReaderV1 = new AliV0ReaderV1("V0ReaderV1");
50                 
51                 fV0ReaderV1->SetUseOwnXYZCalculation(kTRUE);
52                 fV0ReaderV1->SetCreateAODs(kFALSE);// AOD Output
53                 fV0ReaderV1->SetUseAODConversionPhoton(kTRUE);
54
55                 if (!mgr) {
56                         Error("AddTask_V0ReaderV1", "No analysis manager found.");
57                         return;
58                 }
59
60                 AliConvEventCuts *fEventCuts=NULL;
61                 if(V0ReaderEventCutNumber!=""){
62                         fEventCuts= new AliConvEventCuts(V0ReaderEventCutNumber.Data(),V0ReaderEventCutNumber.Data());
63                         fEventCuts->SetPreSelectionCutFlag(kTRUE);
64                         if(fEventCuts->InitializeCutsFromCutString(V0ReaderEventCutNumber.Data())){
65                                 fV0ReaderV1->SetEventCuts(fEventCuts);
66                                 fEventCuts->SetFillCutHistograms("",kTRUE);
67                                 if (IsHeavyIon==2){
68                                         fEventCuts->SelectCollisionCandidates(AliVEvent::kINT7);
69                                         fEventCuts->DoEtaShift(doEtaShiftV0Reader);
70                                 }
71                         }
72                 }
73
74                 // Set AnalysisCut Number
75                 AliConversionPhotonCuts *fCuts=NULL;
76                 if(V0ReaderPhotonCutNumber!=""){
77                         fCuts= new AliConversionPhotonCuts(V0ReaderPhotonCutNumber.Data(),V0ReaderPhotonCutNumber.Data());
78                         fCuts->SetPreSelectionCutFlag(kTRUE);
79                         fCuts->SetIsHeavyIon(IsHeavyIon);
80                         if(fCuts->InitializeCutsFromCutString(V0ReaderPhotonCutNumber.Data())){
81                                 fV0ReaderV1->SetConversionCuts(fCuts);
82                                 fCuts->SetFillCutHistograms("",kTRUE);
83                         }
84                 }
85                 
86                 
87                 if(inputHandler->IsA()==AliAODInputHandler::Class()){
88                         // AOD mode
89                         fV0ReaderV1->SetDeltaAODBranchName(Form("GammaConv_%s_gamma",cutnumberAODBranch.Data()));
90                 }
91                 fV0ReaderV1->Init();
92
93                 AliLog::SetGlobalLogLevel(AliLog::kInfo);
94
95                 //connect input V0Reader
96                 mgr->AddTask(fV0ReaderV1);
97                 mgr->ConnectInput(fV0ReaderV1,0,cinput);
98
99         } else {
100                 Error("AddTask_V0ReaderV1", "Cannot execute AddTask, V0ReaderV1 already exists.");
101         }   
102
103         AliConvEventCuts *analysisEventCuts = new AliConvEventCuts();
104         analysisEventCuts->InitializeCutsFromCutString(TaskEventCutnumber.Data());
105         analysisEventCuts->SetFillCutHistograms("",kFALSE);
106
107         AliConversionPhotonCuts *analysisCuts = new AliConversionPhotonCuts();
108         analysisCuts->InitializeCutsFromCutString(TaskPhotonCutnumber.Data());
109         analysisCuts->SetFillCutHistograms("",kFALSE);
110
111         AliAnalysisTaskResolution *fResolution= new AliAnalysisTaskResolution(Form("%s_%s_Resolution",(analysisEventCuts->GetCutNumber()).Data(), (analysisCuts->GetCutNumber()).Data()));
112         fResolution->SetEventCuts(analysisEventCuts,IsHeavyIon);        
113         fResolution->SetConversionCuts(analysisCuts,IsHeavyIon);
114         fResolution->SetIsMC(IsMC);
115         mgr->AddTask(fResolution);
116         
117         AliAnalysisDataContainer *coutput1 =
118         mgr->CreateContainer(Form("GammaConvResolution_%s_%s", TaskEventCutnumber.Data(), TaskPhotonCutnumber.Data()), TList::Class(),
119                                                 AliAnalysisManager::kOutputContainer, Form("GammaConv_Resolution_%s_%s.root", TaskEventCutnumber.Data(), TaskPhotonCutnumber.Data()));
120
121         AliAnalysisDataContainer *cinput1  = mgr->GetCommonInputContainer();
122         mgr->ConnectInput(fResolution,  0, cinput1 );
123         mgr->ConnectOutput (fResolution,  1, coutput1);
124    //connect containers
125         return;
126 }
127