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