]>
Commit | Line | Data |
---|---|---|
dc740de4 | 1 | /* $Id$ */ |
2 | ||
3 | #include "AlidNdEtaAnalysisESDSelector.h" | |
4 | ||
5 | #include <TStyle.h> | |
6 | #include <TSystem.h> | |
7 | #include <TCanvas.h> | |
8 | #include <TVector3.h> | |
7029240a | 9 | #include <TChain.h> |
16e24ca3 | 10 | #include <TFile.h> |
dc740de4 | 11 | |
12 | #include <AliLog.h> | |
fcf2fb36 | 13 | #include <AliESDVertex.h> |
14 | #include <AliESD.h> | |
dc740de4 | 15 | |
16 | #include "esdTrackCuts/AliESDtrackCuts.h" | |
16e24ca3 | 17 | #include "dNdEta/dNdEtaAnalysis.h" |
45e97e28 | 18 | #include "AliPWG0Helper.h" |
dc740de4 | 19 | |
74fd10b3 | 20 | #include "AliGenEventHeader.h" |
21 | #include "AliHeader.h" | |
22 | #include "AliStack.h" | |
23 | #include "TParticle.h" | |
24 | ||
dc740de4 | 25 | ClassImp(AlidNdEtaAnalysisESDSelector) |
26 | ||
27 | AlidNdEtaAnalysisESDSelector::AlidNdEtaAnalysisESDSelector() : | |
74fd10b3 | 28 | AliSelectorRL(), |
1afae8ff | 29 | fdNdEtaAnalysis(0), |
74fd10b3 | 30 | fEsdTrackCuts(0) |
31 | { | |
dc740de4 | 32 | // |
33 | // Constructor. Initialization of pointers | |
34 | // | |
16e24ca3 | 35 | |
0ab29cfa | 36 | AliLog::SetClassDebugLevel("AlidNdEtaAnalysisESDSelector", AliLog::kDebug); |
dc740de4 | 37 | } |
38 | ||
39 | AlidNdEtaAnalysisESDSelector::~AlidNdEtaAnalysisESDSelector() | |
40 | { | |
41 | // | |
42 | // Destructor | |
43 | // | |
44 | ||
45 | // histograms are in the output list and deleted when the output | |
46 | // list is deleted by the TSelector dtor | |
47 | } | |
48 | ||
0ab29cfa | 49 | void AlidNdEtaAnalysisESDSelector::Begin(TTree* tree) |
dc740de4 | 50 | { |
0ab29cfa | 51 | // Begin function |
dc740de4 | 52 | |
0ab29cfa | 53 | ReadUserObjects(tree); |
54 | } | |
dc740de4 | 55 | |
0ab29cfa | 56 | void AlidNdEtaAnalysisESDSelector::ReadUserObjects(TTree* tree) |
57 | { | |
58 | // read the user objects, called from slavebegin and begin | |
dc740de4 | 59 | |
16e24ca3 | 60 | if (!fEsdTrackCuts && fInput) |
61 | fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (fInput->FindObject("AliESDtrackCuts")); | |
62 | ||
1afae8ff | 63 | if (!fEsdTrackCuts && tree) |
64 | fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (tree->GetUserInfo()->FindObject("AliESDtrackCuts")); | |
65 | ||
16e24ca3 | 66 | if (!fEsdTrackCuts) |
67 | AliDebug(AliLog::kError, "ERROR: Could not read EsdTrackCuts from input list."); | |
0ab29cfa | 68 | } |
1afae8ff | 69 | |
0ab29cfa | 70 | void AlidNdEtaAnalysisESDSelector::SlaveBegin(TTree* tree) |
71 | { | |
72 | // The SlaveBegin() function is called after the Begin() function. | |
73 | // When running with PROOF SlaveBegin() is called on each slave server. | |
74 | // The tree argument is deprecated (on PROOF 0 is passed). | |
75 | ||
74fd10b3 | 76 | AliSelectorRL::SlaveBegin(tree); |
0ab29cfa | 77 | |
78 | ReadUserObjects(tree); | |
1afae8ff | 79 | |
16e24ca3 | 80 | fdNdEtaAnalysis = new dNdEtaAnalysis("dndeta", "dndeta"); |
81 | } | |
82 | ||
83 | void AlidNdEtaAnalysisESDSelector::Init(TTree* tree) | |
84 | { | |
85 | // read the user objects | |
86 | ||
74fd10b3 | 87 | AliSelectorRL::Init(tree); |
5c495d37 | 88 | |
89 | // Enable only the needed branches | |
90 | if (tree) | |
91 | { | |
92 | tree->SetBranchStatus("*", 0); | |
93 | tree->SetBranchStatus("fTriggerMask", 1); | |
94 | tree->SetBranchStatus("fSPDVertex*", 1); | |
74fd10b3 | 95 | tree->SetBranchStatus("fTracks.fLabel", 1); |
5c495d37 | 96 | |
97 | AliESDtrackCuts::EnableNeededBranches(tree); | |
98 | } | |
dc740de4 | 99 | } |
100 | ||
101 | Bool_t AlidNdEtaAnalysisESDSelector::Process(Long64_t entry) | |
102 | { | |
74fd10b3 | 103 | // loop over all events |
dc740de4 | 104 | |
74fd10b3 | 105 | if (AliSelectorRL::Process(entry) == kFALSE) |
dc740de4 | 106 | return kFALSE; |
107 | ||
108 | // Check prerequisites | |
109 | if (!fESD) | |
110 | { | |
111 | AliDebug(AliLog::kError, "ESD branch not available"); | |
112 | return kFALSE; | |
113 | } | |
114 | ||
115 | if (!fEsdTrackCuts) | |
116 | { | |
117 | AliDebug(AliLog::kError, "fESDTrackCuts not available"); | |
118 | return kFALSE; | |
119 | } | |
120 | ||
847489f7 | 121 | if (AliPWG0Helper::IsEventTriggered(fESD) == kFALSE) |
5c495d37 | 122 | { |
123 | AliDebug(AliLog::kDebug+1, Form("Skipping event %d because it was not triggered", (Int_t) entry)); | |
847489f7 | 124 | return kTRUE; |
5c495d37 | 125 | } |
847489f7 | 126 | |
45e97e28 | 127 | if (AliPWG0Helper::IsVertexReconstructed(fESD) == kFALSE) |
5c495d37 | 128 | { |
129 | AliDebug(AliLog::kDebug+1, Form("Skipping event %d because its vertex was not reconstructed", (Int_t) entry)); | |
dc740de4 | 130 | return kTRUE; |
5c495d37 | 131 | } |
dc740de4 | 132 | |
74fd10b3 | 133 | AliHeader* header = GetHeader(); |
134 | if (!header) | |
135 | { | |
136 | AliDebug(AliLog::kError, "Header not available"); | |
137 | return kFALSE; | |
138 | } | |
139 | ||
140 | AliStack* stack = GetStack(); | |
141 | if (!stack) | |
142 | { | |
143 | AliDebug(AliLog::kError, "Stack not available"); | |
144 | return kFALSE; | |
145 | } | |
146 | ||
147 | // get the MC vertex | |
148 | AliGenEventHeader* genHeader = header->GenEventHeader(); | |
149 | ||
150 | TArrayF vtxMC(3); | |
151 | genHeader->PrimaryVertex(vtxMC); | |
152 | ||
45e97e28 | 153 | // ######################################################## |
74fd10b3 | 154 | // get the ESD vertex |
45e97e28 | 155 | const AliESDVertex* vtxESD = fESD->GetVertex(); |
dc740de4 | 156 | Double_t vtx[3]; |
157 | vtxESD->GetXYZ(vtx); | |
158 | ||
74fd10b3 | 159 | vtx[2] = vtxMC[2]; |
160 | ||
45e97e28 | 161 | // get number of "good" tracks |
162 | TObjArray* list = fEsdTrackCuts->GetAcceptedTracks(fESD); | |
163 | Int_t nGoodTracks = list->GetEntries(); | |
164 | ||
74fd10b3 | 165 | // FAKE test! |
166 | //Int_t nContributors = vtxESD->GetNContributors(); | |
1afae8ff | 167 | |
dc740de4 | 168 | // loop over esd tracks |
45e97e28 | 169 | for (Int_t t=0; t<nGoodTracks; t++) |
dc740de4 | 170 | { |
45e97e28 | 171 | AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*> (list->At(t)); |
dc740de4 | 172 | if (!esdTrack) |
173 | { | |
174 | AliDebug(AliLog::kError, Form("ERROR: Could not retrieve track %d.", t)); | |
175 | continue; | |
176 | } | |
177 | ||
74fd10b3 | 178 | Int_t label = TMath::Abs(esdTrack->GetLabel()); |
179 | ||
180 | if (label == 0) | |
181 | { | |
182 | AliDebug(AliLog::kError, Form("Label is 0. Skipping! Track %d.", t)); | |
183 | continue; | |
184 | } | |
185 | ||
186 | TParticle* particle = stack->Particle(label); | |
187 | if (!particle) | |
188 | { | |
189 | AliDebug(AliLog::kError, Form("ERROR: Could not retrieve particle %d.", esdTrack->GetLabel())); | |
190 | continue; | |
191 | } | |
192 | ||
dc740de4 | 193 | Double_t p[3]; |
38233af1 | 194 | esdTrack->GetConstrainedPxPyPz(p); // ### TODO should be okay because we have a vertex, however GetInnerPxPyPy / GetOuterPxPyPy also exist |
dc740de4 | 195 | TVector3 vector(p); |
196 | ||
197 | Float_t theta = vector.Theta(); | |
198 | Float_t eta = -TMath::Log(TMath::Tan(theta/2.)); | |
45e97e28 | 199 | Float_t pt = vector.Pt(); |
200 | ||
74fd10b3 | 201 | //eta = particle->Eta(); |
202 | //pt = particle->Pt(); | |
45e97e28 | 203 | |
74fd10b3 | 204 | fdNdEtaAnalysis->FillTrack(vtx[2], eta, pt); |
dc740de4 | 205 | } // end of track loop |
206 | ||
45e97e28 | 207 | delete list; |
208 | list = 0; | |
209 | ||
dc740de4 | 210 | // for event count per vertex |
74fd10b3 | 211 | fdNdEtaAnalysis->FillEvent(vtx[2], nGoodTracks); |
dc740de4 | 212 | |
213 | return kTRUE; | |
214 | } | |
215 | ||
16e24ca3 | 216 | void AlidNdEtaAnalysisESDSelector::SlaveTerminate() |
217 | { | |
218 | // The SlaveTerminate() function is called after all entries or objects | |
219 | // have been processed. When running with PROOF SlaveTerminate() is called | |
220 | // on each slave server. | |
221 | ||
74fd10b3 | 222 | AliSelectorRL::SlaveTerminate(); |
16e24ca3 | 223 | |
224 | // Add the histograms to the output on each slave server | |
225 | if (!fOutput) | |
226 | { | |
227 | AliDebug(AliLog::kError, Form("ERROR: Output list not initialized.")); | |
228 | return; | |
229 | } | |
230 | ||
38233af1 | 231 | // Add the objects to the output list and set them to 0, so that the destructor does not delete them. |
232 | ||
16e24ca3 | 233 | fOutput->Add(fdNdEtaAnalysis); |
38233af1 | 234 | fdNdEtaAnalysis = 0; |
16e24ca3 | 235 | } |
236 | ||
237 | void AlidNdEtaAnalysisESDSelector::Terminate() | |
dc740de4 | 238 | { |
16e24ca3 | 239 | // The Terminate() function is the last function to be called during |
240 | // a query. It always runs on the client, it can be used to present | |
241 | // the results graphically or save the results to file. | |
242 | ||
74fd10b3 | 243 | AliSelectorRL::Terminate(); |
16e24ca3 | 244 | |
245 | fdNdEtaAnalysis = dynamic_cast<dNdEtaAnalysis*> (fOutput->FindObject("dndeta")); | |
246 | ||
74fd10b3 | 247 | if (!fdNdEtaAnalysis) |
16e24ca3 | 248 | { |
74fd10b3 | 249 | AliDebug(AliLog::kError, "ERROR: Histograms not available"); |
16e24ca3 | 250 | return; |
251 | } | |
252 | ||
74fd10b3 | 253 | TFile* fout = new TFile("analysis_esd_raw.root", "RECREATE"); |
16e24ca3 | 254 | |
255 | if (fdNdEtaAnalysis) | |
256 | fdNdEtaAnalysis->SaveHistograms(); | |
dc740de4 | 257 | |
258 | if (fEsdTrackCuts) | |
259 | fEsdTrackCuts->SaveHistograms("esd_tracks_cuts"); | |
16e24ca3 | 260 | |
261 | fout->Write(); | |
262 | fout->Close(); | |
dc740de4 | 263 | } |