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