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