]> git.uio.no Git - u/mrichter/AliRoot.git/blame - FMD/analysis/AliFMDAnalysisTaskBackgroundCorrection.cxx
Added hit distributions from all events from MC and data in preparation for sharing...
[u/mrichter/AliRoot.git] / FMD / analysis / AliFMDAnalysisTaskBackgroundCorrection.cxx
CommitLineData
3bb122c7 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"
7c3e5162 18#include "AliLog.h"
3bb122c7 19#include "AliESDVertex.h"
20#include "TMath.h"
21#include "AliFMDAnaParameters.h"
78f6f750 22//#include "AliFMDGeometry.h"
3bb122c7 23
24ClassImp(AliFMDAnalysisTaskBackgroundCorrection)
25
26
27AliFMDAnalysisTaskBackgroundCorrection::AliFMDAnalysisTaskBackgroundCorrection()
28: fDebug(0),
3bb122c7 29 fOutputList(0),
7c3e5162 30 fInputList(0),
cc066cb9 31 fHitList(0),
c78bc12b 32 fVertexString(0x0),
7c3e5162 33 fNevents(),
34 fStandalone(kTRUE),
35 fOutputVertexString(0)
3bb122c7 36{
37 // Default constructor
38 DefineInput (0, TList::Class());
8dc7c4c2 39 DefineOutput(0, TList::Class());
9f55be54 40
3bb122c7 41}
8dc823cc 42//_____________________________________________________________________
7c3e5162 43AliFMDAnalysisTaskBackgroundCorrection::AliFMDAnalysisTaskBackgroundCorrection(const char* name, Bool_t SE):
3bb122c7 44 AliAnalysisTask(name, "Density"),
45 fDebug(0),
7c3e5162 46 fOutputList(0),
47 fInputList(0),
cc066cb9 48 fHitList(0),
c78bc12b 49 fVertexString(0x0),
7c3e5162 50 fNevents(),
51 fStandalone(kTRUE),
52 fOutputVertexString(0)
3bb122c7 53{
7c3e5162 54 fStandalone = SE;
55 if(fStandalone) {
56 DefineInput (0, TList::Class());
57 DefineOutput(0, TList::Class());
7c3e5162 58 }
3bb122c7 59}
8dc823cc 60//_____________________________________________________________________
3bb122c7 61void AliFMDAnalysisTaskBackgroundCorrection::CreateOutputObjects()
62{
63 AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
3bb122c7 64
7c3e5162 65 if(!fOutputList)
66 fOutputList = new TList();
67 fOutputList->SetName("BackgroundCorrectedPerEvent");
cc066cb9 68 if(!fHitList)
69 fHitList = new TList();
70 fHitList->SetName("HitsList");
7c3e5162 71
9f55be54 72 //if(fStandalone) {
73 fOutputVertexString = new TObjString();
74 // }
75 fOutputList->Add(fOutputVertexString);
76
77
7c3e5162 78
3bb122c7 79 TH2F* hMult = 0;
bb8a464f 80 TH2F* hHits = 0;
0a2f2742 81 TH2F* hHitsNoCuts = 0;
3bb122c7 82 Int_t nVtxbins = pars->GetNvtxBins();
83
84 for(Int_t det =1; det<=3;det++)
85 {
3bb122c7 86 Int_t nRings = (det==1 ? 1 : 2);
87 for(Int_t ring = 0;ring<nRings;ring++)
88 {
89 Char_t ringChar = (ring == 0 ? 'I' : 'O');
90 Int_t nSec = (ring == 0 ? 20 : 40);
91
3bb122c7 92 for(Int_t i = 0; i< nVtxbins; i++) {
93 TH2F* hBg = pars->GetBackgroundCorrection(det, ringChar, i);
94 hMult = new TH2F(Form("mult_FMD%d%c_vtxbin%d",det,ringChar,i),Form("mult_FMD%d%c_vtxbin%d",det,ringChar,i),
95 hBg->GetNbinsX(),
96 hBg->GetXaxis()->GetXmin(),
97 hBg->GetXaxis()->GetXmax(),
98 nSec, 0, 2*TMath::Pi());
8dc823cc 99 hMult->Sumw2();
7c3e5162 100 fOutputList->Add(hMult);
bb8a464f 101 hHits = new TH2F(Form("hits_FMD%d%c_vtxbin%d",det,ringChar,i),Form("hits_FMD%d%c_vtxbin%d",det,ringChar,i),
102 hBg->GetNbinsX(),
103 hBg->GetXaxis()->GetXmin(),
104 hBg->GetXaxis()->GetXmax(),
105 nSec, 0, 2*TMath::Pi());
106
0a2f2742 107 /* hHitsNoCuts = new TH2F(Form("hits_NoCuts_FMD%d%c_vtxbin%d",det,ringChar,i),Form("hits_NoCuts_FMD%d%c_vtxbin%d",det,ringChar,i),
108 hBg->GetNbinsX(),
109 hBg->GetXaxis()->GetXmin(),
110 hBg->GetXaxis()->GetXmax(),
111 nSec, 0, 2*TMath::Pi());
112
113 */
bb8a464f 114 hHits->Sumw2();
0a2f2742 115 //hHitsNoCuts->Sumw2();
116
cc066cb9 117 fHitList->Add(hHits);
bb8a464f 118 fOutputList->Add(hHits);
0a2f2742 119 // fHitList->Add(hHitsNoCuts);
120 // fOutputList->Add(hHitsNoCuts);
3bb122c7 121
122 }
123 }
124 }
7c3e5162 125
3bb122c7 126
bb8a464f 127
3bb122c7 128}
8dc823cc 129//_____________________________________________________________________
3bb122c7 130void AliFMDAnalysisTaskBackgroundCorrection::ConnectInputData(Option_t */*option*/)
131{
7c3e5162 132 if(fStandalone) {
133 fInputList = (TList*)GetInputData(0);
134
135 }
3bb122c7 136}
8dc823cc 137//_____________________________________________________________________
3bb122c7 138void AliFMDAnalysisTaskBackgroundCorrection::Exec(Option_t */*option*/)
139{
140 AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
141
9f55be54 142 fVertexString = (TObjString*)fInputList->At(0);
143
8dc823cc 144 Int_t vtxbin = fVertexString->GetString().Atoi();
7c3e5162 145 fOutputVertexString->SetString(Form("%d",vtxbin));
8dc7c4c2 146
875e75b6 147 fNevents.Fill(vtxbin);
7c3e5162 148 //Reset everything
149 for(UShort_t det=1;det<=3;det++) {
7c3e5162 150 Int_t nRings = (det==1 ? 1 : 2);
151 for (UShort_t ir = 0; ir < nRings; ir++) {
9f55be54 152 Char_t ringChar = (ir == 0 ? 'I' : 'O');
153 TH2F* hMult = (TH2F*)fOutputList->FindObject(Form("mult_FMD%d%c_vtxbin%d",det,ringChar,vtxbin));
7c3e5162 154 hMult->Reset();
155 }
156
157 }
158
159
160
3bb122c7 161 for(UShort_t det=1;det<=3;det++) {
9f55be54 162
3bb122c7 163 Int_t nRings = (det==1 ? 1 : 2);
164 for (UShort_t ir = 0; ir < nRings; ir++) {
165 Char_t ringChar = (ir == 0 ? 'I' : 'O');
9f55be54 166
167 TH2F* hMultTotal = (TH2F*)fOutputList->FindObject(Form("mult_FMD%d%c_vtxbin%d",det,ringChar,vtxbin));
168
169 TH2F* hMultInput = (TH2F*)fInputList->FindObject(Form("FMD%d%c_vtxbin%d",det,ringChar,vtxbin));
bb8a464f 170 TH2F* hHits = (TH2F*)fOutputList->FindObject(Form("hits_FMD%d%c_vtxbin%d",det,ringChar,vtxbin));
171
55cadbf9 172 if(pars->GetProcessHits())
173 hHits->Add(hMultInput);
174
8dc823cc 175 TH2F* hBg = pars->GetBackgroundCorrection(det, ringChar, vtxbin);
7c3e5162 176
78f6f750 177 hMultTotal->Add(hMultInput);
bb8a464f 178
78f6f750 179 hMultTotal->Divide(hBg);//,"B");
6289b3e8 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);
185
186 Float_t multcor = mult;
187 if(correction != 0)
188 multcor = multcor/correction;
189 else
190 std::cout<<"Warning! No correction for bin "<<i<<" , "<<j<<std::endl;
191
192 hTmp->SetBinContent(i,j,multcor);
193 }
194 }*/
3bb122c7 195 }
196 }
7c3e5162 197 if(fStandalone) {
198 PostData(0, fOutputList);
7c3e5162 199 }
3bb122c7 200
201}
8dc823cc 202//_____________________________________________________________________
203void AliFMDAnalysisTaskBackgroundCorrection::Terminate(Option_t */*option*/) {
18d4b9ae 204 AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
8dc823cc 205
18d4b9ae 206 Int_t nVtxbins = pars->GetNvtxBins();
8dc823cc 207
18d4b9ae 208 for(UShort_t det=1;det<=3;det++) {
209 Int_t nRings = (det==1 ? 1 : 2);
210 for (UShort_t ir = 0; ir < nRings; ir++) {
211 Char_t ringChar = (ir == 0 ? 'I' : 'O');
212 for(Int_t i =0; i<nVtxbins; i++) {
213 TH2F* hHits = (TH2F*)fOutputList->FindObject(Form("hits_FMD%d%c_vtxbin%d",det,ringChar,i));
214 TH1D* hHitsproj = hHits->ProjectionX(Form("hits_FMD%d%c_vtxbin%d_proj",det,ringChar,i),1,hHits->GetNbinsY());
0a2f2742 215 TH1D* hHitsNoCuts = (TH1D*)hHitsproj->Clone(Form("hits_NoCuts_FMD%d%c_vtxbin%d_proj",det,ringChar,i));
216
217 hHitsNoCuts->Scale(1/pars->GetEventSelectionEfficiency(i));
18d4b9ae 218 fHitList->Add(hHitsproj);
0a2f2742 219 fHitList->Add(hHitsNoCuts);
18d4b9ae 220
221 }
222 }
223 }
8dc823cc 224}
225//_____________________________________________________________________
226//
227//
228// EOF