ATLAS Offline Software
LArCalibInject_timeSh.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 // + +
7 // + Author ........: Denis O. Damazio , Will Buttinger (Cambridge) +
8 // + Institut ......: BNL +
9 // + Creation date .: 04/05/2021 +
10 // + +
11 // +======================================================================+
12 //
13 // ........ includes
14 //
15 #include "LArCalibInject_timeSh.h"
16 // .......... utilities
17 //
18 #include <math.h>
19 #include <sys/time.h>
20 
21 #include <chrono>
22 #include <fstream>
23 #include <random>
24 //
27 
28 //
29 // ........ Gaudi needed includes
30 //
31 #include "Gaudi/Property.h"
32 #include "GaudiKernel/IService.h"
33 #include "GaudiKernel/MsgStream.h"
34 
35 //
37  ISvcLocator* pSvcLocator)
38  : AthReentrantAlgorithm(name, pSvcLocator), m_calocell_id(nullptr) {
39  //
40  // ........ default values of private data
41  //
42 
43  m_seedLess = false;
44  return;
45 }
46 
50  return;
51 }
52 
54  //
55  // ......... declaration
56  //
57 
58  ATH_MSG_INFO("***********************************************");
59  ATH_MSG_INFO("* Steering options for LArCalibInject_timeSh algorithm *");
60  ATH_MSG_INFO("***********************************************");
61 
66  ATH_CHECK(detStore()->retrieve(m_calocell_id, "CaloCell_ID"));
68 
69  // Incident Service:
70  ATH_MSG_DEBUG("Initialization completed successfully");
71 
72  return StatusCode::SUCCESS;
73 }
74 
75 StatusCode LArCalibInject_timeSh::execute(const EventContext& context) const {
76 
77  ATH_MSG_DEBUG("Begining of execution");
78 
79  //
80  // ....... fill the LArHitEMap
81  //
82 
83  /* will be used in the near future for better energy to rec energy matching
84  auto fracS = this->retrieve(context,m_fracSKey);
85  */
86 
88  ATH_CHECK(caloMgrHandle.isValid());
89 
90  const auto* cabling = this->retrieve(context, m_cablingKey);
91 
92  SG::WriteHandle<LArHitEMap> hitEMapOutHandle(m_hitMapOutKey, context);
93  auto hitEMapOut = std::make_unique<LArHitEMap>(cabling, m_calocell_id,
94  *caloMgrHandle, false);
95 
96  //
97  // ... initialise vectors for sums of energy in each TT
98  //
99 
100  int it = 0;
101  int it_end(200);
102 
103  // m_nSamples=5;
104 
105  // Copy what exist
106  if (!m_hitMapKey.empty()) {
107  SG::ReadHandle<LArHitEMap> hitmap(m_hitMapKey, context);
108  const auto* hitmapPtr = hitmap.cptr();
109  it_end = hitmapPtr->GetNbCells();
110 
111  for (; it != it_end; ++it) {
112  const LArHitList& hitlist = hitmapPtr->GetCell(it);
113  const std::vector<std::pair<float, float> >& timeE = hitlist.getData();
114  if (!timeE.empty()) {
115  const IdentifierHash idhash(it);
116  for (size_t i = 0; i < timeE.size(); i++) {
117  std::pair<float, float> energy_time = timeE[i];
118  hitEMapOut->AddEnergy(idhash, energy_time.first, energy_time.second);
119  }
120  } // end of if timeE.size()
121  } // it end
122  } // end of empty Key check
123  // Now, become creative
124  it = 0;
125  unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
126  std::default_random_engine generator(seed);
127  std::uniform_real_distribution<double> distribution(-12.5, 12.5);
128  it_end = 480;
129  for (; it != it_end; it += 16) {
130  const IdentifierHash idhash(it);
131  float time_inject = (float)distribution(generator);
132  hitEMapOut->AddEnergy(idhash, 10500.0, time_inject);
133  }
134  ATH_CHECK(hitEMapOutHandle.record(std::move(hitEMapOut)));
135 
136  return StatusCode::SUCCESS;
137 }
138 
140 
141  ATH_MSG_INFO(" LArCalibInject_timeSh finalize completed successfully");
142 
143  return StatusCode::SUCCESS;
144 }
LArHitList.h
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
LArCalibInject_timeSh::m_calocell_id
const CaloCell_ID * m_calocell_id
Definition: LArCalibInject_timeSh.h:102
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
LArCalibInject_timeSh::LArCalibInject_timeSh
LArCalibInject_timeSh(const std::string &name, ISvcLocator *pSvcLocator)
constructor
Definition: LArCalibInject_timeSh.cxx:36
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
skel.it
it
Definition: skel.GENtoEVGEN.py:423
LArCalibInject_timeSh::m_hitMapOutKey
SG::WriteHandleKey< LArHitEMap > m_hitMapOutKey
output Lar Digits Cell container
Definition: LArCalibInject_timeSh.h:94
LArCalibInject_timeSh::m_seedLess
bool m_seedLess
Definition: LArCalibInject_timeSh.h:107
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
LArCalibInject_timeSh::initialize
StatusCode initialize()
Read ascii files for auxiliary data (puslse shapes, noise, etc...)
Definition: LArCalibInject_timeSh.cxx:53
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
LArHitList::getData
const LARLIST & getData() const
Definition: LArHitList.h:25
LArCalibInject_timeSh::retrieve
const T * retrieve(const EventContext &context, SG::ReadCondHandleKey< T > handleKey) const
Definition: LArCalibInject_timeSh.h:76
python.handimod.now
now
Definition: handimod.py:675
LArCalibInject_timeSh::m_caloMgrKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Definition: LArCalibInject_timeSh.h:103
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
LArCalibInject_timeSh.h
LArCalibInject_timeSh::m_hitMapKey
SG::ReadHandleKey< LArHitEMap > m_hitMapKey
hit map
Definition: LArCalibInject_timeSh.h:91
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
LArHitList
Definition: LArHitList.h:9
LArCalibInject_timeSh::execute
StatusCode execute(const EventContext &context) const
Create LAr object save in TES (2 containers: 1 EM, 1 hadronic)
Definition: LArCalibInject_timeSh.cxx:75
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
LArCalibInject_timeSh::finalize
StatusCode finalize()
Definition: LArCalibInject_timeSh.cxx:139
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
mc.generator
generator
Configure Herwig7 These are the commands corresponding to what would go into the regular Herwig infil...
Definition: mc.MGH7_FxFx_H71-DEFAULT_test.py:18
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
LArCalibInject_timeSh::m_fracSKey
SG::ReadCondHandleKey< ILArfSampl > m_fracSKey
Property: Fraction of Energy Sampled (conditions input).
Definition: LArCalibInject_timeSh.h:72
LArHitContainer.h
LArCalibInject_timeSh::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
seedless option
Definition: LArCalibInject_timeSh.h:98
LArHitEMap::GetNbCells
int GetNbCells(void) const
Definition: LArHitEMap.cxx:65
IdentifierHash
Definition: IdentifierHash.h:38
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
LArCalibInject_timeSh::~LArCalibInject_timeSh
~LArCalibInject_timeSh()
destructor
Definition: LArCalibInject_timeSh.cxx:47
readCCLHist.float
float
Definition: readCCLHist.py:83