ATLAS Offline Software
Loading...
Searching...
No Matches
LArRodEncoder.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// Implementation of LArRodEncoder class
7#include "CaloDetDescr/CaloDetDescrElement.h"
8#include "GaudiKernel/Bootstrap.h"
9#include "GaudiKernel/ISvcLocator.h"
10#include "GaudiKernel/IToolSvc.h"
12#include "eformat/Version.h"
13#include <cstdio>
14#include <stdio.h>
16
17
18// constructor
20 const CaloDetDescrManager& calodd,
21 const LArOnOffIdMapping& onOffIdMapping,
22 LArRodBlockStructure* BlStruct)
23 : m_onlineHelper (onlineHelper),
24 m_CaloDetDescrManager (calodd),
25 m_onOffIdMapping (onOffIdMapping),
26 m_BlStruct (BlStruct)
27{
28}
29
30// destructor
35
36// Add LArRawChannel
38{
39 uint32_t FEB_ID = (m_onlineHelper.feb_Id(rc->channelID()).get_identifier32().get_compact());
40 if ( m_mFEB[FEB_ID].vLArRC.empty() ){
41 m_mFEB[FEB_ID].vLArRC.resize(128,0);
42 //for(int i=0;i<128;i++) m_mFEB[FEB_ID].vLArRC.push_back(0);
43 }
44 uint32_t chan = m_BlStruct->FebToRodChannel(m_onlineHelper.channel( rc->channelID() ) );
45 m_mFEB[FEB_ID].vLArRC[chan]=rc;
46}
47
48// Add free gain digits
50{
51 uint32_t FEB_ID = (m_onlineHelper.feb_Id(dg->hardwareID()).get_identifier32().get_compact());
52 m_mFEB[FEB_ID].vLArDigit.push_back(dg);
53}
54//Add fixed gain digits
55void LArRodEncoder::add(const LArDigit* dg, const int gain)
56{
57 uint32_t FEB_ID = (m_onlineHelper.feb_Id(dg->hardwareID()).get_identifier32().get_compact());
58 m_mFEB[FEB_ID].vLArDigitFixed[gain].push_back(dg);
59}
60//Add calibration digits
61void LArRodEncoder::add(const LArCalibDigit* dg, const int gain)
62{
63 uint32_t FEB_ID = (m_onlineHelper.feb_Id(dg->hardwareID()).get_identifier32().get_compact());
64 m_mFEB[FEB_ID].vLArCalibDigit[gain].push_back(dg);
65}
66
67
68
69
70
72{
73 m_mFEB.clear();
74}
75
76// convert all LArRawChannels and LArDigits
77// in the current list to a vector of 32bit words
78void LArRodEncoder::fillROD(std::vector<uint32_t>& v, MsgStream& logstr, const CaloNoise& noise, double nsigma)
79{
80 if (!m_BlStruct)
81 {logstr << MSG::ERROR << "No LArRodBlockStructure defined! Can't encode fragment!" << endmsg;
82 return;
83 }
84 //int febcounter=0;
85 //std::cout << "Going to init Fragment..." << std::endl;
86 m_BlStruct->initializeFragment(v); //Makes new Fragment or splits v into existing Feb-Blocks
87 std::map<uint32_t,FebData_t>::iterator it=m_mFEB.begin();
88 std::map<uint32_t,FebData_t>::iterator it_end=m_mFEB.end();
89 // The sort alorithm for the vectors inside the data object of the map fails
90 // when I use const_iterator at this point. Don't ask me why
91 //std::cout << "Have " << m_mFEB.size() << " FEBs in this ROD" << std::endl;
92 for(;it!=it_end;++it) {
93 //std::cout << "Setting values for feb # " << febcounter << " ID=" << it->first << std::endl;
94 m_BlStruct->initializeFEB(it->first); // Set FEB id
95 //std::cout << "Setting Energy" << std::endl;
96 // ************* Energy Block *************
97 if (m_BlStruct->canSetEnergy() && it->second.vLArRC.size()>0) {
98 //int j=0;
99// m_BlStruct->sortDataVector(it->second.vLArRC);
100 // compute Ex, Ey for this FEB : initialisation phase
101
102 {
103 double Ex=0;
104 double Ey=0;
105 double Ez=0;
106 double SumE=0;
107 Identifier myofflineID;
108
109 for (const LArRawChannel *theChannel : it->second.vLArRC) {
110 if ( theChannel != nullptr ){
111 int cId = m_onlineHelper.channel(theChannel->hardwareID());
112
113 int e=theChannel->energy();
114 uint32_t quality = theChannel->quality();
115 m_BlStruct->setNextEnergy(cId,e, theChannel->time(),
116 quality,theChannel->gain());
117
118 // you convert from hardwareID to offline channle ID hash (???)
119 myofflineID = m_onOffIdMapping.cnvToIdentifier(theChannel->hardwareID()) ;
120 //std::cout << "Got Offile id 0x" << std::hex << myofflineID.get_compact() << std::dec << std::endl;
121 const CaloDetDescrElement* caloDDE = m_CaloDetDescrManager.get_element(myofflineID);
122 // This is probably NOT what one wants. You want the cell gain!
123 double cellnoise = noise.getNoise(myofflineID,theChannel->gain());
124 if( e > (nsigma*cellnoise) && (quality != 65535 ) ){
125 double aux=caloDDE->sinTh();
126 double aux_z=tanh(caloDDE->eta());
127 Ex += e*aux*caloDDE->cosPhi();
128 Ey += e*aux*caloDDE->sinPhi();
129 Ez += e*aux_z;
130 SumE += e;
131 }
132 } // End of if to check for the LArRawChannel existence
133 } // end of chit loop
134 // Set after the loop finishes
135 m_BlStruct->setEx(Ex);
136 m_BlStruct->setEy(Ey);
137 m_BlStruct->setEz(Ez);
138 m_BlStruct->setSumE(SumE);
139 }
140 }//End canSetEnergy
141 // try to include samples together with data
142 if (m_BlStruct->canIncludeRawData() && it->second.vLArDigit.size()>0) {
143 // Order channels according to ROD numbering
144 m_BlStruct->sortDataVector(it->second.vLArDigit);
145 for (const LArDigit* digit : it->second.vLArDigit) {
146 int cId = m_onlineHelper.channel(digit->hardwareID());
147 m_BlStruct->setRawData(cId, digit->samples(), digit->gain());
148 } // end of for digits
149 } // End of can Include Raw Data check
150 //std::cout << "Setting Raw Data" << std::endl;
151 // ************** Raw Data Block ***********
152 if (m_BlStruct->canSetRawData() && it->second.vLArDigit.size()>0) {
153 //sort(it->second.vLArDigit.begin(), it->second.vLArDigit.end(), *m_BlStruct); // Order channels according to ROD numbering
154 m_BlStruct->sortDataVector(it->second.vLArDigit);
155 std::vector<const LArDigit*>::const_iterator digit_it = it->second.vLArDigit.begin();
156 std::vector<const LArDigit*>::const_iterator digit_it_end=it->second.vLArDigit.end();
157 if(digit_it!=digit_it_end) { //Container not empty
158 m_BlStruct->setNumberOfSamples((*digit_it)->samples().size());
159 for (;digit_it!=digit_it_end;++digit_it) {
160 int cId = m_onlineHelper.channel((*digit_it)->hardwareID());
161 //cId = m_BlStruct->FebToRodChannel(cId);
162 m_BlStruct->setRawData(cId, (*digit_it)->samples(), (*digit_it)->gain());
163 }
164 }// end container not empty
165 }// end if can set raw data
166
167 //std::cout << "Setting fixed gain data" << std::endl;
168 // ************** Fixed Gain Data Block ***********
169 if (m_BlStruct->canSetRawDataFixed()) {
170 for (int i=0;i<3;i++) { //Loop over three gains
171 //sort(it->second.vLArDigitFixed[i].begin(), it->second.vLArDigitFixed[i].end(), *m_BlStruct);
172 m_BlStruct->sortDataVector(it->second.vLArDigitFixed[i]);
173 std::vector<const LArDigit*>::const_iterator digit_it = it->second.vLArDigitFixed[i].begin();
174 std::vector<const LArDigit*>::const_iterator digit_it_end=it->second.vLArDigitFixed[i].end();
175 if(digit_it!=digit_it_end) {//Container not empty
176 m_BlStruct->setNumberOfSamples((*digit_it)->samples().size());
177 for (;digit_it!=digit_it_end;++digit_it) {
178 int cId = m_onlineHelper.channel((*digit_it)->hardwareID());
179 //cId = m_BlStruct->FebToRodChannel(cId);
180 m_BlStruct->setRawDataFixed(cId, (*digit_it)->samples(), (*digit_it)->gain());
181 }
182 } //end Container not empty
183 } // end loop over three gains
184 } // end can set raw data fixed
185
186 // ************** Calibration Digit Block ***********
187 if (m_BlStruct->canSetCalibration()) {
188 for (int i=0;i<3;i++) { //Loop over three gains
189 //sort(it->second.vLArCalibDigit[i].begin(), it->second.vLArCalibDigit[i].end(), *m_BlStruct);
190 m_BlStruct->sortDataVector(it->second.vLArCalibDigit[i]);
191 std::vector<const LArCalibDigit*>::const_iterator digit_it = it->second.vLArCalibDigit[i].begin();
192 std::vector<const LArCalibDigit*>::const_iterator digit_it_end=it->second.vLArCalibDigit[i].end();
193 if(digit_it!=digit_it_end) {//Container not empty
194 m_BlStruct->setNumberOfSamples((*digit_it)->samples().size());
195 m_BlStruct->setDelay((*digit_it)->delay());
196 m_BlStruct->setDAC((*digit_it)->DAC());
197 for (;digit_it!=digit_it_end;++digit_it) {
198 int cId = m_onlineHelper.channel((*digit_it)->hardwareID());
199 //cId = m_BlStruct->FebToRodChannel(cId);
200 m_BlStruct->setRawDataFixed(cId, (*digit_it)->samples(), (*digit_it)->gain());
201 if ((*digit_it)->isPulsed())
202 m_BlStruct->setPulsed(cId);
203 }
204 } //End Container not empty
205 }// end loop over three gains
206 } //end can set calibration
207
208 /*
209 // ************** Averaged Calibration Digit Block ***********
210 if (m_BlStruct->canSetAverages()) {
211 for (int i=0;i<3;i++) { //Loop over three gains
212 sort(it->second.vLArCalibDigit[i].begin(), it->second.vLArCalibDigit[i].end(), *m_BlStruct);
213 std::vector<const LArAverageDigit*>::const_iterator digit_it = it->second.vLArAverageDigit.begin();
214 std::vector<const LArAverageDigit*>::const_iterator digit_it_end=it->second.vLArAverageDigit.end();
215 if(digit_it!=digit_it_end) {//Container not empty
216 m_BlStruct->setNumberOfSamples((*digit_it)->samples().size());
217 m_BlStruct->setDAC((*digit_it)->DAC());
218 m_BlStruct->setDelay((*digit_it)->delay());
219 for (;digit_it!=digit_it_end;digit_it++) {
220 int cId = m_onOffIdMapping.channel((*digit_it)->channelID());
221 cId = m_BlStruct->FebToRodChannel(cId);
222 m_BlStruct->setRawData(cId, (*digit_it)->samples(), (*digit_it)->gain());
223 m_BlStruct->setIsPulsed(cId);
224 }
225 } //End Container not empty
226 }// end loop over three gains
227 }// can set averages
228 */
229 //std::cout << "Going to finalize FEB" << std::endl;
230 m_BlStruct->finalizeFEB();
231 }// end iterating over FEB-map
232 //std::cout << "Going to finalize ROD" << std::endl;
233 m_BlStruct->concatinateFEBs();
234 //std::cout << "final size of fragment " << v.size() << std::endl;
235 //m_BlStruct->dumpFragment(); // For testing purpose
236 return;
237}
#define endmsg
static Double_t rc
This class groups all DetDescr information related to a CaloCell.
float cosPhi() const
for fast px py pz computation
float sinTh() const
for algorithm working in transverse Energy
float sinPhi() const
for fast px py pz computation
This class provides the client interface for accessing the detector description information common to...
Base class for LArDigits taken during calibration runs.
Liquid Argon digit base class.
Definition LArDigit.h:25
Liquid Argon ROD output object base class.
const HWIdentifier & hardwareID() const
CaloGain::CaloGain gain() const
int time() const
uint16_t quality() const
int energy() const
void add(const LArRawChannel *rc)
const LArOnlineID & m_onlineHelper
void fillROD(std::vector< uint32_t > &v, MsgStream &logstr, const CaloNoise &noise, double nsigma)
const CaloDetDescrManager & m_CaloDetDescrManager
std::map< uint32_t, FebData_t > m_mFEB
LArRodEncoder(const LArOnlineID &onlineHelper, const CaloDetDescrManager &calodd, const LArOnOffIdMapping &onOffIdMapping, LArRodBlockStructure *BlStruct)
LArRodBlockStructure * m_BlStruct
const LArOnOffIdMapping & m_onOffIdMapping