ATLAS Offline Software
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 //###############################################################################
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),
57  m_isSingleParticle(true),
58  m_NormalizationTypeForFit("Lin"),
59  m_NormalizationTypeForMinim("Lin"),
60  m_ClassificationType("pdg"),
61  m_MaxEventsPerFile(0)
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 ***************************************************************************** */
102 {
103 
104 }
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  ******************************************** */
120  CaloLocalHadCoeffHelper dmHelper;
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;
150  }
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) {
159  CaloHadDMCoeffFit *dmFit = new CaloHadDMCoeffFit();
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) {
173  CaloHadDMCoeffMinim *dmMinim = new CaloHadDMCoeffMinim();
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) {
213  CaloHadDMCoeffCheck *dmCheck = new CaloHadDMCoeffCheck();
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 
CaloHadDMCoeffData::SetMaxEventsPerFile
void SetMaxEventsPerFile(int nev)
Definition: CaloHadDMCoeffData.h:99
GetLCDeadMaterial::initialize
virtual StatusCode initialize()
Definition: GetLCDeadMaterial.cxx:111
CaloHadDMCoeffMinim.h
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
GetLCDeadMaterial::m_ClassificationType
std::string m_ClassificationType
use particle id information
Definition: GetLCDeadMaterial.h:121
get_generator_info.result
result
Definition: get_generator_info.py:21
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
Definition: PathResolver.cxx:251
CaloHadDMCoeffFit::make_report
void make_report(std::string &sfname)
Definition: CaloHadDMCoeffFit.cxx:588
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
GetLCDeadMaterial::GetLCDeadMaterial
GetLCDeadMaterial(const std::string &name, ISvcLocator *pSvcLocator)
Definition: GetLCDeadMaterial.cxx:44
GetLCDeadMaterial::~GetLCDeadMaterial
virtual ~GetLCDeadMaterial()
Definition: GetLCDeadMaterial.cxx:101
GetLCDeadMaterial::m_doCheck
bool m_doCheck
Do toy reconstruction for final validation of new dead material constants.
Definition: GetLCDeadMaterial.h:86
CaloLocalHadCoeffHelper::PrintData
void PrintData(const CaloLocalHadCoeff *data, std::ostream &fout)
Definition: CaloLocalHadCoeffHelper.cxx:167
CaloHadDMCoeffData::kCLASSIFY_USE_PARTICLEID
@ kCLASSIFY_USE_PARTICLEID
Definition: CaloHadDMCoeffData.h:87
CaloLocalHadCoeff::getSizeAreaSet
int getSizeAreaSet() const
return number of areas defined for this data set
Definition: CaloLocalHadCoeff.h:248
GetLCDeadMaterial::m_isTestbeam
bool m_isTestbeam
H6 combined testbeam flag.
Definition: GetLCDeadMaterial.h:101
GetLCDeadMaterial::m_NormalizationTypeForFit
std::string m_NormalizationTypeForFit
Normalization type for fit procedure.
Definition: GetLCDeadMaterial.h:111
CaloHadDMCoeffCheck.h
CaloHadDMCoeffCheck::process
int process(CaloHadDMCoeffData *myData, CaloLocalHadCoeff *myHadDMCoeff, bool isSingleParticle=true, bool tbflag=false)
Definition: CaloHadDMCoeffCheck.cxx:80
GetLCDeadMaterial::m_reportCheck
std::string m_reportCheck
Name of postscript file for results of toy reconstruction.
Definition: GetLCDeadMaterial.h:66
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
CaloLocalHadCoeffHelper::InitDataFromFile
CaloLocalHadCoeff * InitDataFromFile(const char *fname)
Definition: CaloLocalHadCoeffHelper.cxx:59
CaloHadDMCoeffFit
To fill and fit TProfile histograms using special dead material tree.
Definition: CaloHadDMCoeffFit.h:36
GetLCDeadMaterial::m_key
std::string m_key
Name of key to write into pool file.
Definition: GetLCDeadMaterial.h:96
CaloLocalHadCoeffHelper
Definition: CaloLocalHadCoeffHelper.h:14
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
CaloHadDMCoeffCheck
Runs toy reconstruction to validate dead material constants.
Definition: CaloHadDMCoeffCheck.h:40
CaloHadDMCoeffCheck::make_report
void make_report(std::string &sfname)
Definition: CaloHadDMCoeffCheck.cxx:378
CaloHadDMCoeffMinim::make_report
void make_report(std::string &sfname)
Definition: CaloHadDMCoeffMinim.cxx:432
GetLCDeadMaterial::m_MaxEventsPerFile
int m_MaxEventsPerFile
number of maximum events to process in one root files
Definition: GetLCDeadMaterial.h:126
dqt_zlumi_alleff_HIST.fout
fout
Definition: dqt_zlumi_alleff_HIST.py:59
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CaloLocalHadCoeff
Hold binned correction data for local hadronic calibration procedure.
Definition: CaloLocalHadCoeff.h:41
CaloLocalHadCoeffHelper.h
CaloHadDMCoeffMinim::SetNormalizationType
void SetNormalizationType(std::string &stype)
Definition: CaloHadDMCoeffMinim.h:73
CaloHadDMCoeffData
Data to read from special DeadMaterialTree.
Definition: CaloHadDMCoeffData.h:30
CaloHadDMCoeffMinim::process
CaloLocalHadCoeff * process(CaloHadDMCoeffData *myData, CaloLocalHadCoeff *myHadDMCoeff, bool isSingleParticle=true, bool tbflag=false)
Definition: CaloHadDMCoeffMinim.cxx:122
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
GetLCDeadMaterial.h
GetLCDeadMaterial::m_doFit
bool m_doFit
Do TProfile fitting.
Definition: GetLCDeadMaterial.h:71
AthAlgorithm
Definition: AthAlgorithm.h:47
CaloLocalHadCoeff::getSizeCoeffSet
int getSizeCoeffSet() const
return total number of coefficient sets
Definition: CaloLocalHadCoeff.h:269
GetLCDeadMaterial::m_reportProfiles
std::string m_reportProfiles
Name of postscript file for fit summary.
Definition: GetLCDeadMaterial.h:56
CaloHadDMCoeffFit::SetNormalizationType
void SetNormalizationType(std::string &stype)
Definition: CaloHadDMCoeffFit.h:86
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
GetLCDeadMaterial::m_doMinimization
bool m_doMinimization
Do minimization.
Definition: GetLCDeadMaterial.h:76
errorcheck.h
Helpers for checking error return status codes and reporting errors.
GetLCDeadMaterial::m_doPool
bool m_doPool
Do pool writing.
Definition: GetLCDeadMaterial.h:81
CaloHadDMCoeffFit.h
CaloHadDMCoeffData::SetClassificationType
void SetClassificationType(int type)
Definition: CaloHadDMCoeffData.h:98
python.AthDsoLogger.fname
string fname
Definition: AthDsoLogger.py:67
GetLCDeadMaterial::m_HadDMCoeffOutputFile
std::string m_HadDMCoeffOutputFile
Name of text file with calculated coefficients.
Definition: GetLCDeadMaterial.h:51
CaloLocalHadCoeff.h
GetLCDeadMaterial::execute
virtual StatusCode execute()
Definition: GetLCDeadMaterial.cxx:243
GetLCDeadMaterial::m_isSingleParticle
bool m_isSingleParticle
data sample contains single particles only
Definition: GetLCDeadMaterial.h:106
CaloHadDMCoeffFit::process
CaloLocalHadCoeff * process(CaloHadDMCoeffData *myData, CaloLocalHadCoeff *myHadDMCoeff, bool isSingleParticle=true, bool tbflag=false)
Definition: CaloHadDMCoeffFit.cxx:77
GetLCDeadMaterial::m_HadDMCoeffInputFile
std::string m_HadDMCoeffInputFile
Name of text file with initial parameters for coefficients calculation.
Definition: GetLCDeadMaterial.h:46
GetLCDeadMaterial::m_inputRootFiles
std::vector< std::string > m_inputRootFiles
List of root files to process.
Definition: GetLCDeadMaterial.h:91
GetLCDeadMaterial::finalize
virtual StatusCode finalize()
Definition: GetLCDeadMaterial.cxx:232
CaloHadDMCoeffMinim
Definition: CaloHadDMCoeffMinim.h:31
CaloHadDMCoeffData.h
GetLCDeadMaterial::m_reportMinimization
std::string m_reportMinimization
Name of postscript file for minimization summary.
Definition: GetLCDeadMaterial.h:61
GetLCDeadMaterial::m_NormalizationTypeForMinim
std::string m_NormalizationTypeForMinim
Normalization type for minimization procedure.
Definition: GetLCDeadMaterial.h:116