subroutine emEnergyCorrection(EeCorr, + SigEeCorr, dCellGap, dModGap, + Ee, HiCell, Pos, UseTrk, zVtx) c c output: c EeCorr(1) = Electron energy corrected for dead material c EeCorr(2) = same as EeCorr(1) for FCal/BCal c presampler correction for RCal c EeCorr(3) = EeCorr(2) also corrected for nonuniformities c SigEeCorr = the error on EeCorr(3) c dCellGap = distance to the cell edge (cm) c dModGap = distance to the module edge (cm) c c input: c Ee = energy (no corrections except CalCorr) c HiCell = cell number of highest energy cell c Pos = track or Cal position (UseTrk=.true. or .false.) c UseTrk = true if position is measured by track c zVtx = z of the CTD vertex c implicit none #include "partap.inc" #include "fmckin.inc" #include "zrevt.inc" #include "zdskey.inc" #include "empar.inc" integer CentralTile, k, fbr, HiCell, iErr, Year logical MonteCarlo, UseTrk, UsePresampler c real Dir(3), dModGap, dCellGap, + Ee, EeCorr(nEeCorr), EeCorrBCal, EeNoCorr, + Theta, Phi, zVtx, Pos(3), hiPos(3), + PresamplerEnergy(3), PreviousBCALFactor, + R, R_Dead, R_Cell_Crack, R_Modu_Crack, SigEeCorr, ShowerMax(3), + X0, xy(2), zFFace, zRFace, + FCal_Modu_MC, FCal_Modu_TB, FCal_Cell_TB, FCal_Spacer_TB, + FCal_Modu_Res_MC, FCal_Res_TB, xAngle c parameter (zFFace=222.0, zRFace=-152.1) data PreviousBCALFactor/0.0/ c MonteCarlo = (CouTab(FMCKin).gt.0) call emCheckCaltruFactors(MonteCarlo) if (emCaltruFactor(2) .ne. PreviousBCALFactor) then call EeCorrBCalInitEAZE(2, emCaltruFactor(2)) PreviousBCALFactor = emCaltruFactor(2) end if Year = mod(ZREVT_time(1)/10000, 100) c c compute direction cosines Dir(1) = Pos(1) Dir(2) = Pos(2) Dir(3) = Pos(3) - zVtx R = Sqrt(Dir(1)**2 + Dir(2)**2 + Dir(3)**2) do k = 1, 3 Dir(k) = Dir(k)/ R end do c Theta = acos(Dir(3)) Phi = atan2(Dir(2),Dir(1)) c c correct electron energy for dead material based on MC X0 map. CALL DeadCor(zVtx, Theta, Phi, Ee, Year, X0, R_Dead) EeCorr(1) = Ee/ R_Dead c FBR = 1 + HiCell/16384 call CCCxyz(HiCell, hiPos(1),hiPos(2),hiPos(3),iErr) if (iErr .ne. 0) then print *,HiCell stop 'emEnergyCorrection: CCCxyz' end if c c apply cell and module gap correction here EeCorr(2) = EeCorr(1) c.......................................................................... if (FBR .eq. 1) then c FCAL call FRdGap(dModGap, dCellGap, hiCell, hiPos, Pos) do k = 1, 2 xy(k) = Pos(k) * (zFFace-zVtx)/(Pos(3)-zVtx) end do c xAngle = atan(xy(1)/(zFFace-zVtx)) c if (MonteCarlo) then R_Cell_Crack = 1.0 R_Modu_Crack = 1.0/FCal_Modu_mc(xy(1)) else R_Cell_Crack = 1.0/ + (FCal_Cell_TB(xy(1),xy(2)) * FCal_Spacer_TB(xy(2))) R_Modu_Crack = 1.0/ FCal_Modu_TB(dModGap, abs(xAngle)) end if EeCorr(3) = EeCorr(2)/(R_Cell_Crack*R_Modu_Crack) SigEeCorr = 0.25 * sqrt(EeCorr(3)) c.......................................................................... else if (FBR .eq. 2) then c New BCAL Nonuniformity Correction EeCorr(3) = EeCorrBCal(Ee, R_Dead, X0, Pos, Dir, + ShowerMax, dCellGap, dModGap, + R_Cell_Crack, R_Modu_Crack, SigEeCorr) c.......................................................................... else if (FBR .eq. 3) then c RCAL if (MonteCarlo) then UsePreSampler = (Year.ge.95 .or. Year.lt.50) else call PresTake(ZDSKey_Nr1, k) UsePreSampler = (k.eq.0 .or. k.eq.2) end if c if (UsePreSampler) then call PrCalib(k) UsePreSampler = (k.eq.0) end if c if (UsePreSampler) then call PrClus(Pos, zVtx, PresamplerEnergy, CentralTile, k) UsePreSampler = (k.eq.0) end if c if (UsePreSampler) then EeNoCorr = Ee / emCaltruFactor(3) if (MonteCarlo) then call prcorr_3_mc(X0, EeNoCorr, PresamplerEnergy,EeCorr(2),k) else call prcorr_3 (X0, EeNoCorr, PresamplerEnergy,EeCorr(2),k) end if end if c call FRdGap(dModGap, dCellGap, hiCell, hiPos, Pos) c RCAL - No non-uniformity corrections yet EeCorr(3) = EeCorr(2) SigEeCorr = 0.25 * sqrt(EeCorr(3)) end if c.......................................................................... end