9#include "CaloDetDescr/CaloDetDescrElement.h"
11#include "CLHEP/Matrix/Matrix.h"
12#include "CLHEP/Matrix/Vector.h"
14#include "CoralBase/Blob.h"
16#include "GaudiKernel/ThreadLocalContext.h"
19using CLHEP::HepMatrix;
20using CLHEP::HepVector;
27 std::vector<float>
data(CaloSampling::Unknown);
28 data[CaloSampling::PreSamplerB] = 300.;
29 data[CaloSampling::EMB1] = 100.;
30 data[CaloSampling::EMB2] = 400.;
31 data[CaloSampling::EMB3] = 200.;
32 data[CaloSampling::PreSamplerE] = 500.;
33 data[CaloSampling::EME1] = 200.;
34 data[CaloSampling::EME2] = 800.;
35 data[CaloSampling::EME3] = 300.;
36 data[CaloSampling::HEC0] = 2000.;
37 data[CaloSampling::HEC1] = 2000.;
38 data[CaloSampling::HEC2] = 2000.;
39 data[CaloSampling::HEC3] = 2000.;
40 data[CaloSampling::TileBar0] = 9999.;
41 data[CaloSampling::TileBar1] = 9999.;
42 data[CaloSampling::TileBar2] = 9999.;
43 data[CaloSampling::TileExt0] = 9999.;
44 data[CaloSampling::TileExt1] = 9999.;
45 data[CaloSampling::TileExt2] = 9999.;
46 data[CaloSampling::TileGap1] = 9999.;
47 data[CaloSampling::TileGap2] = 9999.;
48 data[CaloSampling::TileGap3] = 9999.;
49 data[CaloSampling::FCAL0]=10000.;
50 data[CaloSampling::FCAL1]=10000.;
51 data[CaloSampling::FCAL2]=10000.;
94 ATH_MSG_INFO (
" end of CaloCellNoiseAlg::initialize " );
95 return StatusCode::SUCCESS;
105 return StatusCode::SUCCESS;
111 return StatusCode::SUCCESS;
118 return StatusCode::SUCCESS;
122 return StatusCode::SUCCESS;
136 bool passTrig =
false;
141 return StatusCode::SUCCESS;
149 const EventContext& ctx = Gaudi::Hive::currentContext();
150 unsigned int lumiblock = ctx.eventID().lumi_block();
167 return StatusCode::SUCCESS;
181 return StatusCode::SUCCESS;
188 totalNoise = noiseH.
cptr();
202 cell0.
identifier =
id.get_identifier32().get_compact();
204 cell0.
eta = calodde->
eta();
205 cell0.
phi = calodde->
phi();
225 m_tree =
new TTree(
"mytree",
"Calo Noise ntuple");
228 m_tree->Branch(
"identifier",
m_treeData->m_identifier,
"identifier[ncell]/I");
240 return StatusCode::SUCCESS;
248 if(
evtStore()->retrieve(cell_container,
"AllCalo").isFailure()) {
250 return StatusCode::SUCCESS;
256 for (; first_cell != end_cell; ++first_cell)
266 double energy= (*first_cell)->energy();
268 int isample =
m_calo_id->calo_sample(cellID);
269 if (std::fabs(energy) <
m_cuts.value()[isample] ) {
272 int index = (int) (idhash);
278 double frac = oldN/(1.+oldN);
279 double Anew = 1.+oldN;
280 double newAverage = frac*oldAverage + energy/Anew;
281 double deltaE = (energy-oldAverage);
282 double newRMS = frac*(oldRMS + deltaE*deltaE/Anew);
293 return StatusCode::SUCCESS;
301 float luminosity = 0.;
304 if (
sc.isFailure() || !attrListColl) {
311 for (; first != last; ++first) {
312 if ((*first).first == 0) {
313 std::ostringstream attrStr1;
314 (*first).second.toOutputStream( attrStr1 );
316 " Attribute list " << attrStr1.str() );
317 const coral::AttributeList& attrList = (*first).second;
318 luminosity = attrList[
"LBAvInstLumi"].data<
float>() *1e-3;
322 ATH_MSG_INFO (
" Luminosity (10**33 units) " << luminosity <<
" (10**27 units) " << 1e+6*luminosity );
355 return StatusCode::SUCCESS;
361 return StatusCode::SUCCESS;
367 const EventContext& ctx = Gaudi::Hive::currentContext();
377 noise = noiseH.
cptr();
381 pedestal = pedH.
cptr();
387 elecNoise = noiseH.
cptr();
392 FILE* fp = fopen(
"calonoise.txt",
"w");
394 TBranch* b1 =
m_tree->GetBranch(
"luminosity");
395 TBranch* b2 =
m_tree->GetBranch(
"nevt");
396 TBranch* b3 =
m_tree->GetBranch(
"average");
397 TBranch* b4 =
m_tree->GetBranch(
"rms");
398 TBranch* b5 =
m_tree->GetBranch(
"nevt_good");
404 int nentries =
m_tree->GetEntries();
405 ATH_MSG_DEBUG (
" Number of entries in ntuple " << nentries );
407 std::vector<float> anoise;
408 std::vector<float> bnoise;
412 for (
int icell=0;icell<
m_ncell;icell++) {
413 std::vector<float>
x;
414 std::vector<float>
y;
415 std::vector<float> ey;
417 for (
int i=0;i<nentries;i++) {
430 if (
x.size()==1) anoise[icell]=
y[0];
436 for (
unsigned int i=0;i<2;i++) {
437 for (
unsigned int j=0;j<2;j++) {
439 for (
unsigned int k=0;k<
x.size();k++) {
440 alpha[i][j] += ((std::pow(
x[k],i))*(std::pow(
x[k],j))/(std::pow(ey[k],2)));
444 for (
unsigned int i=0;i<2;i++) {
446 for (
unsigned int k=0;k<
x.size();k++) {
447 beta[i] += (
y[k]*(std::pow(
x[k],i))/(std::pow(ey[k],2)));
450 HepVector comp=solve(alpha,beta);
451 anoise[icell] = comp[0];
452 bnoise[icell] = comp[1];
456 msg() << MSG::DEBUG <<
" cell " << icell <<
" lumi/noise ";
457 for (
unsigned int i=0;i<
x.size();i++) {
458 msg() << MSG::DEBUG <<
x[i] <<
" " <<
y[i] <<
" / ";
461 ATH_MSG_DEBUG (
" fitted a,b " << anoise[icell] <<
" " << bnoise[icell] );
467 for (
int icell=0;icell<
m_ncell;icell++) {
468 if (anoise[icell]<3. ||
m_treeData->m_nevt_good[icell]==0) {
475 int phimin =
m_calo_id->phi_min(regionId);
476 int phimax =
m_calo_id->phi_max(regionId);
479 ATH_MSG_DEBUG (
" regionId,eta,phimin,phimax " << regionId <<
" " <<
eta <<
" " << phimin <<
" " << phimax );
484 msg() << MSG::DEBUG <<
" cell in ring " <<
m_calo_id->show_to_string(id2) ;
486 int index = (int)(idHash2);
497 float patched_noise = sum/((float)(nring));
498 if (patched_noise>anoise[icell]) anoise[icell] = patched_noise;
500 ATH_MSG_DEBUG(
" corrected noise nring, anoise[icell] " << nring <<
" " << anoise[icell] );
507 for (
int icell=0;icell<
m_ncell;icell++) {
539 int ii = (int) (idSubHash);
544 for (
int igain=0;igain<3;igain++) {
555 float anoise_corr=anoise[icell];
557 if (gain != gainref) {
561 if (
m_doMC) noise0 = noise->noise(hwid,gainref);
567 polynom_adc2mev0 = adc2mev->ADC2MEV(
id,gainref);
569 if (polynom_adc2mev0.size()>1) adc2mev0=polynom_adc2mev0[1];
574 if (
m_doMC) noise1 = noise->noise(hwid,gain);
580 polynom_adc2mev1 = adc2mev->ADC2MEV(hwid,gain);
582 if (polynom_adc2mev1.size()>1) adc2mev1=polynom_adc2mev1[1];
587 if (noise0>0 && noise1>0 && adc2mev0>0 && adc2mev1>0.) {
588 anoise_corr = anoise[icell]*noise1/noise0 * adc2mev1/adc2mev0;
596 float adb = elecNoise->
getNoise(
id,gain);
599 if (anoise_corr<1. && adb>1e-6) {
601 ATH_MSG_WARNING (
" No noise found for cell: " <<
m_calo_id->show_to_string(
id) <<
" gain: " << gain <<
" Use reference value: " << adb );
604 float delta = std::fabs((anoise_corr-adb)/adb);
607 <<
" computed " << anoise_corr <<
" reference " << adb );
612 fprintf(fp,
"%5d %5d %5d %8.3f %8.3f\n",iCool,ii,gain,anoise_corr,bnoise[icell]);
617 for (
int igain=0;igain<4;igain++) {
623 float anoise_corr = anoise[icell];
626 fprintf(fp,
"%5d %5d %5d %8.3f %8.3f\n",iCool,ii,gain,anoise_corr,bnoise[icell]);
633 return StatusCode::SUCCESS;
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
char data[hepevt_bytes_allocation_ATLAS]
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
ServiceHandle< StoreGateSvc > & evtStore()
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
Container class for CaloCell.
SG::ReadCondHandleKey< ILArNoise > m_noiseKey
SG::ReadCondHandleKey< CaloNoise > m_elecNoiseKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
std::vector< CellInfo > m_CellList
SG::ReadCondHandleKey< ILArPedestal > m_pedestalKey
CaloCellNoiseAlg(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
FloatArrayProperty m_cuts
Gaudi::Property< int > m_addlumiblock
virtual StatusCode execute() override
standard Athena-Algorithm method
Gaudi::Property< std::string > m_lumiFolderName
Gaudi::Property< bool > m_doMC
virtual StatusCode stop() override
standard Athena-Algorithm method
virtual ~CaloCellNoiseAlg()
Default Destructor.
const CaloCell_ID * m_calo_id
SG::ReadCondHandleKey< CaloNoise > m_totalNoiseKey
Gaudi::Property< bool > m_doFit
Gaudi::Property< bool > m_readNtuple
Gaudi::Property< bool > m_doLumiFit
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
virtual StatusCode initialize() override
standard Athena-Algorithm method
SG::ReadCondHandleKey< LArADC2MeV > m_adc2mevKey
ToolHandle< Trig::TrigDecisionTool > m_trigDecTool
TDT handle.
ServiceHandle< ITHistSvc > m_thistSvc
Gaudi::Property< std::string > m_triggerChainProp
unsigned int m_lumiblockOld
static StatusCode readNtuple()
Gaudi::Property< int > m_nmin
std::unique_ptr< TreeData > m_treeData
Gaudi::Property< float > m_deltaLumi
This class groups all DetDescr information related to a CaloCell.
float eta() const
cell eta
float phi() const
cell phi
This class initializes the Calo (LAr and Tile) offline identifiers.
float getNoise(const IdentifierHash h, const int gain) const
Accessor by IdentifierHash and gain.
This class is a collection of AttributeLists where each one is associated with a channel number.
const_iterator end() const
const_iterator begin() const
Access to Chan/AttributeList pairs via iterators.
ChanAttrListMap::const_iterator const_iterator
DataModel_detail::const_iterator< DataVector > const_iterator
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
virtual float pedestalRMS(const HWIdentifier &id, int gain) const =0
access to RMS of Pedestal index by Identifier, and gain setting
This is a "hash" representation of an Identifier.
bool is_valid() const
Check if id is in a valid state.
Proxy for accessing a range of float values like a vector.
const_pointer_type cptr()