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
145StatusCode LArDigits2Ntuple::execute(const EventContext& ctx)
146{
147
148 if(!m_contKey.key().size() && !m_accContKey.key().size() && !m_accCalibContKey.key().size()) return StatusCode::SUCCESS;
149
150 StatusCode sc;
151
152 ATH_MSG_DEBUG( "LArDigits2Ntuple in execute" );
153 m_event++;
154 unsigned long long thisevent;
155 unsigned long thisbcid = 0;
156 unsigned long thisELVL1Id = 0;
157
158 thisevent = ctx.eventID().event_number();
159
160 // Get BCID from FEB header
161 if ( !m_isSC ){ // we are not processing SC data, Feb header could be accessed
163 if (! hdrCont.isValid()) {
164 ATH_MSG_WARNING( "No LArFEB container found in TDS" );
165 }
166 else {
167 ATH_MSG_DEBUG( "LArFEB container found");
168 if(m_fillBCID) thisbcid = (*hdrCont->begin())->BCId() ;
169 ATH_MSG_DEBUG( "BCID FROM FEB HEADER " << thisbcid );
170 thisELVL1Id = (*hdrCont->begin())->ELVL1Id();
171 ATH_MSG_DEBUG( "NSAMPLES FROM FEB HEADER " << (*hdrCont->begin())->NbSamples() );
172 }
173 }else{
174 // This should be used for main readout later, once TDAQ fill event headers also in calib. runs properly
175 thisbcid = ctx.eventID().bunch_crossing_id();
176 }
177
178 if( m_contKey.key().size() ) { // fill from standard digits
180 if(!hdlDigit.isValid()) {
181 ATH_MSG_WARNING( "Unable to retrieve LArDigitContainer with key " << m_contKey << " from DetectorStore. " );
182 return StatusCode::SUCCESS;
183 } else
184 ATH_MSG_DEBUG( "Got LArDigitContainer with key " << m_contKey.key() );
185
186 const LArDigitContainer DigitContainer = *hdlDigit;
187
188 if(!hdlDigit.cptr()) {
189 ATH_MSG_WARNING( "No digits in this event ?");
190 return StatusCode::SUCCESS;
191 }
192
193 for( const LArDigit *digi : DigitContainer ){
194
195 if(m_fillBCID) m_bcid = thisbcid;
196 m_ELVL1Id = thisELVL1Id;
197 m_IEvent = thisevent;
198
199 unsigned int trueMaxSample = digi->nsamples();
200
201 if (!m_isSC){
202 m_gain = digi->gain();
204 }
205 if(trueMaxSample>m_Nsamples){
206 if(!m_ipass){
207 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 " );
208 m_ipass = 1;
209 }
210 trueMaxSample = m_Nsamples;
211 }
212 else if(trueMaxSample<m_Nsamples){
213 if(!m_ipass){
214 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 " );
215 m_ipass = 1;
216 }
217 }
218 m_ntNsamples = trueMaxSample;
219 ATH_MSG_DEBUG( "The number of digi samples in data "<< m_Nsamples );
220
221 fillFromIdentifier(digi->hardwareID());
222
223 if(m_isSC && m_fillEMB && m_barrel_ec !=0) continue;
224 if(m_isSC && m_fillEndcap && m_barrel_ec !=1) continue;
225
226 if(m_FTlist.size() > 0) { // should do a selection
227 if(std::find(std::begin(m_FTlist), std::end(m_FTlist), m_FT) == std::end(m_FTlist)) { // is our FT in list ?
228 continue;
229 }
230 }
231
232 if(m_Slotlist.size() > 0) { // should do a selection
233 if(std::find(std::begin(m_Slotlist), std::end(m_Slotlist), m_slot) == std::end(m_Slotlist)) { // is our slot in list ?
234 continue;
235 }
236 }
237
238 if(m_Sidelist.size() > 0) { // should do a selection
239 if(std::find(std::begin(m_Sidelist), std::end(m_Sidelist), m_pos_neg) == std::end(m_Sidelist)) { // is our side in list ?
240 continue;
241 }
242 }
243
244 if(m_BElist.size() > 0) { // should do a selection
245 if(std::find(std::begin(m_BElist), std::end(m_BElist), m_barrel_ec) == std::end(m_BElist)) { // is our BE in list ?
246 continue;
247 }
248 }
249
250 for(unsigned i = 0; i<trueMaxSample;++i) m_samples[i] = digi->samples().at(i);
251
252
253 ATH_CHECK( ntupleSvc()->writeRecord(m_nt) );
254 }// over cells
255 }// standard digits
256
257 if( m_accCalibContKey.key().size() ) { // fill from acc. calib digits
259 if(!hdlDigit.isValid()) {
260 ATH_MSG_WARNING( "Unable to retrieve LArAccumulatedCalibDigitContainer with key " << m_accCalibContKey << " from DetectorStore. " );
261 return StatusCode::SUCCESS;
262 } else
263 ATH_MSG_DEBUG( "Got LArAccumulatedCalibDigitContainer with key " << m_accCalibContKey.key() );
264
265 const LArAccumulatedCalibDigitContainer DigitContainer = *hdlDigit;
266
267 if(!hdlDigit.cptr()) {
268 ATH_MSG_WARNING( "No digits in this event ?");
269 return StatusCode::SUCCESS;
270 }
271
272 for( const LArAccumulatedCalibDigit *digi : DigitContainer ){
273
274 if(m_fillBCID) m_bcid = thisbcid;
275 m_ELVL1Id = thisELVL1Id;
276 m_IEvent = thisevent;
277
278 unsigned int trueMaxSample = digi->nsamples();
279
280 if (!m_isSC){
281 m_gain = digi->gain();
283 }
284 if(trueMaxSample>m_Nsamples){
285 if(!m_ipass){
286 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 " );
287 m_ipass = 1;
288 }
289 trueMaxSample = m_Nsamples;
290 }
291 else if(trueMaxSample<m_Nsamples){
292 if(!m_ipass){
293 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 " );
294 m_ipass = 1;
295 }
296 }
297 m_ntNsamples = trueMaxSample;
298 ATH_MSG_DEBUG( "The number of acc. calib digi samples in data "<< m_Nsamples );
299
300 fillFromIdentifier(digi->hardwareID());
301
302 if(m_isSC && m_fillEMB && m_barrel_ec !=0) continue;
303 if(m_isSC && m_fillEndcap && m_barrel_ec !=1) continue;
304
305 if(m_FTlist.size() > 0) { // should do a selection
306 if(std::find(std::begin(m_FTlist), std::end(m_FTlist), m_FT) == std::end(m_FTlist)) { // is our FT in list ?
307 continue;
308 }
309 }
310
311 if(m_Slotlist.size() > 0) { // should do a selection
312 if(std::find(std::begin(m_Slotlist), std::end(m_Slotlist), m_slot) == std::end(m_Slotlist)) { // is our slot in list ?
313 continue;
314 }
315 }
316 for(unsigned i = 0; i<trueMaxSample;++i) {
317 m_mean[i] = digi->mean(i);
318 m_RMS[i] = digi->RMS(i);
319 }
320 //m_nTriggers = digi->nTriggers();
321 m_dac = digi->DAC();
322 m_delay = digi->delay();
323 m_pulsed = digi->getIsPulsedInt();
324
325
326 ATH_CHECK( ntupleSvc()->writeRecord(m_nt) );
327 }// over cells
328 }// acc calib. digits
329
330 if( m_accContKey.key().size() ) { // fill from acc digits
332 if(!hdlDigit.isValid()) {
333 ATH_MSG_WARNING( "Unable to retrieve LArAccumulatedDigitContainer with key " << m_accContKey << " from DetectorStore. " );
334 return StatusCode::SUCCESS;
335 } else
336 ATH_MSG_DEBUG( "Got LArAccumulatedDigitContainer with key " << m_accContKey.key() << " size: " << hdlDigit->size());
337
338 const LArAccumulatedDigitContainer DigitContainer = *hdlDigit;
339
340 if(!hdlDigit.cptr()) {
341 ATH_MSG_WARNING( "No digits in this event ?");
342 return StatusCode::SUCCESS;
343 }
344
345 for( const LArAccumulatedDigit *digi : DigitContainer ){
346
347 if(m_fillBCID) m_bcid = thisbcid;
348 m_ELVL1Id = thisELVL1Id;
349 m_IEvent = thisevent;
350
351 unsigned int trueMaxSample = digi->nsample();
352
353 if (!m_isSC){
354 m_gain = digi->gain();
356 }
357
358 if(trueMaxSample>m_Nsamples){
359 if(!m_ipass){
360 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 " );
361 m_ipass = 1;
362 }
363 trueMaxSample = m_Nsamples;
364 } else if(trueMaxSample<m_Nsamples){
365 if(!m_ipass){
366 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 " );
367 m_ipass = 1;
368 }
369 }
370 m_ntNsamples = trueMaxSample;
371 ATH_MSG_DEBUG( "The number of acc. digi samples in data "<< m_Nsamples );
372
373 fillFromIdentifier(digi->hardwareID());
374
375 if(m_isSC && m_fillEMB && m_barrel_ec !=0) continue;
376 if(m_isSC && m_fillEndcap && m_barrel_ec !=1) continue;
377
378 if(m_FTlist.size() > 0) { // should do a selection
379 if(std::find(std::begin(m_FTlist), std::end(m_FTlist), m_FT) == std::end(m_FTlist)) { // is our FT in list ?
380 continue;
381 }
382 }
383
384 if(m_Slotlist.size() > 0) { // should do a selection
385 if(std::find(std::begin(m_Slotlist), std::end(m_Slotlist), m_slot) == std::end(m_Slotlist)) { // is our slot in list ?
386 continue;
387 }
388 }
389 for(unsigned i = 0; i<trueMaxSample;++i) {
390 m_mean[i] = digi->mean(i);
391 m_RMS[i] = digi->RMS(i);
392 }
393
394 ATH_CHECK( ntupleSvc()->writeRecord(m_nt) );
395 }// over cells
396 }// acc digits
397
398 if(m_fillLB) {
399 m_IEventEvt = thisevent;
400 m_LB = ctx.eventID().lumi_block();
401
402 sc = ntupleSvc()->writeRecord(m_evt_nt);
403 if (sc != StatusCode::SUCCESS) {
404 ATH_MSG_ERROR( "writeRecord failed" );
405 return sc;
406 }
407 }
408
409 ATH_MSG_DEBUG( "LArDigits2Ntuple has finished." );
410 return StatusCode::SUCCESS;
411}// 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
virtual StatusCode execute(const EventContext &ctx)
Execute method.
NTuple::Item< short > m_bcid
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