ATLAS Offline Software
Loading...
Searching...
No Matches
SCFillerTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include <sstream>
8
10#include "CaloEvent/CaloCell.h"
13
14#include <vector>
15#include <list>
16#include <map>
17#include <iostream>
18#include <cmath>
19
20#include "SCFillerTool.h"
21
22namespace D3PD {
23
24
32 (const std::string& type,
33 const std::string& name,
34 const IInterface* parent)
35 : BlockFillerTool<CaloCellContainer> (type, name, parent),
36 m_tableFilled(false),
37 m_caloEtaSelection( false ),
38 m_caloPhiSelection( false ),
39 m_caloLayerSelection( false ),
40 m_caloSelection( false ),
41 m_tileDLayerOption( false ) {
42
43 declareProperty( "CaloEtaCut", m_etaCut );
44 declareProperty( "CaloPhiCut", m_phiCut );
45 declareProperty( "CaloLayers", m_caloLayers );
46 // 1=EMB; 2=EMEC Outer Wheel; 3=EMEC Inner Wheel; 4=HEC; 5=FCAL; 6=Tile LB; 7=Tile EB
47 declareProperty( "CaloDetectors", m_caloNums );
48 declareProperty( "TileDLayerOption", m_tileDLayerOption);
49
50 SCFillerTool::book().ignore(); // Avoid coverity warnings.
51}
52
54
55 ServiceHandle<StoreGateSvc> detStore("DetectorStore", name());
56 CHECK( detStore.retrieve() ) ;
57
58 // CHECK ( detStore->retrieve(m_dd_man) );
59 CHECK ( detStore->retrieve(m_emid) );
60 CHECK ( detStore->retrieve(m_fcalid) );
61 CHECK ( detStore->retrieve(m_hecid) );
62 CHECK ( detStore->retrieve(m_tileid) );
63 CHECK ( detStore->retrieve(m_onlineHelper));
64
65 const unsigned int nSubCalo = 7; // static_cast< int >( CaloCell_ID::NSUBCALO );
66
67 //check calo number specified
68 m_caloSelection = false;
69 if( m_caloNums.size() == 0 ) {
70 ATH_MSG_INFO( " *** SCFillerTool: No calorimeter selection" );
71 return StatusCode::SUCCESS;
72 } else if( m_caloNums.size() > nSubCalo ) {
73 REPORT_MESSAGE( MSG::FATAL )
74 << " More than " << nSubCalo << " calo specified. "
75 << "Must be wrong. Stop.";
76 return StatusCode::FAILURE;
77 } else {
78 m_caloSelection = true;
79 for( unsigned int index = 0; index < m_caloNums.size(); ++index ) {
80 if( m_caloNums[ index ]> nSubCalo ) {
81 REPORT_MESSAGE( MSG::FATAL )
82 << "Invalid calo specification:"
83 << m_caloNums[index] << "Stop.";
84 return StatusCode::FAILURE;
85 } else {
86 ATH_MSG_INFO( "*** SCFillerTool: Select calorimeter " << m_caloNums[ index ] );
87 }
88 }
89 }
90
91 m_caloEtaSelection = false;
92 if ( m_etaCut.size() >0 ) {
93 if ( m_etaCut.size()== 2 && m_etaCut[0]<m_etaCut[1] ) {
94 REPORT_MESSAGE( MSG::INFO ) << "*** SCFillerTool: Eta Selection specified: " << m_etaCut[0] << ", " << m_etaCut[1];
96 } else {
97 REPORT_MESSAGE( MSG::FATAL ) << " *** SCFillerTool: Invalid Eta Cut Range specified: Abort!";
98 return StatusCode::FAILURE;
99 }
100 }
101
102 m_caloPhiSelection = false;
103 if ( m_phiCut.size() >0 ) {
104 if ( m_phiCut.size() == 2 && m_phiCut[0]<m_phiCut[1] ) {
105 REPORT_MESSAGE( MSG::INFO ) << "*** SCFillerTool: Phi Selection specified: " << m_phiCut[0] << ", " << m_phiCut[1];
106 m_caloPhiSelection = true;
107 } else {
108 REPORT_MESSAGE( MSG::FATAL ) << " *** SCFillerTool: Invalid Phi Cut Range specified: Abort!";
109 return StatusCode::FAILURE;
110 }
111 }
112
113 m_caloLayerSelection = false;
114 if ( m_caloLayers.size()>0 ) {
115 if ( m_caloLayers.size()>28 ) {
116 REPORT_MESSAGE( MSG::FATAL ) << " *** SCFillerTool: Invalid No. of Calo Layer selection: " << m_caloLayers.size() << " Abort!";
117 return StatusCode::FAILURE;
118 }
119 for( unsigned int j=0; j<m_caloLayers.size(); j++) {
120 if (m_caloLayers[j]>27 ) {
121 REPORT_MESSAGE( MSG::FATAL ) << " *** SCFillerTool: Invalid Calo Layer selection: " << m_caloLayers[j] << " Abort!";
122 return StatusCode::FAILURE;
123 }
124 }
126 }
127
128 ATH_CHECK( m_cablingKey.initialize() );
129
130 ATH_MSG_INFO( " *** SCFillerTool: completed" );
131 return StatusCode::SUCCESS;
132}
133
134
139{
140 CHECK( addVariable ("nSC", m_nSC ));
141 CHECK( addVariable ("E", m_E));
142 CHECK( addVariable ("eta", m_eta));
143 CHECK( addVariable ("phi", m_phi));
144 CHECK( addVariable ("Et", m_Et));
145 CHECK( addVariable ("calo", m_calo));
146 CHECK( addVariable ("region", m_region));
147 CHECK( addVariable ("sampling", m_sampling));
148 CHECK( addVariable ("ieta", m_ieta));
149 CHECK( addVariable ("jphi", m_jphi));
150 CHECK( addVariable ("hid", m_hashid));
151 CHECK( addVariable ("time", m_time));
152 CHECK( addVariable ("quality", m_quality));
153
154 return StatusCode::SUCCESS;
155}
156
157
167
168 if ( !m_tableFilled ) {
169 m_tableFilled = true;
172 ATH_MSG_INFO("**** after fillHashTables in first event");
173 }
174
176
177 typedef CaloCellContainer CONTAINER;
178 CONTAINER::const_iterator f_cell = p.begin();
179 CONTAINER::const_iterator l_cell = p.end();
180 for( ; f_cell != l_cell; ++f_cell ) {
181 const CaloCell* cell = ( *f_cell );
182 const Identifier id = cell->ID();
183 int scid = m_sc_hashTable[id];
184 m_sc_energy[scid] += cell->energy();
185 }
186
187 int nSC = 0;
188 std::vector<int>::iterator it;
189 it=m_sc_list.begin();
190 for ( ; it!=m_sc_list.end(); ++it ) {
191 int key = *it;
192 // int sc_hash = (sc_side << 28) | ( sc_calo << 24 ) | (sc_region << 20 ) | ( sc_layer << 16 ) | ( sc_ieta << 8 ) | ( sc_jphi );
193 int pn = ((key >> 28) & 0x1) ? 1: -1;
194 int calo = ((key >> 24) & 0xf)*pn;
195 int region = (key>>20) & 0xf;
196 unsigned int lay = (key>>16) & 0xf;
197 int ieta = (key>>8) & 0xff;
198 int jphi = key & 0xff;
199
200 float feta = m_sc_eta[key];
201 float fphi = m_sc_phi[key];
202 int lardet = abs((key >> 24) & 0xf);
203
204 if (m_caloSelection) {
205 std::vector< unsigned int >::const_iterator theFound =
206 std::find( m_caloNums.begin(), m_caloNums.end(), lardet );
207 if( theFound == m_caloNums.end() ) continue;
208 }
209 if ( m_caloEtaSelection ) {
210 if (feta<m_etaCut[0] || feta>m_etaCut[1]) continue;
211 }
212 if ( m_caloPhiSelection ) {
213 if (fphi<m_phiCut[0] || fphi>m_phiCut[1]) continue;
214 }
215 if ( m_caloLayerSelection ) {
216 bool tmp=false;
217 for( unsigned int j=0; j<m_caloLayers.size(); j++) {
218 if (m_caloLayers[j]==lay) tmp=true;
219 }
220 if (!tmp) continue;
221 }
222 nSC++;
223 m_E->push_back( m_sc_energy[ key ] );
224 m_calo->push_back( calo );
225 m_region->push_back( region );
226 m_sampling->push_back( lay );
227 m_ieta->push_back( ieta );
228 m_jphi->push_back( jphi );
229 m_hashid->push_back( key );
230 m_eta->push_back( feta );
231 m_phi->push_back( m_sc_phi[ key ] );
232 m_Et->push_back( m_sc_energy[key]/cosh( feta ) );
233 }
234 *m_nSC = nSC;
235
236 return StatusCode::SUCCESS;
237}
238
240 std::map<int,double>::iterator it;
241 it=m_sc_energy.begin();
242 for ( ; it!=m_sc_energy.end(); ++it ) {
243 (*it).second=0.0;
244 }
245}
246
247//---------------------------------------------------------------------------------
249//---------------------------------------------------------------------------------
250 typedef CaloCellContainer CONTAINER;
251 CONTAINER::const_iterator f_cell = p.begin();
252 CONTAINER::const_iterator l_cell = p.end();
253
254 for( ; f_cell != l_cell; ++f_cell ) {
255 const CaloCell* cell = ( *f_cell );
256 Identifier id = cell->ID();
257 int posneg = (cell->eta()>=0.0) ? 1: -1;
258 int sc_hash = m_sc_hashTable[ id ];
259 // m_sc_compId[sc_hash];
260 if ( posneg > 0 ) {
261 if ( m_emid->is_lar_em(id) ) {
262 if (m_emid->is_em_barrel(id) ) {
263 int ieta = m_emid->eta(id);
264 int jphi = m_emid->phi(id);
265 int lay = m_emid->sampling(id);
266 // int reg = m_emid->region(id);
267 std::cout << "SCFillerTool::dumpHashTables() [ONLY EM BARREL] ==> posneg,lay,ieta,jphi= " << posneg << ", " << lay << ", " << ieta << ", " << jphi << " ID: " << id << " sc_hash: " << sc_hash << std::endl;
268 }
269 }
270 }
271 }
272 std::map< int, std::vector<const CaloCell*> >::iterator it = m_sc_compId.begin();
273 for( ; it!=m_sc_compId.end(); ++it) {
274 int scID = (*it).first;
275 int key = scID;
276 std::vector<const CaloCell*> v = (*it).second;
277 int nl = v.size();
278 int pn = ((key >> 28) & 0x1) ? 1: -1;
279 int calo = ((key >> 24) & 0xf)*pn;
280 int region = (key>>20) & 0xf;
281 unsigned int lay = (key>>16) & 0xf;
282 int ieta = (key>>8) & 0xff;
283 int jphi = key & 0xff;
284 if (abs(calo)==1 && pn>0) {
285 std::cout << "SCFillerTool::dumpHashTables() ===> scID = " << scID << " calo,pn,region,lay,ieta,jphi: " << calo << ", " << pn << ", " << region << ", " << lay << ", " << ieta << ", " << jphi << std::endl;
286 std::cout << "SCFillerTool::dumpHashTables() ===> scID = " << scID << " No. of cells: " << nl << std::endl;
287 std::cout << "SCFillerTool::dumpHashTables() ===> " ;
288 for (const CaloCell* cell : v) {
289 std::cout << cell << ", " ;
290 }
291 std::cout << "" << std::endl;
292 }
293 }
294}
295
296//---------------------------------------------------------------------------------
298//---------------------------------------------------------------------------------
299 typedef CaloCellContainer CONTAINER;
300 CONTAINER::const_iterator f_cell = p.begin();
301 CONTAINER::const_iterator l_cell = p.end();
302
303 int /*posneg,*/reg,lay,ieta,jphi;
304 int sc_side, sc_calo, sc_region, sc_layer, sc_ieta, sc_jphi;
305 //float sc_feta, sc_fphi;
306
308
309 for( ; f_cell != l_cell; ++f_cell ) {
310 const CaloCell* cell = ( *f_cell );
311 Identifier id = cell->ID();
312 //posneg = (cell->eta()>=0.0) ? 1: -1;
313 sc_side = (cell->eta()>=0.0) ? 1: 0;
314 sc_ieta = -999;
315 sc_jphi = -999;
316 //sc_feta = 0.;
317 //sc_fphi = 0.;
318 sc_calo = -1;
319 sc_region = -1;
320 sc_layer = -1;
321
322 ieta = -999;
323 jphi = -999;
324
325 if ( m_emid->is_lar_em(id) ) {
326 ieta = m_emid->eta(id);
327 jphi = m_emid->phi(id);
328 lay = m_emid->sampling(id);
329 reg = m_emid->region(id);
330 sc_region = reg;
331 sc_layer = lay;
332 if (m_emid->is_em_barrel(id) ) {
333 sc_calo = 1;
334 if ( lay == 0 ) {
335 sc_ieta = int(ieta/4);
336 sc_jphi = jphi;
337 } else if ( lay == 1 ) {
338 sc_ieta = (reg==0) ? int(ieta/8) : 56+ieta;
339 sc_jphi = (reg==0) ? jphi: int(jphi/4);
340 } else if ( lay == 2 ) {
341 sc_ieta = (reg==0) ? ieta: 56 + ieta;
342 sc_jphi = int(jphi/4);
343 } else if ( lay == 3 ) {
344 sc_ieta = int(ieta/2);
345 sc_jphi = int(jphi/4);
346 }
347 } else if ( m_emid->is_em_endcap_outer(id) ) {
348 sc_calo = 2;
349 if ( lay == 0 ) {
350 sc_ieta = int(ieta/4);
351 sc_jphi = jphi;
352 sc_region = 1;
353 } else if (lay == 1) {
354 // sc_ieta = (reg<=1) ? 0 : ((reg==2) ? 1+int(ieta/8) : ((reg==3) ? 13+int(ieta/8) : ((reg==4) ? 19+int(ieta/4): 35)));
355 sc_ieta = (reg<=1) ? 0 : ((reg==2) ? 1+int(ieta/8) : ((reg==3) ? 13+int(ieta/4) : ((reg==4) ? 25+int(ieta/4): 41)));
356 sc_jphi = jphi;
357 sc_region = (reg<2) ? 0: reg-1;
358 } else if (lay==2) {
359 sc_ieta = (reg==0) ? 0 : 1+ieta;
360 sc_jphi = int(jphi/4);
361 sc_region = (ieta<3) ? 0: ((ieta<15) ? 1 : ((ieta<23) ? 2 : ((ieta<39) ? 3 : 4)));
362 } else if (lay==3) {
363 sc_ieta = int(ieta/2);
364 sc_jphi = int(jphi/4);
365 sc_region = (ieta<6) ? 1: ((ieta<10) ? 2 : ((ieta<18) ? 3: 4));
366 } else {
367 sc_ieta = -999;
368 sc_jphi = -999;
369 sc_region = -999;
370 }
371 } else if ( m_emid->is_em_endcap_inner(id) ) {
372 sc_calo = 3;
373 sc_ieta = (ieta<6) ? int(ieta/2) : 47;
374 sc_jphi = int(jphi/2);
375 sc_region = (ieta<6) ? 5 : 6;
376 }
377 } else if (m_hecid->is_lar_hec(id)) {
378 sc_layer = m_hecid->sampling(id);
379 sc_region = m_hecid->region(id);
380 sc_calo= 4;
381 ieta = m_hecid->eta(id);
382 jphi = m_hecid->phi(id);
383 sc_ieta = (sc_region==0) ? ieta : 10+ieta;
384 sc_jphi = jphi;
385 sc_region = 0;
386 } else if (m_fcalid->is_lar_fcal(id)) {
387 HWIdentifier hwid = cabling->createSignalChannelID( id );
388 sc_calo = 5;
389 const int lay = m_fcalid->module(id);
390 const int s = m_onlineHelper->slot(hwid);
391 const int c = m_onlineHelper->channel(hwid);
392 const int c64 = c%64;
393 sc_layer = lay;
394 if (lay==3) {
395 sc_ieta = 4-int((c%16)/4);
396 int jphip = 8*(s-14) + 3 + 4*int(c/64)-int(c64/16);
397 int jphin = 8*(s-14) + 7 - int(c/16);
398 sc_jphi = (sc_side)>0 ? jphip : jphin;
399 sc_region = 0;
400 } else if (lay==2) {
401 sc_ieta = ((c%32)<16 ? 4 : 8) - int((c%32)/4);
402 int jphip = 4*(s-10) + 1 + 2*int(c/64)-int(c64/32);
403 int jphin = ((s>=12) ? 14 -4*(s-12): 6 -4*(s-10) ) + int(c64/32) -2*int(c/64);
404 sc_jphi = (sc_side>0) ? jphip : jphin;
405 sc_region = 0;
406 } else if (lay==1) {
407 ieta = 15-int(c64%16) + 16*int(c64/16);
408 sc_ieta = int(ieta/4);
409 int jphip = int(c/64) + 2*(s- ((s==9) ? 2 : 1));
410 int jphin = ((s<5) ? 7 - 2*(s-1) : 15 - 2*(s-((s==9)?6:5))) - int(c/64);
411 sc_jphi = (sc_side>0) ? jphip : jphin;
412 if (c64<16) {
413 sc_region = 0;
414 } else if (c64>=16 && c64<32 ) {
415 sc_region = 1;
416 } else if (c64>=32 && c64<48 ) {
417 sc_region = 2;
418 } else {
419 sc_region = 3;
420 }
421 }
422 } else if (m_tileid->is_tile(id) ) {
423 sc_region = 0;
424 sc_layer = m_tileid->sampling(id);
425 sc_side = (m_tileid->side(id)>0) ? 1 : 0;
426 ieta = m_tileid->tower(id);
427 jphi = m_tileid->module(id);
428 sc_ieta = ieta;
429 sc_jphi = jphi;
430 if ( m_tileid->is_tile_barrel(id) )
431 sc_calo = 6;
432 if ( m_tileid->is_tile_extbarrel(id) )
433 sc_calo = 7;
434 }
435 if( sc_ieta<0 || sc_jphi<0 || sc_calo<=0 || sc_region<0 || sc_layer<0 ) continue;
436 // This is a kludge so that for HEC/Tile (sc_calo=4,6,7) the SC hash id don't have any layer information...(11/27/12)
437 if (sc_calo==4)
438 sc_layer = 0;
439 if (sc_calo==6 || sc_calo==7) {
440 if ( sc_layer!=2 || !m_tileDLayerOption)
441 sc_layer = 0;
442 }
443 int sc_hash = (sc_side << 28) | ( sc_calo << 24 ) | (sc_region << 20 ) | ( sc_layer << 16 ) | ( sc_ieta << 8 ) | ( sc_jphi );
444 m_sc_hashTable[ id ] = sc_hash;
445 m_sc_compId[sc_hash].push_back( cell );
446 }
447
448 std::map< int, std::vector<const CaloCell*> >::iterator it = m_sc_compId.begin();
449 for( ; it!=m_sc_compId.end(); ++it) {
450 int scID = (*it).first;
451 m_sc_list.push_back( scID );
452 std::vector<const CaloCell*> v = (*it).second;
453 int nl = v.size();
454 std::vector<const CaloCell*>::iterator vit;
455 /*
456 if ( ((scID >> 24) & 0xf) >= 6 ) {
457 std::cout << "*** KAKKA TILECAL: THIS IS A TILECAL SCELL hash= " << std::hex << scID << " no. of cells: " << nl << std::endl;
458 for( vit=v.begin(); vit!=v.end(); ++vit) {
459 std::cout << " " << (*vit)->ID() << " ";
460 }
461 std::cout << "" << std::endl;
462 for( vit=v.begin(); vit!=v.end(); ++vit) {
463 std::cout << " " << (*vit)->eta() << " ";
464 }
465 std::cout << "" << std::endl;
466 for( vit=v.begin(); vit!=v.end(); ++vit) {
467 std::cout << " " << (*vit)->phi() << " ";
468 }
469 std::cout << "" << std::endl;
470 }
471 */
472 double feta = 0;
473 double fphi = 0;
474 for( vit=v.begin(); vit!=v.end(); ++vit) {
475 feta += (*vit)->eta();
476 fphi += (*vit)->phi();
477 }
478 if (nl>0) {
479 feta /= nl;
480 fphi /= nl;
481 }
482 m_sc_eta[ scID ] = feta;
483 m_sc_phi[ scID ] = fphi;
484 } // for (; it!=m_sc_compId...)
485
486
487}
488
489
490} // namespace D3PD
491
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
Helpers for checking error return status codes and reporting errors.
#define REPORT_MESSAGE(LVL)
Report a message.
#define CHECK(...)
Evaluate an expression and check for errors.
Container class for CaloCell.
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
virtual StatusCode addVariable(const std::string &name, const std::type_info &ti, void *&ptr, const std::string &docstring="", const void *defval=0)
Type-safe wrapper for block filler tools.
std::map< const Identifier, int > m_sc_hashTable
std::map< int, double > m_sc_eta
std::map< int, std::vector< const CaloCell * > > m_sc_compId
virtual void fillHashTables(const CaloCellContainer &p)
std::vector< int > m_sc_list
std::vector< unsigned int > m_caloNums
std::vector< double > * m_E
virtual StatusCode fill(const CaloCellContainer &p)
Fill one block — type-safe version.
const TileID * m_tileid
virtual StatusCode book()
Book variables for this block.
std::vector< float > m_phiCut
std::vector< int > * m_jphi
int * m_nSC
parameters
std::vector< int > * m_region
std::vector< int > * m_hashid
std::vector< int > * m_ieta
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
const LArFCAL_ID * m_fcalid
const LArEM_ID * m_emid
std::vector< float > m_etaCut
const LArHEC_ID * m_hecid
std::vector< int > * m_calo
std::map< int, double > m_sc_phi
std::vector< double > * m_Et
std::vector< double > * m_quality
virtual void dumpHashTables(const CaloCellContainer &p)
std::map< int, double > m_sc_energy
std::vector< double > * m_eta
const LArOnlineID * m_onlineHelper
SCFillerTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
std::vector< unsigned int > m_caloLayers
virtual void resetEnergies()
virtual StatusCode initialize()
std::vector< double > * m_time
std::vector< double > * m_phi
std::vector< int > * m_sampling
Block filler tool for noisy FEB information.
Definition index.py:1