ATLAS Offline Software
Loading...
Searching...
No Matches
LArPhysWaveFromStdNtuple.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
12
13#include "TFile.h"
14#include "TBranch.h"
15#include "TTree.h"
16#include "TChain.h"
17
18#include <vector>
19#include <iostream>
20#include <string>
21
23
25{
26 ATH_MSG_INFO ( "... in stop()" );
27
28 // get LArOnlineID helper
29 const LArOnlineID_Base* onlineHelper = nullptr;
30 if(m_isSC) {
31 const LArOnline_SuperCellID* onltmp;
32 ATH_CHECK( detStore()->retrieve(onltmp, "LArOnline_SuperCellID") );
33 onlineHelper = static_cast<const LArOnlineID_Base*>( onltmp);
34 } else {
35 const LArOnlineID* onltmp = nullptr;
36 ATH_CHECK( detStore()->retrieve(onltmp, "LArOnlineID") );
37 onlineHelper = static_cast<const LArOnlineID_Base*> (onltmp);
38 }
39
40 TChain* outfit = new TChain(m_ntuple_name.value().c_str());
41 for (const std::string& s : m_root_file_names) {
42 outfit->Add(s.c_str());
43 }
44
45
46 Int_t timeIndex;
47 Int_t flag;
48 Double_t Dt;
49 Double_t timeOffset;
50 Int_t channelId;
51 Int_t FT, slot, channel;
52 //avoid large stack use, with heap allocation
53 auto Amplitude = std::make_unique<Double_t[]>(2000); // The function
54 auto Error = std::make_unique<Double_t[]>(2000); // The function
55 Int_t Triggers[2000]; // The function
56 Int_t gain = 0; // LARHIGHGAIN = 0, LARMEDIUMGAIN = 1, LARLOWGAIN = 2,
57 outfit->SetBranchAddress("channelId", &channelId);
58 outfit->SetBranchAddress("FT", &FT);
59 outfit->SetBranchAddress("slot", &slot);
60 outfit->SetBranchAddress("channel", &channel);
61 outfit->SetBranchAddress("timeIndex", &timeIndex);
62 outfit->SetBranchAddress("Dt", &Dt);
63 outfit->SetBranchAddress("timeOffset", &timeOffset);
64 outfit->SetBranchAddress("flag", &flag);
65 outfit->SetBranchAddress("gain", &gain);
66 outfit->SetBranchAddress("Amplitude", Amplitude.get());
67 outfit->SetBranchAddress("Error", Error.get());
68 outfit->SetBranchAddress("Triggers", Triggers);
69
70 // Create new LArPhysWaveContainer
71 auto larPhysWaveContainerNew = std::make_unique<LArPhysWaveContainer>();
72 ATH_CHECK ( larPhysWaveContainerNew->setGroupingType(m_groupingType, msg()) );
73 ATH_CHECK ( larPhysWaveContainerNew->initialize() );
74
75 unsigned int hwid;
76 unsigned int uflag;
77 // loop over entries in the Tuple, one entry = one channel
78 Long64_t nentries = outfit->GetEntries();
79 for ( Long64_t i = 0; i < nentries; i++ )
80 {
81 outfit->GetEvent(i);
82 if(m_isSC && gain >0) continue;
83 ATH_MSG_INFO ( " Chan " << std::hex << channelId << std::dec );
84
85 hwid = channelId;
86 HWIdentifier id(hwid);
87 if(FT != onlineHelper->feedthrough(id) || slot != onlineHelper->slot(id) || channel != onlineHelper->channel(id)) {
88 ATH_MSG_ERROR ( "Inconsistency in decoding HWID !!!!" );
89 ATH_MSG_ERROR ( FT << " - " << onlineHelper->feedthrough(id) );
90 ATH_MSG_ERROR ( slot << " - " << onlineHelper->slot(id) );
91 ATH_MSG_ERROR ( channel << " - " << onlineHelper->channel(id) );
92 ATH_MSG_ERROR ( "Not creating PhysWave !!!!" );
93 continue;
94 }
95
96 // Catch potential array index out of range error.
97 if ( timeIndex >= 2000 ) {
98 ATH_MSG_ERROR ( " Too many points specified vs the expected content of the ntuple ! " );
99 ATH_MSG_ERROR ( "Not creating PhysWave !!!!" );
100 continue;
101 }
102 std::vector<double> wave(timeIndex);
103 std::vector<double> wave_err(timeIndex);
104 std::vector<int> wave_trig(timeIndex);
105 for ( int i = 0; i < timeIndex; i++ ) {
106 wave[i]=0.;
107 wave_err[i]=0.;
108 wave_trig[i]=0.;
109 }
110 unsigned int skipped = 0;
111 unsigned int limit = timeIndex;
112 if ( m_skipPoints < m_prefixPoints ) limit = timeIndex+m_skipPoints-m_prefixPoints;
113 for ( unsigned int i = 0; i < limit; i++ )
114 {
115 if ( skipped >= m_skipPoints )
116 {
117 wave[i-m_skipPoints+m_prefixPoints]=Amplitude[i];
118 wave_err[i-m_skipPoints+m_prefixPoints]=Error[i];
119 wave_trig[i-m_skipPoints+m_prefixPoints]=Triggers[i];
120 }
121 else skipped++;
122 }
123
124 uflag = flag;
125 LArPhysWave newLArPhysWave(wave, wave_err, wave_trig, Dt, timeOffset, uflag);
126
127 // Add physics wave to container
128 larPhysWaveContainerNew->setPdata(id, newLArPhysWave, (CaloGain::CaloGain)gain);
129 }
130 ATH_CHECK( detStore()->record(std::move(larPhysWaveContainerNew),m_store_key) );
131 ATH_MSG_INFO ( "LArPhysWaveFromStdNtuple finalized!" );
132 return StatusCode::SUCCESS;
133}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
const ServiceHandle< StoreGateSvc > & detStore() const
Helper for the Liquid Argon Calorimeter cell identifiers.
int feedthrough(const HWIdentifier id) const
Return the feedthrough of a hardware cell identifier : feedthrough = [0,31] Barrel - A/C side or H/...
int slot(const HWIdentifier id) const
Return the slot number of a hardware cell identifier: slot = [1,15] Slot-ID in top part of the crat...
int channel(const HWIdentifier id) const
Return the channel number of a hardware cell identifier channel = [0,127] in all FEB.
Gaudi::Property< bool > m_isSC
is SC ?
Gaudi::Property< std::string > m_ntuple_name
ntuple name
Gaudi::Property< unsigned int > m_prefixPoints
make a PhysWave with the first m_prefixPoints as zeros
virtual ~LArPhysWaveFromStdNtuple()
Gaudi::Property< std::string > m_store_key
key of the PhysWave collection in Storegate
Gaudi::Property< unsigned int > m_skipPoints
the first m_skipPoints points of the waveform in the ntuple are skipped
virtual StatusCode stop() override
Gaudi::Property< std::string > m_groupingType
Grouping type. Default is Feedthrough.
Gaudi::Property< std::vector< std::string > > m_root_file_names
list of input ntuple file names