ATLAS Offline Software
CBNTAA_BeamInstrumentation.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
8 #include "TBEvent/TBBPCCont.h"
9 #include "TBEvent/TBBPCRawCont.h"
10 #include "TBEvent/TBPhase.h"
12 #include <vector>
13 
14 CBNTAA_BeamInstrumentation::CBNTAA_BeamInstrumentation(const std::string & name, ISvcLocator * pSvcLocator) : CBNT_TBRecBase(name, pSvcLocator)
15 {
16  declareProperty("ContainerKey1",m_containerKey1="ScintillatorCont");
17  declareProperty("ContainerKey2",m_containerKey2="BPCCont");
18  declareProperty("ContainerKey3",m_containerKey3="BPCRawCont");
19  declareProperty("ContainerKey4",m_containerKey4="TBPhase");
20  declareProperty("ContainerKey5",m_containerKey5="TBTrigPat");
21  declareProperty("BPCRAW", m_bpc_raw=false);
22  declareProperty("BPCnames",m_bpc_names);
23  declareProperty("Scintnames",m_scint_names);
24  declareProperty("TrigArray",m_trig_array=false);
25  declareProperty("TrigPattern",m_triggflag);
26  declareProperty("NeverReturnFailure", m_neverReturnFailure=false);
27  m_scint_adc=NULL;
28  m_scint_tdc=NULL;
29  m_bpc_x=NULL;
30  m_bpc_y=NULL;
31  m_bpc_up=NULL;
32  m_bpc_down=NULL;
33  m_bpc_left=NULL;
34  m_bpc_right=NULL;
35  m_bpc_adc_hor=NULL;
36  m_bpc_adc_ver=NULL;
37  m_trig_sel=NULL;
38  m_bpc_ntnames=NULL;
39  m_scint_ntnames=NULL;
40  m_clock = 0;
41  m_trig = 0;
42  m_trig_id = 0;
43 }
44 
46 {//Clean up arrays of ntuple entries (if they have been booked)
47  if (m_scint_adc)
48  delete m_scint_adc;
49  if (m_scint_tdc)
50  delete m_scint_tdc;
51  if ( m_bpc_x)
52  delete m_bpc_x;
53  if ( m_bpc_y)
54  delete m_bpc_y;
55  if (m_bpc_up)
56  delete m_bpc_up;
57  if (m_bpc_down)
58  delete m_bpc_down;
59  if (m_bpc_right)
60  delete m_bpc_right;
61  if (m_bpc_left)
62  delete m_bpc_left;
63  if (m_bpc_adc_ver)
64  delete m_bpc_adc_ver;
65  if (m_bpc_adc_hor)
66  delete m_bpc_adc_hor;
67  if (m_trig_sel)
68  delete m_trig_sel;
69 }
70 
72 {
73  ATH_MSG_DEBUG ( "in initialize()" );
74 
75  const unsigned nScint=m_scint_names.size();
76  addBranch("Beam_sNames",m_scint_ntnames);
77  for (unsigned i=0;i<nScint;i++) {
78  const std::string ADCItemName=add_name("scint_",m_scint_names[i]);
79  m_scint_ntnames->push_back(ADCItemName);
80  }
81  addBranch("Beam_sADC",m_scint_adc);
82  addBranch("Beam_sTDC",m_scint_tdc);
83 
84  const unsigned nBPCs=m_bpc_names.size();
85  addBranch("Beam_bNames",m_bpc_ntnames);
86  for (unsigned i=0;i<nBPCs;i++) {
87  const std::string BPCName=add_name("bpc_",m_bpc_names[i]);
88  m_bpc_ntnames->push_back(BPCName);
89  }
90  addBranch("Beam_bpcX",m_bpc_x);
91  addBranch("Beam_bpcY",m_bpc_y);
92 
93  // BPC RAW, set to false by default
94  if(m_bpc_raw==true) {// bpc raw
95 
96  addBranch("Beam_bpcUp",m_bpc_up);
97  addBranch("Beam_bpcDown",m_bpc_down);
98  addBranch("Beam_bpcRight",m_bpc_right);
99  addBranch("Beam_bpcLeft",m_bpc_left);
100  addBranch("Beam_bpcADCHor",m_bpc_adc_hor);
101  addBranch("Beam_bpcADCVer",m_bpc_adc_ver);
102 
103  } //bpcraw
104 
105  addBranch("Beam_Trigger",m_trig,"Trigger/l");
106  // trigger array
107  ATH_MSG_DEBUG (" m_trig_array"<<m_trig_array);
108  if (m_trig_array==true) {
109 
110  ATH_MSG_DEBUG (" loading array ntuple");
111  addBranch("Beam_NTrig",m_trig_id,"/l");
112 
113  addBranch("Beam_Trig_Array",m_trig_sel);
114  }
115 
116  addBranch ("Beam_Clock",m_clock,"Clock/f");
117 
118  return StatusCode::SUCCESS;
119 
120 }
121 
123 {
124  const TBScintillatorCont * scintc = nullptr;
125  StatusCode sc = evtStore()->retrieve(scintc,m_containerKey1);
126  if (sc.isFailure())
127  {
128  ATH_MSG_ERROR ( " Cannot read TBScintillatorCont from StoreGate! key= " << m_containerKey1 );
129  if (m_neverReturnFailure) {
130  return StatusCode::SUCCESS;
131  } else {
132  return StatusCode::FAILURE;
133  }
134  }
135  else
136  {
137  const unsigned nScint=m_scint_names.size();
138  ATH_MSG_DEBUG ( "Filling for "<<nScint<<" scintilators");
139 // m_scint_adc->reserve(nScint);
140 // m_scint_tdc->reserve(nScint);
141  m_scint_adc->resize(nScint);
142  m_scint_tdc->resize(nScint);
143  for (const TBScintillator * scint : *scintc) {
144  const std::string name = scint->getDetectorName();
145  //In the initialize method we build the vectors of ntuple-items for ADCs and BPCs that
146  //the same scintillators have the same index. We search the name-vector and use the index
147  //for m_scint_adc and m_scint_tdc
148  unsigned NtupleVectorIndex;
149  for ( NtupleVectorIndex=0; NtupleVectorIndex!=nScint; NtupleVectorIndex++)
150  if (name==m_scint_names[NtupleVectorIndex]) {
151  // log << MSG::DEBUG << "Scintillator '" << name << "' not found." << endmsg;
152  break;
153  }
154  if (NtupleVectorIndex==nScint) {
155  ATH_MSG_DEBUG ( "Not found a scint name: "<<name);
156  continue; //Name not found for this event
157  }
158  //Otherwise: Fill nutple
159  (*m_scint_adc)[NtupleVectorIndex] = scint->getSignal();
160  (*m_scint_tdc)[NtupleVectorIndex] = scint->getTimeSignal();
161  } //end loop over scintillator-container
162  }
163 
164  const TBBPCCont * bpcc = nullptr;
165  sc = evtStore()->retrieve(bpcc,m_containerKey2);
166  if (sc.isFailure())
167  {
168  ATH_MSG_ERROR ( " Cannot read TBBPCCont from StoreGate! key= " << m_containerKey2 );
169  if (m_neverReturnFailure) {
170  return StatusCode::SUCCESS;
171  } else {
172  return StatusCode::FAILURE;
173  }
174  }
175  else
176  {
177  const unsigned nBPCs=m_bpc_names.size();
178  m_bpc_x->reserve(nBPCs);
179  m_bpc_y->reserve(nBPCs);
180  for (const TBBPC * bpc : *bpcc) {
181  std::string name = bpc->getDetectorName();
182  unsigned NtupleVectorIndex;
183  for ( NtupleVectorIndex=0; NtupleVectorIndex!=nBPCs; NtupleVectorIndex++)
184  if (name==m_bpc_names[NtupleVectorIndex])
185  break;
186  if (NtupleVectorIndex==nBPCs)
187  continue; //Name not found for this event
188  //Otherwise: Fill nutple
189  (*m_bpc_x)[NtupleVectorIndex] = bpc->getXPos();
190  (*m_bpc_y)[NtupleVectorIndex] = bpc->getYPos();
191  } //end loop over scintillator container
192  }
193 
194  if (m_bpc_raw==true) { //bpc raw
195  TBBPCRawCont * bpccr = nullptr;
196  sc = evtStore()->retrieve(bpccr, m_containerKey3);
197  if (sc.isFailure()){
198  ATH_MSG_ERROR ( " Cannot read TBBPCRawCont from StoreGate! key= " <<m_containerKey3);
199  } else {
200  const unsigned nBPCs=m_bpc_names.size();
201  m_bpc_up->reserve(nBPCs);
202  m_bpc_down->reserve(nBPCs);
203  m_bpc_right->reserve(nBPCs);
204  m_bpc_left->reserve(nBPCs);
205  m_bpc_adc_hor->reserve(nBPCs);
206  m_bpc_adc_ver->reserve(nBPCs);
207  for (const TBBPCRaw * bpcr : *bpccr) {
208  std::string name = bpcr->getDetectorName();
209  unsigned NtupleVectorIndex;
210  for ( NtupleVectorIndex=0; NtupleVectorIndex!=nBPCs; NtupleVectorIndex++){
211  ATH_MSG_DEBUG (" loading 1");
212  if (name==m_bpc_names[NtupleVectorIndex]){
213  ATH_MSG_DEBUG (" Ntuple Vector"<<NtupleVectorIndex);
214  (*m_bpc_up)[NtupleVectorIndex] = bpcr->getTDCUp();
215  (*m_bpc_down)[NtupleVectorIndex] = bpcr->getTDCDown();
216  (*m_bpc_right)[NtupleVectorIndex] = bpcr->getTDCRight();
217  (*m_bpc_left)[NtupleVectorIndex] = bpcr->getTDCLeft();
218  (*m_bpc_adc_hor)[NtupleVectorIndex] = bpcr->getADCHorizontal();
219  (*m_bpc_adc_ver)[NtupleVectorIndex] = bpcr->getADCVertical();
220  }
221  }
222  }
223  }
224  } //bpcraw
225 
226  const TBPhase * phase = nullptr;
227  sc = evtStore()->retrieve(phase,m_containerKey4);
228  if (sc.isFailure())
229  {
230  ATH_MSG_ERROR ( " Cannot read TBPhase from StoreGate! key= " << m_containerKey4 );
231  if (m_neverReturnFailure) {
232  return StatusCode::SUCCESS;
233  } else {
234  return StatusCode::FAILURE;
235  }
236  }
237  else
238  {
239  m_clock = phase->getPhase();
240  }
241 
242  const TBTriggerPatternUnit * trig = nullptr;
243  sc = evtStore()->retrieve(trig,m_containerKey5);
244  if (sc.isFailure())
245  {
246  ATH_MSG_ERROR ( " Cannot read TBTriggerPatternUnit from StoreGate! key= " << m_containerKey5 );
247  if (m_neverReturnFailure) {
248  return StatusCode::SUCCESS;
249  } else {
250  return StatusCode::FAILURE;
251  }
252  }
253  else
254  {
255  m_trig = trig->getTriggerWord();
256  }
257 
258 
259  //Trigger Array, returns array of triggers with corresponding 0 or 1 for each event
260 
261  if (m_trig_array==true) {
262  unsigned int word =trig->getTriggerWord();
263 
264  // Checking if objects in triggflag triggered
265  ATH_MSG_DEBUG(m_triggflag.size());
266  m_trig_sel->reserve(m_triggflag.size()+1);
267  for(int unsigned i=0;i<m_triggflag.size()+1;i++){
268  bool triggbol=0;
269  m_trig_id=i;
270  triggbol=((word & m_triggflag[i])!=0);
271  if(triggbol){
272  (*m_trig_sel)[i]=1;
273  }
274  }
275  }
276 
277  return StatusCode::SUCCESS;
278 }
279 
281 {
282  if (m_scint_adc)
283  m_scint_adc->clear();
284  if (m_scint_tdc)
285  m_scint_tdc->clear();
286  if ( m_bpc_x)
287  m_bpc_x->clear();
288  if ( m_bpc_y)
289  m_bpc_y->clear();
290  if (m_bpc_up)
291  m_bpc_up->clear();
292  if (m_bpc_down)
293  m_bpc_down->clear();
294  if (m_bpc_right)
295  m_bpc_right->clear();
296  if (m_bpc_left)
297  m_bpc_left->clear();
298  if (m_bpc_adc_ver)
299  m_bpc_adc_ver->clear();
300  if (m_bpc_adc_hor)
301  m_bpc_adc_hor->clear();
302  if (m_trig_sel)
303  m_trig_sel->clear();
304 
305  return StatusCode::SUCCESS;
306 }
307 
309 {
310  ATH_MSG_DEBUG ( "in finalize()" );
311  return StatusCode::SUCCESS;
312 }
313 
314 std::string CBNTAA_BeamInstrumentation::add_name(const char* base, const std::string& extension) {
315  std::string retval(base);
316  for (unsigned i=0;i<extension.size();i++) {
317  const char& ch=extension[i];
318  if (ch=='=' || ch==':' || ch=='/')
319  continue; //Inore these characters
320  else if (ch=='-')
321  retval.append("m");//replace by letter m
322  else if (ch=='+')
323  retval.append("p");//replace by letter p
324  else
325  retval.append(1,ch);
326  }
327  return retval;
328 }
base
std::string base
Definition: hcg.cxx:78
ReadOfcFromCool.phase
phase
Definition: ReadOfcFromCool.py:127
sendEI_SPB.ch
ch
Definition: sendEI_SPB.py:35
CBNTAA_BeamInstrumentation::m_bpc_down
std::vector< float > * m_bpc_down
Definition: CBNTAA_BeamInstrumentation.h:45
TBBPCRaw
raw data class for BPC measurement
Definition: TBBPCRaw.h:33
CBNTAA_BeamInstrumentation::m_bpc_ntnames
std::vector< std::string > * m_bpc_ntnames
Definition: CBNTAA_BeamInstrumentation.h:38
TBScintillatorCont.h
CBNTAA_BeamInstrumentation::m_bpc_x
std::vector< float > * m_bpc_x
Definition: CBNTAA_BeamInstrumentation.h:39
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TBBPC
Definition: TBBPC.h:23
CBNTAA_BeamInstrumentation::m_bpc_up
std::vector< float > * m_bpc_up
Definition: CBNTAA_BeamInstrumentation.h:45
CBNTAA_BeamInstrumentation::m_trig
long m_trig
Definition: CBNTAA_BeamInstrumentation.h:40
CBNTAA_BeamInstrumentation::m_triggflag
std::vector< unsigned int > m_triggflag
Definition: CBNTAA_BeamInstrumentation.h:49
CBNTAA_BeamInstrumentation::m_trig_id
long m_trig_id
Definition: CBNTAA_BeamInstrumentation.h:51
CBNTAA_BeamInstrumentation::add_name
std::string add_name(const char *base, const std::string &extension)
Definition: CBNTAA_BeamInstrumentation.cxx:314
TBScintillatorCont
Definition: TBScintillatorCont.h:19
CBNTAA_BeamInstrumentation::m_bpc_adc_hor
std::vector< float > * m_bpc_adc_hor
Definition: CBNTAA_BeamInstrumentation.h:45
CBNTAA_BeamInstrumentation::m_trig_sel
std::vector< long > * m_trig_sel
Definition: CBNTAA_BeamInstrumentation.h:52
CBNTAA_BeamInstrumentation::m_containerKey4
std::string m_containerKey4
Definition: CBNTAA_BeamInstrumentation.h:33
CBNTAA_BeamInstrumentation::m_scint_adc
std::vector< float > * m_scint_adc
Definition: CBNTAA_BeamInstrumentation.h:39
TBTriggerPatternUnit::getTriggerWord
unsigned int getTriggerWord() const
Definition: TBTriggerPatternUnit.h:50
TBTriggerPatternUnit.h
CBNTAA_BeamInstrumentation::m_bpc_names
std::vector< std::string > m_bpc_names
Definition: CBNTAA_BeamInstrumentation.h:36
CBNTAA_BeamInstrumentation::~CBNTAA_BeamInstrumentation
virtual ~CBNTAA_BeamInstrumentation()
Definition: CBNTAA_BeamInstrumentation.cxx:45
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
LArCellBinning_test.retval
def retval
Definition: LArCellBinning_test.py:112
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
CBNTAA_BeamInstrumentation::m_scint_ntnames
std::vector< std::string > * m_scint_ntnames
Definition: CBNTAA_BeamInstrumentation.h:38
lumiFormat.i
int i
Definition: lumiFormat.py:92
CBNTAA_BeamInstrumentation::CBNT_execute
virtual StatusCode CBNT_execute() override
Definition: CBNTAA_BeamInstrumentation.cxx:122
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_BeamInstrumentation::m_bpc_left
std::vector< float > * m_bpc_left
Definition: CBNTAA_BeamInstrumentation.h:45
CBNTAA_BeamInstrumentation::m_scint_tdc
std::vector< float > * m_scint_tdc
Definition: CBNTAA_BeamInstrumentation.h:39
TBBPCRawCont.h
CBNTAA_BeamInstrumentation::m_containerKey5
std::string m_containerKey5
Definition: CBNTAA_BeamInstrumentation.h:34
CBNTAA_BeamInstrumentation::m_neverReturnFailure
bool m_neverReturnFailure
Definition: CBNTAA_BeamInstrumentation.h:28
CBNTAA_BeamInstrumentation::CBNT_clear
virtual StatusCode CBNT_clear() override
Definition: CBNTAA_BeamInstrumentation.cxx:280
CBNTAA_BeamInstrumentation::CBNTAA_BeamInstrumentation
CBNTAA_BeamInstrumentation(const std::string &name, ISvcLocator *pSvcLocator)
Definition: CBNTAA_BeamInstrumentation.cxx:14
CBNTAA_BeamInstrumentation::m_bpc_adc_ver
std::vector< float > * m_bpc_adc_ver
Definition: CBNTAA_BeamInstrumentation.h:45
CBNTAA_BeamInstrumentation::m_containerKey2
std::string m_containerKey2
Definition: CBNTAA_BeamInstrumentation.h:31
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TBBPCCont.h
CBNTAA_BeamInstrumentation::m_bpc_raw
bool m_bpc_raw
Definition: CBNTAA_BeamInstrumentation.h:44
CBNTAA_BeamInstrumentation::m_containerKey1
std::string m_containerKey1
Definition: CBNTAA_BeamInstrumentation.h:30
TBPhase
Definition: TBPhase.h:22
CBNTAA_BeamInstrumentation::m_clock
float m_clock
Definition: CBNTAA_BeamInstrumentation.h:41
CBNTAA_BeamInstrumentation::m_bpc_y
std::vector< float > * m_bpc_y
Definition: CBNTAA_BeamInstrumentation.h:39
CBNTAA_BeamInstrumentation::CBNT_initialize
virtual StatusCode CBNT_initialize() override
Definition: CBNTAA_BeamInstrumentation.cxx:71
CBNTAA_BeamInstrumentation::m_scint_names
std::vector< std::string > m_scint_names
Definition: CBNTAA_BeamInstrumentation.h:35
CBNTAA_BeamInstrumentation.h
TBPhase.h
TBScintillator
Definition: TBScintillator.h:25
CBNTAA_BeamInstrumentation::m_trig_array
bool m_trig_array
Definition: CBNTAA_BeamInstrumentation.h:48
TBTriggerPatternUnit
Definition: TBTriggerPatternUnit.h:27
CBNTAA_BeamInstrumentation::m_containerKey3
std::string m_containerKey3
Definition: CBNTAA_BeamInstrumentation.h:32
CBNTAA_BeamInstrumentation::CBNT_finalize
virtual StatusCode CBNT_finalize() override
Definition: CBNTAA_BeamInstrumentation.cxx:308
CBNTAA_BeamInstrumentation::m_bpc_right
std::vector< float > * m_bpc_right
Definition: CBNTAA_BeamInstrumentation.h:45
TBBPCRawCont
Definition: TBBPCRawCont.h:17
TBBPCCont
Definition: TBBPCCont.h:17