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