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(std::vector<TAbsFitParticle*>* particles,
33  TFitConstraintEp::component thecomponent,
34  Double_t constraint)
36  ,_particles(0)
37  ,_constraint(constraint)
38  ,_component(thecomponent)
39 {
40  // particles: vector containing pointer to TAbsFitParticle objects.
41  // Energy or momentum conservation will be calculated for
42  // those particles.
43  // thecomponent: conserved 4vector component ( pX, pY, pZ, E ). For
44  // full 4vector conservation four objects of type TFitConstraintEp
45  // are needed (four constraints)
46  // constraint:value of energy or momentum constraint ( e.g. sum[ pX_i ] = constraint )
47 
48  if (particles) {
49  _particles = (*particles);
50  }
51 }
52 
53 TFitConstraintEp::TFitConstraintEp(const TString &name, const TString &title,
54  std::vector<TAbsFitParticle*>* particles,
55  TFitConstraintEp::component thecomponent,
56  Double_t constraint)
57  :TAbsFitConstraint(name, title)
58  ,_particles(0)
59  ,_constraint(constraint)
60  ,_component(thecomponent)
61 {
62  // particles: vector containing pointer to TAbsFitParticle objects.
63  // Energy or momentum conservation will be calculated for
64  // those particles.
65  // thecomponent: conserved 4vector component ( pX, pY, pZ, E ). For
66  // full 4vector conservation four objects of type TFitConstraintEp
67  // are needed (four constraints)
68  // constraint:value of energy or momentum constraint ( e.g. sum[ pX_i ] = constraint )
69 
70  if (particles) {
71  _particles = (*particles);
72  }
73 }
74 
75 //--------------
76 // Destructor --
77 //--------------
79 
80 }
81 
83  // Add one particles to list of constrained particles
84 
85  _particles.push_back( particle );
86 
87 }
88 
91  TAbsFitParticle* p9, TAbsFitParticle* p10) {
92  // Add many particles to list of constrained particles
93 
94  if (p1) addParticle( p1 );
95  if (p2) addParticle( p2 );
96  if (p3) addParticle( p3 );
97  if (p4) addParticle( p4 );
98  if (p5) addParticle( p5 );
99  if (p6) addParticle( p6 );
100  if (p7) addParticle( p7 );
101  if (p8) addParticle( p8 );
102  if (p9) addParticle( p9 );
103  if (p10) addParticle( p10 );
104 
105 }
106 
107 //--------------
108 // Operations --
109 //--------------
111  // returns derivative df/dP with P=(p,E) and f the constraint (f=0).
112  // The matrix contains one row (df/dp, df/dE).
113 
114  TMatrixD* DerivativeMatrix = new TMatrixD(1,4);
115  (*DerivativeMatrix) *= 0.;
116  (*DerivativeMatrix)(0,(int) _component) = 1.;
117  return DerivativeMatrix;
118 }
119 
120 
122  // Get initial value of constraint (before the fit)
123 
124  Double_t InitValue(0) ;
125  UInt_t Npart = _particles.size();
126  for (unsigned int i=0;i<Npart;i++) {
127  const TLorentzVector* FourVec = _particles[i]->getIni4Vec();
128  InitValue += (*FourVec)[(int) _component];
129  }
130  InitValue -= _constraint;
131  return InitValue;
132 }
133 
135  // Get value of constraint after the fit
136 
137  Double_t CurrentValue(0);
138  UInt_t Npart = _particles.size();
139  for (unsigned int i=0;i<Npart;i++) {
140  const TLorentzVector* FourVec = _particles[i]->getCurr4Vec();
141  CurrentValue += (*FourVec)[(int) _component];
142  }
143  CurrentValue -= _constraint;
144  return CurrentValue;
145 }
146 
148  // Collect information to be used for printout
149 
150  std::stringstream info;
151  info << std::scientific << std::setprecision(6);
152 
153  info << "__________________________" << std::endl
154  << std::endl;
155  info << "OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << std::endl;
156 
157  info << "initial value: " << getInitValue() << std::endl;
158  info << "current value: " << getCurrentValue() << std::endl;
159  info << "component: " << _component << std::endl;
160  info << "constraint: " << _constraint << std::endl;
161 
162  return info.str();
163 
164 }
165 
167  // Print constraint contents
168 
169  edm::LogVerbatim("KinFitter") << this->getInfoString();
170 
171 }
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)
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
unsigned int UInt_t
Definition: FUTypes.h:12
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