ATLAS Offline Software
Loading...
Searching...
No Matches
LArPhysWaveFromStdNtuple.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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
22LArPhysWaveFromStdNtuple::LArPhysWaveFromStdNtuple(const std::string & name, ISvcLocator * pSvcLocator):AthAlgorithm(name, pSvcLocator) {};
23
25
27{
28 ATH_MSG_INFO ( "... in stop()" );
29
30 // get LArOnlineID helper
31 const LArOnlineID_Base* onlineHelper = nullptr;
32 if(m_isSC) {
33 const LArOnline_SuperCellID* onltmp;
34 ATH_CHECK( detStore()->retrieve(onltmp, "LArOnline_SuperCellID") );
35 onlineHelper = static_cast<const LArOnlineID_Base*>( onltmp);
36 } else {
37 const LArOnlineID* onltmp = nullptr;
38 ATH_CHECK( detStore()->retrieve(onltmp, "LArOnlineID") );
39 onlineHelper = static_cast<const LArOnlineID_Base*> (onltmp);
40 }
41
42 TChain* outfit = new TChain(m_ntuple_name.value().c_str());
43 for (const std::string& s : m_root_file_names) {
44 outfit->Add(s.c_str());
45 }
46
47
48 Int_t timeIndex;
49 Int_t flag;
50 Double_t Dt;
51 Double_t timeOffset;
52 Int_t channelId;
53 Int_t FT, slot, channel;
54 //avoid large stack use, with heap allocation
55 auto Amplitude = std::make_unique<Double_t[]>(2000); // The function
56 auto Error = std::make_unique<Double_t[]>(2000); // The function
57 Int_t Triggers[2000]; // The function
58 Int_t gain = 0; // LARHIGHGAIN = 0, LARMEDIUMGAIN = 1, LARLOWGAIN = 2,
59 outfit->SetBranchAddress("channelId", &channelId);
60 outfit->SetBranchAddress("FT", &FT);
61 outfit->SetBranchAddress("slot", &slot);
62 outfit->SetBranchAddress("channel", &channel);
63 outfit->SetBranchAddress("timeIndex", &timeIndex);
64 outfit->SetBranchAddress("Dt", &Dt);
65 outfit->SetBranchAddress("timeOffset", &timeOffset);
66 outfit->SetBranchAddress("flag", &flag);
67 outfit->SetBranchAddress("gain", &gain);
68 outfit->SetBranchAddress("Amplitude", Amplitude.get());
69 outfit->SetBranchAddress("Error", Error.get());
70 outfit->SetBranchAddress("Triggers", Triggers);
71
72 // Create new LArPhysWaveContainer
73 auto larPhysWaveContainerNew = std::make_unique<LArPhysWaveContainer>();
74 ATH_CHECK ( larPhysWaveContainerNew->setGroupingType(m_groupingType, msg()) );
75 ATH_CHECK ( larPhysWaveContainerNew->initialize() );
76
77 unsigned int hwid;
78 unsigned int uflag;
79 // loop over entries in the Tuple, one entry = one channel
80 Long64_t nentries = outfit->GetEntries();
81 for ( Long64_t i = 0; i < nentries; i++ )
82 {
83 outfit->GetEvent(i);
84 if(m_isSC && gain >0) continue;
85 ATH_MSG_INFO ( " Chan " << std::hex << channelId << std::dec );
86
87 hwid = channelId;
88 HWIdentifier id(hwid);
89 if(FT != onlineHelper->feedthrough(id) || slot != onlineHelper->slot(id) || channel != onlineHelper->channel(id)) {
90 ATH_MSG_ERROR ( "Inconsistency in decoding HWID !!!!" );
91 ATH_MSG_ERROR ( FT << " - " << onlineHelper->feedthrough(id) );
92 ATH_MSG_ERROR ( slot << " - " << onlineHelper->slot(id) );
93 ATH_MSG_ERROR ( channel << " - " << onlineHelper->channel(id) );
94 ATH_MSG_ERROR ( "Not creating PhysWave !!!!" );
95 continue;
96 }
97
98 // Catch potential array index out of range error.
99 if ( timeIndex >= 2000 ) {
100 ATH_MSG_ERROR ( " Too many points specified vs the expected content of the ntuple ! " );
101 ATH_MSG_ERROR ( "Not creating PhysWave !!!!" );
102 continue;
103 }
104 std::vector<double> wave(timeIndex);
105 std::vector<double> wave_err(timeIndex);
106 std::vector<int> wave_trig(timeIndex);
107 for ( int i = 0; i < timeIndex; i++ ) {
108 wave[i]=0.;
109 wave_err[i]=0.;
110 wave_trig[i]=0.;
111 }
112 unsigned int skipped = 0;
113 unsigned int limit = timeIndex;
114 if ( m_skipPoints < m_prefixPoints ) limit = timeIndex+m_skipPoints-m_prefixPoints;
115 for ( unsigned int i = 0; i < limit; i++ )
116 {
117 if ( skipped >= m_skipPoints )
118 {
119 wave[i-m_skipPoints+m_prefixPoints]=Amplitude[i];
120 wave_err[i-m_skipPoints+m_prefixPoints]=Error[i];
121 wave_trig[i-m_skipPoints+m_prefixPoints]=Triggers[i];
122 }
123 else skipped++;
124 }
125
126 uflag = flag;
127 LArPhysWave newLArPhysWave(wave, wave_err, wave_trig, Dt, timeOffset, uflag);
128
129 // Add physics wave to container
130 larPhysWaveContainerNew->setPdata(id, newLArPhysWave, (CaloGain::CaloGain)gain);
131 }
132 ATH_CHECK( detStore()->record(std::move(larPhysWaveContainerNew),m_store_key) );
133 ATH_MSG_INFO ( "LArPhysWaveFromStdNtuple finalized!" );
134 return StatusCode::SUCCESS;
135}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
const ServiceHandle< StoreGateSvc > & detStore() const
MsgStream & msg() 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
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
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
LArPhysWaveFromStdNtuple(const std::string &name, ISvcLocator *pSvcLocator)