]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCAnalysisTaskcalib.cxx
Pseudo code - description
[u/mrichter/AliRoot.git] / TPC / AliTPCAnalysisTaskcalib.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16
17 ///////////////////////////////////////////////////////////////////////////////
18 //                                                                           //
19 // ANALYSIS task to perrorm TPC calibration                                  //
20
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23 #include "AliTPCAnalysisTaskcalib.h"
24 #include "TChain.h"
25 #include "AliTPCcalibBase.h"
26 #include "AliESDEvent.h"
27 #include "AliESDfriend.h"
28 #include "AliESDtrack.h"
29 #include "AliESDfriendTrack.h"
30 #include "AliTPCseed.h"
31 #include "AliESDInputHandler.h"
32 #include "AliAnalysisManager.h"
33
34 ClassImp(AliTPCAnalysisTaskcalib)
35
36
37 AliTPCAnalysisTaskcalib::AliTPCAnalysisTaskcalib()
38   :AliAnalysisTask(),
39    fCalibJobs(0),
40    fESD(0),
41    fESDfriend(0),
42    fDebugOutputPath()
43 {
44   //
45   // default constructor
46   // 
47   
48 }
49
50
51 AliTPCAnalysisTaskcalib::AliTPCAnalysisTaskcalib(const char *name) 
52   :AliAnalysisTask(name,""),
53    fCalibJobs(0),
54    fESD(0),
55    fESDfriend(0),
56    fDebugOutputPath()
57 {
58   //
59   // Constructor
60   //
61   DefineInput(0, TChain::Class());
62   DefineOutput(0, TObjArray::Class());
63   fCalibJobs = new TObjArray(0);
64   fCalibJobs->SetOwner(kTRUE);
65 }
66
67 AliTPCAnalysisTaskcalib::~AliTPCAnalysisTaskcalib() {
68   //
69   // destructor
70   //
71   printf("AliTPCAnalysisTaskcalib::~AliTPCAnalysisTaskcalib");
72   fCalibJobs->Delete();
73 }
74
75 void AliTPCAnalysisTaskcalib::Exec(Option_t *) {
76   //
77   // Exec function
78   // Loop over tracks and call  Process function
79   if (!fESD) {
80     //Printf("ERROR: fESD not available");
81     return;
82   }
83   fESDfriend=static_cast<AliESDfriend*>(fESD->FindListObject("AliESDfriend"));
84   if (!fESDfriend) {
85     //Printf("ERROR: fESDfriend not available");
86     return;
87   }
88   Int_t n=fESD->GetNumberOfTracks();
89   Process(fESD);
90   Int_t run = fESD->GetRunNumber();
91   for (Int_t i=0;i<n;++i) {
92     AliESDfriendTrack *friendTrack=fESDfriend->GetTrack(i);
93     AliESDtrack *track=fESD->GetTrack(i);
94     TObject *calibObject=0;
95     AliTPCseed *seed=0;
96     for (Int_t j=0;(calibObject=friendTrack->GetCalibObject(j));++j)
97       if ((seed=dynamic_cast<AliTPCseed*>(calibObject)))
98         break;
99     if (track) Process(track, run);
100     if (seed)
101       Process(seed);
102   }
103   PostData(0,fCalibJobs);
104 }
105
106 void AliTPCAnalysisTaskcalib::ConnectInputData(Option_t *) {
107   //
108   //
109   //
110   TTree* tree=dynamic_cast<TTree*>(GetInputData(0));
111   if (!tree) {
112     //Printf("ERROR: Could not read chain from input slot 0");
113   } 
114   else {
115     AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
116     if (!esdH) {
117       //Printf("ERROR: Could not get ESDInputHandler");
118     } 
119     else {
120       fESD = esdH->GetEvent();
121       //Printf("*** CONNECTED NEW EVENT ****");
122     }
123   }
124 }
125
126 void AliTPCAnalysisTaskcalib::CreateOutputObjects() {
127   //
128   //
129   //
130   OpenFile(0, "RECREATE");
131 }
132 void AliTPCAnalysisTaskcalib::Terminate(Option_t */*option*/) {
133   //
134   // Terminate
135   //
136   AliTPCcalibBase *job=0;
137   Int_t njobs = fCalibJobs->GetEntriesFast();
138   for (Int_t i=0;i<njobs;i++){
139     job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
140     if (job) job->Terminate();
141   }
142   
143 }
144
145 void AliTPCAnalysisTaskcalib::FinishTaskOutput()
146 {
147   //
148   // According description in AliAnalisysTask this method is call 
149   // on the slaves before sending data
150   //
151   Terminate("slave");
152   RegisterDebugOutput();
153 }
154
155
156 void AliTPCAnalysisTaskcalib::Process(AliESDEvent *event) {
157   //
158   // Process ESD event
159   //
160   AliTPCcalibBase *job=0;
161   Int_t njobs = fCalibJobs->GetEntriesFast();
162   for (Int_t i=0;i<njobs;i++){
163     job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
164     if (job) {
165       job->UpdateEventInfo(event);
166       job->Process(event);
167     }
168   }
169 }
170
171 void AliTPCAnalysisTaskcalib::Process(AliTPCseed *track) {
172   //
173   // Process TPC track
174   //
175   AliTPCcalibBase *job=0;
176   Int_t njobs = fCalibJobs->GetEntriesFast();
177   for (Int_t i=0;i<njobs;i++){
178     job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
179     if (job) job->Process(track);
180   }
181 }
182
183 void AliTPCAnalysisTaskcalib::Process(AliESDtrack *track, Int_t run) {
184   //
185   // Process ESD track
186   //
187   AliTPCcalibBase *job=0;
188   Int_t njobs = fCalibJobs->GetEntriesFast();
189   for (Int_t i=0;i<njobs;i++){
190     job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
191     if (job) job->Process(track,run);
192   }
193 }
194
195 Long64_t AliTPCAnalysisTaskcalib::Merge(TCollection *li) {
196   TIterator *i=fCalibJobs->MakeIterator();
197   AliTPCcalibBase *job;
198   Long64_t n=0;
199   while ((job=dynamic_cast<AliTPCcalibBase*>(i->Next())))
200     n+=job->Merge(li);
201   return n;
202 }
203
204 void AliTPCAnalysisTaskcalib::Analyze() {
205   //
206   // Analyze the content of the task
207   //
208   AliTPCcalibBase *job=0;
209   Int_t njobs = fCalibJobs->GetEntriesFast();
210   for (Int_t i=0;i<njobs;i++){
211     job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
212     if (job) job->Analyze();
213   }
214 }
215
216
217 void AliTPCAnalysisTaskcalib::RegisterDebugOutput(){
218   //
219   //
220   //
221   AliTPCcalibBase *job=0;
222   Int_t njobs = fCalibJobs->GetEntriesFast();
223   for (Int_t i=0;i<njobs;i++){
224     job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
225     if (job) job->RegisterDebugOutput(fDebugOutputPath.Data());
226   }
227  
228 }