#include "Solver.h"
#include <algorithm>
#include <cstdlib>
#include <set>
#include <string>
#include <iostream>
Go to the source code of this file.
|
template<class T > |
T | sqr (T x) |
|
double | Metric (double q, double p) |
|
QuadExpr | Metric (double q, QuadExpr p) |
|
double | Metric (const std::vector< SpaceCharge * > &scs, double alpha) |
|
double | Metric (const std::vector< CollectionWireHit * > &cwires, double alpha) |
|
QuadExpr | Metric (const SpaceCharge *sci, const SpaceCharge *scj, double alpha) |
|
QuadExpr | Metric (const SpaceCharge *sc, double alpha) |
|
double | SolvePair (CollectionWireHit *cwire, SpaceCharge *sci, SpaceCharge *scj, double alpha) |
|
void | Iterate (CollectionWireHit *cwire, double alpha) |
|
void | Iterate (SpaceCharge *sc, double alpha) |
|
void | Iterate (const std::vector< CollectionWireHit * > &cwires, const std::vector< SpaceCharge * > &orphanSCs, double alpha) |
|
Definition at line 263 of file Solver.cxx.
268 for(
unsigned int i = 0; i+1 <
N; ++i){
271 for(
unsigned int j = i+1; j <
N; ++j){
void AddCharge(double dq)
std::vector< SpaceCharge * > fCrossings
double SolvePair(CollectionWireHit *cwire, SpaceCharge *sci, SpaceCharge *scj, double alpha)
Definition at line 286 of file Solver.cxx.
294 const double xmin = -sc->
fPred;
299 const double chisq_new = chisq.
Eval(x);
304 const double chisq_n = chisq.
Eval(xmin);
306 if(chisq_n < chisq_new)
void AddCharge(double dq)
double Metric(double q, double p)
static int max(int a, int b)
double Eval(double x) const
Definition at line 313 of file Solver.cxx.
319 unsigned int cwireIdx = 0;
320 if (!cwires.empty()){
324 const unsigned int prime = 1299827;
325 cwireIdx = (cwireIdx+prime)%cwires.size();
326 }
while(cwireIdx != 0);
void Iterate(CollectionWireHit *cwire, double alpha)
double Metric |
( |
double |
q, |
|
|
double |
p |
|
) |
| |
Definition at line 83 of file Solver.cxx.
87 std::set<InductionWireHit*> iwires;
89 if(sc->fWire1) iwires.insert(sc->fWire1);
90 if(sc->fWire2) iwires.insert(sc->fWire2);
96 ret -=
alpha * sc->fPred * sc->fNeiPotential;
101 ret +=
Metric(iwire->fCharge, iwire->fPred);
double Metric(double q, double p)
Definition at line 108 of file Solver.cxx.
110 std::vector<SpaceCharge*> scs;
112 scs.insert(scs.end(), cwire->fCrossings.begin(), cwire->fCrossings.end());
double Metric(double q, double p)
Definition at line 117 of file Solver.cxx.
125 const double scip = sci->
fPred;
126 const double scjp = scj->
fPred;
155 const double qi1 = iwire1 ? iwire1->
fCharge : 0;
156 const double pi1 = iwire1 ? iwire1->
fPred : 0;
158 const double qj1 = jwire1 ? jwire1->
fCharge : 0;
159 const double pj1 = jwire1 ? jwire1->
fPred : 0;
161 if(iwire1 == jwire1){
163 if(iwire1) ret +=
Metric(qi1, pi1);
166 if(iwire1) ret +=
Metric(qi1, pi1 + x);
167 if(jwire1) ret +=
Metric(qj1, pj1 - x);
173 const double qi2 = iwire2 ? iwire2->
fCharge : 0;
174 const double pi2 = iwire2 ? iwire2->
fPred : 0;
176 const double qj2 = jwire2 ? jwire2->
fCharge : 0;
177 const double pj2 = jwire2 ? jwire2->
fPred : 0;
179 if(iwire2 == jwire2){
180 if(iwire2) ret +=
Metric(qi2, pi2);
183 if(iwire2) ret +=
Metric(qi2, pi2 + x);
184 if(jwire2) ret +=
Metric(qj2, pj2 - x);
std::vector< Neighbour > fNeighbours
double fNeiPotential
Neighbour-induced potential.
InductionWireHit * fWire2
InductionWireHit * fWire1
double Metric(double q, double p)
Definition at line 191 of file Solver.cxx.
199 const double scp = sc->
fPred;
double fNeiPotential
Neighbour-induced potential.
InductionWireHit * fWire2
InductionWireHit * fWire1
double Metric(double q, double p)
Definition at line 217 of file Solver.cxx.
222 const double chisq0 = chisq.
Eval(0);
228 const double xmin = -sci->
fPred;
229 const double xmax = scj->
fPred;
235 const double chisq_new = chisq.
Eval(x);
240 const double chisq_p = chisq.
Eval(xmax);
241 const double chisq_n = chisq.
Eval(xmin);
244 std::cout <<
"Solution at " << x <<
" is worse than current state! Scan from " << xmin <<
" to " << xmax <<
std::endl;
245 for(
double x = xmin; x < xmax; x += .01*(xmax-xmin)){
249 std::cout <<
"Soln, original, up edge, low edge:" <<
std::endl;
250 std::cout << chisq_new <<
" " << chisq0 <<
" " << chisq_p <<
" " << chisq_n <<
std::endl;
254 if(
std::min(chisq_n, chisq_p) < chisq_new){
255 if(chisq_n < chisq_p)
return xmin;
double Metric(double q, double p)
static int max(int a, int b)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
double Eval(double x) const
QTextStream & endl(QTextStream &s)