+
+//_____________________________________________________________________________
+void AliTOFDigitizer::InitDecalibration() const {
+ //
+ // Initialize TOF digits decalibration
+ //
+
+ fCalib->CreateCalArrays();
+ fCalib->ReadSimHistoFromCDB("TOF/Calib", -1); // use AliCDBManager's number
+ fCalib->ReadParOfflineFromCDB("TOF/Calib", -1); // use AliCDBManager's number
+}
+//---------------------------------------------------------------------
+void AliTOFDigitizer::DecalibrateTOFSignal(){
+
+ // Read Calibration parameters from the CDB
+
+ TObjArray * calOffline= fCalib->GetTOFCalArrayOffline();
+
+ AliDebug(2,Form("Size of array for Offline Calibration = %i",calOffline->GetEntries()));
+
+ // Initialize Quantities to Simulate ToT Spectra
+
+ TH1F * hToT= fCalib->GetTOFSimToT();
+ Int_t nbins = hToT->GetNbinsX();
+ Float_t delta = hToT->GetBinWidth(1);
+ Float_t maxch = hToT->GetBinLowEdge(nbins)+delta;
+ Float_t minch = hToT->GetBinLowEdge(1);
+ Float_t max=0,min=0; //maximum and minimum value of the distribution
+ Int_t maxbin=0,minbin=0; //maximum and minimum bin of the distribution
+
+ for (Int_t ii=nbins; ii>0; ii--){
+ if (hToT->GetBinContent(ii)!= 0) {
+ max = maxch - (nbins-ii-1)*delta;
+ maxbin = ii;
+ break;}
+ }
+ for (Int_t j=1; j<nbins; j++){
+ if (hToT->GetBinContent(j)!= 0) {
+ min = minch + (j-1)*delta;
+ minbin = j;
+ break;}
+ }
+
+ Float_t maxToT=max;
+ Float_t minToT=min;
+
+ Float_t maxToTDistr=hToT->GetMaximum();
+
+ AliDebug (1, Form(" The minimum ToT = %f", minToT));
+ AliDebug (1, Form(" The maximum ToT = %f", maxToT));
+ AliDebug (1, Form(" The maximum peak in ToT = %f", maxToTDistr));
+
+ // Loop on TOF Digits
+
+ Bool_t isToTSimulated=kFALSE;
+ Bool_t misCalibPars=kFALSE;
+ if(hToT->GetEntries()>0)isToTSimulated=kTRUE;
+ Int_t ndigits = fDigits->GetEntriesFast();
+ for (Int_t i=0;i<ndigits;i++){
+ AliTOFdigit * dig = (AliTOFdigit*)fDigits->At(i);
+ Int_t detId[5];
+ detId[0] = dig->GetSector();
+ detId[1] = dig->GetPlate();
+ detId[2] = dig->GetStrip();
+ detId[3] = dig->GetPadz();
+ detId[4] = dig->GetPadx();
+ dig->SetTdcND(dig->GetTdc()); // save the non decalibrated time
+ if(isToTSimulated){
+
+ //A realistic ToT Spectrum was found in input,
+ //decalibrated TOF Digits likely to be simulated....
+
+ Int_t index = AliTOFGeometry::GetIndex(detId); // The channel index
+ AliTOFChannelOffline *calChannelOffline = (AliTOFChannelOffline *)calOffline->At(index); //retrieve the info for time slewing
+ Double_t par[6]; // time slewing parameters
+
+ //check whether we actually ask for miscalibration
+
+ for (Int_t j = 0; j<6; j++){
+ par[j]=(Double_t)calChannelOffline->GetSlewPar(j);
+ if(par[j]!=0)misCalibPars=kTRUE;
+ }
+ AliDebug(2,Form(" Calib Pars = %f (0-th parameter for time slewing + time delay), %f, %f, %f, %f, %f ",par[0],par[1],par[2],par[3],par[4],par[5]));
+
+ // Now generate Realistic ToT distribution from TestBeam Data.
+ // Tot is in ns, assuming a Matching Window of 10 ns.
+
+ Float_t simToT = 0;
+ Float_t trix = 0;
+ Float_t triy = 0;
+ Double_t timeCorr;
+ Double_t tToT;
+ while (simToT <= triy){
+ trix = gRandom->Rndm(i);
+ triy = gRandom->Rndm(i);
+ trix = (maxToT-minToT)*trix + minToT;
+ triy = maxToTDistr*triy;
+ Int_t binx=hToT->FindBin(trix);
+ simToT=hToT->GetBinContent(binx);
+ }
+ // the generated ToT (ns)
+ tToT= (Double_t) trix; // to apply slewing we start from ns..
+ // transform TOF signal in ns
+ AliDebug(2,Form(" The Initial Time (counts): %i: ",dig->GetTdc()));
+ AliDebug(2,Form(" Time before miscalibration (ps) %e: ",dig->GetTdc()*(Double_t)AliTOFGeometry::TdcBinWidth()));
+ // add slewing effect
+ timeCorr=par[0] + tToT*(par[1] +tToT*(par[2] +tToT*(par[3] +tToT*(par[4] +tToT*par[5]))));
+ AliDebug(2,Form(" The Time slewing + delay (ns): %f: ",timeCorr));
+ // add global time shift
+ //convert to ps
+ timeCorr*=1E3;
+ Double_t timeMis = (Double_t)(dig->GetTdc())*(Double_t)AliTOFGeometry::TdcBinWidth();
+ timeMis = timeMis+timeCorr;
+ AliDebug(2,Form(" The Miscalibrated time (ps): %e: ",timeMis));
+
+ // now update the digit info
+
+ Int_t tdcCorr= (Int_t)(timeMis/AliTOFGeometry::TdcBinWidth());
+ AliDebug(2,Form(" Final Time (counts): %i: ",tdcCorr));
+ // Setting Decalibrated Time signal (TDC counts)
+ dig->SetTdc(tdcCorr);
+ // Setting realistic ToT signal (TDC counts)
+ tToT*=1E3; //back to ps
+ Int_t tot=(Int_t)(tToT/AliTOFGeometry::ToTBinWidth());//(factor 1E3 as input ToT is in ns)
+ dig->SetToT(tot);
+ AliDebug(2,Form(" Final Time and ToT (counts): %d: , %d:",dig->GetTdc(),dig->GetToT()));
+ if(tdcCorr<0){
+ AliWarning (Form(" The bad Slewed Time(TDC counts)= %d ", tdcCorr));
+ AliWarning(Form(" The bad ToT (TDC counts)= %d ", tot));
+ }
+ }
+ else{
+ // For Data with no Miscalibration, set ToT signal == Adc
+ dig->SetToT((Int_t)(dig->GetAdc()/AliTOFGeometry::ToTBinWidth())); //remove the factor 10^3 just to have a reasonable ToT range for raw data simulation even in the case of non-realistic ToT distribution (n.b. fAdc is practically an arbitrary quantity, and ToT has no impact on the TOF reco for non-miscalibrated digits)
+ }
+ }
+
+ if(!isToTSimulated)
+ AliDebug(1,"Standard Production, no miscalibrated digits");
+ else
+ if(!misCalibPars)
+ AliDebug(1,"Standard Production, no miscalibrated digits");
+ else
+ AliDebug(1,"Simulating miscalibrated digits");
+
+ return;
+}
+