+// Now builds the scintillator cell response (80 cells i.e. 80 responses)
+
+ for (Int_t i=0; i<80; i++) {
+ Float_t q1 = Float_t ( map[i] )* cPM[i] * kQe;
+ Float_t noise = gRandom->Gaus(10.5,3.22);
+ Float_t pmResponse = q1/kC*TMath::Power(ktheta/kthau,1/(1-ktheta/kthau))
+ + noise*1e-3;
+ map[i] = Int_t( pmResponse * adc_gain[i]);
+ if(map[i] > (110/2)) {map[i] = Int_t(gRandom->Gaus(map[i], 110/6));}
+ }
+
+// Now transforms 80 cell responses into 64 photomultiplier responses
+// Also adds the ADC pedestals taken out of the calibration data base
+
+ for (Int_t j=0; j<16; j++){
+ adc[j] = static_cast<Int_t>(map [j] + gRandom->Gaus(adc_pedestal[j], adc_sigma[j]));
+ time2[j]= time[j];}
+
+ for (Int_t j=48; j<80; j++){
+ adc[j-16] = static_cast<Int_t>(map [j]
+ + gRandom->Gaus(adc_pedestal[j-16],adc_sigma[j-16]));
+ time2[j-16]= time[j]; }
+
+ for (Int_t j=0; j<16; j++){
+ adc[16+j] = static_cast<Int_t>(map [16+2*j]+ map [16+2*j+1]
+ + gRandom->Gaus(adc_pedestal[16+j], adc_sigma[16+j]));
+ Float_t min_time = TMath::Min(time [16+2*j],time [16+2*j+1]);
+ time2[16+j] = min_time;
+ if(min_time==0.0){time2[16+j]=TMath::Max(time[16+2*j],time[16+2*j+1]);}
+ }
+
+
+// Now add digits to the digit Tree
+
+ for (Int_t i=0; i<64; i++) {
+ if(adc[i] > 0) {
+// printf(" Event, cell, adc, tof = %d %d %d %f\n",
+// outRunLoader->GetEventNumber(),i, map[i], time2[i]*10.0);
+// multiply by 10 to have 100 ps per channel :
+ AddDigit(i, adc[i], Int_t(time2[i]*10.0)) ;}
+ }
+