ATLAS Offline Software
LArPhysWaveFromTuple.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 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 
23 LArPhysWaveFromTuple::LArPhysWaveFromTuple (const std::string& name, ISvcLocator* pSvcLocator) : AthAlgorithm(name, pSvcLocator)
24 {
25  declareProperty("NPoints", m_NPoints = 800);
26  declareProperty("SkipPoints", m_skipPoints = 0);
27  declareProperty("PrefixPoints", m_prefixPoints = 0);
28  declareProperty("deltaT", m_deltaT = 1.04e-9);
29  declareProperty("LArWaveFlag", m_flag = 20);
30  declareProperty("FileNames", m_root_file_names);
31  declareProperty("StoreKey", m_store_key="FROMTUPLE");
32  declareProperty("GroupingType", m_groupingType="FeedThrough");
33 }
34 
36 = default;
37 
39 {
40  return StatusCode::SUCCESS ;
41 }
42 
43 
45 {
46  ATH_MSG_INFO ( "... in finalize()" );
47 
48  // get LArOnlineID helper
49  const LArOnlineID* onlineHelper = nullptr;
50  ATH_CHECK( detStore()->retrieve(onlineHelper, "LArOnlineID") );
51 
52  TChain* outfit = new TChain("outfit");
53  for (const std::string& s : m_root_file_names) {
54  outfit->Add(s.c_str());
55  }
56 
57  // This algorithm assumes the input NTuple in contains less than 2000
58  // points. If the NTuple contains less than 2000 points, the
59  // remaining points are automatically initialized to 0.
60  // Catch potential array index out of range error.
61  if ( m_NPoints > 2000 ) {
62  ATH_MSG_ERROR ( " Too many points specified vs the expected content of the ntuple ! " );
63  return StatusCode::FAILURE;
64  }
65 
66  // variable names as in the Ntuple
67  Int_t BarEC; // 0 = Barrel 1 = EndCap
68  Int_t Side; // 0 = side C 1 = side A
69  Int_t FT; // feedthrough 0 - 31
70  Int_t Channel; // 0 - 127
71  Int_t Slot; // 1 -14
72  Double_t tphys[2000]; // The function
73  Int_t gain = 0; // LARHIGHGAIN = 0, LARMEDIUMGAIN = 1, LARLOWGAIN = 2,
74  outfit->SetBranchAddress("Channel", &Channel);
75  outfit->SetBranchAddress("Slot", &Slot);
76  outfit->SetBranchAddress("FT", &FT);
77  if(outfit->FindBranch("BarAC")){ // Handle changed naming scheme
78  ATH_MSG_INFO ( "'Side' is prefered branch name to 'BarAC'." );
79  outfit->SetBranchAddress("BarAC", &Side);
80  } else {
81  outfit->SetBranchAddress("Side", &Side);
82  }
83  if(!outfit->FindBranch("BarEC")){ // Handle
84  ATH_MSG_INFO ( "'BarEC' branch not found. Assuming barrel data." );
85  BarEC = 0;
86  } else {
87  outfit->SetBranchAddress("BarEC", &BarEC);
88  }
89  outfit->SetBranchAddress("Gain", &gain);
90  outfit->SetBranchAddress("tphys", tphys);
91 
92  // Create new LArPhysWaveContainer
93  LArPhysWaveContainer* larPhysWaveContainerNew = new LArPhysWaveContainer();
94  ATH_CHECK ( larPhysWaveContainerNew->setGroupingType(m_groupingType, msg()) );
95  ATH_CHECK ( larPhysWaveContainerNew->initialize() );
96 
97  // loop over entries in the Tuple, one entry = one channel
98  Long64_t nentries = outfit->GetEntries();
99  for ( Long64_t i = 0; i < nentries; i++ )
100  {
101  outfit->GetEvent(i);
102  ATH_MSG_INFO ( BarEC << " Side " << Side << " FT " << FT << " slot " << Slot << " Chan " << Channel );
103  HWIdentifier id = onlineHelper->channel_Id(BarEC, Side, FT, Slot, Channel);
104  ATH_MSG_INFO ( std::hex << id << std::dec );
105 
106  std::vector<double> wave(m_NPoints);
107  for ( unsigned int i = 0; i < m_NPoints; i++ ) wave[i]=0.;
108  unsigned int skipped = 0;
109  unsigned int limit = m_NPoints;
111  for ( unsigned int i = 0; i < limit; i++ )
112  {
113  if ( skipped >= m_skipPoints )
114  {
115  wave[i-m_skipPoints+m_prefixPoints]=tphys[i];
116  }
117  else skipped++;
118  }
119 
120  LArPhysWave newLArPhysWave(wave, m_deltaT, m_flag);
121 
122  // Add physics wave to container
123  larPhysWaveContainerNew->setPdata(id, newLArPhysWave, (CaloGain::CaloGain)gain);
124  }
125 
126  ATH_CHECK( detStore()->record(larPhysWaveContainerNew,m_store_key) );
127  ATH_MSG_INFO ( "LArPhysWaveFromTuple finalized!" );
128  return StatusCode::SUCCESS;
129 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
LArPhysWaveFromTuple::~LArPhysWaveFromTuple
~LArPhysWaveFromTuple()
ForwardTracker::Side
Side
Definition: ForwardTrackerConstants.h:13
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
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
LArBadChanBlobUtils::Channel
Identifier32::value_type Channel
Definition: LArBadChanBlobUtils.h:24
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
LArPhysWaveContainer.h
LArPhysWaveFromTuple::m_store_key
std::string m_store_key
key of the PhysWave collection in Storegate
Definition: LArPhysWaveFromTuple.h:61
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
LArPhysWaveFromTuple::m_root_file_names
std::vector< std::string > m_root_file_names
list of input ntuple file names
Definition: LArPhysWaveFromTuple.h:59
LArPhysWave.h
HWIdentifier
Definition: HWIdentifier.h:13
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
LArPhysWaveFromTuple::m_NPoints
unsigned int m_NPoints
number of points of the waveform in the ntuple
Definition: LArPhysWaveFromTuple.h:49
PlotCalibFromCool.nentries
nentries
Definition: PlotCalibFromCool.py:798
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:92
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
LArPhysWaveFromTuple::stop
StatusCode stop()
Definition: LArPhysWaveFromTuple.cxx:44
LArOnlineID_Base::channel_Id
HWIdentifier channel_Id(int barrel_ec, int pos_neg, int feedthrough, int slot, int channel) const
create channel identifier from fields
Definition: LArOnlineID_Base.cxx:1569
Side
Definition: WaferTree.h:36
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthAlgorithm
Definition: AthAlgorithm.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
LArOnlineID
Definition: LArOnlineID.h:20
LArPhysWaveFromTuple.h
CaloGain::CaloGain
CaloGain
Definition: CaloGain.h:11
LArPhysWaveFromTuple::m_flag
unsigned int m_flag
flag for the PhysWave container
Definition: LArPhysWaveFromTuple.h:57
LArNewCalib_Delay_OFC_Cali.FT
FT
Definition: LArNewCalib_Delay_OFC_Cali.py:120
LArPhysWaveFromTuple::m_deltaT
double m_deltaT
time step of the the waveform in the ntuple
Definition: LArPhysWaveFromTuple.h:55
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
LArConditionsContainer::initialize
virtual StatusCode initialize()
Initialization done after creation or read back - derived classes may augment the functionality.
LArPhysWaveFromTuple::m_prefixPoints
unsigned int m_prefixPoints
make a PhysWave with the first m_prefixPoints as zeros
Definition: LArPhysWaveFromTuple.h:53
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
LArPhysWaveFromTuple::m_groupingType
std::string m_groupingType
Grouping type. Default is Feedthrough.
Definition: LArPhysWaveFromTuple.h:63
CaloGain.h
LArPhysWaveFromTuple::m_skipPoints
unsigned int m_skipPoints
the first m_skipPoints points of the waveform in the ntuple are skipped
Definition: LArPhysWaveFromTuple.h:51
updateCoolNtuple.limit
int limit
Definition: updateCoolNtuple.py:45
LArPhysWaveFromTuple::initialize
StatusCode initialize()
implements IAlgorithm::initialize()
Definition: LArPhysWaveFromTuple.cxx:38
LArOnlineID.h
LArPhysWaveFromTuple::LArPhysWaveFromTuple
LArPhysWaveFromTuple(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArPhysWaveFromTuple.cxx:23