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