Reconstructor to fill new ESD, Digitizer reading new OCDBs and macros to crate them
[u/mrichter/AliRoot.git] / AD / ADbase / AliADCalibData.cxx
CommitLineData
5e319bd5 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/* $Id: AliADCalibData.cxx, */
17
aa8120bb 18#include <TMath.h>
19#include <TObjString.h>
20#include <TMap.h>
21#include <TH1F.h>
22#include <TH2F.h>
5e319bd5 23
4188a021 24#include "AliDCSValue.h"
aa8120bb 25#include "AliCDBManager.h"
26#include "AliCDBEntry.h"
4188a021 27#include "AliADDataDCS.h"
5e319bd5 28#include "AliADCalibData.h"
aa8120bb 29#include "AliADConst.h"
30#include "AliLog.h"
5e319bd5 31
32ClassImp(AliADCalibData)
33
34
35//________________________________________________________________
aa8120bb 36AliADCalibData::AliADCalibData():
37 fLightYields(NULL),
38 fPMGainsA(NULL),
b405b003 39 fPMGainsB(NULL),
40 fBBAThreshold(0),
41 fBBCThreshold(0) ,
42 fBGAThreshold(0) ,
43 fBGCThreshold(0) ,
44 fBBAForBGThreshold(0) ,
45 fBBCForBGThreshold(0) ,
2cbbb1d5 46 fMultADAThrLow(0) ,
47 fMultADAThrHigh(0) ,
48 fMultADCThrLow(0) ,
49 fMultADCThrHigh(0)
5e319bd5 50{
aa8120bb 51 // default constructor
52
53 for(int t=0; t<16; t++) {
beca6103 54 fMeanHV[t] = 1600.0;
aa8120bb 55 fWidthHV[t] = 0.0;
69e96215 56 fTimeOffset[t] = 0.0;
aa8120bb 57 fTimeGain[t] = 1.0;
58 fDeadChannel[t]= kFALSE;
59 fDiscriThr[t] = 2.5;
60 }
61 for(int t=0; t<32; t++) {
beca6103 62 fPedestal[t] = 3.0;
63 fSigma[t] = 1.0;
aa8120bb 64 fADCmean[t] = 0.0;
65 fADCsigma[t] = 0.0;
66 }
67 for(int i=0; i<kNCIUBoards ;i++) {
68 fTimeResolution[i] = 25./256.; // Default time resolution
69 fWidthResolution[i] = 25./64.; // Default time width resolution
70 fMatchWindow[i] = 4;
71 fSearchWindow[i] = 16;
72 fTriggerCountOffset[i] = 3247;
73 fRollOver[i] = 3563;
74 }
b405b003 75 for(int i=0; i<kNCIUBoards ;i++) {
76 fClk1Win1[i] = fClk1Win2[i] = 0;
77 fDelayClk1Win1[i] = fDelayClk1Win2[i] = 0;
78 fClk2Win1[i] = fClk2Win2[i] = 0;
79 fDelayClk2Win1[i] = fDelayClk2Win2[i] = 0;
80 fLatchWin1[i] = fLatchWin2[i] = 0;
81 fResetWin1[i] = fResetWin2[i] = 0;
82 fPedestalSubtraction[i] = kFALSE;
83 }
84 for(Int_t j = 0; j < 16; ++j) {
85 fEnableCharge[j] = fEnableTiming[j] = kFALSE;
86 fPedestalOdd[j] = fPedestalEven[j] = 0;
87 fPedestalCutOdd[j] = fPedestalCutEven[j] = 0;
88 }
89 for(Int_t i = 0; i < 5; ++i) fTriggerSelected[i] = 0;
5e319bd5 90
aa8120bb 91}
5e319bd5 92//________________________________________________________________
93void AliADCalibData::Reset()
94{
95
96}
97
98//________________________________________________________________
99AliADCalibData::AliADCalibData(const char* name) :
aa8120bb 100 fLightYields(NULL),
101 fPMGainsA(NULL),
b405b003 102 fPMGainsB(NULL),
103 fBBAThreshold(0),
104 fBBCThreshold(0) ,
105 fBGAThreshold(0) ,
106 fBGCThreshold(0) ,
107 fBBAForBGThreshold(0) ,
108 fBBCForBGThreshold(0) ,
2cbbb1d5 109 fMultADAThrLow(0) ,
110 fMultADAThrHigh(0) ,
111 fMultADCThrLow(0) ,
112 fMultADCThrHigh(0)
5e319bd5 113{
aa8120bb 114 // Constructor
115 TString namst = "Calib_";
116 namst += name;
117 SetName(namst.Data());
118 SetTitle(namst.Data());
119 for(int t=0; t<16; t++) {
120 fMeanHV[t] = 100.0;
121 fWidthHV[t] = 0.0;
122 fTimeOffset[t] = 5.0;
123 fTimeGain[t] = 1.0;
124 fDeadChannel[t]= kFALSE;
125 fDiscriThr[t] = 2.5;
126 }
127 for(int t=0; t<32; t++) {
128 fPedestal[t] = 0.0;
129 fSigma[t] = 0.0;
130 fADCmean[t] = 0.0;
131 fADCsigma[t] = 0.0;
132 }
133 for(int i=0; i<kNCIUBoards ;i++) {
134 fTimeResolution[i] = 25./256.; // Default time resolution in ns / channel
135 fWidthResolution[i] = 25./64.; // Default time width resolution in ns / channel
136 fMatchWindow[i] = 4;
137 fSearchWindow[i] = 16;
138 fTriggerCountOffset[i] = 3247;
139 fRollOver[i] = 3563;
140 }
b405b003 141 for(int i=0; i<kNCIUBoards ;i++) {
142 fClk1Win1[i] = fClk1Win2[i] = 0;
143 fDelayClk1Win1[i] = fDelayClk1Win2[i] = 0;
144 fClk2Win1[i] = fClk2Win2[i] = 0;
145 fDelayClk2Win1[i] = fDelayClk2Win2[i] = 0;
146 fLatchWin1[i] = fLatchWin2[i] = 0;
147 fResetWin1[i] = fResetWin2[i] = 0;
148 fPedestalSubtraction[i] = kFALSE;
149 }
150 for(Int_t j = 0; j < 16; ++j) {
151 fEnableCharge[j] = fEnableTiming[j] = kFALSE;
152 fPedestalOdd[j] = fPedestalEven[j] = 0;
153 fPedestalCutOdd[j] = fPedestalCutEven[j] = 0;
154 }
155 for(Int_t i = 0; i < 5; ++i) fTriggerSelected[i] = 0;
5e319bd5 156}
157
158//________________________________________________________________
159AliADCalibData::AliADCalibData(const AliADCalibData& calibda) :
aa8120bb 160 TNamed(calibda),
161 fLightYields(NULL),
162 fPMGainsA(NULL),
163 fPMGainsB(NULL)
5e319bd5 164{
165// copy constructor
166
167 SetName(calibda.GetName());
168 SetTitle(calibda.GetName());
169
aa8120bb 170 for(int t=0; t<32; t++) {
171 fPedestal[t] = calibda.GetPedestal(t);
172 fSigma[t] = calibda.GetSigma(t);
173 fADCmean[t] = calibda.GetADCmean(t);
174 fADCsigma[t] = calibda.GetADCsigma(t); }
175
176 for(int t=0; t<16; t++) {
177 fMeanHV[t] = calibda.GetMeanHV(t);
178 fWidthHV[t] = calibda.GetWidthHV(t);
179 fTimeOffset[t] = calibda.GetTimeOffset(t);
180 fTimeGain[t] = calibda.GetTimeGain(t);
181 fDeadChannel[t] = calibda.IsChannelDead(t);
182 fDiscriThr[t] = calibda.GetDiscriThr(t);
183 }
184
185 for(int i=0; i<kNCIUBoards ;i++) {
186 fTimeResolution[i] = calibda.GetTimeResolution(i);
187 fWidthResolution[i] = calibda.GetWidthResolution(i);
188 fMatchWindow[i] = calibda.GetMatchWindow(i);
189 fSearchWindow[i] = calibda.GetSearchWindow(i);
190 fTriggerCountOffset[i] = calibda.GetTriggerCountOffset(i);
191 fRollOver[i] = calibda.GetRollOver(i);
5e319bd5 192 }
aa8120bb 193
5e319bd5 194}
5e319bd5 195
5e319bd5 196//________________________________________________________________
197AliADCalibData &AliADCalibData::operator =(const AliADCalibData& calibda)
198{
199// assignment operator
200
201 SetName(calibda.GetName());
202 SetTitle(calibda.GetName());
aa8120bb 203
204 for(int t=0; t<32; t++) {
205 fPedestal[t] = calibda.GetPedestal(t);
206 fSigma[t] = calibda.GetSigma(t);
207 fADCmean[t] = calibda.GetADCmean(t);
208 fADCsigma[t] = calibda.GetADCsigma(t); }
209
210 for(int t=0; t<16; t++) {
211 fMeanHV[t] = calibda.GetMeanHV(t);
212 fWidthHV[t] = calibda.GetWidthHV(t);
213 fTimeOffset[t] = calibda.GetTimeOffset(t);
214 fTimeGain[t] = calibda.GetTimeGain(t);
215 fDeadChannel[t] = calibda.IsChannelDead(t);
216 fDiscriThr[t] = calibda.GetDiscriThr(t);
217 }
218 for(int i=0; i<kNCIUBoards ;i++) {
219 fTimeResolution[i] = calibda.GetTimeResolution(i);
220 fWidthResolution[i] = calibda.GetWidthResolution(i);
221 fMatchWindow[i] = calibda.GetMatchWindow(i);
222 fSearchWindow[i] = calibda.GetSearchWindow(i);
223 fTriggerCountOffset[i] = calibda.GetTriggerCountOffset(i);
224 fRollOver[i] = calibda.GetRollOver(i);
5e319bd5 225 }
aa8120bb 226
5e319bd5 227 return *this;
aa8120bb 228
5e319bd5 229}
5e319bd5 230
aa8120bb 231//________________________________________________________________
232AliADCalibData::~AliADCalibData()
233{
234 // destructor
235 if (fLightYields)
236 delete [] fLightYields;
237 if (fPMGainsA)
238 delete [] fPMGainsA;
239 if (fPMGainsB)
240 delete [] fPMGainsB;
241}
5e319bd5 242
aa8120bb 243//________________________________________________________________
244Int_t AliADCalibData::GetBoardNumber(Int_t channel)
245{
246 // Get FEE board number
247 // from offline channel index
8484394b 248 if (channel >= 0 && channel < 8) return (0);
249 if (channel >=8 && channel < 16) return (1);
5e319bd5 250
aa8120bb 251 AliErrorClass(Form("Wrong channel index: %d",channel));
252 return -1;
5e319bd5 253}
5e319bd5 254
255//________________________________________________________________
aa8120bb 256Float_t AliADCalibData::GetLightYields(Int_t channel)
5e319bd5 257{
aa8120bb 258 // Get the light yield efficiency
259 // for a given channel
260 if (!fLightYields) InitLightYields();
261
8484394b 262 if (channel >= 0 && channel < 16) {
aa8120bb 263 return fLightYields[channel];
264 }
5e319bd5 265
aa8120bb 266 AliError(Form("Wrong channel index: %d",channel));
267 return 0;
268}
5e319bd5 269
270//________________________________________________________________
aa8120bb 271void AliADCalibData::InitLightYields()
5e319bd5 272{
aa8120bb 273 // Initialize the light yield factors
274 // Read from a separate OCDB entry
275 if (fLightYields) return;
276
68865a3d 277 AliCDBEntry *entry = AliCDBManager::Instance()->Get("AD/Calib/LightYields");
aa8120bb 278 if (!entry) AliFatal("AD light yields are not found in OCDB !");
279 TH1F *yields = (TH1F*)entry->GetObject();
280
281 fLightYields = new Float_t[16];
282 for(Int_t i = 0 ; i < 16; ++i) {
283 fLightYields[i] = yields->GetBinContent(i+1);
284 }
5e319bd5 285}
286
aa8120bb 287//________________________________________________________________
288void AliADCalibData::InitPMGains()
5e319bd5 289{
aa8120bb 290 // Initialize the PM gain factors
291 // Read from a separate OCDB entry
292 if (fPMGainsA) return;
293
68865a3d 294 AliCDBEntry *entry = AliCDBManager::Instance()->Get("AD/Calib/PMGains");
295 if (!entry) AliFatal("AD PM gains are not found in OCDB !");
aa8120bb 296 TH2F *gains = (TH2F*)entry->GetObject();
297
298 fPMGainsA = new Float_t[16];
299 fPMGainsB = new Float_t[16];
300 for(Int_t i = 0 ; i < 16; ++i) {
301 fPMGainsA[i] = gains->GetBinContent(i+1,1);
302 fPMGainsB[i] = gains->GetBinContent(i+1,2);
303 }
5e319bd5 304}
305
aa8120bb 306//________________________________________________________________
307Float_t AliADCalibData::GetGain(Int_t channel)
5e319bd5 308{
aa8120bb 309 // Computes the PM gains
310 // Argument passed is the PM number (aliroot numbering)
311 if (!fPMGainsA) InitPMGains();
312
313 // High Voltage retrieval from Calibration Data Base:
314 Float_t hv = fMeanHV[channel];
315 Float_t gain = 0;
316 if (hv>0)
317 gain = TMath::Exp(fPMGainsA[channel]+fPMGainsB[channel]*TMath::Log(hv));
318 return gain;
5e319bd5 319}
320
aa8120bb 321//________________________________________________________________
322Float_t AliADCalibData::GetCalibDiscriThr(Int_t channel, Bool_t scaled)
323{
324 // The method returns actual TDC discri threshold
325 // extracted from the data.
326 //
327 // In case scaled flag is set the threshold is scaled
328 // so that to get 4.0 for a FEE threshold of 4.0.
329 // In this way we avoid a change in the slewing correction
330 // for the entire 2010 p-p data.
331 //
332 // The method is to be moved to OCDB object.
333
334 Float_t thr = GetDiscriThr(channel);
335
336 Float_t calThr = 0;
337 if (thr <= 1.)
338 calThr = 3.1;
339 else if (thr >= 2.)
340 calThr = (3.1+1.15*thr-1.7);
341 else
342 calThr = (3.1-0.3*thr+0.3*thr*thr);
343
344 if (scaled) calThr *= 4./(3.1+1.15*4.-1.7);
345
346 return calThr;
347}
4188a021 348//_____________________________________________________________________________
349void AliADCalibData::FillDCSData(AliADDataDCS * data){
350 // Set all parameters from the data get by the shuttle
351 TMap * params = data->GetFEEParameters();
352 TIter iter(params);
353 TObjString* aliasName;
354
355 while (( aliasName = (TObjString*) iter.Next() )) {
356 AliDCSValue* aValue = (AliDCSValue*) params->GetValue(aliasName);
357 Int_t val;
358 if(aValue) {
359 val = aValue->GetInt();
360 AliInfo(Form("%s : %d",aliasName->String().Data(), val));
361 SetParameter(aliasName->String(),val);
362 }
363 }
364
365 SetMeanHV(data->GetMeanHV());
366 SetWidthHV(data->GetWidthHV());
367 SetDeadMap(data->GetDeadMap());
69e96215 368
4188a021 369}
69e96215 370//_____________________________________________________________________________
371void AliADCalibData::SetParameter(TString name, Int_t val){
372 // Set given parameter
373
374 Int_t iBoard = -1;
375 Int_t iChannel = -1;
376
377 TSeqCollection* nameSplit = name.Tokenize("/");
378 TObjString * boardName = (TObjString *)nameSplit->At(2);
379 sscanf(boardName->String().Data(),"CIU%d",&iBoard);
380
381 TString paramName = ((TObjString *)nameSplit->At(3))->String();
382 Char_t channel[2] ; channel[1] = '\0';
383 channel[0] = paramName[paramName.Sizeof()-2];
384 sscanf(channel,"%d",&iChannel);
385
386 if(name.Contains("TimeResolution")) SetTimeResolution((UShort_t) val,iBoard);
387 else if(name.Contains("WidthResolution")) SetWidthResolution((UShort_t) val,iBoard);
388 else if(name.Contains("MatchWindow")) SetMatchWindow((UInt_t) val,iBoard);
389 else if(name.Contains("SearchWindow")) SetSearchWindow((UInt_t) val,iBoard);
390 else if(name.Contains("TriggerCountOffset")) SetTriggerCountOffset((UInt_t) val,iBoard);
391 else if(name.Contains("RollOver")) SetRollOver((UInt_t) val,iBoard);
392 else if(name.Contains("DelayHit")) SetTimeOffset(0.01*(Float_t)val,iBoard,(iChannel-1));
4188a021 393 else if(name.Contains("DiscriThr")) SetDiscriThr(((Float_t)val-1040.)/112.,iBoard,(iChannel-1));
b405b003 394
395 else if(name.Contains("DelayClk1Win1")) SetDelayClk1Win1((UShort_t) val,iBoard);
396 else if(name.Contains("Clk1Win1")) SetClk1Win1((UShort_t) val,iBoard);
397 else if(name.Contains("DelayClk1Win2")) SetDelayClk1Win2((UShort_t) val,iBoard);
398 else if(name.Contains("Clk1Win2")) SetClk1Win2((UShort_t) val,iBoard);
399 else if(name.Contains("DelayClk2Win1")) SetDelayClk2Win1((UShort_t) val,iBoard);
400 else if(name.Contains("Clk2Win1")) SetClk2Win1((UShort_t) val,iBoard);
401 else if(name.Contains("DelayClk2Win2")) SetDelayClk2Win2((UShort_t) val,iBoard);
402 else if(name.Contains("Clk2Win2")) SetClk2Win2((UShort_t) val,iBoard);
403 else if(name.Contains("LatchWin1")) SetLatchWin1((UShort_t) val,iBoard);
404 else if(name.Contains("LatchWin2")) SetLatchWin2((UShort_t) val,iBoard);
405 else if(name.Contains("ResetWin1")) SetResetWin1((UShort_t) val,iBoard);
406 else if(name.Contains("ResetWin2")) SetResetWin2((UShort_t) val,iBoard);
407 else if(name.Contains("PedestalSubtraction")) SetPedestalSubtraction((Bool_t) val,iBoard);
408 else if(name.Contains("BBAThreshold")) SetBBAThreshold((UShort_t) val);
409 else if(name.Contains("BBCThreshold")) SetBBCThreshold((UShort_t) val);
410 else if(name.Contains("BGAThreshold")) SetBGAThreshold((UShort_t) val);
411 else if(name.Contains("BGCThreshold")) SetBGCThreshold((UShort_t) val);
412 else if(name.Contains("BBAForBGThreshold")) SetBBAForBGThreshold((UShort_t) val);
413 else if(name.Contains("BBCForBGThreshold")) SetBBCForBGThreshold((UShort_t) val);
2cbbb1d5 414 else if(name.Contains("MultADAThrLow")) SetMultADAThrLow((UShort_t) val);
415 else if(name.Contains("MultADAThrHigh")) SetMultADAThrHigh((UShort_t) val);
416 else if(name.Contains("MultADCThrLow")) SetMultADCThrLow((UShort_t) val);
417 else if(name.Contains("MultADCThrHigh")) SetMultADCThrHigh((UShort_t) val);
b405b003 418 else if(name.Contains("TriggerSelect")) SetTriggerSelected((UShort_t) val, iChannel-1 );
419 else if(name.Contains("EnableCharge")) SetEnableCharge((Bool_t) val, iBoard , iChannel-1);
420 else if(name.Contains("EnableTiming")) SetEnableTiming((Bool_t) val, iBoard , iChannel-1);
421 else if(name.Contains("PedOdd")) SetOnlinePedestal((UShort_t) val, 1, iBoard, iChannel-1);
422 else if(name.Contains("PedEven")) SetOnlinePedestal((UShort_t) val, 0, iBoard, iChannel-1);
423 else if(name.Contains("PedCutOdd")) SetOnlinePedestalCut((UShort_t) val, 1, iBoard, iChannel-1);
424 else if(name.Contains("PedCutEven")) SetOnlinePedestalCut((UShort_t) val, 0, iBoard, iChannel-1);
425
69e96215 426 else AliError(Form("No Setter found for FEE parameter : %s",name.Data()));
427 //
428 delete nameSplit;
429}
430
431//________________________________________________________________
432void AliADCalibData::SetPedestal(const Float_t* Pedestal)
433{
434 if(Pedestal) for(int t=0; t<32; t++) fPedestal[t] = Pedestal[t];
435 else for(int t=0; t<32; t++) fPedestal[t] = 0.0;
436}
437
438//________________________________________________________________
439void AliADCalibData::SetSigma(const Float_t* Sigma)
440{
441 if(Sigma) for(int t=0; t<32; t++) fSigma[t] = Sigma[t];
442 else for(int t=0; t<32; t++) fSigma[t] = 0.0;
443}
444
445//________________________________________________________________
446void AliADCalibData::SetADCmean(const Float_t* ADCmean)
447{
448 if(ADCmean) for(int t=0; t<32; t++) fADCmean[t] = ADCmean[t];
449 else for(int t=0; t<32; t++) fADCmean[t] = 0.0;
450}
451
452//________________________________________________________________
453void AliADCalibData::SetADCsigma(const Float_t* ADCsigma)
454{
455 if(ADCsigma) for(int t=0; t<32; t++) fADCsigma[t] = ADCsigma[t];
456 else for(int t=0; t<32; t++) fADCsigma[t] = 0.0;
457}
458
459//________________________________________________________________
460void AliADCalibData::SetMeanHV(const Float_t* MeanHV)
461{
462 if(MeanHV) for(int t=0; t<16; t++) fMeanHV[t] = MeanHV[t];
463 else for(int t=0; t<16; t++) fMeanHV[t] = 0.0;
464}
465
466//________________________________________________________________
467void AliADCalibData::SetWidthHV(const Float_t* WidthHV)
468{
469 if(WidthHV) for(int t=0; t<16; t++) fWidthHV[t] = WidthHV[t];
470 else for(int t=0; t<16; t++) fWidthHV[t] = 0.0;
471}
472
473//________________________________________________________________
474void AliADCalibData::SetDeadMap(const Bool_t* deadMap)
475{
476 if(deadMap) for(int t=0; t<16; t++) fDeadChannel[t] = deadMap[t];
477 else for(int t=0; t<16; t++) fDeadChannel[t] = kFALSE;
478}
479
480//________________________________________________________________
481void AliADCalibData::SetTimeOffset(Float_t val, Int_t board, Int_t channel)
482{
483 Int_t ch = AliADCalibData::GetOfflineChannelNumber(board,channel);
484 if(ch >= 0){
485 fTimeOffset[ch]=val;
486 AliInfo(Form("Time offset for channel %d set to %f",ch,fTimeOffset[ch]));
487 }
488 else
489 AliError("Board/Channel numbers are not valid");
490}
491
492//________________________________________________________________
493void AliADCalibData::SetTimeOffset(const Float_t* TimeOffset)
494{
495 if(TimeOffset) for(int t=0; t<16; t++) fTimeOffset[t] = TimeOffset[t];
496 else for(int t=0; t<16; t++) fTimeOffset[t] = 5.0;
497}
498//________________________________________________________________
499void AliADCalibData::SetTimeGain(const Float_t* TimeGain)
500{
501 if(TimeGain) for(int t=0; t<16; t++) fTimeGain[t] = TimeGain[t];
502 else for(int t=0; t<16; t++) fTimeGain[t] = 0.0;
503}
504//________________________________________________________________
505void AliADCalibData::SetTimeResolution(UShort_t *resols){
506 // Set Time Resolution of the TDC
507 if(resols) for(int t=0; t<kNCIUBoards; t++) SetTimeResolution(resols[t],t);
508 else AliError("Time Resolution not defined.");
509
510}
511//________________________________________________________________
512void AliADCalibData::SetTimeResolution(UShort_t resol, Int_t board)
513{
514 // Set Time Resolution of the TDC
515 if((board>=0) && (board<kNCIUBoards)) {
516 switch(resol){
517 case 0:
518 fTimeResolution[board] = 25./256.;
519 break;
520 case 1:
521 fTimeResolution[board] = 25./128.;
522 break;
523 case 2:
524 fTimeResolution[board] = 25./64.;
525 break;
526 case 3:
527 fTimeResolution[board] = 25./32.;
528 break;
529 case 4:
530 fTimeResolution[board] = 25./16.;
531 break;
532 case 5:
533 fTimeResolution[board] = 25./8.;
534 break;
535 case 6:
536 fTimeResolution[board] = 6.25;
537 break;
538 case 7:
539 fTimeResolution[board] = 12.5;
540 break;
541 }
542 AliInfo(Form("Time Resolution of board %d set to %f",board,fTimeResolution[board]));
543 } else AliError(Form("Board %d is not valid",board));
544}
545//________________________________________________________________
546void AliADCalibData::SetWidthResolution(UShort_t *resols){
547 // Set Time Width Resolution of the TDC
548 if(resols) for(int t=0; t<kNCIUBoards; t++) SetWidthResolution(resols[t],t);
549 else AliError("Width Resolution not defined.");
550
551}
552//________________________________________________________________
553void AliADCalibData::SetWidthResolution(UShort_t resol, Int_t board)
554{
555 // Set Time Width Resolution of the TDC
556 if((board>=0) && (board<kNCIUBoards)){
557 switch(resol){
558 case 0:
559 fWidthResolution[board] = 25./256.;
560 break;
561 case 1:
562 fWidthResolution[board] = 25./128.;
563 break;
564 case 2:
565 fWidthResolution[board] = 25./64.;
566 break;
567 case 3:
568 fWidthResolution[board] = 25./32.;
569 break;
570 case 4:
571 fWidthResolution[board] = 25./16.;
572 break;
573 case 5:
574 fWidthResolution[board] = 25./8.;
575 break;
576 case 6:
577 fWidthResolution[board] = 6.25;
578 break;
579 case 7:
580 fWidthResolution[board] = 12.5;
581 break;
582 case 8:
583 fWidthResolution[board] = 25.;
584 break;
585 case 9:
586 fWidthResolution[board] = 50.;
587 break;
588 case 10:
589 fWidthResolution[board] = 100.;
590 break;
591 case 11:
592 fWidthResolution[board] = 200.;
593 break;
594 case 12:
595 fWidthResolution[board] = 400.;
596 break;
597 case 13:
598 fWidthResolution[board] = 800.;
599 break;
600
601 }
602 AliInfo(Form("Width Resolution of board %d set to %f",board,fWidthResolution[board]));
603 }else AliError(Form("Board %d is not valid",board));
604}
605
606//________________________________________________________________
607void AliADCalibData::SetMatchWindow(UInt_t *windows)
608{
609 // Set Match window of the HPTDC
610 // The units are 25ns
611 if(windows) for(Int_t b=0; b<kNCIUBoards; b++) SetMatchWindow(windows[b],b);
612 else AliError("Match windows not defined.");
613}
614
615//________________________________________________________________
616void AliADCalibData::SetMatchWindow(UInt_t window, Int_t board)
617{
618 // Set Match window of the HPTDC
619 // The units are 25ns
620 if((board>=0) && (board<kNCIUBoards)){
621 fMatchWindow[board] = window;
622 AliInfo(Form("Match window of board %d set to %d",board,fMatchWindow[board]));
623 }
624 else
625 AliError(Form("Board %d is not valid",board));
626}
627
628//________________________________________________________________
629void AliADCalibData::SetSearchWindow(UInt_t *windows)
630{
631 // Set Search window of the HPTDC
632 // The units are 25ns
633 if(windows) for(Int_t b=0; b<kNCIUBoards; b++) SetSearchWindow(windows[b],b);
634 else AliError("Search windows not defined.");
635}
636
637//________________________________________________________________
638void AliADCalibData::SetSearchWindow(UInt_t window, Int_t board)
639{
640 // Set Search window of the HPTDC
641 // The units are 25ns
642 if((board>=0) && (board<kNCIUBoards)){
643 fSearchWindow[board] = window;
644 AliInfo(Form("Search window of board %d set to %d",board,fSearchWindow[board]));
645 }
646 else
647 AliError(Form("Board %d is not valid",board));
648}
649
650//________________________________________________________________
651void AliADCalibData::SetTriggerCountOffset(UInt_t *offsets)
652{
653 // Set trigger-count offset of the HPTDC
654 // The units are 25ns
655 if(offsets) for(Int_t b=0; b<kNCIUBoards; b++) SetTriggerCountOffset(offsets[b],b);
656 else AliError("Trigger count offsets not defined.");
657}
658
659//________________________________________________________________
660void AliADCalibData::SetTriggerCountOffset(UInt_t offset, Int_t board)
661{
662 // Set trigger-count offsets of the HPTDC
663 // The units are 25ns
664 if((board>=0) && (board<kNCIUBoards)){
665 fTriggerCountOffset[board] = offset;
666 AliInfo(Form("Trigger-count offset of board %d set to %d",board,fTriggerCountOffset[board]));
667 }
668 else
669 AliError(Form("Board %d is not valid",board));
670}
671
672//________________________________________________________________
673void AliADCalibData::SetRollOver(UInt_t *offsets)
674{
675 // Set Roll-over of the HPTDC
676 // The units are 25ns
677 if(offsets) for(Int_t b=0; b<kNCIUBoards; b++) SetRollOver(offsets[b],b);
678 else AliError("Roll-over offsets not defined.");
679}
680
681//________________________________________________________________
682void AliADCalibData::SetRollOver(UInt_t offset, Int_t board)
683{
684 // Set Roll-over of the HPTDC
685 // The units are 25ns
686 if((board>=0) && (board<kNCIUBoards)){
687 fRollOver[board] = offset;
688 AliInfo(Form("Roll-over offset of board %d set to %d",board,fRollOver[board]));
689 }
690 else
691 AliError(Form("Board %d is not valid",board));
692}
693
694//________________________________________________________________
695void AliADCalibData::SetDiscriThr(Float_t thr, Int_t board, Int_t channel)
696{
697 // Set the TDC discriminator
698 // threshold values expressed in units of ADC
699 Int_t ch = AliADCalibData::GetOfflineChannelNumber(board,channel);
700 if(ch >= 0){
701 if (thr > 0) {
702 fDiscriThr[ch]=thr;
703 AliInfo(Form("Discriminator threshold for channel %d set to %f",ch,fDiscriThr[ch]));
704 }
705 else {
706 AliWarning(Form("Ignore wrong threshold value (%f) for channel %d !",thr,ch));
707 }
708 }
709 else
710 AliError("Board/Channel numbers are not valid");
711}
712
713//________________________________________________________________
714void AliADCalibData::SetDiscriThr(const Float_t* thresholds)
715{
716 // Set the TDC discriminator
717 // threshold values expressed in units of ADC
718 if(thresholds) for(int t=0; t<16; t++) fDiscriThr[t] = thresholds[t];
719 else for(int t=0; t<16; t++) fDiscriThr[t] = 2.5;
720}
721
b405b003 722
723//________________________________________________________________
724void AliADCalibData::SetOnlinePedestalCut(UShort_t val,Int_t integrator, Int_t channel)
725{
726 // Set Pedestal Cut of individual channel
727 if(channel>=0 && channel<16) {
728 if(integrator) fPedestalCutOdd[channel] = val;
729 else fPedestalCutEven[channel] = val;
730 } else AliError(Form("Impossible to write at : Channel %d",channel));
731}
732//________________________________________________________________
733void AliADCalibData::SetOnlinePedestalCut(UShort_t val,Int_t integrator, Int_t board, Int_t channel)
734{
735 Int_t ch = AliADCalibData::GetOfflineChannelNumber(board,channel);
736 if(ch>=0 && ch<16) {
737 if(integrator) fPedestalCutOdd[ch] = val;
738 else fPedestalCutEven[ch] = val;
739 }
740 else
741 AliError("Board/Channel numbers are not valid");
742}
743//________________________________________________________________
744UShort_t AliADCalibData::GetOnlinePedestalCut(Int_t integrator, Int_t channel)
745{
746 // Get Pedestal Cut of individual channel
747 if(channel>=0 && channel<16) {
748 if(integrator) return(fPedestalCutOdd[channel]);
749 else return(fPedestalCutEven[channel]);
750 }else AliError(Form("Impossible to read at : Channel %d",channel));
751 return 0;
752}
753//________________________________________________________________
754void AliADCalibData::SetOnlinePedestal(UShort_t val, Int_t integrator, Int_t channel)
755{
756 // Set Pedestal of individual channel
757 if(channel>=0 && channel<16) {
758 if(integrator) fPedestalOdd[channel] = val;
759 else fPedestalEven[channel] = val;
760 } else AliError(Form("Impossible to write at : Channel %d ; Integrator %d ",channel,integrator));
761}
762//________________________________________________________________
763void AliADCalibData::SetOnlinePedestal(UShort_t val,Int_t integrator, Int_t board, Int_t channel)
764{
765 Int_t ch = AliADCalibData::GetOfflineChannelNumber(board,channel);
766 if(ch>=0 && ch<16) {
767 if(integrator) fPedestalOdd[ch] = val;
768 else fPedestalEven[ch] = val;
769 }
770 else
771 AliError("Board/Channel numbers are not valid");
772}
773//________________________________________________________________
774UShort_t AliADCalibData::GetOnlinePedestal(Int_t integrator, Int_t channel)
775{
776 // Get Pedestal of individual channel
777 if(channel>=0 && channel<16) {
778 if(integrator) return(fPedestalOdd[channel]);
779 else return(fPedestalEven[channel]);
780 } else AliError(Form("Impossible to read at : Channel %d",channel));
781 return 0;
782}
783//________________________________________________________________
784void AliADCalibData::SetEnableCharge(Bool_t val, Int_t channel)
785{
786 // Set the channels enabled for Charge triggers
787 if(channel>=0 && channel<16) fEnableCharge[channel] = val;
788 else AliError(Form("Impossible to write at : Channel %d",channel));
789}
790//________________________________________________________________
791Bool_t AliADCalibData::GetEnableCharge(Int_t channel)
792{
793 // Get the channels enabled for Charge triggers
794 if(channel>=0 && channel<16) return(fEnableCharge[channel]);
795 else AliError(Form("Impossible to read at : Channel %d",channel));
796 return kFALSE;
797}
798//________________________________________________________________
799void AliADCalibData::SetEnableTiming(Bool_t val, Int_t channel)
800{
801 // Set the channels enabled for Timing triggers
802 if(channel>=0 && channel<16) fEnableTiming[channel] = val;
803 else AliError(Form("Impossible to write at : Channel %d",channel));
804}
805//________________________________________________________________
806Bool_t AliADCalibData::GetEnableTiming(Int_t channel)
807{
808 // Get the channels enabled for Timing triggers
809 if(channel>=0 && channel<16) return(fEnableTiming[channel]);
810 else AliError(Form("Impossible to read at : Channel %d",channel));
811 return kFALSE;
812}
813//________________________________________________________________
814void AliADCalibData::SetEnableCharge(Bool_t val,Int_t board, Int_t channel)
815{
816 Int_t ch = AliADCalibData::GetOfflineChannelNumber(board,channel);
817 // Set the channels enabled for Charge triggers
818 if(ch>=0) fEnableCharge[ch] = val;
819 else AliError(Form("Impossible to write at : Board %d ; Channel %d",board,channel));
820}
821//________________________________________________________________
822void AliADCalibData::SetEnableTiming(Bool_t val,Int_t board, Int_t channel)
823{
824 Int_t ch = AliADCalibData::GetOfflineChannelNumber(board,channel);
825 // Set the channels enabled for Timing triggers
826 if(ch>=0) fEnableTiming[ch] = val;
827 else AliError(Form("Impossible to write at : Board %d ; Channel %d",board,channel));
828}
829//________________________________________________________________
830void AliADCalibData::SetTriggerSelected(UShort_t trigger, Int_t output)
831{
832 // Set the trigger selected on the outputs to CTP
833 if(output>=0 && output<5) fTriggerSelected[output] = trigger;
834 else AliError(Form("Trigger output number %d not valid",output));
835}
836
837//________________________________________________________________
838void AliADCalibData::SetClk1Win1(UShort_t* clks)
839{
840 // Set Win clock of BB
841 if(clks) for(int t=0; t<kNCIUBoards; t++) SetClk1Win1(clks[t],t);
842 else AliError("Profil Clock1 Win1 Not defined.");
843}
844//________________________________________________________________
845void AliADCalibData::SetClk2Win1(UShort_t* clks)
846{
847 // Set Win clock of BB
848 if(clks) for(int t=0; t<kNCIUBoards; t++) SetClk2Win1(clks[t],t);
849 else AliError("Profil Clock2 Win1 Not defined.");
850}
851//________________________________________________________________
852void AliADCalibData::SetClk1Win1(UShort_t clk, Int_t board)
853{
854 // Set Win clock of BB
855 if((board>=0) && (board<kNCIUBoards)) {
856 fClk1Win1[board] = clk;
857 if(!IsClkValid(clk)) AliWarning(Form("Profil Clock1 Win1 of board %d is not valid : %d",board,clk));
858 }else {
859 AliError(Form("Impossible to Write at Board %d",board));
860 }
861}
862//________________________________________________________________
863void AliADCalibData::SetClk2Win1(UShort_t clk, Int_t board)
864{
865 // Set Win clock of BB
866 if((board>=0) && (board<kNCIUBoards)) {
867 fClk2Win1[board] = clk;
868 if(!IsClkValid(clk)) AliWarning(Form("Profil Clock2 Win1 of board %d is not valid : %d",board,clk));
869 }else {
870 AliError(Form("Impossible to Write at Board %d",board));
871 }
872}
873//________________________________________________________________
874void AliADCalibData::SetClk1Win2(UShort_t* clks)
875{
876 // Set Win clock of BG
877 if(clks) for(int t=0; t<kNCIUBoards; t++) SetClk1Win2(clks[t],t);
878 else AliError("Profil Clock1 Win2 Not defined.");
879}
880//________________________________________________________________
881void AliADCalibData::SetClk2Win2(UShort_t* clks)
882{
883 // Set Win clock of BG
884 if(clks) for(int t=0; t<kNCIUBoards; t++) SetClk2Win2(clks[t],t);
885 else AliError("Profil Clock2 Win2 Not defined.");
886}
887//________________________________________________________________
888void AliADCalibData::SetClk1Win2(UShort_t clk, Int_t board)
889{
890 // Set Win clock of BG
891 if((board>=0) && (board<kNCIUBoards)) {
892 fClk1Win2[board] = clk;
893 if(!IsClkValid(clk)) AliWarning(Form("Profil Clock1 Win2 of board %d is not valid : %d",board,clk));
894 }else {
895 AliError(Form("Impossible to Write at Board %d",board));
896 }
897}
898//________________________________________________________________
899void AliADCalibData::SetClk2Win2(UShort_t clk, Int_t board)
900{
901 // Set Win clock of BG
902 if((board>=0) && (board<kNCIUBoards)) {
903 fClk2Win2[board] = clk;
904 if(!IsClkValid(clk)) AliWarning(Form("Profil Clock2 Win2 of board %d is not valid : %d",board,clk));
905 }else {
906 AliError(Form("Impossible to Write at Board %d",board));
907 }
908}
909//________________________________________________________________
910void AliADCalibData::SetDelayClk1Win1(UShort_t* delays)
911{
912 // Set Delay for Win clock of BB
913 if(delays) for(int t=0; t<kNCIUBoards; t++) SetDelayClk1Win1(delays[t],t);
914 else AliError("Profil Clock1 Win1 Delays Not defined.");
915}
916//________________________________________________________________
917void AliADCalibData::SetDelayClk1Win1(UShort_t delay, Int_t board)
918{
919 // Set Delay for Win clock of BB
920 if(delay>1023){
921 AliWarning(Form("Profil Clock1 Win1 Delay of board %d should be less 1023 is currently %d. Truncated to the first 10 bits",board, delay));
922 delay = delay & 0x3FF;
923 }
924 if((board>=0) && (board<kNCIUBoards)) fDelayClk1Win1[board] = delay;
925 else AliError(Form("Trying to write out of the array Board = %d",board));
926}
927//________________________________________________________________
928void AliADCalibData::SetDelayClk2Win1(UShort_t* delays)
929{
930 // Set Delay for Win clock of BB
931 if(delays) for(int t=0; t<kNCIUBoards; t++) SetDelayClk2Win1(delays[t],t);
932 else AliError("Profil Clock2 Win1 Delays Not defined.");
933}
934//________________________________________________________________
935void AliADCalibData::SetDelayClk2Win1(UShort_t delay, Int_t board)
936{
937 // Set Delay for Win clock of BB
938 if(delay>1023){
939 AliWarning(Form("Profil Clock2 Win1 Delay of board %d should be less 1023 is currently %d. Truncated to the first 10 bits",board, delay));
940 delay = delay & 0x3FF;
941 }
942 if((board>=0) && (board<kNCIUBoards)) fDelayClk2Win1[board] = delay;
943 else AliError(Form("Trying to write out of the array Board = %d",board));
944}
945//________________________________________________________________
946void AliADCalibData::SetDelayClk1Win2(UShort_t* delays)
947{
948 // Set Delay for Win clock of BG
949 if(delays) for(int t=0; t<kNCIUBoards; t++) SetDelayClk1Win2(delays[t],t);
950 else AliError("Profil Clock1 Win2 Delays Not defined.");
951}
952//________________________________________________________________
953void AliADCalibData::SetDelayClk1Win2(UShort_t delay, Int_t board)
954{
955 // Set Delay for Win clock of BG
956 if(delay>1023){
957 AliWarning(Form("Profil Clock1 Win2 Delay of board %d should be less 1023 is currently %d. Truncated to the first 10 bits",board, delay));
958 delay = delay & 0x3FF;
959 }
960 if((board>=0) && (board<kNCIUBoards)) fDelayClk1Win2[board] = delay;
961 else AliError(Form("Trying to write out of the array Board = %d",board));
962}
963//________________________________________________________________
964void AliADCalibData::SetDelayClk2Win2(UShort_t* delays)
965{
966 // Set Delay for Win clock of BG
967 if(delays) for(int t=0; t<kNCIUBoards; t++) SetDelayClk2Win2(delays[t],t);
968 else AliError("Profil Clock2 Win2 Delays Not defined.");
969}
970//________________________________________________________________
971void AliADCalibData::SetDelayClk2Win2(UShort_t delay, Int_t board)
972{
973 // Set Delay for Win clock of BG
974 if(delay>1023){
975 AliWarning(Form("Profil Clock2 Win2 Delay of board %d should be less 1023 is currently %d. Truncated to the first 10 bits",board, delay));
976 delay = delay & 0x3FF;
977 }
978 if((board>=0) && (board<kNCIUBoards)) fDelayClk2Win2[board] = delay;
979 else AliError(Form("Trying to write out of the array Board = %d",board));
980}
981//________________________________________________________________
982void AliADCalibData::SetLatchWin1(UShort_t *latchs){
983 // Set Latch Win clock for BB
984 if(latchs) for(int t=0; t<kNCIUBoards; t++) SetLatchWin1(latchs[t],t);
985 else AliError("Latch Win1 profil Not defined.");
986}
987//________________________________________________________________
988void AliADCalibData::SetLatchWin1(UShort_t latch, Int_t board)
989{
990 // Set Latch Win clock for BB
991 if((board>=0) && (board<kNCIUBoards)) {
992 fLatchWin1[board] = latch;
993 if(!IsClkValid(latch)) AliWarning(Form("Latch Win1 of board %d is not valid : %d",board,latch));
994 }else {
995 AliError(Form("Impossible to Write at Board %d",board));
996 }
997}
998//________________________________________________________________
999void AliADCalibData::SetLatchWin2(UShort_t *latchs){
1000 // Set Latch Win clock for BG
1001 if(latchs) for(int t=0; t<kNCIUBoards; t++) SetLatchWin2(latchs[t],t);
1002 else AliError("Latch Win2 profil Not defined.");
1003}
1004//________________________________________________________________
1005void AliADCalibData::SetLatchWin2(UShort_t latch, Int_t board)
1006{
1007 // Set Latch Win clock for BG
1008 if((board>=0) && (board<kNCIUBoards)) {
1009 fLatchWin2[board] = latch;
1010 if(!IsClkValid(latch)) AliWarning(Form("Latch Win2 of board %d is not valid : %d",board,latch));
1011 }else {
1012 AliError(Form("Impossible to Write at Board %d",board));
1013 }
1014}
1015//________________________________________________________________
1016void AliADCalibData::SetResetWin1(UShort_t *resets){
1017 // Set Reset Win clock for BB
1018 if(resets) for(int t=0; t<kNCIUBoards; t++) SetResetWin1(resets[t],t);
1019 else AliError("Reset Win1 profil Not defined.");
1020}
1021//________________________________________________________________
1022void AliADCalibData::SetResetWin1(UShort_t reset, Int_t board)
1023{
1024 // Set Reset Win clock for BB
1025 if((board>=0) && (board<kNCIUBoards)) {
1026 fResetWin1[board] = reset;
1027 if(!IsClkValid(reset)) AliWarning(Form("Reset Win1 of board %d is not valid : %d",board,reset));
1028 }else {
1029 AliError(Form("Impossible to Write at Board %d",board));
1030 }
1031}
1032//________________________________________________________________
1033void AliADCalibData::SetResetWin2(UShort_t *resets){
1034 // Set Reset Win clock for BG
1035 if(resets) for(int t=0; t<kNCIUBoards; t++) SetResetWin2(resets[t],t);
1036 else AliError("Reset Win2 profil Not defined.");
1037}
1038//________________________________________________________________
1039void AliADCalibData::SetResetWin2(UShort_t reset, Int_t board)
1040{
1041 // Set Reset Win clock for BG
1042 if((board>=0) && (board<kNCIUBoards)) {
1043 fResetWin2[board] = reset;
1044 if(!IsClkValid(reset)) AliWarning(Form("Reset Win2 of board %d is not valid : %d",board,reset));
1045 }else {
1046 AliError(Form("Impossible to Write at Board %d",board));
1047 }
1048}
1049//________________________________________________________________
1050void AliADCalibData::SetPedestalSubtraction(Bool_t *peds){
1051 // Set Pedestal Subtraction Parameter
1052 if(peds) for(int t=0; t<kNCIUBoards; t++) SetPedestalSubtraction(peds[t],t);
1053 else AliError("Pedestal Subtraction Not defined.");
1054
1055}
1056//________________________________________________________________
1057void AliADCalibData::SetPedestalSubtraction(Bool_t ped, Int_t board)
1058{
1059 // Set Pedestal Subtraction Parameter
1060 if((board>=0) && (board<kNCIUBoards)) fPedestalSubtraction[board] = ped;
1061 else AliError(Form("Board %d is not valid",board));
1062}
1063
1064//________________________________________________________________
1065Bool_t AliADCalibData::IsClkValid(UShort_t clock) const {
1066 // Check if the given clock has a valid profil.
1067 Bool_t word[5];
1068 Bool_t isValid = kTRUE;
1069 Short_t risingEdge = 0;
1070 Short_t fallingEdge = 0;
1071 for(int i=0 ; i<5 ; i++) word[i] = (clock >> i) & 0x1;
1072
1073 if(word[0] != word[4]){
1074 if(word[4]) fallingEdge++;
1075 else risingEdge++;
1076 }
1077 for(int i=1 ; i<5 ; i++){
1078 if(word[i] != word[i-1]) {
1079 if(word[i-1]) fallingEdge++;
1080 else risingEdge++;
1081 }
1082 }
1083 if((fallingEdge>1)||(risingEdge>1)) isValid = kFALSE;
1084 if(((risingEdge==0)&&(fallingEdge==0)) &&(!word[0])) isValid = kFALSE;
1085 return isValid;
1086}
1087
69e96215 1088//________________________________________________________________
1089Int_t AliADCalibData::GetOfflineChannelNumber(Int_t board, Int_t channel)
1090{
1091 // Get the offline channel number from
1092 // the FEE board and channel indexes
1093
1094 if (board < 0 || board >= 2) {
1095 AliErrorClass(Form("Wrong FEE board number: %d",board));
1096 return -1;
1097 }
1098 if (channel < 0 || channel >= 8) {
1099 AliErrorClass(Form("Wrong FEE channel number: %d",channel));
1100 return -1;
1101 }
1102
1103 Int_t offCh = (board+1)*channel;
1104
1105 return offCh;
1106}
1107//________________________________________________________________
1108Int_t AliADCalibData::GetFEEChannelNumber(Int_t channel)
1109{
1110 // Get FEE channel number
1111 // from offline channel index
1112 if (channel >= 0 && channel < 16) return ((channel % 8));
1113
1114 AliErrorClass(Form("Wrong channel index: %d",channel));
1115 return -1;
1116}
1117
1118
1119