ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Util/src/ElectronEnergySmearingScaling.cc
(Generate patch)

Comparing UserCode/MitHzz4l/Util/src/ElectronEnergySmearingScaling.cc (file contents):
Revision 1.6 by anlevin, Tue Nov 27 14:11:03 2012 UTC vs.
Revision 1.7 by dkralph, Mon Dec 17 17:23:06 2012 UTC

# Line 4 | Line 4
4   #include <TRandom1.h>
5  
6  
7 void correct_electron_energy(mithep::Electron * ele)
8 {
9  Float_t sigma;
10  Float_t scale;
11
12  //the scale is z_mass_data/z_mass_mc
13  //the sigma of the gaussian used for the smearing is
14  //sqrt(2*(sigma_data^2 - sigma_mc^2)/z_mass_mc^2)
15  //if the resolution is worse in mc, then we use 0 for the smearing factor
16  if(abs(ele->Eta()) < 1.479){
17    Float_t sigma = 0;
18    scale = (-0.0357085 + Z_MASS)/(0.455985 + Z_MASS);
19  }
20  else {
21    Float_t sigma = sqrt(2)*2.15011/(1.28248+91.1876);
22    scale = (1.09664+Z_MASS)/(1.2824+Z_MASS);
23  }
24  TRandom * rand = new TRandom(1024);
25  Float_t smear = rand->Gaus(0,sigma);
26  ele->SetPtEtaPhi((scale+smear)*ele->Pt(),ele->Eta(),ele->Phi());
27
28 }
29
7   //based on
8   //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/CMSSW/EgammaAnalysis/ElectronTools/src/PatElectronEnergyCalibrator.cc?revision=1.6&view=markup
9  
10 < std::pair<float,float> apply_claudes_electron_energy_corrections(mithep::Electron * ele, const float energy, const float energy_error, int run, std::string dataset_, const bool debug_){
34 <
35 <  Bool_t isMC_ = (run == 1);
10 > pair<float,float> apply_claudes_electron_energy_corrections(ControlFlags &ctrl, Electron * ele, const float energy, const float energy_error, unsigned run, string dataset_){
11  
12    float corr=0., scale=1.;
13    float dsigMC=0., corrMC=0.;
14  
15 <  if (!isMC_) {
15 >  if (!ctrl.mc) {
16      if (dataset_=="Jan16ReReco") {                     // corrections for january 16 ReReco
17            // values from http://indico.cern.ch/getFile.py/access?contribId=2&resId=0&materialId=slides&confId=176520
18        if (ele->IsEB() && fabs(ele->SCluster()->Eta())<1 && ele->SCluster()->R9()<0.94) {
# Line 98 | Line 73 | std::pair<float,float> apply_claudes_ele
73          if (run>=178424 && run<=180252) corr = 0.0047;
74        }
75      }
76 <    else if (dataset_=="2012Jul13ReReco") {                    
76 >    else if (dataset_=="2012Jul13ReReco") {
77        // values from https://twiki.cern.ch/twiki/bin/view/CMS/ECALELF  
78        if (ele->IsEB() && fabs(ele->SCluster()->Eta())<1 && ele->SCluster()->R9()<0.94) {
79          if (run>=190645 && run<=190781) scale = 1.0020;
# Line 240 | Line 215 | std::pair<float,float> apply_claudes_ele
215      }
216      else
217        assert(0);
218 +
219 +    assert(scale!=1 || corr!=0); // make sure run number was ok
220    }
221  
222    if (dataset_=="Summer12_DR53X_HCP2012" || dataset_ == "2012Jul13ReReco") {
# Line 262 | Line 239 | std::pair<float,float> apply_claudes_ele
239      if (ele->IsEE() && fabs(ele->SCluster()->Eta())>=2 && ele->SCluster()->R9()<0.94) dsigMC = 0.0301;
240      if (ele->IsEE() && fabs(ele->SCluster()->Eta())>=2 && ele->SCluster()->R9()>=0.94) dsigMC = 0.0293;  
241    }
242 <  else
243 <    assert(!isMC_);
242 >  else  
243 >    assert(!ctrl.mc);
244  
245    float corrected_energy = -999;
246 <
270 <  if (!isMC_){
246 >  if (!ctrl.mc){
247      if(dataset_ == "Jan16ReReco") corrected_energy = energy/(1+corr);
248      else if (dataset_ == "2012Jul13ReReco") corrected_energy = energy*scale;
249      else assert(0);
250    }
251 <  if (isMC_) {
252 <    TRandom1 * rand = new TRandom1();
253 <    rand->SetSeed(0);
254 <    corrMC = rand->Gaus(1,dsigMC);
255 < //     corrMC = 1+dsigMC; //use this only for synchronization
256 <    if (debug_) std::cout << "[ElectronEnergyCalibrator] unsmeared energy " << energy << std::endl;
251 >  if (ctrl.mc) {
252 >    TRandom1 rand;
253 >    rand.SetSeed(0);
254 >    if(ctrl.turnOffRandomization)
255 >      corrMC = 1+dsigMC; // use this only for synchronization
256 >    else
257 >      corrMC = rand.Gaus(1,dsigMC);
258      corrected_energy = energy*corrMC;  
282    if (debug_) std::cout << "[ElectronEnergyCalibrator] smeared energy " << corrected_energy << std::endl;
259    }  
260  
261 +  if(ctrl.debug) cout << "    corr'ting regr E " << setprecision(7) << setw(12) << energy << " -> " << setprecision(7) << setw(12) << corrected_energy << endl;
262    float corrected_energy_error = sqrt(energy_error*energy_error + dsigMC*dsigMC*corrected_energy*corrected_energy) ;
263  
264 <  return std::pair<float,float>(corrected_energy,corrected_energy_error);
264 >  return pair<float,float>(corrected_energy,corrected_energy_error);
265  
266   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines