diff --git a/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/CaloDetMgrDetDescrCnv/CaloCellVolumes.h b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/CaloDetMgrDetDescrCnv/CaloCellVolumes.h new file mode 100755 index 0000000000000000000000000000000000000000..0e3a0a2d24d4b8d99513f6c4de26dffd49dd15f1 --- /dev/null +++ b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/CaloDetMgrDetDescrCnv/CaloCellVolumes.h @@ -0,0 +1,57 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef CALOCELLVOLUMES_H +#define CALOCELLVOLUMES_H + +#include <vector> +#include <string> +#include <map> +#include "Identifier/Identifier.h" + +class CaloCell_ID; +class ISvcLocator; + +/** This class is a modification of LArDetDescr/LArCellVolumes. + Presently it provides volumes for LAr cells only. + +*/ + +struct CaloCellVolume +{ + Identifier channelID; + float volume; +}; + +typedef std::vector<CaloCellVolume> CaloCellVolumeVector; + +class CaloCellVolumes +{ +public: + + // Constructors: + CaloCellVolumes(ISvcLocator* svcLocator); + virtual ~CaloCellVolumes(); + + double CellVolume(Identifier cell_id); + inline std::string layout() { return geometryLayout; } + + // For FCAL cell volumes which are calculated on the fly + double getFcalTubeSpacing(int sampling); + + virtual void print(); + +private: + const CaloCell_ID* m_calocell_id ; + ISvcLocator* m_svcLocator; + CaloCellVolumeVector m_cellVolumes; + std::string geometryLayout; + + // map fcal samplings on tube spacings + typedef std::map<int, double, std::less<int> > TubeSpacingMap; + TubeSpacingMap m_fcalTubeSpacings; +}; + + +#endif diff --git a/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/CaloDetMgrDetDescrCnv/CaloMgrDetDescrCnv.h b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/CaloDetMgrDetDescrCnv/CaloMgrDetDescrCnv.h new file mode 100755 index 0000000000000000000000000000000000000000..da91f247c491eca0064b8590168ca497744c67b6 --- /dev/null +++ b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/CaloDetMgrDetDescrCnv/CaloMgrDetDescrCnv.h @@ -0,0 +1,30 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef CALODETMGRDETDESCRCNV_CALODETMGRDETDESCRCNV_H +#define CALODETMGRDETDESCRCNV_CALODETMGRDETDESCRCNV_H + +#include "DetDescrCnvSvc/DetDescrConverter.h" + +class CaloMgrDetDescrCnv: public DetDescrConverter { + friend class CnvFactory<CaloMgrDetDescrCnv>; + +public: + virtual long int repSvcType() const; + virtual StatusCode initialize(); + virtual StatusCode finalize(); + virtual StatusCode createObj(IOpaqueAddress* pAddr, DataObject*& pObj); + + // Storage type and class ID (used by CnvFactory) + static long storageType(); + static const CLID& classID(); + +protected: + CaloMgrDetDescrCnv(ISvcLocator* svcloc); + +private: + +}; + +#endif diff --git a/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/CaloDetMgrDetDescrCnv/CaloSuperCellMgrDetDescrCnv.h b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/CaloDetMgrDetDescrCnv/CaloSuperCellMgrDetDescrCnv.h new file mode 100755 index 0000000000000000000000000000000000000000..4c756547df909605b01a469c7f57832f371ebe26 --- /dev/null +++ b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/CaloDetMgrDetDescrCnv/CaloSuperCellMgrDetDescrCnv.h @@ -0,0 +1,124 @@ +// This file's extension implies that it's C, but it's really -*- C++ -*-. + +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// $Id$ +/** + * @file CaloDetMgrDetDescrCnv/CaloSuperCellMgrDetDescrCnv.h + * @author scott snyder <snyder@bnl.gov> + * @date Aug, 2012 + * @brief Converter for CaloSuperCellMgrDetDescrCnv. + * Creates the supercell geometry from the offline geometry. + */ + + +#ifndef CALODETMGRDETDESCRCNV_CALOSUPERCELLMGRDETDESCRCNV_H +#define CALODETMGRDETDESCRCNV_CALOSUPERCELLMGRDETDESCRCNV_H + + +#include "DetDescrCnvSvc/DetDescrConverter.h" +#include "GaudiKernel/ToolHandle.h" +class CaloSuperCellDetDescrManager; +class CaloDetDescrManager; +class CaloDetDescrElement; +class ICaloSuperCellIDTool; +class ICaloSuperCellAlignTool; + + +/** + * @brief Converter for CaloSuperCellMgrDetDescrCnv. + * + * This class is a converter for CaloSuperCellDetDescrManager which is + * stored in the detector store. + * + * It creates the supercell geometry based on the offline geometry, + * which should already be available in the detector store. + * + * First, we use the identifier information to create the descriptors + * and elements, then call the update* methods below to initialize + * the geometry information from the offline geometry. The update + * methods may be called again if the offline geometry changes + * (due to alignment changes). + */ +class CaloSuperCellMgrDetDescrCnv + : public DetDescrConverter +{ + friend class CnvFactory<CaloSuperCellMgrDetDescrCnv>; + +public: + /// Standard Gaudi initialize method. + virtual StatusCode initialize(); + + /// Standard Gaudi finalize method. + virtual StatusCode finalize(); + + + /** + * @brief Return the service type. Required by the base class. + */ + virtual long int repSvcType() const; + + + /** + * @brief Called by the converter infrastructure to create an object. + * @param pAddr Address of the object to create. + * @param pObj[out] Set to a reference to the created helper. + */ + virtual StatusCode createObj(IOpaqueAddress* pAddr, DataObject*& pObj); + + /// Storage type and class ID (used by CnvFactory) + static long storageType(); + + + /** + * @brief Return the CLID of the class we create. + * Required by the converter infrastructure. + */ + static const CLID& classID(); + + +protected: + /** + * @brief Constructor. + * @param clid The CLID if the class we're constructing. + * @param svcloc Gaudi service locator. + */ + CaloSuperCellMgrDetDescrCnv(ISvcLocator* svcloc); + +private: + /// offline <> SC mapping tool. + ToolHandle<ICaloSuperCellIDTool> m_scidtool; + + /// Supercell alignment tool. + ToolHandle<ICaloSuperCellAlignTool> m_scAlignTool; + + + /** + * @brief Create the manager object. + * @param helperKey StoreGate key of the manager. + * @param idhelper[out] Set to a pointer to the new manager. + * @param pObj[out] Set to a reference to the created manager. + */ + StatusCode createManager (const std::string& mgrKey, + CaloSuperCellDetDescrManager* & mgr, + DataObject*& pObj); + + + /** + * @brief Create the descriptors for the supercell geometry. + * @param mgr The supercell geometry manager. + */ + StatusCode createDescriptors (CaloSuperCellDetDescrManager* mgr); + + + /** + * @brief Create the elements for the supercell geometry. + * @param mgr The supercell geometry manager. + */ + StatusCode createElements (CaloSuperCellDetDescrManager* mgr); +}; + + +#endif // CALODETMGRDETDESCRCNV_CALOSUPERCELLMGRDETDESCRCNV_H diff --git a/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/CaloDetMgrDetDescrCnv/CaloTTMgrDetDescrCnv.h b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/CaloDetMgrDetDescrCnv/CaloTTMgrDetDescrCnv.h new file mode 100755 index 0000000000000000000000000000000000000000..53c7fca9f894338015ed4c1257a7782d5abd0a43 --- /dev/null +++ b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/CaloDetMgrDetDescrCnv/CaloTTMgrDetDescrCnv.h @@ -0,0 +1,58 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/*************************************************************************** + Calo Trigger Tower Manager converter package + -------------------------------------------- + Copyright (C) 2003 by ATLAS Collaboration + ***************************************************************************/ + +//<doc><file> $Id: CaloTTMgrDetDescrCnv.h,v 1.7 2008-12-14 01:56:04 ssnyder Exp $ +//<version> $Name: not supported by cvs2svn $ + +#ifndef CALODETMGRDETDESCRCNV_CALOTTMGRDETDESCRCNV_H +# define CALODETMGRDETDESCRCNV_CALOTTMGRDETDESCRCNV_H + +//<<<<<< INCLUDES >>>>>> + +#include "DetDescrCnvSvc/DetDescrConverter.h" + + +/** + * @brief This class is a converter for the CaloTTDescrManager which is + * stored in the detector store. + * + * This class derives from DetDescrConverter which is a converter of the DetDescrCnvSvc. + * This converter creates a manager object and adds descriptors and + * detector elements to the manager. This objects are either created + * or accessed from the detector store. + * + * @warning The hadronic part of the FCAL calorimeter calorimeter is constructed + * with 4 channels in eta. These 4 channels actually correspond to 2 channels in eta + * FOR EACH of the hadronic samplings, i.e. FCAL2 and FCAL3. Therefore the geometry + * of these channels is wrong. + */ + +class CaloTTMgrDetDescrCnv: public DetDescrConverter { + friend class CnvFactory<CaloTTMgrDetDescrCnv>; + +public: + virtual long int repSvcType() const; + virtual StatusCode initialize(); + virtual StatusCode finalize(); + virtual StatusCode createObj(IOpaqueAddress* pAddr, DataObject*& pObj); + + // Storage type and class ID (used by CnvFactory) + static long storageType(); + static const CLID& classID(); + +protected: + CaloTTMgrDetDescrCnv(ISvcLocator* svcloc); + +private: + +}; + + +#endif // CALODETMGRDETDESCRCNV_CALOTTMGRDETDESCRCNV_H diff --git a/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/cmt/requirements b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/cmt/requirements new file mode 100755 index 0000000000000000000000000000000000000000..5ceaa051d06fadf94664e8845eaef965f96b421d --- /dev/null +++ b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/cmt/requirements @@ -0,0 +1,46 @@ +package CaloDetMgrDetDescrCnv + +author Claire Bourdarios <Claire.Bourdarios@cern.ch> + +use AtlasPolicy AtlasPolicy-* +use GaudiInterface GaudiInterface-* External +use DetDescrCnvSvc DetDescrCnvSvc-* DetectorDescription +use Identifier Identifier-* DetectorDescription + +apply_pattern declare_joboptions files="*.py" +apply_pattern declare_python_modules files="*.py" + +apply_pattern component_library +library CaloDetMgrDetDescrCnv *.cxx + +private +use AtlasBoost AtlasBoost-* External +use SGTools SGTools-* Control +use StoreGate StoreGate-* Control +use AthenaKernel AthenaKernel-* Control + +use GeoModelInterfaces GeoModelInterfaces-* DetectorDescription/GeoModel +use GeoModelUtilities GeoModelUtilities-* DetectorDescription/GeoModel +use RDBAccessSvc RDBAccessSvc-* Database/AthenaPOOL + +use LArTools LArTools-* LArCalorimeter +use LArReadoutGeometry LArReadoutGeometry-* LArCalorimeter/LArGeoModel + +use TileDetDescr TileDetDescr-* TileCalorimeter + +use CaloDetDescr CaloDetDescr-* Calorimeter +use CaloTTDetDescr CaloTTDetDescr-* Calorimeter +use CaloIdentifier CaloIdentifier-* Calorimeter +use CaloTriggerTool CaloTriggerTool-* Calorimeter + + +private +use TestPolicy TestPolicy-* +use TestTools TestTools-* AtlasTest -no_auto_imports + + +apply_pattern athenarun_test \ + name="CaloSuperCellMgrDetDescrCnv_test" \ + options="CaloDetMgrDetDescrCnv/CaloSuperCellMgrDetDescrCnv_test.py" \ + pre_script="../cmt/setup.sh" \ + post_script="${TESTTOOLSROOT}/share/post.sh CaloSuperCellMgrDetDescrCnv_test $(q)[0-9] [A-Z]+ 20[123][0-9]|Reading file|^CORAL/Services/ConnectionService (Info|Warning)|^RelationalDatabase Info|^Data source lookup|^CORAL/RelationalPlugins/frontier Info|^PluginManager Info|^RalSessionMgr Warning|^EventInfoMgtInit: Got release|^TEnvRec::ChangeValue|being retired|including file|Deaccess DbDatabase|File version|Global positioning|^Domain|duplicate entry|already loaded|RootDbase: all good|frontier.c|^Py:ConfigurableDb +(WARNING|INFO)|ApplicationMgr +INFO|INFO [sS]top|EndcapDMConstru.*INFO|^[^ ]+ +INFO|XMLFileCatalog Info|^RalSessionMgr Info$(q)" diff --git a/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/doc/MainPage.h b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/doc/MainPage.h new file mode 100644 index 0000000000000000000000000000000000000000..3e4bf1e3e8ffb534c43581d9f7010e0e7616b87e --- /dev/null +++ b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/doc/MainPage.h @@ -0,0 +1,29 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/** + + +@mainpage + +The package includes converters for the following managers: CaloDetDescrManager, CaloTTDescrManager. + +1. CaloMgrDetDescrCnv. This is a converter which builds Calo DD elements and descriptors and +ultimately stores them into CaloDetDescrManager. The LAr Calo DD elements and descriptors +are built using LArReadoutGeometry objects and the Tile Calo DD elements and descriptors are +simply copied from TileDetDescrManager to CaloDetDescrManager, because these objects are created +by TileGeoModel. + +2. CaloTTMgrDetDescrCnv. This class derives from DetDescrConverter which is a converter of the DetDescrCnvSvc. +This converter creates a manager object and adds descriptors and detector elements to the manager. This objects are either created +or accessed from the detector store. + +-------------------------------- + REQUIREMENTS +-------------------------------- + +@include requirements +@htmlinclude used_packages.html + +*/ diff --git a/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/python/CaloDetMgrDDCnv.py b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/python/CaloDetMgrDDCnv.py new file mode 100755 index 0000000000000000000000000000000000000000..5e3b352abc2e4a7cc6b81e7096a099b165b12060 --- /dev/null +++ b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/python/CaloDetMgrDDCnv.py @@ -0,0 +1,12 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +# +# Joboptions for the loading of the of CaloDetDescrMgr +# + +from DetDescrCnvSvc.DetDescrCnvSvcConf import DetDescrCnvSvc +DetDescrCnvSvc = DetDescrCnvSvc() +DetDescrCnvSvc.DetectorManagers += [ "CaloMgr" ] +DetDescrCnvSvc.DetectorManagers += [ "CaloTTMgr" ] + + diff --git a/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/python/__init__.py b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/python/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..b50ea153f0f49dfa670401b616e7ada79f1f0032 --- /dev/null +++ b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/python/__init__.py @@ -0,0 +1,3 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +__author__ = 'Vakho Tsulaia' diff --git a/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/share/CaloDetMgrDetDescrCnv_joboptions.py b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/share/CaloDetMgrDetDescrCnv_joboptions.py new file mode 100755 index 0000000000000000000000000000000000000000..86440c297e8faccada3980aa7ae699f796e9b467 --- /dev/null +++ b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/share/CaloDetMgrDetDescrCnv_joboptions.py @@ -0,0 +1,15 @@ +print "now executing CaloDetMgrDetDescrCnv_CaloDetDescrCnv" +# +# Joboptions for the loading of the of CaloDetDescrMgr +# + +theApp.Dlls += [ "CaloDetMgrDetDescrCnv" ] + +DetDescrCnvSvc = Service( "DetDescrCnvSvc" ) +DetDescrCnvSvc.DetectorManagers += [ "CaloMgr" ] +DetDescrCnvSvc.DetectorManagers += [ "CaloTTMgr" ] +include( "CaloConditions/CaloConditions_jobOptions.py" ) + +# must be included once only : +include.block ("CaloDetMgrDetDescrCnv/CaloDetDescr_joboptions.py") + diff --git a/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/share/CaloSuperCellMgrDetDescrCnv_test.py b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/share/CaloSuperCellMgrDetDescrCnv_test.py new file mode 100644 index 0000000000000000000000000000000000000000..9aab4863510842b770386f0fe4a7f489ab916f25 --- /dev/null +++ b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/share/CaloSuperCellMgrDetDescrCnv_test.py @@ -0,0 +1,315 @@ +# $Id$ +# +# @file CaloTriggerTool/share/CaloSuperCellMgrDetDescrCnv_test.py +# @author scott snyder <snyder@bnl.gov> +# @date Sep, 2012 +# @brief Regression tests for CaloSuperCellMgrDetDescrCnv. +# + +# Work around strange Gaudi problem: if we defer this until later, we get +# this in the log: +# Error in <TCint::AutoLoad>: failure loading library libGaudiKernelDict for class StatusCode +# +import PyCintex +import ROOT +ROOT.StatusCode + +from AthenaCommon.DetFlags import DetFlags +DetFlags.detdescr.LAr_setOn() +DetFlags.detdescr.Tile_setOn() + + +import sys +import string +from AtlasGeoModel import SetGeometryVersion +from AtlasGeoModel import GeoModelInit +from AtlasGeoModel import SetupRecoGeometry +include( "CaloConditions/CaloConditions_jobOptions.py" ) +include( "TileIdCnv/TileIdCnv_jobOptions.py" ) + +from GeoModelSvc.GeoModelSvcConf import GeoModelSvc +ServiceMgr += GeoModelSvc() +theApp.CreateSvc += [ "GeoModelSvc"] +from AtlasGeoModel import LArGM +from AtlasGeoModel import TileGM + +from IOVDbSvc.IOVDbSvcConf import IOVDbSvc +IOVDbSvc().GlobalTag = 'OFLCOND-SDR-BS14T-IBL-06' + + +from AthenaPython import PyAthena +from AthenaCommon.AlgSequence import AlgSequence +topSequence = AlgSequence() + +TILE = PyAthena.CaloCell_ID.TILE +LARFCAL = PyAthena.CaloCell_ID.LARFCAL + + +def toiter (range): + beg = range.begin() + end = range.end() + while beg != end: + yield beg.__deref__() + beg.__preinc__() + return + + +def get_descriptors (reg_id, mgr): + if not mgr.getCaloCell_ID().is_tile (reg_id): + return [mgr.get_descriptor (reg_id)] + out = [] + for d in mgr.tile_descriptors_range(): + if d.identify() == reg_id: + out.append (d) + return out + + +class CaloSuperCellDetDescrManagerCnvTest (PyAthena.Alg): + def __init__ (self, name): + PyAthena.Alg.__init__ (self, name) + return + + + def initialize (self): + sg = PyAthena.py_svc('StoreGateSvc') + ds = PyAthena.py_svc('DetectorStore') + self.idol_helper = ds['CaloCell_ID'] + self.idsc_helper = ds['CaloCell_SuperCell_ID'] + self.tool = PyAthena.py_tool ('CaloSuperCellIDTool', + iface='ICaloSuperCellIDTool') + self.mgrol = ds['CaloMgr'] + self.mgrsc = ds['CaloSuperCellMgr'] + return 1 + + + def execute (self): + for d in toiter (self.mgrsc.calo_descriptors_range()): + if not d: continue #xxx + self.dump_descriptor (d) + print + for d in toiter (self.mgrsc.tile_descriptors_range()): + if not d: continue #xxx + self.dump_descriptor (d) + print + self.dump_tile_cells() + self.dump_fcal_cells() + return 1 + + + def dump_descriptor (self, desc, f = sys.stdout): + idsc = self.idsc_helper + idol = self.idol_helper + mgrol = self.mgrol + + id = desc.identify() + idlist = self.tool.superCellToOfflineRegion (id) + + + def pr_line (typ, d): + print >> f, '%s %2d ' % (typ, d.calo_hash().value()), + return + + def posneg_or_side (id, helper): + if helper.is_tile(id): + return helper.side(id) + return helper.pos_neg(id) + def sampling_or_sample (id, helper): + if helper.is_tile(id): + return helper.sample(id) + return helper.sampling(id) + def region_or_section (id, helper): + if helper.is_tile(id): + return helper.section(id) + return helper.region(id) + def pr_id (typ, d, helper): + pr_line (typ, d) + print >> f, ('subcal %d BE %2d samp %d reg %d sc/sg/ly/sm %d/%2d/%d/%d flgs %d%d%d%d%d%d%d%d' % + (helper.sub_calo(id), + posneg_or_side(id, helper), + sampling_or_sample(id, helper), + region_or_section(id, helper), + d.getSubCalo(), + d.calo_sign(), + d.layer(), + d.getSampling(), + d.is_lar_em(), + d.is_lar_em_barrel(), + d.is_lar_em_endcap(), + d.is_lar_em_endcap_inner(), + d.is_lar_em_endcap_outer(), + d.is_lar_hec(), + d.is_lar_fcal(), + d.is_tile(), + )) + return + + + def pr_etaphi (typ, d, helper): + pr_line (typ, d) + print >> f, ('calo_eta %7.4f %7.4f calo_phi %7.4f %7.4f de/p %7.4f %7.4f' % + (d.calo_eta_min(), + d.calo_eta_max(), + d.calo_phi_min(), + d.calo_phi_max(), + d.deta(), + d.dphi(), + )) + return + + def pr_rz (typ, d, helper): + pr_line (typ, d) + print >> f, ('calo_r %7.2f %7.2f calo_z %8.2f %8.2f ne/p %3d %3d' % + (d.calo_r_min(), + d.calo_r_max(), + d.calo_z_min(), + d.calo_z_max(), + d.n_eta(), + d.n_phi(), + )) + return + + def pr_lar (typ, d, helper): + pr_line (typ, d) + print >> f, ('lar %7.4f %7.4f %7.4f %7.4f' % + (d.reg_min(), + d.reg_max(), + d.lar_eta_min(), + d.lar_phi_min(), + )) + return + + + def pr_depth (typ, d, helper): + pr_line (typ, d) + def get_depth (which): + v = getattr (PyAthena, 'vector<double>')() + getattr(d, 'get_depth_' + which)(v) + return '[' + string.join (['%7.2f' % x for x in v], ',') + ']' + print >> f, ('depth %d %s %s' % + (d.n_calo_depth(), + get_depth('in'), + get_depth('out'))) + return + + + def pr_xform (typ, d, helper): + pr_line (typ, d) + xf = d.transform() + r = xf.rotation() + t = xf.translation() + ea = r.eulerAngles (2, 0, 2) + ss = ('xform %f %f %f %f %f %f' % + (ea[0], ea[1], ea[2], + t[0], t[1], t[2])) + print >> f, ss.replace ('-0.000000', '0.000000') + return + + + def pr (func): + func ('SC', desc, idsc) + descs = [] + for olid in idlist: + descs += get_descriptors (olid, self.mgrol) + for d in descs: + func ('OL', d, idol) + return + + pr (pr_id) + pr (pr_etaphi) + pr (pr_rz) + pr (pr_lar) + pr (pr_depth) + pr (pr_xform) + return + + + def dump_tile_cells1 (self, mgr, idhelper): + i1 = 0 + i2 = 0 + i3 = 0 + i4 = 0 + for id in toiter (idhelper.cell_range (TILE)): + i1 += 1 + if idhelper.module(id) != 0: continue + i2 += 1 + if idhelper.side(id) < 0: continue + i3 += 1 + if idhelper.sample(id) not in [0, 2]: continue + i4 += 1 + e = mgr.get_element(id) + print '%d %2d %d %d %f %f %f %f' % \ + (idhelper.section(id), \ + idhelper.tower(id), \ + idhelper.sample(id), \ + e.getSampling(), \ + e.eta(), \ + e.phi(), \ + e.deta(), \ + e.dphi()) + print i1, i2, i3, i4 + return + + + def dump_tile_cells (self): + print + print 'Supercell tiles' + self.dump_tile_cells1 (self.mgrsc, self.idsc_helper) + print + print 'Offline tiles' + self.dump_tile_cells1 (self.mgrol, self.idol_helper) + return + + + def print_fcal_cell (self, tag, id, mgr, idhelper): + elt = mgr.get_element (id) + print '%2s %2d %1d %2d %5.1f %5.1f %7.1f %5.1f %5.1f %5.1f %5.2f %5.2f %5.2f %5.2f' % \ + (tag, + idhelper.pos_neg(id), + idhelper.module(id), + idhelper.eta(id), + elt.x(), + elt.y(), + elt.z(), + elt.dx(), + elt.dy(), + elt.dz(), + elt.eta(), + elt.phi(), + elt.deta(), + elt.dphi()) + return + + + def dump_fcal_cells (self): + print + print 'FCAL cells' + + idsc_helper = self.idsc_helper.fcal_idHelper() + idol_helper = self.idol_helper.fcal_idHelper() + + for id in toiter (self.idsc_helper.cell_range (LARFCAL)): + if idsc_helper.phi(id) != 1: continue + self.print_fcal_cell ('SC', id, self.mgrsc, idsc_helper) + idlist = self.tool.superCellToOfflineID (id) + for id_ol in idlist: + self.print_fcal_cell (' ', id_ol, self.mgrol, idol_helper) + pass + + + + +alg = CaloSuperCellDetDescrManagerCnvTest('test') +topSequence += [alg] +theApp.EvtMax = 1 + + +# For when testing by hand. +def init(): + theApp.initialize() + theApp.nextEvent() + global sg, ds, m, mm + sg = PyAthena.py_svc('StoreGateSvc') + ds = PyAthena.py_svc('DetectorStore') + mm=ds['CaloMgr'] + m=ds['CaloSuperCellMgr'] + return diff --git a/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/share/CaloTTDetMgrDetDescrCnv_joboptions.py b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/share/CaloTTDetMgrDetDescrCnv_joboptions.py new file mode 100755 index 0000000000000000000000000000000000000000..0702e4e862f40762b74c17e074ecc0e8de6a853b --- /dev/null +++ b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/share/CaloTTDetMgrDetDescrCnv_joboptions.py @@ -0,0 +1,10 @@ +# +# Joboptions for the loading of the of CaloTTDetDescrMgr +# + +theApp.Dlls += [ "CaloDetMgrDetDescrCnv" ] + +DetDescrCnvSvc = Service( "DetDescrCnvSvc" ) +DetDescrCnvSvc.DetectorManagers += [ "CaloTTMgr" ] +include( "CaloConditions/CaloConditions_jobOptions.py" ) + diff --git a/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/src/CaloCellVolumes.cxx b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/src/CaloCellVolumes.cxx new file mode 100755 index 0000000000000000000000000000000000000000..f1da5f340f63fffa6611700a03970da0af517f07 --- /dev/null +++ b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/src/CaloCellVolumes.cxx @@ -0,0 +1,196 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "CaloDetMgrDetDescrCnv/CaloCellVolumes.h" + +#include "Identifier/Identifier.h" +#include "CaloIdentifier/CaloIdManager.h" +#include "CaloIdentifier/CaloCell_ID.h" + +#include "GaudiKernel/ISvcLocator.h" +#include "GeoModelInterfaces/IGeoModelSvc.h" +#include "GeoModelUtilities/DecodeVersionKey.h" + +#include "RDBAccessSvc/IRDBAccessSvc.h" +#include "RDBAccessSvc/IRDBRecordset.h" +#include "RDBAccessSvc/IRDBRecord.h" + +#include <iostream> +#include <iomanip> +#include <algorithm> + + +struct CaloCellVolume_Compare +{ + bool operator() (const CaloCellVolume& a, const CaloCellVolume& b) + { return a.channelID < b.channelID; } + bool operator() (const CaloCellVolume& a, Identifier b) + { return a.channelID < b; } +}; + + +CaloCellVolumes::CaloCellVolumes(ISvcLocator* svcLocator): + m_svcLocator(svcLocator) +{ + // default values for tube spacings + m_fcalTubeSpacings[1] = 7.5; + m_fcalTubeSpacings[2] = 8.179; + m_fcalTubeSpacings[3] = 9.; + + // Get Id Helper + m_calocell_id = CaloIdManager::instance()->getCaloCell_ID(); + + //Get pointers to the IGeoModelSvc and IRDBAccessSvc + IGeoModelSvc* geoModelSvc = 0; + IRDBAccessSvc* rdbAccessSvc = 0; + + StatusCode sc = m_svcLocator->service("GeoModelSvc",geoModelSvc); + + if(sc.isFailure()) + throw std::runtime_error("CaloCellVolumes error: cannot access GeoModelSvc"); + + sc = m_svcLocator->service("RDBAccessSvc",rdbAccessSvc); + if(sc.isFailure()) + throw std::runtime_error("CaloCellVolumes error: cannot access RDBAccessSvc"); + + DecodeVersionKey detectorKey = DecodeVersionKey(geoModelSvc,"LAr"); + rdbAccessSvc->connect(); + + IRDBRecordset_ptr cellVolRec = rdbAccessSvc->getRecordsetPtr("LArCellVolumes",detectorKey.tag(),detectorKey.node()); + if(cellVolRec->size()==0) + { + cellVolRec = rdbAccessSvc->getRecordsetPtr("LArCellVolumes","LArCellVolumes-00"); + if(cellVolRec->size()==0) + { + rdbAccessSvc->disconnect(); + throw std::runtime_error("CaloCellVolumes error: 0 size of LArCellVolumes recordset"); + } + } + + // get fcal tube spacings + IRDBRecordset_ptr fcalModRec = rdbAccessSvc->getRecordsetPtr("FCalMod",detectorKey.tag(),detectorKey.node()); + if(fcalModRec->size()==0) + fcalModRec = rdbAccessSvc->getRecordsetPtr("FCalMod","FCalMod-00"); + + for(unsigned int i=0; i<fcalModRec->size(); i++) + { + const IRDBRecord* rec = (*fcalModRec)[i]; + m_fcalTubeSpacings[rec->getInt("FCALSAMPLING")] = rec->getDouble("TUBESPACING"); + } + + std::string LArTag = rdbAccessSvc->getChildTag("LAr",detectorKey.tag(),detectorKey.node()); + + geometryLayout = "Atlas"; + if(LArTag.find("H8")!=std::string::npos) + geometryLayout = "H8"; + else if(LArTag.find("H6")!=std::string::npos) + geometryLayout = "H6"; + else if(LArTag.find("G3")!=std::string::npos) + geometryLayout = "G3"; + + rdbAccessSvc->disconnect(); + + // Initialize m_cellVolumes vector + for(unsigned int ind = 0; ind < cellVolRec->size(); ind++) + { + const IRDBRecord* currentRec = (*cellVolRec)[ind]; + + int subcalo = currentRec->getInt("SUBCALO"); + int posneg = currentRec->getInt("POSNEG"); + int sampling = currentRec->getInt("SAMPLING"); + int region = currentRec->getInt("REGION"); + int eta = currentRec->getInt("ETA"); + int phi = currentRec->getInt("PHI"); + + Identifier channelID; + if(geometryLayout != "H6" || subcalo == CaloCell_ID::LARFCAL) { + channelID = m_calocell_id->cell_id (subcalo, posneg, sampling, region, eta, phi); + } else { + Identifier reg_id = m_calocell_id->region_id(subcalo, posneg, sampling, region); + int phimin = m_calocell_id->phi_min(reg_id); + channelID = m_calocell_id->cell_id (subcalo, posneg, sampling, region, eta, phimin); + } + + CaloCellVolume cellVol; + cellVol.channelID = channelID; + cellVol.volume = currentRec->getDouble("VOLUME"); + m_cellVolumes.push_back(cellVol); + } + + std::sort (m_cellVolumes.begin(), m_cellVolumes.end(), + CaloCellVolume_Compare()); + +} + +CaloCellVolumes::~CaloCellVolumes() +{ + m_cellVolumes.clear(); +} + +double CaloCellVolumes::CellVolume(Identifier cell_id) +{ + if (m_cellVolumes.size()==0) + std::cerr << "CaloCellVolumes::CellVolume(). Problem in CaloCellVolumes: no cell volumes...\n"; + else + { + // compute Identifier of Cell with same eta, but phi=0 and pos side + // (except for fcal) + Identifier volId; + + if (!m_calocell_id->is_fcal(cell_id)) + { + int subCalo = m_calocell_id->sub_calo(cell_id); + int posneg = std::abs (m_calocell_id->pos_neg(cell_id)); + int sampling = m_calocell_id->sampling(cell_id); + int region = m_calocell_id->region(cell_id); + int eta = m_calocell_id->eta(cell_id); + + if(geometryLayout != "H6") { + volId = m_calocell_id->cell_id(subCalo, posneg, sampling, region, eta, 0); + } else { + Identifier reg_id = m_calocell_id->region_id(subCalo, posneg, sampling, region); + int phimin = m_calocell_id->phi_min(reg_id); + volId = m_calocell_id->cell_id(subCalo, posneg, sampling, region, eta, phimin); + } + } + else + volId = cell_id; + + CaloCellVolumeVector::const_iterator it = + std::lower_bound (m_cellVolumes.begin(), m_cellVolumes.end(), volId, + CaloCellVolume_Compare()); + if (it != m_cellVolumes.end() && it->channelID == volId) + return it->volume; + } + + return 0.; +} + +void CaloCellVolumes::print () +{ + if (m_cellVolumes.size()==0) + std::cerr << "CaloCellVolumes::print(). No cell volumes...\n"; + else + { + std::cout << "CaloCellVolumes::print(). Number of volumes found: " + << m_cellVolumes.size(); + + for(unsigned int i = 0; i<m_cellVolumes.size(); i++) + { + const CaloCellVolume vol = m_cellVolumes[i]; + m_calocell_id->print( (Identifier) vol.channelID ); + std::cout<<m_calocell_id->show_to_string( (Identifier) vol.channelID ); + std::cout << " ==> vol= " << vol.volume << " mm3\n"; + } + } +} + +double CaloCellVolumes::getFcalTubeSpacing(int sampling) +{ + TubeSpacingMap::const_iterator it = m_fcalTubeSpacings.find(sampling); + if(it==m_fcalTubeSpacings.end()) + throw std::runtime_error("CaloCellVolumes::getFcalTubeSpacing error: wrong sampling provided"); + + return (*it).second; +} diff --git a/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/src/CaloDetMgrDetDescrCnv_entries.cxx b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/src/CaloDetMgrDetDescrCnv_entries.cxx new file mode 100755 index 0000000000000000000000000000000000000000..45302aa83a09af75afd1e263e74b9b9d2a747338 --- /dev/null +++ b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/src/CaloDetMgrDetDescrCnv_entries.cxx @@ -0,0 +1,24 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +//==================================================================== + +//<doc><file> $Id: CaloDetMgrDetDescrCnv_entries.cxx,v 1.6 2007-01-11 14:53:05 tsulaia Exp $ +//<version> $Name: not supported by cvs2svn $ + + +#include "GaudiKernel/DeclareFactoryEntries.h" +#include "CaloDetMgrDetDescrCnv/CaloMgrDetDescrCnv.h" +#include "CaloDetMgrDetDescrCnv/CaloTTMgrDetDescrCnv.h" +#include "CaloDetMgrDetDescrCnv/CaloSuperCellMgrDetDescrCnv.h" + +DECLARE_CONVERTER_FACTORY(CaloTTMgrDetDescrCnv) +DECLARE_CONVERTER_FACTORY(CaloMgrDetDescrCnv) +DECLARE_CONVERTER_FACTORY(CaloSuperCellMgrDetDescrCnv) + +DECLARE_FACTORY_ENTRIES ( CaloDetMgrDetDescrCnv ) { + DECLARE_CONVERTER ( CaloMgrDetDescrCnv ); + DECLARE_CONVERTER ( CaloTTMgrDetDescrCnv ); + DECLARE_CONVERTER ( CaloSuperCellMgrDetDescrCnv ) +} diff --git a/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/src/CaloDetMgrDetDescrCnv_load.cxx b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/src/CaloDetMgrDetDescrCnv_load.cxx new file mode 100755 index 0000000000000000000000000000000000000000..b6234b45b396ebce61fcc6844ed63f15af5f8481 --- /dev/null +++ b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/src/CaloDetMgrDetDescrCnv_load.cxx @@ -0,0 +1,12 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + + +//<doc><file> $Id: CaloDetMgrDetDescrCnv_load.cxx,v 1.1 2003-04-18 17:07:53 schaffer Exp $ +//<version> $Name: not supported by cvs2svn $ +//==================================================================== + +#include "GaudiKernel/LoadFactoryEntries.h" + +LOAD_FACTORY_ENTRIES( CaloDetMgrDetDescrCnv ) diff --git a/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/src/CaloMgrDetDescrCnv.cxx b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/src/CaloMgrDetDescrCnv.cxx new file mode 100755 index 0000000000000000000000000000000000000000..b599030451d85118cc5e30f83610ac6ff1cbada6 --- /dev/null +++ b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/src/CaloMgrDetDescrCnv.cxx @@ -0,0 +1,824 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "CaloDetMgrDetDescrCnv/CaloMgrDetDescrCnv.h" +#include "CaloDetMgrDetDescrCnv/CaloCellVolumes.h" + +#include "DetDescrCnvSvc/DetDescrConverter.h" +#include "DetDescrCnvSvc/DetDescrAddress.h" +#include "GaudiKernel/MsgStream.h" +#include "GaudiKernel/CnvFactory.h" +#include "StoreGate/StoreGate.h" + +#include "CaloDetDescr/CaloDetDescrManager.h" +#include "CaloDetDescr/CaloDetectorElements.h" +#include "CaloDetDescr/CaloDescriptors.h" +#include "CaloDetDescr/CaloDetDescrElementContainer.h" + +#include "LArReadoutGeometry/LArDetectorManager.h" + +#include "LArReadoutGeometry/EMBCell.h" +#include "LArReadoutGeometry/EMBDetectorRegion.h" +#include "LArReadoutGeometry/EMBDetDescr.h" +#include "LArReadoutGeometry/EMBDetectorManager.h" + +#include "LArReadoutGeometry/EMECCell.h" +#include "LArReadoutGeometry/EMECDetectorRegion.h" +#include "LArReadoutGeometry/EMECDetDescr.h" +#include "LArReadoutGeometry/EMECDetectorManager.h" + +#include "LArReadoutGeometry/HECCell.h" +#include "LArReadoutGeometry/HECDetectorRegion.h" +#include "LArReadoutGeometry/HECDetDescr.h" +#include "LArReadoutGeometry/HECDetectorManager.h" + +#include "LArReadoutGeometry/FCALTile.h" +#include "LArReadoutGeometry/FCALModule.h" +#include "LArReadoutGeometry/FCALDetectorManager.h" + +#include "CaloIdentifier/CaloCell_ID.h" +#include "CaloIdentifier/CaloIdManager.h" + +#include "TileDetDescr/TileDetDescrManager.h" + +long int CaloMgrDetDescrCnv::repSvcType() const +{ + return storageType(); +} + +StatusCode CaloMgrDetDescrCnv::initialize() +{ + StatusCode sc = DetDescrConverter::initialize(); + MsgStream log(messageService(), "CaloMgrDetDescrCnv"); + if (log.level()<=MSG::DEBUG) log << MSG::DEBUG << "in initialize" << endreq; + + if (sc.isFailure()) + { + log << MSG::ERROR << "DetDescrConverter::initialize failed" << endreq; + return sc; + } + + return StatusCode::SUCCESS; +} + +StatusCode CaloMgrDetDescrCnv::finalize() +{ + MsgStream log(messageService(), "CaloMgrDetDescrCnv"); + if (log.level()<=MSG::DEBUG) log << MSG::DEBUG << "in finalize" << endreq; + + return StatusCode::SUCCESS; +} + +StatusCode CaloMgrDetDescrCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj) +{ + MsgStream log(messageService(), "CaloMgrDetDescrCnv"); + log << MSG::INFO << "in createObj: creating a Calo Detector Manager object in the detector store" << endreq; + + bool debug = log.level()<=MSG::DEBUG; + + DetDescrAddress* ddAddr; + ddAddr = dynamic_cast<DetDescrAddress*> (pAddr); + if(!ddAddr) { + log << MSG::FATAL << "Could not cast to DetDescrAddress." << endreq; + return StatusCode::FAILURE; + } + + std::string mgrKey = *(ddAddr->par()); + if (debug) + { + if ("" == mgrKey) + log << MSG::DEBUG << "No Manager key " << endreq; + else + log << MSG::DEBUG << "Manager key is " << mgrKey << endreq; + } + + // --- --- Get CaloCell_ID and CaloIdManager helpers --- --- + StoreGateSvc * detStore; + StatusCode status = serviceLocator()->service("DetectorStore", detStore); + if (status.isFailure()) + { + log << MSG::FATAL << "DetectorStore service not found !" << endreq; + return StatusCode::FAILURE; + } + + const CaloCell_ID* cell_id; + status = detStore->retrieve(cell_id, "CaloCell_ID"); + if (status.isFailure()) + { + log << MSG::FATAL << "Could not get CaloCell_ID helper !" << endreq; + return status; + } + else + log << MSG::DEBUG << " Found the CaloCell_ID helper. " << endreq; + + const CaloIdManager* caloId_mgr; + status = detStore->retrieve(caloId_mgr, "CaloIdManager"); + if (status.isFailure()) + { + log << MSG::ERROR << "Could not get CaloIdManager helper !" << endreq; + return status; + } + else + if (debug) log << MSG::DEBUG << " Found the CaloIdManager helper. " << endreq; + // --- --- Get CaloCell_ID and CaloIdManager helpers --- --- + + // --- --- Create CaloDetDescrManager object --- --- + CaloDetDescrManager* caloMgr = new CaloDetDescrManager(); + pObj = StoreGateSvc::asStorable(caloMgr); + + // set helpers + caloMgr->set_helper(cell_id); + caloMgr->set_helper(caloId_mgr); + + caloMgr->initialize(); + // --- --- Create CaloDetDescrManager object --- --- + + // Cell volumes + CaloCellVolumes cellVol (serviceLocator()); + + // geometry layout + caloMgr->set_lar_geometry(cellVol.layout()); + + //unsigned int idhash; + IdentifierHash min; + IdentifierHash max; + + const LArEM_ID* em_id = caloId_mgr->getEM_ID(); + const LArHEC_ID* hec_id = caloId_mgr->getHEC_ID(); + const LArFCAL_ID* fcal_id = caloId_mgr->getFCAL_ID(); + + // Create Calo Detector Elements + + // Check whether we are working with Test Beam geometry + bool isTestBeam = false; + const LArDetectorManager* larMgr = 0; + status = detStore->retrieve(larMgr); + if(status.isFailure() || larMgr==0) + log << MSG::WARNING << "Could not get LArDetectorManager. Assuming TestBeam=false" << endreq; + else + isTestBeam = larMgr->isTestBeam(); + + // **************************************************************** + // ** --- --- EMB --- --- ** + // **************************************************************** + + // --- Retrieve Emec Detector Manager + const EMBDetectorManager* embManager = 0; + status = detStore->retrieve(embManager); + if(status.isFailure()) + { + log << MSG::WARNING << "Could not get the EMBDetectorManager. No Calo Elements will be built for EMB" << endreq; + } + else + { + // --- --- Iterate over EMB regions and cells --- --- + EMBDetectorManager::DetectorRegionConstIterator embregIt; + + for (embregIt=embManager->beginDetectorRegion(); embregIt!=embManager->endDetectorRegion(); embregIt++) + { + const EMBDetectorRegion *embRegion = *embregIt; + + // *** *** Create descriptor for this region *** *** + // Region identifier. + // Do some mapping between LArReadoutGeometry and CaloID + + int barrel_ec = 0; + switch(embRegion->getEndcapIndex()) + { + case EMBDetectorRegion::NEG: + { + barrel_ec = -1; // negative side + break; + } + case EMBDetectorRegion::POS: + { + barrel_ec = 1; // positive side + break; + } + default: + { + log << MSG::ERROR << "Wrong Side Index for EMB region " << embRegion->getEndcapIndex() << endreq; + return StatusCode::FAILURE; + } + } + + Identifier regId = em_id->region_id(barrel_ec, + embRegion->getSamplingIndex(), + embRegion->getRegionIndex()); + + EMBDescriptor* embDescr = new EMBDescriptor(regId,(AtlasDetectorID *)cell_id,cell_id,embRegion); + caloMgr->add(embDescr); + + double phi_min = 0.; + double z_min = 10000.; + double z_max = -10000.; + double r_min = 10000.; + double r_max = -10000.; + + double reg_min = 10000.; + double reg_max = -10000.; + + std::vector<double> depth_in; + std::vector<double> depth_out; + + // *** *** Create descriptor for this region *** *** + + // + // *** *** *** Iterate over cells *** *** *** + // + for (unsigned int iPhi=embRegion->beginPhiIndex();iPhi<embRegion->endPhiIndex();iPhi++) + { + for (unsigned int iEta=embRegion->beginEtaIndex();iEta<embRegion->endEtaIndex();iEta++) + { + EMBCellConstLink cellPtr = embRegion->getEMBCell(iEta,iPhi); + + // build hash identifier for this cell + Identifier chanId = em_id->channel_id(barrel_ec, + cellPtr->getSamplingIndex(), + cellPtr->getRegionIndex(), + iEta,iPhi); + + // Create the element and store it + EMBDetectorElement* embElement = new EMBDetectorElement(em_id->channel_hash(chanId), + 0,0, + embDescr, + cellPtr, + embRegion, + isTestBeam); + if(iPhi==embRegion->beginPhiIndex()) + phi_min = embElement->phi() - 0.5*embElement->dphi(); + + // cell volume + embElement->set_volume(cellVol.CellVolume(chanId)); + + caloMgr->add(embElement); + + if(r_min > embElement->r()-0.5*embElement->dr()) + r_min = embElement->r()-0.5*embElement->dr(); + if(r_max < embElement->r()+0.5*embElement->dr()) + r_max = embElement->r()+0.5*embElement->dr(); + + if(z_min > fabs(embElement->z_raw())-0.5*embElement->dz()) + z_min = fabs(embElement->z_raw())-0.5*embElement->dz(); + if(z_max < fabs(embElement->z_raw())+0.5*embElement->dz()) + z_max = fabs(embElement->z_raw())+0.5*embElement->dz(); + + if(reg_min > embElement->eta()-0.5*embElement->deta()) + reg_min = embElement->eta()-0.5*embElement->deta(); + if(reg_max < embElement->eta()+0.5*embElement->deta()) + reg_max = embElement->eta()+0.5*embElement->deta(); + + // deal with depth + if(iPhi==embRegion->beginPhiIndex()) + { + depth_in.push_back(cellPtr->getRLocal(EMBCell::FRONT)); + depth_out.push_back(cellPtr->getRLocal(EMBCell::BACK)); + } + } // Eta loop + } // Phi loop + // *** *** *** Iterate over cells *** *** *** + + double eta_min; + if(embRegion->getSamplingIndex()==1 && embRegion->getRegionIndex()==0) + { + // special case for this region: strip 0 is missing + eta_min = (embRegion->getDescriptor()->getEtaBinning()).getStart() - + (embRegion->getDescriptor()->getEtaBinning()).getDelta(); + } + else + eta_min = (embRegion->getDescriptor()->getEtaBinning()).getStart(); + + double eta_max = (embRegion->getDescriptor()->getEtaBinning()).getEnd(); + double phi_max = phi_min + fabs((embRegion->getDescriptor()->getPhiBinning()).getDelta())*embDescr->n_phi(); + + // 'ideal' values + embDescr->setCaloEtaMin(eta_min); + embDescr->setCaloEtaMax(eta_max); + embDescr->setCaloPhiMin(phi_min); + embDescr->setCaloPhiMax(phi_max); + embDescr->setCaloZMin(z_min); + embDescr->setCaloZMax(z_max); + embDescr->setCaloRMin(r_min); + embDescr->setCaloRMax(r_max); + + // depths + embDescr->set_n_calo_depth(depth_in.size()); + embDescr->set_depth_in(depth_in); + embDescr->set_depth_out(depth_out); + + // 'alignable' values + embDescr->setLArRegMin(reg_min); + embDescr->setLArRegMax(reg_max); + embDescr->setLArEtaMin(eta_min); + embDescr->setLArPhiMin(phi_min); + + }// Region loop + } // if EMB manager has been retrieved + + // **************************************************************** + // ** --- --- EMB --- --- ** + // **************************************************************** + + // **************************************************************** + // ** --- --- EMEC --- --- ** + // **************************************************************** + + // --- Retrieve Emec Detector Manager + const EMECDetectorManager* emecManager = 0; + status = detStore->retrieve(emecManager); + if(status.isFailure()) + { + log << MSG::WARNING << "Could not get the EMECDetectorManager. No Calo Elements will be built for EMEC" << endreq; + } + else + { + // --- --- Iterate over EMEC regions and cells --- --- + EMECDetectorManager::DetectorRegionConstIterator emecregIt; + + for (emecregIt=emecManager->beginDetectorRegion(); emecregIt!=emecManager->endDetectorRegion(); emecregIt++) + { + const EMECDetectorRegion *emecRegion = *emecregIt; + + // *** *** Create descriptor for this region *** *** + // Region identifier. + // Do some mapping between LArReadoutGeometry and CaloID + EMECDetectorRegion::DetectorSide endcapInd = emecRegion->getEndcapIndex(); + + unsigned int radialInd = emecRegion->getRadialIndex(); + int barrel_ec; + + switch(endcapInd) + { + case EMECDetectorRegion::NEG: + { + barrel_ec = -1; // negative side + break; + } + case EMECDetectorRegion::POS: + { + barrel_ec = 1; // positive side + break; + } + default: + { + log << MSG::ERROR << "Wrong Endcap Index for EMEC region " << endcapInd << endreq; + return StatusCode::FAILURE; + } + }// switch(endcapInd) + + switch(radialInd) + { + case 0: + { + barrel_ec *= 2; // outer wheel + break; + } + case 1: + { + barrel_ec *= 3; // inner wheel + break; + } + default: + { + log << MSG::ERROR << "Wrong Radial Index for EMEC region " << radialInd << endreq; + return StatusCode::FAILURE; + } + }// switch(radialInd) + + Identifier regId = em_id->region_id(barrel_ec, + emecRegion->getSamplingIndex(), + emecRegion->getRegionIndex()); + + EMECDescriptor* emecDescr = new EMECDescriptor(regId,(AtlasDetectorID *)cell_id,cell_id,emecRegion); + caloMgr->add(emecDescr); + + double phi_min = 0.; + double z_min = 10000.; + double z_max = -10000.; + double r_min = 10000.; + double r_max = -10000.; + + double reg_min = 10000.; + double reg_max = -10000.; + + std::vector<double> depth_in; + std::vector<double> depth_out; + // *** *** Create descriptor for this region *** *** + + // + // *** *** *** Iterate over cells *** *** *** + // + for (unsigned int iPhi=emecRegion->beginPhiIndex();iPhi<emecRegion->endPhiIndex();iPhi++) + { + for (unsigned int iEta=emecRegion->beginEtaIndex();iEta<emecRegion->endEtaIndex();iEta++) + { + EMECCellConstLink cellPtr = emecRegion->getEMECCell(iEta,iPhi); + + Identifier chanId = em_id->channel_id(barrel_ec, + cellPtr->getSamplingIndex(), + cellPtr->getRegionIndex(), + iEta,iPhi); + + // Create the element and store it + EMECDetectorElement* emecElement = new EMECDetectorElement(em_id->channel_hash(chanId), + 0,0, + emecDescr, + cellPtr, + emecRegion, + isTestBeam); + if(iPhi==emecRegion->beginPhiIndex()) + phi_min = emecElement->phi() - 0.5*emecElement->dphi(); + + // cell volume + emecElement->set_volume(cellVol.CellVolume(chanId)); + caloMgr->add(emecElement); + + if(r_min > emecElement->r()-0.5*emecElement->dr()) + r_min = emecElement->r()-0.5*emecElement->dr(); + if(r_max < emecElement->r()+0.5*emecElement->dr()) + r_max = emecElement->r()+0.5*emecElement->dr(); + + if(z_min > fabs(emecElement->z_raw())-0.5*emecElement->dz()) + z_min = fabs(emecElement->z_raw())-0.5*emecElement->dz(); + if(z_max < fabs(emecElement->z_raw())+0.5*emecElement->dz()) + z_max = fabs(emecElement->z_raw())+0.5*emecElement->dz(); + + if(reg_min > emecElement->eta()-0.5*emecElement->deta()) + reg_min = emecElement->eta()-0.5*emecElement->deta(); + if(reg_max < emecElement->eta()+0.5*emecElement->deta()) + reg_max = emecElement->eta()+0.5*emecElement->deta(); + + // depths + if(iPhi==emecRegion->beginPhiIndex()) + { + depth_in.push_back(fabs(emecElement->z_raw())-emecElement->dz()); + depth_out.push_back(fabs(emecElement->z_raw())+emecElement->dz()); + } + } // Eta loop + } // Phi loop + // *** *** *** Iterate over cells *** *** *** + + double eta_min = (emecRegion->getDescriptor()->getEtaBinning()).getStart(); + double eta_max = (emecRegion->getDescriptor()->getEtaBinning()).getEnd(); + double phi_max = phi_min + fabs((emecRegion->getDescriptor()->getPhiBinning()).getDelta())*emecDescr->n_phi(); + + // 'ideal' values + emecDescr->setCaloEtaMin(eta_min); + emecDescr->setCaloEtaMax(eta_max); + emecDescr->setCaloPhiMin(phi_min); + emecDescr->setCaloPhiMax(phi_max); + emecDescr->setCaloZMin(z_min); + emecDescr->setCaloZMax(z_max); + emecDescr->setCaloRMin(r_min); + emecDescr->setCaloRMax(r_max); + + // depths + emecDescr->set_n_calo_depth(depth_in.size()); + emecDescr->set_depth_in(depth_in); + emecDescr->set_depth_out(depth_out); + + // 'alignable' values + emecDescr->setLArRegMin(reg_min); + emecDescr->setLArRegMax(reg_max); + emecDescr->setLArEtaMin(eta_min); + emecDescr->setLArPhiMin(phi_min); + }// Region loop + }// if EMEC manager has been retrieved + + // **************************************************************** + // ** --- --- EMEC --- --- ** + // **************************************************************** + + + // **************************************************************** + // ** --- --- HEC --- --- ** + // **************************************************************** + + // --- Retrieve Hec Detector Manager + const HECDetectorManager* hecManager = 0; + status = detStore->retrieve(hecManager); + if(status.isFailure()) + { + log << MSG::WARNING << "Could not get the HECDetectorManager. No Calo Elements will be built for HEC" << endreq; + } + else + { + // --- --- Iterate over HEC regions and cells --- --- + HECDetectorManager::DetectorRegionConstIterator hecregIt; + + for (hecregIt=hecManager->beginDetectorRegion(); hecregIt!=hecManager->endDetectorRegion(); hecregIt++) + { + const HECDetectorRegion *hecregion = *hecregIt; + + // *** *** Create descriptor for this region *** *** + // Region identifier. + // Do some mapping between LArReadoutGeometry and CaloID + HECDetectorRegion::DetectorSide endcapInd = hecregion->getEndcapIndex(); + int pos_neg = endcapInd==HECDetectorRegion::NEG ? -2 : 2; + + Identifier regId = hec_id->region_id(pos_neg, + hecregion->getSamplingIndex(), + hecregion->getRegionIndex()); + + HECDescriptor* hecDescr = new HECDescriptor(regId,(AtlasDetectorID *)cell_id,cell_id,hecregion); + caloMgr->add(hecDescr); + + double phi_min = 0.; + double z_min = 10000.; + double z_max = -10000.; + double r_min = 10000.; + double r_max = -10000.; + + double reg_min = 10000.; + double reg_max = -10000.; + + std::vector<double> depth_in; + std::vector<double> depth_out; + + // + // *** *** *** Iterate over cells *** *** *** + // + for (unsigned int iPhi=hecregion->beginPhiIndex();iPhi<hecregion->endPhiIndex();iPhi++) + { + for (unsigned int iEta=hecregion->beginEtaIndex();iEta<hecregion->endEtaIndex();iEta++) + { + HECCellConstLink cellPtr = hecregion->getHECCell(iEta,iPhi); + // build hash identifier for this cell + // Do some mapping between LArReadoutGeometry and CaloID + + if(cellPtr) + { + Identifier chanId = hec_id->channel_id(pos_neg, + cellPtr->getSamplingIndex(), + cellPtr->getRegionIndex(), + iEta,iPhi); + + // Create the element and store it + HECDetectorElement* hecElement = new HECDetectorElement(hec_id->channel_hash(chanId), + 0,0, + hecDescr, + cellPtr, + hecregion, + isTestBeam); + if(iPhi==hecregion->beginPhiIndex()) + phi_min = hecElement->phi() - 0.5*hecElement->dphi(); + + // cell volume + hecElement->set_volume(cellVol.CellVolume(chanId)); + + caloMgr->add(hecElement); + + if(r_min > cellPtr->getRMinLocalNominal(HECCell::FRONT)) + r_min = cellPtr->getRMinLocalNominal(HECCell::FRONT); + if(r_max < cellPtr->getRMaxLocalNominal(HECCell::FRONT)) + r_max = cellPtr->getRMaxLocalNominal(HECCell::FRONT); + + if(z_min > fabs(hecElement->z_raw())-hecElement->dz()) + z_min = fabs(hecElement->z_raw())-hecElement->dz(); + if(z_max < fabs(hecElement->z_raw())+hecElement->dz()) + z_max = fabs(hecElement->z_raw())+hecElement->dz(); + + if(reg_min > hecElement->eta()-0.5*hecElement->deta()) + reg_min = hecElement->eta()-0.5*hecElement->deta(); + if(reg_max < hecElement->eta()+0.5*hecElement->deta()) + reg_max = hecElement->eta()+0.5*hecElement->deta(); + + if(iPhi==hecregion->beginPhiIndex() && iEta==hecregion->beginEtaIndex()) + { + depth_in.push_back(fabs(hecElement->z_raw())-hecElement->dz()); + depth_out.push_back(fabs(hecElement->z_raw())+hecElement->dz()); + } + + } + } // Eta loop + } // Phi loop + // *** *** *** Iterate over cells *** *** *** + + double eta_min = (hecregion->getDescriptor()->getEtaBinning()).getStart(); + double eta_max = (hecregion->getDescriptor()->getEtaBinning()).getEnd(); + double phi_max = phi_min + fabs((hecregion->getDescriptor()->getPhiBinning()).getDelta())*hecDescr->n_phi(); + + // 'ideal' values + hecDescr->setCaloEtaMin(eta_min); + hecDescr->setCaloEtaMax(eta_max); + hecDescr->setCaloPhiMin(phi_min); + hecDescr->setCaloPhiMax(phi_max); + hecDescr->setCaloZMin(z_min); + hecDescr->setCaloZMax(z_max); + hecDescr->setCaloRMin(r_min); + hecDescr->setCaloRMax(r_max); + + // depths + hecDescr->set_n_calo_depth(depth_in.size()); + hecDescr->set_depth_in(depth_in); + hecDescr->set_depth_out(depth_out); + + // 'alignable' values + hecDescr->setLArRegMin(reg_min); + hecDescr->setLArRegMax(reg_max); + hecDescr->setLArEtaMin(eta_min); + hecDescr->setLArPhiMin(phi_min); + }// Region loop + } // if HEC manager has been retrieved + + // **************************************************************** + // ** --- --- HEC --- --- ** + // **************************************************************** + + + // **************************************************************** + // ** --- --- FCAL --- --- ** + // **************************************************************** + + // --- Retrieve Fcal Detector Manager + const FCALDetectorManager* fcalManager = 0; + status = detStore->retrieve(fcalManager); + if(status.isFailure()) + { + log << MSG::WARNING << "Could not get the FCALDetectorManager. No Calo Elements will be built for FCAL" << endreq; + } + else + { + // --- --- Iterate over FCAL modules and tiles --- --- + FCALDetectorManager::ConstIterator fcalmodIt; + + for (fcalmodIt=fcalManager->beginFCAL(); fcalmodIt!=fcalManager->endFCAL(); fcalmodIt++) + { + const FCALModule* fcalmodule = *fcalmodIt; + + // *** *** Create descriptor for this module *** *** + // Module identifier. + // Do some mapping between LArReadoutGeometry and CaloID + + FCALModule::Endcap endcapInd = fcalmodule->getEndcapIndex(); + + int pos_neg = endcapInd==FCALModule::NEG ? -2 : 2; + + Identifier regId = fcal_id->module_id(pos_neg, + (int)fcalmodule->getModuleIndex()); + + FCALDescriptor* fcalDescr = new FCALDescriptor(regId,(AtlasDetectorID *)cell_id,cell_id,fcalmodule); + caloMgr->add(fcalDescr); + + double eta_min = 10000.; + double eta_max = -10000.; + double z_min = 10000.; + double z_max = -10000.; + double r_min = 10000.; + double r_max = -10000.; + + double reg_min = 10000.; + double reg_max = -10000.; + + std::vector<double> depth_in; + std::vector<double> depth_out; + + // + // *** *** *** Iterate over cells *** *** *** + // + FCALModule::ConstIterator fcaltileIt; + for (fcaltileIt=fcalmodule->beginTiles();fcaltileIt!=fcalmodule->endTiles();fcaltileIt++) + { + Identifier chanId = fcal_id->channel_id(pos_neg, + (int)fcalmodule->getModuleIndex(), + fcaltileIt->getIndexJ(), // eta + fcaltileIt->getIndexI()); // phi + + FCALDetectorElement* fcalElement = new FCALDetectorElement(fcal_id->channel_hash(chanId), + 0,0, + fcalDescr, + &(*fcaltileIt), + fcalmodule, + isTestBeam); + // calculate cell volume + double tubeSpacing = cellVol.getFcalTubeSpacing((int)fcalmodule->getModuleIndex()); + unsigned int numTubes = fcaltileIt->getNumTubes(); + double dz = fcalmodule->getFullDepthZ(*fcaltileIt); + fcalElement->set_volume(.5*sqrt(3)*numTubes*tubeSpacing*tubeSpacing*dz); + + caloMgr->add(fcalElement); + + if(eta_min > std::fabs(fcalElement->eta_raw())-0.5*fcalElement->deta()) + eta_min = std::fabs(fcalElement->eta_raw())-0.5*fcalElement->deta(); + if(eta_max < std::fabs(fcalElement->eta_raw())+0.5*fcalElement->deta()) + eta_max = std::fabs(fcalElement->eta_raw())+0.5*fcalElement->deta(); + if(r_min > fcalElement->r() - 0.5*fcalElement->dr()) + r_min = fcalElement->r() - 0.5*fcalElement->dr(); + if(r_max < fcalElement->r() + 0.5*fcalElement->dr()) + r_max = fcalElement->r() + 0.5*fcalElement->dr(); + if(z_min > fabs(fcalElement->z_raw()) - 0.5*fcalElement->dz()) + z_min = fabs(fcalElement->z_raw()) - 0.5*fcalElement->dz(); + if(z_max < fabs(fcalElement->z_raw()) + 0.5*fcalElement->dz()) + z_max = fabs(fcalElement->z_raw()) + 0.5*fcalElement->dz(); + if(reg_min > fcalElement->eta()-0.5*fcalElement->deta()) + reg_min = fcalElement->eta()-0.5*fcalElement->deta(); + if(reg_max < fcalElement->eta()+0.5*fcalElement->deta()) + reg_max = fcalElement->eta()+0.5*fcalElement->deta(); + + if(fcaltileIt==fcalmodule->beginTiles()) + { + depth_in.push_back(fabs(fcalElement->z_raw()) - fcalElement->dz()); + depth_out.push_back(fabs(fcalElement->z_raw()) + fcalElement->dz()); + } + } + + // These values have no importance for FCAL - hardwire them here. + fcalDescr->setCaloPhiMin(0.); + fcalDescr->setCaloPhiMax(2*M_PI); + fcalDescr->setLArPhiMin(0.); + + + fcalDescr->setCaloEtaMin(eta_min); + fcalDescr->setCaloEtaMax(eta_max); + fcalDescr->setCaloZMin(z_min); + fcalDescr->setCaloZMax(z_max); + fcalDescr->setCaloRMin(r_min); + fcalDescr->setCaloRMax(r_max); + fcalDescr->setLArRegMin(reg_min); + fcalDescr->setLArRegMax(reg_max); + + // depths + fcalDescr->set_n_calo_depth(depth_in.size()); + fcalDescr->set_depth_in(depth_in); + fcalDescr->set_depth_out(depth_out); + + if(fcalmodule->getEndcapIndex()==FCALModule::NEG) + fcalDescr->setLArEtaMin(-reg_max); + else + fcalDescr->setLArEtaMin(reg_min); + + }// Module loop + }// if FCAL manager has been retrieved + + // **************************************************************** + // ** --- --- FCAL --- --- ** + // **************************************************************** + + + // **************************************************************** + // ** --- --- Tile --- --- ** + // **************************************************************** + const TileDetDescrManager* tile_mgr; + + status = detStore->retrieve(tile_mgr); + if (status.isFailure()) + { + log << MSG::WARNING << "Could not get the TileDetectorManager. No Calo Elements will be built for Tile" << endreq; + } + else + { + if (debug) log << MSG::DEBUG << " Found the TileDetDescrManager " << endreq; + cell_id->calo_cell_hash_range((int)CaloCell_ID::TILE,min,max); + for(unsigned int idhash=0; idhash < max-min; idhash++) + { + CaloDetDescrElement* newelt = tile_mgr->get_cell_element(idhash); + if(newelt) caloMgr->add(newelt); + } + + std::vector<CaloDetDescriptor*>::const_iterator itr = tile_mgr->calo_descriptors_begin(); + std::vector<CaloDetDescriptor*>::const_iterator end = tile_mgr->calo_descriptors_end(); + + for(; itr != end; ++itr) caloMgr->add_tile(*itr); + } + // **************************************************************** + // ** --- --- Tile --- --- ** + // **************************************************************** + + // **************************************************************** + // ** --- Additional elements --- ** + // **************************************************************** + if(isTestBeam) + { + const CaloDetDescrElementContainer *cDDEvec; + if(detStore->retrieve(cDDEvec) == StatusCode::SUCCESS) + { // We have additional elements + CaloDetDescrElementContainer::const_iterator c_begin = cDDEvec->begin(); + CaloDetDescrElementContainer::const_iterator c_end = cDDEvec->end(); + for( ; c_begin != c_end; ++c_begin) + caloMgr->add(*c_begin); + } + } + + return StatusCode::SUCCESS; +} + +//-------------------------------------------------------------------- + +long +CaloMgrDetDescrCnv::storageType() +{ + return DetDescr_StorageType; +} + +//-------------------------------------------------------------------- +const CLID& +CaloMgrDetDescrCnv::classID() { + return ClassID_traits<CaloDetDescrManager>::ID(); +} + +//-------------------------------------------------------------------- +CaloMgrDetDescrCnv::CaloMgrDetDescrCnv(ISvcLocator* svcloc) + : + DetDescrConverter(ClassID_traits<CaloDetDescrManager>::ID(), svcloc) +{} diff --git a/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/src/CaloSuperCellMgrDetDescrCnv.cxx b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/src/CaloSuperCellMgrDetDescrCnv.cxx new file mode 100755 index 0000000000000000000000000000000000000000..c7281143655b1751f1cd7c533735b9fc36c21e58 --- /dev/null +++ b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/src/CaloSuperCellMgrDetDescrCnv.cxx @@ -0,0 +1,267 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// $Id$ +/** + * @file CaloDetMgrDetDescrCnv/src/CaloSuperCellMgrDetDescrCnv.cxx + * @author scott snyder <snyder@bnl.gov> + * @date Aug, 2012 + * @brief Converter for CaloSuperCellMgrDetDescrCnv. + * Creates the supercell geometry from the offline geometry. + */ + + +#undef NDEBUG + + +#include "CaloDetMgrDetDescrCnv/CaloSuperCellMgrDetDescrCnv.h" +#include "CaloTriggerTool/ICaloSuperCellIDTool.h" +#include "TileDetDescr/TileDetDescrManager.h" +#include "CaloDetDescr/CaloDetDescrManager.h" +#include "CaloDetDescr/CaloDetDescriptor.h" +#include "CaloDetDescr/CaloDetDescrElement.h" +#include "CaloDetDescr/CaloDetectorElements.h" +#include "CaloDetDescr/ICaloSuperCellAlignTool.h" +#include "CaloIdentifier/CaloIdManager.h" +#include "CaloIdentifier/CaloCell_SuperCell_ID.h" +#include "GeoModelInterfaces/IGeoAlignTool.h" +#include "DetDescrCnvSvc/DetDescrAddress.h" +#include "StoreGate/StoreGateSvc.h" +#include "SGTools/StorableConversions.h" +#include "AthenaKernel/errorcheck.h" +#include "boost/foreach.hpp" +#include <cassert> + + +namespace { + + +CaloDetDescriptor* get_descriptor (Identifier cell_id, + const CaloDetDescrManager_Base* mgr) +{ + const CaloCell_Base_ID* calo_helper = mgr->getCaloCell_ID(); + Identifier reg_id = calo_helper->region_id (cell_id); + if (!calo_helper->is_tile (cell_id)) { + assert (reg_id.is_valid()); + return mgr->get_descriptor (reg_id); + } + + int clayer = calo_helper->sample (cell_id); + bool is_sc = calo_helper->is_supercell (cell_id); + BOOST_FOREACH (CaloDetDescriptor* d, mgr->tile_descriptors_range()) { + if (d->identify() != reg_id) continue; + int dlayer = d->layer(); + if (clayer == dlayer) return d; + if (is_sc && dlayer == 0 && clayer != 2) return d; + } + return 0; +} + + +} // anonymous namespace + + + +/** + * @brief Return the service type. Required by the base class. + */ +long int +CaloSuperCellMgrDetDescrCnv::repSvcType() const +{ + return (storageType()); +} + + +/** + * @brief Standard Gaudi initialize method. + */ +StatusCode +CaloSuperCellMgrDetDescrCnv::initialize() +{ + CHECK( DetDescrConverter::initialize() ); + CHECK( m_scidtool.retrieve() ); + return StatusCode::SUCCESS; +} + + +/** + * @brief Standard Gaudi finalize method. + */ +StatusCode +CaloSuperCellMgrDetDescrCnv::finalize() +{ + return StatusCode::SUCCESS; +} + + +/** + * @brief Called by the converter infrastructure to create an object. + * @param pAddr Address of the object to create. + * @param pObj[out] Set to a reference to the created helper. + * + * This is all boilerplate; the real work is done in @c createManager. + */ +StatusCode +CaloSuperCellMgrDetDescrCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj) +{ + MsgStream log(messageService(), "CaloSCMgrDetDescrCnv"); + int outputLevel = msgSvc()->outputLevel( "CaloSCMgrDetDescrCnv" ); + + // Create a new CaloSCDescrManager + + DetDescrAddress* ddAddr; + ddAddr = dynamic_cast<DetDescrAddress*> (pAddr); + if(!ddAddr) { + log << MSG::FATAL << "Could not cast to DetDescrAddress." << endreq; + return StatusCode::FAILURE; + } + + // Get the StoreGate key of this container. + std::string mgrKey = *( ddAddr->par() ); + + if (outputLevel <= MSG::DEBUG) { + if ("" == mgrKey) { + log << MSG::DEBUG << "No Manager key " << endreq; + } + else { + log << MSG::DEBUG << "Manager key is " << mgrKey << endreq; + } + } + + // Create the manager + CaloSuperCellDetDescrManager* mgr = 0; + CHECK( createManager (mgrKey, mgr, pObj) ); + + + return StatusCode::SUCCESS; + +} + + +/** + * @brief Storage type and class ID (used by CnvFactory) + */ +long +CaloSuperCellMgrDetDescrCnv::storageType() +{ + return DetDescr_StorageType; +} + + +/** + * @brief Return the CLID of the class we create. + * Required by the converter infrastructure. + */ +const CLID& +CaloSuperCellMgrDetDescrCnv::classID() { + return ClassID_traits<CaloSuperCellDetDescrManager>::ID(); +} + + +/** + * @brief Constructor. + * @param clid The CLID if the class we're constructing. + * @param svcloc Gaudi service locator. + */ +CaloSuperCellMgrDetDescrCnv::CaloSuperCellMgrDetDescrCnv(ISvcLocator* svcloc) + : + DetDescrConverter(ClassID_traits<CaloSuperCellDetDescrManager>::ID(), svcloc), + m_scidtool ("CaloSuperCellIDTool"), + m_scAlignTool ("CaloSuperCellAlignTool") +{} + + +/** + * @brief Create the manager object. + * @param helperKey StoreGate key of the manager. + * @param idhelper[out] Set to a pointer to the new manager. + * @param pObj[out] Set to a reference to the created manager. + * + * This actually creates the manager object. + */ +StatusCode +CaloSuperCellMgrDetDescrCnv::createManager(const std::string& /*mgrKey*/, + CaloSuperCellDetDescrManager* & mgr, + DataObject*& pObj) +{ + // Get ID helpers. + StoreGateSvc * detStore = 0; + CHECK( serviceLocator()->service("DetectorStore", detStore) ); + const CaloIdManager* caloId_mgr = 0; + CHECK( detStore->retrieve(caloId_mgr, "CaloIdManager") ); + + // Create the manager and initialize the helpers. + mgr = new CaloSuperCellDetDescrManager; + mgr->set_helper(caloId_mgr->getCaloCell_SuperCell_ID()); + mgr->set_helper(caloId_mgr); + mgr->initialize(); + + // return the manager to the caller. + pObj = SG::asStorable (mgr); + + // Create descriptors / elements (with null geometry). + CHECK( createDescriptors (mgr) ); + CHECK( createElements (mgr) ); + + // Update the geometry from the offline manager. + const CaloDetDescrManager* cellmgr = 0; + CHECK( detStore->retrieve(cellmgr, "CaloMgr") ); + + CHECK( m_scAlignTool.retrieve() ); + CHECK( m_scAlignTool->doUpdate (mgr, cellmgr) ); + + return StatusCode::SUCCESS; +} + + +/** + * @brief Create the descriptors for the supercell geometry. + * @param mgr The supercell geometry manager. + */ +StatusCode +CaloSuperCellMgrDetDescrCnv::createDescriptors (CaloSuperCellDetDescrManager* mgr) +{ + const CaloCell_Base_ID* calo_helper = mgr->getCaloCell_ID(); + BOOST_FOREACH (Identifier reg_id, calo_helper->reg_range()) { + if (! calo_helper->is_tile (reg_id)) { + mgr->add (new CaloDetDescriptor (reg_id, 0, calo_helper)); + } + else { + mgr->add_tile (new CaloDetDescriptor + (reg_id, calo_helper->tile_idHelper(), calo_helper, + (CaloCell_ID::CaloSample)calo_helper->calo_sample(reg_id), 0)); + // NB. CaloDetDescrElement::getSampling adds the tile cell sampling + // index to the descriptor's sampling, so don't add 2 here + // to calo_sample. + mgr->add_tile (new CaloDetDescriptor + (reg_id, calo_helper->tile_idHelper(), calo_helper, + (CaloCell_ID::CaloSample)(calo_helper->calo_sample(reg_id)), 2)); + } + } + return StatusCode::SUCCESS; +} + + + +/** + * @brief Create the elements for the supercell geometry. + * @param mgr The supercell geometry manager. + */ +StatusCode +CaloSuperCellMgrDetDescrCnv::createElements (CaloSuperCellDetDescrManager* mgr) +{ + const CaloCell_Base_ID* calo_helper = mgr->getCaloCell_ID(); + BOOST_FOREACH (Identifier cell_id, calo_helper->cell_range()) { + int subCalo = -1; + IdentifierHash subCaloHash = + calo_helper->subcalo_cell_hash (cell_id, subCalo); + + CaloDetDescriptor* desc = get_descriptor (cell_id, mgr); + assert (desc); + mgr->add (new CaloSuperCellDetectorElement (subCaloHash, desc)); + } + return StatusCode::SUCCESS; +} + + diff --git a/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/src/CaloTTMgrDetDescrCnv.cxx b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/src/CaloTTMgrDetDescrCnv.cxx new file mode 100755 index 0000000000000000000000000000000000000000..a6904ac9724f1ad2505261f4b98ddc9d7214096b --- /dev/null +++ b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/src/CaloTTMgrDetDescrCnv.cxx @@ -0,0 +1,384 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/*************************************************************************** + Calo Trigger Tower Manager converter package + -------------------------------------------- + Copyright (C) 2003 by ATLAS Collaboration + ***************************************************************************/ + +//<doc><file> $Id: CaloTTMgrDetDescrCnv.cxx,v 1.21 2008-12-14 01:56:04 ssnyder Exp $ +//<version> $Name: not supported by cvs2svn $ + +//<<<<<< INCLUDES >>>>>> + +#include "CaloDetMgrDetDescrCnv/CaloTTMgrDetDescrCnv.h" + +// infrastructure includes +#include "DetDescrCnvSvc/DetDescrConverter.h" +#include "DetDescrCnvSvc/DetDescrAddress.h" +#include "GaudiKernel/MsgStream.h" +#include "GaudiKernel/CnvFactory.h" +#include "StoreGate/StoreGate.h" +#include "StoreGate/StoreGateSvc.h" + +// detdescr includes +#include "CaloTTDetDescr/CaloTTDescrManager.h" +#include "CaloTTDetDescr/CaloTTDescrRegion.h" +#include "CaloTTDetDescr/CaloTTDescriptor.h" +#include "CaloIdentifier/CaloLVL1_ID.h" + +#include "CaloDetDescr/CaloDetDescrManager.h" +#include "CaloDetDescr/CaloDetDescrElement.h" +#include "LArTools/LArCablingService.h" +#include "CaloTriggerTool/CaloTriggerTowerService.h" + +//<<<<<< PRIVATE DEFINES >>>>>> +//<<<<<< PRIVATE CONSTANTS >>>>>> +//<<<<<< PRIVATE TYPES >>>>>> +//<<<<<< PRIVATE VARIABLE DEFINITIONS >>>>>> +//<<<<<< PUBLIC VARIABLE DEFINITIONS >>>>>> +//<<<<<< CLASS STRUCTURE INITIALIZATION >>>>>> +//<<<<<< PRIVATE FUNCTION DEFINITIONS >>>>>> +//<<<<<< PUBLIC FUNCTION DEFINITIONS >>>>>> +//<<<<<< MEMBER FUNCTION DEFINITIONS >>>>>> + +// Instantiation of a static factory class used by clients to create +// instances of this service + +long int +CaloTTMgrDetDescrCnv::repSvcType() const +{ + return (storageType()); +} + +StatusCode +CaloTTMgrDetDescrCnv::initialize() +{ + // First call parent init + StatusCode sc = DetDescrConverter::initialize(); + MsgStream log(messageService(), "CaloTTMgrDetDescrCnv"); + if (log.level()<=MSG::DEBUG) log << MSG::DEBUG << "in initialize" << endreq; + + if (sc.isFailure()) { + log << MSG::ERROR << "DetDescrConverter::initialize failed" << endreq; + return sc; + } + + // The following is an attempt to "bootstrap" the loading of a + // proxy for CaloTTDescrManager into the detector store. However, + // CaloTTMgrDetDescrCnv::initialize is NOT called by the conversion + // service. So for the moment, this cannot be use. Instead the + // DetDescrCnvSvc must do the bootstrap from a parameter list. + + +// // Add CaloTTDescrManager proxy as entry point to the detector store +// // - this is ONLY needed for the manager of each system +// sc = addToDetStore(classID(), "CaloTTDescrManager"); +// if (sc.isFailure()) { +// log << MSG::FATAL << "Unable to add proxy for CaloTTDescrManager to the Detector Store!" << endreq; +// return StatusCode::FAILURE; +// } else {} + + return StatusCode::SUCCESS; +} + +//-------------------------------------------------------------------- + +StatusCode +CaloTTMgrDetDescrCnv::finalize() +{ + MsgStream log(messageService(), "CaloTTMgrDetDescrCnv"); + if (log.level()<=MSG::DEBUG) log << MSG::DEBUG << "in finalize" << endreq; + + return StatusCode::SUCCESS; +} + +//-------------------------------------------------------------------- + +StatusCode +CaloTTMgrDetDescrCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj) +{ + MsgStream log(messageService(), "CaloTTMgrDetDescrCnv"); + log << MSG::INFO << "in createObj: creating a CaloTTDescrManager object in the detector store" << endreq; + int outputLevel = msgSvc()->outputLevel( "CaloTTMgrDetDescrCnv" ); + + // Create a new CaloTTDescrManager + + DetDescrAddress* ddAddr; + ddAddr = dynamic_cast<DetDescrAddress*> (pAddr); + if(!ddAddr) { + log << MSG::FATAL << "Could not cast to DetDescrAddress." << endreq; + return StatusCode::FAILURE; + } + + // Get the StoreGate key of this container. + std::string mgrKey = *( ddAddr->par() ); + + if (outputLevel <= MSG::DEBUG) { + if ("" == mgrKey) { + log << MSG::DEBUG << "No Manager key " << endreq; + } + else { + log << MSG::DEBUG << "Manager key is " << mgrKey << endreq; + } + } + + // Create the manager + CaloTTDescrManager* caloTTMgr = new CaloTTDescrManager(); + + // Pass a pointer to the container to the Persistency service by reference. + pObj = StoreGateSvc::asStorable(caloTTMgr); + + // get DetectorStore service + StoreGateSvc * detStore; + StatusCode status = serviceLocator()->service("DetectorStore", detStore); + if (status.isFailure()) { + log << MSG::FATAL << "DetectorStore service not found !" << endreq; + return StatusCode::FAILURE; + } else {} + + // Get idhelper from detector store and add to mgr + //const DataHandle<CaloLVL1_ID> lvl1_id; + const CaloLVL1_ID* lvl1_id; + status = detStore->retrieve(lvl1_id, "CaloLVL1_ID"); + if (status.isFailure()) { + log << MSG::FATAL << "Could not get CaloLVL1_ID helper !" << endreq; + return StatusCode::FAILURE; + } + else { + if (outputLevel <= MSG::DEBUG) log << MSG::DEBUG << " Found the CaloLVL1_ID helper. " << endreq; + } + caloTTMgr->set_helper(lvl1_id); + log << MSG::INFO << "Set CaloLVL1_ID helper in CaloTTMgr " + << endreq; + + // Get CaloDetDescrManager from detector store + // to build geometry of trigger towers + const CaloDetDescrManager* caloMgr; + status = detStore->retrieve(caloMgr); + if (status.isFailure()) { + log << MSG::FATAL << "Could not get CaloDetDescr manager !" << endreq; + return StatusCode::FAILURE; + } + else { + if (outputLevel <= MSG::DEBUG) log << MSG::DEBUG << " Retrieved CaloDetDescr Manager " << endreq; + } + + // Retrieve LArCablingSvc also needed to build TT geometry + IToolSvc* toolSvc; + status = service( "ToolSvc",toolSvc ); + if(! status.isSuccess()) { + return status; + } + LArCablingService* cablingSvc; + status =toolSvc->retrieveTool("LArCablingService",cablingSvc); + if(!status.isSuccess() ) return status; + + CaloTriggerTowerService* ttSvc; + status =toolSvc->retrieveTool("CaloTriggerTowerService",ttSvc); + if(!status.isSuccess() ) return status; + + + // Initialize the caloTT mgr + // We protect here in case this has been initialized elsewhere + + if (!caloTTMgr->is_initialized()) { + + if (outputLevel <= MSG::DEBUG) log << MSG::DEBUG << "Initializing CaloTTMgr from values in CaloTTMgrDetDescrCnv " + << endreq; + + int numberOfIdRegions=0; + int numberOfDescrRegions=0; + int nEmb=0; + int nEmec=0; + int nHec=0; + int nFcal=0; + + // Initialize the manager ... + + const CaloLVL1_ID* lvl1_helper = lvl1_id; + + std::vector<Identifier>::const_iterator itId = lvl1_id->region_begin(); + std::vector<Identifier>::const_iterator itIdEnd = lvl1_id->region_end(); + + for(; itId!=itIdEnd;++itId){ + Identifier regId = *itId; + ++numberOfIdRegions; + int posNeg = lvl1_helper->pos_neg_z(regId); + // int sampling = lvl1_helper->sampling(regId); + int region = lvl1_helper->region(regId); + int halfNphi = (lvl1_helper->phi_max(regId)+1)/2; + int nLay = lvl1_helper->layer_max(regId)+1; + + // create Descriptors for both LAr and Tile + CaloTTDescriptor* calo_descriptor = new CaloTTDescriptor() ; + calo_descriptor->set(regId); + + if( 0 == region ) { + // calo_descriptor->set(0. ,2.5,0.1,-M_PI,M_PI,M_PI/halfNphi,posNeg,nLay); + calo_descriptor->set(0. ,2.5,0.1,0.,2.*M_PI,M_PI/halfNphi,posNeg,nLay); + } else if( 1 == region ) { + // calo_descriptor->set(2.5,3.1,0.2,-M_PI,M_PI,M_PI/halfNphi,posNeg,nLay); + calo_descriptor->set(2.5,3.1,0.2,0.,2.*M_PI,M_PI/halfNphi,posNeg,nLay); + } else if( 2 == region ) { + // calo_descriptor->set(3.1,3.2,0.1,-M_PI,M_PI,M_PI/halfNphi,posNeg,nLay); + calo_descriptor->set(3.1,3.2,0.1,0.,2.*M_PI,M_PI/halfNphi,posNeg,nLay); + } else if( 3 == region ) { + // calo_descriptor->set(3.2,4.9,0.4,-M_PI,M_PI,M_PI/halfNphi,posNeg,nLay); + calo_descriptor->set(3.2,4.9,0.4,0.,2.*M_PI,M_PI/halfNphi,posNeg,nLay); + } + + // Initialize + caloTTMgr->add(calo_descriptor); + + // now, create CaloTTDescrRegions for LAr only + // Loop on TTs of this region and create CaloTTDescrRegion's (equiv. to cell's CaloDDE for TT) + int maxEta=calo_descriptor->nEta(); + for(int iEta=0;iEta<maxEta;++iEta) { + + int maxPhi=calo_descriptor->nPhi(); + for(int iPhi=0;iPhi<maxPhi;++iPhi) { + + Identifier TTid = lvl1_helper->tower_id(regId,iEta,iPhi); + if(!lvl1_helper->is_tile(TTid)) { + + int maxLay=calo_descriptor->nLay(); + for(int iLay=0;iLay<maxLay;++iLay) { + + Identifier layId = lvl1_helper->layer_id(TTid,iLay); + bool isFCAL(0), isEC(0); + if(lvl1_helper->is_fcal(layId)) { + isFCAL=true; + } + else if(lvl1_helper->is_emec(layId) || lvl1_helper->is_hec(layId)) { + isEC=true; + } + if (outputLevel <= MSG::DEBUG) { + if(lvl1_helper->is_emb(layId) || lvl1_helper->is_barrel_end(layId) ) { + ++nEmb; + log << MSG::DEBUG << " Found EMB TT " << lvl1_helper->show_to_string(layId) << endreq; + } + else if(lvl1_helper->is_emec(layId)) { + ++nEmec; + log << MSG::DEBUG << " Found EMEC TT " << lvl1_helper->show_to_string(layId) << endreq; + } + else if(lvl1_helper->is_hec(layId)) { + ++nHec; + log << MSG::DEBUG << " Found HEC TT " << lvl1_helper->show_to_string(layId) << endreq; + } + else { // FCAL + ++nFcal; + log << MSG::DEBUG << " Found FCAL TT " << lvl1_helper->show_to_string(layId) << endreq; + } + } + + double dEta=calo_descriptor->deta(); + double eta=calo_descriptor->eta_min()+(iEta+0.5)*dEta; + eta*=calo_descriptor->sign_eta(); + + double dPhi=calo_descriptor->dphi(); + // beware of the -pi,pi convention + // fixed thanks to Denis Damazio when integrating LArRegionSelector + // float orig=-M_PI; + float orig=0.; + double phi=calo_descriptor->phiMin() + (iPhi+0.5)*dPhi + orig; + if(phi>=M_PI) {phi-=2.*M_PI;} + if(phi<-M_PI) {phi+=2.*M_PI;} + + + float rhoMin=99999.; + float rhoMax=0.; + float zMin=99999.; + float zMax=-99999.; + + //int atlas_tb=0; + std::vector<Identifier> vec = ttSvc->createCellIDvecLayer(layId); + + if(vec.size() > 0) { + numberOfDescrRegions++; + std::vector<Identifier>::const_iterator it = vec.begin(); + std::vector<Identifier>::const_iterator it_end = vec.end(); + for(;it!=it_end;++it) { + Identifier offId = (*it); + CaloDetDescrElement* caloDDE = 0; + caloDDE = caloMgr->get_element(offId); + double rho =caloDDE->r_raw(); + double cDrho=caloDDE->dr(); + double z =caloDDE->z_raw(); + double cDz =caloDDE->dz(); + + if( (rho-cDrho/2.)<rhoMin ) {rhoMin=std::max(rho-cDrho/2.,0.);} + if( (rho+cDrho/2.)>rhoMax ) {rhoMax=rho+cDrho/2.;} + if( (z-cDz/2.)<zMin ) {zMin=z-cDz/2.;} + if( (z+cDz/2.)>zMax ) {zMax=z+cDz/2.;} + } // end loop on vector elements + + + CaloTTDescrRegion* tt_region = new CaloTTDescrRegion(layId,calo_descriptor); + if(isFCAL) { + // FIX ME !? + tt_region->set_cylindric(eta,phi,(zMax+zMin)/2.); + tt_region->set_cylindric_size(dEta,dPhi,fabs(zMax-zMin)); + } else if(isEC) { + tt_region->set_cylindric(eta,phi,(zMax+zMin)/2.); + tt_region->set_cylindric_size(dEta,dPhi,fabs(zMax-zMin)); + } else { + tt_region->set_spherical(eta,phi,(rhoMax+rhoMin)/2.); + tt_region->set_spherical_size(dEta,dPhi,fabs(rhoMax-rhoMin)); + } + + caloTTMgr->add(tt_region); + + } // end condition of vec size + else { + if (outputLevel <= MSG::DEBUG) log << MSG::DEBUG << " Found no cell for TT " << lvl1_helper->show_to_string(layId) << endreq; + } + } // end loop on layers + } // end condition against tile + } // end loop on phi + } // end loop on eta + } // end loop on descr_regions + + // Set to initialized state only if descriptors have been found + if (caloTTMgr->calo_descriptors_size () > 0) caloTTMgr->initialize(); + + + log << MSG::INFO << " Initialized CaloTTMgr, number of descr regions is " << numberOfDescrRegions << endreq; + if (outputLevel <= MSG::DEBUG) { + log << MSG::DEBUG << " including " + << nEmb << " Em Barrel " + << nEmec << " Em EC " + << nHec << " HEC " + << nFcal << " FCAL " + << endreq; + log << MSG::DEBUG << " number of helper regions= " << numberOfIdRegions << endreq; + } + } // end of condition !is_initialized() + + + return StatusCode::SUCCESS; + +} + +//-------------------------------------------------------------------- + +long +CaloTTMgrDetDescrCnv::storageType() +{ + return DetDescr_StorageType; +} + +//-------------------------------------------------------------------- +const CLID& +CaloTTMgrDetDescrCnv::classID() { + return ClassID_traits<CaloTTDescrManager>::ID(); +} + +//-------------------------------------------------------------------- +CaloTTMgrDetDescrCnv::CaloTTMgrDetDescrCnv(ISvcLocator* svcloc) + : + DetDescrConverter(ClassID_traits<CaloTTDescrManager>::ID(), svcloc) +{} + diff --git a/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/test/CaloDetMgrDetDescrCnv.xml b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/test/CaloDetMgrDetDescrCnv.xml new file mode 100755 index 0000000000000000000000000000000000000000..5b34279c557735dd08c31df3898251f5403e8b6b --- /dev/null +++ b/Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv/test/CaloDetMgrDetDescrCnv.xml @@ -0,0 +1,16 @@ +<?xml version="1.0"?> +<atn> + <TEST name="CaloDetMgrDetDescrCnvTest" type="makecheck" suite="Examples"> + <package>Calorimeter/CaloCnv/CaloDetMgrDetDescrCnv</package> + <timelimit>10</timelimit> + <author> scott snyder </author> + <mailto> snyder@bnl.gov </mailto> + <expectations> + <errorMessage>Athena exited abnormally</errorMessage> + <errorMessage>differ</errorMessage> + <warningMessage> # WARNING_MESSAGE : post.sh> ERROR</warningMessage> + <successMessage>check ok</successMessage> + <returnValue>0</returnValue> + </expectations> + </TEST> +</atn>