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:
153  CombinedKinematicConstraintT(Constraints const & iconstraints): constraints(constraints){
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:
214  Constraints constraints;
215 
216 };
217 
218 #endif
type
Definition: HCALResponse.h:21
super::positionDerivativeType positionDerivativeType
auto_ptr< ClusterSequence > cs
ROOT::Math::SMatrix< double, DIM, 7 *NTRK > & ret
Definition: helper.py:1
std::tuple_element< N-1, TupleType >::type Elem
static void call(TupleType &, F)
virtual void init(const std::vector< KinematicState > &states, const GlobalPoint &point, const GlobalVector &mf)
MultiTrackKinematicConstraintBaseT base
virtual CombinedKinematicConstraintT * clone() const
PlaceValue(ROOT::Math::SVector< double, DIM > &iret)
void iterate_tuple(TupleType &t, F f)
double f[11][100]
CombinedKinematicConstraintT(Constraints const &iconstraints)
ROOT::Math::SMatrix< double, DIM, 3 > & ret
static void call(TupleType &t, F f)
PlaceParDer(ROOT::Math::SMatrix< double, DIM, 7 *NTRK > &iret)
static void call(TupleType const &t, F f)
MultiTrackKinematicConstraintT< NTRK, combinedConstraintHelpers::totDim< TupleType >::nDim > super
#define N
Definition: blowfish.cc:9
#define DIM
PlacePosDer(ROOT::Math::SMatrix< double, DIM, 3 > &iret)
ROOT::Math::SVector< double, DIM > & ret
super::parametersDerivativeType parametersDerivativeType
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
long double T
*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
static void call(TupleType const &, F)