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