#include "Top_MET.h" #include double Top_MET::SoftJetEM_FractionUncert[]={0.105}; double Top_MET::SoftJetEM_SumETBins[]={1000}; double Top_MET::SoftJetEM_NBins=1; double Top_MET::CellOutEM_FractionUncert[]={0.132}; double Top_MET::CellOutEM_SumETBins[]={1000}; double Top_MET::CellOutEM_NBins=1; //Setup uncerianties for the CellOut double Top_MET::SoftJetLC_FractionUncert[]={0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0, 55.0, 60.0, 65.0, 70.0, 75.0, 80.0, 85.0, 90.0, 95.0, 100.0, 105.0, 110.0, 115.0, 120.0, 125.0, 130.0, 135.0, 140.0, 145.0, 150.0, 155.0, 160.0, 165.0, 170.0, 175.0, 180.0, 185.0, 190.0, 195.0, 200.0, 205.0, 210.0, 215.0, 220.0, 225.0, 230.0, 235.0, 240.0, 245.0, 250.0, 255.0, 260.0, 265.0, 270.0, 275.0, 280.0, 285.0, 290.0, 295.0, 300.0, 305.0, 310.0, 315.0, 320.0, 325.0, 330.0, 335.0, 340.0, 345.0, 350.0, 355.0, 360.0, 365.0, 370.0, 375.0, 380.0, 385.0, 390.0, 395.0, 400.0, 405.0, 410.0, 415.0, 420.0, 425.0, 430.0, 455.0, 465.0, 470.0, 475.0, 500.0, 505.0}; double Top_MET::SoftJetLC_SumETBins[]={0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0, 55.0, 60.0, 65.0, 70.0, 75.0, 80.0, 85.0, 90.0, 95.0, 100.0, 105.0, 110.0, 115.0, 120.0, 125.0, 130.0, 135.0, 140.0, 145.0, 150.0, 155.0, 160.0, 165.0, 170.0, 175.0, 180.0, 185.0, 190.0, 195.0, 200.0, 205.0, 210.0, 215.0, 220.0, 225.0, 230.0, 235.0, 240.0, 245.0, 250.0, 255.0, 260.0, 265.0, 270.0, 275.0, 280.0, 285.0, 290.0, 295.0, 300.0, 305.0, 310.0, 315.0, 320.0, 325.0, 330.0, 335.0, 340.0, 345.0, 350.0, 355.0, 360.0, 365.0, 370.0, 375.0, 380.0, 385.0, 390.0, 395.0, 400.0, 405.0, 410.0, 415.0, 420.0, 425.0, 430.0, 455.0, 465.0, 470.0, 475.0, 500.0, 505.0}; double Top_MET::SoftJetLC_NBins=93; double Top_MET::CellOutEFlow_FractionUncert[]={0.136409, 0.153857, 0.153689, 0.149694, 0.138453, 0.139799, 0.133924, 0.139531, 0.138844, 0.134789, 0.138834, 0.132662, 0.142114, 0.13908, 0.13661, 0.128625, 0.133791, 0.125408, 0.122293, 0.133035, 0.132411, 0.131334, 0.128113, 0.13843, 0.12271, 0.129, 0.125528, 0.125005, 0.130233, 0.125374, 0.120071, 0.125658, 0.121132, 0.121722, 0.113541, 0.105426, 0.109559, 0.0875806, 0.06, 0.166667, 0.215}; double Top_MET::CellOutEFlow_SumETBins[]={-5.0, 0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0, 55.0, 60.0, 65.0, 70.0, 75.0, 80.0, 85.0, 90.0, 95.0, 100.0, 105.0, 110.0, 115.0, 120.0, 125.0, 130.0, 135.0, 140.0, 145.0, 150.0, 155.0, 160.0, 165.0, 170.0, 175.0, 180.0, 185.0, 190.0, 195.0}; double Top_MET::CellOutEFlow_NBins=41; //constructor Top_MET::Top_MET(): GeV(1000) ,JetPtThreshold(20*GeV) ,METComOk(false) ,METWeightsOK(false) ,pileupsigma(0.0) { Reset(); } //destructor Top_MET::~Top_MET(){} void Top_MET::Reset(){ e_scaled.clear(); e.clear(); ph_scaled.clear(); ph.clear(); jet_scaled.clear(); jet.clear(); jet_em.clear(); mucb_scaled.clear(); mucb.clear(); mums_scaled.clear(); mums.clear(); muid_scaled.clear(); muid.clear(); Jets_JESup.clear(); SoftJet_sigma=0.0; CellOut_sigma=0.0; pileupsigma=0.0; } void Top_MET::Set_Electrons(std::vector e_scaled_, std::vector e_){ e_scaled=e_scaled_; e=e_; } void Top_MET::Set_Photons(std::vector ph_scaled_, std::vector ph_){ ph_scaled=ph_scaled_; ph=ph_; } void Top_MET::Set_Jets(std::vector jet_scaled_, std::vector jet_, std::vector jet_em_){ jet_scaled=jet_scaled_; jet=jet_; jet_em=jet_em_; } void Top_MET::Set_Muons(std::vector mucb_scaled_, std::vector mucb_, std::vector mums_scaled_, std::vector mums_, std::vector muid_scaled_, std::vector muid_){ mucb_scaled=mucb_scaled_; mucb=mucb_; mums_scaled=mums_scaled_; mums=mums_; muid_scaled=muid_scaled_; muid=muid_; } void Top_MET::ApplySoftJetUncertainty(float sigma, std::vector Jets_JESup_, int softjet_sysType){ SoftJet_sigma=sigma; Jets_JESup=Jets_JESup_; if(softjet_sysType==EM || softjet_sysType==LC) SoftJet_SysType=softjet_sysType; else{ std::cout << "Top_MET::ApplyCellOutUncertainty Invalid value for SoftJet_sysType. Using EM" << std::endl; SoftJet_SysType=EM; } } void Top_MET::ApplyCellOutUncertainty(float sigma,int cellout_sysType){ CellOut_sigma=sigma; if(cellout_sysType==EM || cellout_sysType==EFlow) CellOut_SysType=cellout_sysType; else{ std::cout << "Top_MET::ApplyCellOutUncertainty Invalid value for CellOut_sysType. Using EM" << std::endl; CellOut_SysType=EM; } } void Top_MET::ApplyPileupUncertainty(float sigma){ pileupsigma=sigma; } float Top_MET::MET_EtMiss(bool correct,bool METComp,int type){ float sumet(0),ex(0),ey(0); Get_MET(sumet,ex,ey,correct,METComp,type); return sqrt(ex*ex+ey*ey); } float Top_MET::MET_EyMiss(bool correct,bool METComp,int type){ float sumet(0),ex(0),ey(0); Get_MET(sumet,ex,ey,correct,METComp,type); return ey; } float Top_MET::MET_ExMiss(bool correct,bool METComp,int type){ float sumet(0),ex(0),ey(0); Get_MET(sumet,ex,ey,correct,METComp,type); return ex; } float Top_MET::MET_SumEt(bool correct,bool METComp,int type){ float sumet(0),ex(0),ey(0); Get_MET(sumet,ex,ey,correct,METComp,type); return sumet; } float Top_MET::MET_MetPhi(bool correct,bool METComp,int type){ float sumet(0),ex(0),ey(0); Get_MET(sumet,ex,ey,correct,METComp,type); return TMath::ATan2(ey,ex); } void Top_MET::Get_MET(float &met_et, float &met_sumet, float &met_etx, float &met_ety, float &met_phi, bool correct, bool METComp, int type){ Get_MET(met_sumet,met_etx,met_ety,correct,METComp,type); met_phi=TMath::ATan2(met_ety,met_etx); met_et=sqrt(met_etx*met_etx+met_ety*met_ety); } void Top_MET::Get_MET(float &met_sumet, float &met_etx, float &met_ety, bool correct, bool METComp, int type){ //set Default for MET composition or Error. met_sumet=0; met_etx=0; met_ety=0; if(!METComOk){ std::cout << "Error Met composition has not been set (Top_MET::Get_MET)" << std::endl; return; } if(!METWeightsOK){ std::cout << "Error Met Weights have not been set (Top_MET::Get_MET)" << std::endl; return; } if(METComp){ met_sumet=0; met_etx=0; met_ety=0; } else if(type==MET_All){ met_sumet=(*MET_sumet); met_etx=(*MET_etx); met_ety=(*MET_ety); } else if(type==MET_e){ met_sumet=(*MET_RefEle_sumet); met_etx=(*MET_RefEle_etx); met_ety=(*MET_RefEle_ety); } else if(type==MET_ph){ met_sumet=(*MET_RefGamma_sumet); met_etx=(*MET_RefGamma_etx); met_ety=(*MET_RefGamma_ety); } else if(type==MET_jet){ met_sumet=(*MET_RefJet_sumet); met_etx=(*MET_RefJet_etx); met_ety=(*MET_RefJet_ety); } else if(type==MET_softjet){ met_sumet=(*MET_SoftJets_sumet); met_etx=(*MET_SoftJets_etx); met_ety=(*MET_SoftJets_ety); } else if(type==MET_mu){ met_sumet=(*MET_Muon_Total_Muid_sumet); met_etx=(*MET_Muon_Total_Muid_etx); met_ety=(*MET_Muon_Total_Muid_ety); } else if(type==MET_cellout){ met_sumet=(*MET_CellOut_sumet); met_etx=(*MET_CellOut_etx); met_ety=(*MET_CellOut_ety); } else{ std::cout << "Error incorrect MET Type selected: " << type << " --- using default settings: results maybe invalid" << std::endl; Get_MET(met_sumet,met_etx,met_ety); return; } if(!correct && !METComp){ return; } ///////////////////////////////////////////////////////////////////////////////////////////////////////// // // Start Composition // // Modify MET for scaled Electrons if(type==MET_All || type==MET_e){ for(int i=0; iat(i).at(0); float obj_wy=el_MET_wpy->at(i).at(0); float obj_wt=el_MET_wet->at(i).at(0); float obj_scale=1; if(e.at(i).Pt()!=0 ) obj_scale=e_scaled.at(i).Pt()/e.at(i).Pt(); CorrectMet(met_sumet,met_etx,met_ety,obj_pt,obj_px,obj_py,obj_wt,obj_wx,obj_wy,obj_scale,!METComp); } } //Modify MET for scaled Photons if(type==MET_All || type==MET_ph){ for(int i=0; iat(i).at(0); float obj_wy=ph_MET_wpy->at(i).at(0); float obj_wt=ph_MET_wet->at(i).at(0); float obj_scale=1; if(ph_scaled.at(i).Pt()!=0 && ph.at(i).Pt()!=0 ) obj_scale=ph_scaled.at(i).Pt()/ph.at(i).Pt(); CorrectMet(met_sumet,met_etx,met_ety,obj_pt,obj_px,obj_py,obj_wt,obj_wx,obj_wy,obj_scale,!METComp); } } //Modify MET for scaled Jets if(type==MET_All || type==MET_jet || type==MET_softjet){ for(int i=0; iat(i).at(0); float obj_wy=jet_wpy->at(i).at(0); float obj_wt=jet_wet->at(i).at(0); float obj_scale=1; if(jet_scaled.at(i).Pt()!=0 && jet.at(i).Pt()!=0){ obj_scale=jet_scaled.at(i).Pt()/jet.at(i).Pt(); if(jet_scaled.at(i).Pt()>20*GeV && jet.at(i).Pt()<20*GeV)obj_scale*=jet.at(i).Pt()/jet_em.at(i).Pt(); if(jet_scaled.at(i).Pt()<20*GeV && jet.at(i).Pt()>20*GeV)obj_scale*=jet_em.at(i).Pt()/jet.at(i).Pt(); } if(jet_scaled.at(i).Pt()<20*GeV && jet.at(i).Pt()<20*GeV)obj_scale=1; //do not scale soft jets // remove outof range jets when only looking at the JetRef or the SoftJet term if(type==MET_softjet && ((jet_scaled.at(i).Pt()>=20*GeV && correct) || (!correct && jet.at(i).Pt()>=20*GeV ))) obj_scale=0; if(type==MET_jet && ((jet_scaled.at(i).Pt()<20*GeV && correct) || (!correct && jet.at(i).Pt()<20*GeV))) obj_scale=0; // allow for efficiency systematic uncertainty and put it in the SoftJet term if(jet_scaled.at(i).Pt()==0.0 && jet.at(i).Pt()!=0 && correct){ obj_scale=1; // Soft jet term is at EM scale if(jet.at(i).Pt()>20*GeV) obj_scale=jet_em.at(i).Pt()/jet.at(i).Pt(); if(type==MET_jet) obj_scale=0; } CorrectMet(met_sumet,met_etx,met_ety,obj_pt,obj_px,obj_py,obj_wt,obj_wx,obj_wy,obj_scale,!METComp); } } //Modify MET for scaled muons if(type==MET_All || type==MET_mu){ for(int i=0; iat(i).at(0)) &DEFAULT) { //already setup as default } else if (mu_muid_MET_statusWord->at(i).at(0) &SPECTRO){ // use the muon spectrometer track px and py obj_pt=mums.at(i).Pt(); obj_px=mums.at(i).Px(); obj_py=mums.at(i).Py(); if(mums_scaled.at(i).Pt()!=0 && mums.at(i).Pt()!=0)obj_scale=mums_scaled.at(i).Pt()/mums.at(i).Pt(); } else if (mu_muid_MET_statusWord->at(i).at(0) &TRACK){ // use the muon track px and py obj_pt=muid.at(i).Pt(); obj_px=muid.at(i).Px(); obj_py=muid.at(i).Py(); if(muid_scaled.at(i).Pt()!=0 && muid.at(i).Pt()!=0) obj_scale=muid_scaled.at(i).Pt()/muid.at(i).Pt(); } float obj_wx=mu_muid_MET_wpx->at(i).at(0); float obj_wy=mu_muid_MET_wpy->at(i).at(0); float obj_wt=mu_muid_MET_wet->at(i).at(0); // muons do not contribute to the sumET if(type!=MET_mu) obj_wt=0; CorrectMet(met_sumet,met_etx,met_ety,obj_pt,obj_px,obj_py,obj_wt,obj_wx,obj_wy,obj_scale,!METComp); } } // Add the cell Out for METComp if((type==MET_All || type==MET_cellout) && METComp){ met_sumet+=(*MET_CellOut_sumet); met_etx+=(*MET_CellOut_etx); met_ety+=(*MET_CellOut_ety); } //SoftJet Uncertainty if(SoftJet_sigma!=0.0){ float obj_pt=(*MET_SoftJets_sumet); float obj_px=(*MET_SoftJets_etx); float obj_py=(*MET_SoftJets_ety); float obj_wx=1; float obj_wy=1; float obj_wt=1; float obj_scale=1; float SoftJetSys=0; if(SoftJet_SysType==EM){ SoftJetSys=SoftJetEM_FractionUncert[0]; for(int j=0;j+11E-4){ std::cout << "Top_MET::CheckConsistency Error MET Et for enum MET_Types=" << i << " not consistent at :" <<(MET_EtMiss(false,false,i)-MET_EtMiss(false,true,i)) << " D3PD value: " << MET_EtMiss(false,false,i) << " METComposition value " << MET_EtMiss(false,true,i) << " Please check the variables corresponding to the MET Type " << i << std::endl; } if((MET_ExMiss(false,false,i)-MET_ExMiss(false,true,i))/MET_EtMiss(false,false,i)>1E-4){ std::cout << "Top_MET::CheckConsistency Error MET Ex for enum MET_Types=" << i << " not consistent " <<(MET_ExMiss(false,false,i)-MET_ExMiss(false,true,i)) << " D3PD value: " << MET_ExMiss(false,false,i) << " METComposition value " << MET_ExMiss(false,true,i) << " Please check the variables corresponding to the MET Type " << i << std::endl; } if((MET_EyMiss(false,false,i)-MET_EyMiss(false,true,i))/MET_EtMiss(false,false,i)>1E-4){ std::cout << "Top_MET::CheckConsistency Error MET Ey for enum MET_Types=" << i << " not consistent " <<(MET_EyMiss(false,false,i)-MET_EyMiss(false,true,i)) << " D3PD value: " << MET_EyMiss(false,false,i) << " METComposition value " << MET_EyMiss(false,true,i) << " Please check the variables corresponding to the MET Type " << i << std::endl; } if((MET_SumEt(false,false,i)-MET_SumEt(false,true,i))/MET_SumEt(false,false,i)>1E-4){ std::cout << "Top_MET::CheckConsistency Error MET SumEt for enum MET_Types=" << i << " not consistent " <<(MET_SumEt(false,false,i)-MET_SumEt(false,true,i)) << " D3PD value: " << MET_SumEt(false,false,i) << " METComposition value " << MET_SumEt(false,true,i) << " Please check the variables corresponding to the MET Type " << i << std::endl; } } } void Top_MET::CorrectMet(float &met_sumet, float &met_etx, float &met_ety, float obj_pt, float obj_px, float obj_py, float obj_wt, float obj_wx, float obj_wy, float obj_scale,bool remove){ if(remove){ met_etx+= obj_px*obj_wx; met_ety+= obj_py*obj_wy; met_sumet-= obj_pt*obj_wt; } met_etx-= obj_px*obj_wx*obj_scale; met_ety-= obj_py*obj_wy*obj_scale; met_sumet += obj_pt*obj_wt*obj_scale; } void Top_MET::Set_METComposition( float &MET_etx_, float &MET_ety_, float &MET_sumet_, float &MET_RefEle_sumet_, float &MET_RefEle_etx_, float &MET_RefEle_ety_, float &MET_RefGamma_sumet_, float &MET_RefGamma_etx_, float &MET_RefGamma_ety_, float &MET_RefJet_sumet_, float &MET_RefJet_etx_, float &MET_RefJet_ety_, float &MET_SoftJets_sumet_, float &MET_SoftJets_etx_, float &MET_SoftJets_ety_, float &MET_CellOut_sumet_, float &MET_CellOut_etx_, float &MET_CellOut_ety_, float &MET_Muon_Total_Muid_sumet_, float &MET_Muon_Total_Muid_etx_, float &MET_Muon_Total_Muid_ety_ ){ MET_etx=&MET_etx_; MET_ety=&MET_ety_; MET_sumet=&MET_sumet_; MET_RefEle_sumet=&MET_RefEle_sumet_; MET_RefEle_etx=&MET_RefEle_etx_; MET_RefEle_ety=&MET_RefEle_ety_; MET_RefGamma_sumet=&MET_RefGamma_sumet_; MET_RefGamma_etx=&MET_RefGamma_etx_; MET_RefGamma_ety=&MET_RefGamma_ety_; MET_RefJet_sumet=&MET_RefJet_sumet_; MET_RefJet_etx=&MET_RefJet_etx_; MET_RefJet_ety=&MET_RefJet_ety_; MET_SoftJets_sumet=&MET_SoftJets_sumet_; MET_SoftJets_etx=&MET_SoftJets_etx_; MET_SoftJets_ety=&MET_SoftJets_ety_; MET_CellOut_sumet=&MET_CellOut_sumet_; MET_CellOut_etx=&MET_CellOut_etx_; MET_CellOut_ety=&MET_CellOut_ety_; MET_Muon_Total_Muid_sumet=&MET_Muon_Total_Muid_sumet_; MET_Muon_Total_Muid_etx=&MET_Muon_Total_Muid_etx_; MET_Muon_Total_Muid_ety=&MET_Muon_Total_Muid_ety_; METComOk=true; } void Top_MET::Set_METWeights( std::vector >* el_MET_wpx_, std::vector >* el_MET_wpy_, std::vector >* el_MET_wet_, std::vector >* ph_MET_wpx_, std::vector >* ph_MET_wpy_, std::vector >* ph_MET_wet_, std::vector >* jet_wpx_, std::vector >* jet_wpy_, std::vector >* jet_wet_, std::vector >* mu_muid_MET_statusWord_, std::vector >* mu_muid_MET_wpx_, std::vector >* mu_muid_MET_wpy_, std::vector >* mu_muid_MET_wet_ ){ el_MET_wpx=el_MET_wpx_; el_MET_wpy=el_MET_wpy_; el_MET_wet=el_MET_wet_; ph_MET_wpx=ph_MET_wpx_; ph_MET_wpy=ph_MET_wpy_; ph_MET_wet=ph_MET_wet_; jet_wpx=jet_wpx_; jet_wpy=jet_wpy_; jet_wet=jet_wet_; mu_muid_MET_statusWord=mu_muid_MET_statusWord_; mu_muid_MET_wpx=mu_muid_MET_wpx_; mu_muid_MET_wpy=mu_muid_MET_wpy_; mu_muid_MET_wet=mu_muid_MET_wet_; METWeightsOK=true; } void Top_MET::Get_ElectronWeights(int i,float &wet, float &wpx, float &wpy){ wet=0; wpx=0; wpy=0; if(el_MET_wpx->size()>i && i>=0){ wet=el_MET_wet->at(i).at(0); wpx=el_MET_wpx->at(i).at(0); wpy=el_MET_wpy->at(i).at(0); } } void Top_MET::Get_PhotonWeights(int i,float &wet, float &wpx, float &wpy){ wet=0; wpx=0; wpy=0; if(ph_MET_wpx->size()>i && i>=0){ wet=ph_MET_wet->at(i).at(0); wpx=ph_MET_wpx->at(i).at(0); wpy=ph_MET_wpy->at(i).at(0); } } void Top_MET::Get_JetWeights(int i,float &wet, float &wpx, float &wpy){ wet=0; wpx=0; wpy=0; if(jet_wpx->size()>i && i>=0){ wet=jet_wet->at(i).at(0); wpx=jet_wpx->at(i).at(0); wpy=jet_wpy->at(i).at(0); } } void Top_MET::Get_MuonWeights(int i,float &wet, float &wpx, float &wpy,unsigned int &mu_statusWord){ wet=0; wpx=0; wpy=0; mu_statusWord=0; if(mu_muid_MET_wpx->size()>i && i>=0){ wet=mu_muid_MET_wet->at(i).at(0); wpx=mu_muid_MET_wpx->at(i).at(0); wpy=mu_muid_MET_wpy->at(i).at(0); mu_statusWord=mu_muid_MET_statusWord->at(i).at(0); } }