a69b24467e88be2ce5666bdc292f43157a6ddef5
[u/mrichter/AliRoot.git] / PWG0 / dNdEta / AlidNdEtaCorrection.cxx
1 /* $Id$ */
2
3 #include "AlidNdEtaCorrection.h"
4
5 #include <TCanvas.h>
6 #include <TH2F.h>
7
8 //____________________________________________________________________
9 ClassImp(AlidNdEtaCorrection)
10
11 //____________________________________________________________________
12 AlidNdEtaCorrection::AlidNdEtaCorrection(Char_t* name) 
13   : TNamed(name, name),
14   fNEvents(0),
15   fNTriggeredEvents(0)
16 {  
17   // constructor
18   //
19
20   fTrack2ParticleCorrection = new AliCorrectionMatrix3D("nTrackToNPart", "nTrackToNPart",80,-20,20,120,-6,6, 100, 0, 10);
21
22   Float_t binLimitsN[]   = {-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 
23                             10.5, 12.5, 14.5, 16.5, 18.5, 20.5, 25.5, 30.5, 40.5, 50.5, 100.5, 300.5};
24   Float_t binLimitsVtx[] = {-20,-15,-10,-6,-3,0,3,6,10,15,20};
25   
26   fVertexRecoCorrection        = new AliCorrectionMatrix2D("vtxReco",       "vtxReco",10,binLimitsVtx ,22,binLimitsN);
27
28   fTriggerBiasCorrection       = new AliCorrectionMatrix2D("triggerBias",   "triggerBias",120,-6,6,100, 0, 10);
29
30   fTrack2ParticleCorrection ->SetAxisTitles("vtx z [cm]", "#eta", "p_{T}");
31   fVertexRecoCorrection        ->SetAxisTitles("vtx z [cm]", "n particles/tracks/tracklets?");
32
33   fTriggerBiasCorrection       ->SetAxisTitles("#eta", "p_{T} [GeV/c]");
34 }
35
36 //____________________________________________________________________
37 void
38 AlidNdEtaCorrection::Finish() {
39   //
40   // finish method
41   //
42   // divide the histograms in the AliCorrectionMatrix2D objects to get the corrections
43
44
45   fTrack2ParticleCorrection->Divide();
46
47   fVertexRecoCorrection->Divide();
48
49   fTriggerBiasCorrection->GetMeasuredHistogram()->Scale(Double_t(fNTriggeredEvents)/Double_t(fNEvents));
50   fTriggerBiasCorrection->Divide();
51
52 }
53
54 //____________________________________________________________________
55 Long64_t 
56 AlidNdEtaCorrection::Merge(TCollection* list) {
57   // Merge a list of dNdEtaCorrection objects with this (needed for
58   // PROOF). 
59   // Returns the number of merged objects (including this).
60
61   if (!list)
62     return 0;
63   
64   if (list->IsEmpty())
65     return 1;
66
67   TIterator* iter = list->MakeIterator();
68   TObject* obj;
69
70   // collections of measured and generated histograms
71   TList* collectionNtrackToNparticle = new TList;
72   TList* collectionVertexReco        = new TList;
73   TList* collectionTriggerBias       = new TList;
74
75   Int_t count = 0;
76   while ((obj = iter->Next())) {
77     
78     AlidNdEtaCorrection* entry = dynamic_cast<AlidNdEtaCorrection*> (obj);
79     if (entry == 0) 
80       continue;
81
82     collectionNtrackToNparticle ->Add(entry->GetTrack2ParticleCorrection());
83     collectionVertexReco        ->Add(entry->GetVertexRecoCorrection());
84     collectionTriggerBias        ->Add(entry->GetTriggerBiasCorrection());
85
86     count++;
87   }
88   fTrack2ParticleCorrection ->Merge(collectionNtrackToNparticle);
89   fVertexRecoCorrection        ->Merge(collectionVertexReco);
90   fTriggerBiasCorrection        ->Merge(collectionTriggerBias);
91   
92   delete collectionNtrackToNparticle;
93   delete collectionVertexReco;
94   delete collectionTriggerBias;
95
96   return count+1;
97 }
98
99
100 //____________________________________________________________________
101 Bool_t
102 AlidNdEtaCorrection::LoadHistograms(Char_t* fileName, Char_t* dir) {
103   //
104   // loads the histograms
105   //
106
107   fTrack2ParticleCorrection ->LoadHistograms(fileName, dir);
108   fVertexRecoCorrection        ->LoadHistograms(fileName, dir);
109   fTriggerBiasCorrection       ->LoadHistograms(fileName, dir);
110   
111   return kTRUE;
112 }
113
114
115 //____________________________________________________________________
116 void
117 AlidNdEtaCorrection::SaveHistograms() {
118   //
119   // save the histograms
120   //
121
122   gDirectory->mkdir(fName.Data());
123   gDirectory->cd(fName.Data());
124
125   fTrack2ParticleCorrection ->SaveHistograms();
126   fVertexRecoCorrection        ->SaveHistograms();
127   fTriggerBiasCorrection       ->SaveHistograms();
128
129   gDirectory->cd("../");
130 }
131
132 //____________________________________________________________________
133 void AlidNdEtaCorrection::DrawHistograms()
134 {
135   //
136   // call the draw histogram method of the two AliCorrectionMatrix2D objects
137
138   fTrack2ParticleCorrection ->DrawHistograms();
139   fVertexRecoCorrection        ->DrawHistograms();
140   fTriggerBiasCorrection       ->DrawHistograms();
141
142 }