CMS 3D CMS Logo

HcalSimpleRecAlgo.cc

Go to the documentation of this file.
00001 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalSimpleRecAlgo.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include "CalibCalorimetry/HcalAlgos/interface/HcalTimeSlew.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 HcalSimpleRecAlgo::HcalSimpleRecAlgo(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<HcalPulseContainmentCorrection>(new HcalPulseContainmentCorrection(samplesToAdd_,phaseNS,MaximumFractionalError));
00015 }
00016 
00017 HcalSimpleRecAlgo::HcalSimpleRecAlgo(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 HcalSimpleRecAlgoImpl {
00035   template<class Digi, class RecHit>
00036   inline RecHit reco(const Digi& digi, const HcalCoder& coder, const HcalCalibrations& calibs, 
00037                      int ifirst, int n, bool slewCorrect, const HcalPulseContainmentCorrection* corr, HcalTimeSlew::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.respcorrgain(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       LogDebug("HCAL Pulse") << "HcalSimpleRecAlgo::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.respcorrgain(capid) );
00068       capid=digi[maxI+1].capid();
00069       float t2 = fabs((tool[maxI+1]-calibs.pedestal(capid))*calibs.respcorrgain(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_hbheho(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-=HcalTimeSlew::delay(std::max(1.0,fc_ampl),slewFlavor);
00082     }
00083     return RecHit(digi.id(),ampl,time);    
00084   }
00085 }
00086 
00087 HBHERecHit HcalSimpleRecAlgo::reconstruct(const HBHEDataFrame& digi, const HcalCoder& coder, const HcalCalibrations& calibs) const {
00088   return HcalSimpleRecAlgoImpl::reco<HBHEDataFrame,HBHERecHit>(digi,coder,calibs,
00089                                                                firstSample_,samplesToAdd_,correctForTimeslew_,
00090                                                                pulseCorr_.get(),
00091                                                                HcalTimeSlew::Medium);
00092 }
00093 
00094 HORecHit HcalSimpleRecAlgo::reconstruct(const HODataFrame& digi, const HcalCoder& coder, const HcalCalibrations& calibs) const {
00095   return HcalSimpleRecAlgoImpl::reco<HODataFrame,HORecHit>(digi,coder,calibs,
00096                                                            firstSample_,samplesToAdd_,correctForTimeslew_,
00097                                                            pulseCorr_.get(),
00098                                                            HcalTimeSlew::Slow);
00099 }
00100 
00101 ZDCRecHit HcalSimpleRecAlgo::reconstruct(const ZDCDataFrame& digi, const HcalCoder& coder, const HcalCalibrations& calibs) const {
00102   return HcalSimpleRecAlgoImpl::reco<ZDCDataFrame,ZDCRecHit>(digi,coder,calibs,
00103                                                              firstSample_,samplesToAdd_,false,
00104                                                              0,
00105                                                              HcalTimeSlew::Fast);
00106 }
00107 
00108 HcalCalibRecHit HcalSimpleRecAlgo::reconstruct(const HcalCalibDataFrame& digi, const HcalCoder& coder, const HcalCalibrations& calibs) const {
00109   return HcalSimpleRecAlgoImpl::reco<HcalCalibDataFrame,HcalCalibRecHit>(digi,coder,calibs,
00110                                                                          firstSample_,samplesToAdd_,correctForTimeslew_,
00111                                                                          pulseCorr_.get(),
00112                                                                          HcalTimeSlew::Fast);
00113 }
00114 
00115 HFRecHit HcalSimpleRecAlgo::reconstruct(const HFDataFrame& digi, const HcalCoder& coder, const HcalCalibrations& calibs) const {
00116   CaloSamples tool;
00117   coder.adc2fC(digi,tool);
00118   
00119   double ampl=0; int maxI = -1; double maxA = -1e10; float ta=0;
00120   for (int i=firstSample_; i<tool.size() && i<samplesToAdd_+firstSample_; i++) {
00121     int capid=digi[i].capid();
00122     ta = (tool[i]-calibs.pedestal(capid))*calibs.respcorrgain(capid);
00123     ampl+=ta;
00124     if(ta>maxA){
00125       maxA=ta;
00126       maxI=i;
00127     }
00128   }
00129 
00130   float time=-9999.0;
00132   if(maxI==0 || maxI==(tool.size()-1)) {
00133       LogDebug("HCAL Pulse") << "HcalSimpleRecAlgo::reconstruct :" 
00134                                                << " Invalid max amplitude position, " 
00135                                                << " max Amplitude: "<< maxI
00136                                                << " first: "<<firstSample_
00137                                                << " last: "<<(tool.size()-1)
00138                                                << std::endl;
00139   } else {
00140     maxA=fabs(maxA);  
00141     int capid=digi[maxI-1].capid();
00142     float t0 = fabs((tool[maxI-1]-calibs.pedestal(capid))*calibs.respcorrgain(capid) );
00143     capid=digi[maxI+1].capid();
00144     float t2 = fabs((tool[maxI+1]-calibs.pedestal(capid))*calibs.respcorrgain(capid) );    
00145     float wpksamp = (t0 + maxA + t2);
00146     if (wpksamp!=0) wpksamp=(maxA + 2.0*t2) / wpksamp; 
00147     time = (maxI - digi.presamples())*25.0 + timeshift_ns_hf(wpksamp);
00148   }
00149 
00150   return HFRecHit(digi.id(),ampl,time); 
00151 }
00152 
00153 // timeshift implementation
00154 
00155 static const float wpksamp0_hbheho = 0.680178;
00156 static const float scale_hbheho    = 0.819786;
00157 static const int   num_bins_hbheho = 50;
00158 
00159 static const float actual_ns_hbheho[num_bins_hbheho] = {
00160  0.00000, // 0.000-0.020
00161  0.41750, // 0.020-0.040
00162  0.81500, // 0.040-0.060
00163  1.21000, // 0.060-0.080
00164  1.59500, // 0.080-0.100
00165  1.97250, // 0.100-0.120
00166  2.34750, // 0.120-0.140
00167  2.71250, // 0.140-0.160
00168  3.07500, // 0.160-0.180
00169  3.43500, // 0.180-0.200
00170  3.79000, // 0.200-0.220
00171  4.14250, // 0.220-0.240
00172  4.49250, // 0.240-0.260
00173  4.84250, // 0.260-0.280
00174  5.19000, // 0.280-0.300
00175  5.53750, // 0.300-0.320
00176  5.89000, // 0.320-0.340
00177  6.23750, // 0.340-0.360
00178  6.59250, // 0.360-0.380
00179  6.95250, // 0.380-0.400
00180  7.31000, // 0.400-0.420
00181  7.68000, // 0.420-0.440
00182  8.05500, // 0.440-0.460
00183  8.43000, // 0.460-0.480
00184  8.83250, // 0.480-0.500
00185  9.23250, // 0.500-0.520
00186  9.65500, // 0.520-0.540
00187 10.09500, // 0.540-0.560
00188 10.54750, // 0.560-0.580
00189 11.04500, // 0.580-0.600
00190 11.55750, // 0.600-0.620
00191 12.13000, // 0.620-0.640
00192 12.74500, // 0.640-0.660
00193 13.41250, // 0.660-0.680
00194 14.18500, // 0.680-0.700
00195 15.02750, // 0.700-0.720
00196 15.92250, // 0.720-0.740
00197 16.82500, // 0.740-0.760
00198 17.70000, // 0.760-0.780
00199 18.52500, // 0.780-0.800
00200 19.28750, // 0.800-0.820
00201 19.99750, // 0.820-0.840
00202 20.67250, // 0.840-0.860
00203 21.31250, // 0.860-0.880
00204 21.90750, // 0.880-0.900
00205 22.48750, // 0.900-0.920
00206 23.02750, // 0.920-0.940
00207 23.55250, // 0.940-0.960
00208 24.05000, // 0.960-0.980
00209 24.53750, // 0.980-1.000
00210 };
00211 
00212 float timeshift_ns_hbheho(float wpksamp) {
00213   int index=(int)(0.5+num_bins_hbheho*(wpksamp-wpksamp0_hbheho)/scale_hbheho);
00214   
00215   if      (index <    0)             return actual_ns_hbheho[0];
00216   else if (index >= num_bins_hbheho) return actual_ns_hbheho[num_bins_hbheho-1];
00217   
00218   return actual_ns_hbheho[index];
00219 }
00220 
00221 
00222 static const float wpksamp0_hf = 0.500635;
00223 static const float scale_hf    = 0.999301;
00224 static const int   num_bins_hf = 100;
00225 
00226 static const float actual_ns_hf[num_bins_hf] = {
00227  0.00000, // 0.000-0.010
00228  0.03750, // 0.010-0.020
00229  0.07250, // 0.020-0.030
00230  0.10750, // 0.030-0.040
00231  0.14500, // 0.040-0.050
00232  0.18000, // 0.050-0.060
00233  0.21500, // 0.060-0.070
00234  0.25000, // 0.070-0.080
00235  0.28500, // 0.080-0.090
00236  0.32000, // 0.090-0.100
00237  0.35500, // 0.100-0.110
00238  0.39000, // 0.110-0.120
00239  0.42500, // 0.120-0.130
00240  0.46000, // 0.130-0.140
00241  0.49500, // 0.140-0.150
00242  0.53000, // 0.150-0.160
00243  0.56500, // 0.160-0.170
00244  0.60000, // 0.170-0.180
00245  0.63500, // 0.180-0.190
00246  0.67000, // 0.190-0.200
00247  0.70750, // 0.200-0.210
00248  0.74250, // 0.210-0.220
00249  0.78000, // 0.220-0.230
00250  0.81500, // 0.230-0.240
00251  0.85250, // 0.240-0.250
00252  0.89000, // 0.250-0.260
00253  0.92750, // 0.260-0.270
00254  0.96500, // 0.270-0.280
00255  1.00250, // 0.280-0.290
00256  1.04250, // 0.290-0.300
00257  1.08250, // 0.300-0.310
00258  1.12250, // 0.310-0.320
00259  1.16250, // 0.320-0.330
00260  1.20500, // 0.330-0.340
00261  1.24500, // 0.340-0.350
00262  1.29000, // 0.350-0.360
00263  1.33250, // 0.360-0.370
00264  1.38000, // 0.370-0.380
00265  1.42500, // 0.380-0.390
00266  1.47500, // 0.390-0.400
00267  1.52500, // 0.400-0.410
00268  1.57750, // 0.410-0.420
00269  1.63250, // 0.420-0.430
00270  1.69000, // 0.430-0.440
00271  1.75250, // 0.440-0.450
00272  1.82000, // 0.450-0.460
00273  1.89250, // 0.460-0.470
00274  1.97500, // 0.470-0.480
00275  2.07250, // 0.480-0.490
00276  2.20000, // 0.490-0.500
00277 19.13000, // 0.500-0.510
00278 21.08750, // 0.510-0.520
00279 21.57750, // 0.520-0.530
00280 21.89000, // 0.530-0.540
00281 22.12250, // 0.540-0.550
00282 22.31000, // 0.550-0.560
00283 22.47000, // 0.560-0.570
00284 22.61000, // 0.570-0.580
00285 22.73250, // 0.580-0.590
00286 22.84500, // 0.590-0.600
00287 22.94750, // 0.600-0.610
00288 23.04250, // 0.610-0.620
00289 23.13250, // 0.620-0.630
00290 23.21500, // 0.630-0.640
00291 23.29250, // 0.640-0.650
00292 23.36750, // 0.650-0.660
00293 23.43750, // 0.660-0.670
00294 23.50500, // 0.670-0.680
00295 23.57000, // 0.680-0.690
00296 23.63250, // 0.690-0.700
00297 23.69250, // 0.700-0.710
00298 23.75000, // 0.710-0.720
00299 23.80500, // 0.720-0.730
00300 23.86000, // 0.730-0.740
00301 23.91250, // 0.740-0.750
00302 23.96500, // 0.750-0.760
00303 24.01500, // 0.760-0.770
00304 24.06500, // 0.770-0.780
00305 24.11250, // 0.780-0.790
00306 24.16000, // 0.790-0.800
00307 24.20500, // 0.800-0.810
00308 24.25000, // 0.810-0.820
00309 24.29500, // 0.820-0.830
00310 24.33750, // 0.830-0.840
00311 24.38000, // 0.840-0.850
00312 24.42250, // 0.850-0.860
00313 24.46500, // 0.860-0.870
00314 24.50500, // 0.870-0.880
00315 24.54500, // 0.880-0.890
00316 24.58500, // 0.890-0.900
00317 24.62500, // 0.900-0.910
00318 24.66500, // 0.910-0.920
00319 24.70250, // 0.920-0.930
00320 24.74000, // 0.930-0.940
00321 24.77750, // 0.940-0.950
00322 24.81500, // 0.950-0.960
00323 24.85250, // 0.960-0.970
00324 24.89000, // 0.970-0.980
00325 24.92750, // 0.980-0.990
00326 24.96250, // 0.990-1.000
00327 };
00328 
00329 float timeshift_ns_hf(float wpksamp) {
00330   float flx = (num_bins_hf*(wpksamp - wpksamp0_hf)/scale_hf);
00331   int index = (int)flx;
00332   float yval;
00333   
00334   if      (index <    0)        return actual_ns_hf[0];
00335   else if (index >= num_bins_hf-1) return actual_ns_hf[num_bins_hf-1];
00336 
00337   // else interpolate:
00338   float y1       = actual_ns_hf[index];
00339   float y2       = actual_ns_hf[index+1];
00340 
00341   // float delta_x  = 1/(float)num_bins_hf;
00342   // yval = y1 + (y2-y1)*(flx-(float)index)/delta_x;
00343 
00344   yval = y1 + (y2-y1)*(flx-(float)index);
00345   return yval;
00346 }

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