ATLAS Offline Software
CaloHadDMCoeffMinim.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: CaloHadDMCoeffMinim.cxx,v 1.2 2009/03/06 14:43:23 pospelov Exp $
8 //
9 // Description: see CaloHadDMCoeffMinim.h
10 //
11 // Environment:
12 // Software developed for the ATLAS Detector at CERN LHC
13 //
14 // Author List:
15 // Gennady Pospelov
16 //
17 //-----------------------------------------------------------------------
19 #include "AthenaKernel/Units.h"
27 #include "boost/io/ios_state.hpp"
28 #include <cmath>
29 #include <fstream>
30 #include <iomanip>
31 #include <iostream>
32 #include <sstream>
33 
34 #include <CLHEP/Vector/LorentzVector.h>
35 
36 #include "TROOT.h"
37 #include "TStyle.h"
38 #include "TError.h"
39 #include "TFile.h"
40 #include "TChain.h"
41 #include "TH1.h"
42 #include "TF1.h"
43 #include "TProfile.h"
44 #include "TH2F.h"
45 #include "TCanvas.h"
46 #include "TPad.h"
47 #include "TText.h"
48 #include "TMinuit.h"
49 #include "TVirtualFitter.h"
50 #include "TLatex.h"
51 #include "TGraphErrors.h"
52 #include "TBenchmark.h"
53 
54 
55 using CLHEP::HepLorentzVector;
56 using Athena::Units::MeV;
57 using Athena::Units::GeV;
58 
59 
61 
62 
64  m_data (nullptr),
65  m_HadDMHelper (std::make_unique<CaloLocalHadCoeffHelper>()),
66  m_HadDMCoeff (nullptr),
67  m_isTestbeam(false),
68  m_nstep_fcn(0),
69  m_iBinGlob(0),
70  m_engClusMin(1.*GeV),
71  m_engBeamMin(1.*GeV),
72  m_area_index(0),
73  m_NormalizationType("Lin"),
74  m_NormalizationTypeNumber(0)
75 {
76  // list of parameters available for minimization
77  m_minimPars.emplace_back("PreSamplerB", 1.0, 0.5, 0.99, 20.0 );
78  m_minimPars.emplace_back("EMB1", 1.0, 0.5, 0.99, 20.0 );
79  m_minimPars.emplace_back("EMB2", 1.0, 0.5, 0.99, 20.0 );
80  m_minimPars.emplace_back("EMB3", 1.0, 0.5, 0.99, 20.0 );
81  m_minimPars.emplace_back("PreSamplerE", 1.0, 0.5, 0.99, 20.0 );
82  m_minimPars.emplace_back("EME1", 1.0, 0.5, 0.99, 20.0 );
83  m_minimPars.emplace_back("EME2", 1.0, 0.5, 0.99, 2000.0 ); // 6
84  m_minimPars.emplace_back("EME3", 1.0, 0.5, 0.99, 2000.0 );
85  m_minimPars.emplace_back("HEC0", 1.0, 0.5, 0.99, 2000.0 );
86  m_minimPars.emplace_back("HEC1", 1.0, 0.5, 0.99, 2000.0 );
87  m_minimPars.emplace_back("HEC2", 1.0, 0.5, 0.99, 20.0 );
88  m_minimPars.emplace_back("HEC3", 1.0, 0.5, 0.99, 20.0 );
89  m_minimPars.emplace_back("TileBar0", 1.0, 0.5, 0.99, 20.0 );
90  m_minimPars.emplace_back("TileBar1", 1.0, 0.5, 0.99, 20.0 );
91  m_minimPars.emplace_back("TileBar2", 1.0, 0.5, 0.99, 20.0 );
92  m_minimPars.emplace_back("TileGap1", 1.0, 0.5, 0.99, 20.0 );
93  m_minimPars.emplace_back("TileGap2", 1.0, 0.5, 0.99, 20.0 );
94  m_minimPars.emplace_back("TileGap3", 1.0, 0.5, 0.99, 20.0 );
95  m_minimPars.emplace_back("TileExt0", 1.0, 0.5, 0.99, 20.0 );
96  m_minimPars.emplace_back("TileExt1", 1.0, 0.5, 0.99, 20.0 );
97  m_minimPars.emplace_back("TileExt2", 1.0, 0.5, 0.99, 20.0 );
98  m_minimPars.emplace_back("FCAL0", 1.0, 0.01, 0.99, 3.0 );
99  m_minimPars.emplace_back("FCAL1", 1.0, 0.01, 0.99, 3.0 );
100  m_minimPars.emplace_back("FCAL2", 1.0, 0.5, 0.99, 20.0 );
101  m_minimPars.emplace_back("MINIFCAL0", 1.0, 0.5, 0.99, 20.0 );
102  m_minimPars.emplace_back("MINIFCAL1", 1.0, 0.5, 0.99, 20.0 );
103  m_minimPars.emplace_back("MINIFCAL2", 1.0, 0.5, 0.99, 20.0 );
104  m_minimPars.emplace_back("MINIFCAL3", 1.0, 0.5, 0.99, 20.0 );
105  m_minimPars.emplace_back("CONST", 0.0, 10., 0.0, 5000. );
106 
107  m_distance_cut = 1.5;
108 
109  s_instance = this;
110 }
111 
112 
114 {
115 }
116 
117 
118 /* ****************************************************************************
119 Runs minimization to get new sampling weights for optimum reconstruction of
120 dead material before FCAL
121 **************************************************************************** */
123 {
124  m_isTestbeam = tbflag;
125 
126  std::cout << std::endl;
127  std::cout << std::endl;
128  std::cout << "--- CaloHadDMCoeffMinim::process() --- " << std::endl;
129 
130  if(m_isTestbeam) std::cout << "Processing TESTBEAM data" << std::endl;
131 
132  if ( m_NormalizationType == "Lin" ) {
133  std::cout << "Using weighting proportional to E_calib" << std::endl;
135  } else if ( m_NormalizationType == "Log" ) {
136  std::cout << "Using weighting proportional to log(E_calib)" << std::endl;
138  } else if ( m_NormalizationType == "NClus" ) {
139  std::cout << "Using weighting proportional to 1/N_Clus_E_calib>0" << std::endl;
141  } else {
142  std::cout << "Using constant weighting" << std::endl;
144  }
145 
146  m_data = myData; // pointer to TChain data
147  m_HadDMCoeff = myHadDMCoeff; // pointer to the initial coefficients
148 
149  m_data->fChain->SetBranchStatus("*",0);
150  m_data->fChain->SetBranchStatus("mc_ener",1);
151  m_data->fChain->SetBranchStatus("mc_eta",1);
152  m_data->fChain->SetBranchStatus("mc_phi",1);
153  m_data->fChain->SetBranchStatus("mc_pdg",1);
154  m_data->fChain->SetBranchStatus("ncls",1);
155  m_data->fChain->SetBranchStatus("cls_eta",1);
156  m_data->fChain->SetBranchStatus("cls_phi",1);
157  m_data->fChain->SetBranchStatus("cls_lambda",1);
158  m_data->fChain->SetBranchStatus("cls_calib_emfrac",1);
159  m_data->fChain->SetBranchStatus("cls_engcalib",1);
160  m_data->fChain->SetBranchStatus("engClusSumCalib",1);
161  m_data->fChain->SetBranchStatus("cls_ener_unw",1);
162  m_data->fChain->SetBranchStatus("narea",1);
163  //m_data->fChain->SetBranchStatus("cls_eprep",1);
164  m_data->fChain->SetBranchStatus("cls_dmener",1);
165  m_data->fChain->SetBranchStatus("cls_smpener_unw",1);
166  //m_data->fChain->SetBranchStatus("m_cls_oocener",1);
167  //m_data->fChain->SetBranchStatus("cls_engcalibpres",1);
168 
169  if( !m_data->GetEntries() ) {
170  std::cout << "CaloHadDMCoeffMinim::process -> Error! No entries in DeadMaterialTree." << std::endl;
171  return nullptr;
172  }
173 
174  m_data->GetEntry(0);
176  std::cout << "CaloHadDMCoeffFit::process -> Error! Different numbers of areas for DM definition" << std::endl;
177  std::cout << "m_data->m_narea:" << m_data->m_narea << " m_HadDMCoeff->getSizeAreaSet():" << m_HadDMCoeff->getSizeAreaSet() << std::endl;
178  return nullptr;
179  }
180 
181  // We are going to receive dead material correction coefficients only for one
182  // dead material area corresponding 'ENG_CALIB_DEAD_FCAL' calibration moment
183  const CaloLocalHadCoeff::LocalHadArea *dmArea = m_HadDMHelper->getAreaFromName(m_HadDMCoeff, "ENG_CALIB_DEAD_FCAL", m_area_index);
184  std::cout << "CaloHadDMCoeffMinim::process() -> Info. Preparing for '" << dmArea->getTitle() << " index:" << m_area_index
185  << " npars:" << dmArea->getNpars() << ", for minimization:" << m_validNames.size() << std::endl;
186  if( (int)m_minimPars.size() != dmArea->getNpars()) {
187  std::cout << "CaloHadDMCoeffMinim::process() -> FATAL! Number of parameters for dead material area is different from number of mininuit pars." << std::endl;
188  exit(0);
189  }
190 
191  /* ********************************************
192  Let's fill sample with data to calculate chi2
193  1. loop through data sample
194  3. filling minimisation sample with clusters having appropriate iBin
195  ********************************************* */
196  std::cout << "CaloHadDMCoeffMinim::process() -> Info. Step 2 - making cluster set..." << std::endl;
197  m_minimSample.clear();
198  m_sample_size.resize(dmArea->getLength(), 0);
199  int nGoodEvents = 0;
200  for(int i_ev=0; m_data->GetEntry(i_ev)>0;i_ev++) {
201 
202  //if(m_data->m_mc_ener < m_engBeamMin) continue;
203 
204  if(i_ev%20000==0) std::cout << " i_ev: " << i_ev << " (" << nGoodEvents << ") '" << ((TChain *)m_data->fChain)->GetFile()->GetName() << "'" << std::endl;
205 
206  double EnergyResolution; // in GeV
207  if( abs(m_data->m_mc_pdg) == 211) {
208  EnergyResolution = sqrt((0.5*0.5/GeV)*m_data->m_mc_ener+pow((0.03/GeV*m_data->m_mc_ener),2));// in GeV
209  } else {
210  //EnergyResolution = sqrt(0.1*0.1*m_data->m_mc_ener/GeV+0.003*0.003+0.007*0.007*pow((m_data->m_mc_ener/GeV),2)); // in GeV
211  EnergyResolution = sqrt((0.5*0.5/GeV)*m_data->m_mc_ener+pow((0.03/GeV*m_data->m_mc_ener),2));// in GeV
212  }
213 
214  // checking event quality
215  if(isSingleParticle) {
216  bool GoodClusterFound(false);
217  if( m_data->m_ncls ) {
218  HepLorentzVector hlv_pion(1,0,0,1);
219  hlv_pion.setREtaPhi(1./cosh(m_data->m_mc_eta), m_data->m_mc_eta, m_data->m_mc_phi);
220  for(int i_cls=0; i_cls<m_data->m_ncls; i_cls++){ // loop over clusters
221  HepLorentzVector hlv_cls(1,0,0,1);
222  hlv_cls.setREtaPhi(1./cosh( (*m_data->m_cls_eta)[i_cls] ), (*m_data->m_cls_eta)[i_cls], (*m_data->m_cls_phi)[i_cls]);
223  double r = hlv_pion.angle(hlv_cls.vect());
225  && (*m_data->m_cls_engcalib)[i_cls] > 20.0*MeV
226  //&& (*m_data->m_cls_ener)[i_cls] > 0.01*m_data->m_mc_ener
227  ) {
228  GoodClusterFound = true;
229  break;
230  }
231  } // i_cls
232  } // m_ncls
233  if(!GoodClusterFound) continue;
234  }
235 
236  if(m_data->m_engClusSumCalib <=0.0) continue;
237 
238  for(int i_cls=0; i_cls<m_data->m_ncls; i_cls++){ // loop over clusters
239  if( (*m_data->m_cls_ener_unw)[i_cls] < m_engClusMin
240  || (*m_data->m_cls_engcalib)[i_cls] < 20.0*MeV
241  ) continue;
242  std::vector<float> vars;
243  m_data->PackClusterVars(i_cls, vars);
244  int iBin = m_HadDMCoeff->getBin(m_area_index, vars );
245 
246  if(iBin >= dmArea->getOffset() && iBin < (dmArea->getOffset()+dmArea->getLength()) && m_data->m_engClusSumCalib > 0.0 && m_data->m_mc_ener > 0.0) {
247  auto ev = std::make_unique<MinimSample>();
248  // we need only edmtrue and energy in cluster samplings to calculate fcn
249  ev->ibin = iBin;
250  ev->edmtrue = (*m_data->m_cls_dmener)[i_cls][m_area_index];
251  if(ev->edmtrue<0) ev->edmtrue=0.0;
253  ev->clsm_smp_energy_unw.resize((*m_data->m_cls_smpener_unw)[i_cls].size());
254  for(unsigned int i_smp=0; i_smp<(*m_data->m_cls_smpener_unw)[i_cls].size(); i_smp++){
255  ev->clsm_smp_energy_unw[i_smp] = (*m_data->m_cls_smpener_unw)[i_cls][i_smp];
256  }
257  }
258  // Calculation of cluster weight, which shows siginicance of it for chi2 calculation
259  double clus_weight = 1.0;
261  clus_weight = (*m_data->m_cls_engcalib)[i_cls]/m_data->m_engClusSumCalib;
262  }
263  ev->weight = clus_weight;
264 
265  // error which will be used during chi2 calculation, currently it is simply the energy resolution
266  ev->sigma2 = EnergyResolution*EnergyResolution;
267  m_minimSample.push_back(std::move(ev));
268  m_sample_size[iBin - dmArea->getOffset()]++;
269  }
270  } // i_cls
271 
272  nGoodEvents++;
273  } // i_ev
274 
275 
276  /* ********************************************
277  run minimization
278  ********************************************* */
279  std::cout << "CaloHadDMCoeffMinim::process() -> Info. Starting minimization, m_minimSample.size(): " << m_minimSample.size() << "( " << float(m_minimSample.size())*(26.0/1e+06) << " Mb)"<< std::endl;
280  for(int i_data=0; i_data<dmArea->getLength(); i_data++) {
281  TBenchmark mb;
282  mb.Start("minuitperf");
283  m_iBinGlob = dmArea->getOffset() + i_data;
284  m_minimSubSample.clear();
285  for (std::unique_ptr<MinimSample>& event : m_minimSample) {
286  if(event->ibin == m_iBinGlob) {
287  m_minimSubSample.push_back(event.get());
288  if(m_minimSubSample.size() > 100000) break;
289  }
290  }
291 
292  std::vector<int > indexes;
294  std::cout << "==============================================================================" << std::endl;
295  std::cout << "run " << i_data
296  << " out of " << dmArea->getLength()
297  << " m_iBinGlob:" << m_iBinGlob
298  << " frac:" << indexes[CaloLocalHadCoeffHelper::DIM_EMFRAC]
299  << " side:" << indexes[CaloLocalHadCoeffHelper::DIM_SIDE]
300  << " eta:" << indexes[CaloLocalHadCoeffHelper::DIM_ETA]
301  << " phi:" << indexes[CaloLocalHadCoeffHelper::DIM_PHI]
302  << " ener:" << indexes[CaloLocalHadCoeffHelper::DIM_ENER]
303  << " lambda:" << indexes[CaloLocalHadCoeffHelper::DIM_LAMBDA]
304  << " size_of_subset:" << m_sample_size[i_data]
305  << std::endl;
306 
307  // name of parameters to be minimized
308  m_validNames.clear();
309  if(indexes[CaloLocalHadCoeffHelper::DIM_EMFRAC] == 0) {
310  // list of samplings to minimise for charged pions
311  m_validNames.emplace_back("EME2");
312  m_validNames.emplace_back("EME3");
313  m_validNames.emplace_back("HEC0");
314  m_validNames.emplace_back("HEC1");
315  m_validNames.emplace_back("FCAL0");
316  m_validNames.emplace_back("FCAL1");
317  m_validNames.emplace_back("CONST");
318  }else{
319  // list of samplings to minimise for neutral pions
320  m_validNames.emplace_back("EME2");
321  m_validNames.emplace_back("EME3");
322  m_validNames.emplace_back("HEC0");
323  m_validNames.emplace_back("FCAL0");
324  m_validNames.emplace_back("CONST");
325  }
326 
327  // setting up parameters which we are going to minimize
328  for (MinimPar& par : m_minimPars) {
329  bool fixIt = true;
330  for (const std::string& name : m_validNames) {
331  if(name == par.name) {
332  fixIt = false;
333  break;
334  }
335  }
336  par.fixIt = fixIt;
337  }
338 
339  for(unsigned int i_par=0; i_par<m_minimPars.size(); i_par++){
340  m_minimPars[i_par].value = 1.0;
341  m_minimPars[i_par].error = 0.0;
342  }
343 
344  // skip minimization if size of minimization sample is too small (no clusters falling in given iBinGlob
345  if(m_minimSubSample.size() > 80) {
346  // preparing for minimization
347  TVirtualFitter::SetDefaultFitter("Minuit");
348  TVirtualFitter * minuit = TVirtualFitter::Fitter(nullptr, m_minimPars.size());
349  for(unsigned int i_par=0; i_par<m_minimPars.size(); i_par++){
350  MinimPar *par = &m_minimPars[i_par];
351  minuit->SetParameter(i_par,par->name.c_str(), par->initVal, par->initErr, par->lowerLim, par->upperLim);
352  if( par->fixIt ) minuit->FixParameter(i_par);
353  }
354  m_nstep_fcn = 0;
355  minuit->SetFCN(CaloHadDMCoeffMinim::fcnWrapper);
356  double arglist[100];
357  arglist[0] = 0;
358  // set print level
359  minuit->ExecuteCommand("SET PRINT",arglist,2);
360  // minimize
361  arglist[0] = 2000; // number of function calls
362  arglist[1] = 0.001; // tolerance
363  // It is where minimization begins
364  minuit->ExecuteCommand("MIGRAD",arglist,2);
365 
366  // Saving data
367  std::cout << "Minuit results:" << std::endl;
368  for(unsigned int i_par=0; i_par<m_minimPars.size(); i_par++){
369  m_minimPars[i_par].value = minuit->GetParameter(i_par);
370  m_minimPars[i_par].error = minuit->GetParError(i_par);
371  std::cout << " i_par:" << i_par << " '" << m_minimPars[i_par].name << "' val:" << minuit->GetParameter(i_par) << " err:" << minuit->GetParError(i_par) << std::endl;
372  }
373  delete minuit;
374  } // if minim sample is big enough
375  // saving minimisation data
377  mb.Stop("minuitperf");
378  std::cout << "CPU: " << mb.GetCpuTime("minuitperf") << std::endl;
379  } // loop over i_data
380 
381 
382  /* *********************************************
383  Making set with of new coefficients
384  ********************************************* */
385  std::cout << "CaloHadDMCoeffMinim::process() -> Info. Making output coefficients set " << std::endl;
386  CaloLocalHadCoeff *newHadDMCoeff = new CaloLocalHadCoeff(*m_HadDMCoeff);
387  for (std::pair<const int, std::vector<MinimPar > >& p : m_minimResults) {
388  int iBin = p.first;
389 
390  m_minimPars = p.second;
392  pars.resize(m_minimPars.size(),0.0);
393  boost::io::ios_base_all_saver coutsave (std::cout);
394  std::cout << std::fixed << std::setprecision(3) << iBin << " ";
395  for(unsigned int i_par = 0; i_par<m_minimPars.size(); i_par++){
396  pars[i_par] = m_minimPars[i_par].value;
397  if(m_minimPars[i_par].fixIt == 1) continue;
398  std::cout << std::fixed << std::setprecision(3) << "(" << m_minimPars[i_par].name << " " << m_minimPars[i_par].value << " " << m_minimPars[i_par].error << ") ";
399  }
400  std::cout << std::endl;
401 
402  if(m_isTestbeam) {
403  std::vector<int > indexes;
404  m_HadDMCoeff->bin2indexes(iBin, indexes);
405  if(indexes[CaloLocalHadCoeffHelper::DIM_EMFRAC]==1) {
407  float eta = dimEta->getXmin() + dimEta->getDx()*(indexes[CaloLocalHadCoeffHelper::DIM_ETA]+0.5);
408  if( (fabs(eta)>2.9 && fabs(eta)<3.15)) {
409  //pars[CaloSampling::EME2] *= 0.96;
410  //pars[CaloSampling::EME2] *= 0.97;
411  pars[CaloSampling::EME2] *= 0.98;
412  }
413  if( fabs(eta) > 3.25) {
414  //pars[CaloSampling::FCAL0] *= 0.93;
415  //pars[CaloSampling::FCAL0] *= 0.94;
416  pars[CaloSampling::FCAL0] *= 0.95;
417  }
418  }
419  } // m_isTestbeam
420 
421  newHadDMCoeff->setCoeff(iBin, pars);
422  }
423 
424  return newHadDMCoeff;
425 }
426 
427 
428 
429 /* ****************************************************************************
430 Making nice postscript report
431 **************************************************************************** */
432 void CaloHadDMCoeffMinim::make_report(std::string &sreport)
433 {
434  std::cout << "CaloHadDMCoeffMinim::make_report() -> Info. Making report..." << std::endl;
435  gStyle->SetCanvasColor(10);
436  gStyle->SetCanvasBorderMode(0);
437  gStyle->SetPadColor(10);
438  gStyle->SetPadBorderMode(0);
439  gStyle->SetPalette(1);
440  gStyle->SetTitleBorderSize(1);
441  gStyle->SetTitleFillColor(10);
442  int cc_xx = 768, cc_yy = 1024;
443  char str[1024];
444  char cname[256];
445  gROOT->SetBatch(kTRUE);
446  gErrorIgnoreLevel=3; // root global variables to supress text output in ->Print() methods
447  std::string sfname = sreport;
448  TCanvas *ctmp = new TCanvas("ctmp","ctmp", cc_xx, cc_yy);
449  sfname += "[";
450  ctmp->Print(sfname.c_str());
451  sfname = sreport;
452  // ---------------------
453  int area_indx;
454  const CaloLocalHadCoeff::LocalHadArea *dmArea = m_HadDMHelper->getAreaFromName(m_HadDMCoeff, "ENG_CALIB_DEAD_FCAL", area_indx);
455  TLatex *tex = new TLatex(); tex->SetNDC();
456 
463 
464  for(int i_frac=0; i_frac<dimFrac->getNbins(); i_frac++){
465  for(int i_ener=0; i_ener<dimEner->getNbins(); i_ener++){
466  for(int i_lambda=0; i_lambda<dimLambda->getNbins(); i_lambda++){
467  for(int i_side=0; i_side<dimSide->getNbins(); i_side++){
468  for(int i_phi=0; i_phi<dimPhi->getNbins(); i_phi++){
469  sprintf(cname,"c1_dmfcal_minuit_weights_frac%d_ener%d_lambda%d_phi%d_side%d",i_frac, i_ener, i_lambda, i_phi, i_side);
470  TCanvas *c1_weights = new TCanvas(cname, cname, cc_xx, cc_yy);
471  c1_weights->cd();
472  TPad *pad1=nullptr, *pad2=nullptr;
473  float y_edge = 0.85;
474  pad1 = new TPad("p1ps","p1ps",0.0, y_edge, 1.0, 1.0); pad1->Draw();
475  pad2 = new TPad("p2ps","p2ps",0.0, 0.0, 1.0, y_edge); pad2->Draw();
476  // top pad
477  pad1->cd(); gPad->SetGrid(); gPad->SetLeftMargin(0.07); gPad->SetTopMargin(0.05); gPad->SetRightMargin(0.05); gPad->SetBottomMargin(0.08);
478  sprintf(str,"frac:%d ener:%d lambda:%d phi:%d side:%d",i_frac, i_ener, i_lambda, i_phi, i_side);
479  tex->SetTextColor(1); tex->SetTextSize(0.20); tex->DrawLatex(0.1,0.4,str);
480  pad2->Divide(3,3);
481  int i_canvas = 0;
482  // lets draw sample size
483  pad2->cd(i_canvas+1);
484  TGraph *gr = new TGraph(dimEta->getNbins());
485  float smpsize=0.0;
486  for(int i_eta=0; i_eta<dimEta->getNbins(); i_eta++){
487  std::vector<int > v_indx;
488  v_indx.resize(CaloLocalHadCoeffHelper::DIM_UNKNOWN, 0);
489  v_indx[CaloLocalHadCoeffHelper::DIM_EMFRAC] = i_frac;
490  v_indx[CaloLocalHadCoeffHelper::DIM_SIDE] = i_side;
491  v_indx[CaloLocalHadCoeffHelper::DIM_ETA] = i_eta;
492  v_indx[CaloLocalHadCoeffHelper::DIM_PHI] = i_phi;
493  v_indx[CaloLocalHadCoeffHelper::DIM_ENER] = i_ener;
494  v_indx[CaloLocalHadCoeffHelper::DIM_LAMBDA] = i_lambda;
495  int iBin = m_HadDMCoeff->getBin(area_indx, v_indx);
496  float xx = dimEta->getXmin() + dimEta->getDx()*i_eta;
497  float w = (float)m_sample_size[iBin-dmArea->getOffset()];
498  smpsize += w;
499  gr->SetPoint(i_eta, xx, w);
500  }
501  char str[256];
502  sprintf(str,"Sample size %d",int(smpsize));
503  gr->SetTitle(str);
504  gr->Draw("apl");
505  i_canvas++;
506  for(unsigned int i_par=0; i_par<m_minimPars.size(); i_par++){
507  std::vector<float> vx;
508  std::vector<float> vy;
509  std::vector<float> vye;
510  for(int i_eta=0; i_eta<dimEta->getNbins(); i_eta++){
511  std::vector<int > v_indx;
512  v_indx.resize(CaloLocalHadCoeffHelper::DIM_UNKNOWN, 0);
513  v_indx[CaloLocalHadCoeffHelper::DIM_EMFRAC] = i_frac;
514  v_indx[CaloLocalHadCoeffHelper::DIM_SIDE] = i_side;
515  v_indx[CaloLocalHadCoeffHelper::DIM_ETA] = i_eta;
516  v_indx[CaloLocalHadCoeffHelper::DIM_PHI] = i_phi;
517  v_indx[CaloLocalHadCoeffHelper::DIM_ENER] = i_ener;
518  v_indx[CaloLocalHadCoeffHelper::DIM_LAMBDA] = i_lambda;
519  int iBin = m_HadDMCoeff->getBin(area_indx, v_indx);
520  if(!m_minimResults[iBin][i_par].fixIt){
521  vx.push_back(dimEta->getXmin() + dimEta->getDx()*i_eta);
522  vy.push_back(m_minimResults[iBin][i_par].value);
523  vye.push_back(m_minimResults[iBin][i_par].error);
524  }
525  } // i_eta
526  if(!vx.empty()) {
527  TGraphErrors *gr = new TGraphErrors(dimEta->getNbins());
528  for(unsigned int i_p=0; i_p<vx.size(); i_p++){
529  gr->SetPoint(i_p, vx[i_p], vy[i_p]);
530  gr->SetPointError(i_p, 0.0, vye[i_p]);
531  }
532  pad2->cd(i_canvas+1);
533  gPad->SetGrid();
534  gr->SetMinimum(0.0);
535  gr->SetLineColor(4);
536  gr->SetTitle(m_minimPars[i_par].name.c_str());
537  gr->Draw("apl");
538  i_canvas++;
539  }
540  } // i_weight
541  c1_weights->Print(sfname.c_str());
542  } // i_phi
543  } // i_side
544  } // i_lambda
545  } // i_ener
546  } // i_frac
547 
548  sfname = sreport;
549  sfname += "]";
550  ctmp->Print(sfname.c_str());
551 }
552 
553 
554 
555 /* ****************************************************************************
556 
557 **************************************************************************** */
558 void CaloHadDMCoeffMinim::fcn(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
559 {
560  if(gin && iflag){
561  // to avoid warnings during compilation
562  }
563  double hi2 = 0.0;
564  int nsel = 0;
565  double sum_edm_rec = 0.0;
566  double sum_edm_true = 0.0;
568  double edm_rec = 0.0;
569  double edm_true = event->edmtrue;
570  for(int i_smp=0; i_smp<CaloSampling::Unknown; i_smp++){
571  edm_rec += (par[i_smp] - 1.0) * (double)(event->clsm_smp_energy_unw[i_smp]);
572  }
573  edm_rec += par[CaloSampling::Unknown];
574 
575 // if(edm_rec < 0.0) edm_rec = 0.0;
576 // if(edm_true < 0.0) edm_true = 0.0;
577  edm_rec = edm_rec/GeV;
578  edm_true = edm_true/GeV;
579 
580  sum_edm_rec += edm_rec/( event->sigma2 );
581  sum_edm_true += edm_true/( event->sigma2 );
582  hi2 += (event->weight*(edm_rec - edm_true)*(edm_rec - edm_true)/( event->sigma2 ) );
583  nsel++;
584  }
585 
586  if(nsel == 0) {
587  std::cout << "nsel == 0 ! PANIC!" << std::endl;
588  hi2=99999999999.;
589  }else{
590  if(m_nstep_fcn%20 == 0) {
591  std::cout << ">>> step:" << m_nstep_fcn
592  << " size:(" << m_minimSample.size() << "," << nsel
593  << ") sum_edm_rec:" << sum_edm_rec/float(nsel)
594  << " sum_edm_true:" << sum_edm_true/float(nsel)
595  << " hi2:" << hi2
596  << " npar:" << npar
597  << std::endl;
598  for(unsigned int i_par=0; i_par<m_minimPars.size(); i_par++){
599  if( !m_minimPars[i_par].fixIt ) std::cout << "( " << i_par << " " << m_minimPars[i_par].name << " " << par[i_par] << ")";
600  }
601  std::cout << std::endl;
602  }
603  }
604  f = hi2;
605  m_nstep_fcn++;
606 }
607 
608 
CaloHadDMCoeffMinim::m_iBinGlob
int m_iBinGlob
Definition: CaloHadDMCoeffMinim.h:90
GetLCDefs::CONST
@ CONST
Definition: GetLCDefs.h:21
CaloHadDMCoeffData::m_mc_ener
Double_t m_mc_ener
Definition: CaloHadDMCoeffData.h:39
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
make_hlt_rep.pars
pars
Definition: make_hlt_rep.py:90
beamspotman.r
def r
Definition: beamspotman.py:676
GetLCDefs::Unknown
@ Unknown
Definition: GetLCDefs.h:21
CaloLocalHadCoeff::LocalHadDimension
Class defines binning for user dimension.
Definition: CaloLocalHadCoeff.h:47
CaloHadDMCoeffMinim.h
CaloLocalHadCoeffHelper::DIM_SIDE
@ DIM_SIDE
Definition: CaloLocalHadCoeffHelper.h:17
CaloLocalHadCoeff::LocalHadDimension::getNbins
int getNbins() const
return number of bins
Definition: CaloLocalHadCoeff.h:99
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
CaloHadDMCoeffMinim::m_isTestbeam
bool m_isTestbeam
Definition: CaloHadDMCoeffMinim.h:88
CaloHadDMCoeffData::m_cls_dmener
std::vector< std::vector< double > > * m_cls_dmener
Definition: CaloHadDMCoeffData.h:51
CaloHadDMCoeffMinim::m_engClusMin
double m_engClusMin
Definition: CaloHadDMCoeffMinim.h:96
CaloHadDMCoeffMinim::m_validNames
std::vector< std::string > m_validNames
Definition: CaloHadDMCoeffMinim.h:75
CaloHadDMCoeffMinim::m_area_index
int m_area_index
Definition: CaloHadDMCoeffMinim.h:98
CaloHadDMCoeffMinim::s_instance
static CaloHadDMCoeffMinim * s_instance
Definition: CaloHadDMCoeffMinim.h:83
CaloLocalHadDefs.h
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
m_data
std::vector< T > m_data
Definition: TrackTruthMatchingBaseAlg.cxx:660
CaloHadDMCoeffMinim::m_NormalizationTypeNumber
int m_NormalizationTypeNumber
Definition: CaloHadDMCoeffMinim.h:102
CaloLocalHadCoeffHelper::DIM_EMFRAC
@ DIM_EMFRAC
Definition: CaloLocalHadCoeffHelper.h:17
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
GetLCDefs.h
python.SystemOfUnits.MeV
int MeV
Definition: SystemOfUnits.py:154
CaloLocalHadCoeffHelper::DIM_ENER
@ DIM_ENER
Definition: CaloLocalHadCoeffHelper.h:17
CaloLocalHadCoeff::LocalHadArea::getOffset
int getOffset() const
return area offset
Definition: CaloLocalHadCoeff.h:175
CaloHadDMCoeffData::m_mc_pdg
Int_t m_mc_pdg
Definition: CaloHadDMCoeffData.h:38
athena.value
value
Definition: athena.py:124
gr
#define gr
CaloLocalHadCoeff::LocalHadArea::getLength
int getLength() const
return area length
Definition: CaloLocalHadCoeff.h:177
CaloLocalHadCoeff::getSizeAreaSet
int getSizeAreaSet() const
return number of areas defined for this data set
Definition: CaloLocalHadCoeff.h:248
CaloLocalHadCoeff::LocalHadDimension::getXmin
float getXmin() const
return minimum value for the first bin
Definition: CaloLocalHadCoeff.h:102
CaloHadDMCoeffData::m_narea
Int_t m_narea
Definition: CaloHadDMCoeffData.h:49
CaloHadDMCoeffData::m_cls_phi
std::vector< double > * m_cls_phi
Definition: CaloHadDMCoeffData.h:46
GetLCSinglePionsPerf::angle_mollier_factor
static double angle_mollier_factor(double x)
Definition: GetLCSinglePionsPerf.cxx:1288
CaloLocalHadCoeff::LocalHadArea::getDimension
const CaloLocalHadCoeff::LocalHadDimension * getDimension(int n_dim) const
to get dimension
Definition: CaloLocalHadCoeff.h:192
CaloHadDMCoeffData::m_cls_eta
std::vector< double > * m_cls_eta
Definition: CaloHadDMCoeffData.h:45
CaloHadDMCoeffMinim::m_HadDMCoeff
CaloLocalHadCoeff * m_HadDMCoeff
Definition: CaloHadDMCoeffMinim.h:86
CaloLocalHadCoeff::LocalHadCoeff
std::vector< float > LocalHadCoeff
Correction parameters for one general bin.
Definition: CaloLocalHadCoeff.h:220
GetLCDefs::NCLUS
@ NCLUS
Definition: GetLCDefs.h:21
CaloLocalHadCoeffHelper
Definition: CaloLocalHadCoeffHelper.h:14
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
CaloHadDMCoeffData::m_mc_eta
Double_t m_mc_eta
Definition: CaloHadDMCoeffData.h:40
CaloHadDMCoeffMinim::m_data
CaloHadDMCoeffData * m_data
Definition: CaloHadDMCoeffMinim.h:84
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ev
int ev
Definition: globals.cxx:25
CaloHadDMCoeffMinim::m_minimPars
std::vector< MinimPar > m_minimPars
Definition: CaloHadDMCoeffMinim.h:91
CaloLocalHadCoeffHelper::DIM_LAMBDA
@ DIM_LAMBDA
Definition: CaloLocalHadCoeffHelper.h:17
CaloHadDMCoeffMinim::make_report
void make_report(std::string &sfname)
Definition: CaloHadDMCoeffMinim.cxx:432
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
CaloHadDMCoeffData::m_mc_phi
Double_t m_mc_phi
Definition: CaloHadDMCoeffData.h:41
CaloHadDMCoeffData::m_cls_ener_unw
std::vector< double > * m_cls_ener_unw
Definition: CaloHadDMCoeffData.h:43
CaloHadDMCoeffMinim::m_nstep_fcn
int m_nstep_fcn
Definition: CaloHadDMCoeffMinim.h:89
CaloLocalHadCoeff
Hold binned correction data for local hadronic calibration procedure.
Definition: CaloLocalHadCoeff.h:41
CaloLocalHadCoeffHelper.h
CaloHadDMCoeffData::m_cls_smpener_unw
std::vector< std::vector< double > > * m_cls_smpener_unw
Definition: CaloHadDMCoeffData.h:48
CaloLocalHadCoeffHelper::DIM_PHI
@ DIM_PHI
Definition: CaloLocalHadCoeffHelper.h:17
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
hist_file_dump.f
f
Definition: hist_file_dump.py:135
CaloLocalHadCoeff::LocalHadDimension::getDx
float getDx() const
return size of bin
Definition: CaloLocalHadCoeff.h:108
CaloHadDMCoeffMinim::m_NormalizationType
std::string m_NormalizationType
Definition: CaloHadDMCoeffMinim.h:101
CaloHadDMCoeffData::GetEntries
virtual Int_t GetEntries()
Definition: CaloHadDMCoeffData.cxx:124
CaloHadDMCoeffMinim::MinimPar
Definition: CaloHadDMCoeffMinim.h:35
MC::isSingleParticle
bool isSingleParticle(const T &p)
Identify a particlegun particle.
Definition: HepMCHelpers.h:74
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
CaloHadDMCoeffMinim::CaloHadDMCoeffMinim
CaloHadDMCoeffMinim()
Definition: CaloHadDMCoeffMinim.cxx:63
calibdata.exit
exit
Definition: calibdata.py:236
CaloLocalHadCoeffHelper::DIM_UNKNOWN
@ DIM_UNKNOWN
Definition: CaloLocalHadCoeffHelper.h:17
CaloLocalHadCoeff::LocalHadArea::getNpars
int getNpars() const
return number of parameters
Definition: CaloLocalHadCoeff.h:173
CaloLocalHadCoeff::setCoeff
void setCoeff(const int iBin, const LocalHadCoeff &theCoeff)
set new data
Definition: CaloLocalHadCoeff.cxx:243
CaloLocalHadCoeffHelper::DIM_ETA
@ DIM_ETA
Definition: CaloLocalHadCoeffHelper.h:17
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
createCoolChannelIdFile.par
par
Definition: createCoolChannelIdFile.py:29
CaloHadDMCoeffData::m_cls_engcalib
std::vector< double > * m_cls_engcalib
Definition: CaloHadDMCoeffData.h:53
CaloLocalHadCoeff::bin2indexes
int bin2indexes(const int iBin, std::vector< int > &v_dim_indx) const
expand general bin into vector of bins for defined dimensions
Definition: CaloLocalHadCoeff.cxx:301
CaloHadDMCoeffMinim::m_HadDMHelper
std::unique_ptr< CaloLocalHadCoeffHelper > m_HadDMHelper
Definition: CaloHadDMCoeffMinim.h:85
CaloHadDMCoeffFit.h
CaloHadDMCoeffMinim::m_minimResults
std::map< int, std::vector< MinimPar > > m_minimResults
Definition: CaloHadDMCoeffMinim.h:92
Units.h
Wrapper to avoid constant divisions when using units.
CaloHadDMCoeffData::PackClusterVars
int PackClusterVars(int iClus, std::vector< float > &vars)
Definition: CaloHadDMCoeffData.cxx:298
gErrorIgnoreLevel
int gErrorIgnoreLevel
CaloHadDMCoeffMinim::fcn
void fcn(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
Definition: CaloHadDMCoeffMinim.cxx:558
CaloLocalHadCoeff.h
CaloHadDMCoeffMinim::m_sample_size
std::vector< int > m_sample_size
Definition: CaloHadDMCoeffMinim.h:95
CaloHadDMCoeffMinim::m_minimSample
std::vector< std::unique_ptr< MinimSample > > m_minimSample
Definition: CaloHadDMCoeffMinim.h:93
TRT_PAI_physicsConstants::mb
const double mb
1mb to cm2
Definition: TRT_PAI_physicsConstants.h:15
CaloLocalHadCoeff::LocalHadArea::getTitle
const std::string & getTitle() const
return name
Definition: CaloLocalHadCoeff.h:183
GetLCSinglePionsPerf.h
GetLCDefs::LOG
@ LOG
Definition: GetLCDefs.h:21
GetLCDefs::LIN
@ LIN
Definition: GetLCDefs.h:21
CaloLocalHadCoeff::LocalHadArea
Definition of correction area.
Definition: CaloLocalHadCoeff.h:145
str
Definition: BTagTrackIpAccessor.cxx:11
CaloHadDMCoeffMinim
Definition: CaloHadDMCoeffMinim.h:31
CaloHadDMCoeffMinim::m_distance_cut
double m_distance_cut
Definition: CaloHadDMCoeffMinim.h:99
CaloHadDMCoeffMinim::fcnWrapper
static void fcnWrapper(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
Definition: CaloHadDMCoeffMinim.h:78
CaloLocalHadCoeff::getBin
int getBin(const int n_area, std::vector< float > &vars) const
calculate general bin from vector of input cluster variables
Definition: CaloLocalHadCoeff.cxx:273
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
CaloHadDMCoeffData::m_engClusSumCalib
Double_t m_engClusSumCalib
Definition: CaloHadDMCoeffData.h:52
CaloHadDMCoeffData.h
CaloHadDMCoeffData::GetEntry
virtual Int_t GetEntry(Long64_t entry)
Definition: CaloHadDMCoeffData.cxx:101
CaloCell_ID_FCS::FCAL0
@ FCAL0
Definition: FastCaloSim_CaloCell_ID.h:40
error
Definition: IImpactPoint3dEstimator.h:70
CaloHadDMCoeffData::fChain
TTree * fChain
Definition: CaloHadDMCoeffData.h:33
CaloHadDMCoeffMinim::MinimSample
Definition: CaloHadDMCoeffMinim.h:59
CaloHadDMCoeffMinim::m_minimSubSample
std::vector< MinimSample * > m_minimSubSample
Definition: CaloHadDMCoeffMinim.h:94
readCCLHist.float
float
Definition: readCCLHist.py:83
constants.EME2
int EME2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:56
CaloHadDMCoeffMinim::~CaloHadDMCoeffMinim
~CaloHadDMCoeffMinim()
Definition: CaloHadDMCoeffMinim.cxx:113
CaloHadDMCoeffData::m_ncls
Int_t m_ncls
current Tree number in a TChain
Definition: CaloHadDMCoeffData.h:37