]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/calibration/AliHLTTPCCalibTimeComponent.cxx
correcting memory leaks on error conditions
[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
2d5b943a 49#include "AliHLTTPCOfflineCluster.h"
50#include "AliHLTTPCSpacePointData.h"
51#include "AliHLTTPCTrackletDataFormat.h"
52#include "AliHLTExternalTrackParam.h"
53#include "AliHLTGlobalBarrelTrack.h"
54#include "AliHLTTPCTransform.h"
55
8677d183 56#include "TObjArray.h"
57#include "TString.h"
138f8044 58#include "TFile.h"
33a4976d 59
84bdcebe 60#include "THnSparse.h"
61#include "TGraphErrors.h"
62
33a4976d 63#include <cstdlib>
64#include <cerrno>
33a4976d 65
84bdcebe 66#include "AliHLTReadoutList.h"
33a4976d 67
68ClassImp(AliHLTTPCCalibTimeComponent) // ROOT macro for the implementation of ROOT specific class methods
69
70AliHLTTPCCalibTimeComponent::AliHLTTPCCalibTimeComponent()
71 :
c849bb8e 72 fCalibTime(NULL)
73 ,fCal(NULL)
74 ,fESDevent(NULL)
75 ,fESDtrack(NULL)
76 ,fESDfriend(NULL)
77 ,fSeedArray(NULL)
78 ,fOutputSize(50000)
33a4976d 79{
80 // see header file for class documentation
81 // or
82 // refer to README to build package
83 // or
2d5b943a 84 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
85
86 for(int i=0; i<fkNPartition; i++){
87 fPartitionClusters[i] = 0;
88 fNPartitionClusters[i] = 0;
89 }
33a4976d 90}
91
c849bb8e 92const char* AliHLTTPCCalibTimeComponent::fgkOCDBEntry="HLT/ConfigTPC/TPCCalibTime";
93
2d5b943a 94AliHLTTPCCalibTimeComponent::~AliHLTTPCCalibTimeComponent(){
95// see header file for class documentation
96
97 for(int i=0; i<fkNPartition; i++){
98 delete[] fPartitionClusters[i];
99 }
33a4976d 100}
101
33a4976d 102const char* AliHLTTPCCalibTimeComponent::GetComponentID() {
103// see header file for class documentation
33a4976d 104 return "TPCCalibTime";
105}
106
2d5b943a 107void AliHLTTPCCalibTimeComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list){
33a4976d 108// see header file for class documentation
109
110 list.clear();
1151db47 111 list.push_back( kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC ); // output of TPCCalibSeedMaker
2d5b943a 112 list.push_back( AliHLTTPCDefinitions::fgkClustersDataType ); // output of the TPC CF
113 list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC ); // output of the global merger
1151db47 114 list.push_back( kAliHLTDataTypeESDObject|kAliHLTDataOriginOut ); // output of global esd converter
33a4976d 115}
116
117AliHLTComponentDataType AliHLTTPCCalibTimeComponent::GetOutputDataType() {
118// see header file for class documentation
119
1151db47 120 return AliHLTTPCDefinitions::fgkCalibCEDataType|kAliHLTDataOriginOut;
33a4976d 121}
122
2d5b943a 123void AliHLTTPCCalibTimeComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ){
33a4976d 124// see header file for class documentation
125
c849bb8e 126 constBase = fOutputSize;
127 inputMultiplier = 0; // to be estimated
33a4976d 128}
129
2d5b943a 130AliHLTComponent* AliHLTTPCCalibTimeComponent::Spawn(){
33a4976d 131// see header file for class documentation
132
133 return new AliHLTTPCCalibTimeComponent();
134}
135
136
2d5b943a 137Int_t AliHLTTPCCalibTimeComponent::ScanConfigurationArgument( Int_t argc, const char** argv ){
33a4976d 138// see header file for class documentation
c849bb8e 139
140 if (argc<=0) return 0;
141 int i=0;
142 TString argument=argv[i];
143
144 // -output-size
145 if (argument.CompareTo("-output-size")==0) {
146 if (++i>=argc) return -EPROTO;
147 argument=argv[i];
80d83a65 148 fOutputSize=argument.Atof();
c849bb8e 149 return 2;
150 }
151 return -EINVAL;
33a4976d 152}
153
2d5b943a 154Int_t AliHLTTPCCalibTimeComponent::InitCalibration(){
33a4976d 155// see header file for class documentation
138f8044 156
32a71843 157 AliTPCcalibDB::Instance()->SetRun(AliHLTMisc::Instance().GetCDBRunNo());
158 AliTPCcalibDB::Instance()->GetClusterParam()->SetInstance(AliTPCcalibDB::Instance()->GetClusterParam());
c849bb8e 159
32a71843 160
161// AliTPCcalibDB *calib = AliTPCcalibDB::Instance();
162//
163// if(!calib){
164// HLTError("AliTPCcalibDB does not exist");
165// return -ENOENT;
166// }
167//
168// AliTPCClusterParam *clusPar = calib->GetClusterParam();
169// if(!clusPar){
170// HLTError("OCDB entry TPC/Calib/ClusterParam (AliTPCcalibDB::GetClusterParam()) is not available.");
171// return -ENOENT;
172// }
c849bb8e 173
174 // first configure the default
175 int iResult=0;
176 if (iResult>=0) iResult=ConfigureFromCDBTObjString(fgkOCDBEntry);
c849bb8e 177
33a4976d 178 if(fCalibTime) return EINPROGRESS;
74ad39fa 179 fCal = new AliTPCcalibCalib();
180
2d5b943a 181 fSeedArray = new TObjArray();
182
c849bb8e 183 return iResult;
184
33a4976d 185}
186
187Int_t AliHLTTPCCalibTimeComponent::DeinitCalibration() {
188// see header file for class documentation
189
518432e2 190 if(fCalibTime) delete fCalibTime; fCalibTime = NULL;
191 if(fCal) delete fCal; fCal = NULL;
2d5b943a 192 if(fSeedArray) delete fSeedArray; fSeedArray = NULL;
193
138f8044 194 //if(fESDfriend) delete fESDfriend; fESDfriend = NULL;
518432e2 195
2d5b943a 196 //if(arr) delete arr; arr = NULL;
197
33a4976d 198 return 0;
199}
200
c849bb8e 201int AliHLTTPCCalibTimeComponent::Reconfigure(const char* cdbEntry, const char* /*chainId*/){
202// see header file for class documentation
203
204 // configure from the specified antry or the default one
205 const char* entry=cdbEntry;
2d5b943a 206 if(!entry || entry[0]==0){
c849bb8e 207 entry=fgkOCDBEntry;
208 }
209
210 return ConfigureFromCDBTObjString(entry);
211}
212
33a4976d 213Int_t AliHLTTPCCalibTimeComponent::ProcessCalibration( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/ ){
214// see header file for class documentation
84bdcebe 215
33a4976d 216 if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )) return 0;
217
2d5b943a 218 const AliHLTComponentBlockData *iter = NULL;
33a4976d 219
1151db47 220 //--------------- output over TObjArray of AliTPCseed objects (output of TPCSeedMaker) -------------------//
221
5a36298f 222 // A previous component in the chain (TPCSeedMaker) has processed the TPC clusters and tracks and created a TClonesArray of AliTPCseed objects
518432e2 223 // 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
224
2d5b943a 225// for(iter = (TObject*)GetFirstInputObject(kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC); iter != NULL; iter = (TObject*)GetNextInputObject()){
226//
227// if(GetDataType(iter) != (kAliHLTDataTypeTObjArray | kAliHLTDataOriginTPC)) continue;
228// fSeedArray = dynamic_cast<TClonesArray*>(iter);
229// }
230
231 // int nInputClusters = 0;
232 // int nInputTracks = 0;
233
234 //TObjArray *arr = new TObjArray(1000);
235 //arr->SetOwner(kTRUE);
236 fSeedArray->Clear();
237
238
239 for( int i=0; i<fkNPartition; i++ ){
240 delete[] fPartitionClusters[i];
241 fPartitionClusters[i] = 0;
242 fNPartitionClusters[i] = 0;
243 }
244
245
246
247 //------------------- loop over clusters -------------//
248
249 for(iter = GetFirstInputBlock(AliHLTTPCDefinitions::fgkClustersDataType); iter != NULL; iter = GetNextInputBlock()){
250
251 if ( iter->fDataType != AliHLTTPCDefinitions::fgkClustersDataType ) continue;
252
253 Int_t slice = AliHLTTPCDefinitions::GetMinSliceNr(iter->fSpecification);
254 Int_t partition = AliHLTTPCDefinitions::GetMinPatchNr(iter->fSpecification);
255
256 Int_t slicepartition = slice*6+partition;
257
258 if(slicepartition > fkNPartition){
259 HLTWarning("Wrong header of TPC cluster data, slice %d, partition %d", slice, partition );
260 continue;
261 }
262
263 AliHLTTPCClusterData* inPtrSP = ( AliHLTTPCClusterData* )( iter->fPtr );
264 // nInputClusters += inPtrSP->fSpacePointCnt;
265
266 delete[] fPartitionClusters[slicepartition];
267 fPartitionClusters[slicepartition] = new AliTPCclusterMI[inPtrSP->fSpacePointCnt];
268 fNPartitionClusters[slicepartition] = inPtrSP->fSpacePointCnt;
269
270 // create offline clusters out of the HLT clusters
271 // todo: check which cluster information is really needed for the dEdx
272 for(unsigned int i = 0; i < inPtrSP->fSpacePointCnt; i++){
273 AliHLTTPCSpacePointData *chlt = &( inPtrSP->fSpacePoints[i] );
274 AliTPCclusterMI *c = fPartitionClusters[slicepartition]+i;
275 c->SetX(chlt->fX);
276 c->SetY(chlt->fY);
277 c->SetZ(chlt->fZ);
278 c->SetSigmaY2(chlt->fSigmaY2);
279 c->SetSigmaYZ( 0 );
280 c->SetSigmaZ2(chlt->fSigmaZ2);
281 c->SetQ( chlt->fCharge );
282 c->SetMax( chlt->fQMax );
283 Int_t sector, row;
284 Float_t padtime[3] = {0,chlt->fY,chlt->fZ};
285 AliHLTTPCTransform::Slice2Sector(slice,chlt->fPadRow, sector, row);
286 AliHLTTPCTransform::Local2Raw( padtime, sector, row);
287 c->SetDetector( sector );
288 c->SetRow( row );
289 c->SetPad( (Int_t) padtime[1] );
290 c->SetTimeBin( (Int_t) padtime[2] );
291 }
292 } // end of loop over blocks of clusters
293
294
295
296
297 //---------- loop over merged tracks ------------------ //
298 int nTracks = 0;
299 for(const AliHLTComponentBlockData *pBlock = GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC); pBlock != NULL; pBlock = GetNextInputBlock()){
300
301 AliHLTTracksData *dataPtr = (AliHLTTracksData*) pBlock->fPtr;
302 nTracks = dataPtr->fCount;
303
304 AliHLTExternalTrackParam *currTrack = dataPtr->fTracklets;
305
306 //nInputTracks += nTracks;
307
308 for(int itr=0; itr<nTracks && ( (AliHLTUInt8_t *)currTrack < ((AliHLTUInt8_t *) pBlock->fPtr)+pBlock->fSize); itr++){
309
310 // create an offline track
311 AliHLTGlobalBarrelTrack gb(*currTrack);
312 AliTPCseed tTPC;
313 tTPC.Set(gb.GetX(), gb.GetAlpha(), gb.GetParameter(), gb.GetCovariance());
314
315 // set the cluster pointers
316 for(UInt_t ic=0; ic<currTrack->fNPoints; ic++){
317
318 tTPC.SetNumberOfClusters(currTrack->fNPoints);
319
320 UInt_t id = currTrack->fPointIDs[ic];
a371a266 321 int iSlice = AliHLTTPCSpacePointData::GetSlice(id);
322 int iPartition = AliHLTTPCSpacePointData::GetPatch(id);
323 int iCluster = AliHLTTPCSpacePointData::GetNumber(id);
2d5b943a 324
325 if(iSlice<0 || iSlice>36 || iPartition<0 || iPartition>5){
326 HLTError("Corrupted TPC cluster Id: slice %d, partition %d, cluster %d", iSlice, iPartition, iCluster);
327 continue;
328 }
329
330 AliTPCclusterMI *partitionClusters = fPartitionClusters[iSlice*6 + iPartition];
331
332 if(!partitionClusters){
333 HLTError("Clusters are missed for slice %d, partition %d", iSlice, iPartition );
334 continue;
335 }
336
337 if(iCluster >= fNPartitionClusters[iSlice*6 + iPartition]){
338 HLTError("TPC slice %d, partition %d: ClusterID==%d >= N Clusters==%d ", iSlice, iPartition,iCluster, fNPartitionClusters[iSlice*6 + iPartition]);
339 continue;
340 }
341
342 AliTPCclusterMI *c = &(partitionClusters[iCluster]);
343 int sec = c->GetDetector();
344 int row = c->GetRow();
345 if(sec >= 36) row = row + AliHLTTPCTransform::GetNRowLow();
346
347 tTPC.SetClusterPointer(row, c);
348
349 AliTPCTrackerPoint &point = *( tTPC.GetTrackPoint( row ) );
350 //tTPC.Propagate( TMath::DegToRad()*(sec%18*20.+10.), c->GetX(), fSolenoidBz );
351 Double_t angle2 = tTPC.GetSnp()*tTPC.GetSnp();
352 angle2 = (angle2<1) ?TMath::Sqrt(angle2/(1-angle2)) :10.;
353 point.SetAngleY( angle2 );
354 point.SetAngleZ( tTPC.GetTgl() );
355 } // end of associated cluster loop
356
357 AliTPCseed *seed = &(tTPC);
358 fSeedArray->Add(seed);
359
360 unsigned int step = sizeof( AliHLTExternalTrackParam ) + currTrack->fNPoints * sizeof( unsigned int );
361 currTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currTrack) + step );
362
363 }// end of vector track loop
364 } // end of loop over blocks of merged tracks
365
366 HLTInfo("Number of reconstructed tracks %d, number of produced seeds %d\n", nTracks, fSeedArray->GetEntries());
8677d183 367
1151db47 368
369 //----------- loop over output of global esd converter ----------------//
518432e2 370
371 // In this loop we access the AliESDevent that was produced by the HLT and is stored in memory. There should exist 1 object
372 // of type kAliHLTDataTypeESDObject per event.
1151db47 373
2d5b943a 374 TObject *iterOb = NULL;
375 for(iterOb = (TObject*)GetFirstInputObject(kAliHLTDataTypeESDObject | kAliHLTDataOriginOut); iterOb != NULL; iterOb = (TObject*)GetNextInputObject()){
1151db47 376
2d5b943a 377 if(GetDataType(iterOb) != (kAliHLTDataTypeESDObject | kAliHLTDataOriginOut)) continue;
84bdcebe 378
2d5b943a 379 fESDevent = dynamic_cast<AliESDEvent*>(iterOb);
380 fESDevent->GetStdContent();
381
382 HLTInfo("Number of seeds: %i\n", fSeedArray->GetEntriesFast()); // access of the info from the previous loop over the AliTPCseed array
383
384 fCal->UpdateEventInfo(fESDevent);
385 for(Int_t i=0; i<fSeedArray->GetEntriesFast(); i++){ // loop over TObjArray with seeds
386
387 AliTPCseed *seed = (AliTPCseed*)fSeedArray->UncheckedAt(i);
388 fESDtrack = fESDevent->GetTrack(i);
389 if(!fESDtrack || !seed) continue;
390
391 //if(fESDtrack->GetID() != seed->GetLabel()) {
392 // HLTWarning("Mismatch of track id between seed and ESD track: %i, %i\n", fESDtrack->GetID(), seed->GetLabel());
393 // continue;
394 //}
395
396 if(seed->GetNumberOfClusters()==0) continue;
397 fCal->RefitTrack(fESDtrack, seed, GetBz()); // update AliESDtrack and AliTPCseed info, acccording to Marian's request
398
399 AliTPCseed *seedCopy = new AliTPCseed(*seed, kTRUE);
400 fESDtrack->AddCalibObject(seedCopy); // add the AliTPCseed as a friend track to the AliESDtrack (to be accessed in TPC/AliTPCcalibTime.cxx)
8008c07c 401
2d5b943a 402 //fESDfriendTrack = const_cast<AliESDfriendTrack*>(fESDtrack->GetFriendTrack());
403 }
84bdcebe 404 }
ac517e4d 405
518432e2 406 if(!fCalibTime){ // create the calibration object that will call the offline functions
ac517e4d 407
518432e2 408 Int_t startTime = fESDevent->GetTimeStamp()-60*60*1; //Start time one hour before first event, will make precise cuts later.
409 Int_t endTime = fESDevent->GetTimeStamp()+60*60*23; //End time 23 hours after first event.
410 fCalibTime = new AliTPCcalibTime("calibTime","time dependent Vdrift calibration", startTime, endTime, 20*60);
138f8044 411 fCalibTime->SetStreamLevel(20);
412 fCalibTime->SetDebugLevel(20);
413 printf("fCalibTime = %i, startTime = %i, endTime = %i \n", fCalibTime!=0, startTime, endTime);
84bdcebe 414 }
74ad39fa 415
416 fESDfriend = new AliESDfriend();
417 fESDevent->GetESDfriend(fESDfriend);
418 fESDevent->SetESDfriend(fESDfriend);
518432e2 419 fESDevent->AddObject(fESDfriend);
420 // 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 421
518432e2 422 fCalibTime->UpdateEventInfo(fESDevent); // needed for getting the run number and time stamp information correct on the offline side
423 fCalibTime->Process(fESDevent); // first offline function called
424
138f8044 425 // delete fESDfriend;
84bdcebe 426
74ad39fa 427 //PushBack( (TObject*)fCalibTime, AliHLTTPCDefinitions::fgkCalibCEDataType | kAliHLTDataOriginOut, 0x0);
33a4976d 428
429 return 0;
430}
431
432Int_t AliHLTTPCCalibTimeComponent::ShipDataToFXS( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/ ){
433// see header file for class documentation
84bdcebe 434
435 HLTInfo("Shipping data to FXS...\n");
74ad39fa 436
518432e2 437 fCalibTime->Analyze(); // called at the end of the run or event modulo
438
439 // 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
440 // thinking here to avoid copying all these lines that might chain in offline without HLT realizing.
441
442 THnSparse* addHist = fCalibTime->GetHistoDrift("all");
84bdcebe 443 if(!addHist) return -1;
444
445 //Identifying used range of histogram
518432e2 446
447 Int_t startTimeBin = 0;
448 Int_t endTimeBin = 0;
449
450 TH1D *histoTime = addHist->Projection(0);
451 if(histoTime){
452 startTimeBin = histoTime->FindFirstBinAbove(0);
453 endTimeBin = histoTime->FindLastBinAbove(0);
138f8044 454 printf("startTimeBin = %i endTimeBin = %i\n", startTimeBin, endTimeBin);
455 printf("startTimeBinCentre = %f endTimeBinCentre = %f\n", histoTime->GetBinCenter(startTimeBin), histoTime->GetBinCenter(endTimeBin));
456 printf("startTimeBinWidth = %f endTimeBinWidth = %f\n", histoTime->GetBinWidth(startTimeBin), histoTime->GetBinWidth(endTimeBin));
518432e2 457 delete histoTime; histoTime = 0;
84bdcebe 458 }
459
518432e2 460 Int_t startPtBin = 0;
461 Int_t endPtBin = 0;
462 TH1D *histoPt = addHist->Projection(1);
463 if(histoPt){
464 startPtBin = histoPt->FindFirstBinAbove(0);
465 endPtBin = histoPt->FindLastBinAbove(0);
138f8044 466 printf("startPtBin = %i endPtBin = %i\n", startPtBin, endPtBin);
467 printf("startPtBinCentre = %f endPtBinCentre = %f\n", histoPt->GetBinCenter(startPtBin), histoPt->GetBinCenter(endPtBin));
468 printf("startPtinWidth = %f endPtBinWidth = %f\n", histoPt->GetBinWidth(startPtBin), histoPt->GetBinWidth(endPtBin));
518432e2 469 delete histoPt; histoPt = 0;
84bdcebe 470 }
471
518432e2 472 Int_t startVdBin = 0;
473 Int_t endVdBin = 0;
474 TH1D *histoVd = addHist->Projection(2);
475 if(histoVd){
476 startVdBin = histoVd->FindFirstBinAbove(0);
477 endVdBin = histoVd->FindLastBinAbove(0);
138f8044 478 printf("startVdBin = %i endVdBin = %i\n", startVdBin, endVdBin);
479 printf("startVdBinCentre = %f endVdBinCentre = %f\n", histoVd->GetBinCenter(startVdBin), histoVd->GetBinCenter(endVdBin));
480 printf("startVdBinWidth = %f endVdBinWidth = %f\n", histoVd->GetBinWidth(startVdBin), histoVd->GetBinWidth(endVdBin));
518432e2 481 delete histoVd; histoVd = 0;
84bdcebe 482 }
483
518432e2 484 Int_t startRunBin = 0;
485 Int_t endRunBin = 0;
486 TH1D *histoRun = addHist->Projection(3);
487 if(histoRun){
488 startRunBin = histoRun->FindFirstBinAbove(0);
489 endRunBin = histoRun->FindLastBinAbove(0);
490 printf("startRunBin = %i endRunBin = %i\n", startRunBin, endRunBin);
491 printf("startRunBinCentre = %f endRunBinCentre = %f\n", histoRun->GetBinCenter(startRunBin), histoRun->GetBinCenter(endRunBin));
492 printf("startRunBinWidth = %f endRunBinWidth = %f\n", histoRun->GetBinWidth(startRunBin), histoRun->GetBinWidth(endRunBin));
493 delete histoRun; histoRun = 0;
84bdcebe 494 }
495
518432e2 496 TObjArray *vdriftArray = new TObjArray();
84bdcebe 497 if(!vdriftArray) return -2;
498
518432e2 499 TObjArray *array = fCalibTime->GetHistoDrift();
84bdcebe 500 if(!array) return -3;
501
518432e2 502 TIterator *iterator = array->MakeIterator();
84bdcebe 503 if(!iterator) return -4;
504
505 iterator->Reset();
518432e2 506 THnSparse *hist = NULL;
507 while((hist = (THnSparseF*)iterator->Next())){
508
509 if(!hist) continue;
510 hist->Print();
511 hist->GetAxis(0)->SetRange(startTimeBin, endTimeBin);
512 hist->GetAxis(1)->SetRange(startPtBin, endPtBin);
513 hist->GetAxis(0)->SetRange(startVdBin, endVdBin);
514 hist->GetAxis(3)->SetRange(startRunBin, endRunBin);
515
516 TString name = hist->GetName();
517 Int_t dim[4] = {0,1,2,3};
518 THnSparse *newHist = hist->Projection(4,dim);
519 newHist->SetName(name);
520 vdriftArray->Add(newHist);
521
522 TGraphErrors *graph = AliTPCcalibBase::FitSlices(newHist,2,0,400,100,0.05,0.95, kTRUE);
523 printf("name = %s graph = %i\n", name.Data(), graph==0);
524 if(!graph || !graph->GetN()) continue;
525 printf("name = %s graph = %i, N = %i\n", name.Data(), graph==0, graph->GetN());
526 Int_t pos = name.Index("_");
527 name = name(pos,name.Capacity()-pos);
528 TString graphName = graph->ClassName();
529 graphName+=name;
530 graphName.ToUpper();
531 graph->SetName(graphName);
532 printf("name = %s\n", graphName.Data());
533 vdriftArray->Add(graph);
534
535 //Currently, AliSplineFits can not be given names...
536 //AliSplineFit* fit=new AliSplineFit();
537 //fit->SetGraph(graph);
538 //fit->SetMinPoints(graph->GetN()+1);
539 //fit->InitKnots(graph,2,0,0.001);
540 //fit->SplineFit(0);
541 //TString fiName=fit->ClassName();
542 //fiName+=type;
543 //fiName+=trigger;
544 //fiName.ToUpper();
545 //fit->SetName(fiName.Data());
546 //printf("name=%s\n", fiName.Data());
547 //vdriftArray->Add(fit);
84bdcebe 548 }
518432e2 549
550 THnSparse *laserHist = NULL;
551 TGraphErrors *laserGraph = NULL;
552 TString laserName = "";
84bdcebe 553
554 //Histograms and graphs for A side lasers
518432e2 555 laserHist = fCalibTime->GetHistVdriftLaserA(1);
84bdcebe 556 if(laserHist){
518432e2 557
558 laserName=laserHist->ClassName();
559 laserName+="_MEAN_DRIFT_LASER_ALL_A";
560 laserName.ToUpper();
561 laserHist->SetName(laserName);
562 vdriftArray->Add(laserHist);
563 laserGraph=AliTPCcalibBase::FitSlices(laserHist,2,0,400,100,0.05,0.95, kTRUE);
564 if(laserGraph && laserGraph->GetN()){
565 laserName=laserGraph->GetName();
566 laserName+="_MEAN_DRIFT_LASER_ALL_A";
567 laserName.ToUpper();
568 laserGraph->SetName(laserName);
569 vdriftArray->Add(laserGraph);
570 }
84bdcebe 571 }
572
573 //Histograms and graphs for C side lasers
574 laserHist=fCalibTime->GetHistVdriftLaserC(1);
575 if(laserHist){
518432e2 576 laserName=laserHist->ClassName();
577 laserName+="_MEAN_DRIFT_LASER_ALL_C";
578 laserName.ToUpper();
579 laserHist->SetName(laserName);
580 vdriftArray->Add(laserHist);
581 laserGraph=AliTPCcalibBase::FitSlices(laserHist,2,0,400,100,0.05,0.95, kTRUE);
582 if(laserGraph && laserGraph->GetN()){
583 laserName=laserGraph->GetName();
584 laserName+="_MEAN_DRIFT_LASER_ALL_C";
585 laserName.ToUpper();
586 laserGraph->SetName(laserName);
587 vdriftArray->Add(laserGraph);
588 }
84bdcebe 589 }
590
591 //Meatdata set in off-line...
592 //AliCDBMetaData *metaData= new AliCDBMetaData();
593 //metaData->SetObjectClassName("TObjArray");
594 //metaData->SetResponsible("Dag Toppe Larsen");
595 //metaData->SetBeamPeriod(1);
596 //metaData->SetAliRootVersion("05-25-01"); //root version
597 //metaData->SetComment("Calibration of the time dependence of the drift velocity due to pressure and temperature changes");
598 //AliCDBId* id1=NULL;
599 //if(end) id1=new AliCDBId("TPC/Calib/TimeDrift", runNumber, end);
600 //else id1=new AliCDBId("TPC/Calib/TimeDrift", runNumber, runNumber);
601 //AliCDBStorage* gStorage = AliCDBManager::Instance()->GetStorage("local://$ALICE_ROOT/OCDB");
602 //gStorage->Put(vdriftArray, (*id1), metaData);
603 //printf("done runNumber=%i, end=%i\n", runNumber, end);
604
8d53dca2 605 static AliHLTReadoutList rdList(AliHLTReadoutList::kTPC);
518432e2 606
84bdcebe 607
138f8044 608 TFile *file = TFile::Open("vdrift.root", "RECREATE");
609 vdriftArray->Write();
610 file->Close();
611 delete file;
612
613 file = TFile::Open("calibTime.root", "RECREATE");
614 fCalibTime->Write();
615 file->Close();
616 delete file;
2d5b943a 617
618 // the vdriftArray is pushed to the HLT-FXSsubscriber
89413559 619 PushToFXS( (TObject*)vdriftArray, "TPC", "TIMEDRIFT", &rdList );
2d5b943a 620
84bdcebe 621 //Should array be deleted now?
622 // if(vdriftArray){
623 // vdriftArray.Clear();
624 // delete vdriftArray;
625 // vdriftArray=0;
626 // }
33a4976d 627
628 return 0;
629}
630