CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TFitConstraintEp.cc
Go to the documentation of this file.
1 // Classname: TFitConstraintEp
2 // Author: Jan E. Sundermann, Verena Klose (TU Dresden)
3 
4 //________________________________________________________________
5 //
6 // TFitConstraintEp::
7 // --------------------
8 //
9 // Fit constraint: energy and momentum conservation
10 //
11 
14 #include <iostream>
15 #include <iomanip>
16 #include "TClass.h"
17 
18 //----------------
19 // Constructor --
20 //----------------
21 
23  : TAbsFitConstraint(), _particles(0), _constraint(0.), _component(TFitConstraintEp::pX) {}
24 
26  const TString& title,
27  TFitConstraintEp::component thecomponent,
28  Double_t constraint)
29  : TAbsFitConstraint(name, title), _constraint(constraint), _component(thecomponent) {}
30 
31 TFitConstraintEp::TFitConstraintEp(std::vector<TAbsFitParticle*>* particles,
32  TFitConstraintEp::component thecomponent,
33  Double_t constraint)
34  : TAbsFitConstraint(), _particles(0), _constraint(constraint), _component(thecomponent) {
35  // particles: vector containing pointer to TAbsFitParticle objects.
36  // Energy or momentum conservation will be calculated for
37  // those particles.
38  // thecomponent: conserved 4vector component ( pX, pY, pZ, E ). For
39  // full 4vector conservation four objects of type TFitConstraintEp
40  // are needed (four constraints)
41  // constraint:value of energy or momentum constraint ( e.g. sum[ pX_i ] = constraint )
42 
43  if (particles) {
44  _particles = (*particles);
45  }
46 }
47 
49  const TString& title,
50  std::vector<TAbsFitParticle*>* particles,
51  TFitConstraintEp::component thecomponent,
52  Double_t constraint)
53  : TAbsFitConstraint(name, title), _particles(0), _constraint(constraint), _component(thecomponent) {
54  // particles: vector containing pointer to TAbsFitParticle objects.
55  // Energy or momentum conservation will be calculated for
56  // those particles.
57  // thecomponent: conserved 4vector component ( pX, pY, pZ, E ). For
58  // full 4vector conservation four objects of type TFitConstraintEp
59  // are needed (four constraints)
60  // constraint:value of energy or momentum constraint ( e.g. sum[ pX_i ] = constraint )
61 
62  if (particles) {
63  _particles = (*particles);
64  }
65 }
66 
67 //--------------
68 // Destructor --
69 //--------------
71 
73  // Add one particles to list of constrained particles
74 
75  _particles.push_back(particle);
76 }
77 
80  TAbsFitParticle* p3,
81  TAbsFitParticle* p4,
82  TAbsFitParticle* p5,
83  TAbsFitParticle* p6,
84  TAbsFitParticle* p7,
85  TAbsFitParticle* p8,
86  TAbsFitParticle* p9,
87  TAbsFitParticle* p10) {
88  // Add many particles to list of constrained particles
89 
90  if (p1)
91  addParticle(p1);
92  if (p2)
93  addParticle(p2);
94  if (p3)
95  addParticle(p3);
96  if (p4)
97  addParticle(p4);
98  if (p5)
99  addParticle(p5);
100  if (p6)
101  addParticle(p6);
102  if (p7)
103  addParticle(p7);
104  if (p8)
105  addParticle(p8);
106  if (p9)
107  addParticle(p9);
108  if (p10)
109  addParticle(p10);
110 }
111 
112 //--------------
113 // Operations --
114 //--------------
116  // returns derivative df/dP with P=(p,E) and f the constraint (f=0).
117  // The matrix contains one row (df/dp, df/dE).
118 
119  TMatrixD* DerivativeMatrix = new TMatrixD(1, 4);
120  (*DerivativeMatrix) *= 0.;
121  (*DerivativeMatrix)(0, (int)_component) = 1.;
122  return DerivativeMatrix;
123 }
124 
126  // Get initial value of constraint (before the fit)
127 
128  Double_t InitValue(0);
129  UInt_t Npart = _particles.size();
130  for (unsigned int i = 0; i < Npart; i++) {
131  const TLorentzVector* FourVec = _particles[i]->getIni4Vec();
132  InitValue += (*FourVec)[(int)_component];
133  }
134  InitValue -= _constraint;
135  return InitValue;
136 }
137 
139  // Get value of constraint after the fit
140 
141  Double_t CurrentValue(0);
142  UInt_t Npart = _particles.size();
143  for (unsigned int i = 0; i < Npart; i++) {
144  const TLorentzVector* FourVec = _particles[i]->getCurr4Vec();
145  CurrentValue += (*FourVec)[(int)_component];
146  }
147  CurrentValue -= _constraint;
148  return CurrentValue;
149 }
150 
152  // Collect information to be used for printout
153 
154  std::stringstream info;
155  info << std::scientific << std::setprecision(6);
156 
157  info << "__________________________" << std::endl << std::endl;
158  info << "OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << std::endl;
159 
160  info << "initial value: " << getInitValue() << std::endl;
161  info << "current value: " << getCurrentValue() << std::endl;
162  info << "component: " << _component << std::endl;
163  info << "constraint: " << _constraint << std::endl;
164 
165  return info.str();
166 }
167 
169  // Print constraint contents
170 
171  edm::LogVerbatim("KinFitter") << this->getInfoString();
172 }
Log< level::Info, true > LogVerbatim
static const TGPicture * info(bool iBackgroundIsBlack)
const TString p2
Definition: fwPaths.cc:13
TMatrixD * getDerivative(TAbsFitParticle *particle) override
Double_t getInitValue() override
void addParticles(TAbsFitParticle *p1, TAbsFitParticle *p2=nullptr, TAbsFitParticle *p3=nullptr, TAbsFitParticle *p4=nullptr, TAbsFitParticle *p5=nullptr, TAbsFitParticle *p6=nullptr, TAbsFitParticle *p7=nullptr, TAbsFitParticle *p8=nullptr, TAbsFitParticle *p9=nullptr, TAbsFitParticle *p10=nullptr)
Double_t getCurrentValue() override
void addParticle(TAbsFitParticle *particle)
const TString p1
Definition: fwPaths.cc:12
TString getInfoString() override
void print() override
TFitConstraintEp::component _component
~TFitConstraintEp() override
std::vector< TAbsFitParticle * > _particles