]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG0/dNdEta/AlidNdEtaAnalysisESDSelector.cxx
12d5655bf1ea9308abe79e6b2b23eb1a94e79c98
[u/mrichter/AliRoot.git] / PWG0 / dNdEta / AlidNdEtaAnalysisESDSelector.cxx
1 /* $Id$ */
2
3 #include "AlidNdEtaAnalysisESDSelector.h"
4
5 #include <TStyle.h>
6 #include <TSystem.h>
7 #include <TCanvas.h>
8 #include <TVector3.h>
9 #include <TChain.h>
10
11 #include <AliLog.h>
12 #include <AliESDVertex.h>
13 #include <AliESD.h>
14
15 #include "esdTrackCuts/AliESDtrackCuts.h"
16 #include "dNdEtaAnalysis.h"
17
18 ClassImp(AlidNdEtaAnalysisESDSelector)
19
20 AlidNdEtaAnalysisESDSelector::AlidNdEtaAnalysisESDSelector() :
21   AlidNdEtaAnalysisSelector(),
22   fEsdTrackCuts(0)
23 {
24   //
25   // Constructor. Initialization of pointers
26   //
27 }
28
29 AlidNdEtaAnalysisESDSelector::~AlidNdEtaAnalysisESDSelector()
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
39 void AlidNdEtaAnalysisESDSelector::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   AlidNdEtaAnalysisSelector::SlaveBegin(tree);
46
47   if (fChain)
48   {
49     fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (fChain->GetUserInfo()->FindObject("AliESDtrackCuts"));
50   }
51
52   if (!fEsdTrackCuts)
53      AliDebug(AliLog::kError, "ERROR: Could not read EsdTrackCuts from user info.");
54 }
55
56 Bool_t AlidNdEtaAnalysisESDSelector::Process(Long64_t entry)
57 {
58   // The Process() function is called for each entry in the tree (or possibly
59   // keyed object in the case of PROOF) to be processed. The entry argument
60   // specifies which entry in the currently loaded tree is to be processed.
61   // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
62   // to read either all or the required parts of the data. When processing
63   // keyed objects with PROOF, the object is already loaded and is available
64   // via the fObject pointer.
65   //
66   // This function should contain the "body" of the analysis. It can contain
67   // simple or elaborate selection criteria, run algorithms on the data
68   // of the event and typically fill histograms.
69
70   // WARNING when a selector is used with a TChain, you must use
71   //  the pointer to the current TTree to call GetEntry(entry).
72   //  The entry is always the local entry number in the current tree.
73   //  Assuming that fChain is the pointer to the TChain being processed,
74   //  use fChain->GetTree()->GetEntry(entry).
75
76   if (AlidNdEtaAnalysisSelector::Process(entry) == kFALSE)
77     return kFALSE;
78
79   // Check prerequisites
80   if (!fESD)
81   {
82     AliDebug(AliLog::kError, "ESD branch not available");
83     return kFALSE;
84   }
85
86   if (!fEsdTrackCuts)
87   {
88     AliDebug(AliLog::kError, "fESDTrackCuts not available");
89     return kFALSE;
90   }
91
92   // ########################################################
93   // get the EDS vertex
94   const AliESDVertex* vtxESD = fESD->GetVertex();
95
96   // the vertex should be reconstructed
97   if (strcmp(vtxESD->GetName(),"default")==0)
98     return kTRUE;
99
100   Double_t vtx_res[3];
101   vtx_res[0] = vtxESD->GetXRes();
102   vtx_res[1] = vtxESD->GetYRes();
103   vtx_res[2] = vtxESD->GetZRes();
104
105   // the resolution should be reasonable???
106   if (vtx_res[2]==0 || vtx_res[2]>0.1)
107     return kTRUE;
108
109   Double_t vtx[3];
110   vtxESD->GetXYZ(vtx);
111
112   // ########################################################
113   // loop over esd tracks
114   Int_t nTracks = fESD->GetNumberOfTracks();
115   for (Int_t t=0; t<nTracks; t++)
116   {
117     AliESDtrack* esdTrack = fESD->GetTrack(t);
118     if (!esdTrack)
119     {
120       AliDebug(AliLog::kError, Form("ERROR: Could not retrieve track %d.", t));
121       continue;
122     }
123
124     // cut the esd track?
125     if (!fEsdTrackCuts->AcceptTrack(esdTrack))
126       continue;
127
128     Double_t p[3];
129     esdTrack->GetConstrainedPxPyPz(p); // ### TODO or GetInnerPxPyPy / GetOuterPxPyPy
130     TVector3 vector(p);
131
132     Float_t theta = vector.Theta();
133     Float_t eta   = -TMath::Log(TMath::Tan(theta/2.));
134
135     fdNdEtaAnalysis->FillTrack(vtx[2], eta);
136
137   } // end of track loop
138
139   // for event count per vertex
140   fdNdEtaAnalysis->FillEvent(vtx[2]);
141
142   return kTRUE;
143 }
144
145 void AlidNdEtaAnalysisESDSelector::WriteObjects()
146 {
147   AlidNdEtaAnalysisSelector::WriteObjects();
148
149   if (fEsdTrackCuts)
150     fEsdTrackCuts->SaveHistograms("esd_tracks_cuts");
151 }