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