ATLAS Offline Software
Loading...
Searching...
No Matches
LArPhysWaveFromTuple.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
11
12#include "TFile.h"
13#include "TBranch.h"
14#include "TTree.h"
15#include "TChain.h"
16
17#include <vector>
18#include <iostream>
19#include <fstream>
20#include <string>
21
22
24= default;
25
27{
28 return StatusCode::SUCCESS ;
29}
30
31
33{
34 ATH_MSG_INFO ( "... in stop()" );
35
36 // get LArOnlineID helper
37 const LArOnlineID* onlineHelper = nullptr;
38 ATH_CHECK( detStore()->retrieve(onlineHelper, "LArOnlineID") );
39
40 TChain* outfit = new TChain(m_ntuple_name.value().c_str());
41 outfit->Add(m_root_file_name.value().c_str());
42
43 // This algorithm assumes the input NTuple in contains less than 2000
44 // points. If the NTuple contains less than 2000 points, the
45 // remaining points are automatically initialized to 0.
46 // Catch potential array index out of range error.
47 if ( m_NPoints > 2000 ) {
48 ATH_MSG_WARNING ( " Too many points specified vs the expected content of the ntuple ! " );
49 ATH_MSG_WARNING ( " Only 2000 will be used !");
50 m_NPoints = 2000;
51 }
52
53 // variable names as in the Ntuple
54 Int_t channelId;
55 UInt_t tIndex;
56 std::vector<Double_t> Amplitude(2000);
57 std::vector<Double_t> Time(2000);
58 outfit->SetBranchAddress("channelId", &channelId);
59 outfit->SetBranchAddress("timeIndex", &tIndex);
60 outfit->SetBranchAddress("Amplitude", Amplitude.data());
61 outfit->SetBranchAddress("Time", Time.data());
62
63 // Create new LArPhysWaveContainer
64 auto larPhysWaveContainerNew = std::make_unique<LArPhysWaveContainer>();
65 ATH_CHECK ( larPhysWaveContainerNew->setGroupingType(m_groupingType, msg()) );
66 ATH_CHECK ( larPhysWaveContainerNew->initialize() );
67
68 // loop over entries in the Tuple, one entry = one channel
69 Long64_t nentries = outfit->GetEntries();
70 std::vector<double> wave(m_NPoints);
71 for ( Long64_t i = 0; i < nentries; i++ )
72 {
73 outfit->GetEvent(i);
74 HWIdentifier id(channelId);
75 ATH_MSG_INFO ( std::hex << id << std::dec );
76
77 for ( unsigned int i = 0; i < m_NPoints; i++ ) wave[i]=0.;
78 unsigned int skipped = 0;
79 unsigned int limit = tIndex<m_NPoints.value() ? tIndex : m_NPoints.value();
80 if ( m_skipPoints < m_prefixPoints ) limit = m_NPoints.value() + m_skipPoints.value() - m_prefixPoints.value();
81 double dt=Time[1]-Time[0];
82 for ( unsigned int i = 0; i < limit; i++ )
83 {
84 if(i>1 && Time[i] - Time[i-1] != dt) {
85 ATH_MSG_ERROR("No equidistant time, could not process....");
86 return StatusCode::FAILURE;
87 }
88 if ( skipped >= m_skipPoints )
89 {
90 wave[i-m_skipPoints+m_prefixPoints]=Amplitude[i];
91 }
92 else skipped++;
93 }
94
95 LArPhysWave newLArPhysWave(wave, dt, m_flag);
96
97 // Add physics wave to container
98 larPhysWaveContainerNew->setPdata(id, newLArPhysWave, (CaloGain::CaloGain)m_gain.value());
99 }
100
101 ATH_CHECK( detStore()->record(std::move(larPhysWaveContainerNew),m_store_key) );
102 ATH_MSG_INFO ( "LArPhysWaveFromTuple finalized!" );
103 return StatusCode::SUCCESS;
104}
#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)
const ServiceHandle< StoreGateSvc > & detStore() const
Gaudi::Property< std::string > m_root_file_name
input file name
Gaudi::Property< unsigned int > m_flag
flag for the PhysWave container
Gaudi::Property< unsigned int > m_NPoints
max number of points of the waveform in the ntuple
virtual ~LArPhysWaveFromTuple()
virtual StatusCode initialize() override
Gaudi::Property< std::string > m_store_key
key of the PhysWave collection in Storegate
Gaudi::Property< std::string > m_ntuple_name
ntuple name
Gaudi::Property< std::string > m_groupingType
Grouping type. Default is Feedthrough.
Gaudi::Property< int > m_gain
virtual StatusCode stop() override
Gaudi::Property< unsigned int > m_skipPoints
the first m_skipPoints points of the waveform in the ntuple are skipped
Gaudi::Property< unsigned int > m_prefixPoints
make a PhysWave with the first m_prefixPoints as zeros