2 /**************************************************************************
3 * This file is property of and copyright by the ALICE HLT Project *
4 * ALICE Experiment at CERN, All rights reserved. *
6 * Primary Authors: Jochen Thaeder <thaeder@kip.uni-heidelberg.de> *
7 * for The ALICE HLT Project. *
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 **************************************************************************/
18 /** @file AliHLTTPCCalibTimeComponent.cxx
19 @author Kalliopi Kanaki
21 @brief A calibration component for interfacing the offline calculation of TPC drift velocity correction
24 // see header file for class documentation
26 // refer to README to build package
28 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
35 #include "AliHLTTPCCalibTimeComponent.h"
36 #include "AliHLTTPCDefinitions.h"
37 #include "AliHLTMisc.h"
39 #include "AliESDEvent.h"
40 #include "AliESDtrack.h"
41 #include "AliESDfriend.h"
43 #include "AliTPCcalibTime.h"
44 #include "AliTPCcalibCalib.h"
45 #include "AliTPCseed.h"
46 #include "AliTPCcalibDB.h"
47 #include "AliTPCClusterParam.h"
49 #include "TObjArray.h"
53 #include "THnSparse.h"
54 #include "TGraphErrors.h"
59 #include "AliHLTReadoutList.h"
61 ClassImp(AliHLTTPCCalibTimeComponent) // ROOT macro for the implementation of ROOT specific class methods
63 AliHLTTPCCalibTimeComponent::AliHLTTPCCalibTimeComponent()
73 // see header file for class documentation
75 // refer to README to build package
77 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
80 const char* AliHLTTPCCalibTimeComponent::fgkOCDBEntry="HLT/ConfigTPC/TPCCalibTime";
82 AliHLTTPCCalibTimeComponent::~AliHLTTPCCalibTimeComponent() {
83 // see header file for class documentation
87 const char* AliHLTTPCCalibTimeComponent::GetComponentID() {
88 // see header file for class documentation
90 return "TPCCalibTime";
93 void AliHLTTPCCalibTimeComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
94 // see header file for class documentation
97 list.push_back( kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC ); // output of TPCCalibSeedMaker
98 list.push_back( kAliHLTDataTypeESDObject|kAliHLTDataOriginOut ); // output of global esd converter
101 AliHLTComponentDataType AliHLTTPCCalibTimeComponent::GetOutputDataType() {
102 // see header file for class documentation
104 return AliHLTTPCDefinitions::fgkCalibCEDataType|kAliHLTDataOriginOut;
107 void AliHLTTPCCalibTimeComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
108 // see header file for class documentation
110 constBase = fOutputSize;
111 inputMultiplier = 0; // to be estimated
114 AliHLTComponent* AliHLTTPCCalibTimeComponent::Spawn() {
115 // see header file for class documentation
117 return new AliHLTTPCCalibTimeComponent();
121 Int_t AliHLTTPCCalibTimeComponent::ScanConfigurationArgument( Int_t argc, const char** argv ) {
122 // see header file for class documentation
124 if (argc<=0) return 0;
126 TString argument=argv[i];
129 if (argument.CompareTo("-output-size")==0) {
130 if (++i>=argc) return -EPROTO;
132 fOutputSize=argument.Atof();
138 Int_t AliHLTTPCCalibTimeComponent::InitCalibration() {
139 // see header file for class documentation
141 //AliTPCcalibDB::Instance()->SetRun(84714);
142 AliTPCcalibDB::Instance()->SetRun(AliHLTMisc::Instance().GetCDBRunNo());
143 AliTPCcalibDB::Instance()->GetClusterParam()->SetInstance(AliTPCcalibDB::Instance()->GetClusterParam());
146 // AliTPCcalibDB *calib = AliTPCcalibDB::Instance();
149 // HLTError("AliTPCcalibDB does not exist");
153 // AliTPCClusterParam *clusPar = calib->GetClusterParam();
155 // HLTError("OCDB entry TPC/Calib/ClusterParam (AliTPCcalibDB::GetClusterParam()) is not available.");
159 // first configure the default
161 if (iResult>=0) iResult=ConfigureFromCDBTObjString(fgkOCDBEntry);
163 // configure from the command line parameters if specified
164 //if (iResult>=0 && argc>0) iResult=ConfigureFromArgumentString(argc, argv);
166 if(fCalibTime) return EINPROGRESS;
167 fCal = new AliTPCcalibCalib();
173 Int_t AliHLTTPCCalibTimeComponent::DeinitCalibration() {
174 // see header file for class documentation
176 if(fCalibTime) delete fCalibTime; fCalibTime = NULL;
177 if(fCal) delete fCal; fCal = NULL;
178 //if(fESDfriend) delete fESDfriend; fESDfriend = NULL;
183 int AliHLTTPCCalibTimeComponent::Reconfigure(const char* cdbEntry, const char* /*chainId*/){
184 // see header file for class documentation
186 // configure from the specified antry or the default one
187 const char* entry=cdbEntry;
188 if (!entry || entry[0]==0) {
192 return ConfigureFromCDBTObjString(entry);
195 Int_t AliHLTTPCCalibTimeComponent::ProcessCalibration( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/ ){
196 // see header file for class documentation
198 if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )) return 0;
200 TObject *iter = NULL;
202 //--------------- output over TObjArray of AliTPCseed objects (output of TPCSeedMaker) -------------------//
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
207 for(iter = (TObject*)GetFirstInputObject(kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC); iter != NULL; iter = (TObject*)GetNextInputObject()){
209 if(GetDataType(iter) != (kAliHLTDataTypeTObjArray | kAliHLTDataOriginTPC)) continue;
210 fSeedArray = dynamic_cast<TObjArray*>(iter);
214 //----------- loop over output of global esd converter ----------------//
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.
219 for(iter = (TObject*)GetFirstInputObject(kAliHLTDataTypeESDObject | kAliHLTDataOriginOut); iter != NULL; iter = (TObject*)GetNextInputObject()){
221 if(GetDataType(iter) != (kAliHLTDataTypeESDObject | kAliHLTDataOriginOut)) continue;
223 fESDevent = dynamic_cast<AliESDEvent*>(iter);
224 fESDevent->GetStdContent();
226 //fESDevent->SetTimeStamp(1256910155);
227 //fESDevent->SetRunNumber(0);
228 //fESDevent->SetRunNumber(84714);
230 HLTDebug("# Seeds: %i\n", fSeedArray->GetEntriesFast()); // access of the info from the previous loop over the AliTPCseed array
232 fCal->UpdateEventInfo(fESDevent);
234 for(Int_t i=0; i<fSeedArray->GetEntriesFast(); i++){ // loop over TObjArray
236 AliTPCseed *seed = (AliTPCseed*)fSeedArray->UncheckedAt(i);
239 fESDtrack = fESDevent->GetTrack(i);
240 if(!fESDtrack) continue;
242 fCal->RefitTrack(fESDtrack, seed, GetBz()); // update AliESDtrack and AliTPCseed info, acccording to Marian's request
244 AliTPCseed *seedCopy = new AliTPCseed(*seed, kTRUE);
245 fESDtrack->AddCalibObject(seedCopy); // add the AliTPCseed as a friend track to the AliESDtrack (to be accessed in TPC/AliTPCcalibTime.cxx)
247 //fESDfriendTrack = const_cast<AliESDfriendTrack*>(fESDtrack->GetFriendTrack());
251 if(!fCalibTime){ // create the calibration object that will call the offline functions
253 Int_t startTime = fESDevent->GetTimeStamp()-60*60*1; //Start time one hour before first event, will make precise cuts later.
254 Int_t endTime = fESDevent->GetTimeStamp()+60*60*23; //End time 23 hours after first event.
255 fCalibTime = new AliTPCcalibTime("calibTime","time dependent Vdrift calibration", startTime, endTime, 20*60);
256 fCalibTime->SetStreamLevel(20);
257 fCalibTime->SetDebugLevel(20);
258 printf("fCalibTime = %i, startTime = %i, endTime = %i \n", fCalibTime!=0, startTime, endTime);
261 fESDfriend = new AliESDfriend();
262 fESDevent->GetESDfriend(fESDfriend);
263 fESDevent->SetESDfriend(fESDfriend);
264 fESDevent->AddObject(fESDfriend);
265 // 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
267 fCalibTime->UpdateEventInfo(fESDevent); // needed for getting the run number and time stamp information correct on the offline side
268 fCalibTime->Process(fESDevent); // first offline function called
270 // delete fESDfriend;
272 //PushBack( (TObject*)fCalibTime, AliHLTTPCDefinitions::fgkCalibCEDataType | kAliHLTDataOriginOut, 0x0);
277 Int_t AliHLTTPCCalibTimeComponent::ShipDataToFXS( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/ ){
278 // see header file for class documentation
280 HLTInfo("Shipping data to FXS...\n");
282 fCalibTime->Analyze(); // called at the end of the run or event modulo
284 // 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
285 // thinking here to avoid copying all these lines that might chain in offline without HLT realizing.
287 THnSparse* addHist = fCalibTime->GetHistoDrift("all");
288 if(!addHist) return -1;
290 //Identifying used range of histogram
292 Int_t startTimeBin = 0;
293 Int_t endTimeBin = 0;
295 TH1D *histoTime = addHist->Projection(0);
297 startTimeBin = histoTime->FindFirstBinAbove(0);
298 endTimeBin = histoTime->FindLastBinAbove(0);
299 printf("startTimeBin = %i endTimeBin = %i\n", startTimeBin, endTimeBin);
300 printf("startTimeBinCentre = %f endTimeBinCentre = %f\n", histoTime->GetBinCenter(startTimeBin), histoTime->GetBinCenter(endTimeBin));
301 printf("startTimeBinWidth = %f endTimeBinWidth = %f\n", histoTime->GetBinWidth(startTimeBin), histoTime->GetBinWidth(endTimeBin));
302 delete histoTime; histoTime = 0;
305 Int_t startPtBin = 0;
307 TH1D *histoPt = addHist->Projection(1);
309 startPtBin = histoPt->FindFirstBinAbove(0);
310 endPtBin = histoPt->FindLastBinAbove(0);
311 printf("startPtBin = %i endPtBin = %i\n", startPtBin, endPtBin);
312 printf("startPtBinCentre = %f endPtBinCentre = %f\n", histoPt->GetBinCenter(startPtBin), histoPt->GetBinCenter(endPtBin));
313 printf("startPtinWidth = %f endPtBinWidth = %f\n", histoPt->GetBinWidth(startPtBin), histoPt->GetBinWidth(endPtBin));
314 delete histoPt; histoPt = 0;
317 Int_t startVdBin = 0;
319 TH1D *histoVd = addHist->Projection(2);
321 startVdBin = histoVd->FindFirstBinAbove(0);
322 endVdBin = histoVd->FindLastBinAbove(0);
323 printf("startVdBin = %i endVdBin = %i\n", startVdBin, endVdBin);
324 printf("startVdBinCentre = %f endVdBinCentre = %f\n", histoVd->GetBinCenter(startVdBin), histoVd->GetBinCenter(endVdBin));
325 printf("startVdBinWidth = %f endVdBinWidth = %f\n", histoVd->GetBinWidth(startVdBin), histoVd->GetBinWidth(endVdBin));
326 delete histoVd; histoVd = 0;
329 Int_t startRunBin = 0;
331 TH1D *histoRun = addHist->Projection(3);
333 startRunBin = histoRun->FindFirstBinAbove(0);
334 endRunBin = histoRun->FindLastBinAbove(0);
335 printf("startRunBin = %i endRunBin = %i\n", startRunBin, endRunBin);
336 printf("startRunBinCentre = %f endRunBinCentre = %f\n", histoRun->GetBinCenter(startRunBin), histoRun->GetBinCenter(endRunBin));
337 printf("startRunBinWidth = %f endRunBinWidth = %f\n", histoRun->GetBinWidth(startRunBin), histoRun->GetBinWidth(endRunBin));
338 delete histoRun; histoRun = 0;
341 TObjArray *vdriftArray = new TObjArray();
342 if(!vdriftArray) return -2;
344 TObjArray *array = fCalibTime->GetHistoDrift();
345 if(!array) return -3;
347 TIterator *iterator = array->MakeIterator();
348 if(!iterator) return -4;
351 THnSparse *hist = NULL;
352 while((hist = (THnSparseF*)iterator->Next())){
356 hist->GetAxis(0)->SetRange(startTimeBin, endTimeBin);
357 hist->GetAxis(1)->SetRange(startPtBin, endPtBin);
358 hist->GetAxis(0)->SetRange(startVdBin, endVdBin);
359 hist->GetAxis(3)->SetRange(startRunBin, endRunBin);
361 TString name = hist->GetName();
362 Int_t dim[4] = {0,1,2,3};
363 THnSparse *newHist = hist->Projection(4,dim);
364 newHist->SetName(name);
365 vdriftArray->Add(newHist);
367 TGraphErrors *graph = AliTPCcalibBase::FitSlices(newHist,2,0,400,100,0.05,0.95, kTRUE);
368 printf("name = %s graph = %i\n", name.Data(), graph==0);
369 if(!graph || !graph->GetN()) continue;
370 printf("name = %s graph = %i, N = %i\n", name.Data(), graph==0, graph->GetN());
371 Int_t pos = name.Index("_");
372 name = name(pos,name.Capacity()-pos);
373 TString graphName = graph->ClassName();
376 graph->SetName(graphName);
377 printf("name = %s\n", graphName.Data());
378 vdriftArray->Add(graph);
380 //Currently, AliSplineFits can not be given names...
381 //AliSplineFit* fit=new AliSplineFit();
382 //fit->SetGraph(graph);
383 //fit->SetMinPoints(graph->GetN()+1);
384 //fit->InitKnots(graph,2,0,0.001);
386 //TString fiName=fit->ClassName();
390 //fit->SetName(fiName.Data());
391 //printf("name=%s\n", fiName.Data());
392 //vdriftArray->Add(fit);
395 THnSparse *laserHist = NULL;
396 TGraphErrors *laserGraph = NULL;
397 TString laserName = "";
399 //Histograms and graphs for A side lasers
400 laserHist = fCalibTime->GetHistVdriftLaserA(1);
403 laserName=laserHist->ClassName();
404 laserName+="_MEAN_DRIFT_LASER_ALL_A";
406 laserHist->SetName(laserName);
407 vdriftArray->Add(laserHist);
408 laserGraph=AliTPCcalibBase::FitSlices(laserHist,2,0,400,100,0.05,0.95, kTRUE);
409 if(laserGraph && laserGraph->GetN()){
410 laserName=laserGraph->GetName();
411 laserName+="_MEAN_DRIFT_LASER_ALL_A";
413 laserGraph->SetName(laserName);
414 vdriftArray->Add(laserGraph);
418 //Histograms and graphs for C side lasers
419 laserHist=fCalibTime->GetHistVdriftLaserC(1);
421 laserName=laserHist->ClassName();
422 laserName+="_MEAN_DRIFT_LASER_ALL_C";
424 laserHist->SetName(laserName);
425 vdriftArray->Add(laserHist);
426 laserGraph=AliTPCcalibBase::FitSlices(laserHist,2,0,400,100,0.05,0.95, kTRUE);
427 if(laserGraph && laserGraph->GetN()){
428 laserName=laserGraph->GetName();
429 laserName+="_MEAN_DRIFT_LASER_ALL_C";
431 laserGraph->SetName(laserName);
432 vdriftArray->Add(laserGraph);
436 //Meatdata set in off-line...
437 //AliCDBMetaData *metaData= new AliCDBMetaData();
438 //metaData->SetObjectClassName("TObjArray");
439 //metaData->SetResponsible("Dag Toppe Larsen");
440 //metaData->SetBeamPeriod(1);
441 //metaData->SetAliRootVersion("05-25-01"); //root version
442 //metaData->SetComment("Calibration of the time dependence of the drift velocity due to pressure and temperature changes");
443 //AliCDBId* id1=NULL;
444 //if(end) id1=new AliCDBId("TPC/Calib/TimeDrift", runNumber, end);
445 //else id1=new AliCDBId("TPC/Calib/TimeDrift", runNumber, runNumber);
446 //AliCDBStorage* gStorage = AliCDBManager::Instance()->GetStorage("local://$ALICE_ROOT/OCDB");
447 //gStorage->Put(vdriftArray, (*id1), metaData);
448 //printf("done runNumber=%i, end=%i\n", runNumber, end);
450 static AliHLTReadoutList rdList(AliHLTReadoutList::kTPC);
452 // the vdriftArray is pushed to the HLT-FXSsubscriber
453 PushToFXS( (TObject*)vdriftArray, "TPC", "TIMEDRIFT", rdList.Buffer() );
455 //PushToFXS( (TObject*)vdriftArray, "TPC", "Time");
457 TFile *file = TFile::Open("vdrift.root", "RECREATE");
458 vdriftArray->Write();
462 file = TFile::Open("calibTime.root", "RECREATE");
467 //Should array be deleted now?
469 // vdriftArray.Clear();
470 // delete vdriftArray;