#include "ATOOLS/Math/Variable.H" #include "ATOOLS/Org/Message.H" #include "ATOOLS/Math/Vector.H" #include "ATOOLS/Math/Algebra_Interpreter.H" #include "ATOOLS/Org/MyStrStream.H" #include "ATOOLS/Org/Exception.H" using namespace ATOOLS; template Variable_Base::Variable_Base(const std::string &name, const std::string &idname): m_name(name), m_idname(idname) { if (m_idname=="") m_idname=m_name; } template Variable_Base::~Variable_Base() {} template ValueType Variable_Base::Value (const Vec3D *vectors,const int &n) const { msg_Error()<<"Variable_Base::Value("< ValueType Variable_Base::Value (const Vec4D *vectors,const int &n) const { msg_Error()<<"Variable_Base::Value("< bool Variable_Base::Init(const std::string &name) { return true; } template Algebra_Interpreter *Variable_Base::GetInterpreter() const { return NULL; } template void Variable_Base::ShowVariables(const int mode) { if (!msg_LevelIsInfo() || mode==0) return; msg_Out()<<"Variable_Base::ShowVariables(): {\n\n"; Variable_Getter::PrintGetterInfo(msg->Out(),20); msg_Out()<<"\n}"< const std::string &Variable_Base::Name() const { return m_name; } template const std::string &Variable_Base::IDName() const { return m_idname; } template std::string Variable_Base::SelectorID() const { return m_selectorid; } template ValueType Variable_Base::operator() (const Vec3D *vectors,const int &n) const { return Value(vectors,n); } template ValueType Variable_Base::operator() (const Vec4D *vectors,const int &n) const { return Value(vectors,n); } template class No_Variable: public Variable_Base { public: No_Variable(); };// end of class No_Variable template No_Variable::No_Variable(): Variable_Base("") {} double Get(Algebra_Interpreter *const inter) { Term *res(inter->Calculate()); return res->Get(); } template class Calc_Variable: public Variable_Base, public Tag_Replacer { private: std::string m_formula; Algebra_Interpreter *p_interpreter; Tag_Replacer *p_replacer; mutable std::vector m_p; public: Calc_Variable(const std::string &tag); ~Calc_Variable(); ValueType Value(const Vec3D *vectors,const int &n) const { m_p.resize(n); for (int i(0);i Calc_Variable::Calc_Variable(const std::string &tag): Variable_Base("Calc"), m_formula(tag), p_interpreter(new Algebra_Interpreter()), p_replacer(NULL) { p_interpreter->SetTagReplacer(this); Init(m_formula); } template bool Calc_Variable::Init(const std::string &name) { m_formula=name; msg_Debugging()< ((Tag_Replacer*)ToType(reps)); if (p_replacer==NULL) THROW(fatal_error,"Invalid pointer"); } size_t bpos(m_formula.find("(")); if (bpos==std::string::npos) return false; m_formula=m_formula.substr(bpos); if ((bpos=m_formula.rfind(")"))==std::string::npos) return false; m_formula=m_formula.substr(1,bpos-1); if (m_formula.length()==0) return false; size_t pos(m_formula.find("p[")), nmf(0); while (pos!=std::string::npos) { std::string ex(m_formula.substr(pos+2,m_formula.find("]",pos)-pos-2)); p_interpreter->AddTag("p["+ex+"]","(1.0,0.0,0.0,1.0)"); pos=m_formula.find("p[",pos+ex.length()+1); nmf=Max(nmf,ToType(ex)); } m_p.resize(nmf+1); p_interpreter->Interprete(m_formula); if (msg_LevelIsTracking()) p_interpreter->PrintEquation(); return true; } template Calc_Variable::~Calc_Variable() { delete p_interpreter; } template std::string Calc_Variable::ReplaceTags(std::string &expr) const { return p_interpreter->ReplaceTags(expr); } template ATOOLS::Term *Calc_Variable::ReplaceTags(ATOOLS::Term *term) const { if (term->Id()>=100) term->Set(m_p[term->Id()-100]); else if (p_replacer!=NULL) return p_replacer->ReplaceTags(term); else THROW(fatal_error,"Invalid tag."); return term; } template void Calc_Variable::AssignId(ATOOLS::Term *term) { if (term->Tag().find("p[")==0) { size_t i(ToType(term->Tag().substr(2,term->Tag().length()-3))); if (i>=m_p.size()) THROW(fatal_error,"Invalid tag."); term->SetId(100+i); } else if (p_replacer!=NULL) p_replacer->AssignId(term); else THROW(fatal_error,"Invalid tag."); } template class Count: public Variable_Base { public: Count(); ValueType Value(const Vec3D *vectors,const int &n) const { return n; } ValueType Value(const Vec4D *vectors,const int &n) const { return n; } };// end of class Count template Count::Count(): Variable_Base("Count") {} template class PPerp: public Variable_Base { public: PPerp(); ValueType Value(const Vec3D *vectors,const int &n) const { Vec4D mom(0.0,vectors[0]); for (int i(1);i PPerp::PPerp(): Variable_Base("PT") { this->m_selectorid="PT"; } template class EPerp: public Variable_Base { public: EPerp(); ValueType Value(const Vec4D *vectors,const int &n) const { Vec4D mom(vectors[0]); for (int i(1);i EPerp::EPerp(): Variable_Base("ET") { this->m_selectorid="ET"; } template class MPerp: public Variable_Base { public: MPerp(); ValueType Value(const Vec4D *vectors,const int &n) const { Vec4D mom(vectors[0]); for (int i(1);i MPerp::MPerp(): Variable_Base("mT") {} template class MTWW: public Variable_Base { public: MTWW(); ValueType Value(const Vec4D *vectors,const int &n) const { if (n!=3) THROW(fatal_error,"Variable MTWW only defined for three momenta."); Vec4D ll(vectors[0]+vectors[1]); double m2ll(ll*ll); Vec4D miss(vectors[2]); Vec3D llp = Vec3D(ll[1],ll[2],0.); Vec3D missp = Vec3D(miss[1],miss[2],0.); return sqrt(sqr(sqrt(llp*llp+m2ll)+sqrt(missp*missp+m2ll))-(llp+missp)*(llp+missp)); } };// end of class MTWW template MTWW::MTWW(): Variable_Base("mTWW") {} template class HT: public Variable_Base { public: HT(); ValueType Value(const Vec4D *vectors,const int &n) const { double ht(vectors[0].PPerp()); for (int i(1);i HT::HT(): Variable_Base("HT") {} template class Energy: public Variable_Base { public: Energy(); ValueType Value(const Vec4D *vectors,const int &n) const { double E(vectors[0][0]); for (int i(1);i Energy::Energy(): Variable_Base("E") { this->m_selectorid="Energy"; } template class Mass: public Variable_Base { public: Mass(); ValueType Value(const Vec4D *vectors,const int &n) const { Vec4D mom(vectors[0]); for (int i(1);i Mass::Mass(): Variable_Base("m") { this->m_selectorid="Mass"; } template class Rapidity: public Variable_Base { public: Rapidity(); ValueType Value(const Vec4D *vectors,const int &n) const { Vec4D mom(vectors[0]); for (int i(1);i Rapidity::Rapidity(): Variable_Base("y") { this->m_selectorid="Rapidity"; } template class Eta: public Variable_Base { public: Eta(); ValueType Value(const Vec3D *vectors,const int &n) const { Vec4D mom(0.0,vectors[0]); for (int i(1);i Eta::Eta(): Variable_Base("Eta") { this->m_selectorid="PseudoRapidity"; } template class BTheta: public Variable_Base { public: BTheta(); ValueType Value(const Vec3D *vectors,const int &n) const { Vec4D mom(0.0,vectors[0]); for (int i(1);i BTheta::BTheta(): Variable_Base("Theta") { this->m_selectorid="BeamAngle"; } template class Phi: public Variable_Base { public: Phi(); ValueType Value(const Vec3D *vectors,const int &n) const { Vec4D mom(0.0,vectors[0]); for (int i(1);i Phi::Phi(): Variable_Base("Phi") {} template class DEta: public Variable_Base { public: DEta(); ValueType Value(const Vec3D *vectors) const { return dabs(Vec4D(0.0,vectors[1]).DEta(Vec4D(0.0,vectors[0]))); } ValueType Value(const Vec4D *vectors,const int &n) const { return dabs(vectors[1].DEta(vectors[0])); } };// end of class DEta template DEta::DEta(): Variable_Base("DEta") {} template class DY: public Variable_Base { public: DY(); ValueType Value(const Vec3D *vectors) const { return Vec4D(0.0,vectors[1]).DY(Vec4D(0.0,vectors[0])); } ValueType Value(const Vec4D *vectors,const int &n) const { return vectors[1].DY(vectors[0]); } };// end of class DY template DY::DY(): Variable_Base("DY") {} template class DPhi: public Variable_Base { public: DPhi(); ValueType Value(const Vec3D *vectors) const { return Vec4D(0.0,vectors[1]).DPhi(Vec4D(0.0,vectors[0])); } ValueType Value(const Vec4D *vectors,const int &n) const { return vectors[1].DPhi(vectors[0]); } };// end of class DPhi template DPhi::DPhi(): Variable_Base("DPhi") {} template class DR: public Variable_Base { public: DR(); ValueType Value(const Vec3D *vectors) const { return Vec4D(0.0,vectors[1]).DR(Vec4D(0.0,vectors[0])); } ValueType Value(const Vec4D *vectors,const int &n) const { return vectors[1].DR(vectors[0]); } };// end of class DR template DR::DR(): Variable_Base("DR") {} template class Theta2: public Variable_Base { public: Theta2(); ValueType Value(const Vec3D *vectors) const { return Vec4D(0.0,vectors[1]).Theta(Vec4D(0.0,vectors[0])); } ValueType Value(const Vec4D *vectors,const int &n) const { return vectors[1].Theta(vectors[0]); } };// end of class Theta2 template Theta2::Theta2(): Variable_Base("Theta2") { this->m_selectorid="Angle"; } template class ATOOLS::Variable_Base; #define COMPILE__Getter_Function #define OBJECT_TYPE Variable_Base #define PARAMETER_TYPE std::string #define EXACTMATCH false #include "ATOOLS/Org/Getter_Function.C" template Variable_Base *GetVariable(const std::string ¶meter) { return new Class(); } #define DEFINE_GETTER_METHOD(CLASS) \ Variable_Base * \ ATOOLS::Getter,std::string,CLASS>:: \ operator()(const std::string ¶meter) const \ { return GetVariable(parameter); } #define DEFINE_PRINT_METHOD(CLASS,PRINT) \ void ATOOLS::Getter,std::string,CLASS>:: \ PrintInfo(std::ostream &str,const size_t width) const \ { str<,std::string,DISP); \ DEFINE_GETTER_METHOD(CLASS) \ DEFINE_PRINT_METHOD(CLASS,PRINT) template class No_Variable; DEFINE_VARIABLE_GETTER(No_Variable,"","",0) template class Calc_Variable; DECLARE_ND_GETTER(Calc_Variable,"Calc", Variable_Base,std::string,1); Variable_Base * ATOOLS::Getter,std::string,Calc_Variable >:: operator()(const std::string ¶meter) const { return new Calc_Variable(parameter); } void ATOOLS::Getter,std::string,Calc_Variable >:: PrintInfo(std::ostream &str,const size_t width) const { str<<"calculator, usage: Calc()"; } template class PPerp; DEFINE_VARIABLE_GETTER(PPerp,"PT","p_\\perp",1) template class EPerp; DEFINE_VARIABLE_GETTER(EPerp,"ET","E_\\perp",1) template class MPerp; DEFINE_VARIABLE_GETTER(MPerp,"mT","m_\\perp",1) template class MTWW; DEFINE_VARIABLE_GETTER(MTWW,"mTWW","m_\\perp(WW)",1) template class HT; DEFINE_VARIABLE_GETTER(HT,"HT","H_T",1) template class Count; DEFINE_VARIABLE_GETTER(Count,"N","number",1) template class Energy; DEFINE_VARIABLE_GETTER(Energy,"E","E",1) template class Mass; DEFINE_VARIABLE_GETTER(Mass,"m","m",1) template class Rapidity; DEFINE_VARIABLE_GETTER(Rapidity,"y","y",1) template class Eta; DEFINE_VARIABLE_GETTER(Eta,"Eta","\\eta",1) template class BTheta; DEFINE_VARIABLE_GETTER(BTheta,"Theta","\\theta",1) template class Phi; DEFINE_VARIABLE_GETTER(Phi,"Phi","\\phi",1) template class Theta2; DEFINE_VARIABLE_GETTER(Theta2,"Theta2","\\theta_{ij}",1) template class DEta; DEFINE_VARIABLE_GETTER(DEta,"DEta","\\Delta\\eta_{ij}",1) template class DY; DEFINE_VARIABLE_GETTER(DY,"DY","\\Delta y_{ij}",1) template class DPhi; DEFINE_VARIABLE_GETTER(DPhi,"DPhi","\\Delta\\phi_{ij}",1) template class DR; DEFINE_VARIABLE_GETTER(DR,"DR","\\Delta R_{ij}",1)