ATLAS Offline Software
TBBPCRec.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 #include "TBBPCRec.h"
7 
9 
10 #include <iostream>
11 #include <fstream>
12 #include <math.h>
13 
14 // static const AlgFactory<TBBPCRec> s_factory;
15 // const IAlgFactory& TBBPCRecFactory = s_factory;
16 
17 
18 
19 
20 
21 TBBPCRec::TBBPCRec(const std::string& name,
22  ISvcLocator* pSvcLocator) :
23  AthAlgorithm(name,pSvcLocator)
24  {
25  // job options
26 
27  declareProperty("SGkey", m_SGkey="BPCRawCont");
28  declareProperty("SGrecordkey", m_SGrecordkey="BPCCont");
29  declareProperty("CalibFileName", m_calib_filename="H6BPCCalib.txt");
30 
31  declareProperty("BPCnames", m_bpc_names);
32  declareProperty("BPCcalibX", m_bpc_calibX);
33  declareProperty("BPCcalibY", m_bpc_calibY);
34  declareProperty("BPCleftright", m_bpc_leftright);
35  declareProperty("BPCupdown", m_bpc_updown);
36  declareProperty("BPCudoffset", m_bpc_udoffset);
37  declareProperty("BPClroffset", m_bpc_lroffset);
38 
39  declareProperty("BPCinvX", m_bpc_invX);
40  declareProperty("BPCinvY", m_bpc_invY);
41  m_runnumber = 0;
42 
43  declareProperty("TDCmin", m_tdccutmin);
44  declareProperty("TDCmax", m_tdccutmax);
45  declareProperty("TDClrcut", m_tdccutlr);
46  declareProperty("TDCudcut", m_tdccutud);
47  declareProperty("BPCRotation", m_rotation);
48  }
49 
51 { }
52 
55 {
56  return StatusCode::SUCCESS;
57 }
58 
61 {
62  ATH_MSG_DEBUG ( "In execute()" );
63  const EventContext& ctx = Gaudi::Hive::currentContext();
64 
65  // Get run number and get new calib constants -----------------------------
66  unsigned int thisrun=ctx.eventID().run_number();
67 
68  if(thisrun != m_runnumber)
69  {
70  m_runnumber= thisrun;
72  }
73  // ------------------------------------------------------------------------
74 
75  // Reconstruct BPC :
76  TBBPCRawCont * bpcrawCont;
77  StatusCode sc = evtStore()->retrieve(bpcrawCont, m_SGkey);
78  if (sc.isFailure()){
79  ATH_MSG_DEBUG ( "TBObjectReco: Retrieval of "<<m_SGkey<<" failed" );
80  }else {
81  ATH_MSG_DEBUG ( "TBBPCRec : Retrieval of "<<m_SGkey<<" succeed : cont size=" << bpcrawCont->size());
82 
83  TBBPCCont * bpcCont = new TBBPCCont();
84 
85  // Loop over BPC
86  for (const TBBPCRaw * bpcraw : *bpcrawCont) {
87  std::string name = bpcraw->getDetectorName();
88  unsigned int ind=0;
89  // Find calibration index for this BPC
90  while(ind<m_bpc_names.size())
91  {
92  if(name==m_bpc_names[ind]) break;
93  else ind++;
94  }
95  if(ind==m_bpc_names.size()){
96  ATH_MSG_ERROR( "No calibrations for BPC" <<name);
97  continue;
98  }
99 
100  // build new BPC
101  TBBPC * bpc = new TBBPC(name);
102  // hit position
103  float xpos = m_bpc_calibX[ind]*(bpcraw->getTDCLeft()-m_bpc_leftright[ind]*bpcraw->getTDCRight()+m_bpc_lroffset[ind]);
104  // PL at least true for BPC5 y = -y!
105  float ypos = -(m_bpc_calibY[ind]*(bpcraw->getTDCUp()-m_bpc_updown[ind]*bpcraw->getTDCDown()+m_bpc_udoffset[ind]));
106 
107 
108  // perform rotation
109  // PWK 29/06/05 only if m_rotation is set
110 
111  float xposR;
112  float yposR;
113 
114  if (m_rotation.size()>0) {
115  xposR = xpos*cos(m_rotation[ind]) - ypos*sin(m_rotation[ind]);
116  yposR = xpos*sin(m_rotation[ind]) + ypos*cos(m_rotation[ind]);
117  } else {
118  xposR = xpos;
119  yposR = ypos;
120  }
121 
122  ATH_MSG_DEBUG ( "BPC " << name << " PosX = " << xpos << " PosY = " <<ypos );
123  ATH_MSG_DEBUG ( "BPC " << name << " PosXR = " << xposR << " PosYR = " << yposR );
124 
125  bpc->setXPos(xposR);
126  bpc->setYPos(yposR);
127 
128 
129  // pulse
130  bpc->setXPulse(1.*bpcraw->getADCHorizontal());
131  bpc->setYPulse(1.*bpcraw->getADCVertical());
132 
133 
134  // addition September 27 2004
135  // let, in addition to the existing conditions, XPosOverflow and YPosOverflow
136  // be 'true' if either of the left/right or up/down TDC counts falls outside
137  // the range 5 -> 2047
138 
139  // this way, overflows indicate undesirable conditions in general
140 
141  // must find out what causes a real overflow
142 
143  bool xcut = false;
144  bool ycut = false;
145 
146 
147  //PWK 29/06/05 set xcut, ycut true only if TDCmin, TDCmax properties set
148 
149  if (m_tdccutmin.size()>0 && m_tdccutmax.size()>0) {
150 
151  if (bpcraw->getTDCLeft()>m_tdccutmax[ind] || bpcraw->getTDCLeft()<m_tdccutmin[ind]) {xcut = true;}
152  if (bpcraw->getTDCRight()>m_tdccutmax[ind] || bpcraw->getTDCRight()<m_tdccutmin[ind]) {xcut = true;}
153 
154  if (bpcraw->getTDCUp()>m_tdccutmax[ind] || bpcraw->getTDCUp()<m_tdccutmin[ind]) {ycut = true;}
155  if (bpcraw->getTDCDown()>m_tdccutmax[ind] || bpcraw->getTDCDown()<m_tdccutmin[ind]) {ycut = true;}
156 
157  }
158 
159  if (xcut == true)
160  ATH_MSG_INFO ( "TDC left/right out of range " );
161 
162  if (ycut == true)
163  ATH_MSG_INFO ( "TDC up/down out of range " );
164 
165  //PWK 29/06/05 set xcut, ycut true only if TDClrcut, TDCudcut properties set
166 
167  if (m_tdccutlr.size()>0) {
168  if (bpcraw->getTDCLeft()+bpcraw->getTDCRight() < m_tdccutlr[ind])
169  {
170  xcut = true;
171  ATH_MSG_INFO ( "TDC left+right sum below cutoff for BPC " << ind );
172  }
173  }
174  if (m_tdccutud.size()>0) {
175  if (bpcraw->getTDCUp()+bpcraw->getTDCDown() < m_tdccutud[ind])
176  {
177  ycut = true;
178  ATH_MSG_INFO ( "TDC up+down sum below cutoff for BPC " << ind );
179  }
180  }
181 
182  // Overflows
183  bpc->setXPosOverflow(bpcraw->isOverflow(TBBPCRaw::tdcLeft)||bpcraw->isOverflow(TBBPCRaw::tdcRight)||xcut);
184  bpc->setYPosOverflow(bpcraw->isOverflow(TBBPCRaw::tdcUp)||bpcraw->isOverflow(TBBPCRaw::tdcDown)||ycut);
185  bpc->setXPulseOverflow(bpcraw->isOverflow(TBBPCRaw::adcHorizontal));
186  bpc->setYPulseOverflow(bpcraw->isOverflow(TBBPCRaw::adcVertical));
187 
188 
189  bpcCont->push_back(bpc);
190  }
191 
192  sc = evtStore()->record(bpcCont,m_SGrecordkey);
193  if ( sc.isFailure( ) ) {
194  ATH_MSG_FATAL ( "Cannot record BPCCont" );
195  }
196  }
197 
198  if ( sc.isFailure( ) ) {
199  setFilterPassed(false);
200  } else {
201  setFilterPassed(true);
202  }
203 
204  return StatusCode::SUCCESS;
205 
206 }
207 
208 
209 StatusCode
211 {
212  return StatusCode::SUCCESS;
213 }
214 
216 {
217  // Get calib constant from an ASCII file with the following structure :
218  //
219  // runnumber
220  // bpcnumber1 coeff1 coeff2 ... coeff8
221  // bpcnumber2 coeff1 coeff2 ... coeff8
222  // ...
223  // bpcnumber6 coeff1 coeff2 ... coeff8
224  // runnumber
225  // ...
226  //
227  // coeff must have the following order :
228  // bpcnumber calibX calibY leftright updown lroffset udoffset invX invY
229 
230  ATH_MSG_DEBUG ( "Get new calibs for run " << m_runnumber);
231 
232  int bpcnumber= m_bpc_names.size();
233 
234  m_bpc_calibX.clear(); m_bpc_calibX.resize(bpcnumber);
235  m_bpc_calibY.clear(); m_bpc_calibY.resize(bpcnumber);
236  m_bpc_leftright.clear(); m_bpc_leftright.resize(bpcnumber);
237  m_bpc_updown.clear(); m_bpc_updown.resize(bpcnumber);
238  m_bpc_udoffset.clear(); m_bpc_udoffset.resize(bpcnumber);
239  m_bpc_lroffset.clear(); m_bpc_lroffset.resize(bpcnumber);
240  m_bpc_invX.clear(); m_bpc_invX.resize(bpcnumber);
241  m_bpc_invY.clear(); m_bpc_invY.resize(bpcnumber);
242 
243  int pos;
244 
245  std::ifstream calibfile;
246  std::string filename = PathResolver::find_file (m_calib_filename, "DATAPATH");
247  calibfile.open(filename.c_str());
248  if(!calibfile.good()){
249  ATH_MSG_WARNING ( " Problem with file named "<< m_calib_filename << " in $DATAPATH" );
250  return StatusCode::FAILURE;
251  } else {
252  ATH_MSG_DEBUG ( " file " << filename << " opened" );
253  }
254  unsigned int runnumber;
255  calibfile >> runnumber;
256  pos = calibfile.tellg();
257  ATH_MSG_DEBUG ( " Run number "<< runnumber );
258  while((runnumber<m_runnumber)&&(!calibfile.eof()))
259  {
260  runnumber=0;
261  pos = calibfile.tellg();
262  // discard next lines
263  for(int j=0;j<bpcnumber+1;j++) calibfile.ignore(5000,'\n');
264  // check next runnumber
265  calibfile >> runnumber;
266  if(runnumber==0) {
267  ATH_MSG_DEBUG ( "empty line");
268  calibfile.clear();
269  break;
270  } // reached an empty line : exit.
271  ATH_MSG_DEBUG ( " Run number "<< runnumber );
272  }
273 
274  // Now we found the good set of constant (the ones following pos)
275  if(runnumber==m_runnumber) pos = calibfile.tellg();
276  ATH_MSG_DEBUG ( " Pos = "<< pos );
277  calibfile.seekg(pos);
278  ATH_MSG_DEBUG ( " Will use the following constants :" );
279  for(int j=0;j<bpcnumber;j++)
280  {
281  int bpcn;
282  calibfile >> bpcn;
283  calibfile >> m_bpc_calibX[j];
284  calibfile >> m_bpc_calibY[j];
285  calibfile >> m_bpc_leftright[j];
286  calibfile >> m_bpc_updown[j];
287  calibfile >> m_bpc_lroffset[j];
288  calibfile >> m_bpc_udoffset[j];
289  calibfile >> m_bpc_invX[j];
290  calibfile >> m_bpc_invY[j];
291  ATH_MSG_DEBUG ( bpcn << " "<<m_bpc_calibX[j]
292  << " "<< m_bpc_calibY[j]
293  << " "<< m_bpc_leftright[j]
294  << " "<< m_bpc_updown[j]
295  << " "<< m_bpc_lroffset[j]
296  << " "<< m_bpc_udoffset[j]
297  << " "<< m_bpc_invX[j]
298  << " "<< m_bpc_invY[j] );
299 
300  }
301 
302  calibfile.close();
303 
304  return StatusCode::SUCCESS;
305 
306 }
TBBPC::setXPulse
void setXPulse(signal_type theSignal)
Definition: TBBPC.cxx:69
TBBPCRec::m_bpc_lroffset
std::vector< float > m_bpc_lroffset
Definition: TBBPCRec.h:61
TBBPCRec::m_runnumber
unsigned int m_runnumber
Definition: TBBPCRec.h:48
TBBPCRec::~TBBPCRec
virtual ~TBBPCRec()
Definition: TBBPCRec.cxx:50
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
TBBPCRec::m_bpc_updown
std::vector< float > m_bpc_updown
Definition: TBBPCRec.h:59
TBBPCRaw
raw data class for BPC measurement
Definition: TBBPCRaw.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
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
TBBPCRec::m_tdccutmax
std::vector< float > m_tdccutmax
Definition: TBBPCRec.h:67
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TBBPC
Definition: TBBPC.h:23
TBBPCRec::execute
virtual StatusCode execute() override
Definition: TBBPCRec.cxx:60
TBBPCRec::m_calib_filename
std::string m_calib_filename
Definition: TBBPCRec.h:46
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
TBBPCRaw::tdcUp
@ tdcUp
Definition: TBBPCRaw.h:46
TBBPC::setYPulse
void setYPulse(signal_type theSignal)
Definition: TBBPC.cxx:74
TBBPCRaw::adcVertical
@ adcVertical
Definition: TBBPCRaw.h:49
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
TBBPCRec::m_SGrecordkey
std::string m_SGrecordkey
Definition: TBBPCRec.h:45
TBBPCRec::m_bpc_calibY
std::vector< float > m_bpc_calibY
Definition: TBBPCRec.h:57
TBBPC::setXPulseOverflow
void setXPulseOverflow(bool overflow=true)
Definition: TBBPC.cxx:94
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
TBBPCRec::m_bpc_leftright
std::vector< float > m_bpc_leftright
Definition: TBBPCRec.h:58
TBBPCRec::m_rotation
std::vector< float > m_rotation
Definition: TBBPCRec.h:71
TBBPCRec::m_bpc_calibX
std::vector< float > m_bpc_calibX
Definition: TBBPCRec.h:56
TBBPCRec::m_bpc_udoffset
std::vector< float > m_bpc_udoffset
Definition: TBBPCRec.h:60
TBBPCRec::m_SGkey
std::string m_SGkey
Definition: TBBPCRec.h:45
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TBBPCRec::m_tdccutud
std::vector< float > m_tdccutud
Definition: TBBPCRec.h:69
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
TBBPCRec::finalize
virtual StatusCode finalize() override
Definition: TBBPCRec.cxx:210
TBBPCRaw::adcHorizontal
@ adcHorizontal
Definition: TBBPCRaw.h:48
TBBPCRec::m_bpc_names
std::vector< std::string > m_bpc_names
Definition: TBBPCRec.h:54
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TBBPCRec::initialize
virtual StatusCode initialize() override
Definition: TBBPCRec.cxx:54
TBBPCRaw::tdcDown
@ tdcDown
Definition: TBBPCRaw.h:47
TBBPCRec::m_tdccutmin
std::vector< float > m_tdccutmin
Definition: TBBPCRec.h:66
TBBPC::setYPosOverflow
void setYPosOverflow(bool overflow=true)
Definition: TBBPC.cxx:89
AthAlgorithm
Definition: AthAlgorithm.h:47
TBBPCRaw::tdcLeft
@ tdcLeft
Definition: TBBPCRaw.h:44
DeMoScan.runnumber
runnumber
Definition: DeMoScan.py:266
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
TBBPCRec.h
TBBPCRec::getnewcalib
StatusCode getnewcalib()
Definition: TBBPCRec.cxx:215
TBBPC::setXPos
void setXPos(signal_type theSignal)
Definition: TBBPC.cxx:49
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
TBBPCRaw::tdcRight
@ tdcRight
Definition: TBBPCRaw.h:45
TBBPCRec::TBBPCRec
TBBPCRec(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TBBPCRec.cxx:21
TBBPCRec::m_bpc_invY
std::vector< float > m_bpc_invY
Definition: TBBPCRec.h:64
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
TBBPCRec::m_tdccutlr
std::vector< float > m_tdccutlr
Definition: TBBPCRec.h:68
TBBPC::setYPulseOverflow
void setYPulseOverflow(bool overflow=true)
Definition: TBBPC.cxx:99
TBBPCRec::m_bpc_invX
std::vector< float > m_bpc_invX
Definition: TBBPCRec.h:63
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
TBBPC::setYPos
void setYPos(signal_type theSignal)
Definition: TBBPC.cxx:54
TBBPC::setXPosOverflow
void setXPosOverflow(bool overflow=true)
Definition: TBBPC.cxx:84
checkFileSG.ind
list ind
Definition: checkFileSG.py:118
TBBPCRawCont
Definition: TBBPCRawCont.h:17
TBBPCCont
Definition: TBBPCCont.h:17