ATLAS Offline Software
Loading...
Searching...
No Matches
GetLCDeadMaterial.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//-----------------------------------------------------------------------
6// File and Version Information:
7// $Id: GetLCDeadMaterial.cxx,v 1.1 2009-03-03 17:30:23 pospelov Exp $
8//
9// Description: see GetLCDeadMaterial.h
10//
11// Environment:
12// Software developed for the ATLAS Detector at CERN LHC
13//
14// Author List:
15// Gennady Pospelov
16//
17//-----------------------------------------------------------------------
18
19//-----------------------
20// This Class's Header --
21//-----------------------
23
24//---------------
25// C++ Headers --
26//---------------
29#include "GaudiKernel/ISvcLocator.h"
30#include "GaudiKernel/StatusCode.h"
31
38
39#include "TTree.h"
40#include <memory>
41
42
43//###############################################################################
44GetLCDeadMaterial::GetLCDeadMaterial(const std::string& name,
45 ISvcLocator* pSvcLocator)
46 : AthAlgorithm(name, pSvcLocator),
47 m_HadDMCoeffInputFile("CaloHadDMCoeff_init_v2.txt"),
48 m_HadDMCoeffOutputFile("CaloHadDMCoeff_output.txt"),
49 m_reportProfiles("report_CaloHadDMCoeff_profiles.ps"),
50 m_reportMinimization("report_CaloHadDMCoeff_minim.ps"),
51 m_reportCheck("report_CaloHadDMCoeff_check.ps"),
52 m_doFit(true),
53 m_doMinimization(false),
54 m_doPool(true),
55 m_doCheck(true),
56 m_isTestbeam(false),
62{
63
64 // initial coeffitients
65 declareProperty("HadDMCoeffInputFile",m_HadDMCoeffInputFile);
66 // output file with coeffitients
67 declareProperty("HadDMCoeffOutputFile",m_HadDMCoeffOutputFile);
68 // name of file with fitting results
69 declareProperty("ReportProfiles",m_reportProfiles);
70 // name of file with fitting results
71 declareProperty("ReportMinimization",m_reportMinimization);
72 // name of file with fitting results
73 declareProperty("ReportCheck",m_reportCheck);
74 // do TProfile fit
75 declareProperty("DoFit",m_doFit);
76 // do minimization
77 declareProperty("DoMinimization",m_doMinimization);
78 // do writing to pool file
79 declareProperty("DoPool",m_doPool);
80 // do writing to pool file
81 declareProperty("DoCheck",m_doCheck);
82 // list of files to process
83 declareProperty("InputRootFiles",m_inputRootFiles);
84 // key to write into pool file
85 declareProperty("CorrectionKey",m_key="HadDMCoeff2");
86 // H6 combined testbeam flag
87 declareProperty("isTestbeam",m_isTestbeam);
88 // normalization types
89 declareProperty("NormalizationTypeForFit",m_NormalizationTypeForFit);
90 declareProperty("NormalizationTypeForMinim",m_NormalizationTypeForMinim);
91 // number of maximum events to process in one root files
92 declareProperty("MaxEventsPerFile", m_MaxEventsPerFile);
93
94}
95
96
97
98/* ****************************************************************************
99
100***************************************************************************** */
105
106
107
108/* ****************************************************************************
109
110***************************************************************************** */
112{
113 //std::cout << std::endl;
114 //std::cout << std::endl;
115 //std::cout << "--- GetLCDeadMaterial::initialize() --- " << std::endl;
116
117 /* ********************************************
118 default coefficients
119 ******************************************** */
121 std::string fileName = PathResolver::find_file (m_HadDMCoeffInputFile, "DATAPATH");
122 std::unique_ptr<CaloLocalHadCoeff> initHadDMCoeff (dmHelper.InitDataFromFile(fileName.c_str()));
123 if( !initHadDMCoeff ) {
124 ATH_MSG_FATAL( " Error while initializing default dead material coefficients " );
125 return StatusCode::FAILURE;
126 }
127 //dmHelper.PrintData(initHadDMCoeff, std::cout);
128 ATH_MSG_INFO( " Number of dead material areas defined:" << initHadDMCoeff->getSizeAreaSet()
129 << ", total number of correction coefficients:" << initHadDMCoeff->getSizeCoeffSet() );
130
131 /* ********************************************
132 input chain
133 ******************************************** */
134 TChain *pChain = new TChain("DeadMaterialTree");
135 if( m_inputRootFiles.empty() ) {
136 ATH_MSG_FATAL( " Empty vector of input root files! " );
137 return StatusCode::FAILURE;
138 }
139 for (const std::string& fname : m_inputRootFiles) {
140 ATH_MSG_INFO( " Adding root file '" <<fname << "'" );
141 pChain->Add( fname.c_str() );
142 }
143
144 // pointer to the chain and data in it
145 std::unique_ptr<CaloHadDMCoeffData> dmData (new CaloHadDMCoeffData(pChain));
146 if(m_ClassificationType == "particleid") {
147 ATH_MSG_INFO( "Particle ID em fraction will be used to classify clusters:" );
148 m_isSingleParticle = false;
149 dmData->SetClassificationType(CaloHadDMCoeffData::kCLASSIFY_USE_PARTICLEID);
150 }
151 dmData->SetMaxEventsPerFile(m_MaxEventsPerFile);
152
153 std::unique_ptr<CaloLocalHadCoeff> newHadDMCoeffFit;
154 std::unique_ptr<CaloLocalHadCoeff> newHadDMCoeffMinim;
155
156 // TProfile approach (presamplers, material between EMB&TILE, EMEC&HEC)
157 // and lookup approach (leakages, unclassified DM energy)
158 if(m_doFit) {
161 newHadDMCoeffFit = std::unique_ptr<CaloLocalHadCoeff>(dmFit->process(dmData.get(), initHadDMCoeff.get(), m_isSingleParticle, m_isTestbeam));
162 if( !newHadDMCoeffFit ) {
163 ATH_MSG_FATAL( "Failed in CaloHadDMCoeffFit::process()" );
164 delete dmFit;
165 return StatusCode::FAILURE;
166 }
167 if(!m_reportProfiles.empty()) dmFit->make_report(m_reportProfiles);
168 delete dmFit;
169 }
170
171 // minimization approach (material before FCAL)
172 if(m_doMinimization) {
175 if(newHadDMCoeffFit) {
176 // to use previous coefficients as initial values
177 newHadDMCoeffMinim = std::unique_ptr<CaloLocalHadCoeff>(dmMinim->process(dmData.get(), newHadDMCoeffFit.get(), m_isSingleParticle, m_isTestbeam));
178 }else{
179 newHadDMCoeffMinim = std::unique_ptr<CaloLocalHadCoeff>(dmMinim->process(dmData.get(), initHadDMCoeff.get(), m_isSingleParticle, m_isTestbeam));
180 }
181 if( !newHadDMCoeffMinim ) {
182 ATH_MSG_FATAL( "Failed in CaloHadDMCoeffMinim::process()" );
183 return StatusCode::FAILURE;
184 }
186 delete dmMinim;
187 }
188
189 CaloLocalHadCoeff *result = nullptr;
190 if(newHadDMCoeffMinim) {
191 result = new CaloLocalHadCoeff(*newHadDMCoeffMinim);
192 }else if(newHadDMCoeffFit) {
193 result = new CaloLocalHadCoeff(*newHadDMCoeffFit);
194 }else{
195 result = new CaloLocalHadCoeff(*initHadDMCoeff);
196 }
197 // prints coefficients to ASCII file
198 if (result) {
199 std::ofstream fout;
200 fout.open(m_HadDMCoeffOutputFile.c_str());
201 dmHelper.PrintData(result, fout);
202 fout.close();
203 }
204
205 // writing data to the pool
206 if(m_doPool) {
207 ATH_CHECK( detStore()->record(result,m_key) );
208 ATH_CHECK( detStore()->setConst(result) );
209 }
210
211 // running toy reconstruction for validation of new dead material constants
212 if(m_doCheck) {
214 dmCheck->process(dmData.get(), result, m_isSingleParticle, m_isTestbeam);
215 dmCheck->make_report(m_reportCheck);
216 delete dmCheck;
217 }
218
219 // end of the game
220 delete pChain;
221
222 if(result && !m_doPool) delete result;
223
224 return StatusCode::SUCCESS;
225}
226
227
228
229/* ****************************************************************************
230
231***************************************************************************** */
233{
234 ATH_MSG_INFO( " Nothing to be done in finalize() method " );
235 return StatusCode::SUCCESS;
236}
237
238
239
240/* ****************************************************************************
241
242***************************************************************************** */
244{
245 ATH_MSG_INFO( " Nothing to be done in execute() method " );
246 return StatusCode::SUCCESS;
247}
248
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
Helpers for checking error return status codes and reporting errors.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
Runs toy reconstruction to validate dead material constants.
int process(CaloHadDMCoeffData *myData, CaloLocalHadCoeff *myHadDMCoeff, bool isSingleParticle=true, bool tbflag=false)
void make_report(std::string &sfname)
Data to read from special DeadMaterialTree.
To fill and fit TProfile histograms using special dead material tree.
void SetNormalizationType(std::string &stype)
void make_report(std::string &sfname)
CaloLocalHadCoeff * process(CaloHadDMCoeffData *myData, CaloLocalHadCoeff *myHadDMCoeff, bool isSingleParticle=true, bool tbflag=false)
CaloLocalHadCoeff * process(CaloHadDMCoeffData *myData, CaloLocalHadCoeff *myHadDMCoeff, bool isSingleParticle=true, bool tbflag=false)
void SetNormalizationType(std::string &stype)
void make_report(std::string &sfname)
CaloLocalHadCoeff * InitDataFromFile(const char *fname)
void PrintData(const CaloLocalHadCoeff *data, std::ostream &fout)
Hold binned correction data for local hadronic calibration procedure.
std::string m_key
Name of key to write into pool file.
bool m_isTestbeam
H6 combined testbeam flag.
bool m_doFit
Do TProfile fitting.
std::string m_NormalizationTypeForFit
Normalization type for fit procedure.
bool m_doPool
Do pool writing.
GetLCDeadMaterial(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode initialize()
std::string m_reportMinimization
Name of postscript file for minimization summary.
bool m_isSingleParticle
data sample contains single particles only
std::string m_NormalizationTypeForMinim
Normalization type for minimization procedure.
bool m_doMinimization
Do minimization.
bool m_doCheck
Do toy reconstruction for final validation of new dead material constants.
std::string m_HadDMCoeffOutputFile
Name of text file with calculated coefficients.
virtual StatusCode finalize()
std::string m_reportCheck
Name of postscript file for results of toy reconstruction.
virtual StatusCode execute()
std::string m_reportProfiles
Name of postscript file for fit summary.
std::string m_ClassificationType
use particle id information
int m_MaxEventsPerFile
number of maximum events to process in one root files
std::vector< std::string > m_inputRootFiles
List of root files to process.
std::string m_HadDMCoeffInputFile
Name of text file with initial parameters for coefficients calculation.
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
static TFile * fout
Definition listroot.cxx:40