ATLAS Offline Software
SuperCellVsCaloCellTestAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // LArROD includes
7 
9 
10 #include "TFile.h"
11 #include "TProfile.h"
12 #include "TGraph.h"
13 #include "TH1F.h"
14 #include "TH2F.h"
15 
16 #include "TTree.h"
17 #include "GaudiKernel/ITHistSvc.h"
18 
20 
21 //needed for linker ...
22 //constexpr double SuperCellVsCaloCellTestAlg::eBins[SuperCellVsCaloCellTestAlg::nBinsE+1];
23 //constexpr double SuperCellVsCaloCellTestAlg::etaBins[SuperCellVsCaloCellTestAlg::nBinsEta+1];
24 
25 SuperCellVsCaloCellTestAlg::SuperCellVsCaloCellTestAlg( const std::string& name, ISvcLocator* pSvcLocator ) :
26  AthAlgorithm( name, pSvcLocator ),
27  m_sc2ccMappingTool("CaloSuperCellIDTool"),
28  m_ccIdHelper(nullptr),
29  m_treeDigits(nullptr),
30  m_tree(nullptr)
31 {
32 
33  declareProperty("SuperCellContainer",m_scKey="SCell");
34  declareProperty("CaloCellContainer",m_ccKey="AllCalo");
35  declareProperty("TruthSuperCellContainer",m_tscKey="SCellTruth");
36  declareProperty("DigitContainer",m_digitKey="LArDigitSCL1","Only used for supicious supercells");
37 
38  declareProperty("OutputStream",m_stream="SUPERCELLTEST");
39 
40 }
41 
42 
44 
45 
47 
48  //get the mapping tool
49  CHECK( m_sc2ccMappingTool.retrieve() );
50  //and the id helper (used for making id hashes)
51  CHECK( detStore()->retrieve (m_ccIdHelper, "CaloCell_ID") );
52 
53  double etBins[11] = {0.1,0.25,0.5,0.75,1.,1.5,2.,3.,4.,5.,10.}; //in GeV
55  if(!m_ccKey.empty()) {
56  m_etReso.push_back(new TProfile(TString::Format("%s_calocell",CaloSampling::getSamplingName(i).c_str()),TString::Format("%s;CaloCell E_{T} [GeV];SuperCell E_{T} / CaloCell E_{T}",CaloSampling::getSamplingName(i).c_str()),10,etBins,"s"/* standard deviation for error*/));
57  m_etReso.back()->SetDirectory(nullptr);
58  m_Reso_et.push_back(new TH1F(TString::Format("%s_SuperCellResolution",CaloSampling::getSamplingName(i).c_str()),TString::Format("%s;(SuperCell E_{T} - CaloCell E_{T}) / CaloCell E_{T} (%%)",CaloSampling::getSamplingName(i).c_str()),80,-40,40) );
59  m_Reso_et_vs_et.push_back(new TH2F(TString::Format("%s_SuperCellResolution_versus_et",CaloSampling::getSamplingName(i).c_str()),TString::Format("%s; E_{T}[GeV] ; (SuperCell E_{T} - CaloCell E_{T}) / CaloCell E_{T} (%%)",CaloSampling::getSamplingName(i).c_str()),60,-10,50,80,-40,40) );
60  m_Reso_et_vs_eta.push_back(new TH2F(TString::Format("%s_SuperCellResolution_versus_eta",CaloSampling::getSamplingName(i).c_str()),TString::Format("%s; #eta ; (SuperCell E_{T} - CaloCell E_{T}) / CaloCell E_{T} (%%)",CaloSampling::getSamplingName(i).c_str()),50,-2.5,2.5,80,-40,40) );
61  m_Linear_SCet_vs_et.push_back(new TH2F(TString::Format("%s_Linearity",CaloSampling::getSamplingName(i).c_str()),TString::Format("%s; CaloCell Sum E_{T}[GeV] ; SuperCell E_{T}",CaloSampling::getSamplingName(i).c_str()),60,-10,50,60,-10,50) );
62  }
63  if(!m_tscKey.empty()) {
64  m_etResoTruth.push_back(new TProfile(TString::Format("%s_truth",CaloSampling::getSamplingName(i).c_str()),TString::Format("%s;Truth SuperCell E_{T} [GeV];SuperCell E_{T} / Truth SuperCell E_{T}",CaloSampling::getSamplingName(i).c_str()),10,etBins,"s"/* standard deviation for error*/));
65  m_etResoTruth.back()->SetDirectory(nullptr);
66  }
67  }
68 
69  m_tree = new TTree("debug","debug");
70 
71  m_treeDigits= new std::vector<short int>;
72 
73  m_tree->Branch("EventNumber",&m_eventNumber);
74  m_tree->Branch("Channel",&m_treeChannel);
75  m_tree->Branch("Sampling",&m_treeSampling);
76  m_tree->Branch("eta",&m_treeEta);
77  m_tree->Branch("scET",&m_treeSCET);
78  m_tree->Branch("truthET",&m_treeTruthET);
79  m_tree->Branch("digits",&m_treeDigits);
80 
82  CHECK( histSvc->regTree(TString::Format("/%s/debug",m_stream.c_str()).Data(),m_tree) );
83 
85 
86 
87  return StatusCode::SUCCESS;
88 }
89 
91 
93 
94  for(uint i=0;i<CaloSampling::getNumberOfSamplings();i++) { //don't bother writing empty hists
95  if(m_etReso[i]->GetEntries()) CHECK( histSvc->regHist(TString::Format("/%s/SuperCellValidation/%s",m_stream.c_str(),m_etReso[i]->GetName()).Data(),m_etReso[i]) );
96  if(m_Reso_et[i]->GetEntries()) CHECK( histSvc->regHist(TString::Format("/%s/SuperCellValidation/%s",m_stream.c_str(),m_Reso_et[i]->GetName()).Data(), m_Reso_et[i]) );
97  if(m_Reso_et_vs_eta[i]->GetEntries()) CHECK( histSvc->regHist(TString::Format("/%s/SuperCellValidation/%s",m_stream.c_str(),m_Reso_et_vs_eta[i]->GetName()).Data(), m_Reso_et_vs_eta[i]) );
98  if(m_Reso_et_vs_et[i]->GetEntries()) CHECK( histSvc->regHist(TString::Format("/%s/SuperCellValidation/%s",m_stream.c_str(),m_Reso_et_vs_et[i]->GetName()).Data(), m_Reso_et_vs_et[i]) );
99  if(m_Linear_SCet_vs_et[i]->GetEntries()) CHECK( histSvc->regHist(TString::Format("/%s/SuperCellValidation/%s",m_stream.c_str(),m_Linear_SCet_vs_et[i]->GetName()).Data(), m_Linear_SCet_vs_et[i]) );
100 
101 
102  if(!m_tscKey.empty()) {
103  if(m_etResoTruth[i]->GetEntries())CHECK( histSvc->regHist(TString::Format("/%s/%s",m_stream.c_str(),m_etResoTruth[i]->GetName()).Data(),m_etResoTruth[i]) );
104  }
105  }
106 
107  //also write any graphs
108  for(auto graphPointsX : m_graphsX) {
109  TGraph* g = new TGraph(graphPointsX.second.size(),&graphPointsX.second[0],&m_graphsY[graphPointsX.first][0]);
110  g->SetTitle(graphPointsX.first);
111  g->SetMarkerStyle(6);
112  CHECK( histSvc->regGraph(TString::Format("/%s/%s",m_stream.c_str(),graphPointsX.first.Data()).Data(),g) );
113  }
114 
115 
116  return StatusCode::SUCCESS;
117 }
118 
120  //get the supercells, calocells
121  const CaloCellContainer* scells=nullptr;CHECK( evtStore()->retrieve(scells, m_scKey) );
122 
123  const CaloCellContainer* ccells=nullptr;if(!m_ccKey.empty()) CHECK( evtStore()->retrieve(ccells, m_ccKey) );
124 
125  const CaloCellContainer* tscells=nullptr;if(!m_tscKey.empty()) CHECK( evtStore()->retrieve(tscells,m_tscKey) );
126 
128  const LArOnOffIdMapping* cabling{*cablingHdl};
129  if(!cabling) {
130  ATH_MSG_ERROR("Do not have SC mapping object " << m_cablingKey.key() );
131  return StatusCode::FAILURE;
132  }
133 
134  //iterate over supercells, and build up a histogram of the resolution
135  for(const auto *scell : *scells) {
136  //bool passPeakFinder( (scell->provenance()&0x40) );
137  //if(!passPeakFinder) continue; //skip non maxima?
138 
139  int samplingEnum = m_ccIdHelper->calo_sample(scell->ID());
140 
141  double scellEt = scell->e()*scell->sinTh()*1e-3;
142 
143  if(ccells) {
144  std::vector<Identifier> ccellIds = m_sc2ccMappingTool->superCellToOfflineID( scell->ID() );
145  double cellEt(0.);
146  //use findCell function of CaloCellContainer, which takes an identifier hash
147  for(auto& ccellId : ccellIds) {
148  const CaloCell* ccell = ccells->findCell(m_ccIdHelper->calo_cell_hash(ccellId));
149  if(!ccell) { ATH_MSG_WARNING("Could not find cell"); continue; }
150  if(ccell->e()>0) cellEt += ccell->e()*ccell->sinTh();
151  }
152  if(cellEt>0) m_etReso[samplingEnum]->Fill(cellEt*1e-3,scellEt*1000./cellEt);
153  float resolution = 0.0;
154  if ( TMath::Abs(cellEt)>1 ) resolution = 100*(scellEt - cellEt*1e-3 ) / (cellEt*1e-3);
155  if ( TMath::Abs(cellEt)>150 ) {
156  m_Reso_et[samplingEnum]->Fill( resolution );
157  m_Reso_et_vs_et[samplingEnum]->Fill( cellEt*1e-3, resolution );
158  m_Reso_et_vs_eta[samplingEnum]->Fill( scell->eta(), resolution );
159  m_Linear_SCet_vs_et[samplingEnum]->Fill( cellEt*1e-3 , scellEt );
160  }
161  }
162 
163  if(tscells) {
164  const CaloCell* tscell = tscells->findCell(scell->caloDDE()->calo_hash());
165  double tscellEt = tscell->e()*tscell->sinTh()*1e-3;
166  if(tscellEt>0) m_etResoTruth[samplingEnum]->Fill(tscellEt,scellEt/tscellEt);
167 
168  //detect suspicious supercells .. where truth energy is greater than 1GeV and we measure less than 25% of it, or super cell ET is greater than 1GeV and truth ET < 25% of that
169  if( (tscellEt>1. && scellEt/tscellEt<0.25) || (scellEt>1. && tscellEt/scellEt<0.25) ) {
170  m_eventNumber = getContext().eventID().event_number();
171 
172  HWIdentifier hwid = cabling->createSignalChannelID(scell->ID());
174  m_treeSampling = samplingEnum;
175  m_treeEta = scell->caloDDE()->eta();
176  m_treeSCET = scellEt;
177  m_treeTruthET = tscellEt;
178  if(!m_digitKey.empty()) {
179  const LArDigitContainer* digits=nullptr;CHECK( evtStore()->retrieve(digits, m_digitKey) );
180  for(const auto *digit : *digits) { if(digit->hardwareID()==hwid) *m_treeDigits = digit->samples(); }
181  }
182  m_tree->Fill();
183  }
184 
185  }
186 
187 
188 
189 
190  }
191 
192 
193  return StatusCode::SUCCESS;
194 }
195 
196 
SuperCellVsCaloCellTestAlg::m_scKey
std::string m_scKey
Definition: SuperCellVsCaloCellTestAlg.h:44
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
SuperCellVsCaloCellTestAlg::m_etReso
std::vector< TProfile * > m_etReso
Definition: SuperCellVsCaloCellTestAlg.h:53
SuperCellVsCaloCellTestAlg::m_treeSCET
float m_treeSCET
Definition: SuperCellVsCaloCellTestAlg.h:68
SuperCellVsCaloCellTestAlg::m_ccKey
std::string m_ccKey
Definition: SuperCellVsCaloCellTestAlg.h:44
SuperCellVsCaloCellTestAlg::m_Linear_SCet_vs_et
std::vector< TH2F * > m_Linear_SCet_vs_et
Definition: SuperCellVsCaloCellTestAlg.h:59
CaloCell_Base_ID::calo_cell_hash
IdentifierHash calo_cell_hash(const Identifier cellId) const
create hash id from 'global' cell id
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
SuperCellVsCaloCellTestAlg.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
StateLessPT_NewConfig.Format
Format
Definition: StateLessPT_NewConfig.py:146
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
Identifier::get_identifier32
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
CaloCell::e
virtual double e() const override final
get energy (data member) (synonym to method energy()
Definition: CaloCell.h:317
SuperCellVsCaloCellTestAlg::m_graphsX
std::map< TString, std::vector< float > > m_graphsX
Definition: SuperCellVsCaloCellTestAlg.h:61
SuperCellVsCaloCellTestAlg::finalize
virtual StatusCode finalize()
Definition: SuperCellVsCaloCellTestAlg.cxx:90
GetEntries
TGraphErrors * GetEntries(TH2F *histo)
Definition: TRTCalib_makeplots.cxx:4019
SuperCellVsCaloCellTestAlg::m_eventNumber
int m_eventNumber
Definition: SuperCellVsCaloCellTestAlg.h:64
CaloCell_Base_ID::calo_sample
int calo_sample(const Identifier id) const
returns an int taken from Sampling enum and describing the subCalo to which the Id belongs.
Definition: CaloCell_Base_ID.cxx:141
SuperCellVsCaloCellTestAlg::SuperCellVsCaloCellTestAlg
SuperCellVsCaloCellTestAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: SuperCellVsCaloCellTestAlg.cxx:25
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SuperCellVsCaloCellTestAlg::m_digitKey
std::string m_digitKey
Definition: SuperCellVsCaloCellTestAlg.h:44
checkRpcDigits.digit
digit
Definition: checkRpcDigits.py:186
SuperCellVsCaloCellTestAlg::initialize
virtual StatusCode initialize()
Definition: SuperCellVsCaloCellTestAlg.cxx:46
HWIdentifier
Definition: HWIdentifier.h:13
python.TrigEgammaMonitorHelper.TH2F
def TH2F(name, title, nxbins, bins_par2, bins_par3, bins_par4, bins_par5=None, bins_par6=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:45
SuperCellVsCaloCellTestAlg::m_tree
TTree * m_tree
Definition: SuperCellVsCaloCellTestAlg.h:71
Dedxcorrection::resolution
double resolution[nGasTypes][nParametersResolution]
Definition: TRT_ToT_Corrections.h:46
SuperCellVsCaloCellTestAlg::m_stream
std::string m_stream
Definition: SuperCellVsCaloCellTestAlg.h:44
Identifier32::get_compact
value_type get_compact() const
Get the compact id.
Definition: Identifier32.h:44
SuperCellVsCaloCellTestAlg::m_Reso_et_vs_eta
std::vector< TH2F * > m_Reso_et_vs_eta
Definition: SuperCellVsCaloCellTestAlg.h:57
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
uint
unsigned int uint
Definition: LArOFPhaseFill.cxx:20
SuperCellVsCaloCellTestAlg::m_graphsY
std::map< TString, std::vector< float > > m_graphsY
Definition: SuperCellVsCaloCellTestAlg.h:61
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SuperCellVsCaloCellTestAlg::m_etResoTruth
std::vector< TProfile * > m_etResoTruth
Definition: SuperCellVsCaloCellTestAlg.h:54
lumiFormat.i
int i
Definition: lumiFormat.py:85
python.TrigEgammaMonitorHelper.TProfile
def TProfile(*args, **kwargs)
Definition: TrigEgammaMonitorHelper.py:81
python.CaloCondTools.g
g
Definition: CaloCondTools.py:15
SuperCellVsCaloCellTestAlg::m_treeDigits
std::vector< short int > * m_treeDigits
Definition: SuperCellVsCaloCellTestAlg.h:70
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SuperCellVsCaloCellTestAlg::m_treeSampling
int m_treeSampling
Definition: SuperCellVsCaloCellTestAlg.h:66
SuperCellVsCaloCellTestAlg::m_Reso_et
std::vector< TH1F * > m_Reso_et
Definition: SuperCellVsCaloCellTestAlg.h:56
MuonSegmentReaderConfig.histSvc
histSvc
Definition: MuonSegmentReaderConfig.py:96
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
SuperCellVsCaloCellTestAlg::m_treeChannel
int m_treeChannel
Definition: SuperCellVsCaloCellTestAlg.h:65
SuperCellVsCaloCellTestAlg::m_sc2ccMappingTool
ToolHandle< ICaloSuperCellIDTool > m_sc2ccMappingTool
Definition: SuperCellVsCaloCellTestAlg.h:41
AthAlgorithm
Definition: AthAlgorithm.h:47
SuperCellVsCaloCellTestAlg::m_treeTruthET
float m_treeTruthET
Definition: SuperCellVsCaloCellTestAlg.h:69
CaloCellContainer::findCell
const CaloCell * findCell(const IdentifierHash theHash) const
fast find method given identifier hash.
Definition: CaloCellContainer.cxx:345
SuperCellVsCaloCellTestAlg::m_treeEta
float m_treeEta
Definition: SuperCellVsCaloCellTestAlg.h:67
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CaloSampling::getNumberOfSamplings
static constexpr unsigned int getNumberOfSamplings()
Get number of available samplings.
Definition: Calorimeter/CaloGeoHelpers/CaloGeoHelpers/CaloSampling.h:30
LArDigitContainer.h
CaloCellContainer.h
CaloCellContainer
Container class for CaloCell.
Definition: CaloCellContainer.h:55
SuperCellVsCaloCellTestAlg::execute
virtual StatusCode execute()
Definition: SuperCellVsCaloCellTestAlg.cxx:119
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
SuperCellVsCaloCellTestAlg::m_tscKey
std::string m_tscKey
Definition: SuperCellVsCaloCellTestAlg.h:44
LArDigitContainer
Container class for LArDigit.
Definition: LArDigitContainer.h:24
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
CaloSampling::getSamplingName
static std::string getSamplingName(CaloSample theSample)
Returns a string (name) for each CaloSampling.
Definition: Calorimeter/CaloGeoHelpers/Root/CaloSampling.cxx:18
SuperCellVsCaloCellTestAlg::m_ccIdHelper
const CaloCell_ID * m_ccIdHelper
Definition: SuperCellVsCaloCellTestAlg.h:42
SuperCellVsCaloCellTestAlg::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Definition: SuperCellVsCaloCellTestAlg.h:40
SuperCellVsCaloCellTestAlg::~SuperCellVsCaloCellTestAlg
virtual ~SuperCellVsCaloCellTestAlg()
CaloCell::sinTh
virtual double sinTh() const override final
get sin(theta) (through CaloDetDescrElement)
Definition: CaloCell.h:373
ServiceHandle< ITHistSvc >
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20
SuperCellVsCaloCellTestAlg::m_Reso_et_vs_et
std::vector< TH2F * > m_Reso_et_vs_et
Definition: SuperCellVsCaloCellTestAlg.h:58