ATLAS Offline Software
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"
11 #include "StoreGate/StoreGateSvc.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
32 {
33  clear();
34 }
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  }
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
55 void 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
61 void 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
78 void 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
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 ***********
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;
231  }// end iterating over FEB-map
232  //std::cout << "Going to finalize ROD" << std::endl;
234  //std::cout << "final size of fragment " << v.size() << std::endl;
235  //m_BlStruct->dumpFragment(); // For testing purpose
236  return;
237 }
LArRodBlockStructure
Definition: LArRodBlockStructure.h:48
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
CaloDetDescrElement::cosPhi
float cosPhi() const
for fast px py pz computation
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:391
LArRodEncoder::add
void add(const LArRawChannel *rc)
Definition: LArRodEncoder.cxx:37
LArRodBlockStructure::setEz
virtual void setEz(double)
Definition: LArRodBlockStructure.cxx:212
checkCoolLatestUpdate.dg
dg
Definition: checkCoolLatestUpdate.py:9
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
LArRodBlockStructure::setNextEnergy
virtual void setNextEnergy(const int channel, const int32_t energy, const int32_t time, const int32_t quality, const uint32_t gain)
Definition: LArRodBlockStructure.cxx:106
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
CaloDetDescrManager_Base::get_element
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
Definition: CaloDetDescrManager.cxx:159
LArRodEncoder::m_BlStruct
LArRodBlockStructure * m_BlStruct
Definition: LArRodEncoder.h:118
skel.it
it
Definition: skel.GENtoEVGEN.py:423
LArRodEncoder::clear
void clear()
Definition: LArRodEncoder.cxx:71
LArRodEncoder.h
LArRodBlockStructure::concatinateFEBs
virtual void concatinateFEBs()
Definition: LArRodBlockStructure.cxx:81
LArRodBlockStructure::setPulsed
virtual void setPulsed(const unsigned channelNumber)
Definition: LArRodBlockStructure.cxx:69
LArRawChannel::quality
uint16_t quality() const
Definition: LArRawChannel.h:174
checkRpcDigits.digit
digit
Definition: checkRpcDigits.py:186
LArRodBlockStructure::setEy
virtual void setEy(double)
Definition: LArRodBlockStructure.cxx:206
LArRodEncoder::m_CaloDetDescrManager
const CaloDetDescrManager & m_CaloDetDescrManager
Definition: LArRodEncoder.h:116
LArRodBlockStructure::canSetRawData
virtual bool canSetRawData()
Definition: LArRodBlockStructure.h:97
LArRodBlockStructure::setDAC
virtual void setDAC(const uint16_t DACValue)
Definition: LArRodBlockStructure.cxx:57
LArRodBlockStructure::initializeFragment
virtual void initializeFragment(std::vector< uint32_t > &fragment)
Definition: LArRodBlockStructure.cxx:188
LArOnlineID_Base::channel
int channel(const HWIdentifier id) const
Return the channel number of a hardware cell identifier channel = [0,127] in all FEB.
Definition: LArOnlineID_Base.cxx:1967
LArRodBlockStructure::canIncludeRawData
virtual bool canIncludeRawData()
Definition: LArRodBlockStructure.h:101
Identifier32::get_compact
value_type get_compact(void) const
Get the compact id.
Definition: Identifier32.h:171
LArRodEncoder::fillROD
void fillROD(std::vector< uint32_t > &v, MsgStream &logstr, const CaloNoise &noise, double nsigma)
Definition: LArRodEncoder.cxx:78
LArDigit
Liquid Argon digit base class.
Definition: LArDigit.h:25
lumiFormat.i
int i
Definition: lumiFormat.py:92
LArRawChannel
Liquid Argon ROD output object base class.
Definition: LArRawChannel.h:40
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
LArRodBlockStructure::FebToRodChannel
virtual int FebToRodChannel(int ch) const
Definition: LArRodBlockStructure.h:175
LArRodBlockStructure::canSetRawDataFixed
virtual bool canSetRawDataFixed()
Definition: LArRodBlockStructure.h:98
LArRodBlockStructure::canSetCalibration
virtual bool canSetCalibration()
Definition: LArRodBlockStructure.h:99
LArRodBlockStructure::finalizeFEB
virtual void finalizeFEB()
Definition: LArRodBlockStructure.cxx:194
LArRodEncoder::LArRodEncoder
LArRodEncoder(const LArOnlineID &onlineHelper, const CaloDetDescrManager &calodd, const LArOnOffIdMapping &onOffIdMapping, LArRodBlockStructure *BlStruct)
Definition: LArRodEncoder.cxx:19
LArRodBlockStructure::setNumberOfSamples
virtual void setNumberOfSamples(const uint8_t n)
Definition: LArRodBlockStructure.cxx:132
LArRodBlockStructure::setSumE
virtual void setSumE(double)
Definition: LArRodBlockStructure.cxx:218
LArRodEncoder::~LArRodEncoder
~LArRodEncoder()
Definition: LArRodEncoder.cxx:31
LArOnlineID_Base::feb_Id
HWIdentifier feb_Id(int barrel_ec, int pos_neg, int feedthrough, int slot) const
Create feb_Id from fields.
Definition: LArOnlineID_Base.cxx:1483
CaloNoise
Definition: CaloNoise.h:16
HWIdentifier.h
LArCalibDigit
Base class for LArDigits taken during calibration runs.
Definition: LArCalibDigit.h:29
LArRawChannel::hardwareID
const HWIdentifier & hardwareID() const
Definition: LArRawChannel.h:162
LArOnlineID
Definition: LArOnlineID.h:20
LArRodBlockStructure::setRawDataFixed
virtual void setRawDataFixed(const int channel, const std::vector< short > &samples, const uint32_t gain)
Definition: LArRodBlockStructure.cxx:126
LArRodBlockStructure::canSetEnergy
virtual bool canSetEnergy()
Definition: LArRodBlockStructure.h:96
LArRodBlockStructure::sortDataVector
virtual void sortDataVector(std::vector< const LArRawChannel * > &)
Definition: LArRodBlockStructure.cxx:230
LArRodBlockStructure::initializeFEB
virtual void initializeFEB(const uint32_t id)
Definition: LArRodBlockStructure.cxx:182
LArRodEncoder::m_onlineHelper
const LArOnlineID & m_onlineHelper
Definition: LArRodEncoder.h:115
python.PyAthena.v
v
Definition: PyAthena.py:157
LArRodBlockStructure::setEx
virtual void setEx(double)
Definition: LArRodBlockStructure.cxx:200
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
CaloDetDescrManager
This class provides the client interface for accessing the detector description information common to...
Definition: CaloDetDescrManager.h:473
LArOnOffIdMapping::cnvToIdentifier
Identifier cnvToIdentifier(const HWIdentifier &sid) const
create an Identifier from a HWIdentifier (inline)
Definition: LArOnOffIdMapping.h:116
LArRodEncoder::m_onOffIdMapping
const LArOnOffIdMapping & m_onOffIdMapping
Definition: LArRodEncoder.h:117
LArRodBlockStructure::setDelay
virtual void setDelay(const uint16_t DelayValue)
Definition: LArRodBlockStructure.cxx:63
LArRawChannel::time
int time() const
Definition: LArRawChannel.h:170
LArRodEncoder::m_mFEB
std::map< uint32_t, FebData_t > m_mFEB
Definition: LArRodEncoder.h:113
LArRawChannel::energy
int energy() const
Definition: LArRawChannel.h:166
CaloDetDescrElement::eta
float eta() const
cell eta
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:344
CaloDetDescrElement::sinTh
float sinTh() const
for algorithm working in transverse Energy
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:383
LArRawChannel::gain
CaloGain::CaloGain gain() const
Definition: LArRawChannel.h:186
Identifier::get_identifier32
Identifier32 get_identifier32(void) const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
CaloDetDescrElement::sinPhi
float sinPhi() const
for fast px py pz computation
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:389
LArRodBlockStructure::setRawData
virtual void setRawData(const int channel, const std::vector< short > &samples, const uint32_t gain)
Definition: LArRodBlockStructure.cxx:113
StoreGateSvc.h
WriteCellNoiseToCool.noise
noise
Definition: WriteCellNoiseToCool.py:380
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20