ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitCommon/VertexFit/interface/MultiVertexFitterC.h
Revision: 1.2
Committed: Fri Mar 20 13:33:03 2009 UTC (16 years, 1 month ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_011, Mit_010a, Mit_010, Mit_009c, Mit_009b, Mit_009a, Mit_009, Mit_008
Changes since 1.1: +15 -8 lines
Log Message:
Cleanup

File Contents

# Content
1 //--------------------------------------------------------------------------------------------------
2 // $Id: MultiVertexFitterC.h,v 1.1 2008/11/13 16:34:28 paus Exp $
3 //
4 // MultiVertexFitterC class header file
5 //
6 // Compact version of MultiVertexFitter
7 //
8 //--------------------------------------------------------------------------------------------------
9
10 #ifndef MITCOMMON_VERTEXFIT_MULTIVERTEXFITTERC_H
11 #define MITCOMMON_VERTEXFIT_MULTIVERTEXFITTERC_H
12
13 #include <string>
14 #include <iostream>
15
16 #include <Rtypes.h>
17 #include <TVectorD.h>
18 #include <TMatrixDSym.h>
19 #include <CLHEP/Vector/LorentzVector.h>
20 #include <CLHEP/Vector/ThreeVector.h>
21 #include <CLHEP/Matrix/SymMatrix.h>
22 #include <CLHEP/Matrix/Vector.h>
23
24 #include "MitCommon/DataFormats/interface/Types.h"
25 #include "MitCommon/Ctvmft/interface/cdimensions.hh"
26
27 //-------------------------------------------------------------------------------------------------
28 // Fortran routines to get address of the start of the ctvmq and ctvmfr common blocks
29 //-------------------------------------------------------------------------------------------------
30 extern "C" {
31 int cctvmq_address_ (void);
32 int cctvmfr_address_(void);
33 int cfiddle_address_(void);
34 int ctrkprm_address_(void);
35 }
36
37 namespace mithep {
38 class MultiVertexFitterC {
39
40 public:
41 //--------------------------------------------------------------------------------------------
42 // Enumerations
43 //--------------------------------------------------------------------------------------------
44 enum vertexNumber { PRIMARY_VERTEX,VERTEX_1,VERTEX_2,VERTEX_3,VERTEX_4,VERTEX_5,VERTEX_6 };
45 enum vertexIndex { X_INDEX=0, Y_INDEX, Z_INDEX, P1_INDEX, P2_INDEX };
46 enum trackIndex { CURVATURE_INDEX=0, PHI_INDEX, COTTH_INDEX };
47
48 //--------------------------------------------------------------------------------------------
49 // *structors
50 //--------------------------------------------------------------------------------------------
51 MultiVertexFitterC();
52 ~MultiVertexFitterC() {}
53
54 //--------------------------------------------------------------------------------------------
55 // Fundamental funtions
56 //--------------------------------------------------------------------------------------------
57 void init (double bfield = 3.8);
58 void setChisqMax (const float chisqmx);
59
60 //--------------------------------------------------------------------------------------------
61 // CMS parameter ordering for the vector/matrix, which is assumed here:
62 //
63 // qoverp, cotTheta, phi0, d0, z0;
64 // mapping to CDF is therefore { 1, 0*, 4, 3, 2 }
65 //
66 // Note that the radius of curvature (in cm) is then:
67 //
68 // Rc = cos(theta) / [ 0.0029979.... * (q/p) * B ],
69 //
70 // where B is the magnetic field in Tesla and tht is the angle between the field and the
71 // direction. With p * cos(theta) = pT it follows:
72 //
73 // Rc = pT / [ 0.0029979.... * q * B ],
74 // fullCurvature = 1 / Rc = 0.0029979 * q * B / pT = - 0.0029979 * B / pT.
75 //
76 //--------------------------------------------------------------------------------------------
77
78 //--------------------------------------------------------------------------------------------
79 // Parameter ordering for the vector/matrix, assumed here:
80 //
81 // cotTheta, curvature, z0, d0, phi0;
82 //
83 // And also: curvature = -0.5 * CurvConst * BFieldT / pT (strictly speaking: half curvature)
84 // CurvConst = 0.0029979, BField in Tesla
85 //
86 // Incidentally this is the ordering used in the CDF experiment.
87 //--------------------------------------------------------------------------------------------
88 bool addTrack (const HepVector &pars, const HepSymMatrix &cov, int trackid,
89 float mass, vertexNumber jv);
90
91 bool addTrack (const TVectorD &pars, const TMatrixDSym &cov, int trackid,
92 double mass, vertexNumber jv);
93
94
95 bool vertexPoint_2d (vertexNumber jv1, vertexNumber jv2);
96 bool vertexPoint_3d (vertexNumber jv1, vertexNumber jv2);
97 bool vertexPoint_1track (vertexNumber jv1, vertexNumber jv2);
98 bool vertexPoint_0track (vertexNumber jv1, vertexNumber jv2);
99 bool conversion_2d (vertexNumber jv);
100 bool conversion_3d (vertexNumber jv);
101 bool massConstrain (int ntrk, const int trkIds[], float mass);
102
103 void setPrimaryVertex (float xv, float yv, float zv);
104 void setPrimaryVertex (Hep3Vector pv);
105 bool setPrimaryVertexError(const HepSymMatrix &xverr);
106 void setPrimaryVertexError(const float xverr[3][3]);
107
108 bool fit ();
109
110 void print (std::ostream& os) const;
111 void print () const;
112 void printErr (std::ostream& os) const;
113 void printErr () const;
114
115 void restoreFromCommons ();
116
117 // -------------------------------------------------------------------------------------------
118 // Turn ON this option only when fitting the primary with no additional constraints.
119 // The routineis protected and will not function if those options are selected as well as the
120 // beamline constraint. In case this option is chosen the fit will calculate a result also
121 // with just one track in input.
122 //
123 // In order to enable this option the user must do the following: Fit the primary vertex as
124 // VERTEX_1 (without any other vertices). Enable beamlineConstraint by setting the pointing
125 // constraint variable vtxpnt[0][0] to -100 (no pointing constraints when <0) Note that index
126 // 0,0 corresponds to index 1,1 in fortran Provide the beamline parameters:
127 //
128 // --> assume xv = xb + xzbslope*z,
129 // yv = yb + yzbslope*z, where (xv, yv) is the transverse
130 // beam position at z, (xb, yb) is the transverse beam position at z = 0
131 // and (xzbslope, yzbslope) are the slopes of the beamline
132 // --> set primary vertex at z=0 (xb, yb, 0)
133 // --> set the diagonal elements of the primary vertex error matrix to the
134 // sigma**2 of beam spread in x, y and z:
135 // xverr[1][1] = (~30 - 50 um)**2
136 // xverr[2][2] = (~30 - 50 um)**2
137 // xverr[3][3] = (~30 cm) **2
138 // All other elements should be 0
139 // For help email: Joao Guimaraes guima@huhepl.harvard.edu, Franco Bedeschi bed@fnal.gov
140 // See more information in the ctvmft.f
141 // -------------------------------------------------------------------------------------------
142 bool beamlineConstraint(float xb, float yb, HepSymMatrix berr,float xzbslope,float yzbslope);
143 bool beamlineConstraint(Hep3Vector pv, HepSymMatrix berr, float xzbslope, float yzbslope);
144
145 //--------------------------------------------------------------------------------------------
146 // Accessors
147 //--------------------------------------------------------------------------------------------
148
149 void setBField (double bField) { _bField = bField; }
150 double bField () const { return _bField; }
151 void setExcuse ();
152 void setNoExcuse();
153
154 std::string expert () const; // name/email of MultiVertexFitter expert
155 int status () const; // return status of fit
156 // overall fit quality paramters
157 int ndof () const; // number of degrees of freedom
158 float prob () const; // return probability of chi-square
159 float chisq () const; // return chi-square of fit
160 float chisq (const int trkId) const;
161 float chisq_rphi () const;
162 float chisq_rphi (const int trkId) const;
163 float chisq_z () const;
164 float chisq_z (const int trkId) const;
165 float chisq_rphiz() const;
166 float chisq_rphiz(const int trkId) const;
167
168 // return fit track four momentum
169 //HepLorentzVector getTrackP4 (const int trkId) const;
170 FourVector getTrackP4 (const int trkId) const;
171
172 //// return fit track parameters
173 //Helix getHelix (const int trkId) const;
174
175 // return fit mass and get error
176 float getMass (int ntrk, const int trkIds[], float& dmass) const;
177
178 // return decay length
179 float getDecayLength (vertexNumber nv, vertexNumber mv, const Hep3Vector& dir,
180 float& dlerr) const;
181 float getDecayLength (vertexNumber nv, vertexNumber mv, const ThreeVector& dir,
182 float& dlerr) const;
183 float getZDecayLength (vertexNumber nv, vertexNumber mv,
184 const Hep3Vector& dir, float& dlerr) const;
185 float getZDecayLength (vertexNumber nv, vertexNumber mv,
186 const ThreeVector& dir, float& dlerr) const;
187 float getImpactPar (vertexNumber prdV, vertexNumber dcyV,
188 const Hep3Vector &v, float &dxyerr) const;
189 float getImpactPar (vertexNumber prdV, vertexNumber dcyV,
190 const ThreeVector &v, float &dxyerr) const;
191 float get_dr (vertexNumber nv, vertexNumber mv, float& drerr) const;
192 float get_dz (vertexNumber nv, vertexNumber mv, float& dzerr) const;
193
194 // return location of vertex
195 Hep3Vector getVertexHep (vertexNumber nv) const;
196 ThreeVector getVertex (vertexNumber nv) const;
197
198 // return error matrix element.
199 ThreeSymMatrix getErrorMatrix (vertexNumber nv) const;
200 double getErrorMatrixHep(int j, int k) const;
201 HepSymMatrix getErrorMatrixHep(vertexNumber nv) const;
202 HepSymMatrix getErrorMatrixHep(const int trkId) const;
203 void getPosMomErr (HepMatrix& errors) const;
204 int vOff (vertexNumber jv) const;
205 int tOff (const int trkId) const;
206 int pOff (int lp) const;
207 int cOff (int lc) const;
208 int mOff () const;
209 double VMat (int i, int j) const;
210 float getPtError (const int trkId) const;
211 MultiVertexFitterC::vertexNumber
212 allocateVertexNumber();
213 void resetAllocatedVertexNumber();
214
215 // Accessors for getting information relative to ijk errors.
216 // Get the error code from the three ijk indexes into the argument variables
217 void getIJKErr(int& err0, int& err1, int& err2) const;
218 // Return each error code from the three ijk indexes
219 int getIJKErr0() const;
220 int getIJKErr1() const;
221 int getIJKErr2() const;
222
223 // Get the track-id of the track causing a fatal error as indicated
224 // by the corresponding ijk error
225 int getErrTrackId() const;
226
227 // Set new track reference point
228 void setTrackReferencePoint(const ThreeVector &ref);
229
230 //--------------------------------------------------------------------------------------------
231 // Overload operators
232 //--------------------------------------------------------------------------------------------
233 friend std::ostream& operator << (std::ostream& os, const MultiVertexFitterC& vfit);
234
235 protected:
236 std::string _expert; // string: name and email of expert
237 int _stat; // status returned from fit
238
239 static const int _maxvtx = CCTVMFT_MAXVTX; // Maximum number of vertices
240 static const int _maxmcn = CCTVMFT_MAXMCN; // Maximum number of mass constraints
241 static const int _maxtrk = CCTVMFT_MAXTRK; // Maximum number of tracks
242 static const int _maxitr = CCTVMFT_MAXITR; // Maximum number of iteration steps
243 static const int _maxdim = 5*(CCTVMFT_MAXVTX+1)+3*CCTVMFT_MAXTRK+CCTVMFT_MAXMCN;
244
245 // FIDDLE must have access to protected data like _maxvtx, etc. It must therefore be a
246 // friend
247 struct FIDDLE;
248 friend struct FIDDLE;
249 struct FIDDLE {
250 int excuse;
251 float chisqmax;
252 };
253
254 // CTVMQ must have access to MultiVertexFitterC's (other) protected data like _maxvtx, etc.
255 // It must therefore be a friend.
256 struct CTVMQ;
257 friend struct CTVMQ;
258 struct CTVMQ {
259 int runnum;
260 int trgnum;
261 int iter;
262 int ntscut;
263 int nvertx;
264 int nmassc;
265 int ntrack;
266 int trkvtx[_maxvtx][_maxtrk]; // Logical in FORTRAN, but integer here to get the size
267 int trkmcn[_maxmcn][_maxtrk]; // Logical in FORTRAN, but integer here to get the size
268 int vtxpnt[2][_maxvtx];
269 float cmass [_maxmcn];
270 int cvtx [_maxvtx];
271 int vtxvtx[_maxvtx][_maxvtx]; // Logical in FORTRAN, but integer here to get the size
272 char tkbank[_maxtrk][4];
273 int list [_maxtrk];
274 float tmass [_maxtrk];
275 int matdim;
276 int tkerr [_maxtrk];
277 int ndof;
278 float chisqr[_maxitr+1];
279 float chit [_maxtrk];
280 float chiv [_maxvtx+1];
281 float chim [_maxmcn];
282 float xyzpv0[3];
283 float exyzpv[3][3];
284 float xzslope;
285 float yzslope;
286 float xyzvrt[_maxvtx+1][3];
287 float dxyzpv[3];
288 float par [_maxtrk][5];
289 float g [_maxtrk][5][5];
290 float trkp4 [6][_maxtrk];
291 float vtxp4 [_maxvtx][4];
292 float mcnp4 [_maxmcn][4];
293 float dda [8][_maxtrk];
294 int voff [_maxvtx];
295 int toff [_maxtrk];
296 int poff [_maxvtx];
297 int coff [_maxvtx];
298 int moff;
299 float par0 [_maxtrk][5];
300 float pardif[_maxtrk][5];
301 float fmcdif[_maxmcn];
302 float pcon [2][_maxvtx];
303 float sang [2][_maxvtx];
304 float drmax;
305 float rvmax;
306 float dzmax;
307 float trnmax;
308 float dsmin;
309 int ijkerr[3];
310 float pscale;
311 };
312
313 // CTVMFR must have access to MultiVertexFitterC's (other) protected data like _maxdim, etc.
314 // It must therefore be a friend.
315 struct CTVMFR;
316 friend struct CTVMFR;
317 struct CTVMFR {
318 double vmat[_maxdim+1][_maxdim];
319 };
320
321 // TRKPRM must have access to MultiVertexFitterC's (other) protected data like _maxtrk, etc.
322 // It must therefore be a friend.
323 struct TRKPRM;
324 friend struct TRKPRM;
325 struct TRKPRM {
326 float trhelix[_maxtrk][5];
327 float trem [_maxtrk][5][5];
328 };
329
330 CTVMQ _ctvmq;
331 CTVMQ* _ctvmq_com;
332 CTVMFR _ctvmfr;
333 CTVMFR* _ctvmfr_com;
334 FIDDLE _fiddle;
335 FIDDLE* _fiddle_com;
336 TRKPRM _trkprm;
337 TRKPRM* _trkprm_com;
338
339 //--------------------------------------------------------------------------------------------
340 // Private functions used by class
341 //--------------------------------------------------------------------------------------------
342
343 private:
344
345 // Moves reference point of track parameters and errors to _referencePoint
346 //void moveReferencePoint(HepVector &v, HepSymMatrix &m);
347 // Moves reference point of track parameters and errors to _referencePoint. Additionally
348 //checks if track has already been moved by examining it's "derived" link
349 //void moveReferencePoint(const CdfTrack *trk, HepVector &v, HepSymMatrix &m);
350
351 //--------------------------------------------------------------------------------------------
352 // Data members of class
353 //--------------------------------------------------------------------------------------------
354 double _bField; // B field in Tesla
355
356 int _currentAllocatedVertexNumber; // index to enum vertexNumber
357 ThreeVector _referencePoint; // reference point of track
358 Hep3Vector _primaryVertex; // primary vertex relative to _referencePoint
359 Hep3Vector _cdfPrimaryVertex; // primary vertex in CDF coordinate system
360 bool _extrapolateTrackErrors; // extrapolate track errors to _referencePoint
361 };
362 }
363
364 //--------------------------------------------------------------------------------------------------
365 // Inline functions
366 //--------------------------------------------------------------------------------------------------
367 inline
368 std::ostream& operator << (std::ostream& os, const mithep::MultiVertexFitterC& vfit)
369 {
370 vfit.print(os);
371 return (os);
372 }
373
374 //--------------------------------------------------------------------------------------------------
375 inline
376 void mithep::MultiVertexFitterC::setExcuse()
377 {
378 _fiddle.excuse = 1; // the default
379 }
380
381 //--------------------------------------------------------------------------------------------------
382 inline
383 void mithep::MultiVertexFitterC::setNoExcuse()
384 {
385 _fiddle.excuse = 0; // crash on input error
386 }
387
388 //--------------------------------------------------------------------------------------------------
389 inline
390 void mithep::MultiVertexFitterC::setChisqMax(const float chisqmx)
391 {
392 _fiddle.chisqmax = chisqmx;
393 }
394 #endif