ATLAS Offline Software
Loading...
Searching...
No Matches
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//
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
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
62 CHECK(m_fracSKey.initialize());
63 CHECK(m_cablingKey.initialize());
64 CHECK(m_hitMapKey.initialize(SG::AllowEmpty));
65 CHECK(m_hitMapOutKey.initialize());
66 ATH_CHECK(detStore()->retrieve(m_calocell_id, "CaloCell_ID"));
67 ATH_CHECK(m_caloMgrKey.initialize());
68
69 // Incident Service:
70 ATH_MSG_DEBUG("Initialization completed successfully");
71
72 return StatusCode::SUCCESS;
73}
74
75StatusCode 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()) {
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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
const ServiceHandle< StoreGateSvc > & detStore() const
An algorithm that can be simultaneously executed in multiple threads.
This is a "hash" representation of an Identifier.
SG::ReadCondHandleKey< ILArfSampl > m_fracSKey
Property: Fraction of Energy Sampled (conditions input).
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
seedless option
LArCalibInject_timeSh(const std::string &name, ISvcLocator *pSvcLocator)
constructor
SG::WriteHandleKey< LArHitEMap > m_hitMapOutKey
output Lar Digits Cell container
StatusCode execute(const EventContext &context) const
Create LAr object save in TES (2 containers: 1 EM, 1 hadronic)
StatusCode initialize()
Read ascii files for auxiliary data (puslse shapes, noise, etc...)
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
const T * retrieve(const EventContext &context, const SG::ReadCondHandleKey< T > &handleKey) const
const CaloCell_ID * m_calocell_id
SG::ReadHandleKey< LArHitEMap > m_hitMapKey
hit map
const LARLIST & getData() const
Definition LArHitList.h:25
const_pointer_type cptr()
Dereference the pointer.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.