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