00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "AtlfastAlgs/ElectronSmearer.h"
00012 #include "AtlfastAlgs/CorrectionFactorElectron.h"
00013
00014 #include <cmath>
00015
00016 #include "CLHEP/Vector/LorentzVector.h"
00017
00018
00019 #include "CLHEP/Random/JamesRandom.h"
00020 #include "CLHEP/Random/RandGauss.h"
00021 #include "CLHEP/Units/SystemOfUnits.h"
00022
00023 namespace Atlfast {
00024
00025 HepLorentzVector ElectronSmearer::smear(const HepMC::GenParticle& particle){
00026 return smear(particle.momentum());
00027 }
00028
00029 HepLorentzVector ElectronSmearer::smear (const HepLorentzVector& avec) {
00030
00031 double rpilup = 0.0;
00032 double aa, bb, sigph1, sigph, sigpu;
00033
00034 double ene = avec.e()/GeV ;
00035 double sqrtene = sqrt(ene);
00036 double pt = avec.perp()/GeV ;
00037 double vEta = fabs(avec.pseudoRapidity());
00038 HepLorentzVector bvec(0,0,0,0);
00039
00040 if(m_smearParamSchema==1){
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 while (1) {
00051 aa=randGauss()->fire();
00052
00053 sigph1 = aa*m_smearParams[0]/sqrtene;
00054 if (1.0 + sigph1 <= 0.0) continue;
00055 sigph = sigph1;
00056 if (vEta < 1.4) {
00057 while (1) {
00058 aa=randGauss()->fire();
00059 bb=randGauss()->fire();
00060 sigph1 = aa*m_smearParams[1]/pt + bb*m_smearParams[2];
00061 if (1.0+sigph1 > 0) break;
00062 }
00063 } else {
00064 while (1) {
00065 aa=randGauss()->fire();
00066 bb=randGauss()->fire();
00067 sigph1 = aa*m_smearParams[3]*((m_smearParams[4]-vEta)+m_smearParams[5])/ene + bb*m_smearParams[6];
00068
00069 if (1.0+sigph1 > 0) break;
00070 }
00071 }
00072 sigph += sigph1;
00073 if (m_lumi == 2) {
00074 if (vEta < 0.6) rpilup = 0.32;
00075 if (vEta > 0.6 && vEta < 1.4) rpilup = 0.295;
00076 if (vEta > 1.4) rpilup = 0.27;
00077 while (1) {
00078 aa=randGauss()->fire();
00079
00080 sigpu = aa*rpilup/pt;
00081 if (1.0+sigpu > 0) break;
00082 }
00083 sigph += sigpu;
00084 }
00085 if (1.0 + sigph > 0) break;
00086 }
00087
00088
00089 bvec.set(avec.px()*(1.0+sigph), avec.py()*(1.0+sigph), avec.pz()*(1.0+sigph), avec.e() *(1.0+sigph));
00090
00091 } else if (m_smearParamSchema==2){
00092
00093 double vE = avec.e();
00094
00095 double vLimEta=EtaElectron[NbEtaElectron-1]+(EtaElectron[NbEtaElectron-1]-EtaElectron[NbEtaElectron-2])*0.5;
00096
00097 if( vEta>vLimEta )
00098 {
00099 m_log<<MSG::DEBUG<<"No calibration : "<<vEta<<endreq;
00100 return avec;
00101 }
00102
00103 int iEnergy=0;
00104 m_log<<MSG::DEBUG<<vE<<" > "<<vEnergiesElectron[iEnergy]<<" ";
00105 while(iEnergy<NbEnergiesElectron&&vE>vEnergiesElectron[iEnergy]*1000)
00106 {
00107 m_log<<MSG::DEBUG<<vEnergiesElectron[iEnergy]<<" ";
00108 iEnergy++;
00109 }
00110 m_log<<MSG::DEBUG<<endreq;
00111 if(iEnergy==0)iEnergy++;
00112 double ratioEnergy=(vE*0.001-vEnergiesElectron[iEnergy-1])/(vEnergiesElectron[iEnergy]-vEnergiesElectron[iEnergy-1]);
00113
00114 int iEta=0;
00115 m_log<<MSG::DEBUG<<vEta<<" > "<<EtaElectron[iEta]<<" ";
00116 while(iEta<NbEtaElectron&&vEta>EtaElectron[iEta])
00117 {
00118 m_log<<MSG::DEBUG<<EtaElectron[iEta]<<" ";
00119 iEta++;
00120 }
00121 m_log<<MSG::DEBUG<<endreq;
00122
00123 if(iEta==0)iEta++;
00124 double ratioEta=(vEta-EtaElectron[iEta-1])/(EtaElectron[iEta]-EtaElectron[iEta-1]);
00125
00126 int iPos;
00127 double sigma,sigma1,sigma2;
00128
00129 iPos=iEnergy-1;
00130 sigma1=CorrFactorElectronSigma[iPos][iEta-1]+ratioEta*(CorrFactorElectronSigma[iPos][iEta]-CorrFactorElectronSigma[iPos][iEta-1]);
00131 iPos=iEnergy;
00132 sigma2=CorrFactorElectronSigma[iPos][iEta-1]+ratioEta*(CorrFactorElectronSigma[iPos][iEta]-CorrFactorElectronSigma[iPos][iEta-1]);
00133
00134 sigma=sigma1+ratioEnergy*(sigma2-sigma1);
00135
00136 m_log<<MSG::DEBUG<<" -> interpolation sigma "<<sigma1<<" "<<sigma2<<" "<<sigma<<endreq;
00137
00138 double alpha=1.0;
00139 double vrandom=alpha;
00140
00141 int iCmpt=int(randFlat()->fire()*20);
00142 for(int i=0; i<iCmpt; i++)
00143 vrandom=randGauss()->fire(1.0,sigma);
00144
00145 m_log<<MSG::DEBUG<<" -> Energie : "<<vEnergiesElectron[iEnergy]<<" Eta : "<<vEnergiesElectron[iEnergy-1]<<" < "<<vE<<" < "<<vEnergiesElectron[iEnergy]<<endreq;
00146 m_log<<MSG::DEBUG<<" -> Energie : "<<vEnergiesElectron[iEnergy]<<" Eta : "<<EtaElectron[iEta-1]<<" < "<<vEta<<" < "<<EtaElectron[iEta]<<endreq;
00147 m_log<<MSG::DEBUG<<" calib mean-sigma "<<alpha<<" "<<sigma<<" -> "<<vrandom<<endreq;
00148
00149 bvec.set(avec.px()*vrandom, avec.py()*vrandom, avec.pz()*vrandom, vE*vrandom);
00150
00151 m_log<<MSG::DEBUG<<"-> HepLorentzVector calibration "<<vEta<<" "<<avec<<" -> "<<bvec<<endreq;
00152
00153 }
00154
00155 return bvec;
00156 }
00157
00158
00159 int ElectronSmearer::setSmearParameters (const std::vector<double>& smearValues){
00160 m_smearParams=smearValues;
00161 return 0;
00162 }
00163
00164
00165 int ElectronSmearer::setSmearParamSchema ( const int smearSchema){
00166 m_smearParamSchema=smearSchema;
00167 return 0;
00168 }
00169
00170 }