ATLAS Offline Software
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 
7 #include "TBEvent/TBEventInfo.h"
8 #include "TBEvent/TBTrack.h"
10 #include <fstream>
11 #include <string>
12 
13 
14 CBNTAA_TBTrack::CBNTAA_TBTrack(const std::string & name, ISvcLocator * pSvcLocator) :
15  CBNT_TBRecBase(name, pSvcLocator),
16  m_readFileforXcryo(true),
17  m_nRun(0),
18  m_beam_coor_x(0),
19  m_beam_coor_y(0),
20  m_beam_chi2_x(0),
21  m_beam_chi2_y(0),
22  m_beam_intercept_x(0),
23  m_beam_intercept_y(0),
24  m_beam_slope_x(0),
25  m_beam_slope_y(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;
59  if(m_readFileforXcryo) {
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 
104 std::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)
121 StatusCode 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 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
CBNTAA_TBTrack::m_beam_chi2_y
float m_beam_chi2_y
Definition: CBNTAA_TBTrack.h:37
base
std::string base
Definition: hcg.cxx:78
checkFileSG.line
line
Definition: checkFileSG.py:75
sendEI_SPB.ch
ch
Definition: sendEI_SPB.py:35
TBTrack
Definition: TBTrack.h:20
CBNTAA_TBTrack::m_readFileforXcryo
bool m_readFileforXcryo
Get Xcryo and Ytable from a text file.
Definition: CBNTAA_TBTrack.h:29
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
Definition: PathResolver.cxx:251
CBNTAA_TBTrack::m_nRun
int m_nRun
Definition: CBNTAA_TBTrack.h:31
CBNTAA_TBTrack::m_beam_intercept_y
float m_beam_intercept_y
Definition: CBNTAA_TBTrack.h:39
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TBEventInfo::getRunNum
unsigned int getRunNum() const
Definition: TBEventInfo.h:67
run
int run(int argc, char *argv[])
Definition: ttree2hdf5.cxx:28
CBNTAA_TBTrack::CBNT_finalize
virtual StatusCode CBNT_finalize() override
Definition: CBNTAA_TBTrack.cxx:99
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
x
#define x
CBNTAA_TBTrack::CBNT_execute
virtual StatusCode CBNT_execute() override
Definition: CBNTAA_TBTrack.cxx:46
LArCellBinning_test.retval
def retval
Definition: LArCellBinning_test.py:112
TBEventInfo::getTableY
float getTableY() const
Definition: TBEventInfo.h:72
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CBNT_TBRecBase
Definition: CBNT_TBRecBase.h:21
lumiFormat.i
int i
Definition: lumiFormat.py:92
CBNTAA_TBTrack::getXcryoYtable
StatusCode getXcryoYtable(float &x, float &y, float &eBeam)
Definition: CBNTAA_TBTrack.cxx:121
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
CBNT_TBRecBase::addBranch
void addBranch(const std::string &branchname, T &obj, const std::string &leaflist)
Definition: CBNT_TBRecBase.h:44
CBNTAA_TBTrack::CBNT_initialize
virtual StatusCode CBNT_initialize() override
Definition: CBNTAA_TBTrack.cxx:30
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TBTrack.h
CBNTAA_TBTrack::m_beam_coor_x
float m_beam_coor_x
Definition: CBNTAA_TBTrack.h:34
run
Definition: run.py:1
CBNTAA_TBTrack::m_beam_coor_y
float m_beam_coor_y
Definition: CBNTAA_TBTrack.h:35
CBNTAA_TBTrack::CBNTAA_TBTrack
CBNTAA_TBTrack(const std::string &name, ISvcLocator *pSvcLocator)
Definition: CBNTAA_TBTrack.cxx:14
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
CBNTAA_TBTrack::m_beam_chi2_x
float m_beam_chi2_x
Definition: CBNTAA_TBTrack.h:36
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
y
#define y
TBEventInfo
Definition: TBEventInfo.h:27
CBNTAA_TBTrack::m_beam_slope_x
float m_beam_slope_x
Definition: CBNTAA_TBTrack.h:40
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
CBNTAA_TBTrack::m_beam_slope_y
float m_beam_slope_y
Definition: CBNTAA_TBTrack.h:41
TBEventInfo::getBeamMomentum
float getBeamMomentum() const
Definition: TBEventInfo.h:68
TBEventInfo.h
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
TBEventInfo::getCryoX
float getCryoX() const
Definition: TBEventInfo.h:70
CBNTAA_TBTrack::add_name
std::string add_name(const char *base, const std::string &extension)
Definition: CBNTAA_TBTrack.cxx:104
CBNTAA_TBTrack.h
CBNTAA_TBTrack::m_beam_intercept_x
float m_beam_intercept_x
Definition: CBNTAA_TBTrack.h:38