CMS 3D CMS Logo

CastorSimpleRecAlgo.cc

Go to the documentation of this file.
00001 #include "RecoLocalCalo/CastorReco/interface/CastorSimpleRecAlgo.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include "CalibCalorimetry/CastorCalib/interface/CastorTimeSlew.h"
00004 #include <algorithm> // for "max"
00005 #include <math.h>
00006 
00007 static double MaximumFractionalError = 0.0005; // 0.05% error allowed from this source
00008 
00009 CastorSimpleRecAlgo::CastorSimpleRecAlgo(int firstSample, int samplesToAdd, bool correctForTimeslew, bool correctForPulse, float phaseNS) : 
00010   firstSample_(firstSample), 
00011   samplesToAdd_(samplesToAdd), 
00012   correctForTimeslew_(correctForTimeslew) {
00013   if (correctForPulse) 
00014     pulseCorr_=std::auto_ptr<CastorPulseContainmentCorrection>(new CastorPulseContainmentCorrection(samplesToAdd_,phaseNS,MaximumFractionalError));
00015 }
00016 
00017 CastorSimpleRecAlgo::CastorSimpleRecAlgo(int firstSample, int samplesToAdd) : 
00018   firstSample_(firstSample), 
00019   samplesToAdd_(samplesToAdd), 
00020   correctForTimeslew_(false) {
00021 }
00022 
00028 //static float timeshift_ns_hbheho(float wpksamp);
00029 
00031 static float timeshift_ns_hf(float wpksamp);
00032 
00033 
00034 namespace CastorSimpleRecAlgoImpl {
00035   template<class Digi, class RecHit>
00036   inline RecHit reco(const Digi& digi, const CastorCoder& coder, const CastorCalibrations& calibs, 
00037                      int ifirst, int n, bool slewCorrect, const CastorPulseContainmentCorrection* corr, CastorTimeSlew::BiasSetting slewFlavor) {
00038     CaloSamples tool;
00039     coder.adc2fC(digi,tool);
00040 
00041     double ampl=0; int maxI = -1; double maxA = -1e10; float ta=0;
00042     double fc_ampl=0;
00043     for (int i=ifirst; i<tool.size() && i<n+ifirst; i++) {
00044       int capid=digi[i].capid();
00045       ta = (tool[i]-calibs.pedestal(capid)); // pedestal subtraction
00046       fc_ampl+=ta; 
00047       ta*=calibs.gain(capid); // fC --> GeV
00048       ampl+=ta;
00049       if(ta>maxA){
00050         maxA=ta;
00051         maxI=i;
00052       }
00053     }
00054 
00055     float time=-9999;
00057     if(maxI==0 || maxI==(tool.size()-1)) {      
00058       edm::LogWarning("HCAL/CASTOR Pulse") << "CastorSimpleRecAlgo::reconstruct :" 
00059                                                << " Invalid max amplitude position, " 
00060                                                << " max Amplitude: "<< maxI
00061                                                << " first: "<<ifirst
00062                                                << " last: "<<(tool.size()-1)
00063                                                << std::endl;
00064     } else {
00065       maxA=fabs(maxA);
00066       int capid=digi[maxI-1].capid();
00067       float t0 = fabs((tool[maxI-1]-calibs.pedestal(capid))*calibs.gain(capid));
00068       capid=digi[maxI+1].capid();
00069       float t2 = fabs((tool[maxI+1]-calibs.pedestal(capid))*calibs.gain(capid));    
00070       float wpksamp = (t0 + maxA + t2);
00071       if (wpksamp!=0) wpksamp=(maxA + 2.0*t2) / wpksamp; 
00072       time = (maxI - digi.presamples())*25.0 + timeshift_ns_hf(wpksamp);
00073 
00074       if (corr!=0) {
00075         // Apply phase-based amplitude correction:
00076         ampl *= corr->getCorrection(fc_ampl);
00077         //      std::cout << fc_ampl << " --> " << corr->getCorrection(fc_ampl) << std::endl;
00078       }
00079 
00080     
00081       if (slewCorrect) time-=CastorTimeSlew::delay(std::max(1.0,fc_ampl),slewFlavor);
00082     }
00083     return RecHit(digi.id(),ampl,time);    
00084   }
00085 }
00086 
00087 CastorRecHit CastorSimpleRecAlgo::reconstruct(const CastorDataFrame& digi, const CastorCoder& coder, const CastorCalibrations& calibs) const {
00088   return CastorSimpleRecAlgoImpl::reco<CastorDataFrame,CastorRecHit>(digi,coder,calibs,
00089                                                              firstSample_,samplesToAdd_,false,
00090                                                              0,
00091                                                              CastorTimeSlew::Fast);
00092 }
00093 
00094 // timeshift implementation
00095 
00096 static const float wpksamp0_hf = 0.500635;
00097 static const float scale_hf    = 0.999301;
00098 static const int   num_bins_hf = 100;
00099 
00100 static const float actual_ns_hf[num_bins_hf] = {
00101  0.00000, // 0.000-0.010
00102  0.03750, // 0.010-0.020
00103  0.07250, // 0.020-0.030
00104  0.10750, // 0.030-0.040
00105  0.14500, // 0.040-0.050
00106  0.18000, // 0.050-0.060
00107  0.21500, // 0.060-0.070
00108  0.25000, // 0.070-0.080
00109  0.28500, // 0.080-0.090
00110  0.32000, // 0.090-0.100
00111  0.35500, // 0.100-0.110
00112  0.39000, // 0.110-0.120
00113  0.42500, // 0.120-0.130
00114  0.46000, // 0.130-0.140
00115  0.49500, // 0.140-0.150
00116  0.53000, // 0.150-0.160
00117  0.56500, // 0.160-0.170
00118  0.60000, // 0.170-0.180
00119  0.63500, // 0.180-0.190
00120  0.67000, // 0.190-0.200
00121  0.70750, // 0.200-0.210
00122  0.74250, // 0.210-0.220
00123  0.78000, // 0.220-0.230
00124  0.81500, // 0.230-0.240
00125  0.85250, // 0.240-0.250
00126  0.89000, // 0.250-0.260
00127  0.92750, // 0.260-0.270
00128  0.96500, // 0.270-0.280
00129  1.00250, // 0.280-0.290
00130  1.04250, // 0.290-0.300
00131  1.08250, // 0.300-0.310
00132  1.12250, // 0.310-0.320
00133  1.16250, // 0.320-0.330
00134  1.20500, // 0.330-0.340
00135  1.24500, // 0.340-0.350
00136  1.29000, // 0.350-0.360
00137  1.33250, // 0.360-0.370
00138  1.38000, // 0.370-0.380
00139  1.42500, // 0.380-0.390
00140  1.47500, // 0.390-0.400
00141  1.52500, // 0.400-0.410
00142  1.57750, // 0.410-0.420
00143  1.63250, // 0.420-0.430
00144  1.69000, // 0.430-0.440
00145  1.75250, // 0.440-0.450
00146  1.82000, // 0.450-0.460
00147  1.89250, // 0.460-0.470
00148  1.97500, // 0.470-0.480
00149  2.07250, // 0.480-0.490
00150  2.20000, // 0.490-0.500
00151 19.13000, // 0.500-0.510
00152 21.08750, // 0.510-0.520
00153 21.57750, // 0.520-0.530
00154 21.89000, // 0.530-0.540
00155 22.12250, // 0.540-0.550
00156 22.31000, // 0.550-0.560
00157 22.47000, // 0.560-0.570
00158 22.61000, // 0.570-0.580
00159 22.73250, // 0.580-0.590
00160 22.84500, // 0.590-0.600
00161 22.94750, // 0.600-0.610
00162 23.04250, // 0.610-0.620
00163 23.13250, // 0.620-0.630
00164 23.21500, // 0.630-0.640
00165 23.29250, // 0.640-0.650
00166 23.36750, // 0.650-0.660
00167 23.43750, // 0.660-0.670
00168 23.50500, // 0.670-0.680
00169 23.57000, // 0.680-0.690
00170 23.63250, // 0.690-0.700
00171 23.69250, // 0.700-0.710
00172 23.75000, // 0.710-0.720
00173 23.80500, // 0.720-0.730
00174 23.86000, // 0.730-0.740
00175 23.91250, // 0.740-0.750
00176 23.96500, // 0.750-0.760
00177 24.01500, // 0.760-0.770
00178 24.06500, // 0.770-0.780
00179 24.11250, // 0.780-0.790
00180 24.16000, // 0.790-0.800
00181 24.20500, // 0.800-0.810
00182 24.25000, // 0.810-0.820
00183 24.29500, // 0.820-0.830
00184 24.33750, // 0.830-0.840
00185 24.38000, // 0.840-0.850
00186 24.42250, // 0.850-0.860
00187 24.46500, // 0.860-0.870
00188 24.50500, // 0.870-0.880
00189 24.54500, // 0.880-0.890
00190 24.58500, // 0.890-0.900
00191 24.62500, // 0.900-0.910
00192 24.66500, // 0.910-0.920
00193 24.70250, // 0.920-0.930
00194 24.74000, // 0.930-0.940
00195 24.77750, // 0.940-0.950
00196 24.81500, // 0.950-0.960
00197 24.85250, // 0.960-0.970
00198 24.89000, // 0.970-0.980
00199 24.92750, // 0.980-0.990
00200 24.96250, // 0.990-1.000
00201 };
00202 
00203 
00204 float timeshift_ns_hf(float wpksamp) {
00205   float flx = (num_bins_hf*(wpksamp - wpksamp0_hf)/scale_hf);
00206   int index = (int)flx;
00207   float yval;
00208   
00209   if      (index <    0)        return actual_ns_hf[0];
00210   else if (index >= num_bins_hf-1) return actual_ns_hf[num_bins_hf-1];
00211 
00212   // else interpolate:
00213   float y1       = actual_ns_hf[index];
00214   float y2       = actual_ns_hf[index+1];
00215 
00216   // float delta_x  = 1/(float)num_bins_hf;
00217   // yval = y1 + (y2-y1)*(flx-(float)index)/delta_x;
00218 
00219   yval = y1 + (y2-y1)*(flx-(float)index);
00220   return yval;
00221 }

Generated on Tue Jun 9 17:43:44 2009 for CMSSW by  doxygen 1.5.4