]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/analysis/AliFMDAnalysisTaskBackgroundCorrection.cxx
This is rather large upgrade of the analysis. The sharing correction has been improve...
[u/mrichter/AliRoot.git] / FMD / analysis / AliFMDAnalysisTaskBackgroundCorrection.cxx
1  
2 #include <TROOT.h>
3 #include <TSystem.h>
4 #include <TInterpreter.h>
5 #include <TChain.h>
6 #include <TFile.h>
7 #include <TList.h>
8 #include <iostream>
9 #include "TH2F.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"
17 #include "AliStack.h"
18 #include "AliLog.h"
19 #include "AliESDVertex.h"
20 #include "TMath.h"
21 #include "AliFMDAnaParameters.h"
22 #include "AliFMDGeometry.h"
23
24 ClassImp(AliFMDAnalysisTaskBackgroundCorrection)
25
26
27 AliFMDAnalysisTaskBackgroundCorrection::AliFMDAnalysisTaskBackgroundCorrection()
28 : fDebug(0),
29   fOutputList(0),
30   fInputList(0),
31   fArray(0),
32   fInputArray(0),
33   fVertexString(0x0),
34   fNevents(),
35   fStandalone(kTRUE),
36   fOutputVertexString(0)
37 {
38   // Default constructor
39   DefineInput (0, TList::Class());
40   DefineOutput(0, TList::Class());
41   DefineOutput(1, TObjString::Class());
42 }
43 //_____________________________________________________________________
44 AliFMDAnalysisTaskBackgroundCorrection::AliFMDAnalysisTaskBackgroundCorrection(const char* name, Bool_t SE):
45     AliAnalysisTask(name, "Density"),
46     fDebug(0),
47     fOutputList(0),
48     fInputList(0),
49     fArray(),
50     fInputArray(0),
51     fVertexString(0x0),
52     fNevents(),
53     fStandalone(kTRUE),
54     fOutputVertexString(0)
55 {
56   fStandalone = SE;
57   if(fStandalone) {
58     DefineInput (0, TList::Class());
59     DefineOutput(0, TList::Class());
60     DefineOutput(1, TObjString::Class());
61   }
62 }
63 //_____________________________________________________________________
64 void AliFMDAnalysisTaskBackgroundCorrection::CreateOutputObjects()
65 {
66   AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
67   
68   fArray.SetName("FMD");
69   fArray.SetOwner();
70   
71   if(!fOutputList)
72     fOutputList = new TList();
73   fOutputList->SetName("BackgroundCorrectedPerEvent");
74   
75   
76   TH2F* hMult = 0;
77   TH2F* hHits = 0;
78   Int_t nVtxbins = pars->GetNvtxBins();
79   
80   for(Int_t det =1; det<=3;det++)
81     {
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++)
87         {
88           Char_t ringChar = (ring == 0 ? 'I' : 'O');
89           Int_t  nSec     = (ring == 0 ? 20 : 40);
90           
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),
97                               hBg->GetNbinsX(),
98                               hBg->GetXaxis()->GetXmin(),
99                               hBg->GetXaxis()->GetXmax(),
100                               nSec, 0, 2*TMath::Pi());
101             hMult->Sumw2();
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),
104                               hBg->GetNbinsX(),
105                               hBg->GetXaxis()->GetXmin(),
106                               hBg->GetXaxis()->GetXmax(),
107                               nSec, 0, 2*TMath::Pi());
108             
109             hHits->Sumw2();
110             fOutputList->Add(hHits);
111             vtxArray->AddAtAndExpand(hMult,i);
112             
113           }
114         } 
115     }
116   if(fStandalone) {
117     fOutputVertexString = new TObjString();
118   }
119   fOutputList->Add(fOutputVertexString);
120   
121   
122   
123 }
124 //_____________________________________________________________________
125 void AliFMDAnalysisTaskBackgroundCorrection::ConnectInputData(Option_t */*option*/)
126 {
127   if(fStandalone) {
128     fInputList   = (TList*)GetInputData(0);
129     
130   }
131 }
132 //_____________________________________________________________________
133 void AliFMDAnalysisTaskBackgroundCorrection::Exec(Option_t */*option*/)
134 {
135   AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
136   
137   fInputArray   = (TObjArray*)fInputList->At(0);
138   fVertexString = (TObjString*)fInputList->At(1);
139   
140   
141   Int_t vtxbin   = fVertexString->GetString().Atoi();
142   fOutputVertexString->SetString(Form("%d",vtxbin));
143   
144   //fNevents.operator[](vtxbin)++;
145   fNevents.Fill(vtxbin);
146   
147   //Reset everything
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);
153       
154       TH2F* hMult   = (TH2F*)vtxArray->At(vtxbin); 
155       hMult->Reset();
156     }
157     
158   }
159   
160   
161   
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));
173       
174       hHits->Add(hMultInput);
175       TH2F* hBg        = pars->GetBackgroundCorrection(det, ringChar, vtxbin);
176       
177       TH2F* hTmp       = (TH2F*)hMultInput->Clone("hMult_from_event");
178       
179       hTmp->Divide(hTmp,hBg,1,1);//,"B");
180       
181       hMultTotal->Add(hTmp);
182       delete hTmp;
183       
184     }
185   }
186   if(fStandalone) {
187     PostData(0, fOutputList); 
188     PostData(1, fOutputVertexString);
189   }
190   
191 }
192 //_____________________________________________________________________
193 void AliFMDAnalysisTaskBackgroundCorrection::Terminate(Option_t */*option*/) {
194   
195   /*
196   AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
197   
198   Int_t nVtxbins = pars->GetNvtxBins();
199   
200   for(UShort_t det=1;det<=3;det++) {
201     TObjArray* detArray = (TObjArray*)fArray.At(det);
202     Int_t nRings = (det==1 ? 1 : 2);
203     for (UShort_t ir = 0; ir < nRings; ir++) {
204       TObjArray* vtxArray = (TObjArray*)detArray->At(ir);
205       for(Int_t i =0; i<nVtxbins; i++) {
206         TH2F* hMultTotal = (TH2F*)vtxArray->At(i);
207         if(fNevents.At(i))
208           hMultTotal->Scale(1/(Float_t)fNevents.At(i));
209       }
210     }
211   }
212   */
213 }
214 //_____________________________________________________________________
215 //
216 //
217 // EOF