ATLAS Offline Software
Loading...
Searching...
No Matches
CBNTAA_TBTrack.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "CBNTAA_TBTrack.h"
6
8#include "TBEvent/TBTrack.h"
10#include <fstream>
11#include <string>
12
13
14CBNTAA_TBTrack::CBNTAA_TBTrack(const std::string & name, ISvcLocator * pSvcLocator) :
15 CBNT_TBRecBase(name, pSvcLocator),
17 m_nRun(0),
26{
27 declareProperty("ReadFileforXcryo", m_readFileforXcryo);
28}
29
31 ATH_MSG_DEBUG ( "in initialize()" );
32
33 // Add beam track parameters
34 addBranch("bm_x", m_beam_coor_x, "bm_x/f");
35 addBranch("bm_y", m_beam_coor_y, "bm_y/f");
36 addBranch("bm_chi2_x", m_beam_chi2_x, "bm_chi2_x/f");
37 addBranch("bm_chi2_y", m_beam_chi2_y, "bm_chi2_y/f");
38 addBranch("bm_x0", m_beam_intercept_x,"bm_x0/f");
39 addBranch("bm_y0", m_beam_intercept_y,"bm_y0/f");
40 addBranch("bm_slope_x",m_beam_slope_x, "bm_slope_x/f");
41 addBranch("bm_slope_y",m_beam_slope_y, "bm_slope_y/f");
42
43 return StatusCode::SUCCESS;
44}
45
47 ATH_MSG_DEBUG ( "in execute()" );
48
49 // Get xcryo and ytable from a file (by A. Minaenko)
50 // Retrieve Event Info
51 const TBEventInfo* theEventInfo = nullptr;
52 ATH_CHECK( evtStore()->retrieve(theEventInfo,"TBEventInfo") );
53
54 // Fill run header
55 m_nRun = theEventInfo->getRunNum();
56 float beamMom = theEventInfo->getBeamMomentum();
57 float xCryo = -9999;
58 float yTable = -9999;
60 if (!this->getXcryoYtable(xCryo, yTable, beamMom)) {
61 ATH_MSG_ERROR ( "xCryo and yTable are not found" );
62 return StatusCode::FAILURE;
63 }
64 } else {
65 xCryo = theEventInfo->getCryoX();
66 yTable = theEventInfo->getTableY();
67 }
68 ATH_MSG_VERBOSE ( "xCryo = " << xCryo );
69 ATH_MSG_VERBOSE ( "yTable = " << yTable );
70 ATH_MSG_VERBOSE ( "m_nRun = " << m_nRun );
71 ATH_MSG_VERBOSE ( "beamMom = " << beamMom );
72
73 // Get beam coordinates (by A. Mineanko)
74 TBTrack *track = nullptr;
75 ATH_CHECK( evtStore()->retrieve(track,"Track") );
76
77 float zCalo = 30000.; // z-coordinate of the calorimeter surface at which beam coordinates calculated
78 m_beam_coor_x = track->getUslope()*zCalo + track->getUintercept() + xCryo;
79 m_beam_coor_y = track->getVslope()*zCalo + track->getVintercept();
80 m_beam_chi2_x = track->getChi2_u();
81 m_beam_chi2_y = track->getChi2_v();
82 m_beam_intercept_x = track->getUintercept();
83 m_beam_intercept_y = track->getVintercept();
84 m_beam_slope_x = track->getUslope();
85 m_beam_slope_y = track->getVslope();
86 ATH_MSG_VERBOSE ( "m_beam_coor_x = " << m_beam_coor_x );
87 ATH_MSG_VERBOSE ( "track->getUslope() = " << track->getUslope() );
88 ATH_MSG_VERBOSE ( "zCalo = " << zCalo );
89 ATH_MSG_VERBOSE ( "track->getUintercept() = " << track->getUintercept() );
90 ATH_MSG_VERBOSE ( "xCryo = " << xCryo );
91 ATH_MSG_VERBOSE ( "m_beam_coor_y = " << m_beam_coor_y );
92 ATH_MSG_VERBOSE ( "track->getVslope() = " << track->getVslope() );
93 ATH_MSG_VERBOSE ( "m_beam_intercept_x = " << m_beam_intercept_x );
94 ATH_MSG_VERBOSE ( "m_beam_intercept_y = " << m_beam_intercept_y );
95
96 return StatusCode::SUCCESS;
97}
98
100 ATH_MSG_DEBUG ( "in finalize()" );
101 return StatusCode::SUCCESS;
102}
103
104std::string CBNTAA_TBTrack::add_name(const char* base, const std::string& extension) {
105 std::string retval(base);
106 for (unsigned i=0;i<extension.size();i++) {
107 const char& ch=extension[i];
108 if (ch=='=' || ch==':' || ch=='/')
109 continue; //Ignore these characters
110 else if (ch=='-')
111 retval.append("m");//replace by letter m
112 else if (ch=='+')
113 retval.append("p");//replace by letter p
114 else
115 retval.append(1,ch);
116 }
117 return retval;
118}
119
120// by A. Minaenko (necessary for TBTrack information)
121StatusCode CBNTAA_TBTrack::getXcryoYtable(float &x, float &y, float &e) {
122
123 // not good to put here (just a workaround) - joh
124 std::string txtFileWithXY = "xcryo_ytable.txt";
125
126 ATH_MSG_DEBUG ( "in getXcryoYtable(float x, float y)" );
127 std::ifstream xyFile;
128 std::string line;
129 std::string filename = PathResolver::find_file(txtFileWithXY, "DATAPATH");
130 xyFile.open(filename.c_str());
131 if (!xyFile.is_open()) {
132 ATH_MSG_ERROR ( "File " << txtFileWithXY << " fail to open in $DATAPATH");
133 return StatusCode::FAILURE;
134 }
135 while ( getline(xyFile, line, '\n') ) {
136 int run;
137 std::istringstream buf(line);
138 e = 0;
139 buf >> run >> x >> y >> e;
140 ATH_MSG_DEBUG ( "m_nRun,run,x,y,e= "<<m_nRun<<" "<<run<<" "<<x<<" "<<y<<" "<<e);
141 if (run==m_nRun && xyFile.good()) return StatusCode::SUCCESS;
142 }
143 return StatusCode::FAILURE;
144}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
#define y
#define x
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
virtual StatusCode CBNT_initialize() override
bool m_readFileforXcryo
Get Xcryo and Ytable from a text file.
CBNTAA_TBTrack(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode CBNT_finalize() override
std::string add_name(const char *base, const std::string &extension)
StatusCode getXcryoYtable(float &x, float &y, float &eBeam)
virtual StatusCode CBNT_execute() override
void addBranch(const std::string &branchname, T &obj, const std::string &leaflist)
CBNT_TBRecBase(const std::string &name, ISvcLocator *pSvcLocator)
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
float getBeamMomentum() const
Definition TBEventInfo.h:73
float getTableY() const
Definition TBEventInfo.h:77
float getCryoX() const
Definition TBEventInfo.h:75
unsigned int getRunNum() const
Definition TBEventInfo.h:72
std::string base
Definition hcg.cxx:81
Definition run.py:1