45 return StatusCode::SUCCESS;
56 "Using FillRandomHit method to get data");
63 StatusCode checkOut =
evtStore()->retrieve(theEventInfo,
"TBEventInfo");
64 if ( checkOut.isFailure() )
67 return StatusCode::FAILURE;
71 if (evtType != 1)
return StatusCode::SUCCESS;
76 unsigned int thisrun=ctx.eventID().run_number();
95 return StatusCode::SUCCESS;
98 int hitPlaneNumU, hitPlaneNumV;
102 if( (hitPlaneNumU < 2) || (hitPlaneNumV < 2) ){
104 <<
"Not enough hits in one or both planes, "
105 <<
"Cannot make track.");
108 return StatusCode::SUCCESS;
114 std::vector<double> residual_u, residual_v;
125 return StatusCode::SUCCESS;
132 return StatusCode::SUCCESS;
139 track->setUintercept(a1_u);
140 track->setVintercept(a1_v);
141 track->setUslope(a2_u);
142 track->setVslope(a2_v);
145 for(
int i = 0; i < hitPlaneNumU; i++){
146 track->setResidualu(i, residual_u[i]);
150 for(
int i = 0; i < hitPlaneNumV; i++){
151 track->setResidualv(i, residual_v[i]);
158 track->setChi2_u(chi2_u);
159 track->setChi2_v(chi2_v);
162 StatusCode
sc =
evtStore()->record(track,
"Track");
164 if (
sc.isFailure( ) ) {
170 return StatusCode::SUCCESS;
178 return StatusCode::SUCCESS;
183double &a1,
double &a2,
double &
chi2, std::vector<double> &residual)
187 int hitPlaneNum = hitPlaneCont->
size();
189 ATH_MSG_DEBUG (
"The hit plane container size is: " << hitPlaneNum);
191 std::vector<double> vec_u;
192 std::vector<double> vec_w;
193 std::vector<double> err_vec_u;
194 std::vector<double> err_vec_w;
201 vec_u.push_back(hp->getPosu());
202 vec_w.push_back(hp->getPosw());
203 err_vec_u.push_back(hp->getErroru());
204 err_vec_w.push_back(hp->getErrorw());
207 if(vec_u.size() != vec_w.size()){
214 check =
fitHits(vec_u, vec_w, err_vec_u, a1, a2);
224 <<
" intercept = " << a1
225 <<
" and slope = " << a2);
228 for (
int i = 0; i < hitPlaneNum; i++) {
229 residual.push_back(
getResidual(vec_u[i],vec_w[i],a1, a2));
236 const std::vector<double> & v_w,
237 const std::vector<double> & v_eu,
239 double &a1,
double &a2)
262 int numHits = v_u.size();
263 for(
int i = 0; i < numHits; i++){
264 m_s += 1 / (v_eu[i]*v_eu[i]);
265 m_su += v_u[i] / (v_eu[i]*v_eu[i]);
266 m_sww += v_w[i]*v_w[i] / (v_eu[i]*v_eu[i]);
267 m_sw += v_w[i] / (v_eu[i]*v_eu[i]);
268 m_suw += v_u[i]*v_w[i] / (v_eu[i]*v_eu[i]);
271 const double denom = (m_s*m_sww-m_sw*m_sw);
277 const double inv_denom = 1. / denom;
278 a1 = (m_su*m_sww - m_sw*m_suw) * inv_denom;
279 a2 = (m_s*m_suw - m_su*m_sw) * inv_denom;
284 ,
const double &a1,
const double &a2)
287 return (u - a1 - a2*w);
292 const std::vector<double> &v_w,
293 const std::vector<double> &v_eu,
295 const double &a1,
const double &a2)
303 int numX = v_u.size();
306 for(
int i = 0; i < numX; i++){
307 chi2 += (v_u[i] - a1 - a2*v_w[i])*(v_u[i] - a1 - a2*v_w[i])/(v_eu[i]*v_eu[i]);
332 StatusCode sc1 =
evtStore()->record(hitPlaneCont_U,
"HitPlaneCont_U");
333 if ( sc1.isFailure( ) ) {
345 StatusCode sc2 =
evtStore()->record(hitPlaneCont_V,
"HitPlaneCont_V");
346 if ( sc2.isFailure( ) ) {
366 for (
const TBBPC* bpc : *bpcCont) {
367 std::string name = bpc->getDetectorName();
384 if(!(bpc->isXPosOverflow()||bpc->isXPulseOverflow())){
393 hitu->
setValidFlag(bpc->isXPosOverflow()&&bpc->isYPosOverflow());
397 if(!(bpc->isYPosOverflow()||bpc->isYPulseOverflow())){
406 hitv->
setValidFlag(bpc->isXPosOverflow()&&bpc->isYPosOverflow());
411 return StatusCode::SUCCESS;
447 std::ifstream calibfile;
449 calibfile.open(filename.c_str());
450 if(!calibfile.good()){
452 return StatusCode::FAILURE;
458 pos = calibfile.tellg();
463 pos = calibfile.tellg();
465 for(
int j=0;j<bpcnumber+1;j++) calibfile.ignore(5000,
'\n');
479 calibfile.seekg(pos);
481 for(
int j=0;j<bpcnumber;j++)
510 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
void setFilterPassed(bool state) const
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 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
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
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