CMS 3D CMS Logo

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