]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/calibration/AliHLTTPCCalibTimeComponent.cxx
- removed TObjArray for the storing of clusters
[u/mrichter/AliRoot.git] / HLT / TPCLib / calibration / AliHLTTPCCalibTimeComponent.cxx
CommitLineData
33a4976d 1// $Id$
2/**************************************************************************
3 * This file is property of and copyright by the ALICE HLT Project *
4 * ALICE Experiment at CERN, All rights reserved. *
5 * *
6 * Primary Authors: Jochen Thaeder <thaeder@kip.uni-heidelberg.de> *
7 * for The ALICE HLT Project. *
8 * *
9 * Permission to use, copy, modify and distribute this software and its *
10 * documentation strictly for non-commercial purposes is hereby granted *
11 * without fee, provided that the above copyright notice appears in all *
12 * copies and that both the copyright notice and this permission notice *
13 * appear in the supporting documentation. The authors make no claims *
14 * about the suitability of this software for any purpose. It is *
15 * provided "as is" without express or implied warranty. *
16 **************************************************************************/
17
18/** @file AliHLTTPCCalibTimeComponent.cxx
19 @author Kalliopi Kanaki
20 @date 2009-07-08
21 @brief A calibration component for interfacing the offline calculation of TPC drift velocity correction
22*/
23
24// see header file for class documentation
25// or
26// refer to README to build package
27// or
28// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
29
30#if __GNUC__>= 3
31using namespace std;
32#endif
33
84bdcebe 34
33a4976d 35#include "AliHLTTPCCalibTimeComponent.h"
33a4976d 36#include "AliHLTTPCDefinitions.h"
32a71843 37#include "AliHLTMisc.h"
1151db47 38
8677d183 39#include "AliESDEvent.h"
1151db47 40#include "AliESDtrack.h"
421dce74 41#include "AliESDfriend.h"
1151db47 42
43#include "AliTPCcalibTime.h"
bd441ee1 44#include "AliTPCcalibCalib.h"
1151db47 45#include "AliTPCseed.h"
138f8044 46#include "AliTPCcalibDB.h"
47#include "AliTPCClusterParam.h"
8677d183 48
49#include "TObjArray.h"
50#include "TString.h"
138f8044 51#include "TFile.h"
33a4976d 52
84bdcebe 53#include "THnSparse.h"
54#include "TGraphErrors.h"
55
33a4976d 56#include <cstdlib>
57#include <cerrno>
33a4976d 58
84bdcebe 59#include "AliHLTReadoutList.h"
33a4976d 60
61ClassImp(AliHLTTPCCalibTimeComponent) // ROOT macro for the implementation of ROOT specific class methods
62
63AliHLTTPCCalibTimeComponent::AliHLTTPCCalibTimeComponent()
64 :
c849bb8e 65 fCalibTime(NULL)
66 ,fCal(NULL)
67 ,fESDevent(NULL)
68 ,fESDtrack(NULL)
69 ,fESDfriend(NULL)
70 ,fSeedArray(NULL)
71 ,fOutputSize(50000)
33a4976d 72{
73 // see header file for class documentation
74 // or
75 // refer to README to build package
76 // or
77 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
78}
79
c849bb8e 80const char* AliHLTTPCCalibTimeComponent::fgkOCDBEntry="HLT/ConfigTPC/TPCCalibTime";
81
33a4976d 82AliHLTTPCCalibTimeComponent::~AliHLTTPCCalibTimeComponent() {
83// see header file for class documentation
84}
85
86
87const char* AliHLTTPCCalibTimeComponent::GetComponentID() {
88// see header file for class documentation
89
90 return "TPCCalibTime";
91}
92
93void AliHLTTPCCalibTimeComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
94// see header file for class documentation
95
96 list.clear();
1151db47 97 list.push_back( kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC ); // output of TPCCalibSeedMaker
98 list.push_back( kAliHLTDataTypeESDObject|kAliHLTDataOriginOut ); // output of global esd converter
33a4976d 99}
100
101AliHLTComponentDataType AliHLTTPCCalibTimeComponent::GetOutputDataType() {
102// see header file for class documentation
103
1151db47 104 return AliHLTTPCDefinitions::fgkCalibCEDataType|kAliHLTDataOriginOut;
33a4976d 105}
106
107void AliHLTTPCCalibTimeComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
108// see header file for class documentation
109
c849bb8e 110 constBase = fOutputSize;
111 inputMultiplier = 0; // to be estimated
33a4976d 112}
113
114AliHLTComponent* AliHLTTPCCalibTimeComponent::Spawn() {
115// see header file for class documentation
116
117 return new AliHLTTPCCalibTimeComponent();
118}
119
120
c849bb8e 121Int_t AliHLTTPCCalibTimeComponent::ScanConfigurationArgument( Int_t argc, const char** argv ) {
33a4976d 122// see header file for class documentation
c849bb8e 123
124 if (argc<=0) return 0;
125 int i=0;
126 TString argument=argv[i];
127
128 // -output-size
129 if (argument.CompareTo("-output-size")==0) {
130 if (++i>=argc) return -EPROTO;
131 argument=argv[i];
132 fOutputSize=argument.Atof();
133 return 2;
134 }
135 return -EINVAL;
33a4976d 136}
137
138Int_t AliHLTTPCCalibTimeComponent::InitCalibration() {
139// see header file for class documentation
138f8044 140
32a71843 141 //AliTPCcalibDB::Instance()->SetRun(84714);
142 AliTPCcalibDB::Instance()->SetRun(AliHLTMisc::Instance().GetCDBRunNo());
143 AliTPCcalibDB::Instance()->GetClusterParam()->SetInstance(AliTPCcalibDB::Instance()->GetClusterParam());
c849bb8e 144
32a71843 145
146// AliTPCcalibDB *calib = AliTPCcalibDB::Instance();
147//
148// if(!calib){
149// HLTError("AliTPCcalibDB does not exist");
150// return -ENOENT;
151// }
152//
153// AliTPCClusterParam *clusPar = calib->GetClusterParam();
154// if(!clusPar){
155// HLTError("OCDB entry TPC/Calib/ClusterParam (AliTPCcalibDB::GetClusterParam()) is not available.");
156// return -ENOENT;
157// }
c849bb8e 158
159 // first configure the default
160 int iResult=0;
161 if (iResult>=0) iResult=ConfigureFromCDBTObjString(fgkOCDBEntry);
162
163 // configure from the command line parameters if specified
164 //if (iResult>=0 && argc>0) iResult=ConfigureFromArgumentString(argc, argv);
165
33a4976d 166 if(fCalibTime) return EINPROGRESS;
74ad39fa 167 fCal = new AliTPCcalibCalib();
168
c849bb8e 169 return iResult;
170
33a4976d 171}
172
173Int_t AliHLTTPCCalibTimeComponent::DeinitCalibration() {
174// see header file for class documentation
175
518432e2 176 if(fCalibTime) delete fCalibTime; fCalibTime = NULL;
177 if(fCal) delete fCal; fCal = NULL;
138f8044 178 //if(fESDfriend) delete fESDfriend; fESDfriend = NULL;
518432e2 179
33a4976d 180 return 0;
181}
182
c849bb8e 183int AliHLTTPCCalibTimeComponent::Reconfigure(const char* cdbEntry, const char* /*chainId*/){
184// see header file for class documentation
185
186 // configure from the specified antry or the default one
187 const char* entry=cdbEntry;
188 if (!entry || entry[0]==0) {
189 entry=fgkOCDBEntry;
190 }
191
192 return ConfigureFromCDBTObjString(entry);
193}
194
33a4976d 195Int_t AliHLTTPCCalibTimeComponent::ProcessCalibration( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/ ){
196// see header file for class documentation
84bdcebe 197
33a4976d 198 if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )) return 0;
199
1151db47 200 TObject *iter = NULL;
33a4976d 201
1151db47 202 //--------------- output over TObjArray of AliTPCseed objects (output of TPCSeedMaker) -------------------//
203
518432e2 204 // A previous component in the chain (TPCSeedMaker) has processed the TPC clusters and tracks and created a TObjArray of AliTPCseed objects
205 // In this loop the iterator accesses this array stored in memory, in order to use it in the next loop over the AliESDevent of the HLT
206
1151db47 207 for(iter = (TObject*)GetFirstInputObject(kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC); iter != NULL; iter = (TObject*)GetNextInputObject()){
208
209 if(GetDataType(iter) != (kAliHLTDataTypeTObjArray | kAliHLTDataOriginTPC)) continue;
210 fSeedArray = dynamic_cast<TObjArray*>(iter);
211 }
8677d183 212
1151db47 213
214 //----------- loop over output of global esd converter ----------------//
518432e2 215
216 // In this loop we access the AliESDevent that was produced by the HLT and is stored in memory. There should exist 1 object
217 // of type kAliHLTDataTypeESDObject per event.
1151db47 218
219 for(iter = (TObject*)GetFirstInputObject(kAliHLTDataTypeESDObject | kAliHLTDataOriginOut); iter != NULL; iter = (TObject*)GetNextInputObject()){
220
84bdcebe 221 if(GetDataType(iter) != (kAliHLTDataTypeESDObject | kAliHLTDataOriginOut)) continue;
84bdcebe 222
223 fESDevent = dynamic_cast<AliESDEvent*>(iter);
ac517e4d 224 fESDevent->GetStdContent();
84bdcebe 225
226 //fESDevent->SetTimeStamp(1256910155);
ac517e4d 227
518432e2 228 HLTDebug("# Seeds: %i\n", fSeedArray->GetEntriesFast()); // access of the info from the previous loop over the AliTPCseed array
138f8044 229
9dfdf8cc 230 fCal->UpdateEventInfo(fESDevent);
231
8008c07c 232 for(Int_t i=0; i<fSeedArray->GetEntriesFast(); i++){ // loop over TClonesArray
84bdcebe 233
9dfdf8cc 234 AliTPCseed *seed = (AliTPCseed*)fSeedArray->UncheckedAt(i);
84bdcebe 235 fESDtrack = fESDevent->GetTrack(i);
9dfdf8cc 236 if(!fESDtrack || !seed) continue;
9dfdf8cc 237
4d11883f 238 if(fESDtrack->GetID() != seed->GetLabel()) {
239 HLTWarning("Mismatch of track id between seed and ESD track: %i, %i\n", fESDtrack->GetID(), seed->GetLabel());
240 continue;
241 }
8008c07c 242
4d11883f 243 //printf("kelly time calib dedx before update: %f, P: %f\n", seed->CookdEdx(0.02,0.6), seed->P());
244
245 fCal->RefitTrack(fESDtrack, seed, GetBz()); // update AliESDtrack and AliTPCseed info, acccording to Marian's request
246
247 //printf("kelly time calib dedx after update: %f\n", seed->CookdEdx(0.02,0.6));
248
249 AliTPCseed *seedCopy = new AliTPCseed(*seed, kTRUE);
518432e2 250 fESDtrack->AddCalibObject(seedCopy); // add the AliTPCseed as a friend track to the AliESDtrack (to be accessed in TPC/AliTPCcalibTime.cxx)
ac517e4d 251
74ad39fa 252 //fESDfriendTrack = const_cast<AliESDfriendTrack*>(fESDtrack->GetFriendTrack());
ac517e4d 253 }
84bdcebe 254 }
ac517e4d 255
518432e2 256 if(!fCalibTime){ // create the calibration object that will call the offline functions
ac517e4d 257
518432e2 258 Int_t startTime = fESDevent->GetTimeStamp()-60*60*1; //Start time one hour before first event, will make precise cuts later.
259 Int_t endTime = fESDevent->GetTimeStamp()+60*60*23; //End time 23 hours after first event.
260 fCalibTime = new AliTPCcalibTime("calibTime","time dependent Vdrift calibration", startTime, endTime, 20*60);
138f8044 261 fCalibTime->SetStreamLevel(20);
262 fCalibTime->SetDebugLevel(20);
263 printf("fCalibTime = %i, startTime = %i, endTime = %i \n", fCalibTime!=0, startTime, endTime);
84bdcebe 264 }
74ad39fa 265
266 fESDfriend = new AliESDfriend();
267 fESDevent->GetESDfriend(fESDfriend);
268 fESDevent->SetESDfriend(fESDfriend);
518432e2 269 fESDevent->AddObject(fESDfriend);
270 // create the AliESDfriend and add it to the event, now both the friend tracks and the friends are available for the offline functions to be called
84bdcebe 271
518432e2 272 fCalibTime->UpdateEventInfo(fESDevent); // needed for getting the run number and time stamp information correct on the offline side
273 fCalibTime->Process(fESDevent); // first offline function called
274
138f8044 275 // delete fESDfriend;
84bdcebe 276
74ad39fa 277 //PushBack( (TObject*)fCalibTime, AliHLTTPCDefinitions::fgkCalibCEDataType | kAliHLTDataOriginOut, 0x0);
33a4976d 278
279 return 0;
280}
281
282Int_t AliHLTTPCCalibTimeComponent::ShipDataToFXS( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/ ){
283// see header file for class documentation
84bdcebe 284
285 HLTInfo("Shipping data to FXS...\n");
74ad39fa 286
518432e2 287 fCalibTime->Analyze(); // called at the end of the run or event modulo
288
289 // the rest of the histogram and graph declarations were copied by Dag as a first attempt to get the start/end time bin "automatically". Perhaps we need some more
290 // thinking here to avoid copying all these lines that might chain in offline without HLT realizing.
291
292 THnSparse* addHist = fCalibTime->GetHistoDrift("all");
84bdcebe 293 if(!addHist) return -1;
294
295 //Identifying used range of histogram
518432e2 296
297 Int_t startTimeBin = 0;
298 Int_t endTimeBin = 0;
299
300 TH1D *histoTime = addHist->Projection(0);
301 if(histoTime){
302 startTimeBin = histoTime->FindFirstBinAbove(0);
303 endTimeBin = histoTime->FindLastBinAbove(0);
138f8044 304 printf("startTimeBin = %i endTimeBin = %i\n", startTimeBin, endTimeBin);
305 printf("startTimeBinCentre = %f endTimeBinCentre = %f\n", histoTime->GetBinCenter(startTimeBin), histoTime->GetBinCenter(endTimeBin));
306 printf("startTimeBinWidth = %f endTimeBinWidth = %f\n", histoTime->GetBinWidth(startTimeBin), histoTime->GetBinWidth(endTimeBin));
518432e2 307 delete histoTime; histoTime = 0;
84bdcebe 308 }
309
518432e2 310 Int_t startPtBin = 0;
311 Int_t endPtBin = 0;
312 TH1D *histoPt = addHist->Projection(1);
313 if(histoPt){
314 startPtBin = histoPt->FindFirstBinAbove(0);
315 endPtBin = histoPt->FindLastBinAbove(0);
138f8044 316 printf("startPtBin = %i endPtBin = %i\n", startPtBin, endPtBin);
317 printf("startPtBinCentre = %f endPtBinCentre = %f\n", histoPt->GetBinCenter(startPtBin), histoPt->GetBinCenter(endPtBin));
318 printf("startPtinWidth = %f endPtBinWidth = %f\n", histoPt->GetBinWidth(startPtBin), histoPt->GetBinWidth(endPtBin));
518432e2 319 delete histoPt; histoPt = 0;
84bdcebe 320 }
321
518432e2 322 Int_t startVdBin = 0;
323 Int_t endVdBin = 0;
324 TH1D *histoVd = addHist->Projection(2);
325 if(histoVd){
326 startVdBin = histoVd->FindFirstBinAbove(0);
327 endVdBin = histoVd->FindLastBinAbove(0);
138f8044 328 printf("startVdBin = %i endVdBin = %i\n", startVdBin, endVdBin);
329 printf("startVdBinCentre = %f endVdBinCentre = %f\n", histoVd->GetBinCenter(startVdBin), histoVd->GetBinCenter(endVdBin));
330 printf("startVdBinWidth = %f endVdBinWidth = %f\n", histoVd->GetBinWidth(startVdBin), histoVd->GetBinWidth(endVdBin));
518432e2 331 delete histoVd; histoVd = 0;
84bdcebe 332 }
333
518432e2 334 Int_t startRunBin = 0;
335 Int_t endRunBin = 0;
336 TH1D *histoRun = addHist->Projection(3);
337 if(histoRun){
338 startRunBin = histoRun->FindFirstBinAbove(0);
339 endRunBin = histoRun->FindLastBinAbove(0);
340 printf("startRunBin = %i endRunBin = %i\n", startRunBin, endRunBin);
341 printf("startRunBinCentre = %f endRunBinCentre = %f\n", histoRun->GetBinCenter(startRunBin), histoRun->GetBinCenter(endRunBin));
342 printf("startRunBinWidth = %f endRunBinWidth = %f\n", histoRun->GetBinWidth(startRunBin), histoRun->GetBinWidth(endRunBin));
343 delete histoRun; histoRun = 0;
84bdcebe 344 }
345
518432e2 346 TObjArray *vdriftArray = new TObjArray();
84bdcebe 347 if(!vdriftArray) return -2;
348
518432e2 349 TObjArray *array = fCalibTime->GetHistoDrift();
84bdcebe 350 if(!array) return -3;
351
518432e2 352 TIterator *iterator = array->MakeIterator();
84bdcebe 353 if(!iterator) return -4;
354
355 iterator->Reset();
518432e2 356 THnSparse *hist = NULL;
357 while((hist = (THnSparseF*)iterator->Next())){
358
359 if(!hist) continue;
360 hist->Print();
361 hist->GetAxis(0)->SetRange(startTimeBin, endTimeBin);
362 hist->GetAxis(1)->SetRange(startPtBin, endPtBin);
363 hist->GetAxis(0)->SetRange(startVdBin, endVdBin);
364 hist->GetAxis(3)->SetRange(startRunBin, endRunBin);
365
366 TString name = hist->GetName();
367 Int_t dim[4] = {0,1,2,3};
368 THnSparse *newHist = hist->Projection(4,dim);
369 newHist->SetName(name);
370 vdriftArray->Add(newHist);
371
372 TGraphErrors *graph = AliTPCcalibBase::FitSlices(newHist,2,0,400,100,0.05,0.95, kTRUE);
373 printf("name = %s graph = %i\n", name.Data(), graph==0);
374 if(!graph || !graph->GetN()) continue;
375 printf("name = %s graph = %i, N = %i\n", name.Data(), graph==0, graph->GetN());
376 Int_t pos = name.Index("_");
377 name = name(pos,name.Capacity()-pos);
378 TString graphName = graph->ClassName();
379 graphName+=name;
380 graphName.ToUpper();
381 graph->SetName(graphName);
382 printf("name = %s\n", graphName.Data());
383 vdriftArray->Add(graph);
384
385 //Currently, AliSplineFits can not be given names...
386 //AliSplineFit* fit=new AliSplineFit();
387 //fit->SetGraph(graph);
388 //fit->SetMinPoints(graph->GetN()+1);
389 //fit->InitKnots(graph,2,0,0.001);
390 //fit->SplineFit(0);
391 //TString fiName=fit->ClassName();
392 //fiName+=type;
393 //fiName+=trigger;
394 //fiName.ToUpper();
395 //fit->SetName(fiName.Data());
396 //printf("name=%s\n", fiName.Data());
397 //vdriftArray->Add(fit);
84bdcebe 398 }
518432e2 399
400 THnSparse *laserHist = NULL;
401 TGraphErrors *laserGraph = NULL;
402 TString laserName = "";
84bdcebe 403
404 //Histograms and graphs for A side lasers
518432e2 405 laserHist = fCalibTime->GetHistVdriftLaserA(1);
84bdcebe 406 if(laserHist){
518432e2 407
408 laserName=laserHist->ClassName();
409 laserName+="_MEAN_DRIFT_LASER_ALL_A";
410 laserName.ToUpper();
411 laserHist->SetName(laserName);
412 vdriftArray->Add(laserHist);
413 laserGraph=AliTPCcalibBase::FitSlices(laserHist,2,0,400,100,0.05,0.95, kTRUE);
414 if(laserGraph && laserGraph->GetN()){
415 laserName=laserGraph->GetName();
416 laserName+="_MEAN_DRIFT_LASER_ALL_A";
417 laserName.ToUpper();
418 laserGraph->SetName(laserName);
419 vdriftArray->Add(laserGraph);
420 }
84bdcebe 421 }
422
423 //Histograms and graphs for C side lasers
424 laserHist=fCalibTime->GetHistVdriftLaserC(1);
425 if(laserHist){
518432e2 426 laserName=laserHist->ClassName();
427 laserName+="_MEAN_DRIFT_LASER_ALL_C";
428 laserName.ToUpper();
429 laserHist->SetName(laserName);
430 vdriftArray->Add(laserHist);
431 laserGraph=AliTPCcalibBase::FitSlices(laserHist,2,0,400,100,0.05,0.95, kTRUE);
432 if(laserGraph && laserGraph->GetN()){
433 laserName=laserGraph->GetName();
434 laserName+="_MEAN_DRIFT_LASER_ALL_C";
435 laserName.ToUpper();
436 laserGraph->SetName(laserName);
437 vdriftArray->Add(laserGraph);
438 }
84bdcebe 439 }
440
441 //Meatdata set in off-line...
442 //AliCDBMetaData *metaData= new AliCDBMetaData();
443 //metaData->SetObjectClassName("TObjArray");
444 //metaData->SetResponsible("Dag Toppe Larsen");
445 //metaData->SetBeamPeriod(1);
446 //metaData->SetAliRootVersion("05-25-01"); //root version
447 //metaData->SetComment("Calibration of the time dependence of the drift velocity due to pressure and temperature changes");
448 //AliCDBId* id1=NULL;
449 //if(end) id1=new AliCDBId("TPC/Calib/TimeDrift", runNumber, end);
450 //else id1=new AliCDBId("TPC/Calib/TimeDrift", runNumber, runNumber);
451 //AliCDBStorage* gStorage = AliCDBManager::Instance()->GetStorage("local://$ALICE_ROOT/OCDB");
452 //gStorage->Put(vdriftArray, (*id1), metaData);
453 //printf("done runNumber=%i, end=%i\n", runNumber, end);
454
8d53dca2 455 static AliHLTReadoutList rdList(AliHLTReadoutList::kTPC);
518432e2 456
457 // the vdriftArray is pushed to the HLT-FXSsubscriber
138f8044 458 PushToFXS( (TObject*)vdriftArray, "TPC", "TIMEDRIFT", rdList.Buffer() );
74ad39fa 459
84bdcebe 460 //PushToFXS( (TObject*)vdriftArray, "TPC", "Time");
461
138f8044 462 TFile *file = TFile::Open("vdrift.root", "RECREATE");
463 vdriftArray->Write();
464 file->Close();
465 delete file;
466
467 file = TFile::Open("calibTime.root", "RECREATE");
468 fCalibTime->Write();
469 file->Close();
470 delete file;
471
84bdcebe 472 //Should array be deleted now?
473 // if(vdriftArray){
474 // vdriftArray.Clear();
475 // delete vdriftArray;
476 // vdriftArray=0;
477 // }
33a4976d 478
479 return 0;
480}
481