45 return StatusCode::SUCCESS;
53 const EventContext& ctx = Gaudi::Hive::currentContext();
57 "Using FillRandomHit method to get data");
64 StatusCode checkOut =
evtStore()->retrieve(theEventInfo,
"TBEventInfo");
65 if ( checkOut.isFailure() )
68 return StatusCode::FAILURE;
72 if (evtType != 1)
return StatusCode::SUCCESS;
77 unsigned int thisrun=ctx.eventID().run_number();
95 setFilterPassed(
false);
96 return StatusCode::SUCCESS;
99 int hitPlaneNumU, hitPlaneNumV;
103 if( (hitPlaneNumU < 2) || (hitPlaneNumV < 2) ){
105 <<
"Not enough hits in one or both planes, "
106 <<
"Cannot make track.");
108 setFilterPassed(
false);
109 return StatusCode::SUCCESS;
115 std::vector<double> residual_u, residual_v;
125 setFilterPassed(
false);
126 return StatusCode::SUCCESS;
132 setFilterPassed(
false);
133 return StatusCode::SUCCESS;
140 track->setUintercept(a1_u);
141 track->setVintercept(a1_v);
142 track->setUslope(a2_u);
143 track->setVslope(a2_v);
146 for(
int i = 0; i < hitPlaneNumU; i++){
147 track->setResidualu(i, residual_u[i]);
151 for(
int i = 0; i < hitPlaneNumV; i++){
152 track->setResidualv(i, residual_v[i]);
159 track->setChi2_u(chi2_u);
160 track->setChi2_v(chi2_v);
163 StatusCode
sc =
evtStore()->record(track,
"Track");
165 if (
sc.isFailure( ) ) {
170 setFilterPassed(
true);
171 return StatusCode::SUCCESS;
179 return StatusCode::SUCCESS;
184double &a1,
double &a2,
double &
chi2, std::vector<double> &residual)
188 int hitPlaneNum = hitPlaneCont->
size();
190 ATH_MSG_DEBUG (
"The hit plane container size is: " << hitPlaneNum);
192 std::vector<double> vec_u;
193 std::vector<double> vec_w;
194 std::vector<double> err_vec_u;
195 std::vector<double> err_vec_w;
202 vec_u.push_back(hp->getPosu());
203 vec_w.push_back(hp->getPosw());
204 err_vec_u.push_back(hp->getErroru());
205 err_vec_w.push_back(hp->getErrorw());
208 if(vec_u.size() != vec_w.size()){
215 check =
fitHits(vec_u, vec_w, err_vec_u, a1, a2);
225 <<
" intercept = " << a1
226 <<
" and slope = " << a2);
229 for (
int i = 0; i < hitPlaneNum; i++) {
230 residual.push_back(
getResidual(vec_u[i],vec_w[i],a1, a2));
237 const std::vector<double> & v_w,
238 const std::vector<double> & v_eu,
240 double &a1,
double &a2)
263 int numHits = v_u.size();
264 for(
int i = 0; i < numHits; i++){
265 m_s += 1 / (v_eu[i]*v_eu[i]);
266 m_su += v_u[i] / (v_eu[i]*v_eu[i]);
267 m_sww += v_w[i]*v_w[i] / (v_eu[i]*v_eu[i]);
268 m_sw += v_w[i] / (v_eu[i]*v_eu[i]);
269 m_suw += v_u[i]*v_w[i] / (v_eu[i]*v_eu[i]);
272 const double denom = (m_s*m_sww-m_sw*m_sw);
278 const double inv_denom = 1. / denom;
279 a1 = (m_su*m_sww - m_sw*m_suw) * inv_denom;
280 a2 = (m_s*m_suw - m_su*m_sw) * inv_denom;
285 ,
const double &a1,
const double &a2)
288 return (u - a1 - a2*w);
293 const std::vector<double> &v_w,
294 const std::vector<double> &v_eu,
296 const double &a1,
const double &a2)
304 int numX = v_u.size();
307 for(
int i = 0; i < numX; i++){
308 chi2 += (v_u[i] - a1 - a2*v_w[i])*(v_u[i] - a1 - a2*v_w[i])/(v_eu[i]*v_eu[i]);
333 StatusCode sc1 =
evtStore()->record(hitPlaneCont_U,
"HitPlaneCont_U");
334 if ( sc1.isFailure( ) ) {
346 StatusCode sc2 =
evtStore()->record(hitPlaneCont_V,
"HitPlaneCont_V");
347 if ( sc2.isFailure( ) ) {
367 for (
const TBBPC* bpc : *bpcCont) {
368 std::string name = bpc->getDetectorName();
385 if(!(bpc->isXPosOverflow()||bpc->isXPulseOverflow())){
394 hitu->
setValidFlag(bpc->isXPosOverflow()&&bpc->isYPosOverflow());
398 if(!(bpc->isYPosOverflow()||bpc->isYPulseOverflow())){
407 hitv->
setValidFlag(bpc->isXPosOverflow()&&bpc->isYPosOverflow());
412 return StatusCode::SUCCESS;
448 std::ifstream calibfile;
450 calibfile.open(filename.c_str());
451 if(!calibfile.good()){
453 return StatusCode::FAILURE;
459 pos = calibfile.tellg();
464 pos = calibfile.tellg();
466 for(
int j=0;j<bpcnumber+1;j++) calibfile.ignore(5000,
'\n');
480 calibfile.seekg(pos);
482 for(
int j=0;j<bpcnumber;j++)
511 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
value_type push_back(value_type pElem)
Add an element to the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
Holds a set of TBHitPlane objects.
This class is used to store hit information from BPC & MWPC for one plane.
void setValidFlag(bool valid)
void setErroru(double eu)
void setErrorw(double ew)
std::vector< float > m_bpc_posX
double getChi2(const std::vector< double > &v_u, const std::vector< double > &v_w, const std::vector< double > &v_eu, const double &a1, const double &a2)
Calculates the chi2 += ((u_i - a1 - a2*w_i)/eu)^2.
std::vector< float > m_bpc_errmeasX
StatusCode buildHits()
Build HitPlaneCont from BPC.
virtual StatusCode execute() override
virtual StatusCode initialize() override
std::vector< float > m_bpc_errposY
std::vector< float > m_bpc_posZX
bool fitPlane(const TBHitPlaneCont *hitPlaneCont, double &a1, double &a2, double &chi2, std::vector< double > &residual)
Fit data to the function u = a1 + a2*w.
std::vector< float > m_bpc_posY
bool fitHits(const std::vector< double > &u, const std::vector< double > &w, const std::vector< double > &eu, double &a1, double &a2)
Fit data to the function u = a1 + a2*w.
std::vector< std::string > m_bpc_names
std::vector< float > m_bpc_errposZY
std::vector< float > m_bpc_errposZX
std::vector< float > m_bpc_errmeasY
std::vector< float > m_bpc_posZY
virtual StatusCode finalize() override
TBHitPlaneCont m_hitPlaneCont_u
std::vector< float > m_bpc_errposX
std::string m_calib_filename
TBHitPlaneCont m_hitPlaneCont_v
double getResidual(const double &u, const double &w, const double &a1, const double &a2)
Calculates the residual-> r = (u_i - a1 - a2*w_i)
TBPlaneTrackingAlgo(const std::string &name, ISvcLocator *pSvcLocator)
double chi2(TH1 *h0, TH1 *h1)
static std::vector< uint32_t > runnumber