CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/RecoLocalCalo/CastorReco/src/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       // supress warning and use dummy time value for 2009 data
00059       /*
00060       edm::LogWarning("HCAL/CASTOR Pulse") << "CastorSimpleRecAlgo::reconstruct :" 
00061                                                << " Invalid max amplitude position, " 
00062                                                << " max Amplitude: "<< maxI
00063                                                << " first: "<<ifirst
00064                                                << " last: "<<(tool.size()-1)
00065                                                << std::endl;
00066     */
00067     } else {
00068       maxA=fabs(maxA);
00069       int capid=digi[maxI-1].capid();
00070       float t0 = fabs((tool[maxI-1]-calibs.pedestal(capid))*calibs.gain(capid));
00071       capid=digi[maxI+1].capid();
00072       float t2 = fabs((tool[maxI+1]-calibs.pedestal(capid))*calibs.gain(capid));    
00073       float wpksamp = (t0 + maxA + t2);
00074       if (wpksamp!=0) wpksamp=(maxA + 2.0*t2) / wpksamp; 
00075       time = (maxI - digi.presamples())*25.0 + timeshift_ns_hf(wpksamp);
00076 
00077       if (corr!=0) {
00078         // Apply phase-based amplitude correction:
00079         ampl *= corr->getCorrection(fc_ampl);
00080         //      std::cout << fc_ampl << " --> " << corr->getCorrection(fc_ampl) << std::endl;
00081       }
00082 
00083     
00084       if (slewCorrect) time-=CastorTimeSlew::delay(std::max(1.0,fc_ampl),slewFlavor);
00085     }
00086     return RecHit(digi.id(),ampl,time);    
00087   }
00088 }
00089 
00090 CastorRecHit CastorSimpleRecAlgo::reconstruct(const CastorDataFrame& digi, const CastorCoder& coder, const CastorCalibrations& calibs) const {
00091   return CastorSimpleRecAlgoImpl::reco<CastorDataFrame,CastorRecHit>(digi,coder,calibs,
00092                                                              firstSample_,samplesToAdd_,false,
00093                                                              0,
00094                                                              CastorTimeSlew::Fast);
00095 }
00096 
00097 // timeshift implementation
00098 
00099 static const float wpksamp0_hf = 0.500635;
00100 static const float scale_hf    = 0.999301;
00101 static const int   num_bins_hf = 100;
00102 
00103 static const float actual_ns_hf[num_bins_hf] = {
00104  0.00000, // 0.000-0.010
00105  0.03750, // 0.010-0.020
00106  0.07250, // 0.020-0.030
00107  0.10750, // 0.030-0.040
00108  0.14500, // 0.040-0.050
00109  0.18000, // 0.050-0.060
00110  0.21500, // 0.060-0.070
00111  0.25000, // 0.070-0.080
00112  0.28500, // 0.080-0.090
00113  0.32000, // 0.090-0.100
00114  0.35500, // 0.100-0.110
00115  0.39000, // 0.110-0.120
00116  0.42500, // 0.120-0.130
00117  0.46000, // 0.130-0.140
00118  0.49500, // 0.140-0.150
00119  0.53000, // 0.150-0.160
00120  0.56500, // 0.160-0.170
00121  0.60000, // 0.170-0.180
00122  0.63500, // 0.180-0.190
00123  0.67000, // 0.190-0.200
00124  0.70750, // 0.200-0.210
00125  0.74250, // 0.210-0.220
00126  0.78000, // 0.220-0.230
00127  0.81500, // 0.230-0.240
00128  0.85250, // 0.240-0.250
00129  0.89000, // 0.250-0.260
00130  0.92750, // 0.260-0.270
00131  0.96500, // 0.270-0.280
00132  1.00250, // 0.280-0.290
00133  1.04250, // 0.290-0.300
00134  1.08250, // 0.300-0.310
00135  1.12250, // 0.310-0.320
00136  1.16250, // 0.320-0.330
00137  1.20500, // 0.330-0.340
00138  1.24500, // 0.340-0.350
00139  1.29000, // 0.350-0.360
00140  1.33250, // 0.360-0.370
00141  1.38000, // 0.370-0.380
00142  1.42500, // 0.380-0.390
00143  1.47500, // 0.390-0.400
00144  1.52500, // 0.400-0.410
00145  1.57750, // 0.410-0.420
00146  1.63250, // 0.420-0.430
00147  1.69000, // 0.430-0.440
00148  1.75250, // 0.440-0.450
00149  1.82000, // 0.450-0.460
00150  1.89250, // 0.460-0.470
00151  1.97500, // 0.470-0.480
00152  2.07250, // 0.480-0.490
00153  2.20000, // 0.490-0.500
00154 19.13000, // 0.500-0.510
00155 21.08750, // 0.510-0.520
00156 21.57750, // 0.520-0.530
00157 21.89000, // 0.530-0.540
00158 22.12250, // 0.540-0.550
00159 22.31000, // 0.550-0.560
00160 22.47000, // 0.560-0.570
00161 22.61000, // 0.570-0.580
00162 22.73250, // 0.580-0.590
00163 22.84500, // 0.590-0.600
00164 22.94750, // 0.600-0.610
00165 23.04250, // 0.610-0.620
00166 23.13250, // 0.620-0.630
00167 23.21500, // 0.630-0.640
00168 23.29250, // 0.640-0.650
00169 23.36750, // 0.650-0.660
00170 23.43750, // 0.660-0.670
00171 23.50500, // 0.670-0.680
00172 23.57000, // 0.680-0.690
00173 23.63250, // 0.690-0.700
00174 23.69250, // 0.700-0.710
00175 23.75000, // 0.710-0.720
00176 23.80500, // 0.720-0.730
00177 23.86000, // 0.730-0.740
00178 23.91250, // 0.740-0.750
00179 23.96500, // 0.750-0.760
00180 24.01500, // 0.760-0.770
00181 24.06500, // 0.770-0.780
00182 24.11250, // 0.780-0.790
00183 24.16000, // 0.790-0.800
00184 24.20500, // 0.800-0.810
00185 24.25000, // 0.810-0.820
00186 24.29500, // 0.820-0.830
00187 24.33750, // 0.830-0.840
00188 24.38000, // 0.840-0.850
00189 24.42250, // 0.850-0.860
00190 24.46500, // 0.860-0.870
00191 24.50500, // 0.870-0.880
00192 24.54500, // 0.880-0.890
00193 24.58500, // 0.890-0.900
00194 24.62500, // 0.900-0.910
00195 24.66500, // 0.910-0.920
00196 24.70250, // 0.920-0.930
00197 24.74000, // 0.930-0.940
00198 24.77750, // 0.940-0.950
00199 24.81500, // 0.950-0.960
00200 24.85250, // 0.960-0.970
00201 24.89000, // 0.970-0.980
00202 24.92750, // 0.980-0.990
00203 24.96250, // 0.990-1.000
00204 };
00205 
00206 
00207 float timeshift_ns_hf(float wpksamp) {
00208   float flx = (num_bins_hf*(wpksamp - wpksamp0_hf)/scale_hf);
00209   int index = (int)flx;
00210   float yval;
00211   
00212   if      (index <    0)        return actual_ns_hf[0];
00213   else if (index >= num_bins_hf-1) return actual_ns_hf[num_bins_hf-1];
00214 
00215   // else interpolate:
00216   float y1       = actual_ns_hf[index];
00217   float y2       = actual_ns_hf[index+1];
00218 
00219   // float delta_x  = 1/(float)num_bins_hf;
00220   // yval = y1 + (y2-y1)*(flx-(float)index)/delta_x;
00221 
00222   yval = y1 + (y2-y1)*(flx-(float)index);
00223   return yval;
00224 }