From 6621a7c8f6538c935d3a3a4e202a087839f5f93c Mon Sep 17 00:00:00 2001 From: Vincent Pascuzzi <Vincent.Pascuzzi@cern.ch> Date: Wed, 7 Jun 2017 23:40:17 +0200 Subject: [PATCH] svnpull ISF_FastCaloSimParametrization-00-08-40; fix `CMakelists.txt` Rename `CaloGeometry`->`CaloGeoGeometry` required `CMakeLists.txt` update. --- .../CMakeLists.txt | 2 +- .../CaloGeoDetDescrElement.h | 249 ++ .../CaloGeoGeometry.h | 202 ++ .../CaloGeometry.h | 28 +- .../CaloGeometryFromFile.h | 4 +- .../ICaloGeometry.h | 12 +- .../IFastCaloSimCaloExtrapolation.h | 2 + .../Root/EnergyParametrizationValidation.cxx | 168 +- .../Root/TreeReader.cxx | 98 +- .../ISF_FastCaloSimParametrizationConfig.py | 44 +- .../ISF_FastCaloSimParametrizationConfigDb.py | 34 +- .../src/CaloGeoGeometry.cxx | 1220 +++++++ .../src/CaloGeometry.cxx | 113 +- .../src/CaloGeometryFromCaloDDM.cxx | 4 +- .../src/CaloGeometryFromFile.cxx | 494 +-- .../src/FastCaloSimCaloExtrapolation.cxx | 1135 ++++--- .../src/FastCaloSimCaloExtrapolation.h | 112 +- .../src/FastCaloSimGeometryHelper.cxx | 40 +- .../src/ISF_HitAnalysis.cxx | 2851 +++++++++-------- .../tools/CaloHitAna.C | 1347 ++++---- .../tools/CaloHitAna.h | 77 +- .../tools/Makefile | 272 +- .../tools/make_caloHitAna.sh | 4 + 23 files changed, 5194 insertions(+), 3318 deletions(-) create mode 100644 Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/ISF_FastCaloSimParametrization/CaloGeoDetDescrElement.h create mode 100644 Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/ISF_FastCaloSimParametrization/CaloGeoGeometry.h create mode 100644 Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/CaloGeoGeometry.cxx create mode 100644 Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/make_caloHitAna.sh diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/CMakeLists.txt b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/CMakeLists.txt index fcacbb48b48c..0ff7df8d978c 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/CMakeLists.txt +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/CMakeLists.txt @@ -63,7 +63,7 @@ atlas_add_root_dictionary( ISF_FastCaloSimParametrizationLib EXTERNAL_PACKAGES ROOT HepPDT XercesC CLHEP HepMC Geant4 ) atlas_add_library( ISF_FastCaloSimParametrizationLib - Root/*.cxx src/CaloGeometry.cxx src/CaloGeometryFromFile.cxx + Root/*.cxx src/CaloGeoGeometry.cxx src/CaloGeometryFromFile.cxx ${ISF_FastCaloSimParametrizationLibDictSource} PUBLIC_HEADERS ISF_FastCaloSimParametrization INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} ${HEPPDT_INCLUDE_DIRS} ${HEPMC_INCLUDE_DIRS} diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/ISF_FastCaloSimParametrization/CaloGeoDetDescrElement.h b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/ISF_FastCaloSimParametrization/CaloGeoDetDescrElement.h new file mode 100644 index 000000000000..2eca531869fd --- /dev/null +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/ISF_FastCaloSimParametrization/CaloGeoDetDescrElement.h @@ -0,0 +1,249 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef CALOGEODETECTORELEMENT_H +#define CALOGEODETECTORELEMENT_H + +class CaloGeometry; + +#include "Identifier/Identifier.h" +#include <iostream> +#include <iomanip> +#include <cmath> + +class CaloGeoDetDescrElement +{ + friend class CaloGeometry; + public: + CaloGeoDetDescrElement() { + m_identify = 0; + m_hash_id = 0; + m_calosample = 0; + m_eta = 0; + m_phi = 0; + m_deta = 0; + m_dphi = 0; + m_r = 0; + m_eta_raw = 0; + m_phi_raw = 0; + m_r_raw = 0; + m_dr = 0; + m_x = 0; + m_y = 0; + m_z = 0; + m_x_raw = 0; + m_y_raw = 0; + m_z_raw = 0; + m_dx = 0; + m_dy = 0; + m_dz = 0; + }; + + /** @brief virtual destructor + */ + virtual ~CaloGeoDetDescrElement() {}; + + /** @brief cell eta + */ + float eta() const; + /** @brief cell phi + */ + float phi() const; + /** @brief cell r + */ + float r() const; + /** @brief cell eta_raw + */ + float eta_raw() const; + /** @brief cell phi_raw + */ + float phi_raw() const; + /** @brief cell r_raw + */ + float r_raw() const; + /** @brief cell dphi + */ + float dphi() const; + /** @brief cell deta + */ + float deta() const; + /** @brief cell dr + */ + float dr() const; + + /** @brief cell x + */ + float x() const; + /** @brief cell y + */ + float y() const; + /** @brief cell z + */ + float z() const; + /** @brief cell x_raw + */ + float x_raw() const; + /** @brief cell y_raw + */ + float y_raw() const; + /** @brief cell z_raw + */ + float z_raw() const; + /** @brief cell dx + */ + float dx() const; + /** @brief cell dy + */ + float dy() const; + /** @brief cell dz + */ + float dz() const; + + /** @brief cell identifier + */ + Identifier identify() const; + + unsigned long long calo_hash() const; + + int getSampling() const ; + + //ACH protected: + // + long long m_identify; + long long m_hash_id; + + int m_calosample; + + /** @brief cylindric coordinates : eta + */ + float m_eta; + /** @brief cylindric coordinates : phi + */ + float m_phi; + + /** @brief this one is cached for algorithm working in transverse Energy + */ + float m_sinTh; + /** @brief this one is cached for algorithm working in transverse Energy + */ + float m_cosTh; + + /** @brief cylindric coordinates : delta eta + */ + float m_deta; + /** @brief cylindric coordinates : delta phi + */ + float m_dphi; + + /** @brief cylindric coordinates : r + */ + + float m_volume; + + /** @brief cache to allow fast px py pz computation + */ + float m_sinPhi; + + /** @brief cache to allow fast px py pz computation + */ + float m_cosPhi; + + /** @brief cylindric coordinates : r + */ + float m_r; + /** @brief cylindric coordinates : eta_raw + */ + float m_eta_raw; + /** @brief cylindric coordinates : phi_raw + */ + float m_phi_raw; + /** @brief cylindric coordinates : r_raw + */ + float m_r_raw; + /** @brief cylindric coordinates : delta r + */ + float m_dr; + + /** @brief cartesian coordinates : X + */ + float m_x; + /** @brief cartesian coordinates : Y + */ + float m_y; + /** @brief cartesian coordinates : Z + */ + float m_z; + /** @brief cartesian coordinates : X raw + */ + float m_x_raw; + /** @brief cartesian coordinates : Y raw + */ + float m_y_raw; + /** @brief cartesian coordinates : Z raw + */ + float m_z_raw; + /** @brief cartesian coordinates : delta X + */ + float m_dx; + /** @brief cartesian coordinates : delta Y + */ + float m_dy; + /** @brief cartesian coordinates : delta Z + */ + float m_dz; + +}; + +inline Identifier CaloGeoDetDescrElement::identify() const +{ + Identifier id((unsigned long long) m_identify); + return id; +} + +inline unsigned long long CaloGeoDetDescrElement::calo_hash() const +{ + return m_hash_id; +} + +inline int CaloGeoDetDescrElement::getSampling() const +{ return m_calosample;} +inline float CaloGeoDetDescrElement::eta() const +{ return m_eta;} +inline float CaloGeoDetDescrElement::phi() const +{ return m_phi;} +inline float CaloGeoDetDescrElement::r() const +{ return m_r;} +inline float CaloGeoDetDescrElement::eta_raw() const +{ return m_eta_raw;} +inline float CaloGeoDetDescrElement::phi_raw() const +{ return m_phi_raw;} +inline float CaloGeoDetDescrElement::r_raw() const +{ return m_r_raw;} +inline float CaloGeoDetDescrElement::deta() const +{ return m_deta;} +inline float CaloGeoDetDescrElement::dphi() const +{ return m_dphi;} +inline float CaloGeoDetDescrElement::dr() const +{ return m_dr;} + +inline float CaloGeoDetDescrElement::x() const +{ return m_x;} +inline float CaloGeoDetDescrElement::y() const +{ return m_y;} +inline float CaloGeoDetDescrElement::z() const +{ return m_z;} +inline float CaloGeoDetDescrElement::x_raw() const +{ return m_x_raw;} +inline float CaloGeoDetDescrElement::y_raw() const +{ return m_y_raw;} +inline float CaloGeoDetDescrElement::z_raw() const +{ return m_z_raw;} +inline float CaloGeoDetDescrElement::dx() const +{ return m_dx;} +inline float CaloGeoDetDescrElement::dy() const +{ return m_dy;} +inline float CaloGeoDetDescrElement::dz() const +{ return m_dz;} + +#endif diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/ISF_FastCaloSimParametrization/CaloGeoGeometry.h b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/ISF_FastCaloSimParametrization/CaloGeoGeometry.h new file mode 100644 index 000000000000..59faabe14ed8 --- /dev/null +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/ISF_FastCaloSimParametrization/CaloGeoGeometry.h @@ -0,0 +1,202 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef CaloGeoGeometry_h +#define CaloGeoGeometry_h + +#include <TMath.h> + +#include <vector> +#include <map> +#include <iostream> + +#include "ISF_FastCaloSimEvent/FastCaloSim_CaloCell_ID.h" +#include "Identifier/Identifier.h" +//#include "ISF_FastCaloSimParametrization/ICaloGeometry.h" +#include "ISF_FastCaloSimParametrization/MeanAndRMS.h" +#include "ISF_FastCaloSimParametrization/FSmap.h" +#include "ISF_FastCaloSimParametrization/FCAL_ChannelMap.h" + +class CaloGeoDetDescrElement; +class TCanvas; +class TGraphErrors; + +typedef std::map< Identifier , const CaloGeoDetDescrElement* > t_cellmap; +typedef std::map< double , const CaloGeoDetDescrElement* > t_eta_cellmap; + +class CaloGeoGeometryLookup { + public: + CaloGeoGeometryLookup(int ind=0); + virtual ~CaloGeoGeometryLookup(); + + bool IsCompatible(const CaloGeoDetDescrElement* cell); + void add(const CaloGeoDetDescrElement* cell); + t_cellmap::size_type size() const {return m_cells.size();}; + int index() const {return m_index;}; + void set_index(int ind) {m_index=ind;}; + void post_process(); + bool has_overlap(CaloGeoGeometryLookup* ref); + void merge_into_ref(CaloGeoGeometryLookup* ref); + //void CalculateTransformation(); + + float mineta() const {return m_mineta;}; + float maxeta() const {return m_maxeta;}; + float minphi() const {return m_minphi;}; + float maxphi() const {return m_maxphi;}; + + float mineta_raw() const {return m_mineta_raw;}; + float maxeta_raw() const {return m_maxeta_raw;}; + float minphi_raw() const {return m_minphi_raw;}; + float maxphi_raw() const {return m_maxphi_raw;}; + + float minx() const {return m_mineta;}; + float maxx() const {return m_maxeta;}; + float miny() const {return m_minphi;}; + float maxy() const {return m_maxphi;}; + + float minx_raw() const {return m_mineta_raw;}; + float maxx_raw() const {return m_maxeta_raw;}; + float miny_raw() const {return m_minphi_raw;}; + float maxy_raw() const {return m_maxphi_raw;}; + + const MeanAndRMS& deta() {return m_deta;}; + const MeanAndRMS& dphi() {return m_dphi;}; + float mindeta() {return m_mindeta;}; + float mindphi() {return m_mindphi;}; + const MeanAndRMS& dx() {return m_deta;}; + const MeanAndRMS& dy() {return m_dphi;}; + float mindx() {return m_mindeta;}; + float mindy() {return m_mindphi;}; + + const MeanAndRMS& eta_correction() {return m_eta_correction;}; + const MeanAndRMS& phi_correction() {return m_phi_correction;}; + const MeanAndRMS& x_correction() {return m_eta_correction;}; + const MeanAndRMS& y_correction() {return m_phi_correction;}; + + int cell_grid_eta() const {return m_cell_grid_eta;}; + int cell_grid_phi() const {return m_cell_grid_phi;}; + void set_xy_grid_adjustment_factor(float factor) {m_xy_grid_adjustment_factor=factor;}; + + virtual const CaloGeoDetDescrElement* getDDE(float eta,float phi,float* distance=0,int* steps=0); + + protected: + float neta_double() {return (maxeta_raw()-mineta_raw())/deta().mean();}; + float nphi_double() {return (maxphi_raw()-minphi_raw())/dphi().mean();}; + Int_t neta() {return TMath::Nint( neta_double() );}; + Int_t nphi() {return TMath::Nint( nphi_double() );}; + + //FCal is not sufficiently regular to use submaps with regular mapping + float nx_double() {return (maxx_raw()-minx_raw())/mindx();}; + float ny_double() {return (maxy_raw()-miny_raw())/mindy();}; + Int_t nx() {return TMath::Nint(TMath::Ceil( nx_double() ));}; + Int_t ny() {return TMath::Nint(TMath::Ceil( ny_double() ));}; + + float m_xy_grid_adjustment_factor; + + int raw_eta_position_to_index(float eta_raw) const {return TMath::Floor((eta_raw-mineta_raw())/m_deta_double);}; + int raw_phi_position_to_index(float phi_raw) const {return TMath::Floor((phi_raw-minphi_raw())/m_dphi_double);}; + bool index_range_adjust(int& ieta,int& iphi); + float calculate_distance_eta_phi(const CaloGeoDetDescrElement* DDE,float eta,float phi,float& dist_eta0,float& dist_phi0); + + int m_index; + t_cellmap m_cells; + std::vector< std::vector< const CaloGeoDetDescrElement* > > m_cell_grid; + int m_cell_grid_eta,m_cell_grid_phi; + float m_mineta,m_maxeta,m_minphi,m_maxphi; + float m_mineta_raw,m_maxeta_raw,m_minphi_raw,m_maxphi_raw; + float m_mineta_correction,m_maxeta_correction,m_minphi_correction,m_maxphi_correction; + + MeanAndRMS m_deta,m_dphi,m_eta_correction,m_phi_correction; + float m_mindeta,m_mindphi; + float m_deta_double,m_dphi_double; +}; + + +class CaloGeoGeometry //: virtual public ICaloGeometry { +{ + public : + static const int MAX_SAMPLING; + + static Identifier m_debug_identify; + static bool m_debug; + + CaloGeoGeometry(); + virtual ~CaloGeoGeometry(); + + virtual bool PostProcessGeometry(); + + virtual void Validate(); + + virtual const CaloGeoDetDescrElement* getDDE(Identifier identify); + virtual const CaloGeoDetDescrElement* getDDE(int sampling, Identifier identify); + + virtual const CaloGeoDetDescrElement* getDDE(int sampling,float eta,float phi,float* distance=0,int* steps=0); + virtual const CaloGeoDetDescrElement* getFCalDDE(int sampling,float eta,float phi,float z); + + double deta(int sample,double eta) const; + void minmaxeta(int sample,double eta,double& mineta,double& maxeta) const; + double rzmid(int sample,double eta) const; + double rzent(int sample,double eta) const; + double rzext(int sample,double eta) const; + double rmid(int sample,double eta) const; + double rent(int sample,double eta) const; + double rext(int sample,double eta) const; + double zmid(int sample,double eta) const; + double zent(int sample,double eta) const; + double zext(int sample,double eta) const; + double rpos(int sample,double eta,int subpos = CaloSubPos::SUBPOS_MID) const; + double zpos(int sample,double eta,int subpos = CaloSubPos::SUBPOS_MID) const; + double rzpos(int sample,double eta,int subpos = CaloSubPos::SUBPOS_MID) const; + bool isCaloBarrel(int sample) const {return m_isCaloBarrel[sample];}; + static std::string SamplingName(int sample); + + TGraphErrors* GetGraph(unsigned int sample) const {return m_graph_layers[sample];}; + void SetDoGraphs(bool dographs=true) {m_dographs=dographs;}; + bool DoGraphs() const {return m_dographs;}; + + TCanvas* DrawGeoForPhi0(); + FCAL_ChannelMap* GetFCAL_ChannelMap(){return &m_FCal_ChannelMap;} + + protected: + virtual void addcell(const CaloGeoDetDescrElement* cell); + + virtual void post_process(int layer); + + virtual void PrintMapInfo(int i, int j); + + virtual void InitRZmaps(); + + t_cellmap m_cells; + std::vector< t_cellmap > m_cells_in_sampling; + std::vector< t_eta_cellmap > m_cells_in_sampling_for_phi0; + std::vector< std::vector< CaloGeoGeometryLookup* > > m_cells_in_regions; + + std::vector< bool > m_isCaloBarrel; + std::vector< double > m_min_eta_sample[2]; //[side][calosample] + std::vector< double > m_max_eta_sample[2]; //[side][calosample] + std::vector< FSmap< double , double > > m_rmid_map[2]; //[side][calosample] + std::vector< FSmap< double , double > > m_zmid_map[2]; //[side][calosample] + std::vector< FSmap< double , double > > m_rent_map[2]; //[side][calosample] + std::vector< FSmap< double , double > > m_zent_map[2]; //[side][calosample] + std::vector< FSmap< double , double > > m_rext_map[2]; //[side][calosample] + std::vector< FSmap< double , double > > m_zext_map[2]; //[side][calosample] + + bool m_dographs; + std::vector< TGraphErrors* > m_graph_layers; + FCAL_ChannelMap m_FCal_ChannelMap; + /* + double m_min_eta_sample[2][MAX_SAMPLING]; //[side][calosample] + double m_max_eta_sample[2][MAX_SAMPLING]; //[side][calosample] + FSmap< double , double > m_rmid_map[2][MAX_SAMPLING]; //[side][calosample] + FSmap< double , double > m_zmid_map[2][MAX_SAMPLING]; //[side][calosample] + FSmap< double , double > m_rent_map[2][MAX_SAMPLING]; //[side][calosample] + FSmap< double , double > m_zent_map[2][MAX_SAMPLING]; //[side][calosample] + FSmap< double , double > m_rext_map[2][MAX_SAMPLING]; //[side][calosample] + FSmap< double , double > m_zext_map[2][MAX_SAMPLING]; //[side][calosample] + */ +}; + +#endif + + diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/ISF_FastCaloSimParametrization/CaloGeometry.h b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/ISF_FastCaloSimParametrization/CaloGeometry.h index 5d5095e313c7..6dcfdd4d4d7a 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/ISF_FastCaloSimParametrization/CaloGeometry.h +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/ISF_FastCaloSimParametrization/CaloGeometry.h @@ -16,20 +16,20 @@ #include "ISF_FastCaloSimParametrization/FSmap.h" #include "ISF_FastCaloSimParametrization/FCAL_ChannelMap.h" -class CaloGeoDetDescrElement; +class CaloDetDescrElement; class TCanvas; class TGraphErrors; -typedef std::map< Identifier , const CaloGeoDetDescrElement* > t_cellmap; -typedef std::map< double , const CaloGeoDetDescrElement* > t_eta_cellmap; +typedef std::map< Identifier , const CaloDetDescrElement* > t_cellmap; +typedef std::map< double , const CaloDetDescrElement* > t_eta_cellmap; class CaloGeometryLookup { public: CaloGeometryLookup(int ind=0); virtual ~CaloGeometryLookup(); - bool IsCompatible(const CaloGeoDetDescrElement* cell); - void add(const CaloGeoDetDescrElement* cell); + bool IsCompatible(const CaloDetDescrElement* cell); + void add(const CaloDetDescrElement* cell); t_cellmap::size_type size() const {return m_cells.size();}; int index() const {return m_index;}; void set_index(int ind) {m_index=ind;}; @@ -76,7 +76,7 @@ class CaloGeometryLookup { int cell_grid_phi() const {return m_cell_grid_phi;}; void set_xy_grid_adjustment_factor(float factor) {m_xy_grid_adjustment_factor=factor;}; - virtual const CaloGeoDetDescrElement* getDDE(float eta,float phi,float* distance=0,int* steps=0); + virtual const CaloDetDescrElement* getDDE(float eta,float phi,float* distance=0,int* steps=0); protected: float neta_double() {return (maxeta_raw()-mineta_raw())/deta().mean();}; @@ -95,11 +95,11 @@ class CaloGeometryLookup { int raw_eta_position_to_index(float eta_raw) const {return TMath::Floor((eta_raw-mineta_raw())/m_deta_double);}; int raw_phi_position_to_index(float phi_raw) const {return TMath::Floor((phi_raw-minphi_raw())/m_dphi_double);}; bool index_range_adjust(int& ieta,int& iphi); - float calculate_distance_eta_phi(const CaloGeoDetDescrElement* DDE,float eta,float phi,float& dist_eta0,float& dist_phi0); + float calculate_distance_eta_phi(const CaloDetDescrElement* DDE,float eta,float phi,float& dist_eta0,float& dist_phi0); int m_index; t_cellmap m_cells; - std::vector< std::vector< const CaloGeoDetDescrElement* > > m_cell_grid; + std::vector< std::vector< const CaloDetDescrElement* > > m_cell_grid; int m_cell_grid_eta,m_cell_grid_phi; float m_mineta,m_maxeta,m_minphi,m_maxphi; float m_mineta_raw,m_maxeta_raw,m_minphi_raw,m_maxphi_raw; @@ -124,11 +124,11 @@ class CaloGeometry : virtual public ICaloGeometry { virtual void Validate(); - virtual const CaloGeoDetDescrElement* getDDE(Identifier identify); - virtual const CaloGeoDetDescrElement* getDDE(int sampling, Identifier identify); + virtual const CaloDetDescrElement* getDDE(Identifier identify); + virtual const CaloDetDescrElement* getDDE(int sampling, Identifier identify); - virtual const CaloGeoDetDescrElement* getDDE(int sampling,float eta,float phi,float* distance=0,int* steps=0); - virtual const CaloGeoDetDescrElement* getFCalDDE(int sampling,float eta,float phi,float z); + virtual const CaloDetDescrElement* getDDE(int sampling,float eta,float phi,float* distance=0,int* steps=0); + virtual const CaloDetDescrElement* getFCalDDE(int sampling,float eta,float phi,float z); double deta(int sample,double eta) const; void minmaxeta(int sample,double eta,double& mineta,double& maxeta) const; @@ -155,7 +155,7 @@ class CaloGeometry : virtual public ICaloGeometry { FCAL_ChannelMap* GetFCAL_ChannelMap(){return &m_FCal_ChannelMap;} protected: - virtual void addcell(const CaloGeoDetDescrElement* cell); + virtual void addcell(const CaloDetDescrElement* cell); virtual void post_process(int layer); @@ -194,5 +194,3 @@ class CaloGeometry : virtual public ICaloGeometry { }; #endif - - diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/ISF_FastCaloSimParametrization/CaloGeometryFromFile.h b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/ISF_FastCaloSimParametrization/CaloGeometryFromFile.h index 1a1b749dead7..5238fa4d78db 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/ISF_FastCaloSimParametrization/CaloGeometryFromFile.h +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/ISF_FastCaloSimParametrization/CaloGeometryFromFile.h @@ -5,10 +5,10 @@ #ifndef CaloGeometryFromFile_h #define CaloGeometryFromFile_h -#include "ISF_FastCaloSimParametrization/CaloGeometry.h" +#include "ISF_FastCaloSimParametrization/CaloGeoGeometry.h" -class CaloGeometryFromFile:public CaloGeometry { +class CaloGeometryFromFile:public CaloGeoGeometry { public : CaloGeometryFromFile(); virtual ~CaloGeometryFromFile(); diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/ISF_FastCaloSimParametrization/ICaloGeometry.h b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/ISF_FastCaloSimParametrization/ICaloGeometry.h index 41b8a326b50d..7ac58a1d9e6b 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/ISF_FastCaloSimParametrization/ICaloGeometry.h +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/ISF_FastCaloSimParametrization/ICaloGeometry.h @@ -7,18 +7,20 @@ #include "Identifier/Identifier.h" #include "ISF_FastCaloSimEvent/FastCaloSim_CaloCell_ID.h" -#include "ISF_FastCaloSimParametrization/CaloDetDescrElement.h" +#include "CaloDetDescr/CaloDetDescrElement.h" +#include "ISF_FastCaloSimParametrization/CaloGeoDetDescrElement.h" -class CaloGeoDetDescrElement; +class CaloDetDescrElement; class ICaloGeometry { public : virtual bool PostProcessGeometry() = 0; virtual void Validate() = 0; - virtual const CaloGeoDetDescrElement* getDDE(Identifier identify) = 0; - - virtual const CaloGeoDetDescrElement* getDDE(int sampling,float eta,float phi,float* distance=0,int* steps=0) = 0; + virtual const CaloDetDescrElement* getDDE(Identifier identify) = 0; + virtual const CaloDetDescrElement* getDDE(int sampling,float eta,float phi,float* distance=0,int* steps=0) = 0; +// virtual const CaloGeoDetDescrElement* getDDE(Identifier identify) = 0; +// virtual const CaloGeoDetDescrElement* getDDE(int sampling,float eta,float phi,float* distance=0,int* steps=0) = 0; virtual double deta(int sample,double eta) const = 0; virtual void minmaxeta(int sample,double eta,double& mineta,double& maxeta) const = 0; diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/ISF_FastCaloSimParametrization/IFastCaloSimCaloExtrapolation.h b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/ISF_FastCaloSimParametrization/IFastCaloSimCaloExtrapolation.h index 09654054d50c..ae5dc21824b8 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/ISF_FastCaloSimParametrization/IFastCaloSimCaloExtrapolation.h +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/ISF_FastCaloSimParametrization/IFastCaloSimCaloExtrapolation.h @@ -10,6 +10,7 @@ class TFCSTruthState; class TFCSExtrapolationState; +//class IFastCaloSimGeometryHelper; static const InterfaceID IID_IFastCaloSimCaloExtrapolation("IFastCaloSimCaloExtrapolation", 1, 0); @@ -21,6 +22,7 @@ class IFastCaloSimCaloExtrapolation : virtual public IAlgTool virtual void extrapolate(TFCSExtrapolationState& result,const TFCSTruthState* truth) = 0; + //virtual IFastCaloSimGeometryHelper* GetCaloGeometry() const = 0; }; #endif // IFastCaloSimCaloExtrapolation_H diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/Root/EnergyParametrizationValidation.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/Root/EnergyParametrizationValidation.cxx index c748006767cf..5c2378bb7961 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/Root/EnergyParametrizationValidation.cxx +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/Root/EnergyParametrizationValidation.cxx @@ -1,6 +1,6 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration - */ + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ #include "TH1D.h" #include "TFile.h" @@ -18,100 +18,100 @@ using namespace std; void EnergyParametrizationValidation::autozoom(TH1D* h1, double &min, double &max, double &rmin, double &rmax) { - - double min1,min2,max1,max2; - min1=min2=h1->GetXaxis()->GetXmin(); - max1=max2=h1->GetXaxis()->GetXmax(); - - for(int b=1;b<=h1->GetNbinsX();b++) + + double min1,min2,max1,max2; + min1=min2=h1->GetXaxis()->GetXmin(); + max1=max2=h1->GetXaxis()->GetXmax(); + + for(int b=1;b<=h1->GetNbinsX();b++) + { + if(h1->GetBinContent(b)>0) { - if(h1->GetBinContent(b)>0) - { - min1=h1->GetBinCenter(b); - break; - } + min1=h1->GetBinCenter(b); + break; } - for(int b=h1->GetNbinsX();b>=1;b--) + } + for(int b=h1->GetNbinsX();b>=1;b--) + { + if(h1->GetBinContent(b)>0) { - if(h1->GetBinContent(b)>0) - { - max1=h1->GetBinCenter(b); - break; - } + max1=h1->GetBinCenter(b); + break; } - - min=min1;max=max1; - - - rmin=min-0.5*h1->GetBinWidth(1); - rmax=max+0.5*h1->GetBinWidth(1); - + } + + min=min1;max=max1; + + + rmin=min-0.5*h1->GetBinWidth(1); + rmax=max+0.5*h1->GetBinWidth(1); + } TH1D* EnergyParametrizationValidation::refill(TH1D* h_in,double min, double max, double rmin, double rmax) { - - //int debug=0; - - int Nbins; - int bins=0; - for(int b=h_in->FindBin(min);b<=h_in->FindBin(max);b++) + + //int debug=0; + + int Nbins; + int bins=0; + for(int b=h_in->FindBin(min);b<=h_in->FindBin(max);b++) bins++; - - if(bins<=120) - { - //no rebinning - Nbins=bins; - } - else - { - int tries=0; - int rebin=2; - - while(tries<1000) - { - if((10000%rebin)==0) - { - TH1D* h_clone=(TH1D*)h_in->Clone("h_clone"); - h_clone->Rebin(rebin); - Nbins=0; - for(int b=h_clone->FindBin(min);b<=h_clone->FindBin(max);b++) - Nbins++; - if(Nbins<120 && Nbins>50) - { - h_in->Rebin(rebin); - cout<<"*decide for rebin="<<rebin<<"*"<<endl; - break; - } - } - rebin++; - tries++; - } - if(tries>=1000) + + if(bins<=120) + { + //no rebinning + Nbins=bins; + } + else + { + int tries=0; + int rebin=2; + + while(tries<1000) + { + if((10000%rebin)==0) + { + TH1D* h_clone=(TH1D*)h_in->Clone("h_clone"); + h_clone->Rebin(rebin); + Nbins=0; + for(int b=h_clone->FindBin(min);b<=h_clone->FindBin(max);b++) + Nbins++; + if(Nbins<120 && Nbins>50) { - cout<<" ********** GIVE UP ********** "<<endl; - h_in->Rebin((double)bins/100.0); - Nbins=0; - for(int b=h_in->FindBin(min);b<=h_in->FindBin(max);b++) - Nbins++; + h_in->Rebin(rebin); + cout<<"*decide for rebin="<<rebin<<"*"<<endl; + break; } + } + rebin++; + tries++; } - - //if(debug) cout<<"---> NBINS "<<Nbins<<endl; - - int start=h_in->FindBin(min)-1; - - //if(debug) cout<<"AFTER rebin ->underflow "<<h_in->GetBinContent(0)<<" startbin "<<start<<" minimum "<<min<<endl; - - TH1D* h_out=new TH1D("h_out","h_out",Nbins,rmin,rmax); - for(int b=1;b<=h_out->GetNbinsX();b++) + if(tries>=1000) { - h_out->SetBinContent(b,h_in->GetBinContent(start+b)); - h_out->SetBinError(b,h_in->GetBinError(start+b)); + cout<<" ********** GIVE UP ********** "<<endl; + h_in->Rebin((double)bins/100.0); + Nbins=0; + for(int b=h_in->FindBin(min);b<=h_in->FindBin(max);b++) + Nbins++; } - - //if(debug) cout<<"AFTER refill ->underflow "<<h_out->GetBinContent(0)<<" startbin "<<start<<" minimum "<<min<<endl; - - return h_out; - + } + + //if(debug) cout<<"---> NBINS "<<Nbins<<endl; + + int start=h_in->FindBin(min)-1; + + //if(debug) cout<<"AFTER rebin ->underflow "<<h_in->GetBinContent(0)<<" startbin "<<start<<" minimum "<<min<<endl; + + TH1D* h_out=new TH1D("h_out","h_out",Nbins,rmin,rmax); + for(int b=1;b<=h_out->GetNbinsX();b++) + { + h_out->SetBinContent(b,h_in->GetBinContent(start+b)); + h_out->SetBinError(b,h_in->GetBinError(start+b)); + } + + //if(debug) cout<<"AFTER refill ->underflow "<<h_out->GetBinContent(0)<<" startbin "<<start<<" minimum "<<min<<endl; + + return h_out; + } diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/Root/TreeReader.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/Root/TreeReader.cxx index 1c6ff972bc2f..56e8a183b701 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/Root/TreeReader.cxx +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/Root/TreeReader.cxx @@ -1,6 +1,6 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration - */ + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ #include "TTreeFormula.h" #include "TTreeFormulaManager.h" @@ -19,8 +19,8 @@ //______________________________________________________________________________ /* - Class for Tree reading through TFormula. - ______________________________________________________________________________*/ +Class for Tree reading through TFormula. +______________________________________________________________________________*/ TreeReader::TreeReader() @@ -41,7 +41,7 @@ TreeReader::~TreeReader() //============================================================ TreeReader::TreeReader(TTree* n) -//============================================================ + //============================================================ { // Constructor. m_tree = 0; @@ -51,7 +51,7 @@ TreeReader::TreeReader(TTree* n) //============================================================ void TreeReader::SetTree(TTree* n) -//============================================================ + //============================================================ { // check for null pointer BEFORE trying to use it if(!n) return; @@ -59,7 +59,7 @@ void TreeReader::SetTree(TTree* n) m_tree = n; m_currentEntry = -1; m_formulae.clear(); - m_formulae["__DUMMY__"] = new TTreeFormula("__DUMMY__","0",m_tree); + m_formulae["__DUMMY__"] = new TTreeFormula("__DUMMY__","0",m_tree); m_isChain = (n->IsA() == TClass::GetClass("TChain")); m_currentTree = 0; m_entries = (int) m_tree->GetEntries(); @@ -67,71 +67,71 @@ void TreeReader::SetTree(TTree* n) //============================================================= double TreeReader::GetVariable(const char* c, int entry) -//============================================================ + //============================================================ { // Get vaviable. // Return variable for a given entry (<0 -> current entry). - if(entry>=0 && entry!=m_currentEntry) this->GetEntry(entry); - std::string s = c; - TTreeFormula *f = m_formulae[s]; - if(!f) +if(entry>=0 && entry!=m_currentEntry) this->GetEntry(entry); +std::string s = c; +TTreeFormula *f = m_formulae[s]; +if(!f) { - f = new TTreeFormula(c,c,m_tree); - f->SetQuickLoad(kTRUE); - // fManager->Add(f); - // fManager->Sync(); - if(f->GetNdim()!=1) //invalid fomula + f = new TTreeFormula(c,c,m_tree); + f->SetQuickLoad(kTRUE); +// fManager->Add(f); +// fManager->Sync(); + if(f->GetNdim()!=1) //invalid fomula { - delete f; - f = m_formulae["__DUMMY__"]; - std::cout << "in [TreeReader] : " << s << " is not valid -> return 0" << std::endl; + delete f; + f = m_formulae["__DUMMY__"]; + std::cout << "in [TreeReader] : " << s << " is not valid -> return 0" << std::endl; } - // else {f->Notify();} - m_formulae[s] = f; +// else {f->Notify();} + m_formulae[s] = f; } - if(f == m_formulae["__DUMMY__"]) return 0; - int valid = f->GetNdata() ; - if(!valid) return 0; - // std::cout << "Evaluating formula : " << s << std::flush; - // std::cout << " " << f->EvalInstance(0) << std::endl; - return f->EvalInstance(0); +if(f == m_formulae["__DUMMY__"]) return 0; +int valid = f->GetNdata() ; +if(!valid) return 0; +// std::cout << "Evaluating formula : " << s << std::flush; +// std::cout << " " << f->EvalInstance(0) << std::endl; +return f->EvalInstance(0); } //============================================================ int TreeReader::GetEntry(int entry) -//============================================================ + //============================================================ { // Read a given entry in the buffer (-1 -> next entry). // Return kFALSE if not found. - // entry += 1; +// entry += 1; if(m_entries==0) return 0; if(entry==-1) entry = m_currentEntry+1; if(entry<m_entries) - { + { int entryNumber = m_tree->GetEntryNumber(entry); if (entryNumber < 0) return 0; - Long64_t localEntry = m_tree->LoadTree(entryNumber); - if (localEntry < 0) return 0; + Long64_t localEntry = m_tree->LoadTree(entryNumber); + if (localEntry < 0) return 0; m_currentEntry = entry; - if(m_isChain) // check file change in chain - { - int I = static_cast<TChain*>(m_tree)->GetTreeNumber(); - if(I!=m_currentTree) - { - m_currentTree = I; - //fManager->Clear(); - std::map<std::string, TTreeFormula*>::iterator itr = m_formulae.begin(); - std::map<std::string, TTreeFormula*>::iterator itrE= m_formulae.end(); - TTreeFormula* dummy = m_formulae["__DUMMY__"]; - for(;itr!=itrE;itr++) + if(m_isChain) // check file change in chain { - if(itr->second!=dummy) itr->second->Notify(); //itr->second->UpdateFormulaLeaves(); - } - } + int I = static_cast<TChain*>(m_tree)->GetTreeNumber(); + if(I!=m_currentTree) + { + m_currentTree = I; + //fManager->Clear(); + std::map<std::string, TTreeFormula*>::iterator itr = m_formulae.begin(); + std::map<std::string, TTreeFormula*>::iterator itrE= m_formulae.end(); + TTreeFormula* dummy = m_formulae["__DUMMY__"]; + for(;itr!=itrE;itr++) + { + if(itr->second!=dummy) itr->second->Notify(); //itr->second->UpdateFormulaLeaves(); + } + } + } + return 1; } - return 1; - } return 0; } diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/python/ISF_FastCaloSimParametrizationConfig.py b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/python/ISF_FastCaloSimParametrizationConfig.py index 8630ae23c69f..e4814f002bbd 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/python/ISF_FastCaloSimParametrizationConfig.py +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/python/ISF_FastCaloSimParametrizationConfig.py @@ -1,19 +1,29 @@ # Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration - -""" -Tools configurations for ISF_FastCaloSimParametrization -""" -from AthenaCommon import CfgMgr - -from AthenaCommon.Constants import * # FATAL,ERROR etc. -from AthenaCommon.SystemOfUnits import * -from AthenaCommon.DetFlags import DetFlags - -def getFastCaloSimCaloExtrapolation(name="FastCaloSimCaloExtrapolation", **kwargs): - from ISF_FastCaloSimParametrization.ISF_FastCaloSimParametrizationConf import FastCaloSimCaloExtrapolation - return CfgMgr.FastCaloSimCaloExtrapolation(name, **kwargs) - -def getFastCaloSimGeometryHelper(name="FastCaloSimGeometryHelper", **kwargs): - from ISF_FastCaloSimParametrization.ISF_FastCaloSimParametrizationConf import FastCaloSimGeometryHelper - return CfgMgr.FastCaloSimGeometryHelper(name, **kwargs) + +""" +Tools configurations for ISF_FastCaloSimParametrization +""" +from AthenaCommon import CfgMgr +from AthenaCommon.CfgGetter import getPrivateTool,getPrivateToolClone,getPublicTool,getPublicToolClone,getService,getServiceClone,getAlgorithm,getAlgorithmClone + +from AthenaCommon.Constants import * # FATAL,ERROR etc. +from AthenaCommon.SystemOfUnits import * +from AthenaCommon.DetFlags import DetFlags + +def getFastCaloSimCaloExtrapolation(name="FastCaloSimCaloExtrapolation", **kwargs): + from ISF_FastCaloSimParametrization.ISF_FastCaloSimParametrizationConf import FastCaloSimCaloExtrapolation + + kwargs.setdefault("CaloBoundaryR" , 1148.0 ) + kwargs.setdefault("CaloBoundaryZ" , 3549.5 ) + kwargs.setdefault("CaloMargin" , 100 ) + kwargs.setdefault("Extrapolator" , "TimedExtrapolator" ) + kwargs.setdefault("CaloSurfaceHelper" , "CaloSurfaceHelper" ) + kwargs.setdefault("CaloGeometryHelper" , "FastCaloSimGeometryHelper" ) + kwargs.setdefault("CaloEntrance" , "InDet::Containers::InnerDetector" ) + + return CfgMgr.FastCaloSimCaloExtrapolation(name, **kwargs) + +def getFastCaloSimGeometryHelper(name="FastCaloSimGeometryHelper", **kwargs): + from ISF_FastCaloSimParametrization.ISF_FastCaloSimParametrizationConf import FastCaloSimGeometryHelper + return CfgMgr.FastCaloSimGeometryHelper(name, **kwargs) diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/python/ISF_FastCaloSimParametrizationConfigDb.py b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/python/ISF_FastCaloSimParametrizationConfigDb.py index 3a6181cff9d8..feb8a4c22c1c 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/python/ISF_FastCaloSimParametrizationConfigDb.py +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/python/ISF_FastCaloSimParametrizationConfigDb.py @@ -1,16 +1,22 @@ # Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -""" -Configuration database for ISF_FastCaloSimParametrization -""" - -from AthenaCommon.CfgGetter import addTool - -from AthenaCommon.Constants import * # FATAL,ERROR etc. -import AthenaCommon.SystemOfUnits as Units - -# Common tools, services and algorithms used by jobs -addTool("ISF_FastCaloSimParametrization.ISF_FastCaloSimParametrizationConfig.getFastCaloSimCaloExtrapolation" , "FastCaloSimCaloExtrapolation" ) -addTool("ISF_FastCaloSimParametrization.ISF_FastCaloSimParametrizationConfig.getFastCaloSimGeometryHelper" , "FastCaloSimGeometryHelper" ) - - +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +""" +Configuration database for ISF_FastCaloSimParametrization +""" + +from AthenaCommon.CfgGetter import addTool, addToolClone, addService, addAlgorithm, \ + addTypesToExcludeIfDefaultValue, addNamesToExcludeIfDefaultValue, addFullNamesToExcludeIfDefaultValue, \ + addPropertiesToExcludeIfDefault, \ + addTypesToSkipIfNotAvailable, addNamesToSkipIfNotAvailable, addFullNamesToSkipIfNotAvailable, \ + addTypesOnlyToSkip + +from AthenaCommon.Constants import * # FATAL,ERROR etc. +import AthenaCommon.SystemOfUnits as Units + +# Common tools, services and algorithms used by jobs +addTool("ISF_FastCaloSimParametrization.ISF_FastCaloSimParametrizationConfig.getFastCaloSimCaloExtrapolation" , "FastCaloSimCaloExtrapolation" ) +addTool("ISF_FastCaloSimParametrization.ISF_FastCaloSimParametrizationConfig.getFastCaloSimGeometryHelper" , "FastCaloSimGeometryHelper" ) + + diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/CaloGeoGeometry.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/CaloGeoGeometry.cxx new file mode 100644 index 000000000000..92d40e7dc165 --- /dev/null +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/CaloGeoGeometry.cxx @@ -0,0 +1,1220 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "ISF_FastCaloSimParametrization/CaloGeoGeometry.h" +#include <TTree.h> +#include <TVector2.h> +#include <TRandom.h> +#include <TCanvas.h> +#include <TH2D.h> +#include <TGraphErrors.h> +#include <TVector3.h> +#include <TLegend.h> + +//#include "CaloDetDescr/CaloGeoDetDescrElement.h" +#include "ISF_FastCaloSimParametrization/CaloGeoDetDescrElement.h" +#include "CaloGeoHelpers/CaloSampling.h" +#include "ISF_FastCaloSimEvent/FastCaloSim_CaloCell_ID.h" +//#include "TMVA/Tools.h" +//#include "TMVA/Factory.h" + +using namespace std; + +const int CaloGeoGeometry::MAX_SAMPLING = CaloCell_ID_FCS::MaxSample; //number of calorimeter layers/samplings + +Identifier CaloGeoGeometry::m_debug_identify; +bool CaloGeoGeometry::m_debug=false; + +CaloGeoGeometryLookup::CaloGeoGeometryLookup(int ind):m_xy_grid_adjustment_factor(0.75),m_index(ind) +{ + m_mineta=+10000; + m_maxeta=-10000; + m_minphi=+10000; + m_maxphi=-10000; + + m_mineta_raw=+10000; + m_maxeta_raw=-10000; + m_minphi_raw=+10000; + m_maxphi_raw=-10000; + + m_mindeta=10000; + m_mindphi=10000; + + m_mineta_correction=+10000; + m_maxeta_correction=-10000; + m_minphi_correction=+10000; + m_maxphi_correction=-10000; + + m_cell_grid_eta=0.; + m_cell_grid_phi=0.; + m_deta_double =0.; + m_dphi_double =0.; +} + +CaloGeoGeometryLookup::~CaloGeoGeometryLookup() +{ +} + +bool CaloGeoGeometryLookup::has_overlap(CaloGeoGeometryLookup* ref) +{ + if(m_cells.size()==0) return false; + for(t_cellmap::iterator ic=m_cells.begin();ic!=m_cells.end();++ic) { + const CaloGeoDetDescrElement* cell=ic->second; + if(ref->IsCompatible(cell)) return true; + } + return false; +} + +void CaloGeoGeometryLookup::merge_into_ref(CaloGeoGeometryLookup* ref) +{ + for(t_cellmap::iterator ic=m_cells.begin();ic!=m_cells.end();++ic) { + const CaloGeoDetDescrElement* cell=ic->second; + ref->add(cell); + } +} + + +bool CaloGeoGeometryLookup::IsCompatible(const CaloGeoDetDescrElement* cell) +{ + if(m_cells.size()==0) return true; + t_cellmap::iterator ic=m_cells.begin(); + const CaloGeoDetDescrElement* refcell=ic->second; + int sampling=refcell->getSampling(); + if(cell->getSampling()!=sampling) return false; + if(cell->eta_raw()*refcell->eta_raw()<0) return false; + if(sampling<21) { // keep only cells reasonable close in eta to each other + if(TMath::Abs(cell->deta()-refcell->deta())>0.001) return false; + if(TMath::Abs(cell->dphi()-refcell->dphi())>0.001) return false; + + if( cell->eta()<mineta()-2.1*cell->deta() ) return false; + if( cell->eta()>maxeta()+2.1*cell->deta() ) return false; + + double delta_eta=(cell->eta_raw()-refcell->eta_raw())/cell->deta(); + double delta_phi=(cell->phi_raw()-refcell->phi_raw())/cell->dphi(); + if(TMath::Abs(delta_eta-TMath::Nint(delta_eta)) > 0.01) return false; + if(TMath::Abs(delta_phi-TMath::Nint(delta_phi)) > 0.01) return false; + + //cout<<"Compatible: s="<<cell->getSampling()<<"~"<<refcell->getSampling()<<"; "; + //cout<<"eta="<<cell->eta_raw()<<","<<refcell->eta_raw()<<"; "; + //cout<<"phi="<<cell->phi_raw()<<","<<refcell->phi_raw()<<"; "; + //cout<<"deta="<<cell->deta()<<"~"<<refcell->deta()<<"; "; + //cout<<"dphi="<<cell->dphi()<<"~"<<refcell->dphi()<<";"; + //cout<<"mineta="<<mineta()<<", maxeta="<<maxeta()<<"; "; + //cout<<endl; + + } else { + //FCal is not sufficiently regular to use submaps with regular mapping + return true; + + + //if(TMath::Abs(cell->dx()-refcell->dx())>0.001) return false; + //if(TMath::Abs(cell->dy()-refcell->dy())>0.001) return false; + //if( cell->x()<minx()-20*cell->dx() ) return false; + //if( cell->x()>maxx()+20*cell->dx() ) return false; + //if( cell->y()<miny()-20*cell->dy() ) return false; + //if( cell->y()>maxy()+20*cell->dy() ) return false; + + //double delta_x=(cell->x_raw()-refcell->x_raw())/cell->dx(); + //double delta_y=(cell->y_raw()-refcell->y_raw())/cell->dy(); + //if(TMath::Abs(delta_x-TMath::Nint(delta_x)) > 0.01) return false; + //if(TMath::Abs(delta_y-TMath::Nint(delta_y)) > 0.01) return false; + + } + + return true; +} + +void CaloGeoGeometryLookup::add(const CaloGeoDetDescrElement* cell) +{ + if(cell->getSampling()<21) { + m_deta.add(cell->deta()); + m_dphi.add(cell->dphi()); + m_mindeta=TMath::Min(cell->deta(),m_mindeta); + m_mindphi=TMath::Min(cell->dphi(),m_mindphi); + + m_eta_correction.add(cell->eta_raw()-cell->eta()); + m_phi_correction.add(cell->phi_raw()-cell->phi()); + m_mineta_correction=TMath::Min(cell->eta_raw()-cell->eta() , m_mineta_correction); + m_maxeta_correction=TMath::Max(cell->eta_raw()-cell->eta() , m_maxeta_correction); + m_minphi_correction=TMath::Min(cell->phi_raw()-cell->phi() , m_minphi_correction); + m_maxphi_correction=TMath::Max(cell->phi_raw()-cell->phi() , m_maxphi_correction); + + m_mineta=TMath::Min(cell->eta()-cell->deta()/2,m_mineta); + m_maxeta=TMath::Max(cell->eta()+cell->deta()/2,m_maxeta); + m_minphi=TMath::Min(cell->phi()-cell->dphi()/2,m_minphi); + m_maxphi=TMath::Max(cell->phi()+cell->dphi()/2,m_maxphi); + + m_mineta_raw=TMath::Min(cell->eta_raw()-cell->deta()/2,m_mineta_raw); + m_maxeta_raw=TMath::Max(cell->eta_raw()+cell->deta()/2,m_maxeta_raw); + m_minphi_raw=TMath::Min(cell->phi_raw()-cell->dphi()/2,m_minphi_raw); + m_maxphi_raw=TMath::Max(cell->phi_raw()+cell->dphi()/2,m_maxphi_raw); + } else { + m_deta.add(cell->dx()); + m_dphi.add(cell->dy()); + m_mindeta=TMath::Min(cell->dx(),m_mindeta); + m_mindphi=TMath::Min(cell->dy(),m_mindphi); + + m_eta_correction.add(cell->x_raw()-cell->x()); + m_phi_correction.add(cell->y_raw()-cell->y()); + m_mineta_correction=TMath::Min(cell->x_raw()-cell->x() , m_mineta_correction); + m_maxeta_correction=TMath::Max(cell->x_raw()-cell->x() , m_maxeta_correction); + m_minphi_correction=TMath::Min(cell->y_raw()-cell->y() , m_minphi_correction); + m_maxphi_correction=TMath::Max(cell->y_raw()-cell->y() , m_maxphi_correction); + + m_mineta=TMath::Min(cell->x()-cell->dx()/2,m_mineta); + m_maxeta=TMath::Max(cell->x()+cell->dx()/2,m_maxeta); + m_minphi=TMath::Min(cell->y()-cell->dy()/2,m_minphi); + m_maxphi=TMath::Max(cell->y()+cell->dy()/2,m_maxphi); + + m_mineta_raw=TMath::Min(cell->x_raw()-cell->dx()/2,m_mineta_raw); + m_maxeta_raw=TMath::Max(cell->x_raw()+cell->dx()/2,m_maxeta_raw); + m_minphi_raw=TMath::Min(cell->y_raw()-cell->dy()/2,m_minphi_raw); + m_maxphi_raw=TMath::Max(cell->y_raw()+cell->dy()/2,m_maxphi_raw); + } + m_cells[cell->identify()]=cell; +} + +bool CaloGeoGeometryLookup::index_range_adjust(int& ieta,int& iphi) +{ + while(iphi<0) {iphi+=m_cell_grid_phi;}; + while(iphi>=m_cell_grid_phi) {iphi-=m_cell_grid_phi;}; + if(ieta<0) { + ieta=0; + return false; + } + if(ieta>=m_cell_grid_eta) { + ieta=m_cell_grid_eta-1; + return false; + } + return true; +} + +void CaloGeoGeometryLookup::post_process() +{ + if(size()==0) return; + t_cellmap::iterator ic=m_cells.begin(); + const CaloGeoDetDescrElement* refcell=ic->second; + int sampling=refcell->getSampling(); + if(sampling<21) { + double rneta=neta_double()-neta(); + double rnphi=nphi_double()-nphi(); + if(TMath::Abs(rneta)>0.05 || TMath::Abs(rnphi)>0.05) { + cout<<"ERROR: can't map cells into a regular grid for sampling "<<sampling<<", map index "<<index()<<endl; + return; + } + m_cell_grid_eta=neta(); + m_cell_grid_phi=nphi(); + m_deta_double=deta(); + m_dphi_double=dphi(); + } else { + //double rnx=nx_double()-nx(); + //double rny=ny_double()-ny(); + //if(TMath::Abs(rnx)>0.05 || TMath::Abs(rny)>0.05) { + // cout<<"Grid: Sampling "<<sampling<<"_"<<index()<<": mapping cells into a regular grid, although cells don't fit well"<<endl; + //} + + m_cell_grid_eta=TMath::Nint(TMath::Ceil(nx_double()/m_xy_grid_adjustment_factor)); + m_cell_grid_phi=TMath::Nint(TMath::Ceil(ny_double()/m_xy_grid_adjustment_factor)); + m_deta_double=mindx()*m_xy_grid_adjustment_factor; + m_dphi_double=mindy()*m_xy_grid_adjustment_factor; + } + + m_cell_grid.resize(m_cell_grid_eta); + for(int ieta=0;ieta<m_cell_grid_eta;++ieta) { + m_cell_grid[ieta].resize(m_cell_grid_phi,0); + } + + for(ic=m_cells.begin();ic!=m_cells.end();++ic) { + refcell=ic->second; + int ieta,iphi; + if(sampling<21) { + ieta=raw_eta_position_to_index(refcell->eta_raw()); + iphi=raw_phi_position_to_index(refcell->phi_raw()); + } else { + ieta=raw_eta_position_to_index(refcell->x_raw()); + iphi=raw_phi_position_to_index(refcell->y_raw()); + } + if(index_range_adjust(ieta,iphi)) { + if(m_cell_grid[ieta][iphi]) { + cout<<"Grid: Sampling "<<sampling<<"_"<<index()<<": Already cell found at pos ("<<ieta<<","<<iphi<<"): id=" + <<m_cell_grid[ieta][iphi]->identify()<<"->"<<refcell->identify()<<endl; + cout<<" x="<<m_cells[m_cell_grid[ieta][iphi]->identify()]->x_raw()<<" -> "<<refcell->x_raw(); + cout<<" , y="<<m_cells[m_cell_grid[ieta][iphi]->identify()]->y_raw()<<" -> "<<refcell->y_raw(); + cout<<" mindx="<<m_deta_double<<" mindy="<<m_dphi_double<<endl; + cout<<endl; + } + m_cell_grid[ieta][iphi]=refcell; + } else { + cout<<"Grid: Sampling "<<sampling<<"_"<<index()<<": Cell at pos ("<<ieta<<","<<iphi<<"): id=" + <<refcell->identify()<<" outside eta range"<<endl; + } + } + + int ncells=0; + int nempty=0; + for(int ieta=0;ieta<m_cell_grid_eta;++ieta) { + for(int iphi=0;iphi<m_cell_grid_phi;++iphi) { + if(!m_cell_grid[ieta][iphi]) { + ++nempty; + //cout<<"Sampling "<<sampling<<"_"<<index()<<": No cell at pos ("<<ieta<<","<<iphi<<")"<<endl; + } else { + ++ncells; + } + } + } + // cout<<"Grid: Sampling "<<sampling<<"_"<<index()<<": "<<ncells<<"/"<<size()<<" cells filled, "<<nempty<<" empty grid positions deta="<<m_deta_double<<" dphi="<<m_dphi_double<<endl; +} + +float CaloGeoGeometryLookup::calculate_distance_eta_phi(const CaloGeoDetDescrElement* DDE,float eta,float phi,float& dist_eta0,float& dist_phi0) +{ + dist_eta0=(eta - DDE->eta())/m_deta_double; + dist_phi0=(TVector2::Phi_mpi_pi(phi - DDE->phi()))/m_dphi_double; + float abs_dist_eta0=TMath::Abs(dist_eta0); + float abs_dist_phi0=TMath::Abs(dist_phi0); + return TMath::Max(abs_dist_eta0,abs_dist_phi0)-0.5; +} + + +const CaloGeoDetDescrElement* CaloGeoGeometryLookup::getDDE(float eta,float phi,float* distance,int* steps) +{ + float dist; + const CaloGeoDetDescrElement* bestDDE=0; + if(!distance) distance=&dist; + *distance=+10000000; + int intsteps=0; + if(!steps) steps=&intsteps; + + float best_eta_corr=m_eta_correction; + float best_phi_corr=m_phi_correction; + + float raw_eta=eta+best_eta_corr; + float raw_phi=phi+best_phi_corr; + + int ieta=raw_eta_position_to_index(raw_eta); + int iphi=raw_phi_position_to_index(raw_phi); + index_range_adjust(ieta,iphi); + + const CaloGeoDetDescrElement* newDDE=m_cell_grid[ieta][iphi]; + float bestdist=+10000000; + ++(*steps); + int nsearch=0; + while(newDDE && nsearch<3) { + float dist_eta0,dist_phi0; + *distance=calculate_distance_eta_phi(newDDE,eta,phi,dist_eta0,dist_phi0); + bestDDE=newDDE; + bestdist=*distance; + + if(CaloGeoGeometry::m_debug || CaloGeoGeometry::m_debug_identify==newDDE->identify()) { + cout<<"CaloGeoGeometryLookup::getDDE, search iteration "<<nsearch<<endl; + cout<<"cell id="<<newDDE->identify()<<" steps "<<*steps<<" steps, eta="<<eta<<" phi="<<phi<<" dist="<<*distance<<" cell_grid_eta="<<cell_grid_eta()<<" cell_grid_phi="<<cell_grid_phi()<<" m_deta_double="<<m_deta_double<<" m_dphi_double="<<m_dphi_double<<" 1st_eta_corr="<<best_eta_corr<<" 1st_phi_corr="<<best_phi_corr<<endl; + cout<<" input sampling="<<newDDE->getSampling()<<" eta="<<newDDE->eta()<<" eta_raw="<<newDDE->eta_raw()<<" deta="<<newDDE->deta()<<" ("<<(newDDE->eta_raw()-newDDE->eta())/newDDE->deta()<<") phi="<<newDDE->phi()<<" phi_raw="<<newDDE->phi_raw()<<" dphi="<<newDDE->dphi()<<" ("<<(newDDE->phi_raw()-newDDE->phi())/newDDE->dphi()<<")"<<endl; + cout<<" ieta="<<ieta<<" iphi="<<iphi<<endl; + cout<<" dist_eta0="<<dist_eta0<<" ,dist_phi0="<<dist_phi0<<endl; + } + + if(*distance<0) return newDDE; + //correct ieta and iphi by the observed difference to the hit cell + ieta+=TMath::Nint(dist_eta0); + iphi+=TMath::Nint(dist_phi0); + index_range_adjust(ieta,iphi); + const CaloGeoDetDescrElement* oldDDE=newDDE; + newDDE=m_cell_grid[ieta][iphi]; + ++(*steps); + ++nsearch; + if(oldDDE==newDDE) break; + } + if(CaloGeoGeometry::m_debug && !newDDE) { + cout<<"CaloGeoGeometryLookup::getDDE, direct search ieta="<<ieta<<" iphi="<<iphi<<" is empty"<<endl; + } + float minieta=ieta+TMath::Nint(TMath::Floor(m_mineta_correction/cell_grid_eta())); + float maxieta=ieta+TMath::Nint(TMath::Ceil(m_maxeta_correction/cell_grid_eta())); + float miniphi=iphi+TMath::Nint(TMath::Floor(m_minphi_correction/cell_grid_phi())); + float maxiphi=iphi+TMath::Nint(TMath::Ceil(m_maxphi_correction/cell_grid_phi())); + if(minieta<0) minieta=0; + if(maxieta>=m_cell_grid_eta) maxieta=m_cell_grid_eta-1; + for(int iieta=minieta;iieta<=maxieta;++iieta) { + for(int iiphi=miniphi;iiphi<=maxiphi;++iiphi) { + ieta=iieta; + iphi=iiphi; + index_range_adjust(ieta,iphi); + newDDE=m_cell_grid[ieta][iphi]; + ++(*steps); + if(newDDE) { + float dist_eta0,dist_phi0; + *distance=calculate_distance_eta_phi(newDDE,eta,phi,dist_eta0,dist_phi0); + + if(CaloGeoGeometry::m_debug || CaloGeoGeometry::m_debug_identify==newDDE->identify()) { + cout<<"CaloGeoGeometryLookup::getDDE, windows search! minieta="<<m_mineta_correction/cell_grid_eta()<<" maxieta="<<m_maxeta_correction/cell_grid_eta()<<" miniphi="<<m_minphi_correction/cell_grid_phi()<<" maxiphi="<<m_maxphi_correction/cell_grid_phi()<<endl; + cout<<"cell id="<<newDDE->identify()<<" steps "<<*steps<<" steps, eta="<<eta<<" phi="<<phi<<" dist="<<*distance<<endl; + cout<<" input sampling="<<newDDE->getSampling()<<" eta="<<newDDE->eta()<<" eta_raw="<<newDDE->eta_raw()<<" deta="<<newDDE->deta()<<" ("<<(newDDE->eta_raw()-newDDE->eta())/newDDE->deta()<<") phi="<<newDDE->phi()<<" phi_raw="<<newDDE->phi_raw()<<" dphi="<<newDDE->dphi()<<" ("<<(newDDE->phi_raw()-newDDE->phi())/newDDE->dphi()<<")"<<endl; + cout<<" ieta="<<ieta<<" iphi="<<iphi<<endl; + cout<<" dist_eta0="<<dist_eta0<<" ,dist_phi0="<<dist_phi0<<endl; + } + + if(*distance<0) return newDDE; + if(*distance<bestdist) { + bestDDE=newDDE; + bestdist=*distance; + } + } else if(CaloGeoGeometry::m_debug) { + cout<<"CaloGeoGeometryLookup::getDDE, windows search ieta="<<ieta<<" iphi="<<iphi<<" is empty"<<endl; + } + } + } + *distance=bestdist; + return bestDDE; +} + + + +/* +void CaloGeometryLookup::CalculateTransformation() +{ + gROOT->cd(); + + TTree* tmap = new TTree( "mapping" , "mapping" ); + + float eta,phi,Deta_raw,Dphi_raw; + tmap->Branch("eta", &eta,"eta/F"); + tmap->Branch("phi", &phi,"phi/F"); + tmap->Branch("Deta_raw", &Deta_raw,"Deta_raw/F"); + tmap->Branch("Dphi_raw", &Dphi_raw,"Dphi_raw/F"); + + if(m_cells.size()==0) return; + + int sampling=0; + for(t_cellmap::iterator ic=m_cells.begin();ic!=m_cells.end();++ic) { + CaloGeoDetDescrElement* refcell=ic->second; + sampling=refcell->getSampling(); + if(sampling<21) { + eta=refcell->eta(); + phi=refcell->phi(); + Deta_raw=refcell->eta_raw()-eta; + Dphi_raw=refcell->phi_raw()-phi; + } else { + eta=refcell->x(); + phi=refcell->y(); + Deta_raw=refcell->x_raw()-eta; + Dphi_raw=refcell->y_raw()-phi; + } + tmap->Fill(); + tmap->Fill(); //Fill twice to have all events and training and test tree + } + tmap->Print(); + + TString outfileName( Form("Mapping%d_%d.root",sampling,m_index) ); + TFile* outputFile = new TFile( outfileName, "RECREATE" ); + //TFile* outputFile = new TMemFile( outfileName, "RECREATE" ); + + TMVA::Factory *factory = new TMVA::Factory( Form("Mapping%d_%d.root",sampling,m_index) , outputFile, "!V:!Silent:Color:DrawProgressBar" ); + + factory->AddVariable( "eta", "calo eta", "1", 'F' ); + factory->AddVariable( "phi", "calo phi", "1", 'F' ); + factory->AddTarget( "Deta_raw" ); + factory->AddTarget( "Dphi_raw" ); + + factory->AddRegressionTree( tmap ); + + //factory->PrepareTrainingAndTestTree( "" , Form("nTrain_Regression=%d:nTest_Regression=%d:SplitMode=Random:NormMode=NumEvents:!V",(int)m_cells.size(),(int)m_cells.size()) ); + factory->PrepareTrainingAndTestTree( "" , "nTrain_Regression=0:nTest_Regression=0:SplitMode=Alternate:NormMode=NumEvents:!V" ); + + factory->BookMethod( TMVA::Types::kMLP, "MLP", "!H:!V:VarTransform=Norm:NeuronType=tanh:NCycles=20000:HiddenLayers=N+5:TestRate=6:TrainingMethod=BFGS:Sampling=0.3:SamplingEpoch=0.8:ConvergenceImprove=1e-6:ConvergenceTests=15:!UseRegulator" ); + + cout<<"=== Start trainging ==="<<endl; + // Train MVAs using the set of training events + factory->TrainAllMethods(); + + cout<<"=== Start testing ==="<<endl; + // ---- Evaluate all MVAs using the set of test events + factory->TestAllMethods(); + + cout<<"=== Start evaluation ==="<<endl; + // ----- Evaluate and compare performance of all configured MVAs + factory->EvaluateAllMethods(); + + outputFile->Close(); + + delete factory; + + delete tmap; +} +*/ + +CaloGeoGeometry::CaloGeoGeometry() : m_cells_in_sampling(MAX_SAMPLING),m_cells_in_sampling_for_phi0(MAX_SAMPLING),m_cells_in_regions(MAX_SAMPLING),m_isCaloBarrel(MAX_SAMPLING),m_dographs(false),m_FCal_ChannelMap(0) +{ + //TMVA::Tools::Instance(); + for(int i=0;i<2;++i) { + m_min_eta_sample[i].resize(MAX_SAMPLING); //[side][calosample] + m_max_eta_sample[i].resize(MAX_SAMPLING); //[side][calosample] + m_rmid_map[i].resize(MAX_SAMPLING); //[side][calosample] + m_zmid_map[i].resize(MAX_SAMPLING); //[side][calosample] + m_rent_map[i].resize(MAX_SAMPLING); //[side][calosample] + m_zent_map[i].resize(MAX_SAMPLING); //[side][calosample] + m_rext_map[i].resize(MAX_SAMPLING); //[side][calosample] + m_zext_map[i].resize(MAX_SAMPLING); //[side][calosample] + } + m_graph_layers.resize(MAX_SAMPLING); + for(int i=CaloCell_ID_FCS::FirstSample;i<CaloCell_ID_FCS::MaxSample;++i) { + m_graph_layers[i]=0; + CaloSampling::CaloSample s=static_cast<CaloSampling::CaloSample>(i); + m_isCaloBarrel[i]=(CaloSampling::barrelPattern() & CaloSampling::getSamplingPattern(s))!=0; + } + m_isCaloBarrel[CaloCell_ID_FCS::TileGap3]=false; +} + +CaloGeoGeometry::~CaloGeoGeometry() +{ +} + +void CaloGeoGeometry::addcell(const CaloGeoDetDescrElement* cell) +{ + int sampling=cell->getSampling(); + Identifier identify=cell->identify(); + + //m_cells[identify]=cell; + //m_cells_in_sampling[sampling][identify]=cell; + + m_cells[identify]= new CaloGeoDetDescrElement(*cell); + m_cells_in_sampling[sampling][identify]= new CaloGeoDetDescrElement(*cell); + + CaloGeoGeometryLookup* lookup=0; + for(unsigned int i=0;i<m_cells_in_regions[sampling].size();++i) { + if(m_cells_in_regions[sampling][i]->IsCompatible(cell)) { + lookup=m_cells_in_regions[sampling][i]; + //cout<<sampling<<": found compatible map"<<endl; + break; + } + } + if(!lookup) { + lookup=new CaloGeoGeometryLookup(m_cells_in_regions[sampling].size()); + m_cells_in_regions[sampling].push_back(lookup); + } + lookup->add(cell); +} + +void CaloGeoGeometry::PrintMapInfo(int i, int j) +{ + cout<<" map "<<j<<": "<<m_cells_in_regions[i][j]->size()<<" cells"; + if(i<21) { + cout<<", "<<m_cells_in_regions[i][j]->cell_grid_eta()<<"*"<<m_cells_in_regions[i][j]->cell_grid_phi(); + cout<<", deta="<<m_cells_in_regions[i][j]->deta().mean()<<"+-"<<m_cells_in_regions[i][j]->deta().rms(); + cout<<", dphi="<<m_cells_in_regions[i][j]->dphi().mean()<<"+-"<<m_cells_in_regions[i][j]->dphi().rms(); + cout<<", mineta="<<m_cells_in_regions[i][j]->mineta()<<", maxeta="<<m_cells_in_regions[i][j]->maxeta(); + cout<<", minphi="<<m_cells_in_regions[i][j]->minphi()<<", maxphi="<<m_cells_in_regions[i][j]->maxphi(); + cout<<endl<<" "; + cout<<", mineta_raw="<<m_cells_in_regions[i][j]->mineta_raw()<<", maxeta_raw="<<m_cells_in_regions[i][j]->maxeta_raw(); + cout<<", minphi_raw="<<m_cells_in_regions[i][j]->minphi_raw()<<", maxphi_raw="<<m_cells_in_regions[i][j]->maxphi_raw(); + cout<<endl; + } else { + cout<<", "<<m_cells_in_regions[i][j]->cell_grid_eta()<<"*"<<m_cells_in_regions[i][j]->cell_grid_phi(); + cout<<", dx="<<m_cells_in_regions[i][j]->dx().mean()<<"+-"<<m_cells_in_regions[i][j]->dx().rms(); + cout<<", dy="<<m_cells_in_regions[i][j]->dy().mean()<<"+-"<<m_cells_in_regions[i][j]->dy().rms(); + cout<<", mindx="<<m_cells_in_regions[i][j]->mindx(); + cout<<", mindy="<<m_cells_in_regions[i][j]->mindy(); + cout<<", minx="<<m_cells_in_regions[i][j]->minx()<<", maxx="<<m_cells_in_regions[i][j]->maxx(); + cout<<", miny="<<m_cells_in_regions[i][j]->miny()<<", maxy="<<m_cells_in_regions[i][j]->maxy(); + cout<<endl<<" "; + cout<<", minx_raw="<<m_cells_in_regions[i][j]->minx_raw()<<", maxx_raw="<<m_cells_in_regions[i][j]->maxx_raw(); + cout<<", miny_raw="<<m_cells_in_regions[i][j]->miny_raw()<<", maxy_raw="<<m_cells_in_regions[i][j]->maxy_raw(); + cout<<endl; + } +} + +void CaloGeoGeometry::post_process(int sampling) +{ + //cout<<"post processing sampling "<<sampling<<endl; + bool found_overlap=false; + for(unsigned int j=0;j<m_cells_in_regions[sampling].size();++j) { + /* + cout<<"Sample "<<sampling<<": checking map "<<j<<"/"<<m_cells_in_regions[sampling].size(); + for(unsigned int k=0;k<m_cells_in_regions[sampling].size();++k) { + cout<<", "<<k<<":"<<m_cells_in_regions[sampling][k]->size(); + } + cout<<endl; + */ + for(unsigned int i=j+1;i<m_cells_in_regions[sampling].size();++i) { + if(m_cells_in_regions[sampling][i]->has_overlap(m_cells_in_regions[sampling][j])) { + if(!found_overlap) { + cout<<"Sample "<<sampling<<", starting maps : "<<m_cells_in_regions[sampling].size(); + for(unsigned int k=0;k<m_cells_in_regions[sampling].size();++k) { + cout<<", "<<k<<":"<<m_cells_in_regions[sampling][k]->size(); + } + cout<<endl; + } + found_overlap=true; + /* + cout<<"Sample "<<sampling<<": Found overlap between map "<<j<<" and "<<i<<", " + <<m_cells_in_regions[sampling].size()<<" total maps"<<endl; + cout<<" current configuration map "<<j<<"/"<<m_cells_in_regions[sampling].size(); + for(unsigned int k=0;k<m_cells_in_regions[sampling].size();++k) { + cout<<", "<<k<<":"<<m_cells_in_regions[sampling][k]->size(); + } + cout<<endl; + + PrintMapInfo(sampling,j); + PrintMapInfo(sampling,i); + */ + + CaloGeoGeometryLookup* toremove=m_cells_in_regions[sampling][i]; + toremove->merge_into_ref(m_cells_in_regions[sampling][j]); + + /* + cout<<" New "; + PrintMapInfo(sampling,j); + */ + + for(unsigned int k=i;k<m_cells_in_regions[sampling].size()-1;++k) { + m_cells_in_regions[sampling][k]=m_cells_in_regions[sampling][k+1]; + m_cells_in_regions[sampling][k]->set_index(k); + } + m_cells_in_regions[sampling].resize(m_cells_in_regions[sampling].size()-1); + + /* + cout<<" new configuration map "<<j<<"/"<<m_cells_in_regions[sampling].size(); + for(unsigned int k=0;k<m_cells_in_regions[sampling].size();++k) { + cout<<", "<<k<<":"<<m_cells_in_regions[sampling][k]->size(); + } + cout<<endl; + */ + + --i; + } + } + } + + if(found_overlap) { + cout<<"Sample "<<sampling<<", final maps : "<<m_cells_in_regions[sampling].size(); + for(unsigned int k=0;k<m_cells_in_regions[sampling].size();++k) { + cout<<", "<<k<<":"<<m_cells_in_regions[sampling][k]->size(); + } + cout<<endl; + } + + if(found_overlap) { + cout<<"Run another round of "; + post_process(sampling); + } +} + +void CaloGeoGeometry::InitRZmaps() +{ + std::cout<<"CHECKME InitRZmaps"<<std::endl; + + int nok=0; + + FSmap< double , double > rz_map_eta [2][MAX_SAMPLING]; + FSmap< double , double > rz_map_rmid[2][MAX_SAMPLING]; + FSmap< double , double > rz_map_zmid[2][MAX_SAMPLING]; + FSmap< double , double > rz_map_rent[2][MAX_SAMPLING]; + FSmap< double , double > rz_map_zent[2][MAX_SAMPLING]; + FSmap< double , double > rz_map_rext[2][MAX_SAMPLING]; + FSmap< double , double > rz_map_zext[2][MAX_SAMPLING]; + FSmap< double , int > rz_map_n [2][MAX_SAMPLING]; + + + for(int side=0;side<=1;++side) for(int sample=0;sample<MAX_SAMPLING;++sample) + { + m_min_eta_sample[side][sample]=+1000; + m_max_eta_sample[side][sample]=-1000; + } + + + for(t_cellmap::iterator calo_iter=m_cells.begin();calo_iter!=m_cells.end();++calo_iter) + { + const CaloGeoDetDescrElement* theDDE=(*calo_iter).second; + + if(theDDE) + { + ++nok; + int sample=theDDE->getSampling(); + + int side=0; + int sign_side=-1; + double eta_raw=theDDE->eta_raw(); + if(eta_raw>0) { + side=1; + sign_side=+1; + } + + if(!m_cells_in_sampling_for_phi0[sample][eta_raw]) { + m_cells_in_sampling_for_phi0[sample][eta_raw]=theDDE; + } else { + if(TMath::Abs(theDDE->phi()) < TMath::Abs(m_cells_in_sampling_for_phi0[sample][eta_raw]->phi())) { + m_cells_in_sampling_for_phi0[sample][eta_raw]=theDDE; + } + } + + double min_eta=theDDE->eta()-theDDE->deta()/2; + double max_eta=theDDE->eta()+theDDE->deta()/2; + if(min_eta<m_min_eta_sample[side][sample]) m_min_eta_sample[side][sample]=min_eta; + if(max_eta>m_max_eta_sample[side][sample]) m_max_eta_sample[side][sample]=max_eta; + + if(rz_map_eta[side][sample].find(eta_raw)==rz_map_eta[side][sample].end()) { + rz_map_eta [side][sample][eta_raw]=0; + rz_map_rmid[side][sample][eta_raw]=0; + rz_map_zmid[side][sample][eta_raw]=0; + rz_map_rent[side][sample][eta_raw]=0; + rz_map_zent[side][sample][eta_raw]=0; + rz_map_rext[side][sample][eta_raw]=0; + rz_map_zext[side][sample][eta_raw]=0; + rz_map_n [side][sample][eta_raw]=0; + } + rz_map_eta [side][sample][eta_raw]+=theDDE->eta(); + rz_map_rmid[side][sample][eta_raw]+=theDDE->r(); + rz_map_zmid[side][sample][eta_raw]+=theDDE->z(); + double drh=theDDE->dr()/2; + double dzh=theDDE->dz(); + if(sample>=CaloSampling::PreSamplerB && sample<=CaloSampling::EMB3) { + drh=theDDE->dr(); + } + rz_map_rent[side][sample][eta_raw]+=theDDE->r()-drh; + rz_map_zent[side][sample][eta_raw]+=theDDE->z()-dzh*sign_side; + rz_map_rext[side][sample][eta_raw]+=theDDE->r()+drh; + rz_map_zext[side][sample][eta_raw]+=theDDE->z()+dzh*sign_side; + rz_map_n [side][sample][eta_raw]++; + + } + } + + for(int side=0;side<=1;++side) + { + for(int sample=0;sample<MAX_SAMPLING;++sample) + { + + if(rz_map_n[side][sample].size()>0) + { + for(FSmap< double , int >::iterator iter=rz_map_n[side][sample].begin();iter!=rz_map_n[side][sample].end();++iter) + { + double eta_raw=iter->first; + if(iter->second<1) + { + //ATH_MSG_WARNING("rz-map for side="<<side<<" sample="<<sample<<" eta_raw="<<eta_raw<<" : #cells="<<iter->second<<" !!!"); + } + else + { + double eta =rz_map_eta[side][sample][eta_raw]/iter->second; + double rmid=rz_map_rmid[side][sample][eta_raw]/iter->second; + double zmid=rz_map_zmid[side][sample][eta_raw]/iter->second; + double rent=rz_map_rent[side][sample][eta_raw]/iter->second; + double zent=rz_map_zent[side][sample][eta_raw]/iter->second; + double rext=rz_map_rext[side][sample][eta_raw]/iter->second; + double zext=rz_map_zext[side][sample][eta_raw]/iter->second; + + m_rmid_map[side][sample][eta]=rmid; + m_zmid_map[side][sample][eta]=zmid; + + + + m_rent_map[side][sample][eta]=rent; + + + m_zent_map[side][sample][eta]=zent; + m_rext_map[side][sample][eta]=rext; + m_zext_map[side][sample][eta]=zext; + } + } + //ATH_MSG_DEBUG("rz-map for side="<<side<<" sample="<<sample<<" #etas="<<m_rmid_map[side][sample].size()); + } + else + { + std::cout<<"rz-map for side="<<side<<" sample="<<sample<<" is empty!!!"<<std::endl; + } + } //sample + } //side + + if(DoGraphs()) { + int calocol[24]={1,2,3,4, // LAr barrel + 1,2,3,4, // LAr EM endcap + 1,2,3,4, // Hadronic end cap cal. + 1,2,3, // Tile barrel + 6,28,42, // Tile gap (ITC & scint) + 1,2,3, // Tile extended barrel + 1,2,3 // Forward EM endcap + }; + + for(int sample=0;sample<MAX_SAMPLING;++sample) { + m_graph_layers[sample]=new TGraphErrors(rz_map_n[0][sample].size()+rz_map_n[1][sample].size()); + m_graph_layers[sample]->SetMarkerColor(calocol[sample]); + m_graph_layers[sample]->SetLineColor(calocol[sample]); + int np=0; + for(int side=0;side<=1;++side) { + for(FSmap< double , int >::iterator iter=rz_map_n[side][sample].begin();iter!=rz_map_n[side][sample].end();++iter) { + double eta_raw=iter->first; + int sign_side=-1; + if(eta_raw>0) sign_side=+1; + //double eta =rz_map_eta[side][sample][eta_raw]/iter->second; + double rmid=rz_map_rmid[side][sample][eta_raw]/iter->second; + double zmid=rz_map_zmid[side][sample][eta_raw]/iter->second; + //double rent=rz_map_rent[side][sample][eta_raw]/iter->second; + //double zent=rz_map_zent[side][sample][eta_raw]/iter->second; + double rext=rz_map_rext[side][sample][eta_raw]/iter->second; + double zext=rz_map_zext[side][sample][eta_raw]/iter->second; + m_graph_layers[sample]->SetPoint(np,zmid,rmid); + /* + if(isCaloBarrel(sample)) { + m_graph_layers[sample]->SetPointError(np,0,rext-rmid); + } else { + m_graph_layers[sample]->SetPointError(np,(zext-zent)*sign_side,0); + } + */ + m_graph_layers[sample]->SetPointError(np,(zext-zmid)*sign_side,rext-rmid); + ++np; + } + } + } + } +} + +TCanvas* CaloGeoGeometry::DrawGeoForPhi0() +{ + TCanvas* c=new TCanvas("CaloGeoForPhi0","Calo geometry for #phi~0"); + TH2D* hcalolayout=new TH2D("hcalolayoutPhi0","Reconstruction geometry: calorimeter layout;z [mm];r [mm]",50,-7000,7000,50,0,4000); + hcalolayout->Draw(); + hcalolayout->SetStats(0); + hcalolayout->GetYaxis()->SetTitleOffset(1.4); + + int calocol[MAX_SAMPLING]={1,2,3,4, // LAr barrel + 1,2,3,4, // LAr EM endcap + 1,2,3,4, // Hadronic end cap cal. + 1,2,3, // Tile barrel + -42,-28,-6, // Tile gap (ITC & scint) + 1,2,3, // Tile extended barrel + 1,2,3 // Forward EM endcap + }; + + TLegend* leg=new TLegend(0.30,0.13,0.70,0.37); + leg->SetFillStyle(0); + leg->SetFillColor(10); + leg->SetBorderSize(1); + leg->SetNColumns(2); + + for(int sample=0;sample<MAX_SAMPLING;++sample) { +// for(int sample=21;sample<22;++sample) { + cout<<"Start sample "<<sample<<" ("<<SamplingName(sample)<<")"<<endl; + int ngr=0; + for(t_eta_cellmap::iterator calo_iter=m_cells_in_sampling_for_phi0[sample].begin();calo_iter!=m_cells_in_sampling_for_phi0[sample].end();++calo_iter) { + const CaloGeoDetDescrElement* theDDE=(*calo_iter).second; + if(theDDE) { + TVector3 cv; + TGraph* gr=new TGraph(5); + gr->SetLineColor(TMath::Abs(calocol[sample])); + gr->SetFillColor(TMath::Abs(calocol[sample])); + if(calocol[sample]<0) { + gr->SetFillStyle(1001); + } else { + gr->SetFillStyle(0); + } + gr->SetLineWidth(2); + double r=theDDE->r(); + double dr=theDDE->dr(); + double x=theDDE->x(); + double dx=theDDE->dx(); + double y=theDDE->y(); + double dy=theDDE->dy(); + double z=theDDE->z(); + double dz=theDDE->dz()*2; + double eta=theDDE->eta(); + double deta=theDDE->deta(); + if(CaloSampling::PreSamplerB<=sample && sample<=CaloSampling::EMB3) { + dr*=2; + } + + if(isCaloBarrel(sample)) { + cv.SetPtEtaPhi(r-dr/2,eta-deta/2,0); + gr->SetPoint(0,cv.Z(),cv.Pt()); + gr->SetPoint(4,cv.Z(),cv.Pt()); + cv.SetPtEtaPhi(r-dr/2,eta+deta/2,0); + gr->SetPoint(1,cv.Z(),cv.Pt()); + cv.SetPtEtaPhi(r+dr/2,eta+deta/2,0); + gr->SetPoint(2,cv.Z(),cv.Pt()); + cv.SetPtEtaPhi(r+dr/2,eta-deta/2,0); + gr->SetPoint(3,cv.Z(),cv.Pt()); + } else { + if(sample<CaloSampling::FCAL0) { + cv.SetPtEtaPhi(1,eta-deta/2,0);cv*=(z-dz/2)/cv.Z(); + gr->SetPoint(0,cv.Z(),cv.Pt()); + gr->SetPoint(4,cv.Z(),cv.Pt()); + cv.SetPtEtaPhi(1,eta+deta/2,0);cv*=(z-dz/2)/cv.Z(); + gr->SetPoint(1,cv.Z(),cv.Pt()); + cv.SetPtEtaPhi(1,eta+deta/2,0);cv*=(z+dz/2)/cv.Z(); + gr->SetPoint(2,cv.Z(),cv.Pt()); + cv.SetPtEtaPhi(1,eta-deta/2,0);cv*=(z+dz/2)/cv.Z(); + gr->SetPoint(3,cv.Z(),cv.Pt()); + } else { + double minr=r; + double maxr=r; + for(double px=x-dx/2;px<=x+dx/2;px+=dx) { + for(double py=y-dy/2;py<=y+dy/2;py+=dy) { + double pr=TMath::Sqrt(px*px+py*py); + minr=TMath::Min(minr,pr); + maxr=TMath::Max(maxr,pr); + } + } + cv.SetXYZ(minr,0,z-dz/2); + gr->SetPoint(0,cv.Z(),cv.Pt()); + gr->SetPoint(4,cv.Z(),cv.Pt()); + cv.SetXYZ(maxr,0,z-dz/2); + gr->SetPoint(1,cv.Z(),cv.Pt()); + cv.SetXYZ(maxr,0,z+dz/2); + gr->SetPoint(2,cv.Z(),cv.Pt()); + cv.SetXYZ(minr,0,z+dz/2); + gr->SetPoint(3,cv.Z(),cv.Pt()); + } + } + //if(calocol[sample]>0) gr->Draw("Lsame"); + // else gr->Draw("LFsame"); + gr->Draw("LFsame"); + if(ngr==0) { + std::string sname=Form("Sampling %2d : ",sample); + sname+=SamplingName(sample); + leg->AddEntry(gr,sname.c_str(),"LF"); + } + ++ngr; + } + } + cout<<"Done sample "<<sample<<" ("<<SamplingName(sample)<<")="<<ngr<<endl; + } + leg->Draw(); + return c; +} + +const CaloGeoDetDescrElement* CaloGeoGeometry::getDDE(Identifier identify) +{ + return m_cells[identify]; +} +const CaloGeoDetDescrElement* CaloGeoGeometry::getDDE(int sampling,Identifier identify) +{ + return m_cells_in_sampling[sampling][identify]; +} + +const CaloGeoDetDescrElement* CaloGeoGeometry::getDDE(int sampling,float eta,float phi,float* distance,int* steps) +{ + if(sampling<0) return 0; + if(sampling>=MAX_SAMPLING) return 0; + if(m_cells_in_regions[sampling].size()==0) return 0; + + float dist; + const CaloGeoDetDescrElement* bestDDE=0; + if(!distance) distance=&dist; + *distance=+10000000; + int intsteps; + int beststeps; + if(steps) beststeps=(*steps); + else beststeps=0; + + if(sampling<21) { + for(int skip_range_check=0;skip_range_check<=1;++skip_range_check) { + for(unsigned int j=0;j<m_cells_in_regions[sampling].size();++j) { + if(!skip_range_check) { + if(eta<m_cells_in_regions[sampling][j]->mineta()) continue; + if(eta>m_cells_in_regions[sampling][j]->maxeta()) continue; + } + if(steps) intsteps=(*steps); + else intsteps=0; + if(m_debug) { + cout<<"CaloGeoGeometry::getDDE : check map"<<j<<" skip_range_check="<<skip_range_check<<endl; + } + float newdist; + const CaloGeoDetDescrElement* newDDE=m_cells_in_regions[sampling][j]->getDDE(eta,phi,&newdist,&intsteps); + if(m_debug) { + cout<<"CaloGeoGeometry::getDDE : map"<<j<<" dist="<<newdist<<" best dist="<<*distance<<" steps="<<intsteps<<endl; + } + if(newdist<*distance) { + bestDDE=newDDE; + *distance=newdist; + if(steps) beststeps=intsteps; + if(newdist<-0.1) break; //stop, we are well within the hit cell + } + } + if(bestDDE) break; + } + } else { + return 0; + //for(int skip_range_check=0;skip_range_check<=1;++skip_range_check) { + //for(unsigned int j=0;j<m_cells_in_regions[sampling].size();++j) { + //if(!skip_range_check) { + //if(eta<m_cells_in_regions[sampling][j]->minx()) continue; + //if(eta>m_cells_in_regions[sampling][j]->maxx()) continue; + //if(phi<m_cells_in_regions[sampling][j]->miny()) continue; + //if(phi>m_cells_in_regions[sampling][j]->maxy()) continue; + //} + //if(steps) intsteps=*steps; + //else intsteps=0; + //if(m_debug) { + //cout<<"CaloGeoGeometry::getDDE : check map"<<j<<" skip_range_check="<<skip_range_check<<endl; + //} + //float newdist; + //const CaloGeoDetDescrElement* newDDE=m_cells_in_regions[sampling][j]->getDDE(eta,phi,&newdist,&intsteps); + //if(m_debug) { + //cout<<"CaloGeoGeometry::getDDE : map"<<j<<" dist="<<newdist<<" best dist="<<*distance<<" steps="<<intsteps<<endl; + //} + //if(newdist<*distance) { + //bestDDE=newDDE; + //*distance=newdist; + //if(steps) beststeps=intsteps; + //if(newdist<-0.1) break; //stop, we are well within the hit cell + //} + //} + //if(bestDDE) break; + //} + } + if(steps) *steps=beststeps; + return bestDDE; +} + +const CaloGeoDetDescrElement* CaloGeoGeometry::getFCalDDE(int sampling,float x,float y,float z){ + int isam = sampling - 20; + int iphi,ieta; + Long64_t mask1[]{0x34,0x34,0x35}; + Long64_t mask2[]{0x36,0x36,0x37}; + m_FCal_ChannelMap.getTileID(isam, x, y, ieta, iphi); + //cout << ieta << "" + Long64_t id = (ieta << 5) + 2*iphi; + if(isam==2)id+= (8<<8); + + if(z>0) id+=(mask2[isam-1] << 12); + else id+=(mask1[isam-1] << 12); + //if(z<0) cout << "CaloGeoGeometry::getFCalDDE: Identifier: " << (id << 44) << " " << m_cells[id << 44]->identify() << endl; + id = id << 44; + Identifier identify((unsigned long long)id); + return m_cells[identify]; + //return m_cells_in_sampling[sampling][id << 12]; +} + + +bool CaloGeoGeometry::PostProcessGeometry() +{ + for(int i=0;i<MAX_SAMPLING;++i) { + post_process(i); + for(unsigned int j=0;j<m_cells_in_regions[i].size();++j) { + m_cells_in_regions[i][j]->post_process(); + } + //if(i>=21) break; + } + + InitRZmaps(); + + /* + cout<<"all : "<<m_cells.size()<<endl; + for(int sampling=0;sampling<MAX_SAMPLING;++sampling) { + cout<<"cells sampling "<<sampling<<" : "<<m_cells_in_sampling[sampling].size()<<" cells"; + cout<<", "<<m_cells_in_regions[sampling].size()<<" lookup map(s)"<<endl; + for(unsigned int j=0;j<m_cells_in_regions[sampling].size();++j) { + PrintMapInfo(sampling,j); + //break; + } + //if(i>0) break; + } + */ + + return true; +} + +void CaloGeoGeometry::Validate() +{ + int ntest=0; + cout<<"start CaloGeoGeometry::Validate()"<<endl; + for(t_cellmap::iterator ic=m_cells.begin();ic!=m_cells.end();++ic) { + const CaloGeoDetDescrElement* cell=ic->second; + int sampling=cell->getSampling(); + if(sampling>=21) continue; + + if(m_debug_identify==cell->identify()) { + cout<<"CaloGeoGeometry::Validate(), cell "<<ntest<<" id="<<cell->identify()<<endl; + m_debug=true; + } + + const int nrnd=100; + for(int irnd=0;irnd<nrnd;++irnd) { + int steps=0; + float eta=cell->eta()+1.5*(gRandom->Rndm()-0.5)*cell->deta(); + float phi=cell->phi()+1.5*(gRandom->Rndm()-0.5)*cell->dphi(); + float distance; + const CaloGeoDetDescrElement* foundcell=getDDE(sampling,eta,phi,&distance,&steps); + if(m_debug && foundcell) { + cout<<"CaloGeoGeometry::Validate(), irnd="<<irnd<<", foundcell id="<<foundcell->identify()<<", "<<steps<<" steps"<<endl; + } + if(cell==foundcell) { + if(steps>3 && distance<-0.01) { + cout<<"cell id="<<cell->identify()<<", sampling="<<sampling<<" found in "<<steps<<" steps, dist="<<distance<<" eta="<<eta<<" phi="<<phi<<endl; + cout<<" eta="<<cell->eta()<<" eta_raw="<<cell->eta_raw()<<" deta="<<cell->deta()<<" ("<<(cell->eta_raw()-cell->eta())/cell->deta()<<") phi="<<cell->phi()<<" phi_raw="<<cell->phi_raw()<<" dphi="<<cell->dphi()<<" ("<<(cell->phi_raw()-cell->phi())/cell->dphi()<<")"<<endl; + //if(steps>3 && distance>0.01) return; + } + } else { + if( TMath::Abs( (eta-cell->eta())/cell->deta() )<0.45 && TMath::Abs( (phi-cell->phi())/cell->dphi() )<0.45 ) { + cout<<"cell id="<<cell->identify()<<" not found! Found instead id="; + if (foundcell) cout << foundcell->identify(); + cout <<" in "<<steps<<" steps, dist="<<distance<<" eta="<<eta<<" phi="<<phi<<endl; + cout<<" input sampling="<<sampling<<" eta="<<cell->eta()<<" eta_raw="<<cell->eta_raw()<<" deta="<<cell->deta()<<" ("<<(cell->eta_raw()-cell->eta())/cell->deta()<<") phi="<<cell->phi()<<" phi_raw="<<cell->phi_raw()<<" dphi="<<cell->dphi()<<" ("<<(cell->phi_raw()-cell->phi())/cell->dphi()<<")"<<endl; + cout<<" output sampling="<<(foundcell?(foundcell->getSampling()):-1)<<" eta="<<(foundcell?(foundcell->eta()):0)<<" eta_raw="<<(foundcell?(foundcell->eta_raw()):0)<<" deta="<<(foundcell?(foundcell->deta()):0)<<" ("<<(foundcell?((foundcell->eta_raw()-foundcell->eta())/foundcell->deta()):0)<<") phi="<<(foundcell?(foundcell->phi()):0)<<" phi_raw="<<(foundcell?(foundcell->phi_raw()):0)<<" dphi="<<(foundcell?(foundcell->dphi()):0)<<" ("<<(foundcell?((foundcell->phi_raw()-foundcell->phi())/cell->dphi()):0)<<")"<<endl; + return; + } + if(!foundcell) { + cout<<"nothing found close to cell id="<<cell->identify()<<" in "<<steps<<" steps, dist="<<distance<<" eta="<<eta<<" phi="<<phi<<endl; + cout<<" input sampling="<<sampling<<" eta="<<cell->eta()<<" eta_raw="<<cell->eta_raw()<<" deta="<<cell->deta()<<" ("<<(cell->eta_raw()-cell->eta())/cell->deta()<<") phi="<<cell->phi()<<" phi_raw="<<cell->phi_raw()<<" dphi="<<cell->dphi()<<" ("<<(cell->phi_raw()-cell->phi())/cell->dphi()<<")"<<endl; + return; + } + } + //if(ntest>60000) break; + } + m_debug=false; + if(ntest%25000==0) cout<<"Validate cell "<<ntest<<" with "<<nrnd<<" random hits"<<endl; + ++ntest; + } + cout<<"end CaloGeoGeometry::Validate()"<<endl; +} + +double CaloGeoGeometry::deta(int sample,double eta) const +{ + int side=0; + if(eta>0) side=1; + + double mineta=m_min_eta_sample[side][sample]; + double maxeta=m_max_eta_sample[side][sample]; + + if(eta<mineta) + { + return fabs(eta-mineta); + } + else if(eta>maxeta) + { + return fabs(eta-maxeta); + } + else + { + double d1=fabs(eta-mineta); + double d2=fabs(eta-maxeta); + if(d1<d2) return -d1; + else return -d2; + } +} + + +void CaloGeoGeometry::minmaxeta(int sample,double eta,double& mineta,double& maxeta) const +{ + int side=0; + if(eta>0) side=1; + + mineta=m_min_eta_sample[side][sample]; + maxeta=m_max_eta_sample[side][sample]; +} + +double CaloGeoGeometry::rmid(int sample,double eta) const +{ + int side=0; + if(eta>0) side=1; + + return m_rmid_map[side][sample].find_closest(eta)->second; +} + +double CaloGeoGeometry::zmid(int sample,double eta) const +{ + int side=0; + if(eta>0) side=1; + + return m_zmid_map[side][sample].find_closest(eta)->second; +} + +double CaloGeoGeometry::rzmid(int sample,double eta) const +{ + int side=0; + if(eta>0) side=1; + + if(isCaloBarrel(sample)) return m_rmid_map[side][sample].find_closest(eta)->second; + else return m_zmid_map[side][sample].find_closest(eta)->second; +} + +double CaloGeoGeometry::rent(int sample,double eta) const +{ + int side=0; + if(eta>0) side=1; + + return m_rent_map[side][sample].find_closest(eta)->second; +} + +double CaloGeoGeometry::zent(int sample,double eta) const +{ + int side=0; + if(eta>0) side=1; + + return m_zent_map[side][sample].find_closest(eta)->second; +} + +double CaloGeoGeometry::rzent(int sample,double eta) const +{ + int side=0; + if(eta>0) side=1; + + if(isCaloBarrel(sample)) return m_rent_map[side][sample].find_closest(eta)->second; + else return m_zent_map[side][sample].find_closest(eta)->second; +} + +double CaloGeoGeometry::rext(int sample,double eta) const +{ + int side=0; + if(eta>0) side=1; + + return m_rext_map[side][sample].find_closest(eta)->second; +} + +double CaloGeoGeometry::zext(int sample,double eta) const +{ + int side=0; + if(eta>0) side=1; + + return m_zext_map[side][sample].find_closest(eta)->second; +} + +double CaloGeoGeometry::rzext(int sample,double eta) const +{ + int side=0; + if(eta>0) side=1; + + if(isCaloBarrel(sample)) return m_rext_map[side][sample].find_closest(eta)->second; + else return m_zext_map[side][sample].find_closest(eta)->second; +} + +double CaloGeoGeometry::rpos(int sample,double eta,int subpos) const +{ + + int side=0; + if(eta>0) side=1; + + if(subpos==CaloSubPos::SUBPOS_ENT) return m_rent_map[side][sample].find_closest(eta)->second; + if(subpos==CaloSubPos::SUBPOS_EXT) return m_rext_map[side][sample].find_closest(eta)->second; + + return m_rmid_map[side][sample].find_closest(eta)->second; +} + +double CaloGeoGeometry::zpos(int sample,double eta,int subpos) const +{ + int side=0; + if(eta>0) side=1; + + if(subpos==CaloSubPos::SUBPOS_ENT) return m_zent_map[side][sample].find_closest(eta)->second; + if(subpos==CaloSubPos::SUBPOS_EXT) return m_zext_map[side][sample].find_closest(eta)->second; + return m_zmid_map[side][sample].find_closest(eta)->second; +} + +double CaloGeoGeometry::rzpos(int sample,double eta,int subpos) const +{ + int side=0; + if(eta>0) side=1; + + if(isCaloBarrel(sample)) { + if(subpos==CaloSubPos::SUBPOS_ENT) return m_rent_map[side][sample].find_closest(eta)->second; + if(subpos==CaloSubPos::SUBPOS_EXT) return m_rext_map[side][sample].find_closest(eta)->second; + return m_rmid_map[side][sample].find_closest(eta)->second; + } else { + if(subpos==CaloSubPos::SUBPOS_ENT) return m_zent_map[side][sample].find_closest(eta)->second; + if(subpos==CaloSubPos::SUBPOS_EXT) return m_zext_map[side][sample].find_closest(eta)->second; + return m_zmid_map[side][sample].find_closest(eta)->second; + } +} + +std::string CaloGeoGeometry::SamplingName(int sample) +{ + return CaloSampling::getSamplingName(sample); +} + diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/CaloGeometry.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/CaloGeometry.cxx index b29503c6fd6e..6caff6fc20be 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/CaloGeometry.cxx +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/CaloGeometry.cxx @@ -12,8 +12,8 @@ #include <TVector3.h> #include <TLegend.h> -//#include "CaloDetDescr/CaloDetDescrElement.h" -#include "ISF_FastCaloSimParametrization/CaloDetDescrElement.h" +#include "CaloDetDescr/CaloDetDescrElement.h" +//#include "ISF_FastCaloSimParametrization/CaloDetDescrElement.h" #include "CaloGeoHelpers/CaloSampling.h" #include "ISF_FastCaloSimEvent/FastCaloSim_CaloCell_ID.h" //#include "TMVA/Tools.h" @@ -60,7 +60,7 @@ bool CaloGeometryLookup::has_overlap(CaloGeometryLookup* ref) { if(m_cells.size()==0) return false; for(t_cellmap::iterator ic=m_cells.begin();ic!=m_cells.end();++ic) { - const CaloGeoDetDescrElement* cell=ic->second; + const CaloDetDescrElement* cell=ic->second; if(ref->IsCompatible(cell)) return true; } return false; @@ -69,17 +69,17 @@ bool CaloGeometryLookup::has_overlap(CaloGeometryLookup* ref) void CaloGeometryLookup::merge_into_ref(CaloGeometryLookup* ref) { for(t_cellmap::iterator ic=m_cells.begin();ic!=m_cells.end();++ic) { - const CaloGeoDetDescrElement* cell=ic->second; + const CaloDetDescrElement* cell=ic->second; ref->add(cell); } } -bool CaloGeometryLookup::IsCompatible(const CaloGeoDetDescrElement* cell) +bool CaloGeometryLookup::IsCompatible(const CaloDetDescrElement* cell) { if(m_cells.size()==0) return true; t_cellmap::iterator ic=m_cells.begin(); - const CaloGeoDetDescrElement* refcell=ic->second; + const CaloDetDescrElement* refcell=ic->second; int sampling=refcell->getSampling(); if(cell->getSampling()!=sampling) return false; if(cell->eta_raw()*refcell->eta_raw()<0) return false; @@ -125,7 +125,7 @@ bool CaloGeometryLookup::IsCompatible(const CaloGeoDetDescrElement* cell) return true; } -void CaloGeometryLookup::add(const CaloGeoDetDescrElement* cell) +void CaloGeometryLookup::add(const CaloDetDescrElement* cell) { if(cell->getSampling()<21) { m_deta.add(cell->deta()); @@ -194,7 +194,7 @@ void CaloGeometryLookup::post_process() { if(size()==0) return; t_cellmap::iterator ic=m_cells.begin(); - const CaloGeoDetDescrElement* refcell=ic->second; + const CaloDetDescrElement* refcell=ic->second; int sampling=refcell->getSampling(); if(sampling<21) { double rneta=neta_double()-neta(); @@ -266,7 +266,7 @@ void CaloGeometryLookup::post_process() // cout<<"Grid: Sampling "<<sampling<<"_"<<index()<<": "<<ncells<<"/"<<size()<<" cells filled, "<<nempty<<" empty grid positions deta="<<m_deta_double<<" dphi="<<m_dphi_double<<endl; } -float CaloGeometryLookup::calculate_distance_eta_phi(const CaloGeoDetDescrElement* DDE,float eta,float phi,float& dist_eta0,float& dist_phi0) +float CaloGeometryLookup::calculate_distance_eta_phi(const CaloDetDescrElement* DDE,float eta,float phi,float& dist_eta0,float& dist_phi0) { dist_eta0=(eta - DDE->eta())/m_deta_double; dist_phi0=(TVector2::Phi_mpi_pi(phi - DDE->phi()))/m_dphi_double; @@ -275,10 +275,10 @@ float CaloGeometryLookup::calculate_distance_eta_phi(const CaloGeoDetDescrElemen return TMath::Max(abs_dist_eta0,abs_dist_phi0)-0.5; } -const CaloGeoDetDescrElement* CaloGeometryLookup::getDDE(float eta,float phi,float* distance,int* steps) +const CaloDetDescrElement* CaloGeometryLookup::getDDE(float eta,float phi,float* distance,int* steps) { float dist; - const CaloGeoDetDescrElement* bestDDE=0; + const CaloDetDescrElement* bestDDE=0; if(!distance) distance=&dist; *distance=+10000000; int intsteps=0; @@ -294,7 +294,7 @@ const CaloGeoDetDescrElement* CaloGeometryLookup::getDDE(float eta,float phi,flo int iphi=raw_phi_position_to_index(raw_phi); index_range_adjust(ieta,iphi); - const CaloGeoDetDescrElement* newDDE=m_cell_grid[ieta][iphi]; + const CaloDetDescrElement* newDDE=m_cell_grid[ieta][iphi]; float bestdist=+10000000; ++(*steps); int nsearch=0; @@ -317,7 +317,7 @@ const CaloGeoDetDescrElement* CaloGeometryLookup::getDDE(float eta,float phi,flo ieta+=TMath::Nint(dist_eta0); iphi+=TMath::Nint(dist_phi0); index_range_adjust(ieta,iphi); - const CaloGeoDetDescrElement* oldDDE=newDDE; + const CaloDetDescrElement* oldDDE=newDDE; newDDE=m_cell_grid[ieta][iphi]; ++(*steps); ++nsearch; @@ -454,7 +454,8 @@ CaloGeometry::CaloGeometry() : m_cells_in_sampling(MAX_SAMPLING),m_cells_in_samp m_zext_map[i].resize(MAX_SAMPLING); //[side][calosample] } m_graph_layers.resize(MAX_SAMPLING); - for(int i=CaloCell_ID_FCS::FirstSample;i<CaloCell_ID_FCS::MaxSample;++i) { +// for(unsigned int i=CaloCell_ID_FCS::FirstSample;i<CaloCell_ID_FCS::MaxSample;++i) { + for(unsigned int i=CaloSampling::PreSamplerB;i<=CaloSampling::FCAL2;++i) { m_graph_layers[i]=0; CaloSampling::CaloSample s=static_cast<CaloSampling::CaloSample>(i); m_isCaloBarrel[i]=(CaloSampling::barrelPattern() & CaloSampling::getSamplingPattern(s))!=0; @@ -466,7 +467,7 @@ CaloGeometry::~CaloGeometry() { } -void CaloGeometry::addcell(const CaloGeoDetDescrElement* cell) +void CaloGeometry::addcell(const CaloDetDescrElement* cell) { int sampling=cell->getSampling(); Identifier identify=cell->identify(); @@ -474,8 +475,8 @@ void CaloGeometry::addcell(const CaloGeoDetDescrElement* cell) //m_cells[identify]=cell; //m_cells_in_sampling[sampling][identify]=cell; - m_cells[identify]= new CaloGeoDetDescrElement(*cell); - m_cells_in_sampling[sampling][identify]= new CaloGeoDetDescrElement(*cell); + m_cells[identify]= new CaloDetDescrElement(*cell); + m_cells_in_sampling[sampling][identify]= new CaloDetDescrElement(*cell); CaloGeometryLookup* lookup=0; for(unsigned int i=0;i<m_cells_in_regions[sampling].size();++i) { @@ -598,8 +599,9 @@ void CaloGeometry::post_process(int sampling) void CaloGeometry::InitRZmaps() { - int nok=0; + int nok=0; + FSmap< double , double > rz_map_eta [2][MAX_SAMPLING]; FSmap< double , double > rz_map_rmid[2][MAX_SAMPLING]; FSmap< double , double > rz_map_zmid[2][MAX_SAMPLING]; @@ -610,16 +612,20 @@ void CaloGeometry::InitRZmaps() FSmap< double , int > rz_map_n [2][MAX_SAMPLING]; - for(int side=0;side<=1;++side) for(int sample=0;sample<MAX_SAMPLING;++sample) { + for(unsigned int side=0;side<=1;++side) for(unsigned int sample=0;sample<MAX_SAMPLING;++sample) + { m_min_eta_sample[side][sample]=+1000; m_max_eta_sample[side][sample]=-1000; } - - for(t_cellmap::iterator calo_iter=m_cells.begin();calo_iter!=m_cells.end();++calo_iter) { - const CaloGeoDetDescrElement* theDDE=(*calo_iter).second; - if(theDDE) { + + + for(t_cellmap::iterator calo_iter=m_cells.begin();calo_iter!=m_cells.end();++calo_iter) + { + const CaloDetDescrElement* theDDE=(*calo_iter).second; + if(theDDE) + { ++nok; - int sample=theDDE->getSampling(); + unsigned int sample=theDDE->getSampling(); int side=0; int sign_side=-1; @@ -657,9 +663,12 @@ void CaloGeometry::InitRZmaps() rz_map_zmid[side][sample][eta_raw]+=theDDE->z(); double drh=theDDE->dr()/2; double dzh=theDDE->dz(); - if(sample>=CaloSampling::PreSamplerB && sample<=CaloSampling::EMB3) { + if(sample<=CaloSampling::EMB3) { // ensure we have a valid sampling drh=theDDE->dr(); - } + } + // An `else` would be good here since we can't continue with a *bad* sampling... + // Should most likely handle the situation nicely rather than with a crash. + rz_map_rent[side][sample][eta_raw]+=theDDE->r()-drh; rz_map_zent[side][sample][eta_raw]+=theDDE->z()-dzh*sign_side; rz_map_rext[side][sample][eta_raw]+=theDDE->r()+drh; @@ -668,13 +677,23 @@ void CaloGeometry::InitRZmaps() } } - for(int side=0;side<=1;++side) for(int sample=0;sample<MAX_SAMPLING;++sample) { - if(rz_map_n[side][sample].size()>0) { - for(FSmap< double , int >::iterator iter=rz_map_n[side][sample].begin();iter!=rz_map_n[side][sample].end();++iter) { + + for(int side=0;side<=1;++side) + { + for(int sample=0;sample<MAX_SAMPLING;++sample) + { + + if(rz_map_n[side][sample].size()>0) + { + for(FSmap< double , int >::iterator iter=rz_map_n[side][sample].begin();iter!=rz_map_n[side][sample].end();++iter) + { double eta_raw=iter->first; - if(iter->second<1) { + if(iter->second<1) + { //ATH_MSG_WARNING("rz-map for side="<<side<<" sample="<<sample<<" eta_raw="<<eta_raw<<" : #cells="<<iter->second<<" !!!"); - } else { + } + else + { double eta =rz_map_eta[side][sample][eta_raw]/iter->second; double rmid=rz_map_rmid[side][sample][eta_raw]/iter->second; double zmid=rz_map_zmid[side][sample][eta_raw]/iter->second; @@ -692,10 +711,14 @@ void CaloGeometry::InitRZmaps() } } //ATH_MSG_DEBUG("rz-map for side="<<side<<" sample="<<sample<<" #etas="<<m_rmid_map[side][sample].size()); - } else { - //ATH_MSG_WARNING("rz-map for side="<<side<<" sample="<<sample<<" is empty!!!"); + } + else + { + std::cout<<"rz-map for side="<<side<<" sample="<<sample<<" is empty!!!"<<std::endl; } - } + } //sample + } //side + if(DoGraphs()) { int calocol[24]={1,2,3,4, // LAr barrel 1,2,3,4, // LAr EM endcap @@ -767,7 +790,7 @@ TCanvas* CaloGeometry::DrawGeoForPhi0() cout<<"Start sample "<<sample<<" ("<<SamplingName(sample)<<")"<<endl; int ngr=0; for(t_eta_cellmap::iterator calo_iter=m_cells_in_sampling_for_phi0[sample].begin();calo_iter!=m_cells_in_sampling_for_phi0[sample].end();++calo_iter) { - const CaloGeoDetDescrElement* theDDE=(*calo_iter).second; + const CaloDetDescrElement* theDDE=(*calo_iter).second; if(theDDE) { TVector3 cv; TGraph* gr=new TGraph(5); @@ -852,23 +875,23 @@ TCanvas* CaloGeometry::DrawGeoForPhi0() return c; } -const CaloGeoDetDescrElement* CaloGeometry::getDDE(Identifier identify) +const CaloDetDescrElement* CaloGeometry::getDDE(Identifier identify) { return m_cells[identify]; } -const CaloGeoDetDescrElement* CaloGeometry::getDDE(int sampling,Identifier identify) +const CaloDetDescrElement* CaloGeometry::getDDE(int sampling,Identifier identify) { return m_cells_in_sampling[sampling][identify]; } -const CaloGeoDetDescrElement* CaloGeometry::getDDE(int sampling,float eta,float phi,float* distance,int* steps) +const CaloDetDescrElement* CaloGeometry::getDDE(int sampling,float eta,float phi,float* distance,int* steps) { if(sampling<0) return 0; if(sampling>=MAX_SAMPLING) return 0; if(m_cells_in_regions[sampling].size()==0) return 0; float dist; - const CaloGeoDetDescrElement* bestDDE=0; + const CaloDetDescrElement* bestDDE=0; if(!distance) distance=&dist; *distance=+10000000; int intsteps; @@ -889,7 +912,7 @@ const CaloGeoDetDescrElement* CaloGeometry::getDDE(int sampling,float eta,float cout<<"CaloGeometry::getDDE : check map"<<j<<" skip_range_check="<<skip_range_check<<endl; } float newdist; - const CaloGeoDetDescrElement* newDDE=m_cells_in_regions[sampling][j]->getDDE(eta,phi,&newdist,&intsteps); + const CaloDetDescrElement* newDDE=m_cells_in_regions[sampling][j]->getDDE(eta,phi,&newdist,&intsteps); if(m_debug) { cout<<"CaloGeometry::getDDE : map"<<j<<" dist="<<newdist<<" best dist="<<*distance<<" steps="<<intsteps<<endl; } @@ -936,7 +959,7 @@ const CaloGeoDetDescrElement* CaloGeometry::getDDE(int sampling,float eta,float return bestDDE; } -const CaloGeoDetDescrElement* CaloGeometry::getFCalDDE(int sampling,float x,float y,float z){ +const CaloDetDescrElement* CaloGeometry::getFCalDDE(int sampling,float x,float y,float z){ int isam = sampling - 20; int iphi,ieta; Long64_t mask1[]{0x34,0x34,0x35}; @@ -989,7 +1012,7 @@ void CaloGeometry::Validate() int ntest=0; cout<<"start CaloGeometry::Validate()"<<endl; for(t_cellmap::iterator ic=m_cells.begin();ic!=m_cells.end();++ic) { - const CaloGeoDetDescrElement* cell=ic->second; + const CaloDetDescrElement* cell=ic->second; int sampling=cell->getSampling(); if(sampling>=21) continue; @@ -1004,7 +1027,7 @@ void CaloGeometry::Validate() float eta=cell->eta()+1.5*(gRandom->Rndm()-0.5)*cell->deta(); float phi=cell->phi()+1.5*(gRandom->Rndm()-0.5)*cell->dphi(); float distance; - const CaloGeoDetDescrElement* foundcell=getDDE(sampling,eta,phi,&distance,&steps); + const CaloDetDescrElement* foundcell=getDDE(sampling,eta,phi,&distance,&steps); if(m_debug && foundcell) { cout<<"CaloGeometry::Validate(), irnd="<<irnd<<", foundcell id="<<foundcell->identify()<<", "<<steps<<" steps"<<endl; } @@ -1150,11 +1173,13 @@ double CaloGeometry::rzext(int sample,double eta) const double CaloGeometry::rpos(int sample,double eta,int subpos) const { + int side=0; if(eta>0) side=1; - + if(subpos==CaloSubPos::SUBPOS_ENT) return m_rent_map[side][sample].find_closest(eta)->second; if(subpos==CaloSubPos::SUBPOS_EXT) return m_rext_map[side][sample].find_closest(eta)->second; + return m_rmid_map[side][sample].find_closest(eta)->second; } diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/CaloGeometryFromCaloDDM.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/CaloGeometryFromCaloDDM.cxx index 942cafc3fcd8..a309a2b7010a 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/CaloGeometryFromCaloDDM.cxx +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/CaloGeometryFromCaloDDM.cxx @@ -3,8 +3,8 @@ */ #include "CaloGeometryFromCaloDDM.h" -//#include "CaloDetDescr/CaloDetDescrElement.h" -#include "ISF_FastCaloSimParametrization/CaloDetDescrElement.h" +#include "CaloDetDescr/CaloDetDescrElement.h" +//#include "ISF_FastCaloSimParametrization/CaloGeoDetDescrElement.h" #include "CaloDetDescr/CaloDetDescrManager.h" using namespace std; diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/CaloGeometryFromFile.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/CaloGeometryFromFile.cxx index fb96f162ffa4..808486f8d947 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/CaloGeometryFromFile.cxx +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/CaloGeometryFromFile.cxx @@ -1,11 +1,12 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration - */ + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ #include "ISF_FastCaloSimParametrization/CaloGeometryFromFile.h" #include <TTree.h> #include <TFile.h> -#include "ISF_FastCaloSimParametrization/CaloDetDescrElement.h" +#include "ISF_FastCaloSimParametrization/CaloGeoDetDescrElement.h" +//#include "CaloDetDescr/CaloGeoDetDescrElement.h" #include <fstream> #include <sstream> #include <TGraph.h> @@ -20,26 +21,26 @@ using namespace std; map<unsigned long long, unsigned long long> g_cellId_vs_cellHashId_map; -CaloGeometryFromFile::CaloGeometryFromFile() : CaloGeometry() +CaloGeometryFromFile::CaloGeometryFromFile() : CaloGeoGeometry() { - ifstream textfile("/afs/cern.ch/atlas/groups/Simulation/FastCaloSimV2/cellId_vs_cellHashId_map.txt"); - unsigned long long id, hash_id; - cout << "Loading cellId_vs_cellHashId_map" << endl; - int i=0; - string line; - stringstream s; - while(1){ - //getline(textfile,line); - s.str(line); - textfile >> id; - if(textfile.eof())break; - textfile >> hash_id; - g_cellId_vs_cellHashId_map[id]=hash_id; - if(i%10000==0)cout << "Line: " << i << " line " << line << " id " << hex << id << " hash_id " << dec << hash_id << endl; - i++; - } - cout << "Done." << endl; - + ifstream textfile("/afs/cern.ch/atlas/groups/Simulation/FastCaloSimV2/cellId_vs_cellHashId_map.txt"); + unsigned long long id, hash_id; + cout << "Loading cellId_vs_cellHashId_map" << endl; + int i=0; + string line; + stringstream s; + while(1){ + //getline(textfile,line); + s.str(line); + textfile >> id; + if(textfile.eof())break; + textfile >> hash_id; + g_cellId_vs_cellHashId_map[id]=hash_id; + if(i%10000==0)cout << "Line: " << i << " line " << line << " id " << hex << id << " hash_id " << dec << hash_id << endl; + i++; + } + cout << "Done." << endl; + } CaloGeometryFromFile::~CaloGeometryFromFile() @@ -55,9 +56,9 @@ bool CaloGeometryFromFile::LoadGeometryFromFile(TString filename,TString treenam if(!tree) return false; TTree* fChain = tree; - + CaloGeoDetDescrElement cell; - + // List of branches TBranch *b_identifier; //! TBranch *b_calosample; //! @@ -79,7 +80,7 @@ bool CaloGeometryFromFile::LoadGeometryFromFile(TString filename,TString treenam TBranch *b_dx; //! TBranch *b_dy; //! TBranch *b_dz; //! - + fChain->SetMakeClass(1); fChain->SetBranchAddress("identifier", &cell.m_identify, &b_identifier); fChain->SetBranchAddress("calosample", &cell.m_calosample, &b_calosample); @@ -101,247 +102,272 @@ bool CaloGeometryFromFile::LoadGeometryFromFile(TString filename,TString treenam fChain->SetBranchAddress("dx", &cell.m_dx, &b_dx); fChain->SetBranchAddress("dy", &cell.m_dy, &b_dy); fChain->SetBranchAddress("dz", &cell.m_dz, &b_dz); - + Long64_t nentries = fChain->GetEntriesFast(); for (Long64_t jentry=0; jentry<nentries;jentry++) { Long64_t ientry = fChain->LoadTree(jentry); if (ientry < 0) break; fChain->GetEntry(jentry); - + if (g_cellId_vs_cellHashId_map.find(cell.m_identify)!=g_cellId_vs_cellHashId_map.end()) cell.m_hash_id=g_cellId_vs_cellHashId_map[cell.m_identify]; else cout << endl << "ERROR: Cell id not found in the cellId_vs_cellHashId_map!!!" << endl << endl; - + const CaloGeoDetDescrElement* pcell=new CaloGeoDetDescrElement(cell); int sampling = pcell->getSampling(); - - + + if(sampling >20) continue; this->addcell(pcell); - + if(jentry%25000==0) { - //if(jentry==nentries-1) { - cout << "Checking loading cells from file" << endl; + //if(jentry==nentries-1) { + cout << "Checking loading cells from file" << endl; cout<<jentry<<" : "<<pcell->getSampling()<<", "<<pcell->identify()<<endl; - - - + + + //if(jentry>5) break; } } - //cout<<"all : "<<m_cells.size()<<endl; + //cout<<"all : "<<m_cells.size()<<endl; //unsigned long long max(0); //unsigned long long min_id=m_cells_in_sampling[0].begin()->first; //for(int i=0;i<21;++i) { - ////cout<<" cells sampling "<<i<<" : "<<m_cells_in_sampling[i].size()<<" cells"; - ////cout<<", "<<m_cells_in_regions[i].size()<<" lookup map(s)"<<endl; - //for(auto it=m_cells_in_sampling[i].begin(); it!=m_cells_in_sampling[i].end();it++){ - ////cout << it->second->getSampling() << " " << it->first << endl; - //if(min_id/10 >= it->first){ - ////cout << "Warning: Identifiers are not in increasing order!!!!" << endl; - ////cout << min_id << " " << it->first << endl; - - //} - //if(min_id > it->first)min_id = it->first; - //} - //} - //cout << "Min id for samplings < 21: " << min_id << endl; + ////cout<<" cells sampling "<<i<<" : "<<m_cells_in_sampling[i].size()<<" cells"; + ////cout<<", "<<m_cells_in_regions[i].size()<<" lookup map(s)"<<endl; + //for(auto it=m_cells_in_sampling[i].begin(); it!=m_cells_in_sampling[i].end();it++){ + ////cout << it->second->getSampling() << " " << it->first << endl; + //if(min_id/10 >= it->first){ + ////cout << "Warning: Identifiers are not in increasing order!!!!" << endl; + ////cout << min_id << " " << it->first << endl; + + //} + //if(min_id > it->first)min_id = it->first; + //} + //} + //cout << "Min id for samplings < 21: " << min_id << endl; delete f; - //return true; - bool ok = PostProcessGeometry(); - - cout << "Result of PostProcessGeometry(): " << ok << endl; - const CaloGeoDetDescrElement* mcell=0; - unsigned long long cellid64(3179554531063103488); - Identifier cellid(cellid64); - mcell=this->getDDE(cellid); //This is working also for the FCal - - std::cout << "\n \n"; - std::cout << "Testing whether CaloGeometry is loaded properly" << std::endl; - if(!mcell)std::cout << "Cell is not found" << std::endl; - std::cout << "Identifier " << mcell->identify() <<" sampling " << mcell->getSampling() << " eta: " << mcell->eta() << " phi: " << mcell->phi() << std::endl<< std::endl; - - const CaloGeoDetDescrElement* mcell2 = this->getDDE(mcell->getSampling(),mcell->eta(),mcell->phi()); - std::cout << "Identifier " << mcell2->identify() <<" sampling " << mcell2->getSampling() << " eta: " << mcell2->eta() << " phi: " << mcell2->phi() << std::endl<< std::endl; - + //return true; + bool ok = PostProcessGeometry(); + + cout << "Result of PostProcessGeometry(): " << ok << endl; + const CaloGeoDetDescrElement* mcell=0; + unsigned long long cellid64(3179554531063103488); + Identifier cellid(cellid64); + mcell=this->getDDE(cellid); //This is working also for the FCal + + std::cout << "\n \n"; + std::cout << "Testing whether CaloGeoGeometry is loaded properly" << std::endl; + if(!mcell)std::cout << "Cell is not found" << std::endl; + std::cout << "Identifier " << mcell->identify() <<" sampling " << mcell->getSampling() << " eta: " << mcell->eta() << " phi: " << mcell->phi() << std::endl<< std::endl; + + const CaloGeoDetDescrElement* mcell2 = this->getDDE(mcell->getSampling(),mcell->eta(),mcell->phi()); + std::cout << "Identifier " << mcell2->identify() <<" sampling " << mcell2->getSampling() << " eta: " << mcell2->eta() << " phi: " << mcell2->phi() << std::endl<< std::endl; + return ok; } bool CaloGeometryFromFile::LoadFCalGeometryFromFiles(TString filename1,TString filename2,TString filename3){ - - vector<ifstream*> electrodes(3); - + + vector<ifstream*> electrodes(3); + electrodes[0]=new ifstream(filename1); electrodes[1]=new ifstream(filename2); electrodes[2]=new ifstream(filename3); - - - int thisTubeId; + + + int thisTubeId; int thisTubeI; - int thisTubeJ; - //int thisTubeID; - //int thisTubeMod; - double thisTubeX; - double thisTubeY; - TString tubeName; - - //int second_column; - string seventh_column; - string eight_column; - int ninth_column; - - - - - - int i; - for(int imodule=1;imodule<=3;imodule++){ - - i=0; - //while(i<50){ - while(1){ - - //cout << electrodes[imodule-1]->eof() << endl; - (*electrodes[imodule-1]) >> tubeName; - if(electrodes[imodule-1]->eof())break; - (*electrodes[imodule-1]) >> thisTubeId; // ????? - (*electrodes[imodule-1]) >> thisTubeI; - (*electrodes[imodule-1]) >> thisTubeJ; - (*electrodes[imodule-1]) >> thisTubeX; - (*electrodes[imodule-1]) >> thisTubeY; - (*electrodes[imodule-1]) >> seventh_column; - (*electrodes[imodule-1]) >> eight_column; - (*electrodes[imodule-1]) >> ninth_column; - - tubeName.ReplaceAll("'",""); - string tubeNamestring=tubeName.Data(); - - std::istringstream tileStream1(std::string(tubeNamestring,1,1)); - std::istringstream tileStream2(std::string(tubeNamestring,3,2)); - std::istringstream tileStream3(std::string(tubeNamestring,6,3)); - int a1=0,a2=0,a3=0; - if (tileStream1) tileStream1 >> a1; - if (tileStream2) tileStream2 >> a2; - if (tileStream3) tileStream3 >> a3; - - //unsigned int tileName= (a3 << 16) + a2; - stringstream s; - - - m_FCal_ChannelMap.add_tube(tubeNamestring, imodule, thisTubeId, thisTubeI,thisTubeJ, thisTubeX, thisTubeY,seventh_column); - - - - //cout << "FCal electrodes: " << tubeName << " " << second_column << " " << thisTubeI << " " << thisTubeJ << " " << thisTubeX << " " << thisTubeY << " " << seventh_column << " " << eight_column << " " << ninth_column << endl; - //cout << tileStream1.str() << " " << tileStream2.str() << " " << tileStream3.str() << endl; - //cout << a1 << " " << a2 << " " << a3 << " " << tileName << endl; - i++; - } - } - m_FCal_ChannelMap.finish(); // Creates maps - - unsigned long long phi_index,eta_index; - float x,y,dx,dy; - long id; - //auto it =m_cells_in_sampling[20].rbegin(); - //it--; - //unsigned long long identify=it->first; - //for(auto it=m_cells_in_sampling[i].begin(); it!=m_cells_in_sampling[i].end();it++){ - // + int thisTubeJ; + //int thisTubeID; + //int thisTubeMod; + double thisTubeX; + double thisTubeY; + TString tubeName; + + //int second_column; + string seventh_column; + string eight_column; + int ninth_column; + + + + + + int i; + for(int imodule=1;imodule<=3;imodule++){ + + i=0; + //while(i<50){ + while(1){ + + //cout << electrodes[imodule-1]->eof() << endl; + (*electrodes[imodule-1]) >> tubeName; + if(electrodes[imodule-1]->eof())break; + (*electrodes[imodule-1]) >> thisTubeId; // ????? + (*electrodes[imodule-1]) >> thisTubeI; + (*electrodes[imodule-1]) >> thisTubeJ; + (*electrodes[imodule-1]) >> thisTubeX; + (*electrodes[imodule-1]) >> thisTubeY; + (*electrodes[imodule-1]) >> seventh_column; + (*electrodes[imodule-1]) >> eight_column; + (*electrodes[imodule-1]) >> ninth_column; + + tubeName.ReplaceAll("'",""); + string tubeNamestring=tubeName.Data(); + + std::istringstream tileStream1(std::string(tubeNamestring,1,1)); + std::istringstream tileStream2(std::string(tubeNamestring,3,2)); + std::istringstream tileStream3(std::string(tubeNamestring,6,3)); + int a1=0,a2=0,a3=0; + if (tileStream1) tileStream1 >> a1; + if (tileStream2) tileStream2 >> a2; + if (tileStream3) tileStream3 >> a3; + + //unsigned int tileName= (a3 << 16) + a2; + stringstream s; + + + m_FCal_ChannelMap.add_tube(tubeNamestring, imodule, thisTubeId, thisTubeI,thisTubeJ, thisTubeX, thisTubeY,seventh_column); + + + + //cout << "FCal electrodes: " << tubeName << " " << second_column << " " << thisTubeI << " " << thisTubeJ << " " << thisTubeX << " " << thisTubeY << " " << seventh_column << " " << eight_column << " " << ninth_column << endl; + //cout << tileStream1.str() << " " << tileStream2.str() << " " << tileStream3.str() << endl; + //cout << a1 << " " << a2 << " " << a3 << " " << tileName << endl; + i++; + } + } + + + m_FCal_ChannelMap.finish(); // Creates maps + + unsigned long long phi_index,eta_index; + float x,y,dx,dy; + long id; + //auto it =m_cells_in_sampling[20].rbegin(); + //it--; + //unsigned long long identify=it->first; + //for(auto it=m_cells_in_sampling[i].begin(); it!=m_cells_in_sampling[i].end();it++){ + // + //} + long mask1[]{0x34,0x34,0x35}; + long mask2[]{0x36,0x36,0x37}; + + for(int imap=1;imap<=3;imap++){ + for(auto it=m_FCal_ChannelMap.begin(imap);it!=m_FCal_ChannelMap.end(imap);it++){ + phi_index = it->first & 0xffff; + eta_index = it->first >> 16; + CaloGeoDetDescrElement *DDE =new CaloGeoDetDescrElement; // side C + CaloGeoDetDescrElement *DDE2 =new CaloGeoDetDescrElement; // side A + x=it->second.x(); + y=it->second.y(); + m_FCal_ChannelMap.tileSize(imap, eta_index, phi_index,dx,dy); + //if(imap==2) eta_index+=100; + //if(imap==3) eta_index+=200; + //cout << imap << " " << eta_index << " " << phi_index << " " << it->first << " " << (eta_index << 16) + phi_index << endl; + + DDE->m_calosample=imap+20; + DDE->m_x=x; + DDE->m_y=y; + DDE->m_x_raw=x; + DDE->m_y_raw=y; + DDE->m_dx=dx; + DDE->m_dy=dy; + + DDE2->m_calosample=imap+20; + DDE2->m_x=x; + DDE2->m_y=y; + DDE2->m_x_raw=x; + DDE2->m_y_raw=y; + DDE2->m_dx=dx; + DDE2->m_dy=dy; + + id=(mask1[imap-1]<<12) + (eta_index << 5) +2*phi_index; + if(imap==2) id+= (8<<8); + DDE->m_identify=(id << 44); + //DDE->m_identify=(id << 12); + //cout << DDE->identify() << endl; + if (g_cellId_vs_cellHashId_map.find(DDE->m_identify)!=g_cellId_vs_cellHashId_map.end()) DDE->m_hash_id=g_cellId_vs_cellHashId_map[DDE->m_identify]; + else cout << endl << "ERROR: Cell id not found in the cellId_vs_cellHashId_map!!!" << endl << endl; + + addcell(DDE); + id=(mask2[imap-1]<<12) + (eta_index << 5) +2*phi_index; + if(imap==2) id+= (8<<8); + DDE2->m_identify=(id << 44); + //DDE->m_identify=(id << 12); + if (g_cellId_vs_cellHashId_map.find(DDE2->m_identify)!=g_cellId_vs_cellHashId_map.end()) DDE2->m_hash_id=g_cellId_vs_cellHashId_map[DDE2->m_identify]; + else cout << endl << "ERROR: Cell id not found in the cellId_vs_cellHashId_map!!!" << endl << endl; + addcell(DDE2); + delete DDE; + delete DDE2; + } + + } + //auto it =m_cells_in_sampling[0].begin(); + //it--; + //unsigned long long identify=it->first; + ////cout << "min identifier from sampling < 21: " << identify << endl; + + //for(int i=0;i<21;++i) { + ////for(int i=21;i<MAX_SAMPLING;++i) { + //cout<<" cells sampling "<<i<<" : "<<m_cells_in_sampling[i].size()<<" cells"; + //cout<<", "<<m_cells_in_regions[i].size()<<" lookup map(s)"<<endl; + //int k=0; + //for(auto it=m_cells_in_sampling[i].begin(); it!=m_cells_in_sampling[i].end();it++){ + //if(k<10){ + //cout << " cells sampling "<< it->second->getSampling() << " : " << it->first << endl; + //const CaloGeoDetDescrElement *DDE = this->getDDE(it->second->getSampling(),it->second->eta(),it->second->phi()); + //cout << " cells sampling "<< DDE->getSampling() << " : " << DDE->identify() << endl; + //DDE = this->getDDE(it->first); + //cout << " cells sampling "<< DDE->getSampling() << " : " << DDE->identify() << endl << endl; + //} + //k++; + //} + //} - long mask1[]{0x34,0x34,0x35}; - long mask2[]{0x36,0x36,0x37}; - - for(int imap=1;imap<=3;imap++){ - for(auto it=m_FCal_ChannelMap.begin(imap);it!=m_FCal_ChannelMap.end(imap);it++){ - phi_index = it->first & 0xffff; - eta_index = it->first >> 16; - CaloGeoDetDescrElement *DDE =new CaloGeoDetDescrElement; // side C - CaloGeoDetDescrElement *DDE2 =new CaloGeoDetDescrElement; // side A - x=it->second.x(); - y=it->second.y(); - m_FCal_ChannelMap.tileSize(imap, eta_index, phi_index,dx,dy); - //if(imap==2) eta_index+=100; - //if(imap==3) eta_index+=200; - //cout << imap << " " << eta_index << " " << phi_index << " " << it->first << " " << (eta_index << 16) + phi_index << endl; - - DDE->m_calosample=imap+20; - DDE->m_x=x; - DDE->m_y=y; - DDE->m_x_raw=x; - DDE->m_y_raw=y; - DDE->m_dx=dx; - DDE->m_dy=dy; - - DDE2->m_calosample=imap+20; - DDE2->m_x=x; - DDE2->m_y=y; - DDE2->m_x_raw=x; - DDE2->m_y_raw=y; - DDE2->m_dx=dx; - DDE2->m_dy=dy; - - id=(mask1[imap-1]<<12) + (eta_index << 5) +2*phi_index; - if(imap==2) id+= (8<<8); - DDE->m_identify=(id << 44); - //DDE->m_identify=(id << 12); - //cout << DDE->identify() << endl; - if (g_cellId_vs_cellHashId_map.find(DDE->m_identify)!=g_cellId_vs_cellHashId_map.end()) DDE->m_hash_id=g_cellId_vs_cellHashId_map[DDE->m_identify]; - else cout << endl << "ERROR: Cell id not found in the cellId_vs_cellHashId_map!!!" << endl << endl; - - addcell(DDE); - id=(mask2[imap-1]<<12) + (eta_index << 5) +2*phi_index; - if(imap==2) id+= (8<<8); - DDE2->m_identify=(id << 44); - //DDE->m_identify=(id << 12); - if (g_cellId_vs_cellHashId_map.find(DDE2->m_identify)!=g_cellId_vs_cellHashId_map.end()) DDE2->m_hash_id=g_cellId_vs_cellHashId_map[DDE2->m_identify]; - else cout << endl << "ERROR: Cell id not found in the cellId_vs_cellHashId_map!!!" << endl << endl; - addcell(DDE2); - delete DDE; - delete DDE2; - } - - } - - for( int imodule=0;imodule<3;imodule++) { delete electrodes[imodule]; } + + + for(int imodule=1;imodule<=3;imodule++) delete electrodes[imodule-1]; electrodes.clear(); - - return true; + + return true; } void CaloGeometryFromFile::DrawFCalGraph(int isam,int color){ - - stringstream ss; - ss << "FCal" << isam - 20 << endl; - TString name = ss.str().c_str(); - - const int size=m_cells_in_sampling[isam].size(); - double *x = new double[size]; - double *y = new double[size]; - //const CaloGeoDetDescrElement* cell; - int i=0; - for(auto it=m_cells_in_sampling[isam].begin();it!=m_cells_in_sampling[isam].end();it++){ - x[i]=it->second->x(); - y[i]=it->second->y(); - i++; - } - // cout << size << endl; - //TH2D* h = new TH2D("","",10,-0.5,0.5,10,-0.5,0.5); - //h->SetStats(0); - //h->Draw(); - TGraph* graph = new TGraph(size,x,y); - graph->SetLineColor(color); - graph->SetTitle(name); - graph->SetMarkerStyle(21); - graph->SetMarkerColor(color); - graph->SetMarkerSize(0.5); - graph->GetXaxis()->SetTitle("x"); - graph->GetYaxis()->SetTitle("y"); - - graph->Draw("AP"); - - delete [] x; - delete [] y; - -} + + stringstream ss; + ss << "FCal" << isam - 20 << endl; + TString name = ss.str().c_str(); + + const int size=m_cells_in_sampling[isam].size(); + double x[size]; + double y[size]; + //const CaloGeoDetDescrElement* cell; + int i=0; + for(auto it=m_cells_in_sampling[isam].begin();it!=m_cells_in_sampling[isam].end();it++){ + x[i]=it->second->x(); + y[i]=it->second->y(); + i++; + } + // cout << size << endl; + //TH2D* h = new TH2D("","",10,-0.5,0.5,10,-0.5,0.5); + //h->SetStats(0); + //h->Draw(); + TGraph* graph = new TGraph(size,x,y); + graph->SetLineColor(color); + graph->SetTitle(name); + graph->SetMarkerStyle(21); + graph->SetMarkerColor(color); + graph->SetMarkerSize(0.5); + graph->GetXaxis()->SetTitle("x"); + graph->GetYaxis()->SetTitle("y"); + + graph->Draw("AP"); + + + +} + diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/FastCaloSimCaloExtrapolation.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/FastCaloSimCaloExtrapolation.cxx index e0321b1104fe..0c6d003afb9b 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/FastCaloSimCaloExtrapolation.cxx +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/FastCaloSimCaloExtrapolation.cxx @@ -20,14 +20,14 @@ FastCaloSimCaloExtrapolation::FastCaloSimCaloExtrapolation(const std::string& t, const std::string& n, const IInterface* p) : AthAlgTool(t,n,p), - m_CaloBoundaryR(1148.0), - m_CaloBoundaryZ(3549.5), - m_calomargin(100), - m_extrapolator("TimedExtrapolator"), - m_caloSurfaceHelper("CaloSurfaceHelper"), - m_caloEntrance(nullptr), - m_caloEntranceName(""), - m_CaloGeometryHelper("FastCaloSimGeometryHelper") + //m_CaloBoundaryR(1148.0), + //m_CaloBoundaryZ(3549.5), + //m_calomargin(100), + //m_extrapolator("TimedExtrapolator"), + //m_caloEntranceName(""), + //m_caloSurfaceHelper("CaloSurfaceHelper"), + //m_CaloGeometryHelper("FastCaloSimGeometryHelper"), + m_caloEntrance(nullptr) { declareInterface<IFastCaloSimCaloExtrapolation>(this); @@ -52,128 +52,143 @@ FastCaloSimCaloExtrapolation::~FastCaloSimCaloExtrapolation() { } -StatusCode FastCaloSimCaloExtrapolation::initialize() { - ATH_MSG_INFO( "Initializing FastCaloSimCaloExtrapolation" ); - - // Get CaloGeometryHelper - ATH_CHECK(m_CaloGeometryHelper.retrieve()); - - // Get PDG table - IPartPropSvc* p_PartPropSvc=nullptr; - - ATH_CHECK(service("PartPropSvc",p_PartPropSvc)); - if(!p_PartPropSvc) - { - ATH_MSG_ERROR("could not find PartPropService"); - return StatusCode::FAILURE; - } - - m_particleDataTable = (HepPDT::ParticleDataTable*) p_PartPropSvc->PDT(); - if(!m_particleDataTable) - { - ATH_MSG_ERROR("PDG table not found"); - return StatusCode::FAILURE; - } - //######################### - - // Get TimedExtrapolator - if (!m_extrapolator.empty()) { - ATH_CHECK(m_extrapolator.retrieve()); - ATH_MSG_INFO("Extrapolator retrieved "<< m_extrapolator); - } - // Get CaloSurfaceHelper - ATH_CHECK(m_caloSurfaceHelper.retrieve()); - - return StatusCode::SUCCESS; -} +StatusCode FastCaloSimCaloExtrapolation::initialize() +{ + ATH_MSG_INFO( "Initializing FastCaloSimCaloExtrapolation" ); + + // Get CaloGeometryHelper + ATH_CHECK(m_CaloGeometryHelper.retrieve()); + + std::cout<<"CHECKME m_CaloGeometryHelper "<<m_CaloGeometryHelper<<std::endl; + + // Get PDG table + IPartPropSvc* p_PartPropSvc=nullptr; + + ATH_CHECK(service("PartPropSvc",p_PartPropSvc)); + if(!p_PartPropSvc) + { + ATH_MSG_ERROR("could not find PartPropService"); + return StatusCode::FAILURE; + } + + m_particleDataTable = (HepPDT::ParticleDataTable*) p_PartPropSvc->PDT(); + if(!m_particleDataTable) + { + ATH_MSG_ERROR("PDG table not found"); + return StatusCode::FAILURE; + } + //######################### + + // Get TimedExtrapolator + if(!m_extrapolator.empty()) + { + ATH_CHECK(m_extrapolator.retrieve()); + ATH_MSG_INFO("Extrapolator retrieved "<< m_extrapolator); + } + + // Get CaloSurfaceHelper + ATH_CHECK(m_caloSurfaceHelper.retrieve()); + + std::cout<<"m_CaloBoundaryR "<<m_CaloBoundaryR<<std::endl; + std::cout<<"m_caloEntranceName "<<m_caloEntranceName<<std::endl; + + return StatusCode::SUCCESS; + +} StatusCode FastCaloSimCaloExtrapolation::finalize() { - ATH_MSG_INFO( "Finalizing FastCaloSimCaloExtrapolation" ); - - return StatusCode::SUCCESS; + ATH_MSG_INFO( "Finalizing FastCaloSimCaloExtrapolation" ); + return StatusCode::SUCCESS; } void FastCaloSimCaloExtrapolation::extrapolate(TFCSExtrapolationState& result,const TFCSTruthState* truth) { - //UPDATE EXTRAPOLATION - ATH_MSG_INFO("Start FastCaloSimCaloExtrapolation::extrapolate"); - std::vector<Trk::HitInfo>* hitVector = caloHits(truth); - ATH_MSG_INFO("Done FastCaloSimCaloExtrapolation::extrapolate: caloHits"); - - ////////////////////////////////////// - // Start calo extrapolation - // First: get entry point into first calo sample - ////////////////////////////////////// - ATH_MSG_INFO("FastCaloSimCaloExtrapolation::extrapolate:*** Get calo surface ***"); - get_calo_surface(result,hitVector); - ATH_MSG_INFO("FastCaloSimCaloExtrapolation::extrapolate:*** Do extrapolation to ID-calo boundary ***"); - extrapolate_to_ID(result,truth,hitVector); - ATH_MSG_INFO("FastCaloSimCaloExtrapolation::extrapolate:*** Do extrapolation ***"); - extrapolate(result,truth,hitVector); - ATH_MSG_INFO("FastCaloSimCaloExtrapolation::extrapolate: Truth extrapolation done"); - - for(std::vector<Trk::HitInfo>::iterator it = hitVector->begin();it < hitVector->end();++it) { - if((*it).trackParms) { - delete (*it).trackParms; - (*it).trackParms=0; - } - } - delete hitVector; - ATH_MSG_INFO("Done FastCaloSimCaloExtrapolation::extrapolate"); + + //UPDATE EXTRAPOLATION + ATH_MSG_INFO("Start FastCaloSimCaloExtrapolation::extrapolate"); + std::vector<Trk::HitInfo>* hitVector = caloHits(truth); + ATH_MSG_INFO("Done FastCaloSimCaloExtrapolation::extrapolate: caloHits"); + + ////////////////////////////////////// + // Start calo extrapolation + // First: get entry point into first calo sample + ////////////////////////////////////// + ATH_MSG_INFO("FastCaloSimCaloExtrapolation::extrapolate:*** Get calo surface ***"); + get_calo_surface(result,hitVector); + + ATH_MSG_INFO("FastCaloSimCaloExtrapolation::extrapolate:*** Do extrapolation to ID-calo boundary ***"); + extrapolate_to_ID(result,truth,hitVector); + + ATH_MSG_INFO("FastCaloSimCaloExtrapolation::extrapolate:*** Do extrapolation ***"); + extrapolate(result,truth,hitVector); + + ATH_MSG_INFO("FastCaloSimCaloExtrapolation::extrapolate: Truth extrapolation done"); + + for(std::vector<Trk::HitInfo>::iterator it = hitVector->begin();it < hitVector->end();++it) + { + if((*it).trackParms) + { + delete (*it).trackParms; + (*it).trackParms=0; + } + } + delete hitVector; + ATH_MSG_INFO("Done FastCaloSimCaloExtrapolation::extrapolate"); } std::vector<Trk::HitInfo>* FastCaloSimCaloExtrapolation::caloHits(const TFCSTruthState* truth) const { - // Start calo extrapolation - ATH_MSG_INFO ("[ fastCaloSim transport ] processing particle "<<truth->pdgid() ); - - std::vector<Trk::HitInfo>* hitVector = new std::vector<Trk::HitInfo>; - - int pdgId = truth->pdgid(); - double charge = HepPDT::ParticleID(pdgId).charge(); - - // particle Hypothesis for the extrapolation - - Trk::ParticleHypothesis pHypothesis = m_pdgToParticleHypothesis.convert(pdgId,charge); - - ATH_MSG_INFO ("particle hypothesis "<< pHypothesis ); - - // geantinos not handled by PdgToParticleHypothesis - fix there - if ( pdgId == 999 ) pHypothesis = Trk::geantino; - - Amg::Vector3D pos = Amg::Vector3D( truth->vertex().X(), truth->vertex().Y(), truth->vertex().Z()); - - Amg::Vector3D mom(truth->X(),truth->Y(),truth->Z()); - - ATH_MSG_INFO( "[ fastCaloSim transport ] starting transport from position eta="<<pos.eta()<<" phi="<<pos.phi()<<" d="<<pos.mag()<<" pT="<<mom.perp() ); - - // input parameters : curvilinear parameters - Trk::CurvilinearParameters inputPar(pos,mom,charge); - - // stable vs. unstable check : ADAPT for FASTCALOSIM - //double freepath = ( !m_particleDecayHelper.empty()) ? m_particleDecayHelper->freePath(isp) : - 1.; - double freepath = -1.; - //ATH_MSG_VERBOSE( "[ fatras transport ] Particle free path : " << freepath); - // path limit -> time limit ( TODO : extract life-time directly from decay helper ) - double tDec = freepath > 0. ? freepath : -1.; - int decayProc = 0; - - /* uncomment if unstable particles used by FastCaloSim - // beta calculated here for further use in validation - double mass = m_particleMasses.mass[pHypothesis]; - double mom = isp.momentum().mag(); - double beta = mom/sqrt(mom*mom+mass*mass); - - if ( tDec>0.) { + // Start calo extrapolation + ATH_MSG_INFO ("[ fastCaloSim transport ] processing particle "<<truth->pdgid() ); + + std::vector<Trk::HitInfo>* hitVector = new std::vector<Trk::HitInfo>; + + int pdgId = truth->pdgid(); + double charge = HepPDT::ParticleID(pdgId).charge(); + + // particle Hypothesis for the extrapolation + + Trk::ParticleHypothesis pHypothesis = m_pdgToParticleHypothesis.convert(pdgId,charge); + + ATH_MSG_INFO ("particle hypothesis "<< pHypothesis ); + + // geantinos not handled by PdgToParticleHypothesis - fix there + if ( pdgId == 999 ) pHypothesis = Trk::geantino; + + Amg::Vector3D pos = Amg::Vector3D( truth->vertex().X(), truth->vertex().Y(), truth->vertex().Z()); + + Amg::Vector3D mom(truth->X(),truth->Y(),truth->Z()); + + ATH_MSG_INFO( "[ fastCaloSim transport ] x from position eta="<<pos.eta()<<" phi="<<pos.phi()<<" d="<<pos.mag()<<" pT="<<mom.perp() ); + + // input parameters : curvilinear parameters + Trk::CurvilinearParameters inputPar(pos,mom,charge); + + // stable vs. unstable check : ADAPT for FASTCALOSIM + //double freepath = ( !m_particleDecayHelper.empty()) ? m_particleDecayHelper->freePath(isp) : - 1.; + double freepath = -1.; + //ATH_MSG_VERBOSE( "[ fatras transport ] Particle free path : " << freepath); + // path limit -> time limit ( TODO : extract life-time directly from decay helper ) + double tDec = freepath > 0. ? freepath : -1.; + int decayProc = 0; + + /* uncomment if unstable particles used by FastCaloSim + // beta calculated here for further use in validation + double mass = m_particleMasses.mass[pHypothesis]; + double mom = isp.momentum().mag(); + double beta = mom/sqrt(mom*mom+mass*mass); + + if ( tDec>0.) + { tDec = tDec/beta/CLHEP::c_light + isp.timeStamp(); - decayProc = 201; - } - */ - - Trk::TimeLimit timeLim(tDec,0.,decayProc); // TODO: set vertex time info - + decayProc = 201; + } + */ + + Trk::TimeLimit timeLim(tDec,0.,decayProc); // TODO: set vertex time info + // prompt decay ( uncomment if unstable particles used ) //if ( freepath>0. && freepath<0.01 ) { // if (!m_particleDecayHelper.empty()) { @@ -183,429 +198,520 @@ std::vector<Trk::HitInfo>* FastCaloSimCaloExtrapolation::caloHits(const TFCSTrut // return 0; //} - // presample interactions - ADAPT FOR FASTCALOSIM - Trk::PathLimit pathLim(-1.,0); - //if (absPdg!=999 && pHypothesis<99) pathLim = m_samplingTool->sampleProcess(mom,isp.charge(),pHypothesis); - - Trk::GeometrySignature nextGeoID=Trk::Calo; - - // first extrapolation to reach the ID boundary - - ATH_MSG_INFO( "[ fastCaloSim transport ] before calo entrance "); - - // get CaloEntrance if not done already - if (!m_caloEntrance) - { - std::cout<<"check1"<<std::endl; - std::cout<<"m_extrapolator "<<m_extrapolator<<std::endl; - std::cout<<"trackingGeometry() "<<m_extrapolator->trackingGeometry()<<std::endl; - std::cout<<"trackingVolume(m_caloEntranceName) "<<m_extrapolator->trackingGeometry()->trackingVolume(m_caloEntranceName)<<std::endl; - - m_caloEntrance = m_extrapolator->trackingGeometry()->trackingVolume(m_caloEntranceName); - - if (!m_caloEntrance) - ATH_MSG_INFO("CaloEntrance not found "); - else ATH_MSG_INFO("CaloEntrance found "); - } - + // presample interactions - ADAPT FOR FASTCALOSIM + Trk::PathLimit pathLim(-1.,0); + //if (absPdg!=999 && pHypothesis<99) pathLim = m_samplingTool->sampleProcess(mom,isp.charge(),pHypothesis); + + Trk::GeometrySignature nextGeoID=Trk::Calo; + + // first extrapolation to reach the ID boundary + + ATH_MSG_INFO( "[ fastCaloSim transport ] before calo entrance "); + + // get CaloEntrance if not done already + if(!m_caloEntrance) + { + std::cout<<"m_extrapolator "<<m_extrapolator<<std::endl; + std::cout<<"trackingGeometry() "<<m_extrapolator->trackingGeometry()<<std::endl; + std::cout<<"trackingVolume(m_caloEntranceName) "<<m_extrapolator->trackingGeometry()->trackingVolume(m_caloEntranceName)<<std::endl; + + m_caloEntrance = m_extrapolator->trackingGeometry()->trackingVolume(m_caloEntranceName); + + if(!m_caloEntrance) + std::cout<<"CaloEntrance not found"<<std::endl; + else + std::cout<<"CaloEntrance found"<<std::endl; + } + ATH_MSG_INFO( "[ fastCaloSim transport ] after calo entrance "); - + const Trk::TrackParameters* caloEntry = 0; - - if (m_caloEntrance && m_caloEntrance->inside(pos,0.001) && - !m_extrapolator->trackingGeometry()->atVolumeBoundary(pos,m_caloEntrance,0.001)) { - - std::vector<Trk::HitInfo>* dummyHitVector = 0; - if ( charge==0 ) { - - caloEntry = m_extrapolator->transportNeutralsWithPathLimit(inputPar,pathLim,timeLim, - Trk::alongMomentum,pHypothesis,dummyHitVector,nextGeoID,m_caloEntrance); - - } else { - - caloEntry = m_extrapolator->extrapolateWithPathLimit(inputPar,pathLim,timeLim, - Trk::alongMomentum,pHypothesis,dummyHitVector,nextGeoID,m_caloEntrance); - } - } else caloEntry=&inputPar; - - ATH_MSG_INFO( "[ fastCaloSim transport ] after calo caloEntry "); - - if ( caloEntry ) { - - const Trk::TrackParameters* eParameters = 0; - - // save Calo entry hit (fallback info) - hitVector->push_back(Trk::HitInfo(caloEntry->clone(),timeLim.time,nextGeoID,0.)); - - ATH_MSG_DEBUG( "[ fastCaloSim transport ] starting Calo transport from position eta="<<caloEntry->position().eta()<<" phi="<<caloEntry->position().phi()<<" d="<<caloEntry->position().mag() ); - - if ( charge==0 ) { - - eParameters = m_extrapolator->transportNeutralsWithPathLimit(*caloEntry,pathLim,timeLim, - Trk::alongMomentum,pHypothesis,hitVector,nextGeoID); - } else { - - eParameters = m_extrapolator->extrapolateWithPathLimit(*caloEntry,pathLim,timeLim, - Trk::alongMomentum,pHypothesis,hitVector,nextGeoID); - } - - // save Calo exit hit (fallback info) - if (eParameters) hitVector->push_back(Trk::HitInfo(eParameters,timeLim.time,nextGeoID,0.)); - - //delete eParameters; // HitInfo took ownership - + + if(m_caloEntrance && m_caloEntrance->inside(pos,0.001) && !m_extrapolator->trackingGeometry()->atVolumeBoundary(pos,m_caloEntrance,0.001)) + { + std::vector<Trk::HitInfo>* dummyHitVector = 0; + if( charge==0 ) + { + caloEntry = m_extrapolator->transportNeutralsWithPathLimit(inputPar,pathLim,timeLim, + Trk::alongMomentum,pHypothesis,dummyHitVector,nextGeoID,m_caloEntrance); + + } + else + { + caloEntry = m_extrapolator->extrapolateWithPathLimit(inputPar,pathLim,timeLim, + Trk::alongMomentum,pHypothesis,dummyHitVector,nextGeoID,m_caloEntrance); + } } + else + caloEntry=&inputPar; + + ATH_MSG_INFO( "[ fastCaloSim transport ] after calo caloEntry "); - if(msgLvl(MSG::DEBUG)) { + if(caloEntry) + { + const Trk::TrackParameters* eParameters = 0; + + // save Calo entry hit (fallback info) + hitVector->push_back(Trk::HitInfo(caloEntry->clone(),timeLim.time,nextGeoID,0.)); + + ATH_MSG_DEBUG( "[ fastCaloSim transport ] starting Calo transport from position eta="<<caloEntry->position().eta()<<" phi="<<caloEntry->position().phi()<<" d="<<caloEntry->position().mag() ); + + if(charge==0) + { + eParameters = m_extrapolator->transportNeutralsWithPathLimit(*caloEntry,pathLim,timeLim, + Trk::alongMomentum,pHypothesis,hitVector,nextGeoID); + } + else + { + eParameters = m_extrapolator->extrapolateWithPathLimit(*caloEntry,pathLim,timeLim, + Trk::alongMomentum,pHypothesis,hitVector,nextGeoID); + } + + // save Calo exit hit (fallback info) + if(eParameters) hitVector->push_back(Trk::HitInfo(eParameters,timeLim.time,nextGeoID,0.)); + //delete eParameters; // HitInfo took ownership + } //if caloEntry + + if(msgLvl(MSG::DEBUG)) + { + std::vector<Trk::HitInfo>::iterator it = hitVector->begin(); + while (it < hitVector->end() ) + { + int sample=(*it).detID; + Amg::Vector3D hitPos = (*it).trackParms->position(); + ATH_MSG_DEBUG(" HIT: layer="<<sample<<" sample="<<sample-3000<<" eta="<<hitPos.eta()<<" phi="<<hitPos.phi()<<" d="<<hitPos.mag()); + it++; + } + } + + std::cout<<"CHECK BEFORE"<<std::endl; + std::vector<Trk::HitInfo>::iterator it = hitVector->begin(); + while(it < hitVector->end() ) + { + int sample=(*it).detID; + Amg::Vector3D hitPos = (*it).trackParms->position(); + std::cout<<" HIT: layer="<<sample<<" sample="<<sample-3000<<" eta="<<hitPos.eta()<<" phi="<<hitPos.phi()<<" d="<<hitPos.mag()<<std::endl; + it++; + } + + int again=1; + while(again) + { + again=0; std::vector<Trk::HitInfo>::iterator it = hitVector->begin(); - while (it < hitVector->end() ) { - int sample=(*it).detID; - Amg::Vector3D hitPos = (*it).trackParms->position(); - ATH_MSG_DEBUG(" HIT: layer="<<sample<<" sample="<<sample-3000<<" eta="<<hitPos.eta()<<" phi="<<hitPos.phi()<<" d="<<hitPos.mag()); - it++; + int ele=0; + while(it < hitVector->end()) + { + int sample=(*it).detID; + Amg::Vector3D hitPos = (*it).trackParms->position(); + //std::cout<<" HIT: layer="<<sample<<" sample="<<sample-3000<<" eta="<<hitPos.eta()<<" phi="<<hitPos.phi()<<" d="<<hitPos.mag()<<std::endl; + //delete the entry from the hit vector if sample is<3000: + if(sample<3000) + { + //std::cout<<"deleting element "<<ele<<std::endl; + hitVector->erase(it); + again=1; + it=hitVector->end(); + } + ele++; + it++; } - } - + } + + std::cout<<"CHECK AFTER"<<std::endl; + std::vector<Trk::HitInfo>::iterator it2 = hitVector->begin(); + while(it2 < hitVector->end() ) + { + int sample=(*it2).detID; + Amg::Vector3D hitPos = (*it2).trackParms->position(); + std::cout<<" HIT: layer="<<sample<<" sample="<<sample-3000<<" eta="<<hitPos.eta()<<" phi="<<hitPos.phi()<<" d="<<hitPos.mag()<<std::endl; + it2++; + } + + return hitVector; } //####################################################################### void FastCaloSimCaloExtrapolation::extrapolate(TFCSExtrapolationState& result,const TFCSTruthState* truth,std::vector<Trk::HitInfo>* hitVector) { - ATH_MSG_DEBUG("Start extrapolate()"); - - double ptruth_eta=truth->Eta(); - double ptruth_phi=truth->Phi(); - double ptruth_pt =truth->Pt(); - double ptruth_p =truth->P(); - int pdgid =truth->pdgid(); - - ////////////////////////////////////// - // Start calo extrapolation - ////////////////////////////////////// - - std::vector< std::vector<double> > eta_safe(3); - std::vector< std::vector<double> > phi_safe(3); - std::vector< std::vector<double> > r_safe(3); - std::vector< std::vector<double> > z_safe(3); - for(int subpos=SUBPOS_MID;subpos<=SUBPOS_EXT;++subpos) { - eta_safe[subpos].resize(CaloCell_ID_FCS::MaxSample,-999.0); - phi_safe[subpos].resize(CaloCell_ID_FCS::MaxSample,-999.0); - r_safe[subpos].resize(CaloCell_ID_FCS::MaxSample,-999.0); - z_safe[subpos].resize(CaloCell_ID_FCS::MaxSample,-999.0); - } - - // only continue if inside the calo - if( fabs(result.CaloSurface_eta())<6 ) - { - // now try to extrpolate to all calo layers, that contain energy - ATH_MSG_DEBUG("Calo position for particle id "<<pdgid<<", trutheta= " << ptruth_eta <<", truthphi= "<<ptruth_phi<<", truthp="<<ptruth_p<<", truthpt="<<ptruth_pt); - for(int sample=CaloCell_ID_FCS::FirstSample;sample<CaloCell_ID_FCS::MaxSample;++sample) { - for(int subpos=SUBPOS_MID;subpos<=SUBPOS_EXT;++subpos) { - if(get_calo_etaphi(result,hitVector,sample,subpos)) { - ATH_MSG_DEBUG( "Result in sample "<<sample<<"."<<subpos<<": eta="<<result.eta(sample,subpos)<<" phi="<<result.phi(sample,subpos)<<" r="<<result.r(sample,subpos)<<" z="<<result.z(sample,subpos)<<" (ok="<<result.OK(sample,subpos)<<")"); - } - else { - ATH_MSG_DEBUG( "Extrapolation to sample "<<sample<<" failed (ok="<<result.OK(sample,subpos)<<")"); - } - } - } - } //inside calo - - ATH_MSG_DEBUG("End extrapolate()"); + ATH_MSG_DEBUG("Start extrapolate()"); + + double ptruth_eta=truth->Eta(); + double ptruth_phi=truth->Phi(); + double ptruth_pt =truth->Pt(); + double ptruth_p =truth->P(); + int pdgid =truth->pdgid(); + + ////////////////////////////////////// + // Start calo extrapolation + ////////////////////////////////////// + + std::vector< std::vector<double> > eta_safe(3); + std::vector< std::vector<double> > phi_safe(3); + std::vector< std::vector<double> > r_safe(3); + std::vector< std::vector<double> > z_safe(3); + for(int subpos=SUBPOS_MID;subpos<=SUBPOS_EXT;++subpos) + { + eta_safe[subpos].resize(CaloCell_ID_FCS::MaxSample,-999.0); + phi_safe[subpos].resize(CaloCell_ID_FCS::MaxSample,-999.0); + r_safe[subpos].resize(CaloCell_ID_FCS::MaxSample,-999.0); + z_safe[subpos].resize(CaloCell_ID_FCS::MaxSample,-999.0); + } + + // only continue if inside the calo + if( fabs(result.CaloSurface_eta())<6 ) + { + // now try to extrpolate to all calo layers, that contain energy + ATH_MSG_DEBUG("Calo position for particle id "<<pdgid<<", trutheta= " << ptruth_eta <<", truthphi= "<<ptruth_phi<<", truthp="<<ptruth_p<<", truthpt="<<ptruth_pt); + for(int sample=CaloCell_ID_FCS::FirstSample;sample<CaloCell_ID_FCS::MaxSample;++sample) + { + for(int subpos=SUBPOS_MID;subpos<=SUBPOS_EXT;++subpos) + { + if(get_calo_etaphi(result,hitVector,sample,subpos)) + ATH_MSG_DEBUG( "Result in sample "<<sample<<"."<<subpos<<": eta="<<result.eta(sample,subpos)<<" phi="<<result.phi(sample,subpos)<<" r="<<result.r(sample,subpos)<<" z="<<result.z(sample,subpos)<<" (ok="<<result.OK(sample,subpos)<<")"); + else + ATH_MSG_DEBUG( "Extrapolation to sample "<<sample<<" failed (ok="<<result.OK(sample,subpos)<<")"); + } //for pos + } //for sample + } //inside calo + else + std::cout<<"Ups. Not inside calo. result.CaloSurface_eta()="<<result.CaloSurface_eta()<<std::endl; + + ATH_MSG_DEBUG("End extrapolate()"); } void FastCaloSimCaloExtrapolation::extrapolate_to_ID(TFCSExtrapolationState& result,const TFCSTruthState* /*truth*/,std::vector<Trk::HitInfo>* hitVector) { - ATH_MSG_DEBUG("Start extrapolate_to_ID()"); - - Amg::Vector3D hitpos(0,0,0); - Amg::Vector3D hitmom(0,0,0); - if(rz_cylinder_get_calo_etaphi(hitVector,m_CaloBoundaryR,m_CaloBoundaryZ,hitpos,hitmom)) { - ATH_MSG_DEBUG("BOUNDARY ID-CALO eta="<<hitpos.eta()<<" phi="<<hitpos.phi()<<" r="<<hitpos.perp()<<" z="<<hitpos[Amg::z]<<" theta="<<hitpos.theta()<<" ; momentum eta="<<hitmom.eta()<<" phi="<<hitmom.phi()<<" theta="<<hitmom.theta()); - result.set_IDCaloBoundary_eta(hitpos.eta()); - result.set_IDCaloBoundary_phi(hitpos.phi()); - result.set_IDCaloBoundary_r(hitpos.perp()); - result.set_IDCaloBoundary_z(hitpos[Amg::z]); - } else { - ATH_MSG_DEBUG("Extrapolation to IDCaloBoundary failed"); - result.set_IDCaloBoundary_eta(-999.); - result.set_IDCaloBoundary_phi(-999.); - result.set_IDCaloBoundary_r(0); - result.set_IDCaloBoundary_z(0); - } + ATH_MSG_DEBUG("Start extrapolate_to_ID()"); + + Amg::Vector3D hitpos(0,0,0); + Amg::Vector3D hitmom(0,0,0); + if(rz_cylinder_get_calo_etaphi(hitVector,m_CaloBoundaryR,m_CaloBoundaryZ,hitpos,hitmom)) + { + ATH_MSG_DEBUG("BOUNDARY ID-CALO eta="<<hitpos.eta()<<" phi="<<hitpos.phi()<<" r="<<hitpos.perp()<<" z="<<hitpos[Amg::z]<<" theta="<<hitpos.theta()<<" ; momentum eta="<<hitmom.eta()<<" phi="<<hitmom.phi()<<" theta="<<hitmom.theta()); + result.set_IDCaloBoundary_eta(hitpos.eta()); + result.set_IDCaloBoundary_phi(hitpos.phi()); + result.set_IDCaloBoundary_r(hitpos.perp()); + result.set_IDCaloBoundary_z(hitpos[Amg::z]); + } + else + { + ATH_MSG_DEBUG("Extrapolation to IDCaloBoundary failed"); + result.set_IDCaloBoundary_eta(-999.); + result.set_IDCaloBoundary_phi(-999.); + result.set_IDCaloBoundary_r(0); + result.set_IDCaloBoundary_z(0); + } + + TVector3 vec(hitpos[Amg::x],hitpos[Amg::y],hitpos[Amg::z]); + + //get the tangentvector on this interaction point: + //GlobalMomentum* mom=params_on_surface_ID->TrackParameters::momentum().unit() ; + //Trk::GlobalMomentum* trackmom=params_on_surface_ID->Trk::TrackParameters::momentum(); + if(hitmom.mag()>0) + { + //angle between vec and trackmom: + TVector3 Trackmom(hitmom[Amg::x],hitmom[Amg::y],hitmom[Amg::z]); + double angle3D=Trackmom.Angle(vec); //isn't this the same as TVector3 vec? + ATH_MSG_DEBUG(" 3D ANGLE "<<angle3D); + + double angleEta=vec.Theta()-Trackmom.Theta(); + ATH_MSG_DEBUG(" ANGLE dTHEA"<<angleEta); + + result.set_IDCaloBoundary_AngleEta(angleEta); + result.set_IDCaloBoundary_Angle3D(angle3D); + } + else + { + result.set_IDCaloBoundary_AngleEta(-999.); + result.set_IDCaloBoundary_Angle3D(-999.); + } + + ATH_MSG_DEBUG("End extrapolate_to_ID()"); - TVector3 vec(hitpos[Amg::x],hitpos[Amg::y],hitpos[Amg::z]); - - //get the tangentvector on this interaction point: - //GlobalMomentum* mom=params_on_surface_ID->TrackParameters::momentum().unit() ; - //Trk::GlobalMomentum* trackmom=params_on_surface_ID->Trk::TrackParameters::momentum(); - if(hitmom.mag()>0) { - //angle between vec and trackmom: - TVector3 Trackmom(hitmom[Amg::x],hitmom[Amg::y],hitmom[Amg::z]); - double angle3D=Trackmom.Angle(vec); //isn't this the same as TVector3 vec? - ATH_MSG_DEBUG(" 3D ANGLE "<<angle3D); - - double angleEta=vec.Theta()-Trackmom.Theta(); - ATH_MSG_DEBUG(" ANGLE dTHEA"<<angleEta); - - result.set_IDCaloBoundary_AngleEta(angleEta); - result.set_IDCaloBoundary_Angle3D(angle3D); - } else { - result.set_IDCaloBoundary_AngleEta(-999.); - result.set_IDCaloBoundary_Angle3D(-999.); - } - ATH_MSG_DEBUG("End extrapolate_to_ID()"); } //extrapolate_to_ID bool FastCaloSimCaloExtrapolation::get_calo_surface(TFCSExtrapolationState& result,std::vector<Trk::HitInfo>* hitVector) { - ATH_MSG_DEBUG("Start get_calo_surface()"); - result.set_CaloSurface_sample(CaloCell_ID_FCS::noSample); - result.set_CaloSurface_eta(-999); - result.set_CaloSurface_phi(-999); - result.set_CaloSurface_r(0); - result.set_CaloSurface_z(0); - double min_calo_surf_dist=1000; - - for(unsigned int i=0;i<m_surfacelist.size();++i) { - int sample=m_surfacelist[i]; - std::vector<Trk::HitInfo>::iterator it = hitVector->begin(); - while (it != hitVector->end() && it->detID != (3000+sample) ) { it++;} - if(it==hitVector->end()) continue; - Amg::Vector3D hitPos = (*it).trackParms->position(); - - //double offset = 0.; - double etaCalo = hitPos.eta(); - - msg(MSG::DEBUG)<<"test: entrance to calo surface : sample="<<sample<<" eta="<<etaCalo; - - if (fabs(etaCalo)<900) { - double phiCalo = hitPos.phi(); - double distsamp =deta(sample,etaCalo); - - msg(MSG::DEBUG)<<" phi="<<phiCalo<<" dist="<<distsamp; - if(distsamp<min_calo_surf_dist && min_calo_surf_dist>=0) { - //hitVector is ordered in r, so if first surface was hit, keep it - result.set_CaloSurface_sample(sample); - result.set_CaloSurface_eta(etaCalo); - result.set_CaloSurface_phi(phiCalo); - double rcalo=rent(sample,etaCalo); - double zcalo=zent(sample,etaCalo); - result.set_CaloSurface_r(rcalo); - result.set_CaloSurface_z(zcalo); - min_calo_surf_dist=distsamp; - msg(MSG::DEBUG)<<" r="<<rcalo<<" z="<<zcalo; - if(distsamp<0) { - msg(MSG::DEBUG)<<endreq; - break; - } - } - msg(MSG::DEBUG)<<endreq; - } else { - msg(MSG::DEBUG)<<": eta > 900, not using this"<<endreq; - } - } - - if(result.CaloSurface_sample()==CaloCell_ID_FCS::noSample) { - // first intersection with sensitive calo layer - std::vector<Trk::HitInfo>::iterator it = hitVector->begin(); - while ( it < hitVector->end() && (*it).detID != 3 ) { it++;} // to be updated - if (it==hitVector->end()) { // no calo intersection, abort - return false; - } - Amg::Vector3D surface_hitPos = (*it).trackParms->position(); - - result.set_CaloSurface_eta(surface_hitPos.eta()); - result.set_CaloSurface_phi(surface_hitPos.phi()); - result.set_CaloSurface_r(surface_hitPos.perp()); - result.set_CaloSurface_z(surface_hitPos[Amg::z]); - - double pT=(*it).trackParms->momentum().perp(); - if(TMath::Abs(result.CaloSurface_eta())>4.9 || pT<500 || (TMath::Abs(result.CaloSurface_eta())>4 && pT<1000) ) { - ATH_MSG_DEBUG("only entrance to calo entrance layer found, no surface : eta="<<result.CaloSurface_eta()<<" phi="<<result.CaloSurface_phi()<<" r="<<result.CaloSurface_r()<<" z="<<result.CaloSurface_z()<<" pT="<<pT); - } else { - ATH_MSG_WARNING("only entrance to calo entrance layer found, no surface : eta="<<result.CaloSurface_eta()<<" phi="<<result.CaloSurface_phi()<<" r="<<result.CaloSurface_r()<<" z="<<result.CaloSurface_z()<<" pT="<<pT); + ATH_MSG_DEBUG("Start get_calo_surface()"); + + result.set_CaloSurface_sample(CaloCell_ID_FCS::noSample); + result.set_CaloSurface_eta(-999); + result.set_CaloSurface_phi(-999); + result.set_CaloSurface_r(0); + result.set_CaloSurface_z(0); + double min_calo_surf_dist=1000; + + for(unsigned int i=0;i<m_surfacelist.size();++i) + { + + int sample=m_surfacelist[i]; + std::vector<Trk::HitInfo>::iterator it = hitVector->begin(); + + while (it != hitVector->end() && it->detID != (3000+sample) ) + it++; + + if(it==hitVector->end()) continue; + + Amg::Vector3D hitPos = (*it).trackParms->position(); + + //double offset = 0.; + double etaCalo = hitPos.eta(); + + if(fabs(etaCalo)<900) + { + double phiCalo = hitPos.phi(); + double distsamp =deta(sample,etaCalo); + + if(distsamp<min_calo_surf_dist && min_calo_surf_dist>=0) + { + //hitVector is ordered in r, so if first surface was hit, keep it + result.set_CaloSurface_sample(sample); + result.set_CaloSurface_eta(etaCalo); + result.set_CaloSurface_phi(phiCalo); + double rcalo=rent(sample,etaCalo); + double zcalo=zent(sample,etaCalo); + result.set_CaloSurface_r(rcalo); + result.set_CaloSurface_z(zcalo); + min_calo_surf_dist=distsamp; + msg(MSG::DEBUG)<<" r="<<rcalo<<" z="<<zcalo; + + if(distsamp<0) + { + msg(MSG::DEBUG)<<endreq; + break; } - } else { - ATH_MSG_DEBUG("entrance to calo surface : sample="<<result.CaloSurface_sample()<<" eta="<<result.CaloSurface_eta()<<" phi="<<result.CaloSurface_phi()<<" r="<<result.CaloSurface_r()<<" z="<<result.CaloSurface_z()<<" deta="<<min_calo_surf_dist); + } + msg(MSG::DEBUG)<<endreq; } + else + msg(MSG::DEBUG)<<": eta > 900, not using this"<<endreq; + } - ATH_MSG_DEBUG("End get_calo_surface()"); - return true; + if(result.CaloSurface_sample()==CaloCell_ID_FCS::noSample) + { + // first intersection with sensitive calo layer + std::vector<Trk::HitInfo>::iterator it = hitVector->begin(); + + while( it < hitVector->end() && (*it).detID != 3 ) + it++; // to be updated + + if (it==hitVector->end()) + return false; // no calo intersection, abort + + Amg::Vector3D surface_hitPos = (*it).trackParms->position(); + + result.set_CaloSurface_eta(surface_hitPos.eta()); + result.set_CaloSurface_phi(surface_hitPos.phi()); + result.set_CaloSurface_r(surface_hitPos.perp()); + result.set_CaloSurface_z(surface_hitPos[Amg::z]); + + double pT=(*it).trackParms->momentum().perp(); + if(TMath::Abs(result.CaloSurface_eta())>4.9 || pT<500 || (TMath::Abs(result.CaloSurface_eta())>4 && pT<1000) ) + ATH_MSG_DEBUG("only entrance to calo entrance layer found, no surface : eta="<<result.CaloSurface_eta()<<" phi="<<result.CaloSurface_phi()<<" r="<<result.CaloSurface_r()<<" z="<<result.CaloSurface_z()<<" pT="<<pT); + else + ATH_MSG_WARNING("only entrance to calo entrance layer found, no surface : eta="<<result.CaloSurface_eta()<<" phi="<<result.CaloSurface_phi()<<" r="<<result.CaloSurface_r()<<" z="<<result.CaloSurface_z()<<" pT="<<pT); + } //sample + else + { + ATH_MSG_DEBUG("entrance to calo surface : sample="<<result.CaloSurface_sample()<<" eta="<<result.CaloSurface_eta()<<" phi="<<result.CaloSurface_phi()<<" r="<<result.CaloSurface_r()<<" z="<<result.CaloSurface_z()<<" deta="<<min_calo_surf_dist); + } + + ATH_MSG_DEBUG("End get_calo_surface()"); + return true; } //UPDATED -bool FastCaloSimCaloExtrapolation::get_calo_etaphi(TFCSExtrapolationState& result,std::vector<Trk::HitInfo>* hitVector, int sample,int subpos) +bool FastCaloSimCaloExtrapolation::get_calo_etaphi(TFCSExtrapolationState& result,std::vector<Trk::HitInfo>* hitVector, int sample,int subpos) { - result.set_OK(sample,subpos,false); - result.set_eta(sample,subpos,result.CaloSurface_eta()); - result.set_phi(sample,subpos,result.CaloSurface_phi()); - result.set_r(sample,subpos,rpos(sample,result.CaloSurface_eta(),subpos)); - result.set_z(sample,subpos,zpos(sample,result.CaloSurface_eta(),subpos)); - double distsamp =deta(sample,result.CaloSurface_eta()); - double lrzpos =rzpos(sample,result.CaloSurface_eta(),subpos); - double hitdist=0; - bool best_found=false; - double best_target=0; - - std::vector<Trk::HitInfo>::iterator it = hitVector->begin(); - while ( it!= hitVector->end() && it->detID != (3000+sample) ) { it++;} - //while ((*it).detID != (3000+sample) && it < hitVector->end() ) it++; - - if (it!=hitVector->end()) { - Amg::Vector3D hitPos1 = (*it).trackParms->position(); - int sid1=(*it).detID; - int sid2=-1; - Amg::Vector3D hitPos; - Amg::Vector3D hitPos2; - - std::vector<Trk::HitInfo>::iterator itnext = it; - ++itnext; - if(itnext!=hitVector->end()) { - hitPos2 = (*itnext).trackParms->position(); - sid2=(*itnext).detID; - double eta_avg=0.5*(hitPos1.eta()+hitPos2.eta()); - double t; - if(isCaloBarrel(sample)) - { - double r=rpos(sample,eta_avg,subpos); - double r1=hitPos1.perp(); - double r2=hitPos2.perp(); - t=(r-r1)/(r2-r1); - best_target=r; - } - else - { - double z=zpos(sample,eta_avg,subpos); - double z1=hitPos1[Amg::z]; - double z2=hitPos2[Amg::z]; - t=(z-z1)/(z2-z1); - best_target=z; - } - hitPos=t*hitPos2+(1-t)*hitPos1; + + result.set_OK(sample,subpos,false); + result.set_eta(sample,subpos,result.CaloSurface_eta()); + result.set_phi(sample,subpos,result.CaloSurface_phi()); + result.set_r(sample,subpos,rpos(sample,result.CaloSurface_eta(),subpos)); + result.set_z(sample,subpos,zpos(sample,result.CaloSurface_eta(),subpos)); + + double distsamp =deta(sample,result.CaloSurface_eta()); + double lrzpos =rzpos(sample,result.CaloSurface_eta(),subpos); + double hitdist=0; + bool best_found=false; + double best_target=0; + + std::vector<Trk::HitInfo>::iterator it = hitVector->begin(); + + while( it!= hitVector->end() && it->detID != (3000+sample) ) + it++; + + //while ((*it).detID != (3000+sample) && it < hitVector->end() ) it++; + + if(it!=hitVector->end()) + { + + Amg::Vector3D hitPos1 = (*it).trackParms->position(); + int sid1=(*it).detID; + int sid2=-1; + Amg::Vector3D hitPos; + Amg::Vector3D hitPos2; + + std::vector<Trk::HitInfo>::iterator itnext = it; + ++itnext; + if(itnext!=hitVector->end()) + { + hitPos2 = (*itnext).trackParms->position(); + sid2=(*itnext).detID; + double eta_avg=0.5*(hitPos1.eta()+hitPos2.eta()); + double t; + + if(isCaloBarrel(sample)) + { + double r=rpos(sample,eta_avg,subpos); + double r1=hitPos1.perp(); + double r2=hitPos2.perp(); + t=(r-r1)/(r2-r1); + best_target=r; + } + else + { + double z=zpos(sample,eta_avg,subpos); + double z1=hitPos1[Amg::z]; + double z2=hitPos2[Amg::z]; + t=(z-z1)/(z2-z1); + best_target=z; + } + hitPos=t*hitPos2+(1-t)*hitPos1; + + } + else + { + hitPos=hitPos1; + hitPos2=hitPos1; + } + + double etaCalo = hitPos.eta(); + double phiCalo = hitPos.phi(); + result.set_OK(sample,subpos,true); + result.set_eta(sample,subpos,etaCalo); + result.set_phi(sample,subpos,phiCalo); + result.set_r(sample,subpos,hitPos.perp()); + result.set_z(sample,subpos,hitPos[Amg::z]); + hitdist=hitPos.mag(); + lrzpos=rzpos(sample,etaCalo,subpos); + distsamp=deta(sample,etaCalo); + best_found=true; + + ATH_MSG_DEBUG("extrapol with layer hit: id="<<sid1<<" -> "<<sid2<<" target r/z="<<best_target<<" r1="<<hitPos1.perp()<<" z1="<<hitPos1[Amg::z]<< + " r2="<<hitPos2.perp()<<" z2="<<hitPos2[Amg::z]<<" result.r="<<result.r(sample,subpos)<<" result.z="<<result.z(sample,subpos)); + + } + + if(!best_found) + { + it = hitVector->begin(); + double best_dist=0.5; + bool best_inside=false; + int best_id1,best_id2; + Amg::Vector3D best_hitPos=(*it).trackParms->position(); + while (it < hitVector->end()-1 ) + { + Amg::Vector3D hitPos1 = (*it).trackParms->position(); + int sid1=(*it).detID; + it++; + Amg::Vector3D hitPos2 = (*it).trackParms->position(); + int sid2=(*it).detID; + double eta_avg=0.5*(hitPos1.eta()+hitPos2.eta()); + double t; + double tmp_target=0; + if(isCaloBarrel(sample)) + { + double r=rpos(sample,eta_avg,subpos); + double r1=hitPos1.perp(); + double r2=hitPos2.perp(); + t=(r-r1)/(r2-r1); + tmp_target=r; + } + else + { + double z=zpos(sample,eta_avg,subpos); + double z1=hitPos1[Amg::z]; + double z2=hitPos2[Amg::z]; + t=(z-z1)/(z2-z1); + tmp_target=z; + } + Amg::Vector3D hitPos=t*hitPos2+(1-t)*hitPos1; + double dist=TMath::Min(TMath::Abs(t-0),TMath::Abs(t-1)); + bool inside=false; + if(t>=0 && t<=1) inside=true; + if(!best_found || inside) + { + if(!best_inside || dist<best_dist) + { + best_dist=dist; + best_hitPos=hitPos; + best_inside=inside; + best_found=true; + best_id1=sid1; + best_id2=sid2; + best_target=tmp_target; } - else - { - hitPos=hitPos1; - hitPos2=hitPos1; - } - double etaCalo = hitPos.eta(); - double phiCalo = hitPos.phi(); + } + else + { + if(!best_inside && dist<best_dist) + { + best_dist=dist; + best_hitPos=hitPos; + best_inside=inside; + best_found=true; + best_id1=sid1; + best_id2=sid2; + best_target=tmp_target; + } + } + ATH_MSG_DEBUG("extrapol without layer hit: id="<<sid1<<" -> "<<sid2<<" dist="<<dist<<" mindist="<<best_dist<< + " t="<<t<<" best_inside="<<best_inside<<" target r/z="<<tmp_target<< + " r1="<<hitPos1.perp()<<" z1="<<hitPos1[Amg::z]<<" r2="<<hitPos2.perp()<<" z2="<<hitPos2[Amg::z]<< + " re="<<hitPos.perp()<<" ze="<<hitPos[Amg::z]<< + " rb="<<best_hitPos.perp()<<" zb="<<best_hitPos[Amg::z]); + if(best_found) + { + double etaCalo = best_hitPos.eta(); result.set_OK(sample,subpos,true); result.set_eta(sample,subpos,etaCalo); - result.set_phi(sample,subpos,phiCalo); - result.set_r(sample,subpos,hitPos.perp()); - result.set_z(sample,subpos,hitPos[Amg::z]); - hitdist=hitPos.mag(); + result.set_phi(sample,subpos,best_hitPos.phi()); + result.set_r(sample,subpos,best_hitPos.perp()); + result.set_z(sample,subpos,best_hitPos[Amg::z]); + hitdist=best_hitPos.mag(); lrzpos=rzpos(sample,etaCalo,subpos); distsamp=deta(sample,etaCalo); - best_found=true; - ATH_MSG_DEBUG(" extrapol with layer hit: id="<<sid1<<" -> "<<sid2<< - " target r/z="<<best_target<< - " r1="<<hitPos1.perp()<<" z1="<<hitPos1[Amg::z]<<" r2="<<hitPos2.perp()<<" z2="<<hitPos2[Amg::z]<< - " re="<<result.r(sample,subpos)<<" ze="<<result.z(sample,subpos) - ); - } - if(!best_found) { - it = hitVector->begin(); - double best_dist=0.5; - bool best_inside=false; - int best_id1,best_id2; - Amg::Vector3D best_hitPos=(*it).trackParms->position(); - while (it < hitVector->end()-1 ) { - Amg::Vector3D hitPos1 = (*it).trackParms->position(); - int sid1=(*it).detID; - it++; - Amg::Vector3D hitPos2 = (*it).trackParms->position(); - int sid2=(*it).detID; - double eta_avg=0.5*(hitPos1.eta()+hitPos2.eta()); - double t; - double tmp_target=0; - if(isCaloBarrel(sample)) { - double r=rpos(sample,eta_avg,subpos); - double r1=hitPos1.perp(); - double r2=hitPos2.perp(); - t=(r-r1)/(r2-r1); - tmp_target=r; - } else { - double z=zpos(sample,eta_avg,subpos); - double z1=hitPos1[Amg::z]; - double z2=hitPos2[Amg::z]; - t=(z-z1)/(z2-z1); - tmp_target=z; - } - Amg::Vector3D hitPos=t*hitPos2+(1-t)*hitPos1; - double dist=TMath::Min(TMath::Abs(t-0),TMath::Abs(t-1)); - bool inside=false; - if(t>=0 && t<=1) inside=true; - if(!best_found || inside) { - if(!best_inside || dist<best_dist) { - best_dist=dist; - best_hitPos=hitPos; - best_inside=inside; - best_found=true; - best_id1=sid1; - best_id2=sid2; - best_target=tmp_target; - } - } else { - if(!best_inside && dist<best_dist) { - best_dist=dist; - best_hitPos=hitPos; - best_inside=inside; - best_found=true; - best_id1=sid1; - best_id2=sid2; - best_target=tmp_target; - } - } - ATH_MSG_VERBOSE(" extrapol without layer hit: id="<<sid1<<" -> "<<sid2<<" dist="<<dist<<" mindist="<<best_dist<< - " t="<<t<<" best_inside="<<best_inside<<" target r/z="<<tmp_target<< - " r1="<<hitPos1.perp()<<" z1="<<hitPos1[Amg::z]<<" r2="<<hitPos2.perp()<<" z2="<<hitPos2[Amg::z]<< - " re="<<hitPos.perp()<<" ze="<<hitPos[Amg::z]<< - " rb="<<best_hitPos.perp()<<" zb="<<best_hitPos[Amg::z] - ); - if(best_found) { - double etaCalo = best_hitPos.eta(); - result.set_OK(sample,subpos,true); - result.set_eta(sample,subpos,etaCalo); - result.set_phi(sample,subpos,best_hitPos.phi()); - result.set_r(sample,subpos,best_hitPos.perp()); - result.set_z(sample,subpos,best_hitPos[Amg::z]); - - hitdist=best_hitPos.mag(); - lrzpos=rzpos(sample,etaCalo,subpos); - distsamp=deta(sample,etaCalo); - } - } - if(best_found) { - ATH_MSG_DEBUG(" extrapol without layer hit: id="<<best_id1<<" -> "<<best_id2<<" mindist="<<best_dist<< + } + } //while hit vector + + if(best_found) + { + ATH_MSG_DEBUG("extrapol without layer hit: id="<<best_id1<<" -> "<<best_id2<<" mindist="<<best_dist<< " best_inside="<<best_inside<<" target r/z="<<best_target<< - " rb="<<best_hitPos.perp()<<" zb="<<best_hitPos[Amg::z] - ); - } - } - - if(isCaloBarrel(sample)) lrzpos*=cosh(result.eta(sample,subpos)); - else lrzpos= fabs(lrzpos/tanh(result.eta(sample,subpos))); - - result.set_d(sample,subpos,lrzpos); - result.set_detaBorder(sample,subpos,distsamp); - - if(msgLvl(MSG::DEBUG)) { - msg(MSG::DEBUG)<<" Final par TTC sample "<<sample<<" subpos="<<subpos; - if(result.OK(sample,subpos)) msg()<<" (good)"; - else msg()<<" (bad)"; - msg()<<" eta=" << result.eta(sample,subpos) << " phi=" << result.phi(sample,subpos) <<" dCalo="<<result.d(sample,subpos)<<" dist(hit)="<<hitdist<< endreq; - } - - return result.OK(sample,subpos); + " rb="<<best_hitPos.perp()<<" zb="<<best_hitPos[Amg::z] ); + } + } + + if(isCaloBarrel(sample)) + lrzpos*=cosh(result.eta(sample,subpos)); + else + lrzpos= fabs(lrzpos/tanh(result.eta(sample,subpos))); + + result.set_d(sample,subpos,lrzpos); + result.set_detaBorder(sample,subpos,distsamp); + + std::cout<<"Final TTC result for sample "<<sample<<" subpos="<<subpos<<" OK() "<<result.OK(sample,subpos)<<" eta="<<result.eta(sample,subpos)<<" phi="<<result.phi(sample,subpos)<<" dCalo="<<result.d(sample,subpos)<<" dist(hit)="<<hitdist<<std::endl; + + return result.OK(sample,subpos); } //UPDATED -bool FastCaloSimCaloExtrapolation::rz_cylinder_get_calo_etaphi(std::vector<Trk::HitInfo>* hitVector, double cylR, double cylZ, Amg::Vector3D& pos, Amg::Vector3D& mom) +bool FastCaloSimCaloExtrapolation::rz_cylinder_get_calo_etaphi(std::vector<Trk::HitInfo>* hitVector, double cylR, double cylZ, Amg::Vector3D& pos, Amg::Vector3D& mom) { + bool best_found=false; double best_dist=10000; bool best_inside=false; @@ -641,7 +747,7 @@ bool FastCaloSimCaloExtrapolation::rz_cylinder_get_calo_etaphi(std::vector<Trk:: double dist=hitPos.mag(); bool inside=false; if(t>=-0.001 && t<=1.001) inside=true; - + if(!best_found || inside) { if(!best_inside || dist<best_dist) { best_dist=dist; @@ -670,16 +776,17 @@ bool FastCaloSimCaloExtrapolation::rz_cylinder_get_calo_etaphi(std::vector<Trk:: " rb="<<best_hitPos.perp()<<" zb="<<best_hitPos[Amg::z] ); } - } - + } + if(best_found) { ATH_MSG_DEBUG(" extrapol to r="<<cylR<<" z="<<cylZ<<": id="<<best_id1<<" -> "<<best_id2<<" dist="<<best_dist<< " best_inside="<<best_inside<< " rb="<<best_hitPos.perp()<<" zb="<<best_hitPos[Amg::z] ); - } + } pos=best_hitPos; + return best_found; } @@ -694,17 +801,17 @@ double FastCaloSimCaloExtrapolation::deta(int sample,double eta) const return GetCaloGeometry()->deta(sample,eta); } -void FastCaloSimCaloExtrapolation::minmaxeta(int sample,double eta,double& mineta,double& maxeta) const +void FastCaloSimCaloExtrapolation::minmaxeta(int sample,double eta,double& mineta,double& maxeta) const { GetCaloGeometry()->minmaxeta(sample,eta,mineta,maxeta); } -double FastCaloSimCaloExtrapolation::rmid(int sample,double eta) const +double FastCaloSimCaloExtrapolation::rmid(int sample,double eta) const { return GetCaloGeometry()->rmid(sample,eta); } -double FastCaloSimCaloExtrapolation::zmid(int sample,double eta) const +double FastCaloSimCaloExtrapolation::zmid(int sample,double eta) const { return GetCaloGeometry()->zmid(sample,eta); } @@ -714,12 +821,12 @@ double FastCaloSimCaloExtrapolation::rzmid(int sample,double eta) const return GetCaloGeometry()->rzmid(sample,eta); } -double FastCaloSimCaloExtrapolation::rent(int sample,double eta) const +double FastCaloSimCaloExtrapolation::rent(int sample,double eta) const { return GetCaloGeometry()->rent(sample,eta); } -double FastCaloSimCaloExtrapolation::zent(int sample,double eta) const +double FastCaloSimCaloExtrapolation::zent(int sample,double eta) const { return GetCaloGeometry()->zent(sample,eta); } @@ -729,12 +836,12 @@ double FastCaloSimCaloExtrapolation::rzent(int sample,double eta) const return GetCaloGeometry()->rzent(sample,eta); } -double FastCaloSimCaloExtrapolation::rext(int sample,double eta) const +double FastCaloSimCaloExtrapolation::rext(int sample,double eta) const { return GetCaloGeometry()->rext(sample,eta); } -double FastCaloSimCaloExtrapolation::zext(int sample,double eta) const +double FastCaloSimCaloExtrapolation::zext(int sample,double eta) const { return GetCaloGeometry()->zext(sample,eta); } @@ -758,3 +865,5 @@ double FastCaloSimCaloExtrapolation::rzpos(int sample,double eta,int subpos) con { return GetCaloGeometry()->rzpos(sample,eta,subpos); } + + diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/FastCaloSimCaloExtrapolation.h b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/FastCaloSimCaloExtrapolation.h index 38366e17ed03..b2689f242488 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/FastCaloSimCaloExtrapolation.h +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/FastCaloSimCaloExtrapolation.h @@ -34,62 +34,62 @@ namespace HepPDT class FastCaloSimCaloExtrapolation:public AthAlgTool, virtual public IFastCaloSimCaloExtrapolation { -public: - FastCaloSimCaloExtrapolation( const std::string& t, const std::string& n, const IInterface* p ); - ~FastCaloSimCaloExtrapolation(); - - virtual StatusCode initialize() override final; - virtual StatusCode finalize() override final; - - enum SUBPOS { SUBPOS_MID = TFCSExtrapolationState::SUBPOS_MID, SUBPOS_ENT = TFCSExtrapolationState::SUBPOS_ENT, SUBPOS_EXT = TFCSExtrapolationState::SUBPOS_EXT}; //MID=middle, ENT=entrance, EXT=exit of cal layer - - virtual void extrapolate(TFCSExtrapolationState& result,const TFCSTruthState* truth) override final; - -protected: - IFastCaloSimGeometryHelper* GetCaloGeometry() const {return &(*m_CaloGeometryHelper);}; - - // extrapolation through Calo - std::vector<Trk::HitInfo>* caloHits(const TFCSTruthState* truth) const; - void extrapolate(TFCSExtrapolationState& result,const TFCSTruthState* truth,std::vector<Trk::HitInfo>* hitVector); - void extrapolate_to_ID(TFCSExtrapolationState& result,const TFCSTruthState* truth,std::vector<Trk::HitInfo>* hitVector); - bool get_calo_etaphi(TFCSExtrapolationState& result,std::vector<Trk::HitInfo>* hitVector,int sample,int subpos=SUBPOS_MID); - bool get_calo_surface(TFCSExtrapolationState& result,std::vector<Trk::HitInfo>* hitVector); - bool rz_cylinder_get_calo_etaphi(std::vector<Trk::HitInfo>* hitVector, double cylR, double cylZ, Amg::Vector3D& pos, Amg::Vector3D& mom); - - bool isCaloBarrel(int sample) const; - double deta(int sample,double eta) const; - void minmaxeta(int sample,double eta,double& mineta,double& maxeta) const; - double rzmid(int sample,double eta) const; - double rzent(int sample,double eta) const; - double rzext(int sample,double eta) const; - double rmid(int sample,double eta) const; - double rent(int sample,double eta) const; - double rext(int sample,double eta) const; - double zmid(int sample,double eta) const; - double zent(int sample,double eta) const; - double zext(int sample,double eta) const; - double rpos(int sample,double eta,int subpos = CaloSubPos::SUBPOS_MID) const; - double zpos(int sample,double eta,int subpos = CaloSubPos::SUBPOS_MID) const; - double rzpos(int sample,double eta,int subpos = CaloSubPos::SUBPOS_MID) const; - - HepPDT::ParticleDataTable* m_particleDataTable; - - double m_CaloBoundaryR; - double m_CaloBoundaryZ; - double m_calomargin; - - std::vector< int > m_surfacelist; - - // The new Extrapolator setup - ToolHandle<Trk::ITimedExtrapolator> m_extrapolator; - ToolHandle<ICaloSurfaceHelper> m_caloSurfaceHelper; - mutable const Trk::TrackingVolume* m_caloEntrance; - std::string m_caloEntranceName; - - Trk::PdgToParticleHypothesis m_pdgToParticleHypothesis; - - // The FastCaloSimGeometryHelper tool - ToolHandle<IFastCaloSimGeometryHelper> m_CaloGeometryHelper; + public: + FastCaloSimCaloExtrapolation( const std::string& t, const std::string& n, const IInterface* p ); + ~FastCaloSimCaloExtrapolation(); + + virtual StatusCode initialize() override final; + virtual StatusCode finalize() override final; + + enum SUBPOS { SUBPOS_MID = TFCSExtrapolationState::SUBPOS_MID, SUBPOS_ENT = TFCSExtrapolationState::SUBPOS_ENT, SUBPOS_EXT = TFCSExtrapolationState::SUBPOS_EXT}; //MID=middle, ENT=entrance, EXT=exit of cal layer + + virtual void extrapolate(TFCSExtrapolationState& result,const TFCSTruthState* truth) override final; + + protected: + IFastCaloSimGeometryHelper* GetCaloGeometry() const {return &(*m_CaloGeometryHelper);}; + + // extrapolation through Calo + std::vector<Trk::HitInfo>* caloHits(const TFCSTruthState* truth) const; + void extrapolate(TFCSExtrapolationState& result,const TFCSTruthState* truth,std::vector<Trk::HitInfo>* hitVector); + void extrapolate_to_ID(TFCSExtrapolationState& result,const TFCSTruthState* truth,std::vector<Trk::HitInfo>* hitVector); + bool get_calo_etaphi(TFCSExtrapolationState& result,std::vector<Trk::HitInfo>* hitVector,int sample,int subpos=SUBPOS_MID); + bool get_calo_surface(TFCSExtrapolationState& result,std::vector<Trk::HitInfo>* hitVector); + bool rz_cylinder_get_calo_etaphi(std::vector<Trk::HitInfo>* hitVector, double cylR, double cylZ, Amg::Vector3D& pos, Amg::Vector3D& mom); + + bool isCaloBarrel(int sample) const; + double deta(int sample,double eta) const; + void minmaxeta(int sample,double eta,double& mineta,double& maxeta) const; + double rzmid(int sample,double eta) const; + double rzent(int sample,double eta) const; + double rzext(int sample,double eta) const; + double rmid(int sample,double eta) const; + double rent(int sample,double eta) const; + double rext(int sample,double eta) const; + double zmid(int sample,double eta) const; + double zent(int sample,double eta) const; + double zext(int sample,double eta) const; + double rpos(int sample,double eta,int subpos = CaloSubPos::SUBPOS_MID) const; + double zpos(int sample,double eta,int subpos = CaloSubPos::SUBPOS_MID) const; + double rzpos(int sample,double eta,int subpos = CaloSubPos::SUBPOS_MID) const; + + HepPDT::ParticleDataTable* m_particleDataTable; + + double m_CaloBoundaryR; + double m_CaloBoundaryZ; + double m_calomargin; + + std::vector< int > m_surfacelist; + + // The new Extrapolator setup + ToolHandle<Trk::ITimedExtrapolator> m_extrapolator; + ToolHandle<ICaloSurfaceHelper> m_caloSurfaceHelper; + mutable const Trk::TrackingVolume* m_caloEntrance; + std::string m_caloEntranceName; + + Trk::PdgToParticleHypothesis m_pdgToParticleHypothesis; + + // The FastCaloSimGeometryHelper tool + ToolHandle<IFastCaloSimGeometryHelper> m_CaloGeometryHelper; }; #endif // FastCaloSimCaloExtrapolation_H diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/FastCaloSimGeometryHelper.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/FastCaloSimGeometryHelper.cxx index d7983b0435e2..c4f12c5b1957 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/FastCaloSimGeometryHelper.cxx +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/FastCaloSimGeometryHelper.cxx @@ -3,8 +3,8 @@ */ #include "FastCaloSimGeometryHelper.h" -//#include "CaloDetDescr/CaloDetDescrElement.h" -#include "ISF_FastCaloSimParametrization/CaloDetDescrElement.h" +#include "CaloDetDescr/CaloDetDescrElement.h" +//#include "ISF_FastCaloSimParametrization/CaloDetDescrElement.h" #include "CaloDetDescr/CaloDetDescrManager.h" #include "GeoModelInterfaces/IGeoModelSvc.h" @@ -13,6 +13,8 @@ using namespace std; /** Constructor **/ FastCaloSimGeometryHelper::FastCaloSimGeometryHelper(const std::string& t, const std::string& n, const IInterface* p) : AthAlgTool(t,n,p), CaloGeometry(), m_geoModel(0),m_caloMgr(0) { + std::cout<<"CHECK123 in the FastCaloSimGeometryHelper constructor "<<std::endl; + declareInterface<IFastCaloSimGeometryHelper>(this); //declareProperty("XXX" , XXX ); @@ -27,6 +29,9 @@ StatusCode FastCaloSimGeometryHelper::initialize() { ATH_MSG_INFO("Initializing FastCaloSimGeometryHelper"); + std::cout<<"CHECK123 in the FastCaloSimGeometryHelper initialize "<<std::endl; + + if(service("GeoModelSvc", m_geoModel).isFailure()) { ATH_MSG_ERROR( "Could not locate GeoModelSvc" ); return StatusCode::FAILURE; @@ -75,19 +80,26 @@ StatusCode FastCaloSimGeometryHelper::finalize() bool FastCaloSimGeometryHelper::LoadGeometryFromCaloDDM() { ATH_MSG_INFO("Start LoadGeometryFromCaloDDM()"); - //int jentry=0; - //for(CaloDetDescrManager::calo_element_const_iterator calo_iter=m_caloMgr->element_begin();calo_iter<m_caloMgr->element_end();++calo_iter) { - //const CaloDetDescrElement* pcell=*calo_iter; - //addcell(pcell); - - //if(jentry%10000==0) { - //ATH_MSG_DEBUG("Load calo cell "<<jentry<<" : "<<pcell->getSampling()<<", "<<pcell->identify()); - //} - //++jentry; - //} - + + std::cout<<"CHECK123 in LoadGeometryFromCaloDDM "<<std::endl; + + int jentry=0; + for(CaloDetDescrManager::calo_element_const_iterator calo_iter=m_caloMgr->element_begin();calo_iter<m_caloMgr->element_end();++calo_iter) + { + const CaloDetDescrElement* pcell=*calo_iter; + addcell(pcell); + + if(jentry%10000==0) + { + ATH_MSG_DEBUG("Load calo cell "<<jentry<<" : "<<pcell->getSampling()<<", "<<pcell->identify()); + } + ++jentry; + } + bool ok=PostProcessGeometry(); - + + std::cout<<"CHECK123 in LoadGeometryFromCaloDDM ok="<<ok<<std::endl; + ATH_MSG_INFO("Done LoadGeometryFromCaloDDM()"); return ok; diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/ISF_HitAnalysis.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/ISF_HitAnalysis.cxx index d40bb04979c1..d5ef695fb5a4 100755 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/ISF_HitAnalysis.cxx +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/src/ISF_HitAnalysis.cxx @@ -76,120 +76,120 @@ #include <iostream> -//const std::string MC_DIGI_PARAM = "/Digitization/Parameters"; +//const std::string MC_DIGI_PARAM = "/Digitization/Parameters"; //const std::string MC_SIM_PARAM = "/Simulation/Parameters"; ISF_HitAnalysis::ISF_HitAnalysis(const std::string& name, ISvcLocator* pSvcLocator) -: AthAlgorithm(name, pSvcLocator) -//, m_storeGate(0) - , m_geoModel(0) - , m_tileInfo(0) -, m_larEmID(0) - , m_larFcalID(0) -, m_larHecID(0) - , m_tileID(0) - , m_tileMgr(0) - , m_hit_x(0) - , m_hit_y(0) - , m_hit_z(0) - , m_hit_energy(0) - , m_hit_time(0) -, m_hit_identifier(0) - , m_hit_cellidentifier(0) -, m_islarbarrel(0) - , m_islarendcap(0) -, m_islarhec(0) - , m_islarfcal(0) - , m_istile(0) - , m_hit_sampling(0) - , m_hit_samplingfraction(0) -, m_truth_energy(0) - , m_truth_px(0) - , m_truth_py(0) - , m_truth_pz(0) - , m_truth_pdg(0) - , m_truth_barcode(0) - , m_truth_vtxbarcode(0) - , m_cell_identifier(0) - , m_cell_energy(0) - , m_cell_sampling(0) - , m_g4hit_energy(0) - , m_g4hit_time(0) - , m_g4hit_identifier(0) - , m_g4hit_cellidentifier(0) - , m_g4hit_samplingfraction(0) - , m_g4hit_sampling(0) - // , m_matched_cells(0) - , m_tree(0) - , m_ntupleFileName("/ntuples/file1") - , m_ntupleDirName("ISF_HitAnalysis") - , m_ntupleTreeName("CaloHitAna") - , m_metadataTreeName("MetaData") - , m_geoFileName("ISF_Geometry") - , m_thistSvc(0) - , m_calo_dd_man(0) - //##################### - , m_eta_calo_surf(0) - , m_phi_calo_surf(0) - , m_d_calo_surf(0) - , m_ptruth_eta(0) - , m_ptruth_phi(0) - , m_ptruth_e(0) - , m_ptruth_et(0) - , m_ptruth_pt(0) - , m_ptruth_p(0) - , m_pdgid(0) - - //###################### - - , m_TTC_entrance_eta(0) - , m_TTC_entrance_phi(0) - , m_TTC_entrance_r(0) - , m_TTC_entrance_z(0) - , m_TTC_back_eta(0) - , m_TTC_back_phi(0) - , m_TTC_back_r(0) - , m_TTC_back_z(0) - , m_TTC_IDCaloBoundary_eta(0) - , m_TTC_IDCaloBoundary_phi(0) - , m_TTC_IDCaloBoundary_r(0) - , m_TTC_IDCaloBoundary_z(0) - , m_TTC_Angle3D(0) - , m_TTC_AngleEta(0) - - , m_newTTC_entrance_eta(0) - , m_newTTC_entrance_phi(0) - , m_newTTC_entrance_r(0) - , m_newTTC_entrance_z(0) - , m_newTTC_back_eta(0) - , m_newTTC_back_phi(0) - , m_newTTC_back_r(0) - , m_newTTC_back_z(0) - , m_newTTC_IDCaloBoundary_eta(0) - , m_newTTC_IDCaloBoundary_phi(0) - , m_newTTC_IDCaloBoundary_r(0) - , m_newTTC_IDCaloBoundary_z(0) - , m_newTTC_Angle3D(0) - , m_newTTC_AngleEta(0) - - , m_caloEntrance(0) - , m_calo_tb_coord(0) - , m_sample_calo_surf(CaloCell_ID_FCS::noSample) - , m_particleDataTable(0) - - ,m_MC_DIGI_PARAM("/Digitization/Parameters") - ,m_MC_SIM_PARAM("/Simulation/Parameters") - - //###################### + : AthAlgorithm(name, pSvcLocator) + //, m_storeGate(0) + , m_geoModel(0) + , m_tileInfo(0) + , m_larEmID(0) + , m_larFcalID(0) + , m_larHecID(0) + , m_tileID(0) + , m_tileMgr(0) + , m_hit_x(0) + , m_hit_y(0) + , m_hit_z(0) + , m_hit_energy(0) + , m_hit_time(0) + , m_hit_identifier(0) + , m_hit_cellidentifier(0) + , m_islarbarrel(0) + , m_islarendcap(0) + , m_islarhec(0) + , m_islarfcal(0) + , m_istile(0) + , m_hit_sampling(0) + , m_hit_samplingfraction(0) + , m_truth_energy(0) + , m_truth_px(0) + , m_truth_py(0) + , m_truth_pz(0) + , m_truth_pdg(0) + , m_truth_barcode(0) + , m_truth_vtxbarcode(0) + , m_cell_identifier(0) + , m_cell_energy(0) + , m_cell_sampling(0) + , m_g4hit_energy(0) + , m_g4hit_time(0) + , m_g4hit_identifier(0) + , m_g4hit_cellidentifier(0) + , m_g4hit_samplingfraction(0) + , m_g4hit_sampling(0) + // , m_matched_cells(0) + , m_tree(0) + , m_ntupleFileName("/ntuples/file1") + , m_ntupleDirName("ISF_HitAnalysis") + , m_ntupleTreeName("CaloHitAna") + , m_metadataTreeName("MetaData") + , m_geoFileName("ISF_Geometry") + , m_thistSvc(0) + , m_calo_dd_man(0) + //##################### + , m_eta_calo_surf(0) + , m_phi_calo_surf(0) + , m_d_calo_surf(0) + , m_ptruth_eta(0) + , m_ptruth_phi(0) + , m_ptruth_e(0) + , m_ptruth_et(0) + , m_ptruth_pt(0) + , m_ptruth_p(0) + , m_pdgid(0) + + //###################### + + , m_TTC_entrance_eta(0) + , m_TTC_entrance_phi(0) + , m_TTC_entrance_r(0) + , m_TTC_entrance_z(0) + , m_TTC_back_eta(0) + , m_TTC_back_phi(0) + , m_TTC_back_r(0) + , m_TTC_back_z(0) + , m_TTC_IDCaloBoundary_eta(0) + , m_TTC_IDCaloBoundary_phi(0) + , m_TTC_IDCaloBoundary_r(0) + , m_TTC_IDCaloBoundary_z(0) + , m_TTC_Angle3D(0) + , m_TTC_AngleEta(0) + + , m_newTTC_entrance_eta(0) + , m_newTTC_entrance_phi(0) + , m_newTTC_entrance_r(0) + , m_newTTC_entrance_z(0) + , m_newTTC_back_eta(0) + , m_newTTC_back_phi(0) + , m_newTTC_back_r(0) + , m_newTTC_back_z(0) + , m_newTTC_IDCaloBoundary_eta(0) + , m_newTTC_IDCaloBoundary_phi(0) + , m_newTTC_IDCaloBoundary_r(0) + , m_newTTC_IDCaloBoundary_z(0) + , m_newTTC_Angle3D(0) + , m_newTTC_AngleEta(0) + + , m_caloEntrance(0) + , m_calo_tb_coord(0) + , m_sample_calo_surf(CaloCell_ID_FCS::noSample) + , m_particleDataTable(0) + + ,m_MC_DIGI_PARAM("/Digitization/Parameters") + ,m_MC_SIM_PARAM("/Simulation/Parameters") + + //###################### //Note that m_xxx are pointers to vectors set to 0, not set to empty vector! see note around TBranch { - declareProperty("NtupleFileName", m_ntupleFileName); - declareProperty("NtupleDirectoryName", m_ntupleDirName); - declareProperty("NtupleTreeName", m_ntupleTreeName); - declareProperty("GeoFileName", m_geoFileName); - declareProperty("MetadataTreeName", m_metadataTreeName); + declareProperty("NtupleFileName", m_ntupleFileName); + declareProperty("NtupleDirectoryName", m_ntupleDirName); + declareProperty("NtupleTreeName", m_ntupleTreeName); + declareProperty("GeoFileName", m_geoFileName); + declareProperty("MetadataTreeName", m_metadataTreeName); declareProperty("NTruthParticles", m_NtruthParticles=1, "Number of truth particles saved from the truth collection, -1 to save all"); declareProperty("FastCaloSimCaloExtrapolation", m_FastCaloSimCaloExtrapolation ); @@ -210,7 +210,7 @@ ISF_HitAnalysis::ISF_HitAnalysis(const std::string& name, ISvcLocator* pSvcLocat declareProperty("CaloSurfaceHelper", m_caloSurfaceHelper ); declareProperty("CaloGeometryHelper", m_CaloGeometryHelper ); - + declareProperty("MetaDataSim", m_MC_SIM_PARAM ); declareProperty("MetaDataDigi", m_MC_DIGI_PARAM ); @@ -220,1212 +220,1224 @@ ISF_HitAnalysis::ISF_HitAnalysis(const std::string& name, ISvcLocator* pSvcLocat m_surfacelist.push_back(CaloCell_ID_FCS::EME1); m_surfacelist.push_back(CaloCell_ID_FCS::EME2); m_surfacelist.push_back(CaloCell_ID_FCS::FCAL0); - - //TLorentzVector *t; - + } -ISF_HitAnalysis::~ISF_HitAnalysis() +ISF_HitAnalysis::~ISF_HitAnalysis() { } StatusCode ISF_HitAnalysis::geoInit(IOVSVC_CALLBACK_ARGS) { - ATH_MSG_INFO("geoInit for " << m_geoModel->atlasVersion() ); - - StatusCode sc = detStore()->retrieve(m_tileMgr); - if (sc.isFailure()) - { - ATH_MSG_ERROR( "Unable to retrieve TileDetDescrManager from DetectorStore" ); - m_tileMgr=0; - } - - sc = detStore()->retrieve(m_tileID); - if (sc.isFailure()) - { - ATH_MSG_ERROR( "Unable to retrieve TileID helper from DetectorStore" ); - m_tileID=0; - } - - const DataHandle<CaloIdManager> caloIdManager; - sc=detStore()->retrieve(caloIdManager); - if(sc.isSuccess()) - ATH_MSG_DEBUG("CaloIDManager retrieved."); - else - throw std::runtime_error("ISF_HitAnalysis: Unable to retrieve CaloIDManeger"); - m_larEmID=caloIdManager->getEM_ID(); - if(m_larEmID==0) - throw std::runtime_error("ISF_HitAnalysis: Invalid LAr EM ID helper"); - m_larFcalID=caloIdManager->getFCAL_ID(); - if(m_larFcalID==0) - throw std::runtime_error("ISF_HitAnalysis: Invalid FCAL ID helper"); - m_larHecID=caloIdManager->getHEC_ID(); - if(m_larHecID==0) - throw std::runtime_error("ISF_HitAnalysis: Invalid HEC ID helper"); - m_tileID=caloIdManager->getTileID(); - if(m_tileID==0) - throw std::runtime_error("ISF_HitAnalysis: Invalid Tile ID helper"); - sc=detStore()->regHandle(m_dd_fSampl,"LArfSampl"); - if(sc.isFailure()) - { - ATH_MSG_ERROR("Unable to register handle for LArfSampl"); - return StatusCode::FAILURE; - } - - detStore()->retrieve(m_tileInfo,"TileInfo"); - if(sc.isFailure()) - { - ATH_MSG_ERROR("Unable to retrieve TileInfo from DetectorStore"); - return StatusCode::FAILURE; - } - m_calo_dd_man = CaloDetDescrManager::instance(); - - // Retrieve Tools - IToolSvc* p_toolSvc = 0; - if ( service("ToolSvc",p_toolSvc).isFailure() ) - { - ATH_MSG_ERROR("Cannot find ToolSvc! "); - return StatusCode::FAILURE; - } - else - { - IAlgTool* algTool; - - // Get TimedExtrapolator *************************************************************************************************** - if (!m_extrapolator.empty() && m_extrapolator.retrieve().isFailure()) - return StatusCode::FAILURE; - - else ATH_MSG_DEBUG("Extrapolator retrieved "<< m_extrapolator); - - // Get CaloSurfaceHelper - if(m_caloSurfaceHelper.retrieve().isFailure()) - ATH_MSG_INFO("CaloSurfaceHelper not found "); - - std::string CaloCoordinateTool_name="TBCaloCoordinate"; - ListItem CaloCoordinateTool(CaloCoordinateTool_name); - if(p_toolSvc->retrieveTool(CaloCoordinateTool.type(),CaloCoordinateTool.name(), algTool, this).isFailure() ) - { - ATH_MSG_ERROR("Cannot retrieve " << CaloCoordinateTool_name); - return StatusCode::FAILURE; - } - m_calo_tb_coord = dynamic_cast<ICaloCoordinateTool*>(algTool); - if(!m_calo_tb_coord ) - { - ATH_MSG_ERROR("Cannot retrieve " << CaloCoordinateTool_name); - return StatusCode::FAILURE; - } - else - ATH_MSG_INFO("retrieved " << CaloCoordinateTool_name); - } //tools - - return StatusCode::SUCCESS; - + ATH_MSG_INFO("geoInit for " << m_geoModel->atlasVersion() ); + + StatusCode sc = detStore()->retrieve(m_tileMgr); + if (sc.isFailure()) + { + ATH_MSG_ERROR( "Unable to retrieve TileDetDescrManager from DetectorStore" ); + m_tileMgr=0; + } + + sc = detStore()->retrieve(m_tileID); + if (sc.isFailure()) + { + ATH_MSG_ERROR( "Unable to retrieve TileID helper from DetectorStore" ); + m_tileID=0; + } + + const DataHandle<CaloIdManager> caloIdManager; + sc=detStore()->retrieve(caloIdManager); + if(sc.isSuccess()) + ATH_MSG_DEBUG("CaloIDManager retrieved."); + else + throw std::runtime_error("ISF_HitAnalysis: Unable to retrieve CaloIDManeger"); + m_larEmID=caloIdManager->getEM_ID(); + if(m_larEmID==0) + throw std::runtime_error("ISF_HitAnalysis: Invalid LAr EM ID helper"); + m_larFcalID=caloIdManager->getFCAL_ID(); + if(m_larFcalID==0) + throw std::runtime_error("ISF_HitAnalysis: Invalid FCAL ID helper"); + m_larHecID=caloIdManager->getHEC_ID(); + if(m_larHecID==0) + throw std::runtime_error("ISF_HitAnalysis: Invalid HEC ID helper"); + m_tileID=caloIdManager->getTileID(); + if(m_tileID==0) + throw std::runtime_error("ISF_HitAnalysis: Invalid Tile ID helper"); + sc=detStore()->regHandle(m_dd_fSampl,"LArfSampl"); + if(sc.isFailure()) + { + ATH_MSG_ERROR("Unable to register handle for LArfSampl"); + return StatusCode::FAILURE; + } + + detStore()->retrieve(m_tileInfo,"TileInfo"); + if(sc.isFailure()) + { + ATH_MSG_ERROR("Unable to retrieve TileInfo from DetectorStore"); + return StatusCode::FAILURE; + } + m_calo_dd_man = CaloDetDescrManager::instance(); + + // Retrieve Tools + IToolSvc* p_toolSvc = 0; + if ( service("ToolSvc",p_toolSvc).isFailure() ) + { + ATH_MSG_ERROR("Cannot find ToolSvc! "); + return StatusCode::FAILURE; + } + else + { + IAlgTool* algTool; + + // Get TimedExtrapolator *************************************************************************************************** + if (!m_extrapolator.empty() && m_extrapolator.retrieve().isFailure()) + return StatusCode::FAILURE; + + else ATH_MSG_DEBUG("Extrapolator retrieved "<< m_extrapolator); + + // Get CaloSurfaceHelper + if(m_caloSurfaceHelper.retrieve().isFailure()) + ATH_MSG_INFO("CaloSurfaceHelper not found "); + + std::string CaloCoordinateTool_name="TBCaloCoordinate"; + ListItem CaloCoordinateTool(CaloCoordinateTool_name); + if(p_toolSvc->retrieveTool(CaloCoordinateTool.type(),CaloCoordinateTool.name(), algTool, this).isFailure() ) + { + ATH_MSG_ERROR("Cannot retrieve " << CaloCoordinateTool_name); + return StatusCode::FAILURE; + } + m_calo_tb_coord = dynamic_cast<ICaloCoordinateTool*>(algTool); + if(!m_calo_tb_coord ) + { + ATH_MSG_ERROR("Cannot retrieve " << CaloCoordinateTool_name); + return StatusCode::FAILURE; + } + else + ATH_MSG_INFO("retrieved " << CaloCoordinateTool_name); + } //tools + + return StatusCode::SUCCESS; + } StatusCode ISF_HitAnalysis::updateMetaData( IOVSVC_CALLBACK_ARGS_P( I, keys ) ) { - ATH_MSG_INFO( "Updating the Sim+Digi MetaData" ); - - // Reset the internal settings: - bool run_update = false; - - // Check what kind of keys we got. In principle the function should only - // receive the "/Digitization/Parameters" and "/Simulation/Parameters" key. - msg( MSG::DEBUG ) << "Update called with " <<I<< " folder " << keys.size() << " keys:"; - std::list< std::string >::const_iterator itr = keys.begin(); - std::list< std::string >::const_iterator end = keys.end(); - for( ; itr != end; ++itr ) - { - if( *itr == m_MC_DIGI_PARAM ) run_update = true; - if( *itr == m_MC_SIM_PARAM ) run_update = true; - msg() << *itr; - } - msg() << endmsg; - // If that's not the key that we received after all, let's just return - // silently... - if( ! run_update ) return StatusCode::SUCCESS; - - const DataHandle< AthenaAttributeList > simParam; - if( detStore()->retrieve( simParam, m_MC_SIM_PARAM ).isFailure() ) - { - ATH_MSG_WARNING("Retrieving MC SIM metadata failed"); - } - else - { - AthenaAttributeList::const_iterator attr_itr = simParam->begin(); - AthenaAttributeList::const_iterator attr_end = simParam->end(); - for( ; attr_itr != attr_end; ++attr_itr ) - { - std::stringstream outstr; - attr_itr->toOutputStream(outstr); - ATH_MSG_INFO("MetaData: " << outstr.str()); - } - } - - return StatusCode::SUCCESS; + ATH_MSG_INFO( "Updating the Sim+Digi MetaData" ); + + // Reset the internal settings: + bool run_update = false; + + // Check what kind of keys we got. In principle the function should only + // receive the "/Digitization/Parameters" and "/Simulation/Parameters" key. + msg( MSG::DEBUG ) << "Update called with " <<I<< " folder " << keys.size() << " keys:"; + std::list< std::string >::const_iterator itr = keys.begin(); + std::list< std::string >::const_iterator end = keys.end(); + for( ; itr != end; ++itr ) + { + if( *itr == m_MC_DIGI_PARAM ) run_update = true; + if( *itr == m_MC_SIM_PARAM ) run_update = true; + msg() << *itr; + } + msg() << endmsg; + // If that's not the key that we received after all, let's just return + // silently... + if( ! run_update ) return StatusCode::SUCCESS; + + const DataHandle< AthenaAttributeList > simParam; + if( detStore()->retrieve( simParam, m_MC_SIM_PARAM ).isFailure() ) + { + ATH_MSG_WARNING("Retrieving MC SIM metadata failed"); + } + else + { + AthenaAttributeList::const_iterator attr_itr = simParam->begin(); + AthenaAttributeList::const_iterator attr_end = simParam->end(); + for( ; attr_itr != attr_end; ++attr_itr ) + { + std::stringstream outstr; + attr_itr->toOutputStream(outstr); + ATH_MSG_INFO("MetaData: " << outstr.str()); + } + } + + return StatusCode::SUCCESS; } StatusCode ISF_HitAnalysis::initialize() { - ATH_MSG_INFO( "Initializing ISF_HitAnalysis" ); - - /* - // get a handle of StoreGate for access to the Detector Store + ATH_MSG_INFO( "Initializing ISF_HitAnalysis" ); + + /* + // get a handle of StoreGate for access to the Detector Store sc = service("DetectorStore", m_detStore); if (sc.isFailure()) { - ATH_MSG_ERROR( "ZH Unable to retrieve pointer to Detector Store"); - return sc; + ATH_MSG_ERROR( "ZH Unable to retrieve pointer to Detector Store"); + return sc; } - // get a handle of StoreGate for access to the Event Store + // get a handle of StoreGate for access to the Event Store sc = service("StoreGateSvc", m_storeGate); if (sc.isFailure()) { - ATH_MSG_ERROR( "Unable to retrieve pointer to StoreGateSvc" ); - return sc; + ATH_MSG_ERROR( "Unable to retrieve pointer to StoreGateSvc" ); + return sc; } - */ - - // - // Register the callback(s): - // - StatusCode sc = service("GeoModelSvc", m_geoModel); + */ + + // + // Register the callback(s): + // + StatusCode sc = service("GeoModelSvc", m_geoModel); + if(sc.isFailure()) + { + ATH_MSG_ERROR( "Could not locate GeoModelSvc" ); + return StatusCode::FAILURE; + } + + // dummy parameters for the callback: + int dummyInt=0; + std::list<std::string> dummyList; + + if (m_geoModel->geoInitialized()) + { + sc=geoInit(dummyInt,dummyList); if(sc.isFailure()) - { - ATH_MSG_ERROR( "Could not locate GeoModelSvc" ); - return StatusCode::FAILURE; - } - - // dummy parameters for the callback: - int dummyInt=0; - std::list<std::string> dummyList; - - if (m_geoModel->geoInitialized()) - { - sc=geoInit(dummyInt,dummyList); - if(sc.isFailure()) - { - ATH_MSG_ERROR( "Call to geoInit failed" ); - return StatusCode::FAILURE; - } - } - else - { - sc = detStore()->regFcn(&IGeoModelSvc::geoInit, m_geoModel, &ISF_HitAnalysis::geoInit,this); - if(sc.isFailure()) - { - ATH_MSG_ERROR( "Could not register geoInit callback" ); - return StatusCode::FAILURE; - } - } - - if( detStore()->contains< AthenaAttributeList >( m_MC_DIGI_PARAM ) ) - { - const DataHandle< AthenaAttributeList > aptr; - if( detStore()->regFcn( &ISF_HitAnalysis::updateMetaData, this, aptr,m_MC_DIGI_PARAM, true ).isFailure() ) - { - ATH_MSG_ERROR( "Could not register callback for "<< m_MC_DIGI_PARAM ); - return StatusCode::FAILURE; - } - } - else - { - ATH_MSG_WARNING( "MetaData not found for "<< m_MC_DIGI_PARAM ); - } - - if(detStore()->contains< AthenaAttributeList >( m_MC_SIM_PARAM ) ) - { - const DataHandle< AthenaAttributeList > aptr; - if( detStore()->regFcn( &ISF_HitAnalysis::updateMetaData, this, aptr,m_MC_SIM_PARAM, true ).isFailure() ) - { - ATH_MSG_ERROR( "Could not register callback for "<< m_MC_SIM_PARAM ); - return StatusCode::FAILURE; - } - } - else - ATH_MSG_WARNING( "MetaData not found for "<< m_MC_SIM_PARAM ); - - // Get CaloGeometryHelper - if (m_CaloGeometryHelper.retrieve().isFailure()) - { - ATH_MSG_ERROR("CaloGeometryHelper not found "); - return StatusCode::FAILURE; - } - - // Get FastCaloSimCaloExtrapolation - if (m_FastCaloSimCaloExtrapolation.retrieve().isFailure()) - { - ATH_MSG_ERROR("FastCaloSimCaloExtrapolation not found "); - return StatusCode::FAILURE; - } - - // Grab the Ntuple and histogramming service for the tree - sc = service("THistSvc",m_thistSvc); - if (sc.isFailure()) - { - ATH_MSG_ERROR( "Unable to retrieve pointer to THistSvc" ); - return StatusCode::FAILURE; - } - + { + ATH_MSG_ERROR( "Call to geoInit failed" ); + return StatusCode::FAILURE; + } + } + else + { + sc = detStore()->regFcn(&IGeoModelSvc::geoInit, m_geoModel, &ISF_HitAnalysis::geoInit,this); + if(sc.isFailure()) + { + ATH_MSG_ERROR( "Could not register geoInit callback" ); + return StatusCode::FAILURE; + } + } + + if( detStore()->contains< AthenaAttributeList >( m_MC_DIGI_PARAM ) ) + { + const DataHandle< AthenaAttributeList > aptr; + if( detStore()->regFcn( &ISF_HitAnalysis::updateMetaData, this, aptr,m_MC_DIGI_PARAM, true ).isFailure() ) + { + ATH_MSG_ERROR( "Could not register callback for "<< m_MC_DIGI_PARAM ); + return StatusCode::FAILURE; + } + } + else + { + ATH_MSG_WARNING( "MetaData not found for "<< m_MC_DIGI_PARAM ); + } + + if(detStore()->contains< AthenaAttributeList >( m_MC_SIM_PARAM ) ) + { + const DataHandle< AthenaAttributeList > aptr; + if( detStore()->regFcn( &ISF_HitAnalysis::updateMetaData, this, aptr,m_MC_SIM_PARAM, true ).isFailure() ) + { + ATH_MSG_ERROR( "Could not register callback for "<< m_MC_SIM_PARAM ); + return StatusCode::FAILURE; + } + } + else + ATH_MSG_WARNING( "MetaData not found for "<< m_MC_SIM_PARAM ); + + // Get CaloGeometryHelper + if (m_CaloGeometryHelper.retrieve().isFailure()) + { + ATH_MSG_ERROR("CaloGeometryHelper not found "); + return StatusCode::FAILURE; + } + + // Get FastCaloSimCaloExtrapolation + if (m_FastCaloSimCaloExtrapolation.retrieve().isFailure()) + { + ATH_MSG_ERROR("FastCaloSimCaloExtrapolation not found "); + return StatusCode::FAILURE; + } + + // Grab the Ntuple and histogramming service for the tree + sc = service("THistSvc",m_thistSvc); + if (sc.isFailure()) + { + ATH_MSG_ERROR( "Unable to retrieve pointer to THistSvc" ); + return StatusCode::FAILURE; + } + + //######################### + IPartPropSvc* p_PartPropSvc=0; + if (service("PartPropSvc",p_PartPropSvc).isFailure() || p_PartPropSvc == 0) + { + ATH_MSG_ERROR("could not find PartPropService"); + return StatusCode::FAILURE; + } + + m_particleDataTable = (HepPDT::ParticleDataTable*) p_PartPropSvc->PDT(); + if(m_particleDataTable == 0) + { + ATH_MSG_ERROR("PDG table not found"); + return StatusCode::FAILURE; + } + //######################### + + // + m_tree = new TTree( TString(m_ntupleTreeName), "CaloHitAna" ); + std::string fullNtupleName = "/"+m_ntupleFileName+"/"+m_ntupleDirName+"/"+m_ntupleTreeName; + sc = m_thistSvc->regTree(fullNtupleName, m_tree); + if (sc.isFailure() || !m_tree ) + { + ATH_MSG_ERROR("Unable to register TTree: " << fullNtupleName); + return StatusCode::FAILURE; + } + + /** now add branches and leaves to the tree */ + if (m_tree) + { + ATH_MSG_INFO("Successfull registered TTree: " << fullNtupleName); + //this actually creates the vector itself! And only if it succeeds! Note that the result is not checked! And the code is probably leaking memory in the end + m_tree->Branch("HitX", &m_hit_x); + m_tree->Branch("HitY", &m_hit_y); + m_tree->Branch("HitZ", &m_hit_z); + m_tree->Branch("HitE", &m_hit_energy); + m_tree->Branch("HitT", &m_hit_time); + m_tree->Branch("HitIdentifier", &m_hit_identifier); + m_tree->Branch("HitCellIdentifier", &m_hit_cellidentifier); + m_tree->Branch("HitIsLArBarrel", &m_islarbarrel); + m_tree->Branch("HitIsLArEndCap", &m_islarendcap); + m_tree->Branch("HitIsHEC", &m_islarhec); + m_tree->Branch("HitIsFCAL", &m_islarfcal); + m_tree->Branch("HitIsTile", &m_istile); + m_tree->Branch("HitSampling", &m_hit_sampling); + m_tree->Branch("HitSamplingFraction", &m_hit_samplingfraction); + + m_tree->Branch("TruthE", &m_truth_energy); + m_tree->Branch("TruthPx", &m_truth_px); + m_tree->Branch("TruthPy", &m_truth_py); + m_tree->Branch("TruthPz", &m_truth_pz); + m_tree->Branch("TruthPDG", &m_truth_pdg); + m_tree->Branch("TruthBarcode", &m_truth_barcode); + m_tree->Branch("TruthVtxBarcode", &m_truth_vtxbarcode); + + m_tree->Branch("CellIdentifier", &m_cell_identifier); + m_tree->Branch("CellE", &m_cell_energy); + m_tree->Branch("CellSampling", &m_cell_sampling); + + m_tree->Branch("G4HitE", &m_g4hit_energy); + m_tree->Branch("G4HitT", &m_g4hit_time); + m_tree->Branch("G4HitIdentifier", &m_g4hit_identifier); + m_tree->Branch("G4HitCellIdentifier", &m_g4hit_cellidentifier); + m_tree->Branch("G4HitSamplingFraction",&m_g4hit_samplingfraction); + m_tree->Branch("G4HitSampling", &m_g4hit_sampling); + //And this looks like will fail since ROOT has no idea what the object is... + //m_tree->Branch("MatchedCells", &m_matched_cells); + //######################### - IPartPropSvc* p_PartPropSvc=0; - if (service("PartPropSvc",p_PartPropSvc).isFailure() || p_PartPropSvc == 0) - { - ATH_MSG_ERROR("could not find PartPropService"); - return StatusCode::FAILURE; - } - - m_particleDataTable = (HepPDT::ParticleDataTable*) p_PartPropSvc->PDT(); - if(m_particleDataTable == 0) - { - ATH_MSG_ERROR("PDG table not found"); - return StatusCode::FAILURE; - } + m_tree->Branch("TTC_back_eta",&m_TTC_back_eta); + m_tree->Branch("TTC_back_phi",&m_TTC_back_phi); + m_tree->Branch("TTC_back_r",&m_TTC_back_r); + m_tree->Branch("TTC_back_z",&m_TTC_back_z); + m_tree->Branch("TTC_entrance_eta",&m_TTC_entrance_eta); + m_tree->Branch("TTC_entrance_phi",&m_TTC_entrance_phi); + m_tree->Branch("TTC_entrance_r",&m_TTC_entrance_r); + m_tree->Branch("TTC_entrance_z",&m_TTC_entrance_z); + m_tree->Branch("TTC_IDCaloBoundary_eta",&m_TTC_IDCaloBoundary_eta); + m_tree->Branch("TTC_IDCaloBoundary_phi",&m_TTC_IDCaloBoundary_phi); + m_tree->Branch("TTC_IDCaloBoundary_r",&m_TTC_IDCaloBoundary_r); + m_tree->Branch("TTC_IDCaloBoundary_z",&m_TTC_IDCaloBoundary_z); + m_tree->Branch("TTC_Angle3D",&m_TTC_Angle3D); + m_tree->Branch("TTC_AngleEta",&m_TTC_AngleEta); + + m_tree->Branch("newTTC_back_eta",&m_newTTC_back_eta); + m_tree->Branch("newTTC_back_phi",&m_newTTC_back_phi); + m_tree->Branch("newTTC_back_r",&m_newTTC_back_r); + m_tree->Branch("newTTC_back_z",&m_newTTC_back_z); + m_tree->Branch("newTTC_entrance_eta",&m_newTTC_entrance_eta); + m_tree->Branch("newTTC_entrance_phi",&m_newTTC_entrance_phi); + m_tree->Branch("newTTC_entrance_r",&m_newTTC_entrance_r); + m_tree->Branch("newTTC_entrance_z",&m_newTTC_entrance_z); + m_tree->Branch("newTTC_IDCaloBoundary_eta",&m_newTTC_IDCaloBoundary_eta); + m_tree->Branch("newTTC_IDCaloBoundary_phi",&m_newTTC_IDCaloBoundary_phi); + m_tree->Branch("newTTC_IDCaloBoundary_r",&m_newTTC_IDCaloBoundary_r); + m_tree->Branch("newTTC_IDCaloBoundary_z",&m_newTTC_IDCaloBoundary_z); + m_tree->Branch("newTTC_Angle3D",&m_newTTC_Angle3D); + m_tree->Branch("newTTC_AngleEta",&m_newTTC_AngleEta); + //######################### + //m_tree->Print(); + if (!m_hit_x || !m_hit_y || !m_hit_z || !m_hit_energy || !m_hit_time || !m_hit_identifier || !m_hit_cellidentifier || !m_islarbarrel || !m_islarendcap || !m_islarfcal || !m_islarhec || !m_istile || !m_hit_sampling || !m_hit_samplingfraction || !m_truth_energy || !m_truth_px || !m_truth_py || !m_truth_pz || !m_truth_pdg || !m_truth_barcode || !m_truth_vtxbarcode) + { + ATH_MSG_ERROR("Unable to create TTree branch correctly"); + return StatusCode::FAILURE; + } + if (!m_cell_identifier || !m_cell_energy || !m_cell_sampling || !m_g4hit_energy || !m_g4hit_time || !m_g4hit_identifier || !m_g4hit_cellidentifier || !m_g4hit_samplingfraction || !m_g4hit_sampling ) + { + ATH_MSG_ERROR("Unable to create TTree branch correctly (cell or g4hit)"); + return StatusCode::FAILURE; + } + if (!m_TTC_back_eta || !m_TTC_back_phi || !m_TTC_back_r || !m_TTC_back_z || !m_TTC_entrance_eta || !m_TTC_entrance_phi || !m_TTC_entrance_r || !m_TTC_entrance_z || !m_TTC_IDCaloBoundary_eta || !m_TTC_IDCaloBoundary_phi || !m_TTC_IDCaloBoundary_r || !m_TTC_IDCaloBoundary_z || !m_TTC_Angle3D || !m_TTC_AngleEta) + { + ATH_MSG_ERROR("Unable to create TTree branch correctly (TTC variables)"); + return StatusCode::FAILURE; + } + if (!m_newTTC_back_eta || !m_newTTC_back_phi || !m_newTTC_back_r || !m_newTTC_back_z || !m_newTTC_entrance_eta || !m_newTTC_entrance_phi || !m_newTTC_entrance_r || !m_newTTC_entrance_z || !m_newTTC_IDCaloBoundary_eta || !m_newTTC_IDCaloBoundary_phi || !m_newTTC_IDCaloBoundary_r || !m_newTTC_IDCaloBoundary_z || !m_newTTC_Angle3D || !m_newTTC_AngleEta) + { + ATH_MSG_ERROR("Unable to create TTree branch correctly (newTTC variables)"); + return StatusCode::FAILURE; + } + } + + return StatusCode::SUCCESS; - // - m_tree = new TTree( TString(m_ntupleTreeName), "CaloHitAna" ); - std::string fullNtupleName = "/"+m_ntupleFileName+"/"+m_ntupleDirName+"/"+m_ntupleTreeName; - sc = m_thistSvc->regTree(fullNtupleName, m_tree); - if (sc.isFailure() || !m_tree ) - { - ATH_MSG_ERROR("Unable to register TTree: " << fullNtupleName); - return StatusCode::FAILURE; - } - - /** now add branches and leaves to the tree */ - if (m_tree) - { - ATH_MSG_INFO("Successfull registered TTree: " << fullNtupleName); - //this actually creates the vector itself! And only if it succeeds! Note that the result is not checked! And the code is probably leaking memory in the end - m_tree->Branch("HitX", &m_hit_x); - m_tree->Branch("HitY", &m_hit_y); - m_tree->Branch("HitZ", &m_hit_z); - m_tree->Branch("HitE", &m_hit_energy); - m_tree->Branch("HitT", &m_hit_time); - m_tree->Branch("HitIdentifier", &m_hit_identifier); - m_tree->Branch("HitCellIdentifier", &m_hit_cellidentifier); - m_tree->Branch("HitIsLArBarrel", &m_islarbarrel); - m_tree->Branch("HitIsLArEndCap", &m_islarendcap); - m_tree->Branch("HitIsHEC", &m_islarhec); - m_tree->Branch("HitIsFCAL", &m_islarfcal); - m_tree->Branch("HitIsTile", &m_istile); - m_tree->Branch("HitSampling", &m_hit_sampling); - m_tree->Branch("HitSamplingFraction", &m_hit_samplingfraction); - - m_tree->Branch("TruthE", &m_truth_energy); - m_tree->Branch("TruthPx", &m_truth_px); - m_tree->Branch("TruthPy", &m_truth_py); - m_tree->Branch("TruthPz", &m_truth_pz); - m_tree->Branch("TruthPDG", &m_truth_pdg); - m_tree->Branch("TruthBarcode", &m_truth_barcode); - m_tree->Branch("TruthVtxBarcode", &m_truth_vtxbarcode); - - m_tree->Branch("CellIdentifier", &m_cell_identifier); - m_tree->Branch("CellE", &m_cell_energy); - m_tree->Branch("CellSampling", &m_cell_sampling); - - m_tree->Branch("G4HitE", &m_g4hit_energy); - m_tree->Branch("G4HitT", &m_g4hit_time); - m_tree->Branch("G4HitIdentifier", &m_g4hit_identifier); - m_tree->Branch("G4HitCellIdentifier", &m_g4hit_cellidentifier); - m_tree->Branch("G4HitSamplingFraction",&m_g4hit_samplingfraction); - m_tree->Branch("G4HitSampling", &m_g4hit_sampling); - //And this looks like will fail since ROOT has no idea what the object is... - //m_tree->Branch("MatchedCells", &m_matched_cells); - - //######################### - m_tree->Branch("TTC_back_eta",&m_TTC_back_eta); - m_tree->Branch("TTC_back_phi",&m_TTC_back_phi); - m_tree->Branch("TTC_back_r",&m_TTC_back_r); - m_tree->Branch("TTC_back_z",&m_TTC_back_z); - m_tree->Branch("TTC_entrance_eta",&m_TTC_entrance_eta); - m_tree->Branch("TTC_entrance_phi",&m_TTC_entrance_phi); - m_tree->Branch("TTC_entrance_r",&m_TTC_entrance_r); - m_tree->Branch("TTC_entrance_z",&m_TTC_entrance_z); - m_tree->Branch("TTC_IDCaloBoundary_eta",&m_TTC_IDCaloBoundary_eta); - m_tree->Branch("TTC_IDCaloBoundary_phi",&m_TTC_IDCaloBoundary_phi); - m_tree->Branch("TTC_IDCaloBoundary_r",&m_TTC_IDCaloBoundary_r); - m_tree->Branch("TTC_IDCaloBoundary_z",&m_TTC_IDCaloBoundary_z); - m_tree->Branch("TTC_Angle3D",&m_TTC_Angle3D); - m_tree->Branch("TTC_AngleEta",&m_TTC_AngleEta); - - m_tree->Branch("newTTC_back_eta",&m_newTTC_back_eta); - m_tree->Branch("newTTC_back_phi",&m_newTTC_back_phi); - m_tree->Branch("newTTC_back_r",&m_newTTC_back_r); - m_tree->Branch("newTTC_back_z",&m_newTTC_back_z); - m_tree->Branch("newTTC_entrance_eta",&m_newTTC_entrance_eta); - m_tree->Branch("newTTC_entrance_phi",&m_newTTC_entrance_phi); - m_tree->Branch("newTTC_entrance_r",&m_newTTC_entrance_r); - m_tree->Branch("newTTC_entrance_z",&m_newTTC_entrance_z); - m_tree->Branch("newTTC_IDCaloBoundary_eta",&m_newTTC_IDCaloBoundary_eta); - m_tree->Branch("newTTC_IDCaloBoundary_phi",&m_newTTC_IDCaloBoundary_phi); - m_tree->Branch("newTTC_IDCaloBoundary_r",&m_newTTC_IDCaloBoundary_r); - m_tree->Branch("newTTC_IDCaloBoundary_z",&m_newTTC_IDCaloBoundary_z); - m_tree->Branch("newTTC_Angle3D",&m_newTTC_Angle3D); - m_tree->Branch("newTTC_AngleEta",&m_newTTC_AngleEta); - - //######################### - //m_tree->Print(); - if (!m_hit_x || !m_hit_y || !m_hit_z || !m_hit_energy || !m_hit_time || !m_hit_identifier || !m_hit_cellidentifier || !m_islarbarrel || !m_islarendcap || !m_islarfcal || !m_islarhec || !m_istile || !m_hit_sampling || !m_hit_samplingfraction || !m_truth_energy || !m_truth_px || !m_truth_py || !m_truth_pz || !m_truth_pdg || !m_truth_barcode || !m_truth_vtxbarcode) - { - ATH_MSG_ERROR("Unable to create TTree branch correctly"); - return StatusCode::FAILURE; - } - if (!m_cell_identifier || !m_cell_energy || !m_cell_sampling || !m_g4hit_energy || !m_g4hit_time || !m_g4hit_identifier || !m_g4hit_cellidentifier || !m_g4hit_samplingfraction || !m_g4hit_sampling ) - { - ATH_MSG_ERROR("Unable to create TTree branch correctly (cell or g4hit)"); - return StatusCode::FAILURE; - } - if (!m_TTC_back_eta || !m_TTC_back_phi || !m_TTC_back_r || !m_TTC_back_z || !m_TTC_entrance_eta || !m_TTC_entrance_phi || !m_TTC_entrance_r || !m_TTC_entrance_z || !m_TTC_IDCaloBoundary_eta || !m_TTC_IDCaloBoundary_phi || !m_TTC_IDCaloBoundary_r || !m_TTC_IDCaloBoundary_z || !m_TTC_Angle3D || !m_TTC_AngleEta) - { - ATH_MSG_ERROR("Unable to create TTree branch correctly (TTC variables)"); - return StatusCode::FAILURE; - } - if (!m_newTTC_back_eta || !m_newTTC_back_phi || !m_newTTC_back_r || !m_newTTC_back_z || !m_newTTC_entrance_eta || !m_newTTC_entrance_phi || !m_newTTC_entrance_r || !m_newTTC_entrance_z || !m_newTTC_IDCaloBoundary_eta || !m_newTTC_IDCaloBoundary_phi || !m_newTTC_IDCaloBoundary_r || !m_newTTC_IDCaloBoundary_z || !m_newTTC_Angle3D || !m_newTTC_AngleEta) - { - ATH_MSG_ERROR("Unable to create TTree branch correctly (newTTC variables)"); - return StatusCode::FAILURE; - } - } - - return StatusCode::SUCCESS; - -} //initialize +} //initialize StatusCode ISF_HitAnalysis::finalize() { - - ATH_MSG_INFO( "doing finalize()" ); - - TTree* geo = new TTree( m_geoModel->atlasVersion().c_str() , m_geoModel->atlasVersion().c_str() ); - std::string fullNtupleName = "/"+m_geoFileName+"/"+m_geoModel->atlasVersion(); - StatusCode sc = m_thistSvc->regTree(fullNtupleName, geo); - if(sc.isFailure() || !geo ) - { - ATH_MSG_ERROR("Unable to register TTree: " << fullNtupleName); - return StatusCode::FAILURE; - } - - /** now add branches and leaves to the tree */ - - typedef struct + + ATH_MSG_INFO( "doing finalize()" ); + + TTree* geo = new TTree( m_geoModel->atlasVersion().c_str() , m_geoModel->atlasVersion().c_str() ); + std::string fullNtupleName = "/"+m_geoFileName+"/"+m_geoModel->atlasVersion(); + StatusCode sc = m_thistSvc->regTree(fullNtupleName, geo); + if(sc.isFailure() || !geo ) + { + ATH_MSG_ERROR("Unable to register TTree: " << fullNtupleName); + return StatusCode::FAILURE; + } + + /** now add branches and leaves to the tree */ + + typedef struct + { + Long64_t identifier; + Int_t calosample; + float eta,phi,r,eta_raw,phi_raw,r_raw,x,y,z,x_raw,y_raw,z_raw; + float deta,dphi,dr,dx,dy,dz; + } GEOCELL; + + static GEOCELL geocell; + + if(geo) + { + ATH_MSG_INFO("Successfull registered TTree: " << fullNtupleName); + //this actually creates the vector itself! And only if it succeeds! Note that the result is not checked! And the code is probably leaking memory in the end + //geo->Branch("cells", &geocell,"identifier/L:eta,phi,r,eta_raw,phi_raw,r_raw,x,y,z,x_raw,y_raw,z_raw/F:Deta,Dphi,Dr,Dx,Dy,Dz/F"); + geo->Branch("identifier", &geocell.identifier,"identifier/L"); + geo->Branch("calosample", &geocell.calosample,"calosample/I"); + + geo->Branch("eta", &geocell.eta,"eta/F"); + geo->Branch("phi", &geocell.phi,"phi/F"); + geo->Branch("r", &geocell.r,"r/F"); + geo->Branch("eta_raw", &geocell.eta_raw,"eta_raw/F"); + geo->Branch("phi_raw", &geocell.phi_raw,"phi_raw/F"); + geo->Branch("r_raw", &geocell.r_raw,"r_raw/F"); + + geo->Branch("x", &geocell.x,"x/F"); + geo->Branch("y", &geocell.y,"y/F"); + geo->Branch("z", &geocell.z,"z/F"); + geo->Branch("x_raw", &geocell.x_raw,"x_raw/F"); + geo->Branch("y_raw", &geocell.y_raw,"y_raw/F"); + geo->Branch("z_raw", &geocell.z_raw,"z_raw/F"); + + geo->Branch("deta", &geocell.deta,"deta/F"); + geo->Branch("dphi", &geocell.dphi,"dphi/F"); + geo->Branch("dr", &geocell.dr,"dr/F"); + geo->Branch("dx", &geocell.dx,"dx/F"); + geo->Branch("dy", &geocell.dy,"dy/F"); + geo->Branch("dz", &geocell.dz,"dz/F"); + } + + if(m_calo_dd_man) + { + int ncells=0; + for(CaloDetDescrManager::calo_element_const_iterator calo_iter=m_calo_dd_man->element_begin();calo_iter<m_calo_dd_man->element_end();++calo_iter) { - Long64_t identifier; - Int_t calosample; - float eta,phi,r,eta_raw,phi_raw,r_raw,x,y,z,x_raw,y_raw,z_raw; - float deta,dphi,dr,dx,dy,dz; - } GEOCELL; - - static GEOCELL geocell; - - if(geo) + const CaloDetDescrElement* theDDE=*calo_iter; + if(theDDE) + { + CaloCell_ID::CaloSample sample=theDDE->getSampling(); + //CaloCell_ID::SUBCALO calo=theDDE->getSubCalo(); + ++ncells; + if(geo) { - ATH_MSG_INFO("Successfull registered TTree: " << fullNtupleName); - //this actually creates the vector itself! And only if it succeeds! Note that the result is not checked! And the code is probably leaking memory in the end - //geo->Branch("cells", &geocell,"identifier/L:eta,phi,r,eta_raw,phi_raw,r_raw,x,y,z,x_raw,y_raw,z_raw/F:Deta,Dphi,Dr,Dx,Dy,Dz/F"); - geo->Branch("identifier", &geocell.identifier,"identifier/L"); - geo->Branch("calosample", &geocell.calosample,"calosample/I"); - - geo->Branch("eta", &geocell.eta,"eta/F"); - geo->Branch("phi", &geocell.phi,"phi/F"); - geo->Branch("r", &geocell.r,"r/F"); - geo->Branch("eta_raw", &geocell.eta_raw,"eta_raw/F"); - geo->Branch("phi_raw", &geocell.phi_raw,"phi_raw/F"); - geo->Branch("r_raw", &geocell.r_raw,"r_raw/F"); - - geo->Branch("x", &geocell.x,"x/F"); - geo->Branch("y", &geocell.y,"y/F"); - geo->Branch("z", &geocell.z,"z/F"); - geo->Branch("x_raw", &geocell.x_raw,"x_raw/F"); - geo->Branch("y_raw", &geocell.y_raw,"y_raw/F"); - geo->Branch("z_raw", &geocell.z_raw,"z_raw/F"); - - geo->Branch("deta", &geocell.deta,"deta/F"); - geo->Branch("dphi", &geocell.dphi,"dphi/F"); - geo->Branch("dr", &geocell.dr,"dr/F"); - geo->Branch("dx", &geocell.dx,"dx/F"); - geo->Branch("dy", &geocell.dy,"dy/F"); - geo->Branch("dz", &geocell.dz,"dz/F"); + geocell.identifier=theDDE->identify().get_compact(); + geocell.calosample=sample; + geocell.eta=theDDE->eta(); + geocell.phi=theDDE->phi(); + geocell.r=theDDE->r(); + geocell.eta_raw=theDDE->eta_raw(); + geocell.phi_raw=theDDE->phi_raw(); + geocell.r_raw=theDDE->r_raw(); + geocell.x=theDDE->x(); + geocell.y=theDDE->y(); + geocell.z=theDDE->z(); + geocell.x_raw=theDDE->x_raw(); + geocell.y_raw=theDDE->y_raw(); + geocell.z_raw=theDDE->z_raw(); + geocell.deta=theDDE->deta(); + geocell.dphi=theDDE->dphi(); + geocell.dr=theDDE->dr(); + geocell.dx=theDDE->dx(); + geocell.dy=theDDE->dy(); + geocell.dz=theDDE->dz(); + + geo->Fill(); } - - if(m_calo_dd_man) - { - int ncells=0; - for(CaloDetDescrManager::calo_element_const_iterator calo_iter=m_calo_dd_man->element_begin();calo_iter<m_calo_dd_man->element_end();++calo_iter) - { - const CaloDetDescrElement* theDDE=*calo_iter; - if(theDDE) - { - CaloCell_ID::CaloSample sample=theDDE->getSampling(); - //CaloCell_ID::SUBCALO calo=theDDE->getSubCalo(); - ++ncells; - if(geo) - { - geocell.identifier=theDDE->identify().get_compact(); - geocell.calosample=sample; - geocell.eta=theDDE->eta(); - geocell.phi=theDDE->phi(); - geocell.r=theDDE->r(); - geocell.eta_raw=theDDE->eta_raw(); - geocell.phi_raw=theDDE->phi_raw(); - geocell.r_raw=theDDE->r_raw(); - geocell.x=theDDE->x(); - geocell.y=theDDE->y(); - geocell.z=theDDE->z(); - geocell.x_raw=theDDE->x_raw(); - geocell.y_raw=theDDE->y_raw(); - geocell.z_raw=theDDE->z_raw(); - geocell.deta=theDDE->deta(); - geocell.dphi=theDDE->dphi(); - geocell.dr=theDDE->dr(); - geocell.dx=theDDE->dx(); - geocell.dy=theDDE->dy(); - geocell.dz=theDDE->dz(); - - geo->Fill(); - } - } - } - - ATH_MSG_INFO( ncells<<" cells found" ); - } - - return StatusCode::SUCCESS; + } + } + + ATH_MSG_INFO( ncells<<" cells found" ); + } + + return StatusCode::SUCCESS; } //finalize StatusCode ISF_HitAnalysis::execute() { - - ATH_MSG_DEBUG( "In ISF_HitAnalysis::execute()" ); - - if (! m_tree) - { - ATH_MSG_ERROR( "tree not registered" ); - return StatusCode::FAILURE; - } - - //now if the branches were created correctly, the pointers point to something and it is possible to clear the vectors - TVector3 vectest; - vectest.SetPtEtaPhi(1.,1.,1.); - m_hit_x->clear(); - m_hit_y->clear(); - m_hit_z->clear(); - m_hit_energy->clear(); - m_hit_time->clear(); - m_hit_identifier->clear(); - m_hit_cellidentifier->clear(); - m_islarbarrel->clear(); - m_islarendcap->clear(); - m_islarhec->clear(); - m_islarfcal->clear(); - m_istile->clear(); - m_hit_sampling->clear(); - m_hit_samplingfraction->clear(); - m_truth_energy->clear(); - m_truth_px->clear(); - m_truth_py->clear(); - m_truth_pz->clear(); - m_truth_pdg->clear(); - m_truth_barcode->clear(); - m_truth_vtxbarcode->clear(); - m_cell_identifier->clear(); - m_cell_energy->clear(); - m_cell_sampling->clear(); - m_g4hit_energy->clear(); - m_g4hit_time->clear(); - m_g4hit_identifier->clear(); - m_g4hit_cellidentifier->clear(); - m_g4hit_sampling->clear(); - m_g4hit_samplingfraction->clear(); - //which fails for this one!! - //m_matched_cells->clear(); - - //########################## - m_TTC_back_eta->clear(); - m_TTC_back_phi->clear(); - m_TTC_back_r->clear(); - m_TTC_back_z->clear(); - m_TTC_entrance_eta->clear(); - m_TTC_entrance_phi->clear(); - m_TTC_entrance_r->clear(); - m_TTC_entrance_z->clear(); - m_TTC_IDCaloBoundary_eta->clear(); - m_TTC_IDCaloBoundary_phi->clear(); - m_TTC_IDCaloBoundary_r->clear(); - m_TTC_IDCaloBoundary_z->clear(); - m_TTC_Angle3D->clear(); - m_TTC_AngleEta->clear(); - - m_newTTC_back_eta->clear(); - m_newTTC_back_phi->clear(); - m_newTTC_back_r->clear(); - m_newTTC_back_z->clear(); - m_newTTC_entrance_eta->clear(); - m_newTTC_entrance_phi->clear(); - m_newTTC_entrance_r->clear(); - m_newTTC_entrance_z->clear(); - m_newTTC_IDCaloBoundary_eta->clear(); - m_newTTC_IDCaloBoundary_phi->clear(); - m_newTTC_IDCaloBoundary_r->clear(); - m_newTTC_IDCaloBoundary_z->clear(); - m_newTTC_Angle3D->clear(); - m_newTTC_AngleEta->clear(); - //########################## - - //Get the FastCaloSim step info collection from store - const ISF_FCS_Parametrization::FCS_StepInfoCollection* eventStepsES; - StatusCode sc = evtStore()->retrieve(eventStepsES, "ZHMergedEventSteps"); - if (sc.isFailure()) - { - ATH_MSG_WARNING( "No FastCaloSim steps read from StoreGate?" ); - //return StatusCode::FAILURE; - } - else - { - ATH_MSG_INFO("Read: "<<eventStepsES->size()<<" position hits"); - for (ISF_FCS_Parametrization::FCS_StepInfoCollection::const_iterator it = eventStepsES->begin(); it != eventStepsES->end(); ++it) - { - m_hit_x->push_back( (*it)->x() ); - m_hit_y->push_back( (*it)->y() ); - m_hit_z->push_back( (*it)->z() ); - m_hit_energy->push_back( (*it)->energy() ); - m_hit_time->push_back( (*it)->time()); - - //Try to get the samplings, sampling fractions from identifiers - bool larbarrel=false; - bool larendcap=false; - bool larhec=false; - bool larfcal=false; - bool tile=false; - int sampling=-1; - double sampfrac=0.0; - - Identifier id = (*it)->identify(); - Identifier cell_id = (*it)->identify(); //to be replaced by cell_id in tile - - if(m_calo_dd_man->get_element(id)) - { - CaloCell_ID::CaloSample layer = m_calo_dd_man->get_element(id)->getSampling(); - sampling = layer; //use CaloCell layer immediately - } - else - ATH_MSG_WARNING( "Warning no sampling info for "<<id.getString()); - - if(m_larEmID->is_lar_em(id) || m_larHecID->is_lar_hec(id) || m_larFcalID->is_lar_fcal(id)) - sampfrac=m_dd_fSampl->FSAMPL(id); - - if(m_larEmID->is_lar_em(id)) - { - //std::cout <<"This hit is in LAr EM "; - if (m_larEmID->is_em_barrel(id)) - larbarrel=true; - else if(m_larEmID->is_em_endcap(id)) - larendcap=true; - } - else if(m_larHecID->is_lar_hec(id)) - larhec = true; - else if(m_larFcalID->is_lar_fcal(id)) - larfcal = true; - else if(m_tileID->is_tile_barrel(id) || m_tileID->is_tile_extbarrel(id) || m_tileID->is_tile_gap(id) || m_tileID->is_tile_gapscin(id) || m_tileID->is_tile_aux(id)) - { - cell_id = m_tileID->cell_id(id); - Int_t tile_sampling = -1; - if(m_calo_dd_man->get_element(cell_id)) - { - tile_sampling = m_calo_dd_man->get_element(cell_id)->getSampling(); - sampfrac = m_tileInfo->HitCalib(cell_id); - } - tile = true; - if(tile_sampling!= -1) - sampling = tile_sampling; //m_calo_dd_man needs to be called with cell_id not pmt_id!! - } - else - ATH_MSG_WARNING( "This hit is somewhere. Please check!"); - - m_hit_identifier->push_back(id.get_compact()); - m_hit_cellidentifier->push_back(cell_id.get_compact()); - //push things into vectors: - m_islarbarrel->push_back(larbarrel); - m_islarendcap->push_back(larendcap); - m_islarhec->push_back(larhec); - m_islarfcal->push_back(larfcal); - m_istile->push_back(tile); - m_hit_sampling->push_back(sampling); - m_hit_samplingfraction->push_back(sampfrac); - - } //event steps - }//event steps read correctly - - //Get truth particle info - //Note that there can be more truth particles, the first one is usually the one we need. - const DataHandle<McEventCollection> mcEvent; - sc = evtStore()->retrieve(mcEvent,"TruthEvent"); - if(sc.isFailure()) - ATH_MSG_WARNING( "No truth event!"); - else - { - if(mcEvent) - { - //std::cout<<"ISF_HitAnalysis: MC event size: "<<mcEvent->size()<<std::endl; - if (mcEvent->size()) - { - int particleIndex=0; - int loopEnd = m_NtruthParticles; - if(loopEnd==-1) - { - loopEnd = (*mcEvent->begin())->particles_size(); //is this the correct thing? - } - //std::cout <<"ISF_HitAnalysis: MC first truth event size: "<<(*mcEvent->begin())->particles_size()<<std::endl; - for (HepMC::GenEvent::particle_const_iterator it = (*mcEvent->begin())->particles_begin(); it != (*mcEvent->begin())->particles_end(); ++it) - { - ATH_MSG_DEBUG("Number truth particles="<<(*mcEvent->begin())->particles_size()<<" loopEnd="<<loopEnd); - particleIndex++; - - if (particleIndex>loopEnd) break; //enough particles - - //UPDATE EXTRAPOLATION WITH ALGTOOL ********************************************************************************************* - TFCSTruthState truth((*it)->momentum().px(),(*it)->momentum().py(),(*it)->momentum().pz(),(*it)->momentum().e(),(*it)->pdg_id()); - TFCSExtrapolationState result; - m_FastCaloSimCaloExtrapolation->extrapolate(result,&truth); - - //write the result into the ntuple variables: - - std::cout<<"IDCaloBoundary_eta() "<<result.IDCaloBoundary_eta()<<std::endl; - std::cout<<"IDCaloBoundary_phi() "<<result.IDCaloBoundary_phi()<<std::endl; - std::cout<<"IDCaloBoundary_r() "<<result.IDCaloBoundary_r()<<std::endl; - std::cout<<"IDCaloBoundary_z() "<<result.IDCaloBoundary_z()<<std::endl; - std::cout<<"AngleEta "<<result.IDCaloBoundary_AngleEta()<<std::endl; - std::cout<<"Angle3D "<<result.IDCaloBoundary_Angle3D()<<std::endl; - - m_newTTC_IDCaloBoundary_eta->push_back(result.IDCaloBoundary_eta()); - m_newTTC_IDCaloBoundary_phi->push_back(result.IDCaloBoundary_phi()); - m_newTTC_IDCaloBoundary_r->push_back(result.IDCaloBoundary_r()); - m_newTTC_IDCaloBoundary_z->push_back(result.IDCaloBoundary_z()); - m_newTTC_Angle3D ->push_back(result.IDCaloBoundary_Angle3D()); - m_newTTC_AngleEta->push_back(result.IDCaloBoundary_AngleEta()); - - std::vector<double> eta_vec_ENT; - std::vector<double> phi_vec_ENT; - std::vector<double> r_vec_ENT; - std::vector<double> z_vec_ENT; - - std::vector<double> eta_vec_EXT; - std::vector<double> phi_vec_EXT; - std::vector<double> r_vec_EXT; - std::vector<double> z_vec_EXT; - - for(int sample=CaloCell_ID_FCS::FirstSample;sample<CaloCell_ID_FCS::MaxSample;++sample) - { - std::cout<<"sample "<<sample<<std::endl; - std::cout<<" eta ENT "<<result.eta(sample,1)<<" eta EXT "<<result.eta(sample,2)<<std::endl; - std::cout<<" phi ENT "<<result.phi(sample,1)<<" phi EXT "<<result.phi(sample,2)<<std::endl; - std::cout<<" r ENT "<<result.r(sample,1) <<" r EXT "<<result.r(sample,2) <<std::endl; - std::cout<<" z ENT "<<result.z(sample,1) <<" z EXT "<<result.z(sample,2) <<std::endl; - eta_vec_ENT.push_back(result.eta(sample,1)); - eta_vec_EXT.push_back(result.eta(sample,2)); - phi_vec_ENT.push_back(result.phi(sample,1)); - phi_vec_EXT.push_back(result.phi(sample,2)); - r_vec_ENT.push_back(result.r(sample,1)); - r_vec_EXT.push_back(result.r(sample,2)); - z_vec_ENT.push_back(result.z(sample,1)); - z_vec_EXT.push_back(result.z(sample,2)); - } - - m_newTTC_back_eta->push_back(eta_vec_EXT); - m_newTTC_back_phi->push_back(phi_vec_EXT); - m_newTTC_back_r ->push_back(r_vec_EXT); - m_newTTC_back_z ->push_back(z_vec_EXT); - m_newTTC_entrance_eta->push_back(eta_vec_ENT); - m_newTTC_entrance_phi->push_back(phi_vec_ENT); - m_newTTC_entrance_r ->push_back(r_vec_ENT); - m_newTTC_entrance_z ->push_back(z_vec_ENT); - - //******************************************************************************************************************************* - - //UPDATE EXTRAPOLATION (old extrapolation) - std::vector<Trk::HitInfo>* hitVector = caloHits(*(*it)); - - Amg::Vector3D mom((*it)->momentum().x(),(*it)->momentum().y(),(*it)->momentum().z()); - - m_truth_energy->push_back((*it)->momentum().e()); - m_truth_px->push_back((*it)->momentum().px()); - m_truth_py->push_back((*it)->momentum().py()); - m_truth_pz->push_back((*it)->momentum().pz()); - m_truth_pdg->push_back((*it)->pdg_id()); - m_truth_barcode->push_back((*it)->barcode()); - - //extrapolate only if the vertex is within the IDcaloboundary - margin - //bool inside_ID=false; - HepMC::GenVertex* pvtx = (*it)->production_vertex(); - if(pvtx) - { - truth.set_vertex(pvtx->position().x(),pvtx->position().y(),pvtx->position().z(),pvtx->position().t()); - - m_truth_vtxbarcode->push_back(pvtx->barcode()); - double radius2=(pvtx->position().x()*pvtx->position().x())+(pvtx->position().y()*pvtx->position().y()); - ATH_MSG_VERBOSE("particle "<<particleIndex<<" Mom: "<<(*it)->momentum().e()<<"|"<<(*it)->momentum().px()<<"|"<<(*it)->momentum().py()<<"|"<<(*it)->momentum().pz()<<" vertex_x "<<pvtx->position().x()<<" y "<<pvtx->position().y()<<" z "<<pvtx->position().z()<<" r2 "<<radius2<<" VertexBarcode: "<<pvtx->barcode()<<" ParticleBarcode:"<<(*it)->barcode()<<" status: "<<(*it)->status()); - //std::cout<<"m_CaloBoundaryZ+m_calomargin "<<m_CaloBoundaryZ+m_calomargin<<" m_CaloBoundaryR+m_calomargin "<<m_CaloBoundaryR+m_calomargin<<std::endl; - - if(fabs(pvtx->position().z())<(m_CaloBoundaryZ+m_calomargin) && radius2<((m_CaloBoundaryR+m_calomargin)*(m_CaloBoundaryR+m_calomargin))) - { - //inside_ID=true; - //if(inside_ID) - // { - ATH_MSG_DEBUG("*** Do extrapolation ***"); - extrapolate(*it,hitVector); - ATH_MSG_DEBUG("*** Do extrapolation to ID ***"); - extrapolate_to_ID(*it,hitVector); - ATH_MSG_DEBUG("Truth extrapolation done for "<<particleIndex<<" "<<(*it)->barcode()); - } //in this case no extrapolation possible - else - { - //fill extrapolated angles with some weird values - m_TTC_IDCaloBoundary_eta->push_back(-999.); - m_TTC_IDCaloBoundary_phi->push_back(-999.); - m_TTC_IDCaloBoundary_r->push_back(-999.); - m_TTC_IDCaloBoundary_z->push_back(-999.); - m_TTC_Angle3D->push_back(-999.); - m_TTC_AngleEta->push_back(-999.); - - } - } //if pvtx - else //no pvtx - { - ATH_MSG_WARNING( "No vertex found for truth particle, no extrapolation"); - m_truth_vtxbarcode->push_back(-999999); - - //fill extrapolated angles with some weird values - std::vector<double> eta_safe; - std::vector<double> phi_safe; - std::vector<double> r_safe; - std::vector<double> z_safe; - for(int sample=CaloCell_ID_FCS::FirstSample;sample<CaloCell_ID_FCS::MaxSample;++sample) - { - eta_safe.push_back(-999.0); - phi_safe.push_back(-999.0); - r_safe.push_back(-999.0); - z_safe.push_back(-999.0); - } - - m_TTC_back_eta->push_back(eta_safe); - m_TTC_back_phi->push_back(phi_safe); - m_TTC_back_r->push_back(r_safe); - m_TTC_back_z->push_back(z_safe); - m_TTC_entrance_eta->push_back(eta_safe); - m_TTC_entrance_phi->push_back(phi_safe); - m_TTC_entrance_r->push_back(r_safe); - m_TTC_entrance_z->push_back(z_safe); - m_TTC_IDCaloBoundary_eta->push_back(-999.); - m_TTC_IDCaloBoundary_phi->push_back(-999.); - m_TTC_IDCaloBoundary_r->push_back(-999.); - m_TTC_IDCaloBoundary_z->push_back(-999.); - m_TTC_Angle3D->push_back(-999.); - m_TTC_AngleEta->push_back(-999.); - - } //no pvtx - for(std::vector<Trk::HitInfo>::iterator it = hitVector->begin();it < hitVector->end();++it) - { - if((*it).trackParms) - { - delete (*it).trackParms; - (*it).trackParms=0; - } - } - delete hitVector; - } - } - } - }//truth event - - //Get reco cells if available - const CaloCellContainer *cellColl = 0; - sc = evtStore()->retrieve(cellColl, "AllCalo"); - - if (sc.isFailure()) - { - ATH_MSG_WARNING( "Couldn't read AllCalo cells from StoreGate"); - //return NULL; + + ATH_MSG_DEBUG( "In ISF_HitAnalysis::execute()" ); + + if (! m_tree) + { + ATH_MSG_ERROR( "tree not registered" ); + return StatusCode::FAILURE; + } + + //now if the branches were created correctly, the pointers point to something and it is possible to clear the vectors + TVector3 vectest; + vectest.SetPtEtaPhi(1.,1.,1.); + m_hit_x->clear(); + m_hit_y->clear(); + m_hit_z->clear(); + m_hit_energy->clear(); + m_hit_time->clear(); + m_hit_identifier->clear(); + m_hit_cellidentifier->clear(); + m_islarbarrel->clear(); + m_islarendcap->clear(); + m_islarhec->clear(); + m_islarfcal->clear(); + m_istile->clear(); + m_hit_sampling->clear(); + m_hit_samplingfraction->clear(); + m_truth_energy->clear(); + m_truth_px->clear(); + m_truth_py->clear(); + m_truth_pz->clear(); + m_truth_pdg->clear(); + m_truth_barcode->clear(); + m_truth_vtxbarcode->clear(); + m_cell_identifier->clear(); + m_cell_energy->clear(); + m_cell_sampling->clear(); + m_g4hit_energy->clear(); + m_g4hit_time->clear(); + m_g4hit_identifier->clear(); + m_g4hit_cellidentifier->clear(); + m_g4hit_sampling->clear(); + m_g4hit_samplingfraction->clear(); + //which fails for this one!! + //m_matched_cells->clear(); + + //########################## + m_TTC_back_eta->clear(); + m_TTC_back_phi->clear(); + m_TTC_back_r->clear(); + m_TTC_back_z->clear(); + m_TTC_entrance_eta->clear(); + m_TTC_entrance_phi->clear(); + m_TTC_entrance_r->clear(); + m_TTC_entrance_z->clear(); + m_TTC_IDCaloBoundary_eta->clear(); + m_TTC_IDCaloBoundary_phi->clear(); + m_TTC_IDCaloBoundary_r->clear(); + m_TTC_IDCaloBoundary_z->clear(); + m_TTC_Angle3D->clear(); + m_TTC_AngleEta->clear(); + + m_newTTC_back_eta->clear(); + m_newTTC_back_phi->clear(); + m_newTTC_back_r->clear(); + m_newTTC_back_z->clear(); + m_newTTC_entrance_eta->clear(); + m_newTTC_entrance_phi->clear(); + m_newTTC_entrance_r->clear(); + m_newTTC_entrance_z->clear(); + m_newTTC_IDCaloBoundary_eta->clear(); + m_newTTC_IDCaloBoundary_phi->clear(); + m_newTTC_IDCaloBoundary_r->clear(); + m_newTTC_IDCaloBoundary_z->clear(); + m_newTTC_Angle3D->clear(); + m_newTTC_AngleEta->clear(); + //########################## + + //Get the FastCaloSim step info collection from store + const ISF_FCS_Parametrization::FCS_StepInfoCollection* eventStepsES; + StatusCode sc = evtStore()->retrieve(eventStepsES, "ZHMergedEventSteps"); + if (sc.isFailure()) + { + ATH_MSG_WARNING( "No FastCaloSim steps read from StoreGate?" ); + //return StatusCode::FAILURE; + } + else + { + ATH_MSG_INFO("Read: "<<eventStepsES->size()<<" position hits"); + for (ISF_FCS_Parametrization::FCS_StepInfoCollection::const_iterator it = eventStepsES->begin(); it != eventStepsES->end(); ++it) + { + m_hit_x->push_back( (*it)->x() ); + m_hit_y->push_back( (*it)->y() ); + m_hit_z->push_back( (*it)->z() ); + m_hit_energy->push_back( (*it)->energy() ); + m_hit_time->push_back( (*it)->time()); + + //Try to get the samplings, sampling fractions from identifiers + bool larbarrel=false; + bool larendcap=false; + bool larhec=false; + bool larfcal=false; + bool tile=false; + int sampling=-1; + double sampfrac=0.0; + + Identifier id = (*it)->identify(); + Identifier cell_id = (*it)->identify(); //to be replaced by cell_id in tile + + if(m_calo_dd_man->get_element(id)) + { + CaloCell_ID::CaloSample layer = m_calo_dd_man->get_element(id)->getSampling(); + sampling = layer; //use CaloCell layer immediately + } + else + ATH_MSG_WARNING( "Warning no sampling info for "<<id.getString()); + + if(m_larEmID->is_lar_em(id) || m_larHecID->is_lar_hec(id) || m_larFcalID->is_lar_fcal(id)) + sampfrac=m_dd_fSampl->FSAMPL(id); + + if(m_larEmID->is_lar_em(id)) + { + //std::cout <<"This hit is in LAr EM "; + if (m_larEmID->is_em_barrel(id)) + larbarrel=true; + else if(m_larEmID->is_em_endcap(id)) + larendcap=true; + } + else if(m_larHecID->is_lar_hec(id)) + larhec = true; + else if(m_larFcalID->is_lar_fcal(id)) + larfcal = true; + else if(m_tileID->is_tile_barrel(id) || m_tileID->is_tile_extbarrel(id) || m_tileID->is_tile_gap(id) || m_tileID->is_tile_gapscin(id) || m_tileID->is_tile_aux(id)) + { + cell_id = m_tileID->cell_id(id); + Int_t tile_sampling = -1; + if(m_calo_dd_man->get_element(cell_id)) + { + tile_sampling = m_calo_dd_man->get_element(cell_id)->getSampling(); + sampfrac = m_tileInfo->HitCalib(cell_id); + } + tile = true; + if(tile_sampling!= -1) + sampling = tile_sampling; //m_calo_dd_man needs to be called with cell_id not pmt_id!! + } + else + ATH_MSG_WARNING( "This hit is somewhere. Please check!"); + + m_hit_identifier->push_back(id.get_compact()); + m_hit_cellidentifier->push_back(cell_id.get_compact()); + //push things into vectors: + m_islarbarrel->push_back(larbarrel); + m_islarendcap->push_back(larendcap); + m_islarhec->push_back(larhec); + m_islarfcal->push_back(larfcal); + m_istile->push_back(tile); + m_hit_sampling->push_back(sampling); + m_hit_samplingfraction->push_back(sampfrac); + + } //event steps + }//event steps read correctly + + //Get truth particle info + //Note that there can be more truth particles, the first one is usually the one we need. + const DataHandle<McEventCollection> mcEvent; + sc = evtStore()->retrieve(mcEvent,"TruthEvent"); + if(sc.isFailure()) + ATH_MSG_WARNING( "No truth event!"); + else + { + if(mcEvent) + { + //std::cout<<"ISF_HitAnalysis: MC event size: "<<mcEvent->size()<<std::endl; + if (mcEvent->size()) + { + int particleIndex=0; + int loopEnd = m_NtruthParticles; + if(loopEnd==-1) + { + loopEnd = (*mcEvent->begin())->particles_size(); //is this the correct thing? + } + //std::cout <<"ISF_HitAnalysis: MC first truth event size: "<<(*mcEvent->begin())->particles_size()<<std::endl; + for (HepMC::GenEvent::particle_const_iterator it = (*mcEvent->begin())->particles_begin(); it != (*mcEvent->begin())->particles_end(); ++it) + { + ATH_MSG_DEBUG("Number truth particles="<<(*mcEvent->begin())->particles_size()<<" loopEnd="<<loopEnd); + particleIndex++; + + if (particleIndex>loopEnd) break; //enough particles + + //UPDATE EXTRAPOLATION WITH ALGTOOL ********************************************************************************************* + + TFCSTruthState truth((*it)->momentum().px(),(*it)->momentum().py(),(*it)->momentum().pz(),(*it)->momentum().e(),(*it)->pdg_id()); + + //calculate the vertex + TVector3 moment; + moment.SetXYZ((*it)->momentum().px(),(*it)->momentum().py(),(*it)->momentum().pz()); + TVector3 direction=moment.Unit(); + + //does it hit the barrel or the EC? + if(abs(direction.Z())/3550.<direction.Perp()/1148.) //BARREL + direction*=1148./direction.Perp(); + else //EC + direction*=3550./abs(direction.Z()); + + truth.set_vertex(direction.X(),direction.Y(),direction.Z()); //is this really needed? + TFCSExtrapolationState result; + m_FastCaloSimCaloExtrapolation->extrapolate(result,&truth); + + //write the result into the ntuple variables: + + std::cout<<"IDCaloBoundary_eta() "<<result.IDCaloBoundary_eta()<<std::endl; + std::cout<<"IDCaloBoundary_phi() "<<result.IDCaloBoundary_phi()<<std::endl; + std::cout<<"IDCaloBoundary_r() "<<result.IDCaloBoundary_r()<<std::endl; + std::cout<<"IDCaloBoundary_z() "<<result.IDCaloBoundary_z()<<std::endl; + std::cout<<"AngleEta "<<result.IDCaloBoundary_AngleEta()<<std::endl; + std::cout<<"Angle3D "<<result.IDCaloBoundary_Angle3D()<<std::endl; + + m_newTTC_IDCaloBoundary_eta->push_back(result.IDCaloBoundary_eta()); + m_newTTC_IDCaloBoundary_phi->push_back(result.IDCaloBoundary_phi()); + m_newTTC_IDCaloBoundary_r->push_back(result.IDCaloBoundary_r()); + m_newTTC_IDCaloBoundary_z->push_back(result.IDCaloBoundary_z()); + m_newTTC_Angle3D ->push_back(result.IDCaloBoundary_Angle3D()); + m_newTTC_AngleEta->push_back(result.IDCaloBoundary_AngleEta()); + + std::vector<double> eta_vec_ENT; + std::vector<double> phi_vec_ENT; + std::vector<double> r_vec_ENT; + std::vector<double> z_vec_ENT; + + std::vector<double> eta_vec_EXT; + std::vector<double> phi_vec_EXT; + std::vector<double> r_vec_EXT; + std::vector<double> z_vec_EXT; + + for(int sample=CaloCell_ID_FCS::FirstSample;sample<CaloCell_ID_FCS::MaxSample;++sample) + { + std::cout<<"sample "<<sample<<std::endl; + std::cout<<" eta ENT "<<result.eta(sample,1)<<" eta EXT "<<result.eta(sample,2)<<std::endl; + std::cout<<" phi ENT "<<result.phi(sample,1)<<" phi EXT "<<result.phi(sample,2)<<std::endl; + std::cout<<" r ENT "<<result.r(sample,1) <<" r EXT "<<result.r(sample,2) <<std::endl; + std::cout<<" z ENT "<<result.z(sample,1) <<" z EXT "<<result.z(sample,2) <<std::endl; + eta_vec_ENT.push_back(result.eta(sample,1)); + eta_vec_EXT.push_back(result.eta(sample,2)); + phi_vec_ENT.push_back(result.phi(sample,1)); + phi_vec_EXT.push_back(result.phi(sample,2)); + r_vec_ENT.push_back(result.r(sample,1)); + r_vec_EXT.push_back(result.r(sample,2)); + z_vec_ENT.push_back(result.z(sample,1)); + z_vec_EXT.push_back(result.z(sample,2)); + } + + m_newTTC_back_eta->push_back(eta_vec_EXT); + m_newTTC_back_phi->push_back(phi_vec_EXT); + m_newTTC_back_r ->push_back(r_vec_EXT); + m_newTTC_back_z ->push_back(z_vec_EXT); + m_newTTC_entrance_eta->push_back(eta_vec_ENT); + m_newTTC_entrance_phi->push_back(phi_vec_ENT); + m_newTTC_entrance_r ->push_back(r_vec_ENT); + m_newTTC_entrance_z ->push_back(z_vec_ENT); + + //******************************************************************************************************************************* + + //OLD EXTRAPOLATION + std::vector<Trk::HitInfo>* hitVector = caloHits(*(*it)); + + Amg::Vector3D mom((*it)->momentum().x(),(*it)->momentum().y(),(*it)->momentum().z()); + + m_truth_energy->push_back((*it)->momentum().e()); + m_truth_px->push_back((*it)->momentum().px()); + m_truth_py->push_back((*it)->momentum().py()); + m_truth_pz->push_back((*it)->momentum().pz()); + m_truth_pdg->push_back((*it)->pdg_id()); + m_truth_barcode->push_back((*it)->barcode()); + + //extrapolate only if the vertex is within the IDcaloboundary - margin + //bool inside_ID=false; + HepMC::GenVertex* pvtx = (*it)->production_vertex(); + if(pvtx) + { + truth.set_vertex(pvtx->position().x(),pvtx->position().y(),pvtx->position().z(),pvtx->position().t()); + + m_truth_vtxbarcode->push_back(pvtx->barcode()); + double radius2=(pvtx->position().x()*pvtx->position().x())+(pvtx->position().y()*pvtx->position().y()); + ATH_MSG_VERBOSE("particle "<<particleIndex<<" Mom: "<<(*it)->momentum().e()<<"|"<<(*it)->momentum().px()<<"|"<<(*it)->momentum().py()<<"|"<<(*it)->momentum().pz()<<" vertex_x "<<pvtx->position().x()<<" y "<<pvtx->position().y()<<" z "<<pvtx->position().z()<<" r2 "<<radius2<<" VertexBarcode: "<<pvtx->barcode()<<" ParticleBarcode:"<<(*it)->barcode()<<" status: "<<(*it)->status()); + //std::cout<<"m_CaloBoundaryZ+m_calomargin "<<m_CaloBoundaryZ+m_calomargin<<" m_CaloBoundaryR+m_calomargin "<<m_CaloBoundaryR+m_calomargin<<std::endl; + + if(fabs(pvtx->position().z())<(m_CaloBoundaryZ+m_calomargin) && radius2<((m_CaloBoundaryR+m_calomargin)*(m_CaloBoundaryR+m_calomargin))) + { + //inside_ID=true; + //if(inside_ID) + // { + ATH_MSG_DEBUG("*** Do extrapolation ***"); + extrapolate(*it,hitVector); + ATH_MSG_DEBUG("*** Do extrapolation to ID ***"); + extrapolate_to_ID(*it,hitVector); + ATH_MSG_DEBUG("Truth extrapolation done for "<<particleIndex<<" "<<(*it)->barcode()); + } //in this case no extrapolation possible + else + { + //fill extrapolated angles with some weird values + m_TTC_IDCaloBoundary_eta->push_back(-999.); + m_TTC_IDCaloBoundary_phi->push_back(-999.); + m_TTC_IDCaloBoundary_r->push_back(-999.); + m_TTC_IDCaloBoundary_z->push_back(-999.); + m_TTC_Angle3D->push_back(-999.); + m_TTC_AngleEta->push_back(-999.); + + } + } //if pvtx + else //no pvtx + { + ATH_MSG_WARNING( "No vertex found for truth particle, no extrapolation"); + m_truth_vtxbarcode->push_back(-999999); + + //fill extrapolated angles with some weird values + std::vector<double> eta_safe; + std::vector<double> phi_safe; + std::vector<double> r_safe; + std::vector<double> z_safe; + for(int sample=CaloCell_ID_FCS::FirstSample;sample<CaloCell_ID_FCS::MaxSample;++sample) + { + eta_safe.push_back(-999.0); + phi_safe.push_back(-999.0); + r_safe.push_back(-999.0); + z_safe.push_back(-999.0); + } + + m_TTC_back_eta->push_back(eta_safe); + m_TTC_back_phi->push_back(phi_safe); + m_TTC_back_r->push_back(r_safe); + m_TTC_back_z->push_back(z_safe); + m_TTC_entrance_eta->push_back(eta_safe); + m_TTC_entrance_phi->push_back(phi_safe); + m_TTC_entrance_r->push_back(r_safe); + m_TTC_entrance_z->push_back(z_safe); + m_TTC_IDCaloBoundary_eta->push_back(-999.); + m_TTC_IDCaloBoundary_phi->push_back(-999.); + m_TTC_IDCaloBoundary_r->push_back(-999.); + m_TTC_IDCaloBoundary_z->push_back(-999.); + m_TTC_Angle3D->push_back(-999.); + m_TTC_AngleEta->push_back(-999.); + + } //no pvtx + for(std::vector<Trk::HitInfo>::iterator it = hitVector->begin();it < hitVector->end();++it) + { + if((*it).trackParms) + { + delete (*it).trackParms; + (*it).trackParms=0; + } + } + delete hitVector; } + } + } + }//truth event + + //Get reco cells if available + const CaloCellContainer *cellColl = 0; + sc = evtStore()->retrieve(cellColl, "AllCalo"); + + if (sc.isFailure()) + { + ATH_MSG_WARNING( "Couldn't read AllCalo cells from StoreGate"); + //return NULL; + } + else + { + ATH_MSG_INFO( "Found: "<<cellColl->size()<<" calorimeter cells"); + CaloCellContainer::const_iterator itrCell = cellColl->begin(); + CaloCellContainer::const_iterator itrLastCell = cellColl->end(); + for ( ; itrCell!=itrLastCell; ++itrCell) + { + m_cell_energy->push_back((*itrCell)->energy()); + m_cell_identifier->push_back((*itrCell)->ID().get_compact()); + if (m_calo_dd_man->get_element((*itrCell)->ID())) + { + CaloCell_ID::CaloSample layer = m_calo_dd_man->get_element((*itrCell)->ID())->getSampling(); + m_cell_sampling->push_back(layer); + } + else + m_cell_sampling->push_back(-1); + } + } //calorimeter cells + + //Get all G4Hits (from CaloHitAnalysis) + std::string lArKey [4] = {"LArHitEMB", "LArHitEMEC", "LArHitFCAL", "LArHitHEC"}; + for (unsigned int i=0;i<4;i++) + { + const DataHandle<LArHitContainer> iter; + ATH_MSG_DEBUG( "Checking G4Hits: "<<lArKey[i]); + if(evtStore()->retrieve(iter,lArKey[i])==StatusCode::SUCCESS) + { + LArHitContainer::const_iterator hi; + int hitnumber = 0; + for (hi=(*iter).begin();hi!=(*iter).end();hi++) + { + hitnumber++; + GeoLArHit ghit(**hi); + if (!ghit) + continue; + const CaloDetDescrElement *hitElement = ghit.getDetDescrElement(); + if(!hitElement) + continue; + Identifier larhitid = hitElement->identify(); + if(m_calo_dd_man->get_element(larhitid)) + { + CaloCell_ID::CaloSample larlayer = m_calo_dd_man->get_element(larhitid)->getSampling(); + + float larsampfrac=m_dd_fSampl->FSAMPL(larhitid); + m_g4hit_energy->push_back( ghit.Energy() ); + m_g4hit_time->push_back( ghit.Time() ); + m_g4hit_identifier->push_back( larhitid.get_compact() ); + m_g4hit_cellidentifier->push_back( larhitid.get_compact() ); + m_g4hit_sampling->push_back( larlayer); + m_g4hit_samplingfraction->push_back( larsampfrac ); + } + } // End while LAr hits + ATH_MSG_INFO( "Read "<<hitnumber<<" G4Hits from "<<lArKey[i]); + } else - { - ATH_MSG_INFO( "Found: "<<cellColl->size()<<" calorimeter cells"); - CaloCellContainer::const_iterator itrCell = cellColl->begin(); - CaloCellContainer::const_iterator itrLastCell = cellColl->end(); - for ( ; itrCell!=itrLastCell; ++itrCell) - { - m_cell_energy->push_back((*itrCell)->energy()); - m_cell_identifier->push_back((*itrCell)->ID().get_compact()); - if (m_calo_dd_man->get_element((*itrCell)->ID())) - { - CaloCell_ID::CaloSample layer = m_calo_dd_man->get_element((*itrCell)->ID())->getSampling(); - m_cell_sampling->push_back(layer); - } - else - m_cell_sampling->push_back(-1); - } - } //calorimeter cells - - //Get all G4Hits (from CaloHitAnalysis) - std::string lArKey [4] = {"LArHitEMB", "LArHitEMEC", "LArHitFCAL", "LArHitHEC"}; - for (unsigned int i=0;i<4;i++) - { - const DataHandle<LArHitContainer> iter; - ATH_MSG_DEBUG( "Checking G4Hits: "<<lArKey[i]); - if(evtStore()->retrieve(iter,lArKey[i])==StatusCode::SUCCESS) - { - LArHitContainer::const_iterator hi; - int hitnumber = 0; - for (hi=(*iter).begin();hi!=(*iter).end();hi++) - { - hitnumber++; - GeoLArHit ghit(**hi); - if (!ghit) - continue; - const CaloDetDescrElement *hitElement = ghit.getDetDescrElement(); - if(!hitElement) - continue; - Identifier larhitid = hitElement->identify(); - if(m_calo_dd_man->get_element(larhitid)) - { - CaloCell_ID::CaloSample larlayer = m_calo_dd_man->get_element(larhitid)->getSampling(); - - float larsampfrac=m_dd_fSampl->FSAMPL(larhitid); - m_g4hit_energy->push_back( ghit.Energy() ); - m_g4hit_time->push_back( ghit.Time() ); - m_g4hit_identifier->push_back( larhitid.get_compact() ); - m_g4hit_cellidentifier->push_back( larhitid.get_compact() ); - m_g4hit_sampling->push_back( larlayer); - m_g4hit_samplingfraction->push_back( larsampfrac ); - } - } // End while LAr hits - ATH_MSG_INFO( "Read "<<hitnumber<<" G4Hits from "<<lArKey[i]); - } - else - { - ATH_MSG_INFO( "Can't retrieve LAr hits"); - }// End statuscode success upon retrieval of hits - //std::cout <<"ZH G4Hit size: "<<m_g4hit_e->size()<<std::endl; - }// End detector type loop - - const TileHitVector * hitVec; - if (evtStore()->retrieve(hitVec,"TileHitVec")==StatusCode::SUCCESS && m_tileMgr && m_tileID ) - { - int hitnumber = 0; - for(TileHitVecConstIterator i_hit=hitVec->begin() ; i_hit!=hitVec->end() ; ++i_hit) - { - hitnumber++; - Identifier pmt_id = (*i_hit).identify(); - Identifier cell_id = m_tileID->cell_id(pmt_id); - //const CaloDetDescrElement* ddElement = m_tileMgr->get_cell_element(cell_id); - - if (m_calo_dd_man->get_element(cell_id)) - { - CaloCell_ID::CaloSample layer = m_calo_dd_man->get_element(cell_id)->getSampling(); - - float tilesampfrac = m_tileInfo->HitCalib(cell_id); - - //could there be more subhits?? - for (int tilesubhit_i = 0; tilesubhit_i<(*i_hit).size(); tilesubhit_i++) - { - //!! - //std::cout <<"Tile subhit: "<<tilesubhit_i<<"/"<<(*i_hit).size()<< " E: "<<(*i_hit).energy(tilesubhit_i)<<std::endl; - m_g4hit_energy->push_back( (*i_hit).energy(tilesubhit_i) ); - m_g4hit_time->push_back( (*i_hit).time(tilesubhit_i) ); - m_g4hit_identifier->push_back( pmt_id.get_compact() ); - m_g4hit_cellidentifier->push_back( cell_id.get_compact() ); - m_g4hit_sampling->push_back( layer ); - m_g4hit_samplingfraction->push_back( tilesampfrac ); - } - } - } - ATH_MSG_INFO( "Read "<<hitnumber<<" G4Hits from TileHitVec"); - } - - //Fill the tree and finish - if (m_tree) m_tree->Fill(); - - return StatusCode::SUCCESS; - + { + ATH_MSG_INFO( "Can't retrieve LAr hits"); + }// End statuscode success upon retrieval of hits + //std::cout <<"ZH G4Hit size: "<<m_g4hit_e->size()<<std::endl; + }// End detector type loop + + const TileHitVector * hitVec; + if (evtStore()->retrieve(hitVec,"TileHitVec")==StatusCode::SUCCESS && m_tileMgr && m_tileID ) + { + int hitnumber = 0; + for(TileHitVecConstIterator i_hit=hitVec->begin() ; i_hit!=hitVec->end() ; ++i_hit) + { + hitnumber++; + Identifier pmt_id = (*i_hit).identify(); + Identifier cell_id = m_tileID->cell_id(pmt_id); + //const CaloDetDescrElement* ddElement = m_tileMgr->get_cell_element(cell_id); + + if (m_calo_dd_man->get_element(cell_id)) + { + CaloCell_ID::CaloSample layer = m_calo_dd_man->get_element(cell_id)->getSampling(); + + float tilesampfrac = m_tileInfo->HitCalib(cell_id); + + //could there be more subhits?? + for (int tilesubhit_i = 0; tilesubhit_i<(*i_hit).size(); tilesubhit_i++) + { + //!! + //std::cout <<"Tile subhit: "<<tilesubhit_i<<"/"<<(*i_hit).size()<< " E: "<<(*i_hit).energy(tilesubhit_i)<<std::endl; + m_g4hit_energy->push_back( (*i_hit).energy(tilesubhit_i) ); + m_g4hit_time->push_back( (*i_hit).time(tilesubhit_i) ); + m_g4hit_identifier->push_back( pmt_id.get_compact() ); + m_g4hit_cellidentifier->push_back( cell_id.get_compact() ); + m_g4hit_sampling->push_back( layer ); + m_g4hit_samplingfraction->push_back( tilesampfrac ); + } + } + } + ATH_MSG_INFO( "Read "<<hitnumber<<" G4Hits from TileHitVec"); + } + + //Fill the tree and finish + if (m_tree) m_tree->Fill(); + + return StatusCode::SUCCESS; + } //execute std::vector<Trk::HitInfo>* ISF_HitAnalysis::caloHits(const HepMC::GenParticle& part) const { - // Start calo extrapolation - ATH_MSG_DEBUG ("[ fastCaloSim transport ] processing particle "<<part.pdg_id() ); - - std::vector<Trk::HitInfo>* hitVector = new std::vector<Trk::HitInfo>; - - int pdgId = part.pdg_id(); - double charge = HepPDT::ParticleID(pdgId).charge(); - - // particle Hypothesis for the extrapolation - Trk::ParticleHypothesis pHypothesis = m_pdgToParticleHypothesis.convert(pdgId,charge); - - ATH_MSG_DEBUG ("particle hypothesis "<< pHypothesis ); - - // geantinos not handled by PdgToParticleHypothesis - fix there - if( pdgId == 999 ) pHypothesis = Trk::geantino; - - HepMC::GenVertex *vtx = part.production_vertex(); - Amg::Vector3D pos(0.,0.,0.); // default - - if (vtx) - { - //const HepMC::ThreeVector vtxPos(vtx->point3d()); - pos = Amg::Vector3D( vtx->point3d().x(),vtx->point3d().y(), vtx->point3d().z()); - } - - Amg::Vector3D mom(part.momentum().x(),part.momentum().y(),part.momentum().z()); - ATH_MSG_DEBUG( "[ fastCaloSim transport ] starting transport from position eta="<<pos.eta()<<" phi="<<pos.phi()<<" d="<<pos.mag()<<" pT="<<mom.perp() ); - - // input parameters : curvilinear parameters - Trk::CurvilinearParameters inputPar(pos,mom,charge); - - // stable vs. unstable check : ADAPT for FASTCALOSIM - //double freepath = ( !m_particleDecayHelper.empty()) ? m_particleDecayHelper->freePath(isp) : - 1.; - double freepath = -1.; - //ATH_MSG_VERBOSE( "[ fatras transport ] Particle free path : " << freepath); - // path limit -> time limit ( TODO : extract life-time directly from decay helper ) - double tDec = freepath > 0. ? freepath : -1.; - int decayProc = 0; - - /* uncomment if unstable particles used by FastCaloSim - // beta calculated here for further use in validation - double mass = m_particleMasses.mass[pHypothesis]; - double mom = isp.momentum().mag(); - double beta = mom/sqrt(mom*mom+mass*mass); - - if ( tDec>0.) + // Start calo extrapolation + ATH_MSG_DEBUG ("[ fastCaloSim transport ] processing particle "<<part.pdg_id() ); + + std::vector<Trk::HitInfo>* hitVector = new std::vector<Trk::HitInfo>; + + int pdgId = part.pdg_id(); + double charge = HepPDT::ParticleID(pdgId).charge(); + + // particle Hypothesis for the extrapolation + Trk::ParticleHypothesis pHypothesis = m_pdgToParticleHypothesis.convert(pdgId,charge); + + ATH_MSG_DEBUG ("particle hypothesis "<< pHypothesis ); + + // geantinos not handled by PdgToParticleHypothesis - fix there + if( pdgId == 999 ) pHypothesis = Trk::geantino; + + HepMC::GenVertex *vtx = part.production_vertex(); + Amg::Vector3D pos(0.,0.,0.); // default + + if (vtx) + { + //const HepMC::ThreeVector vtxPos(vtx->point3d()); + pos = Amg::Vector3D( vtx->point3d().x(),vtx->point3d().y(), vtx->point3d().z()); + } + + Amg::Vector3D mom(part.momentum().x(),part.momentum().y(),part.momentum().z()); + ATH_MSG_DEBUG( "[ fastCaloSim transport ] starting transport from position eta="<<pos.eta()<<" phi="<<pos.phi()<<" d="<<pos.mag()<<" pT="<<mom.perp() ); + + // input parameters : curvilinear parameters + Trk::CurvilinearParameters inputPar(pos,mom,charge); + + // stable vs. unstable check : ADAPT for FASTCALOSIM + //double freepath = ( !m_particleDecayHelper.empty()) ? m_particleDecayHelper->freePath(isp) : - 1.; + double freepath = -1.; + //ATH_MSG_VERBOSE( "[ fatras transport ] Particle free path : " << freepath); + // path limit -> time limit ( TODO : extract life-time directly from decay helper ) + double tDec = freepath > 0. ? freepath : -1.; + int decayProc = 0; + + /* uncomment if unstable particles used by FastCaloSim + // beta calculated here for further use in validation + double mass = m_particleMasses.mass[pHypothesis]; + double mom = isp.momentum().mag(); + double beta = mom/sqrt(mom*mom+mass*mass); + + if ( tDec>0.) + { + tDec = tDec/beta/CLHEP::c_light + isp.timeStamp(); + decayProc = 201; + } + */ + + Trk::TimeLimit timeLim(tDec,0.,decayProc); // TODO: set vertex time info + + // prompt decay ( uncomment if unstable particles used ) + //if ( freepath>0. && freepath<0.01 ) { + // if (!m_particleDecayHelper.empty()) { + // ATH_MSG_VERBOSE( "[ fatras transport ] Decay is triggered for input particle."); + // m_particleDecayHelper->decay(isp); + // } + // return 0; + //} + + // presample interactions - ADAPT FOR FASTCALOSIM + Trk::PathLimit pathLim(-1.,0); + //if (absPdg!=999 && pHypothesis<99) pathLim = m_samplingTool->sampleProcess(mom,isp.charge(),pHypothesis); + + Trk::GeometrySignature nextGeoID=Trk::Calo; + + // first extrapolation to reach the ID boundary + ATH_MSG_DEBUG( "[ fastCaloSim transport ] before calo entrance "); + + // get CaloEntrance if not done already + if (!m_caloEntrance) + { + m_caloEntrance = m_extrapolator->trackingGeometry()->trackingVolume(m_caloEntranceName); + if(!m_caloEntrance) + ATH_MSG_INFO("CaloEntrance not found "); + else + ATH_MSG_INFO("CaloEntrance found "); + } + + ATH_MSG_DEBUG( "[ fastCaloSim transport ] after calo entrance "); + + const Trk::TrackParameters* caloEntry = 0; + + if(m_caloEntrance && m_caloEntrance->inside(pos,0.001) && !m_extrapolator->trackingGeometry()->atVolumeBoundary(pos,m_caloEntrance,0.001)) + { + std::vector<Trk::HitInfo>* dummyHitVector = 0; + if( charge==0 ) { - tDec = tDec/beta/CLHEP::c_light + isp.timeStamp(); - decayProc = 201; + caloEntry = m_extrapolator->transportNeutralsWithPathLimit(inputPar,pathLim,timeLim,Trk::alongMomentum,pHypothesis,dummyHitVector,nextGeoID,m_caloEntrance); } - */ - - Trk::TimeLimit timeLim(tDec,0.,decayProc); // TODO: set vertex time info - - // prompt decay ( uncomment if unstable particles used ) - //if ( freepath>0. && freepath<0.01 ) { - // if (!m_particleDecayHelper.empty()) { - // ATH_MSG_VERBOSE( "[ fatras transport ] Decay is triggered for input particle."); - // m_particleDecayHelper->decay(isp); - // } - // return 0; - //} - - // presample interactions - ADAPT FOR FASTCALOSIM - Trk::PathLimit pathLim(-1.,0); - //if (absPdg!=999 && pHypothesis<99) pathLim = m_samplingTool->sampleProcess(mom,isp.charge(),pHypothesis); - - Trk::GeometrySignature nextGeoID=Trk::Calo; - - // first extrapolation to reach the ID boundary - ATH_MSG_DEBUG( "[ fastCaloSim transport ] before calo entrance "); - - // get CaloEntrance if not done already - if (!m_caloEntrance) - { - m_caloEntrance = m_extrapolator->trackingGeometry()->trackingVolume(m_caloEntranceName); - if(!m_caloEntrance) - ATH_MSG_INFO("CaloEntrance not found "); - else - ATH_MSG_INFO("CaloEntrance found "); - } - - ATH_MSG_DEBUG( "[ fastCaloSim transport ] after calo entrance "); - - const Trk::TrackParameters* caloEntry = 0; - - if(m_caloEntrance && m_caloEntrance->inside(pos,0.001) && !m_extrapolator->trackingGeometry()->atVolumeBoundary(pos,m_caloEntrance,0.001)) - { - std::vector<Trk::HitInfo>* dummyHitVector = 0; - if( charge==0 ) - { - caloEntry = m_extrapolator->transportNeutralsWithPathLimit(inputPar,pathLim,timeLim,Trk::alongMomentum,pHypothesis,dummyHitVector,nextGeoID,m_caloEntrance); - } - else - { - caloEntry = m_extrapolator->extrapolateWithPathLimit(inputPar,pathLim,timeLim,Trk::alongMomentum,pHypothesis,dummyHitVector,nextGeoID,m_caloEntrance); - } - } else - caloEntry=&inputPar; - - ATH_MSG_DEBUG( "[ fastCaloSim transport ] after calo caloEntry "); - - if(caloEntry) - { - const Trk::TrackParameters* eParameters = 0; - - // save Calo entry hit (fallback info) - hitVector->push_back(Trk::HitInfo(caloEntry->clone(),timeLim.time,nextGeoID,0.)); - - ATH_MSG_DEBUG( "[ fastCaloSim transport ] starting Calo transport from position eta="<<caloEntry->position().eta()<<" phi="<<caloEntry->position().phi()<<" d="<<caloEntry->position().mag() ); - - if( charge==0 ) - { - eParameters = m_extrapolator->transportNeutralsWithPathLimit(*caloEntry,pathLim,timeLim,Trk::alongMomentum,pHypothesis,hitVector,nextGeoID); - } - else - { - eParameters = m_extrapolator->extrapolateWithPathLimit(*caloEntry,pathLim,timeLim,Trk::alongMomentum,pHypothesis,hitVector,nextGeoID); - } - // save Calo exit hit (fallback info) - if (eParameters) hitVector->push_back(Trk::HitInfo(eParameters,timeLim.time,nextGeoID,0.)); - //delete eParameters; // HitInfo took ownership - } - - if(msgLvl(MSG::DEBUG)) - { - std::vector<Trk::HitInfo>::iterator it = hitVector->begin(); - while (it < hitVector->end() ) - { - int sample=(*it).detID; - Amg::Vector3D hitPos = (*it).trackParms->position(); - ATH_MSG_DEBUG(" HIT: layer="<<sample<<" sample="<<sample-3000<<" eta="<<hitPos.eta()<<" phi="<<hitPos.phi()<<" d="<<hitPos.mag()); - it++; - } - } - - return hitVector; + { + caloEntry = m_extrapolator->extrapolateWithPathLimit(inputPar,pathLim,timeLim,Trk::alongMomentum,pHypothesis,dummyHitVector,nextGeoID,m_caloEntrance); + } + } + else + caloEntry=&inputPar; + + ATH_MSG_DEBUG( "[ fastCaloSim transport ] after calo caloEntry "); + + if(caloEntry) + { + const Trk::TrackParameters* eParameters = 0; + + // save Calo entry hit (fallback info) + hitVector->push_back(Trk::HitInfo(caloEntry->clone(),timeLim.time,nextGeoID,0.)); + + ATH_MSG_DEBUG( "[ fastCaloSim transport ] starting Calo transport from position eta="<<caloEntry->position().eta()<<" phi="<<caloEntry->position().phi()<<" d="<<caloEntry->position().mag() ); + + if( charge==0 ) + { + eParameters = m_extrapolator->transportNeutralsWithPathLimit(*caloEntry,pathLim,timeLim,Trk::alongMomentum,pHypothesis,hitVector,nextGeoID); + } + else + { + eParameters = m_extrapolator->extrapolateWithPathLimit(*caloEntry,pathLim,timeLim,Trk::alongMomentum,pHypothesis,hitVector,nextGeoID); + } + // save Calo exit hit (fallback info) + if (eParameters) hitVector->push_back(Trk::HitInfo(eParameters,timeLim.time,nextGeoID,0.)); + //delete eParameters; // HitInfo took ownership + } + + if(msgLvl(MSG::DEBUG)) + { + std::vector<Trk::HitInfo>::iterator it = hitVector->begin(); + while (it < hitVector->end() ) + { + int sample=(*it).detID; + Amg::Vector3D hitPos = (*it).trackParms->position(); + ATH_MSG_DEBUG(" HIT: layer="<<sample<<" sample="<<sample-3000<<" eta="<<hitPos.eta()<<" phi="<<hitPos.phi()<<" d="<<hitPos.mag()); + it++; + } + } + + return hitVector; } //caloHits //####################################################################### void ISF_HitAnalysis::extrapolate(const HepMC::GenParticle* part,std::vector<Trk::HitInfo>* hitVector) { - ATH_MSG_DEBUG("Start extrapolate()"); - - m_ptruth_eta=part->momentum().eta(); - m_ptruth_phi=part->momentum().phi(); - m_ptruth_e =part->momentum().e(); - m_ptruth_pt =part->momentum().perp(); - m_ptruth_p =part->momentum().rho(); - m_pdgid=part->pdg_id(); - - ////////////////////////////////////// - // Start calo extrapolation - // First: get entry point into first calo sample - ////////////////////////////////////// - - get_calo_surface(hitVector); - - std::vector< std::vector<double> > eta_safe(3); - std::vector< std::vector<double> > phi_safe(3); - std::vector< std::vector<double> > r_safe(3); - std::vector< std::vector<double> > z_safe(3); - for(int subpos=CaloSubPos::SUBPOS_MID;subpos<=CaloSubPos::SUBPOS_EXT;++subpos) + ATH_MSG_DEBUG("Start extrapolate()"); + + m_ptruth_eta=part->momentum().eta(); + m_ptruth_phi=part->momentum().phi(); + m_ptruth_e =part->momentum().e(); + m_ptruth_pt =part->momentum().perp(); + m_ptruth_p =part->momentum().rho(); + m_pdgid=part->pdg_id(); + + ////////////////////////////////////// + // Start calo extrapolation + // First: get entry point into first calo sample + ////////////////////////////////////// + + get_calo_surface(hitVector); + + std::vector< std::vector<double> > eta_safe(3); + std::vector< std::vector<double> > phi_safe(3); + std::vector< std::vector<double> > r_safe(3); + std::vector< std::vector<double> > z_safe(3); + for(int subpos=CaloSubPos::SUBPOS_MID;subpos<=CaloSubPos::SUBPOS_EXT;++subpos) + { + eta_safe[subpos].resize(CaloCell_ID_FCS::MaxSample,-999.0); + phi_safe[subpos].resize(CaloCell_ID_FCS::MaxSample,-999.0); + r_safe[subpos].resize(CaloCell_ID_FCS::MaxSample,-999.0); + z_safe[subpos].resize(CaloCell_ID_FCS::MaxSample,-999.0); + } + + // only continue if inside the calo + if( fabs(m_eta_calo_surf)<6 ) + { + // now try to extrpolate to all calo layers, that contain energy + ATH_MSG_DEBUG("Calo position for particle id "<<m_pdgid<<", trutheta= " << m_ptruth_eta <<", truthphi= "<<m_ptruth_phi<<", truthp="<<m_ptruth_p<<", truthpt="<<m_ptruth_pt); + for(int sample=CaloCell_ID_FCS::FirstSample;sample<CaloCell_ID_FCS::MaxSample;++sample) + { + for(int subpos=CaloSubPos::SUBPOS_MID;subpos<=CaloSubPos::SUBPOS_EXT;++subpos) + { + m_letaCalo[sample][subpos]=-12345; + m_lphiCalo[sample][subpos]=-12345; + m_lrCalo[sample][subpos]=-12345; + m_lzCalo[sample][subpos]=-12345; + m_layerCaloOK[sample][subpos]=0; + //ATH_MSG_DEBUG("============= Getting Calo position for sample "<<sample<<" E/Etot="<<p.E_layer[sample]<<" ; in : eta= " << m_ptruth_eta); + + if(get_calo_etaphi(hitVector,sample,subpos)) { - eta_safe[subpos].resize(CaloCell_ID_FCS::MaxSample,-999.0); - phi_safe[subpos].resize(CaloCell_ID_FCS::MaxSample,-999.0); - r_safe[subpos].resize(CaloCell_ID_FCS::MaxSample,-999.0); - z_safe[subpos].resize(CaloCell_ID_FCS::MaxSample,-999.0); + ATH_MSG_DEBUG( "Result in sample "<<sample<<"."<<subpos<<": eta="<<m_letaCalo[sample][subpos]<<" phi="<<m_lphiCalo[sample][subpos]<<" r="<<m_lrCalo[sample][subpos]<<" z="<<m_lzCalo[sample][subpos]<<" (ok="<<m_layerCaloOK[sample][subpos]<<")"); + eta_safe[subpos][sample]=m_letaCalo[sample][subpos]; + phi_safe[subpos][sample]=m_lphiCalo[sample][subpos]; + r_safe[subpos][sample]=m_lrCalo[sample][subpos]; + z_safe[subpos][sample]=m_lzCalo[sample][subpos]; } - - // only continue if inside the calo - if( fabs(m_eta_calo_surf)<6 ) - { - // now try to extrpolate to all calo layers, that contain energy - ATH_MSG_DEBUG("Calo position for particle id "<<m_pdgid<<", trutheta= " << m_ptruth_eta <<", truthphi= "<<m_ptruth_phi<<", truthp="<<m_ptruth_p<<", truthpt="<<m_ptruth_pt); - for(int sample=CaloCell_ID_FCS::FirstSample;sample<CaloCell_ID_FCS::MaxSample;++sample) - { - for(int subpos=CaloSubPos::SUBPOS_MID;subpos<=CaloSubPos::SUBPOS_EXT;++subpos) - { - m_letaCalo[sample][subpos]=-12345; - m_lphiCalo[sample][subpos]=-12345; - m_lrCalo[sample][subpos]=-12345; - m_lzCalo[sample][subpos]=-12345; - m_layerCaloOK[sample][subpos]=0; - //ATH_MSG_DEBUG("============= Getting Calo position for sample "<<sample<<" E/Etot="<<p.E_layer[sample]<<" ; in : eta= " << m_ptruth_eta); - - if(get_calo_etaphi(hitVector,sample,subpos)) - { - ATH_MSG_DEBUG( "Result in sample "<<sample<<"."<<subpos<<": eta="<<m_letaCalo[sample][subpos]<<" phi="<<m_lphiCalo[sample][subpos]<<" r="<<m_lrCalo[sample][subpos]<<" z="<<m_lzCalo[sample][subpos]<<" (ok="<<m_layerCaloOK[sample][subpos]<<")"); - eta_safe[subpos][sample]=m_letaCalo[sample][subpos]; - phi_safe[subpos][sample]=m_lphiCalo[sample][subpos]; - r_safe[subpos][sample]=m_lrCalo[sample][subpos]; - z_safe[subpos][sample]=m_lzCalo[sample][subpos]; - } - else - ATH_MSG_DEBUG( "Extrapolation to sample "<<sample<<" failed (ok="<<m_layerCaloOK[sample][subpos]<<")"); - } - } - } //inside calo - - m_TTC_back_eta->push_back(eta_safe[CaloSubPos::SUBPOS_EXT]); - m_TTC_back_phi->push_back(phi_safe[CaloSubPos::SUBPOS_EXT]); - m_TTC_back_r->push_back(r_safe[CaloSubPos::SUBPOS_EXT]); - m_TTC_back_z->push_back(z_safe[CaloSubPos::SUBPOS_EXT]); - - m_TTC_entrance_eta->push_back(eta_safe[CaloSubPos::SUBPOS_ENT]); - m_TTC_entrance_phi->push_back(phi_safe[CaloSubPos::SUBPOS_ENT]); - m_TTC_entrance_r->push_back(r_safe[CaloSubPos::SUBPOS_ENT]); - m_TTC_entrance_z->push_back(z_safe[CaloSubPos::SUBPOS_ENT]); - - ATH_MSG_DEBUG("End extrapolate()"); + else + ATH_MSG_DEBUG( "Extrapolation to sample "<<sample<<" failed (ok="<<m_layerCaloOK[sample][subpos]<<")"); + } + } + } //inside calo + + m_TTC_back_eta->push_back(eta_safe[CaloSubPos::SUBPOS_EXT]); + m_TTC_back_phi->push_back(phi_safe[CaloSubPos::SUBPOS_EXT]); + m_TTC_back_r->push_back(r_safe[CaloSubPos::SUBPOS_EXT]); + m_TTC_back_z->push_back(z_safe[CaloSubPos::SUBPOS_EXT]); + + m_TTC_entrance_eta->push_back(eta_safe[CaloSubPos::SUBPOS_ENT]); + m_TTC_entrance_phi->push_back(phi_safe[CaloSubPos::SUBPOS_ENT]); + m_TTC_entrance_r->push_back(r_safe[CaloSubPos::SUBPOS_ENT]); + m_TTC_entrance_z->push_back(z_safe[CaloSubPos::SUBPOS_ENT]); + + ATH_MSG_DEBUG("End extrapolate()"); } //extrapolate void ISF_HitAnalysis::extrapolate_to_ID(const HepMC::GenParticle* part,std::vector<Trk::HitInfo>* hitVector) { - ATH_MSG_DEBUG("Start extrapolate_to_ID()"); - - m_ptruth_eta=part->momentum().eta(); - m_ptruth_phi=part->momentum().phi(); - m_ptruth_e =part->momentum().e(); - m_ptruth_pt =part->momentum().perp(); - m_ptruth_p =part->momentum().rho(); - m_pdgid =part->pdg_id(); - - Amg::Vector3D hitpos(0,0,0); - Amg::Vector3D hitmom(0,0,0); - if(rz_cylinder_get_calo_etaphi(hitVector,m_CaloBoundaryR,m_CaloBoundaryZ,hitpos,hitmom)) - { - ATH_MSG_DEBUG("BOUNDARY ID-CALO eta="<<hitpos.eta()<<" phi="<<hitpos.phi()<<" r="<<hitpos.perp()<<" z="<<hitpos[Amg::z]<<" theta="<<hitpos.theta()<<" ; momentum eta="<<hitmom.eta()<<" phi="<<hitmom.phi()<<" theta="<<hitmom.theta()); - m_TTC_IDCaloBoundary_eta->push_back(hitpos.eta()); - m_TTC_IDCaloBoundary_phi->push_back(hitpos.phi()); - m_TTC_IDCaloBoundary_r->push_back(hitpos.perp()); - m_TTC_IDCaloBoundary_z->push_back(hitpos[Amg::z]); - } - else - { - ATH_MSG_DEBUG("Extrapolation to IDCaloBoundary failed"); - m_TTC_IDCaloBoundary_eta->push_back(-999.); - m_TTC_IDCaloBoundary_phi->push_back(-999.); - m_TTC_IDCaloBoundary_r->push_back(-999.); - m_TTC_IDCaloBoundary_z->push_back(-999.); - } - - TVector3 vec(hitpos[Amg::x],hitpos[Amg::y],hitpos[Amg::z]); - - //get the tangentvector on this interaction point: - //GlobalMomentum* mom=params_on_surface_ID->TrackParameters::momentum().unit() ; - //Trk::GlobalMomentum* trackmom=params_on_surface_ID->Trk::TrackParameters::momentum(); - - if(hitmom.mag()>0) - { - //angle between vec and trackmom: - TVector3 Trackmom(hitmom[Amg::x],hitmom[Amg::y],hitmom[Amg::z]); - double angle3D=Trackmom.Angle(vec); //isn't this the same as TVector3 vec? - ATH_MSG_DEBUG(" 3D ANGLE "<<angle3D); - - double angleEta=vec.Theta()-Trackmom.Theta(); - ATH_MSG_DEBUG(" ANGLE dTHEA"<<angleEta); - - m_TTC_Angle3D->push_back(angle3D); - m_TTC_AngleEta->push_back(angleEta); - } - else - { - m_TTC_Angle3D->push_back(-999.); - m_TTC_AngleEta->push_back(-999.); - } - ATH_MSG_DEBUG("End extrapolate_to_ID()"); + ATH_MSG_DEBUG("Start extrapolate_to_ID()"); + + m_ptruth_eta=part->momentum().eta(); + m_ptruth_phi=part->momentum().phi(); + m_ptruth_e =part->momentum().e(); + m_ptruth_pt =part->momentum().perp(); + m_ptruth_p =part->momentum().rho(); + m_pdgid =part->pdg_id(); + + Amg::Vector3D hitpos(0,0,0); + Amg::Vector3D hitmom(0,0,0); + if(rz_cylinder_get_calo_etaphi(hitVector,m_CaloBoundaryR,m_CaloBoundaryZ,hitpos,hitmom)) + { + ATH_MSG_DEBUG("BOUNDARY ID-CALO eta="<<hitpos.eta()<<" phi="<<hitpos.phi()<<" r="<<hitpos.perp()<<" z="<<hitpos[Amg::z]<<" theta="<<hitpos.theta()<<" ; momentum eta="<<hitmom.eta()<<" phi="<<hitmom.phi()<<" theta="<<hitmom.theta()); + m_TTC_IDCaloBoundary_eta->push_back(hitpos.eta()); + m_TTC_IDCaloBoundary_phi->push_back(hitpos.phi()); + m_TTC_IDCaloBoundary_r->push_back(hitpos.perp()); + m_TTC_IDCaloBoundary_z->push_back(hitpos[Amg::z]); + } + else + { + ATH_MSG_DEBUG("Extrapolation to IDCaloBoundary failed"); + m_TTC_IDCaloBoundary_eta->push_back(-999.); + m_TTC_IDCaloBoundary_phi->push_back(-999.); + m_TTC_IDCaloBoundary_r->push_back(-999.); + m_TTC_IDCaloBoundary_z->push_back(-999.); + } + + TVector3 vec(hitpos[Amg::x],hitpos[Amg::y],hitpos[Amg::z]); + + //get the tangentvector on this interaction point: + //GlobalMomentum* mom=params_on_surface_ID->TrackParameters::momentum().unit() ; + //Trk::GlobalMomentum* trackmom=params_on_surface_ID->Trk::TrackParameters::momentum(); + + if(hitmom.mag()>0) + { + //angle between vec and trackmom: + TVector3 Trackmom(hitmom[Amg::x],hitmom[Amg::y],hitmom[Amg::z]); + double angle3D=Trackmom.Angle(vec); //isn't this the same as TVector3 vec? + ATH_MSG_DEBUG(" 3D ANGLE "<<angle3D); + + double angleEta=vec.Theta()-Trackmom.Theta(); + ATH_MSG_DEBUG(" ANGLE dTHEA"<<angleEta); + + m_TTC_Angle3D->push_back(angle3D); + m_TTC_AngleEta->push_back(angleEta); + } + else + { + m_TTC_Angle3D->push_back(-999.); + m_TTC_AngleEta->push_back(-999.); + } + ATH_MSG_DEBUG("End extrapolate_to_ID()"); } //extrapolate_to_ID //UPDATED -bool ISF_HitAnalysis::get_calo_etaphi(std::vector<Trk::HitInfo>* hitVector, int sample,int subpos) +bool ISF_HitAnalysis::get_calo_etaphi(std::vector<Trk::HitInfo>* hitVector, int sample,int subpos) { m_layerCaloOK[sample][subpos]=false; m_letaCalo[sample][subpos]=m_eta_calo_surf; @@ -1441,14 +1453,14 @@ bool ISF_HitAnalysis::get_calo_etaphi(std::vector<Trk::HitInfo>* hitVector, int std::vector<Trk::HitInfo>::iterator it = hitVector->begin(); while ( it!= hitVector->end() && it->detID != (3000+sample) ) { it++;} //while ((*it).detID != (3000+sample) && it < hitVector->end() ) it++; - + if (it!=hitVector->end()) { Amg::Vector3D hitPos1 = (*it).trackParms->position(); int sid1=(*it).detID; int sid2=-1; Amg::Vector3D hitPos; Amg::Vector3D hitPos2; - + std::vector<Trk::HitInfo>::iterator itnext = it; ++itnext; if(itnext!=hitVector->end()) { @@ -1490,7 +1502,7 @@ bool ISF_HitAnalysis::get_calo_etaphi(std::vector<Trk::HitInfo>* hitVector, int " r1="<<hitPos1.perp()<<" z1="<<hitPos1[Amg::z]<<" r2="<<hitPos2.perp()<<" z2="<<hitPos2[Amg::z]<< " re="<<m_lrCalo[sample][subpos]<<" ze="<<m_lzCalo[sample][subpos] ); - } + } if(!best_found) { it = hitVector->begin(); double best_dist=0.5; @@ -1545,11 +1557,11 @@ bool ISF_HitAnalysis::get_calo_etaphi(std::vector<Trk::HitInfo>* hitVector, int } } ATH_MSG_VERBOSE(" extrapol without layer hit: id="<<sid1<<" -> "<<sid2<<" dist="<<dist<<" mindist="<<best_dist<< - " t="<<t<<" best_inside="<<best_inside<<" target r/z="<<tmp_target<< - " r1="<<hitPos1.perp()<<" z1="<<hitPos1[Amg::z]<<" r2="<<hitPos2.perp()<<" z2="<<hitPos2[Amg::z]<< - " re="<<hitPos.perp()<<" ze="<<hitPos[Amg::z]<< - " rb="<<best_hitPos.perp()<<" zb="<<best_hitPos[Amg::z] - ); + " t="<<t<<" best_inside="<<best_inside<<" target r/z="<<tmp_target<< + " r1="<<hitPos1.perp()<<" z1="<<hitPos1[Amg::z]<<" r2="<<hitPos2.perp()<<" z2="<<hitPos2[Amg::z]<< + " re="<<hitPos.perp()<<" ze="<<hitPos[Amg::z]<< + " rb="<<best_hitPos.perp()<<" zb="<<best_hitPos[Amg::z] + ); if(best_found) { m_letaCalo[sample][subpos]=best_hitPos.eta(); m_lphiCalo[sample][subpos]=best_hitPos.phi(); @@ -1559,18 +1571,18 @@ bool ISF_HitAnalysis::get_calo_etaphi(std::vector<Trk::HitInfo>* hitVector, int lrzpos=rzpos(sample,m_letaCalo[sample][subpos],subpos); distsamp=deta(sample,m_letaCalo[sample][subpos]); m_layerCaloOK[sample][subpos]=true; - } - } + } + } if(best_found) { ATH_MSG_DEBUG(" extrapol without layer hit: id="<<best_id1<<" -> "<<best_id2<<" mindist="<<best_dist<< " best_inside="<<best_inside<<" target r/z="<<best_target<< " rb="<<best_hitPos.perp()<<" zb="<<best_hitPos[Amg::z] ); - } + } } - + if(isCaloBarrel(sample)) lrzpos*=cosh(m_letaCalo[sample][subpos]); - else lrzpos= fabs(lrzpos/tanh(m_letaCalo[sample][subpos])); + else lrzpos= fabs(lrzpos/tanh(m_letaCalo[sample][subpos])); m_dCalo[sample][subpos]=lrzpos; m_distetaCaloBorder[sample][subpos]=distsamp; @@ -1578,15 +1590,15 @@ bool ISF_HitAnalysis::get_calo_etaphi(std::vector<Trk::HitInfo>* hitVector, int if(msgLvl(MSG::DEBUG)) { msg(MSG::DEBUG)<<" Final par TTC sample "<<sample<<" subpos="<<subpos; if(m_layerCaloOK[sample][subpos]) msg()<<" (good)"; - else msg()<<" (bad)"; + else msg()<<" (bad)"; msg()<<" eta=" << m_letaCalo[sample][subpos] << " phi=" << m_lphiCalo[sample][subpos] <<" m_dCalo="<<m_dCalo[sample][subpos]<<" dist(hit)="<<hitdist<< endmsg; - } - + } + return m_layerCaloOK[sample][subpos]; } //get_calo_etaphi //UPDATED -bool ISF_HitAnalysis::rz_cylinder_get_calo_etaphi(std::vector<Trk::HitInfo>* hitVector, double cylR, double cylZ, Amg::Vector3D& pos, Amg::Vector3D& mom) +bool ISF_HitAnalysis::rz_cylinder_get_calo_etaphi(std::vector<Trk::HitInfo>* hitVector, double cylR, double cylZ, Amg::Vector3D& pos, Amg::Vector3D& mom) { bool best_found=false; double best_dist=10000; @@ -1623,7 +1635,7 @@ bool ISF_HitAnalysis::rz_cylinder_get_calo_etaphi(std::vector<Trk::HitInfo>* hit double dist=hitPos.mag(); bool inside=false; if(t>=-0.001 && t<=1.001) inside=true; - + if(!best_found || inside) { if(!best_inside || dist<best_dist) { best_dist=dist; @@ -1652,14 +1664,14 @@ bool ISF_HitAnalysis::rz_cylinder_get_calo_etaphi(std::vector<Trk::HitInfo>* hit " rb="<<best_hitPos.perp()<<" zb="<<best_hitPos[Amg::z] ); } - } - + } + if(best_found) { ATH_MSG_DEBUG(" extrapol to r="<<cylR<<" z="<<cylZ<<": id="<<best_id1<<" -> "<<best_id2<<" dist="<<best_dist<< " best_inside="<<best_inside<< " rb="<<best_hitPos.perp()<<" zb="<<best_hitPos[Amg::z] ); - } + } pos=best_hitPos; return best_found; @@ -1667,8 +1679,8 @@ bool ISF_HitAnalysis::rz_cylinder_get_calo_etaphi(std::vector<Trk::HitInfo>* hit //UPDATED /* - bool ISF_HitAnalysis::get_calo_etaphi(std::vector<Trk::HitInfo>* hitVector, CaloCell_ID_FCS::CaloSample sample) - { +bool ISF_HitAnalysis::get_calo_etaphi(std::vector<Trk::HitInfo>* hitVector, CaloCell_ID_FCS::CaloSample sample) +{ m_layerCaloOK[sample]=false; m_letaCalo[sample]=m_eta_calo_surf; m_lphiCalo[sample]=m_phi_calo_surf; @@ -1681,145 +1693,145 @@ bool ISF_HitAnalysis::rz_cylinder_get_calo_etaphi(std::vector<Trk::HitInfo>* hit std::vector<Trk::HitInfo>::iterator it = hitVector->begin(); while ( it!= hitVector->end() && it->detID != (3000+sample) ) { it++;} //while ((*it).detID != (3000+sample) && it < hitVector->end() ) it++; - + if (it!=hitVector->end()) { - Amg::Vector3D hitPos1 = (*it).trackParms->position(); - int sid1=(*it).detID; - int sid2=-1; - Amg::Vector3D hitPos; - Amg::Vector3D hitPos2; - - std::vector<Trk::HitInfo>::iterator itnext = it; - ++itnext; - if(itnext!=hitVector->end()) { - hitPos2 = (*itnext).trackParms->position(); - sid2=(*itnext).detID; - double eta_avg=0.5*(hitPos1.eta()+hitPos2.eta()); - double t; - if(isCaloBarrel(sample)) { - double r=rmid(sample,eta_avg); - double r1=hitPos1.perp(); - double r2=hitPos2.perp(); - t=(r-r1)/(r2-r1); - best_target=r; - } else { - double z=zmid(sample,eta_avg); - double z1=hitPos1[Amg::z]; - double z2=hitPos2[Amg::z]; - t=(z-z1)/(z2-z1); - best_target=z; - } - hitPos=t*hitPos2+(1-t)*hitPos1; - } else { - hitPos=hitPos1; - hitPos2=hitPos1; - } - double etaCalo = hitPos.eta(); - double phiCalo = hitPos.phi(); - m_letaCalo[sample]=etaCalo; - m_lphiCalo[sample]=phiCalo; - hitdist=hitPos.mag(); - m_layerCaloOK[sample]=true; - rzmiddle=rzmid((CaloCell_ID_FCS::CaloSample)sample,etaCalo); - distsamp=deta((CaloCell_ID_FCS::CaloSample)sample,etaCalo); - best_found=true; - ATH_MSG_DEBUG(" extrapol with layer hit: id="<<sid1<<" -> "<<sid2<< - " target r/z="<<best_target<< - " r1="<<hitPos1.perp()<<" z1="<<hitPos1[Amg::z]<<" r2="<<hitPos2.perp()<<" z2="<<hitPos2[Amg::z]<< - " re="<<hitPos.perp()<<" ze="<<hitPos[Amg::z] - ); - } + Amg::Vector3D hitPos1 = (*it).trackParms->position(); + int sid1=(*it).detID; + int sid2=-1; + Amg::Vector3D hitPos; + Amg::Vector3D hitPos2; + + std::vector<Trk::HitInfo>::iterator itnext = it; + ++itnext; + if(itnext!=hitVector->end()) { + hitPos2 = (*itnext).trackParms->position(); + sid2=(*itnext).detID; + double eta_avg=0.5*(hitPos1.eta()+hitPos2.eta()); + double t; + if(isCaloBarrel(sample)) { + double r=rmid(sample,eta_avg); + double r1=hitPos1.perp(); + double r2=hitPos2.perp(); + t=(r-r1)/(r2-r1); + best_target=r; + } else { + double z=zmid(sample,eta_avg); + double z1=hitPos1[Amg::z]; + double z2=hitPos2[Amg::z]; + t=(z-z1)/(z2-z1); + best_target=z; + } + hitPos=t*hitPos2+(1-t)*hitPos1; + } else { + hitPos=hitPos1; + hitPos2=hitPos1; + } + double etaCalo = hitPos.eta(); + double phiCalo = hitPos.phi(); + m_letaCalo[sample]=etaCalo; + m_lphiCalo[sample]=phiCalo; + hitdist=hitPos.mag(); + m_layerCaloOK[sample]=true; + rzmiddle=rzmid((CaloCell_ID_FCS::CaloSample)sample,etaCalo); + distsamp=deta((CaloCell_ID_FCS::CaloSample)sample,etaCalo); + best_found=true; + ATH_MSG_DEBUG(" extrapol with layer hit: id="<<sid1<<" -> "<<sid2<< + " target r/z="<<best_target<< + " r1="<<hitPos1.perp()<<" z1="<<hitPos1[Amg::z]<<" r2="<<hitPos2.perp()<<" z2="<<hitPos2[Amg::z]<< + " re="<<hitPos.perp()<<" ze="<<hitPos[Amg::z] + ); + } if(!best_found) { - it = hitVector->begin(); - double best_dist=0.5; - bool best_inside=false; - int best_id1,best_id2; - Amg::Vector3D best_hitPos=(*it).trackParms->position(); - while (it < hitVector->end()-1 ) { - Amg::Vector3D hitPos1 = (*it).trackParms->position(); - int sid1=(*it).detID; - it++; - Amg::Vector3D hitPos2 = (*it).trackParms->position(); - int sid2=(*it).detID; - double eta_avg=0.5*(hitPos1.eta()+hitPos2.eta()); - double t; - double tmp_target=0; - if(isCaloBarrel(sample)) { - double r=rmid(sample,eta_avg); - double r1=hitPos1.perp(); - double r2=hitPos2.perp(); - t=(r-r1)/(r2-r1); - tmp_target=r; - } else { - double z=zmid(sample,eta_avg); - double z1=hitPos1[Amg::z]; - double z2=hitPos2[Amg::z]; - t=(z-z1)/(z2-z1); - tmp_target=z; - } - Amg::Vector3D hitPos=t*hitPos2+(1-t)*hitPos1; - double dist=TMath::Min(TMath::Abs(t-0),TMath::Abs(t-1)); - bool inside=false; - if(t>=0 && t<=1) inside=true; - if(!best_found || inside) { - if(!best_inside || dist<best_dist) { - best_dist=dist; - best_hitPos=hitPos; - best_inside=inside; - best_found=true; - best_id1=sid1; - best_id2=sid2; - best_target=tmp_target; - } - } else { - if(!best_inside && dist<best_dist) { - best_dist=dist; - best_hitPos=hitPos; - best_inside=inside; - best_found=true; - best_id1=sid1; - best_id2=sid2; - best_target=tmp_target; - } - } - ATH_MSG_VERBOSE(" extrapol without layer hit: id="<<sid1<<" -> "<<sid2<<" dist="<<dist<<" mindist="<<best_dist<< - " t="<<t<<" best_inside="<<best_inside<<" target r/z="<<tmp_target<< - " r1="<<hitPos1.perp()<<" z1="<<hitPos1[Amg::z]<<" r2="<<hitPos2.perp()<<" z2="<<hitPos2[Amg::z]<< - " re="<<hitPos.perp()<<" ze="<<hitPos[Amg::z]<< - " rb="<<best_hitPos.perp()<<" zb="<<best_hitPos[Amg::z] - ); - if(best_found) { - m_letaCalo[sample]=best_hitPos.eta(); - m_lphiCalo[sample]=best_hitPos.phi(); - hitdist=best_hitPos.mag(); - rzmiddle=rzmid((CaloCell_ID_FCS::CaloSample)sample,m_letaCalo[sample]); - distsamp=deta((CaloCell_ID_FCS::CaloSample)sample,m_letaCalo[sample]); - m_layerCaloOK[sample]=true; - } - } - if(best_found) { - ATH_MSG_DEBUG(" extrapol without layer hit: id="<<best_id1<<" -> "<<best_id2<<" mindist="<<best_dist<< - " best_inside="<<best_inside<<" target r/z="<<best_target<< - " rb="<<best_hitPos.perp()<<" zb="<<best_hitPos[Amg::z] - ); - } + it = hitVector->begin(); + double best_dist=0.5; + bool best_inside=false; + int best_id1,best_id2; + Amg::Vector3D best_hitPos=(*it).trackParms->position(); + while (it < hitVector->end()-1 ) { + Amg::Vector3D hitPos1 = (*it).trackParms->position(); + int sid1=(*it).detID; + it++; + Amg::Vector3D hitPos2 = (*it).trackParms->position(); + int sid2=(*it).detID; + double eta_avg=0.5*(hitPos1.eta()+hitPos2.eta()); + double t; + double tmp_target=0; + if(isCaloBarrel(sample)) { + double r=rmid(sample,eta_avg); + double r1=hitPos1.perp(); + double r2=hitPos2.perp(); + t=(r-r1)/(r2-r1); + tmp_target=r; + } else { + double z=zmid(sample,eta_avg); + double z1=hitPos1[Amg::z]; + double z2=hitPos2[Amg::z]; + t=(z-z1)/(z2-z1); + tmp_target=z; + } + Amg::Vector3D hitPos=t*hitPos2+(1-t)*hitPos1; + double dist=TMath::Min(TMath::Abs(t-0),TMath::Abs(t-1)); + bool inside=false; + if(t>=0 && t<=1) inside=true; + if(!best_found || inside) { + if(!best_inside || dist<best_dist) { + best_dist=dist; + best_hitPos=hitPos; + best_inside=inside; + best_found=true; + best_id1=sid1; + best_id2=sid2; + best_target=tmp_target; + } + } else { + if(!best_inside && dist<best_dist) { + best_dist=dist; + best_hitPos=hitPos; + best_inside=inside; + best_found=true; + best_id1=sid1; + best_id2=sid2; + best_target=tmp_target; + } + } + ATH_MSG_VERBOSE(" extrapol without layer hit: id="<<sid1<<" -> "<<sid2<<" dist="<<dist<<" mindist="<<best_dist<< + " t="<<t<<" best_inside="<<best_inside<<" target r/z="<<tmp_target<< + " r1="<<hitPos1.perp()<<" z1="<<hitPos1[Amg::z]<<" r2="<<hitPos2.perp()<<" z2="<<hitPos2[Amg::z]<< + " re="<<hitPos.perp()<<" ze="<<hitPos[Amg::z]<< + " rb="<<best_hitPos.perp()<<" zb="<<best_hitPos[Amg::z] + ); + if(best_found) { + m_letaCalo[sample]=best_hitPos.eta(); + m_lphiCalo[sample]=best_hitPos.phi(); + hitdist=best_hitPos.mag(); + rzmiddle=rzmid((CaloCell_ID_FCS::CaloSample)sample,m_letaCalo[sample]); + distsamp=deta((CaloCell_ID_FCS::CaloSample)sample,m_letaCalo[sample]); + m_layerCaloOK[sample]=true; + } + } + if(best_found) { + ATH_MSG_DEBUG(" extrapol without layer hit: id="<<best_id1<<" -> "<<best_id2<<" mindist="<<best_dist<< + " best_inside="<<best_inside<<" target r/z="<<best_target<< + " rb="<<best_hitPos.perp()<<" zb="<<best_hitPos[Amg::z] + ); + } } - + if(isCaloBarrel((CaloCell_ID_FCS::CaloSample)sample)) rzmiddle*=cosh(m_letaCalo[sample]); - else rzmiddle= fabs(rzmiddle/tanh(m_letaCalo[sample])); + else rzmiddle= fabs(rzmiddle/tanh(m_letaCalo[sample])); m_dCalo[sample]=rzmiddle; m_distetaCaloBorder[sample]=distsamp; if(msgLvl(MSG::DEBUG)) { - msg(MSG::DEBUG)<<" Final par TTC sample "<<(int)sample; - if(m_layerCaloOK[sample]) msg()<<" (good)"; - else msg()<<" (bad)"; - msg()<<" eta=" << m_letaCalo[sample] << " phi=" << m_lphiCalo[sample] <<" m_dCalo="<<m_dCalo[sample]<<" dist(hit)="<<hitdist<< endmsg; - } - + msg(MSG::DEBUG)<<" Final par TTC sample "<<(int)sample; + if(m_layerCaloOK[sample]) msg()<<" (good)"; + else msg()<<" (bad)"; + msg()<<" eta=" << m_letaCalo[sample] << " phi=" << m_lphiCalo[sample] <<" m_dCalo="<<m_dCalo[sample]<<" dist(hit)="<<hitdist<< endmsg; + } + return m_layerCaloOK[sample]; - } +} */ //UPDATED @@ -1835,10 +1847,10 @@ bool ISF_HitAnalysis::get_calo_surface(std::vector<Trk::HitInfo>* hitVector) for(unsigned int i=0;i<m_surfacelist.size();++i) { CaloCell_ID_FCS::CaloSample sample=m_surfacelist[i]; std::vector<Trk::HitInfo>::iterator it = hitVector->begin(); - while (it != hitVector->end() && it->detID != (3000+sample) ) { it++;} + while (it != hitVector->end() && it->detID != (3000+sample) ) { it++;} if(it==hitVector->end()) continue; Amg::Vector3D hitPos = (*it).trackParms->position(); - + //double offset = 0.; double etaCalo = hitPos.eta(); @@ -1863,7 +1875,7 @@ bool ISF_HitAnalysis::get_calo_surface(std::vector<Trk::HitInfo>* hitVector) if(distsamp<0) { msg(MSG::DEBUG)<<endmsg; break; - } + } } msg(MSG::DEBUG)<<endmsg; } else { @@ -1874,7 +1886,7 @@ bool ISF_HitAnalysis::get_calo_surface(std::vector<Trk::HitInfo>* hitVector) if(m_sample_calo_surf==CaloCell_ID_FCS::noSample) { // first intersection with sensitive calo layer std::vector<Trk::HitInfo>::iterator it = hitVector->begin(); - while ( it < hitVector->end() && (*it).detID != 3 ) { it++;} // to be updated + while ( it < hitVector->end() && (*it).detID != 3 ) { it++;} // to be updated if (it==hitVector->end()) { // no calo intersection, abort return false; } @@ -1882,17 +1894,17 @@ bool ISF_HitAnalysis::get_calo_surface(std::vector<Trk::HitInfo>* hitVector) m_eta_calo_surf=surface_hitPos.eta(); m_phi_calo_surf=surface_hitPos.phi(); m_d_calo_surf=surface_hitPos.mag(); - + double pT=(*it).trackParms->momentum().perp(); if(TMath::Abs(m_eta_calo_surf)>4.9 || pT<500 || (TMath::Abs(m_eta_calo_surf)>4 && pT<1000) ) { ATH_MSG_DEBUG("only entrance to calo entrance layer found, no surface : eta="<<m_eta_calo_surf<<" phi="<<m_phi_calo_surf<<" d="<<m_d_calo_surf<<" pT="<<pT); - } else { + } else { ATH_MSG_WARNING("only entrance to calo entrance layer found, no surface : eta="<<m_eta_calo_surf<<" phi="<<m_phi_calo_surf<<" d="<<m_d_calo_surf<<" pT="<<pT); - } + } } else { ATH_MSG_DEBUG("entrance to calo surface : sample="<<m_sample_calo_surf<<" eta="<<m_eta_calo_surf<<" phi="<<m_phi_calo_surf<<" deta="<<min_calo_surf_dist<<" dsurf="<<m_d_calo_surf); } - + ATH_MSG_DEBUG("End get_calo_surface()"); return true; } @@ -1909,17 +1921,17 @@ double ISF_HitAnalysis::deta(int sample,double eta) const return GetCaloGeometry()->deta(sample,eta); } -void ISF_HitAnalysis::minmaxeta(int sample,double eta,double& mineta,double& maxeta) const +void ISF_HitAnalysis::minmaxeta(int sample,double eta,double& mineta,double& maxeta) const { GetCaloGeometry()->minmaxeta(sample,eta,mineta,maxeta); } -double ISF_HitAnalysis::rmid(int sample,double eta) const +double ISF_HitAnalysis::rmid(int sample,double eta) const { return GetCaloGeometry()->rmid(sample,eta); } -double ISF_HitAnalysis::zmid(int sample,double eta) const +double ISF_HitAnalysis::zmid(int sample,double eta) const { return GetCaloGeometry()->zmid(sample,eta); } @@ -1929,12 +1941,12 @@ double ISF_HitAnalysis::rzmid(int sample,double eta) const return GetCaloGeometry()->rzmid(sample,eta); } -double ISF_HitAnalysis::rent(int sample,double eta) const +double ISF_HitAnalysis::rent(int sample,double eta) const { return GetCaloGeometry()->rent(sample,eta); } -double ISF_HitAnalysis::zent(int sample,double eta) const +double ISF_HitAnalysis::zent(int sample,double eta) const { return GetCaloGeometry()->zent(sample,eta); } @@ -1944,12 +1956,12 @@ double ISF_HitAnalysis::rzent(int sample,double eta) const return GetCaloGeometry()->rzent(sample,eta); } -double ISF_HitAnalysis::rext(int sample,double eta) const +double ISF_HitAnalysis::rext(int sample,double eta) const { return GetCaloGeometry()->rext(sample,eta); } -double ISF_HitAnalysis::zext(int sample,double eta) const +double ISF_HitAnalysis::zext(int sample,double eta) const { return GetCaloGeometry()->zext(sample,eta); } @@ -1973,3 +1985,4 @@ double ISF_HitAnalysis::rzpos(int sample,double eta,int subpos) const { return GetCaloGeometry()->rzpos(sample,eta,subpos); } + diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/CaloHitAna.C b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/CaloHitAna.C index a53545656957..e9ef4a9a8745 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/CaloHitAna.C +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/CaloHitAna.C @@ -13,655 +13,806 @@ #include "TSystem.h" const int CaloHitAna::MAX_LAYER =25; //number of calorimeter layers/samplings, use last (MAX_LAYER-1) for invalid cells/hits +using namespace std; + void CaloHitAna::Loop() { - //This Loop is supposed to read the output ntuple/tree - //(vector of cells, vector of G4 hits, vector of FCS detailed hits, ...) - //from the athena ISF_HitAnalysis algorithm (==ESD dumper) - //and match them together + save structured output - - //NB: E = Ehit * SamplingFraction for Tile or E = Ehit / SamplingFraction (LAr) conversion - //is done here - - //Create output structure - m_Output = TFile::Open(m_OutputName, "RECREATE"); - m_OutputTree = new TTree("FCS_ParametrizationInput","Output_Matched_cell_Tree"); - - FCS_matchedcellvector oneeventcells; //these are all matched cells in a single event - FCS_matchedcellvector layercells[MAX_LAYER]; //these are all matched cells in a given layer in a given event - - std::vector<FCS_truth> truthcollection; - - Float_t total_cell_e = 0.0; - Float_t total_hit_e = 0.0; - Float_t total_g4hit_e = 0.0; - - std::vector<Float_t> cell_energy; - std::vector<Float_t> hit_energy; - std::vector<Float_t> g4hit_energy; - - //Store energies (not fractions in each layer 0-23 (BPS-FCAL2), 24 = INVALID, 25 = TOTAL - cell_energy.resize(MAX_LAYER+1); - hit_energy.resize(MAX_LAYER+1); - g4hit_energy.resize(MAX_LAYER+1); - - for (int i =0 ; i<MAX_LAYER+1; i++) - { - cell_energy[i] = 0.0; - hit_energy[i] = 0.0; - g4hit_energy[i] = 0.0; - } - - std::vector<Float_t> truthE, truthPx,truthPy,truthPz; - std::vector<int> truthBarcode, truthPDG, truthVtxBarcode; - m_OutputTree->Branch("TruthE",&truthE); - m_OutputTree->Branch("TruthPx",&truthPx); - m_OutputTree->Branch("TruthPy",&truthPy); - m_OutputTree->Branch("TruthPz",&truthPz); - m_OutputTree->Branch("TruthPDG",&truthPDG); - m_OutputTree->Branch("TruthBarcode",&truthBarcode); - m_OutputTree->Branch("TruthVtxBarcode",&truthVtxBarcode); //this is duplicate of what is in the truth collection, will be good to remove/hide at some point - m_OutputTree->Branch("TruthCollection", &truthcollection); //vector of truth particles with track extrapolation variables + + //This Loop is supposed to read the output ntuple/tree + //(vector of cells, vector of G4 hits, vector of FCS detailed hits, ...) + //from the athena ISF_HitAnalysis algorithm (==ESD dumper) + //and match them together + save structured output + //NB: E = Ehit * SamplingFraction for Tile or E = Ehit / SamplingFraction (LAr) conversion + //is done here + + //Create output structure - //create branches in the output tree according to the settings vector - if (! m_Settings.size() || m_Settings[0]==1) - { - //Write all FCS_matchedcells - m_OutputTree->Branch("AllCells", &oneeventcells); - } - if (m_Settings.size()>=2 && m_Settings[1]==1) - { - //write cells per layer - for (Int_t i=0; i<MAX_LAYER; i++) + m_Output = new TFile(m_OutputName, "RECREATE"); + m_OutputTree = new TTree("FCS_ParametrizationInput","Output_Matched_cell_Tree"); + + FCS_matchedcellvector oneeventcells; //these are all matched cells in a single event + FCS_matchedcellvector layercells[MAX_LAYER]; //these are all matched cells in a given layer in a given event + + std::vector<FCS_truth> truthcollection; + + Float_t total_cell_e = 0.0; + Float_t total_hit_e = 0.0; + Float_t total_g4hit_e = 0.0; + + std::vector<Float_t> cell_energy; + std::vector<Float_t> hit_energy; + std::vector<Float_t> g4hit_energy; + + //Store energies (not fractions in each layer 0-23 (BPS-FCAL2), 24 = INVALID, 25 = TOTAL + cell_energy.resize(MAX_LAYER+1); + hit_energy.resize(MAX_LAYER+1); + g4hit_energy.resize(MAX_LAYER+1); + + for (int i =0 ; i<MAX_LAYER+1; i++) + { + cell_energy[i] = 0.0; + hit_energy[i] = 0.0; + g4hit_energy[i] = 0.0; + } + + std::vector<Float_t> truthE, truthPx,truthPy,truthPz; + std::vector<int> truthBarcode, truthPDG, truthVtxBarcode; + /* + std::vector<std::vector<double> >* m_TTC_entrance_eta=0; + std::vector<std::vector<double> >* m_TTC_entrance_phi=0; + std::vector<std::vector<double> >* m_TTC_entrance_r=0; + std::vector<std::vector<double> >* m_TTC_entrance_z=0; + std::vector<std::vector<double> >* m_TTC_back_eta=0; + std::vector<std::vector<double> >* m_TTC_back_phi=0; + std::vector<std::vector<double> >* m_TTC_back_r=0; + std::vector<std::vector<double> >* m_TTC_back_z=0; + std::vector<double>* m_TTC_IDCaloBoundary_eta=0; + std::vector<double>* m_TTC_IDCaloBoundary_phi=0; + std::vector<double>* m_TTC_IDCaloBoundary_r=0; + std::vector<double>* m_TTC_IDCaloBoundary_z=0; + std::vector<double>* m_TTC_Angle3D=0; + std::vector<double>* m_TTC_AngleEta=0; + */ + std::vector<std::vector<double> >* m_newTTC_entrance_eta=0; + std::vector<std::vector<double> >* m_newTTC_entrance_phi=0; + std::vector<std::vector<double> >* m_newTTC_entrance_r=0; + std::vector<std::vector<double> >* m_newTTC_entrance_z=0; + std::vector<std::vector<double> >* m_newTTC_back_eta=0; + std::vector<std::vector<double> >* m_newTTC_back_phi=0; + std::vector<std::vector<double> >* m_newTTC_back_r=0; + std::vector<std::vector<double> >* m_newTTC_back_z=0; + std::vector<double>* m_newTTC_IDCaloBoundary_eta=0; + std::vector<double>* m_newTTC_IDCaloBoundary_phi=0; + std::vector<double>* m_newTTC_IDCaloBoundary_r=0; + std::vector<double>* m_newTTC_IDCaloBoundary_z=0; + std::vector<double>* m_newTTC_Angle3D=0; + std::vector<double>* m_newTTC_AngleEta=0; + + m_OutputTree->Branch("TruthE",&truthE); + m_OutputTree->Branch("TruthPx",&truthPx); + m_OutputTree->Branch("TruthPy",&truthPy); + m_OutputTree->Branch("TruthPz",&truthPz); + m_OutputTree->Branch("TruthPDG",&truthPDG); + m_OutputTree->Branch("TruthBarcode",&truthBarcode); + m_OutputTree->Branch("TruthVtxBarcode",&truthVtxBarcode); //this is duplicate of what is in the truth collection, will be good to remove/hide at some point + + //ADDING THE EXTRAPOLATOR vARIABLES + + /* + m_OutputTree->Branch("TTC_back_eta",&m_TTC_back_eta); + m_OutputTree->Branch("TTC_back_phi",&m_TTC_back_phi); + m_OutputTree->Branch("TTC_back_r", &m_TTC_back_r); + m_OutputTree->Branch("TTC_back_z", &m_TTC_back_z); + m_OutputTree->Branch("TTC_entrance_eta",&m_TTC_entrance_eta); + m_OutputTree->Branch("TTC_entrance_phi",&m_TTC_entrance_phi); + m_OutputTree->Branch("TTC_entrance_r", &m_TTC_entrance_r); + m_OutputTree->Branch("TTC_entrance_z", &m_TTC_entrance_z); + m_OutputTree->Branch("TTC_IDCaloBoundary_eta",&m_TTC_IDCaloBoundary_eta); + m_OutputTree->Branch("TTC_IDCaloBoundary_phi",&m_TTC_IDCaloBoundary_phi); + m_OutputTree->Branch("TTC_IDCaloBoundary_r",&m_TTC_IDCaloBoundary_r); + m_OutputTree->Branch("TTC_IDCaloBoundary_z",&m_TTC_IDCaloBoundary_z); + m_OutputTree->Branch("TTC_Angle3D", &m_TTC_Angle3D); + m_OutputTree->Branch("TTC_AngleEta",&m_TTC_AngleEta); + */ + + m_OutputTree->Branch("newTTC_back_eta",&m_newTTC_back_eta); + m_OutputTree->Branch("newTTC_back_phi",&m_newTTC_back_phi); + m_OutputTree->Branch("newTTC_back_r", &m_newTTC_back_r); + m_OutputTree->Branch("newTTC_back_z", &m_newTTC_back_z); + m_OutputTree->Branch("newTTC_entrance_eta",&m_newTTC_entrance_eta); + m_OutputTree->Branch("newTTC_entrance_phi",&m_newTTC_entrance_phi); + m_OutputTree->Branch("newTTC_entrance_r", &m_newTTC_entrance_r); + m_OutputTree->Branch("newTTC_entrance_z", &m_newTTC_entrance_z); + m_OutputTree->Branch("newTTC_IDCaloBoundary_eta",&m_newTTC_IDCaloBoundary_eta); + m_OutputTree->Branch("newTTC_IDCaloBoundary_phi",&m_newTTC_IDCaloBoundary_phi); + m_OutputTree->Branch("newTTC_IDCaloBoundary_r",&m_newTTC_IDCaloBoundary_r); + m_OutputTree->Branch("newTTC_IDCaloBoundary_z",&m_newTTC_IDCaloBoundary_z); + m_OutputTree->Branch("newTTC_Angle3D", &m_newTTC_Angle3D); + m_OutputTree->Branch("newTTC_AngleEta",&m_newTTC_AngleEta); + + cout<<"check2"<<endl; + + //m_OutputTree->Branch("TruthCollection", &truthcollection); //vector of truth particles with track extrapolation variables + + //create branches in the output tree according to the settings vector + if(! m_Settings.size() || m_Settings[0]==1) + { + //Write all FCS_matchedcells + m_OutputTree->Branch("AllCells", &oneeventcells); + } + if (m_Settings.size()>=2 && m_Settings[1]==1) + { + //write cells per layer + for (Int_t i=0; i<MAX_LAYER; i++) + { + TString branchname="Sampling_"; + branchname+=i; + m_OutputTree->Branch(branchname, &layercells[i]); + } + } + + if (m_Settings.size()>=3 && m_Settings[2]==1) + { + //write also energies per layer: + m_OutputTree->Branch("cell_energy", &cell_energy); + m_OutputTree->Branch("hit_energy", &hit_energy); + m_OutputTree->Branch("g4hit_energy",&g4hit_energy); + + //This is a duplicate of cell_energy[25] + m_OutputTree->Branch("total_cell_energy", &total_cell_e); + m_OutputTree->Branch("total_hit_energy", &total_hit_e); + m_OutputTree->Branch("total_g4hit_energy", &total_g4hit_e); + } + + if(fChain == 0) return; + ProcInfo_t procinfo; + Long64_t nentries = fChain->GetEntriesFast(); + m_all_cells.resize(nentries); + if(m_max_nentries>=0 && m_max_nentries<nentries) nentries=m_max_nentries; + + std::map<Long64_t, FCS_cell> cells; //read all objects and collect them by identifier (Long64_t) + std::map<Long64_t, std::vector<FCS_g4hit> > g4hits; + std::map<Long64_t, std::vector<FCS_hit> > hits; + + FCS_cell one_cell; //note that this is not extra safe if I don't have a clear method! + FCS_g4hit one_g4hit; + FCS_hit one_hit; + FCS_matchedcell one_matchedcell; + FCS_truth one_truth; + + //From here: Loop over events: + Long64_t nbytes = 0, nb = 0; + for(Long64_t jentry=0; jentry<nentries;jentry++) + { + + if(jentry%100==0) cout<<"jentry "<<jentry<<endl; + + Long64_t ientry = LoadTree(jentry); + if (ientry < 0) break; + nb = fChain->GetEntry(jentry); nbytes += nb; + if (jentry % m_PrintOutFrequency == 0) + { + std::cout <<"Processing entry "<<jentry<<std::endl; + gSystem->GetProcInfo(&procinfo); + std::cout <<"Memory usage: "<<procinfo.fMemResident<<" "<<procinfo.fMemVirtual<<std::endl; + } + + //Copy truth + truthE.clear(); + truthPx.clear(); + truthPy.clear(); + truthPz.clear(); + truthPDG.clear(); + truthBarcode.clear(); + truthVtxBarcode.clear(); + truthcollection.clear(); + + for(unsigned int truth_i = 0; truth_i < TruthE->size(); truth_i++) + { + //std::cout <<truth_i<<" "<<(*TruthPDG)[truth_i]<<std::endl; + //std::cout <<"TTC2: "<<(*TTC_entrance_eta)[truth_i].size()<<std::endl;//this one has 24 layers ->ok + truthE.push_back( (*TruthE)[truth_i]); + truthPx.push_back((*TruthPx)[truth_i]); + truthPy.push_back((*TruthPy)[truth_i]); + truthPz.push_back((*TruthPz)[truth_i]); + truthPDG.push_back((*TruthPDG)[truth_i]); + truthBarcode.push_back((*TruthBarcode)[truth_i]); + truthVtxBarcode.push_back((*TruthVtxBarcode)[truth_i]); + + /* + m_TTC_IDCaloBoundary_eta->push_back(TTC_IDCaloBoundary_eta->at(truth_i)); + m_TTC_IDCaloBoundary_phi->push_back(TTC_IDCaloBoundary_phi->at(truth_i)); + m_TTC_IDCaloBoundary_r ->push_back(TTC_IDCaloBoundary_r->at(truth_i)); + m_TTC_IDCaloBoundary_z ->push_back(TTC_IDCaloBoundary_z->at(truth_i)); + m_TTC_Angle3D ->push_back(TTC_Angle3D->at(truth_i)); + m_TTC_AngleEta ->push_back(TTC_AngleEta->at(truth_i)); + */ + + m_newTTC_IDCaloBoundary_eta->push_back(newTTC_IDCaloBoundary_eta->at(truth_i)); + m_newTTC_IDCaloBoundary_phi->push_back(newTTC_IDCaloBoundary_phi->at(truth_i)); + m_newTTC_IDCaloBoundary_r ->push_back(newTTC_IDCaloBoundary_r->at(truth_i)); + m_newTTC_IDCaloBoundary_z ->push_back(newTTC_IDCaloBoundary_z->at(truth_i)); + m_newTTC_Angle3D ->push_back(newTTC_Angle3D->at(truth_i)); + m_newTTC_AngleEta ->push_back(newTTC_AngleEta->at(truth_i)); + + /* + vector<double> entrance_eta; + vector<double> entrance_phi; + vector<double> entrance_r; + vector<double> entrance_z; + vector<double> back_eta; + vector<double> back_phi; + vector<double> back_r; + vector<double> back_z; + */ + + vector<double> new_entrance_eta; + vector<double> new_entrance_phi; + vector<double> new_entrance_r; + vector<double> new_entrance_z; + vector<double> new_back_eta; + vector<double> new_back_phi; + vector<double> new_back_r; + vector<double> new_back_z; + for(unsigned int s=0;s<24;s++) { - TString branchname="Sampling_"; - branchname+=i; - m_OutputTree->Branch(branchname, &layercells[i]); + /* + entrance_eta.push_back((TTC_entrance_eta->at(truth_i))[s]); + entrance_phi.push_back((TTC_entrance_phi->at(truth_i))[s]); + entrance_r .push_back((TTC_entrance_r->at(truth_i))[s]); + entrance_z .push_back((TTC_entrance_z->at(truth_i))[s]); + back_eta .push_back((TTC_back_eta->at(truth_i))[s]); + back_phi .push_back((TTC_back_phi->at(truth_i))[s]); + back_r .push_back((TTC_back_r->at(truth_i))[s]); + back_z .push_back((TTC_back_z->at(truth_i))[s]); + */ + new_entrance_eta.push_back((newTTC_entrance_eta->at(truth_i))[s]); + new_entrance_phi.push_back((newTTC_entrance_phi->at(truth_i))[s]); + new_entrance_r .push_back((newTTC_entrance_r->at(truth_i))[s]); + new_entrance_z .push_back((newTTC_entrance_z->at(truth_i))[s]); + new_back_eta .push_back((newTTC_back_eta->at(truth_i))[s]); + new_back_phi .push_back((newTTC_back_phi->at(truth_i))[s]); + new_back_r .push_back((newTTC_back_r->at(truth_i))[s]); + new_back_z .push_back((newTTC_back_z->at(truth_i))[s]); } - } + /* + m_TTC_entrance_eta->push_back(entrance_eta); + m_TTC_entrance_phi->push_back(entrance_phi); + m_TTC_entrance_r ->push_back(entrance_r); + m_TTC_entrance_z ->push_back(entrance_z); + m_TTC_back_eta ->push_back(back_eta); + m_TTC_back_phi ->push_back(back_phi); + m_TTC_back_r ->push_back(back_r); + m_TTC_back_z ->push_back(back_z); + */ + m_newTTC_entrance_eta->push_back(new_entrance_eta); + m_newTTC_entrance_phi->push_back(new_entrance_phi); + m_newTTC_entrance_r ->push_back(new_entrance_r); + m_newTTC_entrance_z ->push_back(new_entrance_z); + m_newTTC_back_eta ->push_back(new_back_eta); + m_newTTC_back_phi ->push_back(new_back_phi); + m_newTTC_back_r ->push_back(new_back_r); + m_newTTC_back_z ->push_back(new_back_z); - if (m_Settings.size()>=3 && m_Settings[2]==1) - { - //write also energies per layer: - m_OutputTree->Branch("cell_energy", &cell_energy); - m_OutputTree->Branch("hit_energy", &hit_energy); - m_OutputTree->Branch("g4hit_energy",&g4hit_energy); - - //This is a duplicate of cell_energy[25] - m_OutputTree->Branch("total_cell_energy", &total_cell_e); - m_OutputTree->Branch("total_hit_energy", &total_hit_e); - m_OutputTree->Branch("total_g4hit_energy", &total_g4hit_e); - } - - if (fChain == 0) return; - ProcInfo_t procinfo; - Long64_t nentries = fChain->GetEntriesFast(); - m_all_cells.resize(nentries); - if(m_max_nentries>=0 && m_max_nentries<nentries) nentries=m_max_nentries; - - std::map<Long64_t, FCS_cell> cells; //read all objects and collect them by identifier (Long64_t) - std::map<Long64_t, std::vector<FCS_g4hit> > g4hits; - std::map<Long64_t, std::vector<FCS_hit> > hits; - - FCS_cell one_cell; //note that this is not extra safe if I don't have a clear method! - FCS_g4hit one_g4hit; - FCS_hit one_hit; - FCS_matchedcell one_matchedcell; - FCS_truth one_truth; - - - //From here: Loop over events: - Long64_t nbytes = 0, nb = 0; - for (Long64_t jentry=0; jentry<nentries;jentry++) - { - Long64_t ientry = LoadTree(jentry); - if (ientry < 0) break; - nb = fChain->GetEntry(jentry); nbytes += nb; - if (jentry % m_PrintOutFrequency == 0) + /* + one_truth.SetPxPyPzE((*TruthPx)[truth_i], (*TruthPy)[truth_i], (*TruthPz)[truth_i], (*TruthE)[truth_i]); + */ + + one_truth.pdgid = (*TruthPDG)[truth_i]; + one_truth.barcode = (*TruthBarcode)[truth_i]; + one_truth.vtxbarcode = (*TruthVtxBarcode)[truth_i]; + truthcollection.push_back(one_truth); + + } + + //Now matching between cells, G4hits and G4detailed hits + //sort cells by identifier: + //clear first the containers for this event: + cells.clear(); + g4hits.clear(); + hits.clear(); + + //std::cout <<"Check Original size: Cells: "<<CellIdentifier->size()<<" G4Hits: "<<G4HitCellIdentifier->size()<<" FCSHits: "<<HitCellIdentifier->size()<<std::endl; + if(m_Debug > 1) std::cout <<"Reading cells..."; + + for (unsigned int cell_i = 0; cell_i <CellIdentifier->size(); cell_i++) + { + if (cells.find((*CellIdentifier)[cell_i]) == cells.end()) //doesn't exist { - std::cout <<"Processing entry "<<jentry<<std::endl; - gSystem->GetProcInfo(&procinfo); - std::cout <<"Memory usage: "<<procinfo.fMemResident<<" "<<procinfo.fMemVirtual<<std::endl; + //FCS_cell one_cell; + one_cell.cell_identifier = (*CellIdentifier)[cell_i]; + one_cell.sampling = (*CellSampling)[cell_i]; + one_cell.energy = (*CellE)[cell_i]; + one_cell.center_x = 0.0; //for now + one_cell.center_y = 0.0; + one_cell.center_z = 0.0; + cells.insert(std::pair<Long64_t, FCS_cell>(one_cell.cell_identifier, one_cell)); } - - //Copy truth - truthE.clear(); - truthPx.clear(); - truthPy.clear(); - truthPz.clear(); - truthPDG.clear(); - truthBarcode.clear(); - truthVtxBarcode.clear(); - truthcollection.clear(); - for (unsigned int truth_i = 0; truth_i < TruthE->size(); truth_i++) + else { - //std::cout <<truth_i<<" "<<(*TruthPDG)[truth_i]<<std::endl; - //std::cout <<"TTC2: "<<(*TTC_entrance_eta)[truth_i].size()<<std::endl;//this one has 24 layers ->ok - truthE.push_back( (*TruthE)[truth_i]); - truthPx.push_back((*TruthPx)[truth_i]); - truthPy.push_back((*TruthPy)[truth_i]); - truthPz.push_back((*TruthPz)[truth_i]); - truthPDG.push_back((*TruthPDG)[truth_i]); - truthBarcode.push_back((*TruthBarcode)[truth_i]); - truthVtxBarcode.push_back((*TruthVtxBarcode)[truth_i]); - - one_truth.SetPxPyPzE((*TruthPx)[truth_i], (*TruthPy)[truth_i], (*TruthPz)[truth_i], (*TruthE)[truth_i]); - one_truth.TTC_entrance_eta = (*TTC_entrance_eta)[truth_i]; - one_truth.TTC_entrance_phi = (*TTC_entrance_phi)[truth_i]; - one_truth.TTC_entrance_r = (*TTC_entrance_r)[truth_i]; - one_truth.TTC_entrance_z = (*TTC_entrance_z)[truth_i]; - one_truth.TTC_back_eta = (*TTC_back_eta)[truth_i]; - one_truth.TTC_back_phi = (*TTC_back_phi)[truth_i]; - one_truth.TTC_back_r = (*TTC_back_r)[truth_i]; - one_truth.TTC_back_z = (*TTC_back_z)[truth_i]; - - one_truth.TTC_IDCaloBoundary_eta = (*TTC_IDCaloBoundary_eta)[truth_i]; - one_truth.TTC_IDCaloBoundary_phi = (*TTC_IDCaloBoundary_phi)[truth_i]; - one_truth.TTC_IDCaloBoundary_r = (*TTC_IDCaloBoundary_r)[truth_i]; - one_truth.TTC_IDCaloBoundary_z = (*TTC_IDCaloBoundary_z)[truth_i]; - one_truth.TTC_Angle3D = (*TTC_Angle3D)[truth_i]; - one_truth.TTC_AngleEta = (*TTC_AngleEta)[truth_i]; - - one_truth.pdgid = (*TruthPDG)[truth_i]; - one_truth.barcode = (*TruthBarcode)[truth_i]; - one_truth.vtxbarcode = (*TruthVtxBarcode)[truth_i]; - truthcollection.push_back(one_truth); + //there shouldn't be a cell with the same identifier in this event + std::cout <<"ISF_HitAnalysis: Same cell???? ERROR"<<std::endl; } - - - //Now matching between cells, G4hits and G4detailed hits - //sort cells by identifier: - //clear first the containers for this event: - cells.clear(); - g4hits.clear(); - hits.clear(); - - //std::cout <<"Check Original size: Cells: "<<CellIdentifier->size()<<" G4Hits: "<<G4HitCellIdentifier->size()<<" FCSHits: "<<HitCellIdentifier->size()<<std::endl; - if (m_Debug > 1) std::cout <<"Reading cells..."; - for (unsigned int cell_i = 0; cell_i <CellIdentifier->size(); cell_i++) + } + + if(m_Debug > 1) std::cout <<" Done"<<std::endl; + + if (m_Debug > 1) std::cout <<"Reading G4hits"; + + for (unsigned int g4hit_i = 0; g4hit_i <G4HitIdentifier->size(); g4hit_i++) + { + if ((*G4HitSampling)[g4hit_i] >=0 && (*G4HitSampling)[g4hit_i]<=25 && (*G4HitT)[g4hit_i]>m_TimingCut) { - if (cells.find((*CellIdentifier)[cell_i]) == cells.end()) //doesn't exist - { - //FCS_cell one_cell; - one_cell.cell_identifier = (*CellIdentifier)[cell_i]; - one_cell.sampling = (*CellSampling)[cell_i]; - one_cell.energy = (*CellE)[cell_i]; - one_cell.center_x = 0.0; //for now - one_cell.center_y = 0.0; - one_cell.center_z = 0.0; - cells.insert(std::pair<Long64_t, FCS_cell>(one_cell.cell_identifier, one_cell)); - } - else - { - //there shouldn't be a cell with the same identifier in this event - std::cout <<"ISF_HitAnalysis: Same cell???? ERROR"<<std::endl; - } + if (m_Debug > 1) std::cout <<"Ignoring G4hit, time too large: "<<g4hit_i<<" time: "<<(*G4HitT)[g4hit_i]<<std::endl; + continue; } - if (m_Debug > 1) std::cout <<" Done"<<std::endl; - - if (m_Debug > 1) std::cout <<"Reading G4hits"; - for (unsigned int g4hit_i = 0; g4hit_i <G4HitIdentifier->size(); g4hit_i++) + + if (g4hits.find((*G4HitCellIdentifier)[g4hit_i]) == g4hits.end()) { - if ((*G4HitSampling)[g4hit_i] >=0 && (*G4HitSampling)[g4hit_i]<=25 && (*G4HitT)[g4hit_i]>m_TimingCut) - { - if (m_Debug > 1) std::cout <<"Ignoring G4hit, time too large: "<<g4hit_i<<" time: "<<(*G4HitT)[g4hit_i]<<std::endl; - continue; - } - - if (g4hits.find((*G4HitCellIdentifier)[g4hit_i]) == g4hits.end()) - { - //this G4 hit doesn't exist yet - //FCS_g4hit one_g4hit; - one_g4hit.identifier = (*G4HitIdentifier)[g4hit_i]; - one_g4hit.cell_identifier = (*G4HitCellIdentifier)[g4hit_i]; - one_g4hit.sampling = (*G4HitSampling)[g4hit_i]; - one_g4hit.hit_time = (*G4HitT)[g4hit_i]; - //one_g4hit.hit_energy = (*G4HitE)[g4hit_i]; - //scale the hit energy with the sampling fraction - if (one_g4hit.sampling >=12 && one_g4hit.sampling <=20) - {//tile - //std::cout <<"Tile: "<<(*G4HitE)[g4hit_i]<<" "<<(*G4HitSamplingFraction)[g4hit_i]<<std::endl; - if ((*G4HitSamplingFraction)[g4hit_i]) - { - one_g4hit.hit_energy = (*G4HitE)[g4hit_i]*(*G4HitSamplingFraction)[g4hit_i]; - //std::cout <<"TileE: "<<one_g4hit.hit_energy<<std::endl; - } - else one_g4hit.hit_energy = 0.; - } - else + //this G4 hit doesn't exist yet + //FCS_g4hit one_g4hit; + one_g4hit.identifier = (*G4HitIdentifier)[g4hit_i]; + one_g4hit.cell_identifier = (*G4HitCellIdentifier)[g4hit_i]; + one_g4hit.sampling = (*G4HitSampling)[g4hit_i]; + one_g4hit.hit_time = (*G4HitT)[g4hit_i]; + //one_g4hit.hit_energy = (*G4HitE)[g4hit_i]; + //scale the hit energy with the sampling fraction + if (one_g4hit.sampling >=12 && one_g4hit.sampling <=20) + {//tile + //std::cout <<"Tile: "<<(*G4HitE)[g4hit_i]<<" "<<(*G4HitSamplingFraction)[g4hit_i]<<std::endl; + if((*G4HitSamplingFraction)[g4hit_i]) { - //std::cout <<"LAr: "<<(*G4HitE)[g4hit_i]<<" "<<(*G4HitSamplingFraction)[g4hit_i]<<std::endl; - one_g4hit.hit_energy = (*G4HitE)[g4hit_i]/(*G4HitSamplingFraction)[g4hit_i]; - } - //one_g4hit.hit_sampfrac = (*G4HitSamplingFraction)[g4hit_i]; - //new g4hit -> insert vector with 1 element - g4hits.insert(std::pair<Long64_t, std::vector<FCS_g4hit> >(one_g4hit.cell_identifier, std::vector<FCS_g4hit>(1,one_g4hit))); - } - else - { - //G4 hit exists in this identifier -> push_back new to the vector //FCS_g4hit one_g4hit; - one_g4hit.identifier = (*G4HitIdentifier)[g4hit_i]; - one_g4hit.cell_identifier = (*G4HitCellIdentifier)[g4hit_i]; - one_g4hit.sampling = (*G4HitSampling)[g4hit_i]; - one_g4hit.hit_time = (*G4HitT)[g4hit_i]; - if (one_g4hit.sampling >=12 && one_g4hit.sampling <=20) - {//tile - //std::cout <<"Tile2: "<<(*G4HitE)[g4hit_i]<<" "<<(*G4HitSamplingFraction)[g4hit_i]<<std::endl; - - if ((*G4HitSamplingFraction)[g4hit_i]) - { - one_g4hit.hit_energy = (*G4HitE)[g4hit_i]*(*G4HitSamplingFraction)[g4hit_i]; - //std::cout <<"TileE2: "<<one_g4hit.hit_energy<<std::endl; - - } - else one_g4hit.hit_energy = 0.; - } - else + one_g4hit.hit_energy = (*G4HitE)[g4hit_i]*(*G4HitSamplingFraction)[g4hit_i]; + //std::cout <<"TileE: "<<one_g4hit.hit_energy<<std::endl; + } + else one_g4hit.hit_energy = 0.; + } + else + { + //std::cout <<"LAr: "<<(*G4HitE)[g4hit_i]<<" "<<(*G4HitSamplingFraction)[g4hit_i]<<std::endl; + one_g4hit.hit_energy = (*G4HitE)[g4hit_i]/(*G4HitSamplingFraction)[g4hit_i]; + } + //one_g4hit.hit_sampfrac = (*G4HitSamplingFraction)[g4hit_i]; + //new g4hit -> insert vector with 1 element + g4hits.insert(std::pair<Long64_t, std::vector<FCS_g4hit> >(one_g4hit.cell_identifier, std::vector<FCS_g4hit>(1,one_g4hit))); + } + else + { + //G4 hit exists in this identifier -> push_back new to the vector //FCS_g4hit one_g4hit; + one_g4hit.identifier = (*G4HitIdentifier)[g4hit_i]; + one_g4hit.cell_identifier = (*G4HitCellIdentifier)[g4hit_i]; + one_g4hit.sampling = (*G4HitSampling)[g4hit_i]; + one_g4hit.hit_time = (*G4HitT)[g4hit_i]; + if (one_g4hit.sampling >=12 && one_g4hit.sampling <=20) + {//tile + //std::cout <<"Tile2: "<<(*G4HitE)[g4hit_i]<<" "<<(*G4HitSamplingFraction)[g4hit_i]<<std::endl; + if((*G4HitSamplingFraction)[g4hit_i]) { - //std::cout <<"LAr2: "<<(*G4HitE)[g4hit_i]<<" "<<(*G4HitSamplingFraction)[g4hit_i]<<std::endl; - one_g4hit.hit_energy = (*G4HitE)[g4hit_i]/(*G4HitSamplingFraction)[g4hit_i]; - } - //one_g4hit.hit_sampfrac = (*G4HitSamplingFraction)[g4hit_i]; - g4hits[(*G4HitCellIdentifier)[g4hit_i]].push_back(one_g4hit); - } + one_g4hit.hit_energy = (*G4HitE)[g4hit_i]*(*G4HitSamplingFraction)[g4hit_i]; + //std::cout <<"TileE2: "<<one_g4hit.hit_energy<<std::endl; + } + else one_g4hit.hit_energy = 0.; + } + else + { + //std::cout <<"LAr2: "<<(*G4HitE)[g4hit_i]<<" "<<(*G4HitSamplingFraction)[g4hit_i]<<std::endl; + one_g4hit.hit_energy = (*G4HitE)[g4hit_i]/(*G4HitSamplingFraction)[g4hit_i]; + } + //one_g4hit.hit_sampfrac = (*G4HitSamplingFraction)[g4hit_i]; + g4hits[(*G4HitCellIdentifier)[g4hit_i]].push_back(one_g4hit); + } + } + + if (m_Debug > 1) std::cout <<" Done"<<std::endl; + + if (m_Debug > 1) std::cout <<"Reading detailed FCS hits "<< HitIdentifier->size()<<std::endl; + + for (unsigned int hit_i = 0; hit_i < HitIdentifier->size(); hit_i++) + { + if((*HitSampling)[hit_i] >=0 && (*HitSampling)[hit_i]<=25 && (*HitT)[hit_i]>m_TimingCut) + { + if (m_Debug > 1) + std::cout <<"Ignoring FCS hit, time too large: "<<hit_i<<" time: "<<(*HitT)[hit_i]<<std::endl; + continue; } - if (m_Debug > 1) std::cout <<" Done"<<std::endl; - - if (m_Debug > 1) std::cout <<"Reading detailed FCS hits "<< HitIdentifier->size()<<std::endl; - for (unsigned int hit_i = 0; hit_i < HitIdentifier->size(); hit_i++) + if(hits.find((*HitCellIdentifier)[hit_i]) == hits.end()) { - if ((*HitSampling)[hit_i] >=0 && (*HitSampling)[hit_i]<=25 && (*HitT)[hit_i]>m_TimingCut) - { - if (m_Debug > 1) std::cout <<"Ignoring FCS hit, time too large: "<<hit_i<<" time: "<<(*HitT)[hit_i]<<std::endl; - continue; - } - if (hits.find((*HitCellIdentifier)[hit_i]) == hits.end()) - { - //Detailed hit doesn't exist yet - //FCS_hit one_hit; - one_hit.identifier = (*HitIdentifier)[hit_i]; - one_hit.cell_identifier = (*HitCellIdentifier)[hit_i]; - one_hit.sampling = (*HitSampling)[hit_i]; - if (one_hit.sampling >=12 && one_hit.sampling <=20) - {//tile - if ((*HitSamplingFraction)[hit_i]) - { - one_hit.hit_energy = (*HitE)[hit_i]*(*HitSamplingFraction)[hit_i]; - } - else one_hit.hit_energy = 0.; - } - else + //Detailed hit doesn't exist yet + //FCS_hit one_hit; + one_hit.identifier = (*HitIdentifier)[hit_i]; + one_hit.cell_identifier = (*HitCellIdentifier)[hit_i]; + one_hit.sampling = (*HitSampling)[hit_i]; + + if (one_hit.sampling >=12 && one_hit.sampling <=20) + {//tile + if((*HitSamplingFraction)[hit_i]) { - one_hit.hit_energy = (*HitE)[hit_i]/(*HitSamplingFraction)[hit_i]; - } - //one_hit.hit_sampfrac = (*HitSamplingFraction)[hit_i]; - one_hit.hit_time = (*HitT)[hit_i]; - one_hit.hit_x = (*HitX)[hit_i]; - one_hit.hit_y = (*HitY)[hit_i]; - one_hit.hit_z = (*HitZ)[hit_i]; - hits.insert(std::pair<Long64_t, std::vector<FCS_hit> >(one_hit.cell_identifier, std::vector<FCS_hit>(1,one_hit))); - } + one_hit.hit_energy = (*HitE)[hit_i]*(*HitSamplingFraction)[hit_i]; + } else - { - //Detailed hit exists in this identifier -> push_back new to the vector - //FCS_hit one_hit; - one_hit.identifier = (*HitIdentifier)[hit_i]; - one_hit.cell_identifier = (*HitCellIdentifier)[hit_i]; - one_hit.sampling = (*HitSampling)[hit_i]; - //one_hit.hit_energy = (*HitE)[hit_i]; - if (one_hit.sampling >=12 && one_hit.sampling <=20) - {//tile - if ((*HitSamplingFraction)[hit_i]) - { - one_hit.hit_energy = (*HitE)[hit_i]*(*HitSamplingFraction)[hit_i]; - } - else one_hit.hit_energy = 0.; - } - else + one_hit.hit_energy = 0.; + } + else + { + one_hit.hit_energy = (*HitE)[hit_i]/(*HitSamplingFraction)[hit_i]; + } + //one_hit.hit_sampfrac = (*HitSamplingFraction)[hit_i]; + one_hit.hit_time = (*HitT)[hit_i]; + one_hit.hit_x = (*HitX)[hit_i]; + one_hit.hit_y = (*HitY)[hit_i]; + one_hit.hit_z = (*HitZ)[hit_i]; + hits.insert(std::pair<Long64_t, std::vector<FCS_hit> >(one_hit.cell_identifier, std::vector<FCS_hit>(1,one_hit))); + } + else + { + //Detailed hit exists in this identifier -> push_back new to the vector + //FCS_hit one_hit; + one_hit.identifier = (*HitIdentifier)[hit_i]; + one_hit.cell_identifier = (*HitCellIdentifier)[hit_i]; + one_hit.sampling = (*HitSampling)[hit_i]; + //one_hit.hit_energy = (*HitE)[hit_i]; + if (one_hit.sampling >=12 && one_hit.sampling <=20) + {//tile + if ((*HitSamplingFraction)[hit_i]) { - one_hit.hit_energy = (*HitE)[hit_i]/(*HitSamplingFraction)[hit_i]; - } - //one_hit.hit_sampfrac = (*HitSamplingFraction)[hit_i]; - one_hit.hit_time = (*HitT)[hit_i]; - one_hit.hit_x = (*HitX)[hit_i]; - one_hit.hit_y = (*HitY)[hit_i]; - one_hit.hit_z = (*HitZ)[hit_i]; - hits[(*HitCellIdentifier)[hit_i]].push_back(one_hit); - } + one_hit.hit_energy = (*HitE)[hit_i]*(*HitSamplingFraction)[hit_i]; + } + else + one_hit.hit_energy = 0.; + } + else + { + one_hit.hit_energy = (*HitE)[hit_i]/(*HitSamplingFraction)[hit_i]; + } + //one_hit.hit_sampfrac = (*HitSamplingFraction)[hit_i]; + one_hit.hit_time = (*HitT)[hit_i]; + one_hit.hit_x = (*HitX)[hit_i]; + one_hit.hit_y = (*HitY)[hit_i]; + one_hit.hit_z = (*HitZ)[hit_i]; + hits[(*HitCellIdentifier)[hit_i]].push_back(one_hit); } - if (m_Debug > 1) std::cout <<" Done"<<std::endl; - - if (m_Debug > 1) std::cout <<"ISF_HitAnalysis Check: Cells: "<<cells.size()<<" G4hits: "<<g4hits.size()<<" FCS detailed hits: "<<hits.size()<<std::endl; - - //Start matching: - Int_t iindex = 0; - for (std::map<Long64_t, FCS_cell>::iterator it = cells.begin(); it!= cells.end(); ) + } + + if (m_Debug > 1) std::cout <<" Done"<<std::endl; + + if (m_Debug > 1) std::cout <<"ISF_HitAnalysis Check: Cells: "<<cells.size()<<" G4hits: "<<g4hits.size()<<" FCS detailed hits: "<<hits.size()<<std::endl; + + //Start matching: + Int_t iindex = 0; + for (std::map<Long64_t, FCS_cell>::iterator it = cells.begin(); it!= cells.end(); ) + { + iindex++; + //std::cout <<iindex<<std::endl; + //FCS_matchedcell one_matchedcell; + one_matchedcell.clear(); //maybe not completely necessery, as we're not pushing_back into vectors + //set the cell part + one_matchedcell.cell = it->second; + //now look for FCS detailed hits in this cell + std::map<Long64_t, std::vector<FCS_hit> >::iterator it2 = hits.find(it->first); + if (it2!=hits.end()) { - iindex++; - //std::cout <<iindex<<std::endl; - //FCS_matchedcell one_matchedcell; - one_matchedcell.clear(); //maybe not completely necessery, as we're not pushing_back into vectors - //set the cell part - one_matchedcell.cell = it->second; - //now look for FCS detailed hits in this cell - std::map<Long64_t, std::vector<FCS_hit> >::iterator it2 = hits.find(it->first); - if (it2!=hits.end()) - { - //std::cout <<"FCS hits found in this cell"<<std::endl; - one_matchedcell.hit = it2->second; - hits.erase(it2); //remove it - } - else - { - //no hit found for this cell - one_matchedcell.hit.clear(); //important! - } - //now look for G4hits in this cell - std::map<Long64_t, std::vector<FCS_g4hit> >::iterator it3 = g4hits.find(it->first); - if (it3 != g4hits.end()) - { - //std::cout <<"G4 hits found in this cell"<<std::endl; - one_matchedcell.g4hit = it3->second; - g4hits.erase(it3); - } - else - { - //no g4hit found for this cell - one_matchedcell.g4hit.clear();//important! - } - //std::cout <<"Erase cell"<<std::endl; - cells.erase(it++); - //std::cout <<"Insert matched object"<<std::endl; - //push_back matched cell for event jentry - m_all_cells[jentry].push_back(one_matchedcell); - //std::cout <<"Go next"<<std::endl; + //std::cout <<"FCS hits found in this cell"<<std::endl; + one_matchedcell.hit = it2->second; + hits.erase(it2); //remove it } - //ok, cells should be empty, what about hits and g4hits? - //There could be G4hits/FCS hits for which we don't have a cell ->create a dummy empty cell with 0 energy, take the cell identifier from the hit - if (m_Debug > 1) std::cout <<"ISF_HitAnalysis Check after cells: "<<cells.size()<<" "<<g4hits.size()<<" "<<hits.size()<<std::endl; - for (std::map<Long64_t, std::vector<FCS_hit> >::iterator it = hits.begin(); it!= hits.end();) + else { - //FCS_matchedcell one_matchedcell; - one_matchedcell.clear(); - one_matchedcell.cell.cell_identifier = it->first; - //std::cout <<"This hit didn't exist in cell: "<<it->first<<std::endl; - if (it->second.size()) - { - one_matchedcell.cell.sampling = (it->second)[0].sampling; - } - else - { - one_matchedcell.cell.sampling = -1; // - //ok, but you really shouldn't be here - std::cout <<"ERROR: You shouldn't really be here"<<std::endl; - } - one_matchedcell.cell.energy = 0.; - one_matchedcell.cell.center_x = 0.0; - one_matchedcell.cell.center_y = 0.0; - one_matchedcell.cell.center_z = 0.0; - one_matchedcell.hit = it->second; - std::map<Long64_t, std::vector<FCS_g4hit> >::iterator it3 = g4hits.find(it->first); - if (it3 != g4hits.end()) - { - one_matchedcell.g4hit = it3->second; - g4hits.erase(it3); - } - else - { - //no g4hit found for this cell - one_matchedcell.g4hit.clear(); //important! - } - hits.erase(it++); - m_all_cells[jentry].push_back(one_matchedcell); + //no hit found for this cell + one_matchedcell.hit.clear(); //important! } - - //ok, hits should be empty, what about g4hits? - if (m_Debug > 1 )std::cout <<"ISF_HitAnalysis Check after hits: "<<cells.size()<<" "<<g4hits.size()<<" "<<hits.size()<<std::endl; - for (std::map<Long64_t, std::vector<FCS_g4hit> >::iterator it = g4hits.begin(); it!= g4hits.end();) + //now look for G4hits in this cell + std::map<Long64_t, std::vector<FCS_g4hit> >::iterator it3 = g4hits.find(it->first); + if (it3 != g4hits.end()) { - //FCS_matchedcell one_matchedcell; - one_matchedcell.clear(); //maybe not so important - one_matchedcell.cell.cell_identifier = it->first; - if (it->second.size()) - { - one_matchedcell.cell.sampling = (it->second)[0].sampling; - } - else - { - one_matchedcell.cell.sampling = -1; // - //not really - std::cout <<"ERROR: You shouldn't really be here"<<std::endl; - } - one_matchedcell.cell.energy = 0.; - one_matchedcell.cell.center_x = 0.0; - one_matchedcell.cell.center_y = 0.0; - one_matchedcell.cell.center_z = 0.0; - one_matchedcell.g4hit = it->second; - one_matchedcell.hit.clear(); //important!! - g4hits.erase(it++); - m_all_cells[jentry].push_back(one_matchedcell); + //std::cout <<"G4 hits found in this cell"<<std::endl; + one_matchedcell.g4hit = it3->second; + g4hits.erase(it3); } - if (m_Debug > 1) std::cout <<"ISF_HitAnalysis Check after g4hits: "<<cells.size()<<" "<<g4hits.size()<<" "<<hits.size()<<std::endl; - //Final size for this event - if (m_Debug > 1) std::cout <<"ISF_HitAnalysis Matched cells size: "<<m_all_cells[jentry].size()<<std::endl; - - - //Can fill the output tree already here: - total_cell_e = 0.0; - total_hit_e = 0.0; - total_g4hit_e = 0.0; - - oneeventcells = m_all_cells[jentry]; //This gets cells for particular event jentry (m_all_cells holds now all cells from all events (huge!) - for (int j=0; j<MAX_LAYER-1; j++) + else { - layercells[j].m_vector = oneeventcells.GetLayer(j); + //no g4hit found for this cell + one_matchedcell.g4hit.clear();//important! } - //this is for invalid cells - layercells[MAX_LAYER-1].m_vector = oneeventcells.GetLayer(-1); - - for (int i=0; i<MAX_LAYER; i++) + //std::cout <<"Erase cell"<<std::endl; + cells.erase(it++); + //std::cout <<"Insert matched object"<<std::endl; + //push_back matched cell for event jentry + m_all_cells[jentry].push_back(one_matchedcell); + //std::cout <<"Go next"<<std::endl; + } + + //ok, cells should be empty, what about hits and g4hits? + //There could be G4hits/FCS hits for which we don't have a cell ->create a dummy empty cell with 0 energy, take the cell identifier from the hit + if (m_Debug > 1) std::cout <<"ISF_HitAnalysis Check after cells: "<<cells.size()<<" "<<g4hits.size()<<" "<<hits.size()<<std::endl; + + for (std::map<Long64_t, std::vector<FCS_hit> >::iterator it = hits.begin(); it!= hits.end();) + { + //FCS_matchedcell one_matchedcell; + one_matchedcell.clear(); + one_matchedcell.cell.cell_identifier = it->first; + //std::cout <<"This hit didn't exist in cell: "<<it->first<<std::endl; + if (it->second.size()) + { + one_matchedcell.cell.sampling = (it->second)[0].sampling; + } + else { - cell_energy[i] = 0.0; //zero for each event! - hit_energy[i] = 0.0; - g4hit_energy[i] = 0.0; - for (unsigned int cellindex = 0; cellindex < layercells[i].size(); cellindex++) - { - if (i!=MAX_LAYER-1) + one_matchedcell.cell.sampling = -1; // + //ok, but you really shouldn't be here + std::cout <<"ERROR: You shouldn't really be here"<<std::endl; + } + one_matchedcell.cell.energy = 0.; + one_matchedcell.cell.center_x = 0.0; + one_matchedcell.cell.center_y = 0.0; + one_matchedcell.cell.center_z = 0.0; + one_matchedcell.hit = it->second; + std::map<Long64_t, std::vector<FCS_g4hit> >::iterator it3 = g4hits.find(it->first); + if (it3 != g4hits.end()) + { + one_matchedcell.g4hit = it3->second; + g4hits.erase(it3); + } + else + { + //no g4hit found for this cell + one_matchedcell.g4hit.clear(); //important! + } + hits.erase(it++); + m_all_cells[jentry].push_back(one_matchedcell); + } + + //ok, hits should be empty, what about g4hits? + if (m_Debug > 1 )std::cout <<"ISF_HitAnalysis Check after hits: "<<cells.size()<<" "<<g4hits.size()<<" "<<hits.size()<<std::endl; + for (std::map<Long64_t, std::vector<FCS_g4hit> >::iterator it = g4hits.begin(); it!= g4hits.end();) + { + //FCS_matchedcell one_matchedcell; + one_matchedcell.clear(); //maybe not so important + one_matchedcell.cell.cell_identifier = it->first; + if (it->second.size()) + { + one_matchedcell.cell.sampling = (it->second)[0].sampling; + } + else + { + one_matchedcell.cell.sampling = -1; // + //not really + std::cout <<"ERROR: You shouldn't really be here"<<std::endl; + } + one_matchedcell.cell.energy = 0.; + one_matchedcell.cell.center_x = 0.0; + one_matchedcell.cell.center_y = 0.0; + one_matchedcell.cell.center_z = 0.0; + one_matchedcell.g4hit = it->second; + one_matchedcell.hit.clear(); //important!! + g4hits.erase(it++); + m_all_cells[jentry].push_back(one_matchedcell); + } + + if (m_Debug > 1) std::cout <<"ISF_HitAnalysis Check after g4hits: "<<cells.size()<<" "<<g4hits.size()<<" "<<hits.size()<<std::endl; + //Final size for this event + if (m_Debug > 1) std::cout <<"ISF_HitAnalysis Matched cells size: "<<m_all_cells[jentry].size()<<std::endl; + + //Can fill the output tree already here: + total_cell_e = 0.0; + total_hit_e = 0.0; + total_g4hit_e = 0.0; + + oneeventcells = m_all_cells[jentry]; //This gets cells for particular event jentry (m_all_cells holds now all cells from all events (huge!) + for (int j=0; j<MAX_LAYER-1; j++) + { + layercells[j].m_vector = oneeventcells.GetLayer(j); + } + + //this is for invalid cells + layercells[MAX_LAYER-1].m_vector = oneeventcells.GetLayer(-1); + + for (int i=0; i<MAX_LAYER; i++) + { + cell_energy[i] = 0.0; //zero for each event! + hit_energy[i] = 0.0; + g4hit_energy[i] = 0.0; + for (unsigned int cellindex = 0; cellindex < layercells[i].size(); cellindex++) + { + if (i!=MAX_LAYER-1) + { + cell_energy[i]+=layercells[i][cellindex].cell.energy; + total_cell_e+=layercells[i][cellindex].cell.energy; + } + else + { + //don't add the energy in the invalid layer to the total energy (if there is any (shouldn't) + cell_energy[i]+=layercells[i][cellindex].cell.energy; //this should be here anyway + } + + //sum energy of all FCS detailed hits in this layer/cell + for (unsigned int j=0; j<layercells[i][cellindex].hit.size(); j++) + { + if (i!=MAX_LAYER-1) { - cell_energy[i]+=layercells[i][cellindex].cell.energy; - total_cell_e+=layercells[i][cellindex].cell.energy; + total_hit_e+=layercells[i][cellindex].hit[j].hit_energy; + hit_energy[i]+=layercells[i][cellindex].hit[j].hit_energy; } - else + else { - //don't add the energy in the invalid layer to the total energy (if there is any (shouldn't) - cell_energy[i]+=layercells[i][cellindex].cell.energy; //this should be here anyway + //again, don't add invalid layer energy to the sum + hit_energy[i]+=layercells[i][cellindex].hit[j].hit_energy; } - //sum energy of all FCS detailed hits in this layer/cell - for (unsigned int j=0; j<layercells[i][cellindex].hit.size(); j++) + } + + //sum energy of all G4 hits in this layer/cell + for (unsigned int j=0; j<layercells[i][cellindex].g4hit.size(); j++) + { + if (i!=MAX_LAYER-1) { - if (i!=MAX_LAYER-1) - { - total_hit_e+=layercells[i][cellindex].hit[j].hit_energy; - hit_energy[i]+=layercells[i][cellindex].hit[j].hit_energy; - } - else - { - //again, don't add invalid layer energy to the sum - hit_energy[i]+=layercells[i][cellindex].hit[j].hit_energy; - } + total_g4hit_e+=layercells[i][cellindex].g4hit[j].hit_energy; + g4hit_energy[i]+=layercells[i][cellindex].g4hit[j].hit_energy; } - //sum energy of all G4 hits in this layer/cell - for (unsigned int j=0; j<layercells[i][cellindex].g4hit.size(); j++) + else { - if (i!=MAX_LAYER-1) - { - total_g4hit_e+=layercells[i][cellindex].g4hit[j].hit_energy; - g4hit_energy[i]+=layercells[i][cellindex].g4hit[j].hit_energy; - } - else - { - //don't add invalied layer energy to the sum - g4hit_energy[i]+=layercells[i][cellindex].g4hit[j].hit_energy; - } + //don't add invalied layer energy to the sum + g4hit_energy[i]+=layercells[i][cellindex].g4hit[j].hit_energy; } - } - } - cell_energy[MAX_LAYER] = total_cell_e; - hit_energy[MAX_LAYER] = total_hit_e; - g4hit_energy[MAX_LAYER] = total_g4hit_e; - - //Uncomment this to get energy cross check - if (jentry % m_PrintOutFrequency ==0) std::cout <<"Energy check: event: "<<jentry<<" cell: "<<total_cell_e<<" g4hits: "<<total_g4hit_e<<" hits: "<<total_hit_e<<std::endl; - //tree gets filled - m_OutputTree->Fill(); - - - + } + } + } + cell_energy[MAX_LAYER] = total_cell_e; + hit_energy[MAX_LAYER] = total_hit_e; + g4hit_energy[MAX_LAYER] = total_g4hit_e; - }//loop over entries - m_OutputTree->Write(); - m_Output->Close(); + //Uncomment this to get energy cross check + if (jentry % m_PrintOutFrequency ==0) std::cout <<"Energy check: event: "<<jentry<<" cell: "<<total_cell_e<<" g4hits: "<<total_g4hit_e<<" hits: "<<total_hit_e<<std::endl; + //tree gets filled + m_OutputTree->Fill(); + + }//loop over entries + + m_OutputTree->Write(); + m_Output->Close(); + }; void CaloHitAna::Finish(std::vector<Int_t> settings, TString outputname) { - //Not necessary to call now (it is done in Loop directly) - - //This writes out the tree out of m_all_cells vector - //settings vector specifies what branches are written out - //if settings[0]==1 -> write all cells for all events - //if settings[1]==1 -> write all cells for all layers(samplings) separately - //if settings[2]==1 -> write fractions of energies in all layers - - TFile *fout = TFile::Open(outputname,"RECREATE"); - TTree *tout = new TTree("FCS_ParametrizationInput","Output_Matched_cell_Tree"); - - FCS_matchedcellvector oneeventcells; //these are all matched cells in a single event - FCS_matchedcellvector layercells[MAX_LAYER]; //these are all matched cells in a given layer in a given event - - Float_t total_cell_e = 0.0; - Float_t total_hit_e = 0.0; - Float_t total_g4hit_e = 0.0; - - std::vector<Float_t> cell_energy; - std::vector<Float_t> hit_energy; - std::vector<Float_t> g4hit_energy; - - //Store energies (not fractions in each layer 0-23 (BPS-FCAL2), 24 = INVALID, 25 = TOTAL - cell_energy.resize(MAX_LAYER+1); - hit_energy.resize(MAX_LAYER+1); - g4hit_energy.resize(MAX_LAYER+1); - - for (int i =0 ; i<MAX_LAYER+1; i++) - { - cell_energy[i] = 0.0; - hit_energy[i] = 0.0; - g4hit_energy[i] = 0.0; - } - - - //create branches in the output tree according to the settings vector - if (settings[0]==1 || ! settings.size()) - { - //Write all FCS_matchedcells - tout->Branch("AllCells", &oneeventcells); - } - if (settings.size()>=2 && settings[1]==1) - { - //write cells per layer - for (Int_t i=0; i<MAX_LAYER; i++) - { - TString branchname="Sampling_"; - branchname+=i; - tout->Branch(branchname, &layercells[i]); - } - } - - if (settings.size()>=3 && settings[2]==1) - { - //write also energies per layer: - tout->Branch("cell_energy",&cell_energy); - tout->Branch("hit_energy",&hit_energy); - tout->Branch("g4hit_energy",&g4hit_energy); - - //This is a duplicate of cell_energy[25] - tout->Branch("total_cell_energy", &total_cell_e); - tout->Branch("total_hit_energy", &total_hit_e); - tout->Branch("total_g4hit_energy", &total_g4hit_e); - } - - //Loop over all events - for (unsigned int event=0; event<m_all_cells.size(); event++) - { - if (event % m_PrintOutFrequency == 0) - { - std::cout <<"Reprocessing: "<<event<<std::endl; - } - total_cell_e = 0.0; - total_hit_e = 0.0; - total_g4hit_e = 0.0; - oneeventcells = m_all_cells[event]; //This gets cells for particular event i (m_all_cells holds now all cells from all events (huge!) - for (int j=0; j<MAX_LAYER-1; j++) - { - layercells[j].m_vector = oneeventcells.GetLayer(j); - } - //this is for invalid cells - layercells[MAX_LAYER-1].m_vector = oneeventcells.GetLayer(-1); + //Not necessary to call now (it is done in Loop directly) + + //This writes out the tree out of m_all_cells vector + //settings vector specifies what branches are written out + //if settings[0]==1 -> write all cells for all events + //if settings[1]==1 -> write all cells for all layers(samplings) separately + //if settings[2]==1 -> write fractions of energies in all layers + + TFile *fout = TFile::Open(outputname,"RECREATE"); + TTree *tout = new TTree("FCS_ParametrizationInput_TEST","Output_Matched_cell_Tree"); + + FCS_matchedcellvector oneeventcells; //these are all matched cells in a single event + FCS_matchedcellvector layercells[MAX_LAYER]; //these are all matched cells in a given layer in a given event + + Float_t total_cell_e = 0.0; + Float_t total_hit_e = 0.0; + Float_t total_g4hit_e = 0.0; + + std::vector<Float_t> cell_energy; + std::vector<Float_t> hit_energy; + std::vector<Float_t> g4hit_energy; + + //Store energies (not fractions in each layer 0-23 (BPS-FCAL2), 24 = INVALID, 25 = TOTAL + cell_energy.resize(MAX_LAYER+1); + hit_energy.resize(MAX_LAYER+1); + g4hit_energy.resize(MAX_LAYER+1); + + for(int i =0 ; i<MAX_LAYER+1; i++) + { + cell_energy[i] = 0.0; + hit_energy[i] = 0.0; + g4hit_energy[i] = 0.0; + } + + //create branches in the output tree according to the settings vector + if(settings[0]==1 || ! settings.size()) + { + //Write all FCS_matchedcells + tout->Branch("AllCells", &oneeventcells); + } + if (settings.size()>=2 && settings[1]==1) + { + //write cells per layer + for (Int_t i=0; i<MAX_LAYER; i++) + { + TString branchname="Sampling_"; + branchname+=i; + tout->Branch(branchname, &layercells[i]); + } + } + + if(settings.size()>=3 && settings[2]==1) + { + //write also energies per layer: + tout->Branch("cell_energy",&cell_energy); + tout->Branch("hit_energy",&hit_energy); + tout->Branch("g4hit_energy",&g4hit_energy); + + //This is a duplicate of cell_energy[25] + tout->Branch("total_cell_energy", &total_cell_e); + tout->Branch("total_hit_energy", &total_hit_e); + tout->Branch("total_g4hit_energy", &total_g4hit_e); + } + + //Loop over all events + for(unsigned int event=0; event<m_all_cells.size(); event++) + { + + if (event % m_PrintOutFrequency == 0) + std::cout <<"Reprocessing: "<<event<<std::endl; + + total_cell_e = 0.0; + total_hit_e = 0.0; + total_g4hit_e = 0.0; + oneeventcells = m_all_cells[event]; //This gets cells for particular event i (m_all_cells holds now all cells from all events (huge!) + for (int j=0; j<MAX_LAYER-1; j++) + layercells[j].m_vector = oneeventcells.GetLayer(j); + + //this is for invalid cells + layercells[MAX_LAYER-1].m_vector = oneeventcells.GetLayer(-1); - for (int i=0; i<MAX_LAYER; i++) + for (int i=0; i<MAX_LAYER; i++) + { + cell_energy[i] = 0.0; //zero for each event! + hit_energy[i] = 0.0; + g4hit_energy[i] = 0.0; + for (unsigned int cellindex = 0; cellindex < layercells[i].size(); cellindex++) { - cell_energy[i] = 0.0; //zero for each event! - hit_energy[i] = 0.0; - g4hit_energy[i] = 0.0; - for (unsigned int cellindex = 0; cellindex < layercells[i].size(); cellindex++) - { - if (i!=MAX_LAYER-1) + if (i!=MAX_LAYER-1) + { + cell_energy[i]+=layercells[i][cellindex].cell.energy; + total_cell_e+=layercells[i][cellindex].cell.energy; + } + else + { + //don't add the energy in the invalid layer to the total energy (if there is any (shouldn't) + cell_energy[i]+=layercells[i][cellindex].cell.energy; //this should be here anyway + } + + //sum energy of all FCS detailed hits in this layer/cell + for (unsigned int j=0; j<layercells[i][cellindex].hit.size(); j++) + { + if (i!=MAX_LAYER-1) { - cell_energy[i]+=layercells[i][cellindex].cell.energy; - total_cell_e+=layercells[i][cellindex].cell.energy; - } - else + total_hit_e+=layercells[i][cellindex].hit[j].hit_energy; + hit_energy[i]+=layercells[i][cellindex].hit[j].hit_energy; + } + else { - //don't add the energy in the invalid layer to the total energy (if there is any (shouldn't) - cell_energy[i]+=layercells[i][cellindex].cell.energy; //this should be here anyway + //again, don't add invalid layer energy to the sum + hit_energy[i]+=layercells[i][cellindex].hit[j].hit_energy; } - //sum energy of all FCS detailed hits in this layer/cell - for (unsigned int j=0; j<layercells[i][cellindex].hit.size(); j++) + } + + //sum energy of all G4 hits in this layer/cell + for (unsigned int j=0; j<layercells[i][cellindex].g4hit.size(); j++) + { + if (i!=MAX_LAYER-1) { - if (i!=MAX_LAYER-1) - { - total_hit_e+=layercells[i][cellindex].hit[j].hit_energy; - hit_energy[i]+=layercells[i][cellindex].hit[j].hit_energy; - } - else - { - //again, don't add invalid layer energy to the sum - hit_energy[i]+=layercells[i][cellindex].hit[j].hit_energy; - } + total_g4hit_e+=layercells[i][cellindex].g4hit[j].hit_energy; + g4hit_energy[i]+=layercells[i][cellindex].g4hit[j].hit_energy; } - //sum energy of all G4 hits in this layer/cell - for (unsigned int j=0; j<layercells[i][cellindex].g4hit.size(); j++) + else { - if (i!=MAX_LAYER-1) - { - total_g4hit_e+=layercells[i][cellindex].g4hit[j].hit_energy; - g4hit_energy[i]+=layercells[i][cellindex].g4hit[j].hit_energy; - } - else - { - //don't add invalied layer energy to the sum - g4hit_energy[i]+=layercells[i][cellindex].g4hit[j].hit_energy; - } + //don't add invalied layer energy to the sum + g4hit_energy[i]+=layercells[i][cellindex].g4hit[j].hit_energy; } - } - } - //Uncomment this to get energy cross check - // std::cout <<"Energy check: event: "<<event<<" cell: "<<total_cell_e<<" g4hits: "<<total_g4hit_e<<" hits: "<<total_hit_e<<std::endl; - //tree gets filled - tout->Fill(); - } - //and written out - tout->Write(); - fout->Close(); + } + } + } + + //Uncomment this to get energy cross check + //std::cout <<"Energy check: event: "<<event<<" cell: "<<total_cell_e<<" g4hits: "<<total_g4hit_e<<" hits: "<<total_hit_e<<std::endl; + //tree gets filled + tout->Fill(); + + } + + //and written out + tout->Write(); + fout->Close(); } diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/CaloHitAna.h b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/CaloHitAna.h index cb073e2d82ad..ccd08872cdc7 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/CaloHitAna.h +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/CaloHitAna.h @@ -72,6 +72,7 @@ public : std::vector<Long64_t> *G4HitCellIdentifier; std::vector<float> *G4HitSamplingFraction; std::vector<int> *G4HitSampling; + /* std::vector<std::vector<double> > *TTC_back_eta; std::vector<std::vector<double> > *TTC_back_phi; std::vector<std::vector<double> > *TTC_back_r; @@ -86,6 +87,22 @@ public : std::vector<double> *TTC_IDCaloBoundary_z; std::vector<double> *TTC_Angle3D; std::vector<double> *TTC_AngleEta; + */ + std::vector<std::vector<double> >* newTTC_entrance_eta; + std::vector<std::vector<double> >* newTTC_entrance_phi; + std::vector<std::vector<double> >* newTTC_entrance_r; + std::vector<std::vector<double> >* newTTC_entrance_z; + std::vector<std::vector<double> >* newTTC_back_eta; + std::vector<std::vector<double> >* newTTC_back_phi; + std::vector<std::vector<double> >* newTTC_back_r; + std::vector<std::vector<double> >* newTTC_back_z; + std::vector<double>* newTTC_IDCaloBoundary_eta; + std::vector<double>* newTTC_IDCaloBoundary_phi; + std::vector<double>* newTTC_IDCaloBoundary_r; + std::vector<double>* newTTC_IDCaloBoundary_z; + std::vector<double>* newTTC_Angle3D; + std::vector<double>* newTTC_AngleEta; + //If this won't work, we will have to change it... (memory??) std::vector<FCS_matchedcellvector> m_all_cells; //hm, make it a vector of (vector of FCS_matchedcell) and have it for all 1000 events at once in memory?? @@ -120,6 +137,7 @@ public : TBranch *b_G4HitCellIdentifier; //! TBranch *b_G4HitSamplingFraction; //! TBranch *b_G4HitSampling; //! + /* TBranch *b_TTC_back_eta; //! TBranch *b_TTC_back_phi; //! TBranch *b_TTC_back_r; //! @@ -134,7 +152,24 @@ public : TBranch *b_TTC_IDCaloBoundary_z; //! TBranch *b_TTC_Angle3D; //! TBranch *b_TTC_AngleEta; //! - + */ + + TBranch *b_newTTC_back_eta; //! + TBranch *b_newTTC_back_phi; //! + TBranch *b_newTTC_back_r; //! + TBranch *b_newTTC_back_z; //! + TBranch *b_newTTC_entrance_eta; //! + TBranch *b_newTTC_entrance_phi; //! + TBranch *b_newTTC_entrance_r; //! + TBranch *b_newTTC_entrance_z; //! + TBranch *b_newTTC_IDCaloBoundary_eta; //! + TBranch *b_newTTC_IDCaloBoundary_phi; //! + TBranch *b_newTTC_IDCaloBoundary_r; //! + TBranch *b_newTTC_IDCaloBoundary_z; //! + TBranch *b_newTTC_Angle3D; //! + TBranch *b_newTTC_AngleEta; //! + + CaloHitAna(TString filename="ISF_HitAnalysispion_eta1.root", TString outputname="output1.root", std::vector<Int_t> settings=std::vector<Int_t>(), Float_t timingcut=999999., Int_t debug=0, TTree *tree=0); virtual ~CaloHitAna(); virtual Int_t Cut(Long64_t entry); @@ -248,6 +283,7 @@ void CaloHitAna::Init(TTree *tree) G4HitCellIdentifier = 0; G4HitSamplingFraction = 0; G4HitSampling = 0; + /* TTC_back_eta = 0; TTC_back_phi = 0; TTC_back_r = 0; @@ -262,7 +298,23 @@ void CaloHitAna::Init(TTree *tree) TTC_IDCaloBoundary_z = 0; TTC_Angle3D = 0; TTC_AngleEta = 0; - + */ + newTTC_back_eta = 0; + newTTC_back_phi = 0; + newTTC_back_r = 0; + newTTC_back_z = 0; + newTTC_entrance_eta = 0; + newTTC_entrance_phi = 0; + newTTC_entrance_r = 0; + newTTC_entrance_z = 0; + newTTC_IDCaloBoundary_eta = 0; + newTTC_IDCaloBoundary_phi = 0; + newTTC_IDCaloBoundary_r = 0; + newTTC_IDCaloBoundary_z = 0; + newTTC_Angle3D = 0; + newTTC_AngleEta = 0; + + // Set branch addresses and branch pointers if (!tree) return; fChain = tree; @@ -299,6 +351,7 @@ void CaloHitAna::Init(TTree *tree) fChain->SetBranchAddress("G4HitCellIdentifier", &G4HitCellIdentifier, &b_G4HitCellIdentifier); fChain->SetBranchAddress("G4HitSamplingFraction", &G4HitSamplingFraction, &b_G4HitSamplingFraction); fChain->SetBranchAddress("G4HitSampling", &G4HitSampling, &b_G4HitSampling); + /* fChain->SetBranchAddress("TTC_back_eta", &TTC_back_eta, &b_TTC_back_eta); fChain->SetBranchAddress("TTC_back_phi", &TTC_back_phi, &b_TTC_back_phi); fChain->SetBranchAddress("TTC_back_r", &TTC_back_r, &b_TTC_back_r); @@ -311,8 +364,24 @@ void CaloHitAna::Init(TTree *tree) fChain->SetBranchAddress("TTC_IDCaloBoundary_phi", &TTC_IDCaloBoundary_phi, &b_TTC_IDCaloBoundary_phi); fChain->SetBranchAddress("TTC_IDCaloBoundary_r", &TTC_IDCaloBoundary_r, &b_TTC_IDCaloBoundary_r); fChain->SetBranchAddress("TTC_IDCaloBoundary_z", &TTC_IDCaloBoundary_z, &b_TTC_IDCaloBoundary_z); - fChain->SetBranchAddress("TTC_Angle3D", &TTC_Angle3D, &b_TTC_Angle3D); - fChain->SetBranchAddress("TTC_AngleEta", &TTC_AngleEta, &b_TTC_AngleEta); + fChain->SetBranchAddress("TTC_Angle3D", &TTC_Angle3D, &b_TTC_Angle3D); + fChain->SetBranchAddress("TTC_AngleEta", &TTC_AngleEta, &b_TTC_AngleEta); + */ + fChain->SetBranchAddress("newTTC_back_eta", &newTTC_back_eta, &b_newTTC_back_eta); + fChain->SetBranchAddress("newTTC_back_phi", &newTTC_back_phi, &b_newTTC_back_phi); + fChain->SetBranchAddress("newTTC_back_r", &newTTC_back_r, &b_newTTC_back_r); + fChain->SetBranchAddress("newTTC_back_z", &newTTC_back_z, &b_newTTC_back_z); + fChain->SetBranchAddress("newTTC_entrance_eta", &newTTC_entrance_eta, &b_newTTC_entrance_eta); + fChain->SetBranchAddress("newTTC_entrance_phi", &newTTC_entrance_phi, &b_newTTC_entrance_phi); + fChain->SetBranchAddress("newTTC_entrance_r", &newTTC_entrance_r, &b_newTTC_entrance_r); + fChain->SetBranchAddress("newTTC_entrance_z", &newTTC_entrance_z, &b_newTTC_entrance_z); + fChain->SetBranchAddress("newTTC_IDCaloBoundary_eta", &newTTC_IDCaloBoundary_eta, &b_newTTC_IDCaloBoundary_eta); + fChain->SetBranchAddress("newTTC_IDCaloBoundary_phi", &newTTC_IDCaloBoundary_phi, &b_newTTC_IDCaloBoundary_phi); + fChain->SetBranchAddress("newTTC_IDCaloBoundary_r", &newTTC_IDCaloBoundary_r, &b_newTTC_IDCaloBoundary_r); + fChain->SetBranchAddress("newTTC_IDCaloBoundary_z", &newTTC_IDCaloBoundary_z, &b_newTTC_IDCaloBoundary_z); + fChain->SetBranchAddress("newTTC_Angle3D", &newTTC_Angle3D, &b_newTTC_Angle3D); + fChain->SetBranchAddress("newTTC_AngleEta", &newTTC_AngleEta, &b_newTTC_AngleEta); + Notify(); } diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/Makefile b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/Makefile index 3cc648f37490..c409a954cd88 100755 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/Makefile +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/Makefile @@ -1,248 +1,26 @@ -###################################################################### -# Project: TMVA - Toolkit for Multivariate Data Analysis # -# Code : Source # -###################################################################### +if [ -f FCS_CellDict.cxx ]; +then + rm FCS_CellDict.cxx + rm FCS_CellDict.h +fi +rootcint FCS_CellDict.cxx -c FCS_Cell.h Linkdef.h + +#compile +g++ -g -c run.C FCS_CellDict.cxx -I $(root-config --incdir) -I . -fPIC $CPPEXPFLAGS -std=c++11 + +#link executable +g++ -g -o CaloHitAna run.o FCS_CellDict.o -L $(root-config --libdir) -lGui -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lpthread -Wl,-rpath,$(root-config --libdir) -lm -ldl -fPIC $CPPEXPFLAGS -std=c++11 + +#this creates a shared library for ROOT (which can be loaded by hand) +g++ -shared -o FCS_Cell_h.so FCS_CellDict.o -L $(root-config --libdir) -lGui -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lpthread -Wl,-rpath,$(root-config --libdir) -lm -ldl -fPIC $CPPEXPFLAGS -std=c++11 + +#example +g++ -g -c CaloHitAna2.C -I $(root-config --incdir) -I . -fPIC $CPPEXPFLAGS -std=c++11 + +g++ -g -o CaloHitAna2 CaloHitAna2.o FCS_CellDict.o -L $(root-config --libdir) -lGui -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lpthread -Wl,-rpath,$(root-config --libdir) -lm -ldl -lstdc++ -fPIC $CPPEXPFLAGS -std=c++11 + +#another example +g++ -g -c CaloHitAna3.C FCS_CellDict.cxx -Wall -I $(root-config --incdir) -I . -fPIC $CPPEXPFLAGS -Wall -std=c++11 + +g++ -g -o CaloHitAna3 CaloHitAna3.o FCS_CellDict.o -L $(root-config --libdir) -lGui -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lpthread -Wl,-rpath,$(root-config --libdir) -lm -ldl -lstdc++ -fPIC $CPPEXPFLAGS -Wall -std=c++11 -SHELL=bash - -MAKEFLAGS = --no-print-directory -r -s --warn-undefined-variables --debug - -include Makefile.arch - -# Internal configuration -PACKAGE=TMVA -LD_LIBRARY_PATH := $(shell root-config --libdir):$(LD_LIBRARY_PATH) -OBJDIR = obj -DEPDIR = $(OBJDIR)/dep -LIBDIR = lib -VPATH = $(OBJDIR) -INCLUDES += -I./ - -DICTL1 := inc/LinkDef1.h -DICTL2 := inc/LinkDef2.h -DICTL3 := inc/LinkDef3.h -DICTL4 := inc/LinkDef4.h -DICTL := $(DICTL1) $(DICTL2) $(DICTL3) $(DICTL4) -DICTS1 := src/$(PACKAGE)_Dict1.C -DICTS2 := src/$(PACKAGE)_Dict2.C -DICTS3 := src/$(PACKAGE)_Dict3.C -DICTS4 := src/$(PACKAGE)_Dict4.C -DICTS := $(DICTS1) $(DICTS2) $(DICTS3) $(DICTS4) -DICTO1 := $(OBJDIR)/$(PACKAGE)_Dict1.o -DICTO2 := $(OBJDIR)/$(PACKAGE)_Dict2.o -DICTO3 := $(OBJDIR)/$(PACKAGE)_Dict3.o -DICTO4 := $(OBJDIR)/$(PACKAGE)_Dict4.o -DICTO := $(DICTO1) $(DICTO2) $(DICTO3) $(DICTO4) -DICTH1 := Configurable.h Event.h Factory.h MethodBase.h MethodCompositeBase.h \ - MethodANNBase.h MethodTMlpANN.h MethodRuleFit.h MethodCuts.h MethodFisher.h \ - MethodKNN.h MethodCFMlpANN.h MethodCFMlpANN_Utils.h MethodLikelihood.h \ - MethodHMatrix.h MethodPDERS.h MethodBDT.h MethodDT.h MethodSVM.h MethodBayesClassifier.h \ - MethodFDA.h MethodMLP.h MethodBoost.h \ - MethodPDEFoam.h MethodLD.h MethodCategory.h -DICTH2 := TSpline2.h TSpline1.h PDF.h BinaryTree.h BinarySearchTreeNode.h BinarySearchTree.h \ - Timer.h RootFinder.h CrossEntropy.h DecisionTree.h DecisionTreeNode.h MisClassificationError.h \ - Node.h SdivSqrtSplusB.h SeparationBase.h RegressionVariance.h Tools.h Reader.h \ - GeneticAlgorithm.h GeneticGenes.h GeneticPopulation.h GeneticRange.h GiniIndex.h \ - GiniIndexWithLaplace.h SimulatedAnnealing.h QuickMVAProbEstimator.h -DICTH3 := Config.h KDEKernel.h Interval.h LogInterval.h FitterBase.h MCFitter.h GeneticFitter.h \ - SimulatedAnnealingFitter.h MinuitFitter.h MinuitWrapper.h IFitterTarget.h \ - PDEFoam.h PDEFoamDecisionTree.h PDEFoamDensityBase.h PDEFoamDiscriminantDensity.h \ - PDEFoamEventDensity.h PDEFoamTargetDensity.h PDEFoamDecisionTreeDensity.h PDEFoamMultiTarget.h \ - PDEFoamVect.h PDEFoamCell.h PDEFoamDiscriminant.h PDEFoamEvent.h PDEFoamTarget.h \ - PDEFoamKernelBase.h PDEFoamKernelTrivial.h PDEFoamKernelLinN.h PDEFoamKernelGauss.h \ - BDTEventWrapper.h CCTreeWrapper.h \ - CCPruner.h CostComplexityPruneTool.h SVEvent.h OptimizeConfigParameters.h -DICTH4 := TNeuron.h TSynapse.h TActivationChooser.h TActivation.h TActivationSigmoid.h TActivationIdentity.h \ - TActivationTanh.h TActivationRadial.h TNeuronInputChooser.h TNeuronInput.h TNeuronInputSum.h \ - TNeuronInputSqSum.h TNeuronInputAbs.h Types.h Ranking.h RuleFit.h RuleFitAPI.h IMethod.h MsgLogger.h \ - VariableTransformBase.h VariableIdentityTransform.h VariableDecorrTransform.h VariablePCATransform.h \ - VariableGaussTransform.h VariableNormalizeTransform.h VariableRearrangeTransform.h -DICTH1 := $(patsubst %,inc/TMVA/%,$(DICTH1)) -DICTH2 := $(patsubst %,inc/TMVA/%,$(DICTH2)) -DICTH3 := $(patsubst %,inc/TMVA/%,$(DICTH3)) -DICTH4 := $(patsubst %,inc/TMVA/%,$(DICTH4)) -DICTH := $(DICTH1) $(DICTH2) $(DICTH3) $(DICTH4) - - -SKIPCPPLIST := -SKIPHLIST := $(DICTHEAD) $(DICTL) -LIBFILE := lib/lib$(PACKAGE).a -SHLIBFILE := lib$(PACKAGE).$(DllSuf) -DLLIBFILE := lib/lib$(PACKAGE).dll -ROOTMAP := lib/lib$(PACKAGE).rootmap -TESTDIR := test -UNAME = $(shell uname) - -default: shlib linklib - -# List of all source files to build -HLIST = $(filter-out $(SKIPHLIST),$(wildcard inc/TMVA/*.h)) -CPPLIST = $(filter-out $(SKIPCPPLIST),$(patsubst src/%,%,$(wildcard src/*.$(SrcSuf)))) - -# List of all object files to build -OLIST=$(patsubst %.cxx,%.o,$(CPPLIST)) -OLIST=$(CPPLIST:.$(SrcSuf)=.o) -DEPLIST=$(foreach var,$(CPPLIST:.$(SrcSuf)=.d),$(DEPDIR)/$(var)) - -# Implicit rule to compile all classes -sl: - if [[ ( ! -e TMVA ) ]]; then \ - ln -sf inc/TMVA TMVA; \ - fi - -$(OBJDIR)/%.o : src/%.cxx - if [[ ( ! -e TMVA ) ]]; then \ - ln -sf inc/TMVA TMVA; \ - fi - @printf "Compiling $< ... " - @mkdir -p $(OBJDIR) - @$(CXX) $(INCLUDES) $(CXXFLAGS) -ggdb -c $< -o $@ - @echo "Done" - -# Rule to make the dictionary -dict: sl $(DICTO1) $(DICTO2) $(DICTO3) $(DICTO4) - -$(DICTS1): $(DICTH1) $(DICTL1) - @echo "Generating dictionary $@" - $(shell root-config --exec-prefix)/bin/rootcint -f $@ -c -p $(INCLUDES) $^ - -$(DICTS2): $(DICTH2) $(DICTL2) - @echo "Generating dictionary $@" - $(shell root-config --exec-prefix)/bin/rootcint -f $@ -c -p $(INCLUDES) $^ - -$(DICTS3): $(DICTH3) $(DICTL3) - @echo "Generating dictionary $@" - $(shell root-config --exec-prefix)/bin/rootcint -f $@ -c -p $(INCLUDES) $^ - -$(DICTS4): $(DICTH4) $(DICTL4) - @echo "Generating dictionary $@" - $(shell root-config --exec-prefix)/bin/rootcint -f $@ -c -p $(INCLUDES) $^ - -$(DICTO1): $(DICTS1) - @echo "Compiling dictionary $<" - @mkdir -p $(OBJDIR) - @$(CXX) $(INCLUDES) $(CXXFLAGS) -g -c -o $@ $< - -$(DICTO2): $(DICTS2) - @echo "Compiling dictionary $<" - @mkdir -p $(OBJDIR) - @$(CXX) $(INCLUDES) $(CXXFLAGS) -g -c -o $@ $< - -$(DICTO3): $(DICTS3) - @echo "Compiling dictionary $<" - @mkdir -p $(OBJDIR) - @$(CXX) $(INCLUDES) $(CXXFLAGS) -g -c -o $@ $< - -$(DICTO4): $(DICTS4) - @echo "Compiling dictionary $<" - @mkdir -p $(OBJDIR) - @$(CXX) $(INCLUDES) $(CXXFLAGS) -g -c -o $@ $< - - - -# Rule to set up a symbolic links to the created shared library -linklib: - if [[ ( ( `root-config --platform` == "macosx" ) && \ - ( ! -e lib/lib$(PACKAGE).1.dylib ) ) || \ - ( ! -e lib/lib$(PACKAGE).1.so ) ]]; then \ - printf "Setting up soft links to the TMVA library ... "; \ - ln -sf $(SHLIBFILE) $(LIBDIR)/lib$(PACKAGE).1.so; \ - if [[ `root-config --platform` == "macosx" ]]; then \ - ln -sf $(SHLIBFILE) $(LIBDIR)/lib$(PACKAGE).1.dylib; \ - fi; \ - echo "Done"; \ - fi - -############################## -# The dependencies section -# - the purpose of the .d files is to keep track of the -# header file dependence -# - this can be achieved using the makedepend command -############################## -# .d tries to pre-process .cc -ifneq ($(MAKECMDGOALS),clean) --include $(DEPLIST) -endif - -$(DEPDIR)/%.d: src/%.$(SrcSuf) - @mkdir -p $(DEPDIR) - if [[ ( ! -e TMVA ) ]]; then \ - ln -sf inc/TMVA TMVA; \ - fi - if test -f $< ; then \ - printf "Building $(@F) ... "; \ - $(SHELL) -ec '`root-config --exec-prefix`/bin/rmkdepend -f- -Y -w 3000 -- -I./ -- $< 2> /dev/null 1| sed -e "s-src/\(.*\).o\(: .*\)-$(DEPDIR)\/\1.d $(OBJDIR)/\1.o\2-" > $@'; \ - rm -f $@.bak; \ - echo "Done"; \ - fi - -# Rule to combine objects into a library -$(LIBFILE): $(DICTO) $(OLIST) - @printf "Making static library $(LIBFILE) ... " - @rm -f $(LIBFILE) - @ar q $(LIBFILE) $(addprefix $(OBJDIR)/,$(OLIST) $(DICTO) - @ranlib $(LIBFILE) - @echo "Done" - -# Rule to combine objects into a unix shared library -$(LIBDIR)/$(SHLIBFILE): $(OLIST) $(DICTO) - @printf "Building shared library $(LIBDIR)/$(SHLIBFILE) ... " - @mkdir -p $(LIBDIR) - @rm -f $(LIBDIR)/$(SHLIBFILE) - @$(LD) -L$(shell root-config --libdir) $(SOFLAGS) $(addprefix $(OBJDIR)/,$(OLIST)) $(DICTO) -o $(LIBDIR)/$(SHLIBFILE) -lMinuit -lXMLIO -# ln -fs $(SHLIBFILE) lib/lib$(PACKAGE).1.so - @echo "Done" - -# Rule to combine objects into a unix shared library -$(ROOTMAP): $(DICTL) - @printf "Building $(ROOTMAP) ... " - @mkdir -p $(LIBDIR) - rlibmap -f -o $@ -l lib$(PACKAGE).1.$(DllSuf) -d libMinuit.so libMLP.so libMatrix.so libTree.so libGraf.so libTreePlayer.so libXMLIO.so -c $^ - @echo "Done" - -# Rule to combine objects into a windows shared library -$(DLLIBFILE): $(OLIST) $(DICTO) - @printf "Making dll file $(DLLIBFILE) ... " - @rm -f $(DLLIBFILE) - $(LD) -Wl,--export-all-symbols -Wl,--export-dynamic -Wl,--enable-auto-import -Wl,-Bdynamic -shared --enable-auto-image-base -Wl,-soname -o $(DLLIBFILE) -Wl,--whole-archive $(addprefix $(OBJDIR)/,$(OLIST) $(patsubst %.$(SrcSuf),%.o,$(DICTFILE))) -Wl,--no-whole-archive -L$(ROOTSYS)/lib -lCore -lCint -lHist -lGraf -lGraf3d -lTree -lRint -lPostscript -lMatrix -lMinuit -lPhysics -lHtml -lXMLIO -lm - @echo "Done" - -# Useful build targets -lib: $(LIBFILE) - -shlib: $(LIBDIR)/$(SHLIBFILE) $(ROOTMAP) - -winlib: $(DLLIBFILE) - -vars: - #echo $(patsubst src/%,%,$(wildcard src/*.$(SrcSuf))) - echo $(OLIST) $(DICTO) - -clean: - rm -rf obj - rm -rf lib - rm -f TMVA - rm -f $(DICTS) $(DICTS:.C=.h) - rm -f $(OBJDIR)/*.o - rm -f $(DEPDIR)/*.d - rm -f $(LIBFILE) - rm -f $(LIBDIR)/$(SHLIBFILE) - rm -f lib/lib$(PACKAGE).1.so - rm -f lib/lib$(PACKAGE).1.dylib - rm -f $(ROOTMAP) - rm -f $(DLLIBFILE) - -distclean: - rm -rf obj - rm -f *~ - rm -f $(DICTFILE) $(DICTHEAD) - rm -f $(LIBFILE) - rm -f $(LIBDIR)/$(SHLIBFILE ) - rm -f lib/lib$(PACKAGE).1.so - rm -f lib/lib$(PACKAGE).1.dylib - rm -f $(ROOTMAP) - rm -f $(DLLIBFILE) - -.PHONY : winlib shlib lib default clean - -# DO NOT DELETE diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/make_caloHitAna.sh b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/make_caloHitAna.sh new file mode 100644 index 000000000000..0f6fbdc60a0b --- /dev/null +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/make_caloHitAna.sh @@ -0,0 +1,4 @@ +g++ -g -c run.C FCS_CellDict.cxx -I $(root-config --incdir) -I . -fPIC $CPPEXPFLAGS -std=c++11 +g++ -g -o CaloHitAna run.o FCS_CellDict.o -L $(root-config --libdir) -lGui -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lpthread -Wl,-rpath,$(root-config --libdir) -lm -ldl -fPIC $CPPEXPFLAGS -std=c++11 + + -- GitLab