]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/AliTPCcalibDB.cxx
Set finite validity (one run) to TPC/Calib/AltroConfig OCDB entries
[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>
85#include <AliLog.h>
3ac615eb 86#include <AliMagF.h>
7fff7612 87#include <AliSplineFit.h>
c5bbaa2c 88
89#include "AliTPCcalibDB.h"
d6834f5f 90#include "AliTPCAltroMapping.h"
418bbcaf 91#include "AliTPCExB.h"
c5bbaa2c 92
93#include "AliTPCCalROC.h"
94#include "AliTPCCalPad.h"
54472e4f 95#include "AliTPCSensorTempArray.h"
bf85fe4d 96#include "AliGRPObject.h"
418bbcaf 97#include "AliTPCTransform.h"
d6834f5f 98
418bbcaf 99class AliCDBStorage;
100class AliTPCCalDet;
86df2b3a 101//
102//
103
86df2b3a 104#include "TFile.h"
105#include "TKey.h"
106
107#include "TObjArray.h"
108#include "TObjString.h"
109#include "TString.h"
110#include "AliTPCCalPad.h"
0fe7645c 111#include "AliTPCCalibPulser.h"
86df2b3a 112#include "AliTPCCalibPedestal.h"
113#include "AliTPCCalibCE.h"
3ac615eb 114#include "AliTPCExBFirst.h"
bf85fe4d 115#include "AliTPCTempMap.h"
da6c0bc9 116#include "AliTPCCalibVdrift.h"
86df2b3a 117
5312f439 118#include "AliTPCPreprocessorOnline.h"
86df2b3a 119
c5bbaa2c 120
121ClassImp(AliTPCcalibDB)
122
123AliTPCcalibDB* AliTPCcalibDB::fgInstance = 0;
124Bool_t AliTPCcalibDB::fgTerminated = kFALSE;
3ac615eb 125TObjArray AliTPCcalibDB::fgExBArray; // array of ExB corrections
c5bbaa2c 126
127
128//_ singleton implementation __________________________________________________
129AliTPCcalibDB* AliTPCcalibDB::Instance()
130{
131 //
132 // Singleton implementation
133 // Returns an instance of this class, it is created if neccessary
134 //
135
136 if (fgTerminated != kFALSE)
137 return 0;
138
139 if (fgInstance == 0)
140 fgInstance = new AliTPCcalibDB();
141
142 return fgInstance;
143}
144
145void AliTPCcalibDB::Terminate()
146{
147 //
148 // Singleton implementation
149 // Deletes the instance of this class and sets the terminated flag, instances cannot be requested anymore
150 // This function can be called several times.
151 //
152
153 fgTerminated = kTRUE;
154
155 if (fgInstance != 0)
156 {
157 delete fgInstance;
158 fgInstance = 0;
159 }
160}
161
162//_____________________________________________________________________________
e4dce695 163AliTPCcalibDB::AliTPCcalibDB():
9389f9a4 164 TObject(),
e4dce695 165 fRun(-1),
f5344549 166 fTransform(0),
481f877b 167 fExB(0),
e4dce695 168 fPadGainFactor(0),
9f6e9f81 169 fDedxGainFactor(0),
e4dce695 170 fPadTime0(0),
e4dce695 171 fPadNoise(0),
172 fPedestals(0),
5312f439 173 fALTROConfigData(0),
174 fPulserData(0),
175 fCEData(0),
e4dce695 176 fTemperature(0),
d6834f5f 177 fMapping(0),
96305e49 178 fParam(0),
a2c3785e 179 fClusterParam(0),
180 fTimeGainSplines(0),
181 fTimeGainSplinesArray(100000),
da6c0bc9 182 fGRPArray(100000), //! array of GRPs - per run - JUST for calibration studies
0231c65f 183 fGRPMaps(100000), //! array of GRPs - per run - JUST for calibration studies
da6c0bc9 184 fGoofieArray(100000), //! array of GOOFIE values -per run - Just for calibration studies
e2914767 185 fVoltageArray(100000),
da6c0bc9 186 fTemperatureArray(100000), //! array of temperature sensors - per run - Just for calibration studies
187 fVdriftArray(100000), //! array of v drift interfaces
5e1215d4 188 fDriftCorrectionArray(100000), //! array of drift correction
bf85fe4d 189 fRunList(100000) //! run list - indicates try to get the run param
190
c5bbaa2c 191{
192 //
193 // constructor
194 //
54472e4f 195 //
c5bbaa2c 196 Update(); // temporary
197}
198
9389f9a4 199AliTPCcalibDB::AliTPCcalibDB(const AliTPCcalibDB& ):
200 TObject(),
201 fRun(-1),
202 fTransform(0),
203 fExB(0),
204 fPadGainFactor(0),
9f6e9f81 205 fDedxGainFactor(0),
9389f9a4 206 fPadTime0(0),
207 fPadNoise(0),
208 fPedestals(0),
5312f439 209 fALTROConfigData(0),
210 fPulserData(0),
211 fCEData(0),
9389f9a4 212 fTemperature(0),
213 fMapping(0),
9389f9a4 214 fParam(0),
bf85fe4d 215 fClusterParam(0),
a2c3785e 216 fTimeGainSplines(0),
217 fTimeGainSplinesArray(100000),
bf85fe4d 218 fGRPArray(0), //! array of GRPs - per run - JUST for calibration studies
0231c65f 219 fGRPMaps(0), //! array of GRPs - per run - JUST for calibration studies
bf85fe4d 220 fGoofieArray(0), //! array of GOOFIE values -per run - Just for calibration studies
e2914767 221 fVoltageArray(0),
bf85fe4d 222 fTemperatureArray(0), //! array of temperature sensors - per run - Just for calibration studies
da6c0bc9 223 fVdriftArray(0), //! array of v drift interfaces
5e1215d4 224 fDriftCorrectionArray(0), //! array of v drift interfaces
bf85fe4d 225 fRunList(0) //! run list - indicates try to get the run param
9389f9a4 226{
227 //
228 // Copy constructor invalid -- singleton implementation
229 //
230 Error("copy constructor","invalid -- singleton implementation");
231}
232
233AliTPCcalibDB& AliTPCcalibDB::operator= (const AliTPCcalibDB& )
234{
235//
236// Singleton implementation - no assignment operator
237//
238 Error("operator =", "assignment operator not implemented");
239 return *this;
240}
241
242
243
c5bbaa2c 244//_____________________________________________________________________________
245AliTPCcalibDB::~AliTPCcalibDB()
246{
247 //
248 // destructor
249 //
68751c2c 250
251 // don't delete anything, CDB cache is active!
252 //if (fPadGainFactor) delete fPadGainFactor;
253 //if (fPadTime0) delete fPadTime0;
68751c2c 254 //if (fPadNoise) delete fPadNoise;
c5bbaa2c 255}
256
257
258//_____________________________________________________________________________
259AliCDBEntry* AliTPCcalibDB::GetCDBEntry(const char* cdbPath)
260{
261 //
262 // Retrieves an entry with path <cdbPath> from the CDB.
263 //
264 char chinfo[1000];
265
68751c2c 266 AliCDBEntry* entry = AliCDBManager::Instance()->Get(cdbPath, fRun);
c5bbaa2c 267 if (!entry)
268 {
269 sprintf(chinfo,"AliTPCcalibDB: Failed to get entry:\t%s ", cdbPath);
270 AliError(chinfo);
271 return 0;
272 }
273 return entry;
274}
275
276
277//_____________________________________________________________________________
278void AliTPCcalibDB::SetRun(Long64_t run)
279{
280 //
281 // Sets current run number. Calibration data is read from the corresponding file.
282 //
283 if (fRun == run)
284 return;
a2c3785e 285 fRun = run;
c5bbaa2c 286 Update();
287}
288
289
290
291void AliTPCcalibDB::Update(){
a2c3785e 292 //
293 AliCDBEntry * entry=0;
68751c2c 294
295 Bool_t cdbCache = AliCDBManager::Instance()->GetCacheFlag(); // save cache status
296 AliCDBManager::Instance()->SetCacheFlag(kTRUE); // activate CDB cache
297
c5bbaa2c 298 //
299 entry = GetCDBEntry("TPC/Calib/PadGainFactor");
300 if (entry){
68751c2c 301 //if (fPadGainFactor) delete fPadGainFactor;
c5bbaa2c 302 entry->SetOwner(kTRUE);
303 fPadGainFactor = (AliTPCCalPad*)entry->GetObject();
304 }
305 //
3af3fbc4 306 entry = GetCDBEntry("TPC/Calib/TimeGain");
307 if (entry){
308 //if (fTimeGainSplines) delete fTimeGainSplines;
309 entry->SetOwner(kTRUE);
310 fTimeGainSplines = (TObjArray*)entry->GetObject();
311 }
312 //
9f6e9f81 313 entry = GetCDBEntry("TPC/Calib/GainFactorDedx");
314 if (entry){
315 entry->SetOwner(kTRUE);
316 fDedxGainFactor = (AliTPCCalPad*)entry->GetObject();
317 }
318 //
c5bbaa2c 319 entry = GetCDBEntry("TPC/Calib/PadTime0");
320 if (entry){
68751c2c 321 //if (fPadTime0) delete fPadTime0;
c5bbaa2c 322 entry->SetOwner(kTRUE);
323 fPadTime0 = (AliTPCCalPad*)entry->GetObject();
324 }
325 //
c5bbaa2c 326 //
327 entry = GetCDBEntry("TPC/Calib/PadNoise");
328 if (entry){
68751c2c 329 //if (fPadNoise) delete fPadNoise;
c5bbaa2c 330 entry->SetOwner(kTRUE);
331 fPadNoise = (AliTPCCalPad*)entry->GetObject();
332 }
8477f500 333
334 entry = GetCDBEntry("TPC/Calib/Pedestals");
335 if (entry){
336 //if (fPedestals) delete fPedestals;
337 entry->SetOwner(kTRUE);
338 fPedestals = (AliTPCCalPad*)entry->GetObject();
339 }
340
54472e4f 341 entry = GetCDBEntry("TPC/Calib/Temperature");
342 if (entry){
343 //if (fTemperature) delete fTemperature;
344 entry->SetOwner(kTRUE);
345 fTemperature = (AliTPCSensorTempArray*)entry->GetObject();
346 }
347
8477f500 348 entry = GetCDBEntry("TPC/Calib/Parameters");
349 if (entry){
54472e4f 350 //if (fPadNoise) delete fPadNoise;
8477f500 351 entry->SetOwner(kTRUE);
a778f7e3 352 fParam = (AliTPCParam*)(entry->GetObject()->Clone());
8477f500 353 }
354
96305e49 355 entry = GetCDBEntry("TPC/Calib/ClusterParam");
356 if (entry){
96305e49 357 entry->SetOwner(kTRUE);
358 fClusterParam = (AliTPCClusterParam*)(entry->GetObject()->Clone());
359 }
360
5312f439 361 //ALTRO configuration data
362 entry = GetCDBEntry("TPC/Calib/AltroConfig");
363 if (entry){
364 entry->SetOwner(kTRUE);
365 fALTROConfigData=(TObjArray*)(entry->GetObject());
366 }
367
368 //Calibration Pulser data
369 entry = GetCDBEntry("TPC/Calib/Pulser");
370 if (entry){
371 entry->SetOwner(kTRUE);
372 fPulserData=(TObjArray*)(entry->GetObject());
373 }
374
375 //CE data
376 entry = GetCDBEntry("TPC/Calib/CE");
377 if (entry){
378 entry->SetOwner(kTRUE);
379 fCEData=(TObjArray*)(entry->GetObject());
380 }
381
d6834f5f 382 entry = GetCDBEntry("TPC/Calib/Mapping");
383 if (entry){
384 //if (fPadNoise) delete fPadNoise;
385 entry->SetOwner(kTRUE);
386 TObjArray * array = dynamic_cast<TObjArray*>(entry->GetObject());
387 if (array && array->GetEntriesFast()==6){
388 fMapping = new AliTPCAltroMapping*[6];
389 for (Int_t i=0; i<6; i++){
5312f439 390 fMapping[i] = dynamic_cast<AliTPCAltroMapping*>(array->At(i));
d6834f5f 391 }
392 }
393 }
394
395
396
3ac615eb 397 //entry = GetCDBEntry("TPC/Calib/ExB");
398 //if (entry) {
399 // entry->SetOwner(kTRUE);
400 // fExB=dynamic_cast<AliTPCExB*>(entry->GetObject()->Clone());
401 //}
402 //
403 // ExB - calculate during initialization
404 // -
f4d5fd21 405 fExB = GetExB(-5,kTRUE);
406 //
f5344549 407 if (!fTransform) {
408 fTransform=new AliTPCTransform();
bfec3eeb 409 fTransform->SetCurrentRun(AliCDBManager::Instance()->GetRun());
f5344549 410 }
8477f500 411
c5bbaa2c 412 //
68751c2c 413 AliCDBManager::Instance()->SetCacheFlag(cdbCache); // reset original CDB cache
414
c5bbaa2c 415}
e4dce695 416
86df2b3a 417
418
419void AliTPCcalibDB::CreateObjectList(const Char_t *filename, TObjArray *calibObjects)
420{
418bbcaf 421//
422// Create calibration objects and read contents from OCDB
423//
86df2b3a 424 if ( calibObjects == 0x0 ) return;
425 ifstream in;
426 in.open(filename);
427 if ( !in.is_open() ){
428 fprintf(stderr,"Error: cannot open list file '%s'", filename);
429 return;
430 }
431
432 AliTPCCalPad *calPad=0x0;
433
434 TString sFile;
435 sFile.ReadFile(in);
436 in.close();
437
438 TObjArray *arrFileLine = sFile.Tokenize("\n");
439
440 TIter nextLine(arrFileLine);
441
442 TObjString *sObjLine=0x0;
2c632057 443 while ( (sObjLine = (TObjString*)nextLine()) ){
86df2b3a 444 TString sLine(sObjLine->GetString());
445
446 TObjArray *arrNextCol = sLine.Tokenize("\t");
447
448 TObjString *sObjType = (TObjString*)(arrNextCol->At(0));
449 TObjString *sObjFileName = (TObjString*)(arrNextCol->At(1));
450
451 if ( !sObjType || ! sObjFileName ) continue;
452 TString sType(sObjType->GetString());
453 TString sFileName(sObjFileName->GetString());
454 printf("%s\t%s\n",sType.Data(),sFileName.Data());
455
456 TFile *fIn = TFile::Open(sFileName);
457 if ( !fIn ){
458 fprintf(stderr,"File not found: '%s'", sFileName.Data());
459 continue;
460 }
461
462 if ( sType == "CE" ){
463 AliTPCCalibCE *ce = (AliTPCCalibCE*)fIn->Get("AliTPCCalibCE");
464
465 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadT0());
466 calPad->SetNameTitle("CETmean","CETmean");
467 calibObjects->Add(calPad);
468
469 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadQ());
470 calPad->SetNameTitle("CEQmean","CEQmean");
471 calibObjects->Add(calPad);
472
473 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadRMS());
474 calPad->SetNameTitle("CETrms","CETrms");
475 calibObjects->Add(calPad);
476
477 } else if ( sType == "Pulser") {
0fe7645c 478 AliTPCCalibPulser *sig = (AliTPCCalibPulser*)fIn->Get("AliTPCCalibPulser");
86df2b3a 479
480 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadT0());
481 calPad->SetNameTitle("PulserTmean","PulserTmean");
482 calibObjects->Add(calPad);
483
484 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadQ());
485 calPad->SetNameTitle("PulserQmean","PulserQmean");
486 calibObjects->Add(calPad);
487
488 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadRMS());
489 calPad->SetNameTitle("PulserTrms","PulserTrms");
490 calibObjects->Add(calPad);
491
492 } else if ( sType == "Pedestals") {
493 AliTPCCalibPedestal *ped = (AliTPCCalibPedestal*)fIn->Get("AliTPCCalibPedestal");
494
495 calPad = new AliTPCCalPad((TObjArray*)ped->GetCalPadPedestal());
496 calPad->SetNameTitle("Pedestals","Pedestals");
497 calibObjects->Add(calPad);
498
499 calPad = new AliTPCCalPad((TObjArray*)ped->GetCalPadRMS());
500 calPad->SetNameTitle("Noise","Noise");
501 calibObjects->Add(calPad);
502
503 } else {
504 fprintf(stderr,"Undefined Type: '%s'",sType.Data());
505
506 }
507 delete fIn;
508 }
509}
510
511
512
513void AliTPCcalibDB::MakeTree(const char * fileName, TObjArray * array, const char * mapFileName, AliTPCCalPad* outlierPad, Float_t ltmFraction) {
514 //
515 // Write a tree with all available information
418bbcaf 516 // if mapFileName is specified, the Map information are also written to the tree
86df2b3a 517 // pads specified in outlierPad are not used for calculating statistics
518 // - the same function as AliTPCCalPad::MakeTree -
519 //
520 AliTPCROC* tpcROCinstance = AliTPCROC::Instance();
521
522 TObjArray* mapIROCs = 0;
523 TObjArray* mapOROCs = 0;
524 TVectorF *mapIROCArray = 0;
525 TVectorF *mapOROCArray = 0;
526 Int_t mapEntries = 0;
527 TString* mapNames = 0;
528
529 if (mapFileName) {
530 TFile mapFile(mapFileName, "read");
531
532 TList* listOfROCs = mapFile.GetListOfKeys();
533 mapEntries = listOfROCs->GetEntries()/2;
534 mapIROCs = new TObjArray(mapEntries*2);
535 mapOROCs = new TObjArray(mapEntries*2);
536 mapIROCArray = new TVectorF[mapEntries];
537 mapOROCArray = new TVectorF[mapEntries];
538
539 mapNames = new TString[mapEntries];
540 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
418bbcaf 541 TString nameROC(((TKey*)(listOfROCs->At(ivalue*2)))->GetName());
542 nameROC.Remove(nameROC.Length()-4, 4);
543 mapIROCs->AddAt((AliTPCCalROC*)mapFile.Get((nameROC + "IROC").Data()), ivalue);
544 mapOROCs->AddAt((AliTPCCalROC*)mapFile.Get((nameROC + "OROC").Data()), ivalue);
545 mapNames[ivalue].Append(nameROC);
86df2b3a 546 }
547
548 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
549 mapIROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(0));
550 mapOROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(36));
551
552 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(0); ichannel++)
553 (mapIROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapIROCs->At(ivalue)))->GetValue(ichannel);
554 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(36); ichannel++)
555 (mapOROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapOROCs->At(ivalue)))->GetValue(ichannel);
556 }
557
558 } // if (mapFileName)
559
560 TTreeSRedirector cstream(fileName);
561 Int_t arrayEntries = array->GetEntries();
562
563 TString* names = new TString[arrayEntries];
564 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
565 names[ivalue].Append(((AliTPCCalPad*)array->At(ivalue))->GetName());
566
567 for (UInt_t isector = 0; isector < tpcROCinstance->GetNSectors(); isector++) {
568 //
569 // get statistic for given sector
570 //
571 TVectorF median(arrayEntries);
572 TVectorF mean(arrayEntries);
573 TVectorF rms(arrayEntries);
574 TVectorF ltm(arrayEntries);
575 TVectorF ltmrms(arrayEntries);
576 TVectorF medianWithOut(arrayEntries);
577 TVectorF meanWithOut(arrayEntries);
578 TVectorF rmsWithOut(arrayEntries);
579 TVectorF ltmWithOut(arrayEntries);
580 TVectorF ltmrmsWithOut(arrayEntries);
581
582 TVectorF *vectorArray = new TVectorF[arrayEntries];
583 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
584 vectorArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
585
586 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
587 AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue);
588 AliTPCCalROC* calROC = calPad->GetCalROC(isector);
589 AliTPCCalROC* outlierROC = 0;
590 if (outlierPad) outlierROC = outlierPad->GetCalROC(isector);
591 if (calROC) {
592 median[ivalue] = calROC->GetMedian();
593 mean[ivalue] = calROC->GetMean();
594 rms[ivalue] = calROC->GetRMS();
595 Double_t ltmrmsValue = 0;
596 ltm[ivalue] = calROC->GetLTM(&ltmrmsValue, ltmFraction);
597 ltmrms[ivalue] = ltmrmsValue;
598 if (outlierROC) {
599 medianWithOut[ivalue] = calROC->GetMedian(outlierROC);
600 meanWithOut[ivalue] = calROC->GetMean(outlierROC);
601 rmsWithOut[ivalue] = calROC->GetRMS(outlierROC);
602 ltmrmsValue = 0;
603 ltmWithOut[ivalue] = calROC->GetLTM(&ltmrmsValue, ltmFraction, outlierROC);
604 ltmrmsWithOut[ivalue] = ltmrmsValue;
605 }
606 }
607 else {
608 median[ivalue] = 0.;
609 mean[ivalue] = 0.;
610 rms[ivalue] = 0.;
611 ltm[ivalue] = 0.;
612 ltmrms[ivalue] = 0.;
613 medianWithOut[ivalue] = 0.;
614 meanWithOut[ivalue] = 0.;
615 rmsWithOut[ivalue] = 0.;
616 ltmWithOut[ivalue] = 0.;
617 ltmrmsWithOut[ivalue] = 0.;
618 }
619 }
620
621 //
622 // fill vectors of variable per pad
623 //
624 TVectorF *posArray = new TVectorF[8];
625 for (Int_t ivalue = 0; ivalue < 8; ivalue++)
626 posArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
627
628 Float_t posG[3] = {0};
629 Float_t posL[3] = {0};
630 Int_t ichannel = 0;
631 for (UInt_t irow = 0; irow < tpcROCinstance->GetNRows(isector); irow++) {
632 for (UInt_t ipad = 0; ipad < tpcROCinstance->GetNPads(isector, irow); ipad++) {
633 tpcROCinstance->GetPositionLocal(isector, irow, ipad, posL);
634 tpcROCinstance->GetPositionGlobal(isector, irow, ipad, posG);
635 posArray[0][ichannel] = irow;
636 posArray[1][ichannel] = ipad;
637 posArray[2][ichannel] = posL[0];
638 posArray[3][ichannel] = posL[1];
639 posArray[4][ichannel] = posG[0];
640 posArray[5][ichannel] = posG[1];
641 posArray[6][ichannel] = (Int_t)(ipad - (Double_t)(tpcROCinstance->GetNPads(isector, irow))/2);
642 posArray[7][ichannel] = ichannel;
643
644 // loop over array containing AliTPCCalPads
645 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
646 AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue);
647 AliTPCCalROC* calROC = calPad->GetCalROC(isector);
648 if (calROC)
649 (vectorArray[ivalue])[ichannel] = calROC->GetValue(irow, ipad);
650 else
651 (vectorArray[ivalue])[ichannel] = 0;
652 }
653 ichannel++;
654 }
655 }
656
657 cstream << "calPads" <<
658 "sector=" << isector;
659
660 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
661 cstream << "calPads" <<
662 (Char_t*)((names[ivalue] + "_Median=").Data()) << median[ivalue] <<
663 (Char_t*)((names[ivalue] + "_Mean=").Data()) << mean[ivalue] <<
664 (Char_t*)((names[ivalue] + "_RMS=").Data()) << rms[ivalue] <<
665 (Char_t*)((names[ivalue] + "_LTM=").Data()) << ltm[ivalue] <<
666 (Char_t*)((names[ivalue] + "_RMS_LTM=").Data()) << ltmrms[ivalue];
667 if (outlierPad) {
668 cstream << "calPads" <<
669 (Char_t*)((names[ivalue] + "_Median_OutlierCutted=").Data()) << medianWithOut[ivalue] <<
670 (Char_t*)((names[ivalue] + "_Mean_OutlierCutted=").Data()) << meanWithOut[ivalue] <<
671 (Char_t*)((names[ivalue] + "_RMS_OutlierCutted=").Data()) << rmsWithOut[ivalue] <<
672 (Char_t*)((names[ivalue] + "_LTM_OutlierCutted=").Data()) << ltmWithOut[ivalue] <<
673 (Char_t*)((names[ivalue] + "_RMS_LTM_OutlierCutted=").Data()) << ltmrmsWithOut[ivalue];
674 }
675 }
676
677 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
678 cstream << "calPads" <<
679 (Char_t*)((names[ivalue] + ".=").Data()) << &vectorArray[ivalue];
680 }
681
682 if (mapFileName) {
683 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
684 if (isector < 36)
685 cstream << "calPads" <<
686 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapIROCArray[ivalue];
687 else
688 cstream << "calPads" <<
689 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapOROCArray[ivalue];
690 }
691 }
692
693 cstream << "calPads" <<
694 "row.=" << &posArray[0] <<
695 "pad.=" << &posArray[1] <<
696 "lx.=" << &posArray[2] <<
697 "ly.=" << &posArray[3] <<
698 "gx.=" << &posArray[4] <<
699 "gy.=" << &posArray[5] <<
700 "rpad.=" << &posArray[6] <<
701 "channel.=" << &posArray[7];
702
703 cstream << "calPads" <<
704 "\n";
705
706 delete[] posArray;
707 delete[] vectorArray;
708 }
709
710
711 delete[] names;
712 if (mapFileName) {
713 delete mapIROCs;
714 delete mapOROCs;
715 delete[] mapIROCArray;
716 delete[] mapOROCArray;
717 delete[] mapNames;
718 }
719}
3ac615eb 720
721
722
723void AliTPCcalibDB::RegisterExB(Int_t index, Float_t bz, Bool_t bdelete){
724 //
725 // Register static ExB correction map
726 // index - registration index - used for visualization
727 // bz - bz field in kGaus
728
729 Float_t factor = bz/(-5.); // default b filed in Cheb with minus sign
730
f7a1cc68 731 AliMagF* bmap = new AliMagF("MapsExB","MapsExB", 2,factor,1., 10.,AliMagF::k5kG,"$(ALICE_ROOT)/data/maps/mfchebKGI_sym.root");
3ac615eb 732
733 AliTPCExBFirst *exb = new AliTPCExBFirst(bmap,0.88*2.6400e+04,50,50,50);
734 AliTPCExB::SetInstance(exb);
735
736 if (bdelete){
737 delete bmap;
738 }else{
739 AliTPCExB::RegisterField(index,bmap);
740 }
741 if (index>=fgExBArray.GetEntries()) fgExBArray.Expand((index+1)*2+11);
742 fgExBArray.AddAt(exb,index);
743}
744
745
746AliTPCExB* AliTPCcalibDB::GetExB(Float_t bz, Bool_t deleteB) {
747 //
748 // bz filed in KGaus not in tesla
749 // Get ExB correction map
750 // if doesn't exist - create it
751 //
752 Int_t index = TMath::Nint(5+bz);
753 if (index>fgExBArray.GetEntries()) fgExBArray.Expand((index+1)*2+11);
754 if (!fgExBArray.At(index)) AliTPCcalibDB::RegisterExB(index,bz,deleteB);
755 return (AliTPCExB*)fgExBArray.At(index);
756}
757
758
759void AliTPCcalibDB::SetExBField(Float_t bz){
760 //
761 // Set magnetic filed for ExB correction
762 //
763 fExB = GetExB(bz,kFALSE);
764}
bf85fe4d 765
766
767
5e1215d4 768
769
770void AliTPCcalibDB::UpdateRunInformations( Int_t run, Bool_t force){
bf85fe4d 771 //
772 // - > Don't use it for reconstruction - Only for Calibration studies
773 //
774 AliCDBEntry * entry = 0;
775 if (run>= fRunList.GetSize()){
776 fRunList.Set(run*2+1);
da6c0bc9 777 fGRPArray.Expand(run*2+1);
0231c65f 778 fGRPMaps.Expand(run*2+1);
e2914767 779 fGoofieArray.Expand(run*2+1);
780 fVoltageArray.Expand(run*2+1);
da6c0bc9 781 fTemperatureArray.Expand(run*2+1);
782 fVdriftArray.Expand(run*2+1);
5e1215d4 783 fDriftCorrectionArray.Expand(run*2+1);
a2c3785e 784 fTimeGainSplinesArray.Expand(run*2+1);
bf85fe4d 785 }
5e1215d4 786 if (fRunList[run]>0 &&force==kFALSE) return;
787 //
bf85fe4d 788 entry = AliCDBManager::Instance()->Get("GRP/GRP/Data",run);
0231c65f 789 if (entry) {
790 AliGRPObject * grpRun = dynamic_cast<AliGRPObject*>(entry->GetObject());
791 if (!grpRun){
792 TMap* map = dynamic_cast<TMap*>(entry->GetObject());
793 if (map){
e2914767 794 //grpRun = new AliGRPObject;
795 //grpRun->ReadValuesFromMap(map);
796 grpRun = MakeGRPObjectFromMap(map);
797
0231c65f 798 fGRPMaps.AddAt(map,run);
799 }
800 }
801 fGRPArray.AddAt(grpRun,run);
802 }
bf85fe4d 803 entry = AliCDBManager::Instance()->Get("TPC/Calib/Goofie",run);
5e1215d4 804 if (entry){
805 fGoofieArray.AddAt(entry->GetObject(),run);
806 }
e2914767 807 //
808 entry = AliCDBManager::Instance()->Get("TPC/Calib/HighVoltage",run);
5e1215d4 809 if (entry) {
810 fVoltageArray.AddAt(entry->GetObject(),run);
811 }
e2914767 812 //
a2c3785e 813 entry = AliCDBManager::Instance()->Get("TPC/Calib/TimeGain",run);
5e1215d4 814 if (entry) {
815 fTimeGainSplinesArray.AddAt(entry->GetObject(),run);
816 }
817 //
818 entry = AliCDBManager::Instance()->Get("TPC/Calib/TimeDrift",run);
819 if (entry) {
820 fDriftCorrectionArray.AddAt(entry->GetObject(),run);
821 }
a2c3785e 822 //
bf85fe4d 823 entry = AliCDBManager::Instance()->Get("TPC/Calib/Temperature",run);
5e1215d4 824 if (entry) {
825 fTemperatureArray.AddAt(entry->GetObject(),run);
826 }
bf85fe4d 827 fRunList[run]=1; // sign as used
da6c0bc9 828
bfec3eeb 829 AliDCSSensor * press = GetPressureSensor(run,0);
da6c0bc9 830 AliTPCSensorTempArray * temp = GetTemperatureSensor(run);
831 if (press && temp){
832 AliTPCCalibVdrift * vdrift = new AliTPCCalibVdrift(temp, press,0);
833 fVdriftArray.AddAt(vdrift,run);
834 }
bf85fe4d 835}
836
837
838Float_t AliTPCcalibDB::GetGain(Int_t sector, Int_t row, Int_t pad){
839 //
840 //
841 AliTPCCalPad *calPad = Instance()->fDedxGainFactor;;
842 if (!calPad) return 0;
843 return calPad->GetCalROC(sector)->GetValue(row,pad);
844}
845
8de77f00 846
847AliGRPObject *AliTPCcalibDB::GetGRP(Int_t run){
848 //
849 // Get GRP object for given run
850 //
851 AliGRPObject * grpRun = dynamic_cast<AliGRPObject *>((Instance()->fGRPArray).At(run));
852 if (!grpRun) {
5e1215d4 853 Instance()->UpdateRunInformations(run);
8de77f00 854 grpRun = dynamic_cast<AliGRPObject *>(Instance()->fGRPArray.At(run));
855 if (!grpRun) return 0;
856 }
857 return grpRun;
858}
859
0231c65f 860TMap * AliTPCcalibDB::GetGRPMap(Int_t run){
861 //
862 //
863 //
864 TMap * grpRun = dynamic_cast<TMap *>((Instance()->fGRPMaps).At(run));
865 if (!grpRun) {
5e1215d4 866 Instance()->UpdateRunInformations(run);
0231c65f 867 grpRun = dynamic_cast<TMap *>(Instance()->fGRPMaps.At(run));
868 if (!grpRun) return 0;
869 }
870 return grpRun;
871}
8de77f00 872
873
da6c0bc9 874AliDCSSensor * AliTPCcalibDB::GetPressureSensor(Int_t run, Int_t type){
bf85fe4d 875 //
0231c65f 876 // Get Pressure sensor
bfec3eeb 877 // run = run number
878 // type = 0 - Cavern pressure
879 // 1 - Suface pressure
0231c65f 880 // First try to get if trom map - if existing (Old format of data storing)
bf85fe4d 881 //
bfec3eeb 882
883
0231c65f 884 TMap *map = GetGRPMap(run);
885 if (map){
886 AliDCSSensor * sensor = 0;
887 TObject *osensor=0;
888 if (type==0) osensor = ((*map)("fCavernPressure"));
889 if (type==1) osensor = ((*map)("fP2Pressure"));
890 sensor =dynamic_cast<AliDCSSensor *>(osensor);
891 if (sensor) return sensor;
892 }
893 //
894 // If not map try to get it from the GRPObject
895 //
896 AliGRPObject * grpRun = dynamic_cast<AliGRPObject *>(fGRPArray.At(run));
bf85fe4d 897 if (!grpRun) {
5e1215d4 898 UpdateRunInformations(run);
efdbb95a 899 grpRun = dynamic_cast<AliGRPObject *>(fGRPArray.At(run));
bf85fe4d 900 if (!grpRun) return 0;
901 }
902 AliDCSSensor * sensor = grpRun->GetCavernAtmosPressure();
da6c0bc9 903 if (type==1) sensor = grpRun->GetSurfaceAtmosPressure();
904 return sensor;
bf85fe4d 905}
906
907AliTPCSensorTempArray * AliTPCcalibDB::GetTemperatureSensor(Int_t run){
908 //
909 // Get temperature sensor array
910 //
911 AliTPCSensorTempArray * tempArray = (AliTPCSensorTempArray *)fTemperatureArray.At(run);
912 if (!tempArray) {
5e1215d4 913 UpdateRunInformations(run);
bf85fe4d 914 tempArray = (AliTPCSensorTempArray *)fTemperatureArray.At(run);
915 }
916 return tempArray;
917}
918
a2c3785e 919
920TObjArray * AliTPCcalibDB::GetTimeGainSplinesRun(Int_t run){
bf85fe4d 921 //
922 // Get temperature sensor array
923 //
a2c3785e 924 TObjArray * gainSplines = (TObjArray *)fTimeGainSplinesArray.At(run);
925 if (!gainSplines) {
5e1215d4 926 UpdateRunInformations(run);
a2c3785e 927 gainSplines = (TObjArray *)fTimeGainSplinesArray.At(run);
bf85fe4d 928 }
a2c3785e 929 return gainSplines;
bf85fe4d 930}
931
e2914767 932AliDCSSensorArray * AliTPCcalibDB::GetVoltageSensors(Int_t run){
933 //
934 // Get temperature sensor array
935 //
936 AliDCSSensorArray * voltageArray = (AliDCSSensorArray *)fVoltageArray.At(run);
937 if (!voltageArray) {
5e1215d4 938 UpdateRunInformations(run);
e2914767 939 voltageArray = (AliDCSSensorArray *)fVoltageArray.At(run);
940 }
941 return voltageArray;
942}
943
99895a4f 944AliDCSSensorArray * AliTPCcalibDB::GetGoofieSensors(Int_t run){
945 //
946 // Get temperature sensor array
947 //
948 AliDCSSensorArray * goofieArray = (AliDCSSensorArray *)fGoofieArray.At(run);
949 if (!goofieArray) {
5e1215d4 950 UpdateRunInformations(run);
99895a4f 951 goofieArray = (AliDCSSensorArray *)fGoofieArray.At(run);
952 }
953 return goofieArray;
954}
955
956
957
da6c0bc9 958AliTPCCalibVdrift * AliTPCcalibDB::GetVdrift(Int_t run){
959 //
960 // Get the interface to the the vdrift
961 //
962 AliTPCCalibVdrift * vdrift = (AliTPCCalibVdrift*)fVdriftArray.At(run);
963 if (!vdrift) {
5e1215d4 964 UpdateRunInformations(run);
da6c0bc9 965 vdrift= (AliTPCCalibVdrift*)fVdriftArray.At(run);
966 }
967 return vdrift;
968}
969
7fff7612 970Float_t AliTPCcalibDB::GetDCSSensorValue(AliDCSSensorArray *arr, Int_t timeStamp, const char * sensorName, Int_t sigDigits)
971{
972 //
973 // Get Value for a DCS sensor 'sensorName', run 'run' at time 'timeStamp'
974 //
975 Float_t val=0;
976 const TString sensorNameString(sensorName);
977 AliDCSSensor *sensor = arr->GetSensor(sensorNameString);
978 if (!sensor) return val;
979 val=sensor->GetValue(timeStamp);
980 if (sigDigits>=0){
981 val=(Float_t)TMath::Floor(val * TMath::Power(10., sigDigits) + .5) / TMath::Power(10., sigDigits);
982 }
983 return val;
984}
985
986Float_t AliTPCcalibDB::GetDCSSensorMeanValue(AliDCSSensorArray *arr, const char * sensorName, Int_t sigDigits)
987{
988 //
989 // Get mean Value for a DCS sensor 'sensorName' during run 'run'
990 //
991 Float_t val=0;
992 const TString sensorNameString(sensorName);
993 AliDCSSensor *sensor = arr->GetSensor(sensorNameString);
994 if (!sensor) return val;
995
996 //current hack until the spline fit problem is solved
997 if (!sensor->GetFit()) return val;
998 Int_t nKnots=sensor->GetFit()->GetKnots();
999 Double_t tMid=(sensor->GetEndTime()-sensor->GetStartTime())/2.;
1000 for (Int_t iKnot=0;iKnot<nKnots;++iKnot){
1001 if (sensor->GetFit()->GetX()[iKnot]>tMid/3600.) break;
1002 val=(Float_t)sensor->GetFit()->GetY0()[iKnot];
1003 }
1004/*
1005 TGraph *gr=sensor->MakeGraph();
1006 if (gr) val=(Float_t)gr->GetMean(2);
1007 delete gr;
1008 */
1009 if (sigDigits>=0){
1010 val/=10;
1011 val=(Float_t)TMath::Floor(val * TMath::Power(10., sigDigits) + .5) / TMath::Power(10., sigDigits);
1012 val*=10;
1013 }
1014 return val;
1015}
bf85fe4d 1016
7fff7612 1017Float_t AliTPCcalibDB::GetChamberHighVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits) {
e2914767 1018 //
1019 // return the chamber HV for given run and time: 0-35 IROC, 36-72 OROC
7fff7612 1020 // if timeStamp==-1 return mean value
1021 //
1022 Float_t val=0;
1023 TString sensorName="";
1024 TTimeStamp stamp(timeStamp);
1025 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1026 if (!voltageArray || (sector<0) || (sector>71)) return val;
1027 Char_t sideName='A';
1028 if ((sector/18)%2==1) sideName='C';
1029 if (sector<36){
1030 //IROC
1031 sensorName=Form("TPC_ANODE_I_%c%02d_VMEAS",sideName,sector%18);
1032 }else{
1033 //OROC
1034 sensorName=Form("TPC_ANODE_O_%c%02d_0_VMEAS",sideName,sector%18);
1035 }
1036 if (timeStamp==-1){
1037 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1038 } else {
1039 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1040 }
1041 return val;
1042}
1043Float_t AliTPCcalibDB::GetSkirtVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1044{
1045 //
1046 // Get the skirt voltage for 'run' at 'timeStamp' and 'sector': 0-35 IROC, 36-72 OROC
1047 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1048 // if timeStamp==-1 return the mean value for the run
1049 //
1050 Float_t val=0;
1051 TString sensorName="";
1052 TTimeStamp stamp(timeStamp);
1053 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1054 if (!voltageArray || (sector<0) || (sector>71)) return val;
1055 Char_t sideName='A';
1056 if ((sector/18)%2==1) sideName='C';
1057 sensorName=Form("TPC_SKIRT_%c_VMEAS",sideName);
1058 if (timeStamp==-1){
1059 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1060 } else {
1061 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1062 }
1063 return val;
1064}
1065
1066Float_t AliTPCcalibDB::GetCoverVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1067{
1068 //
1069 // Get the cover voltage for run 'run' at time 'timeStamp'
1070 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1071 // if timeStamp==-1 return the mean value for the run
e2914767 1072 //
7fff7612 1073 Float_t val=0;
1074 TString sensorName="";
e2914767 1075 TTimeStamp stamp(timeStamp);
1076 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
7fff7612 1077 if (!voltageArray || (sector<0) || (sector>71)) return val;
1078 Char_t sideName='A';
1079 if ((sector/18)%2==1) sideName='C';
1080 if (sector<36){
1081 //IROC
1082 sensorName=Form("TPC_COVER_I_%c_VMEAS",sideName);
1083 }else{
1084 //OROC
1085 sensorName=Form("TPC_COVER_O_%c_VMEAS",sideName);
1086 }
1087 if (timeStamp==-1){
1088 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1089 } else {
1090 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1091 }
1092 return val;
1093}
1094
1095Float_t AliTPCcalibDB::GetGGoffsetVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1096{
1097 //
1098 // Get the GG offset voltage for run 'run' at time 'timeStamp'
1099 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1100 // if timeStamp==-1 return the mean value for the run
1101 //
1102 Float_t val=0;
1103 TString sensorName="";
1104 TTimeStamp stamp(timeStamp);
1105 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1106 if (!voltageArray || (sector<0) || (sector>71)) return val;
1107 Char_t sideName='A';
1108 if ((sector/18)%2==1) sideName='C';
1109 if (sector<36){
1110 //IROC
1111 sensorName=Form("TPC_GATE_I_%c_OFF_VMEAS",sideName);
1112 }else{
1113 //OROC
1114 sensorName=Form("TPC_GATE_O_%c_OFF_VMEAS",sideName);
1115 }
1116 if (timeStamp==-1){
1117 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1118 } else {
1119 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1120 }
1121 return val;
1122}
1123
1124Float_t AliTPCcalibDB::GetGGnegVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1125{
1126 //
1127 // Get the GG offset voltage for run 'run' at time 'timeStamp'
1128 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1129 // if timeStamp==-1 return the mean value for the run
1130 //
1131 Float_t val=0;
1132 TString sensorName="";
1133 TTimeStamp stamp(timeStamp);
1134 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1135 if (!voltageArray || (sector<0) || (sector>71)) return val;
1136 Char_t sideName='A';
1137 if ((sector/18)%2==1) sideName='C';
1138 if (sector<36){
1139 //IROC
1140 sensorName=Form("TPC_GATE_I_%c_NEG_VMEAS",sideName);
1141 }else{
1142 //OROC
1143 sensorName=Form("TPC_GATE_O_%c_NEG_VMEAS",sideName);
1144 }
1145 if (timeStamp==-1){
1146 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1147 } else {
1148 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1149 }
1150 return val;
1151}
1152
1153Float_t AliTPCcalibDB::GetGGposVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1154{
1155 //
1156 // Get the GG offset voltage for run 'run' at time 'timeStamp'
1157 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1158 // if timeStamp==-1 return the mean value for the run
1159 //
1160 Float_t val=0;
1161 TString sensorName="";
1162 TTimeStamp stamp(timeStamp);
1163 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1164 if (!voltageArray || (sector<0) || (sector>71)) return val;
1165 Char_t sideName='A';
1166 if ((sector/18)%2==1) sideName='C';
1167 if (sector<36){
1168 //IROC
1169 sensorName=Form("TPC_GATE_I_%c_POS_VMEAS",sideName);
1170 }else{
1171 //OROC
1172 sensorName=Form("TPC_GATE_O_%c_POS_VMEAS",sideName);
1173 }
1174 if (timeStamp==-1){
1175 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1176 } else {
1177 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1178 }
1179 return val;
e2914767 1180}
bf85fe4d 1181
da6c0bc9 1182Float_t AliTPCcalibDB::GetPressure(Int_t timeStamp, Int_t run, Int_t type){
bf85fe4d 1183 //
1184 // GetPressure for given time stamp and runt
1185 //
1186 TTimeStamp stamp(timeStamp);
da6c0bc9 1187 AliDCSSensor * sensor = Instance()->GetPressureSensor(run,type);
bf85fe4d 1188 if (!sensor) return 0;
bf85fe4d 1189 return sensor->GetValue(stamp);
1190}
1191
5312f439 1192Float_t AliTPCcalibDB::GetL3Current(Int_t run, Int_t statType){
1193 //
1194 // return L3 current
1195 // stat type is: AliGRPObject::Stats: kMean = 0, kTruncMean = 1, kMedian = 2, kSDMean = 3, kSDMedian = 4
1196 //
1197 Float_t current=-1;
1198 AliGRPObject *grp=AliTPCcalibDB::GetGRP(run);
1199 if (grp) current=grp->GetL3Current((AliGRPObject::Stats)statType);
1200 return current;
1201}
1202
1203Float_t AliTPCcalibDB::GetBz(Int_t run){
1204 //
e6970ab5 1205 // calculate BZ in T from L3 current
5312f439 1206 //
1207 Float_t bz=-1;
1208 Float_t current=AliTPCcalibDB::GetL3Current(run);
e6970ab5 1209 if (current>-1) bz=5*current/30000.*.1;
5312f439 1210 return bz;
1211}
1212
1213Char_t AliTPCcalibDB::GetL3Polarity(Int_t run) {
1214 //
1215 // get l3 polarity from GRP
1216 //
1217 return AliTPCcalibDB::GetGRP(run)->GetL3Polarity();
1218}
1219
1220TString AliTPCcalibDB::GetRunType(Int_t run){
1221 //
1222 // return run type from grp
1223 //
1224 return AliTPCcalibDB::GetGRP(run)->GetRunType();
1225}
1226
7f7847fe 1227Float_t AliTPCcalibDB::GetValueGoofie(Int_t timeStamp, Int_t run, Int_t type){
1228 //
1229 // GetPressure for given time stamp and runt
1230 //
1231 TTimeStamp stamp(timeStamp);
1232 AliDCSSensorArray* goofieArray = AliTPCcalibDB::Instance()->GetGoofieSensors(run);
1233 if (!goofieArray) return 0;
1234 AliDCSSensor *sensor = goofieArray->GetSensor(type);
1235 return sensor->GetValue(stamp);
1236}
1237
1238
1239
1240
1241
1242
f0269955 1243Bool_t AliTPCcalibDB::GetTemperatureFit(Int_t timeStamp, Int_t run, Int_t side,TVectorD& fit){
1244 //
1245 //
1246 //
1247 TTimeStamp tstamp(timeStamp);
64b48395 1248 AliTPCSensorTempArray* tempArray = Instance()->GetTemperatureSensor(run);
f0269955 1249 if (! tempArray) return kFALSE;
1250 AliTPCTempMap * tempMap = new AliTPCTempMap(tempArray);
1251 TLinearFitter * fitter = tempMap->GetLinearFitter(3,side,tstamp);
1252 if (fitter){
1253 fitter->Eval();
1254 fitter->GetParameters(fit);
1255 }
1256 delete fitter;
1257 delete tempMap;
1258 if (!fitter) return kFALSE;
1259 return kTRUE;
1260}
1261
64b48395 1262Float_t AliTPCcalibDB::GetTemperature(Int_t timeStamp, Int_t run, Int_t side){
1263 //
1264 //
1265 //
12e42756 1266 TVectorD vec(5);
64b48395 1267 if (side==0) {
1268 GetTemperatureFit(timeStamp,run,0,vec);
1269 return vec[0];
1270 }
1271 if (side==1){
1272 GetTemperatureFit(timeStamp,run,0,vec);
1273 return vec[0];
1274 }
57dc06f2 1275 return 0;
64b48395 1276}
bf85fe4d 1277
1278
da6c0bc9 1279Double_t AliTPCcalibDB::GetPTRelative(UInt_t timeSec, Int_t run, Int_t side){
1280 //
1281 // Get relative P/T
1282 // time - absolute time
1283 // run - run number
1284 // side - 0 - A side 1-C side
1285 AliTPCCalibVdrift * vdrift = Instance()->GetVdrift(run);
1286 if (!vdrift) return 0;
1287 return vdrift->GetPTRelative(timeSec,side);
1288}
1289
bf85fe4d 1290
1291void AliTPCcalibDB::ProcessEnv(const char * runList){
1292 //
1293 // Example test function - how to use the environment variables
1294 // runList - ascii file with run numbers
1295 // output - dcsTime.root file with tree
1296
1297 ifstream in;
1298 in.open(runList);
1299 Int_t irun=0;
1300 TTreeSRedirector *pcstream = new TTreeSRedirector("dcsTime.root");
1301 while(in.good()) {
1302 in >> irun;
1303 if (irun==0) continue;
1304 printf("Processing run %d\n",irun);
1305 AliDCSSensor * sensorPressure = AliTPCcalibDB::Instance()->GetPressureSensor(irun);
1306 if (!sensorPressure) continue;
1307 AliTPCSensorTempArray * tempArray = AliTPCcalibDB::Instance()->GetTemperatureSensor(irun);
1308 AliTPCTempMap * tempMap = new AliTPCTempMap(tempArray);
1309 AliDCSSensorArray* goofieArray = AliTPCcalibDB::Instance()->GetGoofieSensors(irun);
1310 //
1311 Int_t startTime = sensorPressure->GetStartTime();
1312 Int_t endTime = sensorPressure->GetEndTime();
1313 Int_t dtime = TMath::Max((endTime-startTime)/20,10*60);
1314 for (Int_t itime=startTime; itime<endTime; itime+=dtime){
1315 //
1316 TTimeStamp tstamp(itime);
1317 Float_t valuePressure = sensorPressure->GetValue(tstamp);
1318
1319 TLinearFitter * fitter = 0;
1320 TVectorD vecTemp[10];
1321 if (itime<tempArray->GetStartTime().GetSec() || itime>tempArray->GetEndTime().GetSec()){
1322 }else{
1323 for (Int_t itype=0; itype<5; itype++)
1324 for (Int_t iside=0; iside<2; iside++){
1325 fitter= tempMap->GetLinearFitter(itype,iside,tstamp);
1326 if (!fitter) continue;
1327 fitter->Eval(); fitter->GetParameters(vecTemp[itype+iside*5]);
1328 delete fitter;
1329 }
1330 }
1331
1332 TVectorD vecGoofie, vecEntries, vecMean, vecMedian,vecRMS;
1333 if (goofieArray){
1334 vecGoofie.ResizeTo(goofieArray->NumSensors());
1335 ProcessGoofie(goofieArray, vecEntries ,vecMedian, vecMean, vecRMS);
1336 //
1337 for (Int_t isensor=0; isensor<goofieArray->NumSensors();isensor++){
1338 AliDCSSensor *gsensor = goofieArray->GetSensor(isensor);
1339 if (gsensor){
1340 vecGoofie[isensor] = gsensor->GetValue(tstamp);
1341 }
1342 }
1343 }
1344
1345
1346 //tempMap->GetLinearFitter(0,0,itime);
1347 (*pcstream)<<"dcs"<<
1348 "run="<<irun<<
1349 "time="<<itime<<
1350 "goofie.="<<&vecGoofie<<
1351 "goofieE.="<<&vecEntries<<
1352 "goofieMean.="<<&vecMean<<
1353 "goofieMedian.="<<&vecMedian<<
1354 "goofieRMS.="<<&vecRMS<<
1355 "press="<<valuePressure<<
1356 "temp00.="<<&vecTemp[0]<<
1357 "temp10.="<<&vecTemp[1]<<
1358 "temp20.="<<&vecTemp[2]<<
1359 "temp30.="<<&vecTemp[3]<<
1360 "temp40.="<<&vecTemp[4]<<
1361 "temp01.="<<&vecTemp[5]<<
1362 "temp11.="<<&vecTemp[6]<<
1363 "temp21.="<<&vecTemp[7]<<
1364 "temp31.="<<&vecTemp[8]<<
1365 "temp41.="<<&vecTemp[9]<<
1366 "\n";
1367 }
1368 }
1369 delete pcstream;
1370}
1371
1372
1373void AliTPCcalibDB::ProcessGoofie( AliDCSSensorArray* goofieArray, TVectorD & vecEntries, TVectorD & vecMedian, TVectorD &vecMean, TVectorD &vecRMS){
1374 /*
1375
1376 1 TPC_ANODE_I_A00_STAT
1377 2 TPC_DVM_CO2
1378 3 TPC_DVM_DriftVelocity
1379 4 TPC_DVM_FCageHV
1380 5 TPC_DVM_GainFar
1381 6 TPC_DVM_GainNear
1382 7 TPC_DVM_N2
1383 8 TPC_DVM_NumberOfSparks
1384 9 TPC_DVM_PeakAreaFar
1385 10 TPC_DVM_PeakAreaNear
1386 11 TPC_DVM_PeakPosFar
1387 12 TPC_DVM_PeakPosNear
1388 13 TPC_DVM_PickupHV
1389 14 TPC_DVM_Pressure
1390 15 TPC_DVM_T1_Over_P
1391 16 TPC_DVM_T2_Over_P
1392 17 TPC_DVM_T_Over_P
1393 18 TPC_DVM_TemperatureS1
1394 */
1395 //
1396 //
1397 // TVectorD vecMedian; TVectorD vecEntries; TVectorD vecMean; TVectorD vecRMS;
1398 Double_t kEpsilon=0.0000000001;
1399 Double_t kBig=100000000000.;
1400 Int_t nsensors = goofieArray->NumSensors();
1401 vecEntries.ResizeTo(nsensors);
1402 vecMedian.ResizeTo(nsensors);
1403 vecMean.ResizeTo(nsensors);
1404 vecRMS.ResizeTo(nsensors);
1405 TVectorF values;
1406 for (Int_t isensor=0; isensor<goofieArray->NumSensors();isensor++){
1407 AliDCSSensor *gsensor = goofieArray->GetSensor(isensor);
1408 if (gsensor && gsensor->GetGraph()){
1409 Int_t npoints = gsensor->GetGraph()->GetN();
1410 // filter zeroes
1411 values.ResizeTo(npoints);
1412 Int_t nused =0;
1413 for (Int_t ipoint=0; ipoint<npoints; ipoint++){
1414 if (TMath::Abs(gsensor->GetGraph()->GetY()[ipoint])>kEpsilon &&
1415 TMath::Abs(gsensor->GetGraph()->GetY()[ipoint])<kBig ){
1416 values[nused]=gsensor->GetGraph()->GetY()[ipoint];
1417 nused++;
1418 }
1419 }
1420 //
1421 vecEntries[isensor]= nused;
1422 if (nused>1){
1423 vecMedian[isensor] = TMath::Median(nused,values.GetMatrixArray());
1424 vecMean[isensor] = TMath::Mean(nused,values.GetMatrixArray());
1425 vecRMS[isensor] = TMath::RMS(nused,values.GetMatrixArray());
1426 }
1427 }
1428 }
1429}
1430
e2914767 1431
1432
1433AliGRPObject * AliTPCcalibDB::MakeGRPObjectFromMap(TMap *map){
1434 //
1435 // Function to covert old GRP run information from TMap to GRPObject
1436 //
1437 // TMap * map = AliTPCcalibDB::GetGRPMap(52406);
1438 if (!map) return 0;
1439 AliDCSSensor * sensor = 0;
1440 TObject *osensor=0;
1441 osensor = ((*map)("fP2Pressure"));
1442 sensor =dynamic_cast<AliDCSSensor *>(osensor);
1443 //
1444 if (!sensor) return 0;
1445 //
1446 AliDCSSensor * sensor2 = new AliDCSSensor(*sensor);
1447 osensor = ((*map)("fCavernPressure"));
1448 TGraph * gr = new TGraph(2);
1449 gr->GetX()[0]= -100000.;
1450 gr->GetX()[1]= 1000000.;
1451 gr->GetY()[0]= atof(osensor->GetName());
1452 gr->GetY()[1]= atof(osensor->GetName());
1453 sensor2->SetGraph(gr);
1454 sensor2->SetFit(0);
1455
1456
1457 AliGRPObject *grpRun = new AliGRPObject;
1458 grpRun->ReadValuesFromMap(map);
1459 grpRun->SetCavernAtmosPressure(sensor2);
1460 grpRun->SetSurfaceAtmosPressure(sensor);
1461 return grpRun;
1462}
1463
5312f439 1464Bool_t AliTPCcalibDB::CreateGUITree(Int_t run, const char* filename)
1465{
1466 //
1467 // Create a gui tree for run number 'run'
1468 //
e2914767 1469
5312f439 1470 if (!AliCDBManager::Instance()->GetDefaultStorage()){
1471 AliLog::Message(AliLog::kError, "Default Storage not set. Cannot create Calibration Tree!",
1472 MODULENAME(), "AliTPCcalibDB", FUNCTIONNAME(), __FILE__, __LINE__);
1473 return kFALSE;
1474 }
1475 //db instance
1476 AliTPCcalibDB *db=AliTPCcalibDB::Instance();
1477 // retrieve cal pad objects
1478 db->SetRun(run);
1479 AliTPCPreprocessorOnline prep;
1480 //noise and pedestals
1481 prep.AddComponent(db->GetPedestals());
1482 prep.AddComponent(db->GetPadNoise());
1483 //pulser data
1484 prep.AddComponent(db->GetPulserTmean());
1485 prep.AddComponent(db->GetPulserTrms());
1486 prep.AddComponent(db->GetPulserQmean());
1487 //CE data
1488 prep.AddComponent(db->GetCETmean());
1489 prep.AddComponent(db->GetCETrms());
1490 prep.AddComponent(db->GetCEQmean());
1491 //Altro data
1492 prep.AddComponent(db->GetALTROAcqStart() );
1493 prep.AddComponent(db->GetALTROZsThr() );
1494 prep.AddComponent(db->GetALTROFPED() );
1495 prep.AddComponent(db->GetALTROAcqStop() );
1496 prep.AddComponent(db->GetALTROMasked() );
1497 //
1498 TString file(filename);
1499 if (file.IsNull()) file=Form("guiTreeRun_%d.root",run);
1500 prep.DumpToFile(file.Data());
1501 return kTRUE;
1502}
e2914767 1503