+Int_t AliVZERODigitizer::Cell2Pmt(Int_t cell) const
+{
+ // The method maps the scintillator
+ // indexes to the PM ones
+ if (cell < 0 || cell >= 80) {
+ AliError(Form("Wrong VZERO cell index %d",cell));
+ return -1;
+ }
+ if (cell < 16) return cell;
+ if (cell < 48) return 8 + cell/2;
+ return cell - 16;
+}
+
+void AliVZERODigitizer::DigitizeHits()
+{
+ // Digitize the hits to the level of
+ // SDigits (fTime arrays)
+
+ for(Int_t i = 0 ; i < 64; ++i) {
+ memset(fTime[i],0,fNBins[i]*sizeof(Float_t));
+ fLabels[i][0] = fLabels[i][1] = fLabels[i][2] = -1;
+ }
+ Float_t integral = fPMResponse->Integral(-kPMRespTime,2.*kPMRespTime);
+ Float_t meansPhE = fSinglePhESpectrum->Mean(0,20);
+
+ AliLoader* loader = fVZERO->GetLoader();
+ if (!loader) {
+ AliError("Can not get VZERO Loader!");
+ return;
+ }
+ loader->LoadHits();
+ TTree* treeH = loader->TreeH();
+ if (!treeH) {
+ AliError("Cannot get TreeH!");
+ return;
+ }
+ TClonesArray* hits = fVZERO->Hits();
+
+// Now makes Digits from hits
+ Int_t nTracks = (Int_t) treeH->GetEntries();
+ for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
+ fVZERO->ResetHits();
+ treeH->GetEvent(iTrack);
+ Int_t nHits = hits->GetEntriesFast();
+ for (Int_t iHit = 0; iHit < nHits; iHit++) {
+ AliVZEROhit* hit = (AliVZEROhit *)hits->UncheckedAt(iHit);
+ Int_t nPhot = hit->Nphot();
+ Int_t cell = hit->Cell();
+ Int_t pmt = Cell2Pmt(cell);
+ if (pmt < 0) continue;
+ Int_t trackLabel = hit->GetTrack();
+ for(Int_t l = 0; l < 3; ++l) {
+ if (fLabels[pmt][l] < 0) {
+ fLabels[pmt][l] = trackLabel;
+ break;
+ }
+ }
+ Float_t dt_scintillator = gRandom->Gaus(0,kIntTimeRes);
+ Float_t t = dt_scintillator + 1e9*hit->Tof();
+ if (pmt < 32) t += kV0CDelayCables;
+ t += fHptdcOffset[pmt];
+ Int_t nPhE;
+ Float_t prob = fCalibData->GetLightYields(pmt)*fPhotoCathodeEfficiency; // Optical losses included!
+ if (nPhot > 100)
+ nPhE = (Int_t)gRandom->Gaus(prob*Float_t(nPhot)+0.5,
+ sqrt(Float_t(nPhot)*prob*(1.-prob)));
+ else
+ nPhE = gRandom->Binomial(nPhot,prob);
+ Float_t charge = TMath::Qe()*fPmGain[pmt]*fBinSize[pmt]/integral;
+ for (Int_t iPhE = 0; iPhE < nPhE; ++iPhE) {
+ Float_t tPhE = t + fSignalShape->GetRandom(0,fBinSize[pmt]*Float_t(fNBins[pmt]));
+ Float_t gainVar = fSinglePhESpectrum->GetRandom(0,20)/meansPhE;
+ Int_t firstBin = TMath::Max(0,(Int_t)((tPhE-kPMRespTime)/fBinSize[pmt]));
+ Int_t lastBin = TMath::Min(fNBins[pmt]-1,(Int_t)((tPhE+2.*kPMRespTime)/fBinSize[pmt]));
+ for(Int_t iBin = firstBin; iBin <= lastBin; ++iBin) {
+ Float_t tempT = fBinSize[pmt]*(0.5+iBin)-tPhE;
+ fTime[pmt][iBin] += gainVar*charge*fPMResponse->Eval(tempT);
+ }
+ } // ph.e. loop
+ } // hit loop
+ } // track loop
+ loader->UnloadHits();
+}
+
+
+void AliVZERODigitizer::DigitizeSDigits()
+{
+ // Digitize the fTime arrays (SDigits) to the level of
+ // Digits (fAdc arrays)
+ for(Int_t i = 0 ; i < 64; ++i) {
+ for(Int_t j = 0; j < kNClocks; ++j) fAdc[i][j] = 0;
+ fLeadingTime[i] = fTimeWidth[i] = 0;
+ }
+
+ Float_t maximum = 0.9*fSignalShape->GetMaximum(0,200); // Not exact, one needs to do this on the convoluted
+ Float_t integral2 = fSignalShape->Integral(0,200); // function. Anyway the effect is small <10% on the 2.5 ADC thr
+ for (Int_t ipmt = 0; ipmt < 64; ++ipmt) {
+ Float_t thr = fCalibData->GetCalibDiscriThr(ipmt,kFALSE)*kChargePerADC*maximum*fBinSize[ipmt]/integral2;
+ Bool_t ltFound = kFALSE, ttFound = kFALSE;
+ for (Int_t iBin = 0; iBin < fNBins[ipmt]; ++iBin) {
+ Float_t t = fBinSize[ipmt]*Float_t(iBin);
+ if (fTime[ipmt][iBin] > thr) {
+ if (!ltFound && (iBin < fNBinsLT[ipmt])) {
+ ltFound = kTRUE;
+ fLeadingTime[ipmt] = t;
+ }
+ }
+ else {
+ if (ltFound) {
+ if (!ttFound) {
+ ttFound = kTRUE;
+ fTimeWidth[ipmt] = t - fLeadingTime[ipmt];
+ }
+ }
+ }
+ Float_t tadc = t - fClockOffset[ipmt];
+ Int_t clock = kNClocks/2 - Int_t(tadc/25.0);
+ if (clock >= 0 && clock < kNClocks)
+ fAdc[ipmt][clock] += fTime[ipmt][iBin]/kChargePerADC;
+ }
+ AliDebug(1,Form("Channel %d Offset %f Time %f",ipmt,fClockOffset[ipmt],fLeadingTime[ipmt]));
+ Int_t board = AliVZEROCalibData::GetBoardNumber(ipmt);
+ if (ltFound && ttFound) {
+ fTimeWidth[ipmt] = fCalibData->GetWidthResolution(board)*
+ Float_t(Int_t(fTimeWidth[ipmt]/fCalibData->GetWidthResolution(board)));
+ if (fTimeWidth[ipmt] < Float_t(kMinTDCWidth)*fCalibData->GetWidthResolution(board))
+ fTimeWidth[ipmt] = Float_t(kMinTDCWidth)*fCalibData->GetWidthResolution(board);
+ if (fTimeWidth[ipmt] > Float_t(kMaxTDCWidth)*fCalibData->GetWidthResolution(board))
+ fTimeWidth[ipmt] = Float_t(kMaxTDCWidth)*fCalibData->GetWidthResolution(board);
+ }
+ }
+
+ fEvenOrOdd = gRandom->Integer(2);
+ for (Int_t j=0; j<64; ++j){
+ for (Int_t iClock = 0; iClock < kNClocks; ++iClock) {
+ Int_t integrator = (iClock + fEvenOrOdd) % 2;
+ AliDebug(1,Form("ADC %d %d %f",j,iClock,fAdc[j][iClock]));
+ fAdc[j][iClock] += gRandom->Gaus(fAdcPedestal[j][integrator], fAdcSigma[j][integrator]);
+ }
+ }
+
+}