From 46c0ca69ab4e896c181b3cf4344e71d79be67f19 Mon Sep 17 00:00:00 2001
From: James Beacham <j.beacham@cern.ch>
Date: Sat, 24 Nov 2018 19:11:48 +0000
Subject: [PATCH] Merge branch '21.0-FastCaloSim-dev' into '21.0'
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

21.0-FastCaloSim: Created class TFCSHistoLateralShapeParametrizationFCal (ATLASSIM-3927)

See merge request atlas/athena!16158

(cherry picked from commit 66eb48ab2c02b013a09909e8b9deb01621db6c13)

5c6d9b75 Created class TFCSHistoLateralShapeParametrizationFCal
7af2178d Changing inheratence: TFCSHistoLateralShapeParametrizationFCal inherits from…
67242fa5 Changing inheratence: TFCSHistoLateralShapeParametrizationFCal inherits from…
5a765fca Removing Print function and redundant includes
---
 .../python/iconfTool/utils/__init__.py        |  0
 .../ISF_FastCaloSimEvent/CMakeLists.txt       |  1 +
 .../ISF_FastCaloSimEvent/LinkDef.h            |  4 +-
 .../TFCSHistoLateralShapeParametrization.h    |  4 +-
 ...TFCSHistoLateralShapeParametrizationFCal.h | 29 +++++++
 .../TFCSHistoLateralShapeParametrization.cxx  |  5 +-
 ...CSHistoLateralShapeParametrizationFCal.cxx | 76 +++++++++++++++++++
 7 files changed, 114 insertions(+), 5 deletions(-)
 mode change 100644 => 100755 Control/AthenaConfiguration/python/iconfTool/utils/__init__.py
 create mode 100644 Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/ISF_FastCaloSimEvent/TFCSHistoLateralShapeParametrizationFCal.h
 create mode 100644 Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/src/TFCSHistoLateralShapeParametrizationFCal.cxx

diff --git a/Control/AthenaConfiguration/python/iconfTool/utils/__init__.py b/Control/AthenaConfiguration/python/iconfTool/utils/__init__.py
old mode 100644
new mode 100755
diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/CMakeLists.txt b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/CMakeLists.txt
index e7f07e8b203..413eb338342 100644
--- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/CMakeLists.txt
+++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/CMakeLists.txt
@@ -61,6 +61,7 @@ atlas_add_root_dictionary( ISF_FastCaloSimEvent _dictSource
                            ISF_FastCaloSimEvent/TFCSLateralShapeParametrizationHitChain.h
                            ISF_FastCaloSimEvent/TFCSCenterPositionCalculation.h
                            ISF_FastCaloSimEvent/TFCSHistoLateralShapeParametrization.h
+                           ISF_FastCaloSimEvent/TFCSHistoLateralShapeParametrizationFCal.h
                            ISF_FastCaloSimEvent/TFCSLateralShapeParametrizationHitNumberFromE.h
                            ISF_FastCaloSimEvent/TFCSHitCellMapping.h
                            ISF_FastCaloSimEvent/TFCSHitCellMappingFCal.h
diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/ISF_FastCaloSimEvent/LinkDef.h b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/ISF_FastCaloSimEvent/LinkDef.h
index 4979ed94f1f..ffce63d8d40 100644
--- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/ISF_FastCaloSimEvent/LinkDef.h
+++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/ISF_FastCaloSimEvent/LinkDef.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 */
 
 #include "ISF_FastCaloSimEvent/DoubleArray.h"
@@ -41,6 +41,7 @@
 #include "ISF_FastCaloSimEvent/TFCSLateralShapeParametrizationHitChain.h"
 #include "ISF_FastCaloSimEvent/TFCSCenterPositionCalculation.h"
 #include "ISF_FastCaloSimEvent/TFCSHistoLateralShapeParametrization.h"
+#include "ISF_FastCaloSimEvent/TFCSHistoLateralShapeParametrizationFCal.h"
 #include "ISF_FastCaloSimEvent/TFCSLateralShapeParametrizationHitNumberFromE.h"
 #include "ISF_FastCaloSimEvent/TFCSHitCellMapping.h"
 #include "ISF_FastCaloSimEvent/TFCSHitCellMappingFCal.h"
@@ -148,6 +149,7 @@
 #pragma link C++ class TFCSLateralShapeParametrizationHitChain+;
 #pragma link C++ class TFCSCenterPositionCalculation+;
 #pragma link C++ class TFCSHistoLateralShapeParametrization+;
+#pragma link C++ class TFCSHistoLateralShapeParametrizationFCal+;
 #pragma link C++ class TFCSLateralShapeParametrizationHitNumberFromE+;
 #pragma link C++ class TFCSHitCellMapping+;
 #pragma link C++ class TFCSHitCellMappingFCal+;
diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/ISF_FastCaloSimEvent/TFCSHistoLateralShapeParametrization.h b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/ISF_FastCaloSimEvent/TFCSHistoLateralShapeParametrization.h
index 6066bad3d8f..1f6f406bef0 100644
--- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/ISF_FastCaloSimEvent/TFCSHistoLateralShapeParametrization.h
+++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/ISF_FastCaloSimEvent/TFCSHistoLateralShapeParametrization.h
@@ -45,11 +45,13 @@ public:
   const TFCS2DFunctionHistogram& histogram() const {return m_hist;};
   
   void Print(Option_t *option = "") const override;
-private:
+protected:
   /// Histogram to be used for the shape simulation
   TFCS2DFunctionHistogram m_hist;
   float m_nhits;
 
+private:
+
   ClassDefOverride(TFCSHistoLateralShapeParametrization,1)  //TFCSHistoLateralShapeParametrization
 };
 
diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/ISF_FastCaloSimEvent/TFCSHistoLateralShapeParametrizationFCal.h b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/ISF_FastCaloSimEvent/TFCSHistoLateralShapeParametrizationFCal.h
new file mode 100644
index 00000000000..46e934939c9
--- /dev/null
+++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/ISF_FastCaloSimEvent/TFCSHistoLateralShapeParametrizationFCal.h
@@ -0,0 +1,29 @@
+/*
+  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+*/
+
+#ifndef TFCSHistoLateralShapeParametrizationFCal_h
+#define TFCSHistoLateralShapeParametrizationFCal_h
+
+#include "ISF_FastCaloSimEvent/TFCSHistoLateralShapeParametrization.h"
+#include "ISF_FastCaloSimEvent/TFCS2DFunctionHistogram.h"
+
+class TH2;
+
+class TFCSHistoLateralShapeParametrizationFCal:public TFCSHistoLateralShapeParametrization {
+public:
+  TFCSHistoLateralShapeParametrizationFCal(const char* name=nullptr, const char* title=nullptr);
+  ~TFCSHistoLateralShapeParametrizationFCal();
+
+  virtual FCSReturnCode simulate_hit(Hit& hit,TFCSSimulationState& simulstate,const TFCSTruthState* truth, const TFCSExtrapolationState* extrapol) override;
+  
+private:
+ 
+  ClassDefOverride(TFCSHistoLateralShapeParametrizationFCal,1)  //TFCSHistoLateralShapeParametrizationFCal
+};
+
+#if defined(__ROOTCLING__) && defined(__FastCaloSimStandAlone__)
+#pragma link C++ class TFCSHistoLateralShapeParametrizationFCal+;
+#endif
+
+#endif
diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/src/TFCSHistoLateralShapeParametrization.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/src/TFCSHistoLateralShapeParametrization.cxx
index 733d4067ef6..4a5db9df5f0 100644
--- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/src/TFCSHistoLateralShapeParametrization.cxx
+++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/src/TFCSHistoLateralShapeParametrization.cxx
@@ -93,10 +93,9 @@ FCSReturnCode TFCSHistoLateralShapeParametrization::simulate_hit(Hit &hit, TFCSS
   const float delta_eta = delta_eta_mm / eta_jakobi / dist000;
   const float delta_phi = delta_phi_mm / center_r;
 
-  hit.eta() = center_eta + delta_eta;
-  hit.phi() = center_phi + delta_phi;
+  hit.setEtaPhiZE(center_eta + delta_eta,center_phi + delta_phi,center_z, hit.E());
 
-  ATH_MSG_DEBUG("HIT: E="<<hit.E()<<" cs="<<cs<<" eta="<<hit.eta()<<" phi="<<hit.phi()<<" r="<<r<<" alpha="<<alpha);
+  ATH_MSG_DEBUG("HIT: E="<<hit.E()<<" cs="<<cs<<" eta="<<hit.eta()<<" phi="<<hit.phi()<< " z="<<hit.z()<<" r="<<r<<" alpha="<<alpha);
 
   return FCSSuccess;
 }
diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/src/TFCSHistoLateralShapeParametrizationFCal.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/src/TFCSHistoLateralShapeParametrizationFCal.cxx
new file mode 100644
index 00000000000..43037706972
--- /dev/null
+++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent/src/TFCSHistoLateralShapeParametrizationFCal.cxx
@@ -0,0 +1,76 @@
+/*
+  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+*/
+
+#include "CLHEP/Random/RandFlat.h"
+#include "CLHEP/Random/RandPoisson.h"
+
+#include "ISF_FastCaloSimEvent/TFCSHistoLateralShapeParametrizationFCal.h"
+#include "ISF_FastCaloSimEvent/TFCSSimulationState.h"
+#include "ISF_FastCaloSimEvent/TFCSExtrapolationState.h"
+
+#include "TMath.h"
+
+
+//=============================================
+//======= TFCSHistoLateralShapeParametrizationFCal =========
+//=============================================
+
+TFCSHistoLateralShapeParametrizationFCal::TFCSHistoLateralShapeParametrizationFCal(const char* name, const char* title) :
+  TFCSHistoLateralShapeParametrization(name,title)
+{
+}
+
+TFCSHistoLateralShapeParametrizationFCal::~TFCSHistoLateralShapeParametrizationFCal()
+{
+}
+
+FCSReturnCode TFCSHistoLateralShapeParametrizationFCal::simulate_hit(Hit &hit, TFCSSimulationState &simulstate, const TFCSTruthState* /*truth*/, const TFCSExtrapolationState* extrapol)
+{
+  if (!simulstate.randomEngine()) {
+    return FCSFatal;
+  }
+
+  const int cs=calosample();
+  const double center_phi=0.5*( extrapol->phi(cs, CaloSubPos::SUBPOS_ENT) + extrapol->phi(cs, CaloSubPos::SUBPOS_EXT) );
+  const double center_r=0.5*( extrapol->r(cs, CaloSubPos::SUBPOS_ENT) + extrapol->r(cs, CaloSubPos::SUBPOS_EXT) );
+  const double center_z=0.5*( extrapol->z(cs, CaloSubPos::SUBPOS_ENT) + extrapol->z(cs, CaloSubPos::SUBPOS_EXT) );
+  
+  const double center_x=center_r*cos(center_phi);
+  const double center_y=center_r*sin(center_phi);
+
+  float alpha, r, rnd1, rnd2;
+  rnd1 = CLHEP::RandFlat::shoot(simulstate.randomEngine());
+  rnd2 = CLHEP::RandFlat::shoot(simulstate.randomEngine());
+  if(is_phi_symmetric()) {
+    if(rnd2>=0.5) { //Fill negative phi half of shape
+      rnd2-=0.5;
+      rnd2*=2;
+      m_hist.rnd_to_fct(alpha,r,rnd1,rnd2);
+      alpha=-alpha;
+    } else { //Fill positive phi half of shape
+      rnd2*=2;
+      m_hist.rnd_to_fct(alpha,r,rnd1,rnd2);
+    }
+  } else {
+    m_hist.rnd_to_fct(alpha,r,rnd1,rnd2);
+  }
+  if(TMath::IsNaN(alpha) || TMath::IsNaN(r)) {
+    ATH_MSG_ERROR("  Histogram: "<<m_hist.get_HistoBordersx().size()-1<<"*"<<m_hist.get_HistoBordersy().size()-1<<" bins, #hits="<<m_nhits<<" alpha="<<alpha<<" r="<<r<<" rnd1="<<rnd1<<" rnd2="<<rnd2);
+    alpha=0;
+    r=0.001;
+
+    ATH_MSG_ERROR("  This error could probably be retried");
+    return FCSFatal;
+  }
+  
+  const float delta_x = r * cos(alpha);
+  const float delta_y = r * sin(alpha);
+
+  hit.setXYZE(center_x+delta_x,center_y+delta_y,center_z,hit.E());
+
+  ATH_MSG_DEBUG("HIT: E="<<hit.E()<<" cs="<<cs<<" x="<<hit.x()<<" y="<<hit.y()<<" z="<<hit.z()<<" r=" << r <<" alpha="<<alpha);
+
+  return FCSSuccess;
+}
+
-- 
GitLab