CMS 3D CMS Logo

CombinedKinematicConstraintT.h
Go to the documentation of this file.
1 #ifndef CombinedKinematicConstraintT_H
2 #define CombinedKinematicConstraintT_H
3 
8 
9 // this is generic: to be moved elsewhere
10 #include<tuple>
11 #include<functional>
12 #include<algorithm>
13 #include<cassert>
14 
15 // run time iteration
16 template<class TupleType, size_t N>
17 struct do_iterate
18 {
19  template<typename F>
20  static void call(TupleType& t, F f)
21  {
22  f(std::get<N-1>(t));
24  }
25  template<typename F>
26  static void call(TupleType const & t, F f)
27  {
28  f(std::get<N-1>(t));
30  }
31 
32 
33 };
34 
35 template<class TupleType>
36 struct do_iterate<TupleType, 0>
37 {
38  template<typename F>
39  static void call(TupleType&, F)
40  {}
41  template<typename F>
42  static void call(TupleType const &, F)
43  {}
44 };
45 
46 template<class TupleType, typename F>
47 void iterate_tuple(TupleType& t, F f)
48 {
50 }
51 
52 template<class TupleType, typename F>
53 void iterate_tuple(TupleType const& t, F f)
54 {
56 }
57 
58 
60 
61  // a bit less generic
63  struct totDim {
64  typedef typename std::tuple_element<N-1,TupleType>::type Elem;
65  enum { nDim = Elem::nDim + totDim<TupleType,N-1>::nDim};
66  };
67 
68  template<class TupleType>
69  struct totDim<TupleType, 0> {
70  enum { nDim=0};
71  };
72 
73  template<typename T>
74  void sum2(T& x, T y) { x+=y;}
75 
76  // mind: iteration is backward...
77  template<int DIM>
78  struct Place {
79  int offset;
80  Place() : offset(DIM) {}
81  ~Place() {
82  assert(offset==DIM || offset==0);
83  }
84  };
85 
86  template<int DIM>
87  struct PlaceValue : public Place<DIM> {
88  PlaceValue(ROOT::Math::SVector<double, DIM> & iret) : ret(iret){}
89  ROOT::Math::SVector<double, DIM> & ret;
90  template<typename C>
91  void operator()(C const & cs) {
92  this->offset -= C::nDim;
93  ret.Place_at(cs.value(),this->offset);
94  }
95  };
96 
97  template<int DIM, int NTRK>
98  struct PlaceParDer : public Place<DIM> {
99  PlaceParDer(ROOT::Math::SMatrix<double, DIM, 7*NTRK> & iret) : ret(iret){}
100  ROOT::Math::SMatrix<double, DIM, 7*NTRK> & ret;
101  template<typename C>
102  void operator()(C const & cs) {
103  this->offset -= C::nDim;
104  ret.Place_at(cs.parametersDerivative(),this->offset,0);
105  }
106  };
107 
108  template<int DIM>
109  struct PlacePosDer : public Place<DIM> {
110  PlacePosDer(ROOT::Math::SMatrix<double, DIM, 3> & iret) : ret(iret){}
111  ROOT::Math::SMatrix<double, DIM, 3> & ret;
112  template<typename C>
113  void operator()(C const & cs) {
114  this->offset -= C::nDim;
115  ret.Place_at(cs.positionDerivative(),this->offset,0);
116  }
117  };
118 
119 
120 }
121 
122 
134 // maybe a variadic template will be better
135 template< class TupleType, int NTRK >
136 class CombinedKinematicConstraintT : public MultiTrackKinematicConstraintT<NTRK, combinedConstraintHelpers::totDim<TupleType>::nDim>{
137 
138  // need compile time assert on NTRK
139 public:
142  typedef typename super::valueType valueType;
145 
146  typedef TupleType Constraints;
147 
148  //FIXME
149  enum {DIM = super::nDim};
150 
151 
152 public:
154  }
155 
156  // initialize the constraint so it can precompute common qualtities to the three next call
157  virtual void init(const std::vector<KinematicState>& states,
158  const GlobalPoint& point, const GlobalVector& mf) {
160  std::bind(&base::init,std::placeholders::_1,std::ref(states),std::ref(point), std::ref(mf)));
161  }
162 
163 
164 private:
170  void fillValue() const{
172  iterate_tuple(constraints,std::ref(helper));
173  }
174 
182  iterate_tuple(constraints,std::ref(helper));
183  }
184 
192  iterate_tuple(constraints,std::ref(helper));
193  }
194 
195 public:
199  virtual int numberOfEquations() const {
200  int tot=0;
201  iterate_tuple(constraints,std::bind(combinedConstraintHelpers::sum2<int>,std::ref(tot),
202  std::bind(&base::numberOfEquations,std::placeholders::_1)
203  )
204  );
205  return tot;
206  }
207 
209  {
210  return new CombinedKinematicConstraintT(*this);
211  }
212 
213 private:
215 
216 };
217 
218 #endif
Vector3DBase
Definition: Vector3DBase.h:8
MultiTrackKinematicConstraintBaseT::numberOfEquations
virtual int numberOfEquations() const =0
do_iterate::call
static void call(TupleType const &t, F f)
Definition: CombinedKinematicConstraintT.h:26
combinedConstraintHelpers::PlaceParDer::ret
ROOT::Math::SMatrix< double, DIM, 7 *NTRK > & ret
Definition: CombinedKinematicConstraintT.h:100
iterate_tuple
void iterate_tuple(TupleType &t, F f)
Definition: CombinedKinematicConstraintT.h:47
KinematicState.h
AlgebraicObjects.h
CombinedKinematicConstraintT::CombinedKinematicConstraintT
CombinedKinematicConstraintT(Constraints const &iconstraints)
Definition: CombinedKinematicConstraintT.h:153
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
MultiTrackKinematicConstraintT.h
fwrapper::cs
unique_ptr< ClusterSequence > cs
Definition: fastjetfortran_madfks.cc:47
combinedConstraintHelpers::PlaceParDer::operator()
void operator()(C const &cs)
Definition: CombinedKinematicConstraintT.h:102
CombinedKinematicConstraintT::fillParametersDerivative
void fillParametersDerivative() const
Definition: CombinedKinematicConstraintT.h:180
MultiTrackKinematicConstraintT< NTRK, combinedConstraintHelpers::totDim< TupleType >::nDim >::nDim
Definition: MultiTrackKinematicConstraintT.h:41
CombinedKinematicConstraintT::DIM
Definition: CombinedKinematicConstraintT.h:149
MultiTrackKinematicConstraintT< NTRK, combinedConstraintHelpers::totDim< TupleType >::nDim >::positionDerivativeType
ROOT::Math::SMatrix< double, DIM, 3 > positionDerivativeType
Definition: MultiTrackKinematicConstraintT.h:49
cms::cuda::assert
assert(be >=bs)
combinedConstraintHelpers::Place::offset
int offset
Definition: CombinedKinematicConstraintT.h:79
MultiTrackKinematicConstraintT< NTRK, combinedConstraintHelpers::totDim< TupleType >::nDim >::vl
valueType & vl() const
Definition: MultiTrackKinematicConstraintT.h:92
CombinedKinematicConstraintT::parametersDerivativeType
super::parametersDerivativeType parametersDerivativeType
Definition: CombinedKinematicConstraintT.h:143
F
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
MultiTrackKinematicConstraintT< NTRK, combinedConstraintHelpers::totDim< TupleType >::nDim >::jac_d
parametersDerivativeType & jac_d() const
Definition: MultiTrackKinematicConstraintT.h:93
combinedConstraintHelpers::Place::Place
Place()
Definition: CombinedKinematicConstraintT.h:80
DIM
#define DIM(a)
Definition: LogEleMapdb.h:14738
MultiTrackKinematicConstraintT
Definition: MultiTrackKinematicConstraintT.h:39
combinedConstraintHelpers::totDim
Definition: CombinedKinematicConstraintT.h:63
CombinedKinematicConstraintT::positionDerivativeType
super::positionDerivativeType positionDerivativeType
Definition: CombinedKinematicConstraintT.h:144
N
#define N
Definition: blowfish.cc:9
Point3DBase< float, GlobalTag >
combinedConstraintHelpers::PlacePosDer::ret
ROOT::Math::SMatrix< double, DIM, 3 > & ret
Definition: CombinedKinematicConstraintT.h:111
CombinedKinematicConstraintT::fillValue
void fillValue() const
Definition: CombinedKinematicConstraintT.h:170
MultiTrackKinematicConstraintT< NTRK, combinedConstraintHelpers::totDim< TupleType >::nDim >::valueType
ROOT::Math::SVector< double, DIM > valueType
Definition: MultiTrackKinematicConstraintT.h:45
MultiTrackKinematicConstraintBaseT::init
virtual void init(const std::vector< KinematicState > &states, const GlobalPoint &point, const GlobalVector &mf)=0
combinedConstraintHelpers::Place
Definition: CombinedKinematicConstraintT.h:78
MultiTrackKinematicConstraintT< NTRK, combinedConstraintHelpers::totDim< TupleType >::nDim >::jac_e
positionDerivativeType & jac_e() const
Definition: MultiTrackKinematicConstraintT.h:94
combinedConstraintHelpers::PlaceValue
Definition: CombinedKinematicConstraintT.h:87
combinedConstraintHelpers
Definition: CombinedKinematicConstraintT.h:59
combinedConstraintHelpers::PlaceParDer::PlaceParDer
PlaceParDer(ROOT::Math::SMatrix< double, DIM, 7 *NTRK > &iret)
Definition: CombinedKinematicConstraintT.h:99
do_iterate::call
static void call(TupleType &t, F f)
Definition: CombinedKinematicConstraintT.h:20
CombinedKinematicConstraintT::numberOfEquations
virtual int numberOfEquations() const
Definition: CombinedKinematicConstraintT.h:199
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
helper
Definition: helper.py:1
combinedConstraintHelpers::PlacePosDer::PlacePosDer
PlacePosDer(ROOT::Math::SMatrix< double, DIM, 3 > &iret)
Definition: CombinedKinematicConstraintT.h:110
CombinedKinematicConstraintT::init
virtual void init(const std::vector< KinematicState > &states, const GlobalPoint &point, const GlobalVector &mf)
Definition: CombinedKinematicConstraintT.h:157
combinedConstraintHelpers::sum2
void sum2(T &x, T y)
Definition: CombinedKinematicConstraintT.h:74
combinedConstraintHelpers::PlacePosDer::operator()
void operator()(C const &cs)
Definition: CombinedKinematicConstraintT.h:113
MultiTrackKinematicConstraintT< NTRK, combinedConstraintHelpers::totDim< TupleType >::nDim >::parametersDerivativeType
ROOT::Math::SMatrix< double, DIM, 7 *NTRK > parametersDerivativeType
Definition: MultiTrackKinematicConstraintT.h:47
CombinedKinematicConstraintT::base
MultiTrackKinematicConstraintBaseT base
Definition: CombinedKinematicConstraintT.h:140
MultiTrackKinematicConstraintBaseT
Definition: MultiTrackKinematicConstraintT.h:26
CombinedKinematicConstraintT::clone
virtual CombinedKinematicConstraintT * clone() const
Definition: CombinedKinematicConstraintT.h:208
combinedConstraintHelpers::PlaceValue::operator()
void operator()(C const &cs)
Definition: CombinedKinematicConstraintT.h:91
combinedConstraintHelpers::Place::~Place
~Place()
Definition: CombinedKinematicConstraintT.h:81
combinedConstraintHelpers::PlaceValue::ret
ROOT::Math::SVector< double, DIM > & ret
Definition: CombinedKinematicConstraintT.h:89
combinedConstraintHelpers::PlaceValue::PlaceValue
PlaceValue(ROOT::Math::SVector< double, DIM > &iret)
Definition: CombinedKinematicConstraintT.h:88
combinedConstraintHelpers::totDim::nDim
Definition: CombinedKinematicConstraintT.h:65
gen::C
C
Definition: PomwigHadronizer.cc:78
CombinedKinematicConstraintT::fillPositionDerivative
void fillPositionDerivative() const
Definition: CombinedKinematicConstraintT.h:190
T
long double T
Definition: Basic3DVectorLD.h:48
do_iterate< TupleType, 0 >::call
static void call(TupleType const &, F)
Definition: CombinedKinematicConstraintT.h:42
relativeConstraints.value
value
Definition: relativeConstraints.py:53
do_iterate< TupleType, 0 >::call
static void call(TupleType &, F)
Definition: CombinedKinematicConstraintT.h:39
VertexException.h
CombinedKinematicConstraintT::Constraints
TupleType Constraints
Definition: CombinedKinematicConstraintT.h:146
do_iterate
Definition: CombinedKinematicConstraintT.h:17
combinedConstraintHelpers::PlacePosDer
Definition: CombinedKinematicConstraintT.h:109
CombinedKinematicConstraintT::constraints
Constraints constraints
Definition: CombinedKinematicConstraintT.h:214
combinedConstraintHelpers::PlaceParDer
Definition: CombinedKinematicConstraintT.h:98
point
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
CombinedKinematicConstraintT::valueType
super::valueType valueType
Definition: CombinedKinematicConstraintT.h:142
combinedConstraintHelpers::totDim::Elem
std::tuple_element< N-1, TupleType >::type Elem
Definition: CombinedKinematicConstraintT.h:64
CombinedKinematicConstraintT
Definition: CombinedKinematicConstraintT.h:136
CombinedKinematicConstraintT::super
MultiTrackKinematicConstraintT< NTRK, combinedConstraintHelpers::totDim< TupleType >::nDim > super
Definition: CombinedKinematicConstraintT.h:141