00001 #include "RecoLocalCalo/EcalRecAlgos/interface/ESRecHitAnalyticAlgo.h" 00002 #include "FWCore/MessageLogger/interface/MessageLogger.h" 00003 00004 #include <iostream> 00005 #include <cmath> 00006 00007 ESRecHitAnalyticAlgo::ESRecHitAnalyticAlgo() { 00008 } 00009 00010 ESRecHitAnalyticAlgo::~ESRecHitAnalyticAlgo() { 00011 } 00012 00013 double* ESRecHitAnalyticAlgo::EvalAmplitude(const ESDataFrame& digi, double ped) const { 00014 00015 double *fitresults = new double[3]; 00016 double adc[3]; 00017 00018 for (int i=0; i<digi.size(); i++) 00019 adc[i] = digi.sample(i).adc() - ped; 00020 00021 double status = 0; 00022 if (adc[0] > 20) status = 14; 00023 if (adc[1] < 0 || adc[2] < 0) status = 10; 00024 if (adc[0] > adc[1] && adc[0] > adc[2]) status = 8; 00025 if (adc[2] > adc[1] && adc[2] > adc[0]) status = 9; 00026 double r12 = (adc[1] != 0) ? adc[0]/adc[1] : 99999; 00027 double r23 = (adc[2] != 0) ? adc[1]/adc[2] : 99999; 00028 if (r12 > ratioCuts_->getR12High()) status = 5; 00029 if (r23 > ratioCuts_->getR23High()) status = 6; 00030 if (r23 < ratioCuts_->getR23Low()) status = 7; 00031 00032 if (int(status) == 0) { 00033 00034 double A1 = adc[1]; 00035 double A2 = adc[2]; 00036 00037 // t0 from analytical formula: 00038 double n = 1.798; 00039 double w = 0.07291; 00040 double DeltaT = 25.; 00041 double aaa = log(A2/A1)/n; 00042 double bbb = w/n*DeltaT; 00043 double ccc= exp(aaa+bbb); 00044 00045 //double t0 = (2.-ccc)/(ccc-1) * DeltaT + 5; 00046 double t0 = (2.-ccc)/(1.-ccc) * DeltaT - 5; 00047 00048 // A from analytical formula: 00049 double t1 = 20.; 00050 //double t2 = 45.; 00051 double A_1 = pow(w/n*(t1),n) * exp(n-w*(t1)); 00052 //double A_2 = pow(w/n*(t2),n) * exp(n-w*(t2)); 00053 double AA1 = A1 / A_1; 00054 //double AA2 = A2 / A_2; 00055 00056 fitresults[0] = AA1; 00057 fitresults[1] = t0; 00058 00059 if (adc[1] > 2800 && adc[2] > 2800) status = 11; 00060 else if (adc[1] > 2800) status = 12; 00061 else if (adc[2] > 2800) status = 13; 00062 00063 } else { 00064 fitresults[0] = 0; 00065 fitresults[1] = -999; 00066 } 00067 00068 fitresults[2] = status; 00069 00070 return fitresults; 00071 } 00072 00073 EcalRecHit ESRecHitAnalyticAlgo::reconstruct(const ESDataFrame& digi) const { 00074 00075 ESPedestals::const_iterator it_ped = peds_->find(digi.id()); 00076 00077 ESIntercalibConstantMap::const_iterator it_mip = mips_->getMap().find(digi.id()); 00078 ESAngleCorrectionFactors::const_iterator it_ang = ang_->getMap().find(digi.id()); 00079 00080 ESChannelStatusMap::const_iterator it_status = channelStatus_->getMap().find(digi.id()); 00081 00082 double* results; 00083 00084 results = EvalAmplitude(digi, it_ped->getMean()); 00085 00086 double energy = results[0]; 00087 double t0 = results[1]; 00088 int status = (int) results[2]; 00089 delete[] results; 00090 00091 double mipCalib = (fabs(cos(*it_ang)) != 0.) ? (*it_mip)/fabs(cos(*it_ang)) : 0.; 00092 energy *= (mipCalib != 0.) ? MIPGeV_/mipCalib : 0.; 00093 00094 LogDebug("ESRecHitAnalyticAlgo") << "ESRecHitAnalyticAlgo : reconstructed energy "<<energy<<" T0 "<<t0; 00095 00096 EcalRecHit rechit(digi.id(), energy, t0); 00097 00098 if (it_status->getStatusCode() == 1) { 00099 rechit.setFlag(EcalRecHit::kESDead); 00100 } else { 00101 if (status == 0) 00102 rechit.setFlag(EcalRecHit::kESGood); 00103 else if (status == 5) 00104 rechit.setFlag(EcalRecHit::kESBadRatioFor12); 00105 else if (status == 6) 00106 rechit.setFlag(EcalRecHit::kESBadRatioFor23Upper); 00107 else if (status == 7) 00108 rechit.setFlag(EcalRecHit::kESBadRatioFor23Lower); 00109 else if (status == 8) 00110 rechit.setFlag(EcalRecHit::kESTS1Largest); 00111 else if (status == 9) 00112 rechit.setFlag(EcalRecHit::kESTS3Largest); 00113 else if (status == 10) 00114 rechit.setFlag(EcalRecHit::kESTS3Negative); 00115 else if (status == 11) 00116 rechit.setFlag(EcalRecHit::kESSaturated); 00117 else if (status == 12) 00118 rechit.setFlag(EcalRecHit::kESTS2Saturated); 00119 else if (status == 13) 00120 rechit.setFlag(EcalRecHit::kESTS3Saturated); 00121 else if (status == 14) 00122 rechit.setFlag(EcalRecHit::kESTS13Sigmas); 00123 } 00124 00125 return rechit; 00126 } 00127