ATLAS Offline Software
Loading...
Searching...
No Matches
TileMuonReceiverDecisionToNtuple.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5//*****************************************************************************
6// Filename : TileMuonReceiverDecisionToNtuple.cxx
7// Author : Joao Gentil Saraiva <jmendes@lxplus.cern.ch>
8// Created : April 2014
9//
10// DESCRIPTION:
11// Produce a simple output of a container into a ntuple
12//
13// HISTORY:
14//
15// BUGS:
16//
17//*****************************************************************************
18
19// Gaudi Includes
20#include "GaudiKernel/INTupleSvc.h"
21#include "GaudiKernel/IDataProviderSvc.h"
22#include "GaudiKernel/SmartDataPtr.h"
23
24// Atlas include
27
28// TileCal include
29//
31
32// header
33//
35
36// set a limit to the dimension of nt vectors
37//
38//const int max_inputs=128; // this is the maximum possible number of inputs for the
39 // current configuration of tile-d trigger i.e. 1 input per EB module (2x64)
40
41// Constructor
42TileMuonReceiverDecisionToNtuple::TileMuonReceiverDecisionToNtuple(const std::string& name, ISvcLocator* pSvcLocator)
43 : AthAlgorithm(name, pSvcLocator)
44 , m_ntuplePtr(0)
45 , m_ntupleID("TileMuRcvNt") // usualy it is a number hxxx, but here we use a name
46 , m_ntupleLoc("/FILE1")
47 , m_TileMuRcvContainer("TileMuRcvCnt")
48{
49 declareProperty("TileMuonReceiverContainer" , m_TileMuRcvContainer);
50 declareProperty("NTupleLoc" , m_ntupleLoc);
51 declareProperty("NTupleID" , m_ntupleID);
52 declareProperty("NDecisionBits" , m_nBits=4);
53 declareProperty("NMaxTrigInputs" , m_nMaxTrigInputs=128);
54}
55
56
57// Destructor
61
62
63
64// Initialize
65//
67{
68 ATH_MSG_INFO( "TileMuonReceiverDecisionToNtuple::initialize begins" );
69
70 m_ntupleLoc="/NTUPLES" + m_ntupleLoc;
71
72 SmartDataPtr<NTuple::Directory> DirPtr(ntupleSvc(), m_ntupleLoc);
73
74 if(!DirPtr) DirPtr=ntupleSvc()->createDirectory(m_ntupleLoc);
75 if(!DirPtr) {
76 ATH_MSG_ERROR( "Invalid Ntuple Directory: " );
77 return StatusCode::FAILURE;
78 }
79
80 m_ntuplePtr=ntupleSvc()->book(DirPtr.ptr(), m_ntupleID,
81 CLID_ColumnWiseTuple, "Tile Muon Receiver Ntuple");
82 // if(!m_ntuplePtr) {
83
84 // std::string ntupleCompleteID=m_ntupleLoc+"/"+m_ntupleID;
85
86 // NTuplePtr nt(ntupleSvc(),ntupleCompleteID);
87 // if (!nt) {
88 // ATH_MSG_ERROR( "Failed to book or to retrieve ntuple "
89 // << ntupleCompleteID );
90 // return StatusCode::FAILURE;
91 // } else {
92 // ATH_MSG_INFO( "Reaccessing ntuple " << ntupleCompleteID );
93 // m_ntuplePtr = nt;
94 // }
95 // }
96
97 //
98 // The container has an object for each module in a extended barrel partition. Are expected 128 entries per event.
99 //
100 // For each entry i will have :
101 // - thresholds (?) 4 (Global will be equal for all entries) | one vector for each event -> 128 id's
102 // - decision ... NTuple::Matrix ?
103 // - d6 energy, d6 time
104 // d5+d6 energy, d5+d6 time | one vector combines each qty for each id -> NTuple::Array for ech qty
105 // - id mod and part | id is a convoluted number combining part and mod eg 356 part:3 mod:56 -> NTuple::Array for ech qty
106 //
107
108 CHECK ( m_ntuplePtr->addItem("TileMuRcv/nTrigInputs" , m_nTrigInput,0,m_nMaxTrigInputs) );
109 CHECK ( m_ntuplePtr->addItem("TileMuRcv/trigThr_Hi_D5andD6" , m_thershold_hi_d5andd6) );
110 CHECK ( m_ntuplePtr->addItem("TileMuRcv/trigThr_Lo_D5andD6" , m_thershold_lo_d5andd6) );
111 CHECK ( m_ntuplePtr->addItem("TileMuRcv/trigThr_Hi_D6" , m_thershold_hi_d6) );
112 CHECK ( m_ntuplePtr->addItem("TileMuRcv/trigThr_Lo_D6" , m_thershold_lo_d6) );
113 CHECK ( m_ntuplePtr->addItem("TileMuRcv/t_D5andD6" , m_nTrigInput, m_time_D5andD6) );
114 CHECK ( m_ntuplePtr->addItem("TileMuRcv/t_D6" , m_nTrigInput, m_time_D6) );
115 CHECK ( m_ntuplePtr->addItem("TileMuRcv/e_D5andD6" , m_nTrigInput, m_energy_D5andD6) );
116 CHECK ( m_ntuplePtr->addItem("TileMuRcv/e_D6" , m_nTrigInput, m_energy_D6) );
117 CHECK ( m_ntuplePtr->addItem("TileMuRcv/mod" , m_nTrigInput, m_module) );
118 CHECK ( m_ntuplePtr->addItem("TileMuRcv/part" , m_nTrigInput, m_partition) );
119 CHECK ( m_ntuplePtr->addItem("TileMuRcv/d_tile2tgcSL_bit0" , m_nTrigInput, m_trigbit0) );
120 CHECK ( m_ntuplePtr->addItem("TileMuRcv/d_tile2tgcSL_bit1" , m_nTrigInput, m_trigbit1) );
121 CHECK ( m_ntuplePtr->addItem("TileMuRcv/d_tile2tgcSL_bit2" , m_nTrigInput, m_trigbit2) );
122 CHECK ( m_ntuplePtr->addItem("TileMuRcv/d_tile2tgcSL_bit3" , m_nTrigInput, m_trigbit3) );
123
124
125 // ATH_MSG_INFO( "Initialization completed" );
126 return StatusCode::SUCCESS;
127}
128
129// execute
131{
132 // step1: read container and declare temporary vectors
133 //
134 const TileMuonReceiverContainer *TileMuRcvCnt = nullptr;
135 CHECK( evtStore()->retrieve(TileMuRcvCnt, m_TileMuRcvContainer) );
136
137 // step2: to fill items in ntuple
138 //
141
142 ATH_MSG_INFO("Size of the container " << TileMuRcvCnt->size() );
143
144 if (it!=end){
145 // the first entry in the container are the thresholds and was wrote like that to avoid
146 // replicating this information in every element of the collection so to avoid other errors
147 //
148 const std::vector<float> & thresh = (*it)->GetThresholds();
149 ++it;
150
151 if (thresh.size()==4){
152 ATH_MSG_VERBOSE( " thresholds: "<< thresh[0] <<" "<< thresh[1] <<" "<< thresh[2] <<" "<< thresh[3] );
153 m_thershold_hi_d5andd6 = thresh[0];
154 m_thershold_lo_d5andd6 = thresh[1];
155 m_thershold_hi_d6 = thresh[2];
156 m_thershold_lo_d6 = thresh[3];
157 } else {
158 ATH_MSG_WARNING( " unexpected thresholds vector size: "<< thresh.size());
159 m_thershold_hi_d5andd6 = -1000.;
160 m_thershold_lo_d5andd6 = -1000.;
161 m_thershold_hi_d6 = -1000.;
162 m_thershold_lo_d6 = -1000.;
163 }
164 } else {
165 ATH_MSG_DEBUG( " no thresholds available" );
166 m_thershold_hi_d5andd6 = -1000.;
167 m_thershold_lo_d5andd6 = -1000.;
168 m_thershold_hi_d6 = -1000.;
169 m_thershold_lo_d6 = -1000.;
170 }
171
172 m_nTrigInput=0;
173
174 for(; it != end; ++it) {
175
177 ATH_MSG_WARNING(" Number of input objects exceeds max size = " << m_nMaxTrigInputs);
178 break;
179 }
180
181 const TileMuonReceiverObj * obj = (*it);
182
183 // going over the collection of inputs to the L1Muon
184 //
185 // (1) ID
186
187 int id = obj->GetID();
188 int part = id/100;
189 int module = id - 100*part;
191 m_module[m_nTrigInput] = module;
192 if (id>0) {
193 ATH_MSG_DEBUG( " index: " << m_nTrigInput << " id: " << id << " - " << ((part<4)?"EBA":"EBC") << " " << module);
194 } else {
195 ATH_MSG_WARNING( " index: " << m_nTrigInput << " unexpected id: " << id);
196 }
197
198 // (2) Energy
199
200 const std::vector<float> & ene = obj->GetEne();
201
202 if (ene.size()==2){
203 ATH_MSG_VERBOSE( " energy: " << ene[0] << " " << ene[1]);
205 m_energy_D6[m_nTrigInput] = ene[1];
206 } else {
207 ATH_MSG_WARNING( " unexpected energy vector size: " << ene.size());
209 m_energy_D6[m_nTrigInput] = -1000.;
210 }
211
212 // (3) Time d6:t1+t2/2 d5+d6:t1+t2+t3+t4/4
213
214 const std::vector<float> & time = obj->GetTime();
215
216 if (time.size()==2){
217 ATH_MSG_VERBOSE(" time: " << time[0] << " " << time[1] );
218 m_time_D5andD6[m_nTrigInput] = time[0];
219 m_time_D6[m_nTrigInput] = time[1];
220 } else {
221 ATH_MSG_WARNING(" unexpected time vector size: " << time.size());
223 m_time_D6[m_nTrigInput] = -1000.;
224 }
225
226 // (4) decision
227
228 const std::vector<bool> & decision = obj->GetDecision();
229
230 if (decision.size()==4){
231 ATH_MSG_DEBUG( " decision: "<< decision[0] <<" "<< decision[1] <<" "<< decision[2] <<" "<< decision[3]) ;
232 m_trigbit0[m_nTrigInput] = decision[0]; // d5+d6 hi
233 m_trigbit1[m_nTrigInput] = decision[1]; // d5+d6 lo
234 m_trigbit2[m_nTrigInput] = decision[2]; // d6 hi
235 m_trigbit3[m_nTrigInput] = decision[3]; // d6 lo is this right? Ie d6 lo is 0?
236 } else {
237 ATH_MSG_WARNING( " unexpected decision vector size: "<< decision.size()) ;
238 m_trigbit0[m_nTrigInput] = false;
239 m_trigbit1[m_nTrigInput] = false;
240 m_trigbit2[m_nTrigInput] = false;
241 m_trigbit3[m_nTrigInput] = false;
242 }
243
244 m_nTrigInput++;
245 }
246
247 ATH_MSG_INFO(" Number of inputs " << m_nTrigInput);
248
249 // step3: commit ntuple
250 //
251 CHECK( ntupleSvc()->writeRecord(m_ntuplePtr) );
252
253 // Execution completed.
254 //
255 ATH_MSG_DEBUG( "execute() completed successfully" );
256 return StatusCode::SUCCESS;
257}
258
259// finalize
261{
262 ATH_MSG_INFO( "finalize() successfully" );
263 return StatusCode::SUCCESS;
264}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
INTupleSvc * ntupleSvc()
TileContainer< TileMuonReceiverObj > TileMuonReceiverContainer
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
const_iterator begin() const noexcept
size_type size() const noexcept
TileMuonReceiverDecisionToNtuple(const std::string &name, ISvcLocator *pSvcLocator)