ATLAS Offline Software
Loading...
Searching...
No Matches
LArDigits2Ntuple.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
9
10LArDigits2Ntuple::LArDigits2Ntuple(const std::string& name, ISvcLocator* pSvcLocator):
11 LArCond2NtupleBase(name, pSvcLocator),
12 m_ipass(0),
13 m_event(0)
14{
15 m_ntTitle = "LArDigits";
16 m_ntpath = "/NTUPLES/FILE1/LARDIGITS";
17}
18
20= default;
21
22
24{
25 ATH_MSG_DEBUG( "in initialize" );
26
27 ATH_MSG_DEBUG(" IS it SC?? " << m_isSC );
28
29 if( (m_contKey.key().size()) && (m_accContKey.key().size() || m_accCalibContKey.key().size()) ){
30 ATH_MSG_FATAL("Could not run with both standard and acc. digits !!!");
31 ATH_MSG_FATAL("m_contKey: "<<m_contKey.key()<<" m_accContKey: "<<m_accContKey.key()<<" m_accCalibContKey: "<<m_accCalibContKey.key());
32 return StatusCode::FAILURE;
33 }
34
36
37 StatusCode sc = m_nt->addItem("IEvent",m_IEvent);
38 if (sc!=StatusCode::SUCCESS) {
39 ATH_MSG_ERROR( "addItem 'IEvent' failed" );
40 return sc;
41 }
42
43 if(m_accContKey.key().size() || m_accCalibContKey.key().size()) {
44 sc = m_nt->addItem("mean",m_Nsamples,m_mean);
45 if (sc!=StatusCode::SUCCESS) {
46 ATH_MSG_ERROR( "addItem 'mean' failed" );
47 return sc;
48 }
49 sc = m_nt->addItem("RMS",m_Nsamples,m_RMS);
50 if (sc!=StatusCode::SUCCESS) {
51 ATH_MSG_ERROR( "addItem 'RMS' failed" );
52 return sc;
53 }
54 if(m_accCalibContKey.key().size()) {
55 sc = m_nt->addItem("DAC",m_dac);
56 if (sc!=StatusCode::SUCCESS) {
57 ATH_MSG_ERROR( "addItem 'DAC' failed" );
58 return sc;
59 }
60 sc = m_nt->addItem("delay",m_delay);
61 if (sc!=StatusCode::SUCCESS) {
62 ATH_MSG_ERROR( "addItem 'delay' failed" );
63 return sc;
64 }
65 sc = m_nt->addItem("Pulsed",m_pulsed);
66 if (sc!=StatusCode::SUCCESS) {
67 ATH_MSG_ERROR( "addItem 'Pulsed' failed" );
68 return sc;
69 }
70 }
71 }
72
73 if(m_contKey.key().size()) {
74 sc = m_nt->addItem("samples",m_Nsamples,m_samples);
75 if (sc!=StatusCode::SUCCESS) {
76 ATH_MSG_ERROR( "addItem 'samples' failed" );
77 return sc;
78 }
79 }
80
81 sc = m_nt->addItem("Nsamples",m_ntNsamples,0,32);
82 if (sc!=StatusCode::SUCCESS) {
83 ATH_MSG_ERROR( "addItem 'Nsamples' failed" );
84 return sc;
85 }
86
87 if(m_fillBCID){
88 sc = m_nt->addItem("BCID",m_bcid);
89 if (sc!=StatusCode::SUCCESS) {
90 ATH_MSG_ERROR( "addItem 'BCID' failed" );
91 return sc;
92 }
93 }
94
95 sc = m_nt->addItem("ELVL1Id",m_ELVL1Id);
96 if (sc!=StatusCode::SUCCESS) {
97 ATH_MSG_ERROR( "addItem 'ELVL1Id' failed" );
98 return sc;
99 }
100
101 if(!m_isSC){
102 sc = m_nt->addItem("Gain",m_gain,-1,3);
103 if (sc!=StatusCode::SUCCESS) {
104 ATH_MSG_ERROR( "addItem 'Gain' failed" );
105 return sc;
106 }
107 }
108
109 if(m_fillLB){
110 NTuplePtr nt(ntupleSvc(),m_ntpath+"Evnt");
111 if (!nt) {
112 nt=ntupleSvc()->book(m_ntpath+"Evnt",CLID_ColumnWiseTuple,m_ntTitle+"Evnt");
113 }
114 if (!nt){
115 ATH_MSG_ERROR( "Booking of NTuple at "<< m_ntpath << " and name " << m_ntTitle << " failed" );
116 return StatusCode::FAILURE;
117 }
118
119 m_evt_nt=nt;
120
121 sc = m_evt_nt->addItem("IEvent",m_IEventEvt);
122 if (sc!=StatusCode::SUCCESS) {
123 ATH_MSG_ERROR( "addItem 'IEvent' failed" );
124 return sc;
125 }
126
127 sc=m_evt_nt->addItem("LB",m_LB);
128 if (sc.isFailure()) {
129 ATH_MSG_ERROR( "addItem 'LB' failed" );
130 return sc;
131 }
132 }
133 ATH_CHECK(m_contKey.initialize(m_contKey.key().size()) );
134 ATH_CHECK(m_accContKey.initialize(m_accContKey.key().size()) );
135 ATH_CHECK(m_accCalibContKey.initialize(m_accCalibContKey.key().size()) );
137
138 m_ipass = 0;
139 m_event = 0;
140
141 return StatusCode::SUCCESS;
142
143}
144
146{
147
148 const EventContext& ctx = Gaudi::Hive::currentContext();
149 if(!m_contKey.key().size() && !m_accContKey.key().size() && !m_accCalibContKey.key().size()) return StatusCode::SUCCESS;
150
151 StatusCode sc;
152
153 ATH_MSG_DEBUG( "LArDigits2Ntuple in execute" );
154 m_event++;
155 unsigned long long thisevent;
156 unsigned long thisbcid = 0;
157 unsigned long thisELVL1Id = 0;
158
159 thisevent = ctx.eventID().event_number();
160
161 // Get BCID from FEB header
162 if ( !m_isSC ){ // we are not processing SC data, Feb header could be accessed
164 if (! hdrCont.isValid()) {
165 ATH_MSG_WARNING( "No LArFEB container found in TDS" );
166 }
167 else {
168 ATH_MSG_DEBUG( "LArFEB container found");
169 if(m_fillBCID) thisbcid = (*hdrCont->begin())->BCId() ;
170 ATH_MSG_DEBUG( "BCID FROM FEB HEADER " << thisbcid );
171 thisELVL1Id = (*hdrCont->begin())->ELVL1Id();
172 ATH_MSG_DEBUG( "NSAMPLES FROM FEB HEADER " << (*hdrCont->begin())->NbSamples() );
173 }
174 }else{
175 // This should be used for main readout later, once TDAQ fill event headers also in calib. runs properly
176 thisbcid = ctx.eventID().bunch_crossing_id();
177 }
178
179 if( m_contKey.key().size() ) { // fill from standard digits
181 if(!hdlDigit.isValid()) {
182 ATH_MSG_WARNING( "Unable to retrieve LArDigitContainer with key " << m_contKey << " from DetectorStore. " );
183 return StatusCode::SUCCESS;
184 } else
185 ATH_MSG_DEBUG( "Got LArDigitContainer with key " << m_contKey.key() );
186
187 const LArDigitContainer DigitContainer = *hdlDigit;
188
189 if(!hdlDigit.cptr()) {
190 ATH_MSG_WARNING( "No digits in this event ?");
191 return StatusCode::SUCCESS;
192 }
193
194 for( const LArDigit *digi : DigitContainer ){
195
196 if(m_fillBCID) m_bcid = thisbcid;
197 m_ELVL1Id = thisELVL1Id;
198 m_IEvent = thisevent;
199
200 unsigned int trueMaxSample = digi->nsamples();
201
202 if (!m_isSC){
203 m_gain = digi->gain();
205 }
206 if(trueMaxSample>m_Nsamples){
207 if(!m_ipass){
208 ATH_MSG_WARNING( "The number of digi samples in data is larger than the one specified by JO: " << trueMaxSample << " > " << m_Nsamples << " --> only " << m_Nsamples << " will be available in the ntuple " );
209 m_ipass = 1;
210 }
211 trueMaxSample = m_Nsamples;
212 }
213 else if(trueMaxSample<m_Nsamples){
214 if(!m_ipass){
215 ATH_MSG_WARNING( "The number of digi samples in data is lower than the one specified by JO: " << trueMaxSample << " > " << m_Nsamples << " --> only " << trueMaxSample << " will be available in the ntuple " );
216 m_ipass = 1;
217 }
218 }
219 m_ntNsamples = trueMaxSample;
220 ATH_MSG_DEBUG( "The number of digi samples in data "<< m_Nsamples );
221
222 fillFromIdentifier(digi->hardwareID());
223
224 if(m_isSC && m_fillEMB && m_barrel_ec !=0) continue;
225 if(m_isSC && m_fillEndcap && m_barrel_ec !=1) continue;
226
227 if(m_FTlist.size() > 0) { // should do a selection
228 if(std::find(std::begin(m_FTlist), std::end(m_FTlist), m_FT) == std::end(m_FTlist)) { // is our FT in list ?
229 continue;
230 }
231 }
232
233 if(m_Slotlist.size() > 0) { // should do a selection
234 if(std::find(std::begin(m_Slotlist), std::end(m_Slotlist), m_slot) == std::end(m_Slotlist)) { // is our slot in list ?
235 continue;
236 }
237 }
238
239 if(m_Sidelist.size() > 0) { // should do a selection
240 if(std::find(std::begin(m_Sidelist), std::end(m_Sidelist), m_pos_neg) == std::end(m_Sidelist)) { // is our side in list ?
241 continue;
242 }
243 }
244
245 if(m_BElist.size() > 0) { // should do a selection
246 if(std::find(std::begin(m_BElist), std::end(m_BElist), m_barrel_ec) == std::end(m_BElist)) { // is our BE in list ?
247 continue;
248 }
249 }
250
251 for(unsigned i = 0; i<trueMaxSample;++i) m_samples[i] = digi->samples().at(i);
252
253
254 ATH_CHECK( ntupleSvc()->writeRecord(m_nt) );
255 }// over cells
256 }// standard digits
257
258 if( m_accCalibContKey.key().size() ) { // fill from acc. calib digits
260 if(!hdlDigit.isValid()) {
261 ATH_MSG_WARNING( "Unable to retrieve LArAccumulatedCalibDigitContainer with key " << m_accCalibContKey << " from DetectorStore. " );
262 return StatusCode::SUCCESS;
263 } else
264 ATH_MSG_DEBUG( "Got LArAccumulatedCalibDigitContainer with key " << m_accCalibContKey.key() );
265
266 const LArAccumulatedCalibDigitContainer DigitContainer = *hdlDigit;
267
268 if(!hdlDigit.cptr()) {
269 ATH_MSG_WARNING( "No digits in this event ?");
270 return StatusCode::SUCCESS;
271 }
272
273 for( const LArAccumulatedCalibDigit *digi : DigitContainer ){
274
275 if(m_fillBCID) m_bcid = thisbcid;
276 m_ELVL1Id = thisELVL1Id;
277 m_IEvent = thisevent;
278
279 unsigned int trueMaxSample = digi->nsamples();
280
281 if (!m_isSC){
282 m_gain = digi->gain();
284 }
285 if(trueMaxSample>m_Nsamples){
286 if(!m_ipass){
287 ATH_MSG_WARNING( "The number of digi samples in data is larger than the one specified by JO: " << trueMaxSample << " > " << m_Nsamples << " --> only " << m_Nsamples << " will be available in the ntuple " );
288 m_ipass = 1;
289 }
290 trueMaxSample = m_Nsamples;
291 }
292 else if(trueMaxSample<m_Nsamples){
293 if(!m_ipass){
294 ATH_MSG_WARNING( "The number of digi samples in data is lower than the one specified by JO: " << trueMaxSample << " > " << m_Nsamples << " --> only " << trueMaxSample << " will be available in the ntuple " );
295 m_ipass = 1;
296 }
297 }
298 m_ntNsamples = trueMaxSample;
299 ATH_MSG_DEBUG( "The number of acc. calib digi samples in data "<< m_Nsamples );
300
301 fillFromIdentifier(digi->hardwareID());
302
303 if(m_isSC && m_fillEMB && m_barrel_ec !=0) continue;
304 if(m_isSC && m_fillEndcap && m_barrel_ec !=1) continue;
305
306 if(m_FTlist.size() > 0) { // should do a selection
307 if(std::find(std::begin(m_FTlist), std::end(m_FTlist), m_FT) == std::end(m_FTlist)) { // is our FT in list ?
308 continue;
309 }
310 }
311
312 if(m_Slotlist.size() > 0) { // should do a selection
313 if(std::find(std::begin(m_Slotlist), std::end(m_Slotlist), m_slot) == std::end(m_Slotlist)) { // is our slot in list ?
314 continue;
315 }
316 }
317 for(unsigned i = 0; i<trueMaxSample;++i) {
318 m_mean[i] = digi->mean(i);
319 m_RMS[i] = digi->RMS(i);
320 }
321 //m_nTriggers = digi->nTriggers();
322 m_dac = digi->DAC();
323 m_delay = digi->delay();
324 m_pulsed = digi->getIsPulsedInt();
325
326
327 ATH_CHECK( ntupleSvc()->writeRecord(m_nt) );
328 }// over cells
329 }// acc calib. digits
330
331 if( m_accContKey.key().size() ) { // fill from acc digits
333 if(!hdlDigit.isValid()) {
334 ATH_MSG_WARNING( "Unable to retrieve LArAccumulatedDigitContainer with key " << m_accContKey << " from DetectorStore. " );
335 return StatusCode::SUCCESS;
336 } else
337 ATH_MSG_DEBUG( "Got LArAccumulatedDigitContainer with key " << m_accContKey.key() );
338
339 const LArAccumulatedDigitContainer DigitContainer = *hdlDigit;
340
341 if(!hdlDigit.cptr()) {
342 ATH_MSG_WARNING( "No digits in this event ?");
343 return StatusCode::SUCCESS;
344 }
345
346 for( const LArAccumulatedDigit *digi : DigitContainer ){
347
348 if(m_fillBCID) m_bcid = thisbcid;
349 m_ELVL1Id = thisELVL1Id;
350 m_IEvent = thisevent;
351
352 unsigned int trueMaxSample = digi->nsample();
353
354 if (!m_isSC){
355 m_gain = digi->gain();
357 }
358
359 if(trueMaxSample>m_Nsamples){
360 if(!m_ipass){
361 ATH_MSG_WARNING( "The number of digi samples in data is larger than the one specified by JO: " << trueMaxSample << " > " << m_Nsamples << " --> only " << m_Nsamples << " will be available in the ntuple " );
362 m_ipass = 1;
363 }
364 trueMaxSample = m_Nsamples;
365 } else if(trueMaxSample<m_Nsamples){
366 if(!m_ipass){
367 ATH_MSG_WARNING( "The number of digi samples in data is lower than the one specified by JO: " << trueMaxSample << " > " << m_Nsamples << " --> only " << trueMaxSample << " will be available in the ntuple " );
368 m_ipass = 1;
369 }
370 }
371 m_ntNsamples = trueMaxSample;
372 ATH_MSG_DEBUG( "The number of acc. digi samples in data "<< m_Nsamples );
373
374 fillFromIdentifier(digi->hardwareID());
375
376 if(m_isSC && m_fillEMB && m_barrel_ec !=0) continue;
377 if(m_isSC && m_fillEndcap && m_barrel_ec !=1) continue;
378
379 if(m_FTlist.size() > 0) { // should do a selection
380 if(std::find(std::begin(m_FTlist), std::end(m_FTlist), m_FT) == std::end(m_FTlist)) { // is our FT in list ?
381 continue;
382 }
383 }
384
385 if(m_Slotlist.size() > 0) { // should do a selection
386 if(std::find(std::begin(m_Slotlist), std::end(m_Slotlist), m_slot) == std::end(m_Slotlist)) { // is our slot in list ?
387 continue;
388 }
389 }
390 for(unsigned i = 0; i<trueMaxSample;++i) {
391 m_mean[i] = digi->mean(i);
392 m_RMS[i] = digi->RMS(i);
393 }
394
395 ATH_CHECK( ntupleSvc()->writeRecord(m_nt) );
396 }// over cells
397 }// acc digits
398
399 if(m_fillLB) {
400 m_IEventEvt = thisevent;
401 m_LB = ctx.eventID().lumi_block();
402
403 sc = ntupleSvc()->writeRecord(m_evt_nt);
404 if (sc != StatusCode::SUCCESS) {
405 ATH_MSG_ERROR( "writeRecord failed" );
406 return sc;
407 }
408 }
409
410 ATH_MSG_DEBUG( "LArDigits2Ntuple has finished." );
411 return StatusCode::SUCCESS;
412}// end finalize-method.
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static Double_t sc
INTupleSvc * ntupleSvc()
Container class for LArAccumulatedCalibDigit.
Data class for calibration ADC samples preprocessed by the DSP.
Container class for LArAccumulatedDigit.
Data class for ADC samples and autocorr preprocessed by the DSP.
Gaudi::Property< bool > m_isSC
NTuple::Item< long > m_barrel_ec
NTuple::Item< long > m_FT
NTuple::Item< long > m_slot
NTuple::Item< long > m_pos_neg
bool fillFromIdentifier(const HWIdentifier &id)
LArCond2NtupleBase(const std::string &name, ISvcLocator *pSvcLocator)
Container class for LArDigit.
Liquid Argon digit base class.
Definition LArDigit.h:25
NTuple::Array< short > m_samples
Gaudi::Property< bool > m_fillLB
Gaudi::Property< bool > m_fillBCID
NTuple::Item< unsigned int > m_delay
SG::ReadHandleKey< LArDigitContainer > m_contKey
NTuple::Array< float > m_RMS
NTuple::Item< short > m_LB
Gaudi::Property< std::vector< unsigned int > > m_BElist
LArDigits2Ntuple(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< std::vector< unsigned int > > m_Slotlist
NTuple::Array< float > m_mean
Gaudi::Property< std::vector< unsigned int > > m_Sidelist
Gaudi::Property< std::vector< unsigned int > > m_FTlist
SG::ReadHandleKey< LArFebHeaderContainer > m_LArFebHeaderContainerKey
Gaudi::Property< unsigned int > m_Nsamples
NTuple::Item< long > m_ntNsamples
Gaudi::Property< bool > m_fillEMB
NTuple::Item< short > m_bcid
virtual StatusCode execute()
NTuple::Item< unsigned long long > m_IEvent
SG::ReadHandleKey< LArAccumulatedDigitContainer > m_accContKey
NTuple::Item< unsigned long > m_ELVL1Id
virtual StatusCode initialize()
NTuple::Item< unsigned int > m_pulsed
Gaudi::Property< bool > m_fillEndcap
NTuple::Tuple * m_evt_nt
SG::ReadHandleKey< LArAccumulatedCalibDigitContainer > m_accCalibContKey
NTuple::Item< short > m_gain
NTuple::Item< unsigned long long > m_IEventEvt
NTuple::Item< unsigned int > m_dac
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
@ LARNGAIN
Definition CaloGain.h:19