1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 /* $Id: AliADCalibData.cxx, */
19 #include <TObjString.h>
24 #include "AliDCSValue.h"
25 #include "AliCDBManager.h"
26 #include "AliCDBEntry.h"
27 #include "AliADDataDCS.h"
28 #include "AliADCalibData.h"
29 #include "AliADConst.h"
32 ClassImp(AliADCalibData)
35 //________________________________________________________________
36 AliADCalibData::AliADCalibData():
41 // default constructor
43 for(int t=0; t<16; t++) {
48 fDeadChannel[t]= kFALSE;
51 for(int t=0; t<32; t++) {
57 for(int i=0; i<kNCIUBoards ;i++) {
58 fTimeResolution[i] = 25./256.; // Default time resolution
59 fWidthResolution[i] = 25./64.; // Default time width resolution
61 fSearchWindow[i] = 16;
62 fTriggerCountOffset[i] = 3247;
67 //________________________________________________________________
68 void AliADCalibData::Reset()
73 //________________________________________________________________
74 AliADCalibData::AliADCalibData(const char* name) :
80 TString namst = "Calib_";
82 SetName(namst.Data());
83 SetTitle(namst.Data());
84 for(int t=0; t<16; t++) {
89 fDeadChannel[t]= kFALSE;
92 for(int t=0; t<32; t++) {
98 for(int i=0; i<kNCIUBoards ;i++) {
99 fTimeResolution[i] = 25./256.; // Default time resolution in ns / channel
100 fWidthResolution[i] = 25./64.; // Default time width resolution in ns / channel
102 fSearchWindow[i] = 16;
103 fTriggerCountOffset[i] = 3247;
108 //________________________________________________________________
109 AliADCalibData::AliADCalibData(const AliADCalibData& calibda) :
117 SetName(calibda.GetName());
118 SetTitle(calibda.GetName());
120 for(int t=0; t<32; t++) {
121 fPedestal[t] = calibda.GetPedestal(t);
122 fSigma[t] = calibda.GetSigma(t);
123 fADCmean[t] = calibda.GetADCmean(t);
124 fADCsigma[t] = calibda.GetADCsigma(t); }
126 for(int t=0; t<16; t++) {
127 fMeanHV[t] = calibda.GetMeanHV(t);
128 fWidthHV[t] = calibda.GetWidthHV(t);
129 fTimeOffset[t] = calibda.GetTimeOffset(t);
130 fTimeGain[t] = calibda.GetTimeGain(t);
131 fDeadChannel[t] = calibda.IsChannelDead(t);
132 fDiscriThr[t] = calibda.GetDiscriThr(t);
135 for(int i=0; i<kNCIUBoards ;i++) {
136 fTimeResolution[i] = calibda.GetTimeResolution(i);
137 fWidthResolution[i] = calibda.GetWidthResolution(i);
138 fMatchWindow[i] = calibda.GetMatchWindow(i);
139 fSearchWindow[i] = calibda.GetSearchWindow(i);
140 fTriggerCountOffset[i] = calibda.GetTriggerCountOffset(i);
141 fRollOver[i] = calibda.GetRollOver(i);
146 //________________________________________________________________
147 AliADCalibData &AliADCalibData::operator =(const AliADCalibData& calibda)
149 // assignment operator
151 SetName(calibda.GetName());
152 SetTitle(calibda.GetName());
154 for(int t=0; t<32; t++) {
155 fPedestal[t] = calibda.GetPedestal(t);
156 fSigma[t] = calibda.GetSigma(t);
157 fADCmean[t] = calibda.GetADCmean(t);
158 fADCsigma[t] = calibda.GetADCsigma(t); }
160 for(int t=0; t<16; t++) {
161 fMeanHV[t] = calibda.GetMeanHV(t);
162 fWidthHV[t] = calibda.GetWidthHV(t);
163 fTimeOffset[t] = calibda.GetTimeOffset(t);
164 fTimeGain[t] = calibda.GetTimeGain(t);
165 fDeadChannel[t] = calibda.IsChannelDead(t);
166 fDiscriThr[t] = calibda.GetDiscriThr(t);
168 for(int i=0; i<kNCIUBoards ;i++) {
169 fTimeResolution[i] = calibda.GetTimeResolution(i);
170 fWidthResolution[i] = calibda.GetWidthResolution(i);
171 fMatchWindow[i] = calibda.GetMatchWindow(i);
172 fSearchWindow[i] = calibda.GetSearchWindow(i);
173 fTriggerCountOffset[i] = calibda.GetTriggerCountOffset(i);
174 fRollOver[i] = calibda.GetRollOver(i);
181 //________________________________________________________________
182 AliADCalibData::~AliADCalibData()
186 delete [] fLightYields;
193 //________________________________________________________________
194 Int_t AliADCalibData::GetBoardNumber(Int_t channel)
196 // Get FEE board number
197 // from offline channel index
198 if (channel >= 0 && channel < 8) return (0);
199 if (channel >=8 && channel < 16) return (1);
201 AliErrorClass(Form("Wrong channel index: %d",channel));
205 //________________________________________________________________
206 Float_t AliADCalibData::GetLightYields(Int_t channel)
208 // Get the light yield efficiency
209 // for a given channel
210 if (!fLightYields) InitLightYields();
212 if (channel >= 0 && channel < 16) {
213 return fLightYields[channel];
216 AliError(Form("Wrong channel index: %d",channel));
220 //________________________________________________________________
221 void AliADCalibData::InitLightYields()
223 // Initialize the light yield factors
224 // Read from a separate OCDB entry
225 if (fLightYields) return;
227 AliCDBEntry *entry = AliCDBManager::Instance()->Get("VZERO/Calib/LightYields");
228 if (!entry) AliFatal("AD light yields are not found in OCDB !");
229 TH1F *yields = (TH1F*)entry->GetObject();
231 fLightYields = new Float_t[16];
232 for(Int_t i = 0 ; i < 16; ++i) {
233 fLightYields[i] = yields->GetBinContent(i+1);
237 //________________________________________________________________
238 void AliADCalibData::InitPMGains()
240 // Initialize the PM gain factors
241 // Read from a separate OCDB entry
242 if (fPMGainsA) return;
244 AliCDBEntry *entry = AliCDBManager::Instance()->Get("VZERO/Calib/PMGains");
245 if (!entry) AliFatal("VZERO PM gains are not found in OCDB !");
246 TH2F *gains = (TH2F*)entry->GetObject();
248 fPMGainsA = new Float_t[16];
249 fPMGainsB = new Float_t[16];
250 for(Int_t i = 0 ; i < 16; ++i) {
251 fPMGainsA[i] = gains->GetBinContent(i+1,1);
252 fPMGainsB[i] = gains->GetBinContent(i+1,2);
256 //________________________________________________________________
257 Float_t AliADCalibData::GetGain(Int_t channel)
259 // Computes the PM gains
260 // Argument passed is the PM number (aliroot numbering)
261 if (!fPMGainsA) InitPMGains();
263 // High Voltage retrieval from Calibration Data Base:
264 Float_t hv = fMeanHV[channel];
267 gain = TMath::Exp(fPMGainsA[channel]+fPMGainsB[channel]*TMath::Log(hv));
271 //________________________________________________________________
272 Float_t AliADCalibData::GetCalibDiscriThr(Int_t channel, Bool_t scaled)
274 // The method returns actual TDC discri threshold
275 // extracted from the data.
277 // In case scaled flag is set the threshold is scaled
278 // so that to get 4.0 for a FEE threshold of 4.0.
279 // In this way we avoid a change in the slewing correction
280 // for the entire 2010 p-p data.
282 // The method is to be moved to OCDB object.
284 Float_t thr = GetDiscriThr(channel);
290 calThr = (3.1+1.15*thr-1.7);
292 calThr = (3.1-0.3*thr+0.3*thr*thr);
294 if (scaled) calThr *= 4./(3.1+1.15*4.-1.7);
298 //_____________________________________________________________________________
299 void AliADCalibData::FillDCSData(AliADDataDCS * data){
300 // Set all parameters from the data get by the shuttle
301 TMap * params = data->GetFEEParameters();
303 TObjString* aliasName;
305 while (( aliasName = (TObjString*) iter.Next() )) {
306 AliDCSValue* aValue = (AliDCSValue*) params->GetValue(aliasName);
309 val = aValue->GetInt();
310 AliInfo(Form("%s : %d",aliasName->String().Data(), val));
311 SetParameter(aliasName->String(),val);
315 SetMeanHV(data->GetMeanHV());
316 SetWidthHV(data->GetWidthHV());
317 SetDeadMap(data->GetDeadMap());
320 //_____________________________________________________________________________
321 void AliADCalibData::SetParameter(TString name, Int_t val){
322 // Set given parameter
327 TSeqCollection* nameSplit = name.Tokenize("/");
328 TObjString * boardName = (TObjString *)nameSplit->At(2);
329 sscanf(boardName->String().Data(),"CIU%d",&iBoard);
331 TString paramName = ((TObjString *)nameSplit->At(3))->String();
332 Char_t channel[2] ; channel[1] = '\0';
333 channel[0] = paramName[paramName.Sizeof()-2];
334 sscanf(channel,"%d",&iChannel);
336 if(name.Contains("TimeResolution")) SetTimeResolution((UShort_t) val,iBoard);
337 else if(name.Contains("WidthResolution")) SetWidthResolution((UShort_t) val,iBoard);
338 else if(name.Contains("MatchWindow")) SetMatchWindow((UInt_t) val,iBoard);
339 else if(name.Contains("SearchWindow")) SetSearchWindow((UInt_t) val,iBoard);
340 else if(name.Contains("TriggerCountOffset")) SetTriggerCountOffset((UInt_t) val,iBoard);
341 else if(name.Contains("RollOver")) SetRollOver((UInt_t) val,iBoard);
342 else if(name.Contains("DelayHit")) SetTimeOffset(0.01*(Float_t)val,iBoard,(iChannel-1));
343 else if(name.Contains("DiscriThr")) SetDiscriThr(((Float_t)val-1040.)/112.,iBoard,(iChannel-1));
344 else AliError(Form("No Setter found for FEE parameter : %s",name.Data()));
349 //________________________________________________________________
350 void AliADCalibData::SetPedestal(const Float_t* Pedestal)
352 if(Pedestal) for(int t=0; t<32; t++) fPedestal[t] = Pedestal[t];
353 else for(int t=0; t<32; t++) fPedestal[t] = 0.0;
356 //________________________________________________________________
357 void AliADCalibData::SetSigma(const Float_t* Sigma)
359 if(Sigma) for(int t=0; t<32; t++) fSigma[t] = Sigma[t];
360 else for(int t=0; t<32; t++) fSigma[t] = 0.0;
363 //________________________________________________________________
364 void AliADCalibData::SetADCmean(const Float_t* ADCmean)
366 if(ADCmean) for(int t=0; t<32; t++) fADCmean[t] = ADCmean[t];
367 else for(int t=0; t<32; t++) fADCmean[t] = 0.0;
370 //________________________________________________________________
371 void AliADCalibData::SetADCsigma(const Float_t* ADCsigma)
373 if(ADCsigma) for(int t=0; t<32; t++) fADCsigma[t] = ADCsigma[t];
374 else for(int t=0; t<32; t++) fADCsigma[t] = 0.0;
377 //________________________________________________________________
378 void AliADCalibData::SetMeanHV(const Float_t* MeanHV)
380 if(MeanHV) for(int t=0; t<16; t++) fMeanHV[t] = MeanHV[t];
381 else for(int t=0; t<16; t++) fMeanHV[t] = 0.0;
384 //________________________________________________________________
385 void AliADCalibData::SetWidthHV(const Float_t* WidthHV)
387 if(WidthHV) for(int t=0; t<16; t++) fWidthHV[t] = WidthHV[t];
388 else for(int t=0; t<16; t++) fWidthHV[t] = 0.0;
391 //________________________________________________________________
392 void AliADCalibData::SetDeadMap(const Bool_t* deadMap)
394 if(deadMap) for(int t=0; t<16; t++) fDeadChannel[t] = deadMap[t];
395 else for(int t=0; t<16; t++) fDeadChannel[t] = kFALSE;
398 //________________________________________________________________
399 void AliADCalibData::SetTimeOffset(Float_t val, Int_t board, Int_t channel)
401 Int_t ch = AliADCalibData::GetOfflineChannelNumber(board,channel);
404 AliInfo(Form("Time offset for channel %d set to %f",ch,fTimeOffset[ch]));
407 AliError("Board/Channel numbers are not valid");
410 //________________________________________________________________
411 void AliADCalibData::SetTimeOffset(const Float_t* TimeOffset)
413 if(TimeOffset) for(int t=0; t<16; t++) fTimeOffset[t] = TimeOffset[t];
414 else for(int t=0; t<16; t++) fTimeOffset[t] = 5.0;
416 //________________________________________________________________
417 void AliADCalibData::SetTimeGain(const Float_t* TimeGain)
419 if(TimeGain) for(int t=0; t<16; t++) fTimeGain[t] = TimeGain[t];
420 else for(int t=0; t<16; t++) fTimeGain[t] = 0.0;
422 //________________________________________________________________
423 void AliADCalibData::SetTimeResolution(UShort_t *resols){
424 // Set Time Resolution of the TDC
425 if(resols) for(int t=0; t<kNCIUBoards; t++) SetTimeResolution(resols[t],t);
426 else AliError("Time Resolution not defined.");
429 //________________________________________________________________
430 void AliADCalibData::SetTimeResolution(UShort_t resol, Int_t board)
432 // Set Time Resolution of the TDC
433 if((board>=0) && (board<kNCIUBoards)) {
436 fTimeResolution[board] = 25./256.;
439 fTimeResolution[board] = 25./128.;
442 fTimeResolution[board] = 25./64.;
445 fTimeResolution[board] = 25./32.;
448 fTimeResolution[board] = 25./16.;
451 fTimeResolution[board] = 25./8.;
454 fTimeResolution[board] = 6.25;
457 fTimeResolution[board] = 12.5;
460 AliInfo(Form("Time Resolution of board %d set to %f",board,fTimeResolution[board]));
461 } else AliError(Form("Board %d is not valid",board));
463 //________________________________________________________________
464 void AliADCalibData::SetWidthResolution(UShort_t *resols){
465 // Set Time Width Resolution of the TDC
466 if(resols) for(int t=0; t<kNCIUBoards; t++) SetWidthResolution(resols[t],t);
467 else AliError("Width Resolution not defined.");
470 //________________________________________________________________
471 void AliADCalibData::SetWidthResolution(UShort_t resol, Int_t board)
473 // Set Time Width Resolution of the TDC
474 if((board>=0) && (board<kNCIUBoards)){
477 fWidthResolution[board] = 25./256.;
480 fWidthResolution[board] = 25./128.;
483 fWidthResolution[board] = 25./64.;
486 fWidthResolution[board] = 25./32.;
489 fWidthResolution[board] = 25./16.;
492 fWidthResolution[board] = 25./8.;
495 fWidthResolution[board] = 6.25;
498 fWidthResolution[board] = 12.5;
501 fWidthResolution[board] = 25.;
504 fWidthResolution[board] = 50.;
507 fWidthResolution[board] = 100.;
510 fWidthResolution[board] = 200.;
513 fWidthResolution[board] = 400.;
516 fWidthResolution[board] = 800.;
520 AliInfo(Form("Width Resolution of board %d set to %f",board,fWidthResolution[board]));
521 }else AliError(Form("Board %d is not valid",board));
524 //________________________________________________________________
525 void AliADCalibData::SetMatchWindow(UInt_t *windows)
527 // Set Match window of the HPTDC
528 // The units are 25ns
529 if(windows) for(Int_t b=0; b<kNCIUBoards; b++) SetMatchWindow(windows[b],b);
530 else AliError("Match windows not defined.");
533 //________________________________________________________________
534 void AliADCalibData::SetMatchWindow(UInt_t window, Int_t board)
536 // Set Match window of the HPTDC
537 // The units are 25ns
538 if((board>=0) && (board<kNCIUBoards)){
539 fMatchWindow[board] = window;
540 AliInfo(Form("Match window of board %d set to %d",board,fMatchWindow[board]));
543 AliError(Form("Board %d is not valid",board));
546 //________________________________________________________________
547 void AliADCalibData::SetSearchWindow(UInt_t *windows)
549 // Set Search window of the HPTDC
550 // The units are 25ns
551 if(windows) for(Int_t b=0; b<kNCIUBoards; b++) SetSearchWindow(windows[b],b);
552 else AliError("Search windows not defined.");
555 //________________________________________________________________
556 void AliADCalibData::SetSearchWindow(UInt_t window, Int_t board)
558 // Set Search window of the HPTDC
559 // The units are 25ns
560 if((board>=0) && (board<kNCIUBoards)){
561 fSearchWindow[board] = window;
562 AliInfo(Form("Search window of board %d set to %d",board,fSearchWindow[board]));
565 AliError(Form("Board %d is not valid",board));
568 //________________________________________________________________
569 void AliADCalibData::SetTriggerCountOffset(UInt_t *offsets)
571 // Set trigger-count offset of the HPTDC
572 // The units are 25ns
573 if(offsets) for(Int_t b=0; b<kNCIUBoards; b++) SetTriggerCountOffset(offsets[b],b);
574 else AliError("Trigger count offsets not defined.");
577 //________________________________________________________________
578 void AliADCalibData::SetTriggerCountOffset(UInt_t offset, Int_t board)
580 // Set trigger-count offsets of the HPTDC
581 // The units are 25ns
582 if((board>=0) && (board<kNCIUBoards)){
583 fTriggerCountOffset[board] = offset;
584 AliInfo(Form("Trigger-count offset of board %d set to %d",board,fTriggerCountOffset[board]));
587 AliError(Form("Board %d is not valid",board));
590 //________________________________________________________________
591 void AliADCalibData::SetRollOver(UInt_t *offsets)
593 // Set Roll-over of the HPTDC
594 // The units are 25ns
595 if(offsets) for(Int_t b=0; b<kNCIUBoards; b++) SetRollOver(offsets[b],b);
596 else AliError("Roll-over offsets not defined.");
599 //________________________________________________________________
600 void AliADCalibData::SetRollOver(UInt_t offset, Int_t board)
602 // Set Roll-over of the HPTDC
603 // The units are 25ns
604 if((board>=0) && (board<kNCIUBoards)){
605 fRollOver[board] = offset;
606 AliInfo(Form("Roll-over offset of board %d set to %d",board,fRollOver[board]));
609 AliError(Form("Board %d is not valid",board));
612 //________________________________________________________________
613 void AliADCalibData::SetDiscriThr(Float_t thr, Int_t board, Int_t channel)
615 // Set the TDC discriminator
616 // threshold values expressed in units of ADC
617 Int_t ch = AliADCalibData::GetOfflineChannelNumber(board,channel);
621 AliInfo(Form("Discriminator threshold for channel %d set to %f",ch,fDiscriThr[ch]));
624 AliWarning(Form("Ignore wrong threshold value (%f) for channel %d !",thr,ch));
628 AliError("Board/Channel numbers are not valid");
631 //________________________________________________________________
632 void AliADCalibData::SetDiscriThr(const Float_t* thresholds)
634 // Set the TDC discriminator
635 // threshold values expressed in units of ADC
636 if(thresholds) for(int t=0; t<16; t++) fDiscriThr[t] = thresholds[t];
637 else for(int t=0; t<16; t++) fDiscriThr[t] = 2.5;
640 //________________________________________________________________
641 Int_t AliADCalibData::GetOfflineChannelNumber(Int_t board, Int_t channel)
643 // Get the offline channel number from
644 // the FEE board and channel indexes
646 if (board < 0 || board >= 2) {
647 AliErrorClass(Form("Wrong FEE board number: %d",board));
650 if (channel < 0 || channel >= 8) {
651 AliErrorClass(Form("Wrong FEE channel number: %d",channel));
655 Int_t offCh = (board+1)*channel;
659 //________________________________________________________________
660 Int_t AliADCalibData::GetFEEChannelNumber(Int_t channel)
662 // Get FEE channel number
663 // from offline channel index
664 if (channel >= 0 && channel < 16) return ((channel % 8));
666 AliErrorClass(Form("Wrong channel index: %d",channel));