+ // loop over path segments, init. some variables.
+ depEnergy /= nOfSplits;
+ nOfSplitsF = (Float_t) nOfSplits;
+ for(kk=0;kk<nOfSplits;kk++) { // loop over path segments
+ kkF = (Float_t) kk + 0.5;
+ avDrft = xL[0]+dxL[0]*kkF/nOfSplitsF;
+ avAnode = xL[2]+dxL[2]*kkF/nOfSplitsF;
+ driftPath = 10000.*avDrft;
+
+ iWing = 2; // Assume wing is 2
+ if(driftPath < 0) { // if wing is not 2 it is 1.
+ iWing = 1;
+ driftPath = -driftPath;
+ } // end if driftPath < 0
+ driftPath = sddLength-driftPath;
+ detector = 2*(hitDetector-1) + iWing;
+ if(driftPath < 0) {
+ Warning("HitsToAnalogDigits","negative drift path "
+ "driftPath=%e sddLength=%e avDrft=%e dxL[0]=%e "
+ "xL[0]=%e",driftPath,sddLength,avDrft,dxL[0],xL[0]);
+ continue;
+ } // end if driftPath < 0
+
+ // Drift Time
+ drTime = driftPath/driftSpeed; // drift time for segment.
+ timeSample = (Int_t) (fScaleSize*drTime/timeStep + 1);
+ // compute time Sample including tof information. The tof only
+ // effects the time of the signal is recoreded and not the
+ // the defusion.
+ // timeSample = (Int_t) (fScaleSize*(drTime+tof)/timeStep + 1);
+ if(timeSample > fScaleSize*fMaxNofSamples) {
+ Warning("HItsToAnalogDigits","Wrong Time Sample: %e",
+ timeSample);
+ continue;
+ } // end if timeSample > fScaleSize*fMaxNoofSamples
+
+ // Anode
+ xAnode = 10000.*(avAnode)/anodePitch + nofAnodes/2; // +1?
+ if(xAnode*anodePitch > sddWidth || xAnode*anodePitch < 0.)
+ Warning("HitsToAnalogDigits",
+ "Exceedubg sddWidth=%e Z = %e",
+ sddWidth,xAnode*anodePitch);
+ iAnode = (Int_t) (1.+xAnode); // xAnode?
+ if(iAnode < 1 || iAnode > nofAnodes) {
+ Warning("HitToAnalogDigits","Wrong iAnode: 1<%d>%d",
+ iAnode,nofAnodes);
+ continue;
+ } // end if iAnode < 1 || iAnode > nofAnodes
+
+ // store straight away the particle position in the array
+ // of particles and take idhit=ii only when part is entering (this
+ // requires FillModules() in the macro for analysis) :
+
+ // Sigma along the anodes for track segment.
+ sigA = TMath::Sqrt(2.*dfCoeff*drTime+s1*s1);
+ sigT = sigA/driftSpeed;
+ // Peak amplitude in nanoAmpere
+ amplitude = fScaleSize*160.*depEnergy/
+ (timeStep*eVpairs*2.*acos(-1.)*sigT*sigA);
+ amplitude *= timeStep/25.; // WARNING!!!!! Amplitude scaling to
+ // account for clock variations
+ // (reference value: 40 MHz)
+ chargeloss = 1.-cHloss*driftPath/1000;
+ amplitude *= chargeloss;
+ width = 2.*nsigma/(nlookups-1);
+ // Spread the charge
+ // Pixel index
+ ndiv = 2;
+ nmul = 3.;
+ if(drTime > 1200.) {
+ ndiv = 4;
+ nmul = 1.5;
+ } // end if drTime > 1200.
+ // Sub-pixel index
+ nsplit = 4; // hard-wired //nsplit=4;nsplit = (nsplit+1)/2*2;
+ // Sub-pixel size see computation of aExpo and tExpo.
+ aStep = anodePitch/(nsplit*fScaleSize*sigA);
+ aConst = xAnode*anodePitch/sigA;
+ tStep = timeStep/(nsplit*fScaleSize*sigT);
+ tConst = drTime/sigT;
+ // Define SDD window corresponding to the hit
+ anodeWindow = (Int_t)(fScaleSize*nsigma*sigA/anodePitch+1);
+ timeWindow = (Int_t) (fScaleSize*nsigma*sigT/timeStep+1.);
+ jamin = (iAnode - anodeWindow/ndiv - 1)*fScaleSize*nsplit +1;
+ jamax = (iAnode + anodeWindow/ndiv)*fScaleSize*nsplit;
+ if(jamin <= 0) jamin = 1;
+ if(jamax > fScaleSize*nofAnodes*nsplit)
+ jamax = fScaleSize*nofAnodes*nsplit;
+ // jtmin and jtmax are Hard-wired
+ jtmin = (Int_t)(timeSample-timeWindow*nmul-1)*nsplit+1;
+ jtmax = (Int_t)(timeSample+timeWindow*nmul)*nsplit;
+ if(jtmin <= 0) jtmin = 1;
+ if(jtmax > fScaleSize*fMaxNofSamples*nsplit)
+ jtmax = fScaleSize*fMaxNofSamples*nsplit;
+ // Spread the charge in the anode-time window
+ for(ka=jamin; ka <=jamax; ka++) {
+ ia = (ka-1)/(fScaleSize*nsplit) + 1;
+ if(ia <= 0) {
+ Warning("HitsToAnalogDigits","ia < 1: ");
+ continue;
+ } // end if
+ if(ia > nofAnodes) ia = nofAnodes;
+ aExpo = (aStep*(ka-0.5)-aConst);
+ if(TMath::Abs(aExpo) > nsigma) anodeAmplitude = 0.;
+ else {
+ dummy = (Int_t) ((aExpo+nsigma)/width);
+ anodeAmplitude = amplitude*fResponse->GausLookUp(dummy);
+ } // end if TMath::Abs(aEspo) > nsigma
+ // index starts from 0
+ index = ((detector+1)%2)*nofAnodes+ia-1;
+ if(anodeAmplitude) for(kt=jtmin; kt<=jtmax; kt++) {
+ it = (kt-1)/nsplit+1; // it starts from 1
+ if(it<=0){
+ Warning("HitsToAnalogDigits","it < 1:");
+ continue;
+ } // end if
+ if(it>fScaleSize*fMaxNofSamples)
+ it = fScaleSize*fMaxNofSamples;
+ tExpo = (tStep*(kt-0.5)-tConst);
+ if(TMath::Abs(tExpo) > nsigma) timeAmplitude = 0.;
+ else {
+ dummy = (Int_t) ((tExpo+nsigma)/width);
+ timeAmplitude = anodeAmplitude*
+ fResponse->GausLookUp(dummy);
+ } // end if TMath::Abs(tExpo) > nsigma
+ // build the list of digits for this module
+ arg[0] = index;
+ arg[1] = it;
+ arg[2] = itrack; // track number
+ arg[3] = ii-1; // hit number.
+ timeAmplitude *= norm;
+ timeAmplitude *= 10;
+ ListOfFiredCells(arg,timeAmplitude,alst,padr);
+ pList->AddSignal(index,it,itrack,ii-1,
+ mod->GetIndex(),timeAmplitude);
+ } // end if anodeAmplitude and loop over time in window
+ } // loop over anodes in window
+ } // end loop over "sub-hits"
+ } // end loop over hits