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