*** V interface for TPCCalibTasks ***
[u/mrichter/AliRoot.git] / TPC / Calib / AliTPCAnalysisTaskcalib.cxx
CommitLineData
73d51118 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// //
fc492d0d 19// ANALYSIS task to perrorm TPC calibration //
20
73d51118 21// //
22///////////////////////////////////////////////////////////////////////////////
23#include "AliTPCAnalysisTaskcalib.h"
24#include "TChain.h"
25#include "AliTPCcalibBase.h"
26#include "AliESDEvent.h"
27#include "AliESDfriend.h"
f7f33dec 28#include "AliESDtrack.h"
73d51118 29#include "AliESDfriendTrack.h"
30#include "AliTPCseed.h"
31#include "AliESDInputHandler.h"
e3d1b1e2 32
33#include "AliVEvent.h"
34#include "AliVfriendEvent.h"
35#include "AliVTrack.h"
36#include "AliVfriendTrack.h"
37#include "AliVEventHandler.h"
38
73d51118 39#include "AliAnalysisManager.h"
679480d0 40#include "TFile.h"
41#include "TSystem.h"
42#include "TTimeStamp.h"
73d51118 43
44ClassImp(AliTPCAnalysisTaskcalib)
45
f7f33dec 46
47AliTPCAnalysisTaskcalib::AliTPCAnalysisTaskcalib()
48 :AliAnalysisTask(),
49 fCalibJobs(0),
e3d1b1e2 50 fEvent(0),
51 fEventFriend(0),
5647625c 52 fDebugOutputPath("")
f7f33dec 53{
54 //
55 // default constructor
56 //
57
58}
59
60
73d51118 61AliTPCAnalysisTaskcalib::AliTPCAnalysisTaskcalib(const char *name)
62 :AliAnalysisTask(name,""),
63 fCalibJobs(0),
e3d1b1e2 64 fEvent(0),
65 fEventFriend(0),
5647625c 66 fDebugOutputPath("")
73d51118 67{
68 //
69 // Constructor
70 //
71 DefineInput(0, TChain::Class());
08669268 72 DefineOutput(0, AliTPCcalibBase::Class());
73 DefineOutput(1, AliTPCcalibBase::Class());
74 DefineOutput(2, AliTPCcalibBase::Class());
75 DefineOutput(3, AliTPCcalibBase::Class());
76 DefineOutput(4, AliTPCcalibBase::Class());
77 DefineOutput(5, AliTPCcalibBase::Class());
f7f33dec 78 fCalibJobs = new TObjArray(0);
42a48f93 79 fCalibJobs->SetOwner(kTRUE);
73d51118 80}
81
82AliTPCAnalysisTaskcalib::~AliTPCAnalysisTaskcalib() {
83 //
84 // destructor
85 //
f7f33dec 86 printf("AliTPCAnalysisTaskcalib::~AliTPCAnalysisTaskcalib");
edb92719 87 fCalibJobs->Delete();
73d51118 88}
89
90void AliTPCAnalysisTaskcalib::Exec(Option_t *) {
91 //
92 // Exec function
93 // Loop over tracks and call Process function
e3d1b1e2 94 //Printf("AliTPCAnalysisTaskcalib::Exec()...");
95
96 if (!fEvent) {
97 Printf("ERROR AliTPCAnalysisTaskcalib::Exec(): fEvent not available");
73d51118 98 return;
99 }
e3d1b1e2 100 fEventFriend=fEvent->FindFriend();
50ff8c36 101 //fESDfriend=fESD->FindFriend();
e3d1b1e2 102 Int_t n=fEvent->GetNumberOfTracks();
103 Process(fEvent);
104 if (!fEventFriend) {
105 //Printf("ERROR AliTPCAnalysisTaskcalib::Exec(): fEventFriend not available");
73d51118 106 return;
107 }
e3d1b1e2 108 if (fEventFriend->TestSkipBit()) return;
556a6343 109 //
e3d1b1e2 110 Int_t run = fEvent->GetRunNumber();
73d51118 111 for (Int_t i=0;i<n;++i) {
e3d1b1e2 112 const AliVfriendTrack *friendTrack=fEventFriend->GetTrack(i);
113 AliVTrack *track=fEvent->GetVTrack(i);
0db06ea6 114 TObject *calibObject=0;
73d51118 115 AliTPCseed *seed=0;
1f3b7de0 116 if (!friendTrack) continue;
0db06ea6 117 for (Int_t j=0;(calibObject=friendTrack->GetCalibObject(j));++j)
118 if ((seed=dynamic_cast<AliTPCseed*>(calibObject)))
73d51118 119 break;
5822e507 120 if (track) Process(track, run);
73d51118 121 if (seed)
122 Process(seed);
123 }
73d51118 124}
125
126void AliTPCAnalysisTaskcalib::ConnectInputData(Option_t *) {
127 //
128 //
129 //
130 TTree* tree=dynamic_cast<TTree*>(GetInputData(0));
131 if (!tree) {
2acad464 132 //Printf("ERROR: Could not read chain from input slot 0");
73d51118 133 }
134 else {
e3d1b1e2 135 //AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
136 AliVEventHandler *esdH = AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler();
73d51118 137 if (!esdH) {
e3d1b1e2 138 Printf("ERROR: Could not get ESDInputHandler");
73d51118 139 }
140 else {
e3d1b1e2 141 fEvent = esdH->GetEvent();
684602c8 142 //Printf("*** CONNECTED NEW EVENT ****");
73d51118 143 }
144 }
145}
146
147void AliTPCAnalysisTaskcalib::CreateOutputObjects() {
148 //
149 //
150 //
54b8f8e1 151 //OpenFile(0, "RECREATE");
77d31cb8 152
08669268 153 for (Int_t i=0; i<fCalibJobs->GetEntries(); i++)
154 {
155 if (fCalibJobs->At(i))
156 PostData(i,(AliTPCcalibBase*)fCalibJobs->At(i));
157 }
73d51118 158}
77d31cb8 159
0db06ea6 160void AliTPCAnalysisTaskcalib::Terminate(Option_t */*option*/) {
7eaa723e 161 //
08825fb4 162 // Terminate
7eaa723e 163 //
08825fb4 164 AliTPCcalibBase *job=0;
f7f33dec 165 Int_t njobs = fCalibJobs->GetEntriesFast();
08825fb4 166 for (Int_t i=0;i<njobs;i++){
f7f33dec 167 job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
08825fb4 168 if (job) job->Terminate();
7eaa723e 169 }
42a48f93 170
73d51118 171}
172
f7f33dec 173void AliTPCAnalysisTaskcalib::FinishTaskOutput()
174{
175 //
176 // According description in AliAnalisysTask this method is call
177 // on the slaves before sending data
178 //
179 Terminate("slave");
5647625c 180 if(!fDebugOutputPath.IsNull()) {
181 RegisterDebugOutput();
182 }
679480d0 183
f7f33dec 184}
185
186
e3d1b1e2 187void AliTPCAnalysisTaskcalib::Process(AliVEvent *event) {
08825fb4 188 //
189 // Process ESD event
190 //
e3d1b1e2 191 //Printf("AliTPCAnalysisTaskcalib::Process(event)...");
08825fb4 192 AliTPCcalibBase *job=0;
f7f33dec 193 Int_t njobs = fCalibJobs->GetEntriesFast();
08825fb4 194 for (Int_t i=0;i<njobs;i++){
f7f33dec 195 job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
42a48f93 196 if (job) {
197 job->UpdateEventInfo(event);
c51653e8 198 if (job->AcceptTrigger())
199 job->Process(event);
42a48f93 200 }
08825fb4 201 }
73d51118 202}
203
204void AliTPCAnalysisTaskcalib::Process(AliTPCseed *track) {
08825fb4 205 //
206 // Process TPC track
207 //
e3d1b1e2 208 //Printf("AliTPCAnalysisTaskcalib::Process(TPC track)...");
08825fb4 209 AliTPCcalibBase *job=0;
f7f33dec 210 Int_t njobs = fCalibJobs->GetEntriesFast();
08825fb4 211 for (Int_t i=0;i<njobs;i++){
f7f33dec 212 job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
c51653e8 213 if (job)
214 if (job->AcceptTrigger())
215 job->Process(track);
f7f33dec 216 }
217}
218
e3d1b1e2 219void AliTPCAnalysisTaskcalib::Process(AliVTrack *track, Int_t run) {
f7f33dec 220 //
221 // Process ESD track
222 //
e3d1b1e2 223 //Printf("AliTPCAnalysisTaskcalib::Process(ESD track)...");
f7f33dec 224 AliTPCcalibBase *job=0;
225 Int_t njobs = fCalibJobs->GetEntriesFast();
226 for (Int_t i=0;i<njobs;i++){
227 job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
c51653e8 228 if (job)
229 if (job->AcceptTrigger())
230 job->Process(track,run);
08825fb4 231 }
73d51118 232}
233
234Long64_t AliTPCAnalysisTaskcalib::Merge(TCollection *li) {
f7f33dec 235 TIterator *i=fCalibJobs->MakeIterator();
73d51118 236 AliTPCcalibBase *job;
237 Long64_t n=0;
0db06ea6 238 while ((job=dynamic_cast<AliTPCcalibBase*>(i->Next())))
73d51118 239 n+=job->Merge(li);
240 return n;
241}
242
243void AliTPCAnalysisTaskcalib::Analyze() {
08825fb4 244 //
245 // Analyze the content of the task
246 //
247 AliTPCcalibBase *job=0;
f7f33dec 248 Int_t njobs = fCalibJobs->GetEntriesFast();
08825fb4 249 for (Int_t i=0;i<njobs;i++){
f7f33dec 250 job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
08825fb4 251 if (job) job->Analyze();
252 }
73d51118 253}
f7f33dec 254
255
256void AliTPCAnalysisTaskcalib::RegisterDebugOutput(){
257 //
258 //
259 //
260 AliTPCcalibBase *job=0;
261 Int_t njobs = fCalibJobs->GetEntriesFast();
262 for (Int_t i=0;i<njobs;i++){
263 job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
264 if (job) job->RegisterDebugOutput(fDebugOutputPath.Data());
265 }
86cd06f0 266 TString dsName=GetName();
267 dsName+=".root";
268 TFile fff(dsName.Data(),"recreate");
c51653e8 269 fCalibJobs->Write("TPCCalib",TObject::kSingleKey);
679480d0 270 fff.Close();
271 //
272 // store - copy debug output to the destination position
273 // currently ONLY for local copy
679480d0 274 TString dsName2=fDebugOutputPath.Data();
275 gSystem->MakeDirectory(dsName2.Data());
276 dsName2+=gSystem->HostName();
277 gSystem->MakeDirectory(dsName2.Data());
278 dsName2+="/";
279 TTimeStamp s;
280 dsName2+=Int_t(s.GetNanoSec());
281 dsName2+="/";
282 gSystem->MakeDirectory(dsName2.Data());
283 dsName2+=dsName;
284 AliInfo(Form("copy %s\t%s\n",dsName.Data(),dsName2.Data()));
285 printf("copy %s\t%s\n",dsName.Data(),dsName2.Data());
286 TFile::Cp(dsName.Data(),dsName2.Data());
287
f7f33dec 288}