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 unsigned int lumiblock = ctx.eventID().lumi_block();
166 return StatusCode::SUCCESS;
180 return StatusCode::SUCCESS;
187 totalNoise = noiseH.
cptr();
201 cell0.
identifier =
id.get_identifier32().get_compact();
203 cell0.
eta = calodde->
eta();
204 cell0.
phi = calodde->
phi();
224 m_tree =
new TTree(
"mytree",
"Calo Noise ntuple");
227 m_tree->Branch(
"identifier",
m_treeData->m_identifier,
"identifier[ncell]/I");
239 return StatusCode::SUCCESS;
247 if(
evtStore()->retrieve(cell_container,
"AllCalo").isFailure()) {
249 return StatusCode::SUCCESS;
255 for (; first_cell != end_cell; ++first_cell)
265 double energy= (*first_cell)->energy();
267 int isample =
m_calo_id->calo_sample(cellID);
268 if (std::fabs(energy) <
m_cuts.value()[isample] ) {
271 int index = (int) (idhash);
277 double frac = oldN/(1.+oldN);
278 double Anew = 1.+oldN;
279 double newAverage = frac*oldAverage + energy/Anew;
280 double deltaE = (energy-oldAverage);
281 double newRMS = frac*(oldRMS + deltaE*deltaE/Anew);
292 return StatusCode::SUCCESS;
300 float luminosity = 0.;
303 if (
sc.isFailure() || !attrListColl) {
310 for (; first != last; ++first) {
311 if ((*first).first == 0) {
312 std::ostringstream attrStr1;
313 (*first).second.toOutputStream( attrStr1 );
315 " Attribute list " << attrStr1.str() );
316 const coral::AttributeList& attrList = (*first).second;
317 luminosity = attrList[
"LBAvInstLumi"].data<
float>() *1e-3;
321 ATH_MSG_INFO (
" Luminosity (10**33 units) " << luminosity <<
" (10**27 units) " << 1e+6*luminosity );
354 return StatusCode::SUCCESS;
360 return StatusCode::SUCCESS;
366 const EventContext& ctx = Gaudi::Hive::currentContext();
376 noise = noiseH.
cptr();
380 pedestal = pedH.
cptr();
386 elecNoise = noiseH.
cptr();
391 FILE* fp = fopen(
"calonoise.txt",
"w");
393 TBranch* b1 =
m_tree->GetBranch(
"luminosity");
394 TBranch* b2 =
m_tree->GetBranch(
"nevt");
395 TBranch* b3 =
m_tree->GetBranch(
"average");
396 TBranch* b4 =
m_tree->GetBranch(
"rms");
397 TBranch* b5 =
m_tree->GetBranch(
"nevt_good");
403 int nentries =
m_tree->GetEntries();
404 ATH_MSG_DEBUG (
" Number of entries in ntuple " << nentries );
406 std::vector<float> anoise;
407 std::vector<float> bnoise;
411 for (
int icell=0;icell<
m_ncell;icell++) {
412 std::vector<float>
x;
413 std::vector<float>
y;
414 std::vector<float> ey;
416 for (
int i=0;i<nentries;i++) {
429 if (
x.size()==1) anoise[icell]=
y[0];
435 for (
unsigned int i=0;i<2;i++) {
436 for (
unsigned int j=0;j<2;j++) {
438 for (
unsigned int k=0;k<
x.size();k++) {
439 alpha[i][j] += ((std::pow(
x[k],i))*(std::pow(
x[k],j))/(std::pow(ey[k],2)));
443 for (
unsigned int i=0;i<2;i++) {
445 for (
unsigned int k=0;k<
x.size();k++) {
446 beta[i] += (
y[k]*(std::pow(
x[k],i))/(std::pow(ey[k],2)));
449 HepVector comp=solve(alpha,beta);
450 anoise[icell] = comp[0];
451 bnoise[icell] = comp[1];
455 msg() << MSG::DEBUG <<
" cell " << icell <<
" lumi/noise ";
456 for (
unsigned int i=0;i<
x.size();i++) {
457 msg() << MSG::DEBUG <<
x[i] <<
" " <<
y[i] <<
" / ";
460 ATH_MSG_DEBUG (
" fitted a,b " << anoise[icell] <<
" " << bnoise[icell] );
466 for (
int icell=0;icell<
m_ncell;icell++) {
467 if (anoise[icell]<3. ||
m_treeData->m_nevt_good[icell]==0) {
474 int phimin =
m_calo_id->phi_min(regionId);
475 int phimax =
m_calo_id->phi_max(regionId);
478 ATH_MSG_DEBUG (
" regionId,eta,phimin,phimax " << regionId <<
" " <<
eta <<
" " << phimin <<
" " << phimax );
483 msg() << MSG::DEBUG <<
" cell in ring " <<
m_calo_id->show_to_string(id2) ;
485 int index = (int)(idHash2);
496 float patched_noise = sum/((float)(nring));
497 if (patched_noise>anoise[icell]) anoise[icell] = patched_noise;
499 ATH_MSG_DEBUG(
" corrected noise nring, anoise[icell] " << nring <<
" " << anoise[icell] );
506 for (
int icell=0;icell<
m_ncell;icell++) {
538 int ii = (int) (idSubHash);
543 for (
int igain=0;igain<3;igain++) {
554 float anoise_corr=anoise[icell];
556 if (gain != gainref) {
560 if (
m_doMC) noise0 = noise->noise(hwid,gainref);
566 polynom_adc2mev0 = adc2mev->ADC2MEV(
id,gainref);
568 if (polynom_adc2mev0.size()>1) adc2mev0=polynom_adc2mev0[1];
573 if (
m_doMC) noise1 = noise->noise(hwid,gain);
579 polynom_adc2mev1 = adc2mev->ADC2MEV(hwid,gain);
581 if (polynom_adc2mev1.size()>1) adc2mev1=polynom_adc2mev1[1];
586 if (noise0>0 && noise1>0 && adc2mev0>0 && adc2mev1>0.) {
587 anoise_corr = anoise[icell]*noise1/noise0 * adc2mev1/adc2mev0;
595 float adb = elecNoise->
getNoise(
id,gain);
598 if (anoise_corr<1. && adb>1e-6) {
600 ATH_MSG_WARNING (
" No noise found for cell: " <<
m_calo_id->show_to_string(
id) <<
" gain: " << gain <<
" Use reference value: " << adb );
603 float delta = std::fabs((anoise_corr-adb)/adb);
606 <<
" computed " << anoise_corr <<
" reference " << adb );
611 fprintf(fp,
"%5d %5d %5d %8.3f %8.3f\n",iCool,ii,gain,anoise_corr,bnoise[icell]);
616 for (
int igain=0;igain<4;igain++) {
622 float anoise_corr = anoise[icell];
625 fprintf(fp,
"%5d %5d %5d %8.3f %8.3f\n",iCool,ii,gain,anoise_corr,bnoise[icell]);
632 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...
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
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
virtual StatusCode execute(const EventContext &ctx) override
standard Athena-Algorithm method
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
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()