ATLAS Offline Software
CaloCellRandomizer.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // ****************************************************************************************
6 // Randomize calo cell energy according to CaloNoise
7 //
8 // D. Varouchas
9 //
10 // ****************************************************************************************
11 
12 #include "CaloCellRandomizer.h"
13 #include "CaloEvent/CaloCell.h"
14 #include "CaloDetDescr/CaloDetDescrElement.h"
17 #include "GaudiKernel/ThreadLocalContext.h"
18 #include "CLHEP/Random/Randomize.h"
19 
20 using CLHEP::RandGauss;
21 
22 
23 // ======================================================
24 // Constructor
25 
27  const std::string& type,
28  const std::string& name,
29  const IInterface* parent)
31  m_corrSampleMin(0),m_corrSampleMax(0),m_fractionSigma(1),m_GaussRand(false),m_GaussRandGroupedSamples(false),m_GaussRandShifted(false),m_GaussRandShifted_Custom(false), m_shift_EMB(1),m_shift_EMEC(1),m_shift_HEC(1),m_shift_TileBar(1),m_shift_TileGap(1),m_shift_TileExt(1),m_shift_FCAL(1),
32  m_athRNGSvc ("AthRNGSvc", name),
33  m_randomEngine (nullptr)
34 {
35  declareInterface<CaloCellCorrection>(this);
36  // declareProperty("SampleNums",m_sampleNums);
37  declareProperty("DoRandomSampleMin",m_corrSampleMin);
38  declareProperty("DoRandomSampleMax",m_corrSampleMax);
39  declareProperty("RandomiseGroupedSampleCells",m_GaussRandGroupedSamples);
40  declareProperty("DoGaussRandomization",m_GaussRand);
41  declareProperty("DoShiftedGaussRandomization",m_GaussRandShifted);
42  declareProperty("FractionOfSigmaNoiseInShifting",m_fractionSigma);
43 
44  declareProperty("DoShiftedGaussRandomizationCustomisedInCalo",m_GaussRandShifted_Custom);
45  declareProperty("CustomShiftEMB",m_shift_EMB);
46  declareProperty("CustomShiftEMEC",m_shift_EMEC);
47  declareProperty("CustomShiftHEC",m_shift_HEC);
48  declareProperty("CustomShiftTileBar",m_shift_TileBar);
49  declareProperty("CustomShiftTileGap",m_shift_TileGap);
50  declareProperty("CustomShiftTileExt",m_shift_TileExt);
51  declareProperty("CustomShiftFCAL",m_shift_FCAL);
52  declareProperty("AthRNGSvc", m_athRNGSvc);
53  declareProperty("RandomStream", m_randomStream = "CaloCellRandomizer");
54 }
55 
56 //========================================================
57 // Initialize
58 
60 {
61  ATH_MSG_INFO( " in CaloCellRandomizer::initialize() " );
63  ATH_MSG_INFO( "Noise Tool retrieved" );
64  ATH_MSG_INFO( "CaloCellRandomizer initialize() end" );
65  ATH_CHECK( m_athRNGSvc.retrieve() );
66  m_randomEngine = m_athRNGSvc->getEngine (this, m_randomStream);
67  if (!m_randomEngine) {
68  ATH_MSG_ERROR("Could not get random number engine from AthRNGSvc. Abort.");
69  return StatusCode::FAILURE;
70  }
71  return StatusCode::SUCCESS;
72 }
73 
74 
75 // ============================================================================
76 
78  const EventContext& ctx) const
79 {
80  CLHEP::HepRandomEngine* engine = m_randomEngine->getEngine (ctx);
81 
82  int sampl = 0;
83  float Gauss = 0;
84  float GaussShifted = 0;
85 
86  const CaloDetDescrElement* caloDDE = theCell->caloDDE();
87  sampl=caloDDE->getSampling();
88 
89  //CaloNoise
91  double SigmaNoise = caloNoise->getNoise(theCell->ID(), theCell->gain());
92 
93 
94  Gauss = RandGauss::shoot(engine, 0.,1.);
95 
96  GaussShifted = Gauss+m_fractionSigma;
97 
98 
99  if( m_GaussRand ){
100  setenergy(theCell,(Gauss*SigmaNoise));
101  }
102 
103 
104  if(m_GaussRandShifted){
105  // setenergy(theCell,(GaussShifted));
106  setenergy(theCell,(GaussShifted*SigmaNoise));
107  }
108 
109 
110  if(m_GaussRandShifted_Custom){//var
111  if (sampl<4){
112  GaussShifted = RandGauss::shoot(engine, m_shift_EMB*SigmaNoise,SigmaNoise);
113  setenergy(theCell,(GaussShifted));
114  }
115  if (sampl>3 && sampl<8){
116  GaussShifted = RandGauss::shoot(engine, m_shift_EMEC*SigmaNoise,SigmaNoise);
117  setenergy(theCell,(GaussShifted));
118  }
119  if (sampl>7 && sampl<12){
120  GaussShifted = RandGauss::shoot(engine, m_shift_HEC*SigmaNoise,SigmaNoise);
121  setenergy(theCell,(GaussShifted));
122  }
123  if (sampl>11 && sampl<15){
124  GaussShifted = RandGauss::shoot(engine, m_shift_TileBar*SigmaNoise,SigmaNoise);
125  setenergy(theCell,(GaussShifted));
126  }
127  if (sampl>14 && sampl<18){
128  GaussShifted = RandGauss::shoot(engine, m_shift_TileGap*SigmaNoise,SigmaNoise);
129  setenergy(theCell,(GaussShifted));
130  }
131  if (sampl>17 && sampl<21){
132  GaussShifted = RandGauss::shoot(engine, m_shift_TileExt*SigmaNoise,SigmaNoise);
133  setenergy(theCell,(GaussShifted));
134  }
135  if (sampl>20 && sampl<24){
136  GaussShifted = RandGauss::shoot(engine, m_shift_FCAL*SigmaNoise,SigmaNoise);
137  setenergy(theCell,(GaussShifted));
138  }
139 
140  }
141 
142 
144  if(sampl>m_corrSampleMin && sampl<m_corrSampleMax){
145  setenergy(theCell,(Gauss*SigmaNoise));
146  }
147  }
148 
149 
150  //check if cells were masked before from tile reco alg, so to remove them, Tile Case only
151  // const TileCell* aTileCell = dynamic_cast<const TileCell*> (theCell);
152  //if CaloNoise big values means we have bad cells (for tile when badcell is not applicalble). get ride of these cells
153  if ( (sampl>11 && sampl<21) && SigmaNoise>999){
154  setenergy(theCell,0);
155  }
156 
157 
158 }
ReadHandleKey.h
Property holding a SG store/key/clid from which a ReadHandle is made.
CaloCellRandomizer::m_shift_TileExt
float m_shift_TileExt
Definition: CaloCellRandomizer.h:55
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
CaloCellCorrection
Definition: CaloCellCorrection.h:51
CaloCellRandomizer::m_athRNGSvc
ServiceHandle< IAthRNGSvc > m_athRNGSvc
Definition: CaloCellRandomizer.h:58
CaloCell.h
CaloCellRandomizer::CaloCellRandomizer
CaloCellRandomizer(const std::string &type, const std::string &name, const IInterface *parent)
Definition: CaloCellRandomizer.cxx:26
CaloNoise::getNoise
float getNoise(const IdentifierHash h, const int gain) const
Accessor by IdentifierHash and gain.
Definition: CaloNoise.h:34
CaloCellRandomizer::m_shift_FCAL
float m_shift_FCAL
Definition: CaloCellRandomizer.h:56
CaloCellRandomizer::m_randomEngine
ATHRNG::RNGWrapper * m_randomEngine
Definition: CaloCellRandomizer.h:60
CaloCellRandomizer::m_shift_TileGap
float m_shift_TileGap
Definition: CaloCellRandomizer.h:54
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CaloCellRandomizer::m_GaussRandShifted
bool m_GaussRandShifted
Definition: CaloCellRandomizer.h:48
CaloCellRandomizer::m_GaussRandGroupedSamples
bool m_GaussRandGroupedSamples
Definition: CaloCellRandomizer.h:47
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CaloCell::caloDDE
const CaloDetDescrElement * caloDDE() const
get pointer to CaloDetDescrElement (data member)
Definition: CaloCell.h:305
CaloCellRandomizer::m_randomStream
std::string m_randomStream
Definition: CaloCellRandomizer.h:59
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CaloCellRandomizer::m_shift_TileBar
float m_shift_TileBar
Definition: CaloCellRandomizer.h:53
CaloCellRandomizer::m_corrSampleMax
int m_corrSampleMax
Definition: CaloCellRandomizer.h:44
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
CaloCell::gain
CaloGain::CaloGain gain() const
get gain (data member )
Definition: CaloCell.h:345
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CaloCell::ID
Identifier ID() const
get ID (from cached data member) non-virtual and inline for fast access
Definition: CaloCell.h:279
ATHRNG::RNGWrapper::getEngine
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition: RNGWrapper.h:134
RNGWrapper.h
CaloCellRandomizer::MakeCorrection
virtual void MakeCorrection(CaloCell *theCell, const EventContext &ctx) const override
Definition: CaloCellRandomizer.cxx:77
CaloCellRandomizer::m_shift_EMEC
float m_shift_EMEC
Definition: CaloCellRandomizer.h:51
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
CaloDetDescrElement::getSampling
CaloCell_ID::CaloSample getSampling() const
cell sampling
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:395
CaloCellCorrection::setenergy
static void setenergy(CaloCell *lar_cell, float energy)
Definition: CaloCellCorrection.cxx:89
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
CaloCellRandomizer::m_GaussRand
bool m_GaussRand
Definition: CaloCellRandomizer.h:46
CaloCellRandomizer::m_shift_EMB
float m_shift_EMB
Definition: CaloCellRandomizer.h:50
CaloCellRandomizer::m_GaussRandShifted_Custom
bool m_GaussRandShifted_Custom
Definition: CaloCellRandomizer.h:49
CaloCellRandomizer::m_corrSampleMin
int m_corrSampleMin
Definition: CaloCellRandomizer.h:43
CaloCellRandomizer.h
CaloCellRandomizer::initialize
virtual StatusCode initialize() override
Definition: CaloCellRandomizer.cxx:59
CaloCellRandomizer::m_fractionSigma
float m_fractionSigma
Definition: CaloCellRandomizer.h:45
CaloCellRandomizer::m_caloNoiseKey
SG::ReadCondHandleKey< CaloNoise > m_caloNoiseKey
Definition: CaloCellRandomizer.h:39
CaloCellRandomizer::m_shift_HEC
float m_shift_HEC
Definition: CaloCellRandomizer.h:52