8 if(configfile!=
"") m_variables.Initialise(configfile);
15 bool use_stopwatch =
false;
16 m_variables.Get(
"use_stopwatch", use_stopwatch);
40 if(!m_variables.Get(
"time_window", time_window_s)) {
42 Log(
"WARN: No time_window parameter found. Using a value of 20 (seconds)",
WARN,
m_verbose);
45 double time_window_step_s;
46 if(!m_variables.Get(
"time_window_step", time_window_step_s)) {
47 time_window_step_s = 0.2;
48 Log(
"WARN: No time_window_step parameter found. Using a value of 0.2 (seconds)",
WARN,
m_verbose);
51 if(!m_variables.Get(
"min_events",
min_events)) {
53 Log(
"WARN: No min_events parameter found. Using a value of 3",
WARN,
m_verbose);
57 if(!m_variables.Get(
"R2MIN",
R2MIN)) {
59 Log(
"WARN: No R2MIN parameter found. Using a value of 300000",
WARN,
m_verbose);
61 if(!m_variables.Get(
"LOWDBIAS",
LOWDBIAS)) {
63 Log(
"WARN: No LOWDBIAS parameter found. Using a value of 1.15",
WARN,
m_verbose);
65 if(!m_variables.Get(
"GOODPOINT",
GOODPOINT)) {
67 Log(
"WARN: No GOODPOINT parameter found. Using a value of 40000",
WARN,
m_verbose);
69 if(!m_variables.Get(
"MAXMEANPOS",
MAXMEANPOS)) {
71 Log(
"WARN: No MAXMEANPOS parameter found. Using a value of 250000",
WARN,
m_verbose);
77 Log(
"WARN: No nclusters_silent_warning parameter found. Using a value of 200",
WARN,
m_verbose);
81 Log(
"WARN: No nclusters_normal_warning parameter found. Using a value of 435",
WARN,
m_verbose);
85 Log(
"WARN: No nclusters_golden_warning parameter found. Using a value of 630",
WARN,
m_verbose);
89 const int n_event_max = 10000;
90 fEventPos =
new std::vector<double>(n_event_max * 3);
106 ss <<
"DEBUG: dimfit looping in time from " << tstart <<
" to " << tend <<
" in steps of " <<
m_time_window_step;
112 tloopend = tloopend < tend ? tloopend : tend;
113 while(tloopend <= tend) {
116 unsigned int nclusters = 0;
117 for(
int irecon = 0; irecon < N; irecon++) {
120 if(t < tloop || t > tloopend)
132 ss <<
"DEBUG: Adding vertex " << pos.
x <<
", " << pos.
y <<
"\t" << pos.
z <<
" to run through dimfit";
138 ss <<
"DEBUG: Running " << nclusters <<
" event positions through dimfit";
143 ss <<
"INFO: Dimfit returns " << fDim <<
" Exited at " <<
fExitPoint;
158 m_data->SupernovaWarningParameters.push_back(supernova_warning_parameters);
215 int dimfit::dimfit_(
int n,
double *points,
double *centr,
double *rot,
double *rmean,
int &dim,
int &exitpoint,
bool verbose)
218 double x,y,z,root,root2,root3;
221 for(i=0; i<12; i++) centr[i]=0;
230 x=*points++; y=*points++; z=*points++;
242 for(i=0; i<9; i++) centr[i]/=n;
244 for(i=0; i<3; i++) matrix[i]-=centr[i]*centr[i];
246 matrix[3]-=*centr*centr[1];
248 matrix[4]-=centr[1]*centr[2];
250 matrix[5]-=*centr*centr[2];
253 matrix[i+6]=matrix[i];
273 printf(
"centroid: %lf %lf %lf\n",centr[0],centr[1],centr[2]);
274 printf(
"covariance: %lf %lf %lf\n",centr[3],centr[6],centr[8]);
275 printf(
"covariance: %lf %lf %lf\n",centr[6],centr[4],centr[7]);
276 printf(
"covariance: %lf %lf %lf\n",centr[8],centr[7],centr[5]);
277 printf(
"rotated: %lf %lf %lf\n",centr[9],centr[12],centr[14]);
278 printf(
"rotated: %lf %lf %lf\n",centr[12],centr[10],centr[13]);
279 printf(
"rotated: %lf %lf %lf\n",centr[14],centr[13],centr[11]);
280 printf(
"rotation: %lf %lf %lf\n",rot[0],rot[1],rot[2]);
281 printf(
"rotation: %lf %lf %lf\n",rot[3],rot[4],rot[5]);
282 printf(
"rotation: %lf %lf %lf\n",rot[6],rot[7],rot[8]);
286 root=n*(centr[9]+centr[10]+centr[11])/(3*(n-1));
288 root2=n*(centr[9]+centr[10])/(2*(n-2));
289 if (n>3) root3=n*centr[9]/(n-3);
else root3=1e10;
290 double Pos = centr[0]*centr[0]+centr[1]*centr[1]+centr[2]*centr[2];
292 std::cout <<
"dimfit av x,y,z\t" << centr[0] <<
"\t" << centr[1] <<
"\t" << centr[2] << std::endl;
298 printf(
"3 values %lf %lf %lf\n",sqrt(root),sqrt(root2),sqrt(root3));
299 printf(
"Mean position %lf\n", Pos);
322 rmean[0]=sqrt(root3);
340 rmean[0]=sqrt(root2);
348 if( (root >
R2MIN ) &&
362 double ma=fabs(a),mb=fabs(b),rat;
367 return(ma*sqrt(1+rat*rat));
369 if (mb==0)
return(0);
371 return(mb*sqrt(1+rat*rat));
377 double add=fabs(matrix[sta+1])+fabs(matrix[sta]);
378 return(add+fabs(matrix[sta+3])==add);
381 void dimfit::setvec(
double *vectors,
short int vect,
double val1,
double val2,
double val3)
384 vectors[vect+3]=val2;
385 vectors[vect+6]=val3;
393 save=vectors[vect+1];
394 vectors[vect+1]=si*vectors[vect]+co*save;
395 vectors[vect] =co*vectors[vect]-si*save;
396 save=vectors[vect+4];
397 vectors[vect+4]=si*vectors[vect+3]+co*save;
398 vectors[vect+3]=co*vectors[vect+3]-si*save;
399 save=vectors[vect+7];
400 vectors[vect+7]=si*vectors[vect+6]+co*save;
401 vectors[vect+6]=co*vectors[vect+6]-si*save;
407 double si,co,sub,siodiag,coodiag,denom,pkiip1;
413 for(ii=1; ii>=0; ii--)
415 siodiag=si*matrix[ii+3];
416 coodiag=co*matrix[ii+3];
427 shift=matrix[ii+1]-sub;
428 denom=(matrix[ii]-shift)*si+2*co*coodiag;
430 matrix[ii+1]=shift+sub;
431 shift=co*denom-coodiag;
443 double n=
d_pythag(matrix[3],matrix[5]);
444 double u1=matrix[3]-n,u2=matrix[5],u=u1*u1+u2*u2;
447 if ((n==0) || (u==0))
return;
450 p1=h*(matrix[1]*u1+matrix[4]*u2);
451 p2=h*(matrix[4]*u1+matrix[2]*u2);
454 setvec(rot,1,0,1-u1*u1*h, -u1*u2*h);
455 setvec(rot,2,0, -u1*u2*h,1-u2*u2*h);
456 h*=0.5*(u1*p1+u2*p2);
460 matrix[1]-=2*p1*u1; matrix[4]-=p1*u2+p2*u1; matrix[5]=0;
470 save=val[c1]; val[c1] =val[c2]; val[c2]= save;
471 save=rot[c1]; rot[c1] =rot[c2]; rot[c2]= save;
472 save=rot[c1+3]; rot[c1+3]=rot[c2+3]; rot[c2+3]=save;
473 save=rot[c1+6]; rot[c1+6]=rot[c2+6]; rot[c2+6]=save;
478 double rat,root,shift,add,add2,si,co,u2i;
482 for(sta=0; sta<2; sta++)
483 for(iter=0; iter<20; iter++)
486 rat=(matrix[sta+1]-matrix[sta])/(2*matrix[sta+3]);
488 if (rat*root<0) root=-root;
490 add=matrix[sta+3]/root;
492 if ((sta==1) ||
d_iszero(matrix,sta+1))
500 if (matrix[2]<matrix[1])
502 if (matrix[1]<matrix[0])
504 if (matrix[2]<matrix[1])
511 if (matrix[2]<matrix[1])
d_swap(matrix,rot,2,1);
512 if (matrix[1]<matrix[0])
d_swap(matrix,rot,0,1);
513 if (matrix[2]<matrix[1])
d_swap(matrix,rot,2,1);
std::string Result(std::string method_name, std::string output_file="")
Pos3D GetVertex(int irecon)
TimeDelta GetTime(int irecon)
int dimfit_(int n, double *points, double *centr, double *rot, double *rmean, int &dim, int &exitpoint, bool verbose)
void Start()
Start the stopwatch.
std::string m_stopwatch_file
Image filename to save the histogram to, if required.
enum NClustersWarnings NClustersWarning_t
StopwatchTimes Stop()
Stop the stopwatch, returning the CPU time.
void d_swap(double *val, double *rot, int c1, int c2)
void tridiag(double *matrix, double *rot)
void StreamToLog(int level)
bool Initialise(std::string configfile, DataModel &data)
void setvec(double *vectors, short int vect, double val1, double val2, double val3)
std::string fInputFilterName
util::Stopwatch * m_stopwatch
The stopwatch, if we're using one.
TimeDelta m_time_window_step
int nclusters_silent_warning
void rotate(double *vectors, short int vect, double si, double co)
int nclusters_normal_warning
int nclusters_golden_warning
std::vector< double > * fEventPos
int planegivens(double *matrix, double *rot, double shift)
void Log(const std::string &message, const int message_level)
Format messages in the same way as for tools.
static std::string EnumAsString(Reconstructer_t r)
int d_iszero(double *matrix, int sta)
static const TimeDelta s
TimeDelta of 1 s.
double d_pythag(double a, double b)
void eigen(double *matrix, double *rot)