5d7649c2207a8fd72b4bf9932a163af308837699
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis / AliFMDAnalysisTaskSE.cxx
1 #include "AliFMDAnalysisTaskSE.h"
2 #include "AliESDEvent.h"
3 #include "iostream"
4 #include "AliESDFMD.h"
5 #include "AliMCEventHandler.h"
6 #include "AliAnalysisManager.h"
7 #include "AliFMDAnaParameters.h"
8 #include "AliLog.h"
9 #include "AliFMDDndeta.h"
10 #include "TDirectory.h"
11 #include "TProfile2D.h"
12 ClassImp(AliFMDAnalysisTaskSE)
13 //
14 // This task controls the running of the FMD analysis. The current version is made for 
15 // dN/deta analysis but multiplicity and correlation tasks will be added here as well.
16 //
17 // To get the dN/detadphi per selected event as a TH2F* object connect to the 
18 // output list of this task in the analysis framework and do
19 //
20 // TH2F* hFMDdNdetadphi = (TH2F*)list->FindObject("dNdetadphiHistogramTrVtx");
21 //_____________________________________________________________________
22 AliFMDAnalysisTaskSE::AliFMDAnalysisTaskSE():
23 AliAnalysisTaskSE(),
24   fListOfHistos(0),
25   fSharing("Sharing",kFALSE),
26   fDensity("Density",kFALSE),
27   fBackground("BackgroundCorrected",kFALSE),
28   fDndeta("dNdeta",kFALSE), 
29   fBFCorrelation("BFCorrelation",kFALSE), 
30   fParams(0)
31 {
32   // Default constructor
33 }
34 //_____________________________________________________________________
35 AliFMDAnalysisTaskSE::AliFMDAnalysisTaskSE(const char* name):
36   AliAnalysisTaskSE(name),
37   fListOfHistos(0),
38   fSharing("Sharing",kFALSE),
39   fDensity("Density",kFALSE),
40   fBackground("BackgroundCorrected",kFALSE),
41   fDndeta("dNdeta",kFALSE), 
42   fBFCorrelation("BFCorrelation",kFALSE), 
43   fParams(0)
44 {
45   SetParams(AliFMDAnaParameters::Instance());
46   DefineOutput(1, TList::Class());
47   // DefineOutput(2, TH2F::Class());
48 }
49 //_____________________________________________________________________
50 void AliFMDAnalysisTaskSE::UserCreateOutputObjects()
51 {
52 // Create the output containers
53 //
54   fListOfHistos = new TList();
55   
56   AliESDFMD* fmd = new AliESDFMD();
57   AliESDVertex* vertex = new AliESDVertex();
58   
59   TList* densitylist = new TList();
60   
61   TList* bgcorlist = new TList();
62   
63   fSharing.SetFMDData(fmd);
64   fSharing.SetVertex(vertex);
65   fSharing.SetOutputList(fListOfHistos);
66   
67   fDensity.Init();
68   fDensity.SetOutputList(densitylist);
69   fDensity.SetInputESDFMD(fmd) ;
70   fDensity.SetInputVertex(vertex);
71   
72   fBackground.SetInputList(densitylist);
73   fBackground.SetOutputList(bgcorlist);
74   fBackground.SetHitList(fListOfHistos);
75
76   fDndeta.SetInputList(bgcorlist); 
77   fDndeta.SetOutputList(fListOfHistos); 
78   fBFCorrelation.SetInputList(bgcorlist); 
79   fBFCorrelation.SetOutputList(fListOfHistos); 
80   
81   fSharing.CreateOutputObjects();
82   fDensity.CreateOutputObjects();
83   fBackground.CreateOutputObjects();
84   fDndeta.CreateOutputObjects();
85   fBFCorrelation.CreateOutputObjects();
86  
87   
88   PostData(1, fListOfHistos);
89   
90 }
91 //_____________________________________________________________________
92 void AliFMDAnalysisTaskSE::Init()
93 {
94   std::cout<<"Init"<<std::endl;
95 }
96 //_____________________________________________________________________
97 void AliFMDAnalysisTaskSE::UserExec(Option_t */*option*/)
98 {
99   // Execute analysis for current event
100   //
101   
102   AliESDEvent* fESD = (AliESDEvent*)InputEvent();
103   
104   //std::cout<<fESD->GetBeamEnergy()<<"   "<<fESD->GetBeamType()<<"    "<<fESD->GetCurrentL3()<<std::endl;
105   AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
106   
107   pars->SetTriggerStatus(fESD);
108   fSharing.SetInputESD(fESD);
109   
110   fSharing.Exec("");
111   if(fSharing.GetEventStatus()) {
112     fDensity.Exec("");
113     if(fDensity.GetEventStatus()) {
114       fBackground.Exec("");  
115       fDndeta.Exec("");
116       //      fBFCorrelation.Exec("");
117     }
118     else return;
119   }
120   else return;
121   
122  
123   PostData(1, fListOfHistos);
124      
125 }
126 //_____________________________________________________________________
127 void AliFMDAnalysisTaskSE::Terminate(Option_t */*option*/)
128 {
129   
130   TList* outputList = (TList*)GetOutputData(1);
131   AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
132   
133   if(outputList) {
134     fSharing.SetOutputList(outputList);
135     fBackground.SetHitList(outputList);
136     fDndeta.SetOutputList(outputList); 
137     //fBFCorrelation.SetOutputList(outputList); 
138     fSharing.Terminate("");
139     fBackground.Terminate("");
140     if(fSharing.GetVtxEfficiencyFromData() > 0)
141       fDndeta.SetVtxEfficiency(fSharing.GetVtxEfficiencyFromData());
142     else
143       fDndeta.SetVtxEfficiency(pars->GetVtxSelectionEffFromMC());
144     std::cout<<fSharing.GetNSDVtxEfficiencyFromData()<<"   "<<fSharing.GetVtxEfficiencyFromData()<<"   "<<pars->GetVtxSelectionEffFromMC()<<std::endl;
145     
146     if(fSharing.GetNSDVtxEfficiencyFromData() > 0)
147       fDndeta.SetVtxEfficiencyNSD(fSharing.GetNSDVtxEfficiencyFromData());
148     else
149       fDndeta.SetVtxEfficiencyNSD(pars->GetVtxSelectionEffFromMC());
150     
151     fDndeta.Terminate("");
152     //fBFCorrelation.Terminate("");
153     
154     AliFMDDndeta t;
155     t.SetNbinsToCut(2);
156     t.Init(outputList);
157     t.GenerateMult(AliFMDDndeta::kMult);
158     
159     TList* dNdetalist = t.GetMultList(AliFMDDndeta::kMult);
160     TList* cloneList = (TList*)dNdetalist->Clone("dNdeta");
161     cloneList->SetName("dNdeta");
162     outputList->Add(cloneList);
163     
164     t.GenerateMult(AliFMDDndeta::kMultTrVtx);
165     TList* dNdetalist2 = t.GetMultList(AliFMDDndeta::kMultTrVtx);
166     TList* cloneList2 = (TList*)dNdetalist2->Clone("dNdetaTrVtx");
167     cloneList2->SetName("dNdetaTrVtx");
168     outputList->Add(cloneList2);
169   
170     t.GenerateMult(AliFMDDndeta::kHits);
171     TList* dNdetalist3 = t.GetMultList(AliFMDDndeta::kHits);
172     TList* cloneList3 = (TList*)dNdetalist3->Clone("Hits");
173     cloneList3->SetName("Hits");
174     outputList->Add(cloneList3);
175     
176     t.GenerateMult(AliFMDDndeta::kHitsTrVtx);
177     TList* dNdetalist4 = t.GetMultList(AliFMDDndeta::kHits);
178     TList* cloneList4 = (TList*)dNdetalist4->Clone("HitsTrVtx");
179     cloneList4->SetName("HitsTrVtx");
180     outputList->Add(cloneList4);
181     
182     t.GenerateMult(AliFMDDndeta::kMultNSD);
183     TList* dNdetalist5 = t.GetMultList(AliFMDDndeta::kMultNSD);
184     TList* cloneList5 = (TList*)dNdetalist5->Clone("MultNSD");
185     cloneList5->SetName("MultNSD");
186     outputList->Add(cloneList5);
187     
188     // TFile file("fmd_ana_histos_tmp.root","RECREATE");
189     //  fListOfHistos->Write();
190     // file.Close();
191   }
192   else
193     AliWarning("no merged output from manager");
194   
195   
196 }
197
198 //_____________________________________________________________________
199 void AliFMDAnalysisTaskSE::Print(Option_t* option) const
200 {
201   AliInfo(Form("FMD Single Event Analysis Task\n"
202                "Parameters set to %p", fParams));
203   TString opt(option);
204   opt.ToLower();
205   if (opt.Contains("s")) { 
206     fSharing.Print(option);     
207     fDensity.Print(option);     
208     fBackground.Print(option);  
209     fDndeta.Print(option); 
210     fBFCorrelation.Print(option); 
211   }
212   if (opt.Contains("p") && fParams) 
213     fParams->Print(option);      
214 }
215
216 //_____________________________________________________________________
217 //
218 // EOF
219 //