Default changed: SPD chips thickness is 150 microns
[u/mrichter/AliRoot.git] / PWG0 / dNdEta / AlidNdEtaAnalysisSelector.cxx
CommitLineData
75e130df 1#include "AlidNdEtaAnalysisSelector.h"
2
3#include <TStyle.h>
4#include <TSystem.h>
5#include <TCanvas.h>
75e130df 6#include <TVector3.h>
7
8#include <AliLog.h>
9#include <AliGenEventHeader.h>
75e130df 10
37dbb69e 11#include "esdTrackCuts/AliESDtrackCuts.h"
75e130df 12#include "dNdEtaCorrection.h"
13#include "dNdEtaAnalysis.h"
14
15ClassImp(AlidNdEtaAnalysisSelector)
16
17AlidNdEtaAnalysisSelector::AlidNdEtaAnalysisSelector(TTree *) :
18 AliSelector(),
19 fEsdTrackCuts(0),
20 fdNdEtaAnalysis(0),
21 fdNdEtaCorrection(0),
22 fdNdEtaAnalysisFinal(0)
23{
24 //
25 // Constructor. Initialization of pointers
26 //
27}
28
29AlidNdEtaAnalysisSelector::~AlidNdEtaAnalysisSelector()
30{
31 //
32 // Destructor
33 //
34
35 // histograms are in the output list and deleted when the output
36 // list is deleted by the TSelector dtor
37}
38
39void AlidNdEtaAnalysisSelector::SlaveBegin(TTree * tree)
40{
41 // The SlaveBegin() function is called after the Begin() function.
42 // When running with PROOF SlaveBegin() is called on each slave server.
43 // The tree argument is deprecated (on PROOF 0 is passed).
44
45 AliSelector::SlaveBegin(tree);
46
47 fdNdEtaAnalysis = new dNdEtaAnalysis("dndeta");
48
49 if (fChain)
50 {
51 fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (fChain->GetUserInfo()->FindObject("AliESDtrackCuts"));
52 fdNdEtaCorrection = dynamic_cast<dNdEtaCorrection*> (fChain->GetUserInfo()->FindObject("dNdEtaCorrection"));
53 }
54
55 if (!fEsdTrackCuts)
b8e8168f 56 AliDebug(AliLog::kError, "ERROR: Could not read EsdTrackCuts from user info.");
75e130df 57
58 if (!fEsdTrackCuts)
dded7a68 59 AliDebug(AliLog::kWarning, "ERROR: Could not read dNdEtaCorrection from user info.");
75e130df 60
61 AliLog::SetClassDebugLevel("AliESDtrackCuts", 1);
62}
63
64Bool_t AlidNdEtaAnalysisSelector::Process(Long64_t entry)
65{
66 // The Process() function is called for each entry in the tree (or possibly
67 // keyed object in the case of PROOF) to be processed. The entry argument
68 // specifies which entry in the currently loaded tree is to be processed.
69 // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
70 // to read either all or the required parts of the data. When processing
71 // keyed objects with PROOF, the object is already loaded and is available
72 // via the fObject pointer.
73 //
74 // This function should contain the "body" of the analysis. It can contain
75 // simple or elaborate selection criteria, run algorithms on the data
76 // of the event and typically fill histograms.
77
78 // WARNING when a selector is used with a TChain, you must use
79 // the pointer to the current TTree to call GetEntry(entry).
80 // The entry is always the local entry number in the current tree.
81 // Assuming that fChain is the pointer to the TChain being processed,
82 // use fChain->GetTree()->GetEntry(entry).
83
84 if (AliSelector::Process(entry) == kFALSE)
85 return kFALSE;
86
87 // Check prerequisites
88 if (!fESD || !fEsdTrackCuts)
89 return kFALSE;
90
91 // ########################################################
92 // get the EDS vertex
93 const AliESDVertex* vtxESD = fESD->GetVertex();
94
95 // the vertex should be reconstructed
96 if (strcmp(vtxESD->GetName(),"default")==0)
97 return kTRUE;
98
99 Double_t vtx_res[3];
100 vtx_res[0] = vtxESD->GetXRes();
101 vtx_res[1] = vtxESD->GetYRes();
102 vtx_res[2] = vtxESD->GetZRes();
103
104 // the resolution should be reasonable???
105 if (vtx_res[2]==0 || vtx_res[2]>0.1)
106 return kTRUE;
107
108 Double_t vtx[3];
109 vtxESD->GetXYZ(vtx);
110
111 // ########################################################
112 // loop over esd tracks
113 Int_t nTracks = fESD->GetNumberOfTracks();
114 for (Int_t t=0; t<nTracks; t++)
115 {
116 AliESDtrack* esdTrack = fESD->GetTrack(t);
117 if (!esdTrack)
118 {
b8e8168f 119 AliDebug(AliLog::kError, Form("ERROR: Could not retrieve track %d.", t));
75e130df 120 continue;
121 }
122
123 // cut the esd track?
124 if (!fEsdTrackCuts->AcceptTrack(esdTrack))
125 continue;
126
127 Double_t p[3];
4dd2ad81 128 esdTrack->GetConstrainedPxPyPz(p); // ### TODO or GetInnerPxPyPy / GetOuterPxPyPy
75e130df 129 TVector3 vector(p);
130
131 Float_t theta = vector.Theta();
132 Float_t eta = -TMath::Log(TMath::Tan(theta/2.));
133
134 Float_t correction = fdNdEtaCorrection->GetCorrection(vtx[2], eta);
135
136 fdNdEtaAnalysis->FillTrack(vtx[2], eta, correction);
137
138 } // end of track loop
139
140 // for event count per vertex
141 fdNdEtaAnalysis->FillEvent(vtx[2]);
142
143 return kTRUE;
144}
145
146void AlidNdEtaAnalysisSelector::SlaveTerminate()
147{
148 // The SlaveTerminate() function is called after all entries or objects
149 // have been processed. When running with PROOF SlaveTerminate() is called
150 // on each slave server.
151
152 AliSelector::SlaveTerminate();
153
154 // Add the histograms to the output on each slave server
155 if (!fOutput)
156 {
b8e8168f 157 AliDebug(AliLog::kError, Form("ERROR: Output list not initialized."));
75e130df 158 return;
159 }
160
161 fOutput->Add(fdNdEtaAnalysis->GetEtaVsVtxHistogram());
162 fOutput->Add(fdNdEtaAnalysis->GetEtaVsVtxUncorrectedHistogram());
163 fOutput->Add(fdNdEtaAnalysis->GetVtxHistogram());
164
165 fdNdEtaAnalysis->GetVtxHistogram()->Print();
166 fOutput->Print();
167}
168
169void AlidNdEtaAnalysisSelector::Terminate()
170{
171 // The Terminate() function is the last function to be called during
172 // a query. It always runs on the client, it can be used to present
173 // the results graphically or save the results to file.
174
175 AliSelector::Terminate();
176
177 TH2F* etaVsVtxHistogram = dynamic_cast<TH2F*> (fOutput->FindObject("eta_vs_vtx"));
178 TH2F* etaVsVtxUncorrectedHistogram = dynamic_cast<TH2F*> (fOutput->FindObject("eta_vs_vtx_uncorrected"));
179 TH1D* vtxHistogram = dynamic_cast<TH1D*> (fOutput->FindObject("vtx"));
180
181 if (!etaVsVtxHistogram || !vtxHistogram || !etaVsVtxUncorrectedHistogram)
182 {
b8e8168f 183 AliDebug(AliLog::kError, Form("ERROR: Histograms not available %p %p %p", (void*) etaVsVtxHistogram, (void*) etaVsVtxUncorrectedHistogram, (void*) vtxHistogram));
75e130df 184 return;
185 }
186
187 fdNdEtaAnalysisFinal = new dNdEtaAnalysis("dNdEtaResult");
188
189 fdNdEtaAnalysisFinal->SetEtaVsVtxHistogram(etaVsVtxHistogram);
190 fdNdEtaAnalysisFinal->SetEtaVsVtxUncorrectedHistogram(etaVsVtxUncorrectedHistogram);
191 fdNdEtaAnalysisFinal->SetVtxHistogram(vtxHistogram);
192
193 fdNdEtaAnalysisFinal->Finish();
194
195 TFile* fout = new TFile("out.root","RECREATE");
196
dded7a68 197 if (fEsdTrackCuts)
198 fEsdTrackCuts->SaveHistograms("esd_tracks_cuts");
199
200 if (fdNdEtaCorrection)
201 fdNdEtaCorrection->SaveHistograms();
202
75e130df 203 fdNdEtaAnalysisFinal->SaveHistograms();
204
205 fout->Write();
206 fout->Close();
207
208 fdNdEtaAnalysisFinal->DrawHistograms();
209}