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