]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/AliTPCcalibDB.cxx
Coverity fixes
[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>
949d8707 85#include <AliCDBId.h>
c5bbaa2c 86#include <AliLog.h>
3ac615eb 87#include <AliMagF.h>
7fff7612 88#include <AliSplineFit.h>
f14d21a1 89#include <AliCTPTimeParams.h>
c5bbaa2c 90
91#include "AliTPCcalibDB.h"
949d8707 92#include "AliTPCdataQA.h"
817766d5 93#include "AliTPCcalibDButil.h"
d6834f5f 94#include "AliTPCAltroMapping.h"
418bbcaf 95#include "AliTPCExB.h"
c5bbaa2c 96
97#include "AliTPCCalROC.h"
98#include "AliTPCCalPad.h"
54472e4f 99#include "AliTPCSensorTempArray.h"
bf85fe4d 100#include "AliGRPObject.h"
418bbcaf 101#include "AliTPCTransform.h"
f6b5fa33 102#include "AliTPCmapper.h"
d6834f5f 103
418bbcaf 104class AliCDBStorage;
105class AliTPCCalDet;
86df2b3a 106//
107//
108
86df2b3a 109#include "TFile.h"
110#include "TKey.h"
43a74775 111#include "TGraphErrors.h"
86df2b3a 112
113#include "TObjArray.h"
114#include "TObjString.h"
115#include "TString.h"
7390f655 116#include "TDirectory.h"
f6b5fa33 117#include "TArrayI.h"
86df2b3a 118#include "AliTPCCalPad.h"
0fe7645c 119#include "AliTPCCalibPulser.h"
86df2b3a 120#include "AliTPCCalibPedestal.h"
121#include "AliTPCCalibCE.h"
3ac615eb 122#include "AliTPCExBFirst.h"
bf85fe4d 123#include "AliTPCTempMap.h"
da6c0bc9 124#include "AliTPCCalibVdrift.h"
6e7d7dc4 125#include "AliTPCCalibRaw.h"
43a74775 126#include "AliTPCParam.h"
cf5b0aa0 127#include "AliTPCCorrection.h"
5312f439 128#include "AliTPCPreprocessorOnline.h"
86df2b3a 129
c5bbaa2c 130
131ClassImp(AliTPCcalibDB)
132
133AliTPCcalibDB* AliTPCcalibDB::fgInstance = 0;
134Bool_t AliTPCcalibDB::fgTerminated = kFALSE;
3ac615eb 135TObjArray AliTPCcalibDB::fgExBArray; // array of ExB corrections
c5bbaa2c 136
137
138//_ singleton implementation __________________________________________________
139AliTPCcalibDB* AliTPCcalibDB::Instance()
140{
141 //
142 // Singleton implementation
143 // Returns an instance of this class, it is created if neccessary
144 //
145
146 if (fgTerminated != kFALSE)
147 return 0;
148
149 if (fgInstance == 0)
150 fgInstance = new AliTPCcalibDB();
151
152 return fgInstance;
153}
154
155void AliTPCcalibDB::Terminate()
156{
157 //
158 // Singleton implementation
159 // Deletes the instance of this class and sets the terminated flag, instances cannot be requested anymore
160 // This function can be called several times.
161 //
162
163 fgTerminated = kTRUE;
164
165 if (fgInstance != 0)
166 {
167 delete fgInstance;
168 fgInstance = 0;
169 }
170}
171
172//_____________________________________________________________________________
e4dce695 173AliTPCcalibDB::AliTPCcalibDB():
9389f9a4 174 TObject(),
e4dce695 175 fRun(-1),
f5344549 176 fTransform(0),
481f877b 177 fExB(0),
e4dce695 178 fPadGainFactor(0),
9f6e9f81 179 fDedxGainFactor(0),
e4dce695 180 fPadTime0(0),
2293155b 181 fDistortionMap(0),
cf5b0aa0 182 fComposedCorrection(0),
0b736a46 183 fComposedCorrectionArray(0),
e4dce695 184 fPadNoise(0),
185 fPedestals(0),
6e7d7dc4 186 fCalibRaw(0),
949d8707 187 fDataQA(0),
5312f439 188 fALTROConfigData(0),
189 fPulserData(0),
190 fCEData(0),
e4dce695 191 fTemperature(0),
d6834f5f 192 fMapping(0),
96305e49 193 fParam(0),
a2c3785e 194 fClusterParam(0),
195 fTimeGainSplines(0),
196 fTimeGainSplinesArray(100000),
da6c0bc9 197 fGRPArray(100000), //! array of GRPs - per run - JUST for calibration studies
0231c65f 198 fGRPMaps(100000), //! array of GRPs - per run - JUST for calibration studies
da6c0bc9 199 fGoofieArray(100000), //! array of GOOFIE values -per run - Just for calibration studies
e2914767 200 fVoltageArray(100000),
da6c0bc9 201 fTemperatureArray(100000), //! array of temperature sensors - per run - Just for calibration studies
202 fVdriftArray(100000), //! array of v drift interfaces
5e1215d4 203 fDriftCorrectionArray(100000), //! array of drift correction
1e722a63 204 fRunList(100000), //! run list - indicates try to get the run param
f14d21a1 205 fDButil(0),
206 fCTPTimeParams(0)
c5bbaa2c 207{
208 //
209 // constructor
210 //
54472e4f 211 //
534fd34a 212 fgInstance=this;
c5bbaa2c 213 Update(); // temporary
214}
215
9389f9a4 216AliTPCcalibDB::AliTPCcalibDB(const AliTPCcalibDB& ):
217 TObject(),
218 fRun(-1),
219 fTransform(0),
220 fExB(0),
221 fPadGainFactor(0),
9f6e9f81 222 fDedxGainFactor(0),
9389f9a4 223 fPadTime0(0),
2293155b 224 fDistortionMap(0),
cf5b0aa0 225 fComposedCorrection(0),
0b736a46 226 fComposedCorrectionArray(0),
9389f9a4 227 fPadNoise(0),
228 fPedestals(0),
6e7d7dc4 229 fCalibRaw(0),
949d8707 230 fDataQA(0),
5312f439 231 fALTROConfigData(0),
232 fPulserData(0),
233 fCEData(0),
9389f9a4 234 fTemperature(0),
235 fMapping(0),
9389f9a4 236 fParam(0),
bf85fe4d 237 fClusterParam(0),
a2c3785e 238 fTimeGainSplines(0),
239 fTimeGainSplinesArray(100000),
bf85fe4d 240 fGRPArray(0), //! array of GRPs - per run - JUST for calibration studies
0231c65f 241 fGRPMaps(0), //! array of GRPs - per run - JUST for calibration studies
bf85fe4d 242 fGoofieArray(0), //! array of GOOFIE values -per run - Just for calibration studies
e2914767 243 fVoltageArray(0),
bf85fe4d 244 fTemperatureArray(0), //! array of temperature sensors - per run - Just for calibration studies
da6c0bc9 245 fVdriftArray(0), //! array of v drift interfaces
5647625c 246 fDriftCorrectionArray(0), //! array of v drift corrections
1e722a63 247 fRunList(0), //! run list - indicates try to get the run param
f14d21a1 248 fDButil(0),
249 fCTPTimeParams(0)
9389f9a4 250{
251 //
252 // Copy constructor invalid -- singleton implementation
253 //
254 Error("copy constructor","invalid -- singleton implementation");
255}
256
257AliTPCcalibDB& AliTPCcalibDB::operator= (const AliTPCcalibDB& )
258{
259//
260// Singleton implementation - no assignment operator
261//
262 Error("operator =", "assignment operator not implemented");
263 return *this;
264}
265
266
267
c5bbaa2c 268//_____________________________________________________________________________
269AliTPCcalibDB::~AliTPCcalibDB()
270{
271 //
272 // destructor
273 //
68751c2c 274
c5bbaa2c 275}
8b63d99c 276AliTPCCalPad* AliTPCcalibDB::GetDistortionMap(Int_t i) const {
277 //
278 // get distortion map - due E field distortions
279 //
280 return (fDistortionMap) ? (AliTPCCalPad*)fDistortionMap->At(i):0;
281}
c5bbaa2c 282
283//_____________________________________________________________________________
284AliCDBEntry* AliTPCcalibDB::GetCDBEntry(const char* cdbPath)
285{
286 //
287 // Retrieves an entry with path <cdbPath> from the CDB.
288 //
289 char chinfo[1000];
290
68751c2c 291 AliCDBEntry* entry = AliCDBManager::Instance()->Get(cdbPath, fRun);
c5bbaa2c 292 if (!entry)
293 {
294 sprintf(chinfo,"AliTPCcalibDB: Failed to get entry:\t%s ", cdbPath);
295 AliError(chinfo);
296 return 0;
297 }
298 return entry;
299}
300
301
302//_____________________________________________________________________________
303void AliTPCcalibDB::SetRun(Long64_t run)
304{
305 //
306 // Sets current run number. Calibration data is read from the corresponding file.
307 //
308 if (fRun == run)
309 return;
a2c3785e 310 fRun = run;
c5bbaa2c 311 Update();
312}
313
314
315
316void AliTPCcalibDB::Update(){
92fb7d95 317 //
318 // cache the OCDB entries for simulation, reconstruction, calibration
319 //
320 //
a8f8b6a1 321 AliCDBEntry * entry=0;
68751c2c 322 Bool_t cdbCache = AliCDBManager::Instance()->GetCacheFlag(); // save cache status
323 AliCDBManager::Instance()->SetCacheFlag(kTRUE); // activate CDB cache
1e722a63 324 fDButil = new AliTPCcalibDButil;
c5bbaa2c 325 //
5647625c 326
c5bbaa2c 327 entry = GetCDBEntry("TPC/Calib/PadGainFactor");
328 if (entry){
68751c2c 329 //if (fPadGainFactor) delete fPadGainFactor;
c5bbaa2c 330 entry->SetOwner(kTRUE);
331 fPadGainFactor = (AliTPCCalPad*)entry->GetObject();
2293155b 332 }else{
be67055b 333 AliFatal("TPC - Missing calibration entry TPC/Calib/PadGainFactor")
c5bbaa2c 334 }
335 //
3af3fbc4 336 entry = GetCDBEntry("TPC/Calib/TimeGain");
337 if (entry){
338 //if (fTimeGainSplines) delete fTimeGainSplines;
339 entry->SetOwner(kTRUE);
340 fTimeGainSplines = (TObjArray*)entry->GetObject();
2293155b 341 }else{
be67055b 342 AliFatal("TPC - Missing calibration entry TPC/Calib/Timegain")
3af3fbc4 343 }
344 //
9f6e9f81 345 entry = GetCDBEntry("TPC/Calib/GainFactorDedx");
346 if (entry){
347 entry->SetOwner(kTRUE);
348 fDedxGainFactor = (AliTPCCalPad*)entry->GetObject();
2293155b 349 }else{
be67055b 350 AliFatal("TPC - Missing calibration entry TPC/Calib/gainFactordEdx")
9f6e9f81 351 }
352 //
c5bbaa2c 353 entry = GetCDBEntry("TPC/Calib/PadTime0");
354 if (entry){
68751c2c 355 //if (fPadTime0) delete fPadTime0;
c5bbaa2c 356 entry->SetOwner(kTRUE);
357 fPadTime0 = (AliTPCCalPad*)entry->GetObject();
2293155b 358 }else{
359 AliFatal("TPC - Missing calibration entry")
c5bbaa2c 360 }
2293155b 361
8b63d99c 362 entry = GetCDBEntry("TPC/Calib/Distortion");
2293155b 363 if (entry){
364 //if (fPadTime0) delete fPadTime0;
365 entry->SetOwner(kTRUE);
8b63d99c 366 fDistortionMap =dynamic_cast<TObjArray*>(entry->GetObject());
2293155b 367 }else{
368 //AliFatal("TPC - Missing calibration entry")
369 }
370
371
c5bbaa2c 372 //
c5bbaa2c 373 //
374 entry = GetCDBEntry("TPC/Calib/PadNoise");
375 if (entry){
68751c2c 376 //if (fPadNoise) delete fPadNoise;
c5bbaa2c 377 entry->SetOwner(kTRUE);
378 fPadNoise = (AliTPCCalPad*)entry->GetObject();
2293155b 379 }else{
380 AliFatal("TPC - Missing calibration entry")
c5bbaa2c 381 }
8477f500 382
383 entry = GetCDBEntry("TPC/Calib/Pedestals");
384 if (entry){
385 //if (fPedestals) delete fPedestals;
386 entry->SetOwner(kTRUE);
387 fPedestals = (AliTPCCalPad*)entry->GetObject();
388 }
389
54472e4f 390 entry = GetCDBEntry("TPC/Calib/Temperature");
391 if (entry){
392 //if (fTemperature) delete fTemperature;
393 entry->SetOwner(kTRUE);
394 fTemperature = (AliTPCSensorTempArray*)entry->GetObject();
395 }
396
8477f500 397 entry = GetCDBEntry("TPC/Calib/Parameters");
398 if (entry){
54472e4f 399 //if (fPadNoise) delete fPadNoise;
8477f500 400 entry->SetOwner(kTRUE);
a778f7e3 401 fParam = (AliTPCParam*)(entry->GetObject()->Clone());
2293155b 402 }else{
be67055b 403 AliFatal("TPC - Missing calibration entry TPC/Calib/Parameters")
8477f500 404 }
405
96305e49 406 entry = GetCDBEntry("TPC/Calib/ClusterParam");
407 if (entry){
96305e49 408 entry->SetOwner(kTRUE);
409 fClusterParam = (AliTPCClusterParam*)(entry->GetObject()->Clone());
2293155b 410 }else{
411 AliFatal("TPC - Missing calibration entry")
96305e49 412 }
413
5312f439 414 //ALTRO configuration data
415 entry = GetCDBEntry("TPC/Calib/AltroConfig");
416 if (entry){
417 entry->SetOwner(kTRUE);
418 fALTROConfigData=(TObjArray*)(entry->GetObject());
2293155b 419 }else{
420 AliFatal("TPC - Missing calibration entry")
5312f439 421 }
422
423 //Calibration Pulser data
424 entry = GetCDBEntry("TPC/Calib/Pulser");
425 if (entry){
426 entry->SetOwner(kTRUE);
427 fPulserData=(TObjArray*)(entry->GetObject());
428 }
429
430 //CE data
431 entry = GetCDBEntry("TPC/Calib/CE");
432 if (entry){
433 entry->SetOwner(kTRUE);
434 fCEData=(TObjArray*)(entry->GetObject());
435 }
6e7d7dc4 436 //RAW calibration data
56ce896d 437 // entry = GetCDBEntry("TPC/Calib/Raw");
5312f439 438
d6834f5f 439 entry = GetCDBEntry("TPC/Calib/Mapping");
440 if (entry){
441 //if (fPadNoise) delete fPadNoise;
442 entry->SetOwner(kTRUE);
443 TObjArray * array = dynamic_cast<TObjArray*>(entry->GetObject());
444 if (array && array->GetEntriesFast()==6){
445 fMapping = new AliTPCAltroMapping*[6];
446 for (Int_t i=0; i<6; i++){
5312f439 447 fMapping[i] = dynamic_cast<AliTPCAltroMapping*>(array->At(i));
d6834f5f 448 }
449 }
450 }
451
2293155b 452 //CTP calibration data
f14d21a1 453 entry = GetCDBEntry("GRP/CTP/CTPtiming");
454 if (entry){
4a880881 455 //entry->SetOwner(kTRUE);
f14d21a1 456 fCTPTimeParams=dynamic_cast<AliCTPTimeParams*>(entry->GetObject());
2293155b 457 }else{
3d1b41c1 458 AliError("TPC - Missing calibration entry")
2293155b 459 }
be67055b 460 //TPC space point correction data
461 entry = GetCDBEntry("TPC/Calib/Correction");
462 if (entry){
463 //entry->SetOwner(kTRUE);
464 fComposedCorrection=dynamic_cast<AliTPCCorrection*>(entry->GetObject());
0b736a46 465 if (fComposedCorrection) fComposedCorrection->Init();
466 fComposedCorrectionArray=dynamic_cast<TObjArray*>(entry->GetObject());
467 if (fComposedCorrectionArray){
468 for (Int_t i=0; i<fComposedCorrectionArray->GetEntries(); i++){
469 AliTPCCorrection* composedCorrection= dynamic_cast<AliTPCCorrection*>(fComposedCorrectionArray->At(i));
470 if (composedCorrection) composedCorrection->Init();
471 }
472 }
be67055b 473 }else{
474 AliError("TPC - Missing calibration entry- TPC/Calib/Correction")
475 }
476
3ac615eb 477 //
f5344549 478 if (!fTransform) {
479 fTransform=new AliTPCTransform();
bfec3eeb 480 fTransform->SetCurrentRun(AliCDBManager::Instance()->GetRun());
f5344549 481 }
8477f500 482
c5bbaa2c 483 //
68751c2c 484 AliCDBManager::Instance()->SetCacheFlag(cdbCache); // reset original CDB cache
c5bbaa2c 485}
e4dce695 486
56ce896d 487void AliTPCcalibDB::UpdateNonRec(){
488 //
489 // Update/Load the parameters which are important for QA studies
490 // and not used yet for the reconstruction
491 //
492 //RAW calibration data
493 AliCDBEntry * entry=0;
494 entry = GetCDBEntry("TPC/Calib/Raw");
495 if (entry){
496 entry->SetOwner(kTRUE);
497 TObjArray *arr=(TObjArray*)(entry->GetObject());
498 if (arr) fCalibRaw=(AliTPCCalibRaw*)arr->At(0);
499 }
500 //QA calibration data
501 entry = GetCDBEntry("TPC/Calib/QA");
502 if (entry){
503 entry->SetOwner(kTRUE);
504 fDataQA=dynamic_cast<AliTPCdataQA*>(entry->GetObject());
505 }
2293155b 506 // High voltage
14301155 507 if (fRun>=0){
508 entry = AliCDBManager::Instance()->Get("TPC/Calib/HighVoltage",fRun);
509 if (entry) {
510 fVoltageArray.AddAt(entry->GetObject(),fRun);
511 }
2293155b 512 }
513
56ce896d 514}
515
86df2b3a 516
517
518void AliTPCcalibDB::CreateObjectList(const Char_t *filename, TObjArray *calibObjects)
519{
418bbcaf 520//
521// Create calibration objects and read contents from OCDB
522//
86df2b3a 523 if ( calibObjects == 0x0 ) return;
524 ifstream in;
525 in.open(filename);
526 if ( !in.is_open() ){
527 fprintf(stderr,"Error: cannot open list file '%s'", filename);
528 return;
529 }
530
531 AliTPCCalPad *calPad=0x0;
532
533 TString sFile;
534 sFile.ReadFile(in);
535 in.close();
536
537 TObjArray *arrFileLine = sFile.Tokenize("\n");
538
539 TIter nextLine(arrFileLine);
540
541 TObjString *sObjLine=0x0;
2c632057 542 while ( (sObjLine = (TObjString*)nextLine()) ){
86df2b3a 543 TString sLine(sObjLine->GetString());
544
545 TObjArray *arrNextCol = sLine.Tokenize("\t");
546
547 TObjString *sObjType = (TObjString*)(arrNextCol->At(0));
548 TObjString *sObjFileName = (TObjString*)(arrNextCol->At(1));
549
550 if ( !sObjType || ! sObjFileName ) continue;
551 TString sType(sObjType->GetString());
552 TString sFileName(sObjFileName->GetString());
553 printf("%s\t%s\n",sType.Data(),sFileName.Data());
554
555 TFile *fIn = TFile::Open(sFileName);
556 if ( !fIn ){
557 fprintf(stderr,"File not found: '%s'", sFileName.Data());
558 continue;
559 }
560
561 if ( sType == "CE" ){
562 AliTPCCalibCE *ce = (AliTPCCalibCE*)fIn->Get("AliTPCCalibCE");
563
564 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadT0());
565 calPad->SetNameTitle("CETmean","CETmean");
566 calibObjects->Add(calPad);
567
568 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadQ());
569 calPad->SetNameTitle("CEQmean","CEQmean");
570 calibObjects->Add(calPad);
571
572 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadRMS());
573 calPad->SetNameTitle("CETrms","CETrms");
574 calibObjects->Add(calPad);
575
576 } else if ( sType == "Pulser") {
0fe7645c 577 AliTPCCalibPulser *sig = (AliTPCCalibPulser*)fIn->Get("AliTPCCalibPulser");
86df2b3a 578
579 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadT0());
580 calPad->SetNameTitle("PulserTmean","PulserTmean");
581 calibObjects->Add(calPad);
582
583 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadQ());
584 calPad->SetNameTitle("PulserQmean","PulserQmean");
585 calibObjects->Add(calPad);
586
587 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadRMS());
588 calPad->SetNameTitle("PulserTrms","PulserTrms");
589 calibObjects->Add(calPad);
590
591 } else if ( sType == "Pedestals") {
592 AliTPCCalibPedestal *ped = (AliTPCCalibPedestal*)fIn->Get("AliTPCCalibPedestal");
593
594 calPad = new AliTPCCalPad((TObjArray*)ped->GetCalPadPedestal());
595 calPad->SetNameTitle("Pedestals","Pedestals");
596 calibObjects->Add(calPad);
597
598 calPad = new AliTPCCalPad((TObjArray*)ped->GetCalPadRMS());
599 calPad->SetNameTitle("Noise","Noise");
600 calibObjects->Add(calPad);
601
602 } else {
603 fprintf(stderr,"Undefined Type: '%s'",sType.Data());
604
605 }
606 delete fIn;
607 }
608}
609
610
611
612void AliTPCcalibDB::MakeTree(const char * fileName, TObjArray * array, const char * mapFileName, AliTPCCalPad* outlierPad, Float_t ltmFraction) {
613 //
614 // Write a tree with all available information
418bbcaf 615 // if mapFileName is specified, the Map information are also written to the tree
86df2b3a 616 // pads specified in outlierPad are not used for calculating statistics
617 // - the same function as AliTPCCalPad::MakeTree -
618 //
619 AliTPCROC* tpcROCinstance = AliTPCROC::Instance();
620
621 TObjArray* mapIROCs = 0;
622 TObjArray* mapOROCs = 0;
623 TVectorF *mapIROCArray = 0;
624 TVectorF *mapOROCArray = 0;
625 Int_t mapEntries = 0;
626 TString* mapNames = 0;
627
628 if (mapFileName) {
629 TFile mapFile(mapFileName, "read");
630
631 TList* listOfROCs = mapFile.GetListOfKeys();
632 mapEntries = listOfROCs->GetEntries()/2;
633 mapIROCs = new TObjArray(mapEntries*2);
634 mapOROCs = new TObjArray(mapEntries*2);
635 mapIROCArray = new TVectorF[mapEntries];
636 mapOROCArray = new TVectorF[mapEntries];
637
638 mapNames = new TString[mapEntries];
639 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
418bbcaf 640 TString nameROC(((TKey*)(listOfROCs->At(ivalue*2)))->GetName());
641 nameROC.Remove(nameROC.Length()-4, 4);
642 mapIROCs->AddAt((AliTPCCalROC*)mapFile.Get((nameROC + "IROC").Data()), ivalue);
643 mapOROCs->AddAt((AliTPCCalROC*)mapFile.Get((nameROC + "OROC").Data()), ivalue);
644 mapNames[ivalue].Append(nameROC);
86df2b3a 645 }
646
647 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
648 mapIROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(0));
649 mapOROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(36));
650
651 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(0); ichannel++)
652 (mapIROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapIROCs->At(ivalue)))->GetValue(ichannel);
653 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(36); ichannel++)
654 (mapOROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapOROCs->At(ivalue)))->GetValue(ichannel);
655 }
656
657 } // if (mapFileName)
658
659 TTreeSRedirector cstream(fileName);
660 Int_t arrayEntries = array->GetEntries();
661
662 TString* names = new TString[arrayEntries];
663 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
664 names[ivalue].Append(((AliTPCCalPad*)array->At(ivalue))->GetName());
665
666 for (UInt_t isector = 0; isector < tpcROCinstance->GetNSectors(); isector++) {
667 //
668 // get statistic for given sector
669 //
670 TVectorF median(arrayEntries);
671 TVectorF mean(arrayEntries);
672 TVectorF rms(arrayEntries);
673 TVectorF ltm(arrayEntries);
674 TVectorF ltmrms(arrayEntries);
675 TVectorF medianWithOut(arrayEntries);
676 TVectorF meanWithOut(arrayEntries);
677 TVectorF rmsWithOut(arrayEntries);
678 TVectorF ltmWithOut(arrayEntries);
679 TVectorF ltmrmsWithOut(arrayEntries);
680
681 TVectorF *vectorArray = new TVectorF[arrayEntries];
682 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
683 vectorArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
684
685 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
686 AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue);
687 AliTPCCalROC* calROC = calPad->GetCalROC(isector);
688 AliTPCCalROC* outlierROC = 0;
689 if (outlierPad) outlierROC = outlierPad->GetCalROC(isector);
690 if (calROC) {
691 median[ivalue] = calROC->GetMedian();
692 mean[ivalue] = calROC->GetMean();
693 rms[ivalue] = calROC->GetRMS();
694 Double_t ltmrmsValue = 0;
695 ltm[ivalue] = calROC->GetLTM(&ltmrmsValue, ltmFraction);
696 ltmrms[ivalue] = ltmrmsValue;
697 if (outlierROC) {
698 medianWithOut[ivalue] = calROC->GetMedian(outlierROC);
699 meanWithOut[ivalue] = calROC->GetMean(outlierROC);
700 rmsWithOut[ivalue] = calROC->GetRMS(outlierROC);
701 ltmrmsValue = 0;
702 ltmWithOut[ivalue] = calROC->GetLTM(&ltmrmsValue, ltmFraction, outlierROC);
703 ltmrmsWithOut[ivalue] = ltmrmsValue;
704 }
705 }
706 else {
707 median[ivalue] = 0.;
708 mean[ivalue] = 0.;
709 rms[ivalue] = 0.;
710 ltm[ivalue] = 0.;
711 ltmrms[ivalue] = 0.;
712 medianWithOut[ivalue] = 0.;
713 meanWithOut[ivalue] = 0.;
714 rmsWithOut[ivalue] = 0.;
715 ltmWithOut[ivalue] = 0.;
716 ltmrmsWithOut[ivalue] = 0.;
717 }
718 }
719
720 //
721 // fill vectors of variable per pad
722 //
723 TVectorF *posArray = new TVectorF[8];
724 for (Int_t ivalue = 0; ivalue < 8; ivalue++)
725 posArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
726
727 Float_t posG[3] = {0};
728 Float_t posL[3] = {0};
729 Int_t ichannel = 0;
730 for (UInt_t irow = 0; irow < tpcROCinstance->GetNRows(isector); irow++) {
731 for (UInt_t ipad = 0; ipad < tpcROCinstance->GetNPads(isector, irow); ipad++) {
732 tpcROCinstance->GetPositionLocal(isector, irow, ipad, posL);
733 tpcROCinstance->GetPositionGlobal(isector, irow, ipad, posG);
734 posArray[0][ichannel] = irow;
735 posArray[1][ichannel] = ipad;
736 posArray[2][ichannel] = posL[0];
737 posArray[3][ichannel] = posL[1];
738 posArray[4][ichannel] = posG[0];
739 posArray[5][ichannel] = posG[1];
740 posArray[6][ichannel] = (Int_t)(ipad - (Double_t)(tpcROCinstance->GetNPads(isector, irow))/2);
741 posArray[7][ichannel] = ichannel;
742
743 // loop over array containing AliTPCCalPads
744 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
745 AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue);
746 AliTPCCalROC* calROC = calPad->GetCalROC(isector);
747 if (calROC)
748 (vectorArray[ivalue])[ichannel] = calROC->GetValue(irow, ipad);
749 else
750 (vectorArray[ivalue])[ichannel] = 0;
751 }
752 ichannel++;
753 }
754 }
755
756 cstream << "calPads" <<
757 "sector=" << isector;
758
759 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
760 cstream << "calPads" <<
761 (Char_t*)((names[ivalue] + "_Median=").Data()) << median[ivalue] <<
762 (Char_t*)((names[ivalue] + "_Mean=").Data()) << mean[ivalue] <<
763 (Char_t*)((names[ivalue] + "_RMS=").Data()) << rms[ivalue] <<
764 (Char_t*)((names[ivalue] + "_LTM=").Data()) << ltm[ivalue] <<
765 (Char_t*)((names[ivalue] + "_RMS_LTM=").Data()) << ltmrms[ivalue];
766 if (outlierPad) {
767 cstream << "calPads" <<
768 (Char_t*)((names[ivalue] + "_Median_OutlierCutted=").Data()) << medianWithOut[ivalue] <<
769 (Char_t*)((names[ivalue] + "_Mean_OutlierCutted=").Data()) << meanWithOut[ivalue] <<
770 (Char_t*)((names[ivalue] + "_RMS_OutlierCutted=").Data()) << rmsWithOut[ivalue] <<
771 (Char_t*)((names[ivalue] + "_LTM_OutlierCutted=").Data()) << ltmWithOut[ivalue] <<
772 (Char_t*)((names[ivalue] + "_RMS_LTM_OutlierCutted=").Data()) << ltmrmsWithOut[ivalue];
773 }
774 }
775
776 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
777 cstream << "calPads" <<
778 (Char_t*)((names[ivalue] + ".=").Data()) << &vectorArray[ivalue];
779 }
780
781 if (mapFileName) {
782 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
783 if (isector < 36)
784 cstream << "calPads" <<
785 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapIROCArray[ivalue];
786 else
787 cstream << "calPads" <<
788 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapOROCArray[ivalue];
789 }
790 }
791
792 cstream << "calPads" <<
793 "row.=" << &posArray[0] <<
794 "pad.=" << &posArray[1] <<
795 "lx.=" << &posArray[2] <<
796 "ly.=" << &posArray[3] <<
797 "gx.=" << &posArray[4] <<
798 "gy.=" << &posArray[5] <<
799 "rpad.=" << &posArray[6] <<
800 "channel.=" << &posArray[7];
801
802 cstream << "calPads" <<
803 "\n";
804
805 delete[] posArray;
806 delete[] vectorArray;
807 }
808
809
810 delete[] names;
811 if (mapFileName) {
812 delete mapIROCs;
813 delete mapOROCs;
814 delete[] mapIROCArray;
815 delete[] mapOROCArray;
816 delete[] mapNames;
817 }
818}
3ac615eb 819
f14d21a1 820Int_t AliTPCcalibDB::GetRCUTriggerConfig() const
821{
822 //
823 // return the RCU trigger configuration register
824 //
825 TMap *map=GetRCUconfig();
826 if (!map) return -1;
827 TVectorF *v=(TVectorF*)map->GetValue("TRGCONF_TRG_MODE");
828 Float_t mode=-1;
829 for (Int_t i=0; i<v->GetNrows(); ++i){
830 Float_t newmode=v->GetMatrixArray()[i];
831 if (newmode>-1){
832 if (mode>-1&&newmode!=mode) AliWarning("Found different RCU trigger configurations!!!");
833 mode=newmode;
834 }
835 }
836 return (Int_t)mode;
837}
838
839Bool_t AliTPCcalibDB::IsTrgL0()
840{
841 //
842 // return if the FEE readout was triggered on L0
843 //
844 Int_t mode=GetRCUTriggerConfig();
845 if (mode<0) return kFALSE;
7fe54a9b 846 return (mode==1);
f14d21a1 847}
3ac615eb 848
f14d21a1 849Bool_t AliTPCcalibDB::IsTrgL1()
850{
851 //
852 // return if the FEE readout was triggered on L1
853 //
854 Int_t mode=GetRCUTriggerConfig();
855 if (mode<0) return kFALSE;
7fe54a9b 856 return (mode==0);
f14d21a1 857}
3ac615eb 858
859void AliTPCcalibDB::RegisterExB(Int_t index, Float_t bz, Bool_t bdelete){
860 //
861 // Register static ExB correction map
862 // index - registration index - used for visualization
863 // bz - bz field in kGaus
864
0a997b33 865 // Float_t factor = bz/(-5.); // default b filed in Cheb with minus sign
866 Float_t factor = bz/(5.); // default b filed in Cheb with minus sign
867 // was chenged in the Revision ???? (Ruben can you add here number)
3ac615eb 868
4642ac4b 869 AliMagF* bmap = new AliMagF("MapsExB","MapsExB", factor,TMath::Sign(1.f,factor),AliMagF::k5kG);
3ac615eb 870
871 AliTPCExBFirst *exb = new AliTPCExBFirst(bmap,0.88*2.6400e+04,50,50,50);
872 AliTPCExB::SetInstance(exb);
873
874 if (bdelete){
875 delete bmap;
876 }else{
877 AliTPCExB::RegisterField(index,bmap);
878 }
879 if (index>=fgExBArray.GetEntries()) fgExBArray.Expand((index+1)*2+11);
880 fgExBArray.AddAt(exb,index);
881}
882
883
884AliTPCExB* AliTPCcalibDB::GetExB(Float_t bz, Bool_t deleteB) {
885 //
886 // bz filed in KGaus not in tesla
887 // Get ExB correction map
888 // if doesn't exist - create it
889 //
890 Int_t index = TMath::Nint(5+bz);
891 if (index>fgExBArray.GetEntries()) fgExBArray.Expand((index+1)*2+11);
892 if (!fgExBArray.At(index)) AliTPCcalibDB::RegisterExB(index,bz,deleteB);
893 return (AliTPCExB*)fgExBArray.At(index);
894}
895
896
897void AliTPCcalibDB::SetExBField(Float_t bz){
898 //
899 // Set magnetic filed for ExB correction
900 //
901 fExB = GetExB(bz,kFALSE);
902}
bf85fe4d 903
0a997b33 904void AliTPCcalibDB::SetExBField(const AliMagF* bmap){
905 //
906 // Set magnetic field for ExB correction
907 //
908 AliTPCExBFirst *exb = new AliTPCExBFirst(bmap,0.88*2.6400e+04,50,50,50);
909 AliTPCExB::SetInstance(exb);
910 fExB=exb;
911}
912
bf85fe4d 913
914
5e1215d4 915
916
917void AliTPCcalibDB::UpdateRunInformations( Int_t run, Bool_t force){
bf85fe4d 918 //
919 // - > Don't use it for reconstruction - Only for Calibration studies
920 //
b96c3aef 921 if (run<=0) return;
14301155 922 fRun=run;
bf85fe4d 923 AliCDBEntry * entry = 0;
cc65e4f5 924 if (run>= fRunList.fN){
bf85fe4d 925 fRunList.Set(run*2+1);
da6c0bc9 926 fGRPArray.Expand(run*2+1);
0231c65f 927 fGRPMaps.Expand(run*2+1);
e2914767 928 fGoofieArray.Expand(run*2+1);
929 fVoltageArray.Expand(run*2+1);
da6c0bc9 930 fTemperatureArray.Expand(run*2+1);
931 fVdriftArray.Expand(run*2+1);
5e1215d4 932 fDriftCorrectionArray.Expand(run*2+1);
a2c3785e 933 fTimeGainSplinesArray.Expand(run*2+1);
cc65e4f5 934 //
935 //
936 fALTROConfigData->Expand(run*2+1); // ALTRO configuration data
937 fPulserData->Expand(run*2+1); // Calibration Pulser data
938 fCEData->Expand(run*2+1); // CE data
d32e8676 939 if (!fTimeGainSplines) fTimeGainSplines = new TObjArray(run*2+1);
cc65e4f5 940 fTimeGainSplines->Expand(run*2+1); // Array of AliSplineFits: at 0 MIP position in
bf85fe4d 941 }
cc65e4f5 942 if (fRunList[run]>0 &&force==kFALSE) return;
1e722a63 943
944 fRunList[run]=1; // sign as used
945
5e1215d4 946 //
bf85fe4d 947 entry = AliCDBManager::Instance()->Get("GRP/GRP/Data",run);
0231c65f 948 if (entry) {
949 AliGRPObject * grpRun = dynamic_cast<AliGRPObject*>(entry->GetObject());
950 if (!grpRun){
951 TMap* map = dynamic_cast<TMap*>(entry->GetObject());
952 if (map){
e2914767 953 //grpRun = new AliGRPObject;
954 //grpRun->ReadValuesFromMap(map);
955 grpRun = MakeGRPObjectFromMap(map);
956
0231c65f 957 fGRPMaps.AddAt(map,run);
958 }
959 }
960 fGRPArray.AddAt(grpRun,run);
961 }
bf85fe4d 962 entry = AliCDBManager::Instance()->Get("TPC/Calib/Goofie",run);
5e1215d4 963 if (entry){
964 fGoofieArray.AddAt(entry->GetObject(),run);
965 }
e2914767 966 //
2293155b 967
e2914767 968 //
a2c3785e 969 entry = AliCDBManager::Instance()->Get("TPC/Calib/TimeGain",run);
5e1215d4 970 if (entry) {
971 fTimeGainSplinesArray.AddAt(entry->GetObject(),run);
2293155b 972 }else{
973 AliFatal("TPC - Missing calibration entry TimeGain")
5e1215d4 974 }
975 //
976 entry = AliCDBManager::Instance()->Get("TPC/Calib/TimeDrift",run);
977 if (entry) {
978 fDriftCorrectionArray.AddAt(entry->GetObject(),run);
2293155b 979 }else{
980 AliFatal("TPC - Missing calibration entry TimeDrift")
5e1215d4 981 }
a2c3785e 982 //
bf85fe4d 983 entry = AliCDBManager::Instance()->Get("TPC/Calib/Temperature",run);
5e1215d4 984 if (entry) {
985 fTemperatureArray.AddAt(entry->GetObject(),run);
986 }
1e722a63 987 //apply fDButil filters
988
989 fDButil->UpdateFromCalibDB();
990 if (fTemperature) fDButil->FilterTemperature(fTemperature);
da6c0bc9 991
bfec3eeb 992 AliDCSSensor * press = GetPressureSensor(run,0);
da6c0bc9 993 AliTPCSensorTempArray * temp = GetTemperatureSensor(run);
1e722a63 994 Bool_t accept=kTRUE;
995 if (temp) {
996 accept = fDButil->FilterTemperature(temp)>0.1;
997 }
998 if (press) {
7506b1e9 999 const Double_t kMinP=900.;
1e722a63 1000 const Double_t kMaxP=1050.;
1001 const Double_t kMaxdP=10.;
1002 const Double_t kSigmaCut=4.;
1003 fDButil->FilterSensor(press,kMinP,kMaxP,kMaxdP,kSigmaCut);
1004 if (press->GetFit()==0) accept=kFALSE;
1005 }
5647625c 1006
1e722a63 1007 if (press && temp &&accept){
da6c0bc9 1008 AliTPCCalibVdrift * vdrift = new AliTPCCalibVdrift(temp, press,0);
1009 fVdriftArray.AddAt(vdrift,run);
1010 }
5647625c 1011
1e722a63 1012 fDButil->FilterCE(120., 3., 4.,0);
1013 fDButil->FilterTracks(run, 10.,0);
5647625c 1014
bf85fe4d 1015}
1016
1017
1018Float_t AliTPCcalibDB::GetGain(Int_t sector, Int_t row, Int_t pad){
1019 //
92fb7d95 1020 // Get Gain factor for given pad
bf85fe4d 1021 //
1022 AliTPCCalPad *calPad = Instance()->fDedxGainFactor;;
1023 if (!calPad) return 0;
1024 return calPad->GetCalROC(sector)->GetValue(row,pad);
1025}
1026
7390f655 1027AliSplineFit* AliTPCcalibDB::GetVdriftSplineFit(const char* name, Int_t run){
1028 //
92fb7d95 1029 // GetDrift velocity spline fit
7390f655 1030 //
1031 TObjArray *arr=GetTimeVdriftSplineRun(run);
1032 if (!arr) return 0;
1033 return dynamic_cast<AliSplineFit*>(arr->FindObject(name));
1034}
1035
2cb269df 1036AliSplineFit* AliTPCcalibDB::CreateVdriftSplineFit(const char* graphName, Int_t run){
1037 //
1038 // create spline fit from the drift time graph in TimeDrift
1039 //
1040 TObjArray *arr=GetTimeVdriftSplineRun(run);
1041 if (!arr) return 0;
1042 TGraph *graph=dynamic_cast<TGraph*>(arr->FindObject(graphName));
1043 if (!graph) return 0;
1044 AliSplineFit *fit = new AliSplineFit();
1045 fit->SetGraph(graph);
1046 fit->SetMinPoints(graph->GetN()+1);
1047 fit->InitKnots(graph,2,0,0.001);
1048 fit->SplineFit(0);
1049 return fit;
1050}
8de77f00 1051
1052AliGRPObject *AliTPCcalibDB::GetGRP(Int_t run){
1053 //
1054 // Get GRP object for given run
1055 //
14301155 1056 if (run>= ((Instance()->fGRPArray)).GetEntriesFast()){
1057 Instance()->UpdateRunInformations(run);
1058 }
8de77f00 1059 AliGRPObject * grpRun = dynamic_cast<AliGRPObject *>((Instance()->fGRPArray).At(run));
1060 if (!grpRun) {
5e1215d4 1061 Instance()->UpdateRunInformations(run);
8de77f00 1062 grpRun = dynamic_cast<AliGRPObject *>(Instance()->fGRPArray.At(run));
1063 if (!grpRun) return 0;
1064 }
1065 return grpRun;
1066}
1067
0231c65f 1068TMap * AliTPCcalibDB::GetGRPMap(Int_t run){
1069 //
92fb7d95 1070 // Get GRP map for given run
0231c65f 1071 //
1072 TMap * grpRun = dynamic_cast<TMap *>((Instance()->fGRPMaps).At(run));
1073 if (!grpRun) {
5e1215d4 1074 Instance()->UpdateRunInformations(run);
0231c65f 1075 grpRun = dynamic_cast<TMap *>(Instance()->fGRPMaps.At(run));
1076 if (!grpRun) return 0;
1077 }
1078 return grpRun;
1079}
8de77f00 1080
1081
da6c0bc9 1082AliDCSSensor * AliTPCcalibDB::GetPressureSensor(Int_t run, Int_t type){
bf85fe4d 1083 //
0231c65f 1084 // Get Pressure sensor
bfec3eeb 1085 // run = run number
1086 // type = 0 - Cavern pressure
1087 // 1 - Suface pressure
0231c65f 1088 // First try to get if trom map - if existing (Old format of data storing)
bf85fe4d 1089 //
bfec3eeb 1090
1091
0231c65f 1092 TMap *map = GetGRPMap(run);
1093 if (map){
1094 AliDCSSensor * sensor = 0;
1095 TObject *osensor=0;
2cd3a697 1096 if (type==0) osensor = ((*map)("fCavernPressure"));
0231c65f 1097 if (type==1) osensor = ((*map)("fP2Pressure"));
1098 sensor =dynamic_cast<AliDCSSensor *>(osensor);
1099 if (sensor) return sensor;
1100 }
1101 //
1102 // If not map try to get it from the GRPObject
1103 //
1104 AliGRPObject * grpRun = dynamic_cast<AliGRPObject *>(fGRPArray.At(run));
bf85fe4d 1105 if (!grpRun) {
5e1215d4 1106 UpdateRunInformations(run);
efdbb95a 1107 grpRun = dynamic_cast<AliGRPObject *>(fGRPArray.At(run));
bf85fe4d 1108 if (!grpRun) return 0;
1109 }
2cd3a697 1110 AliDCSSensor * sensor = grpRun->GetCavernAtmosPressure();
da6c0bc9 1111 if (type==1) sensor = grpRun->GetSurfaceAtmosPressure();
1112 return sensor;
bf85fe4d 1113}
1114
1115AliTPCSensorTempArray * AliTPCcalibDB::GetTemperatureSensor(Int_t run){
1116 //
1117 // Get temperature sensor array
1118 //
1119 AliTPCSensorTempArray * tempArray = (AliTPCSensorTempArray *)fTemperatureArray.At(run);
1120 if (!tempArray) {
5e1215d4 1121 UpdateRunInformations(run);
bf85fe4d 1122 tempArray = (AliTPCSensorTempArray *)fTemperatureArray.At(run);
1123 }
1124 return tempArray;
1125}
1126
a2c3785e 1127
1128TObjArray * AliTPCcalibDB::GetTimeGainSplinesRun(Int_t run){
bf85fe4d 1129 //
1130 // Get temperature sensor array
1131 //
a2c3785e 1132 TObjArray * gainSplines = (TObjArray *)fTimeGainSplinesArray.At(run);
1133 if (!gainSplines) {
5e1215d4 1134 UpdateRunInformations(run);
a2c3785e 1135 gainSplines = (TObjArray *)fTimeGainSplinesArray.At(run);
bf85fe4d 1136 }
a2c3785e 1137 return gainSplines;
bf85fe4d 1138}
1139
7390f655 1140TObjArray * AliTPCcalibDB::GetTimeVdriftSplineRun(Int_t run){
1141 //
1142 // Get drift spline array
1143 //
1144 TObjArray * driftSplines = (TObjArray *)fDriftCorrectionArray.At(run);
1145 if (!driftSplines) {
1146 UpdateRunInformations(run);
1147 driftSplines = (TObjArray *)fDriftCorrectionArray.At(run);
1148 }
1149 return driftSplines;
1150}
1151
e2914767 1152AliDCSSensorArray * AliTPCcalibDB::GetVoltageSensors(Int_t run){
1153 //
1154 // Get temperature sensor array
1155 //
1156 AliDCSSensorArray * voltageArray = (AliDCSSensorArray *)fVoltageArray.At(run);
1157 if (!voltageArray) {
5e1215d4 1158 UpdateRunInformations(run);
e2914767 1159 voltageArray = (AliDCSSensorArray *)fVoltageArray.At(run);
1160 }
1161 return voltageArray;
1162}
1163
99895a4f 1164AliDCSSensorArray * AliTPCcalibDB::GetGoofieSensors(Int_t run){
1165 //
1166 // Get temperature sensor array
1167 //
1168 AliDCSSensorArray * goofieArray = (AliDCSSensorArray *)fGoofieArray.At(run);
1169 if (!goofieArray) {
5e1215d4 1170 UpdateRunInformations(run);
99895a4f 1171 goofieArray = (AliDCSSensorArray *)fGoofieArray.At(run);
1172 }
1173 return goofieArray;
1174}
1175
1176
1177
da6c0bc9 1178AliTPCCalibVdrift * AliTPCcalibDB::GetVdrift(Int_t run){
1179 //
1180 // Get the interface to the the vdrift
1181 //
41bb661b 1182 if (run>=fVdriftArray.GetEntriesFast()) UpdateRunInformations(run);
da6c0bc9 1183 AliTPCCalibVdrift * vdrift = (AliTPCCalibVdrift*)fVdriftArray.At(run);
1184 if (!vdrift) {
5e1215d4 1185 UpdateRunInformations(run);
da6c0bc9 1186 vdrift= (AliTPCCalibVdrift*)fVdriftArray.At(run);
1187 }
1188 return vdrift;
1189}
1190
892226be 1191Float_t AliTPCcalibDB::GetCEdriftTime(Int_t run, Int_t sector, Double_t timeStamp, Int_t *entries)
1192{
1193 //
1194 // GetCE drift time information for 'sector'
1195 // sector 72 is the mean drift time of the A-Side
1196 // sector 73 is the mean drift time of the C-Side
1197 // it timestamp==-1 return mean value
1198 //
1199 AliTPCcalibDB::Instance()->SetRun(run);
1200 TGraph *gr=AliTPCcalibDB::Instance()->GetCErocTgraph(sector);
1201 if (!gr||sector<0||sector>73) {
1202 if (entries) *entries=0;
1203 return 0.;
1204 }
1205 Float_t val=0.;
1206 if (timeStamp==-1.){
1207 val=gr->GetMean(2);
1208 }else{
1209 for (Int_t ipoint=0;ipoint<gr->GetN();++ipoint){
1210 Double_t x,y;
1211 gr->GetPoint(ipoint,x,y);
1212 if (x<timeStamp) continue;
1213 val=y;
1214 break;
1215 }
1216 }
1217 return val;
1218}
1219
1220Float_t AliTPCcalibDB::GetCEchargeTime(Int_t run, Int_t sector, Double_t timeStamp, Int_t *entries)
1221{
1222 //
1223 // GetCE mean charge for 'sector'
1224 // it timestamp==-1 return mean value
1225 //
1226 AliTPCcalibDB::Instance()->SetRun(run);
1227 TGraph *gr=AliTPCcalibDB::Instance()->GetCErocQgraph(sector);
1228 if (!gr||sector<0||sector>71) {
1229 if (entries) *entries=0;
1230 return 0.;
1231 }
1232 Float_t val=0.;
1233 if (timeStamp==-1.){
1234 val=gr->GetMean(2);
1235 }else{
1236 for (Int_t ipoint=0;ipoint<gr->GetN();++ipoint){
1237 Double_t x,y;
1238 gr->GetPoint(ipoint,x,y);
1239 if (x<timeStamp) continue;
1240 val=y;
1241 break;
1242 }
1243 }
1244 return val;
1245}
1246
7fff7612 1247Float_t AliTPCcalibDB::GetDCSSensorValue(AliDCSSensorArray *arr, Int_t timeStamp, const char * sensorName, Int_t sigDigits)
1248{
1249 //
1250 // Get Value for a DCS sensor 'sensorName', run 'run' at time 'timeStamp'
1251 //
1252 Float_t val=0;
1253 const TString sensorNameString(sensorName);
1254 AliDCSSensor *sensor = arr->GetSensor(sensorNameString);
1255 if (!sensor) return val;
892226be 1256 //use the dcs graph if possible
1257 TGraph *gr=sensor->GetGraph();
1258 if (gr){
1259 for (Int_t ipoint=0;ipoint<gr->GetN();++ipoint){
1260 Double_t x,y;
1261 gr->GetPoint(ipoint,x,y);
7390f655 1262 Int_t time=TMath::Nint(sensor->GetStartTime()+x*3600); //time in graph is hours
892226be 1263 if (time<timeStamp) continue;
1264 val=y;
1265 break;
1266 }
1267 //if val is still 0, test if if the requested time if within 5min of the first/last
1268 //data point. If this is the case return the firs/last entry
1269 //the timestamps might not be syncronised for all calibration types, sometimes a 'pre'
1270 //and 'pos' period is requested. Especially to the HV this is not the case!
1271 //first point
1272 if (val==0 ){
1273 Double_t x,y;
1274 gr->GetPoint(0,x,y);
7390f655 1275 Int_t time=TMath::Nint(sensor->GetStartTime()+x*3600); //time in graph is hours
892226be 1276 if ((time-timeStamp)<5*60) val=y;
1277 }
1278 //last point
1279 if (val==0 ){
1280 Double_t x,y;
1281 gr->GetPoint(gr->GetN()-1,x,y);
7390f655 1282 Int_t time=TMath::Nint(sensor->GetStartTime()+x*3600); //time in graph is hours
892226be 1283 if ((timeStamp-time)<5*60) val=y;
1284 }
1285 } else {
1286 val=sensor->GetValue(timeStamp);
1287 }
7fff7612 1288 if (sigDigits>=0){
1289 val=(Float_t)TMath::Floor(val * TMath::Power(10., sigDigits) + .5) / TMath::Power(10., sigDigits);
1290 }
1291 return val;
1292}
1293
1294Float_t AliTPCcalibDB::GetDCSSensorMeanValue(AliDCSSensorArray *arr, const char * sensorName, Int_t sigDigits)
1295{
1296 //
1297 // Get mean Value for a DCS sensor 'sensorName' during run 'run'
1298 //
1299 Float_t val=0;
1300 const TString sensorNameString(sensorName);
1301 AliDCSSensor *sensor = arr->GetSensor(sensorNameString);
1302 if (!sensor) return val;
892226be 1303
1304 //use dcs graph if it exists
1305 TGraph *gr=sensor->GetGraph();
1306 if (gr){
1307 val=gr->GetMean(2);
1308 } else {
1309 //if we don't have the dcs graph, try to get some meaningful information
1310 if (!sensor->GetFit()) return val;
1311 Int_t nKnots=sensor->GetFit()->GetKnots();
1312 Double_t tMid=(sensor->GetEndTime()-sensor->GetStartTime())/2.;
1313 for (Int_t iKnot=0;iKnot<nKnots;++iKnot){
1314 if (sensor->GetFit()->GetX()[iKnot]>tMid/3600.) break;
1315 val=(Float_t)sensor->GetFit()->GetY0()[iKnot];
1316 }
7fff7612 1317 }
7fff7612 1318 if (sigDigits>=0){
60721370 1319 // val/=10;
7fff7612 1320 val=(Float_t)TMath::Floor(val * TMath::Power(10., sigDigits) + .5) / TMath::Power(10., sigDigits);
60721370 1321 // val*=10;
7fff7612 1322 }
1323 return val;
1324}
bf85fe4d 1325
2073b7a5 1326Float_t AliTPCcalibDB::GetChamberHighVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits, Bool_t current) {
e2914767 1327 //
1328 // return the chamber HV for given run and time: 0-35 IROC, 36-72 OROC
7fff7612 1329 // if timeStamp==-1 return mean value
1330 //
1331 Float_t val=0;
1332 TString sensorName="";
1333 TTimeStamp stamp(timeStamp);
1334 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1335 if (!voltageArray || (sector<0) || (sector>71)) return val;
1336 Char_t sideName='A';
1337 if ((sector/18)%2==1) sideName='C';
1338 if (sector<36){
1339 //IROC
1340 sensorName=Form("TPC_ANODE_I_%c%02d_VMEAS",sideName,sector%18);
1341 }else{
1342 //OROC
1343 sensorName=Form("TPC_ANODE_O_%c%02d_0_VMEAS",sideName,sector%18);
1344 }
2073b7a5 1345 if (current){
1346 if (sector<36){
1347 //IROC
1348 sensorName=Form("TPC_ANODE_I_%c%02d_IMEAS",sideName,sector%18);
1349 }else{
1350 //OROC
1351 sensorName=Form("TPC_ANODE_O_%c%02d_0_IMEAS",sideName,sector%18);
1352 }
1353
1354 }
7fff7612 1355 if (timeStamp==-1){
1356 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1357 } else {
1358 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1359 }
1360 return val;
1361}
1362Float_t AliTPCcalibDB::GetSkirtVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1363{
1364 //
1365 // Get the skirt voltage for 'run' at 'timeStamp' and 'sector': 0-35 IROC, 36-72 OROC
1366 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1367 // if timeStamp==-1 return the mean value for the run
1368 //
1369 Float_t val=0;
1370 TString sensorName="";
1371 TTimeStamp stamp(timeStamp);
1372 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1373 if (!voltageArray || (sector<0) || (sector>71)) return val;
1374 Char_t sideName='A';
1375 if ((sector/18)%2==1) sideName='C';
1376 sensorName=Form("TPC_SKIRT_%c_VMEAS",sideName);
1377 if (timeStamp==-1){
1378 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1379 } else {
1380 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1381 }
1382 return val;
1383}
1384
1385Float_t AliTPCcalibDB::GetCoverVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1386{
1387 //
1388 // Get the cover voltage for run 'run' at time 'timeStamp'
1389 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1390 // if timeStamp==-1 return the mean value for the run
e2914767 1391 //
7fff7612 1392 Float_t val=0;
1393 TString sensorName="";
e2914767 1394 TTimeStamp stamp(timeStamp);
1395 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
7fff7612 1396 if (!voltageArray || (sector<0) || (sector>71)) return val;
1397 Char_t sideName='A';
1398 if ((sector/18)%2==1) sideName='C';
1399 if (sector<36){
1400 //IROC
1401 sensorName=Form("TPC_COVER_I_%c_VMEAS",sideName);
1402 }else{
1403 //OROC
1404 sensorName=Form("TPC_COVER_O_%c_VMEAS",sideName);
1405 }
1406 if (timeStamp==-1){
1407 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1408 } else {
1409 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1410 }
1411 return val;
1412}
1413
1414Float_t AliTPCcalibDB::GetGGoffsetVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1415{
1416 //
1417 // Get the GG offset voltage for run 'run' at time 'timeStamp'
1418 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1419 // if timeStamp==-1 return the mean value for the run
1420 //
1421 Float_t val=0;
1422 TString sensorName="";
1423 TTimeStamp stamp(timeStamp);
1424 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1425 if (!voltageArray || (sector<0) || (sector>71)) return val;
1426 Char_t sideName='A';
1427 if ((sector/18)%2==1) sideName='C';
1428 if (sector<36){
1429 //IROC
1430 sensorName=Form("TPC_GATE_I_%c_OFF_VMEAS",sideName);
1431 }else{
1432 //OROC
1433 sensorName=Form("TPC_GATE_O_%c_OFF_VMEAS",sideName);
1434 }
1435 if (timeStamp==-1){
1436 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1437 } else {
1438 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1439 }
1440 return val;
1441}
1442
1443Float_t AliTPCcalibDB::GetGGnegVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1444{
1445 //
1446 // Get the GG offset voltage for run 'run' at time 'timeStamp'
1447 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1448 // if timeStamp==-1 return the mean value for the run
1449 //
1450 Float_t val=0;
1451 TString sensorName="";
1452 TTimeStamp stamp(timeStamp);
1453 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1454 if (!voltageArray || (sector<0) || (sector>71)) return val;
1455 Char_t sideName='A';
1456 if ((sector/18)%2==1) sideName='C';
1457 if (sector<36){
1458 //IROC
1459 sensorName=Form("TPC_GATE_I_%c_NEG_VMEAS",sideName);
1460 }else{
1461 //OROC
1462 sensorName=Form("TPC_GATE_O_%c_NEG_VMEAS",sideName);
1463 }
1464 if (timeStamp==-1){
1465 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1466 } else {
1467 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1468 }
1469 return val;
1470}
1471
1472Float_t AliTPCcalibDB::GetGGposVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1473{
1474 //
1475 // Get the GG offset voltage for run 'run' at time 'timeStamp'
1476 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1477 // if timeStamp==-1 return the mean value for the run
1478 //
1479 Float_t val=0;
1480 TString sensorName="";
1481 TTimeStamp stamp(timeStamp);
1482 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1483 if (!voltageArray || (sector<0) || (sector>71)) return val;
1484 Char_t sideName='A';
1485 if ((sector/18)%2==1) sideName='C';
1486 if (sector<36){
1487 //IROC
1488 sensorName=Form("TPC_GATE_I_%c_POS_VMEAS",sideName);
1489 }else{
1490 //OROC
1491 sensorName=Form("TPC_GATE_O_%c_POS_VMEAS",sideName);
1492 }
1493 if (timeStamp==-1){
1494 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1495 } else {
1496 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1497 }
1498 return val;
e2914767 1499}
bf85fe4d 1500
da6c0bc9 1501Float_t AliTPCcalibDB::GetPressure(Int_t timeStamp, Int_t run, Int_t type){
bf85fe4d 1502 //
1503 // GetPressure for given time stamp and runt
1504 //
1505 TTimeStamp stamp(timeStamp);
da6c0bc9 1506 AliDCSSensor * sensor = Instance()->GetPressureSensor(run,type);
bf85fe4d 1507 if (!sensor) return 0;
bf85fe4d 1508 return sensor->GetValue(stamp);
1509}
1510
5312f439 1511Float_t AliTPCcalibDB::GetL3Current(Int_t run, Int_t statType){
1512 //
1513 // return L3 current
1514 // stat type is: AliGRPObject::Stats: kMean = 0, kTruncMean = 1, kMedian = 2, kSDMean = 3, kSDMedian = 4
1515 //
1516 Float_t current=-1;
1517 AliGRPObject *grp=AliTPCcalibDB::GetGRP(run);
1518 if (grp) current=grp->GetL3Current((AliGRPObject::Stats)statType);
1519 return current;
1520}
1521
1522Float_t AliTPCcalibDB::GetBz(Int_t run){
1523 //
e6970ab5 1524 // calculate BZ in T from L3 current
5312f439 1525 //
1526 Float_t bz=-1;
1527 Float_t current=AliTPCcalibDB::GetL3Current(run);
e6970ab5 1528 if (current>-1) bz=5*current/30000.*.1;
5312f439 1529 return bz;
1530}
1531
1532Char_t AliTPCcalibDB::GetL3Polarity(Int_t run) {
1533 //
1534 // get l3 polarity from GRP
1535 //
7390f655 1536 Char_t pol=-100;
1537 AliGRPObject *grp=AliTPCcalibDB::GetGRP(run);
1538 if (grp) pol=grp->GetL3Polarity();
1539 return pol;
5312f439 1540}
1541
1542TString AliTPCcalibDB::GetRunType(Int_t run){
1543 //
1544 // return run type from grp
1545 //
7390f655 1546
1547// TString type("UNKNOWN");
1548 AliGRPObject *grp=AliTPCcalibDB::GetGRP(run);
1549 if (grp) return grp->GetRunType();
1550 return "UNKNOWN";
5312f439 1551}
1552
7f7847fe 1553Float_t AliTPCcalibDB::GetValueGoofie(Int_t timeStamp, Int_t run, Int_t type){
1554 //
1555 // GetPressure for given time stamp and runt
1556 //
1557 TTimeStamp stamp(timeStamp);
1558 AliDCSSensorArray* goofieArray = AliTPCcalibDB::Instance()->GetGoofieSensors(run);
1559 if (!goofieArray) return 0;
1560 AliDCSSensor *sensor = goofieArray->GetSensor(type);
1561 return sensor->GetValue(stamp);
1562}
1563
1564
1565
1566
1567
1568
f0269955 1569Bool_t AliTPCcalibDB::GetTemperatureFit(Int_t timeStamp, Int_t run, Int_t side,TVectorD& fit){
1570 //
92fb7d95 1571 // GetTmeparature fit at parameter for given time stamp
f0269955 1572 //
1573 TTimeStamp tstamp(timeStamp);
64b48395 1574 AliTPCSensorTempArray* tempArray = Instance()->GetTemperatureSensor(run);
f0269955 1575 if (! tempArray) return kFALSE;
1576 AliTPCTempMap * tempMap = new AliTPCTempMap(tempArray);
1577 TLinearFitter * fitter = tempMap->GetLinearFitter(3,side,tstamp);
1578 if (fitter){
1579 fitter->Eval();
1580 fitter->GetParameters(fit);
1581 }
1582 delete fitter;
1583 delete tempMap;
1584 if (!fitter) return kFALSE;
1585 return kTRUE;
1586}
1587
64b48395 1588Float_t AliTPCcalibDB::GetTemperature(Int_t timeStamp, Int_t run, Int_t side){
1589 //
92fb7d95 1590 // Get mean temperature
1591 //
12e42756 1592 TVectorD vec(5);
64b48395 1593 if (side==0) {
1594 GetTemperatureFit(timeStamp,run,0,vec);
1595 return vec[0];
1596 }
1597 if (side==1){
1598 GetTemperatureFit(timeStamp,run,0,vec);
1599 return vec[0];
1600 }
57dc06f2 1601 return 0;
64b48395 1602}
bf85fe4d 1603
1604
da6c0bc9 1605Double_t AliTPCcalibDB::GetPTRelative(UInt_t timeSec, Int_t run, Int_t side){
1606 //
1607 // Get relative P/T
1608 // time - absolute time
1609 // run - run number
1610 // side - 0 - A side 1-C side
1611 AliTPCCalibVdrift * vdrift = Instance()->GetVdrift(run);
1612 if (!vdrift) return 0;
1613 return vdrift->GetPTRelative(timeSec,side);
1614}
1615
e2914767 1616AliGRPObject * AliTPCcalibDB::MakeGRPObjectFromMap(TMap *map){
1617 //
1618 // Function to covert old GRP run information from TMap to GRPObject
1619 //
1620 // TMap * map = AliTPCcalibDB::GetGRPMap(52406);
1621 if (!map) return 0;
1622 AliDCSSensor * sensor = 0;
1623 TObject *osensor=0;
1624 osensor = ((*map)("fP2Pressure"));
1625 sensor =dynamic_cast<AliDCSSensor *>(osensor);
1626 //
1627 if (!sensor) return 0;
1628 //
1629 AliDCSSensor * sensor2 = new AliDCSSensor(*sensor);
2cd3a697 1630 osensor = ((*map)("fCavernPressure"));
e2914767 1631 TGraph * gr = new TGraph(2);
1632 gr->GetX()[0]= -100000.;
1633 gr->GetX()[1]= 1000000.;
1634 gr->GetY()[0]= atof(osensor->GetName());
1635 gr->GetY()[1]= atof(osensor->GetName());
1636 sensor2->SetGraph(gr);
1637 sensor2->SetFit(0);
1638
1639
1640 AliGRPObject *grpRun = new AliGRPObject;
1641 grpRun->ReadValuesFromMap(map);
1642 grpRun->SetCavernAtmosPressure(sensor2);
2cd3a697 1643 grpRun->SetCavernAtmosPressure(sensor2);
e2914767 1644 grpRun->SetSurfaceAtmosPressure(sensor);
1645 return grpRun;
1646}
1647
5312f439 1648Bool_t AliTPCcalibDB::CreateGUITree(Int_t run, const char* filename)
1649{
1650 //
1651 // Create a gui tree for run number 'run'
1652 //
e2914767 1653
5312f439 1654 if (!AliCDBManager::Instance()->GetDefaultStorage()){
1655 AliLog::Message(AliLog::kError, "Default Storage not set. Cannot create Calibration Tree!",
1656 MODULENAME(), "AliTPCcalibDB", FUNCTIONNAME(), __FILE__, __LINE__);
1657 return kFALSE;
1658 }
1659 //db instance
1660 AliTPCcalibDB *db=AliTPCcalibDB::Instance();
1661 // retrieve cal pad objects
1662 db->SetRun(run);
949d8707 1663 db->CreateGUITree(filename);
7fe54a9b 1664 return kTRUE;
949d8707 1665}
1666
1667Bool_t AliTPCcalibDB::CreateGUITree(const char* filename){
1668 //
1669 //
1670 //
1671 if (!AliCDBManager::Instance()->GetDefaultStorage()){
1672 AliError("Default Storage not set. Cannot create calibration Tree!");
1673 return kFALSE;
1674 }
56ce896d 1675 UpdateNonRec(); // load all infromation now
1676
5312f439 1677 AliTPCPreprocessorOnline prep;
1678 //noise and pedestals
949d8707 1679 if (GetPedestals()) prep.AddComponent(new AliTPCCalPad(*(GetPedestals())));
1680 if (GetPadNoise() ) prep.AddComponent(new AliTPCCalPad(*(GetPadNoise())));
5312f439 1681 //pulser data
949d8707 1682 if (GetPulserTmean()) prep.AddComponent(new AliTPCCalPad(*(GetPulserTmean())));
1683 if (GetPulserTrms() ) prep.AddComponent(new AliTPCCalPad(*(GetPulserTrms())));
1684 if (GetPulserQmean()) prep.AddComponent(new AliTPCCalPad(*(GetPulserQmean())));
5312f439 1685 //CE data
949d8707 1686 if (GetCETmean()) prep.AddComponent(new AliTPCCalPad(*(GetCETmean())));
1687 if (GetCETrms() ) prep.AddComponent(new AliTPCCalPad(*(GetCETrms())));
1688 if (GetCEQmean()) prep.AddComponent(new AliTPCCalPad(*(GetCEQmean())));
5312f439 1689 //Altro data
949d8707 1690 if (GetALTROAcqStart() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROAcqStart() )));
1691 if (GetALTROZsThr() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROZsThr() )));
1692 if (GetALTROFPED() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROFPED() )));
1693 if (GetALTROAcqStop() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROAcqStop() )));
1694 if (GetALTROMasked() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROMasked() )));
1695 //QA
1696 AliTPCdataQA *dataQA=GetDataQA();
1697 if (dataQA) {
1698 if (dataQA->GetNLocalMaxima())
1699 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNLocalMaxima())));
1700 if (dataQA->GetMaxCharge())
1701 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetMaxCharge())));
1702 if (dataQA->GetMeanCharge())
1703 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetMeanCharge())));
1704 if (dataQA->GetNoThreshold())
1705 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNoThreshold())));
1706 if (dataQA->GetNTimeBins())
1707 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNTimeBins())));
1708 if (dataQA->GetNPads())
1709 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNPads())));
1710 if (dataQA->GetTimePosition())
1711 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetTimePosition())));
1712 }
1713
5312f439 1714 //
1715 TString file(filename);
60721370 1716 if (file.IsNull()) file=Form("guiTreeRun_%lld.root",fRun);
5312f439 1717 prep.DumpToFile(file.Data());
1718 return kTRUE;
1719}
e2914767 1720
7390f655 1721Bool_t AliTPCcalibDB::CreateRefFile(Int_t run, const char* filename)
1722{
1723 //
1724 // Create a gui tree for run number 'run'
1725 //
1726
1727 if (!AliCDBManager::Instance()->GetDefaultStorage()){
1728 AliLog::Message(AliLog::kError, "Default Storage not set. Cannot create Calibration Tree!",
1729 MODULENAME(), "AliTPCcalibDB", FUNCTIONNAME(), __FILE__, __LINE__);
1730 return kFALSE;
1731 }
1732 TString file(filename);
1733 if (file.IsNull()) file=Form("RefCalPads_%d.root",run);
1734 TDirectory *currDir=gDirectory;
1735 //db instance
1736 AliTPCcalibDB *db=AliTPCcalibDB::Instance();
1737 // retrieve cal pad objects
1738 db->SetRun(run);
1739 //open file
1740 TFile f(file.Data(),"recreate");
1741 //noise and pedestals
1742 db->GetPedestals()->Write("Pedestals");
1743 db->GetPadNoise()->Write("PadNoise");
1744 //pulser data
1745 db->GetPulserTmean()->Write("PulserTmean");
1746 db->GetPulserTrms()->Write("PulserTrms");
1747 db->GetPulserQmean()->Write("PulserQmean");
1748 //CE data
1749 db->GetCETmean()->Write("CETmean");
1750 db->GetCETrms()->Write("CETrms");
1751 db->GetCEQmean()->Write("CEQmean");
1752 //Altro data
1753 db->GetALTROAcqStart() ->Write("ALTROAcqStart");
1754 db->GetALTROZsThr() ->Write("ALTROZsThr");
1755 db->GetALTROFPED() ->Write("ALTROFPED");
1756 db->GetALTROAcqStop() ->Write("ALTROAcqStop");
1757 db->GetALTROMasked() ->Write("ALTROMasked");
1758 //
1759 f.Close();
1760 currDir->cd();
1761 return kTRUE;
1762}
17c90083 1763
1764
1765
817766d5 1766Double_t AliTPCcalibDB::GetVDriftCorrectionTime(Int_t timeStamp, Int_t run, Int_t /*side*/, Int_t mode){
17c90083 1767 //
1768 // Get time dependent drift velocity correction
1769 // multiplication factor vd = vdnom *(1+vdriftcorr)
1770 // Arguments:
1771 // mode determines the algorith how to combine the Laser Track, LaserCE and physics tracks
1772 // timestamp - timestamp
1773 // run - run number
1774 // side - the drift velocity per side (possible for laser and CE)
1775 //
1776 // Notice - Extrapolation outside of calibration range - using constant function
1777 //
b7c5eb40 1778 Double_t result=0;
1e722a63 1779 // mode 1 automatic mode - according to the distance to the valid calibration
1780 // -
cc65e4f5 1781 Double_t deltaP=0, driftP=0, wP = 0.;
1782 Double_t deltaITS=0,driftITS=0, wITS= 0.;
1783 Double_t deltaLT=0, driftLT=0, wLT = 0.;
1784 Double_t deltaCE=0, driftCE=0, wCE = 0.;
1e722a63 1785 driftP = fDButil->GetVDriftTPC(deltaP,run,timeStamp);
cc65e4f5 1786 driftITS= fDButil->GetVDriftTPCITS(deltaITS,run,timeStamp);
1e722a63 1787 driftCE = fDButil->GetVDriftTPCCE(deltaCE, run,timeStamp,36000,2);
1788 driftLT = fDButil->GetVDriftTPCLaserTracks(deltaLT,run,timeStamp,36000,2);
cc65e4f5 1789 deltaITS = TMath::Abs(deltaITS);
1e722a63 1790 deltaP = TMath::Abs(deltaP);
1791 deltaLT = TMath::Abs(deltaLT);
1792 deltaCE = TMath::Abs(deltaCE);
1793 if (mode==1) {
cc65e4f5 1794 const Double_t kEpsilon=0.00000000001;
1795 const Double_t kdeltaT=360.; // 10 minutes
a52d8b6f 1796 if(TMath::Abs(deltaITS) < 12*kdeltaT) {
5647625c 1797 result = driftITS;
1798 } else {
cc65e4f5 1799 wITS = 64.*kdeltaT/(deltaITS +kdeltaT);
1800 wLT = 16.*kdeltaT/(deltaLT +kdeltaT);
1801 wP = 0. *kdeltaT/(deltaP +kdeltaT);
1802 wCE = 1. *kdeltaT/(deltaCE +kdeltaT);
1803 //
1804 //
1805 if (TMath::Abs(driftP)<kEpsilon) wP=0; // invalid calibration
1806 if (TMath::Abs(driftITS)<kEpsilon)wITS=0; // invalid calibration
1807 if (TMath::Abs(driftLT)<kEpsilon) wLT=0; // invalid calibration
1e722a63 1808 if (TMath::Abs(driftCE)<kEpsilon) wCE=0; // invalid calibration
cc65e4f5 1809 if (wP+wITS+wLT+wCE<kEpsilon) return 0;
1810 result = (driftP*wP+driftITS*wITS+driftLT*wLT+driftCE*wCE)/(wP+wITS+wLT+wCE);
5647625c 1811 }
1812
1813
43a74775 1814 }
817766d5 1815
43a74775 1816 return result;
17c90083 1817}
1818
817766d5 1819Double_t AliTPCcalibDB::GetTime0CorrectionTime(Int_t timeStamp, Int_t run, Int_t /*side*/, Int_t mode){
17c90083 1820 //
43a74775 1821 // Get time dependent time 0 (trigger delay in cm) correction
17c90083 1822 // additive correction time0 = time0+ GetTime0CorrectionTime
1823 // Value etracted combining the vdrift correction using laser tracks and CE and the physics track matchin
1824 // Arguments:
1825 // mode determines the algorith how to combine the Laser Track and physics tracks
1826 // timestamp - timestamp
1827 // run - run number
1828 // side - the drift velocity per side (possible for laser and CE)
1829 //
1830 // Notice - Extrapolation outside of calibration range - using constant function
1831 //
817766d5 1832 Double_t result=0;
cc65e4f5 1833 if (mode==2) {
1834 // TPC-TPC mode
1835 result=fDButil->GetTriggerOffsetTPC(run,timeStamp);
1836 result *=fParam->GetZLength();
1837 }
1838 if (mode==1){
1839 // TPC-ITS mode
1840 Double_t dist=0;
86c39d37 1841 result= -fDButil->GetTime0TPCITS(dist, run, timeStamp)*fParam->GetDriftV()/1000000.;
cc65e4f5 1842 }
817766d5 1843 return result;
43a74775 1844
17c90083 1845}
1846
1847
1848
1849
43a74775 1850Double_t AliTPCcalibDB::GetVDriftCorrectionGy(Int_t timeStamp, Int_t run, Int_t side, Int_t /*mode*/){
17c90083 1851 //
1852 // Get global y correction drift velocity correction factor
1853 // additive factor vd = vdnom*(1+GetVDriftCorrectionGy *gy)
5647625c 1854 // Value etracted combining the vdrift correction using laser tracks and CE or TPC-ITS
17c90083 1855 // Arguments:
5647625c 1856 // mode determines the algorith how to combine the Laser Track, LaserCE or TPC-ITS
17c90083 1857 // timestamp - timestamp
1858 // run - run number
1859 // side - the drift velocity gy correction per side (CE and Laser tracks)
1860 //
1861 // Notice - Extrapolation outside of calibration range - using constant function
a8f8b6a1 1862 //
1863 if (run<=0 && fTransform) run = fTransform->GetCurrentRunNumber();
1864 UpdateRunInformations(run,kFALSE);
43a74775 1865 TObjArray *array =AliTPCcalibDB::Instance()->GetTimeVdriftSplineRun(run);
4429bfef 1866 if (!array) return 0;
5647625c 1867 Double_t result=0;
1868
1869 // use TPC-ITS if present
1870 TGraphErrors *gr= (TGraphErrors*)array->FindObject("ALIGN_ITSB_TPC_VDGY");
1871 if(gr) {
0fc78dbd 1872 result = AliTPCcalibDButil::EvalGraphConst(gr,timeStamp);
5647625c 1873
1874 // transform from [(cm/mus)/ m] to [1/cm]
1875 result /= (fParam->GetDriftV()/1000000.);
1876 result /= 100.;
1877
1878 //printf("result %e \n", result);
1879 return result;
1880 }
1881
1882 // use laser if ITS-TPC not present
43a74775 1883 TGraphErrors *laserA= (TGraphErrors*)array->FindObject("GRAPH_MEAN_GLOBALYGRADIENT_LASER_ALL_A");
1884 TGraphErrors *laserC= (TGraphErrors*)array->FindObject("GRAPH_MEAN_GLOBALYGRADIENT_LASER_ALL_C");
1885
43a74775 1886 if (laserA && laserC){
1887 result= (laserA->Eval(timeStamp)+laserC->Eval(timeStamp))*0.5;
1888 }
1889 if (laserA && side==0){
1890 result = (laserA->Eval(timeStamp));
1891 }
1892 if (laserC &&side==1){
1893 result = (laserC->Eval(timeStamp));
1894 }
5647625c 1895 //printf("laser result %e \n", -result/250.);
1896
43a74775 1897 return -result/250.; //normalized before
17c90083 1898}
949d8707 1899
72b94ffb 1900AliTPCCalPad* AliTPCcalibDB::MakeDeadMap(Double_t notInMap, const char* nameMappingFile) {
f6b5fa33 1901//
1902// Read list of active DDLs from OCDB entry
1903// Generate and return AliTPCCalPad containing 1 for all pads in active DDLs,
1904// 0 for all pads in non-active DDLs.
72b94ffb 1905// For DDLs with missing status information (no DCS input point to Shuttle),
1906// the value of the AliTPCCalPad entry is determined by the parameter
1907// notInMap (default value 1)
f6b5fa33 1908//
1909 char chinfo[1000];
1910
1911 TFile *fileMapping = new TFile(nameMappingFile, "read");
1912 AliTPCmapper *mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping");
1913 if (!mapping) {
1914 sprintf(chinfo,"Failed to get mapping object from %s. ...\n", nameMappingFile);
1915 AliError (chinfo);
1916 return 0;
1917 }
1918
1919 AliTPCCalPad *deadMap = new AliTPCCalPad("deadMap","deadMap");
1920 if (!deadMap) {
1921 AliError("Failed to allocate dead map AliTPCCalPad");
1922 return 0;
1923 }
1924
1925 /// get list of active DDLs from OCDB entry
1926 Int_t idDDL=0;
1927 if (!fALTROConfigData ) {
1928 AliError("No ALTRO config OCDB entry available");
1929 return 0;
1930 }
1931 TMap *activeDDL = (TMap*)fALTROConfigData->FindObject("DDLArray");
1932 TObjString *ddlArray=0;
1933 if (activeDDL) {
1934 ddlArray = (TObjString*)activeDDL->GetValue("DDLArray");
1935 if (!ddlArray) {
1936 AliError("Empty list of active DDLs in OCDB entry");
1937 return 0;
1938 }
1939 } else {
1940 AliError("List of active DDLs not available in OCDB entry");
1941 return 0;
1942 }
1943 TString arrDDL=ddlArray->GetString();
1944 Int_t offset = mapping->GetTpcDdlOffset();
1945 Double_t active;
1946 for (Int_t i=0; i<mapping->GetNumDdl(); i++) {
1947 idDDL= i+offset;
1948 Int_t patch = mapping->GetPatchFromEquipmentID(idDDL);
1949 Int_t roc=mapping->GetRocFromEquipmentID(idDDL);
1950 AliTPCCalROC *calRoc=deadMap->GetCalROC(roc);
1951 if (calRoc) {
1952 for ( Int_t branch = 0; branch < 2; branch++ ) {
1953 for ( Int_t fec = 0; fec < mapping->GetNfec(patch, branch); fec++ ) {
1954 for ( Int_t altro = 0; altro < 8; altro++ ) {
1955 for ( Int_t channel = 0; channel < 16; channel++ ) {
1956 Int_t hwadd = mapping->CodeHWAddress(branch, fec, altro, channel);
1957 Int_t row = mapping->GetPadRow(patch, hwadd); // row in a ROC (IROC or OROC)
1958// Int_t globalrow = mapping.GetGlobalPadRow(patch, hwadd); // row in full sector (IROC plus OROC)
1959 Int_t pad = mapping->GetPad(patch, hwadd);
72b94ffb 1960 if (!TString(arrDDL[i]).IsDigit()) {
1961 active = notInMap;
1962 } else {
1963 active=TString(arrDDL[i]).Atof();
1964 }
f6b5fa33 1965 calRoc->SetValue(row,pad,active);
1966 } // end channel for loop
1967 } // end altro for loop
1968 } // end fec for loop
1969 } // end branch for loop
1970 } // valid calROC
1971 } // end loop on active DDLs
1972 return deadMap;
1973}
f14d21a1 1974
1975
0b736a46 1976
1977AliTPCCorrection * AliTPCcalibDB::GetTPCComposedCorrection(Float_t field) const{
1978 //
1979 // GetComposed correction for given field setting
1980 //
1981 if (!fComposedCorrectionArray) return 0;
1982 if (field>0.1) return (AliTPCCorrection *)fComposedCorrectionArray->At(1);
1983 if (field<-0.1) return (AliTPCCorrection *)fComposedCorrectionArray->At(2);
1984 return (AliTPCCorrection *)fComposedCorrectionArray->At(0);
1985
1986}
1987