ATLAS Offline Software
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 
22 LArPhysWaveFromStdNtuple::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  LArPhysWaveContainer* larPhysWaveContainerNew = new 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;
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(larPhysWaveContainerNew,m_store_key) );
133  ATH_MSG_INFO ( "LArPhysWaveFromStdNtuple finalized!" );
134  return StatusCode::SUCCESS;
135 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
LArConditionsContainer::setPdata
void setPdata(const HWIdentifier id, const T &payload, unsigned int gain=0)
put payload in persistent data
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
LArPhysWaveContainer.h
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
LArPhysWave.h
LArOnlineID_Base::slot
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...
Definition: LArOnlineID_Base.cxx:1957
LArPhysWaveFromStdNtuple::m_prefixPoints
Gaudi::Property< unsigned int > m_prefixPoints
make a PhysWave with the first m_prefixPoints as zeros
Definition: LArPhysWaveFromStdNtuple.h:38
LArPhysWaveFromStdNtuple.h
HWIdentifier
Definition: HWIdentifier.h:13
LArPhysWaveFromStdNtuple::~LArPhysWaveFromStdNtuple
~LArPhysWaveFromStdNtuple()
LArPhysWave
Definition: LArPhysWave.h:14
LArPhysWaveContainer
Liquid Argon Physics Wave Container.
Definition: LArPhysWaveContainer.h:23
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
PlotCalibFromCool.nentries
nentries
Definition: PlotCalibFromCool.py:798
LArOnlineID_Base::channel
int channel(const HWIdentifier id) const
Return the channel number of a hardware cell identifier channel = [0,127] in all FEB.
Definition: LArOnlineID_Base.cxx:1963
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
LArPhysWaveFromStdNtuple::m_ntuple_name
Gaudi::Property< std::string > m_ntuple_name
ntuple name
Definition: LArPhysWaveFromStdNtuple.h:42
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
master.flag
bool flag
Definition: master.py:29
LArPhysWaveFromStdNtuple::m_store_key
Gaudi::Property< std::string > m_store_key
key of the PhysWave collection in Storegate
Definition: LArPhysWaveFromStdNtuple.h:44
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
LArPhysWaveFromStdNtuple::m_groupingType
Gaudi::Property< std::string > m_groupingType
Grouping type. Default is Feedthrough.
Definition: LArPhysWaveFromStdNtuple.h:46
CaloCondBlobAlgs_fillNoiseFromASCII.channelId
channelId
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:121
LArDigits2NtupleDumper.FT
FT
Definition: LArDigits2NtupleDumper.py:77
AthAlgorithm
Definition: AthAlgorithm.h:47
LArOnlineID_Base
Helper for the Liquid Argon Calorimeter cell identifiers.
Definition: LArOnlineID_Base.h:105
LArPhysWaveFromStdNtuple::LArPhysWaveFromStdNtuple
LArPhysWaveFromStdNtuple(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArPhysWaveFromStdNtuple.cxx:22
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:239
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
LArOnlineID
Definition: LArOnlineID.h:20
LArPhysWaveFromStdNtuple::stop
StatusCode stop()
Definition: LArPhysWaveFromStdNtuple.cxx:26
LArOnline_SuperCellID
Definition: LArOnline_SuperCellID.h:20
LArPhysWaveFromStdNtuple::m_isSC
Gaudi::Property< bool > m_isSC
is SC ?
Definition: LArPhysWaveFromStdNtuple.h:48
CaloGain::CaloGain
CaloGain
Definition: CaloGain.h:11
LArOnlineID_Base::feedthrough
int feedthrough(const HWIdentifier id) const
Return the feedthrough of a hardware cell identifier : feedthrough = [0,31] Barrel - A/C side or H/...
Definition: LArOnlineID_Base.cxx:1944
LArPhysWaveFromStdNtuple::m_root_file_names
Gaudi::Property< std::vector< std::string > > m_root_file_names
list of input ntuple file names
Definition: LArPhysWaveFromStdNtuple.h:40
LArConditionsContainer::initialize
virtual StatusCode initialize()
Initialization done after creation or read back - derived classes may augment the functionality.
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
python.SystemOfUnits.s
float s
Definition: SystemOfUnits.py:147
LArOnline_SuperCellID.h
L1Topo::Error
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition: Error.h:16
CaloGain.h
updateCoolNtuple.limit
int limit
Definition: updateCoolNtuple.py:44
LArOnlineID.h
LArPhysWaveFromStdNtuple::m_skipPoints
Gaudi::Property< unsigned int > m_skipPoints
the first m_skipPoints points of the waveform in the ntuple are skipped
Definition: LArPhysWaveFromStdNtuple.h:36