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