Adding simple example to load default debug streamer
[u/mrichter/AliRoot.git] / TPC / AliTPCSelectorTracks.cxx
CommitLineData
10757ee9 1// The class definition in esdClus.h has been generated automatically
2// by the ROOT utility TTree::MakeSelector(). This class is derived
3// from the ROOT class TSelector. For more information on the TSelector
4// framework see $ROOTSYS/README/README.SELECTOR or the ROOT User Manual.
5
6// The following methods are defined in this file:
7// Begin(): called everytime a loop on the tree starts,
8// a convenient place to create your histograms.
9// SlaveBegin(): called after Begin(), when on PROOF called only on the
10// slave servers.
11// Process(): called for each event, in this function you decide what
12// to read and fill your histograms.
13// SlaveTerminate: called at the end of the loop on the tree, when on PROOF
14// called only on the slave servers.
15// Terminate(): called at the end of the loop on the tree,
16// a convenient place to draw/fit your histograms.
17//
18// To use this file, try the following session on your Tree T:
19//
20// Root > T->Process("esdClus.C")
21// Root > T->Process("esdClus.C","some options")
22// Root > T->Process("esdClus.C+")
23//
24// Modification log:
25// 05/11/2006 HH Correct for large pads (outer sectors) in amplitude plots
26
27#include "TSystem.h"
28#include <TPDGCode.h>
29#include <TStyle.h>
30#include "TCint.h"
31#include "TList.h"
32#include "TH1I.h"
33#include "TChain.h"
34//
35#include "AliTracker.h"
36#include "AliMagF.h"
37//
38#include "AliESD.h"
39#include "AliESDEvent.h"
40#include "AliESDtrack.h"
41#include "AliESDfriend.h"
42#include "AliESDfriendTrack.h"
43#include "AliTPCseed.h"
44#include "AliTPCclusterMI.h"
45//
46//
47#include "AliTPCcalibTracks.h"
48#include "AliTPCcalibTracksGain.h"
49
50#include "AliTPCSelectorESD.h"
51#include "AliTPCSelectorTracks.h"
52#include "TProof.h"
53
54const char* AliTPCSelectorTracks::fgkOutputFileName = "Output.root";
55
56
57AliTPCSelectorTracks::AliTPCSelectorTracks(TTree *) :
58 AliTPCSelectorESD(),
59 fInit(kFALSE),
60 fCalibTracks(0),
61 fCalibTracksGain(0)
62{
63 //
64 //
65 //
66 G__SetCatchException(0);
67}
68
69AliTPCSelectorTracks::~AliTPCSelectorTracks(){
70 //
71 //
72 //
73}
74
75void AliTPCSelectorTracks::InitComponent(){
76 //
77 // Init Components
78 //
79 //
80 // USER -COMPONENT definder part
81 //
82 // before calling the process function, two objects have to be added to the chain/tree:
83 // clusterParam, the cluster parametrization and cuts, a AliTPCcalibTracksCuts object
84 // they have to be added in the following manner:
85 // chain->GetUserInfo()->AddLast(clusterParam);
86 // chain->GetUserInfo()->AddLast(cuts);
87 //
88 static Int_t counter=0;
89 if (!fChain){
90 Error("InitComponent","ERROR - chain not initialized\n");
91 }
92 Info("InitComponent",Form("Selector initialization No\t%d\n", counter));
93 counter++;
94 //
95
96
97 AliTPCClusterParam *clusterParam = (AliTPCClusterParam*)fChain->GetUserInfo()->FindObject("AliTPCClusterParam");
98 //
99 if (clusterParam == 0) Error("InitComponent","CLUSTER PARAM NOT FOUND IN CHAIN! \n");
100 //
101 AliTPCcalibTracksCuts *cuts = (AliTPCcalibTracksCuts*)fChain->GetUserInfo()->FindObject("calibTracksCuts");
102 if (cuts != 0) Info("InitComponent","cuts found in fChain! \n");
103 else{
104 Error("InitComponent","CUTS NOT FOUND IN CHAIN\n");
105 }
106 if (clusterParam==0 && fInput){
107 clusterParam = (AliTPCClusterParam*)fInput->FindObject("AliTPCClusterParam");
108 Error("InitComponent","CLUSTER PARAM NOT FOUND IN PROOF\n");
109 }
110 if (cuts==0 &&fInput ){
111 cuts = (AliTPCcalibTracksCuts*)fInput->FindObject("calibTracksCuts");
112 Error("InitComponent","CUTS NOT FOUND IN PROOF\n");
113 }
114 if (!cuts || !clusterParam) {
115 if (fInput) fInput->Print();
116 return;
117 }
118
119 fCalibTracks = new AliTPCcalibTracks("calibTracks", "Resolution calibration object for tracks", clusterParam, cuts);
120 fOutput->AddLast(fCalibTracks);
121
122 AliTPCcalibTracksGain* prevIter = (AliTPCcalibTracksGain*)fChain->GetUserInfo()->FindObject("calibTracksGain");
123 if (!prevIter) Info("InitComponent", "Previous iteration of calibTracksGain not found, continuing without.");
124 TNamed* debugStreamPrefix = (TNamed*)fChain->GetUserInfo()->FindObject("debugStreamPrefix");
125 fCalibTracksGain = new AliTPCcalibTracksGain("calibTracksGain", "Gain calibration object for tracks", cuts, debugStreamPrefix, prevIter);
126 fOutput->AddLast(fCalibTracksGain);
127 fInit=kTRUE;
128}
129
130void AliTPCSelectorTracks::SlaveBegin(TTree * tree)
131{
132 // The SlaveBegin() function is called after the Begin() function.
133 // When running with PROOF SlaveBegin() is called on each slave server.
134 // The tree argument is deprecated (on PROOF 0 is passed).
135
136 AliTPCSelectorESD::SlaveBegin(tree);
137
138 printf(" ***** SlaveBegin ***** \n");
139}
140
141
142void AliTPCSelectorTracks::SlaveTerminate()
143{
144 // The SlaveTerminate() function is called after all entries or objects
145 // have been processed. When running with PROOF SlaveTerminate() is called
146 // on each slave server.
10757ee9 147 if (fCalibTracksGain) fCalibTracksGain->Terminate();
c6f3749a 148 RegisterData();
10757ee9 149}
150
151
152
153
154Int_t AliTPCSelectorTracks::ProcessIn(Long64_t entry)
155{
156 //
157 //
158 //
159 if (!fInit) InitComponent();
160 if (!fInit) return 0;
161 Int_t status = ReadEvent(entry);
162 if (status<0) return status;
163 Int_t ntracks = (fESD) ? fESD->GetNumberOfTracks() : fESDevent->GetNumberOfTracks();
164 //
165 //
166 // USER code to go here
167 //
168 AliTPCseed *seed;
169
170 for (Int_t tr = 0; tr < ntracks; tr++){
171 AliESDtrack *esdTrack = fESD ? (AliESDtrack*) fESD->GetTrack(tr): (AliESDtrack*) fESDevent->GetTrack(tr);
172 AliESDfriendTrack *friendtrack = (AliESDfriendTrack*) esdTrack->GetFriendTrack();
173 seed = 0;
174 TObject *cobject = 0;
175 for (Int_t i = 0; ; i++){
176 cobject = friendtrack->GetCalibObject(i);
177 if (!cobject) break;
178 seed = dynamic_cast<AliTPCseed*>(cobject);
179 if (seed) break;
180 }
181
182 if (seed) {
183 fNClusters->Fill(seed->GetNumberOfClusters());
184 //
c32da879 185 fCalibTracks->Process(seed); // analysis is done in fCalibTracks
10757ee9 186 fCalibTracksGain->Process(seed);
187 }
188 }
189 CleanESD();
190 return 0;
191}
192
193
194void AliTPCSelectorTracks::Terminate()
195{
196 // The Terminate() function is the last function to be called during
197 // a query. It always runs on the client, it can be used to present
198 // the results graphically or save the results to file.
199
200
201 if (!fOutput) return;
202
203 TFile file(fgkOutputFileName, "recreate");
204 fCalibTracksGain = (AliTPCcalibTracksGain*)fOutput->FindObject("calibTracksGain");
205 // evaluate all fitters before saving them, because it doesn't seem to be possible
206 // to evaluate a TLinearFitter after it has been loaded from a root file
207 if (fCalibTracksGain) fCalibTracksGain->Evaluate();
208 fOutput->Write();
209 file.Close();
210 printf("Successfully written file to '%s'.", fgkOutputFileName);
211
212
213 Info("Destructor","Destuctor");
214 //delete fCalibTracksGain;
215 //delete fCalibTracks;
216// printf ("Terminate... \n");
217// if (!fOutput) return;
218// TFile file("Output.root","recreate");
219// printf("fOutput contains the following: \n");
220// fOutput->Print();
221// printf("Trying to write the file 'Output.root'... \n");
222// fOutput->Write();
223// file.Close();
224
225}
226
227