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