]> git.uio.no Git - u/mrichter/AliRoot.git/blob - 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
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   TH2F* hHitsNoCuts = 0;
82   Int_t nVtxbins = pars->GetNvtxBins();
83   
84   for(Int_t det =1; det<=3;det++)
85     {
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           
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());
99             hMult->Sumw2();
100             fOutputList->Add(hMult);
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             
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             */
114             hHits->Sumw2();
115             //hHitsNoCuts->Sumw2();
116             
117             fHitList->Add(hHits);
118             fOutputList->Add(hHits);
119             // fHitList->Add(hHitsNoCuts);
120             //  fOutputList->Add(hHitsNoCuts);
121             
122           }
123         } 
124     }
125   
126   
127   
128 }
129 //_____________________________________________________________________
130 void AliFMDAnalysisTaskBackgroundCorrection::ConnectInputData(Option_t */*option*/)
131 {
132   if(fStandalone) {
133     fInputList   = (TList*)GetInputData(0);
134     
135   }
136 }
137 //_____________________________________________________________________
138 void AliFMDAnalysisTaskBackgroundCorrection::Exec(Option_t */*option*/)
139 {
140   AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
141   
142   fVertexString = (TObjString*)fInputList->At(0);
143    
144   Int_t vtxbin   = fVertexString->GetString().Atoi();
145   fOutputVertexString->SetString(Form("%d",vtxbin));
146   
147   fNevents.Fill(vtxbin);
148   //Reset everything
149   for(UShort_t det=1;det<=3;det++) {
150     Int_t nRings = (det==1 ? 1 : 2);
151     for (UShort_t ir = 0; ir < nRings; ir++) {
152       Char_t ringChar = (ir == 0 ? 'I' : 'O');
153       TH2F* hMult = (TH2F*)fOutputList->FindObject(Form("mult_FMD%d%c_vtxbin%d",det,ringChar,vtxbin));
154       hMult->Reset();
155     }
156     
157   }
158   
159   
160   
161   for(UShort_t det=1;det<=3;det++) {
162    
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');
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));
170       TH2F* hHits      = (TH2F*)fOutputList->FindObject(Form("hits_FMD%d%c_vtxbin%d",det,ringChar,vtxbin));
171       
172       if(pars->GetProcessHits())
173          hHits->Add(hMultInput);
174       
175       TH2F* hBg        = pars->GetBackgroundCorrection(det, ringChar, vtxbin);
176       
177       hMultTotal->Add(hMultInput);
178       
179       hMultTotal->Divide(hBg);//,"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);
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         }*/
195     }
196   }
197   if(fStandalone) {
198     PostData(0, fOutputList); 
199   }
200   
201 }
202 //_____________________________________________________________________
203 void AliFMDAnalysisTaskBackgroundCorrection::Terminate(Option_t */*option*/) {
204   AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
205   
206   Int_t nVtxbins = pars->GetNvtxBins();
207   
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());
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));
218         fHitList->Add(hHitsproj);
219         fHitList->Add(hHitsNoCuts);
220         
221       }
222     }
223   }
224 }
225 //_____________________________________________________________________
226 //
227 //
228 // EOF