ATLAS Offline Software
Loading...
Searching...
No Matches
LArAutoCorrFromStdNtuple.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 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
62= default;
63
65{
66 ATH_CHECK ( m_mcSymKey.initialize() );
67 ATH_CHECK ( m_cablingKey.initialize() );
68
69 return StatusCode::SUCCESS ;
70}
71
72
74{
75
76 ATH_MSG_INFO ( "... in stop()" );
77
78 const EventContext& ctx = Gaudi::Hive::currentContext();
80
81 // get LArOnlineID helper
82 const LArOnlineID* onlineHelper = nullptr;
83 ATH_CHECK( detStore()->retrieve(onlineHelper, "LArOnlineID") );
84 // and helper for FCAL
85 const CaloCell_ID* idHelper = nullptr;
86 ATH_CHECK( detStore()->retrieve (idHelper, "CaloCell_ID") );
87 const LArFCAL_ID* fcal_id = idHelper->fcal_idHelper();
88
90 const LArOnOffIdMapping* cabling{*cablingHdl};
91 if(!cabling) {
92 ATH_MSG_ERROR( "Do not have mapping from cabling key " << m_cablingKey.key() );
93 return StatusCode::FAILURE;
94 }
95
96 TChain* outfit = new TChain(m_ntuple_name.value().c_str());
97 for (const std::string& s : m_root_file_names) {
98 outfit->Add(s.c_str());
99 }
100
101
102 Int_t det;
103 Int_t channelId;
104 Int_t FT, slot, channel;
105
106 Float_t covr[100]; // The function
107 Int_t gain = 0; // LARHIGHGAIN = 0, LARMEDIUMGAIN = 1, LARLOWGAIN = 2,
108
109 outfit->SetBranchAddress("channelId", &channelId);
110 outfit->SetBranchAddress("FT", &FT);
111 outfit->SetBranchAddress("slot", &slot);
112 outfit->SetBranchAddress("channel", &channel);
113 outfit->SetBranchAddress("detector", &det);
114 outfit->SetBranchAddress("gain", &gain);
115 outfit->SetBranchAddress("covr", covr);
116
117 // Create new LArAutocorrContainer
118 std::unique_ptr<LArAutoCorrComplete> larAutoCorrComplete;
119 std::unique_ptr<LArAutoCorrMC> larAutoCorrMC;
120
121 if(m_isComplete) {
122 larAutoCorrComplete = std::make_unique<LArAutoCorrComplete>();
123 ATH_CHECK( larAutoCorrComplete->setGroupingType(m_groupingType, msg()) );
124 ATH_CHECK( larAutoCorrComplete->initialize() );
125 } else {
126 larAutoCorrMC = std::make_unique<LArAutoCorrMC>();
127 ATH_CHECK( larAutoCorrMC->setGroupingType(m_groupingType, msg()) );
128 ATH_CHECK( larAutoCorrMC->initialize() );
129 }
130
131 typedef std::vector<float> AutoCorrVec;
132 std::map<std::pair<unsigned int,int>, AutoCorrVec> AutoCorr;
133 unsigned int hwid;
134 int nsamples=m_nsamples;
135 if(nsamples>100) nsamples=100;
136 ATH_MSG_INFO( "Using " << nsamples << " samples" );
137 // loop over entries in the Tuple, one entry = one channel
138 // first create a map from existing entries, will fill container later
139 Long64_t nentries = outfit->GetEntries();
140 for ( Long64_t iev = 0; iev < nentries; ++iev )
141 {
142 outfit->GetEvent(iev);
143 ATH_MSG_DEBUG ( " Chan " << std::hex << channelId << " det. "<< det << std::dec );
144
145 hwid = channelId;
146 HWIdentifier id(hwid);
147
148 if(FT != onlineHelper->feedthrough(id) || slot != onlineHelper->slot(id) || channel != onlineHelper->channel(id)) {
149 ATH_MSG_ERROR ( "Inconsistency in decoding HWID !!!!" );
150 ATH_MSG_ERROR ( FT << " - " << onlineHelper->feedthrough(id) );
151 ATH_MSG_ERROR ( slot << " - " << onlineHelper->slot(id) );
152 ATH_MSG_ERROR ( channel << " - " << onlineHelper->channel(id) );
153 continue;
154 }
155
156 if(!m_isComplete) {
157 if (id != mcsym->ZPhiSymOnl(id) ) {
158 ATH_MSG_DEBUG( "Symmetrized, not stored" );
159 continue;
160 }
161 }
162
163 AutoCorrVec av(nsamples);
164 for (int i = 0; i < nsamples; ++i ) {
165 av[i]=covr[i];
166 }
167
168 AutoCorr[{hwid,gain}]= std::move(av);
169
170 ATH_MSG_DEBUG ( "after reading size " << AutoCorr[std::make_pair(hwid,gain)].size() );
171
172 }
173
174 ATH_MSG_INFO ( "Ntuple read out, going to store. Have " << AutoCorr.size() << " numbers" );
175
176 // could fill only now
177 std::map<std::pair<unsigned int,int>, AutoCorrVec>::iterator ibeg = AutoCorr.begin();
178 std::map<std::pair<unsigned int,int>, AutoCorrVec>::iterator iend = AutoCorr.end();
179 unsigned int count=0;
180 for(;ibeg != iend; ++ibeg) {
181 ATH_MSG_DEBUG ( " Chan " << std::hex << (ibeg->first).first << std::dec );
182 if(m_sFcal) {
183 HWIdentifier id((ibeg->first).first);
184 // doesn't work:
185 //if(onlineHelper->isFCALchannel(id) && onlineHelper->feedthrough(id) == 6) {
186 if(onlineHelper->barrel_ec(id)==1 && onlineHelper->feedthrough(id) == 6) {
187 ATH_MSG_INFO ( "Not storing FCAL channel " << onlineHelper->channel_name(id) );
188 continue;
189 }
190 }
191
192 ATH_MSG_DEBUG( "Storing length " << (ibeg->second).size() );
193 if(!m_isComplete) {
194 larAutoCorrMC->set(HWIdentifier((ibeg->first).first),(ibeg->first).second, ibeg->second);
195 } else {
196 larAutoCorrComplete->set(HWIdentifier((ibeg->first).first),(ibeg->first).second, ibeg->second);
197 }
198 ++count;
199 }
200
201 ATH_MSG_INFO ( "Storing old values done...." << count << " values copied..." );
202
203 count = 0;
204 if(m_sFcal) { // now add sFcal
205 int limit = nsamples;
206 if(limit > 31) limit = 31;
207 AutoCorrVec myvec(limit);
208 ATH_MSG_INFO( "Using limit " << limit );
209 for (const HWIdentifier chid: onlineHelper->channel_range()) {
210 if(!m_isComplete) {
211 if (chid != mcsym->ZPhiSymOnl(chid) ) {
212 ATH_MSG_DEBUG( "Symmetrized, not stored" );
213 continue;
214 }
215 }
216 //if(onlineHelper->isFCALchannel(chid)) {
217 if(onlineHelper->barrel_ec(chid)==1 && onlineHelper->feedthrough(chid) >= 25 && onlineHelper->feedthrough(chid) < 28 ) {
218 ATH_MSG_DEBUG ( "Adding sFCAL channel " << onlineHelper->channel_name(chid) );
219 const int mod=fcal_id->module(cabling->cnvToIdentifier(chid));
220 if(mod<0 || mod > 3) {
221 ATH_MSG_ERROR ( "Wrong FCAL module: " << mod << " ignored !!" );
222 continue;
223 }
224 for(int mygain=0; mygain<3; ++mygain) {
225 for(int i=0;i<limit;++i) myvec[i]=sFcalcovr[i][mod-1];
226 if(m_isComplete) {
227 larAutoCorrComplete->set(chid,mygain,myvec);
228 } else {
229 larAutoCorrMC->set(chid,mygain,myvec);
230 }
231 }
232 ATH_MSG_DEBUG ( "sFcal storing size " << myvec.size() );
233 ++count;
234 }
235 }
236 ATH_MSG_INFO ( "Adding " << count << " sFcal values ..." );
237
238 }
239
240 if(m_isComplete) {
241 ATH_CHECK( detStore()->record(std::move(larAutoCorrComplete),m_store_key) );
242 } else {
243 ATH_MSG_INFO ( "Stored container " << larAutoCorrMC->nGains() << "gains, " << larAutoCorrMC->totalNumberOfConditions() << " conditions, key: " << m_store_key );
244 ATH_CHECK( detStore()->record(std::move(larAutoCorrMC),m_store_key) );
245 }
246
247 return StatusCode::SUCCESS;
248}
#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]
size_t size() const
Number of registered mappings.
const ServiceHandle< StoreGateSvc > & detStore() const
const_iterator begin() const
const_iterator end() 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
StringProperty m_groupingType
Grouping type.
StringProperty m_ntuple_name
ntuple name
virtual StatusCode stop() override
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
StringArrayProperty m_root_file_names
list of input ntuple file names
virtual ~LArAutoCorrFromStdNtuple()
StringProperty m_store_key
key of the LArAutoCorr collection in Storegate
BooleanProperty m_sFcal
drop FCAL and change to sFCal
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:148