ATLAS Offline Software
Loading...
Searching...
No Matches
LArSC2Ntuple.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
12
13#include <numeric>
14
15LArSC2Ntuple::LArSC2Ntuple(const std::string& name, ISvcLocator* pSvcLocator):
16 LArDigits2Ntuple(name, pSvcLocator), m_caloMgrSC(nullptr) {
17 m_ntTitle = "SCDigits";
18 m_ntpath = "/NTUPLES/FILE1/SCDIGITS";
19 }
20
22
23 ATH_MSG_DEBUG( "LArSC2Ntuple in initialize" );
24
25 m_isSC = true;
26 if(m_fillTType && (! m_fillLB)) m_fillLB = true;
27 if(m_fillCaloTT && (! m_fillLB)) m_fillLB = true;
28
30 ATH_CHECK( m_scidtool.retrieve() );
31
33 ATH_CHECK( m_eventInfoKey.initialize() );
34 ATH_CHECK( m_eventInfoDecorKey.initialize() );
35
37
38 ATH_CHECK( m_caloSCMgrKey.initialize(m_ETThresh > 0. || m_ETThreshMain > 0.) );
39
40 StatusCode sc=m_nt->addItem("latomeChannel",m_latomeChannel);
41 if (sc.isFailure()) {
42 ATH_MSG_ERROR( "addItem 'latomeChannel' failed" );
43 return sc;
44 }
45
46 sc = m_nt->addItem("bcidVec",m_Nsamples, m_bcidVec);//here - > define length?
47 if (sc.isFailure()) {
48 ATH_MSG_ERROR( "addItem 'bcidVec' failed" );
49 return sc;
50 }
51 sc = m_nt->addItem("latomeSourceId",m_latomeSourceId);
52 if (sc.isFailure()) {
53 ATH_MSG_ERROR( "addItem 'latomeSourceId' failed" );
54 return sc;
55 }
56 sc = m_nt->addItem("Net",m_ntNet);
57 if (sc.isFailure()) {
58 ATH_MSG_ERROR( "addItem 'Net' failed" );
59 return sc;
60 }
61
62 // Loop over container keys
63 for ( const std::string &ck : m_contKeys ){
64 if ( ck.find("SC") == std::string::npos){ // main readout only
65 if ( m_fillRawChan && ck == "LArRawChannels" ){
66 sc = m_nt->addItem("ROD_energy", 16, m_ROD_energy);
67 if (sc.isFailure()) {
68 ATH_MSG_ERROR( "addItem 'ROD_energy' failed" );
69 return sc;
70 }
71 sc = m_nt->addItem("ROD_time", 16, m_ROD_time);
72 if (sc.isFailure()) {
73 ATH_MSG_ERROR( "addItem 'ROD_time' failed" );
74 return sc;
75 }
76 sc = m_nt->addItem("ROD_id", 16, m_ROD_id);
77 if (sc.isFailure()) {
78 ATH_MSG_ERROR( "addItem 'ROD_id' failed" );
79 return sc;
80 }
81 }
82
83 }else if ( ck == "SC_ADC_BAS" ){ // SC_ADC_BAS DigitContainer
84 sc = m_nt->addItem("samples_ADC_BAS",m_Nsamples,m_samples_ADC_BAS);
85 if (sc.isFailure()) {
86 ATH_MSG_ERROR( "addItem 'samples_ADC_BAS' failed" );
87 return sc;
88 }
89
90 sc = m_nt->addItem("bcidVec_ADC_BAS",m_Nsamples, m_bcidVec_ADC_BAS);//here - > define length?
91 if (sc.isFailure()) {
92 ATH_MSG_ERROR( "addItem 'bcidVec_ADC_BAS' failed" );
93 return sc;
94 }
95
96 }else if ( ck == "SC_ET" ){ // SC_ET RawSCContainer
97 sc = m_nt->addItem("energyVec_ET", m_Net, m_energyVec_ET);
98 if (sc.isFailure()) {
99 ATH_MSG_ERROR( "addItem 'energyVec_ET' failed" );
100 return sc;
101 }
102 sc = m_nt->addItem("bcidVec_ET", m_Net, m_bcidVec_ET);
103 if (sc.isFailure()) {
104 ATH_MSG_ERROR( "addItem 'bcidVec_ET' failed" );
105 return sc;
106 }
107 sc = m_nt->addItem("saturVec_ET", m_Net, m_saturVec_ET);
108 if (sc.isFailure()) {
109 ATH_MSG_ERROR( "addItem 'saturVec_ET' failed" );
110 return sc;
111 }
112
113 }else if ( ck == "SC_ET_ID" ){ // SC_ET_ID RawSCContainer
114
115 sc = m_nt->addItem("energyVec_ET_ID", m_Net, m_energyVec_ET_ID);
116 if (sc.isFailure()) {
117 ATH_MSG_ERROR( "addItem 'energyVec_ET_ID' failed" );
118 return sc;
119 }
120 sc = m_nt->addItem("bcidVec_ET_ID", m_Net, m_bcidVec_ET_ID);
121 if (sc.isFailure()) {
122 ATH_MSG_ERROR( "addItem 'bcidVec_ET_ID' failed" );
123 return sc;
124 }
125 sc = m_nt->addItem("saturVec_ET_ID", m_Net, m_saturVec_ET_ID);
126 if (sc.isFailure()) {
127 ATH_MSG_ERROR( "addItem 'saturVec_ET_ID' failed" );
128 return sc;
129 }
130 }
131
132 }// end container key loop
133
134 sc = m_nt->addItem("bcidLATOMEHEAD",m_bcidLATOMEHEAD);
135 if (sc.isFailure()) {
136 ATH_MSG_ERROR( "addItem 'bcidLATOMEHEAD' failed" );
137 return sc;
138 }
139
140 if(m_fillTType) {
141 sc = m_evt_nt->addItem("TType", m_TType);
142 if (sc.isFailure()) {
143 ATH_MSG_ERROR( "addItem 'TType' failed" );
144 return sc;
145 }
146
147 sc = m_evt_nt->addItem("LArEventBits", m_LArEventBits);
148 if (sc.isFailure()) {
149 ATH_MSG_ERROR( "addItem 'LArEventBits' failed" );
150 return sc;
151 }
152 sc = m_evt_nt->addItem("LArError", m_LArInError);
153 if (sc.isFailure()) {
154 ATH_MSG_ERROR( "addItem 'LArError' failed" );
155 return sc;
156 }
157 //Adding trigger decision bit branches
158 CHECK( m_trigDec.retrieve() );
159 for ( const std::string &tn : m_trigNames ){
160 sc = m_evt_nt->addItem(tn,m_trigNameMap[tn]);
161 if (sc.isFailure()) {
162 ATH_MSG_ERROR( "addItem '"+tn+"' failed" );
163 return sc;
164 }
165 }
166
167 }//m_fillTType
168
169 if(m_fillCaloTT) {
170 sc = m_evt_nt->addItem("NTT",m_ntNTT,0,20000);
171 if (sc.isFailure()) {
172 ATH_MSG_ERROR( "addItem 'Net' failed" );
173 return sc;
174 }
175 sc = m_evt_nt->addItem("TTeta", m_ntNTT, m_TTeta);
176 if (sc.isFailure()) {
177 ATH_MSG_ERROR( "addItem 'TTeta' failed" );
178 return sc;
179 }
180 sc = m_evt_nt->addItem("TTphi", m_ntNTT, m_TTphi);
181 if (sc.isFailure()) {
182 ATH_MSG_ERROR( "addItem 'TTphi' failed" );
183 return sc;
184 }
185 sc = m_evt_nt->addItem("TTEem", m_ntNTT, m_TTEem);
186 if (sc.isFailure()) {
187 ATH_MSG_ERROR( "addItem 'TTEem' failed" );
188 return sc;
189 }
190 sc = m_evt_nt->addItem("TTEhad", m_ntNTT, m_TTEhad);
191 if (sc.isFailure()) {
192 ATH_MSG_ERROR( "addItem 'TTEhad' failed" );
193 return sc;
194 }
195 } // end m_fillCaloTT
196
197 return StatusCode::SUCCESS;
198
199}
200
201StatusCode LArSC2Ntuple::execute(const EventContext& ctx)
202{
203
204 StatusCode sc;
205
206
208 ATH_CHECK(evt.isValid());
209
210 unsigned long long thisevent = evt->eventNumber();
211 unsigned short thislb = evt->lumiBlock();
212
213 // This should be used for main readout later, once TDAQ fill event headers also in calib. runs properly
214 unsigned long thisbcid = evt->bcid();
215 unsigned long thisELVL1Id = 0;
216 unsigned long thisttype = evt->level1TriggerType();
217 //
219 bool hasDigitContainer=true;
220 const LArDigitContainer *DigitContainer = nullptr;
221 if(!m_contKey.key().empty()) {
223 if(!hdlDigit.isValid()) {
224 ATH_MSG_WARNING( "Unable to retrieve LArDigitContainer with key " << m_contKey << " from DetectorStore. " );
225 hasDigitContainer=false;
226 } else {
227 ATH_MSG_DEBUG( "Got LArDigitContainer with key " << m_contKey.key() );
228 DigitContainer = hdlDigit.cptr();
229 }
230 } else hasDigitContainer=false;
231
232 bool hasAccCalibDigitContainer=true;
233 const LArAccumulatedCalibDigitContainer *AccCalibDigitContainer = nullptr;
234 if(!m_accCalibContKey.key().empty()) {
236 if(!hdlAccDigit.isValid()) {
237 ATH_MSG_WARNING( "Unable to retrieve LArAccumulatedCalibDigitContainer with key " << m_accCalibContKey << " from DetectorStore. " );
238 hasAccCalibDigitContainer=false;
239 } else {
240 ATH_MSG_DEBUG( "Got LArAccumulatedCalibDigitContainer with key " << m_accCalibContKey.key() );
241 AccCalibDigitContainer = hdlAccDigit.cptr();
242 }
243 } else hasAccCalibDigitContainer=false;
244
245 bool hasAccDigitContainer=true;
246 const LArAccumulatedDigitContainer *AccDigitContainer = nullptr;
247 if(!m_accContKey.key().empty()) {
249 if(!hdlAccDigit.isValid()) {
250 ATH_MSG_WARNING( "Unable to retrieve LArAccumulatedDigitContainer with key " << m_accContKey << " from DetectorStore. " );
251 hasAccDigitContainer=false;
252 } else {
253 ATH_MSG_DEBUG( "Got LArAccumulatedDigitContainer with key " << m_accContKey.key() );
254 AccDigitContainer = hdlAccDigit.cptr();
255 }
256 } else hasAccDigitContainer=false;
257
258 const LArDigitContainer* DigitContainer_next = nullptr;
259 const LArRawSCContainer* etcontainer = nullptr;
260 const LArRawSCContainer* etcontainer_next = nullptr;
261 const LArRawChannelContainer* RawChannelContainer = nullptr;
262 const LArLATOMEHeaderContainer*headcontainer = nullptr;
263 std::map<unsigned int, const LArLATOMEHeader*> LATOMEHeadMap;
264 rawChanMap_t rawChannelMap;
265
266 if ((std::find(m_contKeys.begin(), m_contKeys.end(), "LArRawChannels") != m_contKeys.end()) ){
267 sc = evtStore()->retrieve(RawChannelContainer,"LArRawChannels");
268 if (sc.isFailure()) {
269 ATH_MSG_WARNING( "Unable to retrieve LArRawChannelContainer with key LArRawChannels from DetectorStore. " );
270 }
271 else
272 ATH_MSG_DEBUG( "Got LArRawChannelContainer with key LArRawChannels" );
273 }
274
275 if(m_ETThreshMain > 0. && !RawChannelContainer) {
276 ATH_MSG_WARNING( "Asked for ETThresholdMain, but no LArRawChannelContainer, will not apply ! " );
277 m_ETThreshMain = -1.;
278 }
279
280 if ((std::find(m_contKeys.begin(), m_contKeys.end(), "SC_ADC_BAS") != m_contKeys.end()) ){
281 sc = evtStore()->retrieve(DigitContainer_next,"SC_ADC_BAS");
282 if (sc.isFailure()) {
283 ATH_MSG_WARNING( "Unable to retrieve LArDigitContainer with key SC_ADC_BAS from DetectorStore. " );
284 }
285 else
286 ATH_MSG_DEBUG( "Got additional LArDigitContainer with key SC_ADC_BAS " );
287 }
288
289 if ((std::find(m_contKeys.begin(), m_contKeys.end(), "SC_ET") != m_contKeys.end()) ){
290 sc = evtStore()->retrieve(etcontainer,"SC_ET");
291 if (sc.isFailure()) {
292 ATH_MSG_WARNING( "Unable to retrieve LArRawSCContainer with key SC_ET from DetectorStore. " );
293 }
294 else
295 ATH_MSG_DEBUG( "Got LArRawSCContainer with key SC_ET " );
296 }
297
298 if ((std::find(m_contKeys.begin(), m_contKeys.end(), "SC_ET_ID") != m_contKeys.end()) ){
299 sc = evtStore()->retrieve(etcontainer_next,"SC_ET_ID");
300 if (sc.isFailure()) {
301 ATH_MSG_WARNING( "Unable to retrieve LArRawSCContainer with key SC_ET_ID from DetectorStore. " );
302 }
303 else
304 ATH_MSG_DEBUG( "Got LArRawSCContainer with key SC_ET_ID" );
305 }
306
308 if (! hdrCont.isValid()) {
309 ATH_MSG_WARNING( "No LArLATOME container found in TDS" );
310 } else {
311 ATH_MSG_DEBUG( "LArLATOME container found");
312 headcontainer=&*hdrCont;
313 if(headcontainer != nullptr && *hdrCont->begin()) thisELVL1Id = (*hdrCont->begin())->L1Id();
314 ATH_MSG_DEBUG( " ELVL1I FROM LATOME HEADER " << thisELVL1Id );
315 }
316
317 if (headcontainer){// loop through header container and fill map
318 for (const LArLATOMEHeader* hit : *headcontainer) {
319 LATOMEHeadMap.try_emplace ( hit->SourceId(), hit );
320 }
321 }
322 if(m_fillRawChan && RawChannelContainer){
323 for (const LArRawChannel& raw : *RawChannelContainer) {
324 rawChannelMap.try_emplace( raw.channelID(), &raw );
325 }
326 }
327 const LArOnOffIdMapping* cabling=nullptr;
328 const LArOnOffIdMapping* cablingROD=nullptr;
329 if(m_fillRawChan){
331 cabling=*cablingHdl;
332 if(!cabling) {
333 ATH_MSG_ERROR( "Do not have cabling for SC!" );
334 return StatusCode::FAILURE;
335 }
337 cablingROD=*cablingHdlROD;
338 if(!cablingROD) {
339 ATH_MSG_ERROR( "Do not have cabling for ROD!" );
340 return StatusCode::FAILURE;
341 }
342 }
343
345 if( DigitContainer_next && DigitContainer_next->empty() ) DigitContainer_next = nullptr;
346
347 if( etcontainer && etcontainer->empty() ) etcontainer = nullptr;
348
349 if( etcontainer_next && etcontainer_next->empty() ) etcontainer_next = nullptr;
350
351 int cellsno = 0;
352 if (hasDigitContainer) {
353 if( !DigitContainer->empty() ) cellsno = DigitContainer->size();
354 else {
355 ATH_MSG_WARNING("DigitContainer has zero size, but asked, will be not filled... ");
356 return StatusCode::SUCCESS;
357 }
358 }
359 ATH_MSG_DEBUG("DigitContainer has size: "<<cellsno<<" hasDigitContainer: "<<hasDigitContainer);
360
361 if(m_ETThresh > 0. && !etcontainer && !etcontainer_next) {
362 ATH_MSG_WARNING( "Asked for ETThreshold, but no SC_ET* container, will not apply ! " );
363 m_ETThresh = -1.;
364 }
365
366 if(m_ETThresh > 0. || m_ETThreshMain > 0.) {
368 ATH_CHECK(caloMgrHandle.isValid());
369 m_caloMgrSC = *caloMgrHandle;
370 }
371
372 if(m_ADCThresh > 0. && ! DigitContainer&& !DigitContainer_next) {
373 ATH_MSG_WARNING( "Asked for ADCThreshold, but no digits container, will not apply ! " );
374 m_ADCThresh = -1.;
375 }
376
377 if (hasAccCalibDigitContainer) {
378 if( !AccCalibDigitContainer->empty() ) {
379 cellsno = AccCalibDigitContainer->size();
380 ATH_MSG_DEBUG("AccCalibDigitContainer has size: "<<cellsno<<" hasAccCalibDigitContainer: "<<hasAccCalibDigitContainer);
381 } else {
382 ATH_MSG_WARNING("AccCalibDigitContainer has zero size, but asked, will be not filled... ");
383 return StatusCode::SUCCESS;
384 }
385 }
386 if (hasAccDigitContainer) {
387 if( !AccDigitContainer->empty() ) {
388 cellsno = AccDigitContainer->size();
389 ATH_MSG_DEBUG("AccDigitContainer has size: "<<cellsno<<" hasAccDigitContainer: "<<hasAccDigitContainer);
390 } else {
391 ATH_MSG_WARNING("AccDigitContainer has zero size, but asked, will be not filled... ");
392 return StatusCode::SUCCESS;
393 }
394 }
395
396 if (DigitContainer_next){
397 if ( cellsno == 0 ){
398 cellsno = DigitContainer_next->size();
399 }else if(DigitContainer_next->size() != (unsigned)cellsno ){ ATH_MSG_WARNING(" NOOOOOOO! Different number of entries in DigitContainer_next"<< cellsno << " " << DigitContainer_next->size() );
400 return StatusCode::SUCCESS;
401 }
402 }
403 if (etcontainer){
404 if ( cellsno == 0 ){
405 cellsno = etcontainer->size();
406 }else if(etcontainer->size() != (unsigned)cellsno ){ ATH_MSG_WARNING(" NOOOOOOO! Different number of entries in etcontainer"<< cellsno << " " << etcontainer->size() );
407 return StatusCode::SUCCESS;
408 }
409 }
410 if (etcontainer_next){
411 if ( cellsno == 0 ){
412 cellsno = etcontainer_next->size();
413 }else if(etcontainer_next->size() != (unsigned)cellsno ){ ATH_MSG_WARNING(" NOOOOOOO! Different number of entries in etcontainer_next"<< cellsno << " " << etcontainer_next->size() );
414 return StatusCode::SUCCESS;
415 }
416 }
417 unsigned cellCounter = 0;
418 ATH_MSG_DEBUG("cellsno size: "<<cellsno);
419
420 for( int c = 0;c<cellsno;++c ){
421 if(m_fillBCID) m_bcid = thisbcid;
422
423 m_ELVL1Id = thisELVL1Id;
424 m_IEvent = thisevent;
425 if(m_overwriteEventNumber) m_IEvent = ctx.evt();
426
427 bool acceptETMain = true;
428
429 if( hasAccDigitContainer ){
430
431 const LArAccumulatedDigit* digi = AccDigitContainer->at(c);
432 // ======================
433
434
435 unsigned int trueMaxSample = digi->nsample();
436
437 if(trueMaxSample>m_Nsamples){
438 if(!m_ipass){
439 ATH_MSG_DEBUG( "The number of samples in data is larger than the one specified by JO: " << trueMaxSample << " > " << m_Nsamples << " --> only " << m_Nsamples << " will be available in the ntuple " );
440 m_ipass = 1;
441 }
442 trueMaxSample = m_Nsamples;
443 }
444 m_ntNsamples = trueMaxSample;
445
447
448 float adcmax=-1.;
449 for(unsigned i = 0; i<trueMaxSample;++i) {
450 m_mean[i] = digi->mean(i);
451 m_RMS[i] = digi->RMS(i);
452 if(m_ADCThresh > 0 && m_mean[i]>adcmax) adcmax=m_mean[i];
453 }
454 if(m_ADCThresh > 0 && adcmax-m_mean[0] <= m_ADCThresh) continue;
455
456 }//hasAccDigitContainer
457
458 if( hasAccCalibDigitContainer ){
459
460 const LArAccumulatedCalibDigit* digi = AccCalibDigitContainer->at(c);
461 // ======================
462
463
464 unsigned int trueMaxSample = digi->nsamples();
465
466 if(trueMaxSample>m_Nsamples){
467 if(!m_ipass){
468 ATH_MSG_DEBUG( "The number of samples in data is larger than the one specified by JO: " << trueMaxSample << " > " << m_Nsamples << " --> only " << m_Nsamples << " will be available in the ntuple " );
469 m_ipass = 1;
470 }
471 trueMaxSample = m_Nsamples;
472 }
473 m_ntNsamples = trueMaxSample;
474
476
477 float adcmax=-1.;
478 for(unsigned i = 0; i<trueMaxSample;++i) {
479 m_mean[i] = digi->mean(i);
480 m_RMS[i] = digi->RMS(i);
481 if(m_ADCThresh > 0 && m_mean[i]>adcmax) adcmax=m_mean[i];
482 }
483 if(m_ADCThresh > 0 && adcmax-m_mean[0] <= m_ADCThresh) continue;
484 m_dac = digi->DAC();
485 m_delay = digi->delay();
486 m_pulsed = digi->getIsPulsedInt();
487
488 }//hasAccCalibDigitContainer
489
490 if( hasDigitContainer ){
491
492 const LArDigit* digi = DigitContainer->at(c);
493 // ======================
494
495 unsigned int trueMaxSample = digi->nsamples();
496
497 if(trueMaxSample>m_Nsamples){
498 if(!m_ipass){
499 ATH_MSG_DEBUG( "The number of samples in data is larger than the one specified by JO: " << trueMaxSample << " > " << m_Nsamples << " --> only " << m_Nsamples << " will be available in the ntuple " );
500 m_ipass = 1;
501 }
502 trueMaxSample = m_Nsamples;
503 }
504 m_ntNsamples = trueMaxSample;
505
507
508 if(m_FTlist.size() > 0) { // should do a selection
509 if(std::find(std::begin(m_FTlist), std::end(m_FTlist), m_FT) == std::end(m_FTlist)) { // is our FT in list ?
510 continue;
511 }
512 }
513
514 if( m_fillRawChan && RawChannelContainer ){
515 fillRODEnergy(digi->hardwareID(), rawChannelMap, cabling, cablingROD, acceptETMain);
516 if(!acceptETMain) continue; // do not pass the ETThreshMain cut
517 }
518
519 short adcmax=0;
520 for(unsigned i = 0; i<trueMaxSample;++i) {
521 m_samples[i] = digi->samples().at(i);
522 if(m_ADCThresh > 0 && m_samples[i]>adcmax) adcmax=m_samples[i];
523 }
524 if(m_ADCThresh > 0 && adcmax-m_samples[0] <= m_ADCThresh) continue;
525
526 const LArSCDigit* scdigi = dynamic_cast<const LArSCDigit*>(digi);
527 if(!scdigi){
528 ATH_MSG_DEBUG(" Can't cast digi to LArSCDigit*");
529 }else{
530 if (headcontainer){
531 ATH_MSG_DEBUG(" Accessing LATOME header ");
532 const LArLATOMEHeader*headmap = LATOMEHeadMap[scdigi->SourceId()];
533 if(headmap){
534 m_bcidLATOMEHEAD = headmap->BCId();
535 m_ELVL1Id = headmap->L1Id();
536 }
537 }
538 m_latomeChannel = scdigi->Channel();
539 unsigned int trueMaxBcid = trueMaxSample;
540 if(trueMaxBcid > scdigi->BCId().size()) trueMaxBcid=scdigi->BCId().size();
541 for( unsigned i = 0; i<trueMaxBcid; ++i){
542 m_bcidVec[i] = scdigi->BCId().at(i);
543 }
544 m_latomeSourceId = scdigi->SourceId();
545 }
546
547
548 }//hasDigitContainer
549 ATH_MSG_DEBUG("After hasDigitContainer ");
550
551
552 // DigitContainer 1 -> SC_ADC_BAS
553 if( DigitContainer_next ){
554
555 const LArDigit* digi = DigitContainer_next->at(c);
556
557 unsigned int trueMaxSample = digi->nsamples();
558
559 if(trueMaxSample>m_Nsamples){
560 if(!m_ipass){
561 ATH_MSG_DEBUG( "The number of samples in data is larger than the one specified by JO: " << trueMaxSample << " > " << m_Nsamples << " --> only " << m_Nsamples << " will be available in the ntuple " );
562 m_ipass=1;
563 }
564 trueMaxSample = m_Nsamples;
565 }
566 m_ntNsamples = trueMaxSample;
567
568 if( !hasDigitContainer){
570 if( m_fillRawChan && RawChannelContainer ){
571 fillRODEnergy(digi->hardwareID(), rawChannelMap, cabling, cablingROD, acceptETMain);
572 if(!acceptETMain) continue; // do not pass the ETThreshMain cut
573 }
574 }
575
576 short adcmax=0;
577 for(unsigned i = 0; i<trueMaxSample;++i) {
578 m_samples_ADC_BAS[i] = digi->samples().at(i);
579 if(m_ADCThresh > 0 && m_samples_ADC_BAS[i]>adcmax) adcmax=m_samples_ADC_BAS[i];
580 }
581 if(m_ADCThresh > 0 && adcmax-m_samples_ADC_BAS[0] <= m_ADCThresh) continue;
582
583 const LArSCDigit* scdigi = dynamic_cast<const LArSCDigit*>(digi);
584 if(!scdigi){ ATH_MSG_DEBUG(" Can't cast digi to LArSCDigit*");
585 }else{
586 if (headcontainer){
587 const LArLATOMEHeader*headmap = LATOMEHeadMap[scdigi->SourceId()];
588 if(headmap){
589 m_bcidLATOMEHEAD = headmap->BCId();
590 m_ELVL1Id = headmap->L1Id();
591 }
592 }
593 m_latomeChannel = scdigi->Channel();
594 for( unsigned i = 0; i<trueMaxSample;++i){
595 m_bcidVec[i] = scdigi->BCId().at(i);
596 }
597 m_latomeSourceId = scdigi->SourceId();
598 }
599
600 }
601 ATH_MSG_DEBUG("After DigitContainer_next ");
602
603
604
605 // etcontainer -> SC_ET
606 if( etcontainer ){
607 const LArRawSC*rawSC = etcontainer->at(c);
608
609 if ( !hasDigitContainer && !DigitContainer_next ){
611 m_latomeChannel = rawSC->chan();
612 if (headcontainer){
613 const LArLATOMEHeader*headmap = LATOMEHeadMap[rawSC->SourceId()];
614 if(headmap){
615 m_bcidLATOMEHEAD = headmap->BCId();
616 m_ELVL1Id = headmap->L1Id();
617 }
618 }
619 if( m_fillRawChan && RawChannelContainer ){
620 fillRODEnergy(rawSC->hardwareID(), rawChannelMap, cabling, cablingROD, acceptETMain);
621 if(!acceptETMain) continue; // do not pass the ETThreshMain cut
622 }
623 }
624 unsigned int truenet = m_Net;
625 if(truenet > rawSC->bcids().size()) truenet=rawSC->bcids().size();
626 for( unsigned i=0; i<truenet;++i){ // just use the vector directly?
627 m_bcidVec_ET[i] = rawSC->bcids().at(i);
628 }
629 if(truenet > rawSC->energies().size()) truenet=rawSC->energies().size();
630 unsigned i;
631 for( i=0; i<truenet;++i){ // just use the vector directly?
632 m_energyVec_ET[i] = rawSC->energies().at(i);
633 if(rawSC->bcids().size()) {
634 if(m_ETThresh > 0. && m_bcidVec_ET[i] == thisbcid) { // our ET
635 if(m_energyVec_ET[i] < m_ETThresh) break;
636 }
637 } else {
638 if(m_ETThresh > 0. ) { // our ET
639 if(m_energyVec_ET[i] < m_ETThresh) break;
640 }
641 }
642 }
643 if(i<truenet) continue; // energy cut
644
645 if(truenet > rawSC->satur().size()) truenet=rawSC->satur().size();
646 for( unsigned i = 0; i<truenet;++i){ // just use the vector directly?
647 m_saturVec_ET[i] = rawSC->satur().at(i);
648 }
649 m_Net=truenet;
650 m_ntNet=truenet;
651
652 }
653 ATH_MSG_DEBUG("After etcontainer");
654 // etcontainer_next -> SC_ET_ID
655 if( etcontainer_next ){
656 const LArRawSC*rawSC = etcontainer_next->at(c);
657
658 if ( !hasDigitContainer && !DigitContainer_next && !etcontainer ){
660 m_latomeChannel = rawSC->chan();
661 if (headcontainer){
662 const LArLATOMEHeader*headmap = LATOMEHeadMap[rawSC->SourceId()];
663 if(headmap){
664 m_bcidLATOMEHEAD = headmap->BCId();
665 m_ELVL1Id = headmap->L1Id();
666 }
667 }
668 if( m_fillRawChan && RawChannelContainer ){
669 fillRODEnergy(rawSC->hardwareID(), rawChannelMap, cabling, cablingROD, acceptETMain);
670 if(!acceptETMain) continue; // do not pass the ETThreshMain cut
671 }
672 }
673 ATH_MSG_DEBUG("Mid etcontainer_next "<<c);
674 for( unsigned i=0; i<rawSC->bcids().size();++i){ // just use the vector directly?
675 m_bcidVec_ET_ID[i] = rawSC->bcids()[i];
676 }
677 unsigned i;
678 for( i=0; i<rawSC->energies().size();++i){ // just use the vector directly?
679 m_energyVec_ET_ID[i] = rawSC->energies()[i];
680 if(rawSC->bcids().size()) {
681 if(m_ETThresh > 0. && m_bcidVec_ET_ID[i] == thisbcid) { // our ET
682 if(m_energyVec_ET_ID[i] < m_ETThresh) break;
683 }
684 } else {
685 if(m_ETThresh > 0.) { // our ET
686 if(m_energyVec_ET_ID[i] < m_ETThresh) break;
687 }
688 }
689 }
690 if(i<rawSC->energies().size()) {
691 continue; // energy cut
692 }
693
694 for( unsigned i = 0; i<rawSC->satur().size();++i){ // just use the vector directly?
695 m_saturVec_ET_ID[i] = rawSC->satur()[i];
696 }
697 }
698 ATH_MSG_DEBUG("After etcontainer_next");
699
700 sc = ntupleSvc()->writeRecord(m_nt);
701 if (sc != StatusCode::SUCCESS) {
702 ATH_MSG_ERROR( "writeRecord failed" );
703 return sc;
704 }
705 cellCounter++;
706 }// over cells
707
708 if(m_fillTType) {
709 m_TType = thisttype;
710 m_IEventEvt = thisevent;
712 m_LB = thislb;
713
714 for (auto const & x : m_trigNames) {
715 if( ! m_trigDec->getListOfTriggers(x).empty() ){
716 m_trigNameMap[x] = m_trigDec->isPassedBits( x );
717 }
718 }
719 m_LArEventBits = evt->eventFlags(xAOD::EventInfo::LAr);
720 m_LArInError = 0;
723
724 }
725
726 if(m_fillCaloTT){
727 const DataVector<LVL1::TriggerTower>* TTVector = nullptr;
728 if ( evtStore()->retrieve(TTVector,m_triggerTowerKey).isFailure() ) {
729 ATH_MSG_WARNING("Could not get the Calo TTs, will not fill...");
730 } else {
731 unsigned count=0;
732 ATH_MSG_INFO("Got TT vector of the sixe " << TTVector->size());
734 for ( x = TTVector->begin(); x < TTVector->end(); ++x ){
735 m_TTeta[count]=(*x)->eta();
736 m_TTphi[count]=(*x)->phi();
737 m_TTEem[count]=(*x)->emEnergy();
738 m_TTEhad[count]=(*x)->hadEnergy();
739 ++count;
740 if(count==20000) break;
741 }
743 }
744 }
745
747 sc = ntupleSvc()->writeRecord(m_evt_nt);
748 if (sc != StatusCode::SUCCESS) {
749 ATH_MSG_ERROR( "writeRecord failed" );
750 return sc;
751 }
752 }
753
754 ATH_MSG_DEBUG( "LArSC2Ntuple has finished, filled " << cellCounter << " cells");
755 return StatusCode::SUCCESS;
756}// end execute-method.
757
758void LArSC2Ntuple::fillRODEnergy(HWIdentifier SCId, rawChanMap_t &rawChanMap, const LArOnOffIdMapping* cabling, const LArOnOffIdMapping* cablingROD, bool &acceptETMain)
759{
760 const Identifier offId = cabling->cnvToIdentifier(SCId);
761 const std::vector<Identifier> cellIds = m_scidtool->superCellToOfflineID(offId);
762 std::fill(m_ROD_energy.begin(), m_ROD_energy.end(), 0.);
763 std::fill(m_ROD_time.begin(), m_ROD_time.end(), 0.);
764 std::fill(m_ROD_id.begin(), m_ROD_id.end(), 0.);
765 for(unsigned i=0; i<cellIds.size(); ++i ) {
766 const HWIdentifier hwcell=cablingROD->createSignalChannelID(cellIds[i]);
767 if (hwcell.is_valid() && (rawChanMap.count(hwcell) != 0) ) {
768 m_ROD_energy[i] = rawChanMap[hwcell]->energy();
769 m_ROD_time[i] = rawChanMap[hwcell]->time();
770 m_ROD_id[i] = rawChanMap[hwcell]->hardwareID().get_identifier32().get_compact();
771 } else {
772 ATH_MSG_DEBUG(i<<"-th cell invalid Id");
773 }
774 }
775 if(acceptETMain && m_ETThreshMain > 0. && m_caloMgrSC) { // check if cell is above threshold
776 auto result = std::reduce(m_ROD_energy.begin(), m_ROD_energy.end());
777 auto dde = m_caloMgrSC->get_element(offId);
778 if(dde && result / cosh(dde->eta()) < m_ETThreshMain) acceptETMain = false;
779 }
780}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
static Double_t sc
INTupleSvc * ntupleSvc()
size_t size() const
Number of registered mappings.
#define x
ServiceHandle< StoreGateSvc > & evtStore()
Derived DataVector<T>.
Definition DataVector.h:795
DataModel_detail::const_iterator< DataVector > const_iterator
Standard const_iterator.
Definition DataVector.h:838
const T * at(size_type n) const
Access an element, as an rvalue.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
bool is_valid() const
Check if id is in a valid state.
Container class for LArAccumulatedCalibDigit.
Data class for calibration ADC samples preprocessed by the DSP.
int delay() const
return the setting of the delay
const HWIdentifier & hardwareID() const
Return HWIdentifier.
uint16_t getIsPulsedInt() const
get the four bit int that tells which lines pulsed
int DAC() const
return the number of samples
std::vector< float > RMS() const
Calculates and returns the RMS value of each ADC sample.
std::vector< float > mean() const
Calculates and returns the Mean value of each ADC sample.
size_t nsamples() const
return number of samples
Container class for LArAccumulatedDigit.
Data class for ADC samples and autocorr preprocessed by the DSP.
const HWIdentifier & hardwareID() const
Return HWIdentifier.
float RMS(int n_min=-1, int n_max=-1) const
Calculates and returns the RMS value of ADC samples.
float mean(int n_min=-1, int n_max=-1) const
Calculates and returns the Mean value of ADC samples.
int nsample() const
return number of samples
Gaudi::Property< bool > m_isSC
const SG::ReadCondHandleKey< LArOnOffIdMapping > & cablingKey() const
NTuple::Item< long > m_FT
bool fillFromIdentifier(const HWIdentifier &id)
Container class for LArDigit.
Liquid Argon digit base class.
Definition LArDigit.h:25
const HWIdentifier & hardwareID() const
Definition LArDigit.h:66
int nsamples() const
Definition LArDigit.h:75
const std::vector< short > & samples() const
Definition LArDigit.h:78
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
LArDigits2Ntuple(const std::string &name, ISvcLocator *pSvcLocator)
NTuple::Array< float > m_mean
Gaudi::Property< std::vector< unsigned int > > m_FTlist
Gaudi::Property< unsigned int > m_Nsamples
NTuple::Item< long > m_ntNsamples
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
NTuple::Tuple * m_evt_nt
SG::ReadHandleKey< LArAccumulatedCalibDigitContainer > m_accCalibContKey
NTuple::Item< unsigned long long > m_IEventEvt
NTuple::Item< unsigned int > m_dac
Container class for LArLATOMEHeader.
Holds information from the LATOME Header.
uint32_t L1Id() const
get the L1 Id
uint16_t BCId() const
get the Bunch Crossing IDs
HWIdentifier createSignalChannelID(const Identifier &id) const
create a HWIdentifier from an Identifier (not inline)
Container for LArRawChannel (IDC using LArRawChannelCollection).
Liquid Argon ROD output object base class.
Container class for LArRawSC.
Liquid Argon SuperCell raw data.
Definition LArRawSC.h:19
unsigned int SourceId() const
Definition LArRawSC.h:95
short chan() const
Definition LArRawSC.h:92
const std::vector< bool > & satur() const
Definition LArRawSC.h:107
const std::vector< unsigned short > & bcids() const
Definition LArRawSC.h:104
const std::vector< int > & energies() const
Definition LArRawSC.h:101
const HWIdentifier & hardwareID() const
Definition LArRawSC.h:89
NTuple::Array< bool > m_saturVec_ET_ID
Gaudi::Property< float > m_ETThresh
NTuple::Array< int > m_energyVec_ET_ID
std::map< std::string, NTuple::Item< unsigned int > > m_trigNameMap
NTuple::Array< bool > m_saturVec_ET
std::map< HWIdentifier, const LArRawChannel * > rawChanMap_t
NTuple::Array< unsigned short > m_bcidVec_ET
Gaudi::Property< std::string > m_triggerTowerKey
Gaudi::Property< bool > m_fillRawChan
Gaudi::Property< bool > m_fillTType
NTuple::Array< short > m_samples_ADC_BAS
SG::ReadDecorHandleKey< xAOD::EventInfo > m_eventInfoDecorKey
NTuple::Array< unsigned short > m_bcidVec
Gaudi::Property< std::vector< std::string > > m_contKeys
void fillRODEnergy(HWIdentifier SCId, rawChanMap_t &rawChanMap, const LArOnOffIdMapping *cabling, const LArOnOffIdMapping *cablingROD, bool &acceptMain)
NTuple::Item< uint32_t > m_latomeSourceId
NTuple::Array< unsigned short > m_bcidVec_ADC_BAS
Gaudi::Property< float > m_ETThreshMain
NTuple::Item< short > m_LArInError
NTuple::Array< int > m_TTEem
SG::ReadCondHandleKey< CaloSuperCellDetDescrManager > m_caloSCMgrKey
NTuple::Item< uint32_t > m_ntNTT
Gaudi::Property< float > m_ADCThresh
Gaudi::Property< bool > m_fillCaloTT
Gaudi::Property< std::vector< std::string > > m_trigNames
NTuple::Item< unsigned int > m_TType
ToolHandle< ICaloSuperCellIDTool > m_scidtool
NTuple::Array< double > m_TTeta
NTuple::Array< float > m_ROD_id
SG::ReadHandleKey< LArLATOMEHeaderContainer > m_LArLatomeHeaderContainerKey
NTuple::Array< unsigned short > m_bcidVec_ET_ID
Gaudi::Property< bool > m_overwriteEventNumber
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Gaudi::Property< unsigned int > m_Net
NTuple::Item< uint32_t > m_LArEventBits
NTuple::Array< double > m_TTphi
const CaloSuperCellDetDescrManager * m_caloMgrSC
NTuple::Array< int > m_TTEhad
NTuple::Array< float > m_ROD_energy
NTuple::Item< short > m_latomeChannel
NTuple::Array< int > m_energyVec_ET
NTuple::Item< uint32_t > m_ntNet
NTuple::Array< float > m_ROD_time
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
LArSC2Ntuple(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKeyAdditional
ToolHandle< Trig::TrigDecisionTool > m_trigDec
virtual StatusCode initialize() override
NTuple::Item< uint16_t > m_bcidLATOMEHEAD
Base class for LArDigits taken by LATOME.
Definition LArSCDigit.h:21
unsigned int SourceId() const
Definition LArSCDigit.h:47
const std::vector< unsigned short > & BCId() const
Definition LArSCDigit.h:50
short Channel() const
Definition LArSCDigit.h:44
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
@ LAr
The LAr calorimeter.
@ Warning
The sub-detector issued a warning.
@ Error
The sub-detector issued an error.
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:148