4 #include <TInterpreter.h>
10 #include "AliFMDAnalysisTaskBackgroundCorrection.h"
11 #include "AliAnalysisManager.h"
12 #include "AliESDFMD.h"
13 #include "AliESDEvent.h"
14 #include "AliAODEvent.h"
15 #include "AliAODHandler.h"
16 #include "AliMCEventHandler.h"
19 #include "AliESDVertex.h"
21 #include "AliFMDAnaParameters.h"
22 #include "AliFMDGeometry.h"
24 ClassImp(AliFMDAnalysisTaskBackgroundCorrection)
27 AliFMDAnalysisTaskBackgroundCorrection::AliFMDAnalysisTaskBackgroundCorrection()
36 fOutputVertexString(0)
38 // Default constructor
39 DefineInput (0, TList::Class());
40 DefineOutput(0, TList::Class());
41 DefineOutput(1, TObjString::Class());
43 //_____________________________________________________________________
44 AliFMDAnalysisTaskBackgroundCorrection::AliFMDAnalysisTaskBackgroundCorrection(const char* name, Bool_t SE):
45 AliAnalysisTask(name, "Density"),
54 fOutputVertexString(0)
58 DefineInput (0, TList::Class());
59 DefineOutput(0, TList::Class());
60 DefineOutput(1, TObjString::Class());
63 //_____________________________________________________________________
64 void AliFMDAnalysisTaskBackgroundCorrection::CreateOutputObjects()
66 AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
68 fArray.SetName("FMD");
72 fOutputList = new TList();
73 fOutputList->SetName("BackgroundCorrectedPerEvent");
78 Int_t nVtxbins = pars->GetNvtxBins();
80 for(Int_t det =1; det<=3;det++)
82 TObjArray* detArray = new TObjArray();
83 detArray->SetName(Form("FMD%d",det));
84 fArray.AddAtAndExpand(detArray,det);
85 Int_t nRings = (det==1 ? 1 : 2);
86 for(Int_t ring = 0;ring<nRings;ring++)
88 Char_t ringChar = (ring == 0 ? 'I' : 'O');
89 Int_t nSec = (ring == 0 ? 20 : 40);
91 TObjArray* vtxArray = new TObjArray();
92 vtxArray->SetName(Form("FMD%d%c",det,ringChar));
93 detArray->AddAtAndExpand(vtxArray,ring);
94 for(Int_t i = 0; i< nVtxbins; i++) {
95 TH2F* hBg = pars->GetBackgroundCorrection(det, ringChar, i);
96 hMult = new TH2F(Form("mult_FMD%d%c_vtxbin%d",det,ringChar,i),Form("mult_FMD%d%c_vtxbin%d",det,ringChar,i),
98 hBg->GetXaxis()->GetXmin(),
99 hBg->GetXaxis()->GetXmax(),
100 nSec, 0, 2*TMath::Pi());
102 fOutputList->Add(hMult);
103 hHits = new TH2F(Form("hits_FMD%d%c_vtxbin%d",det,ringChar,i),Form("hits_FMD%d%c_vtxbin%d",det,ringChar,i),
105 hBg->GetXaxis()->GetXmin(),
106 hBg->GetXaxis()->GetXmax(),
107 nSec, 0, 2*TMath::Pi());
110 fOutputList->Add(hHits);
111 vtxArray->AddAtAndExpand(hMult,i);
117 fOutputVertexString = new TObjString();
119 fOutputList->Add(fOutputVertexString);
124 //_____________________________________________________________________
125 void AliFMDAnalysisTaskBackgroundCorrection::ConnectInputData(Option_t */*option*/)
128 fInputList = (TList*)GetInputData(0);
132 //_____________________________________________________________________
133 void AliFMDAnalysisTaskBackgroundCorrection::Exec(Option_t */*option*/)
135 AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
137 fInputArray = (TObjArray*)fInputList->At(0);
138 fVertexString = (TObjString*)fInputList->At(1);
141 Int_t vtxbin = fVertexString->GetString().Atoi();
142 fOutputVertexString->SetString(Form("%d",vtxbin));
144 //fNevents.operator[](vtxbin)++;
145 fNevents.Fill(vtxbin);
148 for(UShort_t det=1;det<=3;det++) {
149 TObjArray* detArray = (TObjArray*)fArray.At(det);
150 Int_t nRings = (det==1 ? 1 : 2);
151 for (UShort_t ir = 0; ir < nRings; ir++) {
152 TObjArray* vtxArray = (TObjArray*)detArray->At(ir);
154 TH2F* hMult = (TH2F*)vtxArray->At(vtxbin);
162 for(UShort_t det=1;det<=3;det++) {
163 TObjArray* detInputArray = (TObjArray*)fInputArray->At(det);
164 TObjArray* detArray = (TObjArray*)fArray.At(det);
165 Int_t nRings = (det==1 ? 1 : 2);
166 for (UShort_t ir = 0; ir < nRings; ir++) {
167 Char_t ringChar = (ir == 0 ? 'I' : 'O');
168 TObjArray* vtxInputArray = (TObjArray*)detInputArray->At(ir);
169 TObjArray* vtxArray = (TObjArray*)detArray->At(ir);
170 TH2F* hMultTotal = (TH2F*)vtxArray->At(vtxbin);
171 TH2F* hMultInput = (TH2F*)vtxInputArray->At(vtxbin);
172 TH2F* hHits = (TH2F*)fOutputList->FindObject(Form("hits_FMD%d%c_vtxbin%d",det,ringChar,vtxbin));
174 hHits->Add(hMultInput);
175 TH2F* hBg = pars->GetBackgroundCorrection(det, ringChar, vtxbin);
177 TH2F* hTmp = (TH2F*)hMultInput->Clone("hMult_from_event");
179 hTmp->Divide(hTmp,hBg,1,1);//,"B");
180 /*for(Int_t i = 1; i<=hTmp->GetNbinsX();i++) {
181 for(Int_t j = 1; j<=hTmp->GetNbinsY();j++) {
182 Float_t mult = hTmp->GetBinContent(i,j);
183 if(mult == 0) continue;
184 Float_t correction = hBg->GetBinContent(i,j);
186 Float_t multcor = mult;
188 multcor = multcor/correction;
190 std::cout<<"Warning! No correction for bin "<<i<<" , "<<j<<std::endl;
192 hTmp->SetBinContent(i,j,multcor);
195 hMultTotal->Add(hTmp);
201 PostData(0, fOutputList);
202 PostData(1, fOutputVertexString);
206 //_____________________________________________________________________
207 void AliFMDAnalysisTaskBackgroundCorrection::Terminate(Option_t */*option*/) {
210 AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
212 Int_t nVtxbins = pars->GetNvtxBins();
214 for(UShort_t det=1;det<=3;det++) {
215 TObjArray* detArray = (TObjArray*)fArray.At(det);
216 Int_t nRings = (det==1 ? 1 : 2);
217 for (UShort_t ir = 0; ir < nRings; ir++) {
218 TObjArray* vtxArray = (TObjArray*)detArray->At(ir);
219 for(Int_t i =0; i<nVtxbins; i++) {
220 TH2F* hMultTotal = (TH2F*)vtxArray->At(i);
222 hMultTotal->Scale(1/(Float_t)fNevents.At(i));
228 //_____________________________________________________________________