37 LabGenFrame::LabGenFrame(
const std::string& sname,
38 const std::string& stitle) :
39 LabFrame<GeneratorFrame>(sname, stitle)
51 m_FailTolerance = 1000;
54 LabGenFrame::~LabGenFrame() {}
60 void LabGenFrame::SetThreeVector(
const TVector3& P){
66 void LabGenFrame::SetPToverM(
double val){
69 m_Log <<
"Unable to set transverse momentum ";
70 m_Log <<
"to negative value: " << val <<
"*mass";
78 void LabGenFrame::SetTransverseMomentum(
double val){
81 m_Log <<
"Unable to set transverse momentum ";
82 m_Log <<
"to negative value: " << val;
90 void LabGenFrame::SetLongitudinalMomentum(
double val){
94 void LabGenFrame::SetPhi(
double val){
95 while(val > acos(-1.)*2.) val -= acos(-1.)*2.;
96 while(val < 0.) val += acos(-1.)*2.;
100 void LabGenFrame::ResetGenFrame(){
105 bool LabGenFrame::InitializeAnalysis(){
106 m_Log << LogVerbose <<
"Initializing this tree for analysis..." << LogEnd;
109 UnSoundBody(RF_FUNCTION);
110 return SetMind(
false);
113 if(!InitializeAnalysisRecursive()){
114 m_Log << LogWarning <<
"...Unable to recursively initialize analysis" << LogEnd;
115 return SetMind(
false);
118 for(
int i = 0; i < m_NBurnInMCMC; i++)
119 if(!IterateRecursiveMCMC()){
120 m_Log << LogWarning <<
"...Unable to recursively initialize analysis" << LogEnd;
121 return SetMind(
false);
124 m_Log << LogVerbose <<
"...Done" << LogEnd;
125 return SetMind(
true);
128 void LabGenFrame::SetN_MCMCBurnIn(
int N){
130 m_NBurnInMCMC = std::max(0,N);
133 void LabGenFrame::SetN_MCMCDiscard(
int N){
135 m_NDiscardMCMC = std::max(1,N);
138 void LabGenFrame::SetFailTolerance(
int Nfail){
139 m_FailTolerance = Nfail;
142 bool LabGenFrame::InitializeGenAnalysis(){
144 UnSoundBody(RF_FUNCTION);
145 return SetMind(
false);
149 if(child.IsVariableMassMCMC()){
150 double ChildMass, ChildProb;
151 child.GenerateMassMCMC(ChildMass, ChildProb, m_MaxM);
152 m_ChildMassMCMC = ChildMass;
153 m_ChildProbMCMC = ChildProb;
154 SetMassMCMC(ChildMass, child);
156 m_ChildMassMCMC = child.GetMass();
157 m_ChildProbMCMC = 1.;
160 return SetMind(
true);
163 bool LabGenFrame::IterateMCMC(){
165 if(child.IsVariableMassMCMC()){
166 double ChildMass, ChildProb = 0.;
167 child.GenerateMassMCMC(ChildMass, ChildProb, m_MaxM);
169 double probOld = GetProbMCMC(m_ChildMassMCMC)*
170 child.GetProbMCMC(m_ChildMassMCMC)/m_ChildProbMCMC;
172 double probNew = GetProbMCMC(ChildMass)*
173 child.GetProbMCMC(ChildMass)/ChildProb;
175 if(probNew/probOld > GetRandom()){
176 m_ChildMassMCMC = ChildMass;
177 m_ChildProbMCMC = ChildProb;
178 SetMassMCMC(ChildMass, child);
180 SetMassMCMC(m_ChildMassMCMC, child);
184 return SetMind(
true);
187 bool LabGenFrame::GenerateFrame(){
193 if(m_Phi < 0.) m_Phi = 2.*acos(-1.)*GetRandom();
196 P.SetPxPyPzE(m_PToM*M*cos(m_Phi), m_PToM*M*sin(m_Phi), m_PL,
197 sqrt(m_PL*m_PL + M*M*(1. + m_PToM*m_PToM)));
199 P.SetPxPyPzE(m_PT*cos(m_Phi), m_PT*sin(m_Phi), m_PL,
200 sqrt(m_PT*m_PT + m_PL*m_PL + M*M));
203 std::vector<TLorentzVector> ChildVector;
204 ChildVector.push_back(P);
205 SetChildren(ChildVector);
207 return SetSpirit(
true);
210 bool LabGenFrame::ClearEvent(){
214 return ClearEventRecursive();
217 bool LabGenFrame::AnalyzeEvent(){
222 for(
int i = 0; i < m_NDiscardMCMC; i++)
223 if(!IterateRecursiveMCMC())
224 return SetSpirit(
false);
226 if(!AnalyzeEventRecursive()){
227 return SetSpirit(
false);
230 pass = EventInAcceptance();
234 if(tries > m_FailTolerance &&
235 m_FailTolerance > 0){
237 m_Log <<
"Failed to generate event in ";
238 m_Log <<
"acceptance in " << tries;
239 m_Log <<
" tries. Giving up." << LogEnd;
240 return SetSpirit(
false);
245 return SetSpirit(
true);
virtual void Clear()
Clears GeneratorFrame of all connections to other objects.
virtual double GetMass() const
Get the mass of this frame.
virtual void Clear()
Clears GeneratorFrame of all connections to other objects.
virtual GeneratorFrame & GetChildFrame(int i=0) const
Get the frame of the i th child.