ATLAS Offline Software
CaloClusterCnvTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 // EDM include(s):
7 #include "CaloEvent/CaloCluster.h"
8 #include "CaloEvent/CaloClusterContainer.h"
12 
13 // Local include(s):
14 #include "CaloClusterCnvTool.h"
15 
16 
17 namespace {
18 
19 
20 typedef bool (xAOD::CaloCluster::*setterFunc) (const xAOD::CaloCluster::CaloSample,
21  const float val);
22 
23 
24 void copyClusterVariables (const CaloCluster* aod,
25  xAOD::CaloCluster* xaod,
27  setterFunc setter)
28 {
29  std::vector<double> vals;
30  if (! aod->getVariable (varType, vals, true))
31  vals.resize (CaloSampling::Unknown, -999);
32 
33  for (unsigned iSamp=0;iSamp<CaloSampling::Unknown;++iSamp) {
36  if (aod->hasSampling(sOld))
37  ((*xaod).*setter) (sNew, vals[iSamp]);
38  }
39 }
40 
41 
42 } // anonymous namespace
43 
44 
45 namespace xAODMaker {
46 
48  const std::string& name,
49  const IInterface* parent )
50  : AthAlgTool( type, name, parent ) {
51 
52  // Declare the interface(s) that the tool implements:
53  declareInterface< ICaloClusterCnvTool >( this );
54  }
55 
57  convert( const CaloCluster* aod,
58  xAOD::CaloCluster* xaod,
59  CaloClusterCellLinkContainer* ccclc ) const
60  {
61 
62  //
63  // Deal with the cell association:
64  //
65  if( aod->isCellLinkValid() && ccclc ) {
66 
67  ATH_MSG_DEBUG( "Found cluster with valid cell link" );
68 
69  CaloCluster::cell_iterator cit = aod->begin();
70  CaloCluster::cell_iterator cit_e = aod->end();
71  if( cit != cit_e ) { //Protect against empty-cluster case
72 
73  //Get underlying cell container
74  const CaloCellContainer* ccc = aod->getContainer( cit );
75 
76  if( ccc && ( !ccc->empty() ) ) {
77 
78  CaloClusterCellLink* cccl = new CaloClusterCellLink( ccc );
79  xaod->addCellLink( cccl );
80  for( ; cit != cit_e; ++cit ) {
81  xaod->addCell( cit.getElement().index(), cit.getParameter() );
82  }//end loop over cells of a cluster
83 
84  // Move cell links to external cell-link container:
85  xaod->setLink( ccclc );
86 
87  } //end cell container ptr not NULL
88  else {
89  ATH_MSG_INFO( "Got NULL ptr to CaloCellContainer" );
90  }
91 
92  }//end check cluster not-empty
93  else {
94  ATH_MSG_DEBUG( "Found cluster with empty list of constituents" );
95  }
96  }//end if isCellLink valid
97  else {
98  ATH_MSG_DEBUG( "Found cluster without valid cell link" );
99  }
100 
101  // Set basic quantities:
102  xaod->setSamplingPattern( aod->samplingPattern() );
103  const xAOD::CaloCluster::ClusterSize clSize =
104  static_cast< xAOD::CaloCluster::ClusterSize >( aod->getClusterSize() );
105  xaod->setClusterSize( clSize );
106  xaod->setEta0( ( double ) aod->eta0() );
107  xaod->setPhi0( ( double ) aod->phi0() );
108  xaod->setTime( aod->getTime() );
109 
110  xaod->setCalE( aod->e (P4SignalState::CALIBRATED) );
111  xaod->setCalEta( aod->eta (P4SignalState::CALIBRATED) );
112  xaod->setCalPhi( aod->phi (P4SignalState::CALIBRATED) );
113  xaod->setCalM( aod->m (P4SignalState::CALIBRATED) );
114 
115  xaod->setRawE( aod->e (P4SignalState::UNCALIBRATED) );
116  xaod->setRawEta( aod->eta (P4SignalState::UNCALIBRATED) );
117  xaod->setRawPhi( aod->phi (P4SignalState::UNCALIBRATED) );
118  xaod->setRawM( aod->m (P4SignalState::UNCALIBRATED) );
119 
120  xaod->setAltE( aod->e (P4SignalState::ALTCALIBRATED) );
123  xaod->setAltM( aod->m (P4SignalState::ALTCALIBRATED) );
124 
125  //
126  // Copy the energy depositions per sampling:
127  copyClusterVariables (aod, xaod,
130  copyClusterVariables (aod, xaod,
133  copyClusterVariables (aod, xaod,
136 
137  //
138  // Copy bad-channel data:
139  //
141  const std::vector< CaloClusterBadChannelData >* bcvec =
142  aod->getBadChannel();
143  for( const CaloClusterBadChannelData& bcd : *bcvec ) {
144  badChanList.emplace_back( bcd.getEta(), bcd.getPhi(),
145  bcd.getLayer(), bcd.getFlag().packedData() );
146  }
147  xaod->setBadChannelList( badChanList );
148 
149  //
150  // Copy the moments:
151  //
152  CaloCluster::moment_iterator mom_itr = aod->beginMoment();
153  CaloCluster::moment_iterator mom_end = aod->endMoment();
154  for( ; mom_itr != mom_end; ++mom_itr ) {
155 
156  // Forcibly convert between the two types:
157  const CaloCluster::moment_type aod_type =
158  static_cast<CaloCluster::moment_type>(mom_itr.getMomentType());
159  const xAOD::CaloCluster_v1::MomentType xaod_type =
160  static_cast< xAOD::CaloCluster_v1::MomentType >( aod_type );
161 
162  // Insert the moment:
163  xaod->insertMoment( xaod_type,
164  mom_itr.getMoment().getValue() );
165  ATH_MSG_VERBOSE( "Copied moment " << aod_type );
166  }
167 
168  // Return gracefully:
169  return StatusCode::SUCCESS;
170  }
171 
173  convert( const CaloClusterContainer* aod,
174  xAOD::CaloClusterContainer* xaod ) const {
175 
178  CaloClusterCellLinkContainer* ccclc = nullptr;
179 
180  for( ; it!= itE; ++it){
181  xAOD::CaloCluster* xcluster = new xAOD::CaloCluster();
182  xaod->push_back( xcluster );
183  CHECK( convert( *it, xcluster, ccclc) );
184  }
185 
186  return StatusCode::SUCCESS;
187  }
188 
189 } // namespace xAODMaker
GetLCDefs::Unknown
@ Unknown
Definition: GetLCDefs.h:21
CaloClusterMoment::MomentType
MomentType
enums to identify different moments
Definition: CaloClusterMoment.h:38
CaloCluster::phi0
double phi0() const
Returns raw of cluster seed.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloCluster.h:1186
CaloVariableType::VariableType
VariableType
Definition: CaloVariableType.h:15
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
xAOD::CaloCluster_v1::ClusterSize
ClusterSize
Enumeration to identify different cluster sizes.
Definition: CaloCluster_v1.h:86
xAOD::CaloCluster_v1::setRawM
void setRawM(flt_t)
Set mass for singal state UNCALIBRATED.
Definition: CaloCluster_v1.cxx:299
CaloCluster::hasSampling
bool hasSampling(const sampling_type &theSampling) const
Checks if certain sampling contributes to cluster.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloCluster.h:954
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::CaloCluster_v1::CaloSample
CaloSampling::CaloSample CaloSample
Definition: CaloCluster_v1.h:66
CaloVariableType::PHI
@ PHI
Definition: CaloVariableType.h:17
xAOD::CaloCluster_v1::setAltM
void setAltM(flt_t)
Set mass for singal state ALTCALIBRATED.
Definition: CaloCluster_v1.cxx:343
CaloClusterContainer
Storable container for CaloCluster.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloClusterContainer.h:37
CaloCluster::MomentStoreIter
Internal cell iterator.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloCluster.h:155
xAODMaker::CaloClusterCnvTool::CaloClusterCnvTool
CaloClusterCnvTool(const std::string &type, const std::string &name, const IInterface *parent)
Regular AlgTool constructor.
Definition: CaloClusterCnvTool.cxx:47
xAOD::CaloCluster_v1::setAltEta
void setAltEta(flt_t)
Set for signal state ALTCALIBRATED.
Definition: CaloCluster_v1.cxx:333
skel.it
it
Definition: skel.GENtoEVGEN.py:423
CaloClusterNavigable::getContainer
const CaloCellContainer * getContainer(const CaloCell *pCell) const
public container access: retrieve Container for given object pointer
Definition: CaloClusterNavigable.h:347
xAOD::CaloCluster_v1::insertMoment
void insertMoment(MomentType type, double value)
Definition: CaloCluster_v1.cxx:754
xAOD::CaloCluster_v1::setBadChannelList
void setBadChannelList(const CaloClusterBadChannelList &bcl)
Definition: CaloCluster_v1.cxx:274
xAOD::CaloCluster_v1::setLink
bool setLink(CaloClusterCellLinkContainer *CCCL, IProxyDict *sg=nullptr)
Set up an ElementLink to a CaloClusterCellLink object.
Definition: CaloCluster_v1.cxx:872
xAOD::CaloCluster_v1::setCalEta
void setCalEta(flt_t)
Set for signal state CALIBRATED.
Definition: CaloCluster_v1.cxx:311
xAOD::CaloCluster_v1::setSamplingPattern
void setSamplingPattern(const unsigned sp, const bool clearSamplingVars=false)
Set sampling pattern (one bit per sampling.
Definition: CaloCluster_v1.cxx:81
xAOD::CaloCluster_v1::setEnergy
bool setEnergy(const CaloSample sampling, const float e)
Set energy for a given sampling. Returns false if the sample isn't part of the cluster.
Definition: CaloCluster_v1.cxx:526
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
xAODMaker
Definition: StoreGateSvc.h:72
CaloCluster::samplingPattern
unsigned int samplingPattern() const
Get sampling bitmask.
Definition: CaloCluster.cxx:1507
xAOD::CaloCluster_v1::setEta0
void setEta0(flt_t)
xAOD::CaloCluster_v1::setTime
void setTime(flt_t)
Set cluster time.
xAOD::CaloCluster
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloCluster.h:19
TruthTest.itE
itE
Definition: TruthTest.py:25
xAOD::CaloCluster_v1::MomentType
MomentType
Enums to identify different moments.
Definition: CaloCluster_v1.h:120
CaloCluster::cell_iterator
CaloCompositeCellBase< CaloClusterNavigable >::cell_iterator cell_iterator
Iterator on CaloCell s.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloCluster.h:115
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
xAOD::CaloClusterBadChannelList
std::vector< CaloClusterBadChannelData > CaloClusterBadChannelList
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloClusterBadChannelData.h:19
xAOD::CaloCluster_v1::setCalPhi
void setCalPhi(flt_t)
Set for signal state CALIBRATED.
Definition: CaloCluster_v1.cxx:316
CaloClusterNavigable::end
virtual object_iter end() const
end iterator for public object access
Definition: CaloClusterNavigable.h:309
xAOD::CaloCluster_v1::setRawE
void setRawE(flt_t)
Set Energy for signal state UNCALIBRATED.
Definition: CaloCluster_v1.cxx:284
xAOD::CaloCluster_v1::setCalM
void setCalM(flt_t)
Set mass for singal state CALIBRATED.
Definition: CaloCluster_v1.cxx:321
xAOD::CaloCluster_v1::setPhi0
void setPhi0(flt_t)
Set raw of cluster seed.
CaloCluster::getBadChannel
const badChannelList * getBadChannel() const
Definition: CaloCluster.cxx:1434
CaloSampling::CaloSample
CaloSample
Definition: Calorimeter/CaloGeoHelpers/CaloGeoHelpers/CaloSampling.h:22
CaloCluster.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
CaloCluster::beginMoment
moment_iterator beginMoment(bool useLink=true) const
First iterator on moment store.
Definition: CaloCluster.cxx:1119
test_pyathena.parent
parent
Definition: test_pyathena.py:15
xAOD::CaloCluster_v1::setAltE
void setAltE(flt_t)
Set Energy for signal state ALTCALIBRATED.
Definition: CaloCluster_v1.cxx:328
xAOD::CaloCluster_v1::setRawEta
void setRawEta(flt_t)
Set for signal state UNCALIBRATED.
Definition: CaloCluster_v1.cxx:289
CaloCluster
Principal data class for CaloCell clusters.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloCluster.h:79
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
P4SignalState::UNCALIBRATED
@ UNCALIBRATED
Definition: ISignalState.h:30
CaloClusterMoment::getValue
const double & getValue() const
returns the value of this moment
Definition: CaloClusterMoment.h:153
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
CaloCluster::MomentStoreIter::getMomentType
moment_type getMomentType() const
Function access to moment type.
Definition: CaloCluster.cxx:1572
xAODMaker::CaloClusterCnvTool::convert
virtual StatusCode convert(const CaloCluster *aod, xAOD::CaloCluster *xaod, CaloClusterCellLinkContainer *ccclc=0) const override
Function that fill an existing xAOD::CaloCluster object with info.
Definition: CaloClusterCnvTool.cxx:57
CaloClusterNavigable::begin
virtual object_iter begin() const
begin iterator for public object access
Definition: CaloClusterNavigable.h:303
CaloCluster::getTime
double getTime() const
Access cluster time.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloCluster.h:886
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
xAOD::CaloCluster_v1::setCalE
void setCalE(flt_t)
Set Energy for signal state CALIBRATED.
Definition: CaloCluster_v1.cxx:306
CaloCellContainer
Container class for CaloCell.
Definition: CaloCellContainer.h:55
CaloCluster::endMoment
moment_iterator endMoment(bool useLink=true) const
Last iterator on moment store.
Definition: CaloCluster.cxx:1141
CaloCluster::MomentStoreIter::getMoment
const CaloClusterMoment & getMoment() const
Function access to CaloClusterMoment.
Definition: CaloCluster.cxx:1570
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
CaloClusterBadChannelData
Definition: Calorimeter/CaloEvent/CaloEvent/CaloClusterBadChannelData.h:12
xAOD::CaloCluster_v1::addCellLink
void addCellLink(CaloClusterCellLink *CCCL)
Definition: CaloCluster_v1.h:721
CaloCluster::getClusterSize
unsigned int getClusterSize() const
Get cluster size.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloCluster.h:895
xAOD::CaloCluster_v1::setClusterSize
void setClusterSize(const ClusterSize)
Get cluster size.
Definition: CaloCluster_v1.cxx:369
CaloCluster::eta
virtual double eta() const
Retrieve eta independent of signal state.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloCluster.h:755
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
xAOD::CaloCluster_v1::addCell
bool addCell(const unsigned index, const double weight)
Method to add a cell to the cluster (Beware: Kinematics not updated!)
Definition: CaloCluster_v1.h:771
CaloCluster::e
virtual double e() const
Retrieve energy independent of signal state.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloCluster.h:753
CaloClusterContainer.h
xAOD::CaloCluster_v1::setPhi
bool setPhi(const CaloSample sampling, const float phi)
Set in a given sampling. Returns false if the sample isn't part of the cluster.
Definition: CaloCluster_v1.cxx:556
P4SignalState::CALIBRATED
@ CALIBRATED
Definition: ISignalState.h:31
CaloCluster::eta0
double eta0() const
Returns raw of cluster seed.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloCluster.h:1180
P4SignalState::ALTCALIBRATED
@ ALTCALIBRATED
Definition: ISignalState.h:32
CaloClusterCnvTool.h
CaloVariableType::ETA
@ ETA
Definition: CaloVariableType.h:16
xAOD::CaloCluster_v1::setEta
bool setEta(const CaloSample sampling, const float eta)
Set in a given sampling. Returns false if the sample isn't part of the cluster.
Definition: CaloCluster_v1.cxx:541
CaloCluster::m
virtual double m() const
Retrieve mass independent of signal state.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloCluster.h:764
AthAlgTool
Definition: AthAlgTool.h:26
xAOD::CaloCluster_v1::setAltPhi
void setAltPhi(flt_t)
Set for signal state ALTCALIBRATED.
Definition: CaloCluster_v1.cxx:338
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
CaloClusterNavigable::isCellLinkValid
virtual bool isCellLinkValid() const
Definition: CaloClusterNavigable.h:449
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
CaloVariableType::ENERGY
@ ENERGY
Definition: CaloVariableType.h:15
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
xAOD::CaloCluster_v1::setRawPhi
void setRawPhi(flt_t)
Set for signal state UNCALIBRATED.
Definition: CaloCluster_v1.cxx:294
CaloCluster::getVariable
double getVariable(const variable_type &varType, const sampling_type &samType, bool useLink=true) const
General sampling variable access.
Definition: CaloCluster.cxx:837
PlotCalibFromCool.vals
vals
Definition: PlotCalibFromCool.py:474
CaloCluster::phi
virtual double phi() const
Retrieve phi independent of signal state.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloCluster.h:759