ATLAS Offline Software
Loading...
Searching...
No Matches
D3PDConverter.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
12#include "LArCafJobs/CellInfo.h"
15
17
18#include <iostream>
19using std::cout;
20using std::endl;
21
22using namespace LArSamples;
23
25{
26 DataStore* samples = new DataStore();
27 RunData* runData = nullptr;
28
29 cout << "Processing " << fChain->GetEntries() << " entries" << endl;
30 for (long long i = 0; i < fChain->GetEntries(); i++) {
31 if (i % 500 == 0) cout << "Processing Entry " << i << endl;
32 fChain->GetEntry(i);
33 if (!runData || runData->run() != (int)RunNumber) {
34 // new run
35 runData = new RunData(RunNumber);
36 samples->addRun(runData);
37 }
38
39 EventData* eventData = new EventData(EventNumber, 0, lbn, bcid);
40 eventData->setRunData(runData);
41 unsigned int eventIndex = samples->addEvent(eventData);
42
43
44 for (int j = 0; j < cc_sel_n; j++) {
45 // skip Tile cells
46 if ((*cc_sel_DetCells)[j] & 8) continue;
47 unsigned int hash = m_id2hash[(*cc_sel_IdCells)[j]];
48 if (hash == 0) {
49 cout << "ERROR: skipping cell with offline ID = " << (*cc_sel_IdCells)[j] << endl;
50 continue;
51 }
52
53 // find digit
54 int digitIndex = -1;
55 for (int k = 0; k < lardigit_n; k++) {
56 if ((*lardigit_offlineId)[k] == (*cc_sel_IdCells)[j]) {
57 digitIndex = k;
58 break;
59 }
60 }
61 //if (digitIndex >= 0) cout << "digitIndex = " << digitIndex << endl;
62 hash -= 1;
63 HistoryContainer* histCont = samples->hist_cont(hash);
64 CellInfo* info = nullptr;
65 if (!histCont) {
66 const CellInfo* templateInfo = m_template->cellInfo(hash);
67 info = new CellInfo(templateInfo->calo(), templateInfo->layer(),
68 templateInfo->iEta(), templateInfo->iPhi(),
69 templateInfo->feedThrough(), templateInfo->slot(), templateInfo->channel(),
70 nullptr,nullptr,nullptr, templateInfo->position(), templateInfo->onlid());
71 histCont = samples->makeNewHistory(IdentifierHash(hash), info);
72 }
73 else
74 info = histCont->cell_info();
75
77 std::vector<short> samples;
78 if (digitIndex >= 0) {
79 gain = (CaloGain::CaloGain)(*lardigit_gain)[digitIndex];
80 std::vector<int> intSamples = (*lardigit_Samples)[digitIndex];
81 for (int s : intSamples) {
82 samples.push_back((short)s);
83 }
84 }
86 new DataContainer(gain, samples, (*cc_sel_E)[j], (*cc_sel_TimeCells)[j],
87 (*cc_sel_QCells)[j], eventIndex,
88 std::vector<float>(), (*cc_sel_Sigma)[j],
89 -1, -1, (*cc_sel_BadCells)[j]);
90 histCont->add(data);
91 }
92 }
93 samples->writeTrees(outputFileName);
94 delete samples;
95 return true;
96}
97
98
99bool D3PDConverter::initMapping(const TString& templateFile, const TString& translatorFile)
100{
101 LArIdTranslatorHelper translator(translatorFile);
102 m_template = Interface::open(templateFile);
103
104 cout << "Making online->hash map" << endl;
105 std::map<unsigned long long, unsigned int> on2hash;
106 for (unsigned int i = 0; i < m_template->nChannels(); i++) {
107 const CellInfo* info = m_template->cellInfo(i);
108 if (!info) continue;
109 on2hash[info->onlid()] = i;
110 }
111
112 cout << "Making offlineID->hash map" << endl;
113 for (unsigned int i = 0; i < translator.Tree()->GetEntries(); i++) {
114 translator.Tree()->GetEntry(i);
115 m_id2hash[translator.offlid] = on2hash[translator.onlid] + 1;
116 }
117 return true;
118}
119
120
121
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
static const std::string outputFileName
TGraphErrors * GetEntries(TH2F *histo)
vector< unsigned int > * lardigit_offlineId
vector< float > * cc_sel_TimeCells
vector< int > * cc_sel_BadCells
vector< unsigned int > * cc_sel_IdCells
UInt_t RunNumber
current Tree number in a TChain
vector< int > * cc_sel_DetCells
vector< int > * cc_sel_QCells
vector< float > * cc_sel_E
vector< float > * cc_sel_Sigma
vector< int > * lardigit_gain
This is a "hash" representation of an Identifier.
short slot() const
Definition CellInfo.h:68
short layer() const
Definition CellInfo.h:53
TVector3 position() const
Definition CellInfo.cxx:204
short feedThrough() const
Definition CellInfo.h:65
ULong64_t onlid() const
Definition CellInfo.h:90
short iPhi() const
Definition CellInfo.h:62
CaloId calo() const
Definition CellInfo.h:50
short channel() const
Definition CellInfo.h:76
short iEta() const
Definition CellInfo.h:56
bool initMapping(const TString &templateFile, const TString &translatorFile)
bool makeSamplesTuple(const TString &outputFileName)
std::map< unsigned int, unsigned int > m_id2hash
storage of the time histories of all the cells
HistoryContainer * makeNewHistory(const IdentifierHash &hash, CellInfo *info)
append data (takes ownership of everything)
unsigned int addEvent(EventData *eventData)
HistoryContainer *& hist_cont(unsigned int i)
unsigned int addRun(RunData *eventData)
void add(const DataContainer *data)
append data (takes ownership)
static Interface * open(const TString &fileName)
Definition Interface.cxx:35
int run() const
Definition RunData.h:36
@ UNKNOWNGAIN
Definition CaloGain.h:21