ATLAS Offline Software
Loading...
Searching...
No Matches
D3PDConverter.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 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
24D3PDConverter::D3PDConverter(TTree& tree, const TString& templateFile, const TString& translatorFile)
26{
27 initMapping(templateFile, translatorFile);
28}
29
31
33{
34 DataStore* samples = new DataStore();
35 RunData* runData = nullptr;
36
37 cout << "Processing " << fChain->GetEntries() << " entries" << endl;
38 for (long long i = 0; i < fChain->GetEntries(); i++) {
39 if (i % 500 == 0) cout << "Processing Entry " << i << endl;
40 fChain->GetEntry(i);
41 if (!runData || runData->run() != (int)RunNumber) {
42 // new run
43 runData = new RunData(RunNumber);
44 samples->addRun(runData);
45 }
46
47 EventData* eventData = new EventData(EventNumber, 0, lbn, bcid);
48 eventData->setRunData(runData);
49 unsigned int eventIndex = samples->addEvent(eventData);
50
51
52 for (int j = 0; j < cc_sel_n; j++) {
53 // skip Tile cells
54 if ((*cc_sel_DetCells)[j] & 8) continue;
55 unsigned int hash = m_id2hash[(*cc_sel_IdCells)[j]];
56 if (hash == 0) {
57 cout << "ERROR: skipping cell with offline ID = " << (*cc_sel_IdCells)[j] << endl;
58 continue;
59 }
60
61 // find digit
62 int digitIndex = -1;
63 for (int k = 0; k < lardigit_n; k++) {
64 if ((*lardigit_offlineId)[k] == (*cc_sel_IdCells)[j]) {
65 digitIndex = k;
66 break;
67 }
68 }
69 //if (digitIndex >= 0) cout << "digitIndex = " << digitIndex << endl;
70 hash -= 1;
71 HistoryContainer* histCont = samples->hist_cont(hash);
72 CellInfo* info = nullptr;
73 if (!histCont) {
74 const CellInfo* templateInfo = m_template->cellInfo(hash);
75 info = new CellInfo(templateInfo->calo(), templateInfo->layer(),
76 templateInfo->iEta(), templateInfo->iPhi(),
77 templateInfo->feedThrough(), templateInfo->slot(), templateInfo->channel(),
78 nullptr,nullptr,nullptr, templateInfo->position(), templateInfo->onlid());
79 histCont = samples->makeNewHistory(IdentifierHash(hash), info);
80 }
81 else
82 info = histCont->cell_info();
83
85 std::vector<short> samples;
86 if (digitIndex >= 0) {
87 gain = (CaloGain::CaloGain)(*lardigit_gain)[digitIndex];
88 std::vector<int> intSamples = (*lardigit_Samples)[digitIndex];
89 for (int s : intSamples) {
90 samples.push_back((short)s);
91 }
92 }
94 new DataContainer(gain, samples, (*cc_sel_E)[j], (*cc_sel_TimeCells)[j],
95 (*cc_sel_QCells)[j], eventIndex,
96 std::vector<float>(), (*cc_sel_Sigma)[j],
97 -1, -1, (*cc_sel_BadCells)[j]);
98 histCont->add(data);
99 }
100 }
101 samples->writeTrees(outputFileName);
102 delete samples;
103 return true;
104}
105
106
107bool D3PDConverter::initMapping(const TString& templateFile, const TString& translatorFile)
108{
109 LArIdTranslatorHelper translator(translatorFile);
110 m_template = Interface::open(templateFile);
111
112 cout << "Making online->hash map" << endl;
113 std::map<unsigned long long, unsigned int> on2hash;
114 for (unsigned int i = 0; i < m_template->nChannels(); i++) {
115 const CellInfo* info = m_template->cellInfo(i);
116 if (!info) continue;
117 on2hash[info->onlid()] = i;
118 }
119
120 cout << "Making offlineID->hash map" << endl;
121 for (unsigned int i = 0; i < translator.Tree()->GetEntries(); i++) {
122 translator.Tree()->GetEntry(i);
123 m_id2hash[translator.offlid] = on2hash[translator.onlid] + 1;
124 }
125 return true;
126}
127
128
129
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
CaloD3PDClass(TTree *tree=0)
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)
std::unique_ptr< Interface > m_template
bool makeSamplesTuple(const TString &outputFileName)
D3PDConverter(TTree &tree, const TString &templateFile, const TString &translatorFile)
Constructor.
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 std::unique_ptr< Interface > open(const TString &fileName)
Definition Interface.cxx:35
int run() const
Definition RunData.h:36
@ UNKNOWNGAIN
Definition CaloGain.h:21
TChain * tree