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