00001
00002
00003
00004
00005
00006
00009
00010
00011
00012
00013
00014
00015 #include "NtupleReader/MySystematics.h"
00016
00017
00018
00019
00020
00021 using namespace std;
00022
00023
00024
00026 void MySystematics::init( unsigned int seed ) {
00027
00028 m_random = new TRandom ( seed );
00029 m_dataset_info = &MyDatasetInfo::Instance();
00030
00031
00032 }
00033
00034
00036 void MySystematics::destruct( void ) {
00037
00038 delete m_random;
00039
00040 }
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 void MySystematics::apply_syst( std::vector<MyParticle*> * vp_syst, MyMissingEt * met_syst, int f_reso, int f_eScale_minus, int f_eScale_plus, int f_effi, int f_btag){
00063
00064
00065
00066
00067
00068 double m_gev = m_dataset_info->get_scale();
00069
00070 double vp_m=0;
00071 double egamma_scale_factor_minus =0.995;
00072 double egamma_scale_factor_plus =1.005;
00073 double electron_eff_error=0.002;
00074 double photon_eff_error=0.002;
00075
00076 double muon_scale_factor_minus =0.99;
00077 double muon_scale_factor_plus =1.01;
00078 double muon_eff_error=0.01;
00079
00080 double jet_scale_factor_minus =0.93;
00081 double jet_scale_factor_plus =1.07;
00082 double jet_scale_factor_minus_large_eta =0.85;
00083 double jet_scale_factor_plus_large_eta =1.15;
00084 double jet_eff_error=0.0;
00085 double jet_eff_error_large_eta=0.0;
00086 double jet_METscale_factor_minus =-0.05;
00087 double jet_METscale_factor_plus =0.05;
00088
00089 double taujet_scale_factor_minus =0.95;
00090 double taujet_scale_factor_plus =1.05;
00091 double tau_eff_error=0.05;
00092 double taujet_METscale_factor_minus =-0.05;
00093 double taujet_METscale_factor_plus =0.05;
00094
00095 double bjet_eff_error_scale=0.05;
00096
00097
00098
00099
00100 double bjet_eff_error=0.;
00101
00102 int nsyst=0;
00103 if (f_reso==1) nsyst++;
00104 if (f_eScale_minus==1) nsyst++;
00105 if (f_eScale_plus==1) nsyst++;
00106 if (f_effi==1) nsyst++;
00107 if (f_btag==1) nsyst++;
00108
00109 if(nsyst>1){
00110 cout<<" ** ERROR MyTools::apply_syst: You should do the systematic study one by one!!! \n";
00111 cout<<" ** ERROR MyTools::apply_syst: NO EFFEKT HAS BEEN APPLIED!!! \n";
00112 cerr<<" ** ERROR MyTools::apply_syst: You should do the systematic study one by one!!! \n";
00113 cerr<<" ** ERROR MyTools::apply_syst: NO EFFEKT HAS BEEN APPLIED!!! \n";
00114 return;
00115 }
00116
00117 double new_metx=met_syst->met_x();
00118 double new_mety=met_syst->met_y();
00119 double new_met=met_syst->met();
00120 double new_metsum=met_syst->met_sum();
00121
00122
00123
00124 for (int il=vp_syst->size()-1; il>=0; il--){
00125
00126 bool syst_remove=false;
00127
00128 TLorentzVector aod_tlv=(((*vp_syst)[il])->tlv());
00129 int id_pdg=0;
00130 id_pdg=TMath::Abs((*vp_syst)[il]->pdgId());
00131
00132 if (id_pdg==22) vp_m=0;
00133 if (id_pdg==11) vp_m=m_gev*0.511;
00134 if (id_pdg==13) vp_m=m_gev*105.6;
00135 if (id_pdg==15) vp_m=m_gev*1776.99;
00136
00137
00138 TLorentzVector new_tlv=aod_tlv;
00139
00140
00141 double mev_adapt=1.;
00142 if (m_gev==1.) mev_adapt=0.001;
00143
00144
00145
00146 if( f_reso==1 ){
00147
00148
00149
00150
00151
00152 if (id_pdg==11){
00153
00154
00155 double et_sys=new_tlv.Et();
00156 double new_et=egamma_resolution(et_sys);
00157 double new_e=new_et*cosh(new_tlv.Eta());
00158 double new_p=new_e*new_e-vp_m*vp_m;
00159 new_p=sqrt(new_p);
00160 double new_pt=new_p/cosh(new_tlv.Eta());
00161
00162 new_tlv.SetPtEtaPhiE(new_pt,new_tlv.Eta(),new_tlv.Phi(),new_e);
00163
00164 }
00165
00166 if (id_pdg==22){
00167
00168
00169 double et_sys=new_tlv.Et();
00170 double new_et=egamma_resolution(et_sys);
00171 double new_e=new_et*cosh(new_tlv.Eta());
00172 double new_p=new_e*new_e-vp_m*vp_m;
00173 new_p=sqrt(new_p);
00174 double new_pt=new_p/cosh(new_tlv.Eta());
00175
00176 new_tlv.SetPtEtaPhiE(new_pt,new_tlv.Eta(),new_tlv.Phi(),new_e);
00177
00178 }
00179
00180 if (id_pdg==13){
00181
00182
00183 double pt_sys=new_tlv.Pt();
00184 double new_pt=muon_resolution(mev_adapt*pt_sys)/mev_adapt;
00185 double new_p=new_pt*cosh(new_tlv.Eta());
00186 double new_e=new_p*new_p+vp_m*vp_m;
00187 new_e=sqrt(new_e);
00188
00189 new_tlv.SetPtEtaPhiE(new_pt,new_tlv.Eta(),new_tlv.Phi(),new_e);
00190
00191 }
00192
00193 if (id_pdg==15){
00194
00195
00196 double e_sys=new_tlv.E();
00197 double new_e=taujet_resolution(mev_adapt*e_sys)/mev_adapt;
00198 double new_p=new_e*new_e-vp_m*vp_m;
00199 new_p=sqrt(new_p);
00200 double new_pt=new_p/cosh(new_tlv.Eta());
00201
00202 new_tlv.SetPtEtaPhiE(new_pt,new_tlv.Eta(),new_tlv.Phi(),new_e);
00203
00204 }
00205
00206 if (id_pdg!=15&&id_pdg!=13&&id_pdg!=11&&id_pdg!=22){
00207
00208
00209
00210
00211 double e_sys=new_tlv.E();
00212 double eta_sys=new_tlv.Eta();
00213 double new_e=jet_resolution(mev_adapt*e_sys,eta_sys)/mev_adapt;
00214 double new_p=new_e*new_e-vp_m*vp_m;
00215 new_p=sqrt(new_p);
00216 double new_pt=new_p/cosh(new_tlv.Eta());
00217
00218 new_tlv.SetPtEtaPhiE(new_pt,new_tlv.Eta(),new_tlv.Phi(),new_e);
00219
00220 }
00221
00222 }
00223
00224
00225
00226 if( f_eScale_minus==1 ){
00227
00228
00229
00230
00231
00232 if (id_pdg==11){
00233
00234 double et_sys=new_tlv.Et();
00235 double new_et=energy_scale(et_sys,egamma_scale_factor_minus);
00236 double new_e=new_et*cosh(new_tlv.Eta());
00237 double new_p=new_e*new_e-vp_m*vp_m;
00238 new_p=sqrt(new_p);
00239 double new_pt=new_p/cosh(new_tlv.Eta());
00240
00241 new_tlv.SetPtEtaPhiE(new_pt,new_tlv.Eta(),new_tlv.Phi(),new_e);
00242
00243 }
00244 if (id_pdg==22){
00245
00246 double et_sys=new_tlv.Et();
00247 double new_et=energy_scale(et_sys,egamma_scale_factor_minus);
00248 double new_e=new_et*cosh(new_tlv.Eta());
00249 double new_p=new_e*new_e-vp_m*vp_m;
00250 new_p=sqrt(new_p);
00251 double new_pt=new_p/cosh(new_tlv.Eta());
00252
00253 new_tlv.SetPtEtaPhiE(new_pt,new_tlv.Eta(),new_tlv.Phi(),new_e);
00254
00255 }
00256
00257 if (id_pdg==13){
00258
00259 double pt_sys=new_tlv.Pt();
00260 double new_pt=energy_scale(pt_sys,muon_scale_factor_minus);;
00261 double new_p=new_pt*cosh(new_tlv.Eta());
00262 double new_e=new_p*new_p+vp_m*vp_m;
00263 new_e=sqrt(new_e);
00264
00265 new_tlv.SetPtEtaPhiE(new_pt,new_tlv.Eta(),new_tlv.Phi(),new_e);
00266
00267 }
00268
00269 if (id_pdg==15){
00270
00271 double e_sys=new_tlv.E();
00272 double new_e=energy_scale(e_sys,taujet_scale_factor_minus);;
00273 double new_p=new_e*new_e-vp_m*vp_m;
00274 new_p=sqrt(new_p);
00275 double new_pt=new_p/cosh(new_tlv.Eta());
00276
00277 new_tlv.SetPtEtaPhiE(new_pt,new_tlv.Eta(),new_tlv.Phi(),new_e);
00278
00279 }
00280
00281 if (id_pdg!=15&&id_pdg!=13&&id_pdg!=11&&id_pdg!=22){
00282
00283
00284
00285 double e_sys=new_tlv.E();
00286 double eta_sys=new_tlv.Eta();
00287 double new_e=energy_scale(e_sys,jet_scale_factor_minus);
00288 if(TMath::Abs(eta_sys)>3.2) new_e=energy_scale(e_sys,jet_scale_factor_minus_large_eta);
00289 double new_p=new_e*new_e-vp_m*vp_m;
00290 new_p=sqrt(new_p);
00291 double new_pt=new_p/cosh(new_tlv.Eta());
00292
00293 new_tlv.SetPtEtaPhiE(new_pt,new_tlv.Eta(),new_tlv.Phi(),new_e);
00294
00295 }
00296
00297 }
00298
00299
00300
00301 if( f_eScale_plus==1 ){
00302
00303
00304
00305
00306
00307 if (id_pdg==11){
00308
00309 double et_sys=new_tlv.Et();
00310 double new_et=energy_scale(et_sys,egamma_scale_factor_plus);
00311 double new_e=new_et*cosh(new_tlv.Eta());
00312 double new_p=new_e*new_e-vp_m*vp_m;
00313 new_p=sqrt(new_p);
00314 double new_pt=new_p/cosh(new_tlv.Eta());
00315
00316 new_tlv.SetPtEtaPhiE(new_pt,new_tlv.Eta(),new_tlv.Phi(),new_e);
00317
00318 }
00319
00320 if(id_pdg==22){
00321
00322 double et_sys=new_tlv.Et();
00323 double new_et=energy_scale(et_sys,egamma_scale_factor_plus);
00324 double new_e=new_et*cosh(new_tlv.Eta());
00325 double new_p=new_e*new_e-vp_m*vp_m;
00326 new_p=sqrt(new_p);
00327 double new_pt=new_p/cosh(new_tlv.Eta());
00328
00329 new_tlv.SetPtEtaPhiE(new_pt,new_tlv.Eta(),new_tlv.Phi(),new_e);
00330
00331 }
00332
00333 if (id_pdg==13){
00334
00335 double pt_sys=new_tlv.Pt();
00336 double new_pt=energy_scale(pt_sys,muon_scale_factor_plus);;
00337 double new_p=new_pt*cosh(new_tlv.Eta());
00338 double new_e=new_p*new_p+vp_m*vp_m;
00339 new_e=sqrt(new_e);
00340
00341 new_tlv.SetPtEtaPhiE(new_pt,new_tlv.Eta(),new_tlv.Phi(),new_e);
00342
00343 }
00344
00345 if (id_pdg==15){
00346
00347 double e_sys=new_tlv.E();
00348 double new_e=energy_scale(e_sys,taujet_scale_factor_plus);;
00349 double new_p=new_e*new_e-vp_m*vp_m;
00350 new_p=sqrt(new_p);
00351 double new_pt=new_p/cosh(new_tlv.Eta());
00352
00353 new_tlv.SetPtEtaPhiE(new_pt,new_tlv.Eta(),new_tlv.Phi(),new_e);
00354
00355 }
00356
00357 if (id_pdg!=15&&id_pdg!=13&&id_pdg!=11&&id_pdg!=22){
00358
00359
00360
00361 double e_sys=new_tlv.E();
00362 double eta_sys=new_tlv.Eta();
00363 double new_e=energy_scale(e_sys,jet_scale_factor_plus);
00364 if(TMath::Abs(eta_sys)>3.2) new_e=energy_scale(e_sys,jet_scale_factor_plus_large_eta);
00365 double new_p=new_e*new_e-vp_m*vp_m;
00366 new_p=sqrt(new_p);
00367 double new_pt=new_p/cosh(new_tlv.Eta());
00368
00369 new_tlv.SetPtEtaPhiE(new_pt,new_tlv.Eta(),new_tlv.Phi(),new_e);
00370
00371 }
00372
00373 }
00374
00375
00376
00377 if( f_effi==1 ){
00378
00379
00380
00381
00382
00383 if (id_pdg==11){
00384 syst_remove=!is_detected(electron_eff_error);
00385 }
00386
00387 else if (id_pdg==22){
00388 syst_remove=!is_detected(photon_eff_error);
00389 }
00390
00391 else if (id_pdg==13){
00392 syst_remove=!is_detected(muon_eff_error);
00393 }
00394
00395 else if (id_pdg==15){
00396 syst_remove=!is_detected(tau_eff_error);
00397 }
00398
00399 else {
00400 double eta_sys=new_tlv.Eta();
00401 if (TMath::Abs(eta_sys) > 3.2 ) {
00402 syst_remove=!is_detected(jet_eff_error_large_eta);
00403 } else {
00404 syst_remove=!is_detected(jet_eff_error);
00405 }
00406 }
00407 }
00408
00409
00410 if( f_btag==1 && (!syst_remove) ){
00411
00412
00413
00414
00415
00416 if (id_pdg!=0){ cout<<"** WARNING MyTools::apply_syst: b tagging effi on e, photon, mu or tau \n"; }
00417
00418
00419 bjet_eff_error=bjet_eff_error_scale;
00420
00421 syst_remove=!is_bjet(bjet_eff_error);
00422
00423 }
00424
00425 (*vp_syst)[il]->set_tlv(new_tlv);
00426
00427
00428
00429
00430
00431
00432
00433 if (!syst_remove) {
00434
00435
00436
00437
00438 double new_px=new_tlv.Px();
00439 double new_py=new_tlv.Py();
00440 double new_pt=new_tlv.Pt();
00441 double aod_px=aod_tlv.Px();
00442 double aod_py=aod_tlv.Py();
00443 double aod_pt=aod_tlv.Pt();
00444
00445
00446 if ((f_eScale_plus==1)&&!((id_pdg==11)||(id_pdg==13)||(id_pdg==22))){
00447
00448 if (id_pdg==15){
00449 new_metx += metCorrection_x(0.0,taujet_METscale_factor_plus*aod_px);
00450
00451 new_mety += metCorrection_y(0.0,taujet_METscale_factor_plus*aod_py);
00452 new_metsum += metCorrection_sum(0.0,taujet_METscale_factor_plus*aod_pt);
00453 }else{
00454 new_metx += metCorrection_x(0.0,jet_METscale_factor_plus*aod_px);
00455 new_mety += metCorrection_y(0.0,jet_METscale_factor_plus*aod_py);
00456 new_metsum += metCorrection_sum(0.0,jet_METscale_factor_plus*aod_pt);
00457 }
00458
00459 }else if((f_eScale_minus==1)&&!((id_pdg==11)||(id_pdg==13)||(id_pdg==22))){
00460
00461 if (id_pdg==15){
00462 new_metx += metCorrection_x(0.0,taujet_METscale_factor_minus*aod_px);
00463 new_mety += metCorrection_y(0.0,taujet_METscale_factor_minus*aod_py);
00464 new_metsum += metCorrection_sum(0.0,taujet_METscale_factor_minus*aod_pt);
00465 }else{
00466 new_metx += metCorrection_x(0.0,jet_METscale_factor_minus*aod_px);
00467 new_mety += metCorrection_y(0.0,jet_METscale_factor_minus*aod_py);
00468 new_metsum += metCorrection_sum(0.0,jet_METscale_factor_minus*aod_pt);
00469 }
00470
00471 }else{
00472
00473 new_metx += metCorrection_x(aod_px,new_px);
00474 new_mety += metCorrection_y(aod_py,new_py);
00475 new_metsum += metCorrection_sum(aod_pt,new_pt);
00476
00477 }
00478 new_met=sqrt( new_metx*new_metx + new_mety*new_mety );
00479
00480 } else {
00481
00482
00483
00484 if (id_pdg==13){
00485 double aod_px=aod_tlv.Px();
00486 double aod_py=aod_tlv.Py();
00487 double aod_pt=aod_tlv.Pt();
00488
00489 new_metx += metCorrection_x(aod_px,0.0);
00490 new_mety += metCorrection_y(aod_py,0.0);
00491 new_metsum += metCorrection_sum(aod_pt,0.0);
00492
00493 new_met=sqrt( new_metx*new_metx + new_mety*new_mety );
00494 }
00495
00496
00497
00498 vp_syst->erase(vp_syst->begin()+il);
00499
00500 }
00501
00502 }
00503
00504
00505
00506 met_syst->set_met_x(new_metx);
00507 met_syst->set_met_y(new_mety);
00508 met_syst->set_met_sum(new_metsum);
00509
00510
00511
00512
00513
00514 *vp_syst=m_tools.sort_particles(*vp_syst);
00515
00516
00517
00518
00519
00520 }
00521
00522