]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/analysis/AliFMDAnalysisTaskBackgroundCorrection.cxx
The FMD analysis tasks. This is a first version and there is work to do
[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 "AliESDVertex.h"
19 #include "TMath.h"
20 #include "AliFMDAnaParameters.h"
21 #include "AliFMDGeometry.h"
22
23 ClassImp(AliFMDAnalysisTaskBackgroundCorrection)
24
25
26 AliFMDAnalysisTaskBackgroundCorrection::AliFMDAnalysisTaskBackgroundCorrection()
27 : fDebug(0),
28   fChain(0x0),
29   fOutputList(0),
30   fArray(0),
31   fInputArray(0)
32 {
33   // Default constructor
34   DefineInput (0, TList::Class());
35   DefineOutput(0,TList::Class());
36 }
37
38 AliFMDAnalysisTaskBackgroundCorrection::AliFMDAnalysisTaskBackgroundCorrection(const char* name):
39     AliAnalysisTask(name, "Density"),
40     fDebug(0),
41     fChain(0x0),
42     fOutputList(0),
43     fArray(0),
44     fInputArray(0)
45 {
46   DefineInput (0, TList::Class());
47   DefineOutput(0, TList::Class());
48 }
49
50 void AliFMDAnalysisTaskBackgroundCorrection::CreateOutputObjects()
51 {
52   AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
53   fOutputList = new TList();
54   
55   fArray     = new TObjArray();
56   fArray->SetName("FMD");
57   fArray->SetOwner();
58   
59   TH2F* hMult = 0;
60   
61   Int_t nVtxbins = pars->GetNvtxBins();
62   
63   for(Int_t det =1; det<=3;det++)
64     {
65       TObjArray* detArray = new TObjArray();
66       detArray->SetName(Form("FMD%d",det));
67       fArray->AddAtAndExpand(detArray,det);
68       Int_t nRings = (det==1 ? 1 : 2);
69       for(Int_t ring = 0;ring<nRings;ring++)
70         {
71           Char_t ringChar = (ring == 0 ? 'I' : 'O');
72           Int_t  nSec     = (ring == 0 ? 20 : 40);
73           
74           TObjArray* vtxArray = new TObjArray();
75           vtxArray->SetName(Form("FMD%d%c",det,ringChar));
76           detArray->AddAtAndExpand(vtxArray,ring);
77           for(Int_t i = 0; i< nVtxbins; i++) {
78             TH2F* hBg = pars->GetBackgroundCorrection(det, ringChar, i);
79             hMult  = new TH2F(Form("mult_FMD%d%c_vtxbin%d",det,ringChar,i),Form("mult_FMD%d%c_vtxbin%d",det,ringChar,i),
80                               hBg->GetNbinsX(),
81                               hBg->GetXaxis()->GetXmin(),
82                               hBg->GetXaxis()->GetXmax(),
83                               nSec, 0, 2*TMath::Pi());
84             vtxArray->AddAtAndExpand(hMult,i);
85             
86           }
87         } 
88     }
89     
90   fOutputList->Add(fArray);
91    
92   
93 }
94
95 void AliFMDAnalysisTaskBackgroundCorrection::ConnectInputData(Option_t */*option*/)
96 {
97
98   TList* list = (TList*)GetInputData(0);
99   fInputArray = (TObjArray*)list->At(0);
100     
101 }
102
103 void AliFMDAnalysisTaskBackgroundCorrection::Exec(Option_t */*option*/)
104 {
105   AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
106   
107   Int_t nVtxbins = pars->GetNvtxBins();
108   
109     
110   for(UShort_t det=1;det<=3;det++) {
111     TObjArray* detInputArray = (TObjArray*)fInputArray->At(det);
112     TObjArray* detArray = (TObjArray*)fArray->At(det);
113     Int_t nRings = (det==1 ? 1 : 2);
114     for (UShort_t ir = 0; ir < nRings; ir++) {
115       Char_t ringChar = (ir == 0 ? 'I' : 'O');
116       TObjArray* vtxInputArray = (TObjArray*)detInputArray->At(ir);
117       TObjArray* vtxArray = (TObjArray*)detArray->At(ir);
118       for(Int_t i =0; i<nVtxbins; i++) {
119         TH2F* hMultTotal = (TH2F*)vtxArray->At(i);
120         TH2F* hMult      = (TH2F*)vtxInputArray->At(i);
121         TH2F* hBg        = pars->GetBackgroundCorrection(det, ringChar, i);
122         
123         TH2F* hTmp       = (TH2F*)hMult->Clone("hMult_from_event");
124         /*for(Int_t j=1; j<=hMult->GetNbinsX();j++) {
125           for(Int_t k=1; k<=hMult->GetNbinsY();k++) {
126             if(hBg->GetBinContent(j,k) != 0) {
127               // std::cout<<hMult->GetBinContent(j,k)<<"    "<<hBg->GetBinContent(j,k)<<std::endl;
128               hTmp->SetBinContent(j,k,hMult->GetBinContent(j,k)/hBg->GetBinContent(j,k));
129             }
130           }
131           }*/
132         hTmp->Divide(hTmp,hBg,1,1,"B");
133         
134         hMultTotal->Add(hTmp);
135         
136       }
137     }
138   }
139   
140   PostData(0, fOutputList); 
141   
142 }
143