11 #include <JANA/JObject.h>
102 void toStrings(vector<pair<string,string> > &items)
const{
103 AddString(items,
"u",
"%3.2f",
u);
104 AddString(items,
"v",
"%3.2f",v);
105 AddString(items,
"t_u",
"%3.2f",t_u);
106 AddString(items,
"t_v",
"%3.2f",t_v);
107 AddString(items,
"phi_u",
"%3.2f",phi_u);
108 AddString(items,
"phi_v",
"%3.2f",phi_v);
109 AddString(items,
"w",
"%3.4f", w);
110 AddString(items,
"w_c",
"%3.4f", w_c);
111 AddString(items,
"s",
"%3.4f", s);
112 AddString(items,
"layer",
"%d", wire->layer);
113 AddString(items,
"wire",
"%d", wire->wire);
114 AddString(items,
"time",
"%3.1f", time);
115 AddString(items,
"status",
"%d", status);
116 AddString(items,
"x",
"%.4f", xy.X());
117 AddString(items,
"y",
"%.4f", xy.Y());
118 AddString(items,
"dE",
"%3.1f", dE);
127 size_t nDerivatives = 12;
128 vector<double> derivatives(nDerivatives);
131 double sinPhiU =
sin(phi_u);
132 double cosPhiU = cos(phi_u);
133 double sinPhiV =
sin(phi_v);
134 double cosPhiV = cos(phi_v);
135 double sinPhiUmPhiV =
sin(phi_u-phi_v);
136 double sinPhiUmPhiV2 = sinPhiUmPhiV*sinPhiUmPhiV;
137 double cosPhiUmPhiV = cos(phi_u-phi_v);
140 derivatives[
dWcddeltaU] = sinPhiV/sinPhiUmPhiV;
141 derivatives[
dWcddeltaV] = -sinPhiU/sinPhiUmPhiV;
142 derivatives[
dWcddeltaPhiU] = (v-
u*cosPhiUmPhiV)*sinPhiV/sinPhiUmPhiV2;
143 derivatives[
dWcddeltaPhiV] = (
u-v*cosPhiUmPhiV)*sinPhiU/sinPhiUmPhiV2;
145 derivatives[
dSddeltaU] = -cosPhiV/sinPhiUmPhiV;
146 derivatives[
dSddeltaV] = cosPhiU/sinPhiUmPhiV;
147 derivatives[
dSddeltaPhiU] = -(v-
u*cosPhiUmPhiV)*cosPhiV/sinPhiUmPhiV2;
148 derivatives[
dSddeltaPhiV] = -(
u-v*cosPhiUmPhiV)*cosPhiU/sinPhiUmPhiV2;
150 derivatives[
dWdX]=1.0;
151 derivatives[
dSdX]=1.0;
163 vector<double> derivatives;
166 double positionNominal, positionShifted;
167 FindCentroid(cluster_u.N, cluster_u.X, positionNominal);
171 DMatrix3x1 deltaVectU0(delta*cluster_u.NRaw(0), 0.0, 0.0);
172 DMatrix3x1 deltaVectU1(0.0,delta*cluster_u.NRaw(1), 0.0);
173 DMatrix3x1 deltaVectU2(0.0,0.0,delta*cluster_u.NRaw(2));
175 DMatrix3x1 deltaVectV0(delta*cluster_v.NRaw(0), 0.0, 0.0);
176 DMatrix3x1 deltaVectV1(0.0,delta*cluster_v.NRaw(1), 0.0);
177 DMatrix3x1 deltaVectV2(0.0,0.0,delta*cluster_v.NRaw(2));
179 FindCentroid(cluster_u.N+deltaVectU0, cluster_u.X, positionShifted);
180 derivatives.push_back((positionShifted-positionNominal)/delta);
182 FindCentroid(cluster_u.N+deltaVectU1, cluster_u.X, positionShifted);
183 derivatives.push_back((positionShifted-positionNominal)/delta);
185 FindCentroid(cluster_u.N+deltaVectU2, cluster_u.X, positionShifted);
186 derivatives.push_back((positionShifted-positionNominal)/delta);
188 FindCentroid(cluster_v.N, cluster_v.X, positionNominal);
190 FindCentroid(cluster_v.N+deltaVectV0, cluster_v.X, positionShifted);
191 derivatives.push_back((positionShifted-positionNominal)/delta);
193 FindCentroid(cluster_v.N+deltaVectV1, cluster_v.X, positionShifted);
194 derivatives.push_back((positionShifted-positionNominal)/delta);
196 FindCentroid(cluster_v.N+deltaVectV2, cluster_v.X, positionShifted);
197 derivatives.push_back((positionShifted-positionNominal)/delta);
210 vector<double> derivatives;
212 double positionNominal, positionShifted;
213 FindCentroid(cluster_u.N, cluster_u.X, positionNominal);
215 double delta = 0.005;
218 for (
int i=0 ; i < 3; i++){
219 if(cluster_u.index(i) < 48) deltaVect(i) = (cluster_u.index(i)-47.)*delta;
220 else deltaVect(i) = 0.0;
223 FindCentroid(cluster_u.N, cluster_u.X + deltaVect, positionShifted);
224 derivatives.push_back((positionShifted-positionNominal)/delta);
227 for (
int i=0 ; i < 3; i++){
228 if(cluster_u.index(i) < 48) deltaVect(i) = -delta;
229 else deltaVect(i) = 0.0;
232 FindCentroid(cluster_u.N, cluster_u.X + deltaVect, positionShifted);
233 derivatives.push_back((positionShifted-positionNominal)/delta);
236 for (
int i=0 ; i < 3; i++){
237 if(cluster_u.index(i) < 48) deltaVect(i) = -47.5*delta;
238 else if (cluster_u.index(i) < 144) deltaVect(i) = (cluster_u.index(i)-95.5)*delta;
239 else deltaVect(i) = 47.5*delta;
242 FindCentroid(cluster_u.N, cluster_u.X + deltaVect, positionShifted);
243 derivatives.push_back((positionShifted-positionNominal)/delta);
246 for (
int i=0 ; i < 3; i++){
247 if(cluster_u.index(i) >= 144) deltaVect(i) = delta;
248 else deltaVect(i) = 0.0;
251 FindCentroid(cluster_u.N, cluster_u.X + deltaVect, positionShifted);
252 derivatives.push_back((positionShifted-positionNominal)/delta);
255 for (
int i=0 ; i < 3; i++){
256 if(cluster_u.index(i) >= 144) deltaVect(i) = (cluster_u.index(i)-144.)*delta;
257 else deltaVect(i) = 0.0;
260 FindCentroid(cluster_u.N, cluster_u.X + deltaVect, positionShifted);
261 derivatives.push_back((positionShifted-positionNominal)/delta);
265 FindCentroid(cluster_v.N, cluster_v.X, positionNominal);
268 for (
int i=0 ; i < 3; i++){
269 if(cluster_v.index(i) < 48) deltaVect(i) = (cluster_v.index(i)-47.)*delta;
270 else deltaVect(i) = 0.0;
273 FindCentroid(cluster_v.N, cluster_v.X + deltaVect, positionShifted);
274 derivatives.push_back((positionShifted-positionNominal)/delta);
277 for (
int i=0 ; i < 3; i++){
278 if(cluster_v.index(i) < 48) deltaVect(i) = -delta;
279 else deltaVect(i) = 0.0;
282 FindCentroid(cluster_v.N, cluster_v.X + deltaVect, positionShifted);
283 derivatives.push_back((positionShifted-positionNominal)/delta);
286 for (
int i=0 ; i < 3; i++){
287 if(cluster_v.index(i) < 48) deltaVect(i) = -47.5*delta;
288 else if (cluster_v.index(i) < 144) deltaVect(i) = (cluster_v.index(i)-95.5)*delta;
289 else deltaVect(i) = 47.5*delta;
292 FindCentroid(cluster_v.N, cluster_v.X + deltaVect, positionShifted);
293 derivatives.push_back((positionShifted-positionNominal)/delta);
296 for (
int i=0 ; i < 3; i++){
297 if(cluster_v.index(i) >= 144) deltaVect(i) = delta;
298 else deltaVect(i) = 0.0;
301 FindCentroid(cluster_v.N, cluster_v.X + deltaVect, positionShifted);
302 derivatives.push_back((positionShifted-positionNominal)/delta);
305 for (
int i=0 ; i < 3; i++){
306 if(cluster_v.index(i) >= 144) deltaVect(i) = (cluster_v.index(i)-144.)*delta;
307 else deltaVect(i) = 0.0;
310 FindCentroid(cluster_v.N, cluster_v.X + deltaVect, positionShifted);
311 derivatives.push_back((positionShifted-positionNominal)/delta);
334 for (
int j=0; j<3; j++){
345 double errf=0.,errx=0;
346 for (
int iter=1;iter<=
ITER_MAX;iter++){
351 for (
int i=0;i<3;i++){
352 double dx=(par(X0)-
X(i))*ONE_OVER_H;
355 double tanh_p=tanh(argp);
356 double tanh_m=tanh(argm);
357 double tanh2_p=tanh_p*tanh_p;
358 double tanh2_m=tanh_m*tanh_m;
359 double q_over_4=0.25*par(QA);
363 J(i,K2)=-q_over_4*(argp/par(K2)*(1.-tanh2_p)
364 -argm/par(K2)*(1.-tanh2_m));
365 J(i,X0)=-q_over_4*par(K2)*(tanh2_m-tanh2_p);
366 F(i)=N(i)-q_over_4*
f(i);
367 double new_errf=fabs(
F(i));
368 if (new_errf>errf) errf=new_errf;
377 FindNewParmVec(N,X,F,J,par,newpar);
380 for (
int i=0;i<3;i++){
381 double new_err=fabs(par(i)-newpar(i));
382 if (new_err>errx) errx=new_err;
391 return INFINITE_RECURSION;
415 double slope=(-1.0)*F.
Mag2();
419 return VALUE_OUT_OF_RANGE;
423 double lambda_temp,lambda2=lambda;
431 newpar=par+lambda*fullstep;
434 for (
int i=0;i<3;i++){
435 double dx=(newpar(X0)-
X(i))*ONE_OVER_H;
436 double argp=newpar(K2)*(dx+
A_OVER_H);
437 double argm=newpar(K2)*(dx-
A_OVER_H);
438 newF(i)=N(i)-0.25*newpar(QA)*(tanh(argp)-tanh(argm));
440 newf=0.5*newF.
Mag2();
446 else if (newf<=f+ALPHA*lambda*slope){
452 lambda_temp=-0.5*slope/(newf-f-slope);
455 double temp1=newf-f-lambda*slope;
456 double temp2=f2-f-lambda2*slope;
457 double one_over_lambda2_sq=1./(lambda2*lambda2);
458 double one_over_lambda_sq=1./(lambda*lambda);
459 double one_over_lambda_diff=1./(lambda-lambda2);
460 double a=(temp1*one_over_lambda_sq-temp2*one_over_lambda2_sq)*one_over_lambda_diff;
461 double b=(-lambda2*temp1*one_over_lambda_sq+lambda*temp2*one_over_lambda2_sq)
462 *one_over_lambda_diff;
463 if (a==0.0) lambda_temp=-0.5*slope/b;
465 double disc=b*b-3.0*a*slope;
466 if (disc<0.0) lambda_temp=0.5*lambda;
467 else if (b<=0.0) lambda_temp=(-b+
sqrt(disc))/(3.*a);
468 else lambda_temp=-slope/(b+
sqrt(disc));
471 if (lambda_temp>0.5*lambda) lambda_temp=0.5*lambda;
477 lambda=(lambda_temp>0.1*lambda ? lambda_temp : 0.1*lambda);
483 #endif //DFDCPSEUDO_H
DVector2 xy
rough x,y coordinates in lab coordinate system
DMatrix3x3 Invert() const
double q
< energy deposition, from pulse height
int status
status word for pseudopoint
double t_v
time of the two cathode clusters
const DFDCWire * wire
DFDCWire for this wire.
double q_from_pulse_height
class DFDCPseudo: definition for a reconstructed point in the FDC
vector< double > GetFDCPseudoAlignmentDerivatives()
static char index(char c)
double phi_v
rotation angles for cathode planes
DFDCPseudo()
DANA identifier.
centroid_t cluster_v
Cathode cluster centroids, Useful for gain/strip pitch calibration.
vector< double > GetFDCStripGainDerivatives()
double dE
energy deposition, from integral
double s
< wire position computed from cathode data, assuming the avalanche occurs at the wire ...
jerror_t FindNewParmVec(const DMatrix3x1 &N, const DMatrix3x1 &X, const DMatrix3x1 &F, const DMatrix3x3 &J, const DMatrix3x1 &par, DMatrix3x1 &newpar)
double covyy
Covariance terms for (x,y)
double time
time corresponding to this pseudopoint.
void toStrings(vector< pair< string, string > > &items) const
const vector< double > GetFDCStripPitchDerivatives()
jerror_t FindCentroid(DMatrix3x1 N, DMatrix3x1 X, double &pos)
double v
centroid positions in the two cathode views