]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/analysis/AliFMDAnalysisTaskBackgroundCorrection.cxx
ee9f95646b879eb803ebccfe21d36f0ce717b898
[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   fHitList(0),
32   fVertexString(0x0),
33   fNevents(),
34   fStandalone(kTRUE),
35   fOutputVertexString(0)
36 {
37   // Default constructor
38   DefineInput (0, TList::Class());
39   DefineOutput(0, TList::Class());
40
41 }
42 //_____________________________________________________________________
43 AliFMDAnalysisTaskBackgroundCorrection::AliFMDAnalysisTaskBackgroundCorrection(const char* name, Bool_t SE):
44     AliAnalysisTask(name, "Density"),
45     fDebug(0),
46     fOutputList(0),
47     fInputList(0),
48     fHitList(0),
49     fVertexString(0x0),
50     fNevents(),
51     fStandalone(kTRUE),
52     fOutputVertexString(0)
53 {
54   fStandalone = SE;
55   if(fStandalone) {
56     DefineInput (0, TList::Class());
57     DefineOutput(0, TList::Class());
58   }
59 }
60 //_____________________________________________________________________
61 void AliFMDAnalysisTaskBackgroundCorrection::CreateOutputObjects()
62 {
63   AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
64   
65   if(!fOutputList)
66     fOutputList = new TList();
67   fOutputList->SetName("BackgroundCorrectedPerEvent");
68   if(!fHitList)
69     fHitList = new TList();
70   fHitList->SetName("HitsList");
71   
72   //if(fStandalone) {
73   fOutputVertexString = new TObjString();
74   // }
75   fOutputList->Add(fOutputVertexString);
76   
77   
78   
79   TH2F* hMult = 0;
80   TH2F* hHits = 0;
81   Int_t nVtxbins = pars->GetNvtxBins();
82   
83   for(Int_t det =1; det<=3;det++)
84     {
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           for(Int_t i = 0; i< nVtxbins; i++) {
92             TH2F* hBg = pars->GetBackgroundCorrection(det, ringChar, i);
93             hMult  = new TH2F(Form("mult_FMD%d%c_vtxbin%d",det,ringChar,i),Form("mult_FMD%d%c_vtxbin%d",det,ringChar,i),
94                               hBg->GetNbinsX(),
95                               hBg->GetXaxis()->GetXmin(),
96                               hBg->GetXaxis()->GetXmax(),
97                               nSec, 0, 2*TMath::Pi());
98             hMult->Sumw2();
99             fOutputList->Add(hMult);
100             hHits  = new TH2F(Form("hits_FMD%d%c_vtxbin%d",det,ringChar,i),Form("hits_FMD%d%c_vtxbin%d",det,ringChar,i),
101                               hBg->GetNbinsX(),
102                               hBg->GetXaxis()->GetXmin(),
103                               hBg->GetXaxis()->GetXmax(),
104                               nSec, 0, 2*TMath::Pi());
105             
106             hHits->Sumw2();
107             fHitList->Add(hHits);
108             fOutputList->Add(hHits);
109             
110           }
111         } 
112     }
113   
114   
115   
116 }
117 //_____________________________________________________________________
118 void AliFMDAnalysisTaskBackgroundCorrection::ConnectInputData(Option_t */*option*/)
119 {
120   if(fStandalone) {
121     fInputList   = (TList*)GetInputData(0);
122     
123   }
124 }
125 //_____________________________________________________________________
126 void AliFMDAnalysisTaskBackgroundCorrection::Exec(Option_t */*option*/)
127 {
128   AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
129   
130   fVertexString = (TObjString*)fInputList->At(0);
131    
132   Int_t vtxbin   = fVertexString->GetString().Atoi();
133   fOutputVertexString->SetString(Form("%d",vtxbin));
134   
135   fNevents.Fill(vtxbin);
136   //Reset everything
137   for(UShort_t det=1;det<=3;det++) {
138     Int_t nRings = (det==1 ? 1 : 2);
139     for (UShort_t ir = 0; ir < nRings; ir++) {
140       Char_t ringChar = (ir == 0 ? 'I' : 'O');
141       TH2F* hMult = (TH2F*)fOutputList->FindObject(Form("mult_FMD%d%c_vtxbin%d",det,ringChar,vtxbin));
142       hMult->Reset();
143     }
144     
145   }
146   
147   
148   
149   for(UShort_t det=1;det<=3;det++) {
150    
151     Int_t nRings = (det==1 ? 1 : 2);
152     for (UShort_t ir = 0; ir < nRings; ir++) {
153       Char_t ringChar = (ir == 0 ? 'I' : 'O');
154    
155       TH2F* hMultTotal = (TH2F*)fOutputList->FindObject(Form("mult_FMD%d%c_vtxbin%d",det,ringChar,vtxbin));
156     
157       TH2F* hMultInput = (TH2F*)fInputList->FindObject(Form("FMD%d%c_vtxbin%d",det,ringChar,vtxbin));
158       TH2F* hHits      = (TH2F*)fOutputList->FindObject(Form("hits_FMD%d%c_vtxbin%d",det,ringChar,vtxbin));
159       
160       if(pars->GetProcessHits())
161          hHits->Add(hMultInput);
162       
163       TH2F* hBg        = pars->GetBackgroundCorrection(det, ringChar, vtxbin);
164       
165       hMultTotal->Add(hMultInput);
166       
167       hMultTotal->Divide(hBg);//,"B");
168       /*for(Int_t i = 1; i<=hTmp->GetNbinsX();i++) {
169         for(Int_t j = 1; j<=hTmp->GetNbinsY();j++) {
170           Float_t mult = hTmp->GetBinContent(i,j);
171           if(mult == 0) continue;
172           Float_t correction = hBg->GetBinContent(i,j);
173           
174           Float_t multcor = mult;
175           if(correction != 0)
176             multcor = multcor/correction;
177           else
178             std::cout<<"Warning! No correction for bin "<<i<<" , "<<j<<std::endl;
179           
180           hTmp->SetBinContent(i,j,multcor);
181         }
182         }*/
183     }
184   }
185   if(fStandalone) {
186     PostData(0, fOutputList); 
187   }
188   
189 }
190 //_____________________________________________________________________
191 void AliFMDAnalysisTaskBackgroundCorrection::Terminate(Option_t */*option*/) {
192   
193   
194 }
195 //_____________________________________________________________________
196 //
197 //
198 // EOF