ATLAS Offline Software
L1CPHitsTools.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3 */
5 // L1CPHitsTools.cxx,
7 
8 #include <map>
9 #include <numeric>
10 
14 #include "TrigT1CaloEvent/CPMRoI.h"
19 #include "L1CPHitsTools.h"
20 
21 namespace LVL1 {
22 
26  const std::string& name,
27  const IInterface* parent)
28  :
30 {
31  declareInterface<IL1CPHitsTools>(this);
32 }
33 
37 {
38 }
39 
40 
44 {
46 
47  ATH_MSG_INFO( "Initialization completed" );
48 
49  return StatusCode::SUCCESS;
50 }
51 
55 {
56  return StatusCode::SUCCESS;
57 }
58 
62  DataVector<CPMRoI>* cpmRoiVec) const
63 {
65  DataVector<EmTauROI>::const_iterator pose = emTauRoiVec->end();
66  for (; pos != pose; ++pos) {
67  CPMRoI* roi = new CPMRoI((*pos)->roiWord());
68  cpmRoiVec->push_back(roi);
69  }
70 }
71 
75  DataVector<CPMHits>* cpmHitsVec) const
76 {
77  std::vector<const DataVector<CPMRoI>*> cpmRoiColls(1, cpmRoiVec);
78  formCPMHits(cpmRoiColls, cpmHitsVec, 0);
79 }
80 
84  const std::vector<const DataVector<CPMRoI>*>& cpmRoiColls,
85  DataVector<CPMHits>* cpmHitsVec, int peak) const
86 {
88  std::map<unsigned int, CPMHits*> cpmHitsMap;
90  int timeslices = cpmRoiColls.size();
91 
92  for (int slice = 0; slice < timeslices; ++slice) {
93  const DataVector<CPMRoI>* cpmRoiVec = cpmRoiColls[slice];
94 
95  for (it=cpmRoiVec->begin(); it!=cpmRoiVec->end(); ++it){
96  const CPMRoI* roi = *it;
97  unsigned int crate = roi->crate();
98  unsigned int module = roi->cpm();
99  unsigned int key = testKey.cpmKey(crate, module);
100  if (m_debug) {
102  CoordinateRange coord = decoder.coordinate(roi->roiWord());
103  if (timeslices > 1) ATH_MSG_DEBUG( "Slice " << slice << ", ");
104  ATH_MSG_DEBUG( "Found RoI with (eta, phi) = ("
105  << coord.eta() << ", " << coord.phi() << ") " << ", RoIWord = "
106  << std::hex << roi->roiWord() << std::dec );
107  ATH_MSG_DEBUG( "Crate = " << crate << ", Module = " << module
108  << ", CPM key = " << key );
109  }
110  CPMHits* cpmHits=0;
111  // find whether corresponding CPMHits already exists
113  // if not, create it
114  if ( test==cpmHitsMap.end()){
115  ATH_MSG_DEBUG( "New key. CPM has crate = "
116  << crate << ", Module = " << module );
117  ATH_MSG_DEBUG( "Create new CPMHits" );
118  cpmHits = new CPMHits(crate, module);
119  if (timeslices > 1) {
120  HitsVector hitVec(timeslices);
121  cpmHits->addHits(hitVec, hitVec);
122  cpmHits->setPeak(peak);
123  }
124 
125  ATH_MSG_DEBUG( "and insert into map" );
126  cpmHitsMap.insert(
127  std::map<unsigned int,CPMHits*>::value_type(key,cpmHits));
128  cpmHitsVec->push_back(cpmHits);
129  }
130  else {
131  ATH_MSG_DEBUG( "Existing CPMHits" );
132  cpmHits = test->second; // Already exists, so set pointer
133  }
134  // increment hit multiplicity.
135  ATH_MSG_DEBUG( "Update CPM hits" );
136  HitsVector hitvec0(cpmHits->HitsVec0());
137  HitsVector hitvec1(cpmHits->HitsVec1());
138  unsigned int hits0 = hitvec0[slice];
139  unsigned int hits1 = hitvec1[slice];
140  hits0 = addHits(hits0, roi->roiWord()&0xFF, 24, 8);
141  hits1 = addHits(hits1,(roi->roiWord()&0xFF00)>>8, 24, 8);
142  hitvec0[slice] = hits0;
143  hitvec1[slice] = hits1;
144  cpmHits->addHits(hitvec0, hitvec1);
145  ATH_MSG_DEBUG( "All done for this one" );
146  }
147  }
148 }
149 
153  DataVector<CMMCPHits>* cmmHitsVec) const
154 {
155  DataVector<CMMCPHits>* cmmHitsCrate = new DataVector<CMMCPHits>;
157  formCMMCPHitsModule(cpmHitsVec, cmmHitsVec);
158  formCMMCPHitsCrate(cmmHitsVec, cmmHitsCrate);
159  formCMMCPHitsSystem(cmmHitsCrate, cmmHitsSys);
160  mergeCMMCPHits(cmmHitsVec, cmmHitsCrate);
161  mergeCMMCPHits(cmmHitsVec, cmmHitsSys);
162  delete cmmHitsCrate;
163  delete cmmHitsSys;
164 }
165 
169  DataVector<CMMCPHits>* cmmHitsMod) const
170 {
172  DataVector<CPMHits>::const_iterator pose = cpmHitsVec->end();
173  for (; pos != pose; ++pos) {
174  const CPMHits* hits = *pos;
175  int crate = hits->crate();
176  int cpm = hits->module();
177  int peak = hits->peak();
178  HitsVector hits0(hits->HitsVec0());
179  HitsVector hits1(hits->HitsVec1());
180  ErrorVector err0(hits0.size());
181  ErrorVector err1(hits1.size());
182  cmmHitsMod->push_back(new CMMCPHits(crate, cpm, hits0, hits1,
183  err0, err1, peak));
184  }
185 }
186 
190  DataVector<CMMCPHits>* cmmHitsCrate) const
191 {
192  int peakm = 0;
193  HitsVector crate0Hit0(1);
194  HitsVector crate0Hit1(1);
195  HitsVector crate1Hit0(1);
196  HitsVector crate1Hit1(1);
197  HitsVector crate2Hit0(1);
198  HitsVector crate2Hit1(1);
199  HitsVector crate3Hit0(1);
200  HitsVector crate3Hit1(1);
202  DataVector<CMMCPHits>::const_iterator pose = cmmHitsMod->end();
203  for (; pos != pose; ++pos) {
204  const CMMCPHits* hits = *pos;
205  int dataId = hits->dataID();
206  if (dataId > 14) continue;
207  int crate = hits->crate();
208  int peak = hits->peak();
209  if (peak > peakm) peakm = peak;
210  HitsVector hits0(hits->HitsVec0());
211  HitsVector hits1(hits->HitsVec1());
212  if (crate == 0) {
213  addCMMCPHits(crate0Hit0, hits0);
214  addCMMCPHits(crate0Hit1, hits1);
215  } else if (crate == 1) {
216  addCMMCPHits(crate1Hit0, hits0);
217  addCMMCPHits(crate1Hit1, hits1);
218  } else if (crate == 2) {
219  addCMMCPHits(crate2Hit0, hits0);
220  addCMMCPHits(crate2Hit1, hits1);
221  } else if (crate == 3) {
222  addCMMCPHits(crate3Hit0, hits0);
223  addCMMCPHits(crate3Hit1, hits1);
224  }
225  }
226  // Save non-zero crate totals
227  saveCMMCPHits(cmmHitsCrate, crate0Hit0, crate0Hit1, 0, CMMCPHits::LOCAL,
228  peakm);
229  saveCMMCPHits(cmmHitsCrate, crate1Hit0, crate1Hit1, 1, CMMCPHits::LOCAL,
230  peakm);
231  saveCMMCPHits(cmmHitsCrate, crate2Hit0, crate2Hit1, 2, CMMCPHits::LOCAL,
232  peakm);
233  saveCMMCPHits(cmmHitsCrate, crate3Hit0, crate3Hit1, 3, CMMCPHits::LOCAL,
234  peakm);
235  saveCMMCPHits(cmmHitsCrate, crate0Hit0, crate0Hit1, 3, CMMCPHits::REMOTE_0,
236  peakm);
237  saveCMMCPHits(cmmHitsCrate, crate1Hit0, crate1Hit1, 3, CMMCPHits::REMOTE_1,
238  peakm);
239  saveCMMCPHits(cmmHitsCrate, crate2Hit0, crate2Hit1, 3, CMMCPHits::REMOTE_2,
240  peakm);
241 }
242 
246  const DataVector<CMMCPHits>* cmmHitsCrate,
247  DataVector<CMMCPHits>* cmmHitsSys) const
248 {
249  int peakm = 0;
250  HitsVector systemHit0(1);
251  HitsVector systemHit1(1);
253  DataVector<CMMCPHits>::const_iterator pose = cmmHitsCrate->end();
254  for (; pos != pose; ++pos) {
255  const CMMCPHits* hits = *pos;
256  if (hits->crate() != 3) continue;
257  int dataId = hits->dataID();
258  if (dataId != CMMCPHits::LOCAL &&
259  dataId != CMMCPHits::REMOTE_0 &&
260  dataId != CMMCPHits::REMOTE_1 &&
261  dataId != CMMCPHits::REMOTE_2) continue;
262  int peak = hits->peak();
263  if (peak > peakm) peakm = peak;
264  HitsVector hits0(hits->HitsVec0());
265  HitsVector hits1(hits->HitsVec1());
266  addCMMCPHits(systemHit0, hits0);
267  addCMMCPHits(systemHit1, hits1);
268  }
269  // Save non-zero system totals
270  saveCMMCPHits(cmmHitsSys, systemHit0, systemHit1, 3, CMMCPHits::TOTAL, peakm);
271 }
272 
276 {
277  int size1 = vec1.size();
278  int size2 = vec2.size();
279  if (size1 < size2) vec1.resize(size2);
280  HitsVector::iterator pos1 = vec1.begin();
281  HitsVector::iterator pose1 = vec1.end();
282  HitsVector::const_iterator pos2 = vec2.begin();
283  HitsVector::const_iterator pose2 = vec2.end();
284  for (; pos1 != pose1 && pos2 != pose2; ++pos1, ++pos2) {
285  *pos1 = addHits(*pos1, *pos2, 24, 24);
286  }
287 }
288 
291 unsigned int L1CPHitsTools::addHits(unsigned int hitMult,
292  unsigned int hitVec,
293  int multBits, int vecBits) const
294 {
295  ATH_MSG_DEBUG("addHits: Original hitMult = " << std::hex << hitMult
296  << ". Add hitWord = " << hitVec << std::dec);
297 
298  // Results transmitted in 2 words, each reporting half of the CP thresholds
299  int nthresh = TrigT1CaloDefs::numOfCPThresholds/2;
300 
301  int nbitsOut = multBits/nthresh;
302  int nbitsIn = vecBits/nthresh;
303 
304  ATH_MSG_DEBUG(" Bits per threshold = " << nbitsOut);
305 
306  int max = (1<<nbitsOut) - 1;
307  unsigned int multMask = max;
308  unsigned int hitMask = (1<<nbitsIn) - 1;
309  unsigned int shift = 0;
310 
311  unsigned int hits = 0;
312 
313  for (int i = 0; i < nthresh; i++) {
314  int mult = (hitMult&multMask) + (hitVec&hitMask);
315  mult = ( (mult<=max) ? mult : max);
316  hits += (mult<<shift);
317 
318  hitMult >>= nbitsOut;
319  hitVec >>= nbitsIn;
320  shift += nbitsOut;
321  }
322 
323  ATH_MSG_DEBUG("addHits returning hitMult = "
324  << std::hex << hits << std::dec );
325 
326  return hits;
327 }
328 
332  DataVector<CMMCPHits>* cmmHitsVec2) const
333 {
334  int size = cmmHitsVec2->size();
335  for (int index = 0; index < size; ++index) {
336  CMMCPHits* hitsIn = 0;
337  CMMCPHits* hitsOut = 0;
338  cmmHitsVec2->swapElement(index, hitsIn, hitsOut);
339  cmmHitsVec1->push_back(hitsOut);
340  }
341  cmmHitsVec2->clear();
342 }
343 
347  const HitsVector& hits0,
348  const HitsVector& hits1,
349  int crate, int dataId, int peak) const
350 {
351  if (std::accumulate(hits0.begin(), hits0.end(), 0) ||
352  std::accumulate(hits1.begin(), hits1.end(), 0)) {
353  ErrorVector err0(hits0.size());
354  ErrorVector err1(hits1.size());
355  cmmHitsVec->push_back(new CMMCPHits(crate, dataId, hits0, hits1,
356  err0, err1, peak));
357  }
358 }
359 
360 } // end of namespace
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
CPMHits.h
LVL1::L1CPHitsTools::initialize
virtual StatusCode initialize()
standard Athena-Algorithm method
Definition: L1CPHitsTools.cxx:43
LVL1::ClusterProcessorModuleKey
The ClusterProcessorModuleKey object provides the key for each trigger tower depending on its eta-phi...
Definition: ClusterProcessorModuleKey.h:49
LVL1::CPMHits::HitsVec0
const std::vector< unsigned int > & HitsVec0() const
Multi-slice accessors.
Definition: CPMHits.cxx:81
D3PDMakerTestInstan::vec2
std::vector< D3PDTest::MyVec2 > vec2
Definition: D3PDMakerTestDict.h:14
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
LVL1::CPMHits::addHits
void addHits(const std::vector< unsigned int > &hits0, const std::vector< unsigned int > &hits1)
Add hits to existing object.
Definition: CPMHits.cxx:89
TRTCalib_Extractor.hits
hits
Definition: TRTCalib_Extractor.py:35
LVL1::L1CPHitsTools::formCPMRoI
virtual void formCPMRoI(const DataVector< EmTauROI > *emTauRoiVec, DataVector< CPMRoI > *cpmRoiVec) const
EmTauROI to CPMRoI conversion.
Definition: L1CPHitsTools.cxx:61
max
#define max(a, b)
Definition: cfImp.cxx:41
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
LVL1::L1CPHitsTools::L1CPHitsTools
L1CPHitsTools(const std::string &type, const std::string &name, const IInterface *parent)
Constructor.
Definition: L1CPHitsTools.cxx:25
python.LArCondContChannels.decoder
decoder
def channelSelection(self, channelList, groupType): if groupType == self.SingleGroup: pass elif group...
Definition: LArCondContChannels.py:618
LVL1::CPMHits::setPeak
void setPeak(int peak)
In multi-slice readout, need to specify which is peak slice.
Definition: CPMHits.cxx:96
index
Definition: index.py:1
accumulate
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
Definition: FPGATrackSimMatrixAccumulator.cxx:22
CPRoIDecoder.h
skel.it
it
Definition: skel.GENtoEVGEN.py:396
ClusterProcessorModuleKey.h
AthCommonMsg< AlgTool >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
LVL1::CPMHits
The CPMHits object contains the hit data produced by a given Cluster Processor Module,...
Definition: Trigger/TrigT1/TrigT1CaloEvent/TrigT1CaloEvent/CPMHits.h:35
TrigInDetValidation_Base.test
test
Definition: TrigInDetValidation_Base.py:147
LVL1::L1CPHitsTools::addHits
unsigned int addHits(unsigned int hitMult, unsigned int hitVec, int multBits, int vecBits) const
Increment CPM/CMM hit word.
Definition: L1CPHitsTools.cxx:291
LVL1::ClusterProcessorModuleKey::cpmKey
unsigned int cpmKey(unsigned int crate, unsigned int module)
calculates key from crate and module index
Definition: ClusterProcessorModuleKey.cxx:47
LVL1::L1CPHitsTools::formCMMCPHitsSystem
virtual void formCMMCPHitsSystem(const DataVector< CMMCPHits > *cmmHitsCrate, DataVector< CMMCPHits > *cmmHitsSys) const
form partial CMM-CP hits (system) from crate CMM-CP hits
Definition: L1CPHitsTools.cxx:245
LVL1::L1CPHitsTools::formCMMCPHitsModule
virtual void formCMMCPHitsModule(const DataVector< CPMHits > *cpmHitsVec, DataVector< CMMCPHits > *cmmHitsMod) const
form partial CMM-CP hits (module) from CPM hits
Definition: L1CPHitsTools.cxx:168
DataVector::swapElement
void swapElement(size_type index, value_type newElem, reference oldElem)
Swap one element out of the container.
LVL1
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...
Definition: ICMMCPHitsCnvTool.h:18
LVL1::CMMCPHits::REMOTE_0
@ REMOTE_0
Definition: Trigger/TrigT1/TrigT1CaloEvent/TrigT1CaloEvent/CMMCPHits.h:33
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
python.PyAthena.module
module
Definition: PyAthena.py:131
LVL1::CPMRoI::cpm
int cpm() const
Return CPM number (1-14)
Definition: Trigger/TrigT1/TrigT1CaloEvent/TrigT1CaloEvent/CPMRoI.h:86
LVL1::CoordinateRange
CoordinateRange class declaration.
Definition: CoordinateRange.h:36
perfmonmt-refit.slice
slice
Definition: perfmonmt-refit.py:52
lumiFormat.i
int i
Definition: lumiFormat.py:85
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
LVL1::CMMCPHits
Summary of CP (EM/tau) hits received by the merger modules.
Definition: Trigger/TrigT1/TrigT1CaloEvent/TrigT1CaloEvent/CMMCPHits.h:30
LVL1::CMMCPHits::LOCAL
@ LOCAL
Definition: Trigger/TrigT1/TrigT1CaloEvent/TrigT1CaloEvent/CMMCPHits.h:33
LVL1::L1CPHitsTools::mergeCMMCPHits
void mergeCMMCPHits(DataVector< CMMCPHits > *cmmHitsVec1, DataVector< CMMCPHits > *cmmHitsVec2) const
Merge CMM-CP hits vectors.
Definition: L1CPHitsTools.cxx:331
LVL1::CPMRoI
CPM RoI data.
Definition: Trigger/TrigT1/TrigT1CaloEvent/TrigT1CaloEvent/CPMRoI.h:20
test_pyathena.parent
parent
Definition: test_pyathena.py:15
xAOD::CPMHits
CPMHits_v1 CPMHits
Define the latest version of the CPMHits class.
Definition: Event/xAOD/xAODTrigL1Calo/xAODTrigL1Calo/CPMHits.h:14
LVL1::L1CPHitsTools::~L1CPHitsTools
virtual ~L1CPHitsTools()
default destructor
Definition: L1CPHitsTools.cxx:36
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
DataVector::clear
void clear()
Erase all the elements in the collection.
LVL1::CMMCPHits::TOTAL
@ TOTAL
Definition: Trigger/TrigT1/TrigT1CaloEvent/TrigT1CaloEvent/CMMCPHits.h:33
TrigConf::name
Definition: HLTChainList.h:35
LVL1::CPMRoI::roiWord
uint32_t roiWord() const
Return packed RoI word.
Definition: Trigger/TrigT1/TrigT1CaloEvent/TrigT1CaloEvent/CPMRoI.h:111
CMMCPHits.h
CPMRoI.h
EmTauROI.h
LVL1::L1CPHitsTools::m_debug
bool m_debug
Definition: L1CPHitsTools.h:104
LVL1::L1CPHitsTools::finalize
virtual StatusCode finalize()
standard Athena-Algorithm method
Definition: L1CPHitsTools.cxx:54
LVL1::L1CPHitsTools::formCMMCPHitsCrate
virtual void formCMMCPHitsCrate(const DataVector< CMMCPHits > *cmmHitsMod, DataVector< CMMCPHits > *cmmHitsCrate) const
form partial CMM-CP hits (crate) from module CMM-CP hits
Definition: L1CPHitsTools.cxx:189
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
LVL1::L1CPHitsTools::ErrorVector
std::vector< int > ErrorVector
Definition: L1CPHitsTools.h:89
TrigT1CaloDefs.h
JetVoronoiDiagramHelpers::coord
double coord
Definition: JetVoronoiDiagramHelpers.h:45
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
LVL1::CPRoIDecoder
A level 1 calorimeter trigger conversion service: returns the Coordinate represented by a RoI word.
Definition: CPRoIDecoder.h:37
DeMoScan.index
string index
Definition: DeMoScan.py:364
CoordinateRange.h
LVL1::TrigT1CaloDefs::numOfCPThresholds
static const unsigned int numOfCPThresholds
Definition: TrigT1CaloDefs.h:125
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
LVL1::CMMCPHits::REMOTE_2
@ REMOTE_2
Definition: Trigger/TrigT1/TrigT1CaloEvent/TrigT1CaloEvent/CMMCPHits.h:33
LVL1::L1CPHitsTools::HitsVector
std::vector< unsigned int > HitsVector
Definition: L1CPHitsTools.h:88
DEBUG
#define DEBUG
Definition: page_access.h:11
LVL1::CPMHits::HitsVec1
const std::vector< unsigned int > & HitsVec1() const
Definition: CPMHits.cxx:84
LVL1::L1CPHitsTools::formCMMCPHits
virtual void formCMMCPHits(const DataVector< CPMHits > *cpmHitsVec, DataVector< CMMCPHits > *cmmHitsVec) const
form complete CMM-CP hits from CPM hits
Definition: L1CPHitsTools.cxx:152
AthAlgTool
Definition: AthAlgTool.h:26
LVL1::CMMCPHits::REMOTE_1
@ REMOTE_1
Definition: Trigger/TrigT1/TrigT1CaloEvent/TrigT1CaloEvent/CMMCPHits.h:33
LVL1::L1CPHitsTools::formCPMHits
virtual void formCPMHits(const DataVector< CPMRoI > *cpmRoiVec, DataVector< CPMHits > *cpmHitsVec) const
form CPM hits from RoIs - single slice
Definition: L1CPHitsTools.cxx:74
LVL1::CPMRoI::crate
int crate() const
Return crate number (0-1)
Definition: Trigger/TrigT1/TrigT1CaloEvent/TrigT1CaloEvent/CPMRoI.h:81
LVL1::L1CPHitsTools::addCMMCPHits
void addCMMCPHits(HitsVector &vec1, const HitsVector &vec2) const
Add hits from second vector to first.
Definition: L1CPHitsTools.cxx:275
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
xAOD::CMMCPHits
CMMCPHits_v1 CMMCPHits
Define the latest version of the CMMCPHits class.
Definition: Event/xAOD/xAODTrigL1Calo/xAODTrigL1Calo/CMMCPHits.h:17
xAOD::CPMRoI
CPMRoI_v1 CPMRoI
Define the latest version of the CPMRoI class.
Definition: Event/xAOD/xAODTrigL1Calo/xAODTrigL1Calo/CPMRoI.h:14
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
L1CPHitsTools.h
LVL1::L1CPHitsTools::saveCMMCPHits
void saveCMMCPHits(DataVector< CMMCPHits > *cmmHitsVec, const HitsVector &hits0, const HitsVector &hits1, int crate, int dataId, int peak) const
Save non-zero CMM-CP hits.
Definition: L1CPHitsTools.cxx:346
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37