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;
41 std::vector<float>
data(CaloSampling::Unknown);
42 data[CaloSampling::PreSamplerB] = 300.;
43 data[CaloSampling::EMB1] = 100.;
44 data[CaloSampling::EMB2] = 400.;
45 data[CaloSampling::EMB3] = 200.;
46 data[CaloSampling::PreSamplerE] = 500.;
47 data[CaloSampling::EME1] = 200.;
48 data[CaloSampling::EME2] = 800.;
49 data[CaloSampling::EME3] = 300.;
50 data[CaloSampling::HEC0] = 2000.;
51 data[CaloSampling::HEC1] = 2000.;
52 data[CaloSampling::HEC2] = 2000.;
53 data[CaloSampling::HEC3] = 2000.;
54 data[CaloSampling::TileBar0] = 9999.;
55 data[CaloSampling::TileBar1] = 9999.;
56 data[CaloSampling::TileBar2] = 9999.;
57 data[CaloSampling::TileExt0] = 9999.;
58 data[CaloSampling::TileExt1] = 9999.;
59 data[CaloSampling::TileExt2] = 9999.;
60 data[CaloSampling::TileGap1] = 9999.;
61 data[CaloSampling::TileGap2] = 9999.;
62 data[CaloSampling::TileGap3] = 9999.;
63 data[CaloSampling::FCAL0]=10000.;
64 data[CaloSampling::FCAL1]=10000.;
65 data[CaloSampling::FCAL2]=10000.;
121 ATH_MSG_INFO (
" end of CaloCellNoiseAlg::initialize " );
122 return StatusCode::SUCCESS;
132 return StatusCode::SUCCESS;
138 return StatusCode::SUCCESS;
145 return StatusCode::SUCCESS;
149 return StatusCode::SUCCESS;
163 bool passTrig =
false;
168 return StatusCode::SUCCESS;
176 const EventContext& ctx = Gaudi::Hive::currentContext();
177 unsigned int lumiblock = ctx.eventID().lumi_block();
194 return StatusCode::SUCCESS;
208 return StatusCode::SUCCESS;
215 totalNoise = noiseH.
cptr();
229 cell0.
identifier =
id.get_identifier32().get_compact();
231 cell0.
eta = calodde->
eta();
232 cell0.
phi = calodde->
phi();
252 m_tree =
new TTree(
"mytree",
"Calo Noise ntuple");
255 m_tree->Branch(
"identifier",
m_treeData->m_identifier,
"identifier[ncell]/I");
267 return StatusCode::SUCCESS;
275 if(
evtStore()->retrieve(cell_container,
"AllCalo").isFailure()) {
277 return StatusCode::SUCCESS;
283 for (; first_cell != end_cell; ++first_cell)
293 double energy= (*first_cell)->energy();
295 int isample =
m_calo_id->calo_sample(cellID);
296 if (std::fabs(energy) <
m_cuts.value()[isample] ) {
299 int index = (int) (idhash);
305 double frac = oldN/(1.+oldN);
306 double Anew = 1.+oldN;
307 double newAverage = frac*oldAverage + energy/Anew;
308 double deltaE = (energy-oldAverage);
309 double newRMS = frac*(oldRMS + deltaE*deltaE/Anew);
320 return StatusCode::SUCCESS;
328 float luminosity = 0.;
331 if (
sc.isFailure() || !attrListColl) {
338 for (; first != last; ++first) {
339 if ((*first).first == 0) {
340 std::ostringstream attrStr1;
341 (*first).second.toOutputStream( attrStr1 );
343 " Attribute list " << attrStr1.str() );
344 const coral::AttributeList& attrList = (*first).second;
345 luminosity = attrList[
"LBAvInstLumi"].data<
float>() *1e-3;
349 ATH_MSG_INFO (
" Luminosity (10**33 units) " << luminosity <<
" (10**27 units) " << 1e+6*luminosity );
382 return StatusCode::SUCCESS;
388 return StatusCode::SUCCESS;
394 const EventContext& ctx = Gaudi::Hive::currentContext();
404 noise = noiseH.
cptr();
408 pedestal = pedH.
cptr();
414 elecNoise = noiseH.
cptr();
419 FILE* fp = fopen(
"calonoise.txt",
"w");
421 TBranch* b1 =
m_tree->GetBranch(
"luminosity");
422 TBranch* b2 =
m_tree->GetBranch(
"nevt");
423 TBranch* b3 =
m_tree->GetBranch(
"average");
424 TBranch* b4 =
m_tree->GetBranch(
"rms");
425 TBranch* b5 =
m_tree->GetBranch(
"nevt_good");
431 int nentries =
m_tree->GetEntries();
432 ATH_MSG_DEBUG (
" Number of entries in ntuple " << nentries );
434 std::vector<float> anoise;
435 std::vector<float> bnoise;
439 for (
int icell=0;icell<
m_ncell;icell++) {
440 std::vector<float>
x;
441 std::vector<float>
y;
442 std::vector<float> ey;
444 for (
int i=0;i<nentries;i++) {
457 if (
x.size()==1) anoise[icell]=
y[0];
463 for (
unsigned int i=0;i<2;i++) {
464 for (
unsigned int j=0;j<2;j++) {
466 for (
unsigned int k=0;k<
x.size();k++) {
467 alpha[i][j] += ((std::pow(
x[k],i))*(std::pow(
x[k],j))/(std::pow(ey[k],2)));
471 for (
unsigned int i=0;i<2;i++) {
473 for (
unsigned int k=0;k<
x.size();k++) {
474 beta[i] += (
y[k]*(std::pow(
x[k],i))/(std::pow(ey[k],2)));
477 HepVector comp=solve(alpha,beta);
478 anoise[icell] = comp[0];
479 bnoise[icell] = comp[1];
483 msg() << MSG::DEBUG <<
" cell " << icell <<
" lumi/noise ";
484 for (
unsigned int i=0;i<
x.size();i++) {
485 msg() << MSG::DEBUG <<
x[i] <<
" " <<
y[i] <<
" / ";
488 ATH_MSG_DEBUG (
" fitted a,b " << anoise[icell] <<
" " << bnoise[icell] );
494 for (
int icell=0;icell<
m_ncell;icell++) {
495 if (anoise[icell]<3. ||
m_treeData->m_nevt_good[icell]==0) {
502 int phimin =
m_calo_id->phi_min(regionId);
503 int phimax =
m_calo_id->phi_max(regionId);
506 ATH_MSG_DEBUG (
" regionId,eta,phimin,phimax " << regionId <<
" " <<
eta <<
" " << phimin <<
" " << phimax );
509 if (
id2.is_valid()) {
511 msg() << MSG::DEBUG <<
" cell in ring " <<
m_calo_id->show_to_string(
id2) ;
513 int index = (int)(idHash2);
524 float patched_noise = sum/((float)(nring));
525 if (patched_noise>anoise[icell]) anoise[icell] = patched_noise;
527 ATH_MSG_DEBUG(
" corrected noise nring, anoise[icell] " << nring <<
" " << anoise[icell] );
534 for (
int icell=0;icell<
m_ncell;icell++) {
566 int ii = (int) (idSubHash);
571 for (
int igain=0;igain<3;igain++) {
582 float anoise_corr=anoise[icell];
584 if (gain != gainref) {
588 if (
m_doMC) noise0 = noise->noise(hwid,gainref);
594 polynom_adc2mev0 = adc2mev->ADC2MEV(
id,gainref);
596 if (polynom_adc2mev0.size()>1) adc2mev0=polynom_adc2mev0[1];
601 if (
m_doMC) noise1 = noise->noise(hwid,gain);
607 polynom_adc2mev1 = adc2mev->ADC2MEV(hwid,gain);
609 if (polynom_adc2mev1.size()>1) adc2mev1=polynom_adc2mev1[1];
614 if (noise0>0 && noise1>0 && adc2mev0>0 && adc2mev1>0.) {
615 anoise_corr = anoise[icell]*noise1/noise0 * adc2mev1/adc2mev0;
623 float adb = elecNoise->
getNoise(
id,gain);
626 if (anoise_corr<1. && adb>1e-6) {
628 ATH_MSG_WARNING (
" No noise found for cell: " <<
m_calo_id->show_to_string(
id) <<
" gain: " << gain <<
" Use reference value: " << adb );
631 float delta = std::fabs((anoise_corr-adb)/adb);
634 <<
" computed " << anoise_corr <<
" reference " << adb );
639 fprintf(fp,
"%5d %5d %5d %8.3f %8.3f\n",iCool,ii,gain,anoise_corr,bnoise[icell]);
644 for (
int igain=0;igain<4;igain++) {
650 float anoise_corr = anoise[icell];
653 fprintf(fp,
"%5d %5d %5d %8.3f %8.3f\n",iCool,ii,gain,anoise_corr,bnoise[icell]);
660 return StatusCode::SUCCESS;
665 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:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
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
std::string m_lumiFolderName
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
std::string m_triggerChainProp
virtual StatusCode execute() override
standard Athena-Algorithm method
virtual StatusCode stop() override
standard Athena-Algorithm method
virtual ~CaloCellNoiseAlg()
Default Destructor.
const CaloCell_ID * m_calo_id
SG::ReadCondHandleKey< CaloNoise > m_totalNoiseKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
virtual StatusCode finalize() override
standard Athena-Algorithm method
virtual StatusCode initialize() override
standard Athena-Algorithm method
SG::ReadCondHandleKey< LArADC2MeV > m_adc2mevKey
ToolHandle< Trig::TrigDecisionTool > m_trigDecTool
TDT handle.
ServiceHandle< ITHistSvc > m_thistSvc
unsigned int m_lumiblockOld
static StatusCode readNtuple()
std::unique_ptr< TreeData > m_treeData
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.
Proxy for accessing a range of float values like a vector.
const_pointer_type cptr()