adding libAliHLTTRD.so as dependency for libAliHLTTrigger.so
[u/mrichter/AliRoot.git] / TPC / AliTPCcalibDB.cxx
CommitLineData
c5bbaa2c 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// Class providing the calibration parameters by accessing the CDB //
20// //
21// Request an instance with AliTPCcalibDB::Instance() //
22// If a new event is processed set the event number with SetRun //
1ac191a6 23// Then request the calibration data ////
f5344549 24//
25//
1ac191a6 26// Calibration data:
8cd9634d 27// 0.) Altro mapping
28// Simulation - not yet
29// Reconstruction - AliTPCclustererMI::Digits2Clusters(AliRawReader* rawReader)
30//
1ac191a6 31// 1.) pad by pad calibration - AliTPCCalPad
f5344549 32//
1ac191a6 33// a.) fPadGainFactor
34// Simulation: AliTPCDigitizer::ExecFast - Multiply by gain
35// Reconstruction : AliTPCclustererMI::Digits2Clusters - Divide by gain
f5344549 36//
1ac191a6 37// b.) fPadNoise -
38// Simulation: AliTPCDigitizer::ExecFast
39// Reconstruction: AliTPCclustererMI::FindClusters(AliTPCCalROC * noiseROC)
8cd9634d 40// Noise depending cut on clusters charge (n sigma)
f5344549 41// c.) fPedestal:
42// Simulation: Not used yet - To be impleneted - Rounding to the nearest integer
43// Reconstruction: Used in AliTPCclustererMI::Digits2Clusters(AliRawReader* rawReader)
44// if data taken without zero suppression
45// Currently switch in fRecoParam->GetCalcPedestal();
46//
47// d.) fPadTime0
48// Simulation: applied in the AliTPC::MakeSector - adding offset
49// Reconstruction: AliTPCTransform::Transform() - remove offset
50// AliTPCTransform::Transform() - to be called
51// in AliTPCtracker::Transform()
8cd9634d 52//
53//
54// 2.) Space points transformation:
55//
56// a.) General coordinate tranformation - AliTPCtransform (see $ALICE_ROOT/TPC/AliTPCtransform.cxx)
57// Created on fly - use the other calibration components
58// Unisochronity - (substract time0 - pad by pad)
59// Drift velocity - Currently common drift velocity - functionality of AliTPCParam
60// ExB effect
61// Simulation - Not used directly (the effects are applied one by one (see AliTPC::MakeSector)
62// Reconstruction -
63// AliTPCclustererMI::AddCluster
64// AliTPCtrackerMI::Transform
65// b.) ExB effect calibration -
66// classes (base class AliTPCExB, implementation- AliTPCExBExact.h AliTPCExBFirst.h)
67// a.a) Simulation: applied in the AliTPC::MakeSector -
68// calib->GetExB()->CorrectInverse(dxyz0,dxyz1);
69// a.b) Reconstruction -
70//
71// in AliTPCtransform::Correct() - called calib->GetExB()->Correct(dxyz0,dxyz1)
72//
96305e49 73// 3.) cluster error, shape and Q parameterization
74//
75//
8cd9634d 76//
c5bbaa2c 77///////////////////////////////////////////////////////////////////////////////
78
418bbcaf 79#include <iostream>
80#include <fstream>
81
c5bbaa2c 82
83#include <AliCDBManager.h>
c5bbaa2c 84#include <AliCDBEntry.h>
85#include <AliLog.h>
3ac615eb 86#include <AliMagF.h>
7fff7612 87#include <AliSplineFit.h>
c5bbaa2c 88
89#include "AliTPCcalibDB.h"
d6834f5f 90#include "AliTPCAltroMapping.h"
418bbcaf 91#include "AliTPCExB.h"
c5bbaa2c 92
93#include "AliTPCCalROC.h"
94#include "AliTPCCalPad.h"
54472e4f 95#include "AliTPCSensorTempArray.h"
bf85fe4d 96#include "AliGRPObject.h"
418bbcaf 97#include "AliTPCTransform.h"
d6834f5f 98
418bbcaf 99class AliCDBStorage;
100class AliTPCCalDet;
86df2b3a 101//
102//
103
86df2b3a 104#include "TFile.h"
105#include "TKey.h"
106
107#include "TObjArray.h"
108#include "TObjString.h"
109#include "TString.h"
110#include "AliTPCCalPad.h"
0fe7645c 111#include "AliTPCCalibPulser.h"
86df2b3a 112#include "AliTPCCalibPedestal.h"
113#include "AliTPCCalibCE.h"
3ac615eb 114#include "AliTPCExBFirst.h"
bf85fe4d 115#include "AliTPCTempMap.h"
da6c0bc9 116#include "AliTPCCalibVdrift.h"
6e7d7dc4 117#include "AliTPCCalibRaw.h"
86df2b3a 118
5312f439 119#include "AliTPCPreprocessorOnline.h"
86df2b3a 120
c5bbaa2c 121
122ClassImp(AliTPCcalibDB)
123
124AliTPCcalibDB* AliTPCcalibDB::fgInstance = 0;
125Bool_t AliTPCcalibDB::fgTerminated = kFALSE;
3ac615eb 126TObjArray AliTPCcalibDB::fgExBArray; // array of ExB corrections
c5bbaa2c 127
128
129//_ singleton implementation __________________________________________________
130AliTPCcalibDB* AliTPCcalibDB::Instance()
131{
132 //
133 // Singleton implementation
134 // Returns an instance of this class, it is created if neccessary
135 //
136
137 if (fgTerminated != kFALSE)
138 return 0;
139
140 if (fgInstance == 0)
141 fgInstance = new AliTPCcalibDB();
142
143 return fgInstance;
144}
145
146void AliTPCcalibDB::Terminate()
147{
148 //
149 // Singleton implementation
150 // Deletes the instance of this class and sets the terminated flag, instances cannot be requested anymore
151 // This function can be called several times.
152 //
153
154 fgTerminated = kTRUE;
155
156 if (fgInstance != 0)
157 {
158 delete fgInstance;
159 fgInstance = 0;
160 }
161}
162
163//_____________________________________________________________________________
e4dce695 164AliTPCcalibDB::AliTPCcalibDB():
9389f9a4 165 TObject(),
e4dce695 166 fRun(-1),
f5344549 167 fTransform(0),
481f877b 168 fExB(0),
e4dce695 169 fPadGainFactor(0),
9f6e9f81 170 fDedxGainFactor(0),
e4dce695 171 fPadTime0(0),
e4dce695 172 fPadNoise(0),
173 fPedestals(0),
6e7d7dc4 174 fCalibRaw(0),
5312f439 175 fALTROConfigData(0),
176 fPulserData(0),
177 fCEData(0),
e4dce695 178 fTemperature(0),
d6834f5f 179 fMapping(0),
96305e49 180 fParam(0),
a2c3785e 181 fClusterParam(0),
182 fTimeGainSplines(0),
183 fTimeGainSplinesArray(100000),
da6c0bc9 184 fGRPArray(100000), //! array of GRPs - per run - JUST for calibration studies
0231c65f 185 fGRPMaps(100000), //! array of GRPs - per run - JUST for calibration studies
da6c0bc9 186 fGoofieArray(100000), //! array of GOOFIE values -per run - Just for calibration studies
e2914767 187 fVoltageArray(100000),
da6c0bc9 188 fTemperatureArray(100000), //! array of temperature sensors - per run - Just for calibration studies
189 fVdriftArray(100000), //! array of v drift interfaces
5e1215d4 190 fDriftCorrectionArray(100000), //! array of drift correction
bf85fe4d 191 fRunList(100000) //! run list - indicates try to get the run param
192
c5bbaa2c 193{
194 //
195 // constructor
196 //
54472e4f 197 //
c5bbaa2c 198 Update(); // temporary
199}
200
9389f9a4 201AliTPCcalibDB::AliTPCcalibDB(const AliTPCcalibDB& ):
202 TObject(),
203 fRun(-1),
204 fTransform(0),
205 fExB(0),
206 fPadGainFactor(0),
9f6e9f81 207 fDedxGainFactor(0),
9389f9a4 208 fPadTime0(0),
209 fPadNoise(0),
210 fPedestals(0),
6e7d7dc4 211 fCalibRaw(0),
5312f439 212 fALTROConfigData(0),
213 fPulserData(0),
214 fCEData(0),
9389f9a4 215 fTemperature(0),
216 fMapping(0),
9389f9a4 217 fParam(0),
bf85fe4d 218 fClusterParam(0),
a2c3785e 219 fTimeGainSplines(0),
220 fTimeGainSplinesArray(100000),
bf85fe4d 221 fGRPArray(0), //! array of GRPs - per run - JUST for calibration studies
0231c65f 222 fGRPMaps(0), //! array of GRPs - per run - JUST for calibration studies
bf85fe4d 223 fGoofieArray(0), //! array of GOOFIE values -per run - Just for calibration studies
e2914767 224 fVoltageArray(0),
bf85fe4d 225 fTemperatureArray(0), //! array of temperature sensors - per run - Just for calibration studies
da6c0bc9 226 fVdriftArray(0), //! array of v drift interfaces
5e1215d4 227 fDriftCorrectionArray(0), //! array of v drift interfaces
bf85fe4d 228 fRunList(0) //! run list - indicates try to get the run param
9389f9a4 229{
230 //
231 // Copy constructor invalid -- singleton implementation
232 //
233 Error("copy constructor","invalid -- singleton implementation");
234}
235
236AliTPCcalibDB& AliTPCcalibDB::operator= (const AliTPCcalibDB& )
237{
238//
239// Singleton implementation - no assignment operator
240//
241 Error("operator =", "assignment operator not implemented");
242 return *this;
243}
244
245
246
c5bbaa2c 247//_____________________________________________________________________________
248AliTPCcalibDB::~AliTPCcalibDB()
249{
250 //
251 // destructor
252 //
68751c2c 253
254 // don't delete anything, CDB cache is active!
255 //if (fPadGainFactor) delete fPadGainFactor;
256 //if (fPadTime0) delete fPadTime0;
68751c2c 257 //if (fPadNoise) delete fPadNoise;
c5bbaa2c 258}
259
260
261//_____________________________________________________________________________
262AliCDBEntry* AliTPCcalibDB::GetCDBEntry(const char* cdbPath)
263{
264 //
265 // Retrieves an entry with path <cdbPath> from the CDB.
266 //
267 char chinfo[1000];
268
68751c2c 269 AliCDBEntry* entry = AliCDBManager::Instance()->Get(cdbPath, fRun);
c5bbaa2c 270 if (!entry)
271 {
272 sprintf(chinfo,"AliTPCcalibDB: Failed to get entry:\t%s ", cdbPath);
273 AliError(chinfo);
274 return 0;
275 }
276 return entry;
277}
278
279
280//_____________________________________________________________________________
281void AliTPCcalibDB::SetRun(Long64_t run)
282{
283 //
284 // Sets current run number. Calibration data is read from the corresponding file.
285 //
286 if (fRun == run)
287 return;
a2c3785e 288 fRun = run;
c5bbaa2c 289 Update();
290}
291
292
293
294void AliTPCcalibDB::Update(){
a2c3785e 295 //
296 AliCDBEntry * entry=0;
68751c2c 297
298 Bool_t cdbCache = AliCDBManager::Instance()->GetCacheFlag(); // save cache status
299 AliCDBManager::Instance()->SetCacheFlag(kTRUE); // activate CDB cache
300
c5bbaa2c 301 //
302 entry = GetCDBEntry("TPC/Calib/PadGainFactor");
303 if (entry){
68751c2c 304 //if (fPadGainFactor) delete fPadGainFactor;
c5bbaa2c 305 entry->SetOwner(kTRUE);
306 fPadGainFactor = (AliTPCCalPad*)entry->GetObject();
307 }
308 //
3af3fbc4 309 entry = GetCDBEntry("TPC/Calib/TimeGain");
310 if (entry){
311 //if (fTimeGainSplines) delete fTimeGainSplines;
312 entry->SetOwner(kTRUE);
313 fTimeGainSplines = (TObjArray*)entry->GetObject();
314 }
315 //
9f6e9f81 316 entry = GetCDBEntry("TPC/Calib/GainFactorDedx");
317 if (entry){
318 entry->SetOwner(kTRUE);
319 fDedxGainFactor = (AliTPCCalPad*)entry->GetObject();
320 }
321 //
c5bbaa2c 322 entry = GetCDBEntry("TPC/Calib/PadTime0");
323 if (entry){
68751c2c 324 //if (fPadTime0) delete fPadTime0;
c5bbaa2c 325 entry->SetOwner(kTRUE);
326 fPadTime0 = (AliTPCCalPad*)entry->GetObject();
327 }
328 //
c5bbaa2c 329 //
330 entry = GetCDBEntry("TPC/Calib/PadNoise");
331 if (entry){
68751c2c 332 //if (fPadNoise) delete fPadNoise;
c5bbaa2c 333 entry->SetOwner(kTRUE);
334 fPadNoise = (AliTPCCalPad*)entry->GetObject();
335 }
8477f500 336
337 entry = GetCDBEntry("TPC/Calib/Pedestals");
338 if (entry){
339 //if (fPedestals) delete fPedestals;
340 entry->SetOwner(kTRUE);
341 fPedestals = (AliTPCCalPad*)entry->GetObject();
342 }
343
54472e4f 344 entry = GetCDBEntry("TPC/Calib/Temperature");
345 if (entry){
346 //if (fTemperature) delete fTemperature;
347 entry->SetOwner(kTRUE);
348 fTemperature = (AliTPCSensorTempArray*)entry->GetObject();
349 }
350
8477f500 351 entry = GetCDBEntry("TPC/Calib/Parameters");
352 if (entry){
54472e4f 353 //if (fPadNoise) delete fPadNoise;
8477f500 354 entry->SetOwner(kTRUE);
a778f7e3 355 fParam = (AliTPCParam*)(entry->GetObject()->Clone());
8477f500 356 }
357
96305e49 358 entry = GetCDBEntry("TPC/Calib/ClusterParam");
359 if (entry){
96305e49 360 entry->SetOwner(kTRUE);
361 fClusterParam = (AliTPCClusterParam*)(entry->GetObject()->Clone());
362 }
363
5312f439 364 //ALTRO configuration data
365 entry = GetCDBEntry("TPC/Calib/AltroConfig");
366 if (entry){
367 entry->SetOwner(kTRUE);
368 fALTROConfigData=(TObjArray*)(entry->GetObject());
369 }
370
371 //Calibration Pulser data
372 entry = GetCDBEntry("TPC/Calib/Pulser");
373 if (entry){
374 entry->SetOwner(kTRUE);
375 fPulserData=(TObjArray*)(entry->GetObject());
376 }
377
378 //CE data
379 entry = GetCDBEntry("TPC/Calib/CE");
380 if (entry){
381 entry->SetOwner(kTRUE);
382 fCEData=(TObjArray*)(entry->GetObject());
383 }
6e7d7dc4 384 //RAW calibration data
385 entry = GetCDBEntry("TPC/Calib/Raw");
386 if (entry){
387 entry->SetOwner(kTRUE);
388 TObjArray *arr=(TObjArray*)(entry->GetObject());
389 if (arr) fCalibRaw=(AliTPCCalibRaw*)arr->At(0);
390 }
5312f439 391
d6834f5f 392 entry = GetCDBEntry("TPC/Calib/Mapping");
393 if (entry){
394 //if (fPadNoise) delete fPadNoise;
395 entry->SetOwner(kTRUE);
396 TObjArray * array = dynamic_cast<TObjArray*>(entry->GetObject());
397 if (array && array->GetEntriesFast()==6){
398 fMapping = new AliTPCAltroMapping*[6];
399 for (Int_t i=0; i<6; i++){
5312f439 400 fMapping[i] = dynamic_cast<AliTPCAltroMapping*>(array->At(i));
d6834f5f 401 }
402 }
403 }
404
405
406
3ac615eb 407 //entry = GetCDBEntry("TPC/Calib/ExB");
408 //if (entry) {
409 // entry->SetOwner(kTRUE);
410 // fExB=dynamic_cast<AliTPCExB*>(entry->GetObject()->Clone());
411 //}
412 //
413 // ExB - calculate during initialization
414 // -
f4d5fd21 415 fExB = GetExB(-5,kTRUE);
416 //
f5344549 417 if (!fTransform) {
418 fTransform=new AliTPCTransform();
bfec3eeb 419 fTransform->SetCurrentRun(AliCDBManager::Instance()->GetRun());
f5344549 420 }
8477f500 421
c5bbaa2c 422 //
68751c2c 423 AliCDBManager::Instance()->SetCacheFlag(cdbCache); // reset original CDB cache
424
c5bbaa2c 425}
e4dce695 426
86df2b3a 427
428
429void AliTPCcalibDB::CreateObjectList(const Char_t *filename, TObjArray *calibObjects)
430{
418bbcaf 431//
432// Create calibration objects and read contents from OCDB
433//
86df2b3a 434 if ( calibObjects == 0x0 ) return;
435 ifstream in;
436 in.open(filename);
437 if ( !in.is_open() ){
438 fprintf(stderr,"Error: cannot open list file '%s'", filename);
439 return;
440 }
441
442 AliTPCCalPad *calPad=0x0;
443
444 TString sFile;
445 sFile.ReadFile(in);
446 in.close();
447
448 TObjArray *arrFileLine = sFile.Tokenize("\n");
449
450 TIter nextLine(arrFileLine);
451
452 TObjString *sObjLine=0x0;
2c632057 453 while ( (sObjLine = (TObjString*)nextLine()) ){
86df2b3a 454 TString sLine(sObjLine->GetString());
455
456 TObjArray *arrNextCol = sLine.Tokenize("\t");
457
458 TObjString *sObjType = (TObjString*)(arrNextCol->At(0));
459 TObjString *sObjFileName = (TObjString*)(arrNextCol->At(1));
460
461 if ( !sObjType || ! sObjFileName ) continue;
462 TString sType(sObjType->GetString());
463 TString sFileName(sObjFileName->GetString());
464 printf("%s\t%s\n",sType.Data(),sFileName.Data());
465
466 TFile *fIn = TFile::Open(sFileName);
467 if ( !fIn ){
468 fprintf(stderr,"File not found: '%s'", sFileName.Data());
469 continue;
470 }
471
472 if ( sType == "CE" ){
473 AliTPCCalibCE *ce = (AliTPCCalibCE*)fIn->Get("AliTPCCalibCE");
474
475 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadT0());
476 calPad->SetNameTitle("CETmean","CETmean");
477 calibObjects->Add(calPad);
478
479 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadQ());
480 calPad->SetNameTitle("CEQmean","CEQmean");
481 calibObjects->Add(calPad);
482
483 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadRMS());
484 calPad->SetNameTitle("CETrms","CETrms");
485 calibObjects->Add(calPad);
486
487 } else if ( sType == "Pulser") {
0fe7645c 488 AliTPCCalibPulser *sig = (AliTPCCalibPulser*)fIn->Get("AliTPCCalibPulser");
86df2b3a 489
490 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadT0());
491 calPad->SetNameTitle("PulserTmean","PulserTmean");
492 calibObjects->Add(calPad);
493
494 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadQ());
495 calPad->SetNameTitle("PulserQmean","PulserQmean");
496 calibObjects->Add(calPad);
497
498 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadRMS());
499 calPad->SetNameTitle("PulserTrms","PulserTrms");
500 calibObjects->Add(calPad);
501
502 } else if ( sType == "Pedestals") {
503 AliTPCCalibPedestal *ped = (AliTPCCalibPedestal*)fIn->Get("AliTPCCalibPedestal");
504
505 calPad = new AliTPCCalPad((TObjArray*)ped->GetCalPadPedestal());
506 calPad->SetNameTitle("Pedestals","Pedestals");
507 calibObjects->Add(calPad);
508
509 calPad = new AliTPCCalPad((TObjArray*)ped->GetCalPadRMS());
510 calPad->SetNameTitle("Noise","Noise");
511 calibObjects->Add(calPad);
512
513 } else {
514 fprintf(stderr,"Undefined Type: '%s'",sType.Data());
515
516 }
517 delete fIn;
518 }
519}
520
521
522
523void AliTPCcalibDB::MakeTree(const char * fileName, TObjArray * array, const char * mapFileName, AliTPCCalPad* outlierPad, Float_t ltmFraction) {
524 //
525 // Write a tree with all available information
418bbcaf 526 // if mapFileName is specified, the Map information are also written to the tree
86df2b3a 527 // pads specified in outlierPad are not used for calculating statistics
528 // - the same function as AliTPCCalPad::MakeTree -
529 //
530 AliTPCROC* tpcROCinstance = AliTPCROC::Instance();
531
532 TObjArray* mapIROCs = 0;
533 TObjArray* mapOROCs = 0;
534 TVectorF *mapIROCArray = 0;
535 TVectorF *mapOROCArray = 0;
536 Int_t mapEntries = 0;
537 TString* mapNames = 0;
538
539 if (mapFileName) {
540 TFile mapFile(mapFileName, "read");
541
542 TList* listOfROCs = mapFile.GetListOfKeys();
543 mapEntries = listOfROCs->GetEntries()/2;
544 mapIROCs = new TObjArray(mapEntries*2);
545 mapOROCs = new TObjArray(mapEntries*2);
546 mapIROCArray = new TVectorF[mapEntries];
547 mapOROCArray = new TVectorF[mapEntries];
548
549 mapNames = new TString[mapEntries];
550 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
418bbcaf 551 TString nameROC(((TKey*)(listOfROCs->At(ivalue*2)))->GetName());
552 nameROC.Remove(nameROC.Length()-4, 4);
553 mapIROCs->AddAt((AliTPCCalROC*)mapFile.Get((nameROC + "IROC").Data()), ivalue);
554 mapOROCs->AddAt((AliTPCCalROC*)mapFile.Get((nameROC + "OROC").Data()), ivalue);
555 mapNames[ivalue].Append(nameROC);
86df2b3a 556 }
557
558 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
559 mapIROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(0));
560 mapOROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(36));
561
562 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(0); ichannel++)
563 (mapIROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapIROCs->At(ivalue)))->GetValue(ichannel);
564 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(36); ichannel++)
565 (mapOROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapOROCs->At(ivalue)))->GetValue(ichannel);
566 }
567
568 } // if (mapFileName)
569
570 TTreeSRedirector cstream(fileName);
571 Int_t arrayEntries = array->GetEntries();
572
573 TString* names = new TString[arrayEntries];
574 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
575 names[ivalue].Append(((AliTPCCalPad*)array->At(ivalue))->GetName());
576
577 for (UInt_t isector = 0; isector < tpcROCinstance->GetNSectors(); isector++) {
578 //
579 // get statistic for given sector
580 //
581 TVectorF median(arrayEntries);
582 TVectorF mean(arrayEntries);
583 TVectorF rms(arrayEntries);
584 TVectorF ltm(arrayEntries);
585 TVectorF ltmrms(arrayEntries);
586 TVectorF medianWithOut(arrayEntries);
587 TVectorF meanWithOut(arrayEntries);
588 TVectorF rmsWithOut(arrayEntries);
589 TVectorF ltmWithOut(arrayEntries);
590 TVectorF ltmrmsWithOut(arrayEntries);
591
592 TVectorF *vectorArray = new TVectorF[arrayEntries];
593 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
594 vectorArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
595
596 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
597 AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue);
598 AliTPCCalROC* calROC = calPad->GetCalROC(isector);
599 AliTPCCalROC* outlierROC = 0;
600 if (outlierPad) outlierROC = outlierPad->GetCalROC(isector);
601 if (calROC) {
602 median[ivalue] = calROC->GetMedian();
603 mean[ivalue] = calROC->GetMean();
604 rms[ivalue] = calROC->GetRMS();
605 Double_t ltmrmsValue = 0;
606 ltm[ivalue] = calROC->GetLTM(&ltmrmsValue, ltmFraction);
607 ltmrms[ivalue] = ltmrmsValue;
608 if (outlierROC) {
609 medianWithOut[ivalue] = calROC->GetMedian(outlierROC);
610 meanWithOut[ivalue] = calROC->GetMean(outlierROC);
611 rmsWithOut[ivalue] = calROC->GetRMS(outlierROC);
612 ltmrmsValue = 0;
613 ltmWithOut[ivalue] = calROC->GetLTM(&ltmrmsValue, ltmFraction, outlierROC);
614 ltmrmsWithOut[ivalue] = ltmrmsValue;
615 }
616 }
617 else {
618 median[ivalue] = 0.;
619 mean[ivalue] = 0.;
620 rms[ivalue] = 0.;
621 ltm[ivalue] = 0.;
622 ltmrms[ivalue] = 0.;
623 medianWithOut[ivalue] = 0.;
624 meanWithOut[ivalue] = 0.;
625 rmsWithOut[ivalue] = 0.;
626 ltmWithOut[ivalue] = 0.;
627 ltmrmsWithOut[ivalue] = 0.;
628 }
629 }
630
631 //
632 // fill vectors of variable per pad
633 //
634 TVectorF *posArray = new TVectorF[8];
635 for (Int_t ivalue = 0; ivalue < 8; ivalue++)
636 posArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
637
638 Float_t posG[3] = {0};
639 Float_t posL[3] = {0};
640 Int_t ichannel = 0;
641 for (UInt_t irow = 0; irow < tpcROCinstance->GetNRows(isector); irow++) {
642 for (UInt_t ipad = 0; ipad < tpcROCinstance->GetNPads(isector, irow); ipad++) {
643 tpcROCinstance->GetPositionLocal(isector, irow, ipad, posL);
644 tpcROCinstance->GetPositionGlobal(isector, irow, ipad, posG);
645 posArray[0][ichannel] = irow;
646 posArray[1][ichannel] = ipad;
647 posArray[2][ichannel] = posL[0];
648 posArray[3][ichannel] = posL[1];
649 posArray[4][ichannel] = posG[0];
650 posArray[5][ichannel] = posG[1];
651 posArray[6][ichannel] = (Int_t)(ipad - (Double_t)(tpcROCinstance->GetNPads(isector, irow))/2);
652 posArray[7][ichannel] = ichannel;
653
654 // loop over array containing AliTPCCalPads
655 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
656 AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue);
657 AliTPCCalROC* calROC = calPad->GetCalROC(isector);
658 if (calROC)
659 (vectorArray[ivalue])[ichannel] = calROC->GetValue(irow, ipad);
660 else
661 (vectorArray[ivalue])[ichannel] = 0;
662 }
663 ichannel++;
664 }
665 }
666
667 cstream << "calPads" <<
668 "sector=" << isector;
669
670 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
671 cstream << "calPads" <<
672 (Char_t*)((names[ivalue] + "_Median=").Data()) << median[ivalue] <<
673 (Char_t*)((names[ivalue] + "_Mean=").Data()) << mean[ivalue] <<
674 (Char_t*)((names[ivalue] + "_RMS=").Data()) << rms[ivalue] <<
675 (Char_t*)((names[ivalue] + "_LTM=").Data()) << ltm[ivalue] <<
676 (Char_t*)((names[ivalue] + "_RMS_LTM=").Data()) << ltmrms[ivalue];
677 if (outlierPad) {
678 cstream << "calPads" <<
679 (Char_t*)((names[ivalue] + "_Median_OutlierCutted=").Data()) << medianWithOut[ivalue] <<
680 (Char_t*)((names[ivalue] + "_Mean_OutlierCutted=").Data()) << meanWithOut[ivalue] <<
681 (Char_t*)((names[ivalue] + "_RMS_OutlierCutted=").Data()) << rmsWithOut[ivalue] <<
682 (Char_t*)((names[ivalue] + "_LTM_OutlierCutted=").Data()) << ltmWithOut[ivalue] <<
683 (Char_t*)((names[ivalue] + "_RMS_LTM_OutlierCutted=").Data()) << ltmrmsWithOut[ivalue];
684 }
685 }
686
687 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
688 cstream << "calPads" <<
689 (Char_t*)((names[ivalue] + ".=").Data()) << &vectorArray[ivalue];
690 }
691
692 if (mapFileName) {
693 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
694 if (isector < 36)
695 cstream << "calPads" <<
696 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapIROCArray[ivalue];
697 else
698 cstream << "calPads" <<
699 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapOROCArray[ivalue];
700 }
701 }
702
703 cstream << "calPads" <<
704 "row.=" << &posArray[0] <<
705 "pad.=" << &posArray[1] <<
706 "lx.=" << &posArray[2] <<
707 "ly.=" << &posArray[3] <<
708 "gx.=" << &posArray[4] <<
709 "gy.=" << &posArray[5] <<
710 "rpad.=" << &posArray[6] <<
711 "channel.=" << &posArray[7];
712
713 cstream << "calPads" <<
714 "\n";
715
716 delete[] posArray;
717 delete[] vectorArray;
718 }
719
720
721 delete[] names;
722 if (mapFileName) {
723 delete mapIROCs;
724 delete mapOROCs;
725 delete[] mapIROCArray;
726 delete[] mapOROCArray;
727 delete[] mapNames;
728 }
729}
3ac615eb 730
731
732
733void AliTPCcalibDB::RegisterExB(Int_t index, Float_t bz, Bool_t bdelete){
734 //
735 // Register static ExB correction map
736 // index - registration index - used for visualization
737 // bz - bz field in kGaus
738
0a997b33 739 // Float_t factor = bz/(-5.); // default b filed in Cheb with minus sign
740 Float_t factor = bz/(5.); // default b filed in Cheb with minus sign
741 // was chenged in the Revision ???? (Ruben can you add here number)
3ac615eb 742
f7a1cc68 743 AliMagF* bmap = new AliMagF("MapsExB","MapsExB", 2,factor,1., 10.,AliMagF::k5kG,"$(ALICE_ROOT)/data/maps/mfchebKGI_sym.root");
3ac615eb 744
745 AliTPCExBFirst *exb = new AliTPCExBFirst(bmap,0.88*2.6400e+04,50,50,50);
746 AliTPCExB::SetInstance(exb);
747
748 if (bdelete){
749 delete bmap;
750 }else{
751 AliTPCExB::RegisterField(index,bmap);
752 }
753 if (index>=fgExBArray.GetEntries()) fgExBArray.Expand((index+1)*2+11);
754 fgExBArray.AddAt(exb,index);
755}
756
757
758AliTPCExB* AliTPCcalibDB::GetExB(Float_t bz, Bool_t deleteB) {
759 //
760 // bz filed in KGaus not in tesla
761 // Get ExB correction map
762 // if doesn't exist - create it
763 //
764 Int_t index = TMath::Nint(5+bz);
765 if (index>fgExBArray.GetEntries()) fgExBArray.Expand((index+1)*2+11);
766 if (!fgExBArray.At(index)) AliTPCcalibDB::RegisterExB(index,bz,deleteB);
767 return (AliTPCExB*)fgExBArray.At(index);
768}
769
770
771void AliTPCcalibDB::SetExBField(Float_t bz){
772 //
773 // Set magnetic filed for ExB correction
774 //
775 fExB = GetExB(bz,kFALSE);
776}
bf85fe4d 777
0a997b33 778void AliTPCcalibDB::SetExBField(const AliMagF* bmap){
779 //
780 // Set magnetic field for ExB correction
781 //
782 AliTPCExBFirst *exb = new AliTPCExBFirst(bmap,0.88*2.6400e+04,50,50,50);
783 AliTPCExB::SetInstance(exb);
784 fExB=exb;
785}
786
bf85fe4d 787
788
5e1215d4 789
790
791void AliTPCcalibDB::UpdateRunInformations( Int_t run, Bool_t force){
bf85fe4d 792 //
793 // - > Don't use it for reconstruction - Only for Calibration studies
794 //
795 AliCDBEntry * entry = 0;
796 if (run>= fRunList.GetSize()){
797 fRunList.Set(run*2+1);
da6c0bc9 798 fGRPArray.Expand(run*2+1);
0231c65f 799 fGRPMaps.Expand(run*2+1);
e2914767 800 fGoofieArray.Expand(run*2+1);
801 fVoltageArray.Expand(run*2+1);
da6c0bc9 802 fTemperatureArray.Expand(run*2+1);
803 fVdriftArray.Expand(run*2+1);
5e1215d4 804 fDriftCorrectionArray.Expand(run*2+1);
a2c3785e 805 fTimeGainSplinesArray.Expand(run*2+1);
bf85fe4d 806 }
5e1215d4 807 if (fRunList[run]>0 &&force==kFALSE) return;
808 //
bf85fe4d 809 entry = AliCDBManager::Instance()->Get("GRP/GRP/Data",run);
0231c65f 810 if (entry) {
811 AliGRPObject * grpRun = dynamic_cast<AliGRPObject*>(entry->GetObject());
812 if (!grpRun){
813 TMap* map = dynamic_cast<TMap*>(entry->GetObject());
814 if (map){
e2914767 815 //grpRun = new AliGRPObject;
816 //grpRun->ReadValuesFromMap(map);
817 grpRun = MakeGRPObjectFromMap(map);
818
0231c65f 819 fGRPMaps.AddAt(map,run);
820 }
821 }
822 fGRPArray.AddAt(grpRun,run);
823 }
bf85fe4d 824 entry = AliCDBManager::Instance()->Get("TPC/Calib/Goofie",run);
5e1215d4 825 if (entry){
826 fGoofieArray.AddAt(entry->GetObject(),run);
827 }
e2914767 828 //
829 entry = AliCDBManager::Instance()->Get("TPC/Calib/HighVoltage",run);
5e1215d4 830 if (entry) {
831 fVoltageArray.AddAt(entry->GetObject(),run);
832 }
e2914767 833 //
a2c3785e 834 entry = AliCDBManager::Instance()->Get("TPC/Calib/TimeGain",run);
5e1215d4 835 if (entry) {
836 fTimeGainSplinesArray.AddAt(entry->GetObject(),run);
837 }
838 //
839 entry = AliCDBManager::Instance()->Get("TPC/Calib/TimeDrift",run);
840 if (entry) {
841 fDriftCorrectionArray.AddAt(entry->GetObject(),run);
842 }
a2c3785e 843 //
bf85fe4d 844 entry = AliCDBManager::Instance()->Get("TPC/Calib/Temperature",run);
5e1215d4 845 if (entry) {
846 fTemperatureArray.AddAt(entry->GetObject(),run);
847 }
bf85fe4d 848 fRunList[run]=1; // sign as used
da6c0bc9 849
bfec3eeb 850 AliDCSSensor * press = GetPressureSensor(run,0);
da6c0bc9 851 AliTPCSensorTempArray * temp = GetTemperatureSensor(run);
852 if (press && temp){
853 AliTPCCalibVdrift * vdrift = new AliTPCCalibVdrift(temp, press,0);
854 fVdriftArray.AddAt(vdrift,run);
855 }
bf85fe4d 856}
857
858
859Float_t AliTPCcalibDB::GetGain(Int_t sector, Int_t row, Int_t pad){
860 //
861 //
862 AliTPCCalPad *calPad = Instance()->fDedxGainFactor;;
863 if (!calPad) return 0;
864 return calPad->GetCalROC(sector)->GetValue(row,pad);
865}
866
8de77f00 867
868AliGRPObject *AliTPCcalibDB::GetGRP(Int_t run){
869 //
870 // Get GRP object for given run
871 //
872 AliGRPObject * grpRun = dynamic_cast<AliGRPObject *>((Instance()->fGRPArray).At(run));
873 if (!grpRun) {
5e1215d4 874 Instance()->UpdateRunInformations(run);
8de77f00 875 grpRun = dynamic_cast<AliGRPObject *>(Instance()->fGRPArray.At(run));
876 if (!grpRun) return 0;
877 }
878 return grpRun;
879}
880
0231c65f 881TMap * AliTPCcalibDB::GetGRPMap(Int_t run){
882 //
883 //
884 //
885 TMap * grpRun = dynamic_cast<TMap *>((Instance()->fGRPMaps).At(run));
886 if (!grpRun) {
5e1215d4 887 Instance()->UpdateRunInformations(run);
0231c65f 888 grpRun = dynamic_cast<TMap *>(Instance()->fGRPMaps.At(run));
889 if (!grpRun) return 0;
890 }
891 return grpRun;
892}
8de77f00 893
894
da6c0bc9 895AliDCSSensor * AliTPCcalibDB::GetPressureSensor(Int_t run, Int_t type){
bf85fe4d 896 //
0231c65f 897 // Get Pressure sensor
bfec3eeb 898 // run = run number
899 // type = 0 - Cavern pressure
900 // 1 - Suface pressure
0231c65f 901 // First try to get if trom map - if existing (Old format of data storing)
bf85fe4d 902 //
bfec3eeb 903
904
0231c65f 905 TMap *map = GetGRPMap(run);
906 if (map){
907 AliDCSSensor * sensor = 0;
908 TObject *osensor=0;
909 if (type==0) osensor = ((*map)("fCavernPressure"));
910 if (type==1) osensor = ((*map)("fP2Pressure"));
911 sensor =dynamic_cast<AliDCSSensor *>(osensor);
912 if (sensor) return sensor;
913 }
914 //
915 // If not map try to get it from the GRPObject
916 //
917 AliGRPObject * grpRun = dynamic_cast<AliGRPObject *>(fGRPArray.At(run));
bf85fe4d 918 if (!grpRun) {
5e1215d4 919 UpdateRunInformations(run);
efdbb95a 920 grpRun = dynamic_cast<AliGRPObject *>(fGRPArray.At(run));
bf85fe4d 921 if (!grpRun) return 0;
922 }
923 AliDCSSensor * sensor = grpRun->GetCavernAtmosPressure();
da6c0bc9 924 if (type==1) sensor = grpRun->GetSurfaceAtmosPressure();
925 return sensor;
bf85fe4d 926}
927
928AliTPCSensorTempArray * AliTPCcalibDB::GetTemperatureSensor(Int_t run){
929 //
930 // Get temperature sensor array
931 //
932 AliTPCSensorTempArray * tempArray = (AliTPCSensorTempArray *)fTemperatureArray.At(run);
933 if (!tempArray) {
5e1215d4 934 UpdateRunInformations(run);
bf85fe4d 935 tempArray = (AliTPCSensorTempArray *)fTemperatureArray.At(run);
936 }
937 return tempArray;
938}
939
a2c3785e 940
941TObjArray * AliTPCcalibDB::GetTimeGainSplinesRun(Int_t run){
bf85fe4d 942 //
943 // Get temperature sensor array
944 //
a2c3785e 945 TObjArray * gainSplines = (TObjArray *)fTimeGainSplinesArray.At(run);
946 if (!gainSplines) {
5e1215d4 947 UpdateRunInformations(run);
a2c3785e 948 gainSplines = (TObjArray *)fTimeGainSplinesArray.At(run);
bf85fe4d 949 }
a2c3785e 950 return gainSplines;
bf85fe4d 951}
952
e2914767 953AliDCSSensorArray * AliTPCcalibDB::GetVoltageSensors(Int_t run){
954 //
955 // Get temperature sensor array
956 //
957 AliDCSSensorArray * voltageArray = (AliDCSSensorArray *)fVoltageArray.At(run);
958 if (!voltageArray) {
5e1215d4 959 UpdateRunInformations(run);
e2914767 960 voltageArray = (AliDCSSensorArray *)fVoltageArray.At(run);
961 }
962 return voltageArray;
963}
964
99895a4f 965AliDCSSensorArray * AliTPCcalibDB::GetGoofieSensors(Int_t run){
966 //
967 // Get temperature sensor array
968 //
969 AliDCSSensorArray * goofieArray = (AliDCSSensorArray *)fGoofieArray.At(run);
970 if (!goofieArray) {
5e1215d4 971 UpdateRunInformations(run);
99895a4f 972 goofieArray = (AliDCSSensorArray *)fGoofieArray.At(run);
973 }
974 return goofieArray;
975}
976
977
978
da6c0bc9 979AliTPCCalibVdrift * AliTPCcalibDB::GetVdrift(Int_t run){
980 //
981 // Get the interface to the the vdrift
982 //
983 AliTPCCalibVdrift * vdrift = (AliTPCCalibVdrift*)fVdriftArray.At(run);
984 if (!vdrift) {
5e1215d4 985 UpdateRunInformations(run);
da6c0bc9 986 vdrift= (AliTPCCalibVdrift*)fVdriftArray.At(run);
987 }
988 return vdrift;
989}
990
892226be 991Float_t AliTPCcalibDB::GetCEdriftTime(Int_t run, Int_t sector, Double_t timeStamp, Int_t *entries)
992{
993 //
994 // GetCE drift time information for 'sector'
995 // sector 72 is the mean drift time of the A-Side
996 // sector 73 is the mean drift time of the C-Side
997 // it timestamp==-1 return mean value
998 //
999 AliTPCcalibDB::Instance()->SetRun(run);
1000 TGraph *gr=AliTPCcalibDB::Instance()->GetCErocTgraph(sector);
1001 if (!gr||sector<0||sector>73) {
1002 if (entries) *entries=0;
1003 return 0.;
1004 }
1005 Float_t val=0.;
1006 if (timeStamp==-1.){
1007 val=gr->GetMean(2);
1008 }else{
1009 for (Int_t ipoint=0;ipoint<gr->GetN();++ipoint){
1010 Double_t x,y;
1011 gr->GetPoint(ipoint,x,y);
1012 if (x<timeStamp) continue;
1013 val=y;
1014 break;
1015 }
1016 }
1017 return val;
1018}
1019
1020Float_t AliTPCcalibDB::GetCEchargeTime(Int_t run, Int_t sector, Double_t timeStamp, Int_t *entries)
1021{
1022 //
1023 // GetCE mean charge for 'sector'
1024 // it timestamp==-1 return mean value
1025 //
1026 AliTPCcalibDB::Instance()->SetRun(run);
1027 TGraph *gr=AliTPCcalibDB::Instance()->GetCErocQgraph(sector);
1028 if (!gr||sector<0||sector>71) {
1029 if (entries) *entries=0;
1030 return 0.;
1031 }
1032 Float_t val=0.;
1033 if (timeStamp==-1.){
1034 val=gr->GetMean(2);
1035 }else{
1036 for (Int_t ipoint=0;ipoint<gr->GetN();++ipoint){
1037 Double_t x,y;
1038 gr->GetPoint(ipoint,x,y);
1039 if (x<timeStamp) continue;
1040 val=y;
1041 break;
1042 }
1043 }
1044 return val;
1045}
1046
7fff7612 1047Float_t AliTPCcalibDB::GetDCSSensorValue(AliDCSSensorArray *arr, Int_t timeStamp, const char * sensorName, Int_t sigDigits)
1048{
1049 //
1050 // Get Value for a DCS sensor 'sensorName', run 'run' at time 'timeStamp'
1051 //
1052 Float_t val=0;
1053 const TString sensorNameString(sensorName);
1054 AliDCSSensor *sensor = arr->GetSensor(sensorNameString);
1055 if (!sensor) return val;
892226be 1056 //use the dcs graph if possible
1057 TGraph *gr=sensor->GetGraph();
1058 if (gr){
1059 for (Int_t ipoint=0;ipoint<gr->GetN();++ipoint){
1060 Double_t x,y;
1061 gr->GetPoint(ipoint,x,y);
1062 Int_t time=sensor->GetStartTime()+x*3600; //time in graph is hours
1063 if (time<timeStamp) continue;
1064 val=y;
1065 break;
1066 }
1067 //if val is still 0, test if if the requested time if within 5min of the first/last
1068 //data point. If this is the case return the firs/last entry
1069 //the timestamps might not be syncronised for all calibration types, sometimes a 'pre'
1070 //and 'pos' period is requested. Especially to the HV this is not the case!
1071 //first point
1072 if (val==0 ){
1073 Double_t x,y;
1074 gr->GetPoint(0,x,y);
1075 Int_t time=sensor->GetStartTime()+x*3600; //time in graph is hours
1076 if ((time-timeStamp)<5*60) val=y;
1077 }
1078 //last point
1079 if (val==0 ){
1080 Double_t x,y;
1081 gr->GetPoint(gr->GetN()-1,x,y);
1082 Int_t time=sensor->GetStartTime()+x*3600; //time in graph is hours
1083 if ((timeStamp-time)<5*60) val=y;
1084 }
1085 } else {
1086 val=sensor->GetValue(timeStamp);
1087 }
7fff7612 1088 if (sigDigits>=0){
1089 val=(Float_t)TMath::Floor(val * TMath::Power(10., sigDigits) + .5) / TMath::Power(10., sigDigits);
1090 }
1091 return val;
1092}
1093
1094Float_t AliTPCcalibDB::GetDCSSensorMeanValue(AliDCSSensorArray *arr, const char * sensorName, Int_t sigDigits)
1095{
1096 //
1097 // Get mean Value for a DCS sensor 'sensorName' during run 'run'
1098 //
1099 Float_t val=0;
1100 const TString sensorNameString(sensorName);
1101 AliDCSSensor *sensor = arr->GetSensor(sensorNameString);
1102 if (!sensor) return val;
892226be 1103
1104 //use dcs graph if it exists
1105 TGraph *gr=sensor->GetGraph();
1106 if (gr){
1107 val=gr->GetMean(2);
1108 } else {
1109 //if we don't have the dcs graph, try to get some meaningful information
1110 if (!sensor->GetFit()) return val;
1111 Int_t nKnots=sensor->GetFit()->GetKnots();
1112 Double_t tMid=(sensor->GetEndTime()-sensor->GetStartTime())/2.;
1113 for (Int_t iKnot=0;iKnot<nKnots;++iKnot){
1114 if (sensor->GetFit()->GetX()[iKnot]>tMid/3600.) break;
1115 val=(Float_t)sensor->GetFit()->GetY0()[iKnot];
1116 }
7fff7612 1117 }
7fff7612 1118 if (sigDigits>=0){
1119 val/=10;
1120 val=(Float_t)TMath::Floor(val * TMath::Power(10., sigDigits) + .5) / TMath::Power(10., sigDigits);
1121 val*=10;
1122 }
1123 return val;
1124}
bf85fe4d 1125
7fff7612 1126Float_t AliTPCcalibDB::GetChamberHighVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits) {
e2914767 1127 //
1128 // return the chamber HV for given run and time: 0-35 IROC, 36-72 OROC
7fff7612 1129 // if timeStamp==-1 return mean value
1130 //
1131 Float_t val=0;
1132 TString sensorName="";
1133 TTimeStamp stamp(timeStamp);
1134 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1135 if (!voltageArray || (sector<0) || (sector>71)) return val;
1136 Char_t sideName='A';
1137 if ((sector/18)%2==1) sideName='C';
1138 if (sector<36){
1139 //IROC
1140 sensorName=Form("TPC_ANODE_I_%c%02d_VMEAS",sideName,sector%18);
1141 }else{
1142 //OROC
1143 sensorName=Form("TPC_ANODE_O_%c%02d_0_VMEAS",sideName,sector%18);
1144 }
1145 if (timeStamp==-1){
1146 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1147 } else {
1148 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1149 }
1150 return val;
1151}
1152Float_t AliTPCcalibDB::GetSkirtVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1153{
1154 //
1155 // Get the skirt voltage for 'run' at 'timeStamp' and 'sector': 0-35 IROC, 36-72 OROC
1156 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1157 // if timeStamp==-1 return the mean value for the run
1158 //
1159 Float_t val=0;
1160 TString sensorName="";
1161 TTimeStamp stamp(timeStamp);
1162 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1163 if (!voltageArray || (sector<0) || (sector>71)) return val;
1164 Char_t sideName='A';
1165 if ((sector/18)%2==1) sideName='C';
1166 sensorName=Form("TPC_SKIRT_%c_VMEAS",sideName);
1167 if (timeStamp==-1){
1168 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1169 } else {
1170 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1171 }
1172 return val;
1173}
1174
1175Float_t AliTPCcalibDB::GetCoverVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1176{
1177 //
1178 // Get the cover voltage for run 'run' at time 'timeStamp'
1179 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1180 // if timeStamp==-1 return the mean value for the run
e2914767 1181 //
7fff7612 1182 Float_t val=0;
1183 TString sensorName="";
e2914767 1184 TTimeStamp stamp(timeStamp);
1185 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
7fff7612 1186 if (!voltageArray || (sector<0) || (sector>71)) return val;
1187 Char_t sideName='A';
1188 if ((sector/18)%2==1) sideName='C';
1189 if (sector<36){
1190 //IROC
1191 sensorName=Form("TPC_COVER_I_%c_VMEAS",sideName);
1192 }else{
1193 //OROC
1194 sensorName=Form("TPC_COVER_O_%c_VMEAS",sideName);
1195 }
1196 if (timeStamp==-1){
1197 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1198 } else {
1199 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1200 }
1201 return val;
1202}
1203
1204Float_t AliTPCcalibDB::GetGGoffsetVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1205{
1206 //
1207 // Get the GG offset voltage for run 'run' at time 'timeStamp'
1208 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1209 // if timeStamp==-1 return the mean value for the run
1210 //
1211 Float_t val=0;
1212 TString sensorName="";
1213 TTimeStamp stamp(timeStamp);
1214 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1215 if (!voltageArray || (sector<0) || (sector>71)) return val;
1216 Char_t sideName='A';
1217 if ((sector/18)%2==1) sideName='C';
1218 if (sector<36){
1219 //IROC
1220 sensorName=Form("TPC_GATE_I_%c_OFF_VMEAS",sideName);
1221 }else{
1222 //OROC
1223 sensorName=Form("TPC_GATE_O_%c_OFF_VMEAS",sideName);
1224 }
1225 if (timeStamp==-1){
1226 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1227 } else {
1228 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1229 }
1230 return val;
1231}
1232
1233Float_t AliTPCcalibDB::GetGGnegVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1234{
1235 //
1236 // Get the GG offset voltage for run 'run' at time 'timeStamp'
1237 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1238 // if timeStamp==-1 return the mean value for the run
1239 //
1240 Float_t val=0;
1241 TString sensorName="";
1242 TTimeStamp stamp(timeStamp);
1243 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1244 if (!voltageArray || (sector<0) || (sector>71)) return val;
1245 Char_t sideName='A';
1246 if ((sector/18)%2==1) sideName='C';
1247 if (sector<36){
1248 //IROC
1249 sensorName=Form("TPC_GATE_I_%c_NEG_VMEAS",sideName);
1250 }else{
1251 //OROC
1252 sensorName=Form("TPC_GATE_O_%c_NEG_VMEAS",sideName);
1253 }
1254 if (timeStamp==-1){
1255 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1256 } else {
1257 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1258 }
1259 return val;
1260}
1261
1262Float_t AliTPCcalibDB::GetGGposVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1263{
1264 //
1265 // Get the GG offset voltage for run 'run' at time 'timeStamp'
1266 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1267 // if timeStamp==-1 return the mean value for the run
1268 //
1269 Float_t val=0;
1270 TString sensorName="";
1271 TTimeStamp stamp(timeStamp);
1272 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1273 if (!voltageArray || (sector<0) || (sector>71)) return val;
1274 Char_t sideName='A';
1275 if ((sector/18)%2==1) sideName='C';
1276 if (sector<36){
1277 //IROC
1278 sensorName=Form("TPC_GATE_I_%c_POS_VMEAS",sideName);
1279 }else{
1280 //OROC
1281 sensorName=Form("TPC_GATE_O_%c_POS_VMEAS",sideName);
1282 }
1283 if (timeStamp==-1){
1284 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1285 } else {
1286 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1287 }
1288 return val;
e2914767 1289}
bf85fe4d 1290
da6c0bc9 1291Float_t AliTPCcalibDB::GetPressure(Int_t timeStamp, Int_t run, Int_t type){
bf85fe4d 1292 //
1293 // GetPressure for given time stamp and runt
1294 //
1295 TTimeStamp stamp(timeStamp);
da6c0bc9 1296 AliDCSSensor * sensor = Instance()->GetPressureSensor(run,type);
bf85fe4d 1297 if (!sensor) return 0;
bf85fe4d 1298 return sensor->GetValue(stamp);
1299}
1300
5312f439 1301Float_t AliTPCcalibDB::GetL3Current(Int_t run, Int_t statType){
1302 //
1303 // return L3 current
1304 // stat type is: AliGRPObject::Stats: kMean = 0, kTruncMean = 1, kMedian = 2, kSDMean = 3, kSDMedian = 4
1305 //
1306 Float_t current=-1;
1307 AliGRPObject *grp=AliTPCcalibDB::GetGRP(run);
1308 if (grp) current=grp->GetL3Current((AliGRPObject::Stats)statType);
1309 return current;
1310}
1311
1312Float_t AliTPCcalibDB::GetBz(Int_t run){
1313 //
e6970ab5 1314 // calculate BZ in T from L3 current
5312f439 1315 //
1316 Float_t bz=-1;
1317 Float_t current=AliTPCcalibDB::GetL3Current(run);
e6970ab5 1318 if (current>-1) bz=5*current/30000.*.1;
5312f439 1319 return bz;
1320}
1321
1322Char_t AliTPCcalibDB::GetL3Polarity(Int_t run) {
1323 //
1324 // get l3 polarity from GRP
1325 //
1326 return AliTPCcalibDB::GetGRP(run)->GetL3Polarity();
1327}
1328
1329TString AliTPCcalibDB::GetRunType(Int_t run){
1330 //
1331 // return run type from grp
1332 //
1333 return AliTPCcalibDB::GetGRP(run)->GetRunType();
1334}
1335
7f7847fe 1336Float_t AliTPCcalibDB::GetValueGoofie(Int_t timeStamp, Int_t run, Int_t type){
1337 //
1338 // GetPressure for given time stamp and runt
1339 //
1340 TTimeStamp stamp(timeStamp);
1341 AliDCSSensorArray* goofieArray = AliTPCcalibDB::Instance()->GetGoofieSensors(run);
1342 if (!goofieArray) return 0;
1343 AliDCSSensor *sensor = goofieArray->GetSensor(type);
1344 return sensor->GetValue(stamp);
1345}
1346
1347
1348
1349
1350
1351
f0269955 1352Bool_t AliTPCcalibDB::GetTemperatureFit(Int_t timeStamp, Int_t run, Int_t side,TVectorD& fit){
1353 //
1354 //
1355 //
1356 TTimeStamp tstamp(timeStamp);
64b48395 1357 AliTPCSensorTempArray* tempArray = Instance()->GetTemperatureSensor(run);
f0269955 1358 if (! tempArray) return kFALSE;
1359 AliTPCTempMap * tempMap = new AliTPCTempMap(tempArray);
1360 TLinearFitter * fitter = tempMap->GetLinearFitter(3,side,tstamp);
1361 if (fitter){
1362 fitter->Eval();
1363 fitter->GetParameters(fit);
1364 }
1365 delete fitter;
1366 delete tempMap;
1367 if (!fitter) return kFALSE;
1368 return kTRUE;
1369}
1370
64b48395 1371Float_t AliTPCcalibDB::GetTemperature(Int_t timeStamp, Int_t run, Int_t side){
1372 //
1373 //
1374 //
12e42756 1375 TVectorD vec(5);
64b48395 1376 if (side==0) {
1377 GetTemperatureFit(timeStamp,run,0,vec);
1378 return vec[0];
1379 }
1380 if (side==1){
1381 GetTemperatureFit(timeStamp,run,0,vec);
1382 return vec[0];
1383 }
57dc06f2 1384 return 0;
64b48395 1385}
bf85fe4d 1386
1387
da6c0bc9 1388Double_t AliTPCcalibDB::GetPTRelative(UInt_t timeSec, Int_t run, Int_t side){
1389 //
1390 // Get relative P/T
1391 // time - absolute time
1392 // run - run number
1393 // side - 0 - A side 1-C side
1394 AliTPCCalibVdrift * vdrift = Instance()->GetVdrift(run);
1395 if (!vdrift) return 0;
1396 return vdrift->GetPTRelative(timeSec,side);
1397}
1398
e2914767 1399AliGRPObject * AliTPCcalibDB::MakeGRPObjectFromMap(TMap *map){
1400 //
1401 // Function to covert old GRP run information from TMap to GRPObject
1402 //
1403 // TMap * map = AliTPCcalibDB::GetGRPMap(52406);
1404 if (!map) return 0;
1405 AliDCSSensor * sensor = 0;
1406 TObject *osensor=0;
1407 osensor = ((*map)("fP2Pressure"));
1408 sensor =dynamic_cast<AliDCSSensor *>(osensor);
1409 //
1410 if (!sensor) return 0;
1411 //
1412 AliDCSSensor * sensor2 = new AliDCSSensor(*sensor);
1413 osensor = ((*map)("fCavernPressure"));
1414 TGraph * gr = new TGraph(2);
1415 gr->GetX()[0]= -100000.;
1416 gr->GetX()[1]= 1000000.;
1417 gr->GetY()[0]= atof(osensor->GetName());
1418 gr->GetY()[1]= atof(osensor->GetName());
1419 sensor2->SetGraph(gr);
1420 sensor2->SetFit(0);
1421
1422
1423 AliGRPObject *grpRun = new AliGRPObject;
1424 grpRun->ReadValuesFromMap(map);
1425 grpRun->SetCavernAtmosPressure(sensor2);
1426 grpRun->SetSurfaceAtmosPressure(sensor);
1427 return grpRun;
1428}
1429
5312f439 1430Bool_t AliTPCcalibDB::CreateGUITree(Int_t run, const char* filename)
1431{
1432 //
1433 // Create a gui tree for run number 'run'
1434 //
e2914767 1435
5312f439 1436 if (!AliCDBManager::Instance()->GetDefaultStorage()){
1437 AliLog::Message(AliLog::kError, "Default Storage not set. Cannot create Calibration Tree!",
1438 MODULENAME(), "AliTPCcalibDB", FUNCTIONNAME(), __FILE__, __LINE__);
1439 return kFALSE;
1440 }
1441 //db instance
1442 AliTPCcalibDB *db=AliTPCcalibDB::Instance();
1443 // retrieve cal pad objects
1444 db->SetRun(run);
1445 AliTPCPreprocessorOnline prep;
1446 //noise and pedestals
1447 prep.AddComponent(db->GetPedestals());
1448 prep.AddComponent(db->GetPadNoise());
1449 //pulser data
1450 prep.AddComponent(db->GetPulserTmean());
1451 prep.AddComponent(db->GetPulserTrms());
1452 prep.AddComponent(db->GetPulserQmean());
1453 //CE data
1454 prep.AddComponent(db->GetCETmean());
1455 prep.AddComponent(db->GetCETrms());
1456 prep.AddComponent(db->GetCEQmean());
1457 //Altro data
1458 prep.AddComponent(db->GetALTROAcqStart() );
1459 prep.AddComponent(db->GetALTROZsThr() );
1460 prep.AddComponent(db->GetALTROFPED() );
1461 prep.AddComponent(db->GetALTROAcqStop() );
1462 prep.AddComponent(db->GetALTROMasked() );
1463 //
1464 TString file(filename);
1465 if (file.IsNull()) file=Form("guiTreeRun_%d.root",run);
1466 prep.DumpToFile(file.Data());
1467 return kTRUE;
1468}
e2914767 1469