+//________________________________________________________________
+void AliVZEROCalibData::SetMatchWindow(UInt_t *windows)
+{
+ // Set Match window of the HPTDC
+ // The units are 25ns
+ if(windows) for(Int_t b=0; b<kNCIUBoards; b++) SetMatchWindow(windows[b],b);
+ else AliError("Match windows not defined.");
+}
+
+//________________________________________________________________
+void AliVZEROCalibData::SetMatchWindow(UInt_t window, Int_t board)
+{
+ // Set Match window of the HPTDC
+ // The units are 25ns
+ if((board>=0) && (board<kNCIUBoards)){
+ fMatchWindow[board] = window;
+ AliInfo(Form("Match window of board %d set to %d",board,fMatchWindow[board]));
+ }
+ else
+ AliError(Form("Board %d is not valid",board));
+}
+
+//________________________________________________________________
+void AliVZEROCalibData::SetSearchWindow(UInt_t *windows)
+{
+ // Set Search window of the HPTDC
+ // The units are 25ns
+ if(windows) for(Int_t b=0; b<kNCIUBoards; b++) SetSearchWindow(windows[b],b);
+ else AliError("Search windows not defined.");
+}
+
+//________________________________________________________________
+void AliVZEROCalibData::SetSearchWindow(UInt_t window, Int_t board)
+{
+ // Set Search window of the HPTDC
+ // The units are 25ns
+ if((board>=0) && (board<kNCIUBoards)){
+ fSearchWindow[board] = window;
+ AliInfo(Form("Search window of board %d set to %d",board,fSearchWindow[board]));
+ }
+ else
+ AliError(Form("Board %d is not valid",board));
+}
+
+//________________________________________________________________
+void AliVZEROCalibData::SetTriggerCountOffset(UInt_t *offsets)
+{
+ // Set trigger-count offset of the HPTDC
+ // The units are 25ns
+ if(offsets) for(Int_t b=0; b<kNCIUBoards; b++) SetTriggerCountOffset(offsets[b],b);
+ else AliError("Trigger count offsets not defined.");
+}
+
+//________________________________________________________________
+void AliVZEROCalibData::SetTriggerCountOffset(UInt_t offset, Int_t board)
+{
+ // Set trigger-count offsets of the HPTDC
+ // The units are 25ns
+ if((board>=0) && (board<kNCIUBoards)){
+ fTriggerCountOffset[board] = offset;
+ AliInfo(Form("Trigger-count offset of board %d set to %d",board,fTriggerCountOffset[board]));
+ }
+ else
+ AliError(Form("Board %d is not valid",board));
+}
+
+//________________________________________________________________
+void AliVZEROCalibData::SetRollOver(UInt_t *offsets)
+{
+ // Set Roll-over of the HPTDC
+ // The units are 25ns
+ if(offsets) for(Int_t b=0; b<kNCIUBoards; b++) SetRollOver(offsets[b],b);
+ else AliError("Roll-over offsets not defined.");
+}
+
+//________________________________________________________________
+void AliVZEROCalibData::SetRollOver(UInt_t offset, Int_t board)
+{
+ // Set Roll-over of the HPTDC
+ // The units are 25ns
+ if((board>=0) && (board<kNCIUBoards)){
+ fRollOver[board] = offset;
+ AliInfo(Form("Roll-over offset of board %d set to %d",board,fRollOver[board]));
+ }
+ else
+ AliError(Form("Board %d is not valid",board));
+}
+
+//________________________________________________________________
+void AliVZEROCalibData::SetDiscriThr(Float_t thr, Int_t board, Int_t channel)
+{
+ // Set the TDC discriminator
+ // threshold values expressed in units of ADC
+ Int_t ch = AliVZEROCalibData::GetOfflineChannelNumber(board,channel);
+ if(ch >= 0){
+ if (thr > 0) {
+ fDiscriThr[ch]=thr;
+ AliInfo(Form("Discriminator threshold for channel %d set to %f",ch,fDiscriThr[ch]));
+ }
+ else {
+ AliWarning(Form("Ignore wrong threshold value (%f) for channel %d !",thr,ch));
+ }
+ }
+ else
+ AliError("Board/Channel numbers are not valid");
+}
+
+//________________________________________________________________
+void AliVZEROCalibData::SetDiscriThr(const Float_t* thresholds)
+{
+ // Set the TDC discriminator
+ // threshold values expressed in units of ADC
+ if(thresholds) for(int t=0; t<64; t++) fDiscriThr[t] = thresholds[t];
+ else for(int t=0; t<64; t++) fDiscriThr[t] = 2.5;
+}
+
+Int_t AliVZEROCalibData::GetOfflineChannelNumber(Int_t board, Int_t channel)
+{
+ // Get the offline channel number from
+ // the FEE board and channel indexes
+
+ if (board < 0 || board >= 8) {
+ AliErrorClass(Form("Wrong FEE board number: %d",board));
+ return -1;
+ }
+ if (channel < 0 || channel >= 8) {
+ AliErrorClass(Form("Wrong FEE channel number: %d",channel));
+ return -1;
+ }
+
+ Int_t offCh = (board < 4) ? (8 * board + 32) : (8 * board -32);
+ offCh += (7 - channel);
+
+ return offCh;
+}
+
+Int_t AliVZEROCalibData::GetBoardNumber(Int_t channel)
+{
+ // Get FEE board number
+ // from offline channel index
+ if (channel >= 0 && channel < 32) return (channel / 8 + 4);
+ if (channel >=32 && channel < 64) return (channel / 8 - 4);
+
+ AliErrorClass(Form("Wrong channel index: %d",channel));
+ return -1;
+}
+
+Int_t AliVZEROCalibData::GetFEEChannelNumber(Int_t channel)
+{
+ // Get FEE channel number
+ // from offline channel index
+ if (channel >= 0 && channel < 64) return (7 - (channel % 8));
+
+ AliErrorClass(Form("Wrong channel index: %d",channel));
+ return -1;
+}
+
+Float_t AliVZEROCalibData::GetLightYields(Int_t channel)
+{
+ // Get the light yield efficiency
+ // for a given channel
+ if (!fLightYields) InitLightYields();
+
+ if (channel >= 0 && channel < 64) {
+ return fLightYields[channel];
+ }
+
+ AliError(Form("Wrong channel index: %d",channel));
+ return 0;
+}
+
+void AliVZEROCalibData::InitLightYields()
+{
+ // Initialize the light yield factors
+ // Read from a separate OCDB entry
+ if (fLightYields) return;
+
+ AliCDBEntry *entry = AliCDBManager::Instance()->Get("VZERO/Calib/LightYields");
+ if (!entry) AliFatal("VZERO light yields are not found in OCDB !");
+ TH1F *yields = (TH1F*)entry->GetObject();
+
+ fLightYields = new Float_t[64];
+ for(Int_t i = 0 ; i < 64; ++i) {
+ fLightYields[i] = yields->GetBinContent(i+1);
+ }
+}
+
+void AliVZEROCalibData::InitPMGains()
+{
+ // Initialize the PM gain factors
+ // Read from a separate OCDB entry
+ if (fPMGainsA) return;
+
+ AliCDBEntry *entry = AliCDBManager::Instance()->Get("VZERO/Calib/PMGains");
+ if (!entry) AliFatal("VZERO PM gains are not found in OCDB !");
+ TH2F *gains = (TH2F*)entry->GetObject();
+
+ fPMGainsA = new Float_t[64];
+ fPMGainsB = new Float_t[64];
+ for(Int_t i = 0 ; i < 64; ++i) {
+ fPMGainsA[i] = gains->GetBinContent(i+1,1);
+ fPMGainsB[i] = gains->GetBinContent(i+1,2);
+ }
+}
+
+Float_t AliVZEROCalibData::GetCalibDiscriThr(Int_t channel, Bool_t scaled)
+{
+ // The method returns actual TDC discri threshold
+ // extracted from the data.
+ //
+ // In case scaled flag is set the threshold is scaled
+ // so that to get 4.0 for a FEE threshold of 4.0.
+ // In this way we avoid a change in the slewing correction
+ // for the entire 2010 p-p data.
+ //
+ // The method is to be moved to OCDB object.
+
+ Float_t thr = GetDiscriThr(channel);
+
+ Float_t calThr = 0;
+ if (thr <= 1.)
+ calThr = 3.1;
+ else if (thr >= 2.)
+ calThr = (3.1+1.15*thr-1.7);
+ else
+ calThr = (3.1-0.3*thr+0.3*thr*thr);
+
+ if (scaled) calThr *= 4./(3.1+1.15*4.-1.7);
+
+ return calThr;
+}