Adding simple example to load default debug streamer
[u/mrichter/AliRoot.git] / TPC / AliAnaTPCTrackBase.cxx
CommitLineData
e2b3cee0 1//\r
2// This class is ment as a base class for doing analysis of\r
3// reconstructed TPC tracks in the AliAnalysisTask framework.\r
4//\r
5// The method FillTrackHistograms should be overloaded by the users\r
6// class and used to make cuts on tracks\r
7//\r
8// Questions, comments, or suggestions can be send to Peter Christiansen (Lund)\r
9// \r
10\r
11// ROOT includes\r
12#include <TChain.h>\r
13#include <TMath.h>\r
14\r
15// ALIROOT includes\r
16#include <AliAnalysisManager.h>\r
17#include <AliESDInputHandler.h>\r
18#include <AliESD.h>\r
19\r
20// STL includes\r
21#include <iostream>\r
3c077364 22//\r
23#include "AliAnaTPCTrackBase.h"\r
24\r
25\r
e2b3cee0 26\r
27using namespace std;\r
28\r
29ClassImp(AliAnaTPCTrackBase)\r
30\r
31//________________________________________________________________________\r
32AliAnaTPCTrackBase::AliAnaTPCTrackBase() : \r
3c077364 33 AliAnalysisTask(), \r
34 fDebug(0), // Debug flag\r
35 fESD(0), \r
36 fESDfriend(0), \r
37 fListOfHists(0),\r
38 fMaxTracks(0), // Max tracks in histogram\r
39 fESDTracks(0), //! N ESD tracks\r
40 fGoodTracks(0) //! GOOD tracks\r
e2b3cee0 41{\r
42 //\r
43 // Default constructor (should not be used)\r
44 //\r
e2b3cee0 45 SetMaxTracks();\r
46}\r
47\r
3c077364 48AliAnaTPCTrackBase::AliAnaTPCTrackBase(const AliAnaTPCTrackBase & ana):\r
49 AliAnalysisTask(ana), \r
50 fDebug(ana.fDebug), // Debug flag\r
51 fESD(ana.fESD), \r
52 fESDfriend(ana.fESDfriend), \r
53 fListOfHists(ana.fListOfHists),\r
54 fMaxTracks(ana.fMaxTracks), // Max tracks in histogram\r
55 fESDTracks(0), //! N ESD tracks\r
56 fGoodTracks(0) //! GOOD tracks\r
57{\r
58 //\r
59 // copy constructor\r
60 // \r
61 fESDTracks = (TH1F*)ana.fESDTracks->Clone(); //! N ESD tracks\r
62 fGoodTracks = (TH1F*)ana.fGoodTracks->Clone(); //! GOOD tracks\r
63}\r
64\r
65\r
66AliAnaTPCTrackBase& AliAnaTPCTrackBase::operator=(const AliAnaTPCTrackBase&ana){\r
67 //\r
68 // assignemnt operator\r
69 //\r
70 if (this != &ana) {\r
71 new (this) AliAnaTPCTrackBase(ana);\r
72 }\r
73 return *this;\r
74\r
75\r
76}\r
77\r
78\r
79\r
e2b3cee0 80//________________________________________________________________________\r
81AliAnaTPCTrackBase::AliAnaTPCTrackBase(const char *name) : \r
82 AliAnalysisTask(name, "AliAnaTPCTrackBase"), \r
3c077364 83 fDebug(0), // Debug flag\r
84 fESD(0), \r
85 fESDfriend(0), \r
86 fListOfHists(0),\r
87 fMaxTracks(0), // Max tracks in histogram\r
88 fESDTracks(0), //! N ESD tracks\r
89 fGoodTracks(0) //! GOOD tracks\r
e2b3cee0 90{\r
91 //\r
92 // Normal constructor\r
93 //\r
94\r
95 // Input slot #0 works with a TChain\r
96 DefineInput(0, TChain::Class());\r
97 // Output slot #0 writes into a TList\r
98 DefineOutput(0, TList::Class());\r
99 \r
100 fDebug = 0;\r
101 SetMaxTracks();\r
102}\r
103\r
104//________________________________________________________________________\r
105void AliAnaTPCTrackBase::ConnectInputData(Option_t *) \r
106{\r
107 //\r
108 // Connect the input data\r
109 //\r
110 if(fDebug>3)\r
111 cout << "AnalysisTaskTPCCluster::ConnectInputData()" << endl;\r
112\r
113 AliESDInputHandler* esdH = (AliESDInputHandler*) \r
114 ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());\r
115 fESD = esdH->GetEvent();\r
116\r
117 if(fESD==0) {\r
118 \r
119 cout << endl << "WARNING: NO ESD event found" << endl << endl;\r
120 } else {\r
121\r
122 fESDfriend = \r
123 (AliESDfriend*)fESD->FindListObject("AliESDfriend"); \r
124 \r
125 if(fESDfriend==0) {\r
126 \r
127 cout << endl << "WARNING: NO ESD friend found" << endl << endl;\r
128 }\r
129 }\r
130}\r
131\r
132//________________________________________________________________________\r
133void AliAnaTPCTrackBase::CreateOutputObjects() \r
134{\r
135 //\r
136 // Connect the output objects\r
137 //\r
138 if(fDebug>3)\r
139 cout << "AnalysisTaskTPCCluster::CreateOutputObjects()" << endl;\r
140 \r
141 OpenFile(0);\r
142 fListOfHists = new TList();\r
143 \r
3c077364 144 fESDTracks = \r
e2b3cee0 145 new TH1F("hESDTracks", \r
146 "Number of ESD tracks per event; N ESD tracks; Counts", \r
147 TMath::Min(fMaxTracks, 100), 0, fMaxTracks);\r
3c077364 148 fListOfHists->Add(fESDTracks);\r
e2b3cee0 149\r
3c077364 150 fGoodTracks = \r
e2b3cee0 151 new TH1F("hGoodTracks", \r
152 "Number of Good tracks per event; N good tracks; Counts", \r
153 TMath::Min(fMaxTracks, 100), 0, fMaxTracks);\r
3c077364 154 fListOfHists->Add(fGoodTracks);\r
e2b3cee0 155}\r
156\r
157\r
158//________________________________________________________________________\r
159void AliAnaTPCTrackBase::Exec(Option_t *) {\r
160 //\r
161 // Execute analysis for current event \r
162 // For the moment I require that mcTruth is there! I am afraid to\r
163 // get out of sync if it is missing for some events since I use the\r
164 // number of MC events for normalisation\r
165 //\r
166\r
167 if(fDebug>3)\r
168 cout << "AliAnaTPCTrackBase::Exec()" << endl;\r
169 \r
170 if(fESD==0 || fESDfriend==0) {\r
171 \r
172 cout << "AliAnaTPCTrackBase::Exec(): WARNING: fESD=" << fESD \r
173 << ", fESDfriend=" << fESDfriend << endl;\r
174 // Post final data. It will be written to a file with option "RECREATE"\r
175 PostData(0, fListOfHists);\r
176 return;\r
177 }\r
178 \r
179 fESD->SetESDfriend(fESDfriend);\r
180 const Int_t nESDTracks = fESD->GetNumberOfTracks();\r
181 \r
182 if(fDebug>0)\r
183 cout << " Number of ESD tracks: " << nESDTracks << endl;\r
184 \r
185 if ( nESDTracks != fESDfriend->GetNumberOfTracks() ) {\r
186 AliWarning("Number of Tracks differs from Number of Friend-Tracks!");\r
187 printf("Number of tracks: %i, number of friend tracks: %i \n", nESDTracks, fESDfriend->GetNumberOfTracks());\r
188 return;\r
189 }\r
190 \r
3c077364 191 fESDTracks->Fill(nESDTracks);\r
e2b3cee0 192 Int_t nGoodTracks = 0;\r
193\r
194 for(Int_t i = 0; i < nESDTracks; i++) {\r
195 \r
196 AliESDtrack* track = (AliESDtrack*)fESD->GetTrack(i);\r
197 AliESDfriendTrack* friendTrack = (AliESDfriendTrack*) track->GetFriendTrack();\r
198 AliTPCseed* seed = 0;\r
199 \r
200 if(friendTrack) {\r
201 TObject *cobject = 0;\r
202 for (Int_t i = 0; ; i++){\r
203 cobject = friendTrack->GetCalibObject(i);\r
204 if (!cobject) break;\r
205 seed = dynamic_cast<AliTPCseed*>(cobject);\r
206 if (seed) break;\r
207 }\r
208 if (!seed && fDebug>1) Error("Exec", "No seed found!!!");\r
209 }\r
210 else if (fDebug>1) Error("Exec", "No friend track found!!!");\r
211\r
212 Int_t accepted = FillTrackHistograms(nESDTracks, track, friendTrack, seed);\r
213\r
214 if(accepted) {\r
215 if(fDebug>1)\r
216 cout << "Track " << i << " was accepted" << endl;\r
217 nGoodTracks++;\r
218 } else {\r
219\r
220 if(fDebug>1)\r
221 cout << "Track " << i << " was rejected" << endl;\r
222 }\r
223 }\r
224 \r
3c077364 225 fGoodTracks->Fill(nGoodTracks);\r
e2b3cee0 226 \r
227 // Post final data. It will be written to a file with option "RECREATE"\r
228 PostData(0, fListOfHists);\r
229} \r
230\r
231//________________________________________________________________________\r
232Int_t AliAnaTPCTrackBase::FillTrackHistograms(Int_t nTracks, AliESDtrack* track, AliESDfriendTrack* friendTrack, AliTPCseed* seed) {\r
233 //\r
234 // This method should be overloaded and used to make cuts on tracks\r
235 // and fill histograms. \r
236 // return 0 if track was rejected, 1 if accepted\r
237 //\r
238\r
239 if(nTracks && track && friendTrack && seed)\r
240 return 1;\r
241 else\r
242 return 0;\r
243}\r
244\r
245//________________________________________________________________________\r
246void AliAnaTPCTrackBase::Terminate(Option_t *) {\r
247 //\r
248 // Terminate loop\r
249 //\r
250 if(fDebug>3)\r
251 printf("AliAnaTPCTrackBase: Terminate() \n");\r
252}\r