ATLAS Offline Software
LArAutoCorrFromStdNtuple.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
14 #include "GaudiKernel/ThreadLocalContext.h"
15 
16 #include "TFile.h"
17 #include "TBranch.h"
18 #include "TTree.h"
19 #include "TChain.h"
20 
21 #include <vector>
22 #include <iostream>
23 #include <fstream>
24 #include <string>
25 
26 // sFcal hardcoded numbers
27 const float sFcalcovr[31][3]={
28  { 0.572496, 0.655057, 0.731093},
29  { 0.075488, 0.104297, 0.214769},
30  { -0.148836, -0.187077, -0.136677},
31  { -0.196002, -0.24895, -0.252711},
32  { -0.177228, -0.21831, -0.245412},
33  { -0.143346, -0.168434, -0.201137},
34  { -0.11199, -0.123737, -0.154998},
35  { -0.0864405, -0.0892498, -0.116567},
36  { -0.0660753, -0.0641608, -0.0867919},
37  { -0.050389, -0.0458778, -0.0642172},
38  { -0.0385136, -0.032897, -0.047445},
39  { -0.0288351, -0.023311, -0.0351371},
40  { -0.0218402, -0.0163931, -0.0260872},
41  { -0.0165734, -0.0114467, -0.019315},
42  { -0.0125223, -0.00795447, -0.0141427},
43  { -0.00894386, -0.00551898, -0.0101339},
44  { -0.00576509, -0.00396242, -0.00705192},
45  { -0.00364762, -0.00298286, -0.00479298},
46  { -0.00188369, -0.00202063, -0.00284983},
47  { -0.000721197, -0.000986272, -0.00117402},
48  { 2.62603e-05, -0.000216376, -0.000234439},
49  { 0.000133223, -5.59111e-06, 6.85495e-06},
50  { 0.000133223, -5.59111e-06, 6.85495e-06},
51  { 0.000133223, -5.59111e-06, 6.85495e-06},
52  { 0.000133223, -5.59111e-06, 6.85495e-06},
53  { 0.000133223, -5.59111e-06, 6.85495e-06},
54  { 0.000133223, -5.59111e-06, 6.85495e-06},
55  { 0.000133223, -5.59111e-06, 6.85495e-06},
56  { 0.000133223, -5.59111e-06, 6.85495e-06},
57  { 0.000133223, -5.59111e-06, 6.85495e-06},
58  { 0.000133223, -5.59111e-06, 6.85495e-06}
59  };
60 
61 LArAutoCorrFromStdNtuple::LArAutoCorrFromStdNtuple (const std::string& name, ISvcLocator* pSvcLocator) : AthAlgorithm(name, pSvcLocator)
62 {
63  declareProperty("Nsamples", m_nsamples=7);
64  declareProperty("FileNames", m_root_file_names);
65  declareProperty("NtupleName", m_ntuple_name="AUTOCORR");
66  declareProperty("StoreKey", m_store_key="FromStdNtuple");
67  declareProperty("GroupingType", m_groupingType="ExtendedSubDetector");
68  declareProperty("isComplete", m_isComplete=false);
69  declareProperty("doSFcal", m_sFcal=false);
70 
71 }
72 
74 = default;
75 
77 {
80 
81  return StatusCode::SUCCESS ;
82 }
83 
84 
86 {
87 
88  ATH_MSG_INFO ( "... in stop()" );
89 
90  const EventContext& ctx = Gaudi::Hive::currentContext();
92 
93  // get LArOnlineID helper
94  const LArOnlineID* onlineHelper = nullptr;
95  ATH_CHECK( detStore()->retrieve(onlineHelper, "LArOnlineID") );
96  // and helper for FCAL
97  const CaloCell_ID* idHelper = nullptr;
98  ATH_CHECK( detStore()->retrieve (idHelper, "CaloCell_ID") );
99  const LArFCAL_ID* fcal_id = idHelper->fcal_idHelper();
100 
102  const LArOnOffIdMapping* cabling{*cablingHdl};
103  if(!cabling) {
104  ATH_MSG_ERROR( "DO not have mapping from cabling key " << m_cablingKey.key() );
105  return StatusCode::FAILURE;
106  }
107 
108  TChain* outfit = new TChain(m_ntuple_name.c_str());
109  for (const std::string& s : m_root_file_names) {
110  outfit->Add(s.c_str());
111  }
112 
113 
114  Int_t det;
115  Int_t channelId;
116  Int_t FT, slot, channel;
117 
118  Float_t covr[100]; // The function
119  Int_t gain = 0; // LARHIGHGAIN = 0, LARMEDIUMGAIN = 1, LARLOWGAIN = 2,
120 
121  outfit->SetBranchAddress("channelId", &channelId);
122  outfit->SetBranchAddress("FT", &FT);
123  outfit->SetBranchAddress("slot", &slot);
124  outfit->SetBranchAddress("channel", &channel);
125  outfit->SetBranchAddress("detector", &det);
126  outfit->SetBranchAddress("gain", &gain);
127  outfit->SetBranchAddress("covr", covr);
128 
129  // Create new LArAutocorrContainer
130  std::unique_ptr<LArAutoCorrComplete> larAutoCorrComplete;
131  std::unique_ptr<LArAutoCorrMC> larAutoCorrMC;
132 
133  if(m_isComplete) {
134  larAutoCorrComplete = std::make_unique<LArAutoCorrComplete>();
135  ATH_CHECK( larAutoCorrComplete->setGroupingType(m_groupingType, msg()) );
136  ATH_CHECK( larAutoCorrComplete->initialize() );
137  } else {
138  larAutoCorrMC = std::make_unique<LArAutoCorrMC>();
139  ATH_CHECK( larAutoCorrMC->setGroupingType(m_groupingType, msg()) );
140  ATH_CHECK( larAutoCorrMC->initialize() );
141  }
142 
143  typedef std::vector<float> AutoCorrVec;
144  std::map<std::pair<unsigned int,int>, AutoCorrVec> AutoCorr;
145  unsigned int hwid;
146  int nsamples=m_nsamples;
147  if(nsamples>100) nsamples=100;
148  ATH_MSG_INFO( "Using " << nsamples << " samples" );
149  // loop over entries in the Tuple, one entry = one channel
150  // first create a map from existing entries, will fill container later
151  Long64_t nentries = outfit->GetEntries();
152  for ( Long64_t iev = 0; iev < nentries; ++iev )
153  {
154  outfit->GetEvent(iev);
155  ATH_MSG_DEBUG ( " Chan " << std::hex << channelId << " det. "<< det << std::dec );
156 
157  hwid = channelId;
158  HWIdentifier id(hwid);
159 
160  if(FT != onlineHelper->feedthrough(id) || slot != onlineHelper->slot(id) || channel != onlineHelper->channel(id)) {
161  ATH_MSG_ERROR ( "Inconsistency in decoding HWID !!!!" );
162  ATH_MSG_ERROR ( FT << " - " << onlineHelper->feedthrough(id) );
163  ATH_MSG_ERROR ( slot << " - " << onlineHelper->slot(id) );
164  ATH_MSG_ERROR ( channel << " - " << onlineHelper->channel(id) );
165  continue;
166  }
167 
168  if(!m_isComplete) {
169  if (id != mcsym->ZPhiSymOnl(id) ) {
170  ATH_MSG_DEBUG( "Symmetrized, not stored" );
171  continue;
172  }
173  }
174 
175  AutoCorrVec av(nsamples);
176  for(int i=0;i<nsamples; ++i) {av[i]=0.; }
177  for (int i = 0; i < nsamples; ++i ) {
178  av[i]=covr[i];
179  }
180 
181  AutoCorr[std::make_pair(hwid,gain)]=av;
182 
183  ATH_MSG_DEBUG ( "after reading size " << AutoCorr[std::make_pair(hwid,gain)].size() );
184 
185  }
186 
187  ATH_MSG_INFO ( "Ntuple read out, going to store. Have " << AutoCorr.size() << " numbers" );
188 
189  // could fill only now
190  std::map<std::pair<unsigned int,int>, AutoCorrVec>::iterator ibeg = AutoCorr.begin();
191  std::map<std::pair<unsigned int,int>, AutoCorrVec>::iterator iend = AutoCorr.end();
192  unsigned int count=0;
193  for(;ibeg != iend; ++ibeg) {
194  ATH_MSG_DEBUG ( " Chan " << std::hex << (ibeg->first).first << std::dec );
195  if(m_sFcal) {
196  HWIdentifier id((ibeg->first).first);
197  // doesn't work:
198  //if(onlineHelper->isFCALchannel(id) && onlineHelper->feedthrough(id) == 6) {
199  if(onlineHelper->barrel_ec(id)==1 && onlineHelper->feedthrough(id) == 6) {
200  ATH_MSG_INFO ( "Not storing FCAL channel " << onlineHelper->channel_name(id) );
201  continue;
202  }
203  }
204 
205  ATH_MSG_DEBUG( "Storing length " << (ibeg->second).size() );
206  if(!m_isComplete) {
207  larAutoCorrMC->set(HWIdentifier((ibeg->first).first),(ibeg->first).second, ibeg->second);
208  } else {
209  larAutoCorrComplete->set(HWIdentifier((ibeg->first).first),(ibeg->first).second, ibeg->second);
210  }
211  ++count;
212  }
213 
214  ATH_MSG_INFO ( "Storing old values done...." << count << " values copied..." );
215 
216  count = 0;
217  if(m_sFcal) { // now add sFcal
218  int limit = nsamples;
219  if(limit > 31) limit = 31;
220  AutoCorrVec myvec(limit);
221  ATH_MSG_INFO( "Using limit " << limit );
222  for (const HWIdentifier chid: onlineHelper->channel_range()) {
223  if(!m_isComplete) {
224  if (chid != mcsym->ZPhiSymOnl(chid) ) {
225  ATH_MSG_DEBUG( "Symmetrized, not stored" );
226  continue;
227  }
228  }
229  //if(onlineHelper->isFCALchannel(chid)) {
230  if(onlineHelper->barrel_ec(chid)==1 && onlineHelper->feedthrough(chid) >= 25 && onlineHelper->feedthrough(chid) < 28 ) {
231  ATH_MSG_DEBUG ( "Adding sFCAL channel " << onlineHelper->channel_name(chid) );
232  const int mod=fcal_id->module(cabling->cnvToIdentifier(chid));
233  if(mod<0 || mod > 3) {
234  ATH_MSG_ERROR ( "Wrong FCAL module: " << mod << " ignored !!" );
235  continue;
236  }
237  for(int mygain=0; mygain<3; ++mygain) {
238  for(int i=0;i<limit;++i) myvec[i]=sFcalcovr[i][mod-1];
239  if(m_isComplete) {
240  larAutoCorrComplete->set(chid,mygain,myvec);
241  } else {
242  larAutoCorrMC->set(chid,mygain,myvec);
243  }
244  }
245  ATH_MSG_DEBUG ( "sFcal storing size " << myvec.size() );
246  ++count;
247  }
248  }
249  ATH_MSG_INFO ( "Adding " << count << " sFcal values ..." );
250 
251  }
252 
253  if(m_isComplete) {
254  ATH_CHECK( detStore()->record(std::move(larAutoCorrComplete),m_store_key) );
255  } else {
256  ATH_MSG_INFO ( "Stored container " << larAutoCorrMC->nGains() << "gains, " << larAutoCorrMC->totalNumberOfConditions() << " conditions, key: " << m_store_key );
257  ATH_CHECK( detStore()->record(std::move(larAutoCorrMC),m_store_key) );
258  }
259 
260  return StatusCode::SUCCESS;
261 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:28
LArAutoCorrFromStdNtuple::m_store_key
std::string m_store_key
key of the LArAutoCorr collection in Storegate
Definition: LArAutoCorrFromStdNtuple.h:48
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
sFcalcovr
const float sFcalcovr[31][3]
Definition: LArAutoCorrFromStdNtuple.cxx:27
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
LArAutoCorrMC::initialize
virtual StatusCode initialize()
Initialization done after creation or read back - derived classes may augment the functionality.
Definition: LArAutoCorrMC.cxx:10
LArAutoCorrFromStdNtuple.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
LArAutoCorrFromStdNtuple::~LArAutoCorrFromStdNtuple
virtual ~LArAutoCorrFromStdNtuple()
LArFCAL_Base_ID::module
int module(const Identifier id) const
module [1,3]
LArAutoCorrComplete::set
void set(const HWIdentifier &CellID, int gain, const std::vector< float > &vAutoCorr)
Definition: LArAutoCorrComplete.cxx:13
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
LArAutoCorrFromStdNtuple::m_isComplete
bool m_isComplete
type
Definition: LArAutoCorrFromStdNtuple.h:52
HWIdentifier
Definition: HWIdentifier.h:13
LArOnlineID_Base::barrel_ec
int barrel_ec(const HWIdentifier id) const
Return the position barrel or endcap of a hardware cell identifier: barrel_ec = [0,...
Definition: LArOnlineID_Base.cxx:1942
LArConditionsContainer::nGains
unsigned int nGains() const
Number of gain values.
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
ReadCondHandle.h
CaloCell_ID.h
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
MonDataType::AutoCorr
@ AutoCorr
LArAutoCorrFromStdNtuple::initialize
virtual StatusCode initialize() override
implements IAlgorithm::initialize()
Definition: LArAutoCorrFromStdNtuple.cxx:76
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
LArConditionsContainer::totalNumberOfConditions
unsigned int totalNumberOfConditions() const
Statistics: total number of conditions.
LArAutoCorrFromStdNtuple::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Definition: LArAutoCorrFromStdNtuple.h:58
LArAutoCorrFromStdNtuple::m_root_file_names
std::vector< std::string > m_root_file_names
list of input ntuple file names
Definition: LArAutoCorrFromStdNtuple.h:44
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
maskDeadModules.mod
mod
Definition: maskDeadModules.py:36
LArOnlineID_Base::channel_range
id_range channel_range() const
Definition: LArOnlineID_Base.cxx:1936
LArAutoCorrFromStdNtuple::m_mcSymKey
SG::ReadCondHandleKey< LArMCSym > m_mcSymKey
Definition: LArAutoCorrFromStdNtuple.h:57
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
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
WritePulseShapeToCool.det
det
Definition: WritePulseShapeToCool.py:204
LArMCSym::ZPhiSymOnl
HWIdentifier ZPhiSymOnl(const HWIdentifier notSymOnlId) const
Find the symmetric HWID for an online channel identifier.
Definition: LArMCSym.h:91
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CaloCell_ID
Helper class for offline cell identifiers.
Definition: CaloCell_ID.h:34
LArAutoCorrFromStdNtuple::m_sFcal
bool m_sFcal
drop FCAL and change to sFCal
Definition: LArAutoCorrFromStdNtuple.h:54
LArAutoCorrComplete.h
CaloCondBlobAlgs_fillNoiseFromASCII.channelId
channelId
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:122
LArAutoCorrFromStdNtuple::m_ntuple_name
std::string m_ntuple_name
ntuple name
Definition: LArAutoCorrFromStdNtuple.h:46
AthAlgorithm
Definition: AthAlgorithm.h:47
LArAutoCorrFromStdNtuple::stop
virtual StatusCode stop() override
Definition: LArAutoCorrFromStdNtuple.cxx:85
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:194
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
LArAutoCorrMC.h
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
LArOnlineID
Definition: LArOnlineID.h:20
LArAutoCorrFromStdNtuple::LArAutoCorrFromStdNtuple
LArAutoCorrFromStdNtuple(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArAutoCorrFromStdNtuple.cxx:61
ReadOfcFromCool.nsamples
nsamples
Definition: ReadOfcFromCool.py:115
LArNewCalib_Delay_OFC_Cali.FT
FT
Definition: LArNewCalib_Delay_OFC_Cali.py:120
LArFCAL_ID.h
LArAutoCorrFromStdNtuple::m_groupingType
std::string m_groupingType
Grouping type.
Definition: LArAutoCorrFromStdNtuple.h:50
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
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
LArOnlineID_Base::channel_name
std::string channel_name(const HWIdentifier id) const
Return a string corresponding to a feedthrough name given an identifier.
Definition: LArOnlineID_Base.cxx:218
CaloGain.h
LArFCAL_ID
Helper class for LArFCAL offline identifiers.
Definition: LArFCAL_ID.h:60
updateCoolNtuple.limit
int limit
Definition: updateCoolNtuple.py:45
LArAutoCorrFromStdNtuple::m_nsamples
int m_nsamples
Definition: LArAutoCorrFromStdNtuple.h:42
CaloCell_ID::fcal_idHelper
const LArFCAL_ID * fcal_idHelper() const
access to FCAL idHelper
Definition: CaloCell_ID.h:75
LArOnlineID.h
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20