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