ATLAS Offline Software
Loading...
Searching...
No Matches
LArAutoCorrFromStdNtuple.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
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
27const 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
61LArAutoCorrFromStdNtuple::LArAutoCorrFromStdNtuple (const std::string& name, ISvcLocator* pSvcLocator) : AthAlgorithm(name, pSvcLocator)
62{
63 declareProperty("Nsamples", m_nsamples=7);
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{
78 ATH_CHECK ( m_mcSymKey.initialize() );
79 ATH_CHECK ( m_cablingKey.initialize() );
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 ) {
177 av[i]=covr[i];
178 }
179
180 AutoCorr[{hwid,gain}]= std::move(av);
181
182 ATH_MSG_DEBUG ( "after reading size " << AutoCorr[std::make_pair(hwid,gain)].size() );
183
184 }
185
186 ATH_MSG_INFO ( "Ntuple read out, going to store. Have " << AutoCorr.size() << " numbers" );
187
188 // could fill only now
189 std::map<std::pair<unsigned int,int>, AutoCorrVec>::iterator ibeg = AutoCorr.begin();
190 std::map<std::pair<unsigned int,int>, AutoCorrVec>::iterator iend = AutoCorr.end();
191 unsigned int count=0;
192 for(;ibeg != iend; ++ibeg) {
193 ATH_MSG_DEBUG ( " Chan " << std::hex << (ibeg->first).first << std::dec );
194 if(m_sFcal) {
195 HWIdentifier id((ibeg->first).first);
196 // doesn't work:
197 //if(onlineHelper->isFCALchannel(id) && onlineHelper->feedthrough(id) == 6) {
198 if(onlineHelper->barrel_ec(id)==1 && onlineHelper->feedthrough(id) == 6) {
199 ATH_MSG_INFO ( "Not storing FCAL channel " << onlineHelper->channel_name(id) );
200 continue;
201 }
202 }
203
204 ATH_MSG_DEBUG( "Storing length " << (ibeg->second).size() );
205 if(!m_isComplete) {
206 larAutoCorrMC->set(HWIdentifier((ibeg->first).first),(ibeg->first).second, ibeg->second);
207 } else {
208 larAutoCorrComplete->set(HWIdentifier((ibeg->first).first),(ibeg->first).second, ibeg->second);
209 }
210 ++count;
211 }
212
213 ATH_MSG_INFO ( "Storing old values done...." << count << " values copied..." );
214
215 count = 0;
216 if(m_sFcal) { // now add sFcal
217 int limit = nsamples;
218 if(limit > 31) limit = 31;
219 AutoCorrVec myvec(limit);
220 ATH_MSG_INFO( "Using limit " << limit );
221 for (const HWIdentifier chid: onlineHelper->channel_range()) {
222 if(!m_isComplete) {
223 if (chid != mcsym->ZPhiSymOnl(chid) ) {
224 ATH_MSG_DEBUG( "Symmetrized, not stored" );
225 continue;
226 }
227 }
228 //if(onlineHelper->isFCALchannel(chid)) {
229 if(onlineHelper->barrel_ec(chid)==1 && onlineHelper->feedthrough(chid) >= 25 && onlineHelper->feedthrough(chid) < 28 ) {
230 ATH_MSG_DEBUG ( "Adding sFCAL channel " << onlineHelper->channel_name(chid) );
231 const int mod=fcal_id->module(cabling->cnvToIdentifier(chid));
232 if(mod<0 || mod > 3) {
233 ATH_MSG_ERROR ( "Wrong FCAL module: " << mod << " ignored !!" );
234 continue;
235 }
236 for(int mygain=0; mygain<3; ++mygain) {
237 for(int i=0;i<limit;++i) myvec[i]=sFcalcovr[i][mod-1];
238 if(m_isComplete) {
239 larAutoCorrComplete->set(chid,mygain,myvec);
240 } else {
241 larAutoCorrMC->set(chid,mygain,myvec);
242 }
243 }
244 ATH_MSG_DEBUG ( "sFcal storing size " << myvec.size() );
245 ++count;
246 }
247 }
248 ATH_MSG_INFO ( "Adding " << count << " sFcal values ..." );
249
250 }
251
252 if(m_isComplete) {
253 ATH_CHECK( detStore()->record(std::move(larAutoCorrComplete),m_store_key) );
254 } else {
255 ATH_MSG_INFO ( "Stored container " << larAutoCorrMC->nGains() << "gains, " << larAutoCorrMC->totalNumberOfConditions() << " conditions, key: " << m_store_key );
256 ATH_CHECK( detStore()->record(std::move(larAutoCorrMC),m_store_key) );
257 }
258
259 return StatusCode::SUCCESS;
260}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
const float sFcalcovr[31][3]
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
MsgStream & msg() const
Helper class for offline cell identifiers.
Definition CaloCell_ID.h:34
const LArFCAL_ID * fcal_idHelper() const
access to FCAL idHelper
Definition CaloCell_ID.h:75
virtual StatusCode stop() override
std::string m_ntuple_name
ntuple name
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
bool m_sFcal
drop FCAL and change to sFCal
LArAutoCorrFromStdNtuple(const std::string &name, ISvcLocator *pSvcLocator)
std::string m_groupingType
Grouping type.
std::vector< std::string > m_root_file_names
list of input ntuple file names
std::string m_store_key
key of the LArAutoCorr collection in Storegate
virtual ~LArAutoCorrFromStdNtuple()
virtual StatusCode initialize() override
implements IAlgorithm::initialize()
SG::ReadCondHandleKey< LArMCSym > m_mcSymKey
Helper class for LArFCAL offline identifiers.
Definition LArFCAL_ID.h:49
int feedthrough(const HWIdentifier id) const
Return the feedthrough of a hardware cell identifier : feedthrough = [0,31] Barrel - A/C side or H/...
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...
int barrel_ec(const HWIdentifier id) const
Return the position barrel or endcap of a hardware cell identifier: barrel_ec = [0,...
id_range channel_range() const
int channel(const HWIdentifier id) const
Return the channel number of a hardware cell identifier channel = [0,127] in all FEB.
std::string channel_name(const HWIdentifier id) const
Return a string corresponding to a feedthrough name given an identifier.
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146