diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorBase/MuonAlignErrorBase/AlignmentDeviation.h b/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorBase/MuonAlignErrorBase/AlignmentDeviation.h index a80d88af2ef81b72fb373fb30de9977a338af7df..ae5a12eaf023e531b522728687b953493aa6eae2 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorBase/MuonAlignErrorBase/AlignmentDeviation.h +++ b/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorBase/MuonAlignErrorBase/AlignmentDeviation.h @@ -5,87 +5,80 @@ #ifndef MUONALIGNERRORBASE_ALIGNMENTDEVIATION_H #define MUONALIGNERRORBASE_ALIGNMENTDEVIATION_H -#include "GeoPrimitives/GeoPrimitives.h" #include <iosfwd> #include <vector> +#include "GeoPrimitives/GeoPrimitives.h" + namespace Trk { - class RIO_OnTrack; + class RIO_OnTrack; - /** - * An object decorating a track and holding degrees of freedom reflecting alignment accuracy - */ - class AlignmentDeviation { + /** + * An object decorating a track and holding degrees of freedom reflecting alignment accuracy + */ + class AlignmentDeviation { public: - - virtual ~AlignmentDeviation() {} - - /** - * The number of free parameters - */ - virtual int nPar() const = 0; - - /** - * The error matrix on the free parameters. Track fitters should use this - * to compute a constraint on the free parameters. - */ - virtual double getCovariance(int ipar, int jpar) const = 0; - - /** - * Return a Transform in the global coordinate system, given a list of - * parameters. - */ - virtual Amg::Transform3D getTransform(const std::vector<double>& parameters) const = 0; - - /** - * Return the list of hits the transform should be applied to. - */ - void getListOfHits(std::vector<const Trk::RIO_OnTrack*>& hits) const; - - /** - * Return hash built out of associated hits for fast comparison if deviations have same content - */ - std::size_t getHashOfHits() const; - - /** - * Set hash built out of associated hits - cannot be calculated in constructor because of dependencies - */ - void setHashOfHits(std::size_t hash); - - /** - * Return if the hash created form associated hits is set - */ - bool hasValidHashOfHits() const; - - /** - * Verbose - */ - virtual void print(std::ostream& out) const = 0; + virtual ~AlignmentDeviation() {} + + /** + * The number of free parameters + */ + virtual int nPar() const = 0; + + /** + * The error matrix on the free parameters. Track fitters should use this + * to compute a constraint on the free parameters. + */ + virtual double getCovariance(int ipar, int jpar) const = 0; + + /** + * Return a Transform in the global coordinate system, given a list of + * parameters. + */ + virtual Amg::Transform3D getTransform(const std::vector<double>& parameters) const = 0; + + /** + * Return the list of hits the transform should be applied to. + */ + void getListOfHits(std::vector<const Trk::RIO_OnTrack*>& hits) const; + + /** + * Return hash built out of associated hits for fast comparison if deviations have same content + */ + std::size_t getHashOfHits() const; + + /** + * Set hash built out of associated hits - cannot be calculated in constructor because of dependencies + */ + void setHashOfHits(std::size_t hash); + + /** + * Return if the hash created form associated hits is set + */ + bool hasValidHashOfHits() const; + + /** + * Verbose + */ + virtual void print(std::ostream& out) const = 0; protected: - std::vector<const Trk::RIO_OnTrack*> m_hits; // not owned - std::size_t m_hitshash; - bool m_hitshashdone; - }; + std::vector<const Trk::RIO_OnTrack*> m_hits; // not owned + std::size_t m_hitshash; + bool m_hitshashdone; + }; - inline void AlignmentDeviation::getListOfHits (std::vector<const Trk::RIO_OnTrack*>& hits) const { - hits = m_hits; - } + inline void AlignmentDeviation::getListOfHits(std::vector<const Trk::RIO_OnTrack*>& hits) const { hits = m_hits; } - inline std::size_t AlignmentDeviation::getHashOfHits () const { - return m_hitshash; - } + inline std::size_t AlignmentDeviation::getHashOfHits() const { return m_hitshash; } - inline void AlignmentDeviation::setHashOfHits (std::size_t hash) { - m_hitshash = hash; - m_hitshashdone = true; - } + inline void AlignmentDeviation::setHashOfHits(std::size_t hash) { + m_hitshash = hash; + m_hitshashdone = true; + } - inline bool AlignmentDeviation::hasValidHashOfHits () const { - return m_hitshashdone; - } + inline bool AlignmentDeviation::hasValidHashOfHits() const { return m_hitshashdone; } -} +} // namespace Trk #endif - diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorBase/MuonAlignErrorBase/AlignmentRotationDeviation.h b/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorBase/MuonAlignErrorBase/AlignmentRotationDeviation.h index 2ef4232cc49940aa61872c3060e67534b47bff4d..c323698c43fd9cfb2732c73a54b3a3ca79374662 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorBase/MuonAlignErrorBase/AlignmentRotationDeviation.h +++ b/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorBase/MuonAlignErrorBase/AlignmentRotationDeviation.h @@ -8,41 +8,40 @@ #include "MuonAlignErrorBase/AlignmentDeviation.h" namespace MuonAlign { - class AlignmentRotationDeviation : public Trk::AlignmentDeviation { + class AlignmentRotationDeviation : public Trk::AlignmentDeviation { public: + AlignmentRotationDeviation(Amg::Vector3D center, Amg::Vector3D axis, double sigma, + const std::vector<const Trk::RIO_OnTrack*>& hits); - AlignmentRotationDeviation(Amg::Vector3D center, Amg::Vector3D axis, double sigma, const std::vector<const Trk::RIO_OnTrack*>& hits); + virtual ~AlignmentRotationDeviation() = default; - virtual ~AlignmentRotationDeviation()=default; + /** + * The number of free parameters + */ + virtual int nPar() const; - /** - * The number of free parameters - */ - virtual int nPar() const; + /** + * The error matrix on the free parameters. Track fitters should use this + * to compute a constraint on the free parameters. + */ + virtual double getCovariance(int ipar, int jpar) const; - /** - * The error matrix on the free parameters. Track fitters should use this - * to compute a constraint on the free parameters. - */ - virtual double getCovariance(int ipar, int jpar) const; + /** + * Return a Transform in the global coordinate system, given a list of + * parameters. + */ + virtual Amg::Transform3D getTransform(const std::vector<double>& parameters) const; - /** - * Return a Transform in the global coordinate system, given a list of - * parameters. - */ - virtual Amg::Transform3D getTransform(const std::vector<double>& parameters) const; - - /** - * Verbose - */ - virtual void print(std::ostream& out) const; + /** + * Verbose + */ + virtual void print(std::ostream& out) const; private: - Amg::Vector3D m_center; - Amg::Vector3D m_axis; - double m_sigma; - }; -} + Amg::Vector3D m_center; + Amg::Vector3D m_axis; + double m_sigma; + }; +} // namespace MuonAlign #endif - diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorBase/MuonAlignErrorBase/AlignmentTranslationDeviation.h b/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorBase/MuonAlignErrorBase/AlignmentTranslationDeviation.h index e8432f1ed8cc08bf6bfa66c047882b41ba962678..e2a625ac7ba5d05f036099fc92126bc1e8e536de 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorBase/MuonAlignErrorBase/AlignmentTranslationDeviation.h +++ b/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorBase/MuonAlignErrorBase/AlignmentTranslationDeviation.h @@ -8,40 +8,38 @@ #include "MuonAlignErrorBase/AlignmentDeviation.h" namespace MuonAlign { - class AlignmentTranslationDeviation : public Trk::AlignmentDeviation { + class AlignmentTranslationDeviation : public Trk::AlignmentDeviation { public: + AlignmentTranslationDeviation(Amg::Vector3D u, double sigma, const std::vector<const Trk::RIO_OnTrack*>& hits); - AlignmentTranslationDeviation(Amg::Vector3D u, double sigma, const std::vector<const Trk::RIO_OnTrack*>& hits); + virtual ~AlignmentTranslationDeviation() = default; - virtual ~AlignmentTranslationDeviation()=default; + /** + * The number of free parameters + */ + virtual int nPar() const; - /** - * The number of free parameters - */ - virtual int nPar() const; + /** + * The error matrix on the free parameters. Track fitters should use this + * to compute a constraint on the free parameters. + */ + virtual double getCovariance(int ipar, int jpar) const; - /** - * The error matrix on the free parameters. Track fitters should use this - * to compute a constraint on the free parameters. - */ - virtual double getCovariance(int ipar, int jpar) const; + /** + * Return a Transform in the global coordinate system, given a list of + * parameters. + */ + virtual Amg::Transform3D getTransform(const std::vector<double>& parameters) const; - /** - * Return a Transform in the global coordinate system, given a list of - * parameters. - */ - virtual Amg::Transform3D getTransform(const std::vector<double>& parameters) const; - - /** - * Verbose - */ - virtual void print(std::ostream& out) const; + /** + * Verbose + */ + virtual void print(std::ostream& out) const; private: - Amg::Vector3D m_u; // unit vector - double m_sigma; - }; -} + Amg::Vector3D m_u; // unit vector + double m_sigma; + }; +} // namespace MuonAlign #endif - diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorBase/src/AlignmentRotationDeviation.cxx b/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorBase/src/AlignmentRotationDeviation.cxx index d68683b5d463e55d275b0e507db722871dd5f684..56e054846f324ce8d328ce1736c43e3d90f55ba3 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorBase/src/AlignmentRotationDeviation.cxx +++ b/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorBase/src/AlignmentRotationDeviation.cxx @@ -3,39 +3,34 @@ */ #include "MuonAlignErrorBase/AlignmentRotationDeviation.h" + #include <iostream> using namespace MuonAlign; -AlignmentRotationDeviation::AlignmentRotationDeviation (Amg::Vector3D center, Amg::Vector3D axis, double sigma, const std::vector<const Trk::RIO_OnTrack*>& hits) : - m_center(center), - m_axis(axis), - m_sigma(sigma) -{ - m_hits = hits; - m_hitshash = 0; - m_hitshashdone = false; +AlignmentRotationDeviation::AlignmentRotationDeviation(Amg::Vector3D center, Amg::Vector3D axis, double sigma, + const std::vector<const Trk::RIO_OnTrack*>& hits) : + m_center(center), m_axis(axis), m_sigma(sigma) { + m_hits = hits; + m_hitshash = 0; + m_hitshashdone = false; } -int AlignmentRotationDeviation::nPar () const { - return 1; -} +int AlignmentRotationDeviation::nPar() const { return 1; } -double AlignmentRotationDeviation::getCovariance (int, int) const { - return m_sigma * m_sigma; -} +double AlignmentRotationDeviation::getCovariance(int, int) const { return m_sigma * m_sigma; } -Amg::Transform3D AlignmentRotationDeviation::getTransform (const std::vector<double>& parameters) const { +Amg::Transform3D AlignmentRotationDeviation::getTransform(const std::vector<double>& parameters) const { + Amg::Translation3D transl1(-m_center); + Amg::Translation3D transl2(m_center); + Amg::AngleAxis3D angleaxis = Eigen::AngleAxis<double>(parameters[0], m_axis); + Amg::Transform3D t = transl2 * angleaxis * transl1; - Amg::Translation3D transl1(-m_center); - Amg::Translation3D transl2(m_center); - Amg::AngleAxis3D angleaxis = Eigen::AngleAxis<double>(parameters[0], m_axis); - Amg::Transform3D t = transl2 * angleaxis * transl1; - - return t; + return t; } -void AlignmentRotationDeviation::print (std::ostream& out) const { - out << "A rotation around center = (" << m_center.x() << ", " << m_center.y() << ", " << m_center.z() << ") and axis = (" << m_axis.x() << ", " << m_axis.y() << ", " << m_axis.z() << ") with sigma=" << m_sigma << " mrad applied to " << m_hits.size() << " hits" << std::endl; +void AlignmentRotationDeviation::print(std::ostream& out) const { + out << "A rotation around center = (" << m_center.x() << ", " << m_center.y() << ", " << m_center.z() << ") and axis = (" << m_axis.x() + << ", " << m_axis.y() << ", " << m_axis.z() << ") with sigma=" << m_sigma << " mrad applied to " << m_hits.size() << " hits" + << std::endl; } - diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorBase/src/AlignmentTranslationDeviation.cxx b/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorBase/src/AlignmentTranslationDeviation.cxx index 41c089757dc60c4febabf61833bf6d052538553c..1cbe7090b6a4767b99af15db818154b016fb63fb 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorBase/src/AlignmentTranslationDeviation.cxx +++ b/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorBase/src/AlignmentTranslationDeviation.cxx @@ -3,33 +3,29 @@ */ #include "MuonAlignErrorBase/AlignmentTranslationDeviation.h" + #include <iostream> using namespace MuonAlign; -AlignmentTranslationDeviation::AlignmentTranslationDeviation (Amg::Vector3D u, double sigma, const std::vector<const Trk::RIO_OnTrack*>& hits) - : m_u(u.unit()), - m_sigma(sigma) -{ - m_hits = hits; - m_hitshash = 0; - m_hitshashdone = false; +AlignmentTranslationDeviation::AlignmentTranslationDeviation(Amg::Vector3D u, double sigma, + const std::vector<const Trk::RIO_OnTrack*>& hits) : + m_u(u.unit()), m_sigma(sigma) { + m_hits = hits; + m_hitshash = 0; + m_hitshashdone = false; } -int AlignmentTranslationDeviation::nPar () const { - return 1; -} +int AlignmentTranslationDeviation::nPar() const { return 1; } -double AlignmentTranslationDeviation::getCovariance (int, int) const { - return m_sigma*m_sigma; -} +double AlignmentTranslationDeviation::getCovariance(int, int) const { return m_sigma * m_sigma; } -Amg::Transform3D AlignmentTranslationDeviation::getTransform (const std::vector<double>& parameters) const { - Amg::Transform3D t(Amg::Translation3D(parameters[0] * m_u)); - return t; +Amg::Transform3D AlignmentTranslationDeviation::getTransform(const std::vector<double>& parameters) const { + Amg::Transform3D t(Amg::Translation3D(parameters[0] * m_u)); + return t; } -void AlignmentTranslationDeviation::print (std::ostream& out) const { - out << "A translation along (" << m_u.x() << ", " << m_u.y() << ", " << m_u.z() << ") with sigma=" << m_sigma << " mm applied to " << m_hits.size() << " hits" << std::endl; +void AlignmentTranslationDeviation::print(std::ostream& out) const { + out << "A translation along (" << m_u.x() << ", " << m_u.y() << ", " << m_u.z() << ") with sigma=" << m_sigma << " mm applied to " + << m_hits.size() << " hits" << std::endl; } - diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorTool/MuonAlignErrorTool/AlignmentErrorTool.h b/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorTool/MuonAlignErrorTool/AlignmentErrorTool.h index b7d0d77df580a43de849146e0673c6c219bd8bba..0a82821fa9dc16a642e0a8e814ffc60a1b89d323 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorTool/MuonAlignErrorTool/AlignmentErrorTool.h +++ b/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorTool/MuonAlignErrorTool/AlignmentErrorTool.h @@ -5,77 +5,71 @@ #ifndef MUONALIGNERRORTOOL_ALIGNMENTERRORTOOL_H #define MUONALIGNERRORTOOL_ALIGNMENTERRORTOOL_H -#include "TrkToolInterfaces/ITrkAlignmentDeviationTool.h" +#include <boost/regex.hpp> +#include <iosfwd> +#include <string> + #include "AthenaBaseComps/AthAlgTool.h" #include "GaudiKernel/ServiceHandle.h" #include "GaudiKernel/ToolHandle.h" - +#include "GeoPrimitives/GeoPrimitives.h" #include "MuonAlignErrorBase/AlignmentDeviation.h" #include "MuonCalibITools/IIdToFixedIdTool.h" +#include "MuonCondAlg/MuonAlignmentErrorData.h" // for accessing info from the DB #include "MuonIdHelpers/IMuonIdHelperSvc.h" -#include "GeoPrimitives/GeoPrimitives.h" -#include "MuonCondAlg/MuonAlignmentErrorData.h" // for accessing info from the DB #include "StoreGate/ReadCondHandleKey.h" - -#include <boost/regex.hpp> -#include <iosfwd> -#include <string> +#include "TrkToolInterfaces/ITrkAlignmentDeviationTool.h" namespace Trk { - class RIO_OnTrack; + class RIO_OnTrack; } namespace MuonAlign { - class AlignmentErrorTool : public Trk::ITrkAlignmentDeviationTool, virtual public AthAlgTool { - + class AlignmentErrorTool : public Trk::ITrkAlignmentDeviationTool, virtual public AthAlgTool { public: - - AlignmentErrorTool(const std::string&,const std::string&,const IInterface*); - virtual ~AlignmentErrorTool()=default; - virtual StatusCode initialize(); - virtual void makeAlignmentDeviations (const Trk::Track& track, std::vector<Trk::AlignmentDeviation*>& deviations) const; + AlignmentErrorTool(const std::string&, const std::string&, const IInterface*); + virtual ~AlignmentErrorTool() = default; + virtual StatusCode initialize(); + virtual void makeAlignmentDeviations(const Trk::Track& track, std::vector<Trk::AlignmentDeviation*>& deviations) const; private: - - ToolHandle<MuonCalib::IIdToFixedIdTool> m_idTool{this,"idTool","MuonCalib::IdToFixedIdTool"}; - ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"}; - - // Struct for per-Station Deviations Information // - struct deviationSummary_t { - deviationSummary_t(); - ~deviationSummary_t()=default; - //static int i_instance; // TMP DEBUG - - // SYSTEMATIC UNCERTAINTIES - double traslation; - double rotation; - // RULE - boost::regex stationName; - boost::regex multilayer; - // SET OF HITS SATISFYING THE RULE - std::vector<const Trk::RIO_OnTrack*> hits; - // USEFUL NUMBERS - Amg::Vector3D sumP; - Amg::Vector3D sumU; - Amg::Vector3D sumV; - double sumW2; - }; - - // SOME USEFUL METHODS // - // GET STATION EXACT NAME, FROM: https://svnweb.cern.ch/cern/wsvn/atlas-giraudpf/giraudpf/MuonSpectrometer/MuonAlignment/MuonAlignTrk/trunk/MuonAlignTrk/MuonFixedId.h - std::string hardwareName(MuonCalib::MuonFixedId calibId) const; - std::string side(MuonCalib::MuonFixedId calibId) const; - std::string sectorString(MuonCalib::MuonFixedId calibId) const; - int sector(MuonCalib::MuonFixedId calibId) const; - int hardwareEta(MuonCalib::MuonFixedId calibId) const; - bool isSmallSector(MuonCalib::MuonFixedId calibId) const; - - SG::ReadCondHandleKey<MuonAlignmentErrorData> m_readKey{this, "ReadKey", "MuonAlignmentErrorData", "Key of MuonAlignmentErrorData"}; - - }; -} - + ToolHandle<MuonCalib::IIdToFixedIdTool> m_idTool{this, "idTool", "MuonCalib::IdToFixedIdTool"}; + ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc{this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"}; + + // Struct for per-Station Deviations Information // + struct deviationSummary_t { + deviationSummary_t(); + ~deviationSummary_t() = default; + // static int i_instance; // TMP DEBUG + + // SYSTEMATIC UNCERTAINTIES + double traslation; + double rotation; + // RULE + boost::regex stationName; + boost::regex multilayer; + // SET OF HITS SATISFYING THE RULE + std::vector<const Trk::RIO_OnTrack*> hits; + // USEFUL NUMBERS + Amg::Vector3D sumP; + Amg::Vector3D sumU; + Amg::Vector3D sumV; + double sumW2; + }; + + // SOME USEFUL METHODS // + // GET STATION EXACT NAME, FROM: + // https://svnweb.cern.ch/cern/wsvn/atlas-giraudpf/giraudpf/MuonSpectrometer/MuonAlignment/MuonAlignTrk/trunk/MuonAlignTrk/MuonFixedId.h + std::string hardwareName(MuonCalib::MuonFixedId calibId) const; + std::string side(MuonCalib::MuonFixedId calibId) const; + std::string sectorString(MuonCalib::MuonFixedId calibId) const; + int sector(MuonCalib::MuonFixedId calibId) const; + int hardwareEta(MuonCalib::MuonFixedId calibId) const; + bool isSmallSector(MuonCalib::MuonFixedId calibId) const; + + SG::ReadCondHandleKey<MuonAlignmentErrorData> m_readKey{this, "ReadKey", "MuonAlignmentErrorData", "Key of MuonAlignmentErrorData"}; + }; +} // namespace MuonAlign #endif - diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorTool/MuonAlignErrorTool/MuonAlignErrorExampleAlg.h b/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorTool/MuonAlignErrorTool/MuonAlignErrorExampleAlg.h index d897d6bbe0fbd57adfada1d1509d5ac1444f30cf..b86a067ed83bb8162c38fbeb08bcf1108f6b6611 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorTool/MuonAlignErrorTool/MuonAlignErrorExampleAlg.h +++ b/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorTool/MuonAlignErrorTool/MuonAlignErrorExampleAlg.h @@ -8,45 +8,42 @@ #include "AthenaBaseComps/AthAlgorithm.h" #include "GaudiKernel/ServiceHandle.h" #include "GaudiKernel/ToolHandle.h" - -#include "TrkToolInterfaces/ITrkAlignmentDeviationTool.h" -#include "MuonIdHelpers/IMuonIdHelperSvc.h" #include "MuonCalibITools/IIdToFixedIdTool.h" - +#include "MuonIdHelpers/IMuonIdHelperSvc.h" #include "TFile.h" #include "TH1F.h" +#include "TrkToolInterfaces/ITrkAlignmentDeviationTool.h" namespace Trk { - class Track; + class Track; } namespace MuonAlign { - class MuonAlignErrorExampleAlg : public AthAlgorithm { + class MuonAlignErrorExampleAlg : public AthAlgorithm { public: - MuonAlignErrorExampleAlg(const std::string& name, ISvcLocator* pSvcLocator); - StatusCode initialize(); - StatusCode execute(); - StatusCode finalize(); + MuonAlignErrorExampleAlg(const std::string& name, ISvcLocator* pSvcLocator); + StatusCode initialize(); + StatusCode execute(); + StatusCode finalize(); + private: - void muonTrack(const Trk::Track* track) const; - - ToolHandle<Trk::ITrkAlignmentDeviationTool> m_alignErrorTool{this,"alignErrorTool","MuonAlign::AlignmentErrorTool"}; - - // FOR DEBUGGING - TFile* m_debug; - TH1F* m_cham_per_dev; - TH1F* m_dev_per_track; - ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"}; - ToolHandle<MuonCalib::IIdToFixedIdTool> m_idTool{this,"idTool","MuonCalib::IdToFixedIdTool/IdToFixedIdTool"}; - std::string hardwareName(MuonCalib::MuonFixedId calibId) const; - std::string side(MuonCalib::MuonFixedId calibId) const; - std::string sectorString(MuonCalib::MuonFixedId calibId) const; - int sector(MuonCalib::MuonFixedId calibId) const; - int hardwareEta(MuonCalib::MuonFixedId calibId) const; - bool isSmallSector(MuonCalib::MuonFixedId calibId) const; - - }; -} + void muonTrack(const Trk::Track* track) const; + + ToolHandle<Trk::ITrkAlignmentDeviationTool> m_alignErrorTool{this, "alignErrorTool", "MuonAlign::AlignmentErrorTool"}; + + // FOR DEBUGGING + TFile* m_debug; + TH1F* m_cham_per_dev; + TH1F* m_dev_per_track; + ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc{this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"}; + ToolHandle<MuonCalib::IIdToFixedIdTool> m_idTool{this, "idTool", "MuonCalib::IdToFixedIdTool/IdToFixedIdTool"}; + std::string hardwareName(MuonCalib::MuonFixedId calibId) const; + std::string side(MuonCalib::MuonFixedId calibId) const; + std::string sectorString(MuonCalib::MuonFixedId calibId) const; + int sector(MuonCalib::MuonFixedId calibId) const; + int hardwareEta(MuonCalib::MuonFixedId calibId) const; + bool isSmallSector(MuonCalib::MuonFixedId calibId) const; + }; +} // namespace MuonAlign #endif - diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorTool/src/AlignmentErrorTool.cxx b/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorTool/src/AlignmentErrorTool.cxx index 91d8ccf34a2a6779a3bdd66ff7520684d34e6f69..207378824b8c5eb3380ddfe50386b7ece92c50e7 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorTool/src/AlignmentErrorTool.cxx +++ b/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorTool/src/AlignmentErrorTool.cxx @@ -9,305 +9,297 @@ #include "MuonAlignErrorTool/AlignmentErrorTool.h" -#include "MuonAlignErrorBase/AlignmentTranslationDeviation.h" -#include "MuonAlignErrorBase/AlignmentRotationDeviation.h" -#include "TrkTrack/Track.h" -#include "TrkRIO_OnTrack/RIO_OnTrack.h" -#include "TrkPrepRawData/PrepRawData.h" -#include "TrkCompetingRIOsOnTrack/CompetingRIOsOnTrack.h" -#include "PathResolver/PathResolver.h" -#include "GeoPrimitives/CLHEPtoEigenConverter.h" - +#include <boost/functional/hash.hpp> #include <fstream> #include <sstream> -#include <boost/functional/hash.hpp> + +#include "GeoPrimitives/CLHEPtoEigenConverter.h" +#include "MuonAlignErrorBase/AlignmentRotationDeviation.h" +#include "MuonAlignErrorBase/AlignmentTranslationDeviation.h" +#include "PathResolver/PathResolver.h" +#include "TrkCompetingRIOsOnTrack/CompetingRIOsOnTrack.h" +#include "TrkPrepRawData/PrepRawData.h" +#include "TrkRIO_OnTrack/RIO_OnTrack.h" +#include "TrkTrack/Track.h" using namespace MuonAlign; -AlignmentErrorTool::AlignmentErrorTool(const std::string& t, const std::string& n, const IInterface* p) : - AthAlgTool(t,n,p) { - declareInterface<Trk::ITrkAlignmentDeviationTool>(this); +AlignmentErrorTool::AlignmentErrorTool(const std::string& t, const std::string& n, const IInterface* p) : AthAlgTool(t, n, p) { + declareInterface<Trk::ITrkAlignmentDeviationTool>(this); } -AlignmentErrorTool::deviationSummary_t::deviationSummary_t() -: traslation(0.), rotation(0.), stationName(""), sumP(Amg::Vector3D(0., 0., 0.)), sumU(Amg::Vector3D(0., 0., 0.)), sumV(Amg::Vector3D(0., 0., 0.)), sumW2(0.) { -} +AlignmentErrorTool::deviationSummary_t::deviationSummary_t() : + traslation(0.), + rotation(0.), + stationName(""), + sumP(Amg::Vector3D(0., 0., 0.)), + sumU(Amg::Vector3D(0., 0., 0.)), + sumV(Amg::Vector3D(0., 0., 0.)), + sumW2(0.) {} StatusCode AlignmentErrorTool::initialize() { + ATH_MSG_INFO("*****************************************"); + ATH_MSG_INFO("AlignmentErrorTool::initialize()"); - ATH_MSG_INFO("*****************************************"); - ATH_MSG_INFO("AlignmentErrorTool::initialize()"); - - ATH_CHECK(m_idTool.retrieve()); - ATH_CHECK(m_idHelperSvc.retrieve()); - ATH_CHECK(m_readKey.initialize()); - - return StatusCode::SUCCESS; + ATH_CHECK(m_idTool.retrieve()); + ATH_CHECK(m_idHelperSvc.retrieve()); + ATH_CHECK(m_readKey.initialize()); + return StatusCode::SUCCESS; } -void AlignmentErrorTool::makeAlignmentDeviations (const Trk::Track& track, std::vector<Trk::AlignmentDeviation*>& deviations) const { - - ATH_MSG_DEBUG("AlignmentErrorTool::makeAlignmentDeviations()"); +void AlignmentErrorTool::makeAlignmentDeviations(const Trk::Track& track, std::vector<Trk::AlignmentDeviation*>& deviations) const { + ATH_MSG_DEBUG("AlignmentErrorTool::makeAlignmentDeviations()"); - SG::ReadCondHandle<MuonAlignmentErrorData> readHandle{m_readKey}; - const MuonAlignmentErrorData* readCdo{*readHandle}; - if(!readCdo){ - ATH_MSG_ERROR("nullptr to the read conditions object"); - return; - } - std::vector<deviationStr> devStrVec; - readCdo->getVec(devStrVec); - std::vector<deviationSummary_t*> devSumVec; - for(unsigned int i=0; i < devStrVec.size(); i++) { - deviationSummary_t* tmp = new deviationSummary_t; - tmp->traslation = devStrVec[i].traslation; - tmp->rotation = devStrVec[i].rotation; - tmp->stationName = devStrVec[i].stationName; - tmp->multilayer = devStrVec[i].multilayer; - tmp->hits.clear(); - Amg::Vector3D nullvec(0., 0., 0.); - tmp->sumP = nullvec; - tmp->sumU = nullvec; - tmp->sumV = nullvec; - tmp->sumW2 = 0.; - devSumVec.push_back(tmp); - } - - typedef DataVector< const Trk::TrackStateOnSurface > tsosc_t; - const tsosc_t* tsosc = track.trackStateOnSurfaces(); - - // LOOP ON HITS ON TRACK // - unsigned int nPrecisionHits = 0; - for (tsosc_t::const_iterator it=tsosc->begin(), end=tsosc->end(); it!=end; it++) { - - const Trk::TrackStateOnSurface* tsos = *it; - - if (tsos->type(Trk::TrackStateOnSurface::Measurement)) { - - const Trk::MeasurementBase* meas = tsos->measurementOnTrack(); - const Trk::RIO_OnTrack* rot = dynamic_cast<const Trk::RIO_OnTrack*> (meas); - - if (!rot) { - const Trk::CompetingRIOsOnTrack* crot = dynamic_cast<const Trk::CompetingRIOsOnTrack*> (meas); - if (crot) { - unsigned int index = crot->indexOfMaxAssignProb(); - rot = &(crot->rioOnTrack(index)); - } - } - if (!rot) continue; - - Identifier channelId = rot->identify(); - if (!m_idHelperSvc->isMuon(channelId)) { - // the RIO_OnTrack Identifiers could also come from ID or Calo, but this tool is only interested in MS hits - ATH_MSG_VERBOSE("Given Identifier "<<channelId.get_compact()<<" is no muon Identifier, continuing"); - continue; - } - if (m_idHelperSvc->isMM(channelId)||m_idHelperSvc->issTgc(channelId)) continue; // needs to be still implemented for the NSW - - MuonCalib::MuonFixedId calibId = m_idTool->idToFixedId(channelId); - if (!calibId.isValid()) continue; - - // GATHERING INFORMATION TO PUT TOGETHER THE STATION NAME // - std::string completename = hardwareName(calibId); - std::stringstream multilayer_stream; - multilayer_stream << calibId.mdtMultilayer(); - std::string multilayer_sstring = multilayer_stream.str(); - - if ( m_idHelperSvc->isMdt(channelId) || ( m_idHelperSvc->isCsc(channelId) && m_idHelperSvc->cscIdHelper().measuresPhi(channelId) == 0 ) ) { - - ATH_MSG_DEBUG("Hit is in station " << completename << " multilayer " << multilayer_sstring); - ++nPrecisionHits; - - // FOR CROSS-CHECK - bool is_matched = false; - - // LOOP ON STATION DEVIATIONS EXTRACTED FROM INPUT FILE // - for(unsigned int iDev=0; iDev < devSumVec.size(); iDev++) { - - // find a match to the reg exp // - boost::regex tmp_stationName = devSumVec[iDev]->stationName; - - if ( boost::regex_match(completename, tmp_stationName) ) { - - if( !boost::regex_match(multilayer_sstring, devSumVec[iDev]->multilayer) && !m_idHelperSvc->isCsc(channelId) ) { - continue; - } - - // ASSOCIATE EACH NUISANCE TO A LIST OF HITS - devSumVec[iDev]->hits.push_back(rot); - - // COMPUTE RELEVANT NUMBERS - const Trk::PrepRawData* prd = rot->prepRawData(); - const Trk::Surface& sur = prd->detectorElement()->surface(prd->identify()); - double w2 = sqrt(rot->localCovariance()(Trk::loc1,Trk::loc1)); - w2 = 1./(w2*w2); - devSumVec[iDev]->sumW2 += w2; - devSumVec[iDev]->sumP += w2 * tsos->trackParameters()->position(); - devSumVec[iDev]->sumU += w2 * tsos->trackParameters()->momentum().unit(); - - // CHECK 1 // - Amg::Vector3D zATLAS(0., 0., 1.); - Amg::Vector3D v1 = (tsos->trackParameters()->position()).cross(zATLAS); - v1 /= v1.mag(); - Amg::Vector3D v2 = sur.transform().rotation().col(2)/(sur.transform().rotation().col(2)).mag(); - double sign = (v1.dot(v2) > 0.) ? 1. : -1.; - - // ARTIFICIALLY ORIENTATE EVERYTHING TOWARDS THE SAME DIRECTION - devSumVec[iDev]->sumV += sign * w2 * sur.transform().rotation().col(2); - - // FOR CROSS-CHECK - is_matched = true; - - } // match the station name to the deviation regexp - - } // LOOP ON DEVIATIONS - - if (is_matched == false) - ATH_MSG_WARNING("The hits in the station " << completename << ", multilayer " << multilayer_sstring << " couldn't be matched to any deviation regexp in the list."); - - } //CHECK IF IT'S MDT OR CSC HIT - - } // CHECK TSOS OF TYPE 'MEASUREMENT' - - } //LOOP ON TSOS - - // Nuisance parameters covering the complete track are not wanted. (MS/ID - // error treated differently for now). Removing the deviations covering the - // full track in further processing. - for (deviationSummary_t* dev : devSumVec) { - if (dev->hits.size() == nPrecisionHits) - dev->hits.clear(); - } - - // CHECK HIT LISTS OVERLAP - // FIRST CREATE AN INDEPENDENT COPY OF THE STRUCT VECTOR - std::vector<deviationSummary_t*> new_deviationsVec; - for(unsigned int iDev=0; iDev < devSumVec.size(); iDev++) { - deviationSummary_t* tmp = new deviationSummary_t(); - (*tmp) = (*devSumVec[iDev]); - new_deviationsVec.push_back(tmp); - } - - for(unsigned int iDev=0; iDev < devSumVec.size(); iDev++) { - - if (!new_deviationsVec[iDev]) - continue; - - std::vector<const Trk::RIO_OnTrack*> v1 = devSumVec[iDev]->hits; - if ( v1.empty() ) - continue; - - std::stable_sort(v1.begin(), v1.end()); - - for(unsigned int jDev=iDev+1; jDev < devSumVec.size(); jDev++) { - - if (!new_deviationsVec[jDev]) - continue; - - bool match = false; - - if ( devSumVec[iDev]->hits.size() != devSumVec[jDev]->hits.size() ) - continue; - - std::vector<const Trk::RIO_OnTrack*> v2 = devSumVec[jDev]->hits; - std::stable_sort(v2.begin(), v2.end()); - - match = (v1 == v2); - - if ( match ) { - - ATH_MSG_DEBUG("Found deviations " << iDev << " and " << jDev << " related to the same list of hits. Merging..."); - ATH_MSG_DEBUG("old (traslation, rotation) systematic uncertainties for " << iDev << ": " << new_deviationsVec[iDev]->traslation << ", " << new_deviationsVec[iDev]->rotation); - ATH_MSG_DEBUG("old (traslation, rotation) systematic uncertainties for " << jDev << ": " << devSumVec[jDev]->traslation << ", " << devSumVec[jDev]->rotation); + SG::ReadCondHandle<MuonAlignmentErrorData> readHandle{m_readKey}; + const MuonAlignmentErrorData* readCdo{*readHandle}; + if (!readCdo) { + ATH_MSG_ERROR("nullptr to the read conditions object"); + return; + } + std::vector<deviationStr> devStrVec; + readCdo->getVec(devStrVec); + std::vector<deviationSummary_t*> devSumVec; + for (unsigned int i = 0; i < devStrVec.size(); i++) { + deviationSummary_t* tmp = new deviationSummary_t; + tmp->traslation = devStrVec[i].traslation; + tmp->rotation = devStrVec[i].rotation; + tmp->stationName = devStrVec[i].stationName; + tmp->multilayer = devStrVec[i].multilayer; + tmp->hits.clear(); + Amg::Vector3D nullvec(0., 0., 0.); + tmp->sumP = nullvec; + tmp->sumU = nullvec; + tmp->sumV = nullvec; + tmp->sumW2 = 0.; + devSumVec.push_back(tmp); + } - // MERGE THE TWO DEVIATIONS ASSOCIATED TO THE SAME LIST OF HITS // - double new_traslation = sqrt(new_deviationsVec[iDev]->traslation*new_deviationsVec[iDev]->traslation + devSumVec[jDev]->traslation*devSumVec[jDev]->traslation); - double new_rotation = sqrt(new_deviationsVec[iDev]->rotation*new_deviationsVec[iDev]->rotation + devSumVec[jDev]->rotation*devSumVec[jDev]->rotation); + typedef DataVector<const Trk::TrackStateOnSurface> tsosc_t; + const tsosc_t* tsosc = track.trackStateOnSurfaces(); + + // LOOP ON HITS ON TRACK // + unsigned int nPrecisionHits = 0; + for (tsosc_t::const_iterator it = tsosc->begin(), end = tsosc->end(); it != end; it++) { + const Trk::TrackStateOnSurface* tsos = *it; + + if (tsos->type(Trk::TrackStateOnSurface::Measurement)) { + const Trk::MeasurementBase* meas = tsos->measurementOnTrack(); + const Trk::RIO_OnTrack* rot = dynamic_cast<const Trk::RIO_OnTrack*>(meas); + + if (!rot) { + const Trk::CompetingRIOsOnTrack* crot = dynamic_cast<const Trk::CompetingRIOsOnTrack*>(meas); + if (crot) { + unsigned int index = crot->indexOfMaxAssignProb(); + rot = &(crot->rioOnTrack(index)); + } + } + if (!rot) continue; + + Identifier channelId = rot->identify(); + if (!m_idHelperSvc->isMuon(channelId)) { + // the RIO_OnTrack Identifiers could also come from ID or Calo, but this tool is only interested in MS hits + ATH_MSG_VERBOSE("Given Identifier " << channelId.get_compact() << " is no muon Identifier, continuing"); + continue; + } + if (m_idHelperSvc->isMM(channelId) || m_idHelperSvc->issTgc(channelId)) continue; // needs to be still implemented for the NSW + + MuonCalib::MuonFixedId calibId = m_idTool->idToFixedId(channelId); + if (!calibId.isValid()) continue; + + // GATHERING INFORMATION TO PUT TOGETHER THE STATION NAME // + std::string completename = hardwareName(calibId); + std::stringstream multilayer_stream; + multilayer_stream << calibId.mdtMultilayer(); + std::string multilayer_sstring = multilayer_stream.str(); + + if (m_idHelperSvc->isMdt(channelId) || + (m_idHelperSvc->isCsc(channelId) && m_idHelperSvc->cscIdHelper().measuresPhi(channelId) == 0)) { + ATH_MSG_DEBUG("Hit is in station " << completename << " multilayer " << multilayer_sstring); + ++nPrecisionHits; + + // FOR CROSS-CHECK + bool is_matched = false; + + // LOOP ON STATION DEVIATIONS EXTRACTED FROM INPUT FILE // + for (unsigned int iDev = 0; iDev < devSumVec.size(); iDev++) { + // find a match to the reg exp // + boost::regex tmp_stationName = devSumVec[iDev]->stationName; + + if (boost::regex_match(completename, tmp_stationName)) { + if (!boost::regex_match(multilayer_sstring, devSumVec[iDev]->multilayer) && !m_idHelperSvc->isCsc(channelId)) { + continue; + } + + // ASSOCIATE EACH NUISANCE TO A LIST OF HITS + devSumVec[iDev]->hits.push_back(rot); + + // COMPUTE RELEVANT NUMBERS + const Trk::PrepRawData* prd = rot->prepRawData(); + const Trk::Surface& sur = prd->detectorElement()->surface(prd->identify()); + double w2 = sqrt(rot->localCovariance()(Trk::loc1, Trk::loc1)); + w2 = 1. / (w2 * w2); + devSumVec[iDev]->sumW2 += w2; + devSumVec[iDev]->sumP += w2 * tsos->trackParameters()->position(); + devSumVec[iDev]->sumU += w2 * tsos->trackParameters()->momentum().unit(); + + // CHECK 1 // + Amg::Vector3D zATLAS(0., 0., 1.); + Amg::Vector3D v1 = (tsos->trackParameters()->position()).cross(zATLAS); + v1 /= v1.mag(); + Amg::Vector3D v2 = sur.transform().rotation().col(2) / (sur.transform().rotation().col(2)).mag(); + double sign = (v1.dot(v2) > 0.) ? 1. : -1.; + + // ARTIFICIALLY ORIENTATE EVERYTHING TOWARDS THE SAME DIRECTION + devSumVec[iDev]->sumV += sign * w2 * sur.transform().rotation().col(2); + + // FOR CROSS-CHECK + is_matched = true; + + } // match the station name to the deviation regexp + + } // LOOP ON DEVIATIONS + + if (is_matched == false) + ATH_MSG_WARNING("The hits in the station " << completename << ", multilayer " << multilayer_sstring + << " couldn't be matched to any deviation regexp in the list."); + + } // CHECK IF IT'S MDT OR CSC HIT + + } // CHECK TSOS OF TYPE 'MEASUREMENT' + + } // LOOP ON TSOS + + // Nuisance parameters covering the complete track are not wanted. (MS/ID + // error treated differently for now). Removing the deviations covering the + // full track in further processing. + for (deviationSummary_t* dev : devSumVec) { + if (dev->hits.size() == nPrecisionHits) dev->hits.clear(); + } - // NOW PREPARE TO ERASE ONE OF THE TWO COPIES // - delete new_deviationsVec[jDev]; - new_deviationsVec[jDev] = nullptr; + // CHECK HIT LISTS OVERLAP + // FIRST CREATE AN INDEPENDENT COPY OF THE STRUCT VECTOR + std::vector<deviationSummary_t*> new_deviationsVec; + for (unsigned int iDev = 0; iDev < devSumVec.size(); iDev++) { + deviationSummary_t* tmp = new deviationSummary_t(); + (*tmp) = (*devSumVec[iDev]); + new_deviationsVec.push_back(tmp); + } - // ASSIGN NEW TRASLATION/ROTATION TO THE REMAINING COPY // - new_deviationsVec[iDev]->traslation = new_traslation; - new_deviationsVec[iDev]->rotation = new_rotation; - ATH_MSG_DEBUG("New combined (traslation, rotation) systematic uncertainties: " << new_traslation << ", " << new_rotation); + for (unsigned int iDev = 0; iDev < devSumVec.size(); iDev++) { + if (!new_deviationsVec[iDev]) continue; - } // FIND AN OVERLAP IN THE HITS LISTS - } // SECOND LOOP ON DEVIATIONS - } // FIRST LOOP ON DEVIATIONS + std::vector<const Trk::RIO_OnTrack*> v1 = devSumVec[iDev]->hits; + if (v1.empty()) continue; - // NOW BUILD THE DEVIATIONS - deviations.clear(); - ATH_MSG_DEBUG("************************************"); - ATH_MSG_DEBUG("FINAL LIST OF DEVIATIONS"); - for(unsigned int iDev=0; iDev < new_deviationsVec.size(); iDev++) { + std::stable_sort(v1.begin(), v1.end()); - // THIS HAPPENS IF A MERGING HAD BEEN DONE - if (!new_deviationsVec[iDev]) { - continue; - } + for (unsigned int jDev = iDev + 1; jDev < devSumVec.size(); jDev++) { + if (!new_deviationsVec[jDev]) continue; - // SKIP IF NO HITS ARE ASSOCIATED TO THIS DEVIATION - if ( new_deviationsVec[iDev]->hits.size() == 0) { - //ATH_MSG_DEBUG("No hits found associated to the rule " << new_deviationsVec[iDev]->stationName.str() << ", skip"); - continue; - } + bool match = false; - double rotation = new_deviationsVec[iDev]->rotation; - double traslation = new_deviationsVec[iDev]->traslation; + if (devSumVec[iDev]->hits.size() != devSumVec[jDev]->hits.size()) continue; - Amg::Vector3D sumP = new_deviationsVec[iDev]->sumP; - Amg::Vector3D sumU = new_deviationsVec[iDev]->sumU; - Amg::Vector3D sumV = new_deviationsVec[iDev]->sumV; - double sumW2 = new_deviationsVec[iDev]->sumW2; + std::vector<const Trk::RIO_OnTrack*> v2 = devSumVec[jDev]->hits; + std::stable_sort(v2.begin(), v2.end()); - sumP *= (1./sumW2); - sumU *= (1./sumW2); - sumV *= (1./sumW2); + match = (v1 == v2); - if ( traslation >= 0.001*Gaudi::Units::mm ) { + if (match) { + ATH_MSG_DEBUG("Found deviations " << iDev << " and " << jDev << " related to the same list of hits. Merging..."); + ATH_MSG_DEBUG("old (traslation, rotation) systematic uncertainties for " + << iDev << ": " << new_deviationsVec[iDev]->traslation << ", " << new_deviationsVec[iDev]->rotation); + ATH_MSG_DEBUG("old (traslation, rotation) systematic uncertainties for " << jDev << ": " << devSumVec[jDev]->traslation + << ", " << devSumVec[jDev]->rotation); - std::size_t hitshash = 0; - for(auto it : new_deviationsVec[iDev]->hits ) boost::hash_combine( hitshash , (it->identify()).get_compact() ); - deviations.push_back(new AlignmentTranslationDeviation(sumU.cross(sumV), traslation*Gaudi::Units::mm, new_deviationsVec[iDev]->hits)); - deviations.back()->setHashOfHits(hitshash); + // MERGE THE TWO DEVIATIONS ASSOCIATED TO THE SAME LIST OF HITS // + double new_traslation = sqrt(new_deviationsVec[iDev]->traslation * new_deviationsVec[iDev]->traslation + + devSumVec[jDev]->traslation * devSumVec[jDev]->traslation); + double new_rotation = sqrt(new_deviationsVec[iDev]->rotation * new_deviationsVec[iDev]->rotation + + devSumVec[jDev]->rotation * devSumVec[jDev]->rotation); - ATH_MSG_DEBUG("A translation along (" << sumU.x() << ", " << sumU.y() << ", " << sumU.z() << ") with sigma=" << traslation*Gaudi::Units::mm << " mm was applied to " << new_deviationsVec[iDev]->hits.size() << " hits matching the station: " << new_deviationsVec[iDev]->stationName.str() << " and the multilayer " << new_deviationsVec[iDev]->multilayer.str()); + // NOW PREPARE TO ERASE ONE OF THE TWO COPIES // + delete new_deviationsVec[jDev]; + new_deviationsVec[jDev] = nullptr; - } - if ( rotation >= 0.000001*Gaudi::Units::rad ) { + // ASSIGN NEW TRASLATION/ROTATION TO THE REMAINING COPY // + new_deviationsVec[iDev]->traslation = new_traslation; + new_deviationsVec[iDev]->rotation = new_rotation; + ATH_MSG_DEBUG("New combined (traslation, rotation) systematic uncertainties: " << new_traslation << ", " << new_rotation); - std::size_t hitshash = 0; - for(auto it : new_deviationsVec[iDev]->hits ) boost::hash_combine( hitshash , (it->identify()).get_compact() ); - deviations.push_back(new AlignmentRotationDeviation(sumP, sumV, rotation*Gaudi::Units::rad, new_deviationsVec[iDev]->hits)); - deviations.back()->setHashOfHits(hitshash); + } // FIND AN OVERLAP IN THE HITS LISTS + } // SECOND LOOP ON DEVIATIONS + } // FIRST LOOP ON DEVIATIONS - ATH_MSG_DEBUG("A rotation around the center = (" << sumP.x() << ", " << sumP.y() << ", " << sumP.z() << ") and axis = (" << sumV.x() << ", " << sumV.y() << ", " << sumV.z() << ") with sigma=" << rotation/Gaudi::Units::mrad << " mrad was applied to " << new_deviationsVec[iDev]->hits.size() << " hits matching the station " << new_deviationsVec[iDev]->stationName.str() << " and the multilayer " << new_deviationsVec[iDev]->multilayer.str()); + // NOW BUILD THE DEVIATIONS + deviations.clear(); + ATH_MSG_DEBUG("************************************"); + ATH_MSG_DEBUG("FINAL LIST OF DEVIATIONS"); + for (unsigned int iDev = 0; iDev < new_deviationsVec.size(); iDev++) { + // THIS HAPPENS IF A MERGING HAD BEEN DONE + if (!new_deviationsVec[iDev]) { continue; } - } + // SKIP IF NO HITS ARE ASSOCIATED TO THIS DEVIATION + if (new_deviationsVec[iDev]->hits.size() == 0) { + // ATH_MSG_DEBUG("No hits found associated to the rule " << new_deviationsVec[iDev]->stationName.str() << ", skip"); + continue; + } - } // LOOP ON NUISANCES + double rotation = new_deviationsVec[iDev]->rotation; + double traslation = new_deviationsVec[iDev]->traslation; + + Amg::Vector3D sumP = new_deviationsVec[iDev]->sumP; + Amg::Vector3D sumU = new_deviationsVec[iDev]->sumU; + Amg::Vector3D sumV = new_deviationsVec[iDev]->sumV; + double sumW2 = new_deviationsVec[iDev]->sumW2; + + sumP *= (1. / sumW2); + sumU *= (1. / sumW2); + sumV *= (1. / sumW2); + + if (traslation >= 0.001 * Gaudi::Units::mm) { + std::size_t hitshash = 0; + for (auto it : new_deviationsVec[iDev]->hits) boost::hash_combine(hitshash, (it->identify()).get_compact()); + deviations.push_back( + new AlignmentTranslationDeviation(sumU.cross(sumV), traslation * Gaudi::Units::mm, new_deviationsVec[iDev]->hits)); + deviations.back()->setHashOfHits(hitshash); + + ATH_MSG_DEBUG("A translation along (" + << sumU.x() << ", " << sumU.y() << ", " << sumU.z() << ") with sigma=" << traslation * Gaudi::Units::mm + << " mm was applied to " << new_deviationsVec[iDev]->hits.size() + << " hits matching the station: " << new_deviationsVec[iDev]->stationName.str() << " and the multilayer " + << new_deviationsVec[iDev]->multilayer.str()); + } + if (rotation >= 0.000001 * Gaudi::Units::rad) { + std::size_t hitshash = 0; + for (auto it : new_deviationsVec[iDev]->hits) boost::hash_combine(hitshash, (it->identify()).get_compact()); + deviations.push_back(new AlignmentRotationDeviation(sumP, sumV, rotation * Gaudi::Units::rad, new_deviationsVec[iDev]->hits)); + deviations.back()->setHashOfHits(hitshash); + + ATH_MSG_DEBUG("A rotation around the center = (" << sumP.x() << ", " << sumP.y() << ", " << sumP.z() << ") and axis = (" + << sumV.x() << ", " << sumV.y() << ", " << sumV.z() + << ") with sigma=" << rotation / Gaudi::Units::mrad << " mrad was applied to " + << new_deviationsVec[iDev]->hits.size() << " hits matching the station " + << new_deviationsVec[iDev]->stationName.str() << " and the multilayer " + << new_deviationsVec[iDev]->multilayer.str()); + } - ATH_MSG_DEBUG("******************************"); - ATH_MSG_DEBUG("FINAL CHECKUP"); - ATH_MSG_DEBUG("Found " << deviations.size() << " nuisances after duplicates merging"); - ATH_MSG_DEBUG("******************************"); + } // LOOP ON NUISANCES - // NOW EMPTY THE LOCAL DEVIATIONS VECTOR // - for(unsigned int iDev=0; iDev < new_deviationsVec.size(); iDev++) { - delete new_deviationsVec[iDev]; - } + ATH_MSG_DEBUG("******************************"); + ATH_MSG_DEBUG("FINAL CHECKUP"); + ATH_MSG_DEBUG("Found " << deviations.size() << " nuisances after duplicates merging"); + ATH_MSG_DEBUG("******************************"); - for(unsigned int iDev=0; iDev < devSumVec.size(); iDev++) { - delete devSumVec[iDev]; - } + // NOW EMPTY THE LOCAL DEVIATIONS VECTOR // + for (unsigned int iDev = 0; iDev < new_deviationsVec.size(); iDev++) { delete new_deviationsVec[iDev]; } - //ATH_MSG_DEBUG("Currently we have " << AlignmentErrorTool::deviationSummary_t::i_instance << " deviation vectors"); + for (unsigned int iDev = 0; iDev < devSumVec.size(); iDev++) { delete devSumVec[iDev]; } - return; + // ATH_MSG_DEBUG("Currently we have " << AlignmentErrorTool::deviationSummary_t::i_instance << " deviation vectors"); + return; } //////////////////////////// @@ -315,96 +307,92 @@ void AlignmentErrorTool::makeAlignmentDeviations (const Trk::Track& track, std:: //////////////////////////// inline std::string AlignmentErrorTool::hardwareName(MuonCalib::MuonFixedId calibId) const { - if (sector(calibId)==13) { - if (calibId.eta()== 7 && calibId.stationName()==5) return "BOE1A13"; // BOE1A13 not BOL7A13 - if (calibId.eta()==-7 && calibId.stationName()==5) return "BOE1C13"; // BOE1C13 not BOL7C13 - } - std::string etaString = "0"; - etaString[0] += std::abs(hardwareEta(calibId)); - return calibId.stationNameString() + etaString + side(calibId) + sectorString(calibId); + if (sector(calibId) == 13) { + if (calibId.eta() == 7 && calibId.stationName() == 5) return "BOE1A13"; // BOE1A13 not BOL7A13 + if (calibId.eta() == -7 && calibId.stationName() == 5) return "BOE1C13"; // BOE1C13 not BOL7C13 + } + std::string etaString = "0"; + etaString[0] += std::abs(hardwareEta(calibId)); + return calibId.stationNameString() + etaString + side(calibId) + sectorString(calibId); } inline std::string AlignmentErrorTool::side(MuonCalib::MuonFixedId calibId) const { - return calibId.eta()>0 ? "A" : calibId.eta()<0 ? "C" : "B"; + return calibId.eta() > 0 ? "A" : calibId.eta() < 0 ? "C" : "B"; } -inline std::string AlignmentErrorTool::sectorString(MuonCalib::MuonFixedId calibId) const { - std::string ret = "00"; - int sec = sector(calibId); - if (sec >= 10) { - ret[0] = '1'; - sec -= 10; - } - ret[1] += sec; - return ret; +inline std::string AlignmentErrorTool::sectorString(MuonCalib::MuonFixedId calibId) const { + std::string ret = "00"; + int sec = sector(calibId); + if (sec >= 10) { + ret[0] = '1'; + sec -= 10; + } + ret[1] += sec; + return ret; } -inline int AlignmentErrorTool::sector (MuonCalib::MuonFixedId calibId) const { - return isSmallSector(calibId) ? 2*calibId.phi() : 2*calibId.phi()-1; +inline int AlignmentErrorTool::sector(MuonCalib::MuonFixedId calibId) const { + return isSmallSector(calibId) ? 2 * calibId.phi() : 2 * calibId.phi() - 1; } -inline bool AlignmentErrorTool::isSmallSector (MuonCalib::MuonFixedId calibId) const { - switch (calibId.stationName()) { - case 2: return true; - case 4: return true; - case 6: return true; - case 7: return true; - case 9: return true; - case 10: return true; - case 11: return true; - case 17: return true; - case 20: return true; - case 23: return true; - case 24: return true; - case 33: return true; - default: return false; - } +inline bool AlignmentErrorTool::isSmallSector(MuonCalib::MuonFixedId calibId) const { + switch (calibId.stationName()) { + case 2: return true; + case 4: return true; + case 6: return true; + case 7: return true; + case 9: return true; + case 10: return true; + case 11: return true; + case 17: return true; + case 20: return true; + case 23: return true; + case 24: return true; + case 33: return true; + default: return false; + } } inline int AlignmentErrorTool::hardwareEta(MuonCalib::MuonFixedId calibId) const { - switch (calibId.stationName()) { - case 3: - { - if (sector(calibId)==13) { - switch (calibId.eta()) { - case 4: return 5; - case 5: return 6; - case 6: return 7; - case -4: return -5; - case -5: return -6; - case -6: return -7; - } - } - return calibId.eta(); - } - case 5: - { - if (sector(calibId)==13) { - if (calibId.eta()== 7) return 1; // BOE1A13 not BOL7A13 - if (calibId.eta()==-7) return -1; // BOE1C13 not BOL7C13 - } - return calibId.eta(); - } - case 10: return calibId.eta()>0 ? calibId.eta()*2-1 : calibId.eta()*2+1; - case 11: return calibId.eta()*2; - case 15: - { - if ((sector(calibId) == 1) || (sector(calibId) == 9)) { - switch (calibId.eta()) { - case 4: return 5; - case 5: return 4; - case -4: return -5; - case -5: return -4; - } + switch (calibId.stationName()) { + case 3: { + if (sector(calibId) == 13) { + switch (calibId.eta()) { + case 4: return 5; + case 5: return 6; + case 6: return 7; + case -4: return -5; + case -5: return -6; + case -6: return -7; + } + } + return calibId.eta(); + } + case 5: { + if (sector(calibId) == 13) { + if (calibId.eta() == 7) return 1; // BOE1A13 not BOL7A13 + if (calibId.eta() == -7) return -1; // BOE1C13 not BOL7C13 + } + return calibId.eta(); + } + case 10: return calibId.eta() > 0 ? calibId.eta() * 2 - 1 : calibId.eta() * 2 + 1; + case 11: return calibId.eta() * 2; + case 15: { + if ((sector(calibId) == 1) || (sector(calibId) == 9)) { + switch (calibId.eta()) { + case 4: return 5; + case 5: return 4; + case -4: return -5; + case -5: return -4; + } + } + return calibId.eta(); } - return calibId.eta(); - } - case 16: - { - if ((sector(calibId) == 5) && (calibId.eta() == 1)) return 2; - if ((sector(calibId) == 5) && (calibId.eta() == -1)) return -2; - return calibId.eta(); - } - default: return calibId.eta(); - } + case 16: { + if ((sector(calibId) == 5) && (calibId.eta() == 1)) return 2; + if ((sector(calibId) == 5) && (calibId.eta() == -1)) return -2; + return calibId.eta(); + } + default: return calibId.eta(); + } } diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorTool/src/MuonAlignErrorExampleAlg.cxx b/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorTool/src/MuonAlignErrorExampleAlg.cxx index 593725a5b48a798c72c13fbcf5b19737cfc168a7..850cfdcea9f4b18e87a0e748b7f5e63bbc092517 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorTool/src/MuonAlignErrorExampleAlg.cxx +++ b/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorTool/src/MuonAlignErrorExampleAlg.cxx @@ -3,195 +3,182 @@ */ #include "MuonAlignErrorTool/MuonAlignErrorExampleAlg.h" + +#include <iostream> + #include "MuonAlignErrorBase/AlignmentDeviation.h" -#include "TrkTrack/TrackCollection.h" #include "TrkRIO_OnTrack/RIO_OnTrack.h" -#include <iostream> +#include "TrkTrack/TrackCollection.h" using namespace MuonAlign; -MuonAlignErrorExampleAlg::MuonAlignErrorExampleAlg (const std::string& name, ISvcLocator* pSvcLocator) : - AthAlgorithm(name, pSvcLocator), - m_debug(nullptr), - m_cham_per_dev(nullptr), - m_dev_per_track(nullptr) { -} - -StatusCode MuonAlignErrorExampleAlg::initialize () { +MuonAlignErrorExampleAlg::MuonAlignErrorExampleAlg(const std::string& name, ISvcLocator* pSvcLocator) : + AthAlgorithm(name, pSvcLocator), m_debug(nullptr), m_cham_per_dev(nullptr), m_dev_per_track(nullptr) {} - m_debug = new TFile("muonalignerrordebug.root", "RECREATE"); - m_debug->cd(); - m_cham_per_dev = new TH1F("cham_per_dev", "# of chamber layers per alignment deviation", 10, 0., 10.); - m_dev_per_track = new TH1F("dev_per_track", "# of chamber layers per alignment deviation", 10, 0., 10.); +StatusCode MuonAlignErrorExampleAlg::initialize() { + m_debug = new TFile("muonalignerrordebug.root", "RECREATE"); + m_debug->cd(); + m_cham_per_dev = new TH1F("cham_per_dev", "# of chamber layers per alignment deviation", 10, 0., 10.); + m_dev_per_track = new TH1F("dev_per_track", "# of chamber layers per alignment deviation", 10, 0., 10.); - ATH_CHECK(m_idHelperSvc.retrieve()); + ATH_CHECK(m_idHelperSvc.retrieve()); - return StatusCode::SUCCESS; + return StatusCode::SUCCESS; } -StatusCode MuonAlignErrorExampleAlg::execute () { - StatusCode sc; - const ::TrackCollection* tracks = 0; - sc = sgSvc()->retrieve(tracks, "MuonSpectrometerTracks"); // for example, should be a job option - if(sc.isFailure()) return sc; +StatusCode MuonAlignErrorExampleAlg::execute() { + StatusCode sc; + const ::TrackCollection* tracks = 0; + sc = sgSvc()->retrieve(tracks, "MuonSpectrometerTracks"); // for example, should be a job option + if (sc.isFailure()) return sc; - // LOOP ON MUON TRACKS // - for (::TrackCollection::const_iterator it=tracks->begin(), end=tracks->end(); it!=end; it++) { - - const Trk::Track* track = *it; - muonTrack(track); - - } + // LOOP ON MUON TRACKS // + for (::TrackCollection::const_iterator it = tracks->begin(), end = tracks->end(); it != end; it++) { + const Trk::Track* track = *it; + muonTrack(track); + } - return StatusCode::SUCCESS; + return StatusCode::SUCCESS; } -void MuonAlignErrorExampleAlg::muonTrack (const Trk::Track* track) const { - // Compute and verbose the alignment deviations for a given track - - ATH_MSG_DEBUG("Processing track with momentum " << track->trackParameters()->front()->momentum().mag()/1000. << " GeV and transverse momentum " << track->trackParameters()->front()->momentum().perp()/1000 << " GeV"); - - std::vector<Trk::AlignmentDeviation*> deviations; - m_alignErrorTool->makeAlignmentDeviations(*track, deviations); - - - // DEBUG - m_dev_per_track->Fill(deviations.size()); - std::vector<const Trk::RIO_OnTrack*> hits; - - // DO SOME CHECKS AND THEN CLEAN UP - for (std::vector<Trk::AlignmentDeviation*>::iterator it(deviations.begin()), end(deviations.end()); it!=end; ++it) { - - (*it)->getListOfHits(hits); - - std::set<std::string> myidset_all; - for(std::vector<const Trk::RIO_OnTrack*>::iterator jt(hits.begin()), end(hits.end()); jt!=end; ++jt) { - // JOCHEN WAY - Identifier myid = ((const Trk::RIO_OnTrack*)(*jt))->identify(); +void MuonAlignErrorExampleAlg::muonTrack(const Trk::Track* track) const { + // Compute and verbose the alignment deviations for a given track + + ATH_MSG_DEBUG("Processing track with momentum " << track->trackParameters()->front()->momentum().mag() / 1000. + << " GeV and transverse momentum " + << track->trackParameters()->front()->momentum().perp() / 1000 << " GeV"); + + std::vector<Trk::AlignmentDeviation*> deviations; + m_alignErrorTool->makeAlignmentDeviations(*track, deviations); + + // DEBUG + m_dev_per_track->Fill(deviations.size()); + std::vector<const Trk::RIO_OnTrack*> hits; + + // DO SOME CHECKS AND THEN CLEAN UP + for (std::vector<Trk::AlignmentDeviation*>::iterator it(deviations.begin()), end(deviations.end()); it != end; ++it) { + (*it)->getListOfHits(hits); + + std::set<std::string> myidset_all; + for (std::vector<const Trk::RIO_OnTrack*>::iterator jt(hits.begin()), end(hits.end()); jt != end; ++jt) { + // JOCHEN WAY + Identifier myid = ((const Trk::RIO_OnTrack*)(*jt))->identify(); + + if (!(m_idHelperSvc->isMM(myid) || m_idHelperSvc->issTgc(myid))) { + // CAMILLA WAY + MuonCalib::MuonFixedId calibId = m_idTool->idToFixedId(myid); + if (!calibId.isValid()) { continue; } + std::string completename = hardwareName(calibId); + myidset_all.insert(completename.substr(0, 2)); + } else + myidset_all.insert(m_idHelperSvc->toStringStation(myid)); + } + m_cham_per_dev->Fill(myidset_all.size()); - if (!(m_idHelperSvc->isMM(myid)||m_idHelperSvc->issTgc(myid))) { - // CAMILLA WAY - MuonCalib::MuonFixedId calibId = m_idTool->idToFixedId(myid); - if (!calibId.isValid()) { - continue; - } - std::string completename = hardwareName(calibId); - myidset_all.insert(completename.substr(0,2)); - } else myidset_all.insert(m_idHelperSvc->toStringStation(myid)); + // cleanup + delete (*it); } - m_cham_per_dev->Fill(myidset_all.size()); - - // cleanup - delete (*it); - - } } -StatusCode MuonAlignErrorExampleAlg::finalize () { - - m_debug->Write(); - //m_cham_per_dev->Write(); - //m_dev_per_track->Write(); - m_debug->Close(); +StatusCode MuonAlignErrorExampleAlg::finalize() { + m_debug->Write(); + // m_cham_per_dev->Write(); + // m_dev_per_track->Write(); + m_debug->Close(); - return StatusCode::SUCCESS; + return StatusCode::SUCCESS; } - //////////////////////////// // RECOGNIZE STATION NAME // //////////////////////////// inline std::string MuonAlignErrorExampleAlg::hardwareName(MuonCalib::MuonFixedId calibId) const { - if (sector(calibId)==13) { - if (calibId.eta()== 7 && calibId.stationName()==5) return "BOE1A13"; // BOE1A13 not BOL7A13 - if (calibId.eta()==-7 && calibId.stationName()==5) return "BOE1C13"; // BOE1C13 not BOL7C13 - } - std::string etaString = "0"; - etaString[0] += std::abs(hardwareEta(calibId)); - return calibId.stationNameString() + etaString + side(calibId) + sectorString(calibId); + if (sector(calibId) == 13) { + if (calibId.eta() == 7 && calibId.stationName() == 5) return "BOE1A13"; // BOE1A13 not BOL7A13 + if (calibId.eta() == -7 && calibId.stationName() == 5) return "BOE1C13"; // BOE1C13 not BOL7C13 + } + std::string etaString = "0"; + etaString[0] += std::abs(hardwareEta(calibId)); + return calibId.stationNameString() + etaString + side(calibId) + sectorString(calibId); } inline std::string MuonAlignErrorExampleAlg::side(MuonCalib::MuonFixedId calibId) const { - return calibId.eta()>0 ? "A" : calibId.eta()<0 ? "C" : "B"; + return calibId.eta() > 0 ? "A" : calibId.eta() < 0 ? "C" : "B"; } -inline std::string MuonAlignErrorExampleAlg::sectorString(MuonCalib::MuonFixedId calibId) const { - std::string ret = "00"; - int sec = sector(calibId); - if (sec >= 10) { - ret[0] = '1'; - sec -= 10; - } - ret[1] += sec; - return ret; +inline std::string MuonAlignErrorExampleAlg::sectorString(MuonCalib::MuonFixedId calibId) const { + std::string ret = "00"; + int sec = sector(calibId); + if (sec >= 10) { + ret[0] = '1'; + sec -= 10; + } + ret[1] += sec; + return ret; } -inline int MuonAlignErrorExampleAlg::sector (MuonCalib::MuonFixedId calibId) const { - return isSmallSector(calibId) ? 2*calibId.phi() : 2*calibId.phi()-1; +inline int MuonAlignErrorExampleAlg::sector(MuonCalib::MuonFixedId calibId) const { + return isSmallSector(calibId) ? 2 * calibId.phi() : 2 * calibId.phi() - 1; } -inline bool MuonAlignErrorExampleAlg::isSmallSector (MuonCalib::MuonFixedId calibId) const { - switch (calibId.stationName()) { - case 2: return true; - case 4: return true; - case 6: return true; - case 7: return true; - case 9: return true; - case 10: return true; - case 11: return true; - case 17: return true; - case 20: return true; - case 23: return true; - case 24: return true; - case 33: return true; - default: return false; - } +inline bool MuonAlignErrorExampleAlg::isSmallSector(MuonCalib::MuonFixedId calibId) const { + switch (calibId.stationName()) { + case 2: return true; + case 4: return true; + case 6: return true; + case 7: return true; + case 9: return true; + case 10: return true; + case 11: return true; + case 17: return true; + case 20: return true; + case 23: return true; + case 24: return true; + case 33: return true; + default: return false; + } } inline int MuonAlignErrorExampleAlg::hardwareEta(MuonCalib::MuonFixedId calibId) const { - switch (calibId.stationName()) { - case 3: - { - if (sector(calibId)==13) { - switch (calibId.eta()) { - case 4: return 5; - case 5: return 6; - case 6: return 7; - case -4: return -5; - case -5: return -6; - case -6: return -7; - } - } - return calibId.eta(); - } - case 5: - { - if (sector(calibId)==13) { - if (calibId.eta()== 7) return 1; // BOE1A13 not BOL7A13 - if (calibId.eta()==-7) return -1; // BOE1C13 not BOL7C13 - } - return calibId.eta(); - } - case 10: return calibId.eta()>0 ? calibId.eta()*2-1 : calibId.eta()*2+1; - case 11: return calibId.eta()*2; - case 15: - { - if ((sector(calibId) == 1) || (sector(calibId) == 9)) { - switch (calibId.eta()) { - case 4: return 5; - case 5: return 4; - case -4: return -5; - case -5: return -4; - } + switch (calibId.stationName()) { + case 3: { + if (sector(calibId) == 13) { + switch (calibId.eta()) { + case 4: return 5; + case 5: return 6; + case 6: return 7; + case -4: return -5; + case -5: return -6; + case -6: return -7; + } + } + return calibId.eta(); + } + case 5: { + if (sector(calibId) == 13) { + if (calibId.eta() == 7) return 1; // BOE1A13 not BOL7A13 + if (calibId.eta() == -7) return -1; // BOE1C13 not BOL7C13 + } + return calibId.eta(); } - return calibId.eta(); - } - case 16: - { - if ((sector(calibId) == 5) && (calibId.eta() == 1)) return 2; - if ((sector(calibId) == 5) && (calibId.eta() == -1)) return -2; - return calibId.eta(); - } - default: return calibId.eta(); - } + case 10: return calibId.eta() > 0 ? calibId.eta() * 2 - 1 : calibId.eta() * 2 + 1; + case 11: return calibId.eta() * 2; + case 15: { + if ((sector(calibId) == 1) || (sector(calibId) == 9)) { + switch (calibId.eta()) { + case 4: return 5; + case 5: return 4; + case -4: return -5; + case -5: return -4; + } + } + return calibId.eta(); + } + case 16: { + if ((sector(calibId) == 5) && (calibId.eta() == 1)) return 2; + if ((sector(calibId) == 5) && (calibId.eta() == -1)) return -2; + return calibId.eta(); + } + default: return calibId.eta(); + } } diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorTool/src/components/MuonAlignErrorTool_entries.cxx b/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorTool/src/components/MuonAlignErrorTool_entries.cxx index 350f2eda9c0e293fc9472b7d855d2249ca5b4109..0797cec68e7dcb1dcea9db1d8286ae59467bb9f8 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorTool/src/components/MuonAlignErrorTool_entries.cxx +++ b/MuonSpectrometer/MuonAlignment/MuonAlignError/MuonAlignErrorTool/src/components/MuonAlignErrorTool_entries.cxx @@ -1,6 +1,5 @@ -#include "MuonAlignErrorTool/MuonAlignErrorExampleAlg.h" #include "MuonAlignErrorTool/AlignmentErrorTool.h" +#include "MuonAlignErrorTool/MuonAlignErrorExampleAlg.h" -DECLARE_COMPONENT( MuonAlign::MuonAlignErrorExampleAlg ) -DECLARE_COMPONENT( MuonAlign::AlignmentErrorTool ) - +DECLARE_COMPONENT(MuonAlign::MuonAlignErrorExampleAlg) +DECLARE_COMPONENT(MuonAlign::AlignmentErrorTool) diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignEvent/MuonAlignEvent/CombinedMuonAlignModule.h b/MuonSpectrometer/MuonAlignment/MuonAlignEvent/MuonAlignEvent/CombinedMuonAlignModule.h index e5dca6b8af00c36eb1bc21ace1ffe2a385f55d55..b569bb28ee152966438fa706568d75157f9560d3 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignEvent/MuonAlignEvent/CombinedMuonAlignModule.h +++ b/MuonSpectrometer/MuonAlignment/MuonAlignEvent/MuonAlignEvent/CombinedMuonAlignModule.h @@ -5,59 +5,52 @@ #ifndef MUONALIGNGENALGS_COMBINEDMUONALIGNMODULE_H #define MUONALIGNGENALGS_COMBINEDMUONALIGNMODULE_H -#include "TrkAlignEvent/AlignModule.h" -#include "TrkAlignEvent/AlignPar.h" - #include <iostream> #include <vector> +#include "TrkAlignEvent/AlignModule.h" +#include "TrkAlignEvent/AlignPar.h" + /** @file CombinedMuonAlignModule.h @class CombinedMuonAlignModule - @brief CombinedMuonAlignModule is a grouping of MdtReadoutElements, + @brief CombinedMuonAlignModule is a grouping of MdtReadoutElements, TgcReadoutElements, and RpcReadoutElements, grouped according to the type of alignment. @author Robert Harrington <roberth@bu.edu> @date 06/09/2009 */ - namespace MuonGM { - class MdtReadoutElement; - class TgcReadoutElement; - class RpcReadoutElement; -} - + class MdtReadoutElement; + class TgcReadoutElement; + class RpcReadoutElement; +} // namespace MuonGM namespace Muon { - - class CombinedMuonAlignModule : public Trk::AlignModule { - - public: - - /** Constructor using AlgTool gives a MsgStream with CombinedMuonAlignModule for name - and the the same output level as the AlgTool. */ - CombinedMuonAlignModule(const AlgTool* algtool, - const Amg::Transform3D& transform=Amg::Transform3D::Identity()); - - /** This constructor gives a MsgStream with the name of the tool that created - the CombinedMuonAlignModule and the same output level. */ - CombinedMuonAlignModule(MsgStream* log, - const Amg::Transform3D& transform=Amg::Transform3D::Identity()); - - virtual ~CombinedMuonAlignModule(); - - virtual void shiftSurface(Trk::TrkDetElementBase* det, Identifier tubeId) const; - virtual void restoreSurfaces(Trk::TrkDetElementBase* mre) const; - - private: - - MsgStream* m_log; - CombinedMuonAlignModule & operator=(const CombinedMuonAlignModule &right); - CombinedMuonAlignModule(const CombinedMuonAlignModule&); - - }; // end class - -} // end namespace - -#endif // MUONALIGNGENALGS_COMBINEDMUONALIGNMODULE_H + + class CombinedMuonAlignModule : public Trk::AlignModule { + public: + /** Constructor using AlgTool gives a MsgStream with CombinedMuonAlignModule for name + and the the same output level as the AlgTool. */ + CombinedMuonAlignModule(const AlgTool* algtool, const Amg::Transform3D& transform = Amg::Transform3D::Identity()); + + /** This constructor gives a MsgStream with the name of the tool that created + the CombinedMuonAlignModule and the same output level. */ + CombinedMuonAlignModule(MsgStream* log, const Amg::Transform3D& transform = Amg::Transform3D::Identity()); + + virtual ~CombinedMuonAlignModule(); + + virtual void shiftSurface(Trk::TrkDetElementBase* det, Identifier tubeId) const; + virtual void restoreSurfaces(Trk::TrkDetElementBase* mre) const; + + private: + MsgStream* m_log; + CombinedMuonAlignModule& operator=(const CombinedMuonAlignModule& right); + CombinedMuonAlignModule(const CombinedMuonAlignModule&); + + }; // end class + +} // namespace Muon + +#endif // MUONALIGNGENALGS_COMBINEDMUONALIGNMODULE_H diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignEvent/MuonAlignEvent/CscAlignModule.h b/MuonSpectrometer/MuonAlignment/MuonAlignEvent/MuonAlignEvent/CscAlignModule.h index 4d58123f3f5d50917f1361cb9e2383bc925bb417..0aceca2728d79815265d422c91beddb531913e6b 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignEvent/MuonAlignEvent/CscAlignModule.h +++ b/MuonSpectrometer/MuonAlignment/MuonAlignEvent/MuonAlignEvent/CscAlignModule.h @@ -5,13 +5,13 @@ #ifndef MUONALIGNGENALGS_CSCALIGNMODULE_H #define MUONALIGNGENALGS_CSCALIGNMODULE_H -#include "TrkAlignEvent/AlignModule.h" -#include "TrkAlignEvent/AlignPar.h" -#include "MuonAlignEvent/CombinedMuonAlignModule.h" - #include <iostream> #include <vector> +#include "MuonAlignEvent/CombinedMuonAlignModule.h" +#include "TrkAlignEvent/AlignModule.h" +#include "TrkAlignEvent/AlignPar.h" + /** @file CscAlignModule.h @class CscAlignModule @@ -27,49 +27,43 @@ class TFile; class TTree; namespace MuonGM { - class CscReadoutElement; + class CscReadoutElement; } namespace Muon { - - class CscAlignModule : public CombinedMuonAlignModule { - - public: - - /** Constructor using AlgTool gives a MsgStream with CscAlignModule for name - and the the same output level as the AlgTool. */ - CscAlignModule(const AlgTool* algtool, - const Amg::Transform3D& transform=Amg::Transform3D::Identity()); - - /** This constructor gives a MsgStream with the name of the tool that created - the CscAlignModule and the same output level. */ - CscAlignModule(MsgStream* log, - const Amg::Transform3D& transform=Amg::Transform3D::Identity()); - - virtual ~CscAlignModule(); - - /** tree in m_rootfile used to store positions of tubes in chambers */ - TFile* getRootFile() { return m_rootfile; } - TTree* getTubePositionTree() { return m_tubePositionTree; } - void setRootFile(TFile* file) { m_rootfile=file; } - void setTubePositionTree(TTree* tree) { m_tubePositionTree=tree; } - - //void shiftSurface(Trk::TrkDetElementBase* det, Identifier tubeId) const; - //void restoreSurfaces(Trk::TrkDetElementBase* mre) const; - - private: - - - /** tree used to store positions of tubes for drawing hits and troubleshooting */ - TFile* m_rootfile; - TTree* m_tubePositionTree; - - MsgStream* m_log; - CscAlignModule & operator=(const CscAlignModule &right); - CscAlignModule(const CscAlignModule&); - - }; // end class - -} // end namespace - -#endif // MUONALIGNGENALGS_CSCALIGNMODULE_H + + class CscAlignModule : public CombinedMuonAlignModule { + public: + /** Constructor using AlgTool gives a MsgStream with CscAlignModule for name + and the the same output level as the AlgTool. */ + CscAlignModule(const AlgTool* algtool, const Amg::Transform3D& transform = Amg::Transform3D::Identity()); + + /** This constructor gives a MsgStream with the name of the tool that created + the CscAlignModule and the same output level. */ + CscAlignModule(MsgStream* log, const Amg::Transform3D& transform = Amg::Transform3D::Identity()); + + virtual ~CscAlignModule(); + + /** tree in m_rootfile used to store positions of tubes in chambers */ + TFile* getRootFile() { return m_rootfile; } + TTree* getTubePositionTree() { return m_tubePositionTree; } + void setRootFile(TFile* file) { m_rootfile = file; } + void setTubePositionTree(TTree* tree) { m_tubePositionTree = tree; } + + // void shiftSurface(Trk::TrkDetElementBase* det, Identifier tubeId) const; + // void restoreSurfaces(Trk::TrkDetElementBase* mre) const; + + private: + /** tree used to store positions of tubes for drawing hits and troubleshooting */ + TFile* m_rootfile; + TTree* m_tubePositionTree; + + MsgStream* m_log; + CscAlignModule& operator=(const CscAlignModule& right); + CscAlignModule(const CscAlignModule&); + + }; // end class + +} // namespace Muon + +#endif // MUONALIGNGENALGS_CSCALIGNMODULE_H diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignEvent/MuonAlignEvent/MdtAlignModule.h b/MuonSpectrometer/MuonAlignment/MuonAlignEvent/MuonAlignEvent/MdtAlignModule.h index c33f09a12a73a72c19728e1247cd46958328bb04..e4152cc4bba284d00dc8b516c5ccb8ec57cfeaf8 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignEvent/MuonAlignEvent/MdtAlignModule.h +++ b/MuonSpectrometer/MuonAlignment/MuonAlignEvent/MuonAlignEvent/MdtAlignModule.h @@ -5,13 +5,13 @@ #ifndef MUONALIGNGENALGS_MDTALIGNMODULE_H #define MUONALIGNGENALGS_MDTALIGNMODULE_H -#include "TrkAlignEvent/AlignModule.h" -#include "TrkAlignEvent/AlignPar.h" -#include "MuonAlignEvent/CombinedMuonAlignModule.h" - #include <iostream> #include <vector> +#include "MuonAlignEvent/CombinedMuonAlignModule.h" +#include "TrkAlignEvent/AlignModule.h" +#include "TrkAlignEvent/AlignPar.h" + /** @file MdtAlignModule.h @class MdtAlignModule @@ -31,49 +31,43 @@ class TFile; class TTree; namespace MuonGM { - class MdtReadoutElement; + class MdtReadoutElement; } namespace Muon { - - class MdtAlignModule : public CombinedMuonAlignModule { - - public: - - /** Constructor using AlgTool gives a MsgStream with MdtAlignModule for name - and the the same output level as the AlgTool. */ - MdtAlignModule(const AlgTool* algtool, - const Amg::Transform3D& transform=Amg::Transform3D::Identity()); - - /** This constructor gives a MsgStream with the name of the tool that created - the MdtAlignModule and the same output level. */ - MdtAlignModule(MsgStream* log, - const Amg::Transform3D& transform=Amg::Transform3D::Identity()); - - virtual ~MdtAlignModule(); - - /** tree in m_rootfile used to store positions of tubes in chambers */ - TFile* getRootFile() { return m_rootfile; } - TTree* getTubePositionTree() { return m_tubePositionTree; } - void setRootFile(TFile* file) { m_rootfile=file; } - void setTubePositionTree(TTree* tree) { m_tubePositionTree=tree; } - - //void shiftSurface(Trk::TrkDetElementBase* det, Identifier tubeId) const; - //void restoreSurfaces(Trk::TrkDetElementBase* mre) const; - - private: - - - /** tree used to store positions of tubes for drawing hits and troubleshooting */ - TFile* m_rootfile; - TTree* m_tubePositionTree; - - MsgStream* m_log; - MdtAlignModule & operator=(const MdtAlignModule &right); - MdtAlignModule(const MdtAlignModule&); - - }; // end class - -} // end namespace - -#endif // MUONALIGNGENALGS_MDTALIGNMODULE_H + + class MdtAlignModule : public CombinedMuonAlignModule { + public: + /** Constructor using AlgTool gives a MsgStream with MdtAlignModule for name + and the the same output level as the AlgTool. */ + MdtAlignModule(const AlgTool* algtool, const Amg::Transform3D& transform = Amg::Transform3D::Identity()); + + /** This constructor gives a MsgStream with the name of the tool that created + the MdtAlignModule and the same output level. */ + MdtAlignModule(MsgStream* log, const Amg::Transform3D& transform = Amg::Transform3D::Identity()); + + virtual ~MdtAlignModule(); + + /** tree in m_rootfile used to store positions of tubes in chambers */ + TFile* getRootFile() { return m_rootfile; } + TTree* getTubePositionTree() { return m_tubePositionTree; } + void setRootFile(TFile* file) { m_rootfile = file; } + void setTubePositionTree(TTree* tree) { m_tubePositionTree = tree; } + + // void shiftSurface(Trk::TrkDetElementBase* det, Identifier tubeId) const; + // void restoreSurfaces(Trk::TrkDetElementBase* mre) const; + + private: + /** tree used to store positions of tubes for drawing hits and troubleshooting */ + TFile* m_rootfile; + TTree* m_tubePositionTree; + + MsgStream* m_log; + MdtAlignModule& operator=(const MdtAlignModule& right); + MdtAlignModule(const MdtAlignModule&); + + }; // end class + +} // namespace Muon + +#endif // MUONALIGNGENALGS_MDTALIGNMODULE_H diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignEvent/MuonAlignEvent/RpcAlignModule.h b/MuonSpectrometer/MuonAlignment/MuonAlignEvent/MuonAlignEvent/RpcAlignModule.h index 6505c95f1440981f0c9e172baa0744e035b7c2c4..a5e18256f1774a15e600b65865e976d722243c8f 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignEvent/MuonAlignEvent/RpcAlignModule.h +++ b/MuonSpectrometer/MuonAlignment/MuonAlignEvent/MuonAlignEvent/RpcAlignModule.h @@ -5,18 +5,18 @@ #ifndef MUONALIGNGENALGS_RPCALIGNMODULE_H #define MUONALIGNGENALGS_RPCALIGNMODULE_H -#include "TrkAlignEvent/AlignModule.h" -#include "TrkAlignEvent/AlignPar.h" -#include "MuonAlignEvent/CombinedMuonAlignModule.h" - #include <iostream> #include <vector> +#include "MuonAlignEvent/CombinedMuonAlignModule.h" +#include "TrkAlignEvent/AlignModule.h" +#include "TrkAlignEvent/AlignPar.h" + /** @file RpcAlignModule.h @class RpcAlignModule - @brief RpcAlignModule is a grouping of RpcReadoutElements, grouped + @brief RpcAlignModule is a grouping of RpcReadoutElements, grouped according to the type of alignment. @author Robert Harrington <roberth@bu.edu> @@ -27,37 +27,31 @@ class TFile; class TTree; namespace MuonGM { - class RpcReadoutElement; + class RpcReadoutElement; } namespace Muon { - - class RpcAlignModule : public CombinedMuonAlignModule { - - public: - - /** Constructor using AlgTool gives a MsgStream with RpcAlignModule for name and the the same output level as the AlgTool. */ - RpcAlignModule(const AlgTool* algtool, - const Amg::Transform3D& transform=Amg::Transform3D::Identity()); - /** This constructor gives a MsgStream with the name of the tool that created the RpcAlignModule and the same output level. */ - RpcAlignModule(MsgStream* log, - const Amg::Transform3D& transform=Amg::Transform3D::Identity()); + class RpcAlignModule : public CombinedMuonAlignModule { + public: + /** Constructor using AlgTool gives a MsgStream with RpcAlignModule for name and the the same output level as the AlgTool. */ + RpcAlignModule(const AlgTool* algtool, const Amg::Transform3D& transform = Amg::Transform3D::Identity()); - virtual ~RpcAlignModule(); + /** This constructor gives a MsgStream with the name of the tool that created the RpcAlignModule and the same output level. */ + RpcAlignModule(MsgStream* log, const Amg::Transform3D& transform = Amg::Transform3D::Identity()); - //void shiftSurface(Trk::TrkDetElementBase* det, Identifier id) const; - //void restoreSurfaces(Trk::TrkDetElementBase* tre) const; + virtual ~RpcAlignModule(); - private: + // void shiftSurface(Trk::TrkDetElementBase* det, Identifier id) const; + // void restoreSurfaces(Trk::TrkDetElementBase* tre) const; + private: + MsgStream* m_log; + RpcAlignModule& operator=(const RpcAlignModule& right); + RpcAlignModule(const RpcAlignModule&); - MsgStream* m_log; - RpcAlignModule & operator=(const RpcAlignModule &right); - RpcAlignModule(const RpcAlignModule&); + }; // end class - }; // end class - -} // end namespace +} // namespace Muon -#endif // MUONALIGNGENALGS_RPCALIGNMODULE_H +#endif // MUONALIGNGENALGS_RPCALIGNMODULE_H diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignEvent/MuonAlignEvent/TgcAlignModule.h b/MuonSpectrometer/MuonAlignment/MuonAlignEvent/MuonAlignEvent/TgcAlignModule.h index 69c96badf32be18938c99b14843a56e2627f445d..389e565dd764d807ce1ca2850d239dfda12df2c8 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignEvent/MuonAlignEvent/TgcAlignModule.h +++ b/MuonSpectrometer/MuonAlignment/MuonAlignEvent/MuonAlignEvent/TgcAlignModule.h @@ -5,13 +5,13 @@ #ifndef MUONALIGNGENALGS_TGCALIGNMODULE_H #define MUONALIGNGENALGS_TGCALIGNMODULE_H -#include "TrkAlignEvent/AlignModule.h" -#include "TrkAlignEvent/AlignPar.h" -#include "MuonAlignEvent/CombinedMuonAlignModule.h" - #include <iostream> #include <vector> +#include "MuonAlignEvent/CombinedMuonAlignModule.h" +#include "TrkAlignEvent/AlignModule.h" +#include "TrkAlignEvent/AlignPar.h" + /** @file TgcAlignModule.h @class TgcAlignModule @@ -30,49 +30,44 @@ class TFile; class TTree; namespace MuonGM { - class TgcReadoutElement; + class TgcReadoutElement; } namespace Muon { - - class TgcAlignModule : public CombinedMuonAlignModule { - - public: - - /** Constructor using AlgTool gives a MsgStream with TgcAlignModule for name and the the same output level as the AlgTool. */ - TgcAlignModule(const AlgTool* algtool, - const Amg::Transform3D& transform=Amg::Transform3D::Identity()); - - /** This constructor gives a MsgStream with the name of the tool that created the TgcAlignModule and the same output level. */ - TgcAlignModule(MsgStream* log, - const Amg::Transform3D& transform=Amg::Transform3D::Identity()); - - virtual ~TgcAlignModule(); - - /** trees in m_rootfile used to store positions of strips and wires in chambers */ - TFile* getRootFile() { return m_rootfile; } - TTree* getStripPositionTree() { return m_stripPositionTree; } - TTree* getWirePositionTree() { return m_wirePositionTree; } - void setRootFile(TFile* file) { m_rootfile=file; } - void setStripPositionTree(TTree* tree) { m_stripPositionTree=tree; } - void setWirePositionTree(TTree* tree) { m_wirePositionTree=tree; } - - //void shiftSurface(Trk::TrkDetElementBase* det, Identifier id) const; - //void restoreSurfaces(Trk::TrkDetElementBase* tre) const; - - private: - - /** trees used to store positions of stripts and wires for drawing hits and troubleshooting */ - TFile* m_rootfile; - TTree* m_stripPositionTree; - TTree* m_wirePositionTree; - - MsgStream* m_log; - TgcAlignModule & operator=(const TgcAlignModule &right); - TgcAlignModule(const TgcAlignModule&); - - }; // end class - -} // end namespace - -#endif // MUONALIGNGENALGS_TGCALIGNMODULE_H + + class TgcAlignModule : public CombinedMuonAlignModule { + public: + /** Constructor using AlgTool gives a MsgStream with TgcAlignModule for name and the the same output level as the AlgTool. */ + TgcAlignModule(const AlgTool* algtool, const Amg::Transform3D& transform = Amg::Transform3D::Identity()); + + /** This constructor gives a MsgStream with the name of the tool that created the TgcAlignModule and the same output level. */ + TgcAlignModule(MsgStream* log, const Amg::Transform3D& transform = Amg::Transform3D::Identity()); + + virtual ~TgcAlignModule(); + + /** trees in m_rootfile used to store positions of strips and wires in chambers */ + TFile* getRootFile() { return m_rootfile; } + TTree* getStripPositionTree() { return m_stripPositionTree; } + TTree* getWirePositionTree() { return m_wirePositionTree; } + void setRootFile(TFile* file) { m_rootfile = file; } + void setStripPositionTree(TTree* tree) { m_stripPositionTree = tree; } + void setWirePositionTree(TTree* tree) { m_wirePositionTree = tree; } + + // void shiftSurface(Trk::TrkDetElementBase* det, Identifier id) const; + // void restoreSurfaces(Trk::TrkDetElementBase* tre) const; + + private: + /** trees used to store positions of stripts and wires for drawing hits and troubleshooting */ + TFile* m_rootfile; + TTree* m_stripPositionTree; + TTree* m_wirePositionTree; + + MsgStream* m_log; + TgcAlignModule& operator=(const TgcAlignModule& right); + TgcAlignModule(const TgcAlignModule&); + + }; // end class + +} // namespace Muon + +#endif // MUONALIGNGENALGS_TGCALIGNMODULE_H diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignEvent/doc/packagedoc.h b/MuonSpectrometer/MuonAlignment/MuonAlignEvent/doc/packagedoc.h index 7e6b23660546f0e7b2bfdf1c28e115dab72da8cb..300cd94b96ad1210f748510ee1fdd5746266ad4c 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignEvent/doc/packagedoc.h +++ b/MuonSpectrometer/MuonAlignment/MuonAlignEvent/doc/packagedoc.h @@ -13,7 +13,8 @@ This package contains classes to be used for alignment of muon chambers. @section MuonAlignEvent_MuonAlignEventOverview Class Overview The package contains the following classes: - - MdtAlignModule: a generalized alignable module, consisting of groups of MDT detectors to be aligned as a single structure. Inherits from Trk::AlignModule. + - MdtAlignModule: a generalized alignable module, consisting of groups of MDT detectors to be aligned as a single structure. Inherits +from Trk::AlignModule. diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignEvent/src/CombinedMuonAlignModule.cxx b/MuonSpectrometer/MuonAlignment/MuonAlignEvent/src/CombinedMuonAlignModule.cxx index 09d36222570b790cd5be4bad864fe90d589c9cab..c7685240078e4933b300ccbc7b3ea2c633fa67e1 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignEvent/src/CombinedMuonAlignModule.cxx +++ b/MuonSpectrometer/MuonAlignment/MuonAlignEvent/src/CombinedMuonAlignModule.cxx @@ -2,97 +2,88 @@ Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration */ -#include "AthenaBaseComps/AthAlgTool.h" +#include "MuonAlignEvent/CombinedMuonAlignModule.h" +#include "AthenaBaseComps/AthAlgTool.h" +#include "MuonReadoutGeometry/CscReadoutElement.h" #include "MuonReadoutGeometry/MdtReadoutElement.h" -#include "MuonReadoutGeometry/TgcReadoutElement.h" #include "MuonReadoutGeometry/RpcReadoutElement.h" -#include "MuonReadoutGeometry/CscReadoutElement.h" - -#include "MuonAlignEvent/CombinedMuonAlignModule.h" +#include "MuonReadoutGeometry/TgcReadoutElement.h" namespace Muon { - - //________________________________________________________________________ - CombinedMuonAlignModule::CombinedMuonAlignModule(MsgStream* log, - const Amg::Transform3D& transform) - : AlignModule(log,transform) - , m_log(new MsgStream(*log)) - { - } - - //________________________________________________________________________ - CombinedMuonAlignModule::CombinedMuonAlignModule(const AlgTool* algtool, - const Amg::Transform3D& transform) - : AlignModule(algtool,transform) - , m_log(new MsgStream(algtool->msgSvc(),"CombinedMuonAlignModule")) - { - const AthAlgTool* athAlgTool=dynamic_cast<const AthAlgTool*>(algtool); - if (athAlgTool) - m_log->setLevel(athAlgTool->msg().level()); - } - - //________________________________________________________________________ - CombinedMuonAlignModule::~CombinedMuonAlignModule() - { - - delete m_log; - } - - //________________________________________________________________________ - void CombinedMuonAlignModule::shiftSurface(Trk::TrkDetElementBase* det, - Identifier id) const - { - - MuonGM::MdtReadoutElement* mdt=dynamic_cast<MuonGM::MdtReadoutElement*>(det); - if (mdt) { - mdt->shiftTube(id); - return; + + //________________________________________________________________________ + CombinedMuonAlignModule::CombinedMuonAlignModule(MsgStream* log, const Amg::Transform3D& transform) : + AlignModule(log, transform), m_log(new MsgStream(*log)) {} + + //________________________________________________________________________ + CombinedMuonAlignModule::CombinedMuonAlignModule(const AlgTool* algtool, const Amg::Transform3D& transform) : + AlignModule(algtool, transform), m_log(new MsgStream(algtool->msgSvc(), "CombinedMuonAlignModule")) { + const AthAlgTool* athAlgTool = dynamic_cast<const AthAlgTool*>(algtool); + if (athAlgTool) m_log->setLevel(athAlgTool->msg().level()); } - - MuonGM::TgcReadoutElement* tgc=dynamic_cast<MuonGM::TgcReadoutElement*>(det); - if (tgc) { - tgc->shiftSurface(id); - return; + //________________________________________________________________________ + CombinedMuonAlignModule::~CombinedMuonAlignModule() { delete m_log; } + + //________________________________________________________________________ + void CombinedMuonAlignModule::shiftSurface(Trk::TrkDetElementBase* det, Identifier id) const { + MuonGM::MdtReadoutElement* mdt = dynamic_cast<MuonGM::MdtReadoutElement*>(det); + if (mdt) { + mdt->shiftTube(id); + return; + } + + MuonGM::TgcReadoutElement* tgc = dynamic_cast<MuonGM::TgcReadoutElement*>(det); + if (tgc) { + tgc->shiftSurface(id); + return; + } + + MuonGM::RpcReadoutElement* rpc = dynamic_cast<MuonGM::RpcReadoutElement*>(det); + if (rpc) { + rpc->shiftSurface(id); + return; + } + + MuonGM::CscReadoutElement* csc = dynamic_cast<MuonGM::CscReadoutElement*>(det); + if (csc) { + csc->shiftSurface(id); + return; + } + + return; } - MuonGM::RpcReadoutElement* rpc=dynamic_cast<MuonGM::RpcReadoutElement*>(det); - if (rpc) { - rpc->shiftSurface(id); - return; + //________________________________________________________________________ + void CombinedMuonAlignModule::restoreSurfaces(Trk::TrkDetElementBase* det) const { + MuonGM::MdtReadoutElement* mdt = dynamic_cast<MuonGM::MdtReadoutElement*>(det); + if (mdt) { + mdt->restoreTubes(); + return; + } + + MuonGM::TgcReadoutElement* tgc = dynamic_cast<MuonGM::TgcReadoutElement*>(det); + if (tgc) { + tgc->restoreSurfaces(); + return; + } + + MuonGM::RpcReadoutElement* rpc = dynamic_cast<MuonGM::RpcReadoutElement*>(det); + if (rpc) { + rpc->restoreSurfaces(); + return; + } + + MuonGM::CscReadoutElement* csc = dynamic_cast<MuonGM::CscReadoutElement*>(det); + if (csc) { + csc->restoreSurfaces(); + return; + } + + *m_log << MSG::ERROR << "det element not MDT, TGC, or RPC!" << endmsg; + + return; } - MuonGM::CscReadoutElement* csc=dynamic_cast<MuonGM::CscReadoutElement*>(det); - if (csc) { - csc->shiftSurface(id); - return; - } - - - return; - } - - //________________________________________________________________________ - void CombinedMuonAlignModule::restoreSurfaces(Trk::TrkDetElementBase* det) const - { - - - MuonGM::MdtReadoutElement* mdt=dynamic_cast<MuonGM::MdtReadoutElement*>(det); - if (mdt) { mdt->restoreTubes(); return; } - - MuonGM::TgcReadoutElement* tgc=dynamic_cast<MuonGM::TgcReadoutElement*>(det); - if (tgc) { tgc->restoreSurfaces(); return; } - - MuonGM::RpcReadoutElement* rpc=dynamic_cast<MuonGM::RpcReadoutElement*>(det); - if (rpc) { rpc->restoreSurfaces(); return; } - - MuonGM::CscReadoutElement* csc=dynamic_cast<MuonGM::CscReadoutElement*>(det); - if (csc) { csc->restoreSurfaces(); return; } - - *m_log<<MSG::ERROR<<"det element not MDT, TGC, or RPC!"<<endmsg; - - return; - } - -} // namespace +} // namespace Muon diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignEvent/src/CscAlignModule.cxx b/MuonSpectrometer/MuonAlignment/MuonAlignEvent/src/CscAlignModule.cxx index 0799740adb57b6c851cf9d361e8355b8bb1d60c3..39842e8140c6e2b8f6d14318e47c5e974c9e1ac4 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignEvent/src/CscAlignModule.cxx +++ b/MuonSpectrometer/MuonAlignment/MuonAlignEvent/src/CscAlignModule.cxx @@ -2,50 +2,38 @@ Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration */ -#include "AthenaBaseComps/AthAlgTool.h" +#include "MuonAlignEvent/CscAlignModule.h" +#include "AthenaBaseComps/AthAlgTool.h" #include "MuonReadoutGeometry/MdtReadoutElement.h" -#include "MuonAlignEvent/CscAlignModule.h" namespace Muon { - //________________________________________________________________________ - CscAlignModule::CscAlignModule(MsgStream* log, - const Amg::Transform3D& transform) - : CombinedMuonAlignModule(log,transform) - , m_rootfile(0) - , m_tubePositionTree(0) - , m_log(new MsgStream(*log)) - { - } - - //________________________________________________________________________ - CscAlignModule::CscAlignModule(const AlgTool* algtool, - const Amg::Transform3D& transform) - : CombinedMuonAlignModule(algtool,transform) - , m_rootfile(0) - , m_tubePositionTree(0) - , m_log(new MsgStream(algtool->msgSvc(),"CscAlignModule")) - { - const AthAlgTool* athAlgTool=dynamic_cast<const AthAlgTool*>(algtool); - if (athAlgTool) - m_log->setLevel(athAlgTool->msg().level()); - } - - //________________________________________________________________________ - CscAlignModule::~CscAlignModule() - { - delete m_log; - } - - //________________________________________________________________________ - //void CscAlignModule::shiftSurface(Trk::TrkDetElementBase* det, Identifier tubeId) const { - //(dynamic_cast<MuonGM::MdtReadoutElement*>(det))->shiftTube(tubeId); - //} - - //________________________________________________________________________ - //void CscAlignModule::restoreSurfaces(Trk::TrkDetElementBase* det) const { - //(dynamic_cast<MuonGM::MdtReadoutElement*>(det))->restoreTubes(); - //} - -} // namespace + //________________________________________________________________________ + CscAlignModule::CscAlignModule(MsgStream* log, const Amg::Transform3D& transform) : + CombinedMuonAlignModule(log, transform), m_rootfile(0), m_tubePositionTree(0), m_log(new MsgStream(*log)) {} + + //________________________________________________________________________ + CscAlignModule::CscAlignModule(const AlgTool* algtool, const Amg::Transform3D& transform) : + CombinedMuonAlignModule(algtool, transform), + m_rootfile(0), + m_tubePositionTree(0), + m_log(new MsgStream(algtool->msgSvc(), "CscAlignModule")) { + const AthAlgTool* athAlgTool = dynamic_cast<const AthAlgTool*>(algtool); + if (athAlgTool) m_log->setLevel(athAlgTool->msg().level()); + } + + //________________________________________________________________________ + CscAlignModule::~CscAlignModule() { delete m_log; } + + //________________________________________________________________________ + // void CscAlignModule::shiftSurface(Trk::TrkDetElementBase* det, Identifier tubeId) const { + //(dynamic_cast<MuonGM::MdtReadoutElement*>(det))->shiftTube(tubeId); + //} + + //________________________________________________________________________ + // void CscAlignModule::restoreSurfaces(Trk::TrkDetElementBase* det) const { + //(dynamic_cast<MuonGM::MdtReadoutElement*>(det))->restoreTubes(); + //} + +} // namespace Muon diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignEvent/src/MdtAlignModule.cxx b/MuonSpectrometer/MuonAlignment/MuonAlignEvent/src/MdtAlignModule.cxx index 72bf83901befae37b95ee504caeb78ec6c37b1a8..c4c553ba8c1921729eba1489823f65ac2dd0acc7 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignEvent/src/MdtAlignModule.cxx +++ b/MuonSpectrometer/MuonAlignment/MuonAlignEvent/src/MdtAlignModule.cxx @@ -2,52 +2,40 @@ Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration */ -#include "AthenaBaseComps/AthAlgTool.h" +#include "MuonAlignEvent/MdtAlignModule.h" +#include "AthenaBaseComps/AthAlgTool.h" #include "MuonReadoutGeometry/MdtReadoutElement.h" -#include "MuonAlignEvent/MdtAlignModule.h" namespace Muon { - //________________________________________________________________________ - MdtAlignModule::MdtAlignModule(MsgStream* log, - const Amg::Transform3D& transform) - : CombinedMuonAlignModule(log,transform) - , m_rootfile(0) - , m_tubePositionTree(0) - , m_log(new MsgStream(*log)) - { - } - - //________________________________________________________________________ - MdtAlignModule::MdtAlignModule(const AlgTool* algtool, - const Amg::Transform3D& transform) - : CombinedMuonAlignModule(algtool,transform) - , m_rootfile(0) - , m_tubePositionTree(0) - , m_log(new MsgStream(algtool->msgSvc(),"MdtAlignModule")) - { - const AthAlgTool* athAlgTool=dynamic_cast<const AthAlgTool*>(algtool); - if (athAlgTool) - m_log->setLevel(athAlgTool->msg().level()); - } - - //________________________________________________________________________ - MdtAlignModule::~MdtAlignModule() - { - delete m_log; - } - - /* - //________________________________________________________________________ - void MdtAlignModule::shiftSurface(Trk::TrkDetElementBase* det, Identifier tubeId) const { - (dynamic_cast<MuonGM::MdtReadoutElement*>(det))->shiftTube(tubeId); - } - - //________________________________________________________________________ - void MdtAlignModule::restoreSurfaces(Trk::TrkDetElementBase* det) const { - (dynamic_cast<MuonGM::MdtReadoutElement*>(det))->restoreTubes(); - } - */ - -} // namespace + //________________________________________________________________________ + MdtAlignModule::MdtAlignModule(MsgStream* log, const Amg::Transform3D& transform) : + CombinedMuonAlignModule(log, transform), m_rootfile(0), m_tubePositionTree(0), m_log(new MsgStream(*log)) {} + + //________________________________________________________________________ + MdtAlignModule::MdtAlignModule(const AlgTool* algtool, const Amg::Transform3D& transform) : + CombinedMuonAlignModule(algtool, transform), + m_rootfile(0), + m_tubePositionTree(0), + m_log(new MsgStream(algtool->msgSvc(), "MdtAlignModule")) { + const AthAlgTool* athAlgTool = dynamic_cast<const AthAlgTool*>(algtool); + if (athAlgTool) m_log->setLevel(athAlgTool->msg().level()); + } + + //________________________________________________________________________ + MdtAlignModule::~MdtAlignModule() { delete m_log; } + + /* + //________________________________________________________________________ + void MdtAlignModule::shiftSurface(Trk::TrkDetElementBase* det, Identifier tubeId) const { + (dynamic_cast<MuonGM::MdtReadoutElement*>(det))->shiftTube(tubeId); + } + + //________________________________________________________________________ + void MdtAlignModule::restoreSurfaces(Trk::TrkDetElementBase* det) const { + (dynamic_cast<MuonGM::MdtReadoutElement*>(det))->restoreTubes(); + } + */ + +} // namespace Muon diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignEvent/src/RpcAlignModule.cxx b/MuonSpectrometer/MuonAlignment/MuonAlignEvent/src/RpcAlignModule.cxx index 50d2f0c7e6ffee8c7e7dd7148c98a4e1455c9b8e..5dd49696bb2d7db1066743f4abc82832ebbe408a 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignEvent/src/RpcAlignModule.cxx +++ b/MuonSpectrometer/MuonAlignment/MuonAlignEvent/src/RpcAlignModule.cxx @@ -2,46 +2,34 @@ Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration */ -#include "AthenaBaseComps/AthAlgTool.h" +#include "MuonAlignEvent/RpcAlignModule.h" +#include "AthenaBaseComps/AthAlgTool.h" #include "MuonReadoutGeometry/RpcReadoutElement.h" -#include "MuonAlignEvent/RpcAlignModule.h" - namespace Muon { - //________________________________________________________________________ - RpcAlignModule::RpcAlignModule( MsgStream* log, - const Amg::Transform3D& transform ) - : CombinedMuonAlignModule( log, transform ) - , m_log( new MsgStream( *log ) ) - { } - - //________________________________________________________________________ - RpcAlignModule::RpcAlignModule( const AlgTool* algtool, - const Amg::Transform3D& transform ) - : CombinedMuonAlignModule( algtool, transform ) - , m_log( new MsgStream( algtool->msgSvc(), "RpcAlignModule" ) ) - { - const AthAlgTool* athAlgTool = dynamic_cast <const AthAlgTool*>( algtool ); - if ( athAlgTool ) { - m_log->setLevel( athAlgTool->msg().level() ); + //________________________________________________________________________ + RpcAlignModule::RpcAlignModule(MsgStream* log, const Amg::Transform3D& transform) : + CombinedMuonAlignModule(log, transform), m_log(new MsgStream(*log)) {} + + //________________________________________________________________________ + RpcAlignModule::RpcAlignModule(const AlgTool* algtool, const Amg::Transform3D& transform) : + CombinedMuonAlignModule(algtool, transform), m_log(new MsgStream(algtool->msgSvc(), "RpcAlignModule")) { + const AthAlgTool* athAlgTool = dynamic_cast<const AthAlgTool*>(algtool); + if (athAlgTool) { m_log->setLevel(athAlgTool->msg().level()); } } - } - - //________________________________________________________________________ - RpcAlignModule::~RpcAlignModule() - { - delete m_log; - } - - //________________________________________________________________________ - //void RpcAlignModule::shiftSurface(Trk::TrkDetElementBase* det, Identifier id) const { - // (dynamic_cast<MuonGM::RpcReadoutElement*>(det))->shiftSurface(id); - //} - - //________________________________________________________________________ - //void RpcAlignModule::restoreSurfaces(Trk::TrkDetElementBase* det) const { - // (dynamic_cast<MuonGM::RpcReadoutElement*>(det))->restoreSurfaces(); - // } - -} + + //________________________________________________________________________ + RpcAlignModule::~RpcAlignModule() { delete m_log; } + + //________________________________________________________________________ + // void RpcAlignModule::shiftSurface(Trk::TrkDetElementBase* det, Identifier id) const { + // (dynamic_cast<MuonGM::RpcReadoutElement*>(det))->shiftSurface(id); + //} + + //________________________________________________________________________ + // void RpcAlignModule::restoreSurfaces(Trk::TrkDetElementBase* det) const { + // (dynamic_cast<MuonGM::RpcReadoutElement*>(det))->restoreSurfaces(); + // } + +} // namespace Muon diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignEvent/src/TgcAlignModule.cxx b/MuonSpectrometer/MuonAlignment/MuonAlignEvent/src/TgcAlignModule.cxx index fdb4af1154c49ed08cc38ef9e375040a34f2d414..de0f496af44264fa46dd689989de746d00d905c3 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignEvent/src/TgcAlignModule.cxx +++ b/MuonSpectrometer/MuonAlignment/MuonAlignEvent/src/TgcAlignModule.cxx @@ -2,53 +2,39 @@ Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration */ -#include "AthenaBaseComps/AthAlgTool.h" +#include "MuonAlignEvent/TgcAlignModule.h" +#include "AthenaBaseComps/AthAlgTool.h" #include "MuonReadoutGeometry/TgcReadoutElement.h" -#include "MuonAlignEvent/TgcAlignModule.h" - namespace Muon { //________________________________________________________________________ - TgcAlignModule::TgcAlignModule( MsgStream* log, - const Amg::Transform3D& transform ) - : CombinedMuonAlignModule( log, transform) - , m_rootfile( 0 ) - , m_stripPositionTree( 0 ) - , m_wirePositionTree( 0 ) - , m_log( new MsgStream( *log ) ) - { } + TgcAlignModule::TgcAlignModule(MsgStream* log, const Amg::Transform3D& transform) : + CombinedMuonAlignModule(log, transform), m_rootfile(0), m_stripPositionTree(0), m_wirePositionTree(0), m_log(new MsgStream(*log)) {} //________________________________________________________________________ - TgcAlignModule::TgcAlignModule( const AlgTool* algtool, - const Amg::Transform3D& transform ) - : CombinedMuonAlignModule( algtool, transform ) - , m_rootfile( 0 ) - , m_stripPositionTree( 0 ) - , m_wirePositionTree( 0 ) - , m_log( new MsgStream( algtool->msgSvc(), "TgcAlignModule" ) ) - { - const AthAlgTool* athAlgTool = dynamic_cast <const AthAlgTool*>( algtool ); - if ( athAlgTool ) { - m_log->setLevel( athAlgTool->msg().level() ); - } + TgcAlignModule::TgcAlignModule(const AlgTool* algtool, const Amg::Transform3D& transform) : + CombinedMuonAlignModule(algtool, transform), + m_rootfile(0), + m_stripPositionTree(0), + m_wirePositionTree(0), + m_log(new MsgStream(algtool->msgSvc(), "TgcAlignModule")) { + const AthAlgTool* athAlgTool = dynamic_cast<const AthAlgTool*>(algtool); + if (athAlgTool) { m_log->setLevel(athAlgTool->msg().level()); } } //________________________________________________________________________ - TgcAlignModule::~TgcAlignModule() - { - delete m_log; + TgcAlignModule::~TgcAlignModule() { delete m_log; } + + //________________________________________________________________________ + /*void TgcAlignModule::shiftSurface(Trk::TrkDetElementBase* det, Identifier id) const { + std::cout<<"in TgcAlignModule::shiftSurface()"<<std::endl; + (dynamic_cast<MuonGM::TgcReadoutElement*>(det))->shiftSurface(id); } - //________________________________________________________________________ - /*void TgcAlignModule::shiftSurface(Trk::TrkDetElementBase* det, Identifier id) const { - std::cout<<"in TgcAlignModule::shiftSurface()"<<std::endl; - (dynamic_cast<MuonGM::TgcReadoutElement*>(det))->shiftSurface(id); - } - - //________________________________________________________________________ - void TgcAlignModule::restoreSurfaces(Trk::TrkDetElementBase* det) const { - (dynamic_cast<MuonGM::TgcReadoutElement*>(det))->restoreSurfaces(); - } - */ -} + //________________________________________________________________________ + void TgcAlignModule::restoreSurfaces(Trk::TrkDetElementBase* det) const { + (dynamic_cast<MuonGM::TgcReadoutElement*>(det))->restoreSurfaces(); + } + */ +} // namespace Muon diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignExample/doc/packagedoc.h b/MuonSpectrometer/MuonAlignment/MuonAlignExample/doc/packagedoc.h index cee0b8ce905aeece1a3bc721d4c4c5b578ce91ef..1254732cbfba6bbd97a1d447c8eaac07ca3508fe 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignExample/doc/packagedoc.h +++ b/MuonSpectrometer/MuonAlignment/MuonAlignExample/doc/packagedoc.h @@ -6,7 +6,7 @@ @page MuonAlignExample_page MuonAlignExample -@author Robert Harrington +@author Robert Harrington */ diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/ChamberDerivs.cpp b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/ChamberDerivs.cpp index 01fa9ec311a08071e4ec2614d52235d6e5aa192e..6c0a9dc4f9b1f89642d3677732e338801436aa29 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/ChamberDerivs.cpp +++ b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/ChamberDerivs.cpp @@ -3,665 +3,588 @@ */ #include "ChamberDerivs.h" + #include <cmath> -#include "TMatrixDSym.h" -#include "TMatrix.h" -#include "TMatrixD.h" -#include "TVectorD.h" -#include "TDecompBK.h" -#include "TDecompSVD.h" #include "CLHEP/Matrix/Matrix.h" #include "CLHEP/Matrix/SymMatrix.h" #include "CLHEP/Matrix/Vector.h" +#include "TDecompBK.h" +#include "TDecompSVD.h" +#include "TMatrix.h" +#include "TMatrixD.h" +#include "TMatrixDSym.h" +#include "TVectorD.h" using namespace CLHEP; //________________________________________________________________________ -ChamberDerivs::ChamberDerivs() - : m_npar(0) - , m_nchambers(0) - , m_nindices(0) -{ -} +ChamberDerivs::ChamberDerivs() : m_npar(0), m_nchambers(0), m_nindices(0) {} //________________________________________________________________________ -ChamberDerivs::ChamberDerivs(int npar, int nchambers) - : m_npar(npar) - , m_nchambers(nchambers) - , m_nindices(npar*nchambers) - , m_chamberIds(new int[m_nchambers]) - , m_matrixIndices(new int[m_nindices]) - , m_hitmap(new int[m_nchambers*m_nchambers]) - , m_secDeriv(new double[m_nindices*m_nindices]) - , m_firstDeriv(new double[m_nindices]) -{ - for (int i=0;i<m_nchambers;i++) { - m_chamberIds[i]=-1; - } - for (int j=0;j<m_nchambers*m_nchambers;j++) { - m_hitmap[j]=0; - } - for (int i=0;i<m_nindices;i++) { - m_firstDeriv[i]=0.; - m_matrixIndices[i]=0; - } - for (int j=0;j<m_nindices*m_nindices;j++) { - m_secDeriv[j]=0.; - } +ChamberDerivs::ChamberDerivs(int npar, int nchambers) : + m_npar(npar), + m_nchambers(nchambers), + m_nindices(npar * nchambers), + m_chamberIds(new int[m_nchambers]), + m_matrixIndices(new int[m_nindices]), + m_hitmap(new int[m_nchambers * m_nchambers]), + m_secDeriv(new double[m_nindices * m_nindices]), + m_firstDeriv(new double[m_nindices]) { + for (int i = 0; i < m_nchambers; i++) { m_chamberIds[i] = -1; } + for (int j = 0; j < m_nchambers * m_nchambers; j++) { m_hitmap[j] = 0; } + for (int i = 0; i < m_nindices; i++) { + m_firstDeriv[i] = 0.; + m_matrixIndices[i] = 0; + } + for (int j = 0; j < m_nindices * m_nindices; j++) { m_secDeriv[j] = 0.; } } //________________________________________________________________________ -ChamberDerivs::~ChamberDerivs() -{ - delete [] m_secDeriv; - delete [] m_firstDeriv; - delete [] m_chamberIds; - delete [] m_matrixIndices; - delete [] m_hitmap; +ChamberDerivs::~ChamberDerivs() { + delete[] m_secDeriv; + delete[] m_firstDeriv; + delete[] m_chamberIds; + delete[] m_matrixIndices; + delete[] m_hitmap; } /* //________________________________________________________________________ void ChamberDerivs::incrementHitmap(int ich, int jch, - int ntracks) -{ - m_hitmap[ich*m_nchambers+jch]+=ntracks; + int ntracks) +{ + m_hitmap[ich*m_nchambers+jch]+=ntracks; } */ //________________________________________________________________________ -double ChamberDerivs::robustAlignPar(int index) const { - return -(this->firstDeriv(index)/this->secondDeriv(index,index)); -} +double ChamberDerivs::robustAlignPar(int index) const { return -(this->firstDeriv(index) / this->secondDeriv(index, index)); } //________________________________________________________________________ -double ChamberDerivs::robustAlignErr(int index) const { - return std::sqrt(2./std::fabs(this->secondDeriv(index,index))); -} +double ChamberDerivs::robustAlignErr(int index) const { return std::sqrt(2. / std::fabs(this->secondDeriv(index, index))); } //________________________________________________________________________ -double ChamberDerivs::robustAlignPar(int ich, int ipar) const { - return -(this->firstDeriv(ich,ipar)/this->secondDeriv(ich,ipar,ich,ipar)); +double ChamberDerivs::robustAlignPar(int ich, int ipar) const { + return -(this->firstDeriv(ich, ipar) / this->secondDeriv(ich, ipar, ich, ipar)); } //________________________________________________________________________ -double ChamberDerivs::robustAlignErr(int ich, int ipar) const { - return std::sqrt(2./std::fabs(this->secondDeriv(ich,ipar,ich,ipar))); -} +double ChamberDerivs::robustAlignErr(int ich, int ipar) const { return std::sqrt(2. / std::fabs(this->secondDeriv(ich, ipar, ich, ipar))); } //________________________________________________________________________ -void ChamberDerivs::PrintSecondDerivs(int ich) const -{ - if (ich<0) { - TMatrixDSym a(m_nindices,m_secDeriv); - //a.Print(); - } - if (ich>=m_nchambers) return; - - cout<<endl<<endl<<"secndDeriv: "<<endl; - if (ich<0) { - for (int i_index=0;i_index<m_nindices;i_index++) { - for (int j_index=0;j_index<m_nindices;j_index++) { - cout<<this->secondDeriv(i_index,j_index)<<" "; - } - cout<<endl; - } - } - else { - for (int ipar=0;ipar<m_npar;ipar++) { - for (int jpar=0;jpar<m_npar;jpar++) { - cout<<this->secondDeriv(ich,ipar,ich,jpar)<<" "; - } - cout<<endl; - } - } +void ChamberDerivs::PrintSecondDerivs(int ich) const { + if (ich < 0) { + TMatrixDSym a(m_nindices, m_secDeriv); + // a.Print(); + } + if (ich >= m_nchambers) return; + + cout << endl << endl << "secndDeriv: " << endl; + if (ich < 0) { + for (int i_index = 0; i_index < m_nindices; i_index++) { + for (int j_index = 0; j_index < m_nindices; j_index++) { cout << this->secondDeriv(i_index, j_index) << " "; } + cout << endl; + } + } else { + for (int ipar = 0; ipar < m_npar; ipar++) { + for (int jpar = 0; jpar < m_npar; jpar++) { cout << this->secondDeriv(ich, ipar, ich, jpar) << " "; } + cout << endl; + } + } } //________________________________________________________________________ -void ChamberDerivs::PrintFirstDerivs(int ich) const -{ - if (ich>=m_nchambers) return; - cout<<endl<<endl<<"firstDeriv: "<<endl; - if (ich<0) { - int index=0; - for (int ich=0;ich<m_nchambers;ich++) { - for (int ipar=0;ipar<m_npar;ipar++) { - cout<<"["<<index++<<"] = "<<this->firstDeriv(ich,ipar)<<endl; - } +void ChamberDerivs::PrintFirstDerivs(int ich) const { + if (ich >= m_nchambers) return; + cout << endl << endl << "firstDeriv: " << endl; + if (ich < 0) { + int index = 0; + for (int ich = 0; ich < m_nchambers; ich++) { + for (int ipar = 0; ipar < m_npar; ipar++) { cout << "[" << index++ << "] = " << this->firstDeriv(ich, ipar) << endl; } + } + } else { + for (int ipar = 0; ipar < m_npar; ipar++) { cout << "[" << ipar << "] = " << this->firstDeriv(ich, ipar) << endl; } } - } - else { - for (int ipar=0;ipar<m_npar;ipar++) { - cout<<"["<<ipar<<"] = "<<this->firstDeriv(ich,ipar)<<endl; - } - } } //________________________________________________________________________ -void ChamberDerivs::PrintChambers(int ich) const -{ - if (ich<0) { - cout<<endl<<"chambers: "<<endl; - for (int iich=0;iich<m_nchambers;iich++) { - cout<<"["<<iich<<"]: "<<this->chamberId(iich)<<", nhits: " - <<this->nhits(iich,iich)<<endl; +void ChamberDerivs::PrintChambers(int ich) const { + if (ich < 0) { + cout << endl << "chambers: " << endl; + for (int iich = 0; iich < m_nchambers; iich++) { + cout << "[" << iich << "]: " << this->chamberId(iich) << ", nhits: " << this->nhits(iich, iich) << endl; + } + } else { + cout << endl << "chamber[" << ich << "]: " << this->chamberId(ich) << ", nhits: " << this->nhits(ich, ich) << endl; } - } - else { - cout<<endl<<"chamber["<<ich<<"]: "<<this->chamberId(ich)<<", nhits: " - <<this->nhits(ich,ich)<<endl; - } } //________________________________________________________________________ -ChamberDerivs ChamberDerivs::trimmedChamberDerivs(int minHitsOnDiagonal, - int minHitsOffDiagonal) const -{ - // see how many chambers have enough hits on diagonal - cout<<"starting with "<<this->nchambers()<<" chambers"<<endl; - - vector<int> goodchamber_ich; - for (int ich=0;ich<this->nchambers();ich++) { - int nhits=this->nhits(ich,ich); - cout<<"ich="<<ich<<"/"<<this->nchambers()<<", nhits: "<<nhits<<endl; - if (nhits>=minHitsOnDiagonal) { - goodchamber_ich.push_back(ich); +ChamberDerivs ChamberDerivs::trimmedChamberDerivs(int minHitsOnDiagonal, int minHitsOffDiagonal) const { + // see how many chambers have enough hits on diagonal + cout << "starting with " << this->nchambers() << " chambers" << endl; + + vector<int> goodchamber_ich; + for (int ich = 0; ich < this->nchambers(); ich++) { + int nhits = this->nhits(ich, ich); + cout << "ich=" << ich << "/" << this->nchambers() << ", nhits: " << nhits << endl; + if (nhits >= minHitsOnDiagonal) { goodchamber_ich.push_back(ich); } } - } - int ngoodchambers=goodchamber_ich.size(); - cout<<"ngoodchambers: "<<ngoodchambers<<endl; - - // create new chamber derivs - ChamberDerivs chDerivs(m_npar,ngoodchambers); - for (int ich=0;ich<ngoodchambers;ich++) { - int old_ich=goodchamber_ich[ich]; - chDerivs.setChamberId(ich,this->chamberId(old_ich)); - for (int ipar=0;ipar<m_npar;ipar++) { - - chDerivs.setFirstDeriv(ich,ipar,this->firstDeriv(old_ich,ipar)); - chDerivs.setMatrixIndex(ich,ipar,this->matrixIndex(old_ich,ipar)); - - for (int jch=ich;jch<ngoodchambers;jch++) { - int old_jch=goodchamber_ich[jch]; - int nOffDiagHits=this->nhits(old_ich,old_jch); - if (jch!=ich) { - if (nOffDiagHits<minHitsOffDiagonal) continue; - } - if (ipar==0) - chDerivs.setNHits(ich,jch,this->nhits(old_ich,old_jch)); - for (int jpar=0;jpar<m_npar;jpar++) { - - chDerivs.setSecondDeriv(ich,ipar,jch,jpar,this->secondDeriv(old_ich,ipar,old_jch,jpar)); - } - } + int ngoodchambers = goodchamber_ich.size(); + cout << "ngoodchambers: " << ngoodchambers << endl; + + // create new chamber derivs + ChamberDerivs chDerivs(m_npar, ngoodchambers); + for (int ich = 0; ich < ngoodchambers; ich++) { + int old_ich = goodchamber_ich[ich]; + chDerivs.setChamberId(ich, this->chamberId(old_ich)); + for (int ipar = 0; ipar < m_npar; ipar++) { + chDerivs.setFirstDeriv(ich, ipar, this->firstDeriv(old_ich, ipar)); + chDerivs.setMatrixIndex(ich, ipar, this->matrixIndex(old_ich, ipar)); + + for (int jch = ich; jch < ngoodchambers; jch++) { + int old_jch = goodchamber_ich[jch]; + int nOffDiagHits = this->nhits(old_ich, old_jch); + if (jch != ich) { + if (nOffDiagHits < minHitsOffDiagonal) continue; + } + if (ipar == 0) chDerivs.setNHits(ich, jch, this->nhits(old_ich, old_jch)); + for (int jpar = 0; jpar < m_npar; jpar++) { + chDerivs.setSecondDeriv(ich, ipar, jch, jpar, this->secondDeriv(old_ich, ipar, old_jch, jpar)); + } + } + } } - } - return chDerivs; + return chDerivs; } //________________________________________________________________________ -ChamberDerivs ChamberDerivs::trimmedChamberDerivsBySV(double singularValueCut, - int minHitsOffDiagonal) const -{ - cout<<"trimmedChamberDerivsBySV"<<endl; - - cout<<"starting with "<<this->nchambers()<<" chambers"<<endl; - - // see how many chambers have good singular value - vector<int> goodchamber_ich; - for (int ich=0;ich<this->nchambers();ich++) { - vector<double> sv; const TMatrixD *u,*vinv; - this->singularValues(sv,u,vinv,ich); - delete u; delete vinv; - - double minval=1.e20; - //cout<<"getting min"<<endl; - for (int ipar=0;ipar<(int)sv.size();ipar++) { - //cout<<"sv["<<ipar<<"]="<<sv[ipar]<<endl; - if (sv[ipar]<minval) { - minval=sv[ipar]; - } - } - //cout<<endl; - - //cout<<"ich="<<ich<<"/"<<this->nchambers()<<endl; - if (minval>singularValueCut) { - goodchamber_ich.push_back(ich); +ChamberDerivs ChamberDerivs::trimmedChamberDerivsBySV(double singularValueCut, int minHitsOffDiagonal) const { + cout << "trimmedChamberDerivsBySV" << endl; + + cout << "starting with " << this->nchambers() << " chambers" << endl; + + // see how many chambers have good singular value + vector<int> goodchamber_ich; + for (int ich = 0; ich < this->nchambers(); ich++) { + vector<double> sv; + const TMatrixD *u, *vinv; + this->singularValues(sv, u, vinv, ich); + delete u; + delete vinv; + + double minval = 1.e20; + // cout<<"getting min"<<endl; + for (int ipar = 0; ipar < (int)sv.size(); ipar++) { + // cout<<"sv["<<ipar<<"]="<<sv[ipar]<<endl; + if (sv[ipar] < minval) { minval = sv[ipar]; } + } + // cout<<endl; + + // cout<<"ich="<<ich<<"/"<<this->nchambers()<<endl; + if (minval > singularValueCut) { goodchamber_ich.push_back(ich); } } - } - int ngoodchambers=goodchamber_ich.size(); - cout<<"ngoodchambers: "<<ngoodchambers<<endl; - - // create new chamber derivs - ChamberDerivs chDerivs(m_npar,ngoodchambers); - for (int ich=0;ich<ngoodchambers;ich++) { - int old_ich=goodchamber_ich[ich]; - chDerivs.setChamberId(ich,this->chamberId(old_ich)); - for (int ipar=0;ipar<m_npar;ipar++) { - - chDerivs.setFirstDeriv(ich,ipar,this->firstDeriv(old_ich,ipar)); - chDerivs.setMatrixIndex(ich,ipar,this->matrixIndex(old_ich,ipar)); - - for (int jch=ich;jch<ngoodchambers;jch++) { - int old_jch=goodchamber_ich[jch]; - int nOffDiagHits=this->nhits(old_ich,old_jch); - if (jch!=ich) { - if (nOffDiagHits<minHitsOffDiagonal) continue; - } - if (ipar==0) - chDerivs.setNHits(ich,jch,this->nhits(old_ich,old_jch)); - for (int jpar=0;jpar<m_npar;jpar++) { - - chDerivs.setSecondDeriv(ich,ipar,jch,jpar,this->secondDeriv(old_ich,ipar,old_jch,jpar)); - } - } + int ngoodchambers = goodchamber_ich.size(); + cout << "ngoodchambers: " << ngoodchambers << endl; + + // create new chamber derivs + ChamberDerivs chDerivs(m_npar, ngoodchambers); + for (int ich = 0; ich < ngoodchambers; ich++) { + int old_ich = goodchamber_ich[ich]; + chDerivs.setChamberId(ich, this->chamberId(old_ich)); + for (int ipar = 0; ipar < m_npar; ipar++) { + chDerivs.setFirstDeriv(ich, ipar, this->firstDeriv(old_ich, ipar)); + chDerivs.setMatrixIndex(ich, ipar, this->matrixIndex(old_ich, ipar)); + + for (int jch = ich; jch < ngoodchambers; jch++) { + int old_jch = goodchamber_ich[jch]; + int nOffDiagHits = this->nhits(old_ich, old_jch); + if (jch != ich) { + if (nOffDiagHits < minHitsOffDiagonal) continue; + } + if (ipar == 0) chDerivs.setNHits(ich, jch, this->nhits(old_ich, old_jch)); + for (int jpar = 0; jpar < m_npar; jpar++) { + chDerivs.setSecondDeriv(ich, ipar, jch, jpar, this->secondDeriv(old_ich, ipar, old_jch, jpar)); + } + } + } } - } - return chDerivs; + return chDerivs; } //________________________________________________________________________ -ChamberDerivs* ChamberDerivs::oneChamberDerivs(int ich) const -{ - ChamberDerivs* localChDerivs=new ChamberDerivs(m_npar,1); - localChDerivs->setChamberId(0,this->chamberId(ich)); - localChDerivs->setNHits(0,this->nhits(ich,ich)); - for (int ipar=0;ipar<m_npar;ipar++) { - localChDerivs->setMatrixIndex(ipar,this->matrixIndex(ich,ipar)); - localChDerivs->setFirstDeriv(ipar,this->firstDeriv(ich,ipar)); - for (int jpar=0;jpar<m_npar;jpar++) { - double sd=this->secondDeriv(ich,ipar,ich,jpar); - localChDerivs->setSecondDeriv(ipar,jpar,sd); +ChamberDerivs* ChamberDerivs::oneChamberDerivs(int ich) const { + ChamberDerivs* localChDerivs = new ChamberDerivs(m_npar, 1); + localChDerivs->setChamberId(0, this->chamberId(ich)); + localChDerivs->setNHits(0, this->nhits(ich, ich)); + for (int ipar = 0; ipar < m_npar; ipar++) { + localChDerivs->setMatrixIndex(ipar, this->matrixIndex(ich, ipar)); + localChDerivs->setFirstDeriv(ipar, this->firstDeriv(ich, ipar)); + for (int jpar = 0; jpar < m_npar; jpar++) { + double sd = this->secondDeriv(ich, ipar, ich, jpar); + localChDerivs->setSecondDeriv(ipar, jpar, sd); + } } - } - return localChDerivs; + return localChDerivs; } //________________________________________________________________________ -double ChamberDerivs::condition(int ich) const -{ - cout<<"getting secderiv, ich "<<ich<<endl; - const TMatrixDSym* mat=this->secDerivMatrixROOT(ich); - - cout<<"got matrix, decomposing"<<endl; - TDecompSVD decompMat(*mat); - decompMat.Decompose(); - - TVectorD sig=decompMat.GetSig(); - //cout<<"Sig: "<<endl; - //sig.Print(); - - double d1,d2; - decompMat.Det(d1,d2); - //cout<<"d1: "<<d1<<", d2: "<<d2<<endl; - - double cond=decompMat.Condition(); - //cout<<"condition: "<<cond<<endl; - - delete mat; - return cond; +double ChamberDerivs::condition(int ich) const { + cout << "getting secderiv, ich " << ich << endl; + const TMatrixDSym* mat = this->secDerivMatrixROOT(ich); -} + cout << "got matrix, decomposing" << endl; + TDecompSVD decompMat(*mat); + decompMat.Decompose(); -//________________________________________________________________________ -void ChamberDerivs::singularValues(vector<double>& sv, - const TMatrixD*& u, const TMatrixD*& vinv, int ich) const -{ + TVectorD sig = decompMat.GetSig(); + // cout<<"Sig: "<<endl; + // sig.Print(); - TMatrixDSym* mat=this->secDerivMatrixROOT(ich); - - TDecompSVD decompMat(*mat); - decompMat.Decompose(); - const TVectorD& svV=decompMat.GetSig(); - - //cout<<"getting elements"<<endl; - sv.clear(); - for (int i=0;i<svV.GetNoElements();i++) { - //cout<<"sv["<<i<<"]="<<svV[i]<<endl; - sv.push_back(svV[i]); - } + double d1, d2; + decompMat.Det(d1, d2); + // cout<<"d1: "<<d1<<", d2: "<<d2<<endl; - u=new TMatrixD(decompMat.GetU()); - cout<<"U:"<<endl; - u->Print(); - - TMatrixD v=decompMat.GetV(); - vinv=new TMatrixD(v.Invert()); - cout<<"Vinv:"<<endl; - vinv->Print(); - - delete mat; - - return; + double cond = decompMat.Condition(); + // cout<<"condition: "<<cond<<endl; + + delete mat; + return cond; } //________________________________________________________________________ -double ChamberDerivs::conditionChamberRemoved(int ichToRemove) const -{ - int nindices=m_nindices-m_npar; - double* array=new double[nindices*nindices]; - //cout<<"array size: "<<nindices*nindices<<endl; - - int index=0; - for (int ich=0;ich<m_nchambers;ich++) { - if (ich==ichToRemove) continue; - for (int ipar=0;ipar<m_npar;ipar++) { - for (int jch=0;jch<m_nchambers;jch++) { - if (jch==ichToRemove) continue; - for (int jpar=0;jpar<m_npar;jpar++) { - array[index]=this->secondDeriv(ich,ipar,jch,jpar); - //cout<<"array["<<index<<"]="<<array[index]<<endl; - index++; - } - } - } - } - - TMatrixDSym* mat=new TMatrixDSym(nindices); - index=0; - for (int i=0;i<nindices;i++) { - for (int j=0;j<nindices;j++) { - (*mat)[i][j]=array[index++]; - //cout<<"mat["<<i<<"]["<<j<<"]="<<(*mat)[i][j]<<endl; +void ChamberDerivs::singularValues(vector<double>& sv, const TMatrixD*& u, const TMatrixD*& vinv, int ich) const { + TMatrixDSym* mat = this->secDerivMatrixROOT(ich); + + TDecompSVD decompMat(*mat); + decompMat.Decompose(); + const TVectorD& svV = decompMat.GetSig(); + + // cout<<"getting elements"<<endl; + sv.clear(); + for (int i = 0; i < svV.GetNoElements(); i++) { + // cout<<"sv["<<i<<"]="<<svV[i]<<endl; + sv.push_back(svV[i]); } - } - delete [] array; - //cout<<"decomposing"<<endl; - TDecompSVD decompMat(*mat); - decompMat.Decompose(); + u = new TMatrixD(decompMat.GetU()); + cout << "U:" << endl; + u->Print(); - TVectorD sig=decompMat.GetSig(); - //cout<<"Sig: "<<endl; - //sig.Print(); + TMatrixD v = decompMat.GetV(); + vinv = new TMatrixD(v.Invert()); + cout << "Vinv:" << endl; + vinv->Print(); - //cout<<"getting condition"<<endl; - double cond=decompMat.Condition(); - //cout<<"done"<<endl; - - delete mat; - return cond; + delete mat; + return; } //________________________________________________________________________ -void ChamberDerivs::constrainLowestEigenvector(const std::map<int,string>& chamberIdMap) -{ - int npar=this->npar(); - for (int ich=0;ich<this->nchambers();ich++) { - - vector<double> sv; - const TMatrixD *u,*vinv; - this->singularValues(sv,u,vinv,ich); +double ChamberDerivs::conditionChamberRemoved(int ichToRemove) const { + int nindices = m_nindices - m_npar; + double* array = new double[nindices * nindices]; + // cout<<"array size: "<<nindices*nindices<<endl; + + int index = 0; + for (int ich = 0; ich < m_nchambers; ich++) { + if (ich == ichToRemove) continue; + for (int ipar = 0; ipar < m_npar; ipar++) { + for (int jch = 0; jch < m_nchambers; jch++) { + if (jch == ichToRemove) continue; + for (int jpar = 0; jpar < m_npar; jpar++) { + array[index] = this->secondDeriv(ich, ipar, jch, jpar); + // cout<<"array["<<index<<"]="<<array[index]<<endl; + index++; + } + } + } + } - cout<<"2nd deriv before: "<<endl; - this->PrintSecondDerivs(ich); + TMatrixDSym* mat = new TMatrixDSym(nindices); + index = 0; + for (int i = 0; i < nindices; i++) { + for (int j = 0; j < nindices; j++) { + (*mat)[i][j] = array[index++]; + // cout<<"mat["<<i<<"]["<<j<<"]="<<(*mat)[i][j]<<endl; + } + } + delete[] array; - const int id=chamberId(ich); - cout<<"id: "<<id<<endl; + // cout<<"decomposing"<<endl; + TDecompSVD decompMat(*mat); + decompMat.Decompose(); - std::map<int,string>::const_iterator it=chamberIdMap.find(id); - string name=it->second; + TVectorD sig = decompMat.GetSig(); + // cout<<"Sig: "<<endl; + // sig.Print(); - cout<<"ch: "<<name<<"(before)"<<endl; - for (int i=0;i<npar;i++) cout<<"sv["<<i<<"]="<<sv[i]<<endl; + // cout<<"getting condition"<<endl; + double cond = decompMat.Condition(); + // cout<<"done"<<endl; - cout<<"u: "<<endl; u->Print(); - //cout<<"vinv: "<<endl; vinv->Print(); + delete mat; + return cond; +} - TMatrixDSym sd(npar); - for (int ipar=0;ipar<npar-2;ipar++) sd[ipar][ipar]=sv[ipar]; - sd[npar-2][npar-2]=sv[0]; - sd[npar-1][npar-1]=sv[0]; - TMatrixD D=(*u)*sd*(*vinv); - D.Print(); - for (int ipar=0;ipar<npar;ipar++) { - for (int jpar=0;jpar<npar;jpar++) { - double val=D[ipar][jpar]; - setSecondDeriv(ich,ipar,ich,jpar,val); - } +//________________________________________________________________________ +void ChamberDerivs::constrainLowestEigenvector(const std::map<int, string>& chamberIdMap) { + int npar = this->npar(); + for (int ich = 0; ich < this->nchambers(); ich++) { + vector<double> sv; + const TMatrixD *u, *vinv; + this->singularValues(sv, u, vinv, ich); + + cout << "2nd deriv before: " << endl; + this->PrintSecondDerivs(ich); + + const int id = chamberId(ich); + cout << "id: " << id << endl; + + std::map<int, string>::const_iterator it = chamberIdMap.find(id); + string name = it->second; + + cout << "ch: " << name << "(before)" << endl; + for (int i = 0; i < npar; i++) cout << "sv[" << i << "]=" << sv[i] << endl; + + cout << "u: " << endl; + u->Print(); + // cout<<"vinv: "<<endl; vinv->Print(); + + TMatrixDSym sd(npar); + for (int ipar = 0; ipar < npar - 2; ipar++) sd[ipar][ipar] = sv[ipar]; + sd[npar - 2][npar - 2] = sv[0]; + sd[npar - 1][npar - 1] = sv[0]; + TMatrixD D = (*u) * sd * (*vinv); + D.Print(); + for (int ipar = 0; ipar < npar; ipar++) { + for (int jpar = 0; jpar < npar; jpar++) { + double val = D[ipar][jpar]; + setSecondDeriv(ich, ipar, ich, jpar, val); + } + } + delete u; + delete vinv; + + cout << "2nd deriv after: " << endl; + this->PrintSecondDerivs(ich); + + this->singularValues(sv, u, vinv, ich); + cout << "ich: " << name << "(after)" << endl; + for (int i = 0; i < npar; i++) cout << "sv[" << i << "]=" << sv[i] << endl; + cout << "u: " << endl; + u->Print(); + + delete u; + delete vinv; } - delete u; delete vinv; - - cout<<"2nd deriv after: "<<endl; - this->PrintSecondDerivs(ich); - - this->singularValues(sv,u,vinv,ich); - cout<<"ich: "<<name<<"(after)"<<endl; - for (int i=0;i<npar;i++) cout<<"sv["<<i<<"]="<<sv[i]<<endl; - cout<<"u: "<<endl; u->Print(); - - delete u; delete vinv; - } - return; + return; } //________________________________________________________________________ -double ChamberDerivs::determinant(int ich) const -{ - - const TMatrixDSym* mat=this->secDerivMatrixROOT(ich); - - cout<<"getting det"<<endl; - double val=mat->Determinant(); - delete mat; - cout<<"val: "<<val<<endl; - return val; - +double ChamberDerivs::determinant(int ich) const { + const TMatrixDSym* mat = this->secDerivMatrixROOT(ich); + + cout << "getting det" << endl; + double val = mat->Determinant(); + delete mat; + cout << "val: " << val << endl; + return val; } //________________________________________________________________________ -HepSymMatrix* ChamberDerivs::secDerivMatrixCLHEP(int ich) const -{ - HepSymMatrix* newmat(0); - if (ich<0) { - newmat=new HepSymMatrix(m_nindices); - for (int i=0;i<m_nindices;i++) { - for (int j=i;j<m_nindices;j++) { - int index=i*m_nindices+j; - (*newmat)[i+1][j+1]=m_secDeriv[index]; - if (i!=j) (*newmat)[j+1][i+1]=m_secDeriv[index]; - //cout<<"newmat["<<i<<"]["<<j<<"]="<<m_secDeriv[index]<<endl; - } +HepSymMatrix* ChamberDerivs::secDerivMatrixCLHEP(int ich) const { + HepSymMatrix* newmat(0); + if (ich < 0) { + newmat = new HepSymMatrix(m_nindices); + for (int i = 0; i < m_nindices; i++) { + for (int j = i; j < m_nindices; j++) { + int index = i * m_nindices + j; + (*newmat)[i + 1][j + 1] = m_secDeriv[index]; + if (i != j) (*newmat)[j + 1][i + 1] = m_secDeriv[index]; + // cout<<"newmat["<<i<<"]["<<j<<"]="<<m_secDeriv[index]<<endl; + } + } + } else { + newmat = new HepSymMatrix(m_npar); + for (int ipar = 0; ipar < m_npar; ipar++) { + for (int jpar = ipar; jpar < m_npar; jpar++) { + double sd = this->secondDeriv(ich, ipar, ich, jpar); + (*newmat)[ipar + 1][jpar + 1] = sd; + if (ipar != jpar) (*newmat)[jpar + 1][ipar + 1] = sd; + // cout<<"newmat["<<ipar<<"]["<<jpar<<"]="<<sd<<endl; + } + } } - } - else { - newmat=new HepSymMatrix(m_npar); - for (int ipar=0;ipar<m_npar;ipar++) { - for (int jpar=ipar;jpar<m_npar;jpar++) { - double sd=this->secondDeriv(ich,ipar,ich,jpar); - (*newmat)[ipar+1][jpar+1]=sd; - if (ipar!=jpar) (*newmat)[jpar+1][ipar+1]=sd; - //cout<<"newmat["<<ipar<<"]["<<jpar<<"]="<<sd<<endl; - } - } - } - return newmat; + return newmat; } //________________________________________________________________________ -TMatrixDSym* ChamberDerivs::secDerivMatrixROOT(int ich, int npar) const -{ - - //this->PrintSecondDerivs(ich); - - int nindices=0; - double* array=0; - if (ich<0) { - cout<<"nindices: "<<nindices<<endl; - nindices=m_nindices; - array=new double[nindices*nindices]; - for (int i=0;i<m_nindices;i++) { - for (int j=0;j<m_nindices;j++) { - int index=i*m_nindices+j; - double sd=m_secDeriv[index]; - array[index]=sd; - index=j*m_nindices+i; - array[index]=sd; - } +TMatrixDSym* ChamberDerivs::secDerivMatrixROOT(int ich, int npar) const { + // this->PrintSecondDerivs(ich); + + int nindices = 0; + double* array = 0; + if (ich < 0) { + cout << "nindices: " << nindices << endl; + nindices = m_nindices; + array = new double[nindices * nindices]; + for (int i = 0; i < m_nindices; i++) { + for (int j = 0; j < m_nindices; j++) { + int index = i * m_nindices + j; + double sd = m_secDeriv[index]; + array[index] = sd; + index = j * m_nindices + i; + array[index] = sd; + } + } + } else { + nindices = (npar == 0) ? m_npar : npar; + array = new double[nindices * nindices]; + for (int ipar = 0; ipar < nindices; ipar++) { + for (int jpar = ipar; jpar < nindices; jpar++) { + double sd = this->secondDeriv(ich, ipar, ich, jpar); + int index = ipar * nindices + jpar; + array[index] = sd; + index = jpar * nindices + ipar; + array[index] = sd; + } + } } - } - else { - nindices=(npar==0)?m_npar:npar; - array=new double[nindices*nindices]; - for (int ipar=0;ipar<nindices;ipar++) { - for (int jpar=ipar;jpar<nindices;jpar++) { - double sd=this->secondDeriv(ich,ipar,ich,jpar); - int index=ipar*nindices+jpar; - array[index]=sd; - index=jpar*nindices+ipar; - array[index]=sd; - } - } - } - - TMatrixDSym* mat=new TMatrixDSym(nindices); - int index(0); - for (int i=0;i<nindices;i++) { - for (int j=0;j<nindices;j++) { - (*mat)[i][j]=array[index++]; + + TMatrixDSym* mat = new TMatrixDSym(nindices); + int index(0); + for (int i = 0; i < nindices; i++) { + for (int j = 0; j < nindices; j++) { (*mat)[i][j] = array[index++]; } } - } - //mat->Print(); + // mat->Print(); - delete [] array; - return mat; + delete[] array; + return mat; } //________________________________________________________________________ -double* ChamberDerivs::solve(double*& err, int ich, SolveType solveType) const -{ - - if (ich>=0) { - ChamberDerivs* localChDeriv=oneChamberDerivs(ich); - double* res=localChDeriv->solve(err,-1,solveType); - cout<<"res[0]="<<res[0]<<endl; - delete localChDeriv; - return res; - } - - double* res = (ich==-1)? new double[m_nindices] : new double[m_npar]; - err = (ich==-1)? new double[m_nindices] : new double[m_npar]; - - int ngoodentries=this->nindices(); - cout<<"ngoodentries="<<ngoodentries<<endl; - - double* secderiv=new double[ngoodentries*ngoodentries]; - double* firstderiv=new double[ngoodentries]; - for (int i=0;i<ngoodentries;i++) { - firstderiv[i]=this->firstDeriv(i); - //if (ngoodentries<10) - cout<<"firstderiv["<<i<<"]="<<firstderiv[i]<<endl; - for (int j=i;j<ngoodentries;j++) { - int index=i*ngoodentries+j; - double sd=this->secondDeriv(i,j); - secderiv[index]=sd; - index=j*ngoodentries+i; - secderiv[index]=sd; - //if (ngoodentries<10) - cout<<"secderiv["<<i<<"]["<<j<<"]="<<sd<<endl; - } - } - - if (solveType==CLHEP) { - if (ngoodentries<10) cout<<"solving CLHEP"<<endl; - HepSymMatrix d2Chi2(ngoodentries,0); - HepVector dChi2(ngoodentries,0); - for (int i=0;i<ngoodentries;i++) { - dChi2[i]=firstderiv[i]; - for (int j=0;j<ngoodentries;j++) { - int index=i*ngoodentries+j; - d2Chi2[i][j]=secderiv[index]; - } +double* ChamberDerivs::solve(double*& err, int ich, SolveType solveType) const { + if (ich >= 0) { + ChamberDerivs* localChDeriv = oneChamberDerivs(ich); + double* res = localChDeriv->solve(err, -1, solveType); + cout << "res[0]=" << res[0] << endl; + delete localChDeriv; + return res; } - if (ngoodentries<10) { - cout<<"d2Chi2: "<<d2Chi2<<endl; - cout<<"dChi2: "<<dChi2<<endl; + double* res = (ich == -1) ? new double[m_nindices] : new double[m_npar]; + err = (ich == -1) ? new double[m_nindices] : new double[m_npar]; + + int ngoodentries = this->nindices(); + cout << "ngoodentries=" << ngoodentries << endl; + + double* secderiv = new double[ngoodentries * ngoodentries]; + double* firstderiv = new double[ngoodentries]; + for (int i = 0; i < ngoodentries; i++) { + firstderiv[i] = this->firstDeriv(i); + // if (ngoodentries<10) + cout << "firstderiv[" << i << "]=" << firstderiv[i] << endl; + for (int j = i; j < ngoodentries; j++) { + int index = i * ngoodentries + j; + double sd = this->secondDeriv(i, j); + secderiv[index] = sd; + index = j * ngoodentries + i; + secderiv[index] = sd; + // if (ngoodentries<10) + cout << "secderiv[" << i << "][" << j << "]=" << sd << endl; + } } - HepSymMatrix cov(d2Chi2); - int ierr=0; - cov.invert(ierr); - - if (ngoodentries<10) - cout<<"cov: "<<cov<<endl; - - HepVector delta = cov * dChi2; - for (int i=0;i<ngoodentries;i++) { - res[i] = -delta[i]; - err[i] = std::sqrt(2.*std::fabs(cov(i+1,i+1))); - cout<<"i: "<<i<<", res/err: "<<res[i]<<"/"<<err[i]<<endl; - } - } - else if (solveType==ROOT) { - - TMatrixDSym a(ngoodentries,secderiv); - TVectorD b(ngoodentries,firstderiv); - - if (0) { - cout<<"First derivatives: "<<endl; - b.Print(); - - cout<<"Second derivatives: "<<endl; - a.Print(); + if (solveType == CLHEP) { + if (ngoodentries < 10) cout << "solving CLHEP" << endl; + HepSymMatrix d2Chi2(ngoodentries, 0); + HepVector dChi2(ngoodentries, 0); + for (int i = 0; i < ngoodentries; i++) { + dChi2[i] = firstderiv[i]; + for (int j = 0; j < ngoodentries; j++) { + int index = i * ngoodentries + j; + d2Chi2[i][j] = secderiv[index]; + } + } + + if (ngoodentries < 10) { + cout << "d2Chi2: " << d2Chi2 << endl; + cout << "dChi2: " << dChi2 << endl; + } + + HepSymMatrix cov(d2Chi2); + int ierr = 0; + cov.invert(ierr); + + if (ngoodentries < 10) cout << "cov: " << cov << endl; + + HepVector delta = cov * dChi2; + for (int i = 0; i < ngoodentries; i++) { + res[i] = -delta[i]; + err[i] = std::sqrt(2. * std::fabs(cov(i + 1, i + 1))); + cout << "i: " << i << ", res/err: " << res[i] << "/" << err[i] << endl; + } + } else if (solveType == ROOT) { + TMatrixDSym a(ngoodentries, secderiv); + TVectorD b(ngoodentries, firstderiv); + + if (0) { + cout << "First derivatives: " << endl; + b.Print(); + + cout << "Second derivatives: " << endl; + a.Print(); + } + + TDecompBK cm(a); + Bool_t status; + TMatrixDSym ainv(cm.Invert(status)); + TVectorD r(b.GetNrows()); + if (status) r = cm.Solve(b, status); + + for (int i = 0; i < ngoodentries; i++) { + res[i] = -r[i]; + err[i] = std::sqrt(2. * std::fabs(ainv(i, i))); + } + } else { + delete[] res; + res = 0; } - TDecompBK cm(a); - Bool_t status; - TMatrixDSym ainv(cm.Invert(status)); - TVectorD r(b.GetNrows()); - if (status) r = cm.Solve(b,status); - - for (int i=0;i<ngoodentries;i++) { - res[i]=-r[i]; - err[i]=std::sqrt(2.*std::fabs(ainv(i,i))); - } - } - else { - delete [] res; - res = 0; - } - - return res; + return res; } //________________________________________________________________________ -int ChamberDerivs::getChIndex(int id) const -{ - for (int ich=0;ich<m_nchambers;ich++) { - if (m_chamberIds[ich]==id) return ich; - } - return -1; +int ChamberDerivs::getChIndex(int id) const { + for (int ich = 0; ich < m_nchambers; ich++) { + if (m_chamberIds[ich] == id) return ich; + } + return -1; } //________________________________________________________________________ -void ChamberDerivs::addConstraint(int ich, int ipar, double constraint) -{ - cout<<"before constraint: "<<endl; - this->PrintChambers(ich); - this->PrintSecondDerivs(ich); - this->addSecondDeriv(ich,ipar,ich,ipar,constraint); - - cout<<endl<<"after constraint: "<<endl; - this->PrintChambers(ich); - this->PrintSecondDerivs(ich); -} +void ChamberDerivs::addConstraint(int ich, int ipar, double constraint) { + cout << "before constraint: " << endl; + this->PrintChambers(ich); + this->PrintSecondDerivs(ich); + this->addSecondDeriv(ich, ipar, ich, ipar, constraint); -//________________________________________________________________________ -void ChamberDerivs::addFirstDerivConstraint(int ich, int ipar, - double constraint) -{ - this->addFirstDeriv(ich,ipar,constraint); + cout << endl << "after constraint: " << endl; + this->PrintChambers(ich); + this->PrintSecondDerivs(ich); } +//________________________________________________________________________ +void ChamberDerivs::addFirstDerivConstraint(int ich, int ipar, double constraint) { this->addFirstDeriv(ich, ipar, constraint); } /* //________________________________________________________________________ ChamberDerivs ChamberDerivs::addParameter(int parameterToAdd, int totalNPar, - double* valueToAdd) + double* valueToAdd) { int mapNewToOldPar[totalNPar]; @@ -674,7 +597,7 @@ ChamberDerivs ChamberDerivs::addParameter(int parameterToAdd, int totalNPar, } cout<<"mapNewToOldPar["<<ipar<<"]="<<mapNewToOldPar[ipar]<<endl; } - + ChamberDerivs newChDerivs(totalNPar, this->nchambers()); for (int ich=0;ich<this->nchambers();ich++) { @@ -690,20 +613,19 @@ ChamberDerivs ChamberDerivs::addParameter(int parameterToAdd, int totalNPar, for (int jch=ich;jch<this->nchambers();jch++) { - if (ipar==0) newChDerivs.setNHits(ich,jch,this->nhits(ich,jch)); + if (ipar==0) newChDerivs.setNHits(ich,jch,this->nhits(ich,jch)); - for (int jpar=0;jpar<totalNPar;jpar++) { - int old_jpar=mapNewToOldPar[jpar]; + for (int jpar=0;jpar<totalNPar;jpar++) { + int old_jpar=mapNewToOldPar[jpar]; - double secndDeriv=this->secndDeriv(ich,old_ipar,jch,old_jpar); - if (ipar==parameterToAdd) secndDeriv+=valueToAdd[jpar]; - if (jpar==parameterToAdd && ipar!=jpar) secndDeriv+=valueToAdd[ipar]; - newChDerivs.setSecndDeriv(ich,ipar,jch,jpar,secndDeriv); - } + double secndDeriv=this->secndDeriv(ich,old_ipar,jch,old_jpar); + if (ipar==parameterToAdd) secndDeriv+=valueToAdd[jpar]; + if (jpar==parameterToAdd && ipar!=jpar) secndDeriv+=valueToAdd[ipar]; + newChDerivs.setSecndDeriv(ich,ipar,jch,jpar,secndDeriv); + } } } } return newChDerivs; } */ - diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/ChamberDerivs.h b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/ChamberDerivs.h index f3b72774c5ae00df41160aaad47d1a49433bf18b..1652cb328528e5c8bb60d0a7dbab5f48effbbd20 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/ChamberDerivs.h +++ b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/ChamberDerivs.h @@ -6,9 +6,9 @@ #define CHAMBERDERIVS_H #include <iostream> +#include <map> #include <string> #include <vector> -#include <map> #include "TMatrix.h" #include "TMatrixD.h" @@ -16,156 +16,147 @@ #include "TMatrixTUtils.h" namespace CLHEP { - class HepSymMatrix; + class HepSymMatrix; } class ChamberDerivs { - - public: - - enum SolveType { CLHEP,ROOT }; - - ChamberDerivs(); - ChamberDerivs(int npar, int nchambers); - virtual ~ChamberDerivs(); - - int npar() const { return m_npar; } - int nchambers() const { return m_nchambers; } - int nindices() const { return m_nindices; } - - // chamber ID - void setChamberId(int ich, int chid) { m_chamberIds[ich]=chid; } - int chamberId(int ich) const { return m_chamberIds[ich]; } - - int getChIndex(int id) const; - - // matrix index - void setMatrixIndex(int index, int matindex) { m_matrixIndices[index]=matindex; } - void setMatrixIndex(int ich, int ipar, int matindex) { m_matrixIndices[ich*m_npar+ipar]=matindex; } - int matrixIndex(int index) const { return m_matrixIndices[index]; } - int matrixIndex(int ich, int ipar) const { return m_matrixIndices[ich*m_npar+ipar]; } - - // first derivs - void setFirstDeriv(int index, double val) { m_firstDeriv[index]=val; } - void setFirstDeriv(int ich, int ipar, double val) { m_firstDeriv[ich*m_npar+ipar]=val; } - void addFirstDeriv(int index, double delta) { m_firstDeriv[index]+=delta; } - void addFirstDeriv(int ich, int ipar, double delta) { m_firstDeriv[ich*m_npar+ipar]+=delta; } - double firstDeriv(int i) const { return m_firstDeriv[i]; } - double firstDeriv(int ich, int ipar) const { return m_firstDeriv[ich*m_npar+ipar]; } - - // second derivs - void setSecondDeriv(int i_index, int j_index, double val); - void setSecondDeriv(int ich, int i_index, int jch, int j_index, double val); - - void addSecondDeriv(int i_index, int j_index, double delta); - void addSecondDeriv(int ich, int i_index, int jch, int j_index, double delta); - - double secondDeriv(int i_index, int j_index) const; - double secondDeriv(int ich, int i_index, int jch, int j_index) const; - - // hits - void incrementHitmap(int ich, int jch); - void incrementHitmap(int index); - void setNHits(int ich, int jch, int nhits); - void setNHits(int index,int nhits); - - int nhits(int ich, int jch) const { return m_hitmap[ich*m_nchambers+jch]; } - - // alignment parameters - double robustAlignPar(int ich, int ipar) const; - double robustAlignErr(int ich, int ipar) const; - double robustAlignPar(int index) const; - double robustAlignErr(int index) const; - - // matrix manipulation methods - ChamberDerivs trimmedChamberDerivs(int minHitsOnDiagonal, int minHitsOffDiagonal) const; - ChamberDerivs trimmedChamberDerivsBySV(double singularValueCut, int offdiagcut=0) const; - ChamberDerivs* oneChamberDerivs(int ich) const; - - CLHEP::HepSymMatrix* secDerivMatrixCLHEP(int ich=-1) const; - TMatrixDSym* secDerivMatrixROOT(int ich=-1, int npar=0) const; - - // dump methods - void PrintSecondDerivs(int ich=-1) const; - void PrintFirstDerivs(int ich=-1) const; - void PrintChambers(int ich=-1) const; - - // solve method - double* solve(double*& err, int ich=-1, SolveType solveType=CLHEP) const; - - // determinant - double determinant(int ich=-1) const; - double condition(int ich=-1) const; - double conditionChamberRemoved(int ich) const; - - - void singularValues(vector<double>& sv, - const TMatrixD*& u, const TMatrixD*& vinv,int ich=-1) const; - - // add constraint - //ChamberDerivs addParameter(int parameterToAdd, int totalNPar, - // double* valueToAdd=0); - void addConstraint(int ich, int ipar, double constraint); - void addFirstDerivConstraint(int ich, int ipar, double constraint); - void constrainLowestEigenvector(const std::map<int,string>& chamberIdMap); - - private: - int m_npar; - int m_nchambers; - int m_nindices; - - //std::list< std::pair<int,int>, double* > - int* m_chamberIds; - int* m_matrixIndices; - int* m_hitmap; - - double* m_secDeriv; - double* m_firstDeriv; +public: + enum SolveType { CLHEP, ROOT }; + + ChamberDerivs(); + ChamberDerivs(int npar, int nchambers); + virtual ~ChamberDerivs(); + + int npar() const { return m_npar; } + int nchambers() const { return m_nchambers; } + int nindices() const { return m_nindices; } + + // chamber ID + void setChamberId(int ich, int chid) { m_chamberIds[ich] = chid; } + int chamberId(int ich) const { return m_chamberIds[ich]; } + + int getChIndex(int id) const; + + // matrix index + void setMatrixIndex(int index, int matindex) { m_matrixIndices[index] = matindex; } + void setMatrixIndex(int ich, int ipar, int matindex) { m_matrixIndices[ich * m_npar + ipar] = matindex; } + int matrixIndex(int index) const { return m_matrixIndices[index]; } + int matrixIndex(int ich, int ipar) const { return m_matrixIndices[ich * m_npar + ipar]; } + + // first derivs + void setFirstDeriv(int index, double val) { m_firstDeriv[index] = val; } + void setFirstDeriv(int ich, int ipar, double val) { m_firstDeriv[ich * m_npar + ipar] = val; } + void addFirstDeriv(int index, double delta) { m_firstDeriv[index] += delta; } + void addFirstDeriv(int ich, int ipar, double delta) { m_firstDeriv[ich * m_npar + ipar] += delta; } + double firstDeriv(int i) const { return m_firstDeriv[i]; } + double firstDeriv(int ich, int ipar) const { return m_firstDeriv[ich * m_npar + ipar]; } + + // second derivs + void setSecondDeriv(int i_index, int j_index, double val); + void setSecondDeriv(int ich, int i_index, int jch, int j_index, double val); + + void addSecondDeriv(int i_index, int j_index, double delta); + void addSecondDeriv(int ich, int i_index, int jch, int j_index, double delta); + + double secondDeriv(int i_index, int j_index) const; + double secondDeriv(int ich, int i_index, int jch, int j_index) const; + + // hits + void incrementHitmap(int ich, int jch); + void incrementHitmap(int index); + void setNHits(int ich, int jch, int nhits); + void setNHits(int index, int nhits); + + int nhits(int ich, int jch) const { return m_hitmap[ich * m_nchambers + jch]; } + + // alignment parameters + double robustAlignPar(int ich, int ipar) const; + double robustAlignErr(int ich, int ipar) const; + double robustAlignPar(int index) const; + double robustAlignErr(int index) const; + + // matrix manipulation methods + ChamberDerivs trimmedChamberDerivs(int minHitsOnDiagonal, int minHitsOffDiagonal) const; + ChamberDerivs trimmedChamberDerivsBySV(double singularValueCut, int offdiagcut = 0) const; + ChamberDerivs* oneChamberDerivs(int ich) const; + + CLHEP::HepSymMatrix* secDerivMatrixCLHEP(int ich = -1) const; + TMatrixDSym* secDerivMatrixROOT(int ich = -1, int npar = 0) const; + + // dump methods + void PrintSecondDerivs(int ich = -1) const; + void PrintFirstDerivs(int ich = -1) const; + void PrintChambers(int ich = -1) const; + + // solve method + double* solve(double*& err, int ich = -1, SolveType solveType = CLHEP) const; + + // determinant + double determinant(int ich = -1) const; + double condition(int ich = -1) const; + double conditionChamberRemoved(int ich) const; + + void singularValues(vector<double>& sv, const TMatrixD*& u, const TMatrixD*& vinv, int ich = -1) const; + + // add constraint + // ChamberDerivs addParameter(int parameterToAdd, int totalNPar, + // double* valueToAdd=0); + void addConstraint(int ich, int ipar, double constraint); + void addFirstDerivConstraint(int ich, int ipar, double constraint); + void constrainLowestEigenvector(const std::map<int, string>& chamberIdMap); + +private: + int m_npar; + int m_nchambers; + int m_nindices; + + // std::list< std::pair<int,int>, double* > + int* m_chamberIds; + int* m_matrixIndices; + int* m_hitmap; + + double* m_secDeriv; + double* m_firstDeriv; }; -inline double ChamberDerivs::secondDeriv(int i_index, int j_index) const { return m_secDeriv[i_index*m_nindices+j_index]; } +inline double ChamberDerivs::secondDeriv(int i_index, int j_index) const { return m_secDeriv[i_index * m_nindices + j_index]; } -inline double ChamberDerivs::secondDeriv(int ich, int ipar, int jch, int jpar) const { int i_index=ich*m_npar+ipar; int j_index=jch*m_npar+jpar; return m_secDeriv[i_index*m_nindices+j_index]; } +inline double ChamberDerivs::secondDeriv(int ich, int ipar, int jch, int jpar) const { + int i_index = ich * m_npar + ipar; + int j_index = jch * m_npar + jpar; + return m_secDeriv[i_index * m_nindices + j_index]; +} //________________________________________________________________________ -inline void ChamberDerivs::addSecondDeriv(int i_index, int j_index, double delta) { m_secDeriv[i_index*m_nindices+j_index]+=delta; } +inline void ChamberDerivs::addSecondDeriv(int i_index, int j_index, double delta) { m_secDeriv[i_index * m_nindices + j_index] += delta; } //________________________________________________________________________ -inline void ChamberDerivs::addSecondDeriv(int ich, int ipar, int jch, int jpar, double delta) { - int i_index=ich*m_npar+ipar; - int j_index=jch*m_npar+jpar; - m_secDeriv[i_index*m_nindices+j_index]+=delta; +inline void ChamberDerivs::addSecondDeriv(int ich, int ipar, int jch, int jpar, double delta) { + int i_index = ich * m_npar + ipar; + int j_index = jch * m_npar + jpar; + m_secDeriv[i_index * m_nindices + j_index] += delta; } //________________________________________________________________________ -inline void ChamberDerivs::setSecondDeriv(int i_index, int j_index, double val) -{ - m_secDeriv[i_index*m_nindices+j_index]=val; -} +inline void ChamberDerivs::setSecondDeriv(int i_index, int j_index, double val) { m_secDeriv[i_index * m_nindices + j_index] = val; } //________________________________________________________________________ -inline void ChamberDerivs::setSecondDeriv(int ich, int ipar, int jch, int jpar, - double val) -{ - int i_index=ich*m_npar+ipar; - int j_index=jch*m_npar+jpar; - m_secDeriv[i_index*m_nindices+j_index]=val; +inline void ChamberDerivs::setSecondDeriv(int ich, int ipar, int jch, int jpar, double val) { + int i_index = ich * m_npar + ipar; + int j_index = jch * m_npar + jpar; + m_secDeriv[i_index * m_nindices + j_index] = val; } //________________________________________________________________________ -inline void ChamberDerivs::incrementHitmap(int ich, int jch) -{ m_hitmap[ich*m_nchambers+jch]++; } +inline void ChamberDerivs::incrementHitmap(int ich, int jch) { m_hitmap[ich * m_nchambers + jch]++; } //________________________________________________________________________ -inline void ChamberDerivs::incrementHitmap(int index) -{ m_hitmap[index]++; } +inline void ChamberDerivs::incrementHitmap(int index) { m_hitmap[index]++; } //________________________________________________________________________ -inline void ChamberDerivs::setNHits(int ich, int jch, int nhits) -{ m_hitmap[ich*m_nchambers+jch]=nhits; } +inline void ChamberDerivs::setNHits(int ich, int jch, int nhits) { m_hitmap[ich * m_nchambers + jch] = nhits; } //________________________________________________________________________ -inline void ChamberDerivs::setNHits(int index,int nhits) -{ m_hitmap[index]=nhits; } +inline void ChamberDerivs::setNHits(int index, int nhits) { m_hitmap[index] = nhits; } -#endif // CHAMBERDERIVS_H +#endif // CHAMBERDERIVS_H diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/ChamberNames.cpp b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/ChamberNames.cpp index 98848523eaf92396f0d79f4816aa99514b486dfd..c3f4ddb014d007d07343fbe4bf57a0e7bc962811 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/ChamberNames.cpp +++ b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/ChamberNames.cpp @@ -4,101 +4,92 @@ #include "ChamberNames.h" -#include <iostream> -#include <sstream> +#include <cstdlib> #include <fstream> #include <iomanip> -#include <cstdlib> - +#include <iostream> +#include <sstream> //________________________________________________________________________ -ChamberNames::ChamberNames(std::string filename) -{ - std::ifstream file(filename.c_str()); - if (!file.is_open()) { - std::cout<<"Can't open AlignmentConstantsFile"<<std::endl; - return; - } - - char ALineMarker; - int jff,jzz,job,ID; - std::string type; - double s,z,t,ths,thz,tht; - - while (file>>ALineMarker>> - type>>jff>>jzz>>job>> - s>>z>>t>>ths>>thz>>tht>>ID) { - - // make chamber name - std::stringstream chname; - chname<<type<<std::abs(jzz); - if (jzz<0) chname<<"C"; else chname<<"A"; - int detphi=2*jff; - if (type.substr(2,1)=="L") detphi--; - else if (type.substr(2,1)!="S"&&type!="BEE") detphi=jff; - chname<<std::setfill('0')<<std::setw(2)<<detphi; +ChamberNames::ChamberNames(std::string filename) { + std::ifstream file(filename.c_str()); + if (!file.is_open()) { + std::cout << "Can't open AlignmentConstantsFile" << std::endl; + return; + } - m_chamberIdMap[ID]=chname.str(); - } - file.close(); -} + char ALineMarker; + int jff, jzz, job, ID; + std::string type; + double s, z, t, ths, thz, tht; -//________________________________________________________________________ -ChamberNames::~ChamberNames() -{ + while (file >> ALineMarker >> type >> jff >> jzz >> job >> s >> z >> t >> ths >> thz >> tht >> ID) { + // make chamber name + std::stringstream chname; + chname << type << std::abs(jzz); + if (jzz < 0) + chname << "C"; + else + chname << "A"; + int detphi = 2 * jff; + if (type.substr(2, 1) == "L") + detphi--; + else if (type.substr(2, 1) != "S" && type != "BEE") + detphi = jff; + chname << std::setfill('0') << std::setw(2) << detphi; + m_chamberIdMap[ID] = chname.str(); + } + file.close(); } //________________________________________________________________________ -std::string ChamberNames::chamberName(int ID) const -{ - std::map<int,std::string>::const_iterator it=m_chamberIdMap.find(ID); - if (it!=m_chamberIdMap.end()) return it->second; - else { - std::cout<<"no chamber found for Identifier "<<ID<<std::endl; - return ""; - } -} +ChamberNames::~ChamberNames() {} //________________________________________________________________________ -int ChamberNames::stEta(int identifier) const -{ - std::string chname=this->chamberName(identifier); - return stEta(chname); +std::string ChamberNames::chamberName(int ID) const { + std::map<int, std::string>::const_iterator it = m_chamberIdMap.find(ID); + if (it != m_chamberIdMap.end()) + return it->second; + else { + std::cout << "no chamber found for Identifier " << ID << std::endl; + return ""; + } } //________________________________________________________________________ -int ChamberNames::stEta(const std::string& chname) const -{ - int jzz=atoi(chname.substr(3,1).c_str()); - if (chname.substr(4,1)=="C") jzz*=-1; - return jzz; +int ChamberNames::stEta(int identifier) const { + std::string chname = this->chamberName(identifier); + return stEta(chname); } //________________________________________________________________________ -int ChamberNames::stPhi(int identifier) const -{ - std::string chname=this->chamberName(identifier); - return stPhi(chname); +int ChamberNames::stEta(const std::string& chname) const { + int jzz = atoi(chname.substr(3, 1).c_str()); + if (chname.substr(4, 1) == "C") jzz *= -1; + return jzz; } //________________________________________________________________________ -int ChamberNames::stPhi(const std::string& chname) const -{ - int detphi=atoi(chname.substr(5,2).c_str()); - if (chname.substr(2,1)=="L") detphi++; - return detphi/2; +int ChamberNames::stPhi(int identifier) const { + std::string chname = this->chamberName(identifier); + return stPhi(chname); } //________________________________________________________________________ -int ChamberNames::chamberIdFromString(const std::string& chname) const -{ - std::map<int,std::string>::const_iterator it = m_chamberIdMap.begin(); - std::map<int,std::string>::const_iterator itEnd = m_chamberIdMap.end(); - - for (; it!=itEnd; ++it) { - if (it->second == chname) return it->first; - } - return -1; +int ChamberNames::stPhi(const std::string& chname) const { + int detphi = atoi(chname.substr(5, 2).c_str()); + if (chname.substr(2, 1) == "L") detphi++; + return detphi / 2; } +//________________________________________________________________________ +int ChamberNames::chamberIdFromString(const std::string& chname) const { + std::map<int, std::string>::const_iterator it = m_chamberIdMap.begin(); + std::map<int, std::string>::const_iterator itEnd = m_chamberIdMap.end(); + + for (; it != itEnd; ++it) { + if (it->second == chname) return it->first; + } + return -1; +} diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/ChamberNames.h b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/ChamberNames.h index b392c455737c751139647799ac65d3a86a1ce8bc..70146f74417587839b63f3ee8a4b86d53ccb843d 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/ChamberNames.h +++ b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/ChamberNames.h @@ -5,30 +5,27 @@ #ifndef CHAMBERNAMES_H #define CHAMBERNAMES_H -#include <map> #include <iostream> +#include <map> #include <string> class ChamberNames { +public: + ChamberNames(std::string filename); + virtual ~ChamberNames(); - public: - - ChamberNames(std::string filename); - virtual ~ChamberNames(); - - std::string chamberName(int identifier) const; - int chamberIdFromString(const std::string& chname) const; + std::string chamberName(int identifier) const; + int chamberIdFromString(const std::string& chname) const; - int stEta(int identifier) const; - int stEta(const std::string& chname) const; + int stEta(int identifier) const; + int stEta(const std::string& chname) const; - int stPhi(int identifier) const; - int stPhi(const std::string& chname) const; + int stPhi(int identifier) const; + int stPhi(const std::string& chname) const; - private: - ChamberNames(); - std::map<int,std::string> m_chamberIdMap; - +private: + ChamberNames(); + std::map<int, std::string> m_chamberIdMap; }; -#endif // CHAMBERNAMES_H +#endif // CHAMBERNAMES_H diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/MuonFixedId.h b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/MuonFixedId.h index 8db261280879be5665ea55a589b031fa3a177960..78a91c26ab8e7f0a77f13f098e513bb67b84886e 100755 --- a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/MuonFixedId.h +++ b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/MuonFixedId.h @@ -11,12 +11,11 @@ * Last Update : 18 April 2005 ***************************************************************************/ - #ifndef SRC_MUONFIXEDID_H #define SRC_MUONFIXEDID_H // std -#include <iostream> #include <iomanip> +#include <iostream> #include <string> // other packages @@ -24,1222 +23,1028 @@ // this package //#include "MuonCalibIdentifier/MuonStationName.h" - /** @namespace MuonCalib -* namespace to identify classes related only to muon calibration -*/ - -namespace MuonCalib { - -/** @class MuonFixedId - Implements fixed identifiers not dependent upon Athena Identifier for internal - use in the calibration framework. - * Fixed identifiers are encoded words which contain some muon generic fields - (for the technology, the station, eta and phi) and some technology specific - fields for Mdt, Csc, Rpc and Tgc. To each field XXX correspond - * an offset (a private static constant XXXShift) - * a minimum and a maximum storable value (derived from private static constantsXXXMin and XXXMask) - * Encoding or decoding of a value num in a given field proceeds via encoding - * or decoding and index, which is defined as num-XXXMin. + * namespace to identify classes related only to muon calibration */ -class MuonFixedId { -public: - /** default constructor */ - MuonFixedId(); - /** explicit constructor from an integer which corresponds to a MuonFixedId*/ - explicit MuonFixedId( unsigned int id ); - - /** @return the fixed identifier in integer form */ - unsigned int getIdInt() const; - - void setMuonIdentifier(int id); - - /** clear the identifier */ - void clear(); - /** check validity of the identifier. @return false if invalid */ - bool isValid(); - - /** @return true if the identifier corresponds to MDT technology */ - bool is_mdt() const; - /** @return true if the identifier corresponds to TGC technology */ - bool is_tgc() const; - /** @return true if the identifier corresponds to CSC technology */ - bool is_csc() const; - /** @return true if the identifier corresponds to RPC technology */ - bool is_rpc() const; - - /** comparison operator */ - bool operator==( const MuonFixedId& rhs ) const; - /** comparison operator */ - bool operator!=( const MuonFixedId& rhs ) const; - /** comparison operator */ - bool operator<( const MuonFixedId& rhs ) const; - - /** dump all the information corresponding to the identifier */ - std::ostream& dump(std::ostream& os) const; - -// friend std::istream& operator>>( std::istream& is, MuonCalib::MuonFixedId& id ); - -// Muon generic code - - /** set technology index in the fixed identifier - * @return false if out of range */ - bool setTechnologyIndex( unsigned int idx ); - /** set station name index in the fixed identifier - * @return false if out of range */ - bool setStationNameIndex( unsigned int idx ); - /** set station eta index in the fixed identifier - * @return false if out of range */ - bool setStationEtaIndex( unsigned int idx ); - /** set station phi index in the fixed identifier - * @return false if out of range */ - bool setStationPhiIndex( unsigned int idx ); - - /** set technology to num in the fixed identifier - * @return false if out of range */ - bool setTechnology( int num ); - /** set station name to num in the fixed identifier - * @return false if out of range */ - bool setStationName( int num ); - /** set station eta to num in the fixed identifier - * @return false if out of range */ - bool setStationEta( int num ); - /** set station phi to num in the fixed identifier - * @return false if out of range */ - bool setStationPhi( int num ); - - /** @return technology index */ - int technologyIndex() const; - /** @return station name index */ - int stationNameIndex() const; - /** @return station eta index */ - int etaIndex() const; - /** @return station phi index */ - int phiIndex() const; - - /** @return technology */ - int technology() const; - /** @return station name */ - int stationName() const; - /** @return station eta */ - int eta() const; - /** @return station phi */ - int phi() const; - - /** @return the minimum index used to store technology */ - static int technologyMin(); - /** @return the minimum index used to store station name */ - static int stationNameMin(); - /** @return the minimum index used to store station eta */ - static int etaMin(); - /** @return the minimum index used to store station phi */ - static int phiMin(); - - /** @return the maximum index used to store technology */ - static int technologyMax(); - /** @return the maximum index used to store station name */ - static int stationNameMax(); - /** @return the maximum index used to store station eta */ - static int etaMax(); - /** @return the maximum index used to store station phi */ - static int phiMax(); - - /** @return the fixed station number for a station name - * @param[in] station the station name string - */ - int stationStringToFixedStationNumber(const std::string station) const; - /** @return the station name string given the fixed station number - * @param[in] station the station integer number - */ - std::string stationNumberToFixedStationString(const int station) const; - - -// Mdt specific code - - /** Mdt specific: set index idx for tube - * @return false if out of range */ - bool setMdtTubeIndex( unsigned int idx ) ; - /** Mdt specific: set index idx for layer - * @return false if out of range */ - bool setMdtTubeLayerIndex( unsigned int idx ) ; - /** Mdt specific: set index idx for multilayer - * @return false if out of range */ - bool setMdtMultilayerIndex( unsigned int idx ) ; - - /** Mdt specific: set tube to num - * @return false if out of range */ - bool setMdtTube( int num ); - /** Mdt specific: set layer to num - * @return false if out of range */ - bool setMdtTubeLayer( int num ); - /** Mdt specific: set multilayer to num - * @return false if out of range */ - bool setMdtMultilayer( int num ); - - /** Mdt specific: @return tube index */ - int mdtTubeIndex() const; - /** Mdt specific: @return layer index */ - int mdtTubeLayerIndex() const; - /** Mdt specific: @return multilayer index */ - int mdtMultilayerIndex() const; - - /** Mdt specific: @return tube number*/ - int mdtTube() const; - /** Mdt specific: @return layer number*/ - int mdtTubeLayer() const; - /** Mdt specific: @return multilayer number*/ - int mdtMultilayer() const; - /** Mdt specific: compute the mezzanine number - * @return mezzanine number */ - int mdtMezzanine() const; - - /** Mdt specific: @return the minimum index used to store the tube number */ - static int mdtTubeMin(); - /** Mdt specific: @return the minimum index used to store the layer number */ - static int mdtTubeLayerMin(); - /** Mdt specific: @return the minimum index used to store the multilayer number */ - static int mdtMultilayerMin(); - - /** Mdt specific: @return the maximum index used to store the tube number */ - static int mdtTubeMax(); - /** Mdt specific: @return the maximum index used to store the layer number */ - static int mdtTubeLayerMax(); - /** Mdt specific: @return the maximum index used to store the multilayer number */ - static int mdtMultilayerMax(); - -// Csc specific code - - /** Csc specific: set chamber layer index to idx - * @return false if out of range */ - bool setCscChamberLayerIndex( unsigned int idx ); - /** Csc specific: set wire layer index to idx - * @return false if out of range */ - bool setCscWireLayerIndex( unsigned int idx ); - /** Csc specific: set measures_phi index to idx - * @return false if out of range */ - bool setCscMeasuresPhiIndex( unsigned int idx ); - /** Csc specific: set strip index to idx - * @return false if out of range */ - bool setCscStripIndex( unsigned int idx ); - - /** Csc specific: set chamber layer to num - * @return false if out of range */ - bool setCscChamberLayer( int num ); - /** Csc specific: set wire layer to num - * @return false if out of range */ - bool setCscWireLayer( int num ); - /** Csc specific: set measures_phi to num - * @return false if out of range */ - bool setCscMeasuresPhi( int num ); - /** Csc specific: set strip to num - * @return false if out of range */ - bool setCscStrip( int num ); - - /** Csc specific: @return chamber layer index */ - int cscChamberLayerIndex() const; - /** Csc specific: @return wire layer index */ - int cscWireLayerIndex() const; - /** Csc specific: @return measures_phi index */ - int cscMeasuresPhiIndex() const; - /** Csc specific: @return strip index */ - int cscStripIndex() const; - - /** Csc specific: @return chamber layer*/ - int cscChamberLayer() const; - /** Csc specific: @return wire layer*/ - int cscWireLayer() const; - /** Csc specific: @return measures_phi */ - int cscMeasuresPhi() const; - /** Csc specific: @return strip */ - int cscStrip() const; - - /** Csc specific: @return the minimum index used to store the chamber layer*/ - static int cscChamberLayerMin(); - /** Csc specific: @return the minimum index used to store the wire layer*/ - static int cscWireLayerMin(); - /** Csc specific: @return the minimum index used to store measures_phi */ - static int cscMeasuresPhiMin(); - /** Csc specific: @return the minimum index used to store the strip number */ - static int cscStripMin(); - - /** Csc specific: @return the maximum index used to store the chamber layer*/ - static int cscChamberLayerMax(); - /** Csc specific: @return the maximum index used to store the wire layer*/ - static int cscWireLayerMax(); - /** Csc specific: @return the maximum index used to store measures_phi */ - static int cscMeasuresPhiMax(); - /** Csc specific: @return the maximum index used to store the strip number */ - static int cscStripMax(); - -// Rpc specific code - - /** Rpc specific: set index for doublet_R to idx - * @return false if out of range */ - bool setRpcDoubletRIndex( unsigned int idx ); - /** Rpc specific: set index for doublet_Z to idx - * @return false if out of range */ - bool setRpcDoubletZIndex( unsigned int idx ); - /** Rpc specific: set index for doublet_Phi to idx - * @return false if out of range */ - bool setRpcDoubletPhiIndex( unsigned int idx ); - /** Rpc specific: set index for gas_gap to idx - * @return false if out of range */ - bool setRpcGasGapIndex( unsigned int idx ); - /** Rpc specific: set index for measures_phi to idx - * @return false if out of range */ - bool setRpcMeasuresPhiIndex( unsigned int idx ); - /** Rpc specific: set index for strip to idx - * @return false if out of range */ - bool setRpcStripIndex( unsigned int idx ); - - /** Rpc specific: set doublet_R to num - * @return false if out of range */ - bool setRpcDoubletR( int num ); - /** Rpc specific: set doublet_Z to num - * @return false if out of range */ - bool setRpcDoubletZ( int num ); - /** Rpc specific: set doublet_Phi to num - * @return false if out of range */ - bool setRpcDoubletPhi( int num ); - /** Rpc specific: set gas_gap to num - * @return false if out of range */ - bool setRpcGasGap( int num ); - /** Rpc specific: set measures_phi to num - * @return false if out of range */ - bool setRpcMeasuresPhi( int num ); - /** Rpc specific: set strip to num - * @return false if out of range */ - bool setRpcStrip( int num ); - - /** Rpc specific: - * @return doublet_R index*/ - int rpcDoubletRIndex() const; - /** Rpc specific: - * @return doublet_Z index*/ - int rpcDoubletZIndex() const; - /** Rpc specific: - * @return doublet_Phi index*/ - int rpcDoubletPhiIndex() const; - /** Rpc specific: - * @return gas_gap index*/ - int rpcGasGapIndex() const; - /** Rpc specific: - * @return measures_phi index*/ - int rpcMeasuresPhiIndex() const; - /** Rpc specific: - * @return strip index*/ - int rpcStripIndex() const; - - /** Rpc specific: - * @return doublet_R */ - int rpcDoubletR() const; - /** Rpc specific: - * @return doublet_Z */ - int rpcDoubletZ() const; - /** Rpc specific: - * @return doublet_Phi */ - int rpcDoubletPhi() const; - /** Rpc specific: - * @return gas_gap */ - int rpcGasGap() const; - /** Rpc specific: - * @return measures_phi */ - int rpcMeasuresPhi() const; - /** Rpc specific: - * @return strip */ - int rpcStrip() const; - -// Tgc specific code - - /** Tgc specific: set index for gas_gap to idx - * @return false if out of range */ - bool setTgcGasGapIndex( unsigned int idx ); - /** Tgc specific: set index for is_strip to idx - * @return false if out of range */ - bool setTgcIsStripIndex( unsigned int idx ); - /** Tgc specific: set index for channel to idx - * @return false if out of range */ - bool setTgcChannelIndex( unsigned int idx ); - - /** Tgc specific: set gas_gap to num - * @return false if out of range */ - bool setTgcGasGap( int num ); - /** Tgc specific: set is_strip to num - * @return false if out of range */ - bool setTgcIsStrip( int num ); - /** Tgc specific: set channel to num - * @return false if out of range */ - bool setTgcChannel( int num ); - - /** Tgc specific: - * @return gas_gap index */ - int tgcGasGapIndex() const; - /** Tgc specific: - * @return is_strip index */ - int tgcIsStripIndex() const; - /** Tgc specific: - * @return channel index */ - int tgcChannelIndex() const; - - /** Tgc specific: - * @return gas_gap */ - int tgcGasGap() const; - /** Tgc specific: - * @return is_strip */ - int tgcIsStrip() const; - /** Tgc specific: - * @return channel */ - int tgcChannel() const; - -private: - -// Muon generic - - static const unsigned int kTechnologyMask = 3; - static const unsigned int kTechnologyShift = 30; - static const unsigned int kTechnologyMin = 0; - - static const unsigned int kStationNameMask = 63; - static const unsigned int kStationNameShift = 24; - static const unsigned int kStationNameMin = 1; - - static const unsigned int kStationEtaMask = 31; - static const unsigned int kStationEtaShift = 19; - static const int kStationEtaMin = -8; - - static const unsigned int kStationPhiMask = 63; - static const unsigned int kStationPhiShift = 13; - static const unsigned int kStationPhiMin = 1; - - unsigned int m_data; - -// Mdt specific code - - static const unsigned int kMdtMultilayerMask = 1; - static const unsigned int kMdtMultilayerShift = 9; - static const unsigned int kMdtMultilayerMin = 1; - - static const unsigned int kMdtTubeLayerMask = 3; - static const unsigned int kMdtTubeLayerShift = 7; - static const unsigned int kMdtTubeLayerMin = 1; - - static const unsigned int kMdtTubeMask = 127; - static const unsigned int kMdtTubeShift = 0; - static const unsigned int kMdtTubeMin = 1; - -// Csc specific code - - static const unsigned int kCscChamberLayerMask = 1; - static const unsigned int kCscChamberLayerShift = 11; - static const unsigned int kCscChamberLayerMin = 1; - - static const unsigned int kCscWireLayerMask = 3; - static const unsigned int kCscWireLayerShift = 9; - static const unsigned int kCscWireLayerMin = 1; - - static const unsigned int kCscMeasuresPhiMask = 1; - static const unsigned int kCscMeasuresPhiShift = 8; - static const unsigned int kCscMeasuresPhiMin = 0; - - static const unsigned int kCscStripMask = 255; - static const unsigned int kCscStripShift = 0; - static const unsigned int kCscStripMin = 1; - -// Rpc specific code - - static const unsigned int kRpcDoubletRMask = 1; - static const unsigned int kRpcDoubletRShift = 12; - static const unsigned int kRpcDoubletRMin = 1; - - static const unsigned int kRpcDoubletZMask = 3; - static const unsigned int kRpcDoubletZShift = 10; - static const unsigned int kRpcDoubletZMin = 1; - - static const unsigned int kRpcDoubletPhiMask = 1; - static const unsigned int kRpcDoubletPhiShift = 9; - static const unsigned int kRpcDoubletPhiMin = 1; - - static const unsigned int kRpcGasGapMask = 1; - static const unsigned int kRpcGasGapShift = 8; - static const unsigned int kRpcGasGapMin = 1; - - static const unsigned int kRpcMeasuresPhiMask = 1; - static const unsigned int kRpcMeasuresPhiShift = 7; - static const unsigned int kRpcMeasuresPhiMin = 0; - - static const unsigned int kRpcStripMask = 127; - static const unsigned int kRpcStripShift = 0; - static const unsigned int kRpcStripMin = 1; - -// Tgc specific code - static const unsigned int kTgcGasGapMask = 3; - static const unsigned int kTgcGasGapShift = 9; - static const unsigned int kTgcGasGapMin = 1; - - static const unsigned int kTgcIsStripMask = 1; - static const unsigned int kTgcIsStripShift = 8; - static const unsigned int kTgcIsStripMin = 0; - - static const unsigned int kTgcChannelMask = 255; - static const unsigned int kTgcChannelShift = 0; - static const unsigned int kTgcChannelMin = 1; - -}; - -// Muon generic methods - -inline MuonFixedId::MuonFixedId() - : m_data(0xFFFFFFFF){ -} - -inline MuonFixedId::MuonFixedId( unsigned int id ) : m_data(id){ -} - -inline unsigned int MuonFixedId::getIdInt() const{ - return m_data; -} - -inline void MuonFixedId::setMuonIdentifier(int id) { - if( id>-1 || id<(int)0xFFFFFFFF ) m_data = id; - else m_data = 0xFFFFFFFF; - } - -inline void MuonFixedId::clear() { - m_data = 0xFFFFFFFF; -} - -inline bool MuonFixedId::isValid(){ - return m_data != 0xFFFFFFFF; -} - -inline bool MuonFixedId::is_mdt() const{ - if(m_data == 0xFFFFFFFF){ - return false; - } else { - if( technology() == 0 ){ - return true; - } else return false; - } -} - -inline bool MuonFixedId::is_tgc() const{ - if(m_data == 0xFFFFFFFF){ - return false; - } else { - if( technology() == 2 ){ - return true; - } else return false; - } -} - -inline bool MuonFixedId::is_csc() const{ - if(m_data == 0xFFFFFFFF){ - return false; - } else { - if( technology() == 1 ){ - return true; - } else return false; - } -} - -inline bool MuonFixedId::is_rpc() const{ - if(m_data == 0xFFFFFFFF){ - return false; - } else { - if( technology() == 3 ){ - return true; - } else return false; - } -} - -inline bool MuonFixedId::operator==( const MuonFixedId& rhs ) const { - return m_data == rhs.m_data; -} - -inline bool MuonFixedId::operator!=( const MuonFixedId& rhs ) const { - return m_data != rhs.m_data; -} - -inline bool MuonFixedId::operator<( const MuonFixedId& rhs ) const { - return m_data < rhs.m_data; -} - -inline bool MuonFixedId::setTechnologyIndex( unsigned int idx ) { - if ( idx > kTechnologyMask ) { - clear(); - return false; - } - m_data &= ~(kTechnologyMask << kTechnologyShift); - m_data |= (idx & kTechnologyMask) << kTechnologyShift; - return true; -} - -inline bool MuonFixedId::setTechnology( int num ) { - return setTechnologyIndex( num - kTechnologyMin ); -} - -inline int MuonFixedId::technologyIndex() const { - return (m_data >> kTechnologyShift) & kTechnologyMask; -} - -inline int MuonFixedId::technology() const { - return technologyIndex() + kTechnologyMin; -} - - -inline bool MuonFixedId::setStationNameIndex( unsigned int idx ) { - if ( idx > kStationNameMask ) { - clear(); - return false; - } - m_data &= ~(kStationNameMask << kStationNameShift); - m_data |= (idx & kStationNameMask) << kStationNameShift; - return true; -} - -inline bool MuonFixedId::setStationName( int num ) { - return setStationNameIndex( num - kStationNameMin ); -} - -inline int MuonFixedId::stationNameIndex() const { - return (m_data >> kStationNameShift) & kStationNameMask; -} - -inline int MuonFixedId::stationName() const { - return stationNameIndex() + kStationNameMin; -} - - -inline bool MuonFixedId::setStationEtaIndex( unsigned int idx ) { - if ( idx > kStationEtaMask ) { - clear(); - return false; - } - m_data &= ~(kStationEtaMask << kStationEtaShift); - m_data |= (idx & kStationEtaMask) << kStationEtaShift; - return true; -} - -inline bool MuonFixedId::setStationEta( int num ) { - return setStationEtaIndex( num - kStationEtaMin ); -} - -inline int MuonFixedId::etaIndex() const { - return (m_data >> kStationEtaShift) & kStationEtaMask; -} - -inline int MuonFixedId::eta() const { - return etaIndex() + kStationEtaMin; -} - - -inline bool MuonFixedId::setStationPhiIndex( unsigned int idx ) { - if ( idx > kStationPhiMask ) { - clear(); - return false; - } - m_data &= ~(kStationPhiMask << kStationPhiShift); - m_data |= (idx & kStationPhiMask) << kStationPhiShift; - return true; -} - -inline bool MuonFixedId::setStationPhi( int num ) { - return setStationPhiIndex( num - kStationPhiMin ); -} - -inline int MuonFixedId::phiIndex() const { - return (m_data >> kStationPhiShift) & kStationPhiMask; -} - -inline int MuonFixedId::phi() const { - return phiIndex() + kStationPhiMin; -} - -inline int MuonFixedId::technologyMin(){ - return kTechnologyMin; -} - -inline int MuonFixedId::stationNameMin(){ - return kStationNameMin; -} - -inline int MuonFixedId::etaMin(){ - return kStationEtaMin; -} - -inline int MuonFixedId::phiMin(){ - return kStationPhiMin; -} - -inline int MuonFixedId::technologyMax(){ - return kTechnologyMin + kTechnologyMask; -} - -inline int MuonFixedId::stationNameMax(){ - return kStationNameMin + kStationNameMask; -} - -inline int MuonFixedId::etaMax(){ - return kStationEtaMin + kStationEtaMask; -} - -inline int MuonFixedId::phiMax(){ - return kStationPhiMin + kStationPhiMask; -} - -inline int MuonFixedId::stationStringToFixedStationNumber(const std::string station ) const -{ - if(station == "BIL" ) return 1; - if(station == "BIS" ) return 2; - if(station == "BML" ) return 3; - if(station == "BMS" ) return 4; - if(station == "BOL" ) return 5; - if(station == "BOS" ) return 6; - if(station == "BEE" ) return 7; - if(station == "BIR" ) return 8; - if(station == "BMF" ) return 9; - if(station == "BOF" ) return 10; - if(station == "BOG" ) return 11; - if(station == "BME" ) return 12; - if(station == "BIM" ) return 13; - if(station == "EIC" ) return 14; - if(station == "EIL" ) return 15; - if(station == "EEL" ) return 16; - if(station == "EES" ) return 17; - if(station == "EMC" ) return 18; - if(station == "EML" ) return 19; - if(station == "EMS" ) return 20; - if(station == "EOC" ) return 21; - if(station == "EOL" ) return 22; - if(station == "EOS" ) return 23; - if(station == "EIS" ) return 24; - if(station == "T1F" ) return 25; - if(station == "T1E" ) return 26; - if(station == "T2F" ) return 27; - if(station == "T2E" ) return 28; - if(station == "T3F" ) return 29; - if(station == "T3E" ) return 30; - if(station == "T4F" ) return 31; - if(station == "T4E" ) return 32; - if(station == "CSS" ) return 33; - if(station == "CSL" ) return 34; - if(station == "BMG" ) return 35; - if(station == "XXX" ) return -1; - return -1; -} - -inline std::string MuonFixedId::stationNumberToFixedStationString(const int station) const -{ - if(station == 1 ) return "BIL" ; - if(station == 2 ) return "BIS" ; - if(station == 3 ) return "BML" ; - if(station == 4 ) return "BMS" ; - if(station == 5 ) return "BOL" ; - if(station == 6 ) return "BOS" ; - if(station == 7 ) return "BEE" ; - if(station == 8 ) return "BIR" ; - if(station == 9 ) return "BMF" ; - if(station == 10 ) return "BOF" ; - if(station == 11 ) return "BOG" ; - if(station == 12 ) return "BME" ; - if(station == 13 ) return "BIM" ; - if(station == 14 ) return "EIC" ; - if(station == 15 ) return "EIL" ; - if(station == 16 ) return "EEL" ; - if(station == 17 ) return "EES" ; - if(station == 18 ) return "EMC" ; - if(station == 19 ) return "EML" ; - if(station == 20 ) return "EMS" ; - if(station == 21 ) return "EOC" ; - if(station == 22 ) return "EOL" ; - if(station == 23 ) return "EOS" ; - if(station == 24 ) return "EIS" ; - if(station == 25 ) return "T1F" ; - if(station == 26 ) return "T1E" ; - if(station == 27 ) return "T2F" ; - if(station == 28 ) return "T2E" ; - if(station == 29 ) return "T3F" ; - if(station == 30 ) return "T3E" ; - if(station == 31 ) return "T4F" ; - if(station == 32 ) return "T4E" ; - if(station == 33 ) return "CSS" ; - if(station == 34 ) return "CSL" ; - if(station == 35 ) return "BMG" ; - else return "XXX" ; -} - -// Mdt specific methods - -inline bool MuonFixedId::setMdtTubeIndex( unsigned int idx ) { - if ( idx > kMdtTubeMask ) { - clear(); - return false; - } - m_data &= ~(kMdtTubeMask << kMdtTubeShift); - m_data |= (idx & kMdtTubeMask) << kMdtTubeShift; - return true; -} - -inline bool MuonFixedId::setMdtTube( int num ) { - return setMdtTubeIndex( num - kMdtTubeMin ); -} - -inline int MuonFixedId::mdtTubeIndex() const { - return (m_data >> kMdtTubeShift) & kMdtTubeMask; -} - -inline int MuonFixedId::mdtTube() const { - return mdtTubeIndex() + kMdtTubeMin; -} - -inline int MuonFixedId::mdtMezzanine() const { - int Ichamber = stationName() ; - int Ieta = eta() ; - int Iphi = phi() ; - int Iml = mdtMultilayer() ; - int Itube = mdtTube() ; - if (Ieta < 0 ) Ieta = -Ieta*10 ; - int ImezzTubes = 8 ; - if (Ichamber==1 || Ichamber==2 || Ichamber==8 || Ichamber==13) ImezzTubes=6 ; - int Imezz = ((Itube-1)/ImezzTubes)*2+(Iml-1) ; - Imezz = 9*100000000 + Ichamber*1000000 + Ieta*10000 + Iphi*100 + Imezz ; - - // std::cout << "Imezz Ichamber Ieta Iphi Iml Itube " - // << Imezz <<" " << Ichamber <<" "<< Ieta <<" " << Iphi - // <<" " << Iml <<" " << Itube << std::endl ; - return Imezz ; -} - - - -inline bool MuonFixedId::setMdtTubeLayerIndex( unsigned int idx ) { - if ( idx > kMdtTubeLayerMask ) { - clear(); - return false; - } - m_data &= ~(kMdtTubeLayerMask << kMdtTubeLayerShift); - m_data |= (idx & kMdtTubeLayerMask) << kMdtTubeLayerShift; - return true; -} - -inline bool MuonFixedId::setMdtTubeLayer( int num ) { - return setMdtTubeLayerIndex( num - kMdtTubeLayerMin ); -} - -inline int MuonFixedId::mdtTubeLayerIndex() const { - return (m_data >> kMdtTubeLayerShift) & kMdtTubeLayerMask; -} - -inline int MuonFixedId::mdtTubeLayer() const { - return mdtTubeLayerIndex() + kMdtTubeLayerMin; -} - - -inline bool MuonFixedId::setMdtMultilayerIndex( unsigned int idx ) { - if ( idx > kMdtMultilayerMask ) { - clear(); - return false; - } - m_data &= ~(kMdtMultilayerMask << kMdtMultilayerShift); - m_data |= (idx & kMdtMultilayerMask) << kMdtMultilayerShift; - return true; -} - -inline bool MuonFixedId::setMdtMultilayer( int num ) { - return setMdtMultilayerIndex( num - kMdtMultilayerMin ); -} - -inline int MuonFixedId::mdtMultilayerIndex() const { - return (m_data >> kMdtMultilayerShift) & kMdtMultilayerMask; -} - -inline int MuonFixedId::mdtMultilayer() const { - return mdtMultilayerIndex() + kMdtMultilayerMin; -} - -inline int MuonFixedId::mdtTubeMin(){ - return kMdtTubeMin; -} - -inline int MuonFixedId::mdtTubeMax(){ - return kMdtTubeMin + kMdtTubeMask; -} - -inline int MuonFixedId::mdtTubeLayerMin(){ - return kMdtTubeLayerMin; -} - -inline int MuonFixedId::mdtTubeLayerMax(){ - return kMdtTubeLayerMin + kMdtTubeLayerMask; -} - -inline int MuonFixedId::mdtMultilayerMin(){ - return kMdtMultilayerMin; -} - -inline int MuonFixedId::mdtMultilayerMax(){ - return kMdtMultilayerMin + kMdtMultilayerMask; -} - -// Csc specific methods - -inline bool MuonFixedId::setCscChamberLayerIndex( unsigned int idx ) { - if ( idx > kCscChamberLayerMask ) { - clear(); - return false; - } - m_data &= ~( kCscChamberLayerMask << kCscChamberLayerShift ); - m_data |= (idx & kCscChamberLayerMask) << kCscChamberLayerShift; - return true; -} - -inline bool MuonFixedId::setCscChamberLayer( int num ) { - return setCscChamberLayerIndex( num - kCscChamberLayerMin ); -} - -inline int MuonFixedId::cscChamberLayerIndex() const { - return (m_data >> kCscChamberLayerShift) & kCscChamberLayerMask; -} - -inline int MuonFixedId::cscChamberLayer() const { - return cscChamberLayerIndex() + kCscChamberLayerMin; -} - - -inline bool MuonFixedId::setCscWireLayerIndex( unsigned int idx ) { - if ( idx > kCscWireLayerMask ) { - clear(); - return false; - } - m_data &= ~( kCscWireLayerMask << kCscWireLayerShift ); - m_data |= (idx & kCscWireLayerMask) << kCscWireLayerShift; - return true; -} - -inline bool MuonFixedId::setCscWireLayer( int num ) { - return setCscWireLayerIndex( num - kCscWireLayerMin ); -} +namespace MuonCalib { -inline int MuonFixedId::cscWireLayerIndex() const { - return (m_data >> kCscWireLayerShift) & kCscWireLayerMask; -} + /** @class MuonFixedId + Implements fixed identifiers not dependent upon Athena Identifier for internal + use in the calibration framework. + * Fixed identifiers are encoded words which contain some muon generic fields + (for the technology, the station, eta and phi) and some technology specific + fields for Mdt, Csc, Rpc and Tgc. To each field XXX correspond + * an offset (a private static constant XXXShift) + * a minimum and a maximum storable value (derived from private static constantsXXXMin and XXXMask) + * Encoding or decoding of a value num in a given field proceeds via encoding + * or decoding and index, which is defined as num-XXXMin. + */ + + class MuonFixedId { + public: + /** default constructor */ + MuonFixedId(); + /** explicit constructor from an integer which corresponds to a MuonFixedId*/ + explicit MuonFixedId(unsigned int id); + + /** @return the fixed identifier in integer form */ + unsigned int getIdInt() const; + + void setMuonIdentifier(int id); + + /** clear the identifier */ + void clear(); + /** check validity of the identifier. @return false if invalid */ + bool isValid(); + + /** @return true if the identifier corresponds to MDT technology */ + bool is_mdt() const; + /** @return true if the identifier corresponds to TGC technology */ + bool is_tgc() const; + /** @return true if the identifier corresponds to CSC technology */ + bool is_csc() const; + /** @return true if the identifier corresponds to RPC technology */ + bool is_rpc() const; + + /** comparison operator */ + bool operator==(const MuonFixedId& rhs) const; + /** comparison operator */ + bool operator!=(const MuonFixedId& rhs) const; + /** comparison operator */ + bool operator<(const MuonFixedId& rhs) const; + + /** dump all the information corresponding to the identifier */ + std::ostream& dump(std::ostream& os) const; + + // friend std::istream& operator>>( std::istream& is, MuonCalib::MuonFixedId& id ); + + // Muon generic code + + /** set technology index in the fixed identifier + * @return false if out of range */ + bool setTechnologyIndex(unsigned int idx); + /** set station name index in the fixed identifier + * @return false if out of range */ + bool setStationNameIndex(unsigned int idx); + /** set station eta index in the fixed identifier + * @return false if out of range */ + bool setStationEtaIndex(unsigned int idx); + /** set station phi index in the fixed identifier + * @return false if out of range */ + bool setStationPhiIndex(unsigned int idx); + + /** set technology to num in the fixed identifier + * @return false if out of range */ + bool setTechnology(int num); + /** set station name to num in the fixed identifier + * @return false if out of range */ + bool setStationName(int num); + /** set station eta to num in the fixed identifier + * @return false if out of range */ + bool setStationEta(int num); + /** set station phi to num in the fixed identifier + * @return false if out of range */ + bool setStationPhi(int num); + + /** @return technology index */ + int technologyIndex() const; + /** @return station name index */ + int stationNameIndex() const; + /** @return station eta index */ + int etaIndex() const; + /** @return station phi index */ + int phiIndex() const; + + /** @return technology */ + int technology() const; + /** @return station name */ + int stationName() const; + /** @return station eta */ + int eta() const; + /** @return station phi */ + int phi() const; + + /** @return the minimum index used to store technology */ + static int technologyMin(); + /** @return the minimum index used to store station name */ + static int stationNameMin(); + /** @return the minimum index used to store station eta */ + static int etaMin(); + /** @return the minimum index used to store station phi */ + static int phiMin(); + + /** @return the maximum index used to store technology */ + static int technologyMax(); + /** @return the maximum index used to store station name */ + static int stationNameMax(); + /** @return the maximum index used to store station eta */ + static int etaMax(); + /** @return the maximum index used to store station phi */ + static int phiMax(); + + /** @return the fixed station number for a station name + * @param[in] station the station name string + */ + int stationStringToFixedStationNumber(const std::string station) const; + /** @return the station name string given the fixed station number + * @param[in] station the station integer number + */ + std::string stationNumberToFixedStationString(const int station) const; + + // Mdt specific code + + /** Mdt specific: set index idx for tube + * @return false if out of range */ + bool setMdtTubeIndex(unsigned int idx); + /** Mdt specific: set index idx for layer + * @return false if out of range */ + bool setMdtTubeLayerIndex(unsigned int idx); + /** Mdt specific: set index idx for multilayer + * @return false if out of range */ + bool setMdtMultilayerIndex(unsigned int idx); + + /** Mdt specific: set tube to num + * @return false if out of range */ + bool setMdtTube(int num); + /** Mdt specific: set layer to num + * @return false if out of range */ + bool setMdtTubeLayer(int num); + /** Mdt specific: set multilayer to num + * @return false if out of range */ + bool setMdtMultilayer(int num); + + /** Mdt specific: @return tube index */ + int mdtTubeIndex() const; + /** Mdt specific: @return layer index */ + int mdtTubeLayerIndex() const; + /** Mdt specific: @return multilayer index */ + int mdtMultilayerIndex() const; + + /** Mdt specific: @return tube number*/ + int mdtTube() const; + /** Mdt specific: @return layer number*/ + int mdtTubeLayer() const; + /** Mdt specific: @return multilayer number*/ + int mdtMultilayer() const; + /** Mdt specific: compute the mezzanine number + * @return mezzanine number */ + int mdtMezzanine() const; + + /** Mdt specific: @return the minimum index used to store the tube number */ + static int mdtTubeMin(); + /** Mdt specific: @return the minimum index used to store the layer number */ + static int mdtTubeLayerMin(); + /** Mdt specific: @return the minimum index used to store the multilayer number */ + static int mdtMultilayerMin(); + + /** Mdt specific: @return the maximum index used to store the tube number */ + static int mdtTubeMax(); + /** Mdt specific: @return the maximum index used to store the layer number */ + static int mdtTubeLayerMax(); + /** Mdt specific: @return the maximum index used to store the multilayer number */ + static int mdtMultilayerMax(); + + // Csc specific code + + /** Csc specific: set chamber layer index to idx + * @return false if out of range */ + bool setCscChamberLayerIndex(unsigned int idx); + /** Csc specific: set wire layer index to idx + * @return false if out of range */ + bool setCscWireLayerIndex(unsigned int idx); + /** Csc specific: set measures_phi index to idx + * @return false if out of range */ + bool setCscMeasuresPhiIndex(unsigned int idx); + /** Csc specific: set strip index to idx + * @return false if out of range */ + bool setCscStripIndex(unsigned int idx); + + /** Csc specific: set chamber layer to num + * @return false if out of range */ + bool setCscChamberLayer(int num); + /** Csc specific: set wire layer to num + * @return false if out of range */ + bool setCscWireLayer(int num); + /** Csc specific: set measures_phi to num + * @return false if out of range */ + bool setCscMeasuresPhi(int num); + /** Csc specific: set strip to num + * @return false if out of range */ + bool setCscStrip(int num); + + /** Csc specific: @return chamber layer index */ + int cscChamberLayerIndex() const; + /** Csc specific: @return wire layer index */ + int cscWireLayerIndex() const; + /** Csc specific: @return measures_phi index */ + int cscMeasuresPhiIndex() const; + /** Csc specific: @return strip index */ + int cscStripIndex() const; + + /** Csc specific: @return chamber layer*/ + int cscChamberLayer() const; + /** Csc specific: @return wire layer*/ + int cscWireLayer() const; + /** Csc specific: @return measures_phi */ + int cscMeasuresPhi() const; + /** Csc specific: @return strip */ + int cscStrip() const; + + /** Csc specific: @return the minimum index used to store the chamber layer*/ + static int cscChamberLayerMin(); + /** Csc specific: @return the minimum index used to store the wire layer*/ + static int cscWireLayerMin(); + /** Csc specific: @return the minimum index used to store measures_phi */ + static int cscMeasuresPhiMin(); + /** Csc specific: @return the minimum index used to store the strip number */ + static int cscStripMin(); + + /** Csc specific: @return the maximum index used to store the chamber layer*/ + static int cscChamberLayerMax(); + /** Csc specific: @return the maximum index used to store the wire layer*/ + static int cscWireLayerMax(); + /** Csc specific: @return the maximum index used to store measures_phi */ + static int cscMeasuresPhiMax(); + /** Csc specific: @return the maximum index used to store the strip number */ + static int cscStripMax(); + + // Rpc specific code + + /** Rpc specific: set index for doublet_R to idx + * @return false if out of range */ + bool setRpcDoubletRIndex(unsigned int idx); + /** Rpc specific: set index for doublet_Z to idx + * @return false if out of range */ + bool setRpcDoubletZIndex(unsigned int idx); + /** Rpc specific: set index for doublet_Phi to idx + * @return false if out of range */ + bool setRpcDoubletPhiIndex(unsigned int idx); + /** Rpc specific: set index for gas_gap to idx + * @return false if out of range */ + bool setRpcGasGapIndex(unsigned int idx); + /** Rpc specific: set index for measures_phi to idx + * @return false if out of range */ + bool setRpcMeasuresPhiIndex(unsigned int idx); + /** Rpc specific: set index for strip to idx + * @return false if out of range */ + bool setRpcStripIndex(unsigned int idx); + + /** Rpc specific: set doublet_R to num + * @return false if out of range */ + bool setRpcDoubletR(int num); + /** Rpc specific: set doublet_Z to num + * @return false if out of range */ + bool setRpcDoubletZ(int num); + /** Rpc specific: set doublet_Phi to num + * @return false if out of range */ + bool setRpcDoubletPhi(int num); + /** Rpc specific: set gas_gap to num + * @return false if out of range */ + bool setRpcGasGap(int num); + /** Rpc specific: set measures_phi to num + * @return false if out of range */ + bool setRpcMeasuresPhi(int num); + /** Rpc specific: set strip to num + * @return false if out of range */ + bool setRpcStrip(int num); + + /** Rpc specific: + * @return doublet_R index*/ + int rpcDoubletRIndex() const; + /** Rpc specific: + * @return doublet_Z index*/ + int rpcDoubletZIndex() const; + /** Rpc specific: + * @return doublet_Phi index*/ + int rpcDoubletPhiIndex() const; + /** Rpc specific: + * @return gas_gap index*/ + int rpcGasGapIndex() const; + /** Rpc specific: + * @return measures_phi index*/ + int rpcMeasuresPhiIndex() const; + /** Rpc specific: + * @return strip index*/ + int rpcStripIndex() const; + + /** Rpc specific: + * @return doublet_R */ + int rpcDoubletR() const; + /** Rpc specific: + * @return doublet_Z */ + int rpcDoubletZ() const; + /** Rpc specific: + * @return doublet_Phi */ + int rpcDoubletPhi() const; + /** Rpc specific: + * @return gas_gap */ + int rpcGasGap() const; + /** Rpc specific: + * @return measures_phi */ + int rpcMeasuresPhi() const; + /** Rpc specific: + * @return strip */ + int rpcStrip() const; + + // Tgc specific code + + /** Tgc specific: set index for gas_gap to idx + * @return false if out of range */ + bool setTgcGasGapIndex(unsigned int idx); + /** Tgc specific: set index for is_strip to idx + * @return false if out of range */ + bool setTgcIsStripIndex(unsigned int idx); + /** Tgc specific: set index for channel to idx + * @return false if out of range */ + bool setTgcChannelIndex(unsigned int idx); + + /** Tgc specific: set gas_gap to num + * @return false if out of range */ + bool setTgcGasGap(int num); + /** Tgc specific: set is_strip to num + * @return false if out of range */ + bool setTgcIsStrip(int num); + /** Tgc specific: set channel to num + * @return false if out of range */ + bool setTgcChannel(int num); + + /** Tgc specific: + * @return gas_gap index */ + int tgcGasGapIndex() const; + /** Tgc specific: + * @return is_strip index */ + int tgcIsStripIndex() const; + /** Tgc specific: + * @return channel index */ + int tgcChannelIndex() const; + + /** Tgc specific: + * @return gas_gap */ + int tgcGasGap() const; + /** Tgc specific: + * @return is_strip */ + int tgcIsStrip() const; + /** Tgc specific: + * @return channel */ + int tgcChannel() const; + + private: + // Muon generic + + static const unsigned int kTechnologyMask = 3; + static const unsigned int kTechnologyShift = 30; + static const unsigned int kTechnologyMin = 0; + + static const unsigned int kStationNameMask = 63; + static const unsigned int kStationNameShift = 24; + static const unsigned int kStationNameMin = 1; + + static const unsigned int kStationEtaMask = 31; + static const unsigned int kStationEtaShift = 19; + static const int kStationEtaMin = -8; + + static const unsigned int kStationPhiMask = 63; + static const unsigned int kStationPhiShift = 13; + static const unsigned int kStationPhiMin = 1; + + unsigned int m_data; + + // Mdt specific code + + static const unsigned int kMdtMultilayerMask = 1; + static const unsigned int kMdtMultilayerShift = 9; + static const unsigned int kMdtMultilayerMin = 1; + + static const unsigned int kMdtTubeLayerMask = 3; + static const unsigned int kMdtTubeLayerShift = 7; + static const unsigned int kMdtTubeLayerMin = 1; + + static const unsigned int kMdtTubeMask = 127; + static const unsigned int kMdtTubeShift = 0; + static const unsigned int kMdtTubeMin = 1; + + // Csc specific code + + static const unsigned int kCscChamberLayerMask = 1; + static const unsigned int kCscChamberLayerShift = 11; + static const unsigned int kCscChamberLayerMin = 1; + + static const unsigned int kCscWireLayerMask = 3; + static const unsigned int kCscWireLayerShift = 9; + static const unsigned int kCscWireLayerMin = 1; + + static const unsigned int kCscMeasuresPhiMask = 1; + static const unsigned int kCscMeasuresPhiShift = 8; + static const unsigned int kCscMeasuresPhiMin = 0; + + static const unsigned int kCscStripMask = 255; + static const unsigned int kCscStripShift = 0; + static const unsigned int kCscStripMin = 1; + + // Rpc specific code + + static const unsigned int kRpcDoubletRMask = 1; + static const unsigned int kRpcDoubletRShift = 12; + static const unsigned int kRpcDoubletRMin = 1; + + static const unsigned int kRpcDoubletZMask = 3; + static const unsigned int kRpcDoubletZShift = 10; + static const unsigned int kRpcDoubletZMin = 1; + + static const unsigned int kRpcDoubletPhiMask = 1; + static const unsigned int kRpcDoubletPhiShift = 9; + static const unsigned int kRpcDoubletPhiMin = 1; + + static const unsigned int kRpcGasGapMask = 1; + static const unsigned int kRpcGasGapShift = 8; + static const unsigned int kRpcGasGapMin = 1; + + static const unsigned int kRpcMeasuresPhiMask = 1; + static const unsigned int kRpcMeasuresPhiShift = 7; + static const unsigned int kRpcMeasuresPhiMin = 0; + + static const unsigned int kRpcStripMask = 127; + static const unsigned int kRpcStripShift = 0; + static const unsigned int kRpcStripMin = 1; + + // Tgc specific code + static const unsigned int kTgcGasGapMask = 3; + static const unsigned int kTgcGasGapShift = 9; + static const unsigned int kTgcGasGapMin = 1; + + static const unsigned int kTgcIsStripMask = 1; + static const unsigned int kTgcIsStripShift = 8; + static const unsigned int kTgcIsStripMin = 0; + + static const unsigned int kTgcChannelMask = 255; + static const unsigned int kTgcChannelShift = 0; + static const unsigned int kTgcChannelMin = 1; + }; + + // Muon generic methods + + inline MuonFixedId::MuonFixedId() : m_data(0xFFFFFFFF) {} + + inline MuonFixedId::MuonFixedId(unsigned int id) : m_data(id) {} + + inline unsigned int MuonFixedId::getIdInt() const { return m_data; } + + inline void MuonFixedId::setMuonIdentifier(int id) { + if (id > -1 || id < (int)0xFFFFFFFF) + m_data = id; + else + m_data = 0xFFFFFFFF; + } + + inline void MuonFixedId::clear() { m_data = 0xFFFFFFFF; } + + inline bool MuonFixedId::isValid() { return m_data != 0xFFFFFFFF; } + + inline bool MuonFixedId::is_mdt() const { + if (m_data == 0xFFFFFFFF) { + return false; + } else { + if (technology() == 0) { + return true; + } else + return false; + } + } + + inline bool MuonFixedId::is_tgc() const { + if (m_data == 0xFFFFFFFF) { + return false; + } else { + if (technology() == 2) { + return true; + } else + return false; + } + } -inline int MuonFixedId::cscWireLayer() const { - return cscWireLayerIndex() + kCscWireLayerMin; -} + inline bool MuonFixedId::is_csc() const { + if (m_data == 0xFFFFFFFF) { + return false; + } else { + if (technology() == 1) { + return true; + } else + return false; + } + } + inline bool MuonFixedId::is_rpc() const { + if (m_data == 0xFFFFFFFF) { + return false; + } else { + if (technology() == 3) { + return true; + } else + return false; + } + } + + inline bool MuonFixedId::operator==(const MuonFixedId& rhs) const { return m_data == rhs.m_data; } + + inline bool MuonFixedId::operator!=(const MuonFixedId& rhs) const { return m_data != rhs.m_data; } + + inline bool MuonFixedId::operator<(const MuonFixedId& rhs) const { return m_data < rhs.m_data; } + + inline bool MuonFixedId::setTechnologyIndex(unsigned int idx) { + if (idx > kTechnologyMask) { + clear(); + return false; + } + m_data &= ~(kTechnologyMask << kTechnologyShift); + m_data |= (idx & kTechnologyMask) << kTechnologyShift; + return true; + } + + inline bool MuonFixedId::setTechnology(int num) { return setTechnologyIndex(num - kTechnologyMin); } + + inline int MuonFixedId::technologyIndex() const { return (m_data >> kTechnologyShift) & kTechnologyMask; } + + inline int MuonFixedId::technology() const { return technologyIndex() + kTechnologyMin; } + + inline bool MuonFixedId::setStationNameIndex(unsigned int idx) { + if (idx > kStationNameMask) { + clear(); + return false; + } + m_data &= ~(kStationNameMask << kStationNameShift); + m_data |= (idx & kStationNameMask) << kStationNameShift; + return true; + } + + inline bool MuonFixedId::setStationName(int num) { return setStationNameIndex(num - kStationNameMin); } + + inline int MuonFixedId::stationNameIndex() const { return (m_data >> kStationNameShift) & kStationNameMask; } + + inline int MuonFixedId::stationName() const { return stationNameIndex() + kStationNameMin; } + + inline bool MuonFixedId::setStationEtaIndex(unsigned int idx) { + if (idx > kStationEtaMask) { + clear(); + return false; + } + m_data &= ~(kStationEtaMask << kStationEtaShift); + m_data |= (idx & kStationEtaMask) << kStationEtaShift; + return true; + } + + inline bool MuonFixedId::setStationEta(int num) { return setStationEtaIndex(num - kStationEtaMin); } + + inline int MuonFixedId::etaIndex() const { return (m_data >> kStationEtaShift) & kStationEtaMask; } + + inline int MuonFixedId::eta() const { return etaIndex() + kStationEtaMin; } + + inline bool MuonFixedId::setStationPhiIndex(unsigned int idx) { + if (idx > kStationPhiMask) { + clear(); + return false; + } + m_data &= ~(kStationPhiMask << kStationPhiShift); + m_data |= (idx & kStationPhiMask) << kStationPhiShift; + return true; + } + + inline bool MuonFixedId::setStationPhi(int num) { return setStationPhiIndex(num - kStationPhiMin); } + + inline int MuonFixedId::phiIndex() const { return (m_data >> kStationPhiShift) & kStationPhiMask; } + + inline int MuonFixedId::phi() const { return phiIndex() + kStationPhiMin; } + + inline int MuonFixedId::technologyMin() { return kTechnologyMin; } + + inline int MuonFixedId::stationNameMin() { return kStationNameMin; } + + inline int MuonFixedId::etaMin() { return kStationEtaMin; } + + inline int MuonFixedId::phiMin() { return kStationPhiMin; } + + inline int MuonFixedId::technologyMax() { return kTechnologyMin + kTechnologyMask; } + + inline int MuonFixedId::stationNameMax() { return kStationNameMin + kStationNameMask; } + + inline int MuonFixedId::etaMax() { return kStationEtaMin + kStationEtaMask; } + + inline int MuonFixedId::phiMax() { return kStationPhiMin + kStationPhiMask; } + + inline int MuonFixedId::stationStringToFixedStationNumber(const std::string station) const { + if (station == "BIL") return 1; + if (station == "BIS") return 2; + if (station == "BML") return 3; + if (station == "BMS") return 4; + if (station == "BOL") return 5; + if (station == "BOS") return 6; + if (station == "BEE") return 7; + if (station == "BIR") return 8; + if (station == "BMF") return 9; + if (station == "BOF") return 10; + if (station == "BOG") return 11; + if (station == "BME") return 12; + if (station == "BIM") return 13; + if (station == "EIC") return 14; + if (station == "EIL") return 15; + if (station == "EEL") return 16; + if (station == "EES") return 17; + if (station == "EMC") return 18; + if (station == "EML") return 19; + if (station == "EMS") return 20; + if (station == "EOC") return 21; + if (station == "EOL") return 22; + if (station == "EOS") return 23; + if (station == "EIS") return 24; + if (station == "T1F") return 25; + if (station == "T1E") return 26; + if (station == "T2F") return 27; + if (station == "T2E") return 28; + if (station == "T3F") return 29; + if (station == "T3E") return 30; + if (station == "T4F") return 31; + if (station == "T4E") return 32; + if (station == "CSS") return 33; + if (station == "CSL") return 34; + if (station == "BMG") return 35; + if (station == "XXX") return -1; + return -1; + } + + inline std::string MuonFixedId::stationNumberToFixedStationString(const int station) const { + if (station == 1) return "BIL"; + if (station == 2) return "BIS"; + if (station == 3) return "BML"; + if (station == 4) return "BMS"; + if (station == 5) return "BOL"; + if (station == 6) return "BOS"; + if (station == 7) return "BEE"; + if (station == 8) return "BIR"; + if (station == 9) return "BMF"; + if (station == 10) return "BOF"; + if (station == 11) return "BOG"; + if (station == 12) return "BME"; + if (station == 13) return "BIM"; + if (station == 14) return "EIC"; + if (station == 15) return "EIL"; + if (station == 16) return "EEL"; + if (station == 17) return "EES"; + if (station == 18) return "EMC"; + if (station == 19) return "EML"; + if (station == 20) return "EMS"; + if (station == 21) return "EOC"; + if (station == 22) return "EOL"; + if (station == 23) return "EOS"; + if (station == 24) return "EIS"; + if (station == 25) return "T1F"; + if (station == 26) return "T1E"; + if (station == 27) return "T2F"; + if (station == 28) return "T2E"; + if (station == 29) return "T3F"; + if (station == 30) return "T3E"; + if (station == 31) return "T4F"; + if (station == 32) return "T4E"; + if (station == 33) return "CSS"; + if (station == 34) return "CSL"; + if (station == 35) + return "BMG"; + else + return "XXX"; + } + + // Mdt specific methods + + inline bool MuonFixedId::setMdtTubeIndex(unsigned int idx) { + if (idx > kMdtTubeMask) { + clear(); + return false; + } + m_data &= ~(kMdtTubeMask << kMdtTubeShift); + m_data |= (idx & kMdtTubeMask) << kMdtTubeShift; + return true; + } + + inline bool MuonFixedId::setMdtTube(int num) { return setMdtTubeIndex(num - kMdtTubeMin); } + + inline int MuonFixedId::mdtTubeIndex() const { return (m_data >> kMdtTubeShift) & kMdtTubeMask; } + + inline int MuonFixedId::mdtTube() const { return mdtTubeIndex() + kMdtTubeMin; } + + inline int MuonFixedId::mdtMezzanine() const { + int Ichamber = stationName(); + int Ieta = eta(); + int Iphi = phi(); + int Iml = mdtMultilayer(); + int Itube = mdtTube(); + if (Ieta < 0) Ieta = -Ieta * 10; + int ImezzTubes = 8; + if (Ichamber == 1 || Ichamber == 2 || Ichamber == 8 || Ichamber == 13) ImezzTubes = 6; + int Imezz = ((Itube - 1) / ImezzTubes) * 2 + (Iml - 1); + Imezz = 9 * 100000000 + Ichamber * 1000000 + Ieta * 10000 + Iphi * 100 + Imezz; + + // std::cout << "Imezz Ichamber Ieta Iphi Iml Itube " + // << Imezz <<" " << Ichamber <<" "<< Ieta <<" " << Iphi + // <<" " << Iml <<" " << Itube << std::endl ; + return Imezz; + } + + inline bool MuonFixedId::setMdtTubeLayerIndex(unsigned int idx) { + if (idx > kMdtTubeLayerMask) { + clear(); + return false; + } + m_data &= ~(kMdtTubeLayerMask << kMdtTubeLayerShift); + m_data |= (idx & kMdtTubeLayerMask) << kMdtTubeLayerShift; + return true; + } + + inline bool MuonFixedId::setMdtTubeLayer(int num) { return setMdtTubeLayerIndex(num - kMdtTubeLayerMin); } + + inline int MuonFixedId::mdtTubeLayerIndex() const { return (m_data >> kMdtTubeLayerShift) & kMdtTubeLayerMask; } + + inline int MuonFixedId::mdtTubeLayer() const { return mdtTubeLayerIndex() + kMdtTubeLayerMin; } + + inline bool MuonFixedId::setMdtMultilayerIndex(unsigned int idx) { + if (idx > kMdtMultilayerMask) { + clear(); + return false; + } + m_data &= ~(kMdtMultilayerMask << kMdtMultilayerShift); + m_data |= (idx & kMdtMultilayerMask) << kMdtMultilayerShift; + return true; + } + + inline bool MuonFixedId::setMdtMultilayer(int num) { return setMdtMultilayerIndex(num - kMdtMultilayerMin); } + + inline int MuonFixedId::mdtMultilayerIndex() const { return (m_data >> kMdtMultilayerShift) & kMdtMultilayerMask; } + + inline int MuonFixedId::mdtMultilayer() const { return mdtMultilayerIndex() + kMdtMultilayerMin; } + + inline int MuonFixedId::mdtTubeMin() { return kMdtTubeMin; } + + inline int MuonFixedId::mdtTubeMax() { return kMdtTubeMin + kMdtTubeMask; } + + inline int MuonFixedId::mdtTubeLayerMin() { return kMdtTubeLayerMin; } + + inline int MuonFixedId::mdtTubeLayerMax() { return kMdtTubeLayerMin + kMdtTubeLayerMask; } + + inline int MuonFixedId::mdtMultilayerMin() { return kMdtMultilayerMin; } -inline bool MuonFixedId::setCscMeasuresPhiIndex( unsigned int idx ) { - if ( idx > kCscMeasuresPhiMask ) { - clear(); - return false; - } - m_data &= ~( kCscMeasuresPhiMask << kCscMeasuresPhiShift ); - m_data |= (idx & kCscMeasuresPhiMask) << kCscMeasuresPhiShift; - return true; -} + inline int MuonFixedId::mdtMultilayerMax() { return kMdtMultilayerMin + kMdtMultilayerMask; } -inline bool MuonFixedId::setCscMeasuresPhi( int num ) { - return setCscMeasuresPhiIndex( num - kCscMeasuresPhiMin ); -} + // Csc specific methods -inline int MuonFixedId::cscMeasuresPhiIndex() const { - return (m_data >> kCscMeasuresPhiShift) & kCscMeasuresPhiMask; -} + inline bool MuonFixedId::setCscChamberLayerIndex(unsigned int idx) { + if (idx > kCscChamberLayerMask) { + clear(); + return false; + } + m_data &= ~(kCscChamberLayerMask << kCscChamberLayerShift); + m_data |= (idx & kCscChamberLayerMask) << kCscChamberLayerShift; + return true; + } -inline int MuonFixedId::cscMeasuresPhi() const { - return cscMeasuresPhiIndex() + kCscMeasuresPhiMin; -} + inline bool MuonFixedId::setCscChamberLayer(int num) { return setCscChamberLayerIndex(num - kCscChamberLayerMin); } + inline int MuonFixedId::cscChamberLayerIndex() const { return (m_data >> kCscChamberLayerShift) & kCscChamberLayerMask; } -inline bool MuonFixedId::setCscStripIndex( unsigned int idx ) { - if ( idx > kCscStripMask ) { - clear(); - return false; - } - m_data &= ~( kCscStripMask << kCscStripShift ); - m_data |= (idx & kCscStripMask) << kCscStripShift; - return true; -} + inline int MuonFixedId::cscChamberLayer() const { return cscChamberLayerIndex() + kCscChamberLayerMin; } -inline bool MuonFixedId::setCscStrip( int num ) { - return setCscStripIndex( num - kCscStripMin ); -} + inline bool MuonFixedId::setCscWireLayerIndex(unsigned int idx) { + if (idx > kCscWireLayerMask) { + clear(); + return false; + } + m_data &= ~(kCscWireLayerMask << kCscWireLayerShift); + m_data |= (idx & kCscWireLayerMask) << kCscWireLayerShift; + return true; + } -inline int MuonFixedId::cscStripIndex() const { - return (m_data >> kCscStripShift) & kCscStripMask; -} + inline bool MuonFixedId::setCscWireLayer(int num) { return setCscWireLayerIndex(num - kCscWireLayerMin); } -inline int MuonFixedId::cscStrip() const { - return cscStripIndex() + kCscStripMin; -} + inline int MuonFixedId::cscWireLayerIndex() const { return (m_data >> kCscWireLayerShift) & kCscWireLayerMask; } -inline int MuonFixedId::cscChamberLayerMin(){ - return kCscChamberLayerMin; -} + inline int MuonFixedId::cscWireLayer() const { return cscWireLayerIndex() + kCscWireLayerMin; } -inline int MuonFixedId::cscChamberLayerMax(){ - return kCscChamberLayerMin + kCscChamberLayerMask; -} + inline bool MuonFixedId::setCscMeasuresPhiIndex(unsigned int idx) { + if (idx > kCscMeasuresPhiMask) { + clear(); + return false; + } + m_data &= ~(kCscMeasuresPhiMask << kCscMeasuresPhiShift); + m_data |= (idx & kCscMeasuresPhiMask) << kCscMeasuresPhiShift; + return true; + } -inline int MuonFixedId::cscWireLayerMin(){ - return kCscWireLayerMin; -} + inline bool MuonFixedId::setCscMeasuresPhi(int num) { return setCscMeasuresPhiIndex(num - kCscMeasuresPhiMin); } -inline int MuonFixedId::cscWireLayerMax(){ - return kCscWireLayerMin + kCscWireLayerMask; -} + inline int MuonFixedId::cscMeasuresPhiIndex() const { return (m_data >> kCscMeasuresPhiShift) & kCscMeasuresPhiMask; } -inline int MuonFixedId::cscMeasuresPhiMin(){ - return kCscMeasuresPhiMin; -} + inline int MuonFixedId::cscMeasuresPhi() const { return cscMeasuresPhiIndex() + kCscMeasuresPhiMin; } -inline int MuonFixedId::cscMeasuresPhiMax(){ - return kCscMeasuresPhiMin + kCscMeasuresPhiMask; -} + inline bool MuonFixedId::setCscStripIndex(unsigned int idx) { + if (idx > kCscStripMask) { + clear(); + return false; + } + m_data &= ~(kCscStripMask << kCscStripShift); + m_data |= (idx & kCscStripMask) << kCscStripShift; + return true; + } -inline int MuonFixedId::cscStripMin(){ - return kCscStripMin; -} + inline bool MuonFixedId::setCscStrip(int num) { return setCscStripIndex(num - kCscStripMin); } -inline int MuonFixedId::cscStripMax(){ - return kCscStripMin + kCscStripMask; -} -// Rpc specific methods - -inline bool MuonFixedId::setRpcDoubletRIndex( unsigned int idx ) { - if ( idx > kRpcDoubletRMask ) { - clear(); - return false; - } - m_data &= ~( kRpcDoubletRMask << kRpcDoubletRShift ); - m_data |= (idx & kRpcDoubletRMask) << kRpcDoubletRShift; - return true; -} + inline int MuonFixedId::cscStripIndex() const { return (m_data >> kCscStripShift) & kCscStripMask; } -inline bool MuonFixedId::setRpcDoubletR( int num ) { - return setRpcDoubletRIndex( num - kRpcDoubletRMin ); -} + inline int MuonFixedId::cscStrip() const { return cscStripIndex() + kCscStripMin; } -inline int MuonFixedId::rpcDoubletRIndex() const { - return (m_data >> kRpcDoubletRShift) & kRpcDoubletRMask; -} + inline int MuonFixedId::cscChamberLayerMin() { return kCscChamberLayerMin; } -inline int MuonFixedId::rpcDoubletR() const { - return rpcDoubletRIndex() + kRpcDoubletRMin; -} + inline int MuonFixedId::cscChamberLayerMax() { return kCscChamberLayerMin + kCscChamberLayerMask; } + inline int MuonFixedId::cscWireLayerMin() { return kCscWireLayerMin; } -inline bool MuonFixedId::setRpcDoubletZIndex( unsigned int idx ) { - if ( idx > kRpcDoubletZMask ) { - clear(); - return false; - } - m_data &= ~( kRpcDoubletZMask << kRpcDoubletZShift ); - m_data |= (idx & kRpcDoubletZMask) << kRpcDoubletZShift; - return true; -} + inline int MuonFixedId::cscWireLayerMax() { return kCscWireLayerMin + kCscWireLayerMask; } -inline bool MuonFixedId::setRpcDoubletZ( int num ) { - return setRpcDoubletZIndex( num - kRpcDoubletZMin ); -} + inline int MuonFixedId::cscMeasuresPhiMin() { return kCscMeasuresPhiMin; } -inline int MuonFixedId::rpcDoubletZIndex() const { - return (m_data >> kRpcDoubletZShift) & kRpcDoubletZMask; -} + inline int MuonFixedId::cscMeasuresPhiMax() { return kCscMeasuresPhiMin + kCscMeasuresPhiMask; } -inline int MuonFixedId::rpcDoubletZ() const { - return rpcDoubletZIndex() + kRpcDoubletZMin; -} + inline int MuonFixedId::cscStripMin() { return kCscStripMin; } + inline int MuonFixedId::cscStripMax() { return kCscStripMin + kCscStripMask; } + // Rpc specific methods -inline bool MuonFixedId::setRpcDoubletPhiIndex( unsigned int idx ) { - if ( idx > kRpcDoubletPhiMask ) { - clear(); - return false; - } - m_data &= ~( kRpcDoubletPhiMask << kRpcDoubletPhiShift ); - m_data |= (idx & kRpcDoubletPhiMask) << kRpcDoubletPhiShift; - return true; -} + inline bool MuonFixedId::setRpcDoubletRIndex(unsigned int idx) { + if (idx > kRpcDoubletRMask) { + clear(); + return false; + } + m_data &= ~(kRpcDoubletRMask << kRpcDoubletRShift); + m_data |= (idx & kRpcDoubletRMask) << kRpcDoubletRShift; + return true; + } -inline bool MuonFixedId::setRpcDoubletPhi( int num ) { - return setRpcDoubletPhiIndex( num - kRpcDoubletPhiMin ); -} + inline bool MuonFixedId::setRpcDoubletR(int num) { return setRpcDoubletRIndex(num - kRpcDoubletRMin); } -inline int MuonFixedId::rpcDoubletPhiIndex() const { - return (m_data >> kRpcDoubletPhiShift) & kRpcDoubletPhiMask; -} + inline int MuonFixedId::rpcDoubletRIndex() const { return (m_data >> kRpcDoubletRShift) & kRpcDoubletRMask; } -inline int MuonFixedId::rpcDoubletPhi() const { - return rpcDoubletPhiIndex() + kRpcDoubletPhiMin; -} + inline int MuonFixedId::rpcDoubletR() const { return rpcDoubletRIndex() + kRpcDoubletRMin; } + inline bool MuonFixedId::setRpcDoubletZIndex(unsigned int idx) { + if (idx > kRpcDoubletZMask) { + clear(); + return false; + } + m_data &= ~(kRpcDoubletZMask << kRpcDoubletZShift); + m_data |= (idx & kRpcDoubletZMask) << kRpcDoubletZShift; + return true; + } -inline bool MuonFixedId::setRpcGasGapIndex( unsigned int idx ) { - if ( idx > kRpcGasGapMask ) { - clear(); - return false; - } - m_data &= ~( kRpcGasGapMask << kRpcGasGapShift ); - m_data |= (idx & kRpcGasGapMask) << kRpcGasGapShift; - return true; -} + inline bool MuonFixedId::setRpcDoubletZ(int num) { return setRpcDoubletZIndex(num - kRpcDoubletZMin); } -inline bool MuonFixedId::setRpcGasGap( int num ) { - return setRpcGasGapIndex( num - kRpcGasGapMin ); -} + inline int MuonFixedId::rpcDoubletZIndex() const { return (m_data >> kRpcDoubletZShift) & kRpcDoubletZMask; } -inline int MuonFixedId::rpcGasGapIndex() const { - return (m_data >> kRpcGasGapShift) & kRpcGasGapMask; -} + inline int MuonFixedId::rpcDoubletZ() const { return rpcDoubletZIndex() + kRpcDoubletZMin; } -inline int MuonFixedId::rpcGasGap() const { - return rpcGasGapIndex() + kRpcGasGapMin; -} + inline bool MuonFixedId::setRpcDoubletPhiIndex(unsigned int idx) { + if (idx > kRpcDoubletPhiMask) { + clear(); + return false; + } + m_data &= ~(kRpcDoubletPhiMask << kRpcDoubletPhiShift); + m_data |= (idx & kRpcDoubletPhiMask) << kRpcDoubletPhiShift; + return true; + } + inline bool MuonFixedId::setRpcDoubletPhi(int num) { return setRpcDoubletPhiIndex(num - kRpcDoubletPhiMin); } -inline bool MuonFixedId::setRpcMeasuresPhiIndex( unsigned int idx ) { - if ( idx > kRpcMeasuresPhiMask ) { - clear(); - return false; - } - m_data &= ~( kRpcMeasuresPhiMask << kRpcMeasuresPhiShift ); - m_data |= (idx & kRpcMeasuresPhiMask) << kRpcMeasuresPhiShift; - return true; -} + inline int MuonFixedId::rpcDoubletPhiIndex() const { return (m_data >> kRpcDoubletPhiShift) & kRpcDoubletPhiMask; } -inline bool MuonFixedId::setRpcMeasuresPhi( int num ) { - return setRpcMeasuresPhiIndex( num - kRpcMeasuresPhiMin ); -} + inline int MuonFixedId::rpcDoubletPhi() const { return rpcDoubletPhiIndex() + kRpcDoubletPhiMin; } -inline int MuonFixedId::rpcMeasuresPhiIndex() const { - return (m_data >> kRpcMeasuresPhiShift) & kRpcMeasuresPhiMask; -} + inline bool MuonFixedId::setRpcGasGapIndex(unsigned int idx) { + if (idx > kRpcGasGapMask) { + clear(); + return false; + } + m_data &= ~(kRpcGasGapMask << kRpcGasGapShift); + m_data |= (idx & kRpcGasGapMask) << kRpcGasGapShift; + return true; + } -inline int MuonFixedId::rpcMeasuresPhi() const { - return rpcMeasuresPhiIndex() + kRpcMeasuresPhiMin; -} + inline bool MuonFixedId::setRpcGasGap(int num) { return setRpcGasGapIndex(num - kRpcGasGapMin); } + inline int MuonFixedId::rpcGasGapIndex() const { return (m_data >> kRpcGasGapShift) & kRpcGasGapMask; } -inline bool MuonFixedId::setRpcStripIndex( unsigned int idx ) { - if ( idx > kRpcStripMask ) { - clear(); - return false; - } - m_data &= ~( kRpcStripMask << kRpcStripShift ); - m_data |= (idx & kRpcStripMask) << kRpcStripShift; - return true; -} + inline int MuonFixedId::rpcGasGap() const { return rpcGasGapIndex() + kRpcGasGapMin; } -inline bool MuonFixedId::setRpcStrip( int num ) { - return setRpcStripIndex( num - kRpcStripMin ); -} + inline bool MuonFixedId::setRpcMeasuresPhiIndex(unsigned int idx) { + if (idx > kRpcMeasuresPhiMask) { + clear(); + return false; + } + m_data &= ~(kRpcMeasuresPhiMask << kRpcMeasuresPhiShift); + m_data |= (idx & kRpcMeasuresPhiMask) << kRpcMeasuresPhiShift; + return true; + } -inline int MuonFixedId::rpcStripIndex() const { - return (m_data >> kRpcStripShift) & kRpcStripMask; -} + inline bool MuonFixedId::setRpcMeasuresPhi(int num) { return setRpcMeasuresPhiIndex(num - kRpcMeasuresPhiMin); } -inline int MuonFixedId::rpcStrip() const { - return rpcStripIndex() + kRpcStripMin; -} + inline int MuonFixedId::rpcMeasuresPhiIndex() const { return (m_data >> kRpcMeasuresPhiShift) & kRpcMeasuresPhiMask; } + inline int MuonFixedId::rpcMeasuresPhi() const { return rpcMeasuresPhiIndex() + kRpcMeasuresPhiMin; } -// Tgc specific methods + inline bool MuonFixedId::setRpcStripIndex(unsigned int idx) { + if (idx > kRpcStripMask) { + clear(); + return false; + } + m_data &= ~(kRpcStripMask << kRpcStripShift); + m_data |= (idx & kRpcStripMask) << kRpcStripShift; + return true; + } -inline bool MuonFixedId::setTgcGasGapIndex( unsigned int idx ) { - if ( idx > kTgcGasGapMask ) { - clear(); - return false; - } - m_data &= ~( kTgcGasGapMask << kTgcGasGapShift ); - m_data |= (idx & kTgcGasGapMask) << kTgcGasGapShift; - return true; -} + inline bool MuonFixedId::setRpcStrip(int num) { return setRpcStripIndex(num - kRpcStripMin); } -inline bool MuonFixedId::setTgcGasGap( int num ) { - return setTgcGasGapIndex( num - kTgcGasGapMin ); -} + inline int MuonFixedId::rpcStripIndex() const { return (m_data >> kRpcStripShift) & kRpcStripMask; } -inline int MuonFixedId::tgcGasGapIndex() const { - return (m_data >> kTgcGasGapShift) & kTgcGasGapMask; -} + inline int MuonFixedId::rpcStrip() const { return rpcStripIndex() + kRpcStripMin; } + + // Tgc specific methods + + inline bool MuonFixedId::setTgcGasGapIndex(unsigned int idx) { + if (idx > kTgcGasGapMask) { + clear(); + return false; + } + m_data &= ~(kTgcGasGapMask << kTgcGasGapShift); + m_data |= (idx & kTgcGasGapMask) << kTgcGasGapShift; + return true; + } -inline int MuonFixedId::tgcGasGap() const { - return tgcGasGapIndex() + kTgcGasGapMin; -} + inline bool MuonFixedId::setTgcGasGap(int num) { return setTgcGasGapIndex(num - kTgcGasGapMin); } -inline bool MuonFixedId::setTgcIsStripIndex( unsigned int idx ) { - if ( idx > kTgcIsStripMask ) { - clear(); - return false; - } - m_data &= ~( kTgcIsStripMask << kTgcIsStripShift ); - m_data |= (idx & kTgcIsStripMask) << kTgcIsStripShift; - return true; -} + inline int MuonFixedId::tgcGasGapIndex() const { return (m_data >> kTgcGasGapShift) & kTgcGasGapMask; } -inline bool MuonFixedId::setTgcIsStrip( int num ) { - return setTgcIsStripIndex( num - kTgcIsStripMin ); -} + inline int MuonFixedId::tgcGasGap() const { return tgcGasGapIndex() + kTgcGasGapMin; } -inline int MuonFixedId::tgcIsStripIndex() const { - return (m_data >> kTgcIsStripShift) & kTgcIsStripMask; -} + inline bool MuonFixedId::setTgcIsStripIndex(unsigned int idx) { + if (idx > kTgcIsStripMask) { + clear(); + return false; + } + m_data &= ~(kTgcIsStripMask << kTgcIsStripShift); + m_data |= (idx & kTgcIsStripMask) << kTgcIsStripShift; + return true; + } -inline int MuonFixedId::tgcIsStrip() const { - return tgcIsStripIndex() + kTgcIsStripMin; -} + inline bool MuonFixedId::setTgcIsStrip(int num) { return setTgcIsStripIndex(num - kTgcIsStripMin); } + inline int MuonFixedId::tgcIsStripIndex() const { return (m_data >> kTgcIsStripShift) & kTgcIsStripMask; } -inline bool MuonFixedId::setTgcChannelIndex( unsigned int idx ) { - if ( idx > kTgcChannelMask ) { - clear(); - return false; - } - m_data &= ~( kTgcChannelMask << kTgcChannelShift ); - m_data |= (idx & kTgcChannelMask) << kTgcChannelShift; - return true; -} + inline int MuonFixedId::tgcIsStrip() const { return tgcIsStripIndex() + kTgcIsStripMin; } -inline bool MuonFixedId::setTgcChannel( int num ) { - return setTgcChannelIndex( num - kTgcChannelMin ); -} + inline bool MuonFixedId::setTgcChannelIndex(unsigned int idx) { + if (idx > kTgcChannelMask) { + clear(); + return false; + } + m_data &= ~(kTgcChannelMask << kTgcChannelShift); + m_data |= (idx & kTgcChannelMask) << kTgcChannelShift; + return true; + } -inline int MuonFixedId::tgcChannelIndex() const { - return (m_data >> kTgcChannelShift) & kTgcChannelMask; -} + inline bool MuonFixedId::setTgcChannel(int num) { return setTgcChannelIndex(num - kTgcChannelMin); } -inline int MuonFixedId::tgcChannel() const { - return tgcChannelIndex() + kTgcChannelMin; -} + inline int MuonFixedId::tgcChannelIndex() const { return (m_data >> kTgcChannelShift) & kTgcChannelMask; } -inline std::ostream& MuonFixedId::dump(std::ostream& os) const -{ - os << technology() << ": stnEta " << eta() << ", stnPhi " << phi() ; - if( is_mdt() ){ - os << "- MDT: " << stationNumberToFixedStationString( stationName() ) << ", mdtMultiLayer " << mdtMultilayer() << ", mdtTubeLayer " - << mdtTubeLayer() << ", mdtTube " << mdtTube() ; - } else if( is_rpc() ) { - os << " RPC: " << stationNumberToFixedStationString( stationName() ) << ", rpcDoubletR " << rpcDoubletR() << ", rpcDoubletZ " - << rpcDoubletZ() << ", rpcDoubletPhi " << rpcDoubletPhi() << ", rpcGasGap " << rpcGasGap() << ", rpcMeasuresPhi " - << rpcMeasuresPhi() << ", rpcStrip " << rpcStrip() ; - } else if( is_tgc() ) { - os << " TGC: " << stationNumberToFixedStationString( stationName() ) << ", tgcGasGap " << tgcGasGap() << ", tgcIsStrip " - << tgcIsStrip() << ", tgcChannel " << tgcChannel() ; - } else if( is_csc() ) { - os << " CSC: " << stationNumberToFixedStationString( stationName() ) << ", cscChamberLayer " << cscChamberLayer() << ", cscWireLayer " - << cscWireLayer() << ", cscMeasuresPhi " << cscMeasuresPhi() << ", cscStrip " << cscStrip() ; - } else - os << "NO MuonFixedId" ; - - return os; -} + inline int MuonFixedId::tgcChannel() const { return tgcChannelIndex() + kTgcChannelMin; } -} //MuonCalib namespace + inline std::ostream& MuonFixedId::dump(std::ostream& os) const { + os << technology() << ": stnEta " << eta() << ", stnPhi " << phi(); + if (is_mdt()) { + os << "- MDT: " << stationNumberToFixedStationString(stationName()) << ", mdtMultiLayer " << mdtMultilayer() + << ", mdtTubeLayer " << mdtTubeLayer() << ", mdtTube " << mdtTube(); + } else if (is_rpc()) { + os << " RPC: " << stationNumberToFixedStationString(stationName()) << ", rpcDoubletR " << rpcDoubletR() << ", rpcDoubletZ " + << rpcDoubletZ() << ", rpcDoubletPhi " << rpcDoubletPhi() << ", rpcGasGap " << rpcGasGap() << ", rpcMeasuresPhi " + << rpcMeasuresPhi() << ", rpcStrip " << rpcStrip(); + } else if (is_tgc()) { + os << " TGC: " << stationNumberToFixedStationString(stationName()) << ", tgcGasGap " << tgcGasGap() << ", tgcIsStrip " + << tgcIsStrip() << ", tgcChannel " << tgcChannel(); + } else if (is_csc()) { + os << " CSC: " << stationNumberToFixedStationString(stationName()) << ", cscChamberLayer " << cscChamberLayer() + << ", cscWireLayer " << cscWireLayer() << ", cscMeasuresPhi " << cscMeasuresPhi() << ", cscStrip " << cscStrip(); + } else + os << "NO MuonFixedId"; + + return os; + } + +} // namespace MuonCalib -std::ostream& operator<<( std::ostream& os, const MuonCalib::MuonFixedId& id ); +std::ostream& operator<<(std::ostream& os, const MuonCalib::MuonFixedId& id); /* ***** must solve conflicts between MuonCalib namespace and friendship @@ -1248,6 +1053,4 @@ inline std::istream& operator>>( std::istream& is, MuonCalib::MuonFixedId& id){ return is; } */ -#endif // SRC_MUONFIXEDID_H - - +#endif // SRC_MUONFIXEDID_H diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/Tools.h b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/Tools.h index 5a0d91fe831c01e66812dbec95c6c822276858f8..6b63992766e7e2014f40d06c788320f101097673 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/Tools.h +++ b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/Tools.h @@ -5,93 +5,87 @@ #ifndef TOOLS_H #define TOOLS_H -#include <iostream> +#include <fstream> #include <iomanip> -#include <string> +#include <iostream> #include <sstream> -#include <fstream> +#include <string> +#include <valarray> +#include "MuonFixedId.h" +#include "TObjArray.h" +#include "TObjString.h" #include "TROOT.h" #include "TStyle.h" -#include "TObjString.h" -#include "TObjArray.h" -#include "MuonFixedId.h" - -#include <valarray> class Tools { - public: - /** default constructor */ - Tools(){}; - static std::string getChamberName(MuonCalib::MuonFixedId* mid); - static double* getPosition(std::string filename, MuonCalib::MuonFixedId* mid); - static void setStyle(); + /** default constructor */ + Tools(){}; + static std::string getChamberName(MuonCalib::MuonFixedId* mid); + static double* getPosition(std::string filename, MuonCalib::MuonFixedId* mid); + static void setStyle(); - template <class MyType> static inline std::vector<MyType> - getOptionVector(TString); + template <class MyType> static inline std::vector<MyType> getOptionVector(TString); private: - }; - -inline std::string Tools::getChamberName(MuonCalib::MuonFixedId* mid){ - - int eta=mid->eta(); - int phi=mid->phi(); - int station=mid->stationName(); - string statname=mid->stationNumberToFixedStationString(station); - - stringstream chambername; - chambername<<statname<<std::abs(eta); - if (eta<0) chambername<<"C"; else chambername<<"A"; - int detphi=2*phi; - if (statname.substr(2,1)=="L") detphi--; - else if (statname.substr(2,1)!="S") detphi=phi; - chambername<<detphi; - - return chambername.str(); +inline std::string Tools::getChamberName(MuonCalib::MuonFixedId* mid) { + int eta = mid->eta(); + int phi = mid->phi(); + int station = mid->stationName(); + string statname = mid->stationNumberToFixedStationString(station); + + stringstream chambername; + chambername << statname << std::abs(eta); + if (eta < 0) + chambername << "C"; + else + chambername << "A"; + int detphi = 2 * phi; + if (statname.substr(2, 1) == "L") + detphi--; + else if (statname.substr(2, 1) != "S") + detphi = phi; + chambername << detphi; + + return chambername.str(); } -inline double* Tools::getPosition(std::string filename, MuonCalib::MuonFixedId* mid){ +inline double* Tools::getPosition(std::string filename, MuonCalib::MuonFixedId* mid) { + double* pos = new double[6]; + for (int i = 0; i < 6; i++) { pos[i] = 0.; } - double* pos =new double[6]; - for (int i=0;i<6;i++){ - pos[i]=0.; - } - ifstream file(filename.c_str()); - if(!file) { - cout<<"Can't open AlignmentConstantsFile"<<endl; - return 0; + if (!file) { + cout << "Can't open AlignmentConstantsFile" << endl; + return 0; } - - int eta=mid->eta(); - int phi=mid->phi(); - int station=mid->stationName(); - string name=mid->stationNumberToFixedStationString(station); - + + int eta = mid->eta(); + int phi = mid->phi(); + int station = mid->stationName(); + string name = mid->stationNumberToFixedStationString(station); + char in_str[255], fname[3]; - int fphi,feta,fjob; - float fpos0,fpos1,fpos2,fpos3,fpos4,fpos5; - while(file) { - file.getline(in_str,255); - if(file) { - sscanf(in_str,"%*c %s %i%i%i %f%f%f%f%f%f", - fname,&fphi,&feta,&fjob, - &fpos0,&fpos1,&fpos2,&fpos3,&fpos4,&fpos5); - - if(fphi != phi) continue; - if(feta != eta) continue; - if(fname != name) continue; - + int fphi, feta, fjob; + float fpos0, fpos1, fpos2, fpos3, fpos4, fpos5; + while (file) { + file.getline(in_str, 255); + if (file) { + sscanf(in_str, "%*c %s %i%i%i %f%f%f%f%f%f", fname, &fphi, &feta, &fjob, &fpos0, &fpos1, &fpos2, &fpos3, &fpos4, &fpos5); + + if (fphi != phi) continue; + if (feta != eta) continue; + if (fname != name) continue; + pos[0] = fpos0; pos[1] = fpos1; pos[2] = fpos2; - pos[3] = fpos3*1000; - pos[4] = fpos4*1000; - pos[5] = fpos5*1000; + pos[3] = fpos3 * 1000; + pos[4] = fpos4 * 1000; + pos[5] = fpos5 * 1000; } } file.close(); @@ -99,16 +93,14 @@ inline double* Tools::getPosition(std::string filename, MuonCalib::MuonFixedId* return pos; } - -inline void Tools::setStyle(){ - +inline void Tools::setStyle() { // The original rootlogon.c // from: http://atlas.web.cern.ch/Atlas/GROUPS/GENERAL/SCINOTES/templates/root/rootlogon.C - TStyle *atlasStyle= new TStyle("ATLAS","Atlas style"); + TStyle* atlasStyle = new TStyle("ATLAS", "Atlas style"); // use plain black on white colors - Int_t icol=0; + Int_t icol = 0; atlasStyle->SetFrameBorderMode(icol); atlasStyle->SetCanvasBorderMode(icol); atlasStyle->SetPadBorderMode(icol); @@ -116,102 +108,95 @@ inline void Tools::setStyle(){ atlasStyle->SetCanvasColor(icol); atlasStyle->SetStatColor(icol); - //atlasStyle->SetFillColor(icol); //no hitso fill color if this is set + // atlasStyle->SetFillColor(icol); //no hitso fill color if this is set atlasStyle->SetLegendBorderSize(icol); // set the paper & margin sizes - atlasStyle->SetPaperSize(20,26); - atlasStyle->SetPadTopMargin(2.); //0.05 + atlasStyle->SetPaperSize(20, 26); + atlasStyle->SetPadTopMargin(2.); // 0.05 atlasStyle->SetPadRightMargin(0.05); atlasStyle->SetPadBottomMargin(0.16); atlasStyle->SetPadLeftMargin(0.12); - - Int_t font=42; - //Double_t tsize=0.05; + Int_t font = 42; + // Double_t tsize=0.05; // increased size a bit - Double_t tsize=0.06; - - atlasStyle->SetTextFont(font); + Double_t tsize = 0.06; + atlasStyle->SetTextFont(font); atlasStyle->SetTextSize(tsize); - atlasStyle->SetLabelFont(font,"x"); - atlasStyle->SetTitleFont(font,"x"); - atlasStyle->SetLabelFont(font,"y"); - atlasStyle->SetTitleFont(font,"y"); - atlasStyle->SetLabelFont(font,"z"); - atlasStyle->SetTitleFont(font,"z"); - - atlasStyle->SetLabelSize(tsize,"x"); - atlasStyle->SetTitleSize(tsize,"x"); - atlasStyle->SetLabelSize(tsize,"y"); - atlasStyle->SetTitleSize(tsize,"y"); - atlasStyle->SetLabelSize(tsize,"z"); - atlasStyle->SetTitleSize(tsize,"z"); - - - //use bold lines and markers - atlasStyle->SetMarkerSize(1.2);//0.8,1.2 - atlasStyle->SetHistLineWidth(2); //2. - atlasStyle->SetLineStyleString(2,"[12 12]"); // postscript dashes + atlasStyle->SetLabelFont(font, "x"); + atlasStyle->SetTitleFont(font, "x"); + atlasStyle->SetLabelFont(font, "y"); + atlasStyle->SetTitleFont(font, "y"); + atlasStyle->SetLabelFont(font, "z"); + atlasStyle->SetTitleFont(font, "z"); + + atlasStyle->SetLabelSize(tsize, "x"); + atlasStyle->SetTitleSize(tsize, "x"); + atlasStyle->SetLabelSize(tsize, "y"); + atlasStyle->SetTitleSize(tsize, "y"); + atlasStyle->SetLabelSize(tsize, "z"); + atlasStyle->SetTitleSize(tsize, "z"); + + // use bold lines and markers + atlasStyle->SetMarkerSize(1.2); // 0.8,1.2 + atlasStyle->SetHistLineWidth(2); // 2. + atlasStyle->SetLineStyleString(2, "[12 12]"); // postscript dashes atlasStyle->SetFrameFillStyle(0); atlasStyle->SetHistFillStyle(0); atlasStyle->SetStatStyle(0); atlasStyle->SetTitleFillColor(0); atlasStyle->SetTitleBorderSize(1); - //atlasStyle->SetHistFillColor(0); + // atlasStyle->SetHistFillColor(0); - //get rid of X error bars and y error bar caps - //atlasStyle->SetErrorX(0.001); + // get rid of X error bars and y error bar caps + // atlasStyle->SetErrorX(0.001); - //do not display any of the standard histogram decorations - //atlasStyle->SetOptTitle(0); - //atlasStyle->SetOptStat(1111); + // do not display any of the standard histogram decorations + // atlasStyle->SetOptTitle(0); + // atlasStyle->SetOptStat(1111); atlasStyle->SetOptStat(0); - //atlasStyle->SetOptFit(1111); + // atlasStyle->SetOptFit(1111); atlasStyle->SetOptFit(0); // put tick marks on top and RHS of plots atlasStyle->SetPadTickX(1); atlasStyle->SetPadTickY(1); - - //atlasStyle->SetPalette(1); - //atlasStyle->SetPadBottomMargin(0.12); - //atlasStyle->SetOptStat(221112211); - //atlasStyle->SetOptFit(1111); + // atlasStyle->SetPalette(1); + // atlasStyle->SetPadBottomMargin(0.12); + // atlasStyle->SetOptStat(221112211); + // atlasStyle->SetOptFit(1111); // 0.20 instead of 0.2, same number of digits in axis - //atlasStyle->SetStripDecimals(false); + // atlasStyle->SetStripDecimals(false); // change default canvas size - //atlasStyle->SetCanvasDefH(500); - //atlasStyle->SetCanvasDefW(500); - //atlasStyle->SetPadLeftMargin(0.15); - //atlasStyle->SetTitleYOffset(1.2); - //atlasStyle->SetTitleXOffset(1.1); - //atlasStyle->SetNdivisions(507,"xyz"); - //atlasStyle->SetNdivisions(508,"xyz"); - //atlasStyle->SetPadLeftMargin(0.14); - - //gROOT->SetStyle("Plain"); + // atlasStyle->SetCanvasDefH(500); + // atlasStyle->SetCanvasDefW(500); + // atlasStyle->SetPadLeftMargin(0.15); + // atlasStyle->SetTitleYOffset(1.2); + // atlasStyle->SetTitleXOffset(1.1); + // atlasStyle->SetNdivisions(507,"xyz"); + // atlasStyle->SetNdivisions(508,"xyz"); + // atlasStyle->SetPadLeftMargin(0.14); + + // gROOT->SetStyle("Plain"); gROOT->SetStyle("ATLAS"); - } -template <class MyType> inline std::vector<MyType> -Tools::getOptionVector(TString optstring){ - - optstring = optstring.ReplaceAll(" ",""); +template <class MyType> inline std::vector<MyType> Tools::getOptionVector(TString optstring) { + optstring = optstring.ReplaceAll(" ", ""); TObjArray* optarray = optstring.Tokenize(","); - + std::vector<MyType> optvec; - for(int k=0; k<optarray->GetEntries(); k++){ + for (int k = 0; k < optarray->GetEntries(); k++) { stringstream optstream; optstream << ((TObjString*)optarray->At(k))->GetString().Data(); - + MyType opt; - optstream>>opt; + optstream >> opt; optvec.push_back(opt); } @@ -219,6 +204,4 @@ Tools::getOptionVector(TString optstring){ return optvec; } -#endif // TOOLS_H - - +#endif // TOOLS_H diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/chi2validation_x.cpp b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/chi2validation_x.cpp index 60e4294fe46e96f1f22a905e84b56c72b9c8cb93..01641c4babac64474b540ab9a3b127db12299b6a 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/chi2validation_x.cpp +++ b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/chi2validation_x.cpp @@ -2,800 +2,750 @@ Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ -#include "MuonFixedId.h" -#include "Tools.h" - -#include "TStyle.h" +#include <TAxis.h> +#include <TCanvas.h> #include <TChain.h> -#include <TTree.h> +#include <TDecompBK.h> #include <TEventList.h> +#include <TF1.h> +#include <TGraph.h> #include <TLorentzVector.h> #include <TMatrixDSym.h> -#include <TVectorD.h> -#include <TDecompBK.h> #include <TMatrixTSparse.h> -#include <TGraph.h> -#include <TCanvas.h> -#include <TF1.h> #include <TPaveText.h> -#include <TAxis.h> -#include "TFile.h" -#include "TH1F.h" -#include "TLine.h" -#include "TSystem.h" -#include "TMatrixD.h" +#include <TTree.h> +#include <TVectorD.h> -#include <iostream> +#include <cmath> +#include <fstream> #include <iomanip> +#include <iostream> +#include <map> +#include <set> #include <sstream> -#include <fstream> #include <string> -#include <map> -#include <cmath> #include <vector> -#include <set> +#include "MuonFixedId.h" +#include "TFile.h" +#include "TH1F.h" #include "TH2F.h" +#include "TLine.h" +#include "TMatrixD.h" +#include "TStyle.h" +#include "TSystem.h" +#include "Tools.h" using namespace MuonCalib; - + MuonFixedId* mid; -const bool BATCH=false; -const bool doL1=true; -const bool ROT=false; -const bool ROTZ=false; - -const bool DOCORRELATIONS=true; - -bool DEBUG=0; - -int m_ntrees=0; - -string dimstrL1[6]={"X","Y","Z","rotX","rotY","rotZ"}; -string dimstrL3[6]={"s","z","t","rots","rotz","rott"}; - -double innerWidthsL1[6] ={30., 30., 10., 2., 2., 10.}; -double outerWidthsL1[6] ={150.,150., 50., 10., 10., 50.}; -double parRangesL1[6] ={300.,300.,32., 25., 25., 150.}; -double errRangesL1[6] ={ 400., 400., 25., 6., 6., 30.}; - -//double innerWidthsL1norotz[6] ={ 2., 2., 7., .03, .03, 10.}; -//double outerWidthsL1norotz[6] ={ 7., 7., 7., .5, .5, 50.}; -//double innerWidthsL1norotz[6] ={ .5, .5, 7., .03, .03, 10.}; -//double outerWidthsL1norotz[6] ={ 2., 2., 7., .5, .5, 50.}; -double innerWidthsL1norotz[6] ={ 15., 15., 12., 3.5, 3.5, 10.}; -double outerWidthsL1norotz[6] ={ 30., 30., 30., 5., 5., 50.}; -//double parRangesL1norotz[6] ={60.,60., 60., 10., 10., 1.}; -//double errRangesL1norotz[6] ={45.,45., 45., 6., 6., 30.}; -double parRangesL1norotz[6] ={50.,50., 50., 10., 10., 1.}; -double errRangesL1norotz[6] ={45.,45., 45., 6., 6., 30.}; - -double innerWidthsL1nocorr[6] ={.5, .5, .8, .00001, .00001, .0001}; -double outerWidthsL1nocorr[6] ={ 5., 5., 5., .02, .02, .002}; -double parRangesL1nocorr[6] ={15.,15.,5., .0001, .0001, .01}; -double errRangesL1nocorr[6] ={ 40., 40., 2.5, .6, .6, 3.}; - -double innerWidthsL3[6] ={.75, 2., 10., 2., 2., 2.}; -double outerWidthsL3[6] ={ 8., 2., 10., 2., 2., 2.}; -double parRangesL3[6] ={15.,20.,20., 10., 20., 20.}; -double errRangesL3[6] ={ 40., 32000., 90000., 200., 320000., 200000.}; - -double parRangeErrCutsL1[6]={20.,20.,30., .06,.06,15.}; -double errRangeErrCutsL1[6]={ .15, .15, .27, .01, .01,.4}; -double parRangeErrCutsL3[6] ={20.,20.,30., .06,.06,15.}; -double errRangeErrCutsL3[6] ={ .15, .15, .27, .01, .01,.4}; - -void help(const char *argv0) { - - cerr << "Usage: " << argv0 << " [options] " << endl - << "Options:" << endl - << " -o :\tOutput path" << endl - << " -i :\tInput files" << endl - << " -r :\tRootname" << endl - << " -j :\tIteration" << endl - << " -a :\tDraw absolute lines" << endl - << " -l :\tL1 alignment" << endl - << " -d :\tDebug" << endl - << " -h :\tShow this message and quit" << endl - << endl; - exit(1); +const bool BATCH = false; +const bool doL1 = true; +const bool ROT = false; +const bool ROTZ = false; + +const bool DOCORRELATIONS = true; + +bool DEBUG = 0; + +int m_ntrees = 0; + +string dimstrL1[6] = {"X", "Y", "Z", "rotX", "rotY", "rotZ"}; +string dimstrL3[6] = {"s", "z", "t", "rots", "rotz", "rott"}; + +double innerWidthsL1[6] = {30., 30., 10., 2., 2., 10.}; +double outerWidthsL1[6] = {150., 150., 50., 10., 10., 50.}; +double parRangesL1[6] = {300., 300., 32., 25., 25., 150.}; +double errRangesL1[6] = {400., 400., 25., 6., 6., 30.}; + +// double innerWidthsL1norotz[6] ={ 2., 2., 7., .03, .03, 10.}; +// double outerWidthsL1norotz[6] ={ 7., 7., 7., .5, .5, 50.}; +// double innerWidthsL1norotz[6] ={ .5, .5, 7., .03, .03, 10.}; +// double outerWidthsL1norotz[6] ={ 2., 2., 7., .5, .5, 50.}; +double innerWidthsL1norotz[6] = {15., 15., 12., 3.5, 3.5, 10.}; +double outerWidthsL1norotz[6] = {30., 30., 30., 5., 5., 50.}; +// double parRangesL1norotz[6] ={60.,60., 60., 10., 10., 1.}; +// double errRangesL1norotz[6] ={45.,45., 45., 6., 6., 30.}; +double parRangesL1norotz[6] = {50., 50., 50., 10., 10., 1.}; +double errRangesL1norotz[6] = {45., 45., 45., 6., 6., 30.}; + +double innerWidthsL1nocorr[6] = {.5, .5, .8, .00001, .00001, .0001}; +double outerWidthsL1nocorr[6] = {5., 5., 5., .02, .02, .002}; +double parRangesL1nocorr[6] = {15., 15., 5., .0001, .0001, .01}; +double errRangesL1nocorr[6] = {40., 40., 2.5, .6, .6, 3.}; + +double innerWidthsL3[6] = {.75, 2., 10., 2., 2., 2.}; +double outerWidthsL3[6] = {8., 2., 10., 2., 2., 2.}; +double parRangesL3[6] = {15., 20., 20., 10., 20., 20.}; +double errRangesL3[6] = {40., 32000., 90000., 200., 320000., 200000.}; + +double parRangeErrCutsL1[6] = {20., 20., 30., .06, .06, 15.}; +double errRangeErrCutsL1[6] = {.15, .15, .27, .01, .01, .4}; +double parRangeErrCutsL3[6] = {20., 20., 30., .06, .06, 15.}; +double errRangeErrCutsL3[6] = {.15, .15, .27, .01, .01, .4}; + +void help(const char* argv0) { + cerr << "Usage: " << argv0 << " [options] " << endl + << "Options:" << endl + << " -o :\tOutput path" << endl + << " -i :\tInput files" << endl + << " -r :\tRootname" << endl + << " -j :\tIteration" << endl + << " -a :\tDraw absolute lines" << endl + << " -l :\tL1 alignment" << endl + << " -d :\tDebug" << endl + << " -h :\tShow this message and quit" << endl + << endl; + exit(1); } bool contains(vector<int> vec, int test) { - for(unsigned int i=0; i<vec.size(); i++) - if (vec[i] == test) return true; - return false; + for (unsigned int i = 0; i < vec.size(); i++) + if (vec[i] == test) return true; + return false; } //_____________________________________________________________________________ -int main(int argc, char** argv) -{ - - //---------------------------- - //-- Parse the command line -- - //---------------------------- - - extern char *optarg; - char c; - TString inputdir(""); - TString outputdir(""); - TString rootname(""); - int iteration = 0; - - bool L1ALIGNMENT = false; - bool ABSLINES = false; - bool ERRCUT = false; - - while((c = getopt(argc, argv, "-hdalo:i:r:j:")) !=-1){ - switch(c){ - case 'o': - outputdir = optarg; - break; - case 'i': - inputdir = optarg; - break; - case 'r': - rootname = optarg; - break; - case 'j': - iteration = atoi(optarg); - break; - case 'd': - DEBUG = true; - break; - case 'a': - ABSLINES = true; - break; - case 'l': - L1ALIGNMENT = true; - break; - default: - cerr << "Help or unknown argument!" << endl; - help(argv[0]); - break; +int main(int argc, char** argv) { + //---------------------------- + //-- Parse the command line -- + //---------------------------- + + extern char* optarg; + char c; + TString inputdir(""); + TString outputdir(""); + TString rootname(""); + int iteration = 0; + + bool L1ALIGNMENT = false; + bool ABSLINES = false; + bool ERRCUT = false; + + while ((c = getopt(argc, argv, "-hdalo:i:r:j:")) != -1) { + switch (c) { + case 'o': outputdir = optarg; break; + case 'i': inputdir = optarg; break; + case 'r': rootname = optarg; break; + case 'j': iteration = atoi(optarg); break; + case 'd': DEBUG = true; break; + case 'a': ABSLINES = true; break; + case 'l': L1ALIGNMENT = true; break; + default: + cerr << "Help or unknown argument!" << endl; + help(argv[0]); + break; + } } - } - bool DOUBLEGAUS=L1ALIGNMENT; - //bool DOUBLEGAUS=false; - bool ANALDERIV =L1ALIGNMENT; - bool DOROTZ=!L1ALIGNMENT; - - int minpar=(L1ALIGNMENT)?0:1; - int maxpar=(DOROTZ)?5:4; - //int maxpar=(DOROTZ)?5:0; - - if(rootname==""){ - cerr << "no rootname passed, exiting..." << endl; - exit(1); - } - if(inputdir==""){ - inputdir = rootname; - } - if(outputdir==""){ - outputdir = inputdir; - } - - - string* dimstr=new string[6]; - double* innerWidths =new double[6]; - double* outerWidths =new double[6]; - double* parRanges =new double[6]; - double* errRanges =new double[6]; - double* parRangeErrCuts=new double[6]; - double* errRangeErrCuts=new double[6]; - - for (int i=0;i<6;i++) { - dimstr [i]=(L1ALIGNMENT)?dimstrL1 [i]:dimstrL3 [i]; - innerWidths [i]=(L1ALIGNMENT)?innerWidthsL1 [i]:innerWidthsL3 [i]; - outerWidths [i]=(L1ALIGNMENT)?outerWidthsL1 [i]:outerWidthsL3 [i]; - parRanges [i]=(L1ALIGNMENT)?parRangesL1 [i]:parRangesL3 [i]; - errRanges [i]=(L1ALIGNMENT)?errRangesL1 [i]:errRangesL3 [i]; - parRangeErrCuts[i]=(L1ALIGNMENT)?parRangeErrCutsL1[i]:parRangeErrCutsL3[i]; - errRangeErrCuts[i]=(L1ALIGNMENT)?errRangeErrCutsL1[i]:errRangeErrCutsL3[i]; - if (L1ALIGNMENT && !DOCORRELATIONS) { - innerWidths[i]=innerWidthsL1nocorr[i]; - outerWidths[i]=outerWidthsL1nocorr[i]; - parRanges [i]=parRangesL1nocorr[i]; - errRanges [i]=errRangesL1nocorr[i]; - } - else if (L1ALIGNMENT && DOCORRELATIONS && !DOROTZ) { - innerWidths[i]=innerWidthsL1norotz[i]; - outerWidths[i]=outerWidthsL1norotz[i]; - parRanges [i]=parRangesL1norotz[i]; - errRanges [i]=errRangesL1norotz[i]; + bool DOUBLEGAUS = L1ALIGNMENT; + // bool DOUBLEGAUS=false; + bool ANALDERIV = L1ALIGNMENT; + bool DOROTZ = !L1ALIGNMENT; + + int minpar = (L1ALIGNMENT) ? 0 : 1; + int maxpar = (DOROTZ) ? 5 : 4; + // int maxpar=(DOROTZ)?5:0; + + if (rootname == "") { + cerr << "no rootname passed, exiting..." << endl; + exit(1); + } + if (inputdir == "") { inputdir = rootname; } + if (outputdir == "") { outputdir = inputdir; } + + string* dimstr = new string[6]; + double* innerWidths = new double[6]; + double* outerWidths = new double[6]; + double* parRanges = new double[6]; + double* errRanges = new double[6]; + double* parRangeErrCuts = new double[6]; + double* errRangeErrCuts = new double[6]; + + for (int i = 0; i < 6; i++) { + dimstr[i] = (L1ALIGNMENT) ? dimstrL1[i] : dimstrL3[i]; + innerWidths[i] = (L1ALIGNMENT) ? innerWidthsL1[i] : innerWidthsL3[i]; + outerWidths[i] = (L1ALIGNMENT) ? outerWidthsL1[i] : outerWidthsL3[i]; + parRanges[i] = (L1ALIGNMENT) ? parRangesL1[i] : parRangesL3[i]; + errRanges[i] = (L1ALIGNMENT) ? errRangesL1[i] : errRangesL3[i]; + parRangeErrCuts[i] = (L1ALIGNMENT) ? parRangeErrCutsL1[i] : parRangeErrCutsL3[i]; + errRangeErrCuts[i] = (L1ALIGNMENT) ? errRangeErrCutsL1[i] : errRangeErrCutsL3[i]; + if (L1ALIGNMENT && !DOCORRELATIONS) { + innerWidths[i] = innerWidthsL1nocorr[i]; + outerWidths[i] = outerWidthsL1nocorr[i]; + parRanges[i] = parRangesL1nocorr[i]; + errRanges[i] = errRangesL1nocorr[i]; + } else if (L1ALIGNMENT && DOCORRELATIONS && !DOROTZ) { + innerWidths[i] = innerWidthsL1norotz[i]; + outerWidths[i] = outerWidthsL1norotz[i]; + parRanges[i] = parRangesL1norotz[i]; + errRanges[i] = errRangesL1norotz[i]; + } } - } - gStyle->SetOptStat(110010); - gStyle->SetOptFit(1111); - gStyle->SetFrameFillStyle(0); - gStyle->SetTitleFillColor(0); - gStyle->SetTitleBorderSize(1); - gStyle->SetPadLeftMargin(0.15); - gStyle->SetPadRightMargin(0.04); - gStyle->SetPalette(1); + gStyle->SetOptStat(110010); + gStyle->SetOptFit(1111); + gStyle->SetFrameFillStyle(0); + gStyle->SetTitleFillColor(0); + gStyle->SetTitleBorderSize(1); + gStyle->SetPadLeftMargin(0.15); + gStyle->SetPadRightMargin(0.04); + gStyle->SetPalette(1); + + mid = new MuonFixedId(0); + + void* directory = gSystem->OpenDirectory(inputdir); + if (!directory) { + cerr << "input directory does not exist, exiting..." << endl; + exit(1); + } + directory = gSystem->OpenDirectory(outputdir); + if (!directory) { + cerr << "create output directory: " << outputdir << endl; + int status = gSystem->mkdir(outputdir, false); + if (status != 0) { + cerr << "could not create output directory, exiting..." << endl; + exit(1); + } + } - mid=new MuonFixedId(0); + TString iterdir = inputdir + "/iter0"; + directory = gSystem->OpenDirectory(inputdir + "/iter0"); + bool multiplejobs = directory ? true : false; + + TString basefilename; + if (multiplejobs) { + TString iterdir = inputdir + Form("/iter%i/", iteration); + directory = gSystem->OpenDirectory(iterdir); + basefilename = iterdir; + if (!directory) { + cerr << "iteration: " << iteration << "does not exists, exiting..." << endl; + exit(1); + } + } else { + basefilename = inputdir + "/"; + } + basefilename += "MuonAlign_" + rootname + Form("_iter%i", iteration); - void *directory = gSystem->OpenDirectory(inputdir); - if (!directory){ - cerr << "input directory does not exist, exiting..." << endl; - exit(1); - } - directory = gSystem->OpenDirectory(outputdir); - if (!directory){ - cerr << "create output directory: " << outputdir << endl; - int status = gSystem->mkdir(outputdir,false); - if(status!=0){ - cerr << "could not create output directory, exiting..." << endl; - exit(1); - } - } - - TString iterdir = inputdir+"/iter0"; - directory = gSystem->OpenDirectory(inputdir+"/iter0"); - bool multiplejobs = directory ? true : false; - - TString basefilename; - if(multiplejobs){ - TString iterdir = inputdir+Form("/iter%i/",iteration); - directory = gSystem->OpenDirectory(iterdir); - basefilename = iterdir; - if(!directory){ - cerr << "iteration: " << iteration << "does not exists, exiting..." << endl; - exit(1); - } - } - else{ - basefilename = inputdir+"/"; - } - - basefilename += "MuonAlign_"+rootname+Form("_iter%i",iteration); - - TString muonalign_filename = basefilename; - TString alignpar_filename = basefilename; - if(multiplejobs){ - muonalign_filename += "_index*"; - alignpar_filename += "_solve"; - } - muonalign_filename += ".root"; - alignpar_filename += ".root"; - std::cout<<"filename: "<<alignpar_filename<<std::endl; - - // - //Read in file and set branch addresses - // - - TChain* tree=new TChain("globalChi2Deriv"); - - tree->Add(muonalign_filename); - m_ntrees=tree->GetNtrees(); - - int chamberId,event;//,nDoF,nMuonHits; - double materialOnTrack,momentum,phi,eta; - double perigee_x,perigee_y,perigee_z; - int trackInfo; - - double * firstDeriv = new double[6]; - TMatrixD* secndDeriv = new TMatrixD(6,6); - - tree->SetBranchAddress("event", &event); - tree->SetBranchAddress("chamberId", &chamberId); - tree->SetBranchAddress("secndDeriv", &secndDeriv); - tree->SetBranchAddress("firstDeriv", firstDeriv); - tree->SetBranchAddress("materialOnTrack", &materialOnTrack); - tree->SetBranchAddress("momentum", &momentum); - tree->SetBranchAddress("phi", &phi); - tree->SetBranchAddress("eta", &eta); - tree->SetBranchAddress("perigee_x", &perigee_x); - tree->SetBranchAddress("perigee_y", &perigee_y); - tree->SetBranchAddress("perigee_z", &perigee_z); - tree->SetBranchAddress("trackInfo", &trackInfo); - - TChain* mualigntree=new TChain("MuonAlign"); - - mualigntree->Add(muonalign_filename); - int nTgcPhiHits,mualignRun,mualignEvt; - int nCscPhiHits,nCscEtaHits,cscAvgPhiErr,cscAvgEtaErr; - - mualigntree->SetBranchStatus("*",0); - mualigntree->SetBranchStatus("nTgcPhiHits", 1); - mualigntree->SetBranchStatus("run", 1); - mualigntree->SetBranchStatus("evt", 1); - mualigntree->SetBranchStatus("CscNumPhiHits", 1); - mualigntree->SetBranchStatus("CscNumEtaHits", 1); - mualigntree->SetBranchStatus("CscAvgPhiError",1); - mualigntree->SetBranchStatus("CscAvgEtaError",1); - - mualigntree->SetBranchAddress("nTgcPhiHits", &nTgcPhiHits); - mualigntree->SetBranchAddress("run", &mualignRun); - mualigntree->SetBranchAddress("evt", &mualignEvt); - - mualigntree->SetBranchAddress("CscNumPhiHits", &nCscPhiHits); - mualigntree->SetBranchAddress("CscNumEtaHits", &nCscEtaHits); - mualigntree->SetBranchAddress("CscAvgPhiError", &cscAvgPhiErr); - mualigntree->SetBranchAddress("CscAvgEtaError", &cscAvgEtaErr); - - // - //Initialize variables - // - - TH1F** hPar =new TH1F*[6]; - TH2F** h2ErrorVParam =new TH2F*[6]; - TH1F** hError =new TH1F*[6]; - TH1F** hPull =new TH1F*[6]; - TH1F** hFirstDeriv =new TH1F*[6]; - TH1F** hFirstDerivErr =new TH1F*[6]; - TH2F** h2FirstDerivErrVParam=new TH2F*[6]; - - TH2F** hParVMaterialOnTrack=new TH2F*[6]; - TH2F** hParVMomentum =new TH2F*[6]; - TH2F** hParVPhi =new TH2F*[6]; - TH2F** hParVEta =new TH2F*[6]; - TH2F** hPullVEta =new TH2F*[6]; - - TH2F** hErrVMaterialOnTrack=new TH2F*[6]; - TH2F** hErrVMomentum =new TH2F*[6]; - TH2F** hErrVPhi =new TH2F*[6]; - TH2F** hErrVEta =new TH2F*[6]; - - TH2F** hErrVPerigeeXDist =new TH2F*[6]; - TH2F** hErrVTrackInfo =new TH2F*[6]; - - TH2F** hErrVNTgcPhiHits =new TH2F*[6]; - TH2F** hParVNTgcPhiHits =new TH2F*[6]; - - TH2F** hErrVCscPhiHits =new TH2F*[6]; - TH2F** hErrVCscEtaHits =new TH2F*[6]; - TH2F** hErrVCscAvgPhiErr =new TH2F*[6]; - TH2F** hErrVCscAvgEtaErr =new TH2F*[6]; - - for (int i=0;i<6;i++) { - - stringstream hParName; hParName<<"hPar_"<<dimstr[i]; - stringstream h2ErrVParName; h2ErrVParName<<"h2ErrorVParam_"<<dimstr[i]; - stringstream hErrName; hErrName<<"hError_"<<dimstr[i]; - stringstream hPullName; hPullName<<"hPull_"<<dimstr[i]; - stringstream hParVMatlName; hParVMatlName<<"hParVMatl_"<<dimstr[i]; - stringstream hParVMomName; hParVMomName<<"hParVMom_"<<dimstr[i]; - stringstream hParVPhiName; hParVPhiName<<"hParVPhi_"<<dimstr[i]; - stringstream hParVEtaName; hParVPhiName<<"hParVEta_"<<dimstr[i]; - stringstream hPullVEtaName; hParVPhiName<<"hPullVEta_"<<dimstr[i]; - stringstream hErrVMatlName; hErrVMatlName<<"hErrVMatl_"<<dimstr[i]; - stringstream hErrVMomName; hErrVMomName<<"hErrVMom_"<<dimstr[i]; - stringstream hErrVPhiName; hErrVPhiName<<"hErrVPhi_"<<dimstr[i]; - stringstream hErrVEtaName; hErrVPhiName<<"hErrVEta_"<<dimstr[i]; - stringstream hErrVPerigeeXDistName; hErrVPerigeeXDistName<<"hErrVPerigeeXDist_"<<dimstr[i]; - stringstream hErrVTrackInfoName; hErrVTrackInfoName<<"hErrVTrackInfo_"<<dimstr[i]; - stringstream hErrVNTgcPhiHitsName; hErrVNTgcPhiHitsName<<"hErrVNTgcPhiHits_"<<dimstr[i]; - stringstream hParVNTgcPhiHitsName; hParVNTgcPhiHitsName<<"hParVNTgcPhiHits_"<<dimstr[i]; - stringstream hErrVCscPhiHitsName; hErrVCscPhiHitsName<<"hErrVCscPhiHits_"<<dimstr[i]; - stringstream hErrVCscEtaHitsName; hErrVCscEtaHitsName<<"hErrVCscEtaHits_"<<dimstr[i]; - stringstream hErrVCscAvgPhiErrName; hErrVCscAvgPhiErrName<<"hErrVCscAvgPhiErr_"<<dimstr[i]; - stringstream hErrVCscAvgEtaErrName; hErrVCscAvgEtaErrName<<"hErrVCscAvgEtaErr_"<<dimstr[i]; - - double parRange = (ERRCUT) ? parRangeErrCuts[i] : parRanges[i]; - double errRange = (ERRCUT) ? errRangeErrCuts[i] : errRanges[i]; - - hPar[i] =new TH1F(hParName.str().c_str(), - dimstr[i].c_str(), 60,-parRange,parRange); - h2ErrorVParam[i]=new TH2F(h2ErrVParName.str().c_str(), - "param error v. param", - 60,-parRange,parRange,30,0.,errRange); - hError[i] =new TH1F(hErrName.str().c_str(), - "parameter error (from 2nd deriv)", 50,0.,errRange); - hPull[i] =new TH1F(hPullName.str().c_str(), - "pull", 50,-5.,5.); - - hParVMaterialOnTrack[i]=new TH2F(hParVMatlName.str().c_str(), - "param v. material on track", - 60,100.,225., - 60,-parRange,parRange); - - hParVMomentum[i] =new TH2F(hParVMomName.str().c_str(), - "param v. momentum", - 60,0.,140.,60,-parRange,parRange); - - hParVPhi[i] =new TH2F(hParVPhiName.str().c_str(), - "param v. phi", - 60,-3.15,3.15,60,-parRange,parRange); - double minEta=(L1ALIGNMENT)? 1.0:1.25; - double maxEta=(L1ALIGNMENT)? 2.50:2.00; - - hParVEta[i] =new TH2F(hParVEtaName.str().c_str(), - "param v. eta", - 60,minEta,maxEta,60,-parRange,parRange); - hPullVEta[i] =new TH2F(hPullVEtaName.str().c_str(), - "pull v. eta", - 60,minEta,maxEta,60,-5.,5.); - - double minMat=(L1ALIGNMENT)?100.:0.; - double maxMat=(L1ALIGNMENT)?225.:20.; - hErrVMaterialOnTrack[i]=new TH2F(hErrVMatlName.str().c_str(), - "param error v. material on track", - 60,minMat,maxMat,60,0.,errRange); - - - hErrVMomentum[i] =new TH2F(hErrVMomName.str().c_str(), - "param error v. momentum", - 60,20.,140.,60,0.,errRange); - - double minPhi=(L1ALIGNMENT)?-3.15:1.; - double maxPhi=(L1ALIGNMENT)? 3.15:2.; - - hErrVPhi[i] =new TH2F(hErrVPhiName.str().c_str(), - "param error v. phi", - 60,minPhi,maxPhi,60,0.,errRange); - - - hErrVEta[i] =new TH2F(hErrVEtaName.str().c_str(), - "param error v. eta", - 60,minEta,maxEta,60,0.,errRange); - - hErrVPerigeeXDist[i] =new TH2F(hErrVPerigeeXDistName.str().c_str(), - "param error vs. perigee transverse distance", - 60,0.,.2,60,0.,errRange); - - hErrVTrackInfo[i] =new TH2F(hErrVTrackInfoName.str().c_str(), - "param error vs. track fitter", - 10,0.,10.,60,0.,errRange); - - hErrVNTgcPhiHits[i] =new TH2F(hErrVNTgcPhiHitsName.str().c_str(), - "param error vs. # TGC phi hits", - 10,0.,20.,60,0.,errRange); - - hParVNTgcPhiHits[i] =new TH2F(hParVNTgcPhiHitsName.str().c_str(), - "param vs. # TGC phi hits", - 10,0.,20.,60,-parRange,parRange); - - hErrVCscPhiHits[i] =new TH2F(hErrVCscPhiHitsName.str().c_str(), - "param error vs. # CSC phi hits", - 10,0.,10.,60,0.,errRange); - - hErrVCscEtaHits[i] =new TH2F(hErrVCscEtaHitsName.str().c_str(), - "param error vs. # CSC eta hits", - 10,0.,10.,60,0.,errRange); - - hErrVCscAvgPhiErr[i] =new TH2F(hErrVCscAvgPhiErrName.str().c_str(), - "param error vs. # average CSC phi error", - 50,0.,15.,60,0.,errRange); - - hErrVCscAvgEtaErr[i] =new TH2F(hErrVCscAvgEtaErrName.str().c_str(), - "param error vs. # average CSC eta error", - 50,0.,5.,60,0.,errRange); - - stringstream hFirstDerivName; hFirstDerivName<<"hFirstDeriv_"<<i; - stringstream hFirstDerivErrName; hFirstDerivErrName<<"hFirstDerivErr_"<<i; - stringstream hFirstDerivErrVParName; hFirstDerivErrVParName<<"hFirstDerivChi2VParam_"<<i; - hFirstDeriv[i] =new TH1F(hFirstDerivName.str().c_str(), - "first derivative", 50,-1.,1.); - hFirstDerivErr[i] =new TH1F(hFirstDerivErrName.str().c_str(), "first deriv error", 30,0.,1.); - h2FirstDerivErrVParam[i]=new TH2F(hFirstDerivErrVParName.str().c_str(), "first deriv error v. param ", - 30,-20.,20.,30,0.,1.); - } - - int nevtssel(0); - - - // - //Get list of moduleIDs - // - vector<int> moduleList; - for (int hentry=0;hentry<tree->GetEntries();hentry++){ - tree->GetEntry(hentry); - if ( !contains(moduleList, chamberId)) { - moduleList.push_back(chamberId); - std::cout<<"pushing back "<<chamberId<<std::endl; - } - }//end for hentry - - cout<<"Found "<<moduleList.size()<<" modules: "; - for(unsigned int tmp=0;tmp<moduleList.size();tmp++) - cout<<moduleList[tmp]<<" "; - cout<<endl; - - TEventList *evlist=new TEventList("evlist"); - for(unsigned int selMod=0;selMod<moduleList.size();selMod++){ - stringstream selcut;selcut<<"chamberId=="<<moduleList[selMod]; - int numEvent = tree->Draw(">>evlist",selcut.str().c_str()); - for (int selEvent=0;selEvent<numEvent;selEvent++){ - int ientry=evlist->GetEntry(selEvent); - tree->GetEntry(ientry); - mualigntree->GetEntry(ientry); - if (event!=mualignEvt) { - std::cout<<"bad run or event!"<<std::endl; - exit(3); - } - - int npar=maxpar-minpar+1; - double* secderivarr=new double[npar*npar]; - double* firstderivarr=new double[npar]; - for (int i=0;i<npar;i++) { - int ipar=i+minpar; - for (int j=i;j<npar;j++) { - int jpar=j+minpar; - double secderiv=(*secndDeriv)[ipar][jpar]; - //if (!ANALDERIV) { - if (ipar>2) secderiv*=.001; - if (jpar>2) secderiv*=.001; - //} - secderivarr[i*npar+j]=secderiv; - secderivarr[j*npar+i]=secderiv; - if (jpar==ipar) { - firstderivarr[i]=firstDeriv[ipar]; - //if (!ANALDERIV) - if (ipar>2) firstderivarr[i]*=.001; - } - } - } - - TMatrixDSym a(npar,secderivarr); - TVectorD b(npar,firstderivarr); - //std::cout<<"a/b: "<<std::endl; - //a.Print(); - //b.Print(); - - TDecompBK c(a); - //std::cout<<"c: "<<std::endl; - //c.Print(); - - Bool_t status; - - TMatrixDSym ainv(c.Invert(status)); - //std::cout<<"ainv: "<<std::endl; - //ainv.Print(); - - TMatrixD prod = ainv * a; - //std::cout<<"prod: "<<std::endl; - //prod.Print(); - - TVectorD r(b.GetNrows()); - if (status) { - r=c.Solve(b,status); - } - if (!status) { - std::cout<<"problem with matrix inversion"<<std::endl; - continue; - } - - //std::cout<<"r: "<<std::endl; - //r.Print(); - if (fabs(r[0])<.01) { - cout<<"a: "<<endl; - a.Print(); - cout<<"b: "<<endl; - b.Print(); - cout<<"r: "<<endl; - r.Print(); - } - double* errors=new double[6]; - for (int i=0;i<npar;i++) { - int ipar=(L1ALIGNMENT)?i:i+1; - if (DOCORRELATIONS) errors[ipar]=std::sqrt(2.*std::fabs(ainv(i,i))); - else errors[ipar]=1000.*std::sqrt(2./std::fabs((*secndDeriv)[ipar][ipar])); - //std::cout<<"errors["<<ipar<<"]="<<errors[ipar]<<std::endl; - } - if (!L1ALIGNMENT) errors[0]=0.; - - for (int ipar=minpar;ipar<=maxpar;ipar++) { - - //double param=-firstDeriv[ipar]/(*secndDeriv)[ipar][ipar]; - int iipar=(L1ALIGNMENT)?ipar:ipar-1; - double param=(DOCORRELATIONS)?-r[iipar]:firstDeriv[ipar]/(*secndDeriv)[ipar][ipar]; - double error=errors[ipar]; - - if (ERRCUT && error>5.) continue; - - //if (ipar>2) { param *=1000.; error *= 1000.; } - - if (ERRCUT && error>errRangeErrCuts[ipar]) continue; - nevtssel++; - - hPar[ipar]->Fill(param); - - hFirstDeriv[ipar]->Fill(firstDeriv[ipar]); - hPull[ipar]->Fill(param/error); - h2ErrorVParam[ipar]->Fill(param,error); - hError[ipar]->Fill(error); - - hParVMaterialOnTrack[ipar]->Fill(materialOnTrack,param); - hParVMomentum[ipar]->Fill(momentum/1000.,param); - hParVPhi[ipar]->Fill(phi,param); - hParVEta[ipar]->Fill(eta,param); - hPullVEta[ipar]->Fill(eta,param/error); - - hErrVMaterialOnTrack[ipar]->Fill(materialOnTrack,error); - hErrVMomentum[ipar]->Fill(momentum/1000.,error); - hErrVPhi[ipar]->Fill(phi,error); - hErrVEta[ipar]->Fill(eta,error); - - hErrVNTgcPhiHits[ipar]->Fill(nTgcPhiHits,error); - hParVNTgcPhiHits[ipar]->Fill(nTgcPhiHits,param); - - hErrVCscPhiHits[ipar]->Fill(nCscPhiHits,error); - hErrVCscEtaHits[ipar]->Fill(nCscEtaHits,error); - hErrVCscAvgPhiErr[ipar]->Fill(cscAvgPhiErr,error); - hErrVCscAvgEtaErr[ipar]->Fill(cscAvgEtaErr,error); - - double perigeeDist=std::sqrt(perigee_x*perigee_x + perigee_y*perigee_y); - hErrVPerigeeXDist[ipar]->Fill(perigeeDist,error); - - hErrVTrackInfo[ipar]->Fill(trackInfo,error); - } - delete [] errors; + TString muonalign_filename = basefilename; + TString alignpar_filename = basefilename; + if (multiplejobs) { + muonalign_filename += "_index*"; + alignpar_filename += "_solve"; } - - // plot histograms - const int NCANVAS=21; - TCanvas** canv=new TCanvas*[NCANVAS]; - for (int i=0;i<NCANVAS;i++) { - stringstream canvname; canvname<<"canv_"<<i; - canv[i]=new TCanvas(canvname.str().c_str(),canvname.str().c_str()); - canv[i]->SetFillColor(10); - canv[i]->Divide(3,2); + muonalign_filename += ".root"; + alignpar_filename += ".root"; + std::cout << "filename: " << alignpar_filename << std::endl; + + // + // Read in file and set branch addresses + // + + TChain* tree = new TChain("globalChi2Deriv"); + + tree->Add(muonalign_filename); + m_ntrees = tree->GetNtrees(); + + int chamberId, event; //,nDoF,nMuonHits; + double materialOnTrack, momentum, phi, eta; + double perigee_x, perigee_y, perigee_z; + int trackInfo; + + double* firstDeriv = new double[6]; + TMatrixD* secndDeriv = new TMatrixD(6, 6); + + tree->SetBranchAddress("event", &event); + tree->SetBranchAddress("chamberId", &chamberId); + tree->SetBranchAddress("secndDeriv", &secndDeriv); + tree->SetBranchAddress("firstDeriv", firstDeriv); + tree->SetBranchAddress("materialOnTrack", &materialOnTrack); + tree->SetBranchAddress("momentum", &momentum); + tree->SetBranchAddress("phi", &phi); + tree->SetBranchAddress("eta", &eta); + tree->SetBranchAddress("perigee_x", &perigee_x); + tree->SetBranchAddress("perigee_y", &perigee_y); + tree->SetBranchAddress("perigee_z", &perigee_z); + tree->SetBranchAddress("trackInfo", &trackInfo); + + TChain* mualigntree = new TChain("MuonAlign"); + + mualigntree->Add(muonalign_filename); + int nTgcPhiHits, mualignRun, mualignEvt; + int nCscPhiHits, nCscEtaHits, cscAvgPhiErr, cscAvgEtaErr; + + mualigntree->SetBranchStatus("*", 0); + mualigntree->SetBranchStatus("nTgcPhiHits", 1); + mualigntree->SetBranchStatus("run", 1); + mualigntree->SetBranchStatus("evt", 1); + mualigntree->SetBranchStatus("CscNumPhiHits", 1); + mualigntree->SetBranchStatus("CscNumEtaHits", 1); + mualigntree->SetBranchStatus("CscAvgPhiError", 1); + mualigntree->SetBranchStatus("CscAvgEtaError", 1); + + mualigntree->SetBranchAddress("nTgcPhiHits", &nTgcPhiHits); + mualigntree->SetBranchAddress("run", &mualignRun); + mualigntree->SetBranchAddress("evt", &mualignEvt); + + mualigntree->SetBranchAddress("CscNumPhiHits", &nCscPhiHits); + mualigntree->SetBranchAddress("CscNumEtaHits", &nCscEtaHits); + mualigntree->SetBranchAddress("CscAvgPhiError", &cscAvgPhiErr); + mualigntree->SetBranchAddress("CscAvgEtaError", &cscAvgEtaErr); + + // + // Initialize variables + // + + TH1F** hPar = new TH1F*[6]; + TH2F** h2ErrorVParam = new TH2F*[6]; + TH1F** hError = new TH1F*[6]; + TH1F** hPull = new TH1F*[6]; + TH1F** hFirstDeriv = new TH1F*[6]; + TH1F** hFirstDerivErr = new TH1F*[6]; + TH2F** h2FirstDerivErrVParam = new TH2F*[6]; + + TH2F** hParVMaterialOnTrack = new TH2F*[6]; + TH2F** hParVMomentum = new TH2F*[6]; + TH2F** hParVPhi = new TH2F*[6]; + TH2F** hParVEta = new TH2F*[6]; + TH2F** hPullVEta = new TH2F*[6]; + + TH2F** hErrVMaterialOnTrack = new TH2F*[6]; + TH2F** hErrVMomentum = new TH2F*[6]; + TH2F** hErrVPhi = new TH2F*[6]; + TH2F** hErrVEta = new TH2F*[6]; + + TH2F** hErrVPerigeeXDist = new TH2F*[6]; + TH2F** hErrVTrackInfo = new TH2F*[6]; + + TH2F** hErrVNTgcPhiHits = new TH2F*[6]; + TH2F** hParVNTgcPhiHits = new TH2F*[6]; + + TH2F** hErrVCscPhiHits = new TH2F*[6]; + TH2F** hErrVCscEtaHits = new TH2F*[6]; + TH2F** hErrVCscAvgPhiErr = new TH2F*[6]; + TH2F** hErrVCscAvgEtaErr = new TH2F*[6]; + + for (int i = 0; i < 6; i++) { + stringstream hParName; + hParName << "hPar_" << dimstr[i]; + stringstream h2ErrVParName; + h2ErrVParName << "h2ErrorVParam_" << dimstr[i]; + stringstream hErrName; + hErrName << "hError_" << dimstr[i]; + stringstream hPullName; + hPullName << "hPull_" << dimstr[i]; + stringstream hParVMatlName; + hParVMatlName << "hParVMatl_" << dimstr[i]; + stringstream hParVMomName; + hParVMomName << "hParVMom_" << dimstr[i]; + stringstream hParVPhiName; + hParVPhiName << "hParVPhi_" << dimstr[i]; + stringstream hParVEtaName; + hParVPhiName << "hParVEta_" << dimstr[i]; + stringstream hPullVEtaName; + hParVPhiName << "hPullVEta_" << dimstr[i]; + stringstream hErrVMatlName; + hErrVMatlName << "hErrVMatl_" << dimstr[i]; + stringstream hErrVMomName; + hErrVMomName << "hErrVMom_" << dimstr[i]; + stringstream hErrVPhiName; + hErrVPhiName << "hErrVPhi_" << dimstr[i]; + stringstream hErrVEtaName; + hErrVPhiName << "hErrVEta_" << dimstr[i]; + stringstream hErrVPerigeeXDistName; + hErrVPerigeeXDistName << "hErrVPerigeeXDist_" << dimstr[i]; + stringstream hErrVTrackInfoName; + hErrVTrackInfoName << "hErrVTrackInfo_" << dimstr[i]; + stringstream hErrVNTgcPhiHitsName; + hErrVNTgcPhiHitsName << "hErrVNTgcPhiHits_" << dimstr[i]; + stringstream hParVNTgcPhiHitsName; + hParVNTgcPhiHitsName << "hParVNTgcPhiHits_" << dimstr[i]; + stringstream hErrVCscPhiHitsName; + hErrVCscPhiHitsName << "hErrVCscPhiHits_" << dimstr[i]; + stringstream hErrVCscEtaHitsName; + hErrVCscEtaHitsName << "hErrVCscEtaHits_" << dimstr[i]; + stringstream hErrVCscAvgPhiErrName; + hErrVCscAvgPhiErrName << "hErrVCscAvgPhiErr_" << dimstr[i]; + stringstream hErrVCscAvgEtaErrName; + hErrVCscAvgEtaErrName << "hErrVCscAvgEtaErr_" << dimstr[i]; + + double parRange = (ERRCUT) ? parRangeErrCuts[i] : parRanges[i]; + double errRange = (ERRCUT) ? errRangeErrCuts[i] : errRanges[i]; + + hPar[i] = new TH1F(hParName.str().c_str(), dimstr[i].c_str(), 60, -parRange, parRange); + h2ErrorVParam[i] = new TH2F(h2ErrVParName.str().c_str(), "param error v. param", 60, -parRange, parRange, 30, 0., errRange); + hError[i] = new TH1F(hErrName.str().c_str(), "parameter error (from 2nd deriv)", 50, 0., errRange); + hPull[i] = new TH1F(hPullName.str().c_str(), "pull", 50, -5., 5.); + + hParVMaterialOnTrack[i] = + new TH2F(hParVMatlName.str().c_str(), "param v. material on track", 60, 100., 225., 60, -parRange, parRange); + + hParVMomentum[i] = new TH2F(hParVMomName.str().c_str(), "param v. momentum", 60, 0., 140., 60, -parRange, parRange); + + hParVPhi[i] = new TH2F(hParVPhiName.str().c_str(), "param v. phi", 60, -3.15, 3.15, 60, -parRange, parRange); + double minEta = (L1ALIGNMENT) ? 1.0 : 1.25; + double maxEta = (L1ALIGNMENT) ? 2.50 : 2.00; + + hParVEta[i] = new TH2F(hParVEtaName.str().c_str(), "param v. eta", 60, minEta, maxEta, 60, -parRange, parRange); + hPullVEta[i] = new TH2F(hPullVEtaName.str().c_str(), "pull v. eta", 60, minEta, maxEta, 60, -5., 5.); + + double minMat = (L1ALIGNMENT) ? 100. : 0.; + double maxMat = (L1ALIGNMENT) ? 225. : 20.; + hErrVMaterialOnTrack[i] = + new TH2F(hErrVMatlName.str().c_str(), "param error v. material on track", 60, minMat, maxMat, 60, 0., errRange); + + hErrVMomentum[i] = new TH2F(hErrVMomName.str().c_str(), "param error v. momentum", 60, 20., 140., 60, 0., errRange); + + double minPhi = (L1ALIGNMENT) ? -3.15 : 1.; + double maxPhi = (L1ALIGNMENT) ? 3.15 : 2.; + + hErrVPhi[i] = new TH2F(hErrVPhiName.str().c_str(), "param error v. phi", 60, minPhi, maxPhi, 60, 0., errRange); + + hErrVEta[i] = new TH2F(hErrVEtaName.str().c_str(), "param error v. eta", 60, minEta, maxEta, 60, 0., errRange); + + hErrVPerigeeXDist[i] = + new TH2F(hErrVPerigeeXDistName.str().c_str(), "param error vs. perigee transverse distance", 60, 0., .2, 60, 0., errRange); + + hErrVTrackInfo[i] = new TH2F(hErrVTrackInfoName.str().c_str(), "param error vs. track fitter", 10, 0., 10., 60, 0., errRange); + + hErrVNTgcPhiHits[i] = new TH2F(hErrVNTgcPhiHitsName.str().c_str(), "param error vs. # TGC phi hits", 10, 0., 20., 60, 0., errRange); + + hParVNTgcPhiHits[i] = + new TH2F(hParVNTgcPhiHitsName.str().c_str(), "param vs. # TGC phi hits", 10, 0., 20., 60, -parRange, parRange); + + hErrVCscPhiHits[i] = new TH2F(hErrVCscPhiHitsName.str().c_str(), "param error vs. # CSC phi hits", 10, 0., 10., 60, 0., errRange); + + hErrVCscEtaHits[i] = new TH2F(hErrVCscEtaHitsName.str().c_str(), "param error vs. # CSC eta hits", 10, 0., 10., 60, 0., errRange); + + hErrVCscAvgPhiErr[i] = + new TH2F(hErrVCscAvgPhiErrName.str().c_str(), "param error vs. # average CSC phi error", 50, 0., 15., 60, 0., errRange); + + hErrVCscAvgEtaErr[i] = + new TH2F(hErrVCscAvgEtaErrName.str().c_str(), "param error vs. # average CSC eta error", 50, 0., 5., 60, 0., errRange); + + stringstream hFirstDerivName; + hFirstDerivName << "hFirstDeriv_" << i; + stringstream hFirstDerivErrName; + hFirstDerivErrName << "hFirstDerivErr_" << i; + stringstream hFirstDerivErrVParName; + hFirstDerivErrVParName << "hFirstDerivChi2VParam_" << i; + hFirstDeriv[i] = new TH1F(hFirstDerivName.str().c_str(), "first derivative", 50, -1., 1.); + hFirstDerivErr[i] = new TH1F(hFirstDerivErrName.str().c_str(), "first deriv error", 30, 0., 1.); + h2FirstDerivErrVParam[i] = new TH2F(hFirstDerivErrVParName.str().c_str(), "first deriv error v. param ", 30, -20., 20., 30, 0., 1.); } - - - TF1** f=new TF1*[6]; - for (int i=minpar;i<=maxpar;i++) { - - double parRange = (ERRCUT) ? parRangeErrCuts[i] : parRanges[i]; - double errRange = (ERRCUT) ? errRangeErrCuts[i] : errRanges[i]; - - string units=(i>2)?"(mrad)":"(mm)"; - - canv[0]->cd(i+1); - hPar[i]->Draw(); - hPar[i]->GetXaxis()->SetTitle(("1-track alignment parameter "+units).c_str()); - hPar[i]->GetYaxis()->SetTitle("# tracks"); - - TH1F* h=hPar[i]; - if (DOUBLEGAUS) { - - //f[i]=new TF1(dimstr[i].c_str(),"gaus(0)+gaus(3)",-parRange,parRange); - f[i]=new TF1(dimstr[i].c_str(),"[0]*exp(-0.5*((x-[1])/[2])^2)+[3]*exp(-0.5*((x-[1])/[4])^2)",-parRange,parRange); - //f[i]->SetParameters(h->GetMaximum(), h->GetMean(), - // innerWidths[i], h->GetMaximum()/3.5, h->GetMean(), - // outerWidths[i]); - f[i]->SetParameters(h->GetMaximum(), h->GetMean(), innerWidths[i], h->GetMaximum()/3.5, - outerWidths[i]); - } - else { - f[i]=new TF1(dimstr[i].c_str(),"[0]*exp(-0.5*((x-[1])/[2])^2)",-parRange,parRange); - f[i]->SetParameters(h->GetMaximum(), h->GetMean(), innerWidths[i]); - } - - h->Fit(f[i],"Q"); - - canv[1]->cd(i+1); - hError[i]->Draw(); - hError[i]->GetXaxis()->SetTitle(("error (from second derivative) "+units).c_str()); - hError[i]->GetYaxis()->SetTitle("# tracks"); - - canv[2]->cd(i+1); - h2ErrorVParam[i]->Draw("colz"); - h2ErrorVParam[i]->GetXaxis()->SetTitle(("1-track alignment parameter "+units).c_str()); - h2ErrorVParam[i]->GetYaxis()->SetTitle(("error (from 2nd derivative) "+units).c_str()); - - canv[3]->cd(i+1); - hPull[i]->Draw(); - hPull[i]->GetXaxis()->SetTitle("1-track alignment parameter/error"); - hPull[i]->GetYaxis()->SetTitle("# tracks"); - hPull[i]->Fit("gaus"); - - canv[4]->cd(i+1); - hParVMaterialOnTrack[i]->Draw("colz"); - hParVMaterialOnTrack[i]->GetXaxis()->SetTitle("material on track (in X0)"); - hParVMaterialOnTrack[i]->GetYaxis()->SetTitle(("1-track alignment parameters "+units).c_str()); - - canv[5]->cd(i+1); - hParVMomentum[i]->Draw("colz"); - hParVMomentum[i]->GetXaxis()->SetTitle("momentum (GeV)"); - hParVMomentum[i]->GetYaxis()->SetTitle(("1-track alignment parameters "+units).c_str()); - - canv[6]->cd(i+1); - hParVPhi[i]->Draw("colz"); - hParVPhi[i]->GetXaxis()->SetTitle("phi"); - hParVPhi[i]->GetYaxis()->SetTitle(("1-track alignment parameters "+units).c_str()); - - canv[7]->cd(i+1); - hParVEta[i]->Draw("colz"); - hParVEta[i]->GetXaxis()->SetTitle("eta"); - hParVEta[i]->GetYaxis()->SetTitle(("1-track alignment parameters "+units).c_str()); - - canv[8]->cd(i+1); - hErrVMaterialOnTrack[i]->Draw("colz"); - hErrVMaterialOnTrack[i]->GetXaxis()->SetTitle("material on track (in X0)"); - hErrVMaterialOnTrack[i]->GetYaxis()->SetTitle(("1-track alignment parameter errors "+units).c_str()); - - canv[9]->cd(i+1); - hErrVMomentum[i]->Draw("colz"); - hErrVMomentum[i]->GetXaxis()->SetTitle("momentum (GeV)"); - hErrVMomentum[i]->GetYaxis()->SetTitle(("1-track alignment parameter errors "+units).c_str()); - - canv[10]->cd(i+1); - hErrVPhi[i]->Draw("colz"); - hErrVPhi[i]->GetXaxis()->SetTitle("phi"); - hErrVPhi[i]->GetYaxis()->SetTitle(("1-track alignment parameter errors "+units).c_str()); - - canv[11]->cd(i+1); - hErrVEta[i]->Draw("colz"); - hErrVEta[i]->GetXaxis()->SetTitle("eta"); - hErrVEta[i]->GetYaxis()->SetTitle(("1-track alignment parameter errors "+units).c_str()); - - canv[12]->cd(i+1); - hErrVTrackInfo[i]->Draw("colz"); - hErrVTrackInfo[i]->GetXaxis()->SetTitle("track fitter"); - hErrVTrackInfo[i]->GetYaxis()->SetTitle(("1-track alignment parameter errors "+units).c_str()); - canv[13]->cd(i+1); - hErrVPerigeeXDist[i]->Draw("colz"); - hErrVPerigeeXDist[i]->GetXaxis()->SetTitle("perigee transverse distance"); - hErrVPerigeeXDist[i]->GetYaxis()->SetTitle(("1-track alignment parameter errors "+units).c_str()); - - canv[14]->cd(i+1); - hPullVEta[i]->Draw("colz"); - hPullVEta[i]->GetXaxis()->SetTitle("eta"); - hPullVEta[i]->GetYaxis()->SetTitle("1-track alignment parameter/error"); - - canv[15]->cd(i+1); - hErrVNTgcPhiHits[i]->Draw("colz"); - hErrVNTgcPhiHits[i]->GetXaxis()->SetTitle("# TGC #phi hits"); - hErrVNTgcPhiHits[i]->GetYaxis()->SetTitle(("1-track alignment errors " +units).c_str()); - - canv[16]->cd(i+1); - hParVNTgcPhiHits[i]->Draw("colz"); - hParVNTgcPhiHits[i]->GetXaxis()->SetTitle("# TGC #phi hits"); - hParVNTgcPhiHits[i]->GetYaxis()->SetTitle(("1-track alignment parameters " +units).c_str()); - canv[17]->cd(i+1); - hErrVCscPhiHits[i]->Draw("colz"); - hErrVCscPhiHits[i]->GetXaxis()->SetTitle("# CSC #phi hits"); - hErrVCscPhiHits[i]->GetYaxis()->SetTitle(("1-track alignment parameter errors " +units).c_str()); - - canv[18]->cd(i+1); - hErrVCscEtaHits[i]->Draw("colz"); - hErrVCscEtaHits[i]->GetXaxis()->SetTitle("# CSC #eta hits"); - hErrVCscEtaHits[i]->GetYaxis()->SetTitle(("1-track alignment parameter errors " +units).c_str()); - - canv[19]->cd(i+1); - hErrVCscAvgPhiErr[i]->Draw("colz"); - hErrVCscAvgPhiErr[i]->GetXaxis()->SetTitle("# CSC average #phi error"); - hErrVCscAvgPhiErr[i]->GetYaxis()->SetTitle(("1-track alignment parameter errors " +units).c_str()); - - canv[20]->cd(i+1); - hErrVCscAvgEtaErr[i]->Draw("colz"); - hErrVCscAvgEtaErr[i]->GetXaxis()->SetTitle("# CSC average #eta error"); - hErrVCscAvgEtaErr[i]->GetYaxis()->SetTitle(("1-track alignment parameter errors " +units).c_str()); + int nevtssel(0); + + // + // Get list of moduleIDs + // + vector<int> moduleList; + for (int hentry = 0; hentry < tree->GetEntries(); hentry++) { + tree->GetEntry(hentry); + if (!contains(moduleList, chamberId)) { + moduleList.push_back(chamberId); + std::cout << "pushing back " << chamberId << std::endl; + } + } // end for hentry + + cout << "Found " << moduleList.size() << " modules: "; + for (unsigned int tmp = 0; tmp < moduleList.size(); tmp++) cout << moduleList[tmp] << " "; + cout << endl; + + TEventList* evlist = new TEventList("evlist"); + for (unsigned int selMod = 0; selMod < moduleList.size(); selMod++) { + stringstream selcut; + selcut << "chamberId==" << moduleList[selMod]; + int numEvent = tree->Draw(">>evlist", selcut.str().c_str()); + for (int selEvent = 0; selEvent < numEvent; selEvent++) { + int ientry = evlist->GetEntry(selEvent); + tree->GetEntry(ientry); + mualigntree->GetEntry(ientry); + if (event != mualignEvt) { + std::cout << "bad run or event!" << std::endl; + exit(3); + } + + int npar = maxpar - minpar + 1; + double* secderivarr = new double[npar * npar]; + double* firstderivarr = new double[npar]; + for (int i = 0; i < npar; i++) { + int ipar = i + minpar; + for (int j = i; j < npar; j++) { + int jpar = j + minpar; + double secderiv = (*secndDeriv)[ipar][jpar]; + // if (!ANALDERIV) { + if (ipar > 2) secderiv *= .001; + if (jpar > 2) secderiv *= .001; + //} + secderivarr[i * npar + j] = secderiv; + secderivarr[j * npar + i] = secderiv; + if (jpar == ipar) { + firstderivarr[i] = firstDeriv[ipar]; + // if (!ANALDERIV) + if (ipar > 2) firstderivarr[i] *= .001; + } + } + } + + TMatrixDSym a(npar, secderivarr); + TVectorD b(npar, firstderivarr); + // std::cout<<"a/b: "<<std::endl; + // a.Print(); + // b.Print(); + + TDecompBK c(a); + // std::cout<<"c: "<<std::endl; + // c.Print(); + + Bool_t status; + + TMatrixDSym ainv(c.Invert(status)); + // std::cout<<"ainv: "<<std::endl; + // ainv.Print(); + + TMatrixD prod = ainv * a; + // std::cout<<"prod: "<<std::endl; + // prod.Print(); + + TVectorD r(b.GetNrows()); + if (status) { r = c.Solve(b, status); } + if (!status) { + std::cout << "problem with matrix inversion" << std::endl; + continue; + } + + // std::cout<<"r: "<<std::endl; + // r.Print(); + if (fabs(r[0]) < .01) { + cout << "a: " << endl; + a.Print(); + cout << "b: " << endl; + b.Print(); + cout << "r: " << endl; + r.Print(); + } + double* errors = new double[6]; + for (int i = 0; i < npar; i++) { + int ipar = (L1ALIGNMENT) ? i : i + 1; + if (DOCORRELATIONS) + errors[ipar] = std::sqrt(2. * std::fabs(ainv(i, i))); + else + errors[ipar] = 1000. * std::sqrt(2. / std::fabs((*secndDeriv)[ipar][ipar])); + // std::cout<<"errors["<<ipar<<"]="<<errors[ipar]<<std::endl; + } + if (!L1ALIGNMENT) errors[0] = 0.; + + for (int ipar = minpar; ipar <= maxpar; ipar++) { + // double param=-firstDeriv[ipar]/(*secndDeriv)[ipar][ipar]; + int iipar = (L1ALIGNMENT) ? ipar : ipar - 1; + double param = (DOCORRELATIONS) ? -r[iipar] : firstDeriv[ipar] / (*secndDeriv)[ipar][ipar]; + double error = errors[ipar]; + + if (ERRCUT && error > 5.) continue; + + // if (ipar>2) { param *=1000.; error *= 1000.; } + + if (ERRCUT && error > errRangeErrCuts[ipar]) continue; + nevtssel++; + + hPar[ipar]->Fill(param); + + hFirstDeriv[ipar]->Fill(firstDeriv[ipar]); + hPull[ipar]->Fill(param / error); + h2ErrorVParam[ipar]->Fill(param, error); + hError[ipar]->Fill(error); + + hParVMaterialOnTrack[ipar]->Fill(materialOnTrack, param); + hParVMomentum[ipar]->Fill(momentum / 1000., param); + hParVPhi[ipar]->Fill(phi, param); + hParVEta[ipar]->Fill(eta, param); + hPullVEta[ipar]->Fill(eta, param / error); + + hErrVMaterialOnTrack[ipar]->Fill(materialOnTrack, error); + hErrVMomentum[ipar]->Fill(momentum / 1000., error); + hErrVPhi[ipar]->Fill(phi, error); + hErrVEta[ipar]->Fill(eta, error); + + hErrVNTgcPhiHits[ipar]->Fill(nTgcPhiHits, error); + hParVNTgcPhiHits[ipar]->Fill(nTgcPhiHits, param); + + hErrVCscPhiHits[ipar]->Fill(nCscPhiHits, error); + hErrVCscEtaHits[ipar]->Fill(nCscEtaHits, error); + hErrVCscAvgPhiErr[ipar]->Fill(cscAvgPhiErr, error); + hErrVCscAvgEtaErr[ipar]->Fill(cscAvgEtaErr, error); + + double perigeeDist = std::sqrt(perigee_x * perigee_x + perigee_y * perigee_y); + hErrVPerigeeXDist[ipar]->Fill(perigeeDist, error); + + hErrVTrackInfo[ipar]->Fill(trackInfo, error); + } + delete[] errors; + } + + // plot histograms + const int NCANVAS = 21; + TCanvas** canv = new TCanvas*[NCANVAS]; + for (int i = 0; i < NCANVAS; i++) { + stringstream canvname; + canvname << "canv_" << i; + canv[i] = new TCanvas(canvname.str().c_str(), canvname.str().c_str()); + canv[i]->SetFillColor(10); + canv[i]->Divide(3, 2); + } + + TF1** f = new TF1*[6]; + for (int i = minpar; i <= maxpar; i++) { + double parRange = (ERRCUT) ? parRangeErrCuts[i] : parRanges[i]; + double errRange = (ERRCUT) ? errRangeErrCuts[i] : errRanges[i]; + + string units = (i > 2) ? "(mrad)" : "(mm)"; + + canv[0]->cd(i + 1); + hPar[i]->Draw(); + hPar[i]->GetXaxis()->SetTitle(("1-track alignment parameter " + units).c_str()); + hPar[i]->GetYaxis()->SetTitle("# tracks"); + + TH1F* h = hPar[i]; + if (DOUBLEGAUS) { + // f[i]=new TF1(dimstr[i].c_str(),"gaus(0)+gaus(3)",-parRange,parRange); + f[i] = new TF1(dimstr[i].c_str(), "[0]*exp(-0.5*((x-[1])/[2])^2)+[3]*exp(-0.5*((x-[1])/[4])^2)", -parRange, parRange); + // f[i]->SetParameters(h->GetMaximum(), h->GetMean(), + // innerWidths[i], h->GetMaximum()/3.5, h->GetMean(), + // outerWidths[i]); + f[i]->SetParameters(h->GetMaximum(), h->GetMean(), innerWidths[i], h->GetMaximum() / 3.5, outerWidths[i]); + } else { + f[i] = new TF1(dimstr[i].c_str(), "[0]*exp(-0.5*((x-[1])/[2])^2)", -parRange, parRange); + f[i]->SetParameters(h->GetMaximum(), h->GetMean(), innerWidths[i]); + } + + h->Fit(f[i], "Q"); + + canv[1]->cd(i + 1); + hError[i]->Draw(); + hError[i]->GetXaxis()->SetTitle(("error (from second derivative) " + units).c_str()); + hError[i]->GetYaxis()->SetTitle("# tracks"); + + canv[2]->cd(i + 1); + h2ErrorVParam[i]->Draw("colz"); + h2ErrorVParam[i]->GetXaxis()->SetTitle(("1-track alignment parameter " + units).c_str()); + h2ErrorVParam[i]->GetYaxis()->SetTitle(("error (from 2nd derivative) " + units).c_str()); + + canv[3]->cd(i + 1); + hPull[i]->Draw(); + hPull[i]->GetXaxis()->SetTitle("1-track alignment parameter/error"); + hPull[i]->GetYaxis()->SetTitle("# tracks"); + hPull[i]->Fit("gaus"); + + canv[4]->cd(i + 1); + hParVMaterialOnTrack[i]->Draw("colz"); + hParVMaterialOnTrack[i]->GetXaxis()->SetTitle("material on track (in X0)"); + hParVMaterialOnTrack[i]->GetYaxis()->SetTitle(("1-track alignment parameters " + units).c_str()); + + canv[5]->cd(i + 1); + hParVMomentum[i]->Draw("colz"); + hParVMomentum[i]->GetXaxis()->SetTitle("momentum (GeV)"); + hParVMomentum[i]->GetYaxis()->SetTitle(("1-track alignment parameters " + units).c_str()); + + canv[6]->cd(i + 1); + hParVPhi[i]->Draw("colz"); + hParVPhi[i]->GetXaxis()->SetTitle("phi"); + hParVPhi[i]->GetYaxis()->SetTitle(("1-track alignment parameters " + units).c_str()); + + canv[7]->cd(i + 1); + hParVEta[i]->Draw("colz"); + hParVEta[i]->GetXaxis()->SetTitle("eta"); + hParVEta[i]->GetYaxis()->SetTitle(("1-track alignment parameters " + units).c_str()); + + canv[8]->cd(i + 1); + hErrVMaterialOnTrack[i]->Draw("colz"); + hErrVMaterialOnTrack[i]->GetXaxis()->SetTitle("material on track (in X0)"); + hErrVMaterialOnTrack[i]->GetYaxis()->SetTitle(("1-track alignment parameter errors " + units).c_str()); + + canv[9]->cd(i + 1); + hErrVMomentum[i]->Draw("colz"); + hErrVMomentum[i]->GetXaxis()->SetTitle("momentum (GeV)"); + hErrVMomentum[i]->GetYaxis()->SetTitle(("1-track alignment parameter errors " + units).c_str()); + + canv[10]->cd(i + 1); + hErrVPhi[i]->Draw("colz"); + hErrVPhi[i]->GetXaxis()->SetTitle("phi"); + hErrVPhi[i]->GetYaxis()->SetTitle(("1-track alignment parameter errors " + units).c_str()); + + canv[11]->cd(i + 1); + hErrVEta[i]->Draw("colz"); + hErrVEta[i]->GetXaxis()->SetTitle("eta"); + hErrVEta[i]->GetYaxis()->SetTitle(("1-track alignment parameter errors " + units).c_str()); + + canv[12]->cd(i + 1); + hErrVTrackInfo[i]->Draw("colz"); + hErrVTrackInfo[i]->GetXaxis()->SetTitle("track fitter"); + hErrVTrackInfo[i]->GetYaxis()->SetTitle(("1-track alignment parameter errors " + units).c_str()); + canv[13]->cd(i + 1); + hErrVPerigeeXDist[i]->Draw("colz"); + hErrVPerigeeXDist[i]->GetXaxis()->SetTitle("perigee transverse distance"); + hErrVPerigeeXDist[i]->GetYaxis()->SetTitle(("1-track alignment parameter errors " + units).c_str()); + + canv[14]->cd(i + 1); + hPullVEta[i]->Draw("colz"); + hPullVEta[i]->GetXaxis()->SetTitle("eta"); + hPullVEta[i]->GetYaxis()->SetTitle("1-track alignment parameter/error"); + + canv[15]->cd(i + 1); + hErrVNTgcPhiHits[i]->Draw("colz"); + hErrVNTgcPhiHits[i]->GetXaxis()->SetTitle("# TGC #phi hits"); + hErrVNTgcPhiHits[i]->GetYaxis()->SetTitle(("1-track alignment errors " + units).c_str()); + + canv[16]->cd(i + 1); + hParVNTgcPhiHits[i]->Draw("colz"); + hParVNTgcPhiHits[i]->GetXaxis()->SetTitle("# TGC #phi hits"); + hParVNTgcPhiHits[i]->GetYaxis()->SetTitle(("1-track alignment parameters " + units).c_str()); + canv[17]->cd(i + 1); + hErrVCscPhiHits[i]->Draw("colz"); + hErrVCscPhiHits[i]->GetXaxis()->SetTitle("# CSC #phi hits"); + hErrVCscPhiHits[i]->GetYaxis()->SetTitle(("1-track alignment parameter errors " + units).c_str()); + + canv[18]->cd(i + 1); + hErrVCscEtaHits[i]->Draw("colz"); + hErrVCscEtaHits[i]->GetXaxis()->SetTitle("# CSC #eta hits"); + hErrVCscEtaHits[i]->GetYaxis()->SetTitle(("1-track alignment parameter errors " + units).c_str()); + + canv[19]->cd(i + 1); + hErrVCscAvgPhiErr[i]->Draw("colz"); + hErrVCscAvgPhiErr[i]->GetXaxis()->SetTitle("# CSC average #phi error"); + hErrVCscAvgPhiErr[i]->GetYaxis()->SetTitle(("1-track alignment parameter errors " + units).c_str()); + + canv[20]->cd(i + 1); + hErrVCscAvgEtaErr[i]->Draw("colz"); + hErrVCscAvgEtaErr[i]->GetXaxis()->SetTitle("# CSC average #eta error"); + hErrVCscAvgEtaErr[i]->GetYaxis()->SetTitle(("1-track alignment parameter errors " + units).c_str()); + } + delete[] f; + + stringstream chname; + chname << "ch" << moduleList[selMod]; + + string canvnames[NCANVAS] = {string(outputdir) + "/" + chname.str() + "_chi2val_alignParam.eps", + string(outputdir) + "/" + chname.str() + "_chi2val_alignParamErr.eps", + string(outputdir) + "/" + chname.str() + "_chi2val_alignParamVErr.eps", + string(outputdir) + "/" + chname.str() + "_chi2val_pull.eps", + string(outputdir) + "/" + chname.str() + "_chi2val_par_v_matl.eps", + string(outputdir) + "/" + chname.str() + "_chi2val_par_v_momentum.eps", + string(outputdir) + "/" + chname.str() + "_chi2val_par_v_phi.eps", + string(outputdir) + "/" + chname.str() + "_chi2val_par_v_eta.eps", + string(outputdir) + "/" + chname.str() + "_chi2val_err_v_matl.eps", + string(outputdir) + "/" + chname.str() + "_chi2val_err_v_momentum.eps", + string(outputdir) + "/" + chname.str() + "_chi2val_err_v_phi.eps", + string(outputdir) + "/" + chname.str() + "_chi2val_err_v_eta.eps", + string(outputdir) + "/" + chname.str() + "_chi2val_err_v_trackInfo.eps", + string(outputdir) + "/" + chname.str() + "_chi2val_err_v_perigeeXDist.eps", + string(outputdir) + "/" + chname.str() + "_chi2val_pull_v_eta.eps", + string(outputdir) + "/" + chname.str() + "_chi2val_err_v_nTgcPhiHits.eps", + string(outputdir) + "/" + chname.str() + "_chi2val_par_v_nTgcPhiHits.eps", + string(outputdir) + "/" + chname.str() + "_chi2val_err_v_nCscPhiHits.eps", + string(outputdir) + "/" + chname.str() + "_chi2val_err_v_nCscEtaHits.eps", + string(outputdir) + "/" + chname.str() + "_chi2val_err_v_nCscAvgPhiErr.eps", + string(outputdir) + "/" + chname.str() + "_chi2val_err_v_nCscAvgEtaErr.eps"}; + for (int i = 0; i < NCANVAS; i++) canv[i]->Print(canvnames[i].c_str()); } - delete [] f; - - stringstream chname; chname<<"ch"<<moduleList[selMod]; - - string canvnames[NCANVAS]={string(outputdir)+"/"+chname.str()+"_chi2val_alignParam.eps", - string(outputdir)+"/"+chname.str()+"_chi2val_alignParamErr.eps", - string(outputdir)+"/"+chname.str()+"_chi2val_alignParamVErr.eps", - string(outputdir)+"/"+chname.str()+"_chi2val_pull.eps", - string(outputdir)+"/"+chname.str()+"_chi2val_par_v_matl.eps", - string(outputdir)+"/"+chname.str()+"_chi2val_par_v_momentum.eps", - string(outputdir)+"/"+chname.str()+"_chi2val_par_v_phi.eps", - string(outputdir)+"/"+chname.str()+"_chi2val_par_v_eta.eps", - string(outputdir)+"/"+chname.str()+"_chi2val_err_v_matl.eps", - string(outputdir)+"/"+chname.str()+"_chi2val_err_v_momentum.eps", - string(outputdir)+"/"+chname.str()+"_chi2val_err_v_phi.eps", - string(outputdir)+"/"+chname.str()+"_chi2val_err_v_eta.eps", - string(outputdir)+"/"+chname.str()+"_chi2val_err_v_trackInfo.eps", - string(outputdir)+"/"+chname.str()+"_chi2val_err_v_perigeeXDist.eps", - string(outputdir)+"/"+chname.str()+"_chi2val_pull_v_eta.eps", - string(outputdir)+"/"+chname.str()+"_chi2val_err_v_nTgcPhiHits.eps", - string(outputdir)+"/"+chname.str()+"_chi2val_par_v_nTgcPhiHits.eps", - string(outputdir)+"/"+chname.str()+"_chi2val_err_v_nCscPhiHits.eps", - string(outputdir)+"/"+chname.str()+"_chi2val_err_v_nCscEtaHits.eps", - string(outputdir)+"/"+chname.str()+"_chi2val_err_v_nCscAvgPhiErr.eps", - string(outputdir)+"/"+chname.str()+"_chi2val_err_v_nCscAvgEtaErr.eps"}; - for (int i=0;i<NCANVAS;i++) - canv[i]->Print(canvnames[i].c_str()); - - } } - diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/combineUnbiasedResPlots_x.cpp b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/combineUnbiasedResPlots_x.cpp index e1a0699d9acce105afa1c94f2454217e67a747a3..a231d052c3d8c2720d31fe146c1d516f5cdc5553 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/combineUnbiasedResPlots_x.cpp +++ b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/combineUnbiasedResPlots_x.cpp @@ -2,85 +2,86 @@ Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ -#include "TFile.h" -#include "TH1F.h" -#include "TF1.h" +#include <dirent.h> +#include <stdlib.h> + +#include <cmath> +#include <iostream> +#include <sstream> +#include <vector> + #include "TCanvas.h" -#include "TStyle.h" +#include "TChain.h" +#include "TF1.h" +#include "TFile.h" #include "TGraphErrors.h" -#include "TText.h" +#include "TH1F.h" #include "TLegend.h" -#include "TChain.h" #include "TPaveStats.h" - -#include <vector> -#include <iostream> -#include <dirent.h> -#include <sstream> -#include <stdlib.h> -#include <cmath> +#include "TStyle.h" +#include "TText.h" // Declaration of leaf types -Int_t run; -Int_t evt; - -Int_t nPixHits; -Int_t nSCTHits; -Int_t nTRTHits; -Int_t nCSCHits; -Int_t nMDTHits; -Int_t nTGCHits; -Int_t nRPCHits; -Int_t nInnerMDTHits; -Int_t nMiddleMDTHits; -Int_t nOuterMDTHits; -Int_t nTriggerPhiHits; -Double_t* cscHitLocX=new Double_t[20]; -Double_t* cscHitLocY=new Double_t[20]; -Double_t* cscHitErrors=new Double_t[20]; -//Double_t* mdtRes =new Double_t[80]; -//Double_t* tgcRes =new Double_t[80]; -//Double_t* cscRes =new Double_t[20]; -//Double_t* rpcRes =new Double_t[80]; -//Double_t* mdtPull=new Double_t[80]; -//Double_t* tgcPull=new Double_t[80]; -//Double_t* cscPull=new Double_t[20]; -//Double_t* rpcPull=new Double_t[80]; - -Int_t author; -Int_t hIndex; -Int_t phiSector; -Int_t isEndcap; -Int_t identifier; -Int_t isCSide; -Int_t detType; -Int_t layer; -Int_t stName; -Int_t stPhi; -Int_t stEta; -Double_t momentum; -Double_t charge; -Double_t d0; -Double_t z0; -Double_t phi0; -Double_t theta0; -Double_t eta0; -Double_t calEnergyLoss; -Double_t calEnergyLossErr; -Double_t materialOnTrack; -Double_t dR; -Double_t dZlocal; -Double_t dXlocal; -Double_t dYlocal; -Double_t pullXlocal; -Double_t pullYlocal; -Double_t dXlocalAngle; -Double_t dYlocalAngle; -Double_t dXglobal; -Double_t dYglobal; -Double_t dZglobal; -Double_t detTheta; -Double_t detThetaErr; +Int_t run; +Int_t evt; + +Int_t nPixHits; +Int_t nSCTHits; +Int_t nTRTHits; +Int_t nCSCHits; +Int_t nMDTHits; +Int_t nTGCHits; +Int_t nRPCHits; +Int_t nInnerMDTHits; +Int_t nMiddleMDTHits; +Int_t nOuterMDTHits; +Int_t nTriggerPhiHits; +Double_t* cscHitLocX = new Double_t[20]; +Double_t* cscHitLocY = new Double_t[20]; +Double_t* cscHitErrors = new Double_t[20]; +// Double_t* mdtRes =new Double_t[80]; +// Double_t* tgcRes =new Double_t[80]; +// Double_t* cscRes =new Double_t[20]; +// Double_t* rpcRes =new Double_t[80]; +// Double_t* mdtPull=new Double_t[80]; +// Double_t* tgcPull=new Double_t[80]; +// Double_t* cscPull=new Double_t[20]; +// Double_t* rpcPull=new Double_t[80]; + +Int_t author; +Int_t hIndex; +Int_t phiSector; +Int_t isEndcap; +Int_t identifier; +Int_t isCSide; +Int_t detType; +Int_t layer; +Int_t stName; +Int_t stPhi; +Int_t stEta; +Double_t momentum; +Double_t charge; +Double_t d0; +Double_t z0; +Double_t phi0; +Double_t theta0; +Double_t eta0; +Double_t calEnergyLoss; +Double_t calEnergyLossErr; +Double_t materialOnTrack; +Double_t dR; +Double_t dZlocal; +Double_t dXlocal; +Double_t dYlocal; +Double_t pullXlocal; +Double_t pullYlocal; +Double_t dXlocalAngle; +Double_t dYlocalAngle; +Double_t dXglobal; +Double_t dYglobal; +Double_t dZglobal; +Double_t detTheta; +Double_t detThetaErr; // new variables to add to tree int nTrack; @@ -89,14 +90,14 @@ int nMiddleChambers; int nOuterChambers; int nOtherChambers; -int innerStEta [10]; +int innerStEta[10]; int middleStEta[10]; -int outerStEta [10]; +int outerStEta[10]; int otherStEta[20]; -int innerStPhi [10]; +int innerStPhi[10]; int middleStPhi[10]; -int outerStPhi [10]; +int outerStPhi[10]; int otherStPhi[20]; int innerIsEC[20]; @@ -104,233 +105,226 @@ int middleIsEC[20]; int outerIsEC[20]; int otherIsEC[20]; -void setBranchAddresses(TTree* tree, bool newBranches=false); - -int main() -{ - vector<string> dirs; - //dirs.push_back("/data/roberth/bfieldoff_V6_noTGC/user.roberth.160296-160303.bfieldoff.UnbiasedRes.V6_MSSAwIDTrackMatch_noTgcEtaHits.100917091852/"); - //dirs.push_back("/data/roberth/bfieldoff_V6_noTGC/user.roberth.160296-160303.bfieldoff.UnbiasedRes.V6_MSSAwIDTrackMatch_noTgcEtaHits.100917011842/"); - //dirs.push_back("."); - dirs.push_back("/data/roberth/bfieldoff_V10/user.roberth.160296-160303.bfieldoff.UnbiasedRes.V10.101002133022/"); - - TChain* tree=new TChain("unbiasedMuonResiduals"); - for (int i=0;i<(int)dirs.size();i++) { - std::string rootname=dirs[i]+"/*UnbiasedMuonResiduals.root*"; - cout<<"adding "<<rootname<<endl; - tree->Add(rootname.c_str()); - } - std::cout<<"tree has "<<tree->GetEntries()<<" entries"<<std::endl; - if (tree->GetEntries()<1) exit(3); - setBranchAddresses(tree); - - nInnerChambers=nMiddleChambers=nOuterChambers=nOtherChambers=0; - for (int ich=0;ich<10;ich++) { - innerStEta[ich]=middleStEta[ich]=outerStEta[ich]=otherStEta[ich]=0; - innerStPhi[ich]=middleStPhi[ich]=outerStPhi[ich]=otherStPhi[ich]=0; - innerIsEC[ich]=middleIsEC[ich]=outerIsEC[ich]=otherIsEC[ich]=-1; - } - int fileno=0; - TFile* file=new TFile("/tmp/roberth/UnbiasedMuonResiduals.root","RECREATE"); - TTree* newTree=tree->CloneTree(0); - setBranchAddresses(newTree,true); - - tree->GetEntry(0); - double lastmomentum = momentum; - double lastd0 = d0; - double lastphi0 = phi0; - int lastHIndex = hIndex; - - nTrack=0; - int nFirstTrackEntry=0; - int nEntriesForTrack=0; - - int kentry(0); - for (int ientry=0;ientry<(int)tree->GetEntries();ientry++,kentry++) { - //for (int ientry=0;ientry<50000;ientry++) { - if (ientry%100000==0) - //if (ientry%100) - std::cout<<"entry "<<ientry<<std::endl; - tree->GetEntry(ientry); - //cout<<"hIndex: "<<hIndex<<"/"<<lastHIndex<<endl; - //cout<<"momentum/d0/phi0: "<<momentum<<"/"<<d0<<"/"<<phi0<<endl; - - if (hIndex!=lastHIndex || - std::fabs(momentum-lastmomentum)>.01 || - std::fabs(d0 -lastd0) >.01 || - std::fabs(phi0 -lastphi0) >.01) { - - // get list of chambers for this track - //std::list<int> chamberIds; - for (int jentry=0;jentry<nEntriesForTrack;jentry++) { - //cout<<"jentry: "<<jentry<<endl; - tree->GetEntry(nFirstTrackEntry+jentry); - newTree->Fill(); - } - if (kentry>=3500000) { - cout<<"creating new file"<<endl; - kentry=0; - newTree->Write(); - file->Close(); - - //delete newTree; - fileno++; - //delete file; - stringstream filename; filename<<"/tmp/roberth/UnbiasedMuonResiduals_"<<fileno<<".root"; - file=new TFile(filename.str().c_str(),"RECREATE"); - newTree=tree->CloneTree(0); - setBranchAddresses(newTree,true); - } - - tree->GetEntry(ientry); - nTrack++; - nInnerChambers=nMiddleChambers=nOuterChambers=nOtherChambers=0; - for (int ich=0;ich<10;ich++) { - innerStEta[ich]=middleStEta[ich]=outerStEta[ich]=otherStEta[ich]=0; - innerStPhi[ich]=middleStPhi[ich]=outerStPhi[ich]=otherStPhi[ich]=0; - innerIsEC[ich]=middleIsEC[ich]=outerIsEC[ich]=otherIsEC[ich]=-1; - } - - lastmomentum=momentum; - lastd0 =d0; - lastphi0 =phi0; - lastHIndex =hIndex; - nFirstTrackEntry=ientry; - nEntriesForTrack=0; - } - - nEntriesForTrack++; - - //cout<<"layer: "<<layer<<", stEta: "<<stEta<<endl; - - if (layer==0) { - int ieta=stEta; - if (detType==1) ieta=0; - innerStEta[nInnerChambers]=ieta; - innerStPhi[nInnerChambers]=stPhi; - innerIsEC[nInnerChambers]=isEndcap; - //cout<<"innerStEta["<<nInnerChambers<<"]="<<innerStEta[nInnerChambers]<<endl; - nInnerChambers++; - if (nInnerChambers>=10) cout<<"too many inner chambers!"<<endl; - } - else if (layer==1) { - middleStEta[nMiddleChambers]=stEta; - middleStPhi[nMiddleChambers]=stPhi; - middleIsEC[nMiddleChambers]=isEndcap; - //cout<<"middleStEta["<<nMiddleChambers<<"]="<<middleStEta[nMiddleChambers]<<endl; - nMiddleChambers++; - if (nMiddleChambers>=10) cout<<"too many middle chambers!"<<endl; +void setBranchAddresses(TTree* tree, bool newBranches = false); + +int main() { + vector<string> dirs; + // dirs.push_back("/data/roberth/bfieldoff_V6_noTGC/user.roberth.160296-160303.bfieldoff.UnbiasedRes.V6_MSSAwIDTrackMatch_noTgcEtaHits.100917091852/"); + // dirs.push_back("/data/roberth/bfieldoff_V6_noTGC/user.roberth.160296-160303.bfieldoff.UnbiasedRes.V6_MSSAwIDTrackMatch_noTgcEtaHits.100917011842/"); + // dirs.push_back("."); + dirs.push_back("/data/roberth/bfieldoff_V10/user.roberth.160296-160303.bfieldoff.UnbiasedRes.V10.101002133022/"); + + TChain* tree = new TChain("unbiasedMuonResiduals"); + for (int i = 0; i < (int)dirs.size(); i++) { + std::string rootname = dirs[i] + "/*UnbiasedMuonResiduals.root*"; + cout << "adding " << rootname << endl; + tree->Add(rootname.c_str()); } - else if (layer==2) { - outerStEta[nOuterChambers]=stEta; - outerStPhi[nOuterChambers]=stPhi; - outerIsEC[nOuterChambers]=isEndcap; - //cout<<"outerStEta["<<nOuterChambers<<"]="<<outerStEta[nOuterChambers]<<endl; - nOuterChambers++; - if (nOuterChambers>=10) cout<<"too many outer chambers!"<<endl; + std::cout << "tree has " << tree->GetEntries() << " entries" << std::endl; + if (tree->GetEntries() < 1) exit(3); + setBranchAddresses(tree); + + nInnerChambers = nMiddleChambers = nOuterChambers = nOtherChambers = 0; + for (int ich = 0; ich < 10; ich++) { + innerStEta[ich] = middleStEta[ich] = outerStEta[ich] = otherStEta[ich] = 0; + innerStPhi[ich] = middleStPhi[ich] = outerStPhi[ich] = otherStPhi[ich] = 0; + innerIsEC[ich] = middleIsEC[ich] = outerIsEC[ich] = otherIsEC[ich] = -1; } - else if (layer==3) { - otherStEta[nOtherChambers]=stEta; - otherStPhi[nOtherChambers]=stPhi; - otherIsEC[nOtherChambers]=isEndcap; - nOtherChambers++; - if (nOtherChambers>=10) cout<<"too many other chambers!"<<endl; + int fileno = 0; + TFile* file = new TFile("/tmp/roberth/UnbiasedMuonResiduals.root", "RECREATE"); + TTree* newTree = tree->CloneTree(0); + setBranchAddresses(newTree, true); + + tree->GetEntry(0); + double lastmomentum = momentum; + double lastd0 = d0; + double lastphi0 = phi0; + int lastHIndex = hIndex; + + nTrack = 0; + int nFirstTrackEntry = 0; + int nEntriesForTrack = 0; + + int kentry(0); + for (int ientry = 0; ientry < (int)tree->GetEntries(); ientry++, kentry++) { + // for (int ientry=0;ientry<50000;ientry++) { + if (ientry % 100000 == 0) + // if (ientry%100) + std::cout << "entry " << ientry << std::endl; + tree->GetEntry(ientry); + // cout<<"hIndex: "<<hIndex<<"/"<<lastHIndex<<endl; + // cout<<"momentum/d0/phi0: "<<momentum<<"/"<<d0<<"/"<<phi0<<endl; + + if (hIndex != lastHIndex || std::fabs(momentum - lastmomentum) > .01 || std::fabs(d0 - lastd0) > .01 || + std::fabs(phi0 - lastphi0) > .01) { + // get list of chambers for this track + // std::list<int> chamberIds; + for (int jentry = 0; jentry < nEntriesForTrack; jentry++) { + // cout<<"jentry: "<<jentry<<endl; + tree->GetEntry(nFirstTrackEntry + jentry); + newTree->Fill(); + } + if (kentry >= 3500000) { + cout << "creating new file" << endl; + kentry = 0; + newTree->Write(); + file->Close(); + + // delete newTree; + fileno++; + // delete file; + stringstream filename; + filename << "/tmp/roberth/UnbiasedMuonResiduals_" << fileno << ".root"; + file = new TFile(filename.str().c_str(), "RECREATE"); + newTree = tree->CloneTree(0); + setBranchAddresses(newTree, true); + } + + tree->GetEntry(ientry); + nTrack++; + nInnerChambers = nMiddleChambers = nOuterChambers = nOtherChambers = 0; + for (int ich = 0; ich < 10; ich++) { + innerStEta[ich] = middleStEta[ich] = outerStEta[ich] = otherStEta[ich] = 0; + innerStPhi[ich] = middleStPhi[ich] = outerStPhi[ich] = otherStPhi[ich] = 0; + innerIsEC[ich] = middleIsEC[ich] = outerIsEC[ich] = otherIsEC[ich] = -1; + } + + lastmomentum = momentum; + lastd0 = d0; + lastphi0 = phi0; + lastHIndex = hIndex; + nFirstTrackEntry = ientry; + nEntriesForTrack = 0; + } + + nEntriesForTrack++; + + // cout<<"layer: "<<layer<<", stEta: "<<stEta<<endl; + + if (layer == 0) { + int ieta = stEta; + if (detType == 1) ieta = 0; + innerStEta[nInnerChambers] = ieta; + innerStPhi[nInnerChambers] = stPhi; + innerIsEC[nInnerChambers] = isEndcap; + // cout<<"innerStEta["<<nInnerChambers<<"]="<<innerStEta[nInnerChambers]<<endl; + nInnerChambers++; + if (nInnerChambers >= 10) cout << "too many inner chambers!" << endl; + } else if (layer == 1) { + middleStEta[nMiddleChambers] = stEta; + middleStPhi[nMiddleChambers] = stPhi; + middleIsEC[nMiddleChambers] = isEndcap; + // cout<<"middleStEta["<<nMiddleChambers<<"]="<<middleStEta[nMiddleChambers]<<endl; + nMiddleChambers++; + if (nMiddleChambers >= 10) cout << "too many middle chambers!" << endl; + } else if (layer == 2) { + outerStEta[nOuterChambers] = stEta; + outerStPhi[nOuterChambers] = stPhi; + outerIsEC[nOuterChambers] = isEndcap; + // cout<<"outerStEta["<<nOuterChambers<<"]="<<outerStEta[nOuterChambers]<<endl; + nOuterChambers++; + if (nOuterChambers >= 10) cout << "too many outer chambers!" << endl; + } else if (layer == 3) { + otherStEta[nOtherChambers] = stEta; + otherStPhi[nOtherChambers] = stPhi; + otherIsEC[nOtherChambers] = isEndcap; + nOtherChambers++; + if (nOtherChambers >= 10) cout << "too many other chambers!" << endl; + } } - } - cout<<"writing tree"<<endl; + cout << "writing tree" << endl; - newTree->Write(); - file->Close(); + newTree->Write(); + file->Close(); } //________________________________________________________________________ -void setBranchAddresses(TTree* tree, bool newBranches) -{ - tree->SetBranchAddress("run", &run); - tree->SetBranchAddress("evt", &evt); - tree->SetBranchAddress("nPixHits", &nPixHits); - tree->SetBranchAddress("nSCTHits", &nSCTHits); - tree->SetBranchAddress("nTRTHits", &nTRTHits); - tree->SetBranchAddress("nCSCHits", &nCSCHits); - tree->SetBranchAddress("nMDTHits", &nMDTHits); - tree->SetBranchAddress("nTGCHits", &nTGCHits); - tree->SetBranchAddress("nRPCHits", &nRPCHits); - - tree->SetBranchAddress("nInnerMDTHits", &nInnerMDTHits); - tree->SetBranchAddress("nMiddleMDTHits", &nMiddleMDTHits); - tree->SetBranchAddress("nOuterMDTHits", &nOuterMDTHits); - tree->SetBranchAddress("nTriggerPhiHits", &nTriggerPhiHits); - tree->SetBranchAddress("cscHitLocX", cscHitLocX); - tree->SetBranchAddress("cscHitLocY", cscHitLocY); - tree->SetBranchAddress("cscHitErrors", cscHitErrors); - - /* - tree->SetBranchAddress("mdtRes", mdtRes); - tree->SetBranchAddress("tgcRes", tgcRes); - tree->SetBranchAddress("cscRes", cscRes); - tree->SetBranchAddress("rpcRes", rpcRes); - - tree->SetBranchAddress("mdtPull", mdtPull); - tree->SetBranchAddress("tgcPull", tgcPull); - tree->SetBranchAddress("cscPull", cscPull); - tree->SetBranchAddress("rpcPull", rpcPull); - */ - - tree->SetBranchAddress("author", &author); - tree->SetBranchAddress("hIndex", &hIndex); - tree->SetBranchAddress("phiSector", &phiSector); - tree->SetBranchAddress("isEndcap", &isEndcap); - tree->SetBranchAddress("identifier", &identifier); - tree->SetBranchAddress("isCSide", &isCSide); - tree->SetBranchAddress("detType", &detType); - tree->SetBranchAddress("layer", &layer); - tree->SetBranchAddress("stName", &stName); - tree->SetBranchAddress("stPhi", &stPhi); - tree->SetBranchAddress("stEta", &stEta); - tree->SetBranchAddress("momentum", &momentum); - tree->SetBranchAddress("charge", &charge); - tree->SetBranchAddress("d0", &d0); - tree->SetBranchAddress("z0", &z0); - tree->SetBranchAddress("phi0", &phi0); - tree->SetBranchAddress("theta0", &theta0); - tree->SetBranchAddress("eta0", &eta0); - tree->SetBranchAddress("calEnergyLoss", &calEnergyLoss); - tree->SetBranchAddress("calEnergyLossErr", &calEnergyLossErr); - tree->SetBranchAddress("materialOnTrack", &materialOnTrack); - tree->SetBranchAddress("dR", &dR); - tree->SetBranchAddress("dZlocal", &dZlocal); - tree->SetBranchAddress("dXlocal", &dXlocal); - tree->SetBranchAddress("dYlocal", &dYlocal); - tree->SetBranchAddress("pullXlocal", &pullXlocal); - tree->SetBranchAddress("pullYlocal", &pullYlocal); - tree->SetBranchAddress("dXlocalAngle", &dXlocalAngle); - tree->SetBranchAddress("dYlocalAngle", &dYlocalAngle); - tree->SetBranchAddress("dXglobal", &dXglobal); - tree->SetBranchAddress("dYglobal", &dYglobal); - tree->SetBranchAddress("dZglobal", &dZglobal); - tree->SetBranchAddress("detTheta", &detTheta); - tree->SetBranchAddress("detThetaErr", &detThetaErr); - - // new branches - if (newBranches) { - tree->Branch("nTrack", &nTrack, "nTrack/I"); - tree->Branch("nInnerChambers", &nInnerChambers, "nInnerChambers/I"); - tree->Branch("nMiddleChambers", &nMiddleChambers, "nMiddleChambers/I"); - tree->Branch("nOuterChambers", &nOuterChambers, "nOuterChambers/I"); - tree->Branch("nOtherChambers", &nOtherChambers, "nOtherChambers/I"); - tree->Branch("innerStEta", innerStEta, "innerStEta[nInnerChambers]/I"); - tree->Branch("middleStEta", middleStEta, "middleStEta[nMiddleChambers]/I"); - tree->Branch("outerStEta", outerStEta, "outerStEta[nOuterChambers]/I"); - tree->Branch("otherStEta", otherStEta, "otherStEta[nOuterChambers]/I"); - tree->Branch("innerStPhi", innerStPhi, "innerStPhi[nInnerChambers]/I"); - tree->Branch("middleStPhi", middleStPhi, "middleStPhi[nMiddleChambers]/I"); - tree->Branch("outerStPhi", outerStPhi, "outerStPhi[nOuterChambers]/I"); - tree->Branch("otherStPhi", otherStPhi, "otherStPhi[nOuterChambers]/I"); - tree->Branch("innerIsEC", innerIsEC, "innerIsEC[nInnerChambers]/I"); - tree->Branch("middleIsEC", middleIsEC, "middleIsEC[nMiddleChambers]/I"); - tree->Branch("outerIsEC", outerIsEC, "outerIsEC[nOuterChambers]/I"); - tree->Branch("otherIsEC", otherIsEC, "otherIsEC[nOuterChambers]/I"); - } - - return; +void setBranchAddresses(TTree* tree, bool newBranches) { + tree->SetBranchAddress("run", &run); + tree->SetBranchAddress("evt", &evt); + tree->SetBranchAddress("nPixHits", &nPixHits); + tree->SetBranchAddress("nSCTHits", &nSCTHits); + tree->SetBranchAddress("nTRTHits", &nTRTHits); + tree->SetBranchAddress("nCSCHits", &nCSCHits); + tree->SetBranchAddress("nMDTHits", &nMDTHits); + tree->SetBranchAddress("nTGCHits", &nTGCHits); + tree->SetBranchAddress("nRPCHits", &nRPCHits); + + tree->SetBranchAddress("nInnerMDTHits", &nInnerMDTHits); + tree->SetBranchAddress("nMiddleMDTHits", &nMiddleMDTHits); + tree->SetBranchAddress("nOuterMDTHits", &nOuterMDTHits); + tree->SetBranchAddress("nTriggerPhiHits", &nTriggerPhiHits); + tree->SetBranchAddress("cscHitLocX", cscHitLocX); + tree->SetBranchAddress("cscHitLocY", cscHitLocY); + tree->SetBranchAddress("cscHitErrors", cscHitErrors); + + /* + tree->SetBranchAddress("mdtRes", mdtRes); + tree->SetBranchAddress("tgcRes", tgcRes); + tree->SetBranchAddress("cscRes", cscRes); + tree->SetBranchAddress("rpcRes", rpcRes); + + tree->SetBranchAddress("mdtPull", mdtPull); + tree->SetBranchAddress("tgcPull", tgcPull); + tree->SetBranchAddress("cscPull", cscPull); + tree->SetBranchAddress("rpcPull", rpcPull); + */ + + tree->SetBranchAddress("author", &author); + tree->SetBranchAddress("hIndex", &hIndex); + tree->SetBranchAddress("phiSector", &phiSector); + tree->SetBranchAddress("isEndcap", &isEndcap); + tree->SetBranchAddress("identifier", &identifier); + tree->SetBranchAddress("isCSide", &isCSide); + tree->SetBranchAddress("detType", &detType); + tree->SetBranchAddress("layer", &layer); + tree->SetBranchAddress("stName", &stName); + tree->SetBranchAddress("stPhi", &stPhi); + tree->SetBranchAddress("stEta", &stEta); + tree->SetBranchAddress("momentum", &momentum); + tree->SetBranchAddress("charge", &charge); + tree->SetBranchAddress("d0", &d0); + tree->SetBranchAddress("z0", &z0); + tree->SetBranchAddress("phi0", &phi0); + tree->SetBranchAddress("theta0", &theta0); + tree->SetBranchAddress("eta0", &eta0); + tree->SetBranchAddress("calEnergyLoss", &calEnergyLoss); + tree->SetBranchAddress("calEnergyLossErr", &calEnergyLossErr); + tree->SetBranchAddress("materialOnTrack", &materialOnTrack); + tree->SetBranchAddress("dR", &dR); + tree->SetBranchAddress("dZlocal", &dZlocal); + tree->SetBranchAddress("dXlocal", &dXlocal); + tree->SetBranchAddress("dYlocal", &dYlocal); + tree->SetBranchAddress("pullXlocal", &pullXlocal); + tree->SetBranchAddress("pullYlocal", &pullYlocal); + tree->SetBranchAddress("dXlocalAngle", &dXlocalAngle); + tree->SetBranchAddress("dYlocalAngle", &dYlocalAngle); + tree->SetBranchAddress("dXglobal", &dXglobal); + tree->SetBranchAddress("dYglobal", &dYglobal); + tree->SetBranchAddress("dZglobal", &dZglobal); + tree->SetBranchAddress("detTheta", &detTheta); + tree->SetBranchAddress("detThetaErr", &detThetaErr); + + // new branches + if (newBranches) { + tree->Branch("nTrack", &nTrack, "nTrack/I"); + tree->Branch("nInnerChambers", &nInnerChambers, "nInnerChambers/I"); + tree->Branch("nMiddleChambers", &nMiddleChambers, "nMiddleChambers/I"); + tree->Branch("nOuterChambers", &nOuterChambers, "nOuterChambers/I"); + tree->Branch("nOtherChambers", &nOtherChambers, "nOtherChambers/I"); + tree->Branch("innerStEta", innerStEta, "innerStEta[nInnerChambers]/I"); + tree->Branch("middleStEta", middleStEta, "middleStEta[nMiddleChambers]/I"); + tree->Branch("outerStEta", outerStEta, "outerStEta[nOuterChambers]/I"); + tree->Branch("otherStEta", otherStEta, "otherStEta[nOuterChambers]/I"); + tree->Branch("innerStPhi", innerStPhi, "innerStPhi[nInnerChambers]/I"); + tree->Branch("middleStPhi", middleStPhi, "middleStPhi[nMiddleChambers]/I"); + tree->Branch("outerStPhi", outerStPhi, "outerStPhi[nOuterChambers]/I"); + tree->Branch("otherStPhi", otherStPhi, "otherStPhi[nOuterChambers]/I"); + tree->Branch("innerIsEC", innerIsEC, "innerIsEC[nInnerChambers]/I"); + tree->Branch("middleIsEC", middleIsEC, "middleIsEC[nMiddleChambers]/I"); + tree->Branch("outerIsEC", outerIsEC, "outerIsEC[nOuterChambers]/I"); + tree->Branch("otherIsEC", otherIsEC, "otherIsEC[nOuterChambers]/I"); + } + + return; } diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/globalchi2_v_alignparam.cpp b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/globalchi2_v_alignparam.cpp index 9f513b0597fcdc77324246ffacda0228a7e2bd76..2f1870b9fd9ca4aa68a6db4d88aef6876c42a4fc 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/globalchi2_v_alignparam.cpp +++ b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/globalchi2_v_alignparam.cpp @@ -2,972 +2,913 @@ Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ -#include "MuonFixedId.h" -#include "Tools.h" - -#include "TStyle.h" +#include <TAxis.h> +#include <TCanvas.h> #include <TChain.h> -#include <TTree.h> +#include <TDecompBK.h> #include <TEventList.h> +#include <TF1.h> +#include <TGraph.h> #include <TLorentzVector.h> #include <TMatrixDSym.h> -#include <TVectorD.h> -#include <TDecompBK.h> #include <TMatrixTSparse.h> -#include <TGraph.h> -#include <TCanvas.h> -#include <TF1.h> #include <TPaveText.h> -#include <TAxis.h> -#include "TFile.h" -#include "TH1F.h" -#include "TH2F.h" -#include "TStyle.h" -#include "TLine.h" -#include "TSystem.h" +#include <TTree.h> +#include <TVectorD.h> -#include <iostream> +#include <cmath> +#include <fstream> #include <iomanip> +#include <iostream> +#include <map> +#include <set> #include <sstream> -#include <fstream> #include <string> -#include <map> -#include <cmath> #include <vector> -#include <set> + +#include "MuonFixedId.h" +#include "TFile.h" +#include "TH1F.h" +#include "TH2F.h" +#include "TLine.h" +#include "TStyle.h" +#include "TSystem.h" +#include "Tools.h" using namespace MuonCalib; void Init(TTree* tree); -void getDataFromTree(TChain* chain, - std::map<long long int,double**>& fullArrayMap, - std::map<long long int,double**>& xarrayMap, - std::map<long long int,long long int>& numTracks, - std::map<long long int,string>& chamberNames, - std::map<long long int,bool*>& goodParams); - -void getDataFromAlignParTree(TChain* chain, - std::map<long long int,double*>& firstderivMap, - std::map<long long int,double*>& secndderivMap, - std::map<long long int,double*>& initPosMap, - std::map<long long int,double*>& alignParMap, - std::map<long long int,double*>& alignParErrMap); - - -bool DEBUG=1; -const int NSHIFTS=11; -const int NPARAMS=6; -string xtitles[NPARAMS]={"#Deltas","#Deltaz","#Deltat", - "#Delta#alpha(s)","#Delta#beta(z)", "#Delta#gamma(t)"}; -string units[NPARAMS]={" [mm]"," [mm]"," [mm]"," [mrad]"," [mrad]"," [mrad]"}; +void getDataFromTree(TChain* chain, std::map<long long int, double**>& fullArrayMap, std::map<long long int, double**>& xarrayMap, + std::map<long long int, long long int>& numTracks, std::map<long long int, string>& chamberNames, + std::map<long long int, bool*>& goodParams); + +void getDataFromAlignParTree(TChain* chain, std::map<long long int, double*>& firstderivMap, + std::map<long long int, double*>& secndderivMap, std::map<long long int, double*>& initPosMap, + std::map<long long int, double*>& alignParMap, std::map<long long int, double*>& alignParErrMap); + +bool DEBUG = 1; +const int NSHIFTS = 11; +const int NPARAMS = 6; +string xtitles[NPARAMS] = {"#Deltas", "#Deltaz", "#Deltat", "#Delta#alpha(s)", "#Delta#beta(z)", "#Delta#gamma(t)"}; +string units[NPARAMS] = {" [mm]", " [mm]", " [mm]", " [mrad]", " [mrad]", " [mrad]"}; MuonFixedId* mid; -double* secderiv =new double[NPARAMS]; -double* firstderiv =new double[NPARAMS]; -double* initPos =new double[NPARAMS]; -double* alignPar =new double[NPARAMS]; -double* alignParErr=new double[NPARAMS]; -double scale[NPARAMS]={1.,1.,1.,1000.,1000.,1000.}; -double nominalPos[NPARAMS]={0.,0.,0.,0.,0.,0.}; +double* secderiv = new double[NPARAMS]; +double* firstderiv = new double[NPARAMS]; +double* initPos = new double[NPARAMS]; +double* alignPar = new double[NPARAMS]; +double* alignParErr = new double[NPARAMS]; +double scale[NPARAMS] = {1., 1., 1., 1000., 1000., 1000.}; +double nominalPos[NPARAMS] = {0., 0., 0., 0., 0., 0.}; -bool goodpar[NPARAMS]={0,0,0,0,0,0}; +bool goodpar[NPARAMS] = {0, 0, 0, 0, 0, 0}; -int m_ntrees=0; +int m_ntrees = 0; TString outputdir(""); TString rootname(""); int iteration = 0; -int kindex=-1; -string chname=""; - -void help(const char *argv0) { - - cerr << "Usage: " << argv0 << " [options] " << endl - << "Options:" << endl - << " -o :\tOutput path" << endl - << " -i :\tInput files" << endl - << " -r :\tRootname" << endl - << " -j :\tIteration" << endl - << " -a :\tDraw absolute lines" << endl - << " -l :\tL1 alignment" << endl - << " -d :\tDebug" << endl - << " -h :\tShow this message and quit" << endl - << endl; - exit(1); +int kindex = -1; +string chname = ""; + +void help(const char* argv0) { + cerr << "Usage: " << argv0 << " [options] " << endl + << "Options:" << endl + << " -o :\tOutput path" << endl + << " -i :\tInput files" << endl + << " -r :\tRootname" << endl + << " -j :\tIteration" << endl + << " -a :\tDraw absolute lines" << endl + << " -l :\tL1 alignment" << endl + << " -d :\tDebug" << endl + << " -h :\tShow this message and quit" << endl + << endl; + exit(1); } //_____________________________________________________________________________ -int main(int argc, char** argv) -{ - - //---------------------------- - //-- Parse the command line -- - //---------------------------- - - extern char *optarg; - char c; - TString inputdir(""); - - bool L1ALIGNMENT = false; - bool ABSLINES = false; - - while((c = getopt(argc, argv, "-hdalo:i:r:j:k:")) !=-1){ - switch(c){ - case 'o': - outputdir = optarg; - break; - case 'i': - inputdir = optarg; - break; - case 'r': - rootname = optarg; - break; - case 'j': - iteration = atoi(optarg); - break; - case 'k': - kindex= atoi(optarg); - break; - case 'd': - DEBUG = true; - break; - case 'a': - ABSLINES = true; - break; - case 'l': - L1ALIGNMENT = true; - break; - default: - cerr << "Help or unknown argument!" << endl; - help(argv[0]); - break; +int main(int argc, char** argv) { + //---------------------------- + //-- Parse the command line -- + //---------------------------- + + extern char* optarg; + char c; + TString inputdir(""); + + bool L1ALIGNMENT = false; + bool ABSLINES = false; + + while ((c = getopt(argc, argv, "-hdalo:i:r:j:k:")) != -1) { + switch (c) { + case 'o': outputdir = optarg; break; + case 'i': inputdir = optarg; break; + case 'r': rootname = optarg; break; + case 'j': iteration = atoi(optarg); break; + case 'k': kindex = atoi(optarg); break; + case 'd': DEBUG = true; break; + case 'a': ABSLINES = true; break; + case 'l': L1ALIGNMENT = true; break; + default: + cerr << "Help or unknown argument!" << endl; + help(argv[0]); + break; + } } - } - if(rootname==""){ - cerr << "no rootname passed, exiting..." << endl; - exit(1); - } - if(inputdir==""){ - inputdir = rootname; - } - if(outputdir==""){ - outputdir = inputdir; - } - - //---------------- - //-- Initialize -- - //---------------- - - if (L1ALIGNMENT) { - xtitles[0]="#Deltax"; - xtitles[1]="#Deltay"; - xtitles[2]="#Deltaz"; - xtitles[3]="#Delta#alpha(x)"; - xtitles[4]="#Delta#beta(y)"; - xtitles[5]="#Delta#gamma(z)"; - } - - Tools::setStyle(); - double tsize=0.05; - gStyle->SetTextSize(tsize); - gStyle->SetLabelSize(tsize,"x"); - gStyle->SetTitleSize(tsize,"x"); - gStyle->SetLabelSize(tsize,"y"); - gStyle->SetTitleSize(tsize,"y"); - // gStyle->SetFrameFillStyle(0); - // gStyle->SetTitleFillColor(0); - // gStyle->SetTitleBorderSize(1); - gStyle->SetPadLeftMargin(0.15); - gStyle->SetPadRightMargin(0.04); - gStyle->SetTitleYOffset(1.5); - //gStyle->SetOptStat(1111111); - //gStyle->SetOptFit(11111); - gStyle->SetFrameFillStyle(0); - gStyle->SetTitleFillColor(0); - gStyle->SetTitleBorderSize(1); - gStyle->SetPadLeftMargin(0.15); - gStyle->SetPadRightMargin(0.04); - gStyle->SetPalette(1); - - // std::string directory=""; - // if (argc>1) { - // directory=string(argv[1]); - // } - // std::string iteration="0"; - // if (argc>2) { - // iteration=string(argv[2]); - // } - // std::cout<<"using input directory "<<directory<<std::endl; - - std::string asztfile=""; - //if (argc>3) { - // asztfile=string(argv[3]); - //} - - - if(asztfile==""){ - nominalPos[1] = 0.; - nominalPos[2] = 0.; - nominalPos[3] = 0.; - nominalPos[4] = 0.; - nominalPos[5] = 0.; + if (rootname == "") { + cerr << "no rootname passed, exiting..." << endl; + exit(1); + } + if (inputdir == "") { inputdir = rootname; } + if (outputdir == "") { outputdir = inputdir; } + + //---------------- + //-- Initialize -- + //---------------- + + if (L1ALIGNMENT) { + xtitles[0] = "#Deltax"; + xtitles[1] = "#Deltay"; + xtitles[2] = "#Deltaz"; + xtitles[3] = "#Delta#alpha(x)"; + xtitles[4] = "#Delta#beta(y)"; + xtitles[5] = "#Delta#gamma(z)"; + } + + Tools::setStyle(); + double tsize = 0.05; + gStyle->SetTextSize(tsize); + gStyle->SetLabelSize(tsize, "x"); + gStyle->SetTitleSize(tsize, "x"); + gStyle->SetLabelSize(tsize, "y"); + gStyle->SetTitleSize(tsize, "y"); + // gStyle->SetFrameFillStyle(0); + // gStyle->SetTitleFillColor(0); + // gStyle->SetTitleBorderSize(1); + gStyle->SetPadLeftMargin(0.15); + gStyle->SetPadRightMargin(0.04); + gStyle->SetTitleYOffset(1.5); + // gStyle->SetOptStat(1111111); + // gStyle->SetOptFit(11111); + gStyle->SetFrameFillStyle(0); + gStyle->SetTitleFillColor(0); + gStyle->SetTitleBorderSize(1); + gStyle->SetPadLeftMargin(0.15); + gStyle->SetPadRightMargin(0.04); + gStyle->SetPalette(1); + + // std::string directory=""; + // if (argc>1) { + // directory=string(argv[1]); + // } + // std::string iteration="0"; + // if (argc>2) { + // iteration=string(argv[2]); + // } + // std::cout<<"using input directory "<<directory<<std::endl; + + std::string asztfile = ""; + // if (argc>3) { + // asztfile=string(argv[3]); //} - } -/* - TMatrixD nomMatrix(4,3); - for (int i=0;i<3;i++) - for (int j=0;j<3;j++) - if (i==j) nomMatrix[i][j]=1.; - else nomMatrix[i][j]=0.; - nomMatrix[0][3]=0.; - nomMatrix[1][3]=0.; - nomMatrix[2][3]=5700.; -*/ + if (asztfile == "") { + nominalPos[1] = 0.; + nominalPos[2] = 0.; + nominalPos[3] = 0.; + nominalPos[4] = 0.; + nominalPos[5] = 0.; + //} + } + + /* + TMatrixD nomMatrix(4,3); + for (int i=0;i<3;i++) + for (int j=0;j<3;j++) + if (i==j) nomMatrix[i][j]=1.; + else nomMatrix[i][j]=0.; + nomMatrix[0][3]=0.; + nomMatrix[1][3]=0.; + nomMatrix[2][3]=5700.; + */ - else{ - //read nomimal pos from asztfile - //Tools:getPos has to be changed to return double[] - } - - mid=new MuonFixedId(0); + else { + // read nomimal pos from asztfile + // Tools:getPos has to be changed to return double[] + } + mid = new MuonFixedId(0); - //------------------------- - //-- Get data from trees -- - //------------------------- + //------------------------- + //-- Get data from trees -- + //------------------------- - std::map<long long int,double**> fullArrayMap; - std::map<long long int,double**> xarrayMap; - std::map<long long int,long long int> numTracks; - std::map<long long int,string> chamberNames; - std::map<long long int,bool*> goodParams; + std::map<long long int, double**> fullArrayMap; + std::map<long long int, double**> xarrayMap; + std::map<long long int, long long int> numTracks; + std::map<long long int, string> chamberNames; + std::map<long long int, bool*> goodParams; - void *directory = gSystem->OpenDirectory(inputdir); - if (!directory){ - cerr << "input directory does not exist, exiting..." << endl; - exit(1); - } - directory = gSystem->OpenDirectory(outputdir); - if (!directory){ - cerr << "create output directory: " << outputdir << endl; - int status = gSystem->mkdir(outputdir,false); - if(status!=0){ - cerr << "could not create output directory, exiting..." << endl; - exit(1); + void* directory = gSystem->OpenDirectory(inputdir); + if (!directory) { + cerr << "input directory does not exist, exiting..." << endl; + exit(1); } - } - - TString iterdir = inputdir+"/iter0"; - directory = gSystem->OpenDirectory(inputdir+"/iter0"); - bool multiplejobs = directory ? true : false; - cout << "multiplejobs: " << multiplejobs << endl; - - TString basefilename; - if(multiplejobs){ - TString iterdir = inputdir+Form("/iter%i/",iteration); - directory = gSystem->OpenDirectory(iterdir); - basefilename = iterdir; - if(!directory){ - cerr << "iteration: " << iteration << "does not exists, exiting..." << endl; - exit(1); - } - } - else{ - basefilename = inputdir+"/"; - } - - basefilename += "MuonAlign_"+rootname+Form("_iter%i",iteration); - if (kindex>-1) basefilename += Form("_index%i",kindex); - - TString muonalign_filename = basefilename; - TString alignpar_filename = basefilename; - if(multiplejobs && kindex<0){ - muonalign_filename += "_index*"; - alignpar_filename += "_Solve"; - } - muonalign_filename += ".root"; - alignpar_filename += ".root"; - - std::map<long long int,double*> firstderivMap; - std::map<long long int,double*> secndderivMap; - std::map<long long int,double*> initPosMap; - std::map<long long int,double*> alignParMap; - std::map<long long int,double*> alignParErrMap; - - TChain* tree_alignPar=new TChain("alignParMDT"); - std::cout<<"adding to alignpar chain: "<<alignpar_filename <<std::endl; - tree_alignPar->Add(alignpar_filename); - - getDataFromAlignParTree(tree_alignPar,firstderivMap,secndderivMap, - initPosMap,alignParMap,alignParErrMap); - - - TChain* tree=new TChain("MuonAlign"); - std::cout<<"adding to muonalign chain: "<<muonalign_filename <<std::endl; - tree->Add(muonalign_filename); - - m_ntrees=tree->GetNtrees(); - std::cout<<"have "<<m_ntrees<<" trees"<<std::endl; - - getDataFromTree(tree,fullArrayMap,xarrayMap,numTracks,chamberNames,goodParams); - - std::cout<<"alignpar_fiilename="<<alignpar_filename<<std::endl; - - - - //------------------ - //-- Create plots -- - //------------------ - - int totalnchambers=(int)fullArrayMap.size(); - std::cout<<totalnchambers<<" total chamber(s)"<<std::endl; - - // now fit and plot results - TGraph*** gr = new TGraph**[NPARAMS]; - TPaveText*** pave = new TPaveText**[NPARAMS]; - double** firstderivs = new double*[NPARAMS]; - double** secondderivs = new double*[NPARAMS]; - double** zeros = new double*[NPARAMS]; - double** sigmas = new double*[NPARAMS]; - - - for (int i=0;i<NPARAMS;i++) { - gr[i] = new TGraph*[totalnchambers]; - pave[i] = new TPaveText*[totalnchambers]; - firstderivs[i] = new double[totalnchambers]; - secondderivs[i] = new double[totalnchambers]; - zeros[i] = new double[totalnchambers]; - sigmas[i] = new double[totalnchambers]; - } - long long int* identifiers = new long long int[totalnchambers]; - - int ichamber(0); - - std::map<long long int,double**>::const_iterator it =fullArrayMap.begin(); - std::map<long long int,double**>::const_iterator itend=fullArrayMap.end(); - std::map<long long int,double**>::const_iterator xit = xarrayMap.begin(); - std::map<long long int,long long int>::const_iterator numTracksit=numTracks.begin(); - std::map<long long int,string>::const_iterator chamberNamesit=chamberNames.begin(); - std::map<long long int,bool*>::const_iterator goodParIt=goodParams.begin(); - - int nPlotChambers(0); - const int CHAMBERSPERPAGE=1; - - TCanvas* canv=new TCanvas("canv","canv"); - canv->SetFillColor(10); - canv->Divide(3,2*CHAMBERSPERPAGE); - int ipad(1); - int nCanvas(0); - bool* goodpar; - int ntracks=-1; - //double* xarray; - bool saveplot(1); - - for (; it!=itend; it++,numTracksit++,chamberNamesit++,xit++,goodParIt++) { - saveplot=1; - if (chname!=""&&nPlotChambers==CHAMBERSPERPAGE) { - nPlotChambers=0; - stringstream canvname; - canvname<<outputdir<<"/"<<rootname<<"_chi2_v_alignparams_"<<chname<<"_iter"<<iteration; - if (kindex>-1) canvname<<"_index"<<kindex; - canvname<<".eps"; - canv->Print(canvname.str().c_str()); - nCanvas++; - canv->Clear(); - canv->SetFillColor(10); - canv->Divide(3,2*CHAMBERSPERPAGE); - ipad=1; + directory = gSystem->OpenDirectory(outputdir); + if (!directory) { + cerr << "create output directory: " << outputdir << endl; + int status = gSystem->mkdir(outputdir, false); + if (status != 0) { + cerr << "could not create output directory, exiting..." << endl; + exit(1); + } } - chname=chamberNamesit->second; - ntracks=numTracksit->second; - goodpar=goodParIt->second; - //xarray=xit->second; - - identifiers[ichamber]=chamberNamesit->first; - - int id=identifiers[ichamber]; - if (DEBUG) std::cout<<"id = "<<id<<std::endl; - alignPar =alignParMap[id]; - alignParErr =alignParErrMap[id]; - firstderiv =firstderivMap[id]; - secderiv =secndderivMap[id]; - initPos =initPosMap[id]; - if (0==secderiv) { - saveplot=0; - std::cout<<"didn't find secderiv for id "<<id<<std::endl; - continue; + TString iterdir = inputdir + "/iter0"; + directory = gSystem->OpenDirectory(inputdir + "/iter0"); + bool multiplejobs = directory ? true : false; + cout << "multiplejobs: " << multiplejobs << endl; + + TString basefilename; + if (multiplejobs) { + TString iterdir = inputdir + Form("/iter%i/", iteration); + directory = gSystem->OpenDirectory(iterdir); + basefilename = iterdir; + if (!directory) { + cerr << "iteration: " << iteration << "does not exists, exiting..." << endl; + exit(1); + } + } else { + basefilename = inputdir + "/"; } - std::cout<<"found secderiv for id "<<id<<std::endl; - - - TLine** vertlines =new TLine*[NPARAMS]; - TLine** vertlines2=new TLine*[NPARAMS]; - - //TLine** vertline_errlow=new TLine*[6]; - //TLine** vertline_errhigh=new TLine*[6]; - //TBox** errbox=new TBox*[6]; - - for (int iparam=0;iparam<6;iparam++) { - if (!goodpar[iparam]) { ipad++; continue; } - - cout<<"---------------------------------------------------"<<endl; - cout<<"first/secderiv="<<firstderiv[iparam]<<", "<<secderiv[iparam]<<endl; - - double initShift(0.); - if(ABSLINES){ initShift = initPos[iparam]; } - double* x=new double[NSHIFTS]; - for (int i=0;i<NSHIFTS;i++) { - //x[i]=-4.*xarray[iparam]+(double)i*xarray[iparam]; - x[i]=(xit->second)[iparam][i];//-ymin; - x[i]+=initShift; - } - std::cout<<"alignPar["<<iparam<<"]="<<alignPar[iparam]<<std::endl; - - canv->cd(ipad); - if (alignPar[iparam]==0.) continue; - - double* y = new double[NSHIFTS]; - for (int i=0;i<NSHIFTS;i++) { - y[i]=(it->second)[iparam][i];//-ymin; - } - //double* x = new double[NSHIFTS]; - //for (int i=0;i<NSHIFTS;i++) { - // x[i]=(xit->second)[iparam][i];//-ymin; - //} - - gr[iparam][ichamber]=new TGraph(NSHIFTS,x,y); - TGraph* thisgr=gr[iparam][ichamber]; - thisgr->SetMarkerSize(1); - thisgr->SetMarkerStyle(20); - thisgr->SetLineWidth(3); - thisgr->Draw("AP"); - thisgr->GetXaxis()->SetTitle((xtitles[iparam]+units[iparam]).c_str()); - // thisgr->GetXaxis()->SetTitleSize(0.045); - thisgr->GetYaxis()->SetTitle("global #chi^{2}"); - // thisgr->GetYaxis()->SetTitleSize(0.06); - //thisgr->GetYaxis()->SetTitleOffset(1.6); - thisgr->SetTitle((chname+string(" - ")+xtitles[iparam]).c_str()); - thisgr->Fit("pol2","Q"); - - TF1* fit=gr[iparam][ichamber]->GetFunction("pol2"); - - stringstream fitname; fitname<<"fit"<<iparam; - TF1* fit2=new TF1(fitname.str().c_str(),"pol2",x[0],x[NSHIFTS-1]); - - double a=0.5*secderiv[iparam]; - double b=firstderiv[iparam] - secderiv[iparam]*initShift; - //double c=fit->GetMinimum() + b*b/a/4.; - double c=fit->Eval(0.); - //if (std::fabs(y[0]-y[4])<1.e-5) { - // c=y[0]; // special case where first deriv is negligible - // a=b=0.; - //} - - fit2->SetParameter(2,a); - fit2->SetParameter(1,b); - fit2->SetParameter(0,c); - fit2->SetLineColor(kRed); - - //double min=fit->GetMinimum(); - //if (fit2->GetMinimum()<min) { - // fit2->Draw(); - // gr[iparam][ichamber]->Draw("Psame"); - // fit->Draw("same"); - //} - //else { - - fit->Draw("same"); - //} - - fit2->Draw("same"); - - //if (DEBUG) std::cout<<"identifiers["<<ichamber<<"]="<<identifiers[ichamber]<<std::endl; - - double gr_Xmin = thisgr->GetXaxis()->GetXmin(); - double gr_Xmax = thisgr->GetXaxis()->GetXmax(); - double gr_Ymin = thisgr->GetYaxis()->GetXmin(); - double gr_Ymax = thisgr->GetYaxis()->GetXmax(); - - double line1pos(0.); - double line2pos(0.); - - if(ABSLINES){ - line1pos = nominalPos[iparam]; - line2pos = initPos[iparam]+alignPar[iparam]; - } - else{ - line1pos = nominalPos[iparam]+initPos[iparam]; - line2pos = nominalPos[iparam]+initPos[iparam]+alignPar[iparam]; - } - if(line2pos > gr_Xmax) line2pos = gr_Xmax; - if(line2pos < gr_Xmin) line2pos = gr_Xmin; - - //cout << "line1: " << - - // vertical lines - //if (identifiers[ichamber]==240131072) { - // std::cout<<"drawing vert line"<<std::endl; - // cout << "min: " << thisgr->GetYaxis()->GetXmin() << endl; - - vertlines[iparam]=new TLine(line1pos,gr_Ymin,line1pos,gr_Ymax); - vertlines[iparam]->SetLineColor(kBlue); - vertlines[iparam]->SetLineWidth(2); - vertlines[iparam]->Draw("same"); - //} - - vertlines2[iparam]=new TLine(line2pos,gr_Ymin,line2pos,gr_Ymax); - vertlines2[iparam]->SetLineColor(kGreen); - vertlines2[iparam]->SetLineWidth(2); - vertlines2[iparam]->Draw("same"); - - - // vertline_errlow[iparam]=new TLine(alignPar[iparam]-alignParErr[iparam],gr_Ymin, - // alignPar[iparam]-alignParErr[iparam],gr_Ymax); - // vertline_errlow[iparam]->SetLineColor(kGreen); - // vertline_errlow[iparam]->SetLineWidth(1); - // vertline_errlow[iparam]->Draw("same"); - // vertline_errhigh[iparam]=new TLine(alignPar[iparam]+alignParErr[iparam],gr_Ymin, - // alignPar[iparam]+alignParErr[iparam],gr_Ymax); - // vertline_errhigh[iparam]->SetLineColor(kGreen); - // vertline_errhigh[iparam]->SetLineWidth(1); - // vertline_errhigh[iparam]->Draw("same"); - - // errbox[iparam]=new TBox(alignPar[iparam]-alignParErr[iparam],gr_Ymin, - // alignPar[iparam]+alignParErr[iparam],gr_Ymax); - // errbox[iparam]->SetFillColor(kGreen); - // errbox[iparam]->SetFillStyle(3144); - // errbox[iparam]->SetLineWidth(0); - // errbox[iparam]->Draw("same"); - - //pave[iparam][ichamber]=new TPaveText(.40,.65,.97,.92,"NDC"); - pave[iparam][ichamber]=new TPaveText(.40,.75,.98,.98,"NDC"); - - TPaveText* thispave=pave[iparam][ichamber]; - thispave->SetFillColor(0); - thispave->SetBorderSize(1); - thispave->SetTextAlign(12); - - firstderivs [iparam][ichamber] = fit->GetParameter(1); - secondderivs[iparam][ichamber] = 2.*fit->GetParameter(2); - sigmas [iparam][ichamber] = std::sqrt(2./fit->GetParameter(2)); - zeros [iparam][ichamber] = fit->GetMinimumX(x[0],x[NSHIFTS-1]); - //if (DEBUG) { - //cout<<"\nfit: "<<endl; - //fit->Print(); - //} - - //stringstream idstr; idstr<<numTracksit->first; - //thispave->AddText(idstr.str().c_str()); - - stringstream num; - num<<"Number of tracks: "<<ntracks;//<<" tracks"; - thispave->AddText(num.str().c_str()); - - //std::cout<<"correct/fit="<<fit->GetParameter(1)<<"/"<<fit2->GetParameter(1)<<std::endl; - - stringstream first; first.setf(ios::scientific); first.precision(2); - first<<"1st deriv: "<<firstderivs[iparam][ichamber]<<" #pm "<<fit->GetParError(1); - //std::cout<<"firstderivs["<<iparam<<"]["<<ichamber<<"]="<<firstderivs[iparam][ichamber]<<std::endl; - //std::cout<<first.str()<<std::endl; - thispave->AddText(first.str().c_str()); - stringstream secnd; - secnd.setf(ios::scientific); secnd.precision(2); - secnd<<"2nd deriv: "<<secondderivs[iparam][ichamber]<<" #pm "<<fit->GetParError(2); - std::cout<<"id 1stderiv 2ndderiv: "<<identifiers[ichamber]<<" "<<firstderivs[iparam][ichamber] - <<" "<<secondderivs[iparam][ichamber]<<std::endl; - thispave->AddText(secnd.str().c_str()); - stringstream sigma; sigma.setf(ios::scientific); sigma.precision(2); - sigma<<"Minimum: "<<zeros[iparam][ichamber]<<" #pm " << sigmas[iparam][ichamber]; - thispave->AddText(sigma.str().c_str()); - thispave->Draw(); - canv->cd(ipad)->Update(); - delete [] y; - delete [] x; - - //stringstream pcanvname; - //pcanvname<<outputdir<<"/"<<rootname<<"_chi2_v_alignparams_"<<chname<<"_pad"<<ipad<<"_iter"<<iteration<<".eps"; - //if(saveplot) canv->cd(ipad)->Print(pcanvname.str().c_str()); - - ipad++; + + basefilename += "MuonAlign_" + rootname + Form("_iter%i", iteration); + if (kindex > -1) basefilename += Form("_index%i", kindex); + + TString muonalign_filename = basefilename; + TString alignpar_filename = basefilename; + if (multiplejobs && kindex < 0) { + muonalign_filename += "_index*"; + alignpar_filename += "_Solve"; + } + muonalign_filename += ".root"; + alignpar_filename += ".root"; + + std::map<long long int, double*> firstderivMap; + std::map<long long int, double*> secndderivMap; + std::map<long long int, double*> initPosMap; + std::map<long long int, double*> alignParMap; + std::map<long long int, double*> alignParErrMap; + + TChain* tree_alignPar = new TChain("alignParMDT"); + std::cout << "adding to alignpar chain: " << alignpar_filename << std::endl; + tree_alignPar->Add(alignpar_filename); + + getDataFromAlignParTree(tree_alignPar, firstderivMap, secndderivMap, initPosMap, alignParMap, alignParErrMap); + + TChain* tree = new TChain("MuonAlign"); + std::cout << "adding to muonalign chain: " << muonalign_filename << std::endl; + tree->Add(muonalign_filename); + + m_ntrees = tree->GetNtrees(); + std::cout << "have " << m_ntrees << " trees" << std::endl; + + getDataFromTree(tree, fullArrayMap, xarrayMap, numTracks, chamberNames, goodParams); + + std::cout << "alignpar_fiilename=" << alignpar_filename << std::endl; + + //------------------ + //-- Create plots -- + //------------------ + + int totalnchambers = (int)fullArrayMap.size(); + std::cout << totalnchambers << " total chamber(s)" << std::endl; + + // now fit and plot results + TGraph*** gr = new TGraph**[NPARAMS]; + TPaveText*** pave = new TPaveText**[NPARAMS]; + double** firstderivs = new double*[NPARAMS]; + double** secondderivs = new double*[NPARAMS]; + double** zeros = new double*[NPARAMS]; + double** sigmas = new double*[NPARAMS]; + + for (int i = 0; i < NPARAMS; i++) { + gr[i] = new TGraph*[totalnchambers]; + pave[i] = new TPaveText*[totalnchambers]; + firstderivs[i] = new double[totalnchambers]; + secondderivs[i] = new double[totalnchambers]; + zeros[i] = new double[totalnchambers]; + sigmas[i] = new double[totalnchambers]; } + long long int* identifiers = new long long int[totalnchambers]; + + int ichamber(0); + + std::map<long long int, double**>::const_iterator it = fullArrayMap.begin(); + std::map<long long int, double**>::const_iterator itend = fullArrayMap.end(); + std::map<long long int, double**>::const_iterator xit = xarrayMap.begin(); + std::map<long long int, long long int>::const_iterator numTracksit = numTracks.begin(); + std::map<long long int, string>::const_iterator chamberNamesit = chamberNames.begin(); + std::map<long long int, bool*>::const_iterator goodParIt = goodParams.begin(); + + int nPlotChambers(0); + const int CHAMBERSPERPAGE = 1; + + TCanvas* canv = new TCanvas("canv", "canv"); + canv->SetFillColor(10); + canv->Divide(3, 2 * CHAMBERSPERPAGE); + int ipad(1); + int nCanvas(0); + bool* goodpar; + int ntracks = -1; + // double* xarray; + bool saveplot(1); + + for (; it != itend; it++, numTracksit++, chamberNamesit++, xit++, goodParIt++) { + saveplot = 1; + if (chname != "" && nPlotChambers == CHAMBERSPERPAGE) { + nPlotChambers = 0; + stringstream canvname; + canvname << outputdir << "/" << rootname << "_chi2_v_alignparams_" << chname << "_iter" << iteration; + if (kindex > -1) canvname << "_index" << kindex; + canvname << ".eps"; + canv->Print(canvname.str().c_str()); + nCanvas++; + canv->Clear(); + canv->SetFillColor(10); + canv->Divide(3, 2 * CHAMBERSPERPAGE); + ipad = 1; + } + + chname = chamberNamesit->second; + ntracks = numTracksit->second; + goodpar = goodParIt->second; + // xarray=xit->second; + + identifiers[ichamber] = chamberNamesit->first; + + int id = identifiers[ichamber]; + if (DEBUG) std::cout << "id = " << id << std::endl; + alignPar = alignParMap[id]; + alignParErr = alignParErrMap[id]; + firstderiv = firstderivMap[id]; + secderiv = secndderivMap[id]; + initPos = initPosMap[id]; + if (0 == secderiv) { + saveplot = 0; + std::cout << "didn't find secderiv for id " << id << std::endl; + continue; + } + std::cout << "found secderiv for id " << id << std::endl; + + TLine** vertlines = new TLine*[NPARAMS]; + TLine** vertlines2 = new TLine*[NPARAMS]; + + // TLine** vertline_errlow=new TLine*[6]; + // TLine** vertline_errhigh=new TLine*[6]; + // TBox** errbox=new TBox*[6]; + + for (int iparam = 0; iparam < 6; iparam++) { + if (!goodpar[iparam]) { + ipad++; + continue; + } + + cout << "---------------------------------------------------" << endl; + cout << "first/secderiv=" << firstderiv[iparam] << ", " << secderiv[iparam] << endl; + + double initShift(0.); + if (ABSLINES) { initShift = initPos[iparam]; } + double* x = new double[NSHIFTS]; + for (int i = 0; i < NSHIFTS; i++) { + // x[i]=-4.*xarray[iparam]+(double)i*xarray[iparam]; + x[i] = (xit->second)[iparam][i]; //-ymin; + x[i] += initShift; + } + std::cout << "alignPar[" << iparam << "]=" << alignPar[iparam] << std::endl; + + canv->cd(ipad); + if (alignPar[iparam] == 0.) continue; + + double* y = new double[NSHIFTS]; + for (int i = 0; i < NSHIFTS; i++) { + y[i] = (it->second)[iparam][i]; //-ymin; + } + // double* x = new double[NSHIFTS]; + // for (int i=0;i<NSHIFTS;i++) { + // x[i]=(xit->second)[iparam][i];//-ymin; + //} + + gr[iparam][ichamber] = new TGraph(NSHIFTS, x, y); + TGraph* thisgr = gr[iparam][ichamber]; + thisgr->SetMarkerSize(1); + thisgr->SetMarkerStyle(20); + thisgr->SetLineWidth(3); + thisgr->Draw("AP"); + thisgr->GetXaxis()->SetTitle((xtitles[iparam] + units[iparam]).c_str()); + // thisgr->GetXaxis()->SetTitleSize(0.045); + thisgr->GetYaxis()->SetTitle("global #chi^{2}"); + // thisgr->GetYaxis()->SetTitleSize(0.06); + // thisgr->GetYaxis()->SetTitleOffset(1.6); + thisgr->SetTitle((chname + string(" - ") + xtitles[iparam]).c_str()); + thisgr->Fit("pol2", "Q"); + + TF1* fit = gr[iparam][ichamber]->GetFunction("pol2"); + + stringstream fitname; + fitname << "fit" << iparam; + TF1* fit2 = new TF1(fitname.str().c_str(), "pol2", x[0], x[NSHIFTS - 1]); + + double a = 0.5 * secderiv[iparam]; + double b = firstderiv[iparam] - secderiv[iparam] * initShift; + // double c=fit->GetMinimum() + b*b/a/4.; + double c = fit->Eval(0.); + // if (std::fabs(y[0]-y[4])<1.e-5) { + // c=y[0]; // special case where first deriv is negligible + // a=b=0.; + //} + + fit2->SetParameter(2, a); + fit2->SetParameter(1, b); + fit2->SetParameter(0, c); + fit2->SetLineColor(kRed); + + // double min=fit->GetMinimum(); + // if (fit2->GetMinimum()<min) { + // fit2->Draw(); + // gr[iparam][ichamber]->Draw("Psame"); + // fit->Draw("same"); + //} + // else { + + fit->Draw("same"); + //} + + fit2->Draw("same"); + + // if (DEBUG) std::cout<<"identifiers["<<ichamber<<"]="<<identifiers[ichamber]<<std::endl; + + double gr_Xmin = thisgr->GetXaxis()->GetXmin(); + double gr_Xmax = thisgr->GetXaxis()->GetXmax(); + double gr_Ymin = thisgr->GetYaxis()->GetXmin(); + double gr_Ymax = thisgr->GetYaxis()->GetXmax(); + + double line1pos(0.); + double line2pos(0.); + + if (ABSLINES) { + line1pos = nominalPos[iparam]; + line2pos = initPos[iparam] + alignPar[iparam]; + } else { + line1pos = nominalPos[iparam] + initPos[iparam]; + line2pos = nominalPos[iparam] + initPos[iparam] + alignPar[iparam]; + } + if (line2pos > gr_Xmax) line2pos = gr_Xmax; + if (line2pos < gr_Xmin) line2pos = gr_Xmin; + + // cout << "line1: " << + + // vertical lines + // if (identifiers[ichamber]==240131072) { + // std::cout<<"drawing vert line"<<std::endl; + // cout << "min: " << thisgr->GetYaxis()->GetXmin() << endl; + + vertlines[iparam] = new TLine(line1pos, gr_Ymin, line1pos, gr_Ymax); + vertlines[iparam]->SetLineColor(kBlue); + vertlines[iparam]->SetLineWidth(2); + vertlines[iparam]->Draw("same"); + //} + + vertlines2[iparam] = new TLine(line2pos, gr_Ymin, line2pos, gr_Ymax); + vertlines2[iparam]->SetLineColor(kGreen); + vertlines2[iparam]->SetLineWidth(2); + vertlines2[iparam]->Draw("same"); + + // vertline_errlow[iparam]=new TLine(alignPar[iparam]-alignParErr[iparam],gr_Ymin, + // alignPar[iparam]-alignParErr[iparam],gr_Ymax); + // vertline_errlow[iparam]->SetLineColor(kGreen); + // vertline_errlow[iparam]->SetLineWidth(1); + // vertline_errlow[iparam]->Draw("same"); + // vertline_errhigh[iparam]=new TLine(alignPar[iparam]+alignParErr[iparam],gr_Ymin, + // alignPar[iparam]+alignParErr[iparam],gr_Ymax); + // vertline_errhigh[iparam]->SetLineColor(kGreen); + // vertline_errhigh[iparam]->SetLineWidth(1); + // vertline_errhigh[iparam]->Draw("same"); + + // errbox[iparam]=new TBox(alignPar[iparam]-alignParErr[iparam],gr_Ymin, + // alignPar[iparam]+alignParErr[iparam],gr_Ymax); + // errbox[iparam]->SetFillColor(kGreen); + // errbox[iparam]->SetFillStyle(3144); + // errbox[iparam]->SetLineWidth(0); + // errbox[iparam]->Draw("same"); + + // pave[iparam][ichamber]=new TPaveText(.40,.65,.97,.92,"NDC"); + pave[iparam][ichamber] = new TPaveText(.40, .75, .98, .98, "NDC"); + + TPaveText* thispave = pave[iparam][ichamber]; + thispave->SetFillColor(0); + thispave->SetBorderSize(1); + thispave->SetTextAlign(12); + + firstderivs[iparam][ichamber] = fit->GetParameter(1); + secondderivs[iparam][ichamber] = 2. * fit->GetParameter(2); + sigmas[iparam][ichamber] = std::sqrt(2. / fit->GetParameter(2)); + zeros[iparam][ichamber] = fit->GetMinimumX(x[0], x[NSHIFTS - 1]); + // if (DEBUG) { + // cout<<"\nfit: "<<endl; + // fit->Print(); + //} + + // stringstream idstr; idstr<<numTracksit->first; + // thispave->AddText(idstr.str().c_str()); + + stringstream num; + num << "Number of tracks: " << ntracks; //<<" tracks"; + thispave->AddText(num.str().c_str()); + + // std::cout<<"correct/fit="<<fit->GetParameter(1)<<"/"<<fit2->GetParameter(1)<<std::endl; + + stringstream first; + first.setf(ios::scientific); + first.precision(2); + first << "1st deriv: " << firstderivs[iparam][ichamber] << " #pm " << fit->GetParError(1); + // std::cout<<"firstderivs["<<iparam<<"]["<<ichamber<<"]="<<firstderivs[iparam][ichamber]<<std::endl; + // std::cout<<first.str()<<std::endl; + thispave->AddText(first.str().c_str()); + stringstream secnd; + secnd.setf(ios::scientific); + secnd.precision(2); + secnd << "2nd deriv: " << secondderivs[iparam][ichamber] << " #pm " << fit->GetParError(2); + std::cout << "id 1stderiv 2ndderiv: " << identifiers[ichamber] << " " << firstderivs[iparam][ichamber] << " " + << secondderivs[iparam][ichamber] << std::endl; + thispave->AddText(secnd.str().c_str()); + stringstream sigma; + sigma.setf(ios::scientific); + sigma.precision(2); + sigma << "Minimum: " << zeros[iparam][ichamber] << " #pm " << sigmas[iparam][ichamber]; + thispave->AddText(sigma.str().c_str()); + thispave->Draw(); + canv->cd(ipad)->Update(); + delete[] y; + delete[] x; + + // stringstream pcanvname; + // pcanvname<<outputdir<<"/"<<rootname<<"_chi2_v_alignparams_"<<chname<<"_pad"<<ipad<<"_iter"<<iteration<<".eps"; + // if(saveplot) canv->cd(ipad)->Print(pcanvname.str().c_str()); + + ipad++; + } - nPlotChambers++; - ichamber++; - } - stringstream canvname; - canvname<<outputdir<<"/"<<rootname<<"_chi2_v_alignparams_"<<chname<<"_iter"<<iteration; - if (kindex>-1) canvname<<"_index"<<kindex; - canvname<<".eps"; - if(saveplot) canv->Print(canvname.str().c_str()); - - - //--------------- - //-- Plot pull -- - //--------------- - - gStyle->SetOptFit(1111); - - canv->Clear(); - canv->SetFillColor(10); - canv->Divide(3,2); - int nplottedchambers=ichamber; - TH1F** hist=new TH1F*[NPARAMS]; - for (int iparam=0;iparam<6;iparam++) { - stringstream histname; histname<<"pull_"<<iparam; - hist[iparam]=new TH1F(histname.str().c_str(),histname.str().c_str(),15,-5.,5.); - for (int ich=0;ich<nplottedchambers;ich++) { - double pull=zeros[iparam][ich]/sigmas[iparam][ich]; - hist[iparam]->Fill(pull); + nPlotChambers++; + ichamber++; + } + stringstream canvname; + canvname << outputdir << "/" << rootname << "_chi2_v_alignparams_" << chname << "_iter" << iteration; + if (kindex > -1) canvname << "_index" << kindex; + canvname << ".eps"; + if (saveplot) canv->Print(canvname.str().c_str()); + + //--------------- + //-- Plot pull -- + //--------------- + + gStyle->SetOptFit(1111); + + canv->Clear(); + canv->SetFillColor(10); + canv->Divide(3, 2); + int nplottedchambers = ichamber; + TH1F** hist = new TH1F*[NPARAMS]; + for (int iparam = 0; iparam < 6; iparam++) { + stringstream histname; + histname << "pull_" << iparam; + hist[iparam] = new TH1F(histname.str().c_str(), histname.str().c_str(), 15, -5., 5.); + for (int ich = 0; ich < nplottedchambers; ich++) { + double pull = zeros[iparam][ich] / sigmas[iparam][ich]; + hist[iparam]->Fill(pull); + } + canv->cd(iparam + 1); + hist[iparam]->Draw(); + hist[iparam]->Fit("gaus", "Q"); } - canv->cd(iparam+1); - hist[iparam]->Draw(); - hist[iparam]->Fit("gaus","Q"); - } - if(saveplot) canv->Print(outputdir+"/"+rootname+"_pull"+Form("_iter%i",iteration)+".eps"); - - delete [] hist; - delete canv; + if (saveplot) canv->Print(outputdir + "/" + rootname + "_pull" + Form("_iter%i", iteration) + ".eps"); + delete[] hist; + delete canv; } //________________________________________________________________________ -void Init(TTree* tree) -{ - - -} +void Init(TTree* tree) {} //________________________________________________________________________ -void getDataFromTree(TChain* tree, - std::map<long long int,double**>& fullArrayMap, - std::map<long long int,double**>& xarrayMap, - std::map<long long int,long long int>& numTracks, - std::map<long long int,string>& chamberNames, - std::map<long long int,bool*>& goodParams) -{ - std::cout<<"getting data from tree"<<std::endl; - // tree variables - int run; - int evt; - int nchambers; - long long int* chamberid =new long long int[10]; - - TMatrixD* chi2_transx =new TMatrixD(NSHIFTS,10); - TMatrixD* chi2_transy =new TMatrixD(NSHIFTS,10); - TMatrixD* chi2_transz =new TMatrixD(NSHIFTS,10); - TMatrixD* chi2_rotx =new TMatrixD(NSHIFTS,10); - TMatrixD* chi2_roty =new TMatrixD(NSHIFTS,10); - TMatrixD* chi2_rotz =new TMatrixD(NSHIFTS,10); - TMatrixD* chi2_transx_X=new TMatrixD(NSHIFTS,10); - TMatrixD* chi2_transy_X=new TMatrixD(NSHIFTS,10); - TMatrixD* chi2_transz_X=new TMatrixD(NSHIFTS,10); - TMatrixD* chi2_rotx_X =new TMatrixD(NSHIFTS,10); - TMatrixD* chi2_roty_X =new TMatrixD(NSHIFTS,10); - TMatrixD* chi2_rotz_X =new TMatrixD(NSHIFTS,10); - - tree->SetBranchAddress("run", &run); - tree->SetBranchAddress("evt", &evt); - tree->SetBranchAddress("nchambers", &nchambers); - tree->SetBranchAddress("chamberid", chamberid); - tree->SetBranchAddress("chi2_transx", &chi2_transx); - tree->SetBranchAddress("chi2_transy", &chi2_transy); - tree->SetBranchAddress("chi2_transz", &chi2_transz); - tree->SetBranchAddress("chi2_rotx", &chi2_rotx); - tree->SetBranchAddress("chi2_roty", &chi2_roty); - tree->SetBranchAddress("chi2_rotz", &chi2_rotz); - tree->SetBranchAddress("chi2_transx_X",&chi2_transx_X); - tree->SetBranchAddress("chi2_transy_X",&chi2_transy_X); - tree->SetBranchAddress("chi2_transz_X",&chi2_transz_X); - tree->SetBranchAddress("chi2_rotx_X", &chi2_rotx_X); - tree->SetBranchAddress("chi2_roty_X", &chi2_roty_X); - tree->SetBranchAddress("chi2_rotz_X", &chi2_rotz_X); - - //double msid_ptDiff; - double chi2VAlignParamQuality[6]; - //tree->SetBranchAddress("MSID_ptDiff", &msid_ptDiff); - tree->SetBranchAddress("chi2VAlignParamQuality", chi2VAlignParamQuality); - - std::cout<<"in datatree, have "<<tree->GetEntries()<<" entries"<<std::endl; - - /* - TH2F** h2MSIDpTVTrackQual=new TH2F*[6]; - - h2MSIDpTVTrackQual[0] =new TH2F("h2MSIDpTVTrackQualX", "h2MSIDpTVTrackQualX", 30,-20.,10.,30,0.,0.2); - h2MSIDpTVTrackQual[1] =new TH2F("h2MSIDpTVTrackQualY", "h2MSIDpTVTrackQualY", 30,-20.,10.,30,0.,0.2); - h2MSIDpTVTrackQual[2] =new TH2F("h2MSIDpTVTrackQualZ", "h2MSIDpTVTrackQualZ", 30,-20.,10.,30,0.,0.2); - h2MSIDpTVTrackQual[3] =new TH2F("h2MSIDpTVTrackQualRotX","h2MSIDpTVTrackQualRotX",30,-20.,10.,30,0.,0.2); - h2MSIDpTVTrackQual[4] =new TH2F("h2MSIDpTVTrackQualRotY","h2MSIDpTVTrackQualRotY",30,-20.,10.,30,0.,0.2); - h2MSIDpTVTrackQual[5] =new TH2F("h2MSIDpTVTrackQualRotZ","h2MSIDpTVTrackQualRotZ",30,-20.,10.,30,0.,0.2); - */ - - for (int ientry=0;ientry<tree->GetEntries();ientry++) { - tree->GetEntry(ientry); - - for (int ich=0;ich<nchambers;ich++) { - - bool* goodpar=new bool[6]; - for (int i=0;i<6;i++) goodpar[i]=true; - - // first make sure there are no zeros in the chi2 - for (int ish=0;ish<NSHIFTS;ish++) { - if ((*chi2_transx)[ish][ich]==0.) goodpar[0]=false; - if ((*chi2_transy)[ish][ich]==0.) goodpar[1]=false; - if ((*chi2_transz)[ish][ich]==0.) goodpar[2]=false; - if ((*chi2_rotx) [ish][ich]==0.) goodpar[3]=false; - if ((*chi2_roty) [ish][ich]==0.) goodpar[4]=false; - if ((*chi2_rotz) [ish][ich]==0.) goodpar[5]=false; - - if ( ((*chi2_transx)[ish][ich]>0. && ((*chi2_transx)[ish][ich]<=.001)) || - ((*chi2_transy)[ish][ich]>0. && ((*chi2_transy)[ish][ich]<=.001)) || - ((*chi2_transz)[ish][ich]>0. && ((*chi2_transz)[ish][ich]<=.001)) || - ((*chi2_rotx)[ish][ich]>0. && ((*chi2_rotx)[ish][ich]<=.001)) || - ((*chi2_roty)[ish][ich]>0. && ((*chi2_roty)[ish][ich]<=.001)) || - ((*chi2_rotz)[ish][ich]>0. && ((*chi2_rotz)[ish][ich]<=.001)) ) - continue; - } - - //int hid=hitid[ich]; - long long int chamberId=chamberid[ich]; - - stringstream chambername; - if (chamberId<3) { - switch (chamberId) { - case 0: chambername<<"endcapA"; break; - case 1: chambername<<"endcapC"; break; - case 2: chambername<<"barrel"; break; - } - } - else { - mid->setMuonIdentifier(chamberId); - chambername << Tools::getChamberName(mid); - } - - std::map<long long int,double**>::const_iterator it=fullArrayMap.find(chamberId); - std::map<long long int,double**>::const_iterator xit=xarrayMap.find(chamberId); - if (it==fullArrayMap.end()) { - double** thisarray=new double*[NPARAMS]; - double** xarray =new double*[NPARAMS]; - for (int iparam=0;iparam<NPARAMS;iparam++){ - thisarray[iparam]=new double[NSHIFTS]; - xarray[iparam]=new double[NSHIFTS]; +void getDataFromTree(TChain* tree, std::map<long long int, double**>& fullArrayMap, std::map<long long int, double**>& xarrayMap, + std::map<long long int, long long int>& numTracks, std::map<long long int, string>& chamberNames, + std::map<long long int, bool*>& goodParams) { + std::cout << "getting data from tree" << std::endl; + // tree variables + int run; + int evt; + int nchambers; + long long int* chamberid = new long long int[10]; + + TMatrixD* chi2_transx = new TMatrixD(NSHIFTS, 10); + TMatrixD* chi2_transy = new TMatrixD(NSHIFTS, 10); + TMatrixD* chi2_transz = new TMatrixD(NSHIFTS, 10); + TMatrixD* chi2_rotx = new TMatrixD(NSHIFTS, 10); + TMatrixD* chi2_roty = new TMatrixD(NSHIFTS, 10); + TMatrixD* chi2_rotz = new TMatrixD(NSHIFTS, 10); + TMatrixD* chi2_transx_X = new TMatrixD(NSHIFTS, 10); + TMatrixD* chi2_transy_X = new TMatrixD(NSHIFTS, 10); + TMatrixD* chi2_transz_X = new TMatrixD(NSHIFTS, 10); + TMatrixD* chi2_rotx_X = new TMatrixD(NSHIFTS, 10); + TMatrixD* chi2_roty_X = new TMatrixD(NSHIFTS, 10); + TMatrixD* chi2_rotz_X = new TMatrixD(NSHIFTS, 10); + + tree->SetBranchAddress("run", &run); + tree->SetBranchAddress("evt", &evt); + tree->SetBranchAddress("nchambers", &nchambers); + tree->SetBranchAddress("chamberid", chamberid); + tree->SetBranchAddress("chi2_transx", &chi2_transx); + tree->SetBranchAddress("chi2_transy", &chi2_transy); + tree->SetBranchAddress("chi2_transz", &chi2_transz); + tree->SetBranchAddress("chi2_rotx", &chi2_rotx); + tree->SetBranchAddress("chi2_roty", &chi2_roty); + tree->SetBranchAddress("chi2_rotz", &chi2_rotz); + tree->SetBranchAddress("chi2_transx_X", &chi2_transx_X); + tree->SetBranchAddress("chi2_transy_X", &chi2_transy_X); + tree->SetBranchAddress("chi2_transz_X", &chi2_transz_X); + tree->SetBranchAddress("chi2_rotx_X", &chi2_rotx_X); + tree->SetBranchAddress("chi2_roty_X", &chi2_roty_X); + tree->SetBranchAddress("chi2_rotz_X", &chi2_rotz_X); + + // double msid_ptDiff; + double chi2VAlignParamQuality[6]; + // tree->SetBranchAddress("MSID_ptDiff", &msid_ptDiff); + tree->SetBranchAddress("chi2VAlignParamQuality", chi2VAlignParamQuality); + + std::cout << "in datatree, have " << tree->GetEntries() << " entries" << std::endl; + + /* + TH2F** h2MSIDpTVTrackQual=new TH2F*[6]; + + h2MSIDpTVTrackQual[0] =new TH2F("h2MSIDpTVTrackQualX", "h2MSIDpTVTrackQualX", 30,-20.,10.,30,0.,0.2); + h2MSIDpTVTrackQual[1] =new TH2F("h2MSIDpTVTrackQualY", "h2MSIDpTVTrackQualY", 30,-20.,10.,30,0.,0.2); + h2MSIDpTVTrackQual[2] =new TH2F("h2MSIDpTVTrackQualZ", "h2MSIDpTVTrackQualZ", 30,-20.,10.,30,0.,0.2); + h2MSIDpTVTrackQual[3] =new TH2F("h2MSIDpTVTrackQualRotX","h2MSIDpTVTrackQualRotX",30,-20.,10.,30,0.,0.2); + h2MSIDpTVTrackQual[4] =new TH2F("h2MSIDpTVTrackQualRotY","h2MSIDpTVTrackQualRotY",30,-20.,10.,30,0.,0.2); + h2MSIDpTVTrackQual[5] =new TH2F("h2MSIDpTVTrackQualRotZ","h2MSIDpTVTrackQualRotZ",30,-20.,10.,30,0.,0.2); + */ + + for (int ientry = 0; ientry < tree->GetEntries(); ientry++) { + tree->GetEntry(ientry); + + for (int ich = 0; ich < nchambers; ich++) { + bool* goodpar = new bool[6]; + for (int i = 0; i < 6; i++) goodpar[i] = true; + + // first make sure there are no zeros in the chi2 + for (int ish = 0; ish < NSHIFTS; ish++) { + if ((*chi2_transx)[ish][ich] == 0.) goodpar[0] = false; + if ((*chi2_transy)[ish][ich] == 0.) goodpar[1] = false; + if ((*chi2_transz)[ish][ich] == 0.) goodpar[2] = false; + if ((*chi2_rotx)[ish][ich] == 0.) goodpar[3] = false; + if ((*chi2_roty)[ish][ich] == 0.) goodpar[4] = false; + if ((*chi2_rotz)[ish][ich] == 0.) goodpar[5] = false; + + if (((*chi2_transx)[ish][ich] > 0. && ((*chi2_transx)[ish][ich] <= .001)) || + ((*chi2_transy)[ish][ich] > 0. && ((*chi2_transy)[ish][ich] <= .001)) || + ((*chi2_transz)[ish][ich] > 0. && ((*chi2_transz)[ish][ich] <= .001)) || + ((*chi2_rotx)[ish][ich] > 0. && ((*chi2_rotx)[ish][ich] <= .001)) || + ((*chi2_roty)[ish][ich] > 0. && ((*chi2_roty)[ish][ich] <= .001)) || + ((*chi2_rotz)[ish][ich] > 0. && ((*chi2_rotz)[ish][ich] <= .001))) + continue; + } + + // int hid=hitid[ich]; + long long int chamberId = chamberid[ich]; + + stringstream chambername; + if (chamberId < 3) { + switch (chamberId) { + case 0: chambername << "endcapA"; break; + case 1: chambername << "endcapC"; break; + case 2: chambername << "barrel"; break; + } + } else { + mid->setMuonIdentifier(chamberId); + chambername << Tools::getChamberName(mid); + } + + std::map<long long int, double**>::const_iterator it = fullArrayMap.find(chamberId); + std::map<long long int, double**>::const_iterator xit = xarrayMap.find(chamberId); + if (it == fullArrayMap.end()) { + double** thisarray = new double*[NPARAMS]; + double** xarray = new double*[NPARAMS]; + for (int iparam = 0; iparam < NPARAMS; iparam++) { + thisarray[iparam] = new double[NSHIFTS]; + xarray[iparam] = new double[NSHIFTS]; + } + + for (int ish = 0; ish < NSHIFTS; ish++) { + if (goodpar[0]) { + xarray[0][ish] = (*chi2_transx_X)[ish][ich]; + thisarray[0][ish] = (*chi2_transx)[ish][ich]; + } + thisarray[1][ish] = (*chi2_transy)[ish][ich]; + thisarray[2][ish] = (*chi2_transz)[ish][ich]; + thisarray[3][ish] = (*chi2_rotx)[ish][ich]; + thisarray[4][ish] = (*chi2_roty)[ish][ich]; + xarray[1][ish] = (*chi2_transy_X)[ish][ich]; + xarray[2][ish] = (*chi2_transz_X)[ish][ich]; + xarray[3][ish] = (*chi2_rotx_X)[ish][ich] * 1000; + xarray[4][ish] = (*chi2_roty_X)[ish][ich] * 1000; + if (goodpar[5]) { + xarray[5][ish] = (*chi2_rotz_X)[ish][ich] * 1000; + thisarray[5][ish] = (*chi2_rotz)[ish][ich]; + } + } + fullArrayMap[chamberId] = thisarray; + numTracks[chamberId] = 1; + chamberNames[chamberId] = chambername.str(); + goodParams[chamberId] = goodpar; + xarrayMap[chamberId] = xarray; + } else { + double** thisarray = it->second; + for (int ish = 0; ish < NSHIFTS; ish++) { + if (goodpar[0]) thisarray[0][ish] += (*chi2_transx)[ish][ich]; + thisarray[1][ish] += (*chi2_transy)[ish][ich]; + thisarray[2][ish] += (*chi2_transz)[ish][ich]; + thisarray[3][ish] += (*chi2_rotx)[ish][ich]; + thisarray[4][ish] += (*chi2_roty)[ish][ich]; + if (goodpar[5]) thisarray[5][ish] += (*chi2_rotz)[ish][ich]; + } + numTracks[chamberId] = numTracks[chamberId] + 1; + chamberNames[chamberId] = chambername.str(); + } } - for (int ish=0;ish<NSHIFTS;ish++) { - if (goodpar[0]) { - xarray[0][ish] =(*chi2_transx_X)[ish][ich]; - thisarray[0][ish]=(*chi2_transx) [ish][ich]; - } - thisarray[1][ish]=(*chi2_transy)[ish][ich]; - thisarray[2][ish]=(*chi2_transz)[ish][ich]; - thisarray[3][ish]=(*chi2_rotx) [ish][ich]; - thisarray[4][ish]=(*chi2_roty) [ish][ich]; - xarray[1][ish]=(*chi2_transy_X) [ish][ich]; - xarray[2][ish]=(*chi2_transz_X) [ish][ich]; - xarray[3][ish]=(*chi2_rotx_X) [ish][ich]*1000; - xarray[4][ish]=(*chi2_roty_X) [ish][ich]*1000; - if (goodpar[5]) { - xarray[5][ish]=(*chi2_rotz_X)[ish][ich]*1000; - thisarray[5][ish]=(*chi2_rotz)[ish][ich]; - } - } - fullArrayMap[chamberId]=thisarray; - numTracks[chamberId]=1; - chamberNames[chamberId]=chambername.str(); - goodParams[chamberId]=goodpar; - xarrayMap[chamberId]=xarray; - } - else { - double** thisarray=it->second; - for (int ish=0;ish<NSHIFTS;ish++) { - if (goodpar[0]) thisarray[0][ish]+=(*chi2_transx)[ish][ich]; - thisarray[1][ish]+=(*chi2_transy)[ish][ich]; - thisarray[2][ish]+=(*chi2_transz)[ish][ich]; - thisarray[3][ish]+=(*chi2_rotx) [ish][ich]; - thisarray[4][ish]+=(*chi2_roty) [ish][ich]; - if (goodpar[5]) thisarray[5][ish]+=(*chi2_rotz)[ish][ich]; - } - numTracks[chamberId]=numTracks[chamberId]+1; - chamberNames[chamberId]=chambername.str(); - } + // for (int i=0;i<6;i++) { + // h2MSIDpTVTrackQual[i]->Fill(log10(chi2VAlignParamQuality[i]),msid_ptDiff); + //} } + if (DEBUG) std::cout << "returning from getDataFromTree" << std::endl; - //for (int i=0;i<6;i++) { - //h2MSIDpTVTrackQual[i]->Fill(log10(chi2VAlignParamQuality[i]),msid_ptDiff); - //} - } - if (DEBUG) std::cout<<"returning from getDataFromTree"<<std::endl; - - TCanvas* canv=new TCanvas("canv","canv"); - canv->Divide(3,2); - - /* - for (int i=0;i<6;i++) { - canv->cd(i+1); - h2MSIDpTVTrackQual[i]->Draw("colz"); - h2MSIDpTVTrackQual[i]->GetXaxis()->SetTitle("log(#chi^{2} of #chi^{2} v. align param)"); - h2MSIDpTVTrackQual[i]->GetYaxis()->SetTitle("|1-pT_{ID}/pT_{MS}|"); - } - - stringstream canvname; - canvname<<outputdir<<"/"<<rootname<<"_msidPtVTrackQuality_iter"<<iteration<<".eps"; - canv->Print(canvname.str().c_str()); - */ - - delete canv; - std::cout<<"returning from getDataFromTree"<<std::endl; - return; + TCanvas* canv = new TCanvas("canv", "canv"); + canv->Divide(3, 2); + + /* + for (int i=0;i<6;i++) { + canv->cd(i+1); + h2MSIDpTVTrackQual[i]->Draw("colz"); + h2MSIDpTVTrackQual[i]->GetXaxis()->SetTitle("log(#chi^{2} of #chi^{2} v. align param)"); + h2MSIDpTVTrackQual[i]->GetYaxis()->SetTitle("|1-pT_{ID}/pT_{MS}|"); + } + + stringstream canvname; + canvname<<outputdir<<"/"<<rootname<<"_msidPtVTrackQuality_iter"<<iteration<<".eps"; + canv->Print(canvname.str().c_str()); + */ + + delete canv; + std::cout << "returning from getDataFromTree" << std::endl; + return; } -void getDataFromAlignParTree(TChain* tree, - std::map<long long int,double*>& firstderivMap, - std::map<long long int,double*>& secndderivMap, - std::map<long long int,double*>& initPosMap, - std::map<long long int,double*>& alignParMap, - std::map<long long int,double*>& alignParErrMap) -{ - std::cout<<"getting data from alignPar tree"<<std::endl; - - long long int chamberId; - double init_tras, init_traz, init_trat; - double init_rots, init_rotz, init_rott; - double err_tras, err_traz, err_trat; - double err_rots, err_rotz, err_rott; - double tras, traz, trat; - double rots, rotz, rott; - double firstderiv_tras; - double firstderiv_traz; - double firstderiv_trat; - double firstderiv_rots; - double firstderiv_rotz; - double firstderiv_rott; - double secndderiv_tras; - double secndderiv_traz; - double secndderiv_trat; - double secndderiv_rots; - double secndderiv_rotz; - double secndderiv_rott; - - tree->SetBranchAddress("chamberId", &chamberId); - tree->SetBranchAddress("init_tras", &init_tras); - tree->SetBranchAddress("init_traz", &init_traz); - tree->SetBranchAddress("init_trat", &init_trat); - tree->SetBranchAddress("init_rots", &init_rots); - tree->SetBranchAddress("init_rotz", &init_rotz); - tree->SetBranchAddress("init_rott", &init_rott); - tree->SetBranchAddress("err_tras", &err_tras); - tree->SetBranchAddress("err_traz", &err_traz); - tree->SetBranchAddress("err_trat", &err_trat); - tree->SetBranchAddress("err_rots", &err_rots); - tree->SetBranchAddress("err_rotz", &err_rotz); - tree->SetBranchAddress("err_rott", &err_rott); - tree->SetBranchAddress("delta_tras", &tras); - tree->SetBranchAddress("delta_traz", &traz); - tree->SetBranchAddress("delta_trat", &trat); - tree->SetBranchAddress("delta_rots", &rots); - tree->SetBranchAddress("delta_rotz", &rotz); - tree->SetBranchAddress("delta_rott", &rott); - tree->SetBranchAddress("firstderiv_tras", &firstderiv_tras); - tree->SetBranchAddress("firstderiv_traz", &firstderiv_traz); - tree->SetBranchAddress("firstderiv_trat", &firstderiv_trat); - tree->SetBranchAddress("firstderiv_rots", &firstderiv_rots); - tree->SetBranchAddress("firstderiv_rotz", &firstderiv_rotz); - tree->SetBranchAddress("firstderiv_rott", &firstderiv_rott); - tree->SetBranchAddress("secndderiv_tras", &secndderiv_tras); - tree->SetBranchAddress("secndderiv_traz", &secndderiv_traz); - tree->SetBranchAddress("secndderiv_trat", &secndderiv_trat); - tree->SetBranchAddress("secndderiv_rots", &secndderiv_rots); - tree->SetBranchAddress("secndderiv_rotz", &secndderiv_rotz); - tree->SetBranchAddress("secndderiv_rott", &secndderiv_rott); - - if (DEBUG) std::cout<<tree->GetEntries() - <<" entries in alignPar tree"<<std::endl; - double *firstderivs(0), *secndderivs(0); - double *alignPar(0), *alignParErr(0); - double *initPos(0); - for (int ientry=0;ientry<tree->GetEntries();ientry++) { - - tree->GetEntry(ientry); - - std::map<long long int,double*>::iterator itFirst=firstderivMap.find(chamberId); - - if (itFirst==firstderivMap.end()) { - firstderivs=new double[NPARAMS]; - secndderivs=new double[NPARAMS]; - alignPar =new double[NPARAMS]; - alignParErr=new double[NPARAMS]; - initPos =new double[NPARAMS]; - - alignPar[0]=tras; - alignPar[1]=traz; - alignPar[2]=trat; - alignPar[3]=rots*1000.; - alignPar[4]=rotz*1000.; - alignPar[5]=rott*1000.; - initPos[0]=init_tras; - initPos[1]=init_traz; - initPos[2]=init_trat; - initPos[3]=(init_rots)*1000.; - initPos[4]=(init_rotz)*1000.; - initPos[5]=(init_rott)*1000.; - for (int i=0;i<6;i++) cout<<"initPos["<<i<<"]="<<initPos[i]<<endl; - - alignParErr[0]=sqrt(err_tras); - alignParErr[1]=sqrt(err_traz); - alignParErr[2]=sqrt(err_trat); - alignParErr[3]=sqrt(err_rots)*1000.; - alignParErr[4]=sqrt(err_rotz)*1000.; - alignParErr[5]=sqrt(err_rott)*1000.; - firstderivs[0]=firstderiv_tras*1.; - firstderivs[1]=firstderiv_traz*1.; - firstderivs[2]=firstderiv_trat*1.; - firstderivs[3]=firstderiv_rots*.001; - firstderivs[4]=firstderiv_rotz*.001; - firstderivs[5]=firstderiv_rott*.001; - secndderivs[0]=secndderiv_tras; - secndderivs[1]=secndderiv_traz; - secndderivs[2]=secndderiv_trat; - secndderivs[3]=secndderiv_rots*.000001; - secndderivs[4]=secndderiv_rotz*.000001; - secndderivs[5]=secndderiv_rott*.000001; - if (DEBUG) { - for (int i=0;i<6;i++) - std::cout<<"firstderivs["<<i<<"]="<<firstderivs[i]<<std::endl; - for (int i=0;i<6;i++) - std::cout<<"secndderivs["<<i<<"]="<<secndderivs[i]<<std::endl; - } - - - initPosMap [chamberId]=initPos; - alignParMap [chamberId]=alignPar; - alignParErrMap[chamberId]=alignParErr; - firstderivMap [chamberId]=firstderivs; - secndderivMap [chamberId]=secndderivs; +void getDataFromAlignParTree(TChain* tree, std::map<long long int, double*>& firstderivMap, std::map<long long int, double*>& secndderivMap, + std::map<long long int, double*>& initPosMap, std::map<long long int, double*>& alignParMap, + std::map<long long int, double*>& alignParErrMap) { + std::cout << "getting data from alignPar tree" << std::endl; + + long long int chamberId; + double init_tras, init_traz, init_trat; + double init_rots, init_rotz, init_rott; + double err_tras, err_traz, err_trat; + double err_rots, err_rotz, err_rott; + double tras, traz, trat; + double rots, rotz, rott; + double firstderiv_tras; + double firstderiv_traz; + double firstderiv_trat; + double firstderiv_rots; + double firstderiv_rotz; + double firstderiv_rott; + double secndderiv_tras; + double secndderiv_traz; + double secndderiv_trat; + double secndderiv_rots; + double secndderiv_rotz; + double secndderiv_rott; + + tree->SetBranchAddress("chamberId", &chamberId); + tree->SetBranchAddress("init_tras", &init_tras); + tree->SetBranchAddress("init_traz", &init_traz); + tree->SetBranchAddress("init_trat", &init_trat); + tree->SetBranchAddress("init_rots", &init_rots); + tree->SetBranchAddress("init_rotz", &init_rotz); + tree->SetBranchAddress("init_rott", &init_rott); + tree->SetBranchAddress("err_tras", &err_tras); + tree->SetBranchAddress("err_traz", &err_traz); + tree->SetBranchAddress("err_trat", &err_trat); + tree->SetBranchAddress("err_rots", &err_rots); + tree->SetBranchAddress("err_rotz", &err_rotz); + tree->SetBranchAddress("err_rott", &err_rott); + tree->SetBranchAddress("delta_tras", &tras); + tree->SetBranchAddress("delta_traz", &traz); + tree->SetBranchAddress("delta_trat", &trat); + tree->SetBranchAddress("delta_rots", &rots); + tree->SetBranchAddress("delta_rotz", &rotz); + tree->SetBranchAddress("delta_rott", &rott); + tree->SetBranchAddress("firstderiv_tras", &firstderiv_tras); + tree->SetBranchAddress("firstderiv_traz", &firstderiv_traz); + tree->SetBranchAddress("firstderiv_trat", &firstderiv_trat); + tree->SetBranchAddress("firstderiv_rots", &firstderiv_rots); + tree->SetBranchAddress("firstderiv_rotz", &firstderiv_rotz); + tree->SetBranchAddress("firstderiv_rott", &firstderiv_rott); + tree->SetBranchAddress("secndderiv_tras", &secndderiv_tras); + tree->SetBranchAddress("secndderiv_traz", &secndderiv_traz); + tree->SetBranchAddress("secndderiv_trat", &secndderiv_trat); + tree->SetBranchAddress("secndderiv_rots", &secndderiv_rots); + tree->SetBranchAddress("secndderiv_rotz", &secndderiv_rotz); + tree->SetBranchAddress("secndderiv_rott", &secndderiv_rott); + + if (DEBUG) std::cout << tree->GetEntries() << " entries in alignPar tree" << std::endl; + double *firstderivs(0), *secndderivs(0); + double *alignPar(0), *alignParErr(0); + double* initPos(0); + for (int ientry = 0; ientry < tree->GetEntries(); ientry++) { + tree->GetEntry(ientry); + + std::map<long long int, double*>::iterator itFirst = firstderivMap.find(chamberId); + + if (itFirst == firstderivMap.end()) { + firstderivs = new double[NPARAMS]; + secndderivs = new double[NPARAMS]; + alignPar = new double[NPARAMS]; + alignParErr = new double[NPARAMS]; + initPos = new double[NPARAMS]; + + alignPar[0] = tras; + alignPar[1] = traz; + alignPar[2] = trat; + alignPar[3] = rots * 1000.; + alignPar[4] = rotz * 1000.; + alignPar[5] = rott * 1000.; + initPos[0] = init_tras; + initPos[1] = init_traz; + initPos[2] = init_trat; + initPos[3] = (init_rots)*1000.; + initPos[4] = (init_rotz)*1000.; + initPos[5] = (init_rott)*1000.; + for (int i = 0; i < 6; i++) cout << "initPos[" << i << "]=" << initPos[i] << endl; + + alignParErr[0] = sqrt(err_tras); + alignParErr[1] = sqrt(err_traz); + alignParErr[2] = sqrt(err_trat); + alignParErr[3] = sqrt(err_rots) * 1000.; + alignParErr[4] = sqrt(err_rotz) * 1000.; + alignParErr[5] = sqrt(err_rott) * 1000.; + firstderivs[0] = firstderiv_tras * 1.; + firstderivs[1] = firstderiv_traz * 1.; + firstderivs[2] = firstderiv_trat * 1.; + firstderivs[3] = firstderiv_rots * .001; + firstderivs[4] = firstderiv_rotz * .001; + firstderivs[5] = firstderiv_rott * .001; + secndderivs[0] = secndderiv_tras; + secndderivs[1] = secndderiv_traz; + secndderivs[2] = secndderiv_trat; + secndderivs[3] = secndderiv_rots * .000001; + secndderivs[4] = secndderiv_rotz * .000001; + secndderivs[5] = secndderiv_rott * .000001; + if (DEBUG) { + for (int i = 0; i < 6; i++) std::cout << "firstderivs[" << i << "]=" << firstderivs[i] << std::endl; + for (int i = 0; i < 6; i++) std::cout << "secndderivs[" << i << "]=" << secndderivs[i] << std::endl; + } + + initPosMap[chamberId] = initPos; + alignParMap[chamberId] = alignPar; + alignParErrMap[chamberId] = alignParErr; + firstderivMap[chamberId] = firstderivs; + secndderivMap[chamberId] = secndderivs; + } else { + firstderivs[0] += firstderiv_tras * 1.; + firstderivs[1] += firstderiv_traz * 1.; + firstderivs[2] += firstderiv_trat * 1.; + firstderivs[3] += firstderiv_rots * .001; + firstderivs[4] += firstderiv_rotz * .001; + firstderivs[5] += firstderiv_rott * .001; + secndderivs[0] += secndderiv_tras; + secndderivs[1] += secndderiv_traz; + secndderivs[2] += secndderiv_trat; + secndderivs[3] += secndderiv_rots * .000001; + secndderivs[4] += secndderiv_rotz * .000001; + secndderivs[5] += secndderiv_rott * .000001; + if (DEBUG) { + for (int i = 0; i < 6; i++) std::cout << "firstderivs[" << i << "]=" << firstderivs[i] << std::endl; + for (int i = 0; i < 6; i++) std::cout << "secndderivs[" << i << "]=" << secndderivs[i] << std::endl; + } + } } - else { - firstderivs[0]+=firstderiv_tras*1.; - firstderivs[1]+=firstderiv_traz*1.; - firstderivs[2]+=firstderiv_trat*1.; - firstderivs[3]+=firstderiv_rots*.001; - firstderivs[4]+=firstderiv_rotz*.001; - firstderivs[5]+=firstderiv_rott*.001; - secndderivs[0]+=secndderiv_tras; - secndderivs[1]+=secndderiv_traz; - secndderivs[2]+=secndderiv_trat; - secndderivs[3]+=secndderiv_rots*.000001; - secndderivs[4]+=secndderiv_rotz*.000001; - secndderivs[5]+=secndderiv_rott*.000001; - if (DEBUG) { - for (int i=0;i<6;i++) - std::cout<<"firstderivs["<<i<<"]="<<firstderivs[i]<<std::endl; - for (int i=0;i<6;i++) - std::cout<<"secndderivs["<<i<<"]="<<secndderivs[i]<<std::endl; - } - - } - } - return; + return; } diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/level1Plots_x.cpp b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/level1Plots_x.cpp index e907f125cd971355eb39da4ccbdd6fc75585efbf..5e97ca5c91672e9b6ac35dd3e9c6f8ca514e0463 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/level1Plots_x.cpp +++ b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/level1Plots_x.cpp @@ -2,629 +2,586 @@ Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ -#include "TH1F.h" -#include "TTree.h" -#include "TFile.h" -#include "TCanvas.h" -#include "TStyle.h" -#include "TROOT.h" -#include "TLegend.h" - -#include <sstream> -#include <iostream> #include <stdlib.h> + #include <cmath> +#include <iostream> +#include <sstream> -int main() { +#include "TCanvas.h" +#include "TFile.h" +#include "TH1F.h" +#include "TLegend.h" +#include "TROOT.h" +#include "TStyle.h" +#include "TTree.h" - const int NFILES=3; - int* colors=new int[NFILES]; - colors[0]=kRed; - colors[1]=kBlue; - colors[2]=kGreen; - - TFile** f=new TFile*[NFILES]; - f[0]=new TFile("/afs/cern.ch/user/r/roberth/scratch0/L1_1file_noscat_results/MuonAlign_L1_1file_noscat_iter0.root","READ"); - f[1]=new TFile("/afs/cern.ch/user/r/roberth/scratch0/L1_1file_noscat_results/MuonAlign_L1_1file_noscat_iter1.root","READ"); - f[2]=new TFile("/afs/cern.ch/user/r/roberth/scratch0/L1_1file_noscat_results/MuonAlign_L1_1file_noscat_iter2.root","READ"); - - - TTree** trees=new TTree*[NFILES]; - for (int i=0;i<NFILES;i++) { - trees[i]=(TTree*)f[i]->Get("MuonTrackPreProcessor"); - } - - TH1F** hIDres=new TH1F*[NFILES]; - TH1F** hMSres=new TH1F*[NFILES]; - TH1F** hCalRes=new TH1F*[NFILES]; - TH1F** hIDphiscatres=new TH1F*[NFILES]; - TH1F** hIDthetascatres=new TH1F*[NFILES]; - TH1F** hMSphiscatres=new TH1F*[NFILES]; - TH1F** hMSthetascatres=new TH1F*[NFILES]; - - TH1F** hIDpull=new TH1F*[NFILES]; - TH1F** hMSpull=new TH1F*[NFILES]; - TH1F** hCalPull=new TH1F*[NFILES]; - TH1F** hIDphiscatpull=new TH1F*[NFILES]; - TH1F** hIDthetascatpull=new TH1F*[NFILES]; - TH1F** hMSphiscatpull=new TH1F*[NFILES]; - TH1F** hMSthetascatpull=new TH1F*[NFILES]; - - TH1F** hIDchi2=new TH1F*[NFILES]; - TH1F** hMSchi2=new TH1F*[NFILES]; - TH1F** hCalChi2=new TH1F*[NFILES]; - TH1F** hIDphiscatchi2=new TH1F*[NFILES]; - TH1F** hIDthetascatchi2=new TH1F*[NFILES]; - TH1F** hMSphiscatchi2=new TH1F*[NFILES]; - TH1F** hMSthetascatchi2=new TH1F*[NFILES]; - - TH1F** hTrackChi2=new TH1F*[NFILES]; - TH1F** hMyTrackChi2=new TH1F*[NFILES]; - - int* run =new int[NFILES]; - int* evt =new int[NFILES]; - - double* trackChi2=new double[NFILES]; - int* trackNDoF=new int[NFILES]; - - double* totalTrackChi2=new double[NFILES]; - int * totalTrackNDoF=new int[NFILES]; - - int* nIDres=new int[NFILES]; - double** IDres =new double*[NFILES]; - double** IDerr =new double*[NFILES]; - - int* nIDscatRes =new int[NFILES]; - double** IDscatPhiRes =new double*[NFILES]; - double** IDscatPhiErr =new double*[NFILES]; - double** IDscatThetaRes =new double*[NFILES]; - double** IDscatThetaErr =new double*[NFILES]; - - int* nMSres =new int[NFILES]; - double** MSres =new double*[NFILES]; - double** MSerr =new double*[NFILES]; - int** MSstatLayer =new int*[NFILES]; - int** MSisEndcap =new int*[NFILES]; - - int* nMStrigRes =new int[NFILES]; - double** MStrigRes =new double*[NFILES]; - double** MStrigErr =new double*[NFILES]; - int ** MStrigStatLayer=new int*[NFILES]; - int ** MStrigIsEndcap =new int*[NFILES]; - - int* nMSscatRes =new int[NFILES]; - double** MSscatPhiRes =new double*[NFILES]; - double** MSscatPhiErr =new double*[NFILES]; - double** MSscatThetaRes =new double*[NFILES]; - double** MSscatThetaErr =new double*[NFILES]; - - int* nCalRes =new int[NFILES]; - double** CalRes =new double*[NFILES]; - double** CalErr =new double*[NFILES]; - - for (int i=0;i<NFILES;i++) { - - totalTrackChi2[i]=0.; - totalTrackNDoF[i]=0; - - IDres[i]=new double[100]; - IDerr[i]=new double[100]; - IDscatPhiRes[i]=new double[100]; - IDscatPhiErr[i]=new double[100]; - IDscatThetaRes[i]=new double[100]; - IDscatThetaErr[i]=new double[100]; - MSres[i]=new double[150]; - MSerr[i]=new double[150]; - MSstatLayer[i]=new int[150]; - MSisEndcap[i]=new int[150]; - MStrigRes[i]=new double[50]; - MStrigErr[i]=new double[50]; - MStrigStatLayer[i]=new int[50]; - MStrigIsEndcap[i]=new int[50]; - MSscatPhiRes[i]=new double[100]; - MSscatPhiErr[i]=new double[100]; - MSscatThetaRes[i]=new double[100]; - MSscatThetaErr[i]=new double[100]; - CalRes[i]=new double[10]; - CalErr[i]=new double[10]; - - TTree* t=trees[i]; - t->SetBranchAddress("run", &run[i]); - t->SetBranchAddress("evt", &evt[i]); - - t->SetBranchAddress("trackChi2", &trackChi2[i]); - t->SetBranchAddress("trackNDoF", &trackNDoF[i]); - - t->SetBranchAddress("nIDres", &nIDres[i]); - t->SetBranchAddress("IDres", IDres[i]); - t->SetBranchAddress("IDerr", IDerr[i]); - - t->SetBranchAddress("nIDscatRes", &nIDscatRes[i]); - t->SetBranchAddress("IDscatPhiRes", IDscatPhiRes[i]); - t->SetBranchAddress("IDscatPhiErr", IDscatPhiErr[i]); - t->SetBranchAddress("IDscatThetaRes", IDscatThetaRes[i]); - t->SetBranchAddress("IDscatThetaErr", IDscatThetaErr[i]); - - t->SetBranchAddress("nMSres", &nMSres[i]); - t->SetBranchAddress("MSres", MSres[i]); - t->SetBranchAddress("MSerr", MSerr[i]); - t->SetBranchAddress("MSstatLayer", MSstatLayer[i]); - t->SetBranchAddress("MSisEndcap", MSisEndcap[i]); - - t->SetBranchAddress("nMStrigRes", &nMStrigRes[i]); - t->SetBranchAddress("MStrigRes", MStrigRes[i]); - t->SetBranchAddress("MStrigErr", MStrigErr[i]); - t->SetBranchAddress("MStrigStatLayer", MStrigStatLayer[i]); - t->SetBranchAddress("MStrigIsEndcap", MStrigIsEndcap[i]); - - t->SetBranchAddress("nMSscatRes", &nMSscatRes[i]); - t->SetBranchAddress("MSscatPhiRes", MSscatPhiRes[i]); - t->SetBranchAddress("MSscatPhiErr", MSscatPhiErr[i]); - t->SetBranchAddress("MSscatThetaRes", MSscatThetaRes[i]); - t->SetBranchAddress("MSscatThetaErr", MSscatThetaErr[i]); - - t->SetBranchAddress("nCalRes", &nCalRes[i]); - t->SetBranchAddress("CalRes", CalRes[i]); - t->SetBranchAddress("CalErr", CalErr[i]); - - stringstream ifilestr; ifilestr<<i; - - // ID res - hIDres[i]=new TH1F(("IDres"+ifilestr.str()).c_str(), - "ID res",100,-.2,.2); - hIDres[i]->SetLineColor(colors[i]); - hIDres[i]->GetXaxis()->SetTitle("residuals for ID hits on combined muon track (mm)"); - - // ID pull - hIDpull[i]=new TH1F(("IDpull"+ifilestr.str()).c_str(), - "ID pulls",100,-5.,5.); - hIDpull[i]->SetLineColor(colors[i]); - hIDpull[i]->GetXaxis()->SetTitle("pulls for ID hits on combined muon track"); - - // ID chi2 - hIDchi2[i]=new TH1F(("IDchi2"+ifilestr.str()).c_str(), - //"ID log(chi2)",100,-4.,2.5); - "ID log(chi2)",100,0.,300.); - hIDchi2[i]->SetLineColor(colors[i]); - hIDchi2[i]->GetXaxis()->SetTitle("log_{10}(#chi^{2}) for ID hits on combined muon track"); - - // MS res - hMSres[i]=new TH1F(("MSres"+ifilestr.str()).c_str(), - "MS res",100,-.5,.5); - hMSres[i]->SetLineColor(colors[i]); - hMSres[i]->GetXaxis()->SetTitle("residuals for MS hits on combined muon track (mm)"); - - // MS pull - hMSpull[i]=new TH1F(("MSpull"+ifilestr.str()).c_str(), - "MS pulls",100,-5.,5.); - hMSpull[i]->SetLineColor(colors[i]); - hMSpull[i]->GetXaxis()->SetTitle("pulls for MS hits on combined muon track"); - - // MS chi2 - hMSchi2[i]=new TH1F(("MSchi2"+ifilestr.str()).c_str(), - //"MS log(chi2)",100,-4.,2.5); - "MS log(chi2)",100,0.,300.); - hMSchi2[i]->SetLineColor(colors[i]); - hMSchi2[i]->GetXaxis()->SetTitle("log_{10}(#chi^{2}) for MS hits on combined muon track"); - - // cal eloss - hCalRes[i]=new TH1F(("CalRes"+ifilestr.str()).c_str(), - "calorimeter energy loss",100,-.5,.5); - hCalRes[i]->SetLineColor(colors[i]); - hCalRes[i]->GetXaxis()->SetTitle("calorimeter energy loss for combined muon track"); - - // cal pull - hCalPull[i]=new TH1F(("CalPull"+ifilestr.str()).c_str(), - "calorimeter pulls",100,-5.,5.); - hCalPull[i]->SetLineColor(colors[i]); - hCalPull[i]->GetXaxis()->SetTitle("calorimeter energy loss/expected energy loss for combined muon track"); - - // cal chi2 - hCalChi2[i]=new TH1F(("CalChi2"+ifilestr.str()).c_str(), - //"Cal log(chi2)",100,-4.,2.5); - "Cal log(chi2)",100,0.,300.); - hCalChi2[i]->SetLineColor(colors[i]); - hCalChi2[i]->GetXaxis()->SetTitle("log_{10}(#chi^{2}) for cal. energy loss on combined muon track"); - - // ID phi scat res - hIDphiscatres[i]=new TH1F(("IDphiscatres"+ifilestr.str()).c_str(), - "ID scat. phi res",100,-.005,.005); - hIDphiscatres[i]->SetLineColor(colors[i]); - hIDphiscatres[i]->GetXaxis()->SetTitle("residuals for scat. phi on combined muon track in ID (mrad)"); - - // ID phi scat pull - hIDphiscatpull[i]=new TH1F(("IDphiscatpull"+ifilestr.str()).c_str(), - "ID scat. phi pulls",100,-.00001,.00001); - hIDphiscatpull[i]->SetLineColor(colors[i]); - hIDphiscatpull[i]->GetXaxis()->SetTitle("pulls for scat. phi on combined muon track in ID"); - - // ID phi scat chi2 - hIDphiscatchi2[i]=new TH1F(("IDphiscatchi2"+ifilestr.str()).c_str(), - "ID log(scat.phi chi2)",100,-4.,2.5); - hIDphiscatchi2[i]->SetLineColor(colors[i]); - hIDphiscatchi2[i]->GetXaxis()->SetTitle("log_{10}(#chi^{2}) from scat. phi on combined muon track in ID (mrad)"); - - - // ID theta scat res - hIDthetascatres[i]=new TH1F(("IDthetascatres"+ifilestr.str()).c_str(), - "ID scat. theta res",100,-.005,.005); - hIDthetascatres[i]->SetLineColor(colors[i]); - hIDthetascatres[i]->GetXaxis()->SetTitle("residuals for scat. theta on combined muon track in ID"); - - // ID theta scat pull - hIDthetascatpull[i]=new TH1F(("IDthetascatpull"+ifilestr.str()).c_str(), - "ID scat. theta pulls",100,-.00001,.00001); - hIDthetascatpull[i]->SetLineColor(colors[i]); - hIDthetascatpull[i]->GetXaxis()->SetTitle("pulls for scat. theta on combined muon track in ID (mrad)"); - - // ID theta scat chi2 - hIDthetascatchi2[i]=new TH1F(("IDthetascatchi2"+ifilestr.str()).c_str(), - "ID log (scat.theta chi2)",100,-4.,2.5); - hIDthetascatchi2[i]->SetLineColor(colors[i]); - hIDthetascatchi2[i]->GetXaxis()->SetTitle("log_{10}(#chi^{2}) from scat. theta on combined muon track in ID"); - - // MS phi scat res - hMSphiscatres[i]=new TH1F(("MSphiscatres"+ifilestr.str()).c_str(), - "MS scat. phi res",100,-.005,.005); - hMSphiscatres[i]->SetLineColor(colors[i]); - hMSphiscatres[i]->GetXaxis()->SetTitle("residuals for scat. phi on combined muon track in MS (mrad)"); - - // MS phi scat pull - hMSphiscatpull[i]=new TH1F(("MSphiscatpull"+ifilestr.str()).c_str(), - "MS scat. phi pulls",100,-.00001,.00001); - hMSphiscatpull[i]->SetLineColor(colors[i]); - hMSphiscatpull[i]->GetXaxis()->SetTitle("pulls for scat. phi on combined muon track in MS"); - - // MS phi scat chi2 - hMSphiscatchi2[i]=new TH1F(("MSphiscatchi2"+ifilestr.str()).c_str(), - "MS log(scat.phi chi2)",100,-4.,2.5); - hMSphiscatchi2[i]->SetLineColor(colors[i]); - hMSphiscatchi2[i]->GetXaxis()->SetTitle("log_{10}(#chi^{2}) from scat. phi on combined muon track in MS"); - - // MS theta scat res - hMSthetascatres[i]=new TH1F(("MSthetascatres"+ifilestr.str()).c_str(), - "MS scat. theta res",100,-.02,.02); - hMSthetascatres[i]->SetLineColor(colors[i]); - hMSthetascatres[i]->GetXaxis()->SetTitle("residuals for scat. theta on combined muon track in MS (mrad)"); - - // MS theta scat pull - hMSthetascatpull[i]=new TH1F(("MSthetascatpull"+ifilestr.str()).c_str(), - "MS scat. theta pulls",100,-.001,.001); - hMSthetascatpull[i]->SetLineColor(colors[i]); - hMSthetascatpull[i]->GetXaxis()->SetTitle("pulls for scat. theta on combined muon track in MS"); - - // MS theta scat chi2 - hMSthetascatchi2[i]=new TH1F(("MSthetascatchi2"+ifilestr.str()).c_str(), - "MS log(scat.theta chi2)",100,-4.,2.5); - hMSthetascatchi2[i]->SetLineColor(colors[i]); - hMSthetascatchi2[i]->GetXaxis()->SetTitle("log_{10}(#chi^{2}) from scat. theta on combined muon track in MS"); - - hTrackChi2[i]=new TH1F(("trackChi2"+ifilestr.str()).c_str(), - //"ID log(trackChi2)",100,0.,2.5); - "ID log(trackChi2)",100,0.,300.); - hTrackChi2[i]->SetLineColor(colors[i]); - hTrackChi2[i]->GetXaxis()->SetTitle("log_{10}(#chi^{2}) for combined muon track"); - - hMyTrackChi2[i]=new TH1F(("myTrackChi2"+ifilestr.str()).c_str(), - "ID log(myTrackChi2)",100,0.,2.5); - hMyTrackChi2[i]->SetLineColor(colors[i]); - hMyTrackChi2[i]->GetXaxis()->SetTitle("log_{10}(my #chi^{2}) for combined muon track"); - - - } - - TLegend* leg=new TLegend(.78,.70,.98,.83); - for (int i=0;i<NFILES;i++) { - stringstream iterstr; iterstr<<"iter "<<i; - leg->AddEntry(hIDpull[i],iterstr.str().c_str(),"l"); - } - - int* lastgoodentry=new int[NFILES]; - for (int i=0;i<NFILES;i++) lastgoodentry[i]=0; - - for (int i=0;i<NFILES;i++) { - cout<<"tree "<<i<<" has "<<trees[i]->GetEntries()<<endl; - } - - for (int ientry0=0;ientry0<trees[0]->GetEntries();ientry0++) { - - //cout<<"ientry0: "<<ientry0<<endl; - - trees[0]->GetEntry(ientry0); - - //cout<<endl; - //cout<<"run0 "<<run[0]<<"/evt "<<evt[0]<<endl; - - double idChi20(0.),msChi20(0.),calChi20(0.),idphiscatChi20(0.),idthetascatChi20(0.),msphiscatChi20(0.),msthetascatChi20(0.); - - - int nidres0=nIDres[0]; - int nmsres0=nMSres[0]; - int ncalres0=nCalRes[0]; - int nidscatres0=nIDscatRes[0]; - int nmsscatres0=nMSscatRes[0]; - - double* idres0 =new double[nidres0]; - double* msres0 =new double[nmsres0]; - double* calres0=new double[ncalres0]; - double* idphiscatres0=new double[nidscatres0]; - double* idthetascatres0=new double[nidscatres0]; - double* msphiscatres0=new double[nmsscatres0]; - double* msthetascatres0=new double[nmsscatres0]; - - double* idpull0 =new double[nidres0]; - double* mspull0 =new double[nmsres0]; - double* calpull0=new double[ncalres0]; - double* idphiscatpull0=new double[nidscatres0]; - double* idthetascatpull0=new double[nidscatres0]; - double* msphiscatpull0=new double[nmsscatres0]; - double* msthetascatpull0=new double[nmsscatres0]; - - for (int i=0;i<nIDres[0];i++) { - double pull=IDres[0][i]; - idres0[i]=pull; - hIDres[0]->Fill(pull); - pull/=IDerr[0][i]; - idpull0[i]=pull; - idChi20 += pull*pull; - hIDpull[0]->Fill(pull); - } - for (int i=0;i<nMSres[0];i++) { - double pull=MSres[0][i]; - msres0[i]=pull; - hMSres[0]->Fill(pull); - pull/=MSerr[0][i]; - mspull0[i]=pull; - msChi20 +=pull*pull; - hMSpull[0]->Fill(pull); +int main() { + const int NFILES = 3; + int* colors = new int[NFILES]; + colors[0] = kRed; + colors[1] = kBlue; + colors[2] = kGreen; + + TFile** f = new TFile*[NFILES]; + f[0] = new TFile("/afs/cern.ch/user/r/roberth/scratch0/L1_1file_noscat_results/MuonAlign_L1_1file_noscat_iter0.root", "READ"); + f[1] = new TFile("/afs/cern.ch/user/r/roberth/scratch0/L1_1file_noscat_results/MuonAlign_L1_1file_noscat_iter1.root", "READ"); + f[2] = new TFile("/afs/cern.ch/user/r/roberth/scratch0/L1_1file_noscat_results/MuonAlign_L1_1file_noscat_iter2.root", "READ"); + + TTree** trees = new TTree*[NFILES]; + for (int i = 0; i < NFILES; i++) { trees[i] = (TTree*)f[i]->Get("MuonTrackPreProcessor"); } + + TH1F** hIDres = new TH1F*[NFILES]; + TH1F** hMSres = new TH1F*[NFILES]; + TH1F** hCalRes = new TH1F*[NFILES]; + TH1F** hIDphiscatres = new TH1F*[NFILES]; + TH1F** hIDthetascatres = new TH1F*[NFILES]; + TH1F** hMSphiscatres = new TH1F*[NFILES]; + TH1F** hMSthetascatres = new TH1F*[NFILES]; + + TH1F** hIDpull = new TH1F*[NFILES]; + TH1F** hMSpull = new TH1F*[NFILES]; + TH1F** hCalPull = new TH1F*[NFILES]; + TH1F** hIDphiscatpull = new TH1F*[NFILES]; + TH1F** hIDthetascatpull = new TH1F*[NFILES]; + TH1F** hMSphiscatpull = new TH1F*[NFILES]; + TH1F** hMSthetascatpull = new TH1F*[NFILES]; + + TH1F** hIDchi2 = new TH1F*[NFILES]; + TH1F** hMSchi2 = new TH1F*[NFILES]; + TH1F** hCalChi2 = new TH1F*[NFILES]; + TH1F** hIDphiscatchi2 = new TH1F*[NFILES]; + TH1F** hIDthetascatchi2 = new TH1F*[NFILES]; + TH1F** hMSphiscatchi2 = new TH1F*[NFILES]; + TH1F** hMSthetascatchi2 = new TH1F*[NFILES]; + + TH1F** hTrackChi2 = new TH1F*[NFILES]; + TH1F** hMyTrackChi2 = new TH1F*[NFILES]; + + int* run = new int[NFILES]; + int* evt = new int[NFILES]; + + double* trackChi2 = new double[NFILES]; + int* trackNDoF = new int[NFILES]; + + double* totalTrackChi2 = new double[NFILES]; + int* totalTrackNDoF = new int[NFILES]; + + int* nIDres = new int[NFILES]; + double** IDres = new double*[NFILES]; + double** IDerr = new double*[NFILES]; + + int* nIDscatRes = new int[NFILES]; + double** IDscatPhiRes = new double*[NFILES]; + double** IDscatPhiErr = new double*[NFILES]; + double** IDscatThetaRes = new double*[NFILES]; + double** IDscatThetaErr = new double*[NFILES]; + + int* nMSres = new int[NFILES]; + double** MSres = new double*[NFILES]; + double** MSerr = new double*[NFILES]; + int** MSstatLayer = new int*[NFILES]; + int** MSisEndcap = new int*[NFILES]; + + int* nMStrigRes = new int[NFILES]; + double** MStrigRes = new double*[NFILES]; + double** MStrigErr = new double*[NFILES]; + int** MStrigStatLayer = new int*[NFILES]; + int** MStrigIsEndcap = new int*[NFILES]; + + int* nMSscatRes = new int[NFILES]; + double** MSscatPhiRes = new double*[NFILES]; + double** MSscatPhiErr = new double*[NFILES]; + double** MSscatThetaRes = new double*[NFILES]; + double** MSscatThetaErr = new double*[NFILES]; + + int* nCalRes = new int[NFILES]; + double** CalRes = new double*[NFILES]; + double** CalErr = new double*[NFILES]; + + for (int i = 0; i < NFILES; i++) { + totalTrackChi2[i] = 0.; + totalTrackNDoF[i] = 0; + + IDres[i] = new double[100]; + IDerr[i] = new double[100]; + IDscatPhiRes[i] = new double[100]; + IDscatPhiErr[i] = new double[100]; + IDscatThetaRes[i] = new double[100]; + IDscatThetaErr[i] = new double[100]; + MSres[i] = new double[150]; + MSerr[i] = new double[150]; + MSstatLayer[i] = new int[150]; + MSisEndcap[i] = new int[150]; + MStrigRes[i] = new double[50]; + MStrigErr[i] = new double[50]; + MStrigStatLayer[i] = new int[50]; + MStrigIsEndcap[i] = new int[50]; + MSscatPhiRes[i] = new double[100]; + MSscatPhiErr[i] = new double[100]; + MSscatThetaRes[i] = new double[100]; + MSscatThetaErr[i] = new double[100]; + CalRes[i] = new double[10]; + CalErr[i] = new double[10]; + + TTree* t = trees[i]; + t->SetBranchAddress("run", &run[i]); + t->SetBranchAddress("evt", &evt[i]); + + t->SetBranchAddress("trackChi2", &trackChi2[i]); + t->SetBranchAddress("trackNDoF", &trackNDoF[i]); + + t->SetBranchAddress("nIDres", &nIDres[i]); + t->SetBranchAddress("IDres", IDres[i]); + t->SetBranchAddress("IDerr", IDerr[i]); + + t->SetBranchAddress("nIDscatRes", &nIDscatRes[i]); + t->SetBranchAddress("IDscatPhiRes", IDscatPhiRes[i]); + t->SetBranchAddress("IDscatPhiErr", IDscatPhiErr[i]); + t->SetBranchAddress("IDscatThetaRes", IDscatThetaRes[i]); + t->SetBranchAddress("IDscatThetaErr", IDscatThetaErr[i]); + + t->SetBranchAddress("nMSres", &nMSres[i]); + t->SetBranchAddress("MSres", MSres[i]); + t->SetBranchAddress("MSerr", MSerr[i]); + t->SetBranchAddress("MSstatLayer", MSstatLayer[i]); + t->SetBranchAddress("MSisEndcap", MSisEndcap[i]); + + t->SetBranchAddress("nMStrigRes", &nMStrigRes[i]); + t->SetBranchAddress("MStrigRes", MStrigRes[i]); + t->SetBranchAddress("MStrigErr", MStrigErr[i]); + t->SetBranchAddress("MStrigStatLayer", MStrigStatLayer[i]); + t->SetBranchAddress("MStrigIsEndcap", MStrigIsEndcap[i]); + + t->SetBranchAddress("nMSscatRes", &nMSscatRes[i]); + t->SetBranchAddress("MSscatPhiRes", MSscatPhiRes[i]); + t->SetBranchAddress("MSscatPhiErr", MSscatPhiErr[i]); + t->SetBranchAddress("MSscatThetaRes", MSscatThetaRes[i]); + t->SetBranchAddress("MSscatThetaErr", MSscatThetaErr[i]); + + t->SetBranchAddress("nCalRes", &nCalRes[i]); + t->SetBranchAddress("CalRes", CalRes[i]); + t->SetBranchAddress("CalErr", CalErr[i]); + + stringstream ifilestr; + ifilestr << i; + + // ID res + hIDres[i] = new TH1F(("IDres" + ifilestr.str()).c_str(), "ID res", 100, -.2, .2); + hIDres[i]->SetLineColor(colors[i]); + hIDres[i]->GetXaxis()->SetTitle("residuals for ID hits on combined muon track (mm)"); + + // ID pull + hIDpull[i] = new TH1F(("IDpull" + ifilestr.str()).c_str(), "ID pulls", 100, -5., 5.); + hIDpull[i]->SetLineColor(colors[i]); + hIDpull[i]->GetXaxis()->SetTitle("pulls for ID hits on combined muon track"); + + // ID chi2 + hIDchi2[i] = new TH1F(("IDchi2" + ifilestr.str()).c_str(), + //"ID log(chi2)",100,-4.,2.5); + "ID log(chi2)", 100, 0., 300.); + hIDchi2[i]->SetLineColor(colors[i]); + hIDchi2[i]->GetXaxis()->SetTitle("log_{10}(#chi^{2}) for ID hits on combined muon track"); + + // MS res + hMSres[i] = new TH1F(("MSres" + ifilestr.str()).c_str(), "MS res", 100, -.5, .5); + hMSres[i]->SetLineColor(colors[i]); + hMSres[i]->GetXaxis()->SetTitle("residuals for MS hits on combined muon track (mm)"); + + // MS pull + hMSpull[i] = new TH1F(("MSpull" + ifilestr.str()).c_str(), "MS pulls", 100, -5., 5.); + hMSpull[i]->SetLineColor(colors[i]); + hMSpull[i]->GetXaxis()->SetTitle("pulls for MS hits on combined muon track"); + + // MS chi2 + hMSchi2[i] = new TH1F(("MSchi2" + ifilestr.str()).c_str(), + //"MS log(chi2)",100,-4.,2.5); + "MS log(chi2)", 100, 0., 300.); + hMSchi2[i]->SetLineColor(colors[i]); + hMSchi2[i]->GetXaxis()->SetTitle("log_{10}(#chi^{2}) for MS hits on combined muon track"); + + // cal eloss + hCalRes[i] = new TH1F(("CalRes" + ifilestr.str()).c_str(), "calorimeter energy loss", 100, -.5, .5); + hCalRes[i]->SetLineColor(colors[i]); + hCalRes[i]->GetXaxis()->SetTitle("calorimeter energy loss for combined muon track"); + + // cal pull + hCalPull[i] = new TH1F(("CalPull" + ifilestr.str()).c_str(), "calorimeter pulls", 100, -5., 5.); + hCalPull[i]->SetLineColor(colors[i]); + hCalPull[i]->GetXaxis()->SetTitle("calorimeter energy loss/expected energy loss for combined muon track"); + + // cal chi2 + hCalChi2[i] = new TH1F(("CalChi2" + ifilestr.str()).c_str(), + //"Cal log(chi2)",100,-4.,2.5); + "Cal log(chi2)", 100, 0., 300.); + hCalChi2[i]->SetLineColor(colors[i]); + hCalChi2[i]->GetXaxis()->SetTitle("log_{10}(#chi^{2}) for cal. energy loss on combined muon track"); + + // ID phi scat res + hIDphiscatres[i] = new TH1F(("IDphiscatres" + ifilestr.str()).c_str(), "ID scat. phi res", 100, -.005, .005); + hIDphiscatres[i]->SetLineColor(colors[i]); + hIDphiscatres[i]->GetXaxis()->SetTitle("residuals for scat. phi on combined muon track in ID (mrad)"); + + // ID phi scat pull + hIDphiscatpull[i] = new TH1F(("IDphiscatpull" + ifilestr.str()).c_str(), "ID scat. phi pulls", 100, -.00001, .00001); + hIDphiscatpull[i]->SetLineColor(colors[i]); + hIDphiscatpull[i]->GetXaxis()->SetTitle("pulls for scat. phi on combined muon track in ID"); + + // ID phi scat chi2 + hIDphiscatchi2[i] = new TH1F(("IDphiscatchi2" + ifilestr.str()).c_str(), "ID log(scat.phi chi2)", 100, -4., 2.5); + hIDphiscatchi2[i]->SetLineColor(colors[i]); + hIDphiscatchi2[i]->GetXaxis()->SetTitle("log_{10}(#chi^{2}) from scat. phi on combined muon track in ID (mrad)"); + + // ID theta scat res + hIDthetascatres[i] = new TH1F(("IDthetascatres" + ifilestr.str()).c_str(), "ID scat. theta res", 100, -.005, .005); + hIDthetascatres[i]->SetLineColor(colors[i]); + hIDthetascatres[i]->GetXaxis()->SetTitle("residuals for scat. theta on combined muon track in ID"); + + // ID theta scat pull + hIDthetascatpull[i] = new TH1F(("IDthetascatpull" + ifilestr.str()).c_str(), "ID scat. theta pulls", 100, -.00001, .00001); + hIDthetascatpull[i]->SetLineColor(colors[i]); + hIDthetascatpull[i]->GetXaxis()->SetTitle("pulls for scat. theta on combined muon track in ID (mrad)"); + + // ID theta scat chi2 + hIDthetascatchi2[i] = new TH1F(("IDthetascatchi2" + ifilestr.str()).c_str(), "ID log (scat.theta chi2)", 100, -4., 2.5); + hIDthetascatchi2[i]->SetLineColor(colors[i]); + hIDthetascatchi2[i]->GetXaxis()->SetTitle("log_{10}(#chi^{2}) from scat. theta on combined muon track in ID"); + + // MS phi scat res + hMSphiscatres[i] = new TH1F(("MSphiscatres" + ifilestr.str()).c_str(), "MS scat. phi res", 100, -.005, .005); + hMSphiscatres[i]->SetLineColor(colors[i]); + hMSphiscatres[i]->GetXaxis()->SetTitle("residuals for scat. phi on combined muon track in MS (mrad)"); + + // MS phi scat pull + hMSphiscatpull[i] = new TH1F(("MSphiscatpull" + ifilestr.str()).c_str(), "MS scat. phi pulls", 100, -.00001, .00001); + hMSphiscatpull[i]->SetLineColor(colors[i]); + hMSphiscatpull[i]->GetXaxis()->SetTitle("pulls for scat. phi on combined muon track in MS"); + + // MS phi scat chi2 + hMSphiscatchi2[i] = new TH1F(("MSphiscatchi2" + ifilestr.str()).c_str(), "MS log(scat.phi chi2)", 100, -4., 2.5); + hMSphiscatchi2[i]->SetLineColor(colors[i]); + hMSphiscatchi2[i]->GetXaxis()->SetTitle("log_{10}(#chi^{2}) from scat. phi on combined muon track in MS"); + + // MS theta scat res + hMSthetascatres[i] = new TH1F(("MSthetascatres" + ifilestr.str()).c_str(), "MS scat. theta res", 100, -.02, .02); + hMSthetascatres[i]->SetLineColor(colors[i]); + hMSthetascatres[i]->GetXaxis()->SetTitle("residuals for scat. theta on combined muon track in MS (mrad)"); + + // MS theta scat pull + hMSthetascatpull[i] = new TH1F(("MSthetascatpull" + ifilestr.str()).c_str(), "MS scat. theta pulls", 100, -.001, .001); + hMSthetascatpull[i]->SetLineColor(colors[i]); + hMSthetascatpull[i]->GetXaxis()->SetTitle("pulls for scat. theta on combined muon track in MS"); + + // MS theta scat chi2 + hMSthetascatchi2[i] = new TH1F(("MSthetascatchi2" + ifilestr.str()).c_str(), "MS log(scat.theta chi2)", 100, -4., 2.5); + hMSthetascatchi2[i]->SetLineColor(colors[i]); + hMSthetascatchi2[i]->GetXaxis()->SetTitle("log_{10}(#chi^{2}) from scat. theta on combined muon track in MS"); + + hTrackChi2[i] = new TH1F(("trackChi2" + ifilestr.str()).c_str(), + //"ID log(trackChi2)",100,0.,2.5); + "ID log(trackChi2)", 100, 0., 300.); + hTrackChi2[i]->SetLineColor(colors[i]); + hTrackChi2[i]->GetXaxis()->SetTitle("log_{10}(#chi^{2}) for combined muon track"); + + hMyTrackChi2[i] = new TH1F(("myTrackChi2" + ifilestr.str()).c_str(), "ID log(myTrackChi2)", 100, 0., 2.5); + hMyTrackChi2[i]->SetLineColor(colors[i]); + hMyTrackChi2[i]->GetXaxis()->SetTitle("log_{10}(my #chi^{2}) for combined muon track"); } - for (int i=0;i<nCalRes[0];i++) { - double pull=CalRes[0][i]; - calres0[i]=pull; - hCalRes[0]->Fill(pull); - pull/=CalErr[0][i]; - calpull0[i]=pull; - calChi20+=pull*pull; - hCalPull[0]->Fill(pull); + + TLegend* leg = new TLegend(.78, .70, .98, .83); + for (int i = 0; i < NFILES; i++) { + stringstream iterstr; + iterstr << "iter " << i; + leg->AddEntry(hIDpull[i], iterstr.str().c_str(), "l"); } - for (int i=0;i<nIDscatRes[0];i++) { - double pull=IDscatPhiRes[0][i]; - idphiscatres0[i]=pull; - hIDphiscatres[0]->Fill(1000.*pull); - pull/=IDscatPhiErr[0][i]; - idphiscatpull0[i]=pull; - idphiscatChi20 += pull*pull; - hIDphiscatpull[0]->Fill(pull); - - pull=IDscatThetaRes[0][i]; - idthetascatres0[i]=pull; - hIDthetascatres[0]->Fill(1000.*pull); - pull/=IDscatThetaErr[0][i]; - idthetascatpull0[i]=pull; - idthetascatChi20 += pull*pull; - hIDthetascatpull[0]->Fill(pull); + + int* lastgoodentry = new int[NFILES]; + for (int i = 0; i < NFILES; i++) lastgoodentry[i] = 0; + + for (int i = 0; i < NFILES; i++) { cout << "tree " << i << " has " << trees[i]->GetEntries() << endl; } + + for (int ientry0 = 0; ientry0 < trees[0]->GetEntries(); ientry0++) { + // cout<<"ientry0: "<<ientry0<<endl; + + trees[0]->GetEntry(ientry0); + + // cout<<endl; + // cout<<"run0 "<<run[0]<<"/evt "<<evt[0]<<endl; + + double idChi20(0.), msChi20(0.), calChi20(0.), idphiscatChi20(0.), idthetascatChi20(0.), msphiscatChi20(0.), msthetascatChi20(0.); + + int nidres0 = nIDres[0]; + int nmsres0 = nMSres[0]; + int ncalres0 = nCalRes[0]; + int nidscatres0 = nIDscatRes[0]; + int nmsscatres0 = nMSscatRes[0]; + + double* idres0 = new double[nidres0]; + double* msres0 = new double[nmsres0]; + double* calres0 = new double[ncalres0]; + double* idphiscatres0 = new double[nidscatres0]; + double* idthetascatres0 = new double[nidscatres0]; + double* msphiscatres0 = new double[nmsscatres0]; + double* msthetascatres0 = new double[nmsscatres0]; + + double* idpull0 = new double[nidres0]; + double* mspull0 = new double[nmsres0]; + double* calpull0 = new double[ncalres0]; + double* idphiscatpull0 = new double[nidscatres0]; + double* idthetascatpull0 = new double[nidscatres0]; + double* msphiscatpull0 = new double[nmsscatres0]; + double* msthetascatpull0 = new double[nmsscatres0]; + + for (int i = 0; i < nIDres[0]; i++) { + double pull = IDres[0][i]; + idres0[i] = pull; + hIDres[0]->Fill(pull); + pull /= IDerr[0][i]; + idpull0[i] = pull; + idChi20 += pull * pull; + hIDpull[0]->Fill(pull); + } + for (int i = 0; i < nMSres[0]; i++) { + double pull = MSres[0][i]; + msres0[i] = pull; + hMSres[0]->Fill(pull); + pull /= MSerr[0][i]; + mspull0[i] = pull; + msChi20 += pull * pull; + hMSpull[0]->Fill(pull); + } + for (int i = 0; i < nCalRes[0]; i++) { + double pull = CalRes[0][i]; + calres0[i] = pull; + hCalRes[0]->Fill(pull); + pull /= CalErr[0][i]; + calpull0[i] = pull; + calChi20 += pull * pull; + hCalPull[0]->Fill(pull); + } + for (int i = 0; i < nIDscatRes[0]; i++) { + double pull = IDscatPhiRes[0][i]; + idphiscatres0[i] = pull; + hIDphiscatres[0]->Fill(1000. * pull); + pull /= IDscatPhiErr[0][i]; + idphiscatpull0[i] = pull; + idphiscatChi20 += pull * pull; + hIDphiscatpull[0]->Fill(pull); + + pull = IDscatThetaRes[0][i]; + idthetascatres0[i] = pull; + hIDthetascatres[0]->Fill(1000. * pull); + pull /= IDscatThetaErr[0][i]; + idthetascatpull0[i] = pull; + idthetascatChi20 += pull * pull; + hIDthetascatpull[0]->Fill(pull); + } + for (int i = 0; i < nMSscatRes[0]; i++) { + double pull = MSscatPhiRes[0][i]; + msphiscatres0[i] = pull; + hMSphiscatres[0]->Fill(1000. * pull); + pull /= MSscatPhiErr[0][i]; + msphiscatpull0[i] = pull; + msphiscatChi20 += pull * pull; + hMSphiscatpull[0]->Fill(pull); + + pull = MSscatThetaRes[0][i]; + msthetascatres0[i] = pull; + hMSthetascatres[0]->Fill(1000. * pull); + pull /= MSscatThetaErr[0][i]; + msthetascatpull0[i] = pull; + msthetascatChi20 += pull * pull; + hMSthetascatpull[0]->Fill(pull); + } + + // hIDchi2[0]->Fill(std::log10(idChi20));//(double)nidres0)); + // hMSchi2[0]->Fill(std::log10(msChi20));///(double)nmsres0)); + // hCalChi2[0]->Fill(std::log10(calChi20));///(double)ncalres0)); + + hIDchi2[0]->Fill(idChi20); //(double)nidres0)); + hMSchi2[0]->Fill(msChi20); ///(double)nmsres0)); + hCalChi2[0]->Fill(calChi20); ///(double)ncalres0)); + + hIDphiscatchi2[0]->Fill(std::log10(idphiscatChi20)); ///(double)nidscatres0)); + hIDthetascatchi2[0]->Fill(std::log10(idthetascatChi20)); ///(double)nidscatres0)); + hMSphiscatchi2[0]->Fill(std::log10(msphiscatChi20)); ///(double)nmsscatres0)); + hMSthetascatchi2[0]->Fill(std::log10(msthetascatChi20)); ///(double)nmsscatres0)); + + // hTrackChi2[0]->Fill(std::log10(trackChi2[0]*(double)trackNDoF[0])); + hTrackChi2[0]->Fill(trackChi2[0] * (double)trackNDoF[0]); + double myChi2 = idChi20 + msChi20 + calChi20 + idphiscatChi20 + idthetascatChi20 + msphiscatChi20 + msthetascatChi20; + hMyTrackChi2[0]->Fill(std::log10(myChi2)); + // cout<<"delta chi2(0): "<<trackChi2[0]*(double)trackNDoF[0]-myChi2<<endl; + totalTrackChi2[0] += trackChi2[0]; + totalTrackNDoF[0] += trackNDoF[0]; + + for (int ifile = 1; ifile < NFILES; ifile++) { + for (int ientry = lastgoodentry[ifile]; ientry < trees[ifile]->GetEntries(); ientry++) { + trees[ifile]->GetEntry(ientry); + + // check matching run/evt + if (run[ifile] != run[0] || evt[ifile] != evt[0]) { continue; } + lastgoodentry[ifile] = ientry; + + // get residuals and add chi2 + double idChi2(0.), msChi2(0.), calChi2(0.), idphiscatChi2(0.), msphiscatChi2(0.), idthetascatChi2(0.), msthetascatChi2(0.); + + for (int i = 0; i < nIDres[ifile]; i++) { + double pull = IDres[ifile][i]; + hIDres[ifile]->Fill(pull); + pull /= IDerr[ifile][i]; + idChi2 += pull * pull; + hIDpull[ifile]->Fill(pull); + } + for (int i = 0; i < nMSres[ifile]; i++) { + double pull = MSres[ifile][i]; + hMSres[ifile]->Fill(pull); + pull /= MSerr[ifile][i]; + msChi2 += pull * pull; + hMSpull[ifile]->Fill(pull); + } + for (int i = 0; i < nCalRes[ifile]; i++) { + double pull = CalRes[ifile][i]; + hCalRes[ifile]->Fill(pull); + pull /= CalErr[ifile][i]; + calChi2 += pull * pull; + hCalPull[ifile]->Fill(pull); + } + for (int i = 0; i < nIDscatRes[ifile]; i++) { + double pull = IDscatPhiRes[ifile][i]; + hIDphiscatres[ifile]->Fill(1000. * pull); + pull /= IDscatPhiErr[ifile][i]; + idphiscatChi2 += pull * pull; + hIDphiscatpull[ifile]->Fill(pull); + + pull = IDscatThetaRes[ifile][i]; + hIDthetascatres[ifile]->Fill(1000. * pull); + pull /= IDscatThetaErr[ifile][i]; + idthetascatChi2 += pull * pull; + hIDthetascatpull[ifile]->Fill(pull); + } + for (int i = 0; i < nMSscatRes[ifile]; i++) { + double pull = MSscatPhiRes[ifile][i]; + hMSphiscatres[ifile]->Fill(1000. * pull); + pull /= MSscatPhiErr[ifile][i]; + msphiscatChi2 += pull * pull; + hMSphiscatpull[ifile]->Fill(pull); + + pull = MSscatThetaRes[ifile][i]; + hMSthetascatres[ifile]->Fill(1000. * pull); + pull /= MSscatThetaErr[ifile][i]; + msthetascatChi2 += pull * pull; + hMSthetascatpull[ifile]->Fill(pull); + } + + // hIDchi2[ifile]->Fill(std::log10(idChi2));///(double)nIDres[ifile])); + // hMSchi2[ifile]->Fill(std::log10(msChi2));///(double)nMSres[ifile])); + // hCalChi2[ifile]->Fill(std::log10(calChi2));///(double)nCalRes[ifile])); + + hIDchi2[ifile]->Fill(idChi2); ///(double)nIDres[ifile])); + hMSchi2[ifile]->Fill(msChi2); ///(double)nMSres[ifile])); + hCalChi2[ifile]->Fill(calChi2); ///(double)nCalRes[ifile])); + + hIDphiscatchi2[ifile]->Fill(std::log10(idphiscatChi2)); ///(double)nIDscatRes[ifile])); + hIDthetascatchi2[ifile]->Fill(std::log10(idthetascatChi2)); ///(double)nIDscatRes[ifile])); + hMSphiscatchi2[ifile]->Fill(std::log10(msphiscatChi2)); ///(double)nMSscatRes[ifile])); + hMSthetascatchi2[ifile]->Fill(std::log10(msthetascatChi2)); ///(double)nMSscatRes[ifile])); + + // hTrackChi2[ifile]->Fill(std::log10(trackChi2[ifile]*(double)trackNDoF[ifile])); + hTrackChi2[ifile]->Fill(trackChi2[ifile] * (double)trackNDoF[ifile]); + + double myChi2 = idChi2 + msChi2 + calChi2 + idphiscatChi2 + idthetascatChi2 + msphiscatChi2 + msthetascatChi2; + hMyTrackChi2[ifile]->Fill(std::log10(myChi2)); + + totalTrackChi2[ifile] += trackChi2[ifile]; + totalTrackNDoF[ifile] += trackNDoF[ifile]; + + // cout<<"delta chi2: "<<trackChi2[ifile]*(double)trackNDoF[ifile]-myChi2<<endl; + + break; + } + } + delete[] idthetascatpull0; + delete[] msthetascatpull0; + delete[] idphiscatpull0; + delete[] msphiscatpull0; + delete[] calpull0; + delete[] idpull0; + delete[] mspull0; + delete[] idthetascatres0; + delete[] msthetascatres0; + delete[] idphiscatres0; + delete[] msphiscatres0; + delete[] calres0; + delete[] idres0; + delete[] msres0; } - for (int i=0;i<nMSscatRes[0];i++) { - double pull=MSscatPhiRes[0][i]; - msphiscatres0[i]=pull; - hMSphiscatres[0]->Fill(1000.*pull); - pull/=MSscatPhiErr[0][i]; - msphiscatpull0[i]=pull; - msphiscatChi20 += pull*pull; - hMSphiscatpull[0]->Fill(pull); - - pull=MSscatThetaRes[0][i]; - msthetascatres0[i]=pull; - hMSthetascatres[0]->Fill(1000.*pull); - pull/=MSscatThetaErr[0][i]; - msthetascatpull0[i]=pull; - msthetascatChi20 += pull*pull; - hMSthetascatpull[0]->Fill(pull); + + for (int i = 0; i < NFILES; i++) + std::cout << "total track chi2 [" << i << "]=" << totalTrackChi2[i] / (double)totalTrackNDoF[i] << endl; + + // gStyle->SetOptStat("111111"); + + TCanvas* canv = new TCanvas("canv", "canv"); + canv->SetFillColor(10); + + const int NHISTS = 21; + TH1F** hists[NHISTS] = {hIDchi2, hIDres, hIDpull, hIDphiscatchi2, hIDphiscatres, hIDphiscatpull, + hIDthetascatchi2, hIDthetascatres, hIDthetascatpull, hCalChi2, hCalRes, hCalPull, + hMSchi2, hMSres, hMSpull, hMSphiscatchi2, hMSphiscatres, hMSphiscatpull, + hMSthetascatchi2, hMSthetascatres, hMSthetascatpull}; + + // ID measurement chi2 + int ipad = 0; + canv->Divide(3, 4); + + for (int ihist = 0; ihist < NHISTS; ihist++) { + canv->cd(++ipad); + double max(0.); + for (int ifile = 0; ifile < NFILES; ifile++) { + double thismax = hists[ihist][ifile]->GetMaximum(); + if (thismax > max) max = thismax; + } + hists[ihist][0]->SetMaximum(max * 1.2); + hists[ihist][0]->Draw(); + for (int ifile = 1; ifile < NFILES; ifile++) hists[ihist][ifile]->Draw("same"); + leg->Draw(); + + if (ihist == 11) { + canv->Print("level1hists_ID.eps"); + ipad = 0; + canv->Clear(); + canv->Divide(3, 4); + } } - - //hIDchi2[0]->Fill(std::log10(idChi20));//(double)nidres0)); - //hMSchi2[0]->Fill(std::log10(msChi20));///(double)nmsres0)); - //hCalChi2[0]->Fill(std::log10(calChi20));///(double)ncalres0)); - - hIDchi2[0]->Fill(idChi20);//(double)nidres0)); - hMSchi2[0]->Fill(msChi20);///(double)nmsres0)); - hCalChi2[0]->Fill(calChi20);///(double)ncalres0)); - - hIDphiscatchi2[0]->Fill(std::log10(idphiscatChi20));///(double)nidscatres0)); - hIDthetascatchi2[0]->Fill(std::log10(idthetascatChi20));///(double)nidscatres0)); - hMSphiscatchi2[0]->Fill(std::log10(msphiscatChi20));///(double)nmsscatres0)); - hMSthetascatchi2[0]->Fill(std::log10(msthetascatChi20));///(double)nmsscatres0)); - - //hTrackChi2[0]->Fill(std::log10(trackChi2[0]*(double)trackNDoF[0])); - hTrackChi2[0]->Fill(trackChi2[0]*(double)trackNDoF[0]); - double myChi2=idChi20+msChi20+calChi20+ - idphiscatChi20+idthetascatChi20+ - msphiscatChi20+msthetascatChi20; - hMyTrackChi2[0]->Fill(std::log10(myChi2)); - //cout<<"delta chi2(0): "<<trackChi2[0]*(double)trackNDoF[0]-myChi2<<endl; - totalTrackChi2[0]+=trackChi2[0]; - totalTrackNDoF[0]+=trackNDoF[0]; - - for (int ifile=1;ifile<NFILES;ifile++) { - - for (int ientry=lastgoodentry[ifile];ientry<trees[ifile]->GetEntries();ientry++) { - - trees[ifile]->GetEntry(ientry); - - // check matching run/evt - if (run[ifile]!=run[0] || evt[ifile]!=evt[0]) { - continue; - } - lastgoodentry[ifile]=ientry; - - // get residuals and add chi2 - double idChi2(0.),msChi2(0.),calChi2(0.), - idphiscatChi2(0.),msphiscatChi2(0.), - idthetascatChi2(0.),msthetascatChi2(0.); - - for (int i=0;i<nIDres[ifile];i++) { - double pull=IDres[ifile][i]; - hIDres[ifile]->Fill(pull); - pull/=IDerr[ifile][i]; - idChi2 += pull*pull; - hIDpull[ifile]->Fill(pull); - } - for (int i=0;i<nMSres[ifile];i++) { - double pull=MSres[ifile][i]; - hMSres[ifile]->Fill(pull); - pull/=MSerr[ifile][i]; - msChi2 += pull*pull; - hMSpull[ifile]->Fill(pull); - } - for (int i=0;i<nCalRes[ifile];i++) { - double pull=CalRes[ifile][i]; - hCalRes[ifile]->Fill(pull); - pull/=CalErr[ifile][i]; - calChi2+= pull*pull; - hCalPull[ifile]->Fill(pull); - } - for (int i=0;i<nIDscatRes[ifile];i++) { - double pull=IDscatPhiRes[ifile][i]; - hIDphiscatres[ifile]->Fill(1000.*pull); - pull/=IDscatPhiErr[ifile][i]; - idphiscatChi2 += pull*pull; - hIDphiscatpull[ifile]->Fill(pull); - - pull=IDscatThetaRes[ifile][i]; - hIDthetascatres[ifile]->Fill(1000.*pull); - pull/=IDscatThetaErr[ifile][i]; - idthetascatChi2 += pull*pull; - hIDthetascatpull[ifile]->Fill(pull); - } - for (int i=0;i<nMSscatRes[ifile];i++) { - double pull=MSscatPhiRes[ifile][i]; - hMSphiscatres[ifile]->Fill(1000.*pull); - pull/=MSscatPhiErr[ifile][i]; - msphiscatChi2 += pull*pull; - hMSphiscatpull[ifile]->Fill(pull); - - pull=MSscatThetaRes[ifile][i]; - hMSthetascatres[ifile]->Fill(1000.*pull); - pull/=MSscatThetaErr[ifile][i]; - msthetascatChi2 += pull*pull; - hMSthetascatpull[ifile]->Fill(pull); - } - - //hIDchi2[ifile]->Fill(std::log10(idChi2));///(double)nIDres[ifile])); - //hMSchi2[ifile]->Fill(std::log10(msChi2));///(double)nMSres[ifile])); - //hCalChi2[ifile]->Fill(std::log10(calChi2));///(double)nCalRes[ifile])); - - hIDchi2[ifile]->Fill(idChi2);///(double)nIDres[ifile])); - hMSchi2[ifile]->Fill(msChi2);///(double)nMSres[ifile])); - hCalChi2[ifile]->Fill(calChi2);///(double)nCalRes[ifile])); - - hIDphiscatchi2[ifile]->Fill(std::log10(idphiscatChi2));///(double)nIDscatRes[ifile])); - hIDthetascatchi2[ifile]->Fill(std::log10(idthetascatChi2));///(double)nIDscatRes[ifile])); - hMSphiscatchi2[ifile]->Fill(std::log10(msphiscatChi2));///(double)nMSscatRes[ifile])); - hMSthetascatchi2[ifile]->Fill(std::log10(msthetascatChi2));///(double)nMSscatRes[ifile])); - - //hTrackChi2[ifile]->Fill(std::log10(trackChi2[ifile]*(double)trackNDoF[ifile])); - hTrackChi2[ifile]->Fill(trackChi2[ifile]*(double)trackNDoF[ifile]); - - double myChi2=idChi2+msChi2+calChi2+ - idphiscatChi2+idthetascatChi2+ - msphiscatChi2+msthetascatChi2; - hMyTrackChi2[ifile]->Fill(std::log10(myChi2)); - - totalTrackChi2[ifile]+=trackChi2[ifile]; - totalTrackNDoF[ifile]+=trackNDoF[ifile]; - - //cout<<"delta chi2: "<<trackChi2[ifile]*(double)trackNDoF[ifile]-myChi2<<endl; - - break; - } + + canv->cd(++ipad); + double max = 0.; + for (int ifile = 0; ifile < NFILES; ifile++) { + double thismax = hTrackChi2[ifile]->GetMaximum(); + if (thismax > max) max = thismax; } - delete [] idthetascatpull0; - delete [] msthetascatpull0; - delete [] idphiscatpull0; - delete [] msphiscatpull0; - delete [] calpull0; - delete [] idpull0; - delete [] mspull0; - delete [] idthetascatres0; - delete [] msthetascatres0; - delete [] idphiscatres0; - delete [] msphiscatres0; - delete [] calres0; - delete [] idres0; - delete [] msres0; - - } - - for (int i=0;i<NFILES;i++) std::cout<<"total track chi2 ["<<i<<"]="<<totalTrackChi2[i]/(double)totalTrackNDoF[i]<<endl; - - //gStyle->SetOptStat("111111"); - - TCanvas* canv=new TCanvas("canv","canv"); - canv->SetFillColor(10); - - const int NHISTS=21; - TH1F** hists[NHISTS]={hIDchi2, hIDres, hIDpull, - hIDphiscatchi2, hIDphiscatres, hIDphiscatpull, - hIDthetascatchi2, hIDthetascatres,hIDthetascatpull, - hCalChi2, hCalRes, hCalPull, - hMSchi2, hMSres, hMSpull, - hMSphiscatchi2, hMSphiscatres, hMSphiscatpull, - hMSthetascatchi2, hMSthetascatres,hMSthetascatpull}; - - - // ID measurement chi2 - int ipad=0; - canv->Divide(3,4); - - for (int ihist=0;ihist<NHISTS;ihist++) { - + hTrackChi2[0]->SetMaximum(max * 1.2); + hTrackChi2[0]->Draw(); + for (int ifile = 1; ifile < NFILES; ifile++) hTrackChi2[ifile]->Draw("same"); + leg->Draw(); + + /* canv->cd(++ipad); - double max(0.); + max=0.; for (int ifile=0;ifile<NFILES;ifile++) { - double thismax=hists[ihist][ifile]->GetMaximum(); + double thismax=hMyTrackChi2[ifile]->GetMaximum(); if (thismax>max) max=thismax; } - hists[ihist][0]->SetMaximum(max*1.2); - hists[ihist][0]->Draw(); - for (int ifile=1;ifile<NFILES;ifile++) hists[ihist][ifile]->Draw("same"); + hMyTrackChi2[0]->SetMaximum(max*1.2); + hMyTrackChi2[0]->Draw(); + for (int ifile=1;ifile<NFILES;ifile++) hMyTrackChi2[ifile]->Draw("same"); leg->Draw(); + */ - if (ihist==11) { - canv->Print("level1hists_ID.eps"); - ipad=0; - canv->Clear(); - canv->Divide(3,4); - } - } - - canv->cd(++ipad); - double max=0.; - for (int ifile=0;ifile<NFILES;ifile++) { - double thismax=hTrackChi2[ifile]->GetMaximum(); - if (thismax>max) max=thismax; - } - hTrackChi2[0]->SetMaximum(max*1.2); - hTrackChi2[0]->Draw(); - for (int ifile=1;ifile<NFILES;ifile++) hTrackChi2[ifile]->Draw("same"); - leg->Draw(); - - /* - canv->cd(++ipad); - max=0.; - for (int ifile=0;ifile<NFILES;ifile++) { - double thismax=hMyTrackChi2[ifile]->GetMaximum(); - if (thismax>max) max=thismax; - } - hMyTrackChi2[0]->SetMaximum(max*1.2); - hMyTrackChi2[0]->Draw(); - for (int ifile=1;ifile<NFILES;ifile++) hMyTrackChi2[ifile]->Draw("same"); - leg->Draw(); - */ - - canv->Print("level1hists_MS.eps"); - - delete canv; - - delete [] lastgoodentry; + canv->Print("level1hists_MS.eps"); + + delete canv; + + delete[] lastgoodentry; } diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/muontrackplots_x.cpp b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/muontrackplots_x.cpp index ef8b41cf98d07373d51c72b442b5c9d51da8b112..9ac399cd000f0a697881815dd6f89796a81e8511 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/muontrackplots_x.cpp +++ b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/muontrackplots_x.cpp @@ -2,435 +2,380 @@ Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ -#include "MuonFixedId.h" -#include "Tools.h" - -#include "TStyle.h" +#include <TAxis.h> +#include <TCanvas.h> #include <TChain.h> -#include <TTree.h> +#include <TDecompBK.h> #include <TEventList.h> +#include <TF1.h> +#include <TGraph.h> #include <TLorentzVector.h> #include <TMatrixDSym.h> -#include <TVectorD.h> -#include <TDecompBK.h> #include <TMatrixTSparse.h> -#include <TGraph.h> -#include <TCanvas.h> -#include <TF1.h> #include <TPaveText.h> -#include <TAxis.h> -#include "TFile.h" -#include "TH1F.h" -#include "TLine.h" -#include "TSystem.h" -#include "TH2F.h" -#include <iostream> +#include <TTree.h> +#include <TVectorD.h> + +#include <cmath> +#include <fstream> #include <iomanip> +#include <iostream> +#include <map> +#include <set> #include <sstream> -#include <fstream> #include <string> -#include <map> -#include <cmath> #include <vector> -#include <set> + +#include "MuonFixedId.h" +#include "TFile.h" +#include "TH1F.h" +#include "TH2F.h" +#include "TLine.h" +#include "TStyle.h" +#include "TSystem.h" +#include "Tools.h" using namespace MuonCalib; - -const bool BATCH=false; -const bool doL1=true; - -bool DEBUG=0; - -int m_ntrees=0; - -void help(const char *argv0) { - - cerr << "Usage: " << argv0 << " [options] " << endl - << "Options:" << endl - << " -o :\tOutput path" << endl - << " -i :\tInput files" << endl - << " -r :\tRootname" << endl - << " -j :\tIteration" << endl - << " -a :\tDraw absolute lines" << endl - << " -l :\tL1 alignment" << endl - << " -d :\tDebug" << endl - << " -h :\tShow this message and quit" << endl - << endl; - exit(1); + +const bool BATCH = false; +const bool doL1 = true; + +bool DEBUG = 0; + +int m_ntrees = 0; + +void help(const char* argv0) { + cerr << "Usage: " << argv0 << " [options] " << endl + << "Options:" << endl + << " -o :\tOutput path" << endl + << " -i :\tInput files" << endl + << " -r :\tRootname" << endl + << " -j :\tIteration" << endl + << " -a :\tDraw absolute lines" << endl + << " -l :\tL1 alignment" << endl + << " -d :\tDebug" << endl + << " -h :\tShow this message and quit" << endl + << endl; + exit(1); } //_____________________________________________________________________________ -int main(int argc, char** argv) -{ - - //---------------------------- - //-- Parse the command line -- - //---------------------------- - - extern char *optarg; - char c; - TString inputdir(""); - TString outputdir(""); - TString rootname(""); - int iteration = 0; - - bool L1ALIGNMENT = false; - bool ABSLINES = false; - - while((c = getopt(argc, argv, "-hdalo:i:r:j:")) !=-1){ - switch(c){ - case 'o': - outputdir = optarg; - break; - case 'i': - inputdir = optarg; - break; - case 'r': - rootname = optarg; - break; - case 'j': - iteration = atoi(optarg); - break; - case 'd': - DEBUG = true; - break; - case 'a': - ABSLINES = true; - break; - case 'l': - L1ALIGNMENT = true; - break; - default: - cerr << "Help or unknown argument!" << endl; - help(argv[0]); - break; +int main(int argc, char** argv) { + //---------------------------- + //-- Parse the command line -- + //---------------------------- + + extern char* optarg; + char c; + TString inputdir(""); + TString outputdir(""); + TString rootname(""); + int iteration = 0; + + bool L1ALIGNMENT = false; + bool ABSLINES = false; + + while ((c = getopt(argc, argv, "-hdalo:i:r:j:")) != -1) { + switch (c) { + case 'o': outputdir = optarg; break; + case 'i': inputdir = optarg; break; + case 'r': rootname = optarg; break; + case 'j': iteration = atoi(optarg); break; + case 'd': DEBUG = true; break; + case 'a': ABSLINES = true; break; + case 'l': L1ALIGNMENT = true; break; + default: + cerr << "Help or unknown argument!" << endl; + help(argv[0]); + break; + } } - } - if(rootname==""){ - cerr << "no rootname passed, exiting..." << endl; - exit(1); - } - if(inputdir==""){ - inputdir = rootname; - } - if(outputdir==""){ - outputdir = inputdir; - } - - - gStyle->SetOptStat(1); - //gStyle->SetOptFit(11111); - gStyle->SetFrameFillStyle(0); - gStyle->SetTitleFillColor(0); - gStyle->SetTitleBorderSize(1); - gStyle->SetPadLeftMargin(0.15); - gStyle->SetPadRightMargin(0.04); - gStyle->SetPalette(1); - - void *directory = gSystem->OpenDirectory(inputdir); - if (!directory){ - cerr << "input directory does not exist, exiting..." << endl; - exit(1); - } - directory = gSystem->OpenDirectory(outputdir); - if (!directory){ - cerr << "create output directory: " << outputdir << endl; - int status = gSystem->mkdir(outputdir,false); - if(status!=0){ - cerr << "could not create output directory, exiting..." << endl; - exit(1); + if (rootname == "") { + cerr << "no rootname passed, exiting..." << endl; + exit(1); + } + if (inputdir == "") { inputdir = rootname; } + if (outputdir == "") { outputdir = inputdir; } + + gStyle->SetOptStat(1); + // gStyle->SetOptFit(11111); + gStyle->SetFrameFillStyle(0); + gStyle->SetTitleFillColor(0); + gStyle->SetTitleBorderSize(1); + gStyle->SetPadLeftMargin(0.15); + gStyle->SetPadRightMargin(0.04); + gStyle->SetPalette(1); + + void* directory = gSystem->OpenDirectory(inputdir); + if (!directory) { + cerr << "input directory does not exist, exiting..." << endl; + exit(1); + } + directory = gSystem->OpenDirectory(outputdir); + if (!directory) { + cerr << "create output directory: " << outputdir << endl; + int status = gSystem->mkdir(outputdir, false); + if (status != 0) { + cerr << "could not create output directory, exiting..." << endl; + exit(1); + } + } + + TString iterdir = inputdir + "/iter0"; + directory = gSystem->OpenDirectory(inputdir + "/iter0"); + bool multiplejobs = directory ? true : false; + cout << "multiplejobs: " << multiplejobs << endl; + + TString basefilename; + if (multiplejobs) { + TString iterdir = inputdir + Form("/iter%i/", iteration); + directory = gSystem->OpenDirectory(iterdir); + basefilename = iterdir; + if (!directory) { + cerr << "iteration: " << iteration << "does not exists, exiting..." << endl; + exit(1); + } + } else { + basefilename = inputdir + "/"; } - } - - TString iterdir = inputdir+"/iter0"; - directory = gSystem->OpenDirectory(inputdir+"/iter0"); - bool multiplejobs = directory ? true : false; - cout << "multiplejobs: " << multiplejobs << endl; - - TString basefilename; - if(multiplejobs){ - TString iterdir = inputdir+Form("/iter%i/",iteration); - directory = gSystem->OpenDirectory(iterdir); - basefilename = iterdir; - if(!directory){ - cerr << "iteration: " << iteration << "does not exists, exiting..." << endl; - exit(1); - } - } - else{ - basefilename = inputdir+"/"; - } - - //basefilename += "MuonAlign_"+rootname+Form("_iter%i",iteration); - basefilename += rootname; - - TString muonalign_filename = basefilename; - TString alignpar_filename = basefilename; - if(multiplejobs){ - //muonalign_filename += "_index*"; - muonalign_filename += "*"; - alignpar_filename += "_solve"; - } - muonalign_filename += ".root"; - alignpar_filename += ".root"; - - TChain* tree=new TChain("MuonAlign"); - tree->Add(muonalign_filename); - - m_ntrees=tree->GetNtrees(); - std::cout<<"have "<<m_ntrees<<" trees"<<std::endl; - - int run,event; - double* chi2VAlignParamQuality=new double[6]; - double trackChi2,trackChi2Dof,idTrackChi2,idTrackChi2Dof,msTrackChi2,msTrackChi2Dof; - double trackEta,energyLoss; - int nSctHits,nPixHits,nTrtHits,nMdtHits,nRpcPhiHits,nTgcPhiHits; - double msidPtDiff,idPtAtIP,idZ0AtIP,idD0AtIP,msPtAtIP,msZ0AtIP,msD0AtIP; - double truth_pt_gen,truth_pt_msentrance; - int nMuonOutliers,nTgcOutliers; - - // set branch addresses - tree->SetBranchAddress("run", &run); - tree->SetBranchAddress("evt", &event); - tree->SetBranchAddress("chi2VAlignParamQuality", chi2VAlignParamQuality); - tree->SetBranchAddress("trackChi2", &trackChi2); - tree->SetBranchAddress("trackChi2Dof", &trackChi2Dof); - tree->SetBranchAddress("idTrackChi2", &idTrackChi2); - tree->SetBranchAddress("idTrackChi2Dof", &idTrackChi2Dof); - tree->SetBranchAddress("msTrackChi2", &msTrackChi2); - tree->SetBranchAddress("msTrackChi2Dof", &msTrackChi2Dof); - tree->SetBranchAddress("trackEta", &trackEta); - tree->SetBranchAddress("energyLoss", &energyLoss); - tree->SetBranchAddress("nSctHits", &nSctHits); - tree->SetBranchAddress("nPixHits", &nPixHits); - tree->SetBranchAddress("nTrtHits", &nTrtHits); - tree->SetBranchAddress("msidPtDiff", &msidPtDiff); - tree->SetBranchAddress("idPtAtIP", &idPtAtIP); - tree->SetBranchAddress("idZ0AtIP", &idZ0AtIP); - tree->SetBranchAddress("idD0AtIP", &idD0AtIP); - tree->SetBranchAddress("msPtAtIP", &msPtAtIP); - tree->SetBranchAddress("msZ0AtIP", &msZ0AtIP); - tree->SetBranchAddress("msD0AtIP", &msD0AtIP); - tree->SetBranchAddress("nMdtHits", &nMdtHits); - tree->SetBranchAddress("nRpcPhiHits", &nRpcPhiHits); - tree->SetBranchAddress("nTgcPhiHits", &nTgcPhiHits); - tree->SetBranchAddress("truth_pt_gen", &truth_pt_gen); - tree->SetBranchAddress("truth_pt_msentrance", &truth_pt_msentrance); - tree->SetBranchAddress("nMuonOutliers", &nMuonOutliers); - tree->SetBranchAddress("nTgcOutliers", &nTgcOutliers); - - const int NHIST=21; - - /*string names[NHIST]={"trackChi2","trackChi2Dof","IDTrackChi2","IDTrackChi2Dof", - "MSTrackChi2","MSTrackChi2Dof", - "trackEta", "energyLoss", - "nSCTHits", "nPixHits", "nTRTHits", - "msidPtDiff", - "ID_pTatIP","ID_z0atIP","ID_d0atIP", - "MS_pTatIP","MS_z0atIP","MS_d0atIP", - "nMDT_hits", "nRPC_phiHits", "nTGC_phiHits"}; - */ - - TH2F** hVarVFitChi2=new TH2F*[NHIST]; - const int NCHI2BIN=50; - const double CHI2MIN=-30.; - const double CHI2MAX=10.; - - hVarVFitChi2[0]=new TH2F("hVarVFitChi2_0","track chi2",NCHI2BIN,CHI2MIN,CHI2MAX, - 30,0.,150.); - hVarVFitChi2[0]->GetYaxis()->SetTitle("track #chi^{2}"); - - hVarVFitChi2[1]=new TH2F("hVarVFitChi2_1","track chi2 per DOF",NCHI2BIN,CHI2MIN,CHI2MAX, - 30,0.,3.); - hVarVFitChi2[1]->GetYaxis()->SetTitle("track #chi^{2}/DOF"); - - hVarVFitChi2[2]=new TH2F("hVarVFitChi2_2","ID track chi2",NCHI2BIN,CHI2MIN,CHI2MAX, - 30,0.,100.); - hVarVFitChi2[2]->GetYaxis()->SetTitle("ID track #chi^{2}"); - - hVarVFitChi2[3]=new TH2F("hVarVFitChi2_3","ID track chi2 per DOF",NCHI2BIN,CHI2MIN,CHI2MAX, - 30,0.,1.6); - hVarVFitChi2[3]->GetYaxis()->SetTitle("ID track #chi^{2}/DOF"); - - hVarVFitChi2[4]=new TH2F("hVarVFitChi2_4","MS track chi2",NCHI2BIN,CHI2MIN,CHI2MAX, - 30,0.,150.); - hVarVFitChi2[4]->GetYaxis()->SetTitle("MS track #chi^{2}"); - - hVarVFitChi2[5]=new TH2F("hVarVFitChi2_5","MS track chi2 per DOF",NCHI2BIN,CHI2MIN,CHI2MAX, - 30,0.,2.5); - hVarVFitChi2[5]->GetYaxis()->SetTitle("MS track #chi^{2}/DOF"); - - hVarVFitChi2[6]=new TH2F("hVarVFitChi2_6","muon track eta",NCHI2BIN,CHI2MIN,CHI2MAX, - 30,1.0,2.8); - hVarVFitChi2[6]->GetYaxis()->SetTitle("muon track |#eta|"); - - hVarVFitChi2[7]=new TH2F("hVarVFitChi2_7","energy loss",NCHI2BIN,CHI2MIN,CHI2MAX, - 30,3.,5.); - hVarVFitChi2[7]->GetYaxis()->SetTitle("energy loss (GeV)"); - - hVarVFitChi2[8]=new TH2F("hVarVFitChi2_8","number SCT hits",NCHI2BIN,CHI2MIN,CHI2MAX, - 30,0.,20.); - hVarVFitChi2[8]->GetYaxis()->SetTitle("number SCT hits"); - - hVarVFitChi2[9]=new TH2F("hVarVFitChi2_9","number pixel hits",NCHI2BIN,CHI2MIN,CHI2MAX, - 30,0.,10.); - hVarVFitChi2[9]->GetYaxis()->SetTitle("number pixel hits"); - - hVarVFitChi2[10]=new TH2F("hVarVFitChi2_10","number TRT hits",NCHI2BIN,CHI2MIN,CHI2MAX, - 30,0.,50.); - hVarVFitChi2[10]->GetYaxis()->SetTitle("number TRT hits"); - - hVarVFitChi2[11]=new TH2F("hVarVFitChi2_11","msid_ptDiff",NCHI2BIN,CHI2MIN,CHI2MAX, - 30,0.,.16); - hVarVFitChi2[11]->GetYaxis()->SetTitle("|1-pT_{ID}/pT_{MS}|"); - - hVarVFitChi2[12]=new TH2F("hVarVFitChi2_12","ID pT at IP",NCHI2BIN,CHI2MIN,CHI2MAX, - 30,0.,150.); - hVarVFitChi2[12]->GetYaxis()->SetTitle("ID pT at IP"); - - hVarVFitChi2[13]=new TH2F("hVarVFitChi2_13","ID z0 at IP",NCHI2BIN,CHI2MIN,CHI2MAX, - 30,-170.,170.); - hVarVFitChi2[13]->GetYaxis()->SetTitle("ID z0 at IP"); - - hVarVFitChi2[14]=new TH2F("hVarVFitChi2_14","ID d0 at IP",NCHI2BIN,CHI2MIN,CHI2MAX, - 30,-0.15,0.15); - hVarVFitChi2[14]->GetYaxis()->SetTitle("ID d0 at IP"); - - hVarVFitChi2[15]=new TH2F("hVarVFitChi2_15","MS pT at IP",NCHI2BIN,CHI2MIN,CHI2MAX, - 30,0.,50.); - hVarVFitChi2[15]->GetYaxis()->SetTitle("MS pT at IP"); - - hVarVFitChi2[16]=new TH2F("hVarVFitChi2_16","MS z0 at IP",NCHI2BIN,CHI2MIN,CHI2MAX, - 30,-180.,180.); - hVarVFitChi2[16]->GetYaxis()->SetTitle("MS z0 at IP"); - - hVarVFitChi2[17]=new TH2F("hVarVFitChi2_17","MS d0 at IP",NCHI2BIN,CHI2MIN,CHI2MAX, - 30,-0.25,0.25); - hVarVFitChi2[17]->GetYaxis()->SetTitle("MS d0 at IP"); - - hVarVFitChi2[18]=new TH2F("hVarVFitChi2_18","number MDT hits",NCHI2BIN,CHI2MIN,CHI2MAX, - 30,0.,50.); - hVarVFitChi2[18]->GetYaxis()->SetTitle("number MDT hits"); - - hVarVFitChi2[19]=new TH2F("hVarVFitChi2_19","number RPC phi hits",NCHI2BIN,CHI2MIN,CHI2MAX, - 30,0.,50.); - hVarVFitChi2[19]->GetYaxis()->SetTitle("number RPC phi hits"); - - hVarVFitChi2[20]=new TH2F("hVarVFitChi2_20","number TGC phi hits",NCHI2BIN,CHI2MIN,CHI2MAX, - 30,0.,50.); - hVarVFitChi2[20]->GetYaxis()->SetTitle("number TGC phi hits"); - - TH2F* hDiscVNMuonOutliers = new TH2F("hDiscVNMuonOutliers", "log(discontinuity chi2) vs. number muon outliers", - 5,0,5,50,-10,0.); - TH2F* hDiscVNTgcOutliers = new TH2F("hDiscVNTgcOutliers", "log(discontinuity chi2) vs. number TGC outliers", - 5,0,5,50,-10,0.); - TH1F* hnTgcOutliers = new TH1F("hnTgcOutliers", "number TGC outliers", - 5,0,5); - for (int i=0;i<NHIST;i++) - hVarVFitChi2[i]->GetXaxis()->SetTitle("log(#chi^{2} of #chi^{2} v. align param)"); - - // fill histograms - for (int ientry=0;ientry<tree->GetEntries();ientry++) { - - tree->GetEntry(ientry); - /* - double worstchi2=0.; - for (int i=0;i<6;i++) - if (chi2VAlignParamQuality[i]>worstchi2) - worstchi2=chi2VAlignParamQuality[i]; - std::cout<<"evt "<<event<<", nMuonOutliers="<<nMuonOutliers<<", worstchi2="<<worstchi2<<std::endl; - hDiscVNMuonOutliers->Fill(nMuonOutliers,std::log10(worstchi2)); + + // basefilename += "MuonAlign_"+rootname+Form("_iter%i",iteration); + basefilename += rootname; + + TString muonalign_filename = basefilename; + TString alignpar_filename = basefilename; + if (multiplejobs) { + // muonalign_filename += "_index*"; + muonalign_filename += "*"; + alignpar_filename += "_solve"; + } + muonalign_filename += ".root"; + alignpar_filename += ".root"; + + TChain* tree = new TChain("MuonAlign"); + tree->Add(muonalign_filename); + + m_ntrees = tree->GetNtrees(); + std::cout << "have " << m_ntrees << " trees" << std::endl; + + int run, event; + double* chi2VAlignParamQuality = new double[6]; + double trackChi2, trackChi2Dof, idTrackChi2, idTrackChi2Dof, msTrackChi2, msTrackChi2Dof; + double trackEta, energyLoss; + int nSctHits, nPixHits, nTrtHits, nMdtHits, nRpcPhiHits, nTgcPhiHits; + double msidPtDiff, idPtAtIP, idZ0AtIP, idD0AtIP, msPtAtIP, msZ0AtIP, msD0AtIP; + double truth_pt_gen, truth_pt_msentrance; + int nMuonOutliers, nTgcOutliers; + + // set branch addresses + tree->SetBranchAddress("run", &run); + tree->SetBranchAddress("evt", &event); + tree->SetBranchAddress("chi2VAlignParamQuality", chi2VAlignParamQuality); + tree->SetBranchAddress("trackChi2", &trackChi2); + tree->SetBranchAddress("trackChi2Dof", &trackChi2Dof); + tree->SetBranchAddress("idTrackChi2", &idTrackChi2); + tree->SetBranchAddress("idTrackChi2Dof", &idTrackChi2Dof); + tree->SetBranchAddress("msTrackChi2", &msTrackChi2); + tree->SetBranchAddress("msTrackChi2Dof", &msTrackChi2Dof); + tree->SetBranchAddress("trackEta", &trackEta); + tree->SetBranchAddress("energyLoss", &energyLoss); + tree->SetBranchAddress("nSctHits", &nSctHits); + tree->SetBranchAddress("nPixHits", &nPixHits); + tree->SetBranchAddress("nTrtHits", &nTrtHits); + tree->SetBranchAddress("msidPtDiff", &msidPtDiff); + tree->SetBranchAddress("idPtAtIP", &idPtAtIP); + tree->SetBranchAddress("idZ0AtIP", &idZ0AtIP); + tree->SetBranchAddress("idD0AtIP", &idD0AtIP); + tree->SetBranchAddress("msPtAtIP", &msPtAtIP); + tree->SetBranchAddress("msZ0AtIP", &msZ0AtIP); + tree->SetBranchAddress("msD0AtIP", &msD0AtIP); + tree->SetBranchAddress("nMdtHits", &nMdtHits); + tree->SetBranchAddress("nRpcPhiHits", &nRpcPhiHits); + tree->SetBranchAddress("nTgcPhiHits", &nTgcPhiHits); + tree->SetBranchAddress("truth_pt_gen", &truth_pt_gen); + tree->SetBranchAddress("truth_pt_msentrance", &truth_pt_msentrance); + tree->SetBranchAddress("nMuonOutliers", &nMuonOutliers); + tree->SetBranchAddress("nTgcOutliers", &nTgcOutliers); + + const int NHIST = 21; + + /*string names[NHIST]={"trackChi2","trackChi2Dof","IDTrackChi2","IDTrackChi2Dof", + "MSTrackChi2","MSTrackChi2Dof", + "trackEta", "energyLoss", + "nSCTHits", "nPixHits", "nTRTHits", + "msidPtDiff", + "ID_pTatIP","ID_z0atIP","ID_d0atIP", + "MS_pTatIP","MS_z0atIP","MS_d0atIP", + "nMDT_hits", "nRPC_phiHits", "nTGC_phiHits"}; */ - for (int i=0;i<6;i++) { - std::cout<<"evt "<<event<<", chi2VAlignParamQuality["<<i<<"]="<<chi2VAlignParamQuality[i]<<std::endl; - hDiscVNMuonOutliers->Fill(nMuonOutliers,std::log10(chi2VAlignParamQuality[i])); - hDiscVNTgcOutliers->Fill(nTgcOutliers,std::log10(chi2VAlignParamQuality[i])); - std::cout<<"nTgcOutliers="<<nTgcOutliers<<std::endl; + + TH2F** hVarVFitChi2 = new TH2F*[NHIST]; + const int NCHI2BIN = 50; + const double CHI2MIN = -30.; + const double CHI2MAX = 10.; + + hVarVFitChi2[0] = new TH2F("hVarVFitChi2_0", "track chi2", NCHI2BIN, CHI2MIN, CHI2MAX, 30, 0., 150.); + hVarVFitChi2[0]->GetYaxis()->SetTitle("track #chi^{2}"); + + hVarVFitChi2[1] = new TH2F("hVarVFitChi2_1", "track chi2 per DOF", NCHI2BIN, CHI2MIN, CHI2MAX, 30, 0., 3.); + hVarVFitChi2[1]->GetYaxis()->SetTitle("track #chi^{2}/DOF"); + + hVarVFitChi2[2] = new TH2F("hVarVFitChi2_2", "ID track chi2", NCHI2BIN, CHI2MIN, CHI2MAX, 30, 0., 100.); + hVarVFitChi2[2]->GetYaxis()->SetTitle("ID track #chi^{2}"); + + hVarVFitChi2[3] = new TH2F("hVarVFitChi2_3", "ID track chi2 per DOF", NCHI2BIN, CHI2MIN, CHI2MAX, 30, 0., 1.6); + hVarVFitChi2[3]->GetYaxis()->SetTitle("ID track #chi^{2}/DOF"); + + hVarVFitChi2[4] = new TH2F("hVarVFitChi2_4", "MS track chi2", NCHI2BIN, CHI2MIN, CHI2MAX, 30, 0., 150.); + hVarVFitChi2[4]->GetYaxis()->SetTitle("MS track #chi^{2}"); + + hVarVFitChi2[5] = new TH2F("hVarVFitChi2_5", "MS track chi2 per DOF", NCHI2BIN, CHI2MIN, CHI2MAX, 30, 0., 2.5); + hVarVFitChi2[5]->GetYaxis()->SetTitle("MS track #chi^{2}/DOF"); + + hVarVFitChi2[6] = new TH2F("hVarVFitChi2_6", "muon track eta", NCHI2BIN, CHI2MIN, CHI2MAX, 30, 1.0, 2.8); + hVarVFitChi2[6]->GetYaxis()->SetTitle("muon track |#eta|"); + + hVarVFitChi2[7] = new TH2F("hVarVFitChi2_7", "energy loss", NCHI2BIN, CHI2MIN, CHI2MAX, 30, 3., 5.); + hVarVFitChi2[7]->GetYaxis()->SetTitle("energy loss (GeV)"); + + hVarVFitChi2[8] = new TH2F("hVarVFitChi2_8", "number SCT hits", NCHI2BIN, CHI2MIN, CHI2MAX, 30, 0., 20.); + hVarVFitChi2[8]->GetYaxis()->SetTitle("number SCT hits"); + + hVarVFitChi2[9] = new TH2F("hVarVFitChi2_9", "number pixel hits", NCHI2BIN, CHI2MIN, CHI2MAX, 30, 0., 10.); + hVarVFitChi2[9]->GetYaxis()->SetTitle("number pixel hits"); + + hVarVFitChi2[10] = new TH2F("hVarVFitChi2_10", "number TRT hits", NCHI2BIN, CHI2MIN, CHI2MAX, 30, 0., 50.); + hVarVFitChi2[10]->GetYaxis()->SetTitle("number TRT hits"); + + hVarVFitChi2[11] = new TH2F("hVarVFitChi2_11", "msid_ptDiff", NCHI2BIN, CHI2MIN, CHI2MAX, 30, 0., .16); + hVarVFitChi2[11]->GetYaxis()->SetTitle("|1-pT_{ID}/pT_{MS}|"); + + hVarVFitChi2[12] = new TH2F("hVarVFitChi2_12", "ID pT at IP", NCHI2BIN, CHI2MIN, CHI2MAX, 30, 0., 150.); + hVarVFitChi2[12]->GetYaxis()->SetTitle("ID pT at IP"); + + hVarVFitChi2[13] = new TH2F("hVarVFitChi2_13", "ID z0 at IP", NCHI2BIN, CHI2MIN, CHI2MAX, 30, -170., 170.); + hVarVFitChi2[13]->GetYaxis()->SetTitle("ID z0 at IP"); + + hVarVFitChi2[14] = new TH2F("hVarVFitChi2_14", "ID d0 at IP", NCHI2BIN, CHI2MIN, CHI2MAX, 30, -0.15, 0.15); + hVarVFitChi2[14]->GetYaxis()->SetTitle("ID d0 at IP"); + + hVarVFitChi2[15] = new TH2F("hVarVFitChi2_15", "MS pT at IP", NCHI2BIN, CHI2MIN, CHI2MAX, 30, 0., 50.); + hVarVFitChi2[15]->GetYaxis()->SetTitle("MS pT at IP"); + + hVarVFitChi2[16] = new TH2F("hVarVFitChi2_16", "MS z0 at IP", NCHI2BIN, CHI2MIN, CHI2MAX, 30, -180., 180.); + hVarVFitChi2[16]->GetYaxis()->SetTitle("MS z0 at IP"); + + hVarVFitChi2[17] = new TH2F("hVarVFitChi2_17", "MS d0 at IP", NCHI2BIN, CHI2MIN, CHI2MAX, 30, -0.25, 0.25); + hVarVFitChi2[17]->GetYaxis()->SetTitle("MS d0 at IP"); + + hVarVFitChi2[18] = new TH2F("hVarVFitChi2_18", "number MDT hits", NCHI2BIN, CHI2MIN, CHI2MAX, 30, 0., 50.); + hVarVFitChi2[18]->GetYaxis()->SetTitle("number MDT hits"); + + hVarVFitChi2[19] = new TH2F("hVarVFitChi2_19", "number RPC phi hits", NCHI2BIN, CHI2MIN, CHI2MAX, 30, 0., 50.); + hVarVFitChi2[19]->GetYaxis()->SetTitle("number RPC phi hits"); + + hVarVFitChi2[20] = new TH2F("hVarVFitChi2_20", "number TGC phi hits", NCHI2BIN, CHI2MIN, CHI2MAX, 30, 0., 50.); + hVarVFitChi2[20]->GetYaxis()->SetTitle("number TGC phi hits"); + + TH2F* hDiscVNMuonOutliers = new TH2F("hDiscVNMuonOutliers", "log(discontinuity chi2) vs. number muon outliers", 5, 0, 5, 50, -10, 0.); + TH2F* hDiscVNTgcOutliers = new TH2F("hDiscVNTgcOutliers", "log(discontinuity chi2) vs. number TGC outliers", 5, 0, 5, 50, -10, 0.); + TH1F* hnTgcOutliers = new TH1F("hnTgcOutliers", "number TGC outliers", 5, 0, 5); + for (int i = 0; i < NHIST; i++) hVarVFitChi2[i]->GetXaxis()->SetTitle("log(#chi^{2} of #chi^{2} v. align param)"); + + // fill histograms + for (int ientry = 0; ientry < tree->GetEntries(); ientry++) { + tree->GetEntry(ientry); + /* + double worstchi2=0.; + for (int i=0;i<6;i++) + if (chi2VAlignParamQuality[i]>worstchi2) + worstchi2=chi2VAlignParamQuality[i]; + std::cout<<"evt "<<event<<", nMuonOutliers="<<nMuonOutliers<<", worstchi2="<<worstchi2<<std::endl; + hDiscVNMuonOutliers->Fill(nMuonOutliers,std::log10(worstchi2)); + */ + for (int i = 0; i < 6; i++) { + std::cout << "evt " << event << ", chi2VAlignParamQuality[" << i << "]=" << chi2VAlignParamQuality[i] << std::endl; + hDiscVNMuonOutliers->Fill(nMuonOutliers, std::log10(chi2VAlignParamQuality[i])); + hDiscVNTgcOutliers->Fill(nTgcOutliers, std::log10(chi2VAlignParamQuality[i])); + std::cout << "nTgcOutliers=" << nTgcOutliers << std::endl; + } + hnTgcOutliers->Fill(nTgcOutliers); + + for (int i = 0; i < 6; i++) { + // if (chi2VAlignParamQuality[i]>.001) continue; + double chi2val = std::log10(chi2VAlignParamQuality[i]); + hVarVFitChi2[0]->Fill(chi2val, trackChi2); + hVarVFitChi2[1]->Fill(chi2val, trackChi2Dof); + hVarVFitChi2[2]->Fill(chi2val, idTrackChi2); + hVarVFitChi2[3]->Fill(chi2val, idTrackChi2Dof); + hVarVFitChi2[4]->Fill(chi2val, msTrackChi2); + hVarVFitChi2[5]->Fill(chi2val, msTrackChi2Dof); + hVarVFitChi2[6]->Fill(chi2val, trackEta); + hVarVFitChi2[7]->Fill(chi2val, energyLoss); + hVarVFitChi2[8]->Fill(chi2val, nSctHits); + hVarVFitChi2[9]->Fill(chi2val, nPixHits); + hVarVFitChi2[10]->Fill(chi2val, nTrtHits); + hVarVFitChi2[11]->Fill(chi2val, msidPtDiff); + hVarVFitChi2[12]->Fill(chi2val, idPtAtIP); + hVarVFitChi2[13]->Fill(chi2val, idZ0AtIP); + hVarVFitChi2[14]->Fill(chi2val, idD0AtIP); + hVarVFitChi2[15]->Fill(chi2val, msPtAtIP * 1000.); + hVarVFitChi2[16]->Fill(chi2val, msZ0AtIP); + hVarVFitChi2[17]->Fill(chi2val, msD0AtIP); + hVarVFitChi2[18]->Fill(chi2val, nMdtHits); + hVarVFitChi2[19]->Fill(chi2val, nRpcPhiHits); + hVarVFitChi2[20]->Fill(chi2val, nTgcPhiHits); + } } - hnTgcOutliers->Fill(nTgcOutliers); - - for (int i=0;i<6;i++) { - //if (chi2VAlignParamQuality[i]>.001) continue; - double chi2val=std::log10(chi2VAlignParamQuality[i]); - hVarVFitChi2[0] ->Fill(chi2val,trackChi2); - hVarVFitChi2[1] ->Fill(chi2val,trackChi2Dof); - hVarVFitChi2[2] ->Fill(chi2val,idTrackChi2); - hVarVFitChi2[3] ->Fill(chi2val,idTrackChi2Dof); - hVarVFitChi2[4] ->Fill(chi2val,msTrackChi2); - hVarVFitChi2[5] ->Fill(chi2val,msTrackChi2Dof); - hVarVFitChi2[6] ->Fill(chi2val,trackEta); - hVarVFitChi2[7] ->Fill(chi2val,energyLoss); - hVarVFitChi2[8] ->Fill(chi2val,nSctHits); - hVarVFitChi2[9] ->Fill(chi2val,nPixHits); - hVarVFitChi2[10]->Fill(chi2val,nTrtHits); - hVarVFitChi2[11]->Fill(chi2val,msidPtDiff); - hVarVFitChi2[12]->Fill(chi2val,idPtAtIP); - hVarVFitChi2[13]->Fill(chi2val,idZ0AtIP); - hVarVFitChi2[14]->Fill(chi2val,idD0AtIP); - hVarVFitChi2[15]->Fill(chi2val,msPtAtIP*1000.); - hVarVFitChi2[16]->Fill(chi2val,msZ0AtIP); - hVarVFitChi2[17]->Fill(chi2val,msD0AtIP); - hVarVFitChi2[18]->Fill(chi2val,nMdtHits); - hVarVFitChi2[19]->Fill(chi2val,nRpcPhiHits); - hVarVFitChi2[20]->Fill(chi2val,nTgcPhiHits); - } - } - - TCanvas* canv=new TCanvas("canv","canv"); - canv->SetFillColor(10); - int ipad(0); - int icanv(0); - for (int ihist=0;ihist<NHIST+1;ihist++) { - if (ihist%6==0 || ihist==NHIST) { - if (ihist>0) { - stringstream canvname; - canvname<<outputdir<<"/muontrackplots_iter"<<iteration<<"_"<<icanv<<".eps"; - canv->Print(canvname.str().c_str()); - canv->Clear(); - icanv++; - } - if (ihist==NHIST) continue; - canv->Divide(3,2); - ipad=0; - } - canv->cd(++ipad); - hVarVFitChi2[ihist]->Draw("colz"); - TLine* line0=new TLine(0.,hVarVFitChi2[ihist]->GetYaxis()->GetXmin(), - 0.,hVarVFitChi2[ihist]->GetYaxis()->GetXmax()); - //line0->SetLineColor(kRed); - line0->Draw(); - TLine* line1=new TLine(-1.,hVarVFitChi2[ihist]->GetYaxis()->GetXmin(), - -1.,hVarVFitChi2[ihist]->GetYaxis()->GetXmax()); - //line1->SetLineColor(kGreen); - line1->Draw(); - TLine* line2=new TLine(-2.,hVarVFitChi2[ihist]->GetYaxis()->GetXmin(), - -2.,hVarVFitChi2[ihist]->GetYaxis()->GetXmax()); - //line2->SetLineColor(kBlue); - line2->Draw(); - TLine* line3=new TLine(-3.,hVarVFitChi2[ihist]->GetYaxis()->GetXmin(), - -3.,hVarVFitChi2[ihist]->GetYaxis()->GetXmax()); - //line2->SetLineColor(kBlue); - line3->Draw(); - } - - canv->Clear(); - hDiscVNMuonOutliers->Draw("colz"); - stringstream canvname; - canvname<<outputdir<<"/discVNMuonOutliers_iter"<<iteration<<".eps"; - canv->Print(canvname.str().c_str()); - - canv->Clear(); - hDiscVNTgcOutliers->Draw("colz"); - stringstream canvname_tgc; - canvname_tgc<<outputdir<<"/discVNTgcOutliers_iter"<<iteration<<".eps"; - canv->Print(canvname_tgc.str().c_str()); - - canv->Clear(); - hnTgcOutliers->Draw(); - stringstream canvname_tgc1; - canvname_tgc1<<outputdir<<"/nTgcOutliers_iter"<<iteration<<".eps"; - canv->Print(canvname_tgc1.str().c_str()); - -} + TCanvas* canv = new TCanvas("canv", "canv"); + canv->SetFillColor(10); + int ipad(0); + int icanv(0); + for (int ihist = 0; ihist < NHIST + 1; ihist++) { + if (ihist % 6 == 0 || ihist == NHIST) { + if (ihist > 0) { + stringstream canvname; + canvname << outputdir << "/muontrackplots_iter" << iteration << "_" << icanv << ".eps"; + canv->Print(canvname.str().c_str()); + canv->Clear(); + icanv++; + } + if (ihist == NHIST) continue; + canv->Divide(3, 2); + ipad = 0; + } + canv->cd(++ipad); + hVarVFitChi2[ihist]->Draw("colz"); + TLine* line0 = new TLine(0., hVarVFitChi2[ihist]->GetYaxis()->GetXmin(), 0., hVarVFitChi2[ihist]->GetYaxis()->GetXmax()); + // line0->SetLineColor(kRed); + line0->Draw(); + TLine* line1 = new TLine(-1., hVarVFitChi2[ihist]->GetYaxis()->GetXmin(), -1., hVarVFitChi2[ihist]->GetYaxis()->GetXmax()); + // line1->SetLineColor(kGreen); + line1->Draw(); + TLine* line2 = new TLine(-2., hVarVFitChi2[ihist]->GetYaxis()->GetXmin(), -2., hVarVFitChi2[ihist]->GetYaxis()->GetXmax()); + // line2->SetLineColor(kBlue); + line2->Draw(); + TLine* line3 = new TLine(-3., hVarVFitChi2[ihist]->GetYaxis()->GetXmin(), -3., hVarVFitChi2[ihist]->GetYaxis()->GetXmax()); + // line2->SetLineColor(kBlue); + line3->Draw(); + } + canv->Clear(); + hDiscVNMuonOutliers->Draw("colz"); + stringstream canvname; + canvname << outputdir << "/discVNMuonOutliers_iter" << iteration << ".eps"; + canv->Print(canvname.str().c_str()); + + canv->Clear(); + hDiscVNTgcOutliers->Draw("colz"); + stringstream canvname_tgc; + canvname_tgc << outputdir << "/discVNTgcOutliers_iter" << iteration << ".eps"; + canv->Print(canvname_tgc.str().c_str()); + + canv->Clear(); + hnTgcOutliers->Draw(); + stringstream canvname_tgc1; + canvname_tgc1 << outputdir << "/nTgcOutliers_iter" << iteration << ".eps"; + canv->Print(canvname_tgc1.str().c_str()); +} diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/plotBEESagitta_x.cpp b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/plotBEESagitta_x.cpp index 2bf91b833b82c1f1140b3be57d3312790868f831..0afa394b84333f822ce7b7c93c0bfa146b03ac54 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/plotBEESagitta_x.cpp +++ b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/plotBEESagitta_x.cpp @@ -2,241 +2,240 @@ Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ +#include <cstdlib> +#include <iomanip> +#include <iostream> +#include <sstream> +#include <string> + #include "ChamberNames.h" -#include "TChain.h" #include "TCanvas.h" +#include "TChain.h" +#include "TFile.h" #include "TH2F.h" #include "TStyle.h" -#include "TFile.h" -#include <sstream> -#include <string> -#include <iomanip> -#include <iostream> -#include <cstdlib> +int main() { + // gStyle->SetOptStat(0); + // gStyle->SetOptFit(0); + gStyle->SetFrameFillStyle(0); + gStyle->SetTitleFillColor(0); + gStyle->SetTitleBorderSize(1); + gStyle->SetPadLeftMargin(0.15); + gStyle->SetPadRightMargin(0.15); + gStyle->SetPalette(1); + gStyle->SetOptFit(111111); -int main() -{ - //gStyle->SetOptStat(0); - //gStyle->SetOptFit(0); - gStyle->SetFrameFillStyle(0); - gStyle->SetTitleFillColor(0); - gStyle->SetTitleBorderSize(1); - gStyle->SetPadLeftMargin(0.15); - gStyle->SetPadRightMargin(0.15); - gStyle->SetPalette(1); - gStyle->SetOptFit(111111); - - const int NXBINS=15; - const int NYBINS=15; - - TFile* outputfile=new TFile("out_iter0.root","RECREATE"); - - TH1F* trackSag=new TH1F("trackSag","trackSag",100,-150.,150.); - TH1F* trackSagNorm=new TH1F("trackSagNorm","trackSagNorm",100,-3.,3.); - - TH1F**** beeRes =new TH1F***[2]; - TH1F**** eelRes =new TH1F***[2]; - TH2F**** beeHists =new TH2F***[2]; - TH2F**** beeHistsAvg =new TH2F***[2]; - TH2F**** beeNTrksHists=new TH2F***[2]; - string*** hnames =new string**[2]; - for (int isideAC=0;isideAC<2;isideAC++) { - beeRes [isideAC]=new TH1F**[2]; - eelRes [isideAC]=new TH1F**[2]; - beeHists [isideAC]=new TH2F**[2]; - beeHistsAvg [isideAC]=new TH2F**[2]; - beeNTrksHists[isideAC]=new TH2F**[2]; - hnames [isideAC]=new string*[2]; - for (int ieta=0;ieta<2;ieta++) { - beeRes [isideAC][ieta]=new TH1F*[8]; - eelRes [isideAC][ieta]=new TH1F*[8]; - beeHists [isideAC][ieta]=new TH2F*[8]; - beeHistsAvg [isideAC][ieta]=new TH2F*[8]; - beeNTrksHists[isideAC][ieta]=new TH2F*[8]; - hnames [isideAC][ieta]=new string[8]; - for (int iphi=0;iphi<8;iphi++) { - stringstream hname; - hname<<"BEE"<<ieta+1; - if (isideAC==0) hname<<"A"; else hname<<"C"; - hname<<setfill('0')<<setw(2)<<(iphi+1)*2; - hnames [isideAC][ieta][iphi]=hname.str(); - beeHists[isideAC][ieta][iphi]= - new TH2F(hname.str().c_str(),hname.str().c_str(),NXBINS,-400.,400.,NYBINS,-700.,700.); - beeHistsAvg[isideAC][ieta][iphi]= - new TH2F((hname.str()+"_avg").c_str(),(hname.str()+"_avg").c_str(), - NXBINS,-400.,400.,NYBINS,-700.,700.); - beeNTrksHists[isideAC][ieta][iphi]= - new TH2F((hname.str()+"_ntrks").c_str(),(hname.str()+"_ntrks").c_str(), - NXBINS,-400.,400.,NYBINS,-700.,700.); - - beeRes[isideAC][ieta][iphi]= - new TH1F((hname.str()+"_res").c_str(),(hname.str()+"_res").c_str(), - 100,-1.,1.); - stringstream eelname; - eelname<<"EEL"<<ieta+1; - if (isideAC==0) eelname<<"A"; else eelname<<"C"; - eelname<<setfill('0')<<setw(2)<<(iphi+1)*2-1; - eelRes[isideAC][ieta][iphi]= - new TH1F((eelname.str()+"_res").c_str(),(eelname.str()+"_res").c_str(), - 100,-1.,1.); - } - } - } - - ChamberNames chNames("chambers.txt"); - - TChain* tree=new TChain("MuonTrackPreProcessor"); - tree->Add("/tmp/roberth/user.roberth.TMU15GEV.20101119_EE_iter0_V1.110216012437/iter0/*root*"); - - double qOverP,trackSagitta; - double beePosX,beePosY; - int nChambers; - int *chamberId(new int[50]), *resIndex(new int[50]); - int nresiduals; - double *residuals(new double[100]); - tree->SetBranchAddress("qOverP", &qOverP); - tree->SetBranchAddress("trackSagitta", &trackSagitta); - tree->SetBranchAddress("BEEPosX", &beePosX); - tree->SetBranchAddress("BEEPosY", &beePosY); - tree->SetBranchAddress("nChambers", &nChambers); - tree->SetBranchAddress("chamberId", chamberId); - tree->SetBranchAddress("resIndex", resIndex); - tree->SetBranchAddress("nresiduals", &nresiduals); - tree->SetBranchAddress("residuals", residuals); - - for (int ientry=0;ientry<(int)tree->GetEntries();ientry++) { - if (ientry%100000==0) cout<<"ientry: "<<ientry<<endl; - tree->GetEntry(ientry); - if (beePosX<-9998.) continue; - - //cout<<"ientry: "<<ientry<<endl; - std::string beeName=""; - std::string eelName=""; - int firstBEERes(0),lastBEERes(0); - int firstEELRes(0),lastEELRes(0); - for (int ich=0;ich<nChambers;ich++) { - int id=chamberId[ich]; - std::string name=chNames.chamberName(id); - if (name.substr(0,3)=="BEE") { - beeName=name; - firstBEERes=resIndex[ich]; - lastBEERes=(ich+1<nChambers)?resIndex[ich+1]:nresiduals; - } - if (name.substr(0,3)=="EEL") { - eelName=name; - firstEELRes=resIndex[ich]; - lastEELRes=(ich+1<nChambers)?resIndex[ich+1]:nresiduals; - } - //cout<<"name: "<<name<<endl; - } - - // remove tracks not passing selection in MuonTrackPreProcessor - if (beeName==""&&eelName=="") { - continue; - } - - if (beeName!="") { - int stPhi=chNames.stPhi(beeName); - int stEta=chNames.stEta(beeName); - int isideAC=(stEta>0)?0:1; - int ieta=std::abs(stEta)-1; - int iphi=stPhi-1; - //cout<<"isideAC: "<<isideAC<<", ieta: "<<ieta<<", stPhi: "<<stPhi<<", iphi: "<<iphi<<endl; - - double trackSagVal=trackSagitta; - if (isideAC==0) trackSagVal*=-1.; - double trackSagNormVal=1.e-6*trackSagVal/qOverP; - if (trackSagNormVal<3.&&trackSagNormVal>-3.) { - beeHists [isideAC][ieta][iphi]->Fill(beePosX,beePosY,trackSagNormVal); - beeNTrksHists[isideAC][ieta][iphi]->Fill(beePosX,beePosY); - } - trackSag->Fill(trackSagitta); - trackSagNorm->Fill(trackSagNormVal); - for (int ires=firstBEERes;ires<lastBEERes;ires++) { - beeRes[isideAC][ieta][iphi]->Fill(residuals[ires]); - } + const int NXBINS = 15; + const int NYBINS = 15; + + TFile* outputfile = new TFile("out_iter0.root", "RECREATE"); + + TH1F* trackSag = new TH1F("trackSag", "trackSag", 100, -150., 150.); + TH1F* trackSagNorm = new TH1F("trackSagNorm", "trackSagNorm", 100, -3., 3.); + + TH1F**** beeRes = new TH1F***[2]; + TH1F**** eelRes = new TH1F***[2]; + TH2F**** beeHists = new TH2F***[2]; + TH2F**** beeHistsAvg = new TH2F***[2]; + TH2F**** beeNTrksHists = new TH2F***[2]; + string*** hnames = new string**[2]; + for (int isideAC = 0; isideAC < 2; isideAC++) { + beeRes[isideAC] = new TH1F**[2]; + eelRes[isideAC] = new TH1F**[2]; + beeHists[isideAC] = new TH2F**[2]; + beeHistsAvg[isideAC] = new TH2F**[2]; + beeNTrksHists[isideAC] = new TH2F**[2]; + hnames[isideAC] = new string*[2]; + for (int ieta = 0; ieta < 2; ieta++) { + beeRes[isideAC][ieta] = new TH1F*[8]; + eelRes[isideAC][ieta] = new TH1F*[8]; + beeHists[isideAC][ieta] = new TH2F*[8]; + beeHistsAvg[isideAC][ieta] = new TH2F*[8]; + beeNTrksHists[isideAC][ieta] = new TH2F*[8]; + hnames[isideAC][ieta] = new string[8]; + for (int iphi = 0; iphi < 8; iphi++) { + stringstream hname; + hname << "BEE" << ieta + 1; + if (isideAC == 0) + hname << "A"; + else + hname << "C"; + hname << setfill('0') << setw(2) << (iphi + 1) * 2; + hnames[isideAC][ieta][iphi] = hname.str(); + beeHists[isideAC][ieta][iphi] = + new TH2F(hname.str().c_str(), hname.str().c_str(), NXBINS, -400., 400., NYBINS, -700., 700.); + beeHistsAvg[isideAC][ieta][iphi] = + new TH2F((hname.str() + "_avg").c_str(), (hname.str() + "_avg").c_str(), NXBINS, -400., 400., NYBINS, -700., 700.); + beeNTrksHists[isideAC][ieta][iphi] = + new TH2F((hname.str() + "_ntrks").c_str(), (hname.str() + "_ntrks").c_str(), NXBINS, -400., 400., NYBINS, -700., 700.); + + beeRes[isideAC][ieta][iphi] = new TH1F((hname.str() + "_res").c_str(), (hname.str() + "_res").c_str(), 100, -1., 1.); + stringstream eelname; + eelname << "EEL" << ieta + 1; + if (isideAC == 0) + eelname << "A"; + else + eelname << "C"; + eelname << setfill('0') << setw(2) << (iphi + 1) * 2 - 1; + eelRes[isideAC][ieta][iphi] = new TH1F((eelname.str() + "_res").c_str(), (eelname.str() + "_res").c_str(), 100, -1., 1.); + } + } } - if (eelName!="") { - int stPhi=chNames.stPhi(eelName); - int stEta=chNames.stEta(eelName); - int isideAC=(stEta>0)?0:1; - int ieta=std::abs(stEta)-1; - int iphi=stPhi-1; - for (int ires=firstEELRes;ires<lastEELRes;ires++) { - eelRes[isideAC][ieta][iphi]->Fill(residuals[ires]); - } + + ChamberNames chNames("chambers.txt"); + + TChain* tree = new TChain("MuonTrackPreProcessor"); + tree->Add("/tmp/roberth/user.roberth.TMU15GEV.20101119_EE_iter0_V1.110216012437/iter0/*root*"); + + double qOverP, trackSagitta; + double beePosX, beePosY; + int nChambers; + int *chamberId(new int[50]), *resIndex(new int[50]); + int nresiduals; + double* residuals(new double[100]); + tree->SetBranchAddress("qOverP", &qOverP); + tree->SetBranchAddress("trackSagitta", &trackSagitta); + tree->SetBranchAddress("BEEPosX", &beePosX); + tree->SetBranchAddress("BEEPosY", &beePosY); + tree->SetBranchAddress("nChambers", &nChambers); + tree->SetBranchAddress("chamberId", chamberId); + tree->SetBranchAddress("resIndex", resIndex); + tree->SetBranchAddress("nresiduals", &nresiduals); + tree->SetBranchAddress("residuals", residuals); + + for (int ientry = 0; ientry < (int)tree->GetEntries(); ientry++) { + if (ientry % 100000 == 0) cout << "ientry: " << ientry << endl; + tree->GetEntry(ientry); + if (beePosX < -9998.) continue; + + // cout<<"ientry: "<<ientry<<endl; + std::string beeName = ""; + std::string eelName = ""; + int firstBEERes(0), lastBEERes(0); + int firstEELRes(0), lastEELRes(0); + for (int ich = 0; ich < nChambers; ich++) { + int id = chamberId[ich]; + std::string name = chNames.chamberName(id); + if (name.substr(0, 3) == "BEE") { + beeName = name; + firstBEERes = resIndex[ich]; + lastBEERes = (ich + 1 < nChambers) ? resIndex[ich + 1] : nresiduals; + } + if (name.substr(0, 3) == "EEL") { + eelName = name; + firstEELRes = resIndex[ich]; + lastEELRes = (ich + 1 < nChambers) ? resIndex[ich + 1] : nresiduals; + } + // cout<<"name: "<<name<<endl; + } + + // remove tracks not passing selection in MuonTrackPreProcessor + if (beeName == "" && eelName == "") { continue; } + + if (beeName != "") { + int stPhi = chNames.stPhi(beeName); + int stEta = chNames.stEta(beeName); + int isideAC = (stEta > 0) ? 0 : 1; + int ieta = std::abs(stEta) - 1; + int iphi = stPhi - 1; + // cout<<"isideAC: "<<isideAC<<", ieta: "<<ieta<<", stPhi: "<<stPhi<<", iphi: "<<iphi<<endl; + + double trackSagVal = trackSagitta; + if (isideAC == 0) trackSagVal *= -1.; + double trackSagNormVal = 1.e-6 * trackSagVal / qOverP; + if (trackSagNormVal < 3. && trackSagNormVal > -3.) { + beeHists[isideAC][ieta][iphi]->Fill(beePosX, beePosY, trackSagNormVal); + beeNTrksHists[isideAC][ieta][iphi]->Fill(beePosX, beePosY); + } + trackSag->Fill(trackSagitta); + trackSagNorm->Fill(trackSagNormVal); + for (int ires = firstBEERes; ires < lastBEERes; ires++) { beeRes[isideAC][ieta][iphi]->Fill(residuals[ires]); } + } + if (eelName != "") { + int stPhi = chNames.stPhi(eelName); + int stEta = chNames.stEta(eelName); + int isideAC = (stEta > 0) ? 0 : 1; + int ieta = std::abs(stEta) - 1; + int iphi = stPhi - 1; + for (int ires = firstEELRes; ires < lastEELRes; ires++) { eelRes[isideAC][ieta][iphi]->Fill(residuals[ires]); } + } } - } - - TCanvas* canv=new TCanvas("canv","canv"); - canv->SetFillColor(10); - - trackSag->Draw(); - canv->Print("trackSag.eps"); - trackSagNorm->Draw(); - canv->Print("trackSagNorm.eps"); - - outputfile->cd(); - trackSag->Write(); - trackSagNorm->Write(); - - TCanvas* canvres=new TCanvas("canvres","canvres"); - canvres->SetFillColor(10); - - for (int isideAC=0;isideAC<2;isideAC++) { - for (int iphi=0;iphi<8;iphi++) { - //for (int isideAC=0;isideAC<1;isideAC++) { - //for (int iphi=7;iphi<8;iphi++) { - double max=-999.; - double min=999.; - canv->Clear(); - canv->Divide(1,2); - for (int ieta=0;ieta<2;ieta++) { - for (int ix=0;ix<NXBINS;ix++) { - for (int iy=0;iy<NYBINS;iy++) { - double ntrks=beeNTrksHists[isideAC][ieta][iphi]->GetBinContent(ix+1,iy+1); - - if (ntrks>0) { - double val=beeHists[isideAC][ieta][iphi]->GetBinContent(ix+1,iy+1)/ntrks; - if (val>max) max=val; if (val<min) min=val; - beeHistsAvg[isideAC][ieta][iphi]->SetBinContent(ix+1,iy+1,val); - } - //else - //beeHists[isideAC][ieta][iphi]->SetBinContent(ix+1,iy+1,-9999.); - } - } - canvres->cd(); - canvres->Clear(); - //gStyle->SetOptStat(1111111); - //gStyle->SetOptFit(11111); - beeRes[isideAC][ieta][iphi]->Draw(); - beeRes[isideAC][ieta][iphi]->Fit("gaus","Q"); - outputfile->cd(); - beeRes[isideAC][ieta][iphi]->Write(); - canvres->Update(); - stringstream canvresname; - canvresname<<"BEERes_"<<ieta+1; - if (isideAC==0) canvresname<<"A"; else canvresname<<"C"; - canvresname<<iphi+1<<".eps"; - canvres->Print(canvresname.str().c_str()); - //gStyle->SetOptStat(0); - //gStyle->SetOptFit(0); - } - for (int ieta=0;ieta<2;ieta++) { - canv->cd(2-ieta); - beeHistsAvg[isideAC][ieta][iphi]->SetAxisRange(-3.,3.,"Z"); - beeHistsAvg[isideAC][ieta][iphi]->Draw("colz"); - outputfile->cd(); - beeHistsAvg[isideAC][ieta][iphi]->Write(); - } - std::stringstream canvname; - canvname<<"beeTrackSag_"; - if (isideAC==0) canvname<<"A"; else canvname<<"C"; - canvname<<"_"<<iphi+1<<".eps"; - canv->Print(canvname.str().c_str()); - + + TCanvas* canv = new TCanvas("canv", "canv"); + canv->SetFillColor(10); + + trackSag->Draw(); + canv->Print("trackSag.eps"); + trackSagNorm->Draw(); + canv->Print("trackSagNorm.eps"); + + outputfile->cd(); + trackSag->Write(); + trackSagNorm->Write(); + + TCanvas* canvres = new TCanvas("canvres", "canvres"); + canvres->SetFillColor(10); + + for (int isideAC = 0; isideAC < 2; isideAC++) { + for (int iphi = 0; iphi < 8; iphi++) { + // for (int isideAC=0;isideAC<1;isideAC++) { + // for (int iphi=7;iphi<8;iphi++) { + double max = -999.; + double min = 999.; + canv->Clear(); + canv->Divide(1, 2); + for (int ieta = 0; ieta < 2; ieta++) { + for (int ix = 0; ix < NXBINS; ix++) { + for (int iy = 0; iy < NYBINS; iy++) { + double ntrks = beeNTrksHists[isideAC][ieta][iphi]->GetBinContent(ix + 1, iy + 1); + + if (ntrks > 0) { + double val = beeHists[isideAC][ieta][iphi]->GetBinContent(ix + 1, iy + 1) / ntrks; + if (val > max) max = val; + if (val < min) min = val; + beeHistsAvg[isideAC][ieta][iphi]->SetBinContent(ix + 1, iy + 1, val); + } + // else + // beeHists[isideAC][ieta][iphi]->SetBinContent(ix+1,iy+1,-9999.); + } + } + canvres->cd(); + canvres->Clear(); + // gStyle->SetOptStat(1111111); + // gStyle->SetOptFit(11111); + beeRes[isideAC][ieta][iphi]->Draw(); + beeRes[isideAC][ieta][iphi]->Fit("gaus", "Q"); + outputfile->cd(); + beeRes[isideAC][ieta][iphi]->Write(); + canvres->Update(); + stringstream canvresname; + canvresname << "BEERes_" << ieta + 1; + if (isideAC == 0) + canvresname << "A"; + else + canvresname << "C"; + canvresname << iphi + 1 << ".eps"; + canvres->Print(canvresname.str().c_str()); + // gStyle->SetOptStat(0); + // gStyle->SetOptFit(0); + } + for (int ieta = 0; ieta < 2; ieta++) { + canv->cd(2 - ieta); + beeHistsAvg[isideAC][ieta][iphi]->SetAxisRange(-3., 3., "Z"); + beeHistsAvg[isideAC][ieta][iphi]->Draw("colz"); + outputfile->cd(); + beeHistsAvg[isideAC][ieta][iphi]->Write(); + } + std::stringstream canvname; + canvname << "beeTrackSag_"; + if (isideAC == 0) + canvname << "A"; + else + canvname << "C"; + canvname << "_" << iphi + 1 << ".eps"; + canv->Print(canvname.str().c_str()); + } } - } - outputfile->Close(); + outputfile->Close(); } diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/plotCorr.C b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/plotCorr.C index 58474f7bf1f1f1b636270b7236967371ba2f567a..2f1f1e05c7c7ca1a68193de23db39f32da7d3812 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/plotCorr.C +++ b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/plotCorr.C @@ -2,397 +2,438 @@ Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ -#include "TFile.h" -#include "TH1F.h" -#include "TF1.h" +#include <dirent.h> +#include <stdlib.h> + +#include <cmath> +#include <iostream> +#include <sstream> +#include <vector> + #include "TCanvas.h" -#include "TStyle.h" -#include "TGraphErrors.h" -#include "TText.h" -#include "TLegend.h" #include "TChain.h" +#include "TF1.h" +#include "TFile.h" +#include "TGraphErrors.h" +#include "TH1F.h" #include "TH2F.h" +#include "TLegend.h" #include "TProfile.h" - -#include <vector> -#include <iostream> -#include <dirent.h> -#include <sstream> -#include <stdlib.h> -#include <cmath> +#include "TStyle.h" +#include "TText.h" void getCorrections(); double** corrX; double** corrY; -int main() -{ - - gStyle->SetPalette(1,0); - - getCorrections(); - - TChain* tree=new TChain("unbiasedMuonResiduals"); - - std::string dir="/tmp/roberth/user10.RobertHarrington.data10_7TeV.allRuns.physics_MuonswBeam.merge.DESD_SGLMU.r1299_p165.UnbiasedRes.iPat.V22"; - - tree->Add((dir+"/*root").c_str()); - - int nPixHits; - int nSCTHits; - int nTRTHits; - int nCSCHits; - int nMDTHits; - - int author; - - int hIndex; - int phiSector; - int isEndcap; - int identifier; - int isCSide; - - int detType; - - int stName; - int stPhi; - int stEta; - - double momentum; - double charge; - double d0; - double z0; - double phi0; - double theta; - double eta; - double calEnergyLoss; - double calEnergyLossErr; - double materialOnTrack; - - double dR; - double dZlocal; - double dXlocal; - double dYlocal; - double dXlocalAngle; - double dYlocalAngle; - - double dXglobal; - double dYglobal; - double dZglobal; - double dXglobalAngle; - double dYglobalAngle; - double dZglobalAngle; - - tree->SetBranchAddress("nPixHits", &nPixHits); - tree->SetBranchAddress("nSCTHits", &nSCTHits); - tree->SetBranchAddress("nTRTHits", &nTRTHits); - tree->SetBranchAddress("nCSCHits", &nCSCHits); - tree->SetBranchAddress("nMDTHits", &nMDTHits); - - tree->SetBranchAddress("author", &author); - - tree->SetBranchAddress("hIndex", &hIndex); - tree->SetBranchAddress("phiSector", &phiSector); - tree->SetBranchAddress("isEndcap", &isEndcap); - tree->SetBranchAddress("identifier", &identifier); - tree->SetBranchAddress("isCSide", &isCSide); - tree->SetBranchAddress("detType", &detType); - - tree->SetBranchAddress("stName", &stName); - tree->SetBranchAddress("stPhi", &stPhi); - tree->SetBranchAddress("stEta", &stEta); - - tree->SetBranchAddress("momentum", &momentum); - tree->SetBranchAddress("charge", &charge); - tree->SetBranchAddress("d0", &d0); - tree->SetBranchAddress("z0", &z0); - tree->SetBranchAddress("phi0", &phi0); - tree->SetBranchAddress("theta", &theta); - tree->SetBranchAddress("eta", &eta); - - tree->SetBranchAddress("calEnergyLoss", &calEnergyLoss); - tree->SetBranchAddress("calEnergyLossErr", &calEnergyLossErr); - tree->SetBranchAddress("materialOnTrack", &materialOnTrack); - - tree->SetBranchAddress("dR", &dR); - tree->SetBranchAddress("dZlocal", &dZlocal); - tree->SetBranchAddress("dXlocal", &dXlocal); - tree->SetBranchAddress("dYlocal", &dYlocal); - tree->SetBranchAddress("dXlocalAngle", &dXlocalAngle); - tree->SetBranchAddress("dYlocalAngle", &dYlocalAngle); - tree->SetBranchAddress("dXglobal", &dXglobal); - tree->SetBranchAddress("dYglobal", &dYglobal); - tree->SetBranchAddress("dZglobal", &dZglobal); - - int itrk=0; - int icharge=0; - int isideAC=0; - - int NVAR=4; - std::string histnames[NVAR]={"Matl", - "CaloEnergy", - "CaloEnergyErr" - "Momentum"}; - std::string histtitles[NVAR]={"Material On Track", - "Calorimeter Energy Loss", - "Calorimeter Energy Loss Error", - "Momentum"}; - int histnbins [NVAR] ={ 30, 30, 30, 35}; - double histlimits[NVAR][2]={{140.,260.},{3200.,4200.},{400.,2000.},{0.,70.}}; - - std::string varnames[NVAR]={"materialOnTrack"}; - const int NBEC=2; - const int NPHI=4; - TH2F**** yVVar = new TH2F***[NVAR]; - for (int ivar=0;ivar<NVAR;ivar++) { - yVVar[ivar]=new TH2F***[NBEC]; - for (int ibec=0;ibec<NBEC;ibec++) { - yVVar[ivar][ibec]=new TH2F**[NPHI]; - for (int iphi=0;iphi<NPHI;iphi++) { - std::stringstream phiss; phiss<<iphi+1; - std::string histname=histnames[ivar]+becStr[ibec]+phiss.str(); - std::string histtitle=histtitles[ivar]+"_" - yVVAr[ivar][ibec][iphi]=new TH2F(histname.c_str(),histtitles.c_str(),histnbins[ivar],histlimits[ivar][0],histlimits[ivar][1]); - } - } - } - - TH2F* yVMatlA=new TH2F("yVMatlA","yVMatlA",30,140.,260.,100,-50.,50.); - TH2F* yVCaloEnergyA =new TH2F("yVCaloEnergyA", "yVCaloEnergyA", - 30,3200.,4200.,100,-50.,50.); - TH2F* yVCaloEnergyErrA =new TH2F("yVCaloEnergyErrA","yVCaloEnergyErrA", - 30, 400.,2000.,100,-50.,50.); - TH2F* yVMomentumA =new TH2F("yVMomentumA","yVMomentumA", - 35, 0.,70.,100,-50.,50.); - TH1F* hMomPosA = new TH1F("hMomPosA", "MomentumPosChargeA",35,0.,70.); - TH1F* hMomNegA = new TH1F("hMomNegA", "MomentumNegChargeA",35,0.,70.); - - TH2F* yVMatlC=new TH2F("yVMatlC","yVMatlC",100,140.,260.,100,-50.,50.); - TH2F* yVCaloEnergyC =new TH2F("yVCaloEnergyC", "yVCaloEnergyC", - 30,3200.,4200.,100,-50.,50.); - TH2F* yVCaloEnergyErrC =new TH2F("yVCaloEnergyErrC","yVCaloEnergyErrC", - 30, 400.,2000.,100,-50.,50.); - TH2F* yVMomentumC =new TH2F("yVMomentumC","yVMomentumC", - 30, 0.,70.,100,-50.,50.); - TH1F* hMomPosC = new TH1F("hMomPosC", "MomentumPosChargeC",35,0.,70.); - TH1F* hMomNegC = new TH1F("hMomNegC", "MomentumNegChargeC",35,0.,70.); - - int nentries=tree->GetEntries(); - for (int ientry=0;ientry<nentries;ientry++) { - tree->GetEntry(ientry); - if (nSCTHits<6||nCSCHits<3) continue; - if (detType!=1) continue; - if (hIndex!=0) continue; - if (isCSide==0) { - double corr=(stPhi%2)?6.271:-0.238; - corr += corrY[0][stPhi-1]; - double dY=dYlocal+corr; - yVMatlA->Fill(materialOnTrack,dY); - yVCaloEnergyA->Fill(calEnergyLoss,dY); - yVCaloEnergyErrA->Fill(calEnergyLossErr,dY); - yVMomentumA->Fill(momentum,dY); - if (charge>0.) hMomPosA->Fill(momentum); - else hMomNegA->Fill(momentum); +int main() { + gStyle->SetPalette(1, 0); + + getCorrections(); + + TChain* tree = new TChain("unbiasedMuonResiduals"); + + std::string dir = + "/tmp/roberth/user10.RobertHarrington.data10_7TeV.allRuns.physics_MuonswBeam.merge.DESD_SGLMU.r1299_p165.UnbiasedRes.iPat.V22"; + + tree->Add((dir + "/*root").c_str()); + + int nPixHits; + int nSCTHits; + int nTRTHits; + int nCSCHits; + int nMDTHits; + + int author; + + int hIndex; + int phiSector; + int isEndcap; + int identifier; + int isCSide; + + int detType; + + int stName; + int stPhi; + int stEta; + + double momentum; + double charge; + double d0; + double z0; + double phi0; + double theta; + double eta; + double calEnergyLoss; + double calEnergyLossErr; + double materialOnTrack; + + double dR; + double dZlocal; + double dXlocal; + double dYlocal; + double dXlocalAngle; + double dYlocalAngle; + + double dXglobal; + double dYglobal; + double dZglobal; + double dXglobalAngle; + double dYglobalAngle; + double dZglobalAngle; + + tree->SetBranchAddress("nPixHits", &nPixHits); + tree->SetBranchAddress("nSCTHits", &nSCTHits); + tree->SetBranchAddress("nTRTHits", &nTRTHits); + tree->SetBranchAddress("nCSCHits", &nCSCHits); + tree->SetBranchAddress("nMDTHits", &nMDTHits); + + tree->SetBranchAddress("author", &author); + + tree->SetBranchAddress("hIndex", &hIndex); + tree->SetBranchAddress("phiSector", &phiSector); + tree->SetBranchAddress("isEndcap", &isEndcap); + tree->SetBranchAddress("identifier", &identifier); + tree->SetBranchAddress("isCSide", &isCSide); + tree->SetBranchAddress("detType", &detType); + + tree->SetBranchAddress("stName", &stName); + tree->SetBranchAddress("stPhi", &stPhi); + tree->SetBranchAddress("stEta", &stEta); + + tree->SetBranchAddress("momentum", &momentum); + tree->SetBranchAddress("charge", &charge); + tree->SetBranchAddress("d0", &d0); + tree->SetBranchAddress("z0", &z0); + tree->SetBranchAddress("phi0", &phi0); + tree->SetBranchAddress("theta", &theta); + tree->SetBranchAddress("eta", &eta); + + tree->SetBranchAddress("calEnergyLoss", &calEnergyLoss); + tree->SetBranchAddress("calEnergyLossErr", &calEnergyLossErr); + tree->SetBranchAddress("materialOnTrack", &materialOnTrack); + + tree->SetBranchAddress("dR", &dR); + tree->SetBranchAddress("dZlocal", &dZlocal); + tree->SetBranchAddress("dXlocal", &dXlocal); + tree->SetBranchAddress("dYlocal", &dYlocal); + tree->SetBranchAddress("dXlocalAngle", &dXlocalAngle); + tree->SetBranchAddress("dYlocalAngle", &dYlocalAngle); + tree->SetBranchAddress("dXglobal", &dXglobal); + tree->SetBranchAddress("dYglobal", &dYglobal); + tree->SetBranchAddress("dZglobal", &dZglobal); + + int itrk = 0; + int icharge = 0; + int isideAC = 0; + + int NVAR = 4; + std::string histnames[NVAR] = {"Matl", "CaloEnergy", + "CaloEnergyErr" + "Momentum"}; + std::string histtitles[NVAR] = {"Material On Track", "Calorimeter Energy Loss", "Calorimeter Energy Loss Error", "Momentum"}; + int histnbins[NVAR] = {30, 30, 30, 35}; + double histlimits[NVAR][2] = {{140., 260.}, {3200., 4200.}, {400., 2000.}, {0., 70.}}; + + std::string varnames[NVAR] = {"materialOnTrack"}; + const int NBEC = 2; + const int NPHI = 4; + TH2F**** yVVar = new TH2F***[NVAR]; + for (int ivar = 0; ivar < NVAR; ivar++) { + yVVar[ivar] = new TH2F***[NBEC]; + for (int ibec = 0; ibec < NBEC; ibec++) { + yVVar[ivar][ibec] = new TH2F**[NPHI]; + for (int iphi = 0; iphi < NPHI; iphi++) { + std::stringstream phiss; + phiss << iphi + 1; + std::string histname = histnames[ivar] + becStr[ibec] + phiss.str(); + std::string histtitle = + histtitles[ivar] + "_" yVVAr[ivar][ibec][iphi] = + new TH2F(histname.c_str(), histtitles.c_str(), histnbins[ivar], histlimits[ivar][0], histlimits[ivar][1]); + } + } } - else { - double corr=(stPhi%2)?6.271:-0.238; - corr += corrY[1][stPhi-1]; - double dY=dYlocal+corr; - yVMatlC->Fill(materialOnTrack,dY); - yVCaloEnergyC->Fill(calEnergyLoss,dY); - yVCaloEnergyErrC->Fill(calEnergyLossErr,dY); - yVMomentumC->Fill(momentum,dY); - if (charge>0.) hMomPosC->Fill(momentum); - else hMomNegC->Fill(momentum); + TH2F* yVMatlA = new TH2F("yVMatlA", "yVMatlA", 30, 140., 260., 100, -50., 50.); + TH2F* yVCaloEnergyA = new TH2F("yVCaloEnergyA", "yVCaloEnergyA", 30, 3200., 4200., 100, -50., 50.); + TH2F* yVCaloEnergyErrA = new TH2F("yVCaloEnergyErrA", "yVCaloEnergyErrA", 30, 400., 2000., 100, -50., 50.); + TH2F* yVMomentumA = new TH2F("yVMomentumA", "yVMomentumA", 35, 0., 70., 100, -50., 50.); + TH1F* hMomPosA = new TH1F("hMomPosA", "MomentumPosChargeA", 35, 0., 70.); + TH1F* hMomNegA = new TH1F("hMomNegA", "MomentumNegChargeA", 35, 0., 70.); + + TH2F* yVMatlC = new TH2F("yVMatlC", "yVMatlC", 100, 140., 260., 100, -50., 50.); + TH2F* yVCaloEnergyC = new TH2F("yVCaloEnergyC", "yVCaloEnergyC", 30, 3200., 4200., 100, -50., 50.); + TH2F* yVCaloEnergyErrC = new TH2F("yVCaloEnergyErrC", "yVCaloEnergyErrC", 30, 400., 2000., 100, -50., 50.); + TH2F* yVMomentumC = new TH2F("yVMomentumC", "yVMomentumC", 30, 0., 70., 100, -50., 50.); + TH1F* hMomPosC = new TH1F("hMomPosC", "MomentumPosChargeC", 35, 0., 70.); + TH1F* hMomNegC = new TH1F("hMomNegC", "MomentumNegChargeC", 35, 0., 70.); + + int nentries = tree->GetEntries(); + for (int ientry = 0; ientry < nentries; ientry++) { + tree->GetEntry(ientry); + if (nSCTHits < 6 || nCSCHits < 3) continue; + if (detType != 1) continue; + if (hIndex != 0) continue; + if (isCSide == 0) { + double corr = (stPhi % 2) ? 6.271 : -0.238; + corr += corrY[0][stPhi - 1]; + double dY = dYlocal + corr; + yVMatlA->Fill(materialOnTrack, dY); + yVCaloEnergyA->Fill(calEnergyLoss, dY); + yVCaloEnergyErrA->Fill(calEnergyLossErr, dY); + yVMomentumA->Fill(momentum, dY); + if (charge > 0.) + hMomPosA->Fill(momentum); + else + hMomNegA->Fill(momentum); + } else { + double corr = (stPhi % 2) ? 6.271 : -0.238; + corr += corrY[1][stPhi - 1]; + double dY = dYlocal + corr; + yVMatlC->Fill(materialOnTrack, dY); + yVCaloEnergyC->Fill(calEnergyLoss, dY); + yVCaloEnergyErrC->Fill(calEnergyLossErr, dY); + yVMomentumC->Fill(momentum, dY); + if (charge > 0.) + hMomPosC->Fill(momentum); + else + hMomNegC->Fill(momentum); + } } - } - - TCanvas* canv=new TCanvas("canv","canv"); - canv->SetFillColor(10); - - // A-side - yVMatlA->GetXaxis()->SetTitle("material on track (X0)"); - yVMatlA->GetYaxis()->SetTitle("#Delta y_{local}"); - yVMatlA->Draw("COLZ"); - - canv->Print("yVMatl_A.eps"); - - canv->Clear(); canv->SetFillColor(10); - yVMatlA->ProfileX()->Draw(); - canv->Print("yVMatlProfX_A.eps"); - - canv->Clear(); canv->SetFillColor(10); - yVCaloEnergyA->GetXaxis()->SetTitle("energy loss in calorimeter (MeV)"); - yVCaloEnergyA->GetYaxis()->SetTitle("#Delta y_{local}"); - yVCaloEnergyA->Draw("COLZ"); - - canv->Print("yVCaloEnergy_A.eps"); - - canv->Clear(); canv->SetFillColor(10); - yVCaloEnergyA->ProfileX()->Draw(); - canv->Print("yVCaloEnergyProfX_A.eps"); - - canv->Clear(); canv->SetFillColor(10); - yVCaloEnergyErrA->GetXaxis()->SetTitle("error on energy loss in calorimeter (MeV)"); - yVCaloEnergyErrA->GetYaxis()->SetTitle("#Delta y_{local}"); - yVCaloEnergyErrA->Draw("COLZ"); - - canv->Clear(); canv->SetFillColor(10); - canv->Print("yVCaloEnergyErr_A.eps"); - - canv->Clear(); canv->SetFillColor(10); - yVCaloEnergyErrA->ProfileX()->Draw(); - - canv->Print("yVCaloEnergyErrProfX_A.eps"); - - canv->Clear(); canv->SetFillColor(10); - yVMomentumA->GetXaxis()->SetTitle("momentum (GeV)"); - yVMomentumA->GetYaxis()->SetTitle("#Delta y_{local}"); - yVMomentumA->Draw("COLZ"); - - canv->Print("yVMomentum_A.eps"); - - canv->Clear(); canv->SetFillColor(10); - yVMomentumA->ProfileX()->Draw(); - canv->Print("yVMomentumProfX_A.eps"); - - - - // C-side - canv->Clear(); canv->SetFillColor(10); - yVMatlC->GetXaxis()->SetTitle("material on track (X0)"); - yVMatlC->GetYaxis()->SetTitle("#Delta y_{local}"); - yVMatlC->Draw("COLZ"); - - canv->Print("yVMatl_C.eps"); - - canv->Clear(); canv->SetFillColor(10); - yVMatlC->ProfileX()->Draw(); - canv->Print("yVMatlProfX_C.eps"); - - canv->Clear(); canv->SetFillColor(10); - yVCaloEnergyC->GetXaxis()->SetTitle("energy loss in calorimeter (MeV)"); - yVCaloEnergyC->GetYaxis()->SetTitle("#Delta y_{local}"); - yVCaloEnergyC->Draw("COLZ"); - - canv->Print("yVCaloEnergy_C.eps"); - - canv->Clear(); canv->SetFillColor(10); - yVCaloEnergyC->ProfileX()->Draw(); - canv->Print("yVCaloEnergyProfX_C.eps"); - - canv->Clear(); canv->SetFillColor(10); - yVCaloEnergyErrC->GetXaxis()->SetTitle("error on energy loss in calorimeter (MeV)"); - yVCaloEnergyErrC->GetYaxis()->SetTitle("#Delta y_{local}"); - yVCaloEnergyErrC->Draw("COLZ"); - - canv->Print("yVCaloEnergyErr_AC.eps"); - - canv->Clear(); canv->SetFillColor(10); - yVCaloEnergyErrC->ProfileX()->Draw(); - canv->Print("yVCaloEnergyErrProfX_C.eps"); - - canv->Clear(); canv->SetFillColor(10); - yVMomentumC->GetXaxis()->SetTitle("momentum (GeV)"); - yVMomentumC->GetYaxis()->SetTitle("#Delta y_{local}"); - yVMomentumC->Draw("COLZ"); - - canv->Print("yVMomentum_C.eps"); - - canv->Clear(); canv->SetFillColor(10); - yVMomentumC->ProfileX()->Draw(); - canv->Print("yVMomentumProfX_C.eps"); - - // momentum plots - canv->Clear(); canv->SetFillColor(10); - gStyle->SetOptStat(0); - hMomPosA->SetLineColor(kBlue); - hMomNegA->SetLineColor(kRed); - double max=0.; - if (hMomPosA->GetMaximum()>max) max=hMomPosA->GetMaximum(); - if (hMomNegA->GetMaximum()>max) max=hMomNegA->GetMaximum(); - hMomPosA->SetMaximum(max); - hMomPosA->SetTitle("Momentum for Positive Muons, A-Side"); - hMomNegA->SetTitle("Momentum for Negative Muons, A-Side"); - hMomPosA->GetXaxis()->SetTitle("momentum (GeV)"); - hMomNegA->GetXaxis()->SetTitle("momentum (GeV)"); - hMomPosA->Draw(); - hMomNegA->Draw("same"); - - TLegend* legA=new TLegend(.75,.6,.99,.95); - legA->AddEntry(hMomPosC,"positive charge","L"); - legA->AddEntry(hMomNegC,"negative charge","L"); - legA->Draw(); - canv->Print("momentum_A.eps"); - - canv->Clear(); canv->SetFillColor(10); - hMomPosC->SetLineColor(kBlue); - hMomNegC->SetLineColor(kRed); - max=0.; - if (hMomPosC->GetMaximum()>max) max=hMomPosC->GetMaximum(); - if (hMomNegC->GetMaximum()>max) max=hMomNegC->GetMaximum(); - hMomPosC->SetMaximum(max); - hMomPosC->SetTitle("Momentum for Positive Muons, C-Side"); - hMomNegC->SetTitle("Momentum for Negative Muons, C-Side"); - hMomPosC->GetXaxis()->SetTitle("muon momentum (GeV)"); - hMomNegC->GetXaxis()->SetTitle("muon momentum (GeV)"); - hMomPosC->Draw(); - hMomNegC->Draw("same"); - - TLegend* leg=new TLegend(.75,.6,.99,.95); - leg->AddEntry(hMomPosC,"positive charge","L"); - leg->AddEntry(hMomNegC,"negative charge","L"); - leg->Draw(); - canv->Print("momentum_C.eps"); - - delete canv; + + TCanvas* canv = new TCanvas("canv", "canv"); + canv->SetFillColor(10); + + // A-side + yVMatlA->GetXaxis()->SetTitle("material on track (X0)"); + yVMatlA->GetYaxis()->SetTitle("#Delta y_{local}"); + yVMatlA->Draw("COLZ"); + + canv->Print("yVMatl_A.eps"); + + canv->Clear(); + canv->SetFillColor(10); + yVMatlA->ProfileX()->Draw(); + canv->Print("yVMatlProfX_A.eps"); + + canv->Clear(); + canv->SetFillColor(10); + yVCaloEnergyA->GetXaxis()->SetTitle("energy loss in calorimeter (MeV)"); + yVCaloEnergyA->GetYaxis()->SetTitle("#Delta y_{local}"); + yVCaloEnergyA->Draw("COLZ"); + + canv->Print("yVCaloEnergy_A.eps"); + + canv->Clear(); + canv->SetFillColor(10); + yVCaloEnergyA->ProfileX()->Draw(); + canv->Print("yVCaloEnergyProfX_A.eps"); + + canv->Clear(); + canv->SetFillColor(10); + yVCaloEnergyErrA->GetXaxis()->SetTitle("error on energy loss in calorimeter (MeV)"); + yVCaloEnergyErrA->GetYaxis()->SetTitle("#Delta y_{local}"); + yVCaloEnergyErrA->Draw("COLZ"); + + canv->Clear(); + canv->SetFillColor(10); + canv->Print("yVCaloEnergyErr_A.eps"); + + canv->Clear(); + canv->SetFillColor(10); + yVCaloEnergyErrA->ProfileX()->Draw(); + + canv->Print("yVCaloEnergyErrProfX_A.eps"); + + canv->Clear(); + canv->SetFillColor(10); + yVMomentumA->GetXaxis()->SetTitle("momentum (GeV)"); + yVMomentumA->GetYaxis()->SetTitle("#Delta y_{local}"); + yVMomentumA->Draw("COLZ"); + + canv->Print("yVMomentum_A.eps"); + + canv->Clear(); + canv->SetFillColor(10); + yVMomentumA->ProfileX()->Draw(); + canv->Print("yVMomentumProfX_A.eps"); + + // C-side + canv->Clear(); + canv->SetFillColor(10); + yVMatlC->GetXaxis()->SetTitle("material on track (X0)"); + yVMatlC->GetYaxis()->SetTitle("#Delta y_{local}"); + yVMatlC->Draw("COLZ"); + + canv->Print("yVMatl_C.eps"); + + canv->Clear(); + canv->SetFillColor(10); + yVMatlC->ProfileX()->Draw(); + canv->Print("yVMatlProfX_C.eps"); + + canv->Clear(); + canv->SetFillColor(10); + yVCaloEnergyC->GetXaxis()->SetTitle("energy loss in calorimeter (MeV)"); + yVCaloEnergyC->GetYaxis()->SetTitle("#Delta y_{local}"); + yVCaloEnergyC->Draw("COLZ"); + + canv->Print("yVCaloEnergy_C.eps"); + + canv->Clear(); + canv->SetFillColor(10); + yVCaloEnergyC->ProfileX()->Draw(); + canv->Print("yVCaloEnergyProfX_C.eps"); + + canv->Clear(); + canv->SetFillColor(10); + yVCaloEnergyErrC->GetXaxis()->SetTitle("error on energy loss in calorimeter (MeV)"); + yVCaloEnergyErrC->GetYaxis()->SetTitle("#Delta y_{local}"); + yVCaloEnergyErrC->Draw("COLZ"); + + canv->Print("yVCaloEnergyErr_AC.eps"); + + canv->Clear(); + canv->SetFillColor(10); + yVCaloEnergyErrC->ProfileX()->Draw(); + canv->Print("yVCaloEnergyErrProfX_C.eps"); + + canv->Clear(); + canv->SetFillColor(10); + yVMomentumC->GetXaxis()->SetTitle("momentum (GeV)"); + yVMomentumC->GetYaxis()->SetTitle("#Delta y_{local}"); + yVMomentumC->Draw("COLZ"); + + canv->Print("yVMomentum_C.eps"); + + canv->Clear(); + canv->SetFillColor(10); + yVMomentumC->ProfileX()->Draw(); + canv->Print("yVMomentumProfX_C.eps"); + + // momentum plots + canv->Clear(); + canv->SetFillColor(10); + gStyle->SetOptStat(0); + hMomPosA->SetLineColor(kBlue); + hMomNegA->SetLineColor(kRed); + double max = 0.; + if (hMomPosA->GetMaximum() > max) max = hMomPosA->GetMaximum(); + if (hMomNegA->GetMaximum() > max) max = hMomNegA->GetMaximum(); + hMomPosA->SetMaximum(max); + hMomPosA->SetTitle("Momentum for Positive Muons, A-Side"); + hMomNegA->SetTitle("Momentum for Negative Muons, A-Side"); + hMomPosA->GetXaxis()->SetTitle("momentum (GeV)"); + hMomNegA->GetXaxis()->SetTitle("momentum (GeV)"); + hMomPosA->Draw(); + hMomNegA->Draw("same"); + + TLegend* legA = new TLegend(.75, .6, .99, .95); + legA->AddEntry(hMomPosC, "positive charge", "L"); + legA->AddEntry(hMomNegC, "negative charge", "L"); + legA->Draw(); + canv->Print("momentum_A.eps"); + + canv->Clear(); + canv->SetFillColor(10); + hMomPosC->SetLineColor(kBlue); + hMomNegC->SetLineColor(kRed); + max = 0.; + if (hMomPosC->GetMaximum() > max) max = hMomPosC->GetMaximum(); + if (hMomNegC->GetMaximum() > max) max = hMomNegC->GetMaximum(); + hMomPosC->SetMaximum(max); + hMomPosC->SetTitle("Momentum for Positive Muons, C-Side"); + hMomNegC->SetTitle("Momentum for Negative Muons, C-Side"); + hMomPosC->GetXaxis()->SetTitle("muon momentum (GeV)"); + hMomNegC->GetXaxis()->SetTitle("muon momentum (GeV)"); + hMomPosC->Draw(); + hMomNegC->Draw("same"); + + TLegend* leg = new TLegend(.75, .6, .99, .95); + leg->AddEntry(hMomPosC, "positive charge", "L"); + leg->AddEntry(hMomNegC, "negative charge", "L"); + leg->Draw(); + canv->Print("momentum_C.eps"); + + delete canv; } //________________________________________________________________________ -void getCorrections() -{ - corrX=new double*[2]; - corrY=new double*[2]; - for (int isideAC=0;isideAC<2;isideAC++) { - corrX[isideAC]=new double[16]; - corrY[isideAC]=new double[16]; - } - - corrX[1][0] =-3.461; corrY[1][0] =-4.018; - corrX[1][1] =-6.423; corrY[1][1] = 0.175; - corrX[1][2] =-1.489; corrY[1][2] =-4.203; - corrX[1][3] = 5.017; corrY[1][3] = 1.556; - corrX[1][4] = 0.399; corrY[1][4] =-5.492; - corrX[1][5] = 2.055; corrY[1][5] = 2.617; - corrX[1][6] =-2.488; corrY[1][6] =-8.192; - corrX[1][7] = 0.371; corrY[1][7] = 1.229; - corrX[1][8] = 9.458; corrY[1][8] =-0.195; - corrX[1][9] =-1.313; corrY[1][9] = 8.063; - corrX[1][10]= 2.331; corrY[1][10]= 2.441; - corrX[1][11]= 5.643; corrY[1][11]= 3.621; - corrX[1][12]= 3.188; corrY[1][12]=-0.424; - corrX[1][13]=-1.345; corrY[1][13]= 1.085; - corrX[1][14]= 0.514; corrY[1][14]=-1.253; - corrX[1][15]=-5.703; corrY[1][15]=-1.890; - - corrX[0][0] = 8.539; corrY[0][0] =-0.816; - corrX[0][1] = 9.112; corrY[0][1] =-3.194; - corrX[0][2] = 1.130; corrY[0][2] =-5.806; - corrX[0][3] = 0.036; corrY[0][3] =-7.465; - corrX[0][4] =-3.183; corrY[0][4] =-5.682; - corrX[0][5] = 1.104; corrY[0][5] =-3.657; - corrX[0][6] =-6.310; corrY[0][6] =-4.543; - corrX[0][7] = 1.029; corrY[0][7] =-0.199; - corrX[0][8] =-6.905; corrY[0][8] = 0.151; - corrX[0][9] =-0.549; corrY[0][9] = 0.457; - corrX[0][10]=-7.236; corrY[0][10]= 0.722; - corrX[0][11]= 0.905; corrY[0][11]= 2.924; - corrX[0][12]=-1.077; corrY[0][12]= 2.528; - corrX[0][13]= 7.075; corrY[0][13]= 3.093; - corrX[0][14]= 6.653; corrY[0][14]= 1.052; - corrX[0][15]= 6.904; corrY[0][15]= 0.666; - - return; +void getCorrections() { + corrX = new double*[2]; + corrY = new double*[2]; + for (int isideAC = 0; isideAC < 2; isideAC++) { + corrX[isideAC] = new double[16]; + corrY[isideAC] = new double[16]; + } + + corrX[1][0] = -3.461; + corrY[1][0] = -4.018; + corrX[1][1] = -6.423; + corrY[1][1] = 0.175; + corrX[1][2] = -1.489; + corrY[1][2] = -4.203; + corrX[1][3] = 5.017; + corrY[1][3] = 1.556; + corrX[1][4] = 0.399; + corrY[1][4] = -5.492; + corrX[1][5] = 2.055; + corrY[1][5] = 2.617; + corrX[1][6] = -2.488; + corrY[1][6] = -8.192; + corrX[1][7] = 0.371; + corrY[1][7] = 1.229; + corrX[1][8] = 9.458; + corrY[1][8] = -0.195; + corrX[1][9] = -1.313; + corrY[1][9] = 8.063; + corrX[1][10] = 2.331; + corrY[1][10] = 2.441; + corrX[1][11] = 5.643; + corrY[1][11] = 3.621; + corrX[1][12] = 3.188; + corrY[1][12] = -0.424; + corrX[1][13] = -1.345; + corrY[1][13] = 1.085; + corrX[1][14] = 0.514; + corrY[1][14] = -1.253; + corrX[1][15] = -5.703; + corrY[1][15] = -1.890; + + corrX[0][0] = 8.539; + corrY[0][0] = -0.816; + corrX[0][1] = 9.112; + corrY[0][1] = -3.194; + corrX[0][2] = 1.130; + corrY[0][2] = -5.806; + corrX[0][3] = 0.036; + corrY[0][3] = -7.465; + corrX[0][4] = -3.183; + corrY[0][4] = -5.682; + corrX[0][5] = 1.104; + corrY[0][5] = -3.657; + corrX[0][6] = -6.310; + corrY[0][6] = -4.543; + corrX[0][7] = 1.029; + corrY[0][7] = -0.199; + corrX[0][8] = -6.905; + corrY[0][8] = 0.151; + corrX[0][9] = -0.549; + corrY[0][9] = 0.457; + corrX[0][10] = -7.236; + corrY[0][10] = 0.722; + corrX[0][11] = 0.905; + corrY[0][11] = 2.924; + corrX[0][12] = -1.077; + corrY[0][12] = 2.528; + corrX[0][13] = 7.075; + corrY[0][13] = 3.093; + corrX[0][14] = 6.653; + corrY[0][14] = 1.052; + corrX[0][15] = 6.904; + corrY[0][15] = 0.666; + + return; } diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/plotres.cpp b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/plotres.cpp index cbd3cba380e29ede7fe3501ed3238f5b2d2d1191..660b6944bcc6a7701cf4eae770ce28fe5bc68560 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/plotres.cpp +++ b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/plotres.cpp @@ -2,344 +2,306 @@ Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ -#include "MuonFixedId.h" -#include "Tools.h" - -#include "TROOT.h" -#include "TStyle.h" +#include <TAxis.h> +#include <TCanvas.h> #include <TChain.h> -#include <TTree.h> +#include <TDecompBK.h> #include <TEventList.h> +#include <TF1.h> +#include <TGraph.h> +#include <TLegend.h> #include <TLorentzVector.h> #include <TMatrixDSym.h> -#include <TVectorD.h> -#include <TDecompBK.h> #include <TMatrixTSparse.h> -#include <TGraph.h> -#include <TCanvas.h> -#include <TF1.h> #include <TPaveText.h> -#include <TAxis.h> -#include "TFile.h" -#include "TH1F.h" -#include "TStyle.h" -#include "TLine.h" -#include <TLegend.h> #include <TString.h> +#include <TTree.h> +#include <TVectorD.h> -#include <iostream> +#include <cmath> +#include <fstream> #include <iomanip> +#include <iostream> +#include <map> +#include <set> #include <sstream> -#include <fstream> #include <string> -#include <map> -#include <cmath> #include <vector> -#include <set> + +#include "MuonFixedId.h" +#include "TFile.h" +#include "TH1F.h" +#include "TLine.h" +#include "TROOT.h" +#include "TStyle.h" +#include "Tools.h" using namespace MuonCalib; -map<TString,TH1*> getHistos(TChain* tree, TString combinetype); +map<TString, TH1*> getHistos(TChain* tree, TString combinetype); MuonFixedId* mid; -int m_xbins; +int m_xbins; double m_xmax; double m_xmin; -void help(const char *argv0) { - +void help(const char* argv0) { cerr << "Usage: " << argv0 << " [options] " << endl << "Options:" << endl - << " -o :\tOutput path" << endl + << " -o :\tOutput path" << endl << " -i :\tInputfiles" << endl - << " -l :\tLegend labels"<< endl + << " -l :\tLegend labels" << endl << " -c :\tHistogram colors " << endl << " -t :\tCombination type (Chamber,Tower,Sector,Side,BarrelEC,MS)" - << " -h :\tShow this message and quit" << endl - << "Multiple arguments for one option are passed via comma seperated lists (e.g. '-c 3,4')" - << endl << endl; + << " -h :\tShow this message and quit" << endl + << "Multiple arguments for one option are passed via comma seperated lists (e.g. '-c 3,4')" << endl + << endl; exit(1); } //_____________________________________________________________________________ -int main(int argc, char* argv[]) -{ - - //./plotres_x -c 3,4 -i MuonAlign_BXS2A4_notshifted_1.root,MuonAlign_BXS2A4_a1notshifted_1.root -o pics -l Perfect,Misaligned - - //---------------------------- - //-- Parse the command line -- - //---------------------------- - - extern char *optarg; - char c; - TString infilestr(""); - TString outputstr(""); - TString labelstr(""); - TString colorstr(""); - TString combinetype("Chamber"); //Chamber,Tower,Sector,Side,BarrelEC,MS - - while((c = getopt(argc, argv, "-ho:i:l:c:t:")) !=-1){ - switch(c){ - case 'o': - outputstr = optarg; - break; - case 'i': - infilestr = optarg; - break; - case 'l': - labelstr = optarg; - break; - case 'c': - colorstr = optarg; - break; - case 't': - combinetype = optarg; - break; - default: - cerr << "Help or unknown argument!" << endl; - help(argv[0]); - break; - } - } - - //--------------------------- - //-- Set and verify inputs -- - //--------------------------- - - vector<TString> filenames = Tools::getOptionVector<TString>(infilestr); - vector<TString> legendlabels = Tools::getOptionVector<TString>(labelstr); - vector<int> colors = Tools::getOptionVector<int>(colorstr); - TString directory = outputstr; - - - if(filenames.size()==0){ - cerr << "no imput files given, exiting..."<< endl; - exit(1); - } - if(filenames.size() != legendlabels.size()){ - cerr << "different number of inpufiles and legendnames,"<< endl - << "exiting..."<< endl; - exit(1); - } - if(filenames.size() != colors.size()){ - cerr << "different number of inpufiles and colors," << endl - << "exiting..."<< endl; - exit(1); - } - - - //--------- - //-- Run -- - //--------- - - TH1::SetDefaultSumw2(); - Tools::setStyle(); - //gStyle->SetOptStat(111); - //gStyle->SetOptStat(0); - - - //unsigned int m_combType = Chamber; - m_xbins = 100; - m_xmax = 0.5; - m_xmin = -1*m_xmax; - - bool saveplot = 1; - - // std::string directory=""; -// if (argc>1) { -// directory=string(argv[1]); -// } -// std::string iteration="0"; -// if (argc>2) { -// iteration=string(argv[2]); -// } -// std::cout<<"using input directory "<<directory<<std::endl; - - // stringstream rootname; -// if (BATCH) -// rootname<<directory<<"/MuonAlign_"<<directory<<"_b8_iter"<<iteration<<".root"; -// else -// rootname<<directory<<"/MuonAlign_"<<directory<<"_"<<iteration<<".root"; - - - mid=new MuonFixedId(0); - - // vector<TString> filenames; -// vector<TString> legendlabels; -// vector<int> colors; - -// TString directory = "pics"; - -// //filenames.push_back("BXS2A4_notshifted/MuonAlign_BXS2A4_notshifted_1.root"); -// //filenames.push_back("BXS2A4_a1notshifted/MuonAlign_BXS2A4_a1notshifted_1.root"); -// filenames.push_back("MuonAlign_BXS2A4_notshifted_1.root"); -// filenames.push_back("MuonAlign_BXS2A4_a1notshifted_1.root"); - - -// legendlabels.push_back("Perfect"); -// legendlabels.push_back("Misaligned"); - -// colors.push_back(3); -// colors.push_back(4); - - - //get histos - vector< map<TString,TH1*> > histMaps; - vector<TCanvas*> cans; - for (unsigned int k=0;k<filenames.size();k++) { - - TChain* tree=new TChain("MuonAlign"); - std::cout<<"adding "<<filenames[k]<<std::endl; - tree->Add(filenames[k]); - int m_ntrees=tree->GetNtrees(); - std::cout<<"have "<<m_ntrees<<" trees"<<std::endl; - - histMaps.push_back( getHistos(tree,combinetype) ); - delete tree; - } - - //create legend - double xmin = 0.65; - double xmax = xmin+0.3; - double ymax = 0.87; - double ymin = ymax - ((gStyle->GetTextSize()+0.01)*(legendlabels.size()+1)); - TLegend* leg = new TLegend(xmin, ymin, xmax, ymax); - leg->SetFillStyle(0); - leg->SetFillColor(0); - for(unsigned int k=0; k<legendlabels.size(); k++){ - TH1* hist = histMaps[k].begin()->second; - if(!hist) continue; - leg->AddEntry(hist,legendlabels[k],"L"); - } - //leg->SetTitle("test"); - //iterate over histos of first file - TCanvas* can = new TCanvas("canv","canv"); - map<TString,TH1*>::const_iterator histIt = histMaps[0].begin(); - for (; histIt!=histMaps[0].end(); ++histIt) { - can->Clear(); - - TH1* firsthist = histIt->second; - firsthist->SetLineColor(colors[0]); - firsthist->SetTitle(""); - firsthist->Draw("Hist"); - TString regionname = histIt->first; - - //if(regionname!="BMS2A4") continue; - //cout << "first hist entries: " << firsthist->GetMean() << endl; - - //get histos for other files and normalize to first histo - for (unsigned int k=1;k<filenames.size();k++) { - TH1* hist = histMaps[k][regionname]; - if(!hist) continue; - //cout << "hist entries: " << hist->GetMean() << endl; - //hist->Scale(firsthist->GetEntries()/hist->GetEntries()); - hist->SetLineColor(colors[k]); - hist->Draw("Hist Same"); +int main(int argc, char* argv[]) { + //./plotres_x -c 3,4 -i MuonAlign_BXS2A4_notshifted_1.root,MuonAlign_BXS2A4_a1notshifted_1.root -o pics -l Perfect,Misaligned + + //---------------------------- + //-- Parse the command line -- + //---------------------------- + + extern char* optarg; + char c; + TString infilestr(""); + TString outputstr(""); + TString labelstr(""); + TString colorstr(""); + TString combinetype("Chamber"); // Chamber,Tower,Sector,Side,BarrelEC,MS + + while ((c = getopt(argc, argv, "-ho:i:l:c:t:")) != -1) { + switch (c) { + case 'o': outputstr = optarg; break; + case 'i': infilestr = optarg; break; + case 'l': labelstr = optarg; break; + case 'c': colorstr = optarg; break; + case 't': combinetype = optarg; break; + default: + cerr << "Help or unknown argument!" << endl; + help(argv[0]); + break; + } } - leg->SetHeader(regionname); - leg->AppendPad(); - TString canvname = directory + "/residuals_" + regionname + ".eps"; - if(saveplot) can->Print(canvname); - } - - - //delete histos - for (unsigned int k=0;k<histMaps.size();k++) { - map<TString,TH1*>::const_iterator histIt = histMaps[k].begin(); - for (; histIt!=histMaps[k].end(); ++histIt) { - delete histIt->second; - } - } - //rootname<<directory<<"/MuonAlign_"<<directory<<"_"<<iteration<<".root"; - //rootname<<directory<<"/MuonAlign_L1_MC_b0_iter0.root"; + //--------------------------- + //-- Set and verify inputs -- + //--------------------------- + vector<TString> filenames = Tools::getOptionVector<TString>(infilestr); + vector<TString> legendlabels = Tools::getOptionVector<TString>(labelstr); + vector<int> colors = Tools::getOptionVector<int>(colorstr); + TString directory = outputstr; - // getDataFromTree(tree,fullArrayMap,xarrayMap,numTracks,chamberNames,goodParams); - - + if (filenames.size() == 0) { + cerr << "no imput files given, exiting..." << endl; + exit(1); + } + if (filenames.size() != legendlabels.size()) { + cerr << "different number of inpufiles and legendnames," << endl << "exiting..." << endl; + exit(1); + } + if (filenames.size() != colors.size()) { + cerr << "different number of inpufiles and colors," << endl << "exiting..." << endl; + exit(1); + } + + //--------- + //-- Run -- + //--------- + + TH1::SetDefaultSumw2(); + Tools::setStyle(); + // gStyle->SetOptStat(111); + // gStyle->SetOptStat(0); + + // unsigned int m_combType = Chamber; + m_xbins = 100; + m_xmax = 0.5; + m_xmin = -1 * m_xmax; + + bool saveplot = 1; + + // std::string directory=""; + // if (argc>1) { + // directory=string(argv[1]); + // } + // std::string iteration="0"; + // if (argc>2) { + // iteration=string(argv[2]); + // } + // std::cout<<"using input directory "<<directory<<std::endl; + + // stringstream rootname; + // if (BATCH) + // rootname<<directory<<"/MuonAlign_"<<directory<<"_b8_iter"<<iteration<<".root"; + // else + // rootname<<directory<<"/MuonAlign_"<<directory<<"_"<<iteration<<".root"; + + mid = new MuonFixedId(0); + + // vector<TString> filenames; + // vector<TString> legendlabels; + // vector<int> colors; + + // TString directory = "pics"; + + // //filenames.push_back("BXS2A4_notshifted/MuonAlign_BXS2A4_notshifted_1.root"); + // //filenames.push_back("BXS2A4_a1notshifted/MuonAlign_BXS2A4_a1notshifted_1.root"); + // filenames.push_back("MuonAlign_BXS2A4_notshifted_1.root"); + // filenames.push_back("MuonAlign_BXS2A4_a1notshifted_1.root"); + + // legendlabels.push_back("Perfect"); + // legendlabels.push_back("Misaligned"); + + // colors.push_back(3); + // colors.push_back(4); + + // get histos + vector<map<TString, TH1*> > histMaps; + vector<TCanvas*> cans; + for (unsigned int k = 0; k < filenames.size(); k++) { + TChain* tree = new TChain("MuonAlign"); + std::cout << "adding " << filenames[k] << std::endl; + tree->Add(filenames[k]); + int m_ntrees = tree->GetNtrees(); + std::cout << "have " << m_ntrees << " trees" << std::endl; + + histMaps.push_back(getHistos(tree, combinetype)); + delete tree; + } -// TCanvas* canv=new TCanvas("canv","canv"); -// map<TString,TH1*>::const_iterator histIt = histMap.begin(); -// for (; histIt!=histMap.end(); ++histIt) { -// canv->Clear(); -// TH1* hist = histIt->second; -// hist->Draw(); -// stringstream canvname; -// canvname<<directory<<"/"<<directory<<"_"<<hist->GetName()<<".eps"; -// if(saveplot) canv->Print(canvname.str().c_str()); -// } - + // create legend + double xmin = 0.65; + double xmax = xmin + 0.3; + double ymax = 0.87; + double ymin = ymax - ((gStyle->GetTextSize() + 0.01) * (legendlabels.size() + 1)); + TLegend* leg = new TLegend(xmin, ymin, xmax, ymax); + leg->SetFillStyle(0); + leg->SetFillColor(0); + for (unsigned int k = 0; k < legendlabels.size(); k++) { + TH1* hist = histMaps[k].begin()->second; + if (!hist) continue; + leg->AddEntry(hist, legendlabels[k], "L"); + } + // leg->SetTitle("test"); + // iterate over histos of first file + TCanvas* can = new TCanvas("canv", "canv"); + map<TString, TH1*>::const_iterator histIt = histMaps[0].begin(); + for (; histIt != histMaps[0].end(); ++histIt) { + can->Clear(); + + TH1* firsthist = histIt->second; + firsthist->SetLineColor(colors[0]); + firsthist->SetTitle(""); + firsthist->Draw("Hist"); + TString regionname = histIt->first; + + // if(regionname!="BMS2A4") continue; + // cout << "first hist entries: " << firsthist->GetMean() << endl; + + // get histos for other files and normalize to first histo + for (unsigned int k = 1; k < filenames.size(); k++) { + TH1* hist = histMaps[k][regionname]; + if (!hist) continue; + // cout << "hist entries: " << hist->GetMean() << endl; + // hist->Scale(firsthist->GetEntries()/hist->GetEntries()); + hist->SetLineColor(colors[k]); + hist->Draw("Hist Same"); + } + leg->SetHeader(regionname); + leg->AppendPad(); + TString canvname = directory + "/residuals_" + regionname + ".eps"; + if (saveplot) can->Print(canvname); + } - + // delete histos + for (unsigned int k = 0; k < histMaps.size(); k++) { + map<TString, TH1*>::const_iterator histIt = histMaps[k].begin(); + for (; histIt != histMaps[k].end(); ++histIt) { delete histIt->second; } + } + // rootname<<directory<<"/MuonAlign_"<<directory<<"_"<<iteration<<".root"; + // rootname<<directory<<"/MuonAlign_L1_MC_b0_iter0.root"; + + // getDataFromTree(tree,fullArrayMap,xarrayMap,numTracks,chamberNames,goodParams); + + // TCanvas* canv=new TCanvas("canv","canv"); + // map<TString,TH1*>::const_iterator histIt = histMap.begin(); + // for (; histIt!=histMap.end(); ++histIt) { + // canv->Clear(); + // TH1* hist = histIt->second; + // hist->Draw(); + // stringstream canvname; + // canvname<<directory<<"/"<<directory<<"_"<<hist->GetName()<<".eps"; + // if(saveplot) canv->Print(canvname.str().c_str()); + // } } -map<TString,TH1*> getHistos(TChain* tree,TString combineType){ - - static int histcounter; - - int evt; - int nchambers; - int* chamberId = new int[10]; - int nhits; - double* res = new double[100]; - int* fixedid = new int[100]; - - tree->SetBranchAddress("evt", &evt); - tree->SetBranchAddress("nchambers", &nchambers); - tree->SetBranchAddress("chamberid", chamberId); - tree->SetBranchAddress("nhits", &nhits); - tree->SetBranchAddress("fixedid", fixedid); - tree->SetBranchAddress("res", res); - - map<TString,TH1*> histMap; - - for (int ientry=0;ientry<tree->GetEntries();ientry++) { - - tree->GetEntry(ientry); - for (int ihit=0;ihit<nhits;ihit++) { - - mid->setMuonIdentifier(fixedid[ihit]); - string chamberName = Tools::getChamberName(mid); - - TString regionname = chamberName; - if(combineType == "Tower") - regionname.Replace(1,1,""); - else if(combineType == "Sector"){ - regionname.Replace(0,5,""); - regionname.Prepend("Sector"); - } - else if(combineType == "Side"){ - regionname.Replace(0,4,""); - regionname.Resize(1); - regionname.Prepend("Side"); - } - else if(combineType == "BarrelEC") - regionname.Resize(1); - else if(combineType == "MS") - regionname="MS"; - - //cout << "ihit: " << ihit << ", " << res[ihit] - // << ", regionname: " << regionname << endl; - - if(!histMap[regionname]){ - TH1* hist = new TH1F("residuals_"+regionname+Form("_%i",histcounter), - "Residuals ("+regionname+")", m_xbins,m_xmin,m_xmax); - hist->GetXaxis()->SetTitle("Residual [mm]"); - hist->GetYaxis()->SetTitle("Entries"); - histMap[regionname]=hist; - histcounter++; - } - histMap[regionname]->Fill(res[ihit]); +map<TString, TH1*> getHistos(TChain* tree, TString combineType) { + static int histcounter; + + int evt; + int nchambers; + int* chamberId = new int[10]; + int nhits; + double* res = new double[100]; + int* fixedid = new int[100]; + + tree->SetBranchAddress("evt", &evt); + tree->SetBranchAddress("nchambers", &nchambers); + tree->SetBranchAddress("chamberid", chamberId); + tree->SetBranchAddress("nhits", &nhits); + tree->SetBranchAddress("fixedid", fixedid); + tree->SetBranchAddress("res", res); + + map<TString, TH1*> histMap; + + for (int ientry = 0; ientry < tree->GetEntries(); ientry++) { + tree->GetEntry(ientry); + for (int ihit = 0; ihit < nhits; ihit++) { + mid->setMuonIdentifier(fixedid[ihit]); + string chamberName = Tools::getChamberName(mid); + + TString regionname = chamberName; + if (combineType == "Tower") + regionname.Replace(1, 1, ""); + else if (combineType == "Sector") { + regionname.Replace(0, 5, ""); + regionname.Prepend("Sector"); + } else if (combineType == "Side") { + regionname.Replace(0, 4, ""); + regionname.Resize(1); + regionname.Prepend("Side"); + } else if (combineType == "BarrelEC") + regionname.Resize(1); + else if (combineType == "MS") + regionname = "MS"; + + // cout << "ihit: " << ihit << ", " << res[ihit] + // << ", regionname: " << regionname << endl; + + if (!histMap[regionname]) { + TH1* hist = new TH1F("residuals_" + regionname + Form("_%i", histcounter), "Residuals (" + regionname + ")", m_xbins, + m_xmin, m_xmax); + hist->GetXaxis()->SetTitle("Residual [mm]"); + hist->GetYaxis()->SetTitle("Entries"); + histMap[regionname] = hist; + histcounter++; + } + histMap[regionname]->Fill(res[ihit]); + } } - } - delete [] chamberId; - delete [] res; - delete [] fixedid; + delete[] chamberId; + delete[] res; + delete[] fixedid; - return histMap; + return histMap; } diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/plottrendEE_x.cpp b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/plottrendEE_x.cpp index fd712710a613fb8901f4cdd4d11dc4ccde417818..96dcdc2c9b309e5e6eee0bc2f5b6406fff2ddee3 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/plottrendEE_x.cpp +++ b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/plottrendEE_x.cpp @@ -2,1276 +2,1303 @@ Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ -#include "ChamberNames.h" - -#include <vector> -#include <sstream> -#include <iostream> -#include <iomanip> -#include <fstream> #include <cmath> #include <cstdlib> +#include <fstream> +#include <iomanip> +#include <iostream> +#include <sstream> +#include <vector> -#include "TGraph.h" -#include "TCanvas.h" -#include "TLegend.h" +#include "ChamberNames.h" #include "TAxis.h" -#include "TH1F.h" -#include "TF1.h" +#include "TCanvas.h" #include "TChain.h" +#include "TF1.h" +#include "TGraph.h" +#include "TH1F.h" +#include "TLegend.h" #include "TPaveStats.h" #include "TStyle.h" -int main() -{ - - ChamberNames chNames("chambers.txt"); +int main() { + ChamberNames chNames("chambers.txt"); + + const int NFILES = 8; + // const int NFILES=5; + + const string basedir = "/tmp/roberth/"; + const string dirs[NFILES] = { + "group.det-muon.ZMUMU.20110609_EE-BIS8_iter0_V21", + "group.det-muon.ZMUMU.20110609_EE-BIS8_iter1_V22", + "group.det-muon.ZMUMU.20110609_EE-BIS8_iter2_V22", + "group.det-muon.ZMUMU.20110609_EE-BIS8_iter3_V22", + "group.det-muon.ZMUMU.20110609_EE-BIS8_iter4_V22", + "group.det-muon.ZMUMU.20110609_EE-BIS8_iter5_V22", + "group.det-muon.ZMUMU.20110609_EE-BIS8_iter6_V22", + "group.det-muon.ZMUMU.20110609_EE-BIS8_iter7_V24" + /* + "group.det-muon.TMU15GEV.20110310_EE-BIS8_iter0_V16.110428220005", + //"group.det-muon.TMU15GEV.20110310_EE-BIS8_iter1_V19.110524092107", + //"group.det-muon.TMU15GEV.20110310_EE-BIS8_iter2_V19.110524114712", + "group.det-muon.TMU15GEV.20110310_EE-BIS8_iter3_V19.110524234018", + //"group.det-muon.TMU15GEV.20110310_EE-BIS8_iter4_V19.110525092140", + //"group.det-muon.TMU15GEV.20110310_EE-BIS8_iter5_V19.110525150617", + "group.det-muon.TMU15GEV.20110310_EE-BIS8_iter6_V19.110526103932", + //"group.det-muon.TMU15GEV.20110310_EE-BIS8_iter7_V19.110526174338", + //"group.det-muon.TMU15GEV.20110310_EE-BIS8_iter8_V19.110526211853", + "group.det-muon.TMU15GEV.20110310_EE-BIS8_iter9_V19.110527014843", + //"group.det-muon.TMU15GEV.20110310_EE-BIS8_iter10_V19.110527113253", + "group.det-muon.TMU15GEV.20110310_EE-BIS8_iter12_V19.110527231239", + "group.det-muon.TMU15GEV.20110310_EE-BIS8_iter15_V19.110529003002", + "group.det-muon.TMU15GEV.20110310_EE-BIS8_iter18_V19.110529215537", + "group.det-muon.TMU15GEV.20110310_EE-BIS8_iter21_V19.110606125252" + */ + }; - const int NFILES=8; - //const int NFILES=5; - - const string basedir="/tmp/roberth/"; - const string dirs[NFILES]={ - "group.det-muon.ZMUMU.20110609_EE-BIS8_iter0_V21", - "group.det-muon.ZMUMU.20110609_EE-BIS8_iter1_V22", - "group.det-muon.ZMUMU.20110609_EE-BIS8_iter2_V22", - "group.det-muon.ZMUMU.20110609_EE-BIS8_iter3_V22", - "group.det-muon.ZMUMU.20110609_EE-BIS8_iter4_V22", - "group.det-muon.ZMUMU.20110609_EE-BIS8_iter5_V22", - "group.det-muon.ZMUMU.20110609_EE-BIS8_iter6_V22", - "group.det-muon.ZMUMU.20110609_EE-BIS8_iter7_V24" /* - "group.det-muon.TMU15GEV.20110310_EE-BIS8_iter0_V16.110428220005", - //"group.det-muon.TMU15GEV.20110310_EE-BIS8_iter1_V19.110524092107", - //"group.det-muon.TMU15GEV.20110310_EE-BIS8_iter2_V19.110524114712", - "group.det-muon.TMU15GEV.20110310_EE-BIS8_iter3_V19.110524234018", - //"group.det-muon.TMU15GEV.20110310_EE-BIS8_iter4_V19.110525092140", - //"group.det-muon.TMU15GEV.20110310_EE-BIS8_iter5_V19.110525150617", - "group.det-muon.TMU15GEV.20110310_EE-BIS8_iter6_V19.110526103932", - //"group.det-muon.TMU15GEV.20110310_EE-BIS8_iter7_V19.110526174338", - //"group.det-muon.TMU15GEV.20110310_EE-BIS8_iter8_V19.110526211853", - "group.det-muon.TMU15GEV.20110310_EE-BIS8_iter9_V19.110527014843", - //"group.det-muon.TMU15GEV.20110310_EE-BIS8_iter10_V19.110527113253", - "group.det-muon.TMU15GEV.20110310_EE-BIS8_iter12_V19.110527231239", - "group.det-muon.TMU15GEV.20110310_EE-BIS8_iter15_V19.110529003002", - "group.det-muon.TMU15GEV.20110310_EE-BIS8_iter18_V19.110529215537", - "group.det-muon.TMU15GEV.20110310_EE-BIS8_iter21_V19.110606125252" + const string dirs[NFILES]={ + "group.det-muon.TMU15GEV.20110310_EE-BIS8_iter17_V19.110529184925", + "group.det-muon.TMU15GEV.20110310_EE-BIS8_iter18_V19.110529215537", + "group.det-muon.TMU15GEV.20110310_EE-BIS8_iter19_V19.110529235409", + "group.det-muon.TMU15GEV.20110310_EE-BIS8_iter20_V19.110530133814", + "group.det-muon.TMU15GEV.20110310_EE-BIS8_iter21_V19.110606125252"}; */ - }; - - /* - const string dirs[NFILES]={ - "group.det-muon.TMU15GEV.20110310_EE-BIS8_iter17_V19.110529184925", - "group.det-muon.TMU15GEV.20110310_EE-BIS8_iter18_V19.110529215537", - "group.det-muon.TMU15GEV.20110310_EE-BIS8_iter19_V19.110529235409", - "group.det-muon.TMU15GEV.20110310_EE-BIS8_iter20_V19.110530133814", - "group.det-muon.TMU15GEV.20110310_EE-BIS8_iter21_V19.110606125252"}; - */ - - const int iters[NFILES]={0,1,2,3,4,5,6,7}; - //const int iters[NFILES]={0,3,6,9,12,15,18,21}; - //const int iters[NFILES]={17,18,19,20,21}; - - const std::string plottypes[6]={"BEEA","BEEC","EELA","EELC","BIS8A","BIS8C"}; - int** beecolor=new int*[2]; - int** eelcolor=new int*[2]; - int** bis8color=new int*[2]; - for (int ieta=0;ieta<2;ieta++) { - beecolor[ieta]=new int[8]; - eelcolor[ieta]=new int[8]; - bis8color[ieta]=new int[8]; - } - - const int phicolor[16]={kRed+4,kRed+2,kRed, - kMagenta+4,kMagenta+2,kMagenta, - kBlue+4,kBlue+2,kBlue, - kCyan+4,kCyan+2,kCyan, - kGreen+4,kGreen+2,kGreen, - kYellow+2}; - - - for (int iplot=0;iplot<6;iplot++) { - const std::string plottype=plottypes[iplot]; - - - std::vector<double> traz0; - std::vector<double> trat0; - std::vector<double> rots0; - std::vector<double> rotz0; - std::vector<double> rott0; - std::string dummy; - char ALineMarker; - int jff,jzz,job; - std::string type; - double tras,traz,trat,rots,rotz,rott; - - std::vector<std::string> names; - std::vector<int> etas; - std::vector<int> phis; - std::vector<TGraph*> graphs_traz; - std::vector<TGraph*> graphs_trat; - std::vector<TGraph*> graphs_rots; - std::vector<TGraph*> graphs_rotz; - std::vector<TGraph*> graphs_rott; - - double minz( 9.),mint( 9.),minrs( 9.),minrz( 9.),minrt( 9.); - double maxz(-9.),maxt(-9.),maxrs(-9.),maxrz(-9.),maxrt(-9.); - - for (int ifile=0;ifile<NFILES;ifile++) { - - int iter=iters[ifile]; - - std::stringstream filename; filename<<"outputAszt_iter"<<iter<<".txt"; - std::ifstream file(filename.str().c_str()); - file>>dummy; - int ich=0; - while (file>>ALineMarker>>type>>jff>>jzz>>job>> - tras>>traz>>trat>>rots>>rotz>>rott) { - if (plottype=="BEEA" && (type!="BEE"||jzz<0) ) continue; - if (plottype=="BEEC" && (type!="BEE"||jzz>0) ) continue; - if (plottype=="EELA" && (type!="EEL"||jzz<0) ) continue; - if (plottype=="EELC" && (type!="EEL"||jzz>0) ) continue; - if (plottype=="BIS8A" && (type!="BIS"||jzz!= 8) ) continue; - if (plottype=="BIS8C" && (type!="BIS"||jzz!=-8) ) continue; - - //std::cout<<ich<<" "<<type<<" "<<jff<<" "<<jzz<<" "<<tras<<std::endl; - - if (traz<minz) minz =traz; if (traz>maxz) maxz =traz; - if (trat<mint) mint =trat; if (trat>maxt) maxt =trat; - if (rots<minrs) minrs=rots; if (rots>maxrs) maxrs=rots; - if (rotz<minrz) minrz=rotz; if (rotz>maxrz) maxrz=rotz; - if (rott<minrt) minrt=rott; if (rott>maxrt) maxrt=rott; - - if (ifile==0) { - std::stringstream chname; - chname<<type<<std::abs(jzz); - if (jzz<0) chname<<"C"; else chname<<"A"; - int detphi=2*jff; - if (type.substr(2,1)=="L") detphi--; - else if (type.substr(2,1)!="S"&&type!="BEE") detphi=jff; - chname<<std::setfill('0')<<std::setw(2)<<detphi; - - //std::cout<<"chname: "<<chname.str()<<std::endl; - - names.push_back(chname.str()); - etas.push_back(std::abs(jzz)-1); - phis.push_back(jff-1); - graphs_traz.push_back(new TGraph(NFILES)); - graphs_trat.push_back(new TGraph(NFILES)); - graphs_rots.push_back(new TGraph(NFILES)); - graphs_rotz.push_back(new TGraph(NFILES)); - graphs_rott.push_back(new TGraph(NFILES)); - } - graphs_traz[ich]->SetPoint(ifile,iter,traz); - graphs_trat[ich]->SetPoint(ifile,iter,trat); - graphs_rots[ich]->SetPoint(ifile,iter,rots*1000.); - graphs_rotz[ich]->SetPoint(ifile,iter,rotz*1000.); - graphs_rott[ich]->SetPoint(ifile,iter,rott*1000.); - - graphs_traz[ich]->SetTitle("z"); - graphs_trat[ich]->SetTitle("t"); - graphs_rots[ich]->SetTitle("rot s"); - graphs_rotz[ich]->SetTitle("rot z"); - graphs_rott[ich]->SetTitle("rot t"); - ich++; - } - } - TCanvas* canv=new TCanvas("canv","canv"); - TLegend* leg=new TLegend(.1,.1,.9,.9); - canv->SetFillColor(10); - canv->Divide(3,2); - for (int i=0;i<5;i++) { - std::vector<TGraph*>& gr=graphs_traz; - double max(0.),min(0.); - switch (i) { - case 0: gr=graphs_traz; max=maxz; min=minz; break; - case 1: gr=graphs_trat; max=maxt; min=mint; break; - case 2: gr=graphs_rots; max=maxrs; min=minrs; break; - case 3: gr=graphs_rotz; max=maxrz; min=minrz; break; - case 4: gr=graphs_rott; max=maxrt; min=minrt; break; - } - - if (max<0.) max=0.; - if (min>0.) min=0.; - if (i>=2) { max*=1000.; min*=1000.; } - - //std::cout<<"i/min/max: "<<i<<"/"<<min<<"/"<<max<<std::endl; - - canv->cd(i+2); - for (int ich=0;ich<(int)names.size();ich++) { - gr[ich]->SetMaximum(1.2*max); - gr[ich]->SetMinimum(1.2*min); - gr[ich]->SetMarkerSize(.4); - int color=(plottype.substr(0,3)=="EEL")?phicolor[ich*2]:phicolor[ich]; - - // set color for later use for BEE and EEL plots - int ieta=etas[ich]; int iphi=phis[ich]; - if (plottype.substr(0,3)=="EEL") - eelcolor[ieta][iphi]=color; - else if (plottype.substr(0,3)=="BEE") - beecolor[ieta][iphi]=color; - else - bis8color[0][iphi]=color; - - gr[ich]->SetMarkerColor(color); - gr[ich]->SetMarkerStyle(8); - gr[ich]->SetLineColor(color); - //gr[ich]->SetLineWidth(1.6); - gr[ich]->SetMarkerSize(.7); - if (ich==0) - gr[ich]->Draw("APL"); - else - gr[ich]->Draw("PLsame"); - gr[ich]->GetXaxis()->SetTitle("iteration"); - if (i<2) gr[ich]->GetYaxis()->SetTitle("mm"); - else gr[ich]->GetYaxis()->SetTitle("mrad"); - if (i==0) leg->AddEntry(gr[ich],names[ich].c_str(),"lp"); - } - } - canv->cd(1); - leg->Draw(); - canv->Modified(); - - if (plottype=="BEEA") - canv->Print("BEEA_trend.eps"); - else if (plottype=="BEEC") - canv->Print("BEEC_trend.eps"); - else if (plottype=="EELA") - canv->Print("EELA_trend.eps"); - else if (plottype=="EELC") - canv->Print("EELC_trend.eps"); - else if (plottype=="BIS8A") - canv->Print("BIS8A_trend.eps"); - else if (plottype=="BIS8C") - canv->Print("BIS8C_trend.eps"); - - delete canv; - delete leg; - } - - // get residuals - TH1F*** allBeeRes = new TH1F**[NFILES]; - TH1F*** allEelRes = new TH1F**[NFILES]; - TH1F***** beeRes = new TH1F****[NFILES]; - TH1F***** eelRes = new TH1F****[NFILES]; - TH1F***** bis8Res = new TH1F****[NFILES]; - string *** hbeenames(0), *** heelnames(0), *** hbis8names(0); - - TGraph* nTracksGr =new TGraph(NFILES); - TGraph* nTracksBEEAGr =new TGraph(NFILES); - TGraph* nTracksBEECGr =new TGraph(NFILES); - TGraph* nTracksEELAGr =new TGraph(NFILES); - TGraph* nTracksEELCGr =new TGraph(NFILES); - TGraph* nTracksBIS8AGr =new TGraph(NFILES); - TGraph* nTracksBIS8CGr =new TGraph(NFILES); - TGraph* trackChi2Gr =new TGraph(NFILES); - TGraph* trackChi2BEEAGr =new TGraph(NFILES); - TGraph* trackChi2BEECGr =new TGraph(NFILES); - TGraph* trackChi2EELAGr =new TGraph(NFILES); - TGraph* trackChi2EELCGr =new TGraph(NFILES); - TGraph* trackChi2BIS8AGr=new TGraph(NFILES); - TGraph* trackChi2BIS8CGr=new TGraph(NFILES); - - nTracksGr->SetName("nTracks"); - nTracksBEEAGr->SetName("nTracksBEEA"); - nTracksBEECGr->SetName("nTracksBEEC"); - nTracksEELAGr->SetName("nTracksEELA"); - nTracksEELCGr->SetName("nTracksEELC"); - nTracksBIS8AGr->SetName("nTracksBIS8A"); - nTracksBIS8CGr->SetName("nTracksBIS8C"); - trackChi2Gr->SetName("trackChi2"); - trackChi2BEEAGr->SetName("trackChi2BEEA"); - trackChi2BEECGr->SetName("trackChi2BEEC"); - trackChi2EELAGr->SetName("trackChi2EELA"); - trackChi2EELCGr->SetName("trackChi2EELC"); - trackChi2BIS8AGr->SetName("trackChi2BIS8A"); - trackChi2BIS8CGr->SetName("trackChi2BIS8C"); - - for (int ifile=0;ifile<NFILES;ifile++) { - int iter=iters[ifile]; - stringstream iterstr; iterstr<<"iter"<<iter; - - stringstream files; files<<basedir<<dirs[ifile]<<"/iter"<<iter<<"/*"; - TChain* tree=new TChain("MuonTrackPreProcessor"); - std::cout<<"adding "<<files.str()<<" to TChain"<<std::endl; - tree->Add(files.str().c_str()); - - int nChambers,* chamberId(new int[50]), nresiduals, * resIndex(new int[50]); - double * residuals(new double[100]); - double trackChi2; - tree->SetBranchAddress("nChambers", &nChambers); - tree->SetBranchAddress("chamberId", chamberId); - tree->SetBranchAddress("nresiduals",&nresiduals); - tree->SetBranchAddress("resIndex", resIndex); - tree->SetBranchAddress("residuals", residuals); - tree->SetBranchAddress("trackChi2", &trackChi2); - - allBeeRes[ifile]=new TH1F*[2]; - allEelRes[ifile]=new TH1F*[2]; - beeRes[ifile] =new TH1F***[2]; - eelRes[ifile] =new TH1F***[2]; - bis8Res[ifile] =new TH1F***[2]; - if (ifile==0) { - hbeenames =new string**[2]; - heelnames =new string**[2]; - hbis8names=new string**[2]; - } - // make histograms - for (int isideAC=0;isideAC<2;isideAC++) { - - // all BEE/EEL - stringstream allEEStr; - if (isideAC==0) allEEStr<<"sideA_"; - else allEEStr<<"sideC_"; - - string allBeeName=allEEStr.str()+iterstr.str(); - allBeeRes[ifile][isideAC]=new TH1F(("allBEE_"+allBeeName).c_str(), - ("allBEE_"+allBeeName).c_str(), - 100,-6.,6.); - allEelRes[ifile][isideAC]=new TH1F(("allEEL_"+allBeeName).c_str(), - ("allEEL_"+allBeeName).c_str(), - 100,-6.,6.); - - // individual BEE/EEL - beeRes [ifile][isideAC]=new TH1F**[2]; - eelRes [ifile][isideAC]=new TH1F**[2]; - bis8Res[ifile][isideAC]=new TH1F**[2]; - if (ifile==0) { - hbeenames [isideAC]=new string*[2]; - heelnames [isideAC]=new string*[2]; - hbis8names[isideAC]=new string*[2]; - } - for (int ieta=0;ieta<2;ieta++) { - beeRes [ifile][isideAC][ieta]=new TH1F*[8]; - eelRes [ifile][isideAC][ieta]=new TH1F*[8]; - bis8Res[ifile][isideAC][ieta]=new TH1F*[8]; - if (ifile==0) { - hbeenames [isideAC][ieta]=new string[8]; - heelnames [isideAC][ieta]=new string[8]; - hbis8names[isideAC][ieta]=new string[8]; - } - for (int iphi=0;iphi<8;iphi++) { - stringstream beename; - beename<<"BEE"<<ieta+1; - if (isideAC==0) beename<<"A"; else beename<<"C"; - beename<<setfill('0')<<setw(2)<<(iphi+1)*2; - beeRes[ifile][isideAC][ieta][iphi]=new TH1F((beename.str()+"_"+iterstr.str()).c_str(), - beename.str().c_str(), - 100,-6.,6.); - if (ifile==0) hbeenames[isideAC][ieta][iphi]=beename.str(); - - stringstream eelname; - eelname<<"EEL"<<ieta+1; - if (isideAC==0) eelname<<"A"; else eelname<<"C"; - eelname<<setfill('0')<<setw(2)<<(iphi+1)*2-1; - - eelRes[ifile][isideAC][ieta][iphi]=new TH1F((eelname.str()+"_"+iterstr.str()).c_str(), - eelname.str().c_str(), - 100,-1.,1.); - if (ifile==0) heelnames[isideAC][ieta][iphi]=eelname.str(); - - if (ieta==0) { - stringstream bis8name; - bis8name<<"BIS8"; - if (isideAC==0) bis8name<<"A"; else bis8name<<"C"; - bis8name<<setfill('0')<<setw(2)<<(iphi+1)*2; - bis8Res[ifile][isideAC][ieta][iphi]=new TH1F((bis8name.str()+"_"+iterstr.str()).c_str(), - bis8name.str().c_str(), - 100,-1.,1.); - if (ifile==0) hbis8names[isideAC][ieta][iphi]=bis8name.str(); - } - } - } + const int iters[NFILES] = {0, 1, 2, 3, 4, 5, 6, 7}; + // const int iters[NFILES]={0,3,6,9,12,15,18,21}; + // const int iters[NFILES]={17,18,19,20,21}; + + const std::string plottypes[6] = {"BEEA", "BEEC", "EELA", "EELC", "BIS8A", "BIS8C"}; + int** beecolor = new int*[2]; + int** eelcolor = new int*[2]; + int** bis8color = new int*[2]; + for (int ieta = 0; ieta < 2; ieta++) { + beecolor[ieta] = new int[8]; + eelcolor[ieta] = new int[8]; + bis8color[ieta] = new int[8]; } - int nTracks=0; - int nTracksBEEA=0; - int nTracksBEEC=0; - int nTracksEELA=0; - int nTracksEELC=0; - int nTracksBIS8A=0; - int nTracksBIS8C=0; - double totalTrackChi2=0.; - double totalTrackChi2BEEA=0.; - double totalTrackChi2BEEC=0.; - double totalTrackChi2EELA=0.; - double totalTrackChi2EELC=0.; - double totalTrackChi2BIS8A=0.; - double totalTrackChi2BIS8C=0.; - - // loop over entries and fill histograms - std::cout<<"tree has "<<tree->GetEntries()<<" entries"<<std::endl; - for (int ientry=0;ientry<(int)tree->GetEntries();ientry++) { - //cout<<"ientry: "<<ientry<<endl; - tree->GetEntry(ientry); - - string beeName =""; - string eelName =""; - string bis8Name=""; - int firstBEERes(0),lastBEERes(0); - int firstEELRes(0),lastEELRes(0); - int firstBIS8Res(0),lastBIS8Res(0); - for (int ich=0;ich<nChambers;ich++) { - int id=chamberId[ich]; - std::string name=chNames.chamberName(id); - //std::cout<<"name: "<<name<<std::endl; - - if (name.substr(0,3)=="BEE") { - beeName=name; - firstBEERes=resIndex[ich]; - lastBEERes=(ich+1<nChambers)?resIndex[ich+1]:nresiduals; - } - if (name.substr(0,3)=="EEL") { - eelName=name; - firstEELRes=resIndex[ich]; - lastEELRes=(ich+1<nChambers)?resIndex[ich+1]:nresiduals; - } - if (name.substr(0,4)=="BIS8") { - bis8Name=name; - firstBIS8Res=resIndex[ich]; - lastBIS8Res=(ich+1<nChambers)?resIndex[ich+1]:nresiduals; - } - } - - // remove tracks not passing selection in MuonTrackPreProcessor - if (beeName==""&&eelName==""&&bis8Name=="") { - continue; - } - - /* - if (bis8Name!=""||eelName!="") { - cout<<" "; - for (int ich=0;ich<nChambers;ich++) { - int id=chamberId[ich]; - std::string name=chNames.chamberName(id); - if (ich==0) cout<<name; - else cout<<", "<<name; - } - cout<<endl; - } - */ - //cout<<"beeName: "<<beeName<<", eelName: "<<eelName<<endl; - - if (beeName!="") { - int stPhi=chNames.stPhi(beeName); - int stEta=chNames.stEta(beeName); - int isideAC=(stEta>0)?0:1; - int ieta=std::abs(stEta)-1; - int iphi=stPhi-1; - for (int ires=firstBEERes;ires<lastBEERes;ires++) { - beeRes [ifile][isideAC][ieta][iphi]->Fill(residuals[ires]); - allBeeRes[ifile][isideAC] ->Fill(residuals[ires]); - //cout<<"BEE res: "<<residuals[ires]<<endl; - } - - - if (isideAC==0) { - totalTrackChi2BEEA+=trackChi2; - nTracksBEEA++; - } - else { - totalTrackChi2BEEC+=trackChi2; - nTracksBEEC++; - } - } - if (eelName!="") { - int stPhi=chNames.stPhi(eelName); - int stEta=chNames.stEta(eelName); - int isideAC=(stEta>0)?0:1; - int ieta=std::abs(stEta)-1; - int iphi=stPhi-1; - for (int ires=firstEELRes;ires<lastEELRes;ires++) { - eelRes[ifile][isideAC][ieta][iphi]->Fill(residuals[ires]); - allEelRes[ifile][isideAC]->Fill(residuals[ires]); - //cout<<"EEL res: "<<residuals[ires]<<endl; - } - - if (isideAC==0) { - totalTrackChi2EELA+=trackChi2; - nTracksEELA++; - } - else { - totalTrackChi2EELC+=trackChi2; - nTracksEELC++; - } - } - if (bis8Name!="") { - int stPhi=chNames.stPhi(bis8Name); - int stEta=chNames.stEta(bis8Name); - int isideAC=(stEta>0)?0:1; - int ieta=0; - int iphi=stPhi-1; - for (int ires=firstBIS8Res;ires<lastBIS8Res;ires++) { - bis8Res[ifile][isideAC][ieta][iphi]->Fill(residuals[ires]); - } - if (isideAC==0) { - totalTrackChi2BIS8A+=trackChi2; - nTracksBIS8A++; - } - else { - totalTrackChi2BIS8C+=trackChi2; - nTracksBIS8C++; - } - } - - totalTrackChi2+=trackChi2; - nTracks++; - - } // loop over tree entries - - // fill graphs - nTracksGr ->SetPoint(ifile, (double)iter,(double)nTracks); - nTracksBEEAGr ->SetPoint(ifile, (double)iter, (double)nTracksBEEA); - nTracksBEECGr ->SetPoint(ifile, (double)iter, (double)nTracksBEEC); - nTracksEELAGr ->SetPoint(ifile, (double)iter, (double)nTracksEELA); - nTracksEELCGr ->SetPoint(ifile, (double)iter, (double)nTracksEELC); - nTracksBIS8AGr ->SetPoint(ifile, (double)iter, (double)nTracksBIS8A); - nTracksBIS8CGr ->SetPoint(ifile, (double)iter, (double)nTracksBIS8C); - trackChi2Gr ->SetPoint(ifile, (double)iter, totalTrackChi2 /(double)nTracks); - trackChi2BEEAGr ->SetPoint(ifile, (double)iter, totalTrackChi2BEEA /(double)nTracksBEEA); - trackChi2BEECGr ->SetPoint(ifile, (double)iter, totalTrackChi2BEEC /(double)nTracksBEEC); - trackChi2EELAGr ->SetPoint(ifile, (double)iter, totalTrackChi2EELA /(double)nTracksEELA); - trackChi2EELCGr ->SetPoint(ifile, (double)iter, totalTrackChi2EELC /(double)nTracksEELC); - trackChi2BIS8AGr->SetPoint(ifile, (double)iter, totalTrackChi2BIS8A/(double)nTracksBIS8A); - trackChi2BIS8CGr->SetPoint(ifile, (double)iter, totalTrackChi2BIS8C/(double)nTracksBIS8C); - - } // ifile - - TGraph* nTracksGrArr[7]={nTracksGr, - nTracksBEEAGr,nTracksBEECGr, - nTracksEELAGr,nTracksEELCGr, - nTracksBIS8AGr,nTracksBIS8CGr}; - string nTracksTitles[7]={"# tracks", - "# BEE tracks - A side", "# BEE tracks - C side", - "# EEL tracks - A side", "# EEL tracks - C side", - "# BIS8 tracks - A side", "# BIS8 tracks - C side"}; - - TGraph* trackChi2GrArr[7]={trackChi2Gr, - trackChi2BEEAGr,trackChi2BEECGr, - trackChi2EELAGr,trackChi2EELCGr, - trackChi2BIS8AGr,trackChi2BIS8CGr}; - string trackChi2Titles[7]={"average track #chi^{2}", - "average track #chi^{2} -BEE A side", "average track #chi^{2} -BEE C side", - "average track #chi^{2} -EEL A side", "average track #chi^{2} -EEL C side", - "average track #chi^{2} -BIS8 A side", "average track #chi^{2} -BIS8 C side"}; - - for (int igr=0;igr<7;igr++) { - for (int itype=0;itype<2;itype++) { - - TCanvas* canvGr=new TCanvas("gr","gr"); - canvGr->SetFillColor(10); - - TGraph* gr =(itype==0)?nTracksGrArr[igr]:trackChi2GrArr[igr]; - string title=(itype==0)?nTracksTitles[igr]:trackChi2Titles[igr]; - - canvGr->Clear(); - gr->SetMarkerStyle(8); - gr->SetMarkerSize(.7); - gr->Draw("APL"); - gr->GetYaxis()->SetTitle(title.c_str()); - gr->GetXaxis()->SetTitle("# iteration"); - canvGr->Modified(); - - string canvname=string(gr->GetName())+".eps"; - canvGr->Print(canvname.c_str()); - - delete canvGr; + const int phicolor[16] = {kRed + 4, kRed + 2, kRed, kMagenta + 4, kMagenta + 2, kMagenta, kBlue + 4, kBlue + 2, + kBlue, kCyan + 4, kCyan + 2, kCyan, kGreen + 4, kGreen + 2, kGreen, kYellow + 2}; + + for (int iplot = 0; iplot < 6; iplot++) { + const std::string plottype = plottypes[iplot]; + + std::vector<double> traz0; + std::vector<double> trat0; + std::vector<double> rots0; + std::vector<double> rotz0; + std::vector<double> rott0; + std::string dummy; + char ALineMarker; + int jff, jzz, job; + std::string type; + double tras, traz, trat, rots, rotz, rott; + + std::vector<std::string> names; + std::vector<int> etas; + std::vector<int> phis; + std::vector<TGraph*> graphs_traz; + std::vector<TGraph*> graphs_trat; + std::vector<TGraph*> graphs_rots; + std::vector<TGraph*> graphs_rotz; + std::vector<TGraph*> graphs_rott; + + double minz(9.), mint(9.), minrs(9.), minrz(9.), minrt(9.); + double maxz(-9.), maxt(-9.), maxrs(-9.), maxrz(-9.), maxrt(-9.); + + for (int ifile = 0; ifile < NFILES; ifile++) { + int iter = iters[ifile]; + + std::stringstream filename; + filename << "outputAszt_iter" << iter << ".txt"; + std::ifstream file(filename.str().c_str()); + file >> dummy; + int ich = 0; + while (file >> ALineMarker >> type >> jff >> jzz >> job >> tras >> traz >> trat >> rots >> rotz >> rott) { + if (plottype == "BEEA" && (type != "BEE" || jzz < 0)) continue; + if (plottype == "BEEC" && (type != "BEE" || jzz > 0)) continue; + if (plottype == "EELA" && (type != "EEL" || jzz < 0)) continue; + if (plottype == "EELC" && (type != "EEL" || jzz > 0)) continue; + if (plottype == "BIS8A" && (type != "BIS" || jzz != 8)) continue; + if (plottype == "BIS8C" && (type != "BIS" || jzz != -8)) continue; + + // std::cout<<ich<<" "<<type<<" "<<jff<<" "<<jzz<<" "<<tras<<std::endl; + + if (traz < minz) minz = traz; + if (traz > maxz) maxz = traz; + if (trat < mint) mint = trat; + if (trat > maxt) maxt = trat; + if (rots < minrs) minrs = rots; + if (rots > maxrs) maxrs = rots; + if (rotz < minrz) minrz = rotz; + if (rotz > maxrz) maxrz = rotz; + if (rott < minrt) minrt = rott; + if (rott > maxrt) maxrt = rott; + + if (ifile == 0) { + std::stringstream chname; + chname << type << std::abs(jzz); + if (jzz < 0) + chname << "C"; + else + chname << "A"; + int detphi = 2 * jff; + if (type.substr(2, 1) == "L") + detphi--; + else if (type.substr(2, 1) != "S" && type != "BEE") + detphi = jff; + chname << std::setfill('0') << std::setw(2) << detphi; + + // std::cout<<"chname: "<<chname.str()<<std::endl; + + names.push_back(chname.str()); + etas.push_back(std::abs(jzz) - 1); + phis.push_back(jff - 1); + graphs_traz.push_back(new TGraph(NFILES)); + graphs_trat.push_back(new TGraph(NFILES)); + graphs_rots.push_back(new TGraph(NFILES)); + graphs_rotz.push_back(new TGraph(NFILES)); + graphs_rott.push_back(new TGraph(NFILES)); + } + graphs_traz[ich]->SetPoint(ifile, iter, traz); + graphs_trat[ich]->SetPoint(ifile, iter, trat); + graphs_rots[ich]->SetPoint(ifile, iter, rots * 1000.); + graphs_rotz[ich]->SetPoint(ifile, iter, rotz * 1000.); + graphs_rott[ich]->SetPoint(ifile, iter, rott * 1000.); + + graphs_traz[ich]->SetTitle("z"); + graphs_trat[ich]->SetTitle("t"); + graphs_rots[ich]->SetTitle("rot s"); + graphs_rotz[ich]->SetTitle("rot z"); + graphs_rott[ich]->SetTitle("rot t"); + ich++; + } + } + + TCanvas* canv = new TCanvas("canv", "canv"); + TLegend* leg = new TLegend(.1, .1, .9, .9); + canv->SetFillColor(10); + canv->Divide(3, 2); + for (int i = 0; i < 5; i++) { + std::vector<TGraph*>& gr = graphs_traz; + double max(0.), min(0.); + switch (i) { + case 0: + gr = graphs_traz; + max = maxz; + min = minz; + break; + case 1: + gr = graphs_trat; + max = maxt; + min = mint; + break; + case 2: + gr = graphs_rots; + max = maxrs; + min = minrs; + break; + case 3: + gr = graphs_rotz; + max = maxrz; + min = minrz; + break; + case 4: + gr = graphs_rott; + max = maxrt; + min = minrt; + break; + } + + if (max < 0.) max = 0.; + if (min > 0.) min = 0.; + if (i >= 2) { + max *= 1000.; + min *= 1000.; + } + + // std::cout<<"i/min/max: "<<i<<"/"<<min<<"/"<<max<<std::endl; + + canv->cd(i + 2); + for (int ich = 0; ich < (int)names.size(); ich++) { + gr[ich]->SetMaximum(1.2 * max); + gr[ich]->SetMinimum(1.2 * min); + gr[ich]->SetMarkerSize(.4); + int color = (plottype.substr(0, 3) == "EEL") ? phicolor[ich * 2] : phicolor[ich]; + + // set color for later use for BEE and EEL plots + int ieta = etas[ich]; + int iphi = phis[ich]; + if (plottype.substr(0, 3) == "EEL") + eelcolor[ieta][iphi] = color; + else if (plottype.substr(0, 3) == "BEE") + beecolor[ieta][iphi] = color; + else + bis8color[0][iphi] = color; + + gr[ich]->SetMarkerColor(color); + gr[ich]->SetMarkerStyle(8); + gr[ich]->SetLineColor(color); + // gr[ich]->SetLineWidth(1.6); + gr[ich]->SetMarkerSize(.7); + if (ich == 0) + gr[ich]->Draw("APL"); + else + gr[ich]->Draw("PLsame"); + gr[ich]->GetXaxis()->SetTitle("iteration"); + if (i < 2) + gr[ich]->GetYaxis()->SetTitle("mm"); + else + gr[ich]->GetYaxis()->SetTitle("mrad"); + if (i == 0) leg->AddEntry(gr[ich], names[ich].c_str(), "lp"); + } + } + canv->cd(1); + leg->Draw(); + canv->Modified(); + + if (plottype == "BEEA") + canv->Print("BEEA_trend.eps"); + else if (plottype == "BEEC") + canv->Print("BEEC_trend.eps"); + else if (plottype == "EELA") + canv->Print("EELA_trend.eps"); + else if (plottype == "EELC") + canv->Print("EELC_trend.eps"); + else if (plottype == "BIS8A") + canv->Print("BIS8A_trend.eps"); + else if (plottype == "BIS8C") + canv->Print("BIS8C_trend.eps"); + + delete canv; + delete leg; } - } - - // get residual means/widths - gStyle->SetOptStat(000000011); - gStyle->SetOptFit(0111); - TGraph**** beeResPeaks0 = new TGraph***[2]; - TGraph**** beeResMeans0 = new TGraph***[2]; - TGraph**** beeResWidth0 = new TGraph***[2]; - TGraph**** eelResPeaks0 = new TGraph***[2]; - TGraph**** eelResMeans0 = new TGraph***[2]; - TGraph**** eelResWidth0 = new TGraph***[2]; - TGraph**** bis8ResPeaks0 = new TGraph***[2]; - TGraph**** bis8ResMeans0 = new TGraph***[2]; - TGraph**** bis8ResWidth0 = new TGraph***[2]; - - TGraph** allBeeResPeaks0 = new TGraph*[2]; - TGraph** allBeeResMeans0 = new TGraph*[2]; - TGraph** allBeeResWidth0 = new TGraph*[2]; - TGraph** allEelResPeaks0 = new TGraph*[2]; - TGraph** allEelResMeans0 = new TGraph*[2]; - TGraph** allEelResWidth0 = new TGraph*[2]; - - TGraph**** beeResPeaks1 = new TGraph***[2]; - TGraph**** beeResMeans1 = new TGraph***[2]; - TGraph**** beeResWidth1 = new TGraph***[2]; - TGraph**** eelResPeaks1 = new TGraph***[2]; - TGraph**** eelResMeans1 = new TGraph***[2]; - TGraph**** eelResWidth1 = new TGraph***[2]; - TGraph**** bis8ResPeaks1 = new TGraph***[2]; - TGraph**** bis8ResMeans1 = new TGraph***[2]; - TGraph**** bis8ResWidth1 = new TGraph***[2]; - - TGraph** allBeeResPeaks1 = new TGraph*[2]; - TGraph** allBeeResMeans1 = new TGraph*[2]; - TGraph** allBeeResWidth1 = new TGraph*[2]; - TGraph** allEelResPeaks1 = new TGraph*[2]; - TGraph** allEelResMeans1 = new TGraph*[2]; - TGraph** allEelResWidth1 = new TGraph*[2]; - - TF1***** beeFits = new TF1****[2]; - TF1***** eelFits = new TF1****[2]; - TF1***** bis8Fits = new TF1****[2]; - - TF1*** allBeeFits = new TF1**[2]; - TF1*** allEelFits = new TF1**[2]; - - TLegend** legbeeall=new TLegend*[2]; - - for (int isideAC=0;isideAC<2;isideAC++) { - - legbeeall[isideAC]=new TLegend(.1,.1,.9,.9); - - allBeeFits[isideAC]=new TF1*[NFILES]; - allEelFits[isideAC]=new TF1*[NFILES]; - - TCanvas* fitcanvbee=new TCanvas("fitcanvbee","BEE gaussian fits"); - fitcanvbee->SetFillColor(10); - fitcanvbee->Divide(3,1); - - TCanvas* fitcanveel=new TCanvas("fitcanveel","EEL gaussian fits"); - fitcanveel->SetFillColor(10); - fitcanveel->Divide(3,2); - - TCanvas* fitcanvbis8=new TCanvas("fitcanvbis8","EEL gaussian fits"); - fitcanvbis8->SetFillColor(10); - fitcanvbis8->Divide(3,1); - - TCanvas* alleelcanv =new TCanvas("alleelcanv","alleelcanv"); - alleelcanv->SetFillColor(10); - alleelcanv->Divide(3,2); - - bool firstplotbee=true; - bool firstploteel=true; - bool firstplotbis8=true; - - beeResPeaks0 [isideAC] = new TGraph**[2]; - beeResMeans0 [isideAC] = new TGraph**[2]; - beeResWidth0 [isideAC] = new TGraph**[2]; - eelResPeaks0 [isideAC] = new TGraph**[2]; - eelResMeans0 [isideAC] = new TGraph**[2]; - eelResWidth0 [isideAC] = new TGraph**[2]; - bis8ResPeaks0[isideAC] = new TGraph**[2]; - bis8ResMeans0[isideAC] = new TGraph**[2]; - bis8ResWidth0[isideAC] = new TGraph**[2]; - beeResPeaks1 [isideAC] = new TGraph**[2]; - beeResMeans1 [isideAC] = new TGraph**[2]; - beeResWidth1 [isideAC] = new TGraph**[2]; - eelResPeaks1 [isideAC] = new TGraph**[2]; - eelResMeans1 [isideAC] = new TGraph**[2]; - eelResWidth1 [isideAC] = new TGraph**[2]; - bis8ResPeaks1[isideAC] = new TGraph**[2]; - bis8ResMeans1[isideAC] = new TGraph**[2]; - bis8ResWidth1[isideAC] = new TGraph**[2]; - beeFits [isideAC] = new TF1***[2]; - eelFits [isideAC] = new TF1***[2]; - bis8Fits [isideAC] = new TF1***[2]; - - - - for (int ieta=0;ieta<2;ieta++) { - - TCanvas* allbeecanv =new TCanvas("allbeecanv","allbeecanv"); - allbeecanv->SetFillColor(10); - allbeecanv->Divide(4,2); - - TCanvas* allbis8canv=new TCanvas("allbis8canv","allbis8canv"); - allbis8canv->SetFillColor(10); - allbis8canv->Divide(4,2); - - beeResPeaks0 [isideAC][ieta] = new TGraph*[8]; - beeResMeans0 [isideAC][ieta] = new TGraph*[8]; - beeResWidth0 [isideAC][ieta] = new TGraph*[8]; - eelResPeaks0 [isideAC][ieta] = new TGraph*[8]; - eelResMeans0 [isideAC][ieta] = new TGraph*[8]; - eelResWidth0 [isideAC][ieta] = new TGraph*[8]; - bis8ResPeaks0[isideAC][ieta] = new TGraph*[8]; - bis8ResMeans0[isideAC][ieta] = new TGraph*[8]; - bis8ResWidth0[isideAC][ieta] = new TGraph*[8]; - beeResPeaks1 [isideAC][ieta] = new TGraph*[8]; - beeResMeans1 [isideAC][ieta] = new TGraph*[8]; - beeResWidth1 [isideAC][ieta] = new TGraph*[8]; - eelResPeaks1 [isideAC][ieta] = new TGraph*[8]; - eelResMeans1 [isideAC][ieta] = new TGraph*[8]; - eelResWidth1 [isideAC][ieta] = new TGraph*[8]; - bis8ResPeaks1[isideAC][ieta] = new TGraph*[8]; - bis8ResMeans1[isideAC][ieta] = new TGraph*[8]; - bis8ResWidth1[isideAC][ieta] = new TGraph*[8]; - beeFits [isideAC][ieta] = new TF1**[8]; - eelFits [isideAC][ieta] = new TF1**[8]; - bis8Fits [isideAC][ieta] = new TF1**[8]; - for (int iphi=0;iphi<8;iphi++) { - beeResPeaks0 [isideAC][ieta][iphi] = new TGraph(NFILES); - beeResMeans0 [isideAC][ieta][iphi] = new TGraph(NFILES); - beeResWidth0 [isideAC][ieta][iphi] = new TGraph(NFILES); - eelResPeaks0 [isideAC][ieta][iphi] = new TGraph(NFILES); - eelResMeans0 [isideAC][ieta][iphi] = new TGraph(NFILES); - eelResWidth0 [isideAC][ieta][iphi] = new TGraph(NFILES); - bis8ResPeaks0[isideAC][ieta][iphi] = new TGraph(NFILES); - bis8ResMeans0[isideAC][ieta][iphi] = new TGraph(NFILES); - bis8ResWidth0[isideAC][ieta][iphi] = new TGraph(NFILES); - beeResPeaks1 [isideAC][ieta][iphi] = new TGraph(NFILES); - beeResMeans1 [isideAC][ieta][iphi] = new TGraph(NFILES); - beeResWidth1 [isideAC][ieta][iphi] = new TGraph(NFILES); - eelResPeaks1 [isideAC][ieta][iphi] = new TGraph(NFILES); - eelResMeans1 [isideAC][ieta][iphi] = new TGraph(NFILES); - eelResWidth1 [isideAC][ieta][iphi] = new TGraph(NFILES); - bis8ResPeaks1[isideAC][ieta][iphi] = new TGraph(NFILES); - bis8ResMeans1[isideAC][ieta][iphi] = new TGraph(NFILES); - bis8ResWidth1[isideAC][ieta][iphi] = new TGraph(NFILES); - beeFits [isideAC][ieta][iphi] = new TF1*[NFILES]; - eelFits [isideAC][ieta][iphi] = new TF1*[NFILES]; - bis8Fits [isideAC][ieta][iphi] = new TF1*[NFILES]; - - TCanvas* beecanv =new TCanvas("beecanv","BEE residuals"); - beecanv->SetFillColor(10); - TCanvas* eelcanv =new TCanvas("eelcanv","EEL residuals"); - eelcanv->SetFillColor(10); - TCanvas* bis8canv=new TCanvas("bis8canv","BIS8 residuals"); - bis8canv->SetFillColor(10); - - TCanvas* dummy=new TCanvas("dummy","dummy"); - //TLegend* legBee=new TLegend(.6,.8,.8,.95); - //TLegend* legEel=new TLegend(.6,.8,.8,.95); - TPaveStats** statsBee =new TPaveStats*[NFILES]; - TPaveStats** statsEel =new TPaveStats*[NFILES]; - //TPaveStats** statsBis8=new TPaveStats*[NFILES]; - - double deltax(0.); - double deltay(.2); - bool firstiter=true; - for (int ifile=NFILES-1;ifile>=0;ifile--) { - int iter=iters[ifile]; - stringstream iterstr; iterstr<<"iter"<<iter; - dummy->cd(); - dummy->Clear(); - - beeFits[isideAC][ieta][iphi][ifile]= - new TF1((hbeenames[isideAC][ieta][iphi]+string("_fit_")+iterstr.str()).c_str(), - //"[0]*exp(-0.5*((x-[1])/[2])^2)+[3]*exp(-0.5*((x-[4])/[5])^2)", -1.,1.); - "[0]*exp(-0.5*((x-[1])/[2])^2)", -6.,6.); - TH1F* hBee=beeRes [ifile][isideAC][ieta][iphi]; - TF1* fBee=beeFits[isideAC][ieta][iphi][ifile]; - //fBee->SetParameters(hBee->GetMaximum(),hBee->GetMean(),.2, - // hBee->GetMaximum()/7.,hBee->GetMean(),.5); - fBee->SetParameters(hBee->GetMaximum(),hBee->GetMean(),.2); - //fBee->SetParLimits(0,hBee->GetMaximum()*.8,hBee->GetMaximum()*2.); - //fBee->SetParLimits(3,0.,hBee->GetMaximum()*.8); - //fBee->SetParLimits(5,0.,1.); - hBee->Fit(fBee,"QR"); - - beeResPeaks0[isideAC][ieta][iphi]->SetPoint(ifile,iter,fBee->GetParameter(0)); - beeResMeans0[isideAC][ieta][iphi]->SetPoint(ifile,iter,fBee->GetParameter(1)); - beeResWidth0[isideAC][ieta][iphi]->SetPoint(ifile,iter,std::fabs(fBee->GetParameter(2))); - beeResPeaks1[isideAC][ieta][iphi]->SetPoint(ifile,iter,fBee->GetParameter(3)); - beeResMeans1[isideAC][ieta][iphi]->SetPoint(ifile,iter,fBee->GetParameter(4)); - beeResWidth1[isideAC][ieta][iphi]->SetPoint(ifile,iter,std::fabs(fBee->GetParameter(5))); - - dummy->Update(); - - TPaveStats* stats=(TPaveStats*)hBee->FindObject("stats"); - //stringstream testname; testname<<"testBEE_iter"<<iter<<".eps"; - //dummy->Print(testname.str().c_str()); - - if (!stats) { - cout<<"no stats for beeRes["<<ifile<<"]["<<isideAC<<"]["<<ieta<<"]["<<iphi<<"]" - <<std::endl; - continue; - } - - statsBee[ifile]=stats; - if (firstiter) { - deltax=stats->GetX2NDC()-stats->GetX1NDC(); - //deltay=stats->GetY2NDC()-stats->GetY1NDC(); - } - int ipos=(ifile<4)?ifile:ifile-4; - - stats->SetY2NDC(stats->GetY2NDC()-deltay*(double)ipos); - stats->SetY1NDC(stats->GetY2NDC()-deltay); - if (ifile>=4) { - stats->SetX1NDC(.05); - stats->SetX2NDC(.05+deltax); - } - stats->SetTextColor(phicolor[ifile]); - - beecanv->cd(); - //hBee->SetLineWidth(.8); - hBee->SetLineColor(phicolor[ifile]); - hBee->GetXaxis()->SetTitle("residuals (mm)"); - //rdh hBee->SetMaximum(1000.); - if (firstiter) { - hBee->Draw(); - } - else hBee->Draw("same"); - //fBee->SetLineWidth(1.5); - fBee->SetLineColor(phicolor[ifile]); - fBee->Draw("same"); - - allbeecanv->cd(iphi+1); - if (firstiter) hBee->Draw(); - else hBee->Draw("same"); - fBee->SetLineColor(phicolor[ifile]); - fBee->Draw("same"); - - if ( (isideAC==0 && iphi==5) || - (isideAC==1 && iphi==7) || - (iphi==2&&ieta==0) || iphi==6) { - - dummy->cd(); - dummy->Clear(); - eelFits[isideAC][ieta][iphi][ifile]= - new TF1((heelnames[isideAC][ieta][iphi]+string("_fit_")+iterstr.str()).c_str(), - "[0]*exp(-0.5*((x-[1])/[2])^2)+[3]*exp(-0.5*((x-[4])/[5])^2)", -1.,1.); - //"[0]*exp(-0.5*((x-[1])/[2])^2)", -1.,1.); - TH1F* hEel=eelRes[ifile][isideAC][ieta][iphi]; - TF1* fEel=eelFits[isideAC][ieta][iphi][ifile]; - fEel->SetParameters(hEel->GetMaximum(),hEel->GetMean(),.2, - hEel->GetMaximum()/7.,hEel->GetMean(),.5); - //fEel->SetParameters(hEel->GetMaximum(),hEel->GetMean(),.2); - // - fEel->SetParLimits(0,hEel->GetMaximum()*.8,hEel->GetMaximum()*2.); - fEel->SetParLimits(3,0.,hEel->GetMaximum()*.8); - fEel->SetParLimits(5,0.,1.); - hEel->Fit(fEel,"QR"); - - eelResPeaks0[isideAC][ieta][iphi]->SetPoint(ifile,iter,fEel->GetParameter(0)); - eelResMeans0[isideAC][ieta][iphi]->SetPoint(ifile,iter,fEel->GetParameter(1)); - eelResWidth0[isideAC][ieta][iphi]->SetPoint(ifile,iter,fEel->GetParameter(2)); - eelResPeaks1[isideAC][ieta][iphi]->SetPoint(ifile,iter,fEel->GetParameter(3)); - eelResMeans1[isideAC][ieta][iphi]->SetPoint(ifile,iter,fEel->GetParameter(4)); - eelResWidth1[isideAC][ieta][iphi]->SetPoint(ifile,iter,fEel->GetParameter(5)); - - dummy->Update(); - TPaveStats* stats1=(TPaveStats*)hEel->FindObject("stats"); - //dummy->Print("testEEL.eps"); - - statsEel[ifile]=stats1; - if (firstiter) { - deltax=stats1->GetX2NDC()-stats1->GetX1NDC(); - } - int ipos=(ifile<4)?ifile:ifile-4; - stats1->SetY2NDC(stats1->GetY2NDC()-deltay*(double)ipos); - stats1->SetY1NDC(stats1->GetY2NDC()-deltay); - if (ifile>=4) { - stats1->SetX1NDC(.05); - stats1->SetX2NDC(.05+deltax); - } - stats1->SetTextColor(phicolor[ifile]); - - eelcanv->cd(); - //hEel->SetLineWidth(.8); - hEel->SetLineColor(phicolor[ifile]); - hEel->GetXaxis()->SetTitle("residuals (mm)"); - //hEel->SetMaximum(3700.); - if (firstiter) { - hEel->Draw(); - } - else hEel->Draw("same"); - //fEel->SetLineWidth(1.5); - fEel->SetLineColor(phicolor[ifile]); - fEel->Draw("same"); - - int ipad=1; - if (iphi>=5&&iphi<=7) { - if (iphi==6) { - if (ieta==0) ipad=2; - else ipad=5; - } - else if (iphi==5||iphi==7) { - if (ieta==0) ipad=3; - else ipad=6; - } - } - alleelcanv->cd(ipad); - //hEel->SetLineWidth(.5); - //fEel->SetLineWidth(.6); - if (firstiter) hEel->Draw(); - else hEel->Draw("same"); - fEel->Draw("same"); - - } - - /* - if (ieta==0) { - dummy->cd(); - dummy->Clear(); - bis8Fits[isideAC][ieta][iphi][ifile]= - //new TF1((hbis8names[isideAC][ieta][iphi]+string("_fit_")+iterstr.str()).c_str(), - // "[0]*exp(-0.5*((x-[1])/[2])^2)+[3]*exp(-0.5*((x-[4])/[5])^2)", -1.,1.); - new TF1((hbis8names[isideAC][ieta][iphi]+string("_fit_")+iterstr.str()).c_str(), - "[0]*exp(-0.5*((x-[1])/[2])^2)", -1.,1.); - TH1F* hBis8=bis8Res [ifile][isideAC][ieta][iphi]; - TF1* fBis8=bis8Fits[isideAC][ieta][iphi][ifile]; - fBis8->SetParameters(hBis8->GetMaximum(),hBis8->GetMean(),.2); - //hBis8->GetMaximum()/7.,hBis8->GetMean(),.5); - //fBis8->SetParLimits(0,hBis8->GetMaximum()*.8,hBis8->GetMaximum()*2.); - //fBis8->SetParLimits(3,0.,hBis8->GetMaximum()*.8); - //fBis8->SetParLimits(5,0.,1.); - hBis8->Fit(fBis8,"QRW"); - - bis8ResPeaks0[isideAC][ieta][iphi]->SetPoint(ifile,iter,fBis8->GetParameter(0)); - bis8ResMeans0[isideAC][ieta][iphi]->SetPoint(ifile,iter,fBis8->GetParameter(1)); - bis8ResWidth0[isideAC][ieta][iphi]->SetPoint(ifile,iter,fBis8->GetParameter(2)); - //bis8ResPeaks1[isideAC][ieta][iphi]->SetPoint(iter,iter,fBis8->GetParameter(3)); - //bis8ResMeans1[isideAC][ieta][iphi]->SetPoint(iter,iter,fBis8->GetParameter(4)); - //bis8ResWidth1[isideAC][ieta][iphi]->SetPoint(iter,iter,fBis8->GetParameter(5)); - - dummy->Update(); - TPaveStats* statsbis8=(TPaveStats*)hBis8->FindObject("stats"); - //dummy->Print("testBIS8.eps"); - - statsBis8[ifile]=statsbis8; - if (firstiter) { - deltax=statsbis8->GetX2NDC()-statsbis8->GetX1NDC(); - } - int iposbis8=(ifile<4)?ifile:ifile-4; - statsbis8->SetY2NDC(statsbis8->GetY2NDC()-deltay*(double)iposbis8); - statsbis8->SetY1NDC(statsbis8->GetY2NDC()-deltay); - if (ifile>=4) { - statsbis8->SetX1NDC(.05); - statsbis8->SetX2NDC(.05+deltax); - } - statsbis8->SetTextColor(phicolor[ifile]); - - bis8canv->cd(); - //hBis8->SetLineWidth(.8); - hBis8->SetLineColor(phicolor[ifile]); - hBis8->SetMaximum(20.); - if (firstiter) { - hBis8->Draw(); - } - else hBis8->Draw("same"); - //fBis8->SetLineWidth(1.5); - fBis8->SetLineColor(phicolor[ifile]); - fBis8->Draw("same"); - - allbis8canv->cd(iphi+1); - //hBis8->SetLineWidth(.5); - //fBis8->SetLineWidth(.6); - if (firstiter) hBis8->Draw(); - else hBis8->Draw(); - fBis8->Draw("same"); - } - */ - firstiter=false; - } - //legBis8->Draw(); - if (ieta==0) - bis8canv->Print((hbis8names[isideAC][ieta][iphi]+"_res.eps").c_str()); - delete bis8canv; - - if ( (isideAC==0 && iphi==5) || - (isideAC==1 && iphi==7) || - (iphi==2&&ieta==0) || iphi==6) { - //legEel->Draw(); - eelcanv->Print((heelnames[isideAC][ieta][iphi]+"_res.eps").c_str()); - } - delete eelcanv; - - beecanv->Print((hbeenames[isideAC][ieta][iphi]+"_res.eps").c_str()); - delete beecanv; - - delete dummy; - - - string grtitles[6]={"inner peak","inner mean (mm)", "inner width (mm)", - "outer peak","outer mean (mm)", "outer width (mm)"}; - //string grtitlesbee[6]={"inner peak","inner mean (mm)", - // "inner width (mm)", - // "outer peak","outer mean (mm)", - // "outer width (mm)"}; - string grtitlesbee[3]={"peak","mean (mm)", "width (mm)"}; - - int colorbee=beecolor[ieta][iphi]; - //double maxbee[6]={1000., .3,.3, 250., .6,1.}; - //double minbee[6]={ 0.,-.3,0., 0.,-.6,0.}; - //for (int ipad=1;ipad<=6;ipad++) { - double maxbee[6]={250., 4.5,2.}; - double minbee[6]={ 0.,-2.,0.}; - for (int ipad=1;ipad<=3;ipad++) { - fitcanvbee->cd(ipad); - TGraph* gr; - switch (ipad) { - case 1: gr=beeResPeaks0[isideAC][ieta][iphi]; break; - case 2: gr=beeResMeans0[isideAC][ieta][iphi]; break; - case 3: gr=beeResWidth0[isideAC][ieta][iphi]; break; - case 4: gr=beeResPeaks1[isideAC][ieta][iphi]; break; - case 5: gr=beeResMeans1[isideAC][ieta][iphi]; break; - case 6: gr=beeResWidth1[isideAC][ieta][iphi]; break; - } - - gr->SetMarkerColor(colorbee); - gr->SetMarkerStyle(8); - gr->SetMarkerSize(.7); - gr->SetLineColor(colorbee); - //gr->SetLineWidth(1.6); - if (firstplotbee) { - gr->SetTitle(grtitlesbee[ipad-1].c_str()); - gr->SetMinimum(minbee[ipad-1]); - gr->SetMaximum(maxbee[ipad-1]); - gr->Draw("APL"); - } - else gr->Draw("PLsame"); - } - firstplotbee=false; - - if ( (isideAC==0 && iphi==5) || - (isideAC==1 && iphi==7) || - (iphi==2&&ieta==0) || iphi==6) { - - int coloreel=eelcolor[ieta][iphi]; - double maxeel[6]={3700., .1,.3,1500., .5,.5}; - double mineel[6]={ 0.,-.1,0., 0.,-.5,0.}; - for (int ipad=1;ipad<=6;ipad++) { - fitcanveel->cd(ipad); - TGraph* gr; - switch (ipad) { - case 1: gr=eelResPeaks0[isideAC][ieta][iphi]; break; - case 2: gr=eelResMeans0[isideAC][ieta][iphi]; break; - case 3: gr=eelResWidth0[isideAC][ieta][iphi]; break; - case 4: gr=eelResPeaks1[isideAC][ieta][iphi]; break; - case 5: gr=eelResMeans1[isideAC][ieta][iphi]; break; - case 6: gr=eelResWidth1[isideAC][ieta][iphi]; break; - } - - gr->SetMarkerColor(coloreel); - gr->SetMarkerStyle(8); - gr->SetMarkerSize(.7); - gr->SetLineColor(coloreel); - //gr->SetLineWidth(1.6); - if (firstploteel) { - gr->SetTitle(grtitles[ipad-1].c_str()); - gr->SetMinimum(mineel[ipad-1]); - gr->SetMaximum(maxeel[ipad-1]); - gr->Draw("APL"); - } - else gr->Draw("PLsame"); - } - firstploteel=false; - } - - if (ieta==0) { - - int colorbis8=bis8color[ieta][iphi]; - double maxbis8[6]={20., .2,1.,20., .5,.5}; - double minbis8[6]={ 0.,-.2,1., 0.,-.5,0.}; - for (int ipad=1;ipad<=3;ipad++) { - fitcanvbis8->cd(ipad); - TGraph* gr; - switch (ipad) { - case 1: gr=bis8ResPeaks0[isideAC][ieta][iphi]; break; - case 2: gr=bis8ResMeans0[isideAC][ieta][iphi]; break; - case 3: gr=bis8ResWidth0[isideAC][ieta][iphi]; break; - case 4: gr=bis8ResPeaks1[isideAC][ieta][iphi]; break; - case 5: gr=bis8ResMeans1[isideAC][ieta][iphi]; break; - case 6: gr=bis8ResWidth1[isideAC][ieta][iphi]; break; - } - - gr->SetMarkerColor(colorbis8); - gr->SetMarkerStyle(8); - gr->SetMarkerSize(.7); - gr->SetLineColor(colorbis8); - //gr->SetLineWidth(1.6); - if (firstplotbis8) { - gr->SetTitle(grtitles[ipad-1].c_str()); - gr->SetMinimum(minbis8[ipad-1]); - gr->SetMaximum(maxbis8[ipad-1]); - gr->Draw("APL"); - } - else gr->Draw("PLsame"); - } - firstplotbis8=false; - } - - } // iphi - - std::stringstream beecanvname; - beecanvname<<"allBEE_side"; - if (isideAC==0) beecanvname<<"A"; else beecanvname<<"C"; - beecanvname<<"_stEta"<<ieta+1; - beecanvname<<".eps"; - allbeecanv->Print(beecanvname.str().c_str()); - delete allbeecanv; - - if (ieta==0) { - std::stringstream bis8canvname; - bis8canvname<<"allBIS8_side"; - if (isideAC==0) bis8canvname<<"A"; else bis8canvname<<"C"; - bis8canvname<<".eps"; - allbis8canv->Print(bis8canvname.str().c_str()); - delete allbis8canv; - } - - } // ieta - - TCanvas* allBeeResCanv=new TCanvas("allBeeResCanv","allBeeResCanv"); - allBeeResCanv->SetFillColor(10); - allBeeResCanv->Divide(3,1); - - TCanvas* allEelResCanv=new TCanvas("allEelResCanv","allEelResCanv"); - allEelResCanv->SetFillColor(10); - allEelResCanv->Divide(3,1); - - allBeeResPeaks0[isideAC] = new TGraph(NFILES); - allBeeResMeans0[isideAC] = new TGraph(NFILES); - allBeeResWidth0[isideAC] = new TGraph(NFILES); - - allEelResPeaks0[isideAC] = new TGraph(NFILES); - allEelResMeans0[isideAC] = new TGraph(NFILES); - allEelResWidth0[isideAC] = new TGraph(NFILES); - allEelResPeaks1[isideAC] = new TGraph(NFILES); - allEelResMeans1[isideAC] = new TGraph(NFILES); - allEelResWidth1[isideAC] = new TGraph(NFILES); - - TCanvas* dummy2=new TCanvas("dummy2","dummy2"); - TPaveStats** statsAllBee =new TPaveStats*[NFILES]; - TPaveStats** statsAllEel =new TPaveStats*[NFILES]; - - double deltax(0.); - double deltay(.2); - bool firstiter=true; - for (int ifile=NFILES-1;ifile>=0;ifile--) { - - int iter=iters[ifile]; - stringstream iterstr; iterstr<<"iter"<<iter; - - // BEE - dummy2->cd(); - dummy2->Clear(); - stringstream allBeeStr; allBeeStr<<"allBEE_fit_"<<iterstr.str(); - if (isideAC==0) allBeeStr<<"_sideA"; - else allBeeStr<<"_sideC"; - allBeeFits[isideAC][ifile]=new TF1( allBeeStr.str().c_str(), - "[0]*exp(-0.5*((x-[1])/[2])^2)", - -6.,6.); - - TH1F* hAllBee=allBeeRes [ifile][isideAC]; - TF1* fAllBee=allBeeFits[isideAC][ifile]; - fAllBee->SetParameters(hAllBee->GetMaximum(),hAllBee->GetMean(),.2); - hAllBee->Fit(fAllBee,"QR"); - - allBeeResPeaks0[isideAC]->SetPoint(ifile,iter,fAllBee->GetParameter(0)); - allBeeResMeans0[isideAC]->SetPoint(ifile,iter,fAllBee->GetParameter(1)); - allBeeResWidth0[isideAC]->SetPoint(ifile,iter,fAllBee->GetParameter(2)); - - dummy2->Update(); - - TPaveStats* stats2=(TPaveStats*)hAllBee->FindObject("stats"); - if (!stats2) { - std::cout<<"no stats box"<<std::endl; - continue; - } - statsAllBee[ifile]=stats2; - if (firstiter) deltax=stats2->GetX2NDC()-stats2->GetX1NDC(); - - int ipos=(ifile<4)?ifile:ifile-4; - stats2->SetY2NDC(stats2->GetY2NDC()-deltay*(double)ipos); - stats2->SetY1NDC(stats2->GetY2NDC()-deltay); - if (ifile>=4) { - stats2->SetX1NDC(.05); - stats2->SetX2NDC(.05+deltax); - } - stats2->SetTextColor(phicolor[ifile]); - - allBeeResCanv->cd(); - hAllBee->SetLineColor(phicolor[ifile]); - hAllBee->GetXaxis()->SetTitle("residuals (mm)"); - - if (firstiter) hAllBee->Draw(); - else hAllBee->Draw("same"); - - fAllBee->SetLineColor(phicolor[ifile]); - fAllBee->Draw("same"); - - // EEL - dummy2->cd(); - dummy2->Clear(); - stringstream allEelStr; allEelStr<<"allEEL_fit_"<<iterstr.str(); - if (isideAC==0) allEelStr<<"_sideA"; - else allEelStr<<"_sideC"; - allEelFits[isideAC][ifile]=new TF1( allEelStr.str().c_str(), - "[0]*exp(-0.5*((x-[1])/[2])^2)+[3]*exp(-0.5*((x-[4])/[5])^2)", - -1.,1.); - - TH1F* hAllEel=allEelRes [ifile][isideAC]; - TF1* fAllEel=allEelFits[isideAC][ifile]; - fAllEel->SetParameters(hAllEel->GetMaximum(),hAllEel->GetMean(),.2); - hAllEel->Fit(fAllEel,"QR"); - - allEelResPeaks0[isideAC]->SetPoint(ifile,iter,fAllEel->GetParameter(0)); - allEelResMeans0[isideAC]->SetPoint(ifile,iter,fAllEel->GetParameter(1)); - allEelResWidth0[isideAC]->SetPoint(ifile,iter,fAllEel->GetParameter(2)); - - dummy2->Update(); - - TPaveStats* stats3=(TPaveStats*)hAllEel->FindObject("stats"); - if (!stats3) { - std::cout<<"no stats box"<<std::endl; - continue; - } - statsAllEel[ifile]=stats3; - if (firstiter) deltax=stats3->GetX2NDC()-stats3->GetX1NDC(); - - ipos=(ifile<4)?ifile:ifile-4; - stats3->SetY2NDC(stats3->GetY2NDC()-deltay*(double)ipos); - stats3->SetY1NDC(stats3->GetY2NDC()-deltay); - if (ifile>=4) { - stats3->SetX1NDC(.05); - stats3->SetX2NDC(.05+deltax); - } - stats3->SetTextColor(phicolor[ifile]); - - allEelResCanv->cd(); - hAllEel->SetLineColor(phicolor[ifile]); - hAllEel->GetXaxis()->SetTitle("residuals (mm)"); - - if (firstiter) hAllEel->Draw(); - else hAllEel->Draw("same"); - - fAllEel->SetLineColor(phicolor[ifile]); - fAllEel->Draw("same"); - - firstiter=false; - - } - - if (isideAC==0) allBeeResCanv->Print("allBEERes_sideA.eps"); - else allBeeResCanv->Print("allBEERes_sideC.eps"); - if (isideAC==0) allEelResCanv->Print("allEELRes_sideA.eps"); - else allEelResCanv->Print("allEELRes_sideC.eps"); - - std::stringstream eelcanvname; - eelcanvname<<"allEEL_side"; - if (isideAC==0) eelcanvname<<"A"; else eelcanvname<<"C"; - eelcanvname<<".eps"; - alleelcanv->Print(eelcanvname.str().c_str()); - delete alleelcanv; - - // print fits - if (isideAC==0) { - fitcanvbee->Print("BEEA_fits.eps"); - fitcanveel->Print("EELA_fits.eps"); - fitcanvbis8->Print("BIS8A_fits.eps"); + // get residuals + TH1F*** allBeeRes = new TH1F**[NFILES]; + TH1F*** allEelRes = new TH1F**[NFILES]; + TH1F***** beeRes = new TH1F****[NFILES]; + TH1F***** eelRes = new TH1F****[NFILES]; + TH1F***** bis8Res = new TH1F****[NFILES]; + string ***hbeenames(0), ***heelnames(0), ***hbis8names(0); + + TGraph* nTracksGr = new TGraph(NFILES); + TGraph* nTracksBEEAGr = new TGraph(NFILES); + TGraph* nTracksBEECGr = new TGraph(NFILES); + TGraph* nTracksEELAGr = new TGraph(NFILES); + TGraph* nTracksEELCGr = new TGraph(NFILES); + TGraph* nTracksBIS8AGr = new TGraph(NFILES); + TGraph* nTracksBIS8CGr = new TGraph(NFILES); + TGraph* trackChi2Gr = new TGraph(NFILES); + TGraph* trackChi2BEEAGr = new TGraph(NFILES); + TGraph* trackChi2BEECGr = new TGraph(NFILES); + TGraph* trackChi2EELAGr = new TGraph(NFILES); + TGraph* trackChi2EELCGr = new TGraph(NFILES); + TGraph* trackChi2BIS8AGr = new TGraph(NFILES); + TGraph* trackChi2BIS8CGr = new TGraph(NFILES); + + nTracksGr->SetName("nTracks"); + nTracksBEEAGr->SetName("nTracksBEEA"); + nTracksBEECGr->SetName("nTracksBEEC"); + nTracksEELAGr->SetName("nTracksEELA"); + nTracksEELCGr->SetName("nTracksEELC"); + nTracksBIS8AGr->SetName("nTracksBIS8A"); + nTracksBIS8CGr->SetName("nTracksBIS8C"); + trackChi2Gr->SetName("trackChi2"); + trackChi2BEEAGr->SetName("trackChi2BEEA"); + trackChi2BEECGr->SetName("trackChi2BEEC"); + trackChi2EELAGr->SetName("trackChi2EELA"); + trackChi2EELCGr->SetName("trackChi2EELC"); + trackChi2BIS8AGr->SetName("trackChi2BIS8A"); + trackChi2BIS8CGr->SetName("trackChi2BIS8C"); + + for (int ifile = 0; ifile < NFILES; ifile++) { + int iter = iters[ifile]; + stringstream iterstr; + iterstr << "iter" << iter; + + stringstream files; + files << basedir << dirs[ifile] << "/iter" << iter << "/*"; + TChain* tree = new TChain("MuonTrackPreProcessor"); + std::cout << "adding " << files.str() << " to TChain" << std::endl; + tree->Add(files.str().c_str()); + + int nChambers, *chamberId(new int[50]), nresiduals, *resIndex(new int[50]); + double* residuals(new double[100]); + double trackChi2; + tree->SetBranchAddress("nChambers", &nChambers); + tree->SetBranchAddress("chamberId", chamberId); + tree->SetBranchAddress("nresiduals", &nresiduals); + tree->SetBranchAddress("resIndex", resIndex); + tree->SetBranchAddress("residuals", residuals); + tree->SetBranchAddress("trackChi2", &trackChi2); + + allBeeRes[ifile] = new TH1F*[2]; + allEelRes[ifile] = new TH1F*[2]; + beeRes[ifile] = new TH1F***[2]; + eelRes[ifile] = new TH1F***[2]; + bis8Res[ifile] = new TH1F***[2]; + if (ifile == 0) { + hbeenames = new string**[2]; + heelnames = new string**[2]; + hbis8names = new string**[2]; + } + // make histograms + for (int isideAC = 0; isideAC < 2; isideAC++) { + // all BEE/EEL + stringstream allEEStr; + if (isideAC == 0) + allEEStr << "sideA_"; + else + allEEStr << "sideC_"; + + string allBeeName = allEEStr.str() + iterstr.str(); + allBeeRes[ifile][isideAC] = new TH1F(("allBEE_" + allBeeName).c_str(), ("allBEE_" + allBeeName).c_str(), 100, -6., 6.); + allEelRes[ifile][isideAC] = new TH1F(("allEEL_" + allBeeName).c_str(), ("allEEL_" + allBeeName).c_str(), 100, -6., 6.); + + // individual BEE/EEL + beeRes[ifile][isideAC] = new TH1F**[2]; + eelRes[ifile][isideAC] = new TH1F**[2]; + bis8Res[ifile][isideAC] = new TH1F**[2]; + if (ifile == 0) { + hbeenames[isideAC] = new string*[2]; + heelnames[isideAC] = new string*[2]; + hbis8names[isideAC] = new string*[2]; + } + for (int ieta = 0; ieta < 2; ieta++) { + beeRes[ifile][isideAC][ieta] = new TH1F*[8]; + eelRes[ifile][isideAC][ieta] = new TH1F*[8]; + bis8Res[ifile][isideAC][ieta] = new TH1F*[8]; + if (ifile == 0) { + hbeenames[isideAC][ieta] = new string[8]; + heelnames[isideAC][ieta] = new string[8]; + hbis8names[isideAC][ieta] = new string[8]; + } + for (int iphi = 0; iphi < 8; iphi++) { + stringstream beename; + beename << "BEE" << ieta + 1; + if (isideAC == 0) + beename << "A"; + else + beename << "C"; + beename << setfill('0') << setw(2) << (iphi + 1) * 2; + beeRes[ifile][isideAC][ieta][iphi] = + new TH1F((beename.str() + "_" + iterstr.str()).c_str(), beename.str().c_str(), 100, -6., 6.); + if (ifile == 0) hbeenames[isideAC][ieta][iphi] = beename.str(); + + stringstream eelname; + eelname << "EEL" << ieta + 1; + if (isideAC == 0) + eelname << "A"; + else + eelname << "C"; + eelname << setfill('0') << setw(2) << (iphi + 1) * 2 - 1; + + eelRes[ifile][isideAC][ieta][iphi] = + new TH1F((eelname.str() + "_" + iterstr.str()).c_str(), eelname.str().c_str(), 100, -1., 1.); + if (ifile == 0) heelnames[isideAC][ieta][iphi] = eelname.str(); + + if (ieta == 0) { + stringstream bis8name; + bis8name << "BIS8"; + if (isideAC == 0) + bis8name << "A"; + else + bis8name << "C"; + bis8name << setfill('0') << setw(2) << (iphi + 1) * 2; + bis8Res[ifile][isideAC][ieta][iphi] = + new TH1F((bis8name.str() + "_" + iterstr.str()).c_str(), bis8name.str().c_str(), 100, -1., 1.); + if (ifile == 0) hbis8names[isideAC][ieta][iphi] = bis8name.str(); + } + } + } + } + + int nTracks = 0; + int nTracksBEEA = 0; + int nTracksBEEC = 0; + int nTracksEELA = 0; + int nTracksEELC = 0; + int nTracksBIS8A = 0; + int nTracksBIS8C = 0; + double totalTrackChi2 = 0.; + double totalTrackChi2BEEA = 0.; + double totalTrackChi2BEEC = 0.; + double totalTrackChi2EELA = 0.; + double totalTrackChi2EELC = 0.; + double totalTrackChi2BIS8A = 0.; + double totalTrackChi2BIS8C = 0.; + + // loop over entries and fill histograms + std::cout << "tree has " << tree->GetEntries() << " entries" << std::endl; + for (int ientry = 0; ientry < (int)tree->GetEntries(); ientry++) { + // cout<<"ientry: "<<ientry<<endl; + tree->GetEntry(ientry); + + string beeName = ""; + string eelName = ""; + string bis8Name = ""; + int firstBEERes(0), lastBEERes(0); + int firstEELRes(0), lastEELRes(0); + int firstBIS8Res(0), lastBIS8Res(0); + for (int ich = 0; ich < nChambers; ich++) { + int id = chamberId[ich]; + std::string name = chNames.chamberName(id); + // std::cout<<"name: "<<name<<std::endl; + + if (name.substr(0, 3) == "BEE") { + beeName = name; + firstBEERes = resIndex[ich]; + lastBEERes = (ich + 1 < nChambers) ? resIndex[ich + 1] : nresiduals; + } + if (name.substr(0, 3) == "EEL") { + eelName = name; + firstEELRes = resIndex[ich]; + lastEELRes = (ich + 1 < nChambers) ? resIndex[ich + 1] : nresiduals; + } + if (name.substr(0, 4) == "BIS8") { + bis8Name = name; + firstBIS8Res = resIndex[ich]; + lastBIS8Res = (ich + 1 < nChambers) ? resIndex[ich + 1] : nresiduals; + } + } + + // remove tracks not passing selection in MuonTrackPreProcessor + if (beeName == "" && eelName == "" && bis8Name == "") { continue; } + + /* + if (bis8Name!=""||eelName!="") { + cout<<" "; + for (int ich=0;ich<nChambers;ich++) { + int id=chamberId[ich]; + std::string name=chNames.chamberName(id); + if (ich==0) cout<<name; + else cout<<", "<<name; + } + cout<<endl; + } + */ + // cout<<"beeName: "<<beeName<<", eelName: "<<eelName<<endl; + + if (beeName != "") { + int stPhi = chNames.stPhi(beeName); + int stEta = chNames.stEta(beeName); + int isideAC = (stEta > 0) ? 0 : 1; + int ieta = std::abs(stEta) - 1; + int iphi = stPhi - 1; + for (int ires = firstBEERes; ires < lastBEERes; ires++) { + beeRes[ifile][isideAC][ieta][iphi]->Fill(residuals[ires]); + allBeeRes[ifile][isideAC]->Fill(residuals[ires]); + // cout<<"BEE res: "<<residuals[ires]<<endl; + } + + if (isideAC == 0) { + totalTrackChi2BEEA += trackChi2; + nTracksBEEA++; + } else { + totalTrackChi2BEEC += trackChi2; + nTracksBEEC++; + } + } + if (eelName != "") { + int stPhi = chNames.stPhi(eelName); + int stEta = chNames.stEta(eelName); + int isideAC = (stEta > 0) ? 0 : 1; + int ieta = std::abs(stEta) - 1; + int iphi = stPhi - 1; + for (int ires = firstEELRes; ires < lastEELRes; ires++) { + eelRes[ifile][isideAC][ieta][iphi]->Fill(residuals[ires]); + allEelRes[ifile][isideAC]->Fill(residuals[ires]); + // cout<<"EEL res: "<<residuals[ires]<<endl; + } + + if (isideAC == 0) { + totalTrackChi2EELA += trackChi2; + nTracksEELA++; + } else { + totalTrackChi2EELC += trackChi2; + nTracksEELC++; + } + } + if (bis8Name != "") { + int stPhi = chNames.stPhi(bis8Name); + int stEta = chNames.stEta(bis8Name); + int isideAC = (stEta > 0) ? 0 : 1; + int ieta = 0; + int iphi = stPhi - 1; + for (int ires = firstBIS8Res; ires < lastBIS8Res; ires++) { bis8Res[ifile][isideAC][ieta][iphi]->Fill(residuals[ires]); } + if (isideAC == 0) { + totalTrackChi2BIS8A += trackChi2; + nTracksBIS8A++; + } else { + totalTrackChi2BIS8C += trackChi2; + nTracksBIS8C++; + } + } + + totalTrackChi2 += trackChi2; + nTracks++; + + } // loop over tree entries + + // fill graphs + nTracksGr->SetPoint(ifile, (double)iter, (double)nTracks); + nTracksBEEAGr->SetPoint(ifile, (double)iter, (double)nTracksBEEA); + nTracksBEECGr->SetPoint(ifile, (double)iter, (double)nTracksBEEC); + nTracksEELAGr->SetPoint(ifile, (double)iter, (double)nTracksEELA); + nTracksEELCGr->SetPoint(ifile, (double)iter, (double)nTracksEELC); + nTracksBIS8AGr->SetPoint(ifile, (double)iter, (double)nTracksBIS8A); + nTracksBIS8CGr->SetPoint(ifile, (double)iter, (double)nTracksBIS8C); + trackChi2Gr->SetPoint(ifile, (double)iter, totalTrackChi2 / (double)nTracks); + trackChi2BEEAGr->SetPoint(ifile, (double)iter, totalTrackChi2BEEA / (double)nTracksBEEA); + trackChi2BEECGr->SetPoint(ifile, (double)iter, totalTrackChi2BEEC / (double)nTracksBEEC); + trackChi2EELAGr->SetPoint(ifile, (double)iter, totalTrackChi2EELA / (double)nTracksEELA); + trackChi2EELCGr->SetPoint(ifile, (double)iter, totalTrackChi2EELC / (double)nTracksEELC); + trackChi2BIS8AGr->SetPoint(ifile, (double)iter, totalTrackChi2BIS8A / (double)nTracksBIS8A); + trackChi2BIS8CGr->SetPoint(ifile, (double)iter, totalTrackChi2BIS8C / (double)nTracksBIS8C); + + } // ifile + + TGraph* nTracksGrArr[7] = {nTracksGr, nTracksBEEAGr, nTracksBEECGr, nTracksEELAGr, nTracksEELCGr, nTracksBIS8AGr, nTracksBIS8CGr}; + string nTracksTitles[7] = {"# tracks", + "# BEE tracks - A side", + "# BEE tracks - C side", + "# EEL tracks - A side", + "# EEL tracks - C side", + "# BIS8 tracks - A side", + "# BIS8 tracks - C side"}; + + TGraph* trackChi2GrArr[7] = {trackChi2Gr, trackChi2BEEAGr, trackChi2BEECGr, trackChi2EELAGr, + trackChi2EELCGr, trackChi2BIS8AGr, trackChi2BIS8CGr}; + string trackChi2Titles[7] = {"average track #chi^{2}", + "average track #chi^{2} -BEE A side", + "average track #chi^{2} -BEE C side", + "average track #chi^{2} -EEL A side", + "average track #chi^{2} -EEL C side", + "average track #chi^{2} -BIS8 A side", + "average track #chi^{2} -BIS8 C side"}; + + for (int igr = 0; igr < 7; igr++) { + for (int itype = 0; itype < 2; itype++) { + TCanvas* canvGr = new TCanvas("gr", "gr"); + canvGr->SetFillColor(10); + + TGraph* gr = (itype == 0) ? nTracksGrArr[igr] : trackChi2GrArr[igr]; + string title = (itype == 0) ? nTracksTitles[igr] : trackChi2Titles[igr]; + + canvGr->Clear(); + gr->SetMarkerStyle(8); + gr->SetMarkerSize(.7); + gr->Draw("APL"); + gr->GetYaxis()->SetTitle(title.c_str()); + gr->GetXaxis()->SetTitle("# iteration"); + canvGr->Modified(); + + string canvname = string(gr->GetName()) + ".eps"; + canvGr->Print(canvname.c_str()); + + delete canvGr; + } } - else { - fitcanvbee->Print("BEEC_fits.eps"); - fitcanveel->Print("EELC_fits.eps"); - fitcanvbis8->Print("BIS8C_fits.eps"); - } - delete fitcanvbee; - delete fitcanveel; - delete fitcanvbis8; - - } // isideAC - + // get residual means/widths + gStyle->SetOptStat(000000011); + gStyle->SetOptFit(0111); + TGraph**** beeResPeaks0 = new TGraph***[2]; + TGraph**** beeResMeans0 = new TGraph***[2]; + TGraph**** beeResWidth0 = new TGraph***[2]; + TGraph**** eelResPeaks0 = new TGraph***[2]; + TGraph**** eelResMeans0 = new TGraph***[2]; + TGraph**** eelResWidth0 = new TGraph***[2]; + TGraph**** bis8ResPeaks0 = new TGraph***[2]; + TGraph**** bis8ResMeans0 = new TGraph***[2]; + TGraph**** bis8ResWidth0 = new TGraph***[2]; + + TGraph** allBeeResPeaks0 = new TGraph*[2]; + TGraph** allBeeResMeans0 = new TGraph*[2]; + TGraph** allBeeResWidth0 = new TGraph*[2]; + TGraph** allEelResPeaks0 = new TGraph*[2]; + TGraph** allEelResMeans0 = new TGraph*[2]; + TGraph** allEelResWidth0 = new TGraph*[2]; + + TGraph**** beeResPeaks1 = new TGraph***[2]; + TGraph**** beeResMeans1 = new TGraph***[2]; + TGraph**** beeResWidth1 = new TGraph***[2]; + TGraph**** eelResPeaks1 = new TGraph***[2]; + TGraph**** eelResMeans1 = new TGraph***[2]; + TGraph**** eelResWidth1 = new TGraph***[2]; + TGraph**** bis8ResPeaks1 = new TGraph***[2]; + TGraph**** bis8ResMeans1 = new TGraph***[2]; + TGraph**** bis8ResWidth1 = new TGraph***[2]; + + TGraph** allBeeResPeaks1 = new TGraph*[2]; + TGraph** allBeeResMeans1 = new TGraph*[2]; + TGraph** allBeeResWidth1 = new TGraph*[2]; + TGraph** allEelResPeaks1 = new TGraph*[2]; + TGraph** allEelResMeans1 = new TGraph*[2]; + TGraph** allEelResWidth1 = new TGraph*[2]; + + TF1***** beeFits = new TF1****[2]; + TF1***** eelFits = new TF1****[2]; + TF1***** bis8Fits = new TF1****[2]; + + TF1*** allBeeFits = new TF1**[2]; + TF1*** allEelFits = new TF1**[2]; + + TLegend** legbeeall = new TLegend*[2]; + + for (int isideAC = 0; isideAC < 2; isideAC++) { + legbeeall[isideAC] = new TLegend(.1, .1, .9, .9); + + allBeeFits[isideAC] = new TF1*[NFILES]; + allEelFits[isideAC] = new TF1*[NFILES]; + + TCanvas* fitcanvbee = new TCanvas("fitcanvbee", "BEE gaussian fits"); + fitcanvbee->SetFillColor(10); + fitcanvbee->Divide(3, 1); + + TCanvas* fitcanveel = new TCanvas("fitcanveel", "EEL gaussian fits"); + fitcanveel->SetFillColor(10); + fitcanveel->Divide(3, 2); + + TCanvas* fitcanvbis8 = new TCanvas("fitcanvbis8", "EEL gaussian fits"); + fitcanvbis8->SetFillColor(10); + fitcanvbis8->Divide(3, 1); + + TCanvas* alleelcanv = new TCanvas("alleelcanv", "alleelcanv"); + alleelcanv->SetFillColor(10); + alleelcanv->Divide(3, 2); + + bool firstplotbee = true; + bool firstploteel = true; + bool firstplotbis8 = true; + + beeResPeaks0[isideAC] = new TGraph**[2]; + beeResMeans0[isideAC] = new TGraph**[2]; + beeResWidth0[isideAC] = new TGraph**[2]; + eelResPeaks0[isideAC] = new TGraph**[2]; + eelResMeans0[isideAC] = new TGraph**[2]; + eelResWidth0[isideAC] = new TGraph**[2]; + bis8ResPeaks0[isideAC] = new TGraph**[2]; + bis8ResMeans0[isideAC] = new TGraph**[2]; + bis8ResWidth0[isideAC] = new TGraph**[2]; + beeResPeaks1[isideAC] = new TGraph**[2]; + beeResMeans1[isideAC] = new TGraph**[2]; + beeResWidth1[isideAC] = new TGraph**[2]; + eelResPeaks1[isideAC] = new TGraph**[2]; + eelResMeans1[isideAC] = new TGraph**[2]; + eelResWidth1[isideAC] = new TGraph**[2]; + bis8ResPeaks1[isideAC] = new TGraph**[2]; + bis8ResMeans1[isideAC] = new TGraph**[2]; + bis8ResWidth1[isideAC] = new TGraph**[2]; + beeFits[isideAC] = new TF1***[2]; + eelFits[isideAC] = new TF1***[2]; + bis8Fits[isideAC] = new TF1***[2]; + + for (int ieta = 0; ieta < 2; ieta++) { + TCanvas* allbeecanv = new TCanvas("allbeecanv", "allbeecanv"); + allbeecanv->SetFillColor(10); + allbeecanv->Divide(4, 2); + + TCanvas* allbis8canv = new TCanvas("allbis8canv", "allbis8canv"); + allbis8canv->SetFillColor(10); + allbis8canv->Divide(4, 2); + + beeResPeaks0[isideAC][ieta] = new TGraph*[8]; + beeResMeans0[isideAC][ieta] = new TGraph*[8]; + beeResWidth0[isideAC][ieta] = new TGraph*[8]; + eelResPeaks0[isideAC][ieta] = new TGraph*[8]; + eelResMeans0[isideAC][ieta] = new TGraph*[8]; + eelResWidth0[isideAC][ieta] = new TGraph*[8]; + bis8ResPeaks0[isideAC][ieta] = new TGraph*[8]; + bis8ResMeans0[isideAC][ieta] = new TGraph*[8]; + bis8ResWidth0[isideAC][ieta] = new TGraph*[8]; + beeResPeaks1[isideAC][ieta] = new TGraph*[8]; + beeResMeans1[isideAC][ieta] = new TGraph*[8]; + beeResWidth1[isideAC][ieta] = new TGraph*[8]; + eelResPeaks1[isideAC][ieta] = new TGraph*[8]; + eelResMeans1[isideAC][ieta] = new TGraph*[8]; + eelResWidth1[isideAC][ieta] = new TGraph*[8]; + bis8ResPeaks1[isideAC][ieta] = new TGraph*[8]; + bis8ResMeans1[isideAC][ieta] = new TGraph*[8]; + bis8ResWidth1[isideAC][ieta] = new TGraph*[8]; + beeFits[isideAC][ieta] = new TF1**[8]; + eelFits[isideAC][ieta] = new TF1**[8]; + bis8Fits[isideAC][ieta] = new TF1**[8]; + for (int iphi = 0; iphi < 8; iphi++) { + beeResPeaks0[isideAC][ieta][iphi] = new TGraph(NFILES); + beeResMeans0[isideAC][ieta][iphi] = new TGraph(NFILES); + beeResWidth0[isideAC][ieta][iphi] = new TGraph(NFILES); + eelResPeaks0[isideAC][ieta][iphi] = new TGraph(NFILES); + eelResMeans0[isideAC][ieta][iphi] = new TGraph(NFILES); + eelResWidth0[isideAC][ieta][iphi] = new TGraph(NFILES); + bis8ResPeaks0[isideAC][ieta][iphi] = new TGraph(NFILES); + bis8ResMeans0[isideAC][ieta][iphi] = new TGraph(NFILES); + bis8ResWidth0[isideAC][ieta][iphi] = new TGraph(NFILES); + beeResPeaks1[isideAC][ieta][iphi] = new TGraph(NFILES); + beeResMeans1[isideAC][ieta][iphi] = new TGraph(NFILES); + beeResWidth1[isideAC][ieta][iphi] = new TGraph(NFILES); + eelResPeaks1[isideAC][ieta][iphi] = new TGraph(NFILES); + eelResMeans1[isideAC][ieta][iphi] = new TGraph(NFILES); + eelResWidth1[isideAC][ieta][iphi] = new TGraph(NFILES); + bis8ResPeaks1[isideAC][ieta][iphi] = new TGraph(NFILES); + bis8ResMeans1[isideAC][ieta][iphi] = new TGraph(NFILES); + bis8ResWidth1[isideAC][ieta][iphi] = new TGraph(NFILES); + beeFits[isideAC][ieta][iphi] = new TF1*[NFILES]; + eelFits[isideAC][ieta][iphi] = new TF1*[NFILES]; + bis8Fits[isideAC][ieta][iphi] = new TF1*[NFILES]; + + TCanvas* beecanv = new TCanvas("beecanv", "BEE residuals"); + beecanv->SetFillColor(10); + TCanvas* eelcanv = new TCanvas("eelcanv", "EEL residuals"); + eelcanv->SetFillColor(10); + TCanvas* bis8canv = new TCanvas("bis8canv", "BIS8 residuals"); + bis8canv->SetFillColor(10); + + TCanvas* dummy = new TCanvas("dummy", "dummy"); + // TLegend* legBee=new TLegend(.6,.8,.8,.95); + // TLegend* legEel=new TLegend(.6,.8,.8,.95); + TPaveStats** statsBee = new TPaveStats*[NFILES]; + TPaveStats** statsEel = new TPaveStats*[NFILES]; + // TPaveStats** statsBis8=new TPaveStats*[NFILES]; + + double deltax(0.); + double deltay(.2); + bool firstiter = true; + for (int ifile = NFILES - 1; ifile >= 0; ifile--) { + int iter = iters[ifile]; + stringstream iterstr; + iterstr << "iter" << iter; + dummy->cd(); + dummy->Clear(); + + beeFits[isideAC][ieta][iphi][ifile] = + new TF1((hbeenames[isideAC][ieta][iphi] + string("_fit_") + iterstr.str()).c_str(), + //"[0]*exp(-0.5*((x-[1])/[2])^2)+[3]*exp(-0.5*((x-[4])/[5])^2)", -1.,1.); + "[0]*exp(-0.5*((x-[1])/[2])^2)", -6., 6.); + TH1F* hBee = beeRes[ifile][isideAC][ieta][iphi]; + TF1* fBee = beeFits[isideAC][ieta][iphi][ifile]; + // fBee->SetParameters(hBee->GetMaximum(),hBee->GetMean(),.2, + // hBee->GetMaximum()/7.,hBee->GetMean(),.5); + fBee->SetParameters(hBee->GetMaximum(), hBee->GetMean(), .2); + // fBee->SetParLimits(0,hBee->GetMaximum()*.8,hBee->GetMaximum()*2.); + // fBee->SetParLimits(3,0.,hBee->GetMaximum()*.8); + // fBee->SetParLimits(5,0.,1.); + hBee->Fit(fBee, "QR"); + + beeResPeaks0[isideAC][ieta][iphi]->SetPoint(ifile, iter, fBee->GetParameter(0)); + beeResMeans0[isideAC][ieta][iphi]->SetPoint(ifile, iter, fBee->GetParameter(1)); + beeResWidth0[isideAC][ieta][iphi]->SetPoint(ifile, iter, std::fabs(fBee->GetParameter(2))); + beeResPeaks1[isideAC][ieta][iphi]->SetPoint(ifile, iter, fBee->GetParameter(3)); + beeResMeans1[isideAC][ieta][iphi]->SetPoint(ifile, iter, fBee->GetParameter(4)); + beeResWidth1[isideAC][ieta][iphi]->SetPoint(ifile, iter, std::fabs(fBee->GetParameter(5))); + + dummy->Update(); + + TPaveStats* stats = (TPaveStats*)hBee->FindObject("stats"); + // stringstream testname; testname<<"testBEE_iter"<<iter<<".eps"; + // dummy->Print(testname.str().c_str()); + + if (!stats) { + cout << "no stats for beeRes[" << ifile << "][" << isideAC << "][" << ieta << "][" << iphi << "]" << std::endl; + continue; + } + + statsBee[ifile] = stats; + if (firstiter) { + deltax = stats->GetX2NDC() - stats->GetX1NDC(); + // deltay=stats->GetY2NDC()-stats->GetY1NDC(); + } + int ipos = (ifile < 4) ? ifile : ifile - 4; + + stats->SetY2NDC(stats->GetY2NDC() - deltay * (double)ipos); + stats->SetY1NDC(stats->GetY2NDC() - deltay); + if (ifile >= 4) { + stats->SetX1NDC(.05); + stats->SetX2NDC(.05 + deltax); + } + stats->SetTextColor(phicolor[ifile]); + + beecanv->cd(); + // hBee->SetLineWidth(.8); + hBee->SetLineColor(phicolor[ifile]); + hBee->GetXaxis()->SetTitle("residuals (mm)"); + // rdh hBee->SetMaximum(1000.); + if (firstiter) { + hBee->Draw(); + } else + hBee->Draw("same"); + // fBee->SetLineWidth(1.5); + fBee->SetLineColor(phicolor[ifile]); + fBee->Draw("same"); + + allbeecanv->cd(iphi + 1); + if (firstiter) + hBee->Draw(); + else + hBee->Draw("same"); + fBee->SetLineColor(phicolor[ifile]); + fBee->Draw("same"); + + if ((isideAC == 0 && iphi == 5) || (isideAC == 1 && iphi == 7) || (iphi == 2 && ieta == 0) || iphi == 6) { + dummy->cd(); + dummy->Clear(); + eelFits[isideAC][ieta][iphi][ifile] = + new TF1((heelnames[isideAC][ieta][iphi] + string("_fit_") + iterstr.str()).c_str(), + "[0]*exp(-0.5*((x-[1])/[2])^2)+[3]*exp(-0.5*((x-[4])/[5])^2)", -1., 1.); + //"[0]*exp(-0.5*((x-[1])/[2])^2)", -1.,1.); + TH1F* hEel = eelRes[ifile][isideAC][ieta][iphi]; + TF1* fEel = eelFits[isideAC][ieta][iphi][ifile]; + fEel->SetParameters(hEel->GetMaximum(), hEel->GetMean(), .2, hEel->GetMaximum() / 7., hEel->GetMean(), .5); + // fEel->SetParameters(hEel->GetMaximum(),hEel->GetMean(),.2); + // + fEel->SetParLimits(0, hEel->GetMaximum() * .8, hEel->GetMaximum() * 2.); + fEel->SetParLimits(3, 0., hEel->GetMaximum() * .8); + fEel->SetParLimits(5, 0., 1.); + hEel->Fit(fEel, "QR"); + + eelResPeaks0[isideAC][ieta][iphi]->SetPoint(ifile, iter, fEel->GetParameter(0)); + eelResMeans0[isideAC][ieta][iphi]->SetPoint(ifile, iter, fEel->GetParameter(1)); + eelResWidth0[isideAC][ieta][iphi]->SetPoint(ifile, iter, fEel->GetParameter(2)); + eelResPeaks1[isideAC][ieta][iphi]->SetPoint(ifile, iter, fEel->GetParameter(3)); + eelResMeans1[isideAC][ieta][iphi]->SetPoint(ifile, iter, fEel->GetParameter(4)); + eelResWidth1[isideAC][ieta][iphi]->SetPoint(ifile, iter, fEel->GetParameter(5)); + + dummy->Update(); + TPaveStats* stats1 = (TPaveStats*)hEel->FindObject("stats"); + // dummy->Print("testEEL.eps"); + + statsEel[ifile] = stats1; + if (firstiter) { deltax = stats1->GetX2NDC() - stats1->GetX1NDC(); } + int ipos = (ifile < 4) ? ifile : ifile - 4; + stats1->SetY2NDC(stats1->GetY2NDC() - deltay * (double)ipos); + stats1->SetY1NDC(stats1->GetY2NDC() - deltay); + if (ifile >= 4) { + stats1->SetX1NDC(.05); + stats1->SetX2NDC(.05 + deltax); + } + stats1->SetTextColor(phicolor[ifile]); + + eelcanv->cd(); + // hEel->SetLineWidth(.8); + hEel->SetLineColor(phicolor[ifile]); + hEel->GetXaxis()->SetTitle("residuals (mm)"); + // hEel->SetMaximum(3700.); + if (firstiter) { + hEel->Draw(); + } else + hEel->Draw("same"); + // fEel->SetLineWidth(1.5); + fEel->SetLineColor(phicolor[ifile]); + fEel->Draw("same"); + + int ipad = 1; + if (iphi >= 5 && iphi <= 7) { + if (iphi == 6) { + if (ieta == 0) + ipad = 2; + else + ipad = 5; + } else if (iphi == 5 || iphi == 7) { + if (ieta == 0) + ipad = 3; + else + ipad = 6; + } + } + alleelcanv->cd(ipad); + // hEel->SetLineWidth(.5); + // fEel->SetLineWidth(.6); + if (firstiter) + hEel->Draw(); + else + hEel->Draw("same"); + fEel->Draw("same"); + } + + /* + if (ieta==0) { + dummy->cd(); + dummy->Clear(); + bis8Fits[isideAC][ieta][iphi][ifile]= + //new TF1((hbis8names[isideAC][ieta][iphi]+string("_fit_")+iterstr.str()).c_str(), + // "[0]*exp(-0.5*((x-[1])/[2])^2)+[3]*exp(-0.5*((x-[4])/[5])^2)", -1.,1.); + new TF1((hbis8names[isideAC][ieta][iphi]+string("_fit_")+iterstr.str()).c_str(), + "[0]*exp(-0.5*((x-[1])/[2])^2)", -1.,1.); + TH1F* hBis8=bis8Res [ifile][isideAC][ieta][iphi]; + TF1* fBis8=bis8Fits[isideAC][ieta][iphi][ifile]; + fBis8->SetParameters(hBis8->GetMaximum(),hBis8->GetMean(),.2); + //hBis8->GetMaximum()/7.,hBis8->GetMean(),.5); + //fBis8->SetParLimits(0,hBis8->GetMaximum()*.8,hBis8->GetMaximum()*2.); + //fBis8->SetParLimits(3,0.,hBis8->GetMaximum()*.8); + //fBis8->SetParLimits(5,0.,1.); + hBis8->Fit(fBis8,"QRW"); + + bis8ResPeaks0[isideAC][ieta][iphi]->SetPoint(ifile,iter,fBis8->GetParameter(0)); + bis8ResMeans0[isideAC][ieta][iphi]->SetPoint(ifile,iter,fBis8->GetParameter(1)); + bis8ResWidth0[isideAC][ieta][iphi]->SetPoint(ifile,iter,fBis8->GetParameter(2)); + //bis8ResPeaks1[isideAC][ieta][iphi]->SetPoint(iter,iter,fBis8->GetParameter(3)); + //bis8ResMeans1[isideAC][ieta][iphi]->SetPoint(iter,iter,fBis8->GetParameter(4)); + //bis8ResWidth1[isideAC][ieta][iphi]->SetPoint(iter,iter,fBis8->GetParameter(5)); + + dummy->Update(); + TPaveStats* statsbis8=(TPaveStats*)hBis8->FindObject("stats"); + //dummy->Print("testBIS8.eps"); + + statsBis8[ifile]=statsbis8; + if (firstiter) { + deltax=statsbis8->GetX2NDC()-statsbis8->GetX1NDC(); + } + int iposbis8=(ifile<4)?ifile:ifile-4; + statsbis8->SetY2NDC(statsbis8->GetY2NDC()-deltay*(double)iposbis8); + statsbis8->SetY1NDC(statsbis8->GetY2NDC()-deltay); + if (ifile>=4) { + statsbis8->SetX1NDC(.05); + statsbis8->SetX2NDC(.05+deltax); + } + statsbis8->SetTextColor(phicolor[ifile]); + + bis8canv->cd(); + //hBis8->SetLineWidth(.8); + hBis8->SetLineColor(phicolor[ifile]); + hBis8->SetMaximum(20.); + if (firstiter) { + hBis8->Draw(); + } + else hBis8->Draw("same"); + //fBis8->SetLineWidth(1.5); + fBis8->SetLineColor(phicolor[ifile]); + fBis8->Draw("same"); + + allbis8canv->cd(iphi+1); + //hBis8->SetLineWidth(.5); + //fBis8->SetLineWidth(.6); + if (firstiter) hBis8->Draw(); + else hBis8->Draw(); + fBis8->Draw("same"); + } + */ + firstiter = false; + } + // legBis8->Draw(); + if (ieta == 0) bis8canv->Print((hbis8names[isideAC][ieta][iphi] + "_res.eps").c_str()); + delete bis8canv; + + if ((isideAC == 0 && iphi == 5) || (isideAC == 1 && iphi == 7) || (iphi == 2 && ieta == 0) || iphi == 6) { + // legEel->Draw(); + eelcanv->Print((heelnames[isideAC][ieta][iphi] + "_res.eps").c_str()); + } + delete eelcanv; + + beecanv->Print((hbeenames[isideAC][ieta][iphi] + "_res.eps").c_str()); + delete beecanv; + + delete dummy; + + string grtitles[6] = {"inner peak", "inner mean (mm)", "inner width (mm)", + "outer peak", "outer mean (mm)", "outer width (mm)"}; + // string grtitlesbee[6]={"inner peak","inner mean (mm)", + // "inner width (mm)", + // "outer peak","outer mean (mm)", + // "outer width (mm)"}; + string grtitlesbee[3] = {"peak", "mean (mm)", "width (mm)"}; + + int colorbee = beecolor[ieta][iphi]; + // double maxbee[6]={1000., .3,.3, 250., .6,1.}; + // double minbee[6]={ 0.,-.3,0., 0.,-.6,0.}; + // for (int ipad=1;ipad<=6;ipad++) { + double maxbee[6] = {250., 4.5, 2.}; + double minbee[6] = {0., -2., 0.}; + for (int ipad = 1; ipad <= 3; ipad++) { + fitcanvbee->cd(ipad); + TGraph* gr; + switch (ipad) { + case 1: gr = beeResPeaks0[isideAC][ieta][iphi]; break; + case 2: gr = beeResMeans0[isideAC][ieta][iphi]; break; + case 3: gr = beeResWidth0[isideAC][ieta][iphi]; break; + case 4: gr = beeResPeaks1[isideAC][ieta][iphi]; break; + case 5: gr = beeResMeans1[isideAC][ieta][iphi]; break; + case 6: gr = beeResWidth1[isideAC][ieta][iphi]; break; + } + + gr->SetMarkerColor(colorbee); + gr->SetMarkerStyle(8); + gr->SetMarkerSize(.7); + gr->SetLineColor(colorbee); + // gr->SetLineWidth(1.6); + if (firstplotbee) { + gr->SetTitle(grtitlesbee[ipad - 1].c_str()); + gr->SetMinimum(minbee[ipad - 1]); + gr->SetMaximum(maxbee[ipad - 1]); + gr->Draw("APL"); + } else + gr->Draw("PLsame"); + } + firstplotbee = false; + + if ((isideAC == 0 && iphi == 5) || (isideAC == 1 && iphi == 7) || (iphi == 2 && ieta == 0) || iphi == 6) { + int coloreel = eelcolor[ieta][iphi]; + double maxeel[6] = {3700., .1, .3, 1500., .5, .5}; + double mineel[6] = {0., -.1, 0., 0., -.5, 0.}; + for (int ipad = 1; ipad <= 6; ipad++) { + fitcanveel->cd(ipad); + TGraph* gr; + switch (ipad) { + case 1: gr = eelResPeaks0[isideAC][ieta][iphi]; break; + case 2: gr = eelResMeans0[isideAC][ieta][iphi]; break; + case 3: gr = eelResWidth0[isideAC][ieta][iphi]; break; + case 4: gr = eelResPeaks1[isideAC][ieta][iphi]; break; + case 5: gr = eelResMeans1[isideAC][ieta][iphi]; break; + case 6: gr = eelResWidth1[isideAC][ieta][iphi]; break; + } + + gr->SetMarkerColor(coloreel); + gr->SetMarkerStyle(8); + gr->SetMarkerSize(.7); + gr->SetLineColor(coloreel); + // gr->SetLineWidth(1.6); + if (firstploteel) { + gr->SetTitle(grtitles[ipad - 1].c_str()); + gr->SetMinimum(mineel[ipad - 1]); + gr->SetMaximum(maxeel[ipad - 1]); + gr->Draw("APL"); + } else + gr->Draw("PLsame"); + } + firstploteel = false; + } + + if (ieta == 0) { + int colorbis8 = bis8color[ieta][iphi]; + double maxbis8[6] = {20., .2, 1., 20., .5, .5}; + double minbis8[6] = {0., -.2, 1., 0., -.5, 0.}; + for (int ipad = 1; ipad <= 3; ipad++) { + fitcanvbis8->cd(ipad); + TGraph* gr; + switch (ipad) { + case 1: gr = bis8ResPeaks0[isideAC][ieta][iphi]; break; + case 2: gr = bis8ResMeans0[isideAC][ieta][iphi]; break; + case 3: gr = bis8ResWidth0[isideAC][ieta][iphi]; break; + case 4: gr = bis8ResPeaks1[isideAC][ieta][iphi]; break; + case 5: gr = bis8ResMeans1[isideAC][ieta][iphi]; break; + case 6: gr = bis8ResWidth1[isideAC][ieta][iphi]; break; + } + + gr->SetMarkerColor(colorbis8); + gr->SetMarkerStyle(8); + gr->SetMarkerSize(.7); + gr->SetLineColor(colorbis8); + // gr->SetLineWidth(1.6); + if (firstplotbis8) { + gr->SetTitle(grtitles[ipad - 1].c_str()); + gr->SetMinimum(minbis8[ipad - 1]); + gr->SetMaximum(maxbis8[ipad - 1]); + gr->Draw("APL"); + } else + gr->Draw("PLsame"); + } + firstplotbis8 = false; + } + + } // iphi + + std::stringstream beecanvname; + beecanvname << "allBEE_side"; + if (isideAC == 0) + beecanvname << "A"; + else + beecanvname << "C"; + beecanvname << "_stEta" << ieta + 1; + beecanvname << ".eps"; + allbeecanv->Print(beecanvname.str().c_str()); + delete allbeecanv; + + if (ieta == 0) { + std::stringstream bis8canvname; + bis8canvname << "allBIS8_side"; + if (isideAC == 0) + bis8canvname << "A"; + else + bis8canvname << "C"; + bis8canvname << ".eps"; + allbis8canv->Print(bis8canvname.str().c_str()); + delete allbis8canv; + } + + } // ieta + + TCanvas* allBeeResCanv = new TCanvas("allBeeResCanv", "allBeeResCanv"); + allBeeResCanv->SetFillColor(10); + allBeeResCanv->Divide(3, 1); + + TCanvas* allEelResCanv = new TCanvas("allEelResCanv", "allEelResCanv"); + allEelResCanv->SetFillColor(10); + allEelResCanv->Divide(3, 1); + + allBeeResPeaks0[isideAC] = new TGraph(NFILES); + allBeeResMeans0[isideAC] = new TGraph(NFILES); + allBeeResWidth0[isideAC] = new TGraph(NFILES); + + allEelResPeaks0[isideAC] = new TGraph(NFILES); + allEelResMeans0[isideAC] = new TGraph(NFILES); + allEelResWidth0[isideAC] = new TGraph(NFILES); + allEelResPeaks1[isideAC] = new TGraph(NFILES); + allEelResMeans1[isideAC] = new TGraph(NFILES); + allEelResWidth1[isideAC] = new TGraph(NFILES); + + TCanvas* dummy2 = new TCanvas("dummy2", "dummy2"); + TPaveStats** statsAllBee = new TPaveStats*[NFILES]; + TPaveStats** statsAllEel = new TPaveStats*[NFILES]; + + double deltax(0.); + double deltay(.2); + bool firstiter = true; + for (int ifile = NFILES - 1; ifile >= 0; ifile--) { + int iter = iters[ifile]; + stringstream iterstr; + iterstr << "iter" << iter; + + // BEE + dummy2->cd(); + dummy2->Clear(); + stringstream allBeeStr; + allBeeStr << "allBEE_fit_" << iterstr.str(); + if (isideAC == 0) + allBeeStr << "_sideA"; + else + allBeeStr << "_sideC"; + allBeeFits[isideAC][ifile] = new TF1(allBeeStr.str().c_str(), "[0]*exp(-0.5*((x-[1])/[2])^2)", -6., 6.); + + TH1F* hAllBee = allBeeRes[ifile][isideAC]; + TF1* fAllBee = allBeeFits[isideAC][ifile]; + fAllBee->SetParameters(hAllBee->GetMaximum(), hAllBee->GetMean(), .2); + hAllBee->Fit(fAllBee, "QR"); + + allBeeResPeaks0[isideAC]->SetPoint(ifile, iter, fAllBee->GetParameter(0)); + allBeeResMeans0[isideAC]->SetPoint(ifile, iter, fAllBee->GetParameter(1)); + allBeeResWidth0[isideAC]->SetPoint(ifile, iter, fAllBee->GetParameter(2)); + + dummy2->Update(); + + TPaveStats* stats2 = (TPaveStats*)hAllBee->FindObject("stats"); + if (!stats2) { + std::cout << "no stats box" << std::endl; + continue; + } + statsAllBee[ifile] = stats2; + if (firstiter) deltax = stats2->GetX2NDC() - stats2->GetX1NDC(); + + int ipos = (ifile < 4) ? ifile : ifile - 4; + stats2->SetY2NDC(stats2->GetY2NDC() - deltay * (double)ipos); + stats2->SetY1NDC(stats2->GetY2NDC() - deltay); + if (ifile >= 4) { + stats2->SetX1NDC(.05); + stats2->SetX2NDC(.05 + deltax); + } + stats2->SetTextColor(phicolor[ifile]); + + allBeeResCanv->cd(); + hAllBee->SetLineColor(phicolor[ifile]); + hAllBee->GetXaxis()->SetTitle("residuals (mm)"); + + if (firstiter) + hAllBee->Draw(); + else + hAllBee->Draw("same"); + + fAllBee->SetLineColor(phicolor[ifile]); + fAllBee->Draw("same"); + + // EEL + dummy2->cd(); + dummy2->Clear(); + stringstream allEelStr; + allEelStr << "allEEL_fit_" << iterstr.str(); + if (isideAC == 0) + allEelStr << "_sideA"; + else + allEelStr << "_sideC"; + allEelFits[isideAC][ifile] = + new TF1(allEelStr.str().c_str(), "[0]*exp(-0.5*((x-[1])/[2])^2)+[3]*exp(-0.5*((x-[4])/[5])^2)", -1., 1.); + + TH1F* hAllEel = allEelRes[ifile][isideAC]; + TF1* fAllEel = allEelFits[isideAC][ifile]; + fAllEel->SetParameters(hAllEel->GetMaximum(), hAllEel->GetMean(), .2); + hAllEel->Fit(fAllEel, "QR"); + + allEelResPeaks0[isideAC]->SetPoint(ifile, iter, fAllEel->GetParameter(0)); + allEelResMeans0[isideAC]->SetPoint(ifile, iter, fAllEel->GetParameter(1)); + allEelResWidth0[isideAC]->SetPoint(ifile, iter, fAllEel->GetParameter(2)); + + dummy2->Update(); + + TPaveStats* stats3 = (TPaveStats*)hAllEel->FindObject("stats"); + if (!stats3) { + std::cout << "no stats box" << std::endl; + continue; + } + statsAllEel[ifile] = stats3; + if (firstiter) deltax = stats3->GetX2NDC() - stats3->GetX1NDC(); + + ipos = (ifile < 4) ? ifile : ifile - 4; + stats3->SetY2NDC(stats3->GetY2NDC() - deltay * (double)ipos); + stats3->SetY1NDC(stats3->GetY2NDC() - deltay); + if (ifile >= 4) { + stats3->SetX1NDC(.05); + stats3->SetX2NDC(.05 + deltax); + } + stats3->SetTextColor(phicolor[ifile]); + + allEelResCanv->cd(); + hAllEel->SetLineColor(phicolor[ifile]); + hAllEel->GetXaxis()->SetTitle("residuals (mm)"); + + if (firstiter) + hAllEel->Draw(); + else + hAllEel->Draw("same"); + + fAllEel->SetLineColor(phicolor[ifile]); + fAllEel->Draw("same"); + + firstiter = false; + } + + if (isideAC == 0) + allBeeResCanv->Print("allBEERes_sideA.eps"); + else + allBeeResCanv->Print("allBEERes_sideC.eps"); + + if (isideAC == 0) + allEelResCanv->Print("allEELRes_sideA.eps"); + else + allEelResCanv->Print("allEELRes_sideC.eps"); + + std::stringstream eelcanvname; + eelcanvname << "allEEL_side"; + if (isideAC == 0) + eelcanvname << "A"; + else + eelcanvname << "C"; + eelcanvname << ".eps"; + alleelcanv->Print(eelcanvname.str().c_str()); + delete alleelcanv; + + // print fits + if (isideAC == 0) { + fitcanvbee->Print("BEEA_fits.eps"); + fitcanveel->Print("EELA_fits.eps"); + fitcanvbis8->Print("BIS8A_fits.eps"); + } else { + fitcanvbee->Print("BEEC_fits.eps"); + fitcanveel->Print("EELC_fits.eps"); + fitcanvbis8->Print("BIS8C_fits.eps"); + } + delete fitcanvbee; + delete fitcanveel; + delete fitcanvbis8; + + } // isideAC } diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/plottrend_x.cpp b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/plottrend_x.cpp index 822f3984de35ce76506b6008010fdbee0ad75ea4..097bcf72edf87677610c1f30c41fb80de79f91f5 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/plottrend_x.cpp +++ b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/plottrend_x.cpp @@ -2,781 +2,730 @@ Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ -#include "MuonFixedId.h" -#include "Tools.h" +#include <cmath> +#include <iostream> +#include <map> +#include <sstream> -#include "TFile.h" +#include "MuonFixedId.h" +#include "TAxis.h" +#include "TCanvas.h" #include "TChain.h" -#include "TTree.h" +#include "TFile.h" #include "TGraph.h" #include "TGraphErrors.h" -#include "TCanvas.h" -#include "TLine.h" -#include "TAxis.h" #include "TH1.h" -#include "TStyle.h" #include "TLegend.h" +#include "TLine.h" +#include "TStyle.h" #include "TSystem.h" - -#include <sstream> -#include <iostream> -#include <cmath> -#include <map> +#include "TTree.h" +#include "Tools.h" using namespace MuonCalib; -const int NITER_MAX=20; - -bool getTotalChi2(int iter, TTree* tree, - std::map<long long int,int*>& ntracksMap, - std::map<long long int,int*>& ndofMap, - std::map<long long int,double*>& chi2Map); - -void help(const char *argv0) { - - cerr << "Usage: " << argv0 << " [options] " << endl - << "Options:" << endl - << " -o :\tOutput path" << endl - << " -i :\tInput files" << endl - << " -r :\tRootname" << endl - << " -e :\tDraw errors" << endl - << " -c :\tCombine chambers in a tower" << endl - << " -l :\tL1 alignment" << endl - << " -h :\tShow this message and quit" << endl - << endl; - exit(1); +const int NITER_MAX = 20; + +bool getTotalChi2(int iter, TTree* tree, std::map<long long int, int*>& ntracksMap, std::map<long long int, int*>& ndofMap, + std::map<long long int, double*>& chi2Map); + +void help(const char* argv0) { + cerr << "Usage: " << argv0 << " [options] " << endl + << "Options:" << endl + << " -o :\tOutput path" << endl + << " -i :\tInput files" << endl + << " -r :\tRootname" << endl + << " -e :\tDraw errors" << endl + << " -c :\tCombine chambers in a tower" << endl + << " -l :\tL1 alignment" << endl + << " -h :\tShow this message and quit" << endl + << endl; + exit(1); } int main(int argc, char** argv) { - - //---------------------------- - //-- Parse the command line -- - //---------------------------- - - extern char *optarg; - char c; - TString inputdir(""); - TString outputdir(""); - TString rootname(""); - bool DRAWERR = false; - bool COMBINE = false; - bool DOALLPLOTS = false; - bool L1ALIGNMENT = false; - bool INITMISAL = false; - - while((c = getopt(argc, argv, "-heclo:i:r:")) !=-1){ - switch(c){ - case 'o': - outputdir = optarg; - break; - case 'i': - inputdir = optarg; - break; - case 'r': - rootname = optarg; - break; - case 'e': - DRAWERR = true; - break; - case 'c': - COMBINE = true; - break; - case 'l': - L1ALIGNMENT = true; - break; - default: - cerr << "Help or unknown argument!" << endl; - help(argv[0]); - break; - } - } - if(rootname==""){ - cerr << "no rootname passed, exiting..." << endl; - exit(1); - } - if(inputdir==""){ - inputdir = rootname; - } - if(outputdir==""){ - outputdir = inputdir; - } - - //--------- - //-- Run -- - //--------- - - Tools::setStyle(); - gStyle->SetPadLeftMargin(0.16); - gStyle->SetPadRightMargin(0.05); - gStyle->SetTitleYOffset(1.65); - - double tsize=0.05; - gStyle->SetTextSize(tsize); - gStyle->SetLabelSize(tsize,"x"); - gStyle->SetTitleSize(tsize,"x"); - gStyle->SetLabelSize(tsize,"y"); - gStyle->SetTitleSize(tsize,"y"); - - // int font=42; - // gStyle->SetTextFont(font); - // gStyle->SetLabelFont(font,"x"); - // gStyle->SetTitleFont(font,"x"); - // gStyle->SetLabelFont(font,"y"); - // gStyle->SetTitleFont(font,"y") - - // std::string directory=""; - // if (argc>1) { - // directory=string(argv[1]); - // } - // else { - // cout<<"please give input directory"<<endl; - // exit(3); - // } - // std::cout<<"using input directory "<<directory<<std::endl; - - //const bool DRAWERR = 0; - //const bool COMBINE = 0; - - string ytitles[6]={"#Deltas","#Deltaz","#Deltat", - "#Delta#alpha(s)","#Delta#beta(z)", "#Delta#gamma(t)"}; - string units[6]={" [mm]"," [mm]"," [mm]"," [mrad]"," [mrad]"," [mrad]"}; - if (L1ALIGNMENT) { - ytitles[0]="#Deltax"; - ytitles[1]="#Deltay"; - ytitles[2]="#Deltaz"; - ytitles[3]="#Delta#alpha(x)"; - ytitles[4]="#Delta#beta(y)"; - ytitles[5]="#Delta#gamma(z)"; - } - - bool activeParam[6] = {1,1,1,1,1,1}; - //bool activeParam[6] = {1,1,1,0,0,0}; - - map<long long int,double**> yArrMap; - map<long long int,double**> yErrMap; - map<long long int,double*> minMap; - map<long long int,double*> maxMap; - - map<long long int,double*> chi2Map; - map<long long int,int*> nDoFMap; - map<long long int,int*> nTracksMap; - - double* xArr = new double[NITER_MAX+1]; - double* xErr = new double[NITER_MAX+1]; - int niter=0; - - void *directory = gSystem->OpenDirectory(inputdir); - if (!directory){ - cerr << "input directory does not exist, exiting..." << endl; - exit(1); - } - directory = gSystem->OpenDirectory(outputdir); - if (!directory){ - cerr << "create output directory" << endl; - int status = gSystem->mkdir(outputdir,false); - if(status!=0){ - cerr << "could not create output directory, exiting..." << endl; - exit(1); - } - } - - TString iterdir = inputdir+"/iter0"; - directory = gSystem->OpenDirectory(inputdir+"/iter0"); - bool multiplejobs = directory ? true : false; - - - //---------------------------- - //-- Get info about iterations - //---------------------------- - bool lastfile=false; - for (int iter=0;iter<NITER_MAX+1;iter++) { - - int fileindex = (iter==0) ? 0 : iter-1; - TString filename; - if(multiplejobs){ - TString iterdir = inputdir+Form("/iter%i/",fileindex); - directory = gSystem->OpenDirectory(iterdir); - filename = iterdir; - if(!directory) break; - } - else{ - filename = inputdir+"/"; + //---------------------------- + //-- Parse the command line -- + //---------------------------- + + extern char* optarg; + char c; + TString inputdir(""); + TString outputdir(""); + TString rootname(""); + bool DRAWERR = false; + bool COMBINE = false; + bool DOALLPLOTS = false; + bool L1ALIGNMENT = false; + bool INITMISAL = false; + + while ((c = getopt(argc, argv, "-heclo:i:r:")) != -1) { + switch (c) { + case 'o': outputdir = optarg; break; + case 'i': inputdir = optarg; break; + case 'r': rootname = optarg; break; + case 'e': DRAWERR = true; break; + case 'c': COMBINE = true; break; + case 'l': L1ALIGNMENT = true; break; + default: + cerr << "Help or unknown argument!" << endl; + help(argv[0]); + break; + } } - - filename += "MuonAlign_"+rootname+"_iter"; - filename += Form("%i",fileindex); - - if(multiplejobs) filename += "_Solve"; - filename += ".root"; - - //stringstream filename; - //filename<<inputdir<<"/MuonAlign_"<<rootname<<"_iter"; - //int fileindex = (iter==0) ? iter+1 : iter; - //filename<<int(fileindex); - - TFile* file=new TFile(filename,"READ"); - std::cout<<"got TFile "<<filename<<", getting tree"<<std::endl; - TTree* tree=(TTree*)file->Get("alignParMDT"); - - if(!tree){ - if(iter==0){ - cout << "-> no tree to run on in file "<<filename<<", exit..." << endl; + if (rootname == "") { + cerr << "no rootname passed, exiting..." << endl; exit(1); - } - else{ - cout << "-> don't worry: still running fine" << endl; - break; - } } - - TString basefilename; - if(multiplejobs){ - TString iterdir = inputdir+Form("/iter%i/",iter); - directory = gSystem->OpenDirectory(iterdir); - basefilename = iterdir; - if (!directory) { - cerr << "iteration: " << iter << " does not exist..." << endl; - lastfile=true; - } + if (inputdir == "") { inputdir = rootname; } + if (outputdir == "") { outputdir = inputdir; } + + //--------- + //-- Run -- + //--------- + + Tools::setStyle(); + gStyle->SetPadLeftMargin(0.16); + gStyle->SetPadRightMargin(0.05); + gStyle->SetTitleYOffset(1.65); + + double tsize = 0.05; + gStyle->SetTextSize(tsize); + gStyle->SetLabelSize(tsize, "x"); + gStyle->SetTitleSize(tsize, "x"); + gStyle->SetLabelSize(tsize, "y"); + gStyle->SetTitleSize(tsize, "y"); + + // int font=42; + // gStyle->SetTextFont(font); + // gStyle->SetLabelFont(font,"x"); + // gStyle->SetTitleFont(font,"x"); + // gStyle->SetLabelFont(font,"y"); + // gStyle->SetTitleFont(font,"y") + + // std::string directory=""; + // if (argc>1) { + // directory=string(argv[1]); + // } + // else { + // cout<<"please give input directory"<<endl; + // exit(3); + // } + // std::cout<<"using input directory "<<directory<<std::endl; + + // const bool DRAWERR = 0; + // const bool COMBINE = 0; + + string ytitles[6] = {"#Deltas", "#Deltaz", "#Deltat", "#Delta#alpha(s)", "#Delta#beta(z)", "#Delta#gamma(t)"}; + string units[6] = {" [mm]", " [mm]", " [mm]", " [mrad]", " [mrad]", " [mrad]"}; + if (L1ALIGNMENT) { + ytitles[0] = "#Deltax"; + ytitles[1] = "#Deltay"; + ytitles[2] = "#Deltaz"; + ytitles[3] = "#Delta#alpha(x)"; + ytitles[4] = "#Delta#beta(y)"; + ytitles[5] = "#Delta#gamma(z)"; } - else{ - basefilename = inputdir+"/"; + + bool activeParam[6] = {1, 1, 1, 1, 1, 1}; + // bool activeParam[6] = {1,1,1,0,0,0}; + + map<long long int, double**> yArrMap; + map<long long int, double**> yErrMap; + map<long long int, double*> minMap; + map<long long int, double*> maxMap; + + map<long long int, double*> chi2Map; + map<long long int, int*> nDoFMap; + map<long long int, int*> nTracksMap; + + double* xArr = new double[NITER_MAX + 1]; + double* xErr = new double[NITER_MAX + 1]; + int niter = 0; + + void* directory = gSystem->OpenDirectory(inputdir); + if (!directory) { + cerr << "input directory does not exist, exiting..." << endl; + exit(1); } - - basefilename += "MuonAlign_"+rootname+Form("_iter%i",fileindex); - TString muonalign_filename = basefilename; - if(multiplejobs) - muonalign_filename += "_index*"; - muonalign_filename += ".root"; - - TChain* muonaligntree=new TChain("alignParMDT"); - std::cout<<"adding to alignPar chain: "<<muonalign_filename <<std::endl; - Int_t nfilesadded=muonaligntree->Add(muonalign_filename); - - if (nfilesadded>0) { - bool success=getTotalChi2(iter,muonaligntree,nTracksMap,nDoFMap,chi2Map); - if (!success) { - cout<<"didn't get total chi2, continuing"<<endl; - continue; - } + directory = gSystem->OpenDirectory(outputdir); + if (!directory) { + cerr << "create output directory" << endl; + int status = gSystem->mkdir(outputdir, false); + if (status != 0) { + cerr << "could not create output directory, exiting..." << endl; + exit(1); + } } - niter++; - xArr[iter]=(double)(iter); - xErr[iter]=0.; + TString iterdir = inputdir + "/iter0"; + directory = gSystem->OpenDirectory(inputdir + "/iter0"); + bool multiplejobs = directory ? true : false; + + //---------------------------- + //-- Get info about iterations + //---------------------------- + bool lastfile = false; + for (int iter = 0; iter < NITER_MAX + 1; iter++) { + int fileindex = (iter == 0) ? 0 : iter - 1; + TString filename; + if (multiplejobs) { + TString iterdir = inputdir + Form("/iter%i/", fileindex); + directory = gSystem->OpenDirectory(iterdir); + filename = iterdir; + if (!directory) break; + } else { + filename = inputdir + "/"; + } - long long int chamberId; - int nDoF; - double chi2; - double init_tras, init_traz, init_trat; - double init_rots, init_rotz, init_rott; - double err_tras, err_traz, err_trat; - double err_rots, err_rotz, err_rott; - double tras,traz,trat,rots,rotz,rott; - - tree->SetBranchAddress("chamberId", &chamberId); - tree->SetBranchAddress("nDoF", &nDoF); - tree->SetBranchAddress("trackChi2", &chi2); - tree->SetBranchAddress("delta_tras", &tras); - tree->SetBranchAddress("delta_traz", &traz); - tree->SetBranchAddress("delta_trat", &trat); - tree->SetBranchAddress("delta_rots", &rots); - tree->SetBranchAddress("delta_rotz", &rotz); - tree->SetBranchAddress("delta_rott", &rott); - tree->SetBranchAddress("init_tras", &init_tras); - tree->SetBranchAddress("init_traz", &init_traz); - tree->SetBranchAddress("init_trat", &init_trat); - tree->SetBranchAddress("init_rots", &init_rots); - tree->SetBranchAddress("init_rotz", &init_rotz); - tree->SetBranchAddress("init_rott", &init_rott); - tree->SetBranchAddress("err_tras", &err_tras); - tree->SetBranchAddress("err_traz", &err_traz); - tree->SetBranchAddress("err_trat", &err_trat); - tree->SetBranchAddress("err_rots", &err_rots); - tree->SetBranchAddress("err_rotz", &err_rotz); - tree->SetBranchAddress("err_rott", &err_rott); - - for (int ientry=0;ientry<(int)tree->GetEntries();ientry++) { - - tree->GetEntry(ientry); - - if(ientry==0){ - if(tras==0 && err_tras==0) activeParam[0]=false; - if(traz==0 && err_traz==0) activeParam[1]=false; - if(trat==0 && err_trat==0) activeParam[2]=false; - if(rots==0 && err_rots==0) activeParam[3]=false; - if(rotz==0 && err_rotz==0) activeParam[4]=false; - if(rott==0 && err_rott==0) activeParam[5]=false; - } - - double** yArr(0); - double** yErr(0); - double* min(0); - double* max(0); - double* chi2Arr(0); - double* nDoFArr(0); - - if(iter==0) { - yArr=new double*[6]; - yArr[0]=new double[NITER_MAX+1]; - yArr[1]=new double[NITER_MAX+1]; - yArr[2]=new double[NITER_MAX+1]; - yArr[3]=new double[NITER_MAX+1]; - yArr[4]=new double[NITER_MAX+1]; - yArr[5]=new double[NITER_MAX+1]; - - yErr=new double*[6]; - yErr[0]=new double[NITER_MAX+1]; - yErr[1]=new double[NITER_MAX+1]; - yErr[2]=new double[NITER_MAX+1]; - yErr[3]=new double[NITER_MAX+1]; - yErr[4]=new double[NITER_MAX+1]; - yErr[5]=new double[NITER_MAX+1]; - - nDoFArr=new double[NITER_MAX+1]; - chi2Arr =new double[NITER_MAX+1]; - - min=new double[6]; - max=new double[6]; - - for (int i=0;i<6;i++) { - yErr[i][0]=0.; - min[i]=1.e6; - max[i]=-1.e6; + filename += "MuonAlign_" + rootname + "_iter"; + filename += Form("%i", fileindex); + + if (multiplejobs) filename += "_Solve"; + filename += ".root"; + + // stringstream filename; + // filename<<inputdir<<"/MuonAlign_"<<rootname<<"_iter"; + // int fileindex = (iter==0) ? iter+1 : iter; + // filename<<int(fileindex); + + TFile* file = new TFile(filename, "READ"); + std::cout << "got TFile " << filename << ", getting tree" << std::endl; + TTree* tree = (TTree*)file->Get("alignParMDT"); + + if (!tree) { + if (iter == 0) { + cout << "-> no tree to run on in file " << filename << ", exit..." << endl; + exit(1); + } else { + cout << "-> don't worry: still running fine" << endl; + break; + } + } + + TString basefilename; + if (multiplejobs) { + TString iterdir = inputdir + Form("/iter%i/", iter); + directory = gSystem->OpenDirectory(iterdir); + basefilename = iterdir; + if (!directory) { + cerr << "iteration: " << iter << " does not exist..." << endl; + lastfile = true; + } + } else { + basefilename = inputdir + "/"; } - - yArrMap[chamberId] = yArr; - yErrMap[chamberId] = yErr; - minMap[chamberId] = min; - maxMap[chamberId] = max; - - } - else{ - yArr = yArrMap[chamberId]; - yErr = yErrMap[chamberId]; - min = minMap[chamberId]; - max = maxMap[chamberId]; - } - //if (chamberId!=240131072) continue; //EIL2A1 - - if(iter==0){ - cout<<"iter 0, init_trat="<<init_trat<<endl; - yArr[0][iter]=init_tras; - yArr[1][iter]=init_traz; - yArr[2][iter]=init_trat; - yArr[3][iter]=init_rots*1000; - yArr[4][iter]=init_rotz*1000; - yArr[5][iter]=init_rott*1000; - if (L1ALIGNMENT && INITMISAL) { - yArr[0][0]+= 2.; - yArr[1][0]+= 1.; - yArr[2][0]+=- .5; - yArr[3][0]+= .01; - yArr[4][0]+=-.03; - yArr[5][0]+=- .2; - } - } - else{ - cout<<"iter "<<iter<<", init_trat="<<init_trat<<endl; - cout<<"init_trat+delta="<<yArr[0][iter-1]+trat<<endl; - yArr[0][iter]= yArr[0][iter-1] + tras; - yArr[1][iter]= yArr[1][iter-1] + traz; - yArr[2][iter]= yArr[2][iter-1] + trat; - yArr[3][iter]= yArr[3][iter-1] + rots*1000.; - yArr[4][iter]= yArr[4][iter-1] + rotz*1000.; - yArr[5][iter]= yArr[5][iter-1] + rott*1000.; - if (L1ALIGNMENT && INITMISAL && iter==2) { - yArr[0][2]-= 2.; - yArr[1][2]-= 1.; - yArr[2][2]-=- .5; - yArr[3][2]-= .01; - yArr[4][2]-=-.03; - yArr[5][2]-=- .2; - } - /* - yArr[0][iter]= tras; - yArr[1][iter]= traz; - yArr[2][iter]= trat; - yArr[3][iter]= rots*1000.; - yArr[4][iter]= rotz*1000.; - yArr[5][iter]= rott*1000.; */ - yErr[0][iter]= err_tras; - yErr[1][iter]= err_traz; - yErr[2][iter]= err_trat; - yErr[3][iter]= err_rots*1000.*1.75; - yErr[4][iter]= err_rotz*1000.*1.7; - yErr[5][iter]= err_rott*1000.*2.44; - } - //chi2Arr[iter]=chi2; - //nTracksArr[iter]=nTracks; - //cout<<"tracks/chi2="<<nTracks<<"/"<<chi2<<endl; - - for (int i=0;i<6;i++) { - - if(!activeParam[i]) continue; - - if(!DRAWERR){ - if (yArr[i][iter]<min[i]) min[i]=yArr[i][iter]; - if (yArr[i][iter]>max[i]) max[i]=yArr[i][iter]; + + basefilename += "MuonAlign_" + rootname + Form("_iter%i", fileindex); + TString muonalign_filename = basefilename; + if (multiplejobs) muonalign_filename += "_index*"; + muonalign_filename += ".root"; + + TChain* muonaligntree = new TChain("alignParMDT"); + std::cout << "adding to alignPar chain: " << muonalign_filename << std::endl; + Int_t nfilesadded = muonaligntree->Add(muonalign_filename); + + if (nfilesadded > 0) { + bool success = getTotalChi2(iter, muonaligntree, nTracksMap, nDoFMap, chi2Map); + if (!success) { + cout << "didn't get total chi2, continuing" << endl; + continue; + } } - else{ - if ((yArr[i][iter]-yErr[i][iter])<min[i]) min[i]=yArr[i][iter]-yErr[i][iter]; - if ((yArr[i][iter]+yErr[i][iter])>max[i]) max[i]=yArr[i][iter]+yErr[i][iter]; + niter++; + + xArr[iter] = (double)(iter); + xErr[iter] = 0.; + + long long int chamberId; + int nDoF; + double chi2; + double init_tras, init_traz, init_trat; + double init_rots, init_rotz, init_rott; + double err_tras, err_traz, err_trat; + double err_rots, err_rotz, err_rott; + double tras, traz, trat, rots, rotz, rott; + + tree->SetBranchAddress("chamberId", &chamberId); + tree->SetBranchAddress("nDoF", &nDoF); + tree->SetBranchAddress("trackChi2", &chi2); + tree->SetBranchAddress("delta_tras", &tras); + tree->SetBranchAddress("delta_traz", &traz); + tree->SetBranchAddress("delta_trat", &trat); + tree->SetBranchAddress("delta_rots", &rots); + tree->SetBranchAddress("delta_rotz", &rotz); + tree->SetBranchAddress("delta_rott", &rott); + tree->SetBranchAddress("init_tras", &init_tras); + tree->SetBranchAddress("init_traz", &init_traz); + tree->SetBranchAddress("init_trat", &init_trat); + tree->SetBranchAddress("init_rots", &init_rots); + tree->SetBranchAddress("init_rotz", &init_rotz); + tree->SetBranchAddress("init_rott", &init_rott); + tree->SetBranchAddress("err_tras", &err_tras); + tree->SetBranchAddress("err_traz", &err_traz); + tree->SetBranchAddress("err_trat", &err_trat); + tree->SetBranchAddress("err_rots", &err_rots); + tree->SetBranchAddress("err_rotz", &err_rotz); + tree->SetBranchAddress("err_rott", &err_rott); + + for (int ientry = 0; ientry < (int)tree->GetEntries(); ientry++) { + tree->GetEntry(ientry); + + if (ientry == 0) { + if (tras == 0 && err_tras == 0) activeParam[0] = false; + if (traz == 0 && err_traz == 0) activeParam[1] = false; + if (trat == 0 && err_trat == 0) activeParam[2] = false; + if (rots == 0 && err_rots == 0) activeParam[3] = false; + if (rotz == 0 && err_rotz == 0) activeParam[4] = false; + if (rott == 0 && err_rott == 0) activeParam[5] = false; + } + + double** yArr(0); + double** yErr(0); + double* min(0); + double* max(0); + double* chi2Arr(0); + double* nDoFArr(0); + + if (iter == 0) { + yArr = new double*[6]; + yArr[0] = new double[NITER_MAX + 1]; + yArr[1] = new double[NITER_MAX + 1]; + yArr[2] = new double[NITER_MAX + 1]; + yArr[3] = new double[NITER_MAX + 1]; + yArr[4] = new double[NITER_MAX + 1]; + yArr[5] = new double[NITER_MAX + 1]; + + yErr = new double*[6]; + yErr[0] = new double[NITER_MAX + 1]; + yErr[1] = new double[NITER_MAX + 1]; + yErr[2] = new double[NITER_MAX + 1]; + yErr[3] = new double[NITER_MAX + 1]; + yErr[4] = new double[NITER_MAX + 1]; + yErr[5] = new double[NITER_MAX + 1]; + + nDoFArr = new double[NITER_MAX + 1]; + chi2Arr = new double[NITER_MAX + 1]; + + min = new double[6]; + max = new double[6]; + + for (int i = 0; i < 6; i++) { + yErr[i][0] = 0.; + min[i] = 1.e6; + max[i] = -1.e6; + } + + yArrMap[chamberId] = yArr; + yErrMap[chamberId] = yErr; + minMap[chamberId] = min; + maxMap[chamberId] = max; + + } else { + yArr = yArrMap[chamberId]; + yErr = yErrMap[chamberId]; + min = minMap[chamberId]; + max = maxMap[chamberId]; + } + // if (chamberId!=240131072) continue; //EIL2A1 + + if (iter == 0) { + cout << "iter 0, init_trat=" << init_trat << endl; + yArr[0][iter] = init_tras; + yArr[1][iter] = init_traz; + yArr[2][iter] = init_trat; + yArr[3][iter] = init_rots * 1000; + yArr[4][iter] = init_rotz * 1000; + yArr[5][iter] = init_rott * 1000; + if (L1ALIGNMENT && INITMISAL) { + yArr[0][0] += 2.; + yArr[1][0] += 1.; + yArr[2][0] += -.5; + yArr[3][0] += .01; + yArr[4][0] += -.03; + yArr[5][0] += -.2; + } + } else { + cout << "iter " << iter << ", init_trat=" << init_trat << endl; + cout << "init_trat+delta=" << yArr[0][iter - 1] + trat << endl; + yArr[0][iter] = yArr[0][iter - 1] + tras; + yArr[1][iter] = yArr[1][iter - 1] + traz; + yArr[2][iter] = yArr[2][iter - 1] + trat; + yArr[3][iter] = yArr[3][iter - 1] + rots * 1000.; + yArr[4][iter] = yArr[4][iter - 1] + rotz * 1000.; + yArr[5][iter] = yArr[5][iter - 1] + rott * 1000.; + if (L1ALIGNMENT && INITMISAL && iter == 2) { + yArr[0][2] -= 2.; + yArr[1][2] -= 1.; + yArr[2][2] -= -.5; + yArr[3][2] -= .01; + yArr[4][2] -= -.03; + yArr[5][2] -= -.2; + } + /* + yArr[0][iter]= tras; + yArr[1][iter]= traz; + yArr[2][iter]= trat; + yArr[3][iter]= rots*1000.; + yArr[4][iter]= rotz*1000.; + yArr[5][iter]= rott*1000.; */ + yErr[0][iter] = err_tras; + yErr[1][iter] = err_traz; + yErr[2][iter] = err_trat; + yErr[3][iter] = err_rots * 1000. * 1.75; + yErr[4][iter] = err_rotz * 1000. * 1.7; + yErr[5][iter] = err_rott * 1000. * 2.44; + } + // chi2Arr[iter]=chi2; + // nTracksArr[iter]=nTracks; + // cout<<"tracks/chi2="<<nTracks<<"/"<<chi2<<endl; + + for (int i = 0; i < 6; i++) { + if (!activeParam[i]) continue; + + if (!DRAWERR) { + if (yArr[i][iter] < min[i]) min[i] = yArr[i][iter]; + if (yArr[i][iter] > max[i]) max[i] = yArr[i][iter]; + } else { + if ((yArr[i][iter] - yErr[i][iter]) < min[i]) min[i] = yArr[i][iter] - yErr[i][iter]; + if ((yArr[i][iter] + yErr[i][iter]) > max[i]) max[i] = yArr[i][iter] + yErr[i][iter]; + } + } } - } - } - delete file; - file=0; - } - - //------------- - //-- Make plots - //------------- - - MuonFixedId* mid=new MuonFixedId(0); - map<long long int,double**>::const_iterator yArrIt = yArrMap.begin(); - map<long long int,double**>::const_iterator yArrEnd = yArrMap.end(); - map<long long int,double**>::const_iterator yErrIt = yErrMap.begin(); - map<long long int,double*>::const_iterator minIt = minMap.begin(); - map<long long int,double*>::const_iterator maxIt = maxMap.begin(); - - const int NITER = niter-1; - - map<string,vector<TGraph**>*> graphMap; - map<string,vector<string> > graphNamesMap; - map<string,double*> graphMinMap; - map<string,double*> graphMaxMap; - - for (; yArrIt!=yArrEnd; yArrIt++,yErrIt++,minIt++,maxIt++) { - - int chamberId = yArrIt->first; - mid->setMuonIdentifier(chamberId); - string chamberName; - if (chamberId>2) chamberName = Tools::getChamberName(mid); - else { - if (chamberId==0) chamberName="endcapA"; - else if (chamberId==1) chamberName="endcapC"; - else if (chamberId==2) chamberName="barrel"; - } - - double** yArr = yArrIt->second; - double** yErr = yErrIt->second; - double* min = minIt->second; - double* max = maxIt->second; - - TCanvas* canv=new TCanvas("canv"+TString(chamberName),"canv"); - //canv->SetFillColor(10); - canv->Divide(3,2); - TGraph** gr =new TGraph*[6]; - TH1F** hist=new TH1F*[6]; - double value[6]={0.,0.,0.,0.,0.,0.}; - if(chamberName=="EIL2A1"){ - value[0] = 2.155; - value[1] = .546; - value[2] = -.283; - value[3] = -.445; - value[4] = 2.23; - value[5] = .517; + delete file; + file = 0; } - - //if plots will be combined, plot difference to nominal position - if(COMBINE){ - for (int i=0;i<6;i++) { - for (int iter=0;iter<niter;iter++){ - yArr[i][iter] -= value[i]; + + //------------- + //-- Make plots + //------------- + + MuonFixedId* mid = new MuonFixedId(0); + map<long long int, double**>::const_iterator yArrIt = yArrMap.begin(); + map<long long int, double**>::const_iterator yArrEnd = yArrMap.end(); + map<long long int, double**>::const_iterator yErrIt = yErrMap.begin(); + map<long long int, double*>::const_iterator minIt = minMap.begin(); + map<long long int, double*>::const_iterator maxIt = maxMap.begin(); + + const int NITER = niter - 1; + + map<string, vector<TGraph**>*> graphMap; + map<string, vector<string> > graphNamesMap; + map<string, double*> graphMinMap; + map<string, double*> graphMaxMap; + + for (; yArrIt != yArrEnd; yArrIt++, yErrIt++, minIt++, maxIt++) { + int chamberId = yArrIt->first; + mid->setMuonIdentifier(chamberId); + string chamberName; + if (chamberId > 2) + chamberName = Tools::getChamberName(mid); + else { + if (chamberId == 0) + chamberName = "endcapA"; + else if (chamberId == 1) + chamberName = "endcapC"; + else if (chamberId == 2) + chamberName = "barrel"; } - min[i] -= value[i]; - max[i] -= value[i]; - value[i] = 0.; - } - } - for (int i=0;i<6;i++) { - for (int iter=0;iter<niter;iter++){ - cout<<"yArr["<<i<<"]["<<iter<<"]="<<yArr[i][iter]<<endl; - } - } + double** yArr = yArrIt->second; + double** yErr = yErrIt->second; + double* min = minIt->second; + double* max = maxIt->second; + + TCanvas* canv = new TCanvas("canv" + TString(chamberName), "canv"); + // canv->SetFillColor(10); + canv->Divide(3, 2); + TGraph** gr = new TGraph*[6]; + TH1F** hist = new TH1F*[6]; + double value[6] = {0., 0., 0., 0., 0., 0.}; + if (chamberName == "EIL2A1") { + value[0] = 2.155; + value[1] = .546; + value[2] = -.283; + value[3] = -.445; + value[4] = 2.23; + value[5] = .517; + } - //string names[6]={"S", "Z", "T", "rot_S", "rot_Z", "rot_T"}; - TLine** line=new TLine*[6]; - for (int i=0;i<6;i++) { - line[i]=new TLine(xArr[0],value[i],xArr[NITER],value[i]); - if (value[i]<min[i]) min[i]=value[i]; - if (value[i]>max[i]) max[i]=value[i]; - } - - for (int i=0;i<6;i++) { - //for (int i=2;i<3;i++) { - if(!activeParam[i]) continue; - canv->cd(i+1); - - double currentmin=(min[i]<0.)?1.1*min[i]:.8*min[i]; - double currentmax=(max[i]>0.)?1.1*max[i]:.8*max[i]; - hist[i]=canv->cd(i+1)->DrawFrame(xArr[0],currentmin,xArr[NITER],currentmax); - string title = chamberName;// + " - " + names[i]; - hist[i]->SetTitle(title.c_str()); - hist[i]->GetXaxis()->SetTitle("Iterations"); - - string ytitle = ytitles[i]+ units[i]; - hist[i]->GetYaxis()->SetTitle(ytitle.c_str()); - - canv->cd(i+1)->Modified(); - - if(!DRAWERR) gr[i]=new TGraph (NITER+1,xArr,yArr[i]); - else gr[i]=new TGraphErrors(NITER+1,xArr,yArr[i],xErr,yErr[i]); - - gr[i]->SetMarkerSize(0.8); - gr[i]->SetMarkerStyle(8); - gr[i]->SetLineWidth(2); - gr[i]->Draw("PLsame"); - - line[i]->SetLineColor(kRed); - line[i]->Draw("same"); - - - } - stringstream canvname; - canvname<<outputdir<<"/iterations_"<<rootname; - if((int)yArrMap.size()>1){ - canvname<<"_"<<chamberName; - } - canvname<<".eps"; - canv->Print(canvname.str().c_str()); - - if(COMBINE) { - string towerName = chamberName; - towerName.replace(1,1,""); - if(!graphMap[towerName]){ - graphMap[towerName] = new vector<TGraph**>(0); - graphNamesMap[towerName] = vector<string>(0); - graphMinMap[towerName] = min; - graphMaxMap[towerName] = max; - } - else{ - double* grMin = graphMinMap[towerName]; - double* grMax = graphMaxMap[towerName]; - for (int i=0;i<6;i++) { - if(min[i]<grMin[i]) grMin[i]=min[i]; - if(max[i]>grMax[i]) grMax[i]=max[i]; - } - } - graphMap[towerName]->push_back(gr); - graphNamesMap[towerName].push_back(chamberName); - } + // if plots will be combined, plot difference to nominal position + if (COMBINE) { + for (int i = 0; i < 6; i++) { + for (int iter = 0; iter < niter; iter++) { yArr[i][iter] -= value[i]; } + min[i] -= value[i]; + max[i] -= value[i]; + value[i] = 0.; + } + } - if (!COMBINE) delete [] gr; - delete [] line; - - delete canv; - }//for yArrIt - - - //--------------- - // Make more plots - //--------------- - - if(DOALLPLOTS){ - yArrIt = yArrMap.begin(); - map<long long int,double*> ::const_iterator chi2It = chi2Map.begin(); - map<long long int,int*> ::const_iterator nTracksIt = nTracksMap.begin(); - map<long long int,int*> ::const_iterator nDoFIt = nDoFMap.begin(); - - for (; yArrIt!=yArrEnd; yArrIt++,nTracksIt++,chi2It++,nDoFIt++) { - int chamberId = yArrIt->first; - mid->setMuonIdentifier(chamberId); - string chamberName; - if (chamberId>2) chamberName = Tools::getChamberName(mid); - else { - if (chamberId==0) chamberName="endcapA"; - else if (chamberId==1) chamberName="endcapC"; - else if (chamberId==2) chamberName="barrel"; - } - int* nDoFArr= nDoFIt->second; - double* dDoFArr=new double[NITER+1]; - for (int iter=0;iter<niter;iter++) { - dDoFArr[iter]=(double)nDoFArr[iter]; - } - - double* totalchi2Arr = chi2It->second; - double* chi2dofArr = new double[NITER+1]; - for (int iter=0;iter<niter;iter++) { - if (nDoFArr[iter]>0) { - chi2dofArr[iter]=totalchi2Arr[iter]/(double)nDoFArr[iter]; - cout<<"chi2dofArr["<<iter<<"]="<<chi2dofArr[iter]<<endl; - cout<<"totalchi2Arr="<<totalchi2Arr[iter]<<", nDoF="<<nDoFArr[iter]<<endl; + for (int i = 0; i < 6; i++) { + for (int iter = 0; iter < niter; iter++) { cout << "yArr[" << i << "][" << iter << "]=" << yArr[i][iter] << endl; } + } + + // string names[6]={"S", "Z", "T", "rot_S", "rot_Z", "rot_T"}; + TLine** line = new TLine*[6]; + for (int i = 0; i < 6; i++) { + line[i] = new TLine(xArr[0], value[i], xArr[NITER], value[i]); + if (value[i] < min[i]) min[i] = value[i]; + if (value[i] > max[i]) max[i] = value[i]; + } + + for (int i = 0; i < 6; i++) { + // for (int i=2;i<3;i++) { + if (!activeParam[i]) continue; + canv->cd(i + 1); + + double currentmin = (min[i] < 0.) ? 1.1 * min[i] : .8 * min[i]; + double currentmax = (max[i] > 0.) ? 1.1 * max[i] : .8 * max[i]; + hist[i] = canv->cd(i + 1)->DrawFrame(xArr[0], currentmin, xArr[NITER], currentmax); + string title = chamberName; // + " - " + names[i]; + hist[i]->SetTitle(title.c_str()); + hist[i]->GetXaxis()->SetTitle("Iterations"); + + string ytitle = ytitles[i] + units[i]; + hist[i]->GetYaxis()->SetTitle(ytitle.c_str()); + + canv->cd(i + 1)->Modified(); + + if (!DRAWERR) + gr[i] = new TGraph(NITER + 1, xArr, yArr[i]); + else + gr[i] = new TGraphErrors(NITER + 1, xArr, yArr[i], xErr, yErr[i]); + + gr[i]->SetMarkerSize(0.8); + gr[i]->SetMarkerStyle(8); + gr[i]->SetLineWidth(2); + gr[i]->Draw("PLsame"); + + line[i]->SetLineColor(kRed); + line[i]->Draw("same"); + } + stringstream canvname; + canvname << outputdir << "/iterations_" << rootname; + if ((int)yArrMap.size() > 1) { canvname << "_" << chamberName; } + canvname << ".eps"; + canv->Print(canvname.str().c_str()); + + if (COMBINE) { + string towerName = chamberName; + towerName.replace(1, 1, ""); + if (!graphMap[towerName]) { + graphMap[towerName] = new vector<TGraph**>(0); + graphNamesMap[towerName] = vector<string>(0); + graphMinMap[towerName] = min; + graphMaxMap[towerName] = max; + } else { + double* grMin = graphMinMap[towerName]; + double* grMax = graphMaxMap[towerName]; + for (int i = 0; i < 6; i++) { + if (min[i] < grMin[i]) grMin[i] = min[i]; + if (max[i] > grMax[i]) grMax[i] = max[i]; + } + } + graphMap[towerName]->push_back(gr); + graphNamesMap[towerName].push_back(chamberName); + } + + if (!COMBINE) delete[] gr; + delete[] line; + + delete canv; + } // for yArrIt + + //--------------- + // Make more plots + //--------------- + + if (DOALLPLOTS) { + yArrIt = yArrMap.begin(); + map<long long int, double*>::const_iterator chi2It = chi2Map.begin(); + map<long long int, int*>::const_iterator nTracksIt = nTracksMap.begin(); + map<long long int, int*>::const_iterator nDoFIt = nDoFMap.begin(); + + for (; yArrIt != yArrEnd; yArrIt++, nTracksIt++, chi2It++, nDoFIt++) { + int chamberId = yArrIt->first; + mid->setMuonIdentifier(chamberId); + string chamberName; + if (chamberId > 2) + chamberName = Tools::getChamberName(mid); + else { + if (chamberId == 0) + chamberName = "endcapA"; + else if (chamberId == 1) + chamberName = "endcapC"; + else if (chamberId == 2) + chamberName = "barrel"; + } + int* nDoFArr = nDoFIt->second; + double* dDoFArr = new double[NITER + 1]; + for (int iter = 0; iter < niter; iter++) { dDoFArr[iter] = (double)nDoFArr[iter]; } + + double* totalchi2Arr = chi2It->second; + double* chi2dofArr = new double[NITER + 1]; + for (int iter = 0; iter < niter; iter++) { + if (nDoFArr[iter] > 0) { + chi2dofArr[iter] = totalchi2Arr[iter] / (double)nDoFArr[iter]; + cout << "chi2dofArr[" << iter << "]=" << chi2dofArr[iter] << endl; + cout << "totalchi2Arr=" << totalchi2Arr[iter] << ", nDoF=" << nDoFArr[iter] << endl; + } + } + + TCanvas* canvnTrks = new TCanvas("canv" + TString(chamberName) + "_ntrks", "canv"); + int* ntracksArr = nTracksIt->second; + double* dtracksArr = new double[NITER + 1]; + for (int iter = 0; iter < niter; iter++) { dtracksArr[iter] = (double)ntracksArr[iter]; } + TGraph* grNTrks = new TGraph(niter - 1, xArr, dtracksArr); + grNTrks->SetMarkerSize(0.8); + grNTrks->SetMarkerStyle(8); + grNTrks->SetLineWidth(2); + grNTrks->Draw("APL"); + grNTrks->GetXaxis()->SetTitle("iterations"); + grNTrks->GetYaxis()->SetTitle("number tracks"); + stringstream canvname; + canvname << outputdir << "/iterations_ntrks_" << rootname; + if ((int)yArrMap.size() > 1) { canvname << "_" << chamberName; } + canvname << ".eps"; + canvnTrks->Print(canvname.str().c_str()); + + TCanvas* canvChi2 = new TCanvas("canv" + TString(chamberName) + "_chi2", "canv"); + + TGraph* grChi2 = new TGraph(niter - 1, xArr, chi2dofArr); + grChi2->SetMarkerSize(0.8); + grChi2->SetMarkerStyle(8); + grChi2->SetLineWidth(2); + grChi2->Draw("APL"); + grChi2->GetXaxis()->SetTitle("iterations"); + grChi2->GetYaxis()->SetTitle("track #chi^{2}/NDoF"); + stringstream canvnamechi2; + canvnamechi2 << outputdir << "/iterations_chi2_" << rootname; + if ((int)yArrMap.size() > 1) { canvnamechi2 << "_" << chamberName; } + canvnamechi2 << ".eps"; + canvChi2->Print(canvnamechi2.str().c_str()); } - } - - TCanvas* canvnTrks =new TCanvas("canv"+TString(chamberName)+"_ntrks","canv"); - int* ntracksArr=nTracksIt->second; - double* dtracksArr=new double[NITER+1]; - for (int iter=0;iter<niter;iter++) { - dtracksArr[iter]=(double)ntracksArr[iter]; - } - TGraph* grNTrks=new TGraph(niter-1,xArr,dtracksArr); - grNTrks->SetMarkerSize(0.8); - grNTrks->SetMarkerStyle(8); - grNTrks->SetLineWidth(2); - grNTrks->Draw("APL"); - grNTrks->GetXaxis()->SetTitle("iterations"); - grNTrks->GetYaxis()->SetTitle("number tracks"); - stringstream canvname; - canvname<<outputdir<<"/iterations_ntrks_"<<rootname; - if((int)yArrMap.size()>1){ - canvname<<"_"<<chamberName; - } - canvname<<".eps"; - canvnTrks->Print(canvname.str().c_str()); - - TCanvas* canvChi2=new TCanvas("canv"+TString(chamberName)+"_chi2","canv"); - - TGraph* grChi2 =new TGraph(niter-1,xArr,chi2dofArr); - grChi2->SetMarkerSize(0.8); - grChi2->SetMarkerStyle(8); - grChi2->SetLineWidth(2); - grChi2->Draw("APL"); - grChi2->GetXaxis()->SetTitle("iterations"); - grChi2->GetYaxis()->SetTitle("track #chi^{2}/NDoF"); - stringstream canvnamechi2; - canvnamechi2<<outputdir<<"/iterations_chi2_"<<rootname; - if((int)yArrMap.size()>1){ - canvnamechi2<<"_"<<chamberName; - } - canvnamechi2<<".eps"; - canvChi2->Print(canvnamechi2.str().c_str()); - } - } - - if (!COMBINE) return 0; - - map<string,vector<TGraph**>*>::const_iterator graphIt = graphMap.begin(); - map<string,vector<TGraph**>*>::const_iterator graphEnd = graphMap.end(); - map<string,vector<string> >::const_iterator graphNamesIt = graphNamesMap.begin(); - map<string,double*>::const_iterator graphMinIt = graphMinMap.begin(); - map<string,double*>::const_iterator graphMaxIt = graphMaxMap.begin(); - - TLine* line = new TLine(xArr[0],0,xArr[NITER],0); - line->SetLineColor(kRed); - //line->SetLineColor(14); - //line->SetLineStyle(2); - //int markerstyles[3] = {8,4,21}; - int markerstyles[3] = {8,22,21}; - - for (; graphIt!=graphEnd; graphIt++,graphMinIt++,graphMaxIt++,graphNamesIt++) { - - string name = graphIt->first; - vector<TGraph**>* graphs=graphIt->second; - - TH1F** hist=new TH1F*[6]; - TCanvas* canv=new TCanvas("canv"+TString(name),"canv"); - double shift = 0.009; - TLegend* leg = new TLegend(0.1+shift, 0.67, 0.25+shift, 0.82); - //TLegend* leg = new TLegend(0.1, 0.65, 0.2, 0.85); - canv->Divide(3,2); - - for(unsigned int iGr=0;iGr<graphs->size();iGr++){ - for (int i=1;i<6;i++) { - if(!activeParam[i]) continue; - canv->cd(i+1); - - if(iGr==0){ - double min = graphMinIt->second[i]; - double max = graphMaxIt->second[i]; - double currentmin=(min<0.)?1.1*min:.8*min; - double currentmax=(max>0.)?1.1*max:.8*max; - hist[i]=canv->cd(i+1)->DrawFrame(xArr[0],currentmin,xArr[NITER],currentmax); - hist[i]->GetXaxis()->SetTitle("Iterations"); - string ytitle = ytitles[i]+ units[i]; - hist[i]->GetYaxis()->SetTitle(ytitle.c_str()); - line->Draw("same"); - } - - TGraph* gr = graphs->at(iGr)[i]; - int color = iGr==0 ? iGr+1 : iGr+2; - gr->SetLineColor(color); - gr->SetMarkerColor(color); - gr->SetMarkerStyle(markerstyles[iGr%3]); - gr->Draw("PLsame"); - - if(i==1){ - leg->AddEntry(gr,graphNamesIt->second[iGr].c_str(),"PL"); - } - } - - if(iGr==graphs->size()-1){ - canv->cd(0); - leg->SetBorderSize(0); - leg->SetFillColor(0); - leg->Draw(); - - stringstream canvname; - canvname<<outputdir<<"/iterations_"<<rootname; - canvname<<"_"<<name<<"combined"; - canvname<<".eps"; - canv->Print(canvname.str().c_str()); - } } - delete [] hist; - delete canv; - delete leg; - for(unsigned int iGr=0;iGr<graphs->size();iGr++){ - for (int i=1;i<6;i++) { - if(!activeParam[i]) continue; - delete graphs->at(iGr)[i]; - } + + if (!COMBINE) return 0; + + map<string, vector<TGraph**>*>::const_iterator graphIt = graphMap.begin(); + map<string, vector<TGraph**>*>::const_iterator graphEnd = graphMap.end(); + map<string, vector<string> >::const_iterator graphNamesIt = graphNamesMap.begin(); + map<string, double*>::const_iterator graphMinIt = graphMinMap.begin(); + map<string, double*>::const_iterator graphMaxIt = graphMaxMap.begin(); + + TLine* line = new TLine(xArr[0], 0, xArr[NITER], 0); + line->SetLineColor(kRed); + // line->SetLineColor(14); + // line->SetLineStyle(2); + // int markerstyles[3] = {8,4,21}; + int markerstyles[3] = {8, 22, 21}; + + for (; graphIt != graphEnd; graphIt++, graphMinIt++, graphMaxIt++, graphNamesIt++) { + string name = graphIt->first; + vector<TGraph**>* graphs = graphIt->second; + + TH1F** hist = new TH1F*[6]; + TCanvas* canv = new TCanvas("canv" + TString(name), "canv"); + double shift = 0.009; + TLegend* leg = new TLegend(0.1 + shift, 0.67, 0.25 + shift, 0.82); + // TLegend* leg = new TLegend(0.1, 0.65, 0.2, 0.85); + canv->Divide(3, 2); + + for (unsigned int iGr = 0; iGr < graphs->size(); iGr++) { + for (int i = 1; i < 6; i++) { + if (!activeParam[i]) continue; + canv->cd(i + 1); + + if (iGr == 0) { + double min = graphMinIt->second[i]; + double max = graphMaxIt->second[i]; + double currentmin = (min < 0.) ? 1.1 * min : .8 * min; + double currentmax = (max > 0.) ? 1.1 * max : .8 * max; + hist[i] = canv->cd(i + 1)->DrawFrame(xArr[0], currentmin, xArr[NITER], currentmax); + hist[i]->GetXaxis()->SetTitle("Iterations"); + string ytitle = ytitles[i] + units[i]; + hist[i]->GetYaxis()->SetTitle(ytitle.c_str()); + line->Draw("same"); + } + + TGraph* gr = graphs->at(iGr)[i]; + int color = iGr == 0 ? iGr + 1 : iGr + 2; + gr->SetLineColor(color); + gr->SetMarkerColor(color); + gr->SetMarkerStyle(markerstyles[iGr % 3]); + gr->Draw("PLsame"); + + if (i == 1) { leg->AddEntry(gr, graphNamesIt->second[iGr].c_str(), "PL"); } + } + + if (iGr == graphs->size() - 1) { + canv->cd(0); + leg->SetBorderSize(0); + leg->SetFillColor(0); + leg->Draw(); + + stringstream canvname; + canvname << outputdir << "/iterations_" << rootname; + canvname << "_" << name << "combined"; + canvname << ".eps"; + canv->Print(canvname.str().c_str()); + } + } + delete[] hist; + delete canv; + delete leg; + for (unsigned int iGr = 0; iGr < graphs->size(); iGr++) { + for (int i = 1; i < 6; i++) { + if (!activeParam[i]) continue; + delete graphs->at(iGr)[i]; + } + } } - - } - delete line; - - return 0; - + delete line; + + return 0; } //________________________________________________________________________ -bool getTotalChi2(int iter, TTree* tree, - std::map<long long int,int*>& ntracksMap, - std::map<long long int,int*>& ndofMap, - std::map<long long int, double*>& totalchi2Map) -{ - long long int chamberId; - int nDoF,nTracks; - double chi2; - - tree->SetBranchAddress("chamberId", &chamberId); - tree->SetBranchAddress("nTracks", &nTracks); - tree->SetBranchAddress("nDoF", &nDoF); - tree->SetBranchAddress("trackChi2", &chi2); - - if (tree->GetEntries()<1) return false; - - for (int ientry=0;ientry<(int)tree->GetEntries();ientry++) { - tree->GetEntry(ientry); - - std::map<long long int,int*>::const_iterator it=ndofMap.find(chamberId); - if (it==ndofMap.end()) { - ntracksMap[chamberId] =new int [NITER_MAX]; - ndofMap[chamberId] =new int [NITER_MAX]; - totalchi2Map[chamberId]=new double[NITER_MAX]; - for (int i=0;i<NITER_MAX;i++) { - ntracksMap[chamberId][i]=0; - ndofMap[chamberId][i]=0; - totalchi2Map[chamberId][i]=0.; - } - ntracksMap [chamberId][iter]=nTracks; - ndofMap [chamberId][iter]=nDoF; - cout<<"chi2="<<chi2<<endl; - totalchi2Map[chamberId][iter]=chi2; - cout<<" totalchi2Map["<<chamberId<<"]["<<iter<<"]="<<totalchi2Map[chamberId][iter]<<endl; - } - else { - ntracksMap [chamberId][iter]+=nTracks; - ndofMap [chamberId][iter]+=nDoF; - totalchi2Map[chamberId][iter]+=chi2; - cout<<"+totalchi2Map["<<chamberId<<"]["<<iter<<"]="<<totalchi2Map[chamberId][iter]<<endl; +bool getTotalChi2(int iter, TTree* tree, std::map<long long int, int*>& ntracksMap, std::map<long long int, int*>& ndofMap, + std::map<long long int, double*>& totalchi2Map) { + long long int chamberId; + int nDoF, nTracks; + double chi2; + + tree->SetBranchAddress("chamberId", &chamberId); + tree->SetBranchAddress("nTracks", &nTracks); + tree->SetBranchAddress("nDoF", &nDoF); + tree->SetBranchAddress("trackChi2", &chi2); + + if (tree->GetEntries() < 1) return false; + + for (int ientry = 0; ientry < (int)tree->GetEntries(); ientry++) { + tree->GetEntry(ientry); + + std::map<long long int, int*>::const_iterator it = ndofMap.find(chamberId); + if (it == ndofMap.end()) { + ntracksMap[chamberId] = new int[NITER_MAX]; + ndofMap[chamberId] = new int[NITER_MAX]; + totalchi2Map[chamberId] = new double[NITER_MAX]; + for (int i = 0; i < NITER_MAX; i++) { + ntracksMap[chamberId][i] = 0; + ndofMap[chamberId][i] = 0; + totalchi2Map[chamberId][i] = 0.; + } + ntracksMap[chamberId][iter] = nTracks; + ndofMap[chamberId][iter] = nDoF; + cout << "chi2=" << chi2 << endl; + totalchi2Map[chamberId][iter] = chi2; + cout << " totalchi2Map[" << chamberId << "][" << iter << "]=" << totalchi2Map[chamberId][iter] << endl; + } else { + ntracksMap[chamberId][iter] += nTracks; + ndofMap[chamberId][iter] += nDoF; + totalchi2Map[chamberId][iter] += chi2; + cout << "+totalchi2Map[" << chamberId << "][" << iter << "]=" << totalchi2Map[chamberId][iter] << endl; + } } - } - return true; + return true; } diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/selcuts_x.cpp b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/selcuts_x.cpp index b400e6dcf52e662bd75b997fcd08d7e25648b2c6..2406982ea2e8b244251c73223ce99756d5f00674 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/selcuts_x.cpp +++ b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/selcuts_x.cpp @@ -2,56 +2,52 @@ Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ -#include "Tools.h" -#include "ChamberDerivs.h" -#include "ChamberNames.h" - -#include "TStyle.h" -#include "TLegend.h" - +#include <TAxis.h> +#include <TCanvas.h> #include <TChain.h> -#include <TTree.h> #include <TEventList.h> -#include <TGraph.h> -#include <TCanvas.h> #include <TF1.h> +#include <TGraph.h> #include <TPaveText.h> -#include <TAxis.h> +#include <TTree.h> + +#include "ChamberDerivs.h" +#include "ChamberNames.h" #include "TFile.h" #include "TH1F.h" -#include "TStyle.h" +#include "TLegend.h" #include "TLine.h" +#include "TStyle.h" +#include "Tools.h" //#include "TBox.h" -#include "TSystem.h" -#include "TGraphErrors.h" -#include "TBranch.h" -#include "TPad.h" -#include "TPaveStats.h" -#include "TMatrixTUtils.h" - -#include <iostream> +#include <cmath> +#include <fstream> #include <iomanip> +#include <iostream> +#include <list> +#include <map> +#include <set> #include <sstream> -#include <fstream> #include <string> -#include <map> -#include <cmath> #include <vector> -#include <set> -#include <list> +#include "CLHEP/Geometry/Transform3D.h" +#include "CLHEP/Matrix/Matrix.h" +#include "CLHEP/Matrix/SymMatrix.h" +#include "CLHEP/Matrix/Vector.h" +#include "TBranch.h" +#include "TDecompBK.h" +#include "TDecompSVD.h" +#include "TGraphErrors.h" #include "TH2F.h" #include "TMatrix.h" #include "TMatrixD.h" #include "TMatrixDSym.h" +#include "TMatrixTUtils.h" +#include "TPad.h" +#include "TPaveStats.h" +#include "TSystem.h" #include "TVectorD.h" -#include "TDecompBK.h" -#include "TDecompSVD.h" - -#include "CLHEP/Matrix/Matrix.h" -#include "CLHEP/Matrix/SymMatrix.h" -#include "CLHEP/Matrix/Vector.h" -#include "CLHEP/Geometry/Transform3D.h" using namespace CLHEP; @@ -60,7 +56,7 @@ void initMTPPTree(); void makeNewTree(); bool getSDTreeEntry(int ientry, int chid); -bool getMTPPTreeEntry(int& ientrySD, int run, int evt,int ntrk, int chid=-1); +bool getMTPPTreeEntry(int& ientrySD, int run, int evt, int ntrk, int chid = -1); const int getNumberMatrixIndices(); void getChamberIdMap(string filename); int getChIdFromString(const string& chname); @@ -68,7 +64,7 @@ void addDerivatives(); void fillTree(); void make2DAlignHists(const ChamberDerivs& chDerivs, TPad** pads); void makeHitmap(const ChamberDerivs& chDerivs, TPad* pad); -void plotDiagonalCutHists(bool offdiag=false); +void plotDiagonalCutHists(bool offdiag = false); int getXcoordinate(const string& chambername); int getYcoordinate(const string& chambername); @@ -81,11 +77,10 @@ void addConstraints(ChamberDerivs* chDerivs); void addSoftConstraints(ChamberDerivs* chDerivs); void addExternalConstraints(ChamberDerivs* chDerivs, const std::string& filename); -//double* fixAlongTrack(double* secDerivs) const; +// double* fixAlongTrack(double* secDerivs) const; void makeSomePlots(const ChamberDerivs& chDerivs); -TH1F** alignParDist(const ChamberDerivs& chDerivs, const string& histname, - double* range=0); +TH1F** alignParDist(const ChamberDerivs& chDerivs, const string& histname, double* range = 0); void getFinalPars(double* initPar, double* deltas, double* finalPars); @@ -93,117 +88,116 @@ bool trackSelection(); void decomposeTransform(const HepGeom::Transform3D& transform, double* values); -double m_rotscale=1.; +double m_rotscale = 1.; -bool DEBUG = true; +bool DEBUG = true; -bool L1ALIGNMENT = true; +bool L1ALIGNMENT = true; -bool FIX_T = !L1ALIGNMENT; -bool FIX_ROTZ = !L1ALIGNMENT; -bool FIX_ROTT = !L1ALIGNMENT; +bool FIX_T = !L1ALIGNMENT; +bool FIX_ROTZ = !L1ALIGNMENT; +bool FIX_ROTT = !L1ALIGNMENT; -bool DO_EC_ONLY = false; -bool DO_ASIDE_ONLY = false; -bool CONSTRAIN_EM = false; -bool CONSTRAIN_EI = false; -bool EIGENVALUE_CUT = false; +bool DO_EC_ONLY = false; +bool DO_ASIDE_ONLY = false; +bool CONSTRAIN_EM = false; +bool CONSTRAIN_EI = false; +bool EIGENVALUE_CUT = false; bool DO_SOFT_CONSTRAINT = false; -bool CONSTRAIN_ROTZ = false; +bool CONSTRAIN_ROTZ = false; bool CONSTRAIN_LOWESTEV = false; -bool DO_EE_ONLY = false; -bool SET_RANGE = true; -const double RANGE_TRA = .5; -const double RANGE_ROTS = 1.5; -const double RANGE_ROTZT= .5; -//const double RANGE_TRA = 3.; -//const double RANGE_ROTS = 4.; -//const double RANGE_ROTZT= 1.; -//const double RANGE_TRA = 1.; -//const double RANGE_ROTS = 2.; -//const double RANGE_ROTZT= 5.; -//const double RANGE_TRA = 6.; -//const double RANGE_ROTS = 4.; -//const double RANGE_ROTZT= 3.; - -string parstr[6]={"align_tras", "align_traz", "align_trat", - "align_rots","align_rotz","align_rott"}; -string unitstr[6]={"mm","mm","mm","mrad","mrad","mrad"}; -//double range_tra=(CONSTRAIN_EM||EIGENVALUE_CUT)?2.:20.; -//double range_rot=(CONSTRAIN_EM||EIGENVALUE_CUT)?2.:20.; -double range_tra=2.; -double range_rot=2.; - -const int NPAR=6; -std::string m_chname=""; - -const int NBARREL=336; -const int NENDCAP=256; - -const int CUTNCHAMBERS=0; - -const int NMAXCHAMBERS=50; -const int NMAXINDICES =NMAXCHAMBERS*6; +bool DO_EE_ONLY = false; +bool SET_RANGE = true; +const double RANGE_TRA = .5; +const double RANGE_ROTS = 1.5; +const double RANGE_ROTZT = .5; +// const double RANGE_TRA = 3.; +// const double RANGE_ROTS = 4.; +// const double RANGE_ROTZT= 1.; +// const double RANGE_TRA = 1.; +// const double RANGE_ROTS = 2.; +// const double RANGE_ROTZT= 5.; +// const double RANGE_TRA = 6.; +// const double RANGE_ROTS = 4.; +// const double RANGE_ROTZT= 3.; + +string parstr[6] = {"align_tras", "align_traz", "align_trat", "align_rots", "align_rotz", "align_rott"}; +string unitstr[6] = {"mm", "mm", "mm", "mrad", "mrad", "mrad"}; +// double range_tra=(CONSTRAIN_EM||EIGENVALUE_CUT)?2.:20.; +// double range_rot=(CONSTRAIN_EM||EIGENVALUE_CUT)?2.:20.; +double range_tra = 2.; +double range_rot = 2.; + +const int NPAR = 6; +std::string m_chname = ""; + +const int NBARREL = 336; +const int NENDCAP = 256; + +const int CUTNCHAMBERS = 0; + +const int NMAXCHAMBERS = 50; +const int NMAXINDICES = NMAXCHAMBERS * 6; ChamberDerivs* m_allChDerivs; -ChamberNames* m_chNames; +ChamberNames* m_chNames; TChain* m_sdTree; -//TChain* m_sdFriendTree; +// TChain* m_sdFriendTree; TChain* m_mtppTree; // SD tree variables -int m_sd_run, m_sd_evt, m_sd_nChambers, m_sd_nMatrixIndices; -int * m_sd_chamberIds(new int[NMAXCHAMBERS]), * m_sd_matrixIndices(new int[NMAXINDICES]); -double * m_sd_firstDeriv(new double[NMAXINDICES]); -double * m_sd_secndDeriv(new double[NMAXINDICES*NMAXINDICES]); -double * m_adjSecndDeriv(new double[NMAXINDICES*NMAXINDICES]); +int m_sd_run, m_sd_evt, m_sd_nChambers, m_sd_nMatrixIndices; +int *m_sd_chamberIds(new int[NMAXCHAMBERS]), *m_sd_matrixIndices(new int[NMAXINDICES]); +double* m_sd_firstDeriv(new double[NMAXINDICES]); +double* m_sd_secndDeriv(new double[NMAXINDICES * NMAXINDICES]); +double* m_adjSecndDeriv(new double[NMAXINDICES * NMAXINDICES]); -double m_sd_momentum; +double m_sd_momentum; -TBranch* m_sd_brNChambers; -TBranch* m_sd_brChambers; -TBranch* m_sd_brRun; -TBranch* m_sd_brEvt; +TBranch* m_sd_brNChambers; +TBranch* m_sd_brChambers; +TBranch* m_sd_brRun; +TBranch* m_sd_brEvt; // MuonTrackPreProcessor tree variables -int m_mtpp_run; -int m_mtpp_evt; -double trackChi2; -double trackPt; -int nresiduals; +int m_mtpp_run; +int m_mtpp_evt; +double trackChi2; +double trackPt; +int nresiduals; double* residuals; -int nInnerLayersHit; -int nMiddleLayersHit; -int nOuterLayersHit; +int nInnerLayersHit; +int nMiddleLayersHit; +int nOuterLayersHit; /* int nresiduals; double residuals[50]; int nInnerLayersHit; -int nMiddleLayersHit; -int nOuterLayersHit; -//int nOtherLayersHit; +int nMiddleLayersHit; +int nOuterLayersHit; +//int nOtherLayersHit; int nTubeLayersHitInner; int nTubeLayersHitMiddle; int nTubeLayersHitOuter; //int nTubeLayersHitOther; int nChambersHit; int nLargeChambersHit; -int nSmallChambersHit; -int nInnerLayerDriftSigns; +int nSmallChambersHit; +int nInnerLayerDriftSigns; int nMiddleLayerDriftSigns; int nOuterLayerDriftSigns; //int nOtherLayerDriftSigns; -int nInnerLayerOutliers; -int nMiddleLayerOutliers; -int nOuterLayerOutliers; -//int nOtherLayerOutliers; -int nInnerLayerHoles; -int nMiddleLayerHoles; -int nOuterLayerHoles; -//int nOtherLayerHoles; -*/ +int nInnerLayerOutliers; +int nMiddleLayerOutliers; +int nOuterLayerOutliers; +//int nOtherLayerOutliers; +int nInnerLayerHoles; +int nMiddleLayerHoles; +int nOuterLayerHoles; +//int nOtherLayerHoles; +*/ TBranch* m_mtpp_brRun; TBranch* m_mtpp_brEvt; @@ -212,1932 +206,1828 @@ TBranch* m_mtpp_brEvt; TFile* m_outputFile; TTree* m_outputTree; -int m_nAlignChambers; -double ** m_alignPar = new double*[NMAXCHAMBERS]; -double ** m_alignErr = new double*[NMAXCHAMBERS]; -double ** m_firstderiv = new double*[NMAXCHAMBERS]; -double ** m_secndderiv = new double*[NMAXCHAMBERS]; -int * m_chamberIds = new int [NMAXCHAMBERS]; - -int m_nInnerChambers,m_nMiddleChambers,m_nOuterChambers,m_nOtherChambers; - -void help(const char *argv0) { - - cerr << "Usage: " << argv0 << " [options] " << endl - << "Options:" << endl - << " -o :\tOutput path" << endl - << " -i :\tInput files" << endl - << " -r :\tRootname" << endl - << " -j :\tIteration" << endl - << " -a :\tDraw absolute lines" << endl - << " -d :\tDebug" << endl - << " -c :\tChamber name" << endl - << " -t :\tMinimum number of tracks" << endl - << " -f :\tMinimum number of tracks in off-diagonal" << endl - << " -h :\tShow this message and quit" << endl - << endl; - exit(1); +int m_nAlignChambers; +double** m_alignPar = new double*[NMAXCHAMBERS]; +double** m_alignErr = new double*[NMAXCHAMBERS]; +double** m_firstderiv = new double*[NMAXCHAMBERS]; +double** m_secndderiv = new double*[NMAXCHAMBERS]; +int* m_chamberIds = new int[NMAXCHAMBERS]; + +int m_nInnerChambers, m_nMiddleChambers, m_nOuterChambers, m_nOtherChambers; + +void help(const char* argv0) { + cerr << "Usage: " << argv0 << " [options] " << endl + << "Options:" << endl + << " -o :\tOutput path" << endl + << " -i :\tInput files" << endl + << " -r :\tRootname" << endl + << " -j :\tIteration" << endl + << " -a :\tDraw absolute lines" << endl + << " -d :\tDebug" << endl + << " -c :\tChamber name" << endl + << " -t :\tMinimum number of tracks" << endl + << " -f :\tMinimum number of tracks in off-diagonal" << endl + << " -h :\tShow this message and quit" << endl + << endl; + exit(1); } //_____________________________________________________________________________ -int main(int argc, char** argv) -{ - int nTracksProcessed=0; - int nTracksBeforeCut=0; - int nTracks=0; - int nTracksBEEA=0; - int nTracksBEEC=0; - int nTracksEELA=0; - int nTracksEELC=0; - int nTracksBIS8A=0; - int nTracksBIS8C=0; - double totalTrackChi2=0.; - double totalTrackChi2BEEA=0.; - double totalTrackChi2BEEC=0.; - double totalTrackChi2EELA=0.; - double totalTrackChi2EELC=0.; - double totalTrackChi2BIS8A=0.; - double totalTrackChi2BIS8C=0.; - int nTracksECA=0; - int nTracksECC=0; - int nTracksBAR=0; - double totalTrackChi2ECA=0.; - double totalTrackChi2ECC=0.; - double totalTrackChi2BAR=0.; - - for (int i=0;i<NMAXCHAMBERS;i++) { - m_alignPar[i]=new double[NPAR]; - m_alignErr[i]=new double[NPAR]; - m_firstderiv[i]=new double[NPAR]; - m_secndderiv[i]=new double[NPAR]; - } +int main(int argc, char** argv) { + int nTracksProcessed = 0; + int nTracksBeforeCut = 0; + int nTracks = 0; + int nTracksBEEA = 0; + int nTracksBEEC = 0; + int nTracksEELA = 0; + int nTracksEELC = 0; + int nTracksBIS8A = 0; + int nTracksBIS8C = 0; + double totalTrackChi2 = 0.; + double totalTrackChi2BEEA = 0.; + double totalTrackChi2BEEC = 0.; + double totalTrackChi2EELA = 0.; + double totalTrackChi2EELC = 0.; + double totalTrackChi2BIS8A = 0.; + double totalTrackChi2BIS8C = 0.; + int nTracksECA = 0; + int nTracksECC = 0; + int nTracksBAR = 0; + double totalTrackChi2ECA = 0.; + double totalTrackChi2ECC = 0.; + double totalTrackChi2BAR = 0.; + + for (int i = 0; i < NMAXCHAMBERS; i++) { + m_alignPar[i] = new double[NPAR]; + m_alignErr[i] = new double[NPAR]; + m_firstderiv[i] = new double[NPAR]; + m_secndderiv[i] = new double[NPAR]; + } - //---------------------------- - //-- Parse the command line -- - //---------------------------- - - - extern char *optarg; - char c; - TString inputdir("/afs/cern.ch/user/r/roberth/scratch0/L1_1file_noscat_results/"); - - - TString outputdir(""); - //TString rootname("group.det-muon"); - TString rootname(""); - - int iteration = 0; - bool ABSLINES = false; - int diagcut(1),offdiagcut(0),maxnevents(-1); - - while((c = getopt(argc, argv, "-hdaloc:i:r:j:t:f:n:")) !=-1){ - switch(c){ - case 'o': - outputdir = optarg; - break; - case 'i': - inputdir = optarg; - break; - case 'r': - rootname = optarg; - break; - case 'j': - iteration = atoi(optarg); - break; - case 'd': - DEBUG = true; - break; - case 'a': - ABSLINES = true; - break; - case 't': - diagcut = atoi(optarg); - break; - case 'f': - offdiagcut = atoi(optarg); - break; - case 'n': - maxnevents = atoi(optarg); - break; - case 'c': - m_chname = optarg; - break; - default: - cerr << "Help or unknown argument!" << endl; - help(argv[0]); - break; + //---------------------------- + //-- Parse the command line -- + //---------------------------- + + extern char* optarg; + char c; + TString inputdir("/afs/cern.ch/user/r/roberth/scratch0/L1_1file_noscat_results/"); + + TString outputdir(""); + // TString rootname("group.det-muon"); + TString rootname(""); + + int iteration = 0; + bool ABSLINES = false; + int diagcut(1), offdiagcut(0), maxnevents(-1); + + while ((c = getopt(argc, argv, "-hdaloc:i:r:j:t:f:n:")) != -1) { + switch (c) { + case 'o': outputdir = optarg; break; + case 'i': inputdir = optarg; break; + case 'r': rootname = optarg; break; + case 'j': iteration = atoi(optarg); break; + case 'd': DEBUG = true; break; + case 'a': ABSLINES = true; break; + case 't': diagcut = atoi(optarg); break; + case 'f': offdiagcut = atoi(optarg); break; + case 'n': maxnevents = atoi(optarg); break; + case 'c': m_chname = optarg; break; + default: + cerr << "Help or unknown argument!" << endl; + help(argv[0]); + break; + } } - } - stringstream namestr; - namestr<<"MuonAlign_L1_1file_noscat_iter"<<iteration; - rootname=namestr.str(); + stringstream namestr; + namestr << "MuonAlign_L1_1file_noscat_iter" << iteration; + rootname = namestr.str(); - //getChamberIdMap("chambers.txt"); - m_chNames=(L1ALIGNMENT)? - new ChamberNames("l1chambers.txt"):new ChamberNames("chambers.txt"); + // getChamberIdMap("chambers.txt"); + m_chNames = (L1ALIGNMENT) ? new ChamberNames("l1chambers.txt") : new ChamberNames("chambers.txt"); - cout<<"diagcut: "<<diagcut<<", offdiagcut: "<<offdiagcut<<endl; + cout << "diagcut: " << diagcut << ", offdiagcut: " << offdiagcut << endl; - if(rootname==""){ - cerr << "no rootname passed, exiting..." << endl; - exit(1); - } - if(inputdir==""){ - inputdir = rootname; - } - if(outputdir==""){ - outputdir = inputdir; - } - - int chid=m_chNames->chamberIdFromString(m_chname); - cout<<"chamber ID: "<<chid<<endl; - - gStyle->SetOptStat(1111111); - gStyle->SetOptFit(11111); - gStyle->SetFrameFillStyle(0); - gStyle->SetTitleFillColor(0); - gStyle->SetTitleBorderSize(1); - gStyle->SetPadLeftMargin(0.15); - gStyle->SetPadRightMargin(0.15); - gStyle->SetPalette(1); - - void *directory = gSystem->OpenDirectory(inputdir); - if (!directory){ - cerr << "input directory "<<inputdir<<" does not exist, exiting..." << endl; - exit(1); - } - directory = gSystem->OpenDirectory(outputdir); - if (!directory){ - cerr << "create output directory: " << outputdir << endl; - int status = gSystem->mkdir(outputdir,false); - if(status!=0){ - cerr << "could not create output directory, exiting..." << endl; - exit(1); + if (rootname == "") { + cerr << "no rootname passed, exiting..." << endl; + exit(1); + } + if (inputdir == "") { inputdir = rootname; } + if (outputdir == "") { outputdir = inputdir; } + + int chid = m_chNames->chamberIdFromString(m_chname); + cout << "chamber ID: " << chid << endl; + + gStyle->SetOptStat(1111111); + gStyle->SetOptFit(11111); + gStyle->SetFrameFillStyle(0); + gStyle->SetTitleFillColor(0); + gStyle->SetTitleBorderSize(1); + gStyle->SetPadLeftMargin(0.15); + gStyle->SetPadRightMargin(0.15); + gStyle->SetPalette(1); + + void* directory = gSystem->OpenDirectory(inputdir); + if (!directory) { + cerr << "input directory " << inputdir << " does not exist, exiting..." << endl; + exit(1); + } + directory = gSystem->OpenDirectory(outputdir); + if (!directory) { + cerr << "create output directory: " << outputdir << endl; + int status = gSystem->mkdir(outputdir, false); + if (status != 0) { + cerr << "could not create output directory, exiting..." << endl; + exit(1); + } + } + + TString iterdir = inputdir + "/iter0"; + directory = gSystem->OpenDirectory(inputdir + "/iter0"); + bool multiplejobs = directory ? true : false; + + TString basefilename; + if (multiplejobs) { + TString iterdir = inputdir + Form("/iter%i/", iteration); + directory = gSystem->OpenDirectory(iterdir); + basefilename = iterdir; + if (!directory) { + cerr << "directory: " << iterdir << " does not exist" << endl; + cerr << "iteration: " << iteration << " exiting..." << endl; + exit(1); + } + } else { + basefilename = inputdir + "/"; } - } - - TString iterdir = inputdir+"/iter0"; - directory = gSystem->OpenDirectory(inputdir+"/iter0"); - bool multiplejobs = directory ? true : false; - - TString basefilename; - if(multiplejobs){ - TString iterdir = inputdir+Form("/iter%i/",iteration); - directory = gSystem->OpenDirectory(iterdir); - basefilename = iterdir; - if(!directory){ - cerr << "directory: "<<iterdir<<" does not exist"<<endl; - cerr << "iteration: " << iteration << " exiting..." << endl; - exit(1); - } - } - else{ - basefilename = inputdir+"/"; - } - //basefilename += "MuonAlign_"+rootname+Form("_iter%i",iteration); - basefilename += rootname; + // basefilename += "MuonAlign_"+rootname+Form("_iter%i",iteration); + basefilename += rootname; - TString muonalign_filename = basefilename; - TString alignpar_filename = basefilename; - if(multiplejobs){ - //muonalign_filename += "_index*"; - muonalign_filename += "*"; - alignpar_filename += "_solve"; - } - muonalign_filename += ".root"; - alignpar_filename += ".root"; - if (multiplejobs){ - muonalign_filename += "*"; - } + TString muonalign_filename = basefilename; + TString alignpar_filename = basefilename; + if (multiplejobs) { + // muonalign_filename += "_index*"; + muonalign_filename += "*"; + alignpar_filename += "_solve"; + } + muonalign_filename += ".root"; + alignpar_filename += ".root"; + if (multiplejobs) { muonalign_filename += "*"; } - cout<<"muonalign_filename: "<<muonalign_filename<<endl; + cout << "muonalign_filename: " << muonalign_filename << endl; - // data from globalChi2Deriv tree + // data from globalChi2Deriv tree - m_sdTree=new TChain("globalChi2Deriv"); - m_sdTree->Add(muonalign_filename); - cout<<"have "<<m_sdTree->GetNtrees()<<" globalChi2Deriv trees"<<endl; + m_sdTree = new TChain("globalChi2Deriv"); + m_sdTree->Add(muonalign_filename); + cout << "have " << m_sdTree->GetNtrees() << " globalChi2Deriv trees" << endl; - //m_sdFriendTree=new TChain("globalChi2DerivFriend"); - //m_sdFriendTree->Add("/tmp/roberth/newGlobalChi2Deriv.root"); - //m_sdTree->AddFriend(m_sdFriendTree); + // m_sdFriendTree=new TChain("globalChi2DerivFriend"); + // m_sdFriendTree->Add("/tmp/roberth/newGlobalChi2Deriv.root"); + // m_sdTree->AddFriend(m_sdFriendTree); - // get number of matrix indices and create matrix/vector - const int NMATINDICES=getNumberMatrixIndices(); - const int NCHAMBERS=NMATINDICES/NPAR; - cout<<"nchambers: "<<NCHAMBERS<<endl; - m_allChDerivs=new ChamberDerivs(NPAR,NCHAMBERS); + // get number of matrix indices and create matrix/vector + const int NMATINDICES = getNumberMatrixIndices(); + const int NCHAMBERS = NMATINDICES / NPAR; + cout << "nchambers: " << NCHAMBERS << endl; + m_allChDerivs = new ChamberDerivs(NPAR, NCHAMBERS); + // set branch addresses for SDTree + initSDTree(); - // set branch addresses for SDTree - initSDTree(); + // get MuonTrackPreProcessor tree + m_mtppTree = new TChain("MuonTrackPreProcessor"); + m_mtppTree->Add(muonalign_filename); + cout << "have " << m_mtppTree->GetNtrees() << " MuonTrackPreProcessor trees" << endl; + initMTPPTree(); - // get MuonTrackPreProcessor tree - m_mtppTree=new TChain("MuonTrackPreProcessor"); - m_mtppTree->Add(muonalign_filename); - cout<<"have "<<m_mtppTree->GetNtrees()<<" MuonTrackPreProcessor trees"<<endl; - initMTPPTree(); + // create new tree with combined results + makeNewTree(); - // create new tree with combined results - makeNewTree(); + int ientryMTPP(0); + int ntrks(0), lastrun(0), lastevt(0); + int nevts(0); + for (int ientrySD = 0; ientrySD < (int)m_sdTree->GetEntries(); ientrySD++) { + // cout<<"ientrySD: "<<ientrySD<<endl; - int ientryMTPP(0); - int ntrks(0),lastrun(0),lastevt(0); - int nevts(0); - for (int ientrySD=0;ientrySD<(int)m_sdTree->GetEntries();ientrySD++) { - //cout<<"ientrySD: "<<ientrySD<<endl; + if (nevts % 100000 == 0 && nevts > 0) cout << "nevts: " << nevts << endl; + nevts++; - if (nevts%100000==0&&nevts>0) cout<<"nevts: "<<nevts<<endl; - nevts++; + if (maxnevents > -1 && nevts > maxnevents) { + // cout<<"maxnevents: "<<maxnevents<<", nevts: "<<nevts<<endl; + break; + } - if (maxnevents>-1 && nevts>maxnevents) { - //cout<<"maxnevents: "<<maxnevents<<", nevts: "<<nevts<<endl; - break; - } - - // get next entry in derivatives tree - bool goodSDentry=getSDTreeEntry(ientrySD,chid); - - // increment or reset ntrks counter - if (m_sd_run!=lastrun||m_sd_evt!=lastevt) { - lastrun=m_sd_run; lastevt=m_sd_evt; - ntrks=-1; - } - ntrks++; + // get next entry in derivatives tree + bool goodSDentry = getSDTreeEntry(ientrySD, chid); - nTracksProcessed++; + // increment or reset ntrks counter + if (m_sd_run != lastrun || m_sd_evt != lastevt) { + lastrun = m_sd_run; + lastevt = m_sd_evt; + ntrks = -1; + } + ntrks++; - if (!goodSDentry) { - cout<<"not goodSDentry"<<endl; - continue; - } - //cout<<"m_sd_nMatrixIndices="<<m_sd_nMatrixIndices<<endl; - - // cut on negative second derivative - int index0=-1; - for (int imat=0;imat<m_sd_nMatrixIndices;imat++) { - for (int jmat=imat;jmat<m_sd_nMatrixIndices;jmat++) { - index0++; - if (imat!=jmat) continue; - double sd=m_sd_secndDeriv[index0]; - //cout<<"sd["<<imat<<"]["<<imat<<"]="<<sd<<endl; - if (sd<0.) goodSDentry=false; - } - } - if (!goodSDentry) { - //cout<<"bad sd entry"<<endl; - continue; - } - //else - //cout<<"good sd entry"<<endl; - - // get corresponding entry in MuonTrackPreProcessor tree - bool goodMTPPEntry=getMTPPTreeEntry(ientryMTPP,m_sd_run,m_sd_evt,ntrks,chid); - - nTracksBeforeCut++; - if (!goodMTPPEntry) continue; - //cout<<"goodMTPPEntry"<<endl; - - if (!trackSelection()) continue; - - totalTrackChi2+=trackChi2; - - for (int ich=0;ich<m_sd_nChambers;ich++) { - int chid=m_sd_chamberIds[ich]; - string chname=m_chNames->chamberName(chid); - if (chname=="") continue; - if (chname.substr(0,3)=="BEE") { - if (chname.substr(4,1)=="A") { - totalTrackChi2BEEA+=trackChi2; - nTracksBEEA++; - } - else { - totalTrackChi2BEEC+=trackChi2; - nTracksBEEC++; - } - break; - } - else if (chname.substr(0,3)=="EEL") { - if (chname.substr(4,1)=="A") { - totalTrackChi2EELA+=trackChi2; - nTracksEELA++; - } - else { - totalTrackChi2EELC+=trackChi2; - nTracksEELC++; - } - break; - } - else if (chname.substr(0,4)=="BIS8") { - if (chname.substr(4,1)=="A") { - totalTrackChi2BIS8A+=trackChi2; - nTracksBIS8A++; - } - else { - totalTrackChi2BIS8C+=trackChi2; - nTracksBIS8C++; - } - break; - } - else if (chname.substr(0,3)=="ECA") { - totalTrackChi2ECA+=trackChi2; - nTracksECA++; - break; - } - else if (chname.substr(0,3)=="ECC") { - totalTrackChi2ECC+=trackChi2; - nTracksECC++; - break; - } - else if (chname.substr(0,3)=="BAR") { - totalTrackChi2BAR+=trackChi2; - nTracksBAR++; - break; - } + nTracksProcessed++; - } + if (!goodSDentry) { + cout << "not goodSDentry" << endl; + continue; + } + // cout<<"m_sd_nMatrixIndices="<<m_sd_nMatrixIndices<<endl; + + // cut on negative second derivative + int index0 = -1; + for (int imat = 0; imat < m_sd_nMatrixIndices; imat++) { + for (int jmat = imat; jmat < m_sd_nMatrixIndices; jmat++) { + index0++; + if (imat != jmat) continue; + double sd = m_sd_secndDeriv[index0]; + // cout<<"sd["<<imat<<"]["<<imat<<"]="<<sd<<endl; + if (sd < 0.) goodSDentry = false; + } + } + if (!goodSDentry) { + // cout<<"bad sd entry"<<endl; + continue; + } + // else + // cout<<"good sd entry"<<endl; + + // get corresponding entry in MuonTrackPreProcessor tree + bool goodMTPPEntry = getMTPPTreeEntry(ientryMTPP, m_sd_run, m_sd_evt, ntrks, chid); + + nTracksBeforeCut++; + if (!goodMTPPEntry) continue; + // cout<<"goodMTPPEntry"<<endl; + + if (!trackSelection()) continue; + + totalTrackChi2 += trackChi2; + + for (int ich = 0; ich < m_sd_nChambers; ich++) { + int chid = m_sd_chamberIds[ich]; + string chname = m_chNames->chamberName(chid); + if (chname == "") continue; + if (chname.substr(0, 3) == "BEE") { + if (chname.substr(4, 1) == "A") { + totalTrackChi2BEEA += trackChi2; + nTracksBEEA++; + } else { + totalTrackChi2BEEC += trackChi2; + nTracksBEEC++; + } + break; + } else if (chname.substr(0, 3) == "EEL") { + if (chname.substr(4, 1) == "A") { + totalTrackChi2EELA += trackChi2; + nTracksEELA++; + } else { + totalTrackChi2EELC += trackChi2; + nTracksEELC++; + } + break; + } else if (chname.substr(0, 4) == "BIS8") { + if (chname.substr(4, 1) == "A") { + totalTrackChi2BIS8A += trackChi2; + nTracksBIS8A++; + } else { + totalTrackChi2BIS8C += trackChi2; + nTracksBIS8C++; + } + break; + } else if (chname.substr(0, 3) == "ECA") { + totalTrackChi2ECA += trackChi2; + nTracksECA++; + break; + } else if (chname.substr(0, 3) == "ECC") { + totalTrackChi2ECC += trackChi2; + nTracksECC++; + break; + } else if (chname.substr(0, 3) == "BAR") { + totalTrackChi2BAR += trackChi2; + nTracksBAR++; + break; + } + } - nTracks++; + nTracks++; - // add derivatives - addDerivatives(); + // add derivatives + addDerivatives(); - // fill tree - fillTree(); + // fill tree + fillTree(); + } - } + cout << "---------------------------------------------" << endl; + cout << "- number tracks : " << nTracks << endl; + cout << "- track chi2/NDoF : " << totalTrackChi2 / (double)nTracks << endl; - cout<<"---------------------------------------------"<<endl; - cout<<"- number tracks : "<<nTracks<<endl; - cout<<"- track chi2/NDoF : "<<totalTrackChi2/(double)nTracks<<endl; - - if (!L1ALIGNMENT) { - cout<<"- BEEA # tracks / track chi2/NDoF : "<<nTracksBEEA<<"/"<<totalTrackChi2BEEA/(double)nTracksBEEA<<endl; - cout<<"- BEEC # tracks / track chi2/NDoF : "<<nTracksBEEC<<"/"<<totalTrackChi2BEEC/(double)nTracksBEEC<<endl; - cout<<"- EELA # tracks / track chi2/NDoF : "<<nTracksEELA<<"/"<<totalTrackChi2EELA/(double)nTracksEELA<<endl; - cout<<"- EELC # tracks / track chi2/NDoF : "<<nTracksEELC<<"/"<<totalTrackChi2EELC/(double)nTracksEELC<<endl; - cout<<"- BIS8A # tracks / track chi2/NDoF : "<<nTracksBIS8A<<"/"<<totalTrackChi2BIS8A/(double)nTracksBIS8A<<endl; - cout<<"- BIS8C # tracks / track chi2/NDoF : "<<nTracksBIS8C<<"/"<<totalTrackChi2BIS8C/(double)nTracksBIS8C<<endl; - } - else { - cout<<"- ECA # tracks / track chi2/NDoF : "<<nTracksECA<<"/"<<totalTrackChi2ECA/(double)nTracksECA<<endl; - cout<<"- ECC # tracks / track chi2/NDoF : "<<nTracksECC<<"/"<<totalTrackChi2ECC/(double)nTracksECC<<endl; - cout<<"- BAR # tracks / track chi2/NDoF : "<<nTracksBAR<<"/"<<totalTrackChi2BAR/(double)nTracksBAR<<endl; + if (!L1ALIGNMENT) { + cout << "- BEEA # tracks / track chi2/NDoF : " << nTracksBEEA << "/" << totalTrackChi2BEEA / (double)nTracksBEEA + << endl; + cout << "- BEEC # tracks / track chi2/NDoF : " << nTracksBEEC << "/" << totalTrackChi2BEEC / (double)nTracksBEEC + << endl; + cout << "- EELA # tracks / track chi2/NDoF : " << nTracksEELA << "/" << totalTrackChi2EELA / (double)nTracksEELA + << endl; + cout << "- EELC # tracks / track chi2/NDoF : " << nTracksEELC << "/" << totalTrackChi2EELC / (double)nTracksEELC + << endl; + cout << "- BIS8A # tracks / track chi2/NDoF : " << nTracksBIS8A << "/" << totalTrackChi2BIS8A / (double)nTracksBIS8A + << endl; + cout << "- BIS8C # tracks / track chi2/NDoF : " << nTracksBIS8C << "/" << totalTrackChi2BIS8C / (double)nTracksBIS8C + << endl; + } else { + cout << "- ECA # tracks / track chi2/NDoF : " << nTracksECA << "/" << totalTrackChi2ECA / (double)nTracksECA << endl; + cout << "- ECC # tracks / track chi2/NDoF : " << nTracksECC << "/" << totalTrackChi2ECC / (double)nTracksECC << endl; + cout << "- BAR # tracks / track chi2/NDoF : " << nTracksBAR << "/" << totalTrackChi2BAR / (double)nTracksBAR << endl; + } + cout << "---------------------------------------------" << endl; - } - cout<<"---------------------------------------------"<<endl; - - //cout<<"printing"<<endl; - //m_allChDerivs->PrintChambers(); - //m_allChDerivs->PrintFirstDerivs(); - //m_allChDerivs->PrintSecondDerivs(); - - cout<<"printing info for all chambers"<<endl; - for (int ich=0;ich<m_allChDerivs->nchambers();ich++) { - - if (m_allChDerivs->chamberId(ich)<0) continue; - - string chname=m_chNames->chamberName(m_allChDerivs->chamberId(ich)); - cout<<"ich: "<<ich<<", (CLHEP) ch: "<<m_allChDerivs->chamberId(ich) - <<", ntracks: "<<m_allChDerivs->nhits(ich,ich) - <<" ("<<chname<<")"<<endl; - } + // cout<<"printing"<<endl; + // m_allChDerivs->PrintChambers(); + // m_allChDerivs->PrintFirstDerivs(); + // m_allChDerivs->PrintSecondDerivs(); + + cout << "printing info for all chambers" << endl; + for (int ich = 0; ich < m_allChDerivs->nchambers(); ich++) { + if (m_allChDerivs->chamberId(ich) < 0) continue; - //if (CONSTRAIN_LOWESTEV) m_allChDerivs->constrainLowestEigenvector(m_chamberIdMap); - - // add 300 to all diagonal terms - if (DO_SOFT_CONSTRAINT) addSoftConstraints(m_allChDerivs); + string chname = m_chNames->chamberName(m_allChDerivs->chamberId(ich)); + cout << "ich: " << ich << ", (CLHEP) ch: " << m_allChDerivs->chamberId(ich) << ", ntracks: " << m_allChDerivs->nhits(ich, ich) + << " (" << chname << ")" << endl; + } + // if (CONSTRAIN_LOWESTEV) m_allChDerivs->constrainLowestEigenvector(m_chamberIdMap); - // add constraints - addConstraints(m_allChDerivs); + // add 300 to all diagonal terms + if (DO_SOFT_CONSTRAINT) addSoftConstraints(m_allChDerivs); + // add constraints + addConstraints(m_allChDerivs); - /* - // get condition numbers for various cuts - for (int i=0;i<5;i++) { - double idiagcut=2000.+2000.*(double)i; - //for (int j=0;j<5;j++) { - //double joffdiagcut=1000.*(double)j; - ChamberDerivs tmpChDerivs= - m_allChDerivs->trimmedChamberDerivs(idiagcut,400); - double tmpcond=tmpChDerivs.condition(-1); - cout<<"diag/offdiag/cond: "<<idiagcut<<"/4000/"<<tmpcond<<endl; - //} - } - */ - - // get plots for different diagonal cuts - /* - plotDiagonalCutHists(); - plotDiagonalCutHists(true); - */ - - // trim ChamberDerivs - //cout<<"getting trimmed ChamberDerivs"<<endl; - ChamberDerivs trimmedChDerivs=m_allChDerivs->trimmedChamberDerivs(diagcut,offdiagcut); - cout<<"printing trimmed chamber"<<endl; - trimmedChDerivs.PrintChambers(); - trimmedChDerivs.PrintFirstDerivs(); - trimmedChDerivs.PrintSecondDerivs(); - - cout<<"printing info for trimmed chambers"<<endl; - for (int ich=0;ich<trimmedChDerivs.nchambers();ich++) { - if (trimmedChDerivs.chamberId(ich)<0) continue; - string chname=m_chNames->chamberName(trimmedChDerivs.chamberId(ich)); - cout<<"(CLHEP) ch: "<<trimmedChDerivs.chamberId(ich) - <<", ntracks: "<<trimmedChDerivs.nhits(ich,ich) - <<" ("<<chname<<")"<<endl; - } + /* + // get condition numbers for various cuts + for (int i=0;i<5;i++) { + double idiagcut=2000.+2000.*(double)i; + //for (int j=0;j<5;j++) { + //double joffdiagcut=1000.*(double)j; + ChamberDerivs tmpChDerivs= + m_allChDerivs->trimmedChamberDerivs(idiagcut,400); + double tmpcond=tmpChDerivs.condition(-1); + cout<<"diag/offdiag/cond: "<<idiagcut<<"/4000/"<<tmpcond<<endl; + //} + } + */ - cout<<"======================================================="<<endl; - cout<<" external constraints"<<endl; - cout<<"======================================================="<<endl; + // get plots for different diagonal cuts + /* + plotDiagonalCutHists(); + plotDiagonalCutHists(true); + */ - // external constraints - string asztFileNameLastIter=""; - if (iteration>0) { - stringstream ss; ss<<"outputAszt_iter"<<iteration-1<<".txt"; - asztFileNameLastIter=ss.str(); - } - cout<<"asztFileNameLastIter: "<<asztFileNameLastIter<<endl; - - addExternalConstraints(&trimmedChDerivs,asztFileNameLastIter); - - - TH2F* h_tVSV0 =new TH2F("h_tVSV0","align_trat vs. log10(min singular value)", - 100,1.,2.5,50,-20.,20.); - vector<double> svArray; - for (int ich=0;ich<trimmedChDerivs.nchambers();ich++) { - cout<<"ch: "<<m_chNames->chamberName(trimmedChDerivs.chamberId(ich))<<endl; - vector<double> sv; const TMatrixD *u,*vinv; - trimmedChDerivs.singularValues(sv,u,vinv,ich); - delete u; delete vinv; - double minval(1.e10); - for (int i=0;i<(int)sv.size();i++) { - if (sv[i]<minval) minval=sv[i]; - cout<<"sv["<<i<<"]="<<sv[i]<<endl; + // trim ChamberDerivs + // cout<<"getting trimmed ChamberDerivs"<<endl; + ChamberDerivs trimmedChDerivs = m_allChDerivs->trimmedChamberDerivs(diagcut, offdiagcut); + cout << "printing trimmed chamber" << endl; + trimmedChDerivs.PrintChambers(); + trimmedChDerivs.PrintFirstDerivs(); + trimmedChDerivs.PrintSecondDerivs(); + + cout << "printing info for trimmed chambers" << endl; + for (int ich = 0; ich < trimmedChDerivs.nchambers(); ich++) { + if (trimmedChDerivs.chamberId(ich) < 0) continue; + string chname = m_chNames->chamberName(trimmedChDerivs.chamberId(ich)); + cout << "(CLHEP) ch: " << trimmedChDerivs.chamberId(ich) << ", ntracks: " << trimmedChDerivs.nhits(ich, ich) << " (" << chname + << ")" << endl; } - svArray.push_back(minval); - } - // solve for global parameters/write to file - string dummy; - std::ofstream asztFile; - stringstream asztFileName; asztFileName<<"outputAszt_iter"<<iteration; - asztFile.open((asztFileName.str()+".txt").c_str()); - if (L1ALIGNMENT) - asztFile<<"/Muon/Align/L1\n"; - else - asztFile<<"/Muon/Align/L3\n"; - - std::ofstream asztFileDelta; - asztFileDelta.open((asztFileName.str()+"_delta.txt").c_str()); - asztFileDelta<<"/Muon/Align/L3\n"; - - string origType; - int origJff,origJzz,origJob; - - std::ifstream asztFileLastIter; - if (iteration>0) { - cout<<"opening "<<asztFileNameLastIter<<endl; - asztFileLastIter.open(asztFileNameLastIter.c_str()); - asztFileLastIter>>dummy; - } + cout << "=======================================================" << endl; + cout << " external constraints" << endl; + cout << "=======================================================" << endl; - cout<<"-----------------------------------------------"<<endl; - cout<<"Solving for global parameters"<<endl; - double* err(0); - double* initPars =new double[6]; - double* finalPars=new double[6]; - double* deltas=trimmedChDerivs.solve(err,-1,ChamberDerivs::ROOT); - for (int i=0;i<trimmedChDerivs.nindices();i++) { - int ipar=i%NPAR; - if (!L1ALIGNMENT) { - if (ipar>=NPAR-6+3) { - } + // external constraints + string asztFileNameLastIter = ""; + if (iteration > 0) { + stringstream ss; + ss << "outputAszt_iter" << iteration - 1 << ".txt"; + asztFileNameLastIter = ss.str(); } - else { - cout<<"deltas["<<i<<"]="<<deltas[i]<<"(before)"; - deltas[i]*=m_rotscale; - cout<<", "<<deltas[i]<<"(after)"<<endl; - } - } - for (int ich=0;ich<trimmedChDerivs.nchambers();ich++) { - - string chname=m_chNames->chamberName(trimmedChDerivs.chamberId(ich)); - cout<<"(CLHEP) ch: "<<trimmedChDerivs.chamberId(ich) - <<", ntracks: "<<trimmedChDerivs.nhits(ich,ich) - <<" ("<<chname<<")"<<endl; - - int jzz=atoi(chname.substr(3,1).c_str()); - if (chname.substr(4,1)=="C") jzz*=-1; - int detphi=atoi(chname.substr(5,2).c_str()); - if (chname.substr(2,1)=="L") detphi++; - int jff=detphi/2; - - if (L1ALIGNMENT) { - if (chname.substr(0,3)=="ECA") { jff=jzz=0; } - else if (chname.substr(0,3)=="ECC") {jff=jzz=1; } - else if (chname.substr(0,3)=="Bar") {jff=jzz=2; } + cout << "asztFileNameLastIter: " << asztFileNameLastIter << endl; + + addExternalConstraints(&trimmedChDerivs, asztFileNameLastIter); + + TH2F* h_tVSV0 = new TH2F("h_tVSV0", "align_trat vs. log10(min singular value)", 100, 1., 2.5, 50, -20., 20.); + vector<double> svArray; + for (int ich = 0; ich < trimmedChDerivs.nchambers(); ich++) { + cout << "ch: " << m_chNames->chamberName(trimmedChDerivs.chamberId(ich)) << endl; + vector<double> sv; + const TMatrixD *u, *vinv; + trimmedChDerivs.singularValues(sv, u, vinv, ich); + delete u; + delete vinv; + double minval(1.e10); + for (int i = 0; i < (int)sv.size(); i++) { + if (sv[i] < minval) minval = sv[i]; + cout << "sv[" << i << "]=" << sv[i] << endl; + } + svArray.push_back(minval); } - // get original values - if (iteration>0) { - asztFileLastIter>>dummy>>origType>>origJff>>origJzz>>origJob; - for (int i=0;i<6;i++) { - double val; - asztFileLastIter>>val; - if (NPAR<6 && i==0) continue; - int ipar=(NPAR==6)?i:i-1; - initPars[ipar]=val; - } - - if (!L1ALIGNMENT && (origType!=chname.substr(0,3) || - jff!=origJff || jzz!=origJzz)) { - cout<<"origType: "<<origType<<", chname: "<<chname<<endl; - cout<<"origJff: "<<origJff<<", jff: "<<jff<<endl; - cout<<"origJzz: "<<origJzz<<", jzz: "<<jzz<<endl; - cout<<"bad entry"<<endl; continue; } + // solve for global parameters/write to file + string dummy; + std::ofstream asztFile; + stringstream asztFileName; + asztFileName << "outputAszt_iter" << iteration; + asztFile.open((asztFileName.str() + ".txt").c_str()); + if (L1ALIGNMENT) + asztFile << "/Muon/Align/L1\n"; + else + asztFile << "/Muon/Align/L3\n"; + + std::ofstream asztFileDelta; + asztFileDelta.open((asztFileName.str() + "_delta.txt").c_str()); + asztFileDelta << "/Muon/Align/L3\n"; + + string origType; + int origJff, origJzz, origJob; + + std::ifstream asztFileLastIter; + if (iteration > 0) { + cout << "opening " << asztFileNameLastIter << endl; + asztFileLastIter.open(asztFileNameLastIter.c_str()); + asztFileLastIter >> dummy; } - else for (int i=0;i<6;i++) initPars[i]=0.; - - // write deltas to file - asztFileDelta<<"A "<<chname.substr(0,3)<<" "<<jff<<" "<<jzz<<" 0 "; - if (!L1ALIGNMENT) asztFileDelta<<"0.0 "; - for (int ipar=0;ipar<NPAR;ipar++) { - int i=ich*NPAR+ipar; - //cout<<" "<<i<<": "<<deltas[i]<<" +/- "<<err[i]<<endl; - asztFileDelta<<deltas[i]<<" "; + + cout << "-----------------------------------------------" << endl; + cout << "Solving for global parameters" << endl; + double* err(0); + double* initPars = new double[6]; + double* finalPars = new double[6]; + double* deltas = trimmedChDerivs.solve(err, -1, ChamberDerivs::ROOT); + for (int i = 0; i < trimmedChDerivs.nindices(); i++) { + int ipar = i % NPAR; + if (!L1ALIGNMENT) { + if (ipar >= NPAR - 6 + 3) {} + } else { + cout << "deltas[" << i << "]=" << deltas[i] << "(before)"; + deltas[i] *= m_rotscale; + cout << ", " << deltas[i] << "(after)" << endl; + } } - cout<<endl; - asztFileDelta<<"\n"; - - // get final values - getFinalPars(initPars,&deltas[ich*NPAR],finalPars); - asztFile<<"A "<<chname.substr(0,3)<<" "<<jff<<" "<<jzz<<" 0 "; - if (!L1ALIGNMENT) asztFile<<"0.0 "; - for (int ipar=0;ipar<NPAR;ipar++) { - int i=ich*NPAR+ipar; - int thisipar=(L1ALIGNMENT)?ipar:ipar+1; - cout<<" "<<i<<": "<<finalPars[thisipar]<<" +/- "<<err[i]<<endl; - asztFile<<finalPars[thisipar]<<" "; + for (int ich = 0; ich < trimmedChDerivs.nchambers(); ich++) { + string chname = m_chNames->chamberName(trimmedChDerivs.chamberId(ich)); + cout << "(CLHEP) ch: " << trimmedChDerivs.chamberId(ich) << ", ntracks: " << trimmedChDerivs.nhits(ich, ich) << " (" << chname + << ")" << endl; + + int jzz = atoi(chname.substr(3, 1).c_str()); + if (chname.substr(4, 1) == "C") jzz *= -1; + int detphi = atoi(chname.substr(5, 2).c_str()); + if (chname.substr(2, 1) == "L") detphi++; + int jff = detphi / 2; + + if (L1ALIGNMENT) { + if (chname.substr(0, 3) == "ECA") { + jff = jzz = 0; + } else if (chname.substr(0, 3) == "ECC") { + jff = jzz = 1; + } else if (chname.substr(0, 3) == "Bar") { + jff = jzz = 2; + } + } + + // get original values + if (iteration > 0) { + asztFileLastIter >> dummy >> origType >> origJff >> origJzz >> origJob; + for (int i = 0; i < 6; i++) { + double val; + asztFileLastIter >> val; + if (NPAR < 6 && i == 0) continue; + int ipar = (NPAR == 6) ? i : i - 1; + initPars[ipar] = val; + } + + if (!L1ALIGNMENT && (origType != chname.substr(0, 3) || jff != origJff || jzz != origJzz)) { + cout << "origType: " << origType << ", chname: " << chname << endl; + cout << "origJff: " << origJff << ", jff: " << jff << endl; + cout << "origJzz: " << origJzz << ", jzz: " << jzz << endl; + cout << "bad entry" << endl; + continue; + } + } else + for (int i = 0; i < 6; i++) initPars[i] = 0.; + + // write deltas to file + asztFileDelta << "A " << chname.substr(0, 3) << " " << jff << " " << jzz << " 0 "; + if (!L1ALIGNMENT) asztFileDelta << "0.0 "; + for (int ipar = 0; ipar < NPAR; ipar++) { + int i = ich * NPAR + ipar; + // cout<<" "<<i<<": "<<deltas[i]<<" +/- "<<err[i]<<endl; + asztFileDelta << deltas[i] << " "; + } + cout << endl; + asztFileDelta << "\n"; + + // get final values + getFinalPars(initPars, &deltas[ich * NPAR], finalPars); + asztFile << "A " << chname.substr(0, 3) << " " << jff << " " << jzz << " 0 "; + if (!L1ALIGNMENT) asztFile << "0.0 "; + for (int ipar = 0; ipar < NPAR; ipar++) { + int i = ich * NPAR + ipar; + int thisipar = (L1ALIGNMENT) ? ipar : ipar + 1; + cout << " " << i << ": " << finalPars[thisipar] << " +/- " << err[i] << endl; + asztFile << finalPars[thisipar] << " "; + } + cout << endl; + asztFile << "\n"; + + // fill histogram with determinant for local 2nd deriv matrix + // if (chname[4]=='A' || !DO_EC_ONLY) { + int ipar = ich * NPAR + NPAR - 6 + 2; // z-parameter + h_tVSV0->Fill(log10(svArray[ich]), deltas[ipar]); + //} } - cout<<endl; - asztFile<<"\n"; - - // fill histogram with determinant for local 2nd deriv matrix - //if (chname[4]=='A' || !DO_EC_ONLY) { - int ipar=ich*NPAR+NPAR-6+2; // z-parameter - h_tVSV0->Fill(log10(svArray[ich]),deltas[ipar]); - //} - } - asztFile.close(); - asztFileDelta.close(); - asztFileLastIter.close(); - - delete [] deltas; - delete [] initPars; - delete [] finalPars; - - TCanvas* c2=new TCanvas("c2","c2"); - h_tVSV0->Draw("colz"); - c2->Print("c2.eps"); - - if (EIGENVALUE_CUT) { - ChamberDerivs newTrimmedChDerivs= - trimmedChDerivs.trimmedChamberDerivsBySV(80.); - cout<<"printing newly trimmed chamber"<<endl; - newTrimmedChDerivs.PrintChambers(); - makeSomePlots(newTrimmedChDerivs); - } - else - makeSomePlots(trimmedChDerivs); - - // solve for local parameters - cout<<"-----------------------------------------------"<<endl; - cout<<"Solving for local parameters"<<endl; - for (int ich=0;ich<trimmedChDerivs.nchambers();ich++) { - trimmedChDerivs.PrintSecondDerivs(ich); - - double* locerr(0); - double* locres=trimmedChDerivs.solve(locerr,ich,ChamberDerivs::CLHEP); - cout<<"(CLHEP) ch: "<<trimmedChDerivs.chamberId(ich) - <<", ntracks: "<<trimmedChDerivs.nhits(ich,ich) - <<" ("<<m_chNames->chamberName(trimmedChDerivs.chamberId(ich))<<")"<<endl; - for (int ipar=0;ipar<NPAR;ipar++) { - cout<<" (loc) "<<ipar<<": "<<locres[ipar]<<" +/- "<<locerr[ipar]<<endl; + asztFile.close(); + asztFileDelta.close(); + asztFileLastIter.close(); + + delete[] deltas; + delete[] initPars; + delete[] finalPars; + + TCanvas* c2 = new TCanvas("c2", "c2"); + h_tVSV0->Draw("colz"); + c2->Print("c2.eps"); + + if (EIGENVALUE_CUT) { + ChamberDerivs newTrimmedChDerivs = trimmedChDerivs.trimmedChamberDerivsBySV(80.); + cout << "printing newly trimmed chamber" << endl; + newTrimmedChDerivs.PrintChambers(); + makeSomePlots(newTrimmedChDerivs); + } else + makeSomePlots(trimmedChDerivs); + + // solve for local parameters + cout << "-----------------------------------------------" << endl; + cout << "Solving for local parameters" << endl; + for (int ich = 0; ich < trimmedChDerivs.nchambers(); ich++) { + trimmedChDerivs.PrintSecondDerivs(ich); + + double* locerr(0); + double* locres = trimmedChDerivs.solve(locerr, ich, ChamberDerivs::CLHEP); + cout << "(CLHEP) ch: " << trimmedChDerivs.chamberId(ich) << ", ntracks: " << trimmedChDerivs.nhits(ich, ich) << " (" + << m_chNames->chamberName(trimmedChDerivs.chamberId(ich)) << ")" << endl; + for (int ipar = 0; ipar < NPAR; ipar++) { cout << " (loc) " << ipar << ": " << locres[ipar] << " +/- " << locerr[ipar] << endl; } + delete[] locerr; + delete[] locres; } - delete [] locerr; delete [] locres; - } - - - m_outputFile->cd(); - m_outputTree->Write(); + + m_outputFile->cd(); + m_outputTree->Write(); } //________________________________________________________________________ -void initSDTree() -{ - m_sdTree->ResetBranchAddresses(); - - m_sdTree->SetBranchStatus("*",0); - - m_sdTree->SetBranchStatus("run", 1); - m_sdTree->SetBranchStatus("event", 1); - m_sdTree->SetBranchStatus("momentum", 1); - m_sdTree->SetBranchStatus("nChambers", 1); - m_sdTree->SetBranchStatus("chamberIds", 1); - m_sdTree->SetBranchStatus("nMatrixIndices",1); - m_sdTree->SetBranchStatus("matrixIndices", 1); - //m_sdTree->SetBranchStatus("newSecndDeriv", 1); - m_sdTree->SetBranchStatus("secndDeriv", 1); - m_sdTree->SetBranchStatus("firstDeriv", 1); - - m_sdTree->SetBranchAddress("run", &m_sd_run, &m_sd_brRun); - m_sdTree->SetBranchAddress("event", &m_sd_evt, &m_sd_brEvt); - m_sdTree->SetBranchAddress("momentum", &m_sd_momentum); - m_sdTree->SetBranchAddress("nChambers", &m_sd_nChambers, &m_sd_brNChambers); - m_sdTree->SetBranchAddress("chamberIds", m_sd_chamberIds, &m_sd_brChambers); - m_sdTree->SetBranchAddress("nMatrixIndices", &m_sd_nMatrixIndices); - m_sdTree->SetBranchAddress("matrixIndices", m_sd_matrixIndices); - //m_sdTree->SetBranchAddress("newSecndDeriv", m_sd_secndDeriv); - m_sdTree->SetBranchAddress("secndDeriv", m_sd_secndDeriv); - m_sdTree->SetBranchAddress("firstDeriv", m_sd_firstDeriv); +void initSDTree() { + m_sdTree->ResetBranchAddresses(); + + m_sdTree->SetBranchStatus("*", 0); + + m_sdTree->SetBranchStatus("run", 1); + m_sdTree->SetBranchStatus("event", 1); + m_sdTree->SetBranchStatus("momentum", 1); + m_sdTree->SetBranchStatus("nChambers", 1); + m_sdTree->SetBranchStatus("chamberIds", 1); + m_sdTree->SetBranchStatus("nMatrixIndices", 1); + m_sdTree->SetBranchStatus("matrixIndices", 1); + // m_sdTree->SetBranchStatus("newSecndDeriv", 1); + m_sdTree->SetBranchStatus("secndDeriv", 1); + m_sdTree->SetBranchStatus("firstDeriv", 1); + + m_sdTree->SetBranchAddress("run", &m_sd_run, &m_sd_brRun); + m_sdTree->SetBranchAddress("event", &m_sd_evt, &m_sd_brEvt); + m_sdTree->SetBranchAddress("momentum", &m_sd_momentum); + m_sdTree->SetBranchAddress("nChambers", &m_sd_nChambers, &m_sd_brNChambers); + m_sdTree->SetBranchAddress("chamberIds", m_sd_chamberIds, &m_sd_brChambers); + m_sdTree->SetBranchAddress("nMatrixIndices", &m_sd_nMatrixIndices); + m_sdTree->SetBranchAddress("matrixIndices", m_sd_matrixIndices); + // m_sdTree->SetBranchAddress("newSecndDeriv", m_sd_secndDeriv); + m_sdTree->SetBranchAddress("secndDeriv", m_sd_secndDeriv); + m_sdTree->SetBranchAddress("firstDeriv", m_sd_firstDeriv); } //________________________________________________________________________ -void initMTPPTree() -{ +void initMTPPTree() { + m_mtppTree->SetBranchStatus("*", 0); + + m_mtppTree->SetBranchStatus("run", 1); + m_mtppTree->SetBranchStatus("evt", 1); + m_mtppTree->SetBranchStatus("trackChi2", 1); + m_mtppTree->SetBranchStatus("trackPt", 1); + + m_mtppTree->SetBranchStatus("nresiduals", 1); + m_mtppTree->SetBranchStatus("residuals", 1); + m_mtppTree->SetBranchStatus("nInnerLayersHit", 1); + m_mtppTree->SetBranchStatus("nMiddleLayersHit", 1); + m_mtppTree->SetBranchStatus("nOuterLayersHit", 1); + /* + m_mtppTree->SetBranchStatus("nChambersHit", 1); + m_mtppTree->SetBranchStatus("nLargeChambersHit", 1); + m_mtppTree->SetBranchStatus("nSmallChambersHit", 1); + m_mtppTree->SetBranchStatus("nTubeLayersHitInner", 1); + m_mtppTree->SetBranchStatus("nTubeLayersHitMiddle", 1); + m_mtppTree->SetBranchStatus("nTubeLayersHitOuter", 1); + m_mtppTree->SetBranchStatus("DriftSignsInnerLayer", 1); + m_mtppTree->SetBranchStatus("DriftSignsMiddleLayer", 1); + m_mtppTree->SetBranchStatus("DriftSignsOuterLayer", 1); + //m_mtppTree->SetBranchStatus("trackEta", 1); + m_mtppTree->SetBranchStatus("nInnerLayerOutliers", 1); + m_mtppTree->SetBranchStatus("nMiddleLayerOutliers", 1); + m_mtppTree->SetBranchStatus("nOuterLayerOutliers", 1); + m_mtppTree->SetBranchStatus("nInnerLayerHoles", 1); + m_mtppTree->SetBranchStatus("nMiddleLayerHoles", 1); + m_mtppTree->SetBranchStatus("nOuterLayerHoles", 1); + */ - m_mtppTree->SetBranchStatus("*", 0); - - m_mtppTree->SetBranchStatus("run", 1); - m_mtppTree->SetBranchStatus("evt", 1); - m_mtppTree->SetBranchStatus("trackChi2", 1); - m_mtppTree->SetBranchStatus("trackPt", 1); - - m_mtppTree->SetBranchStatus("nresiduals", 1); - m_mtppTree->SetBranchStatus("residuals", 1); - m_mtppTree->SetBranchStatus("nInnerLayersHit", 1); - m_mtppTree->SetBranchStatus("nMiddleLayersHit", 1); - m_mtppTree->SetBranchStatus("nOuterLayersHit", 1); - /* - m_mtppTree->SetBranchStatus("nChambersHit", 1); - m_mtppTree->SetBranchStatus("nLargeChambersHit", 1); - m_mtppTree->SetBranchStatus("nSmallChambersHit", 1); - m_mtppTree->SetBranchStatus("nTubeLayersHitInner", 1); - m_mtppTree->SetBranchStatus("nTubeLayersHitMiddle", 1); - m_mtppTree->SetBranchStatus("nTubeLayersHitOuter", 1); - m_mtppTree->SetBranchStatus("DriftSignsInnerLayer", 1); - m_mtppTree->SetBranchStatus("DriftSignsMiddleLayer", 1); - m_mtppTree->SetBranchStatus("DriftSignsOuterLayer", 1); - //m_mtppTree->SetBranchStatus("trackEta", 1); - m_mtppTree->SetBranchStatus("nInnerLayerOutliers", 1); - m_mtppTree->SetBranchStatus("nMiddleLayerOutliers", 1); - m_mtppTree->SetBranchStatus("nOuterLayerOutliers", 1); - m_mtppTree->SetBranchStatus("nInnerLayerHoles", 1); - m_mtppTree->SetBranchStatus("nMiddleLayerHoles", 1); - m_mtppTree->SetBranchStatus("nOuterLayerHoles", 1); - */ - - m_mtppTree->SetBranchAddress("run", &m_mtpp_run, &m_mtpp_brRun); - m_mtppTree->SetBranchAddress("evt", &m_mtpp_evt, &m_mtpp_brEvt); - m_mtppTree->SetBranchAddress("trackChi2", &trackChi2); - m_mtppTree->SetBranchAddress("trackPt", &trackPt); - - m_mtppTree->SetBranchAddress("nresiduals", &nresiduals); - m_mtppTree->SetBranchAddress("residuals", residuals); - m_mtppTree->SetBranchAddress("nInnerLayersHit", &nInnerLayersHit); - m_mtppTree->SetBranchAddress("nMiddleLayersHit", &nMiddleLayersHit); - m_mtppTree->SetBranchAddress("nOuterLayersHit", &nOuterLayersHit); - - /* - m_mtppTree->SetBranchAddress("nChambersHit", &nChambersHit); - m_mtppTree->SetBranchAddress("nLargeChambersHit", &nLargeChambersHit); - m_mtppTree->SetBranchAddress("nSmallChambersHit", &nSmallChambersHit); - m_mtppTree->SetBranchAddress("nTubeLayersHitInner", &nTubeLayersHitInner); - m_mtppTree->SetBranchAddress("nTubeLayersHitMiddle", &nTubeLayersHitMiddle); - m_mtppTree->SetBranchAddress("nTubeLayersHitOuter", &nTubeLayersHitOuter); - m_mtppTree->SetBranchAddress("DriftSignsInnerLayer", &nInnerLayerDriftSigns); - m_mtppTree->SetBranchAddress("DriftSignsMiddleLayer", &nMiddleLayerDriftSigns); - m_mtppTree->SetBranchAddress("DriftSignsOuterLayer", &nOuterLayerDriftSigns); - */ - - /* - //m_mtppTree->SetBranchAddress("trackEta", &trackEta); - m_mtppTree->SetBranchAddress("nInnerLayerOutliers", &nInnerLayerOutliers); - m_mtppTree->SetBranchAddress("nMiddleLayerOutliers", &nMiddleLayerOutliers); - m_mtppTree->SetBranchAddress("nOuterLayerOutliers", &nOuterLayerOutliers); - m_mtppTree->SetBranchAddress("nInnerLayerHoles", &nInnerLayerHoles); - m_mtppTree->SetBranchAddress("nMiddleLayerHoles", &nMiddleLayerHoles); - m_mtppTree->SetBranchAddress("nOuterLayerHoles", &nOuterLayerHoles); - */ - return; + m_mtppTree->SetBranchAddress("run", &m_mtpp_run, &m_mtpp_brRun); + m_mtppTree->SetBranchAddress("evt", &m_mtpp_evt, &m_mtpp_brEvt); + m_mtppTree->SetBranchAddress("trackChi2", &trackChi2); + m_mtppTree->SetBranchAddress("trackPt", &trackPt); + + m_mtppTree->SetBranchAddress("nresiduals", &nresiduals); + m_mtppTree->SetBranchAddress("residuals", residuals); + m_mtppTree->SetBranchAddress("nInnerLayersHit", &nInnerLayersHit); + m_mtppTree->SetBranchAddress("nMiddleLayersHit", &nMiddleLayersHit); + m_mtppTree->SetBranchAddress("nOuterLayersHit", &nOuterLayersHit); + + /* + m_mtppTree->SetBranchAddress("nChambersHit", &nChambersHit); + m_mtppTree->SetBranchAddress("nLargeChambersHit", &nLargeChambersHit); + m_mtppTree->SetBranchAddress("nSmallChambersHit", &nSmallChambersHit); + m_mtppTree->SetBranchAddress("nTubeLayersHitInner", &nTubeLayersHitInner); + m_mtppTree->SetBranchAddress("nTubeLayersHitMiddle", &nTubeLayersHitMiddle); + m_mtppTree->SetBranchAddress("nTubeLayersHitOuter", &nTubeLayersHitOuter); + m_mtppTree->SetBranchAddress("DriftSignsInnerLayer", &nInnerLayerDriftSigns); + m_mtppTree->SetBranchAddress("DriftSignsMiddleLayer", &nMiddleLayerDriftSigns); + m_mtppTree->SetBranchAddress("DriftSignsOuterLayer", &nOuterLayerDriftSigns); + */ + + /* + //m_mtppTree->SetBranchAddress("trackEta", &trackEta); + m_mtppTree->SetBranchAddress("nInnerLayerOutliers", &nInnerLayerOutliers); + m_mtppTree->SetBranchAddress("nMiddleLayerOutliers", &nMiddleLayerOutliers); + m_mtppTree->SetBranchAddress("nOuterLayerOutliers", &nOuterLayerOutliers); + m_mtppTree->SetBranchAddress("nInnerLayerHoles", &nInnerLayerHoles); + m_mtppTree->SetBranchAddress("nMiddleLayerHoles", &nMiddleLayerHoles); + m_mtppTree->SetBranchAddress("nOuterLayerHoles", &nOuterLayerHoles); + */ + return; } //________________________________________________________________________ -bool getSDTreeEntry(int ientry, int chid) -{ - //cout<<"loading ientry "<<ientry<<endl; - - m_sdTree->LoadTree(ientry); - - int treenum = m_sdTree->GetTreeNumber(); - int treeentry = ientry-m_sdTree->GetTreeOffset()[treenum]; - - m_sd_brRun ->GetEntry(treeentry); - m_sd_brEvt ->GetEntry(treeentry); - m_sd_brNChambers->GetEntry(treeentry); - m_sd_brChambers ->GetEntry(treeentry); - - //cout<<"chid: "<<chid<<endl; - bool goodchamber=(chid==-1); - if (!goodchamber) { - for (int ich=0;ich<m_sd_nChambers;ich++) { - //cout<<"m_sd_chamberIds["<<ich<<"]="<<m_sd_chamberIds[ich]<<endl; - if (m_sd_chamberIds[ich]==chid) { - goodchamber=true; break; - } +bool getSDTreeEntry(int ientry, int chid) { + // cout<<"loading ientry "<<ientry<<endl; + + m_sdTree->LoadTree(ientry); + + int treenum = m_sdTree->GetTreeNumber(); + int treeentry = ientry - m_sdTree->GetTreeOffset()[treenum]; + + m_sd_brRun->GetEntry(treeentry); + m_sd_brEvt->GetEntry(treeentry); + m_sd_brNChambers->GetEntry(treeentry); + m_sd_brChambers->GetEntry(treeentry); + + // cout<<"chid: "<<chid<<endl; + bool goodchamber = (chid == -1); + if (!goodchamber) { + for (int ich = 0; ich < m_sd_nChambers; ich++) { + // cout<<"m_sd_chamberIds["<<ich<<"]="<<m_sd_chamberIds[ich]<<endl; + if (m_sd_chamberIds[ich] == chid) { + goodchamber = true; + break; + } + } + } + if (!goodchamber) { + cout << "returning false" << endl; + return false; } - } - if (!goodchamber) { - cout<<"returning false"<<endl; - return false; - } - m_sdTree->GetEntry(ientry); - //cout<<"get entry "<<ientry<<endl; + m_sdTree->GetEntry(ientry); + // cout<<"get entry "<<ientry<<endl; - return true; + return true; } //________________________________________________________________________ -bool getMTPPTreeEntry(int& ientryMTPP, int run, int evt,int ntrkSD, int chid) -{ - - int ntrksMTPP=ntrkSD-1; +bool getMTPPTreeEntry(int& ientryMTPP, int run, int evt, int ntrkSD, int chid) { + int ntrksMTPP = ntrkSD - 1; - while (m_mtpp_run!=run || m_mtpp_evt!=evt || ntrksMTPP<ntrkSD) { + while (m_mtpp_run != run || m_mtpp_evt != evt || ntrksMTPP < ntrkSD) { + // cout<<"getting entry "<<ientryMTPP<<endl; + m_mtppTree->LoadTree(ientryMTPP); + int treenum = m_mtppTree->GetTreeNumber(); + int treeentry = ientryMTPP - m_mtppTree->GetTreeOffset()[treenum]; + m_mtpp_brRun->GetEntry(treeentry); + m_mtpp_brEvt->GetEntry(treeentry); - //cout<<"getting entry "<<ientryMTPP<<endl; - m_mtppTree->LoadTree(ientryMTPP); - int treenum=m_mtppTree->GetTreeNumber(); - int treeentry=ientryMTPP-m_mtppTree->GetTreeOffset()[treenum]; - m_mtpp_brRun->GetEntry(treeentry); - m_mtpp_brEvt->GetEntry(treeentry); + if (m_mtpp_run == run && m_mtpp_evt == evt) ntrksMTPP++; - if (m_mtpp_run==run && m_mtpp_evt==evt) ntrksMTPP++; + ++ientryMTPP; + } - ++ientryMTPP; + m_mtppTree->GetEntry(ientryMTPP); + + // get numbers of chambers + m_nInnerChambers = m_nMiddleChambers = m_nOuterChambers = m_nOtherChambers = 0; + if (chid != -1) { + for (int ich = 0; ich < m_sd_nChambers; ich++) { + int tchid = m_sd_chamberIds[ich]; + string nchname = m_chNames->chamberName(tchid); + if (nchname.substr(0, 2) == "EI") + m_nInnerChambers++; + else if (nchname.substr(0, 2) == "EM") + m_nMiddleChambers++; + else if (nchname.substr(0, 2) == "EO") + m_nOuterChambers++; + else + m_nOtherChambers++; + } + } - } + int& nChambers = m_nInnerChambers; + if (chid != -1) { + if (m_chname.substr(1, 1) == "I") + nChambers = m_nInnerChambers; + else if (m_chname.substr(1, 1) == "M") + nChambers = m_nMiddleChambers; + else if (m_chname.substr(1, 1) == "O") + nChambers = m_nOuterChambers; + else + nChambers = m_nOtherChambers; + } - m_mtppTree->GetEntry(ientryMTPP); - - // get numbers of chambers - m_nInnerChambers=m_nMiddleChambers=m_nOuterChambers=m_nOtherChambers=0; - if (chid!=-1) { - for (int ich=0;ich<m_sd_nChambers;ich++) { - int tchid=m_sd_chamberIds[ich]; - string nchname=m_chNames->chamberName(tchid); - if (nchname.substr(0,2)=="EI") m_nInnerChambers++; - else if (nchname.substr(0,2)=="EM") m_nMiddleChambers++; - else if (nchname.substr(0,2)=="EO") m_nOuterChambers++; - else m_nOtherChambers++; + bool goodentry = chid == -1; + if (!goodentry) { + goodentry = (nChambers > CUTNCHAMBERS); + if (CUTNCHAMBERS == 1) goodentry = (nChambers == 1); + if (CUTNCHAMBERS == 2) goodentry = (nChambers >= 2); } - } - int& nChambers=m_nInnerChambers; - if (chid!=-1) { - if (m_chname.substr(1,1)=="I") nChambers=m_nInnerChambers; - else if (m_chname.substr(1,1)=="M") nChambers=m_nMiddleChambers; - else if (m_chname.substr(1,1)=="O") nChambers=m_nOuterChambers; - else nChambers=m_nOtherChambers; - } - - bool goodentry = chid==-1; - if (!goodentry) { - goodentry=(nChambers>CUTNCHAMBERS); - if (CUTNCHAMBERS==1) goodentry=(nChambers==1); - if (CUTNCHAMBERS==2) goodentry=(nChambers>=2); - } - - //cout<<"returning "<<goodentry<<endl; + // cout<<"returning "<<goodentry<<endl; - return goodentry; + return goodentry; } //________________________________________________________________________ -const int getNumberMatrixIndices() -{ - - TBranch* brNMatIndices; - TBranch* brMatIndices; - int nMatIndices; - int* matIndices=new int[50]; - - m_sdTree->SetBranchAddress("nMatrixIndices", &nMatIndices, &brNMatIndices); - m_sdTree->SetBranchAddress("matrixIndices", matIndices, &brMatIndices); - - int maxIndex(0); - int minIndex(-1); - for (int ientry=0;ientry<(int)m_sdTree->GetEntries();ientry++) { - - m_sdTree->LoadTree(ientry); - int treenum=m_sdTree->GetTreeNumber(); - int treeentry=ientry-m_sdTree->GetTreeOffset()[treenum]; - - brNMatIndices->GetEntry(treeentry); - brMatIndices ->GetEntry(treeentry); - - for (int imat=0;imat<nMatIndices;imat++) { - if (minIndex<0||matIndices[imat]<minIndex) minIndex=matIndices[imat]; - if ( matIndices[imat]>maxIndex) maxIndex=matIndices[imat]; +const int getNumberMatrixIndices() { + TBranch* brNMatIndices; + TBranch* brMatIndices; + int nMatIndices; + int* matIndices = new int[50]; + + m_sdTree->SetBranchAddress("nMatrixIndices", &nMatIndices, &brNMatIndices); + m_sdTree->SetBranchAddress("matrixIndices", matIndices, &brMatIndices); + + int maxIndex(0); + int minIndex(-1); + for (int ientry = 0; ientry < (int)m_sdTree->GetEntries(); ientry++) { + m_sdTree->LoadTree(ientry); + int treenum = m_sdTree->GetTreeNumber(); + int treeentry = ientry - m_sdTree->GetTreeOffset()[treenum]; + + brNMatIndices->GetEntry(treeentry); + brMatIndices->GetEntry(treeentry); + + for (int imat = 0; imat < nMatIndices; imat++) { + if (minIndex < 0 || matIndices[imat] < minIndex) minIndex = matIndices[imat]; + if (matIndices[imat] > maxIndex) maxIndex = matIndices[imat]; + } } - } - - return maxIndex+1; + return maxIndex + 1; } - //________________________________________________________________________ -void addDerivatives() -{ - //cout<<"addDerivatives"<<endl; - - // fix 2nd derivatives to constrain along track - int sdIndex(0); - TMatrixDSym secDerivMatrix(m_sd_nMatrixIndices); - for (int imat=0;imat<m_sd_nMatrixIndices;imat++) { - for (int jmat=imat;jmat<m_sd_nMatrixIndices;jmat++) { - double sd=m_sd_secndDeriv[sdIndex++]; - if (imat%NPAR >=NPAR-6+3) sd*=m_rotscale; - if (jmat%NPAR >=NPAR-6+3) sd*=m_rotscale; - secDerivMatrix[imat][jmat]=sd; - if (jmat!=imat) secDerivMatrix[jmat][imat]=sd; +void addDerivatives() { + // cout<<"addDerivatives"<<endl; + + // fix 2nd derivatives to constrain along track + int sdIndex(0); + TMatrixDSym secDerivMatrix(m_sd_nMatrixIndices); + for (int imat = 0; imat < m_sd_nMatrixIndices; imat++) { + for (int jmat = imat; jmat < m_sd_nMatrixIndices; jmat++) { + double sd = m_sd_secndDeriv[sdIndex++]; + if (imat % NPAR >= NPAR - 6 + 3) sd *= m_rotscale; + if (jmat % NPAR >= NPAR - 6 + 3) sd *= m_rotscale; + secDerivMatrix[imat][jmat] = sd; + if (jmat != imat) secDerivMatrix[jmat][imat] = sd; + } } - } - if (CONSTRAIN_LOWESTEV) { - - if (DEBUG) - std::cout<<"constraining lowest eigenvalues"<<std::endl; - - for (int ich=0;ich<m_sd_nChambers;ich++) { - TMatrixDSym secDerivCh(NPAR); - for (int ipar=0;ipar<NPAR;ipar++) { - int oldiindex=ich*NPAR+ipar; - for (int jpar=ipar;jpar<NPAR;jpar++) { - int oldjindex=ich*NPAR+jpar; - secDerivCh[ipar][jpar]=secDerivMatrix[oldiindex][oldjindex]; - if (jpar!=ipar) - secDerivCh[jpar][ipar]=secDerivMatrix[oldiindex][oldjindex]; - } - } - - if (DEBUG) { - int chid=m_sd_chamberIds[ich]; - cout<<"secDeriv (ich="<<ich<<") "<<m_chNames->chamberName(chid)<<endl; - secDerivCh.Print(); - } - - TDecompSVD decompMat(secDerivCh); - decompMat.Decompose(); - const TVectorD& svV=decompMat.GetSig(); - - vector<double> sv; - for (int i=0;i<svV.GetNoElements();i++) { - sv.push_back(svV[i]); - if (DEBUG) cout<<"sv["<<i<<"]="<<sv[i]<<endl; - } - - TMatrixD u=decompMat.GetU(); - if (DEBUG) { - cout<<"U:"<<endl; - u.Print(); - } - - TMatrixD v=decompMat.GetV(); - TMatrixD vinv(v.Invert()); - //cout<<"Vinv:"<<endl; - //vinv.Print(); - - TMatrixDSym newSD(NPAR); - double constraintval(0.); - for (int ipar=0;ipar<NPAR;ipar++) { - if (ipar==0) { - //double sd=secDerivCh[NPAR-1][NPAR-1]; - //constraintval=.03;//2.*sd; - //constraintval=100.; - constraintval=5.; - if (DEBUG) cout<<"constraintval: "<<constraintval<<endl; - } - if (ipar<NPAR-6+3) newSD[ipar][ipar]=sv[ipar]; - else newSD[ipar][ipar]=sv[ipar]+constraintval; - } - TMatrixD D=u*newSD*vinv; - //D.Print(); - - for (int ipar=0;ipar<NPAR;ipar++) { - int oldiindex=ich*NPAR+ipar; - for (int jpar=ipar;jpar<NPAR;jpar++) { - int oldjindex=ich*NPAR+jpar; - secDerivMatrix[oldiindex][oldjindex]=D[ipar][jpar]; - if (jpar!=ipar) - secDerivMatrix[oldjindex][oldiindex]=D[ipar][jpar]; - } - } - } - if (DEBUG) { - cout<<"after"<<endl; - secDerivMatrix.Print(); + if (CONSTRAIN_LOWESTEV) { + if (DEBUG) std::cout << "constraining lowest eigenvalues" << std::endl; + + for (int ich = 0; ich < m_sd_nChambers; ich++) { + TMatrixDSym secDerivCh(NPAR); + for (int ipar = 0; ipar < NPAR; ipar++) { + int oldiindex = ich * NPAR + ipar; + for (int jpar = ipar; jpar < NPAR; jpar++) { + int oldjindex = ich * NPAR + jpar; + secDerivCh[ipar][jpar] = secDerivMatrix[oldiindex][oldjindex]; + if (jpar != ipar) secDerivCh[jpar][ipar] = secDerivMatrix[oldiindex][oldjindex]; + } + } + + if (DEBUG) { + int chid = m_sd_chamberIds[ich]; + cout << "secDeriv (ich=" << ich << ") " << m_chNames->chamberName(chid) << endl; + secDerivCh.Print(); + } + + TDecompSVD decompMat(secDerivCh); + decompMat.Decompose(); + const TVectorD& svV = decompMat.GetSig(); + + vector<double> sv; + for (int i = 0; i < svV.GetNoElements(); i++) { + sv.push_back(svV[i]); + if (DEBUG) cout << "sv[" << i << "]=" << sv[i] << endl; + } + + TMatrixD u = decompMat.GetU(); + if (DEBUG) { + cout << "U:" << endl; + u.Print(); + } + + TMatrixD v = decompMat.GetV(); + TMatrixD vinv(v.Invert()); + // cout<<"Vinv:"<<endl; + // vinv.Print(); + + TMatrixDSym newSD(NPAR); + double constraintval(0.); + for (int ipar = 0; ipar < NPAR; ipar++) { + if (ipar == 0) { + // double sd=secDerivCh[NPAR-1][NPAR-1]; + // constraintval=.03;//2.*sd; + // constraintval=100.; + constraintval = 5.; + if (DEBUG) cout << "constraintval: " << constraintval << endl; + } + if (ipar < NPAR - 6 + 3) + newSD[ipar][ipar] = sv[ipar]; + else + newSD[ipar][ipar] = sv[ipar] + constraintval; + } + TMatrixD D = u * newSD * vinv; + // D.Print(); + + for (int ipar = 0; ipar < NPAR; ipar++) { + int oldiindex = ich * NPAR + ipar; + for (int jpar = ipar; jpar < NPAR; jpar++) { + int oldjindex = ich * NPAR + jpar; + secDerivMatrix[oldiindex][oldjindex] = D[ipar][jpar]; + if (jpar != ipar) secDerivMatrix[oldjindex][oldiindex] = D[ipar][jpar]; + } + } + } + if (DEBUG) { + cout << "after" << endl; + secDerivMatrix.Print(); + } } - } - - // add derivatives - int nChambers=m_allChDerivs->nchambers(); - int ich=-1; - - int index(0); - - int lastChId=-1; - //cout<<"m_sd_nMatrixIndices: "<<m_sd_nMatrixIndices<<endl; - for (int imat=0;imat<m_sd_nMatrixIndices;imat++) { - - //cout<<"imat: "<<imat<<endl; - - if (imat%NPAR==0) { - //cout<<"setting chamberId"<<endl; - int ii_matIndex=m_sd_matrixIndices[imat]; - ich++; - int allChId=ii_matIndex/NPAR; - //cout<<"allChId: "<<allChId<<endl; - if (m_allChDerivs->chamberId(allChId)<0) { - m_allChDerivs->setChamberId(allChId,m_sd_chamberIds[ich]); - } - //cout<<"chamberId: "<<m_allChDerivs->chamberId(allChId)<<endl; - lastChId=m_sd_chamberIds[ich]; - } + // add derivatives + int nChambers = m_allChDerivs->nchambers(); + int ich = -1; + + int index(0); + + int lastChId = -1; + // cout<<"m_sd_nMatrixIndices: "<<m_sd_nMatrixIndices<<endl; + + for (int imat = 0; imat < m_sd_nMatrixIndices; imat++) { + // cout<<"imat: "<<imat<<endl; + + if (imat % NPAR == 0) { + // cout<<"setting chamberId"<<endl; + int ii_matIndex = m_sd_matrixIndices[imat]; + ich++; + int allChId = ii_matIndex / NPAR; + // cout<<"allChId: "<<allChId<<endl; + if (m_allChDerivs->chamberId(allChId) < 0) { m_allChDerivs->setChamberId(allChId, m_sd_chamberIds[ich]); } + // cout<<"chamberId: "<<m_allChDerivs->chamberId(allChId)<<endl; + lastChId = m_sd_chamberIds[ich]; + } - string chname=m_chNames->chamberName(lastChId); - if (DO_EE_ONLY) { - if (chname.substr(0,3)!="BEE"&&chname.substr(0,3)!="EEL") continue; - //std::cout<<"chname="<<chname<<std::endl; - } - //cout<<"chname: "<<chname<<endl; - - //if (m_sd_nMatrixIndices<15) cout<<"imat: "<<imat<<endl; - int i_matIndex=m_sd_matrixIndices[imat]; - - double fd=m_sd_firstDeriv[imat]; - if ( imat%NPAR >= NPAR-6+3) fd*=m_rotscale; - //cout<<"adding "<<fd<<" to "<<i_matIndex<<endl; - m_allChDerivs->addFirstDeriv(i_matIndex,fd); - - for (int jmat=imat;jmat<m_sd_nMatrixIndices;jmat++) { - int j_matIndex=m_sd_matrixIndices[jmat]; - double sd=secDerivMatrix[imat][jmat]; - - //cout<<"adding "<<sd<<" to "<<i_matIndex<<","<<j_matIndex<<endl; - if (j_matIndex>=i_matIndex) - m_allChDerivs->addSecondDeriv(i_matIndex,j_matIndex,sd); - else - m_allChDerivs->addSecondDeriv(j_matIndex,i_matIndex,sd); - - if (imat%NPAR==0&&jmat%NPAR==0) { - int j_matIndex=m_sd_matrixIndices[jmat]; - int i_allChId=i_matIndex/NPAR; - int j_allChId=j_matIndex/NPAR; - //cout<<"increment hitmap"<<endl; - if (j_matIndex>=i_matIndex) - m_allChDerivs->incrementHitmap(i_allChId*nChambers+j_allChId); - else - m_allChDerivs->incrementHitmap(j_allChId*nChambers+i_allChId); - } - index++; + string chname = m_chNames->chamberName(lastChId); + if (DO_EE_ONLY) { + if (chname.substr(0, 3) != "BEE" && chname.substr(0, 3) != "EEL") continue; + // std::cout<<"chname="<<chname<<std::endl; + } + // cout<<"chname: "<<chname<<endl; + + // if (m_sd_nMatrixIndices<15) cout<<"imat: "<<imat<<endl; + int i_matIndex = m_sd_matrixIndices[imat]; + + double fd = m_sd_firstDeriv[imat]; + if (imat % NPAR >= NPAR - 6 + 3) fd *= m_rotscale; + // cout<<"adding "<<fd<<" to "<<i_matIndex<<endl; + m_allChDerivs->addFirstDeriv(i_matIndex, fd); + + for (int jmat = imat; jmat < m_sd_nMatrixIndices; jmat++) { + int j_matIndex = m_sd_matrixIndices[jmat]; + double sd = secDerivMatrix[imat][jmat]; + + // cout<<"adding "<<sd<<" to "<<i_matIndex<<","<<j_matIndex<<endl; + if (j_matIndex >= i_matIndex) + m_allChDerivs->addSecondDeriv(i_matIndex, j_matIndex, sd); + else + m_allChDerivs->addSecondDeriv(j_matIndex, i_matIndex, sd); + + if (imat % NPAR == 0 && jmat % NPAR == 0) { + int j_matIndex = m_sd_matrixIndices[jmat]; + int i_allChId = i_matIndex / NPAR; + int j_allChId = j_matIndex / NPAR; + // cout<<"increment hitmap"<<endl; + if (j_matIndex >= i_matIndex) + m_allChDerivs->incrementHitmap(i_allChId * nChambers + j_allChId); + else + m_allChDerivs->incrementHitmap(j_allChId * nChambers + i_allChId); + } + index++; + } } - } - return; + return; } -//________________________________________________________________________ -void fillTree() -{ - int m_nChambers=-1; - int index=-1; - for (int imat=0;imat<m_sd_nMatrixIndices;imat++) { - int ipar=imat%NPAR; - if (ipar==0) { - m_nChambers++; - m_chamberIds[m_nChambers]=m_sd_chamberIds[m_nChambers]; - } - - for (int jmat=imat;jmat<m_sd_nMatrixIndices;jmat++) { - index++; - if (jmat!=imat) continue; - double sd=m_sd_secndDeriv[index]; - double fd=m_sd_firstDeriv[imat]; - //cout<<"ft: sd["<<imat<<"]="<<sd<<", fd="<<fd<<endl; - double alignPar=-fd/sd; - double alignErr=std::sqrt(2./fabs(sd)); - m_alignPar [m_nChambers][ipar]=alignPar; - m_alignErr [m_nChambers][ipar]=alignErr; - m_firstderiv[m_nChambers][ipar]=fd; - m_secndderiv[m_nChambers][ipar]=sd; +//________________________________________________________________________ +void fillTree() { + int m_nChambers = -1; + int index = -1; + for (int imat = 0; imat < m_sd_nMatrixIndices; imat++) { + int ipar = imat % NPAR; + if (ipar == 0) { + m_nChambers++; + m_chamberIds[m_nChambers] = m_sd_chamberIds[m_nChambers]; + } + + for (int jmat = imat; jmat < m_sd_nMatrixIndices; jmat++) { + index++; + if (jmat != imat) continue; + double sd = m_sd_secndDeriv[index]; + double fd = m_sd_firstDeriv[imat]; + // cout<<"ft: sd["<<imat<<"]="<<sd<<", fd="<<fd<<endl; + double alignPar = -fd / sd; + double alignErr = std::sqrt(2. / fabs(sd)); + m_alignPar[m_nChambers][ipar] = alignPar; + m_alignErr[m_nChambers][ipar] = alignErr; + m_firstderiv[m_nChambers][ipar] = fd; + m_secndderiv[m_nChambers][ipar] = sd; + } } - } - m_outputTree->Fill(); + m_outputTree->Fill(); } -//________________________________________________________________________ -void makeNewTree() -{ - m_outputFile=new TFile("outputfile.root","RECREATE"); - m_outputTree=m_mtppTree->CloneTree(0); - - m_outputTree->Branch("nAlignChambers", &m_nAlignChambers, "nAlignChambers"); - m_outputTree->Branch("chamberIds", m_chamberIds, "chamberIds[nAlignChambers]"); - - stringstream alignParStr; alignParStr<<"alignPar[nAlignChambers]["<<NPAR<<"]"; - stringstream alignErrStr; alignErrStr<<"alignErr[nAlignChambers]["<<NPAR<<"]"; - stringstream fdStr; fdStr<<"fd[nAlignChambers]["<<NPAR<<"]"; - stringstream sdStr; sdStr<<"sd[nAlignChambers]["<<NPAR<<"]"; - - m_outputTree->Branch("alignPar", m_alignPar, alignParStr.str().c_str()); - m_outputTree->Branch("alignErr", m_alignErr, alignErrStr.str().c_str()); - m_outputTree->Branch("firstderiv", m_firstderiv, fdStr.str().c_str()); - m_outputTree->Branch("secndderiv", m_secndderiv, sdStr.str().c_str()); - - m_outputTree->Branch("nInnerChambers", &m_nInnerChambers, "nInnerChambers/I"); - m_outputTree->Branch("nMiddleChambers", &m_nMiddleChambers, "nMiddleChambers/I"); - m_outputTree->Branch("nOuterChambers", &m_nOuterChambers, "nOuterChambers/I"); - m_outputTree->Branch("nOtherChambers", &m_nOtherChambers, "nOtherChambers/I"); - - return; +//________________________________________________________________________ +void makeNewTree() { + m_outputFile = new TFile("outputfile.root", "RECREATE"); + m_outputTree = m_mtppTree->CloneTree(0); + + m_outputTree->Branch("nAlignChambers", &m_nAlignChambers, "nAlignChambers"); + m_outputTree->Branch("chamberIds", m_chamberIds, "chamberIds[nAlignChambers]"); + + stringstream alignParStr; + alignParStr << "alignPar[nAlignChambers][" << NPAR << "]"; + stringstream alignErrStr; + alignErrStr << "alignErr[nAlignChambers][" << NPAR << "]"; + stringstream fdStr; + fdStr << "fd[nAlignChambers][" << NPAR << "]"; + stringstream sdStr; + sdStr << "sd[nAlignChambers][" << NPAR << "]"; + + m_outputTree->Branch("alignPar", m_alignPar, alignParStr.str().c_str()); + m_outputTree->Branch("alignErr", m_alignErr, alignErrStr.str().c_str()); + m_outputTree->Branch("firstderiv", m_firstderiv, fdStr.str().c_str()); + m_outputTree->Branch("secndderiv", m_secndderiv, sdStr.str().c_str()); + + m_outputTree->Branch("nInnerChambers", &m_nInnerChambers, "nInnerChambers/I"); + m_outputTree->Branch("nMiddleChambers", &m_nMiddleChambers, "nMiddleChambers/I"); + m_outputTree->Branch("nOuterChambers", &m_nOuterChambers, "nOuterChambers/I"); + m_outputTree->Branch("nOtherChambers", &m_nOtherChambers, "nOtherChambers/I"); + + return; } //________________________________________________________________________ -void makeHitmap(const ChamberDerivs& chDerivs, TPad* pad) -{ - int optfit=gStyle->GetOptFit(); - int optstat=gStyle->GetOptStat(); - gStyle->SetOptFit(000000); - gStyle->SetOptStat(000000); - - if (DO_EC_ONLY && !DO_ASIDE_ONLY) pad->Divide(2,1); +void makeHitmap(const ChamberDerivs& chDerivs, TPad* pad) { + int optfit = gStyle->GetOptFit(); + int optstat = gStyle->GetOptStat(); + gStyle->SetOptFit(000000); + gStyle->SetOptStat(000000); - //int nchambers=chDerivs.nchambers(); - int nchambers= (DO_EC_ONLY) ? NENDCAP : NENDCAP+NBARREL; - if (!DO_ASIDE_ONLY && !DO_EC_ONLY) nchambers*=2; + if (DO_EC_ONLY && !DO_ASIDE_ONLY) pad->Divide(2, 1); - int minbin=(DO_ASIDE_ONLY)?0:-nchambers/2; - int maxbin=(DO_ASIDE_ONLY)?nchambers:nchambers/2; - TH2F* hitmap=new TH2F("hitmap","log_{10}(# tracks) for each pair of chambers", - maxbin-minbin,minbin,maxbin, - maxbin-minbin,minbin,maxbin); - - for (int ich=0;ich<chDerivs.nchambers();ich++) { + // int nchambers=chDerivs.nchambers(); + int nchambers = (DO_EC_ONLY) ? NENDCAP : NENDCAP + NBARREL; + if (!DO_ASIDE_ONLY && !DO_EC_ONLY) nchambers *= 2; - int ichid=chDerivs.chamberId(ich); - string ichambername=m_chNames->chamberName(ichid); - if (ichambername=="") continue; + int minbin = (DO_ASIDE_ONLY) ? 0 : -nchambers / 2; + int maxbin = (DO_ASIDE_ONLY) ? nchambers : nchambers / 2; + TH2F* hitmap = new TH2F("hitmap", "log_{10}(# tracks) for each pair of chambers", maxbin - minbin, minbin, maxbin, maxbin - minbin, + minbin, maxbin); - if (ichambername.substr(4,1)=='C' && - (DO_ASIDE_ONLY)) continue; + for (int ich = 0; ich < chDerivs.nchambers(); ich++) { + int ichid = chDerivs.chamberId(ich); + string ichambername = m_chNames->chamberName(ichid); + if (ichambername == "") continue; - int icoord=hitMapCoord(get1Dcoordinate(ichambername),ichambername)-minbin+1; + if (ichambername.substr(4, 1) == 'C' && (DO_ASIDE_ONLY)) continue; - for (int jch=ich;jch<chDerivs.nchambers();jch++) { + int icoord = hitMapCoord(get1Dcoordinate(ichambername), ichambername) - minbin + 1; - //if (jch!=ich) continue; + for (int jch = ich; jch < chDerivs.nchambers(); jch++) { + // if (jch!=ich) continue; - int jchid=chDerivs.chamberId(jch); - string jchambername=m_chNames->chamberName(jchid); - if (jchambername=="") continue; - if (jchambername.substr(4,1)=='C' && DO_ASIDE_ONLY) continue; + int jchid = chDerivs.chamberId(jch); + string jchambername = m_chNames->chamberName(jchid); + if (jchambername == "") continue; + if (jchambername.substr(4, 1) == 'C' && DO_ASIDE_ONLY) continue; - int jcoord=hitMapCoord(get1Dcoordinate(jchambername),jchambername)-minbin+1; + int jcoord = hitMapCoord(get1Dcoordinate(jchambername), jchambername) - minbin + 1; - double val=std::log10(chDerivs.nhits(ich,jch)); - //cout<<"setting bin "<<icoord<<endl; - hitmap->SetBinContent(icoord,jcoord,val); - //cout<<"setting bin "<<jcoord<<endl; - hitmap->SetBinContent(jcoord,icoord,val); + double val = std::log10(chDerivs.nhits(ich, jch)); + // cout<<"setting bin "<<icoord<<endl; + hitmap->SetBinContent(icoord, jcoord, val); + // cout<<"setting bin "<<jcoord<<endl; + hitmap->SetBinContent(jcoord, icoord, val); + } } - } - // set bin labels - string chnames[16]={"EIL1A1","EIL2A1","EIL3A1","EIL4A1","EML1A1","EML2A1", - "EML3A1","EML4A1","EML5A1","BEE1A1","EOL1A1","EOL2A1", - "EOL3A1","EOL4A1","EOL5A1","EOL6A1"}; - string labels[16]={"EI_1A", "EI_2A", "EI_3A", "EI_4A", "EM_1A", "EM_2A", - "EM_3A", "EM_4A", "EM_5A", "EE", "EO_1A", "EO_2A", - "EO_3A", "EO_4A", "EO_5A", "EO_6A" }; - - for (int i=0;i<16;i++) { - int ibin=hitMapCoord(get1Dcoordinate(chnames[i]),chnames[i])-minbin+1; - hitmap->GetXaxis()->SetBinLabel(ibin,labels[i].c_str()); - hitmap->GetYaxis()->SetBinLabel(ibin,labels[i].c_str()); - } + // set bin labels + string chnames[16] = {"EIL1A1", "EIL2A1", "EIL3A1", "EIL4A1", "EML1A1", "EML2A1", "EML3A1", "EML4A1", + "EML5A1", "BEE1A1", "EOL1A1", "EOL2A1", "EOL3A1", "EOL4A1", "EOL5A1", "EOL6A1"}; + string labels[16] = {"EI_1A", "EI_2A", "EI_3A", "EI_4A", "EM_1A", "EM_2A", "EM_3A", "EM_4A", + "EM_5A", "EE", "EO_1A", "EO_2A", "EO_3A", "EO_4A", "EO_5A", "EO_6A"}; - pad->cd(); - hitmap->Draw("COLZ"); - //hitmap->Draw("LEGO2"); - gStyle->SetOptFit(optfit); - gStyle->SetOptStat(optstat); + for (int i = 0; i < 16; i++) { + int ibin = hitMapCoord(get1Dcoordinate(chnames[i]), chnames[i]) - minbin + 1; + hitmap->GetXaxis()->SetBinLabel(ibin, labels[i].c_str()); + hitmap->GetYaxis()->SetBinLabel(ibin, labels[i].c_str()); + } - return; + pad->cd(); + hitmap->Draw("COLZ"); + // hitmap->Draw("LEGO2"); + gStyle->SetOptFit(optfit); + gStyle->SetOptStat(optstat); + + return; } //________________________________________________________________________ -void make2DAlignHists(const ChamberDerivs& chDerivs, TPad** pad1, TPad** pad2) -{ - int optfit=gStyle->GetOptFit(); - int optstat=gStyle->GetOptStat(); - gStyle->SetOptFit(000000); - gStyle->SetOptStat(000000); - - TH2D** h2_align =new TH2D*[NPAR]; - TLegend** h2_align_leg =new TLegend*[NPAR]; - TH2D** h2_alignVNtrks=new TH2D*[NPAR]; - - int NXBINS =(DO_EC_ONLY&&DO_ASIDE_ONLY) ? 8 : 35; - double xmin=(DO_EC_ONLY&&DO_ASIDE_ONLY)? 9.5 : -17.5; - double xmax=17.5; - for (int ipar=0;ipar<NPAR;ipar++) { - - string thisparstr=parstr[6-NPAR+ipar]; - - h2_align[ipar] = new TH2D(thisparstr.c_str(), thisparstr.c_str(), - NXBINS,xmin,xmax,51,0.5,51.5); - string histname=thisparstr+"VNtrks"; - double range=(ipar<NPAR-3)?range_tra:range_rot; range*=10.; - h2_alignVNtrks[ipar] = new TH2D(histname.c_str(),histname.c_str(), - 100,1000.,20000.,100,-range,range); - } +void make2DAlignHists(const ChamberDerivs& chDerivs, TPad** pad1, TPad** pad2) { + int optfit = gStyle->GetOptFit(); + int optstat = gStyle->GetOptStat(); + gStyle->SetOptFit(000000); + gStyle->SetOptStat(000000); + + TH2D** h2_align = new TH2D*[NPAR]; + TLegend** h2_align_leg = new TLegend*[NPAR]; + TH2D** h2_alignVNtrks = new TH2D*[NPAR]; + + int NXBINS = (DO_EC_ONLY && DO_ASIDE_ONLY) ? 8 : 35; + double xmin = (DO_EC_ONLY && DO_ASIDE_ONLY) ? 9.5 : -17.5; + double xmax = 17.5; + for (int ipar = 0; ipar < NPAR; ipar++) { + string thisparstr = parstr[6 - NPAR + ipar]; + + h2_align[ipar] = new TH2D(thisparstr.c_str(), thisparstr.c_str(), NXBINS, xmin, xmax, 51, 0.5, 51.5); + string histname = thisparstr + "VNtrks"; + double range = (ipar < NPAR - 3) ? range_tra : range_rot; + range *= 10.; + h2_alignVNtrks[ipar] = new TH2D(histname.c_str(), histname.c_str(), 100, 1000., 20000., 100, -range, range); + } - double histmin[NPAR]; - double histmax[NPAR]; - for (int i=0;i<NPAR;i++) { - histmin[i]=1e8; - histmax[i]=0.; - } + double histmin[NPAR]; + double histmax[NPAR]; + for (int i = 0; i < NPAR; i++) { + histmin[i] = 1e8; + histmax[i] = 0.; + } - double* err, *res; - res=chDerivs.solve(err,-1,ChamberDerivs::ROOT); - - for (int ich=0;ich<chDerivs.nchambers();ich++) { - - int chid=chDerivs.chamberId(ich); - string chambername=m_chNames->chamberName(chid); - int ntrks=chDerivs.nhits(ich,ich); - - for (int ipar=0;ipar<NPAR;ipar++) { - - double alignpar=res[ich*NPAR+ipar]; - - if (chambername!="") { - - h2_align[ipar]->Fill(getXcoordinate(chambername), - 51-getYcoordinate(chambername),alignpar); - h2_alignVNtrks[ipar]->Fill(ntrks,alignpar); - - if (alignpar>histmax[ipar]) histmax[ipar]=alignpar; - if (alignpar<histmin[ipar]) histmin[ipar]=alignpar; - - - string Ytitle, Xtitle; - if (chambername[3]!='0') { - if (chambername[0]=='E') Xtitle="Endcap"+chambername.substr(3,2); - if (chambername[0]=='B') Xtitle="Barrel"+chambername.substr(3,2); - if (chambername[1]=='E') Xtitle="EE/BEE"+chambername.substr(3,2); - } - - if (chambername[1]=='I' || chambername.substr(0,3)=="BEE") - Ytitle="Inner"+chambername.substr(5,2); - if (chambername[1]=='M' ||chambername.substr(0,3)=="EEL") - Ytitle="Middle"+chambername.substr(5,2); - if (chambername[1]=='O') - Ytitle="Outer"+chambername.substr(5,2); - - cout<<"chambername: "<<chambername<<", Ytitle: "<<Ytitle<<endl; - h2_align[ipar]->GetYaxis()->SetBinLabel(51-getYcoordinate(chambername), - Ytitle.c_str()); - - int firstbin=int(-xmin); - if (firstbin>0) firstbin++; - if (chambername.substr(4,1)=="C" && DO_ASIDE_ONLY) continue; - - //cout<<"setting bin label x"<<firstbin+getXcoordinate(chambername)<<endl; - h2_align[ipar]->GetXaxis()->SetBinLabel(firstbin+getXcoordinate(chambername), - Xtitle.c_str()); - } - int thispar=6-NPAR+ipar; - h2_align[ipar]->GetYaxis()->SetTitle((parstr[thispar]+" ("+unitstr[thispar]+")").c_str()); + double *err, *res; + res = chDerivs.solve(err, -1, ChamberDerivs::ROOT); - } - } + for (int ich = 0; ich < chDerivs.nchambers(); ich++) { + int chid = chDerivs.chamberId(ich); + string chambername = m_chNames->chamberName(chid); + int ntrks = chDerivs.nhits(ich, ich); - delete [] res; - delete [] err; + for (int ipar = 0; ipar < NPAR; ipar++) { + double alignpar = res[ich * NPAR + ipar]; - Double_t contours_tra[16]={ -2.,1.5,-1.,-.5,-.4,-.3,-.2,-.1, - .1,.2,.3,.4,.5,1.,1.5,2.}; - Double_t contours_rot[16]={ -2.,1.5,-1.,-.5,-.4,-.3,-.2,-.1, - .1,.2,.3,.4,.5,1.,1.5,2.}; + if (chambername != "") { + h2_align[ipar]->Fill(getXcoordinate(chambername), 51 - getYcoordinate(chambername), alignpar); + h2_alignVNtrks[ipar]->Fill(ntrks, alignpar); - for (int i=0;i<16;i++) contours_rot[i]*=.01; + if (alignpar > histmax[ipar]) histmax[ipar] = alignpar; + if (alignpar < histmin[ipar]) histmin[ipar] = alignpar; - - for (int ipar=0;ipar<NPAR;ipar++) { - TH2D* h = h2_align[ipar]; + string Ytitle, Xtitle; + if (chambername[3] != '0') { + if (chambername[0] == 'E') Xtitle = "Endcap" + chambername.substr(3, 2); + if (chambername[0] == 'B') Xtitle = "Barrel" + chambername.substr(3, 2); + if (chambername[1] == 'E') Xtitle = "EE/BEE" + chambername.substr(3, 2); + } - h2_align_leg[ipar]=new TLegend(.75,.8,.85,.9); - TLegend* leg = h2_align_leg[ipar]; + if (chambername[1] == 'I' || chambername.substr(0, 3) == "BEE") Ytitle = "Inner" + chambername.substr(5, 2); + if (chambername[1] == 'M' || chambername.substr(0, 3) == "EEL") Ytitle = "Middle" + chambername.substr(5, 2); + if (chambername[1] == 'O') Ytitle = "Outer" + chambername.substr(5, 2); - if (SET_RANGE) { - for (int ix=1; ix<=NXBINS; ix++) { - for (int iy=1; iy<=51; iy++) { - if (h->GetBinContent(ix,iy)==0.) - //cout<<"setting bin "<<ix<<" "<<iy<<endl; - h->SetBinContent(ix,iy,-999.); + cout << "chambername: " << chambername << ", Ytitle: " << Ytitle << endl; + h2_align[ipar]->GetYaxis()->SetBinLabel(51 - getYcoordinate(chambername), Ytitle.c_str()); + + int firstbin = int(-xmin); + if (firstbin > 0) firstbin++; + if (chambername.substr(4, 1) == "C" && DO_ASIDE_ONLY) continue; + + // cout<<"setting bin label x"<<firstbin+getXcoordinate(chambername)<<endl; + h2_align[ipar]->GetXaxis()->SetBinLabel(firstbin + getXcoordinate(chambername), Xtitle.c_str()); + } + int thispar = 6 - NPAR + ipar; + h2_align[ipar]->GetYaxis()->SetTitle((parstr[thispar] + " (" + unitstr[thispar] + ")").c_str()); } - } } - pad1[ipar]->cd(); - cout<<"histmin: "<<histmin[ipar]<<", histmax: "<<histmax[ipar]<<endl; + delete[] res; + delete[] err; - if (SET_RANGE) { - if (0) { - if (ipar<NPAR-3) { - h->SetAxisRange(-range_tra, range_tra,"Z"); - if (CONSTRAIN_EM||EIGENVALUE_CUT) - h->SetContour(16,contours_tra); - } - else { - h->SetAxisRange(-range_rot,range_rot,"Z"); - if (CONSTRAIN_EM||EIGENVALUE_CUT) - h->SetContour(16,contours_rot); - } - } - else { - double range(0.); - if (ipar<NPAR-3) { - cout<<"setting axis range to -2,2"<<endl; - range=RANGE_TRA; - } - else { - cout<<"setting axis range to -10,10"<<endl; - range=RANGE_ROTZT; + Double_t contours_tra[16] = {-2., 1.5, -1., -.5, -.4, -.3, -.2, -.1, .1, .2, .3, .4, .5, 1., 1.5, 2.}; + Double_t contours_rot[16] = {-2., 1.5, -1., -.5, -.4, -.3, -.2, -.1, .1, .2, .3, .4, .5, 1., 1.5, 2.}; + + for (int i = 0; i < 16; i++) contours_rot[i] *= .01; + + for (int ipar = 0; ipar < NPAR; ipar++) { + TH2D* h = h2_align[ipar]; + + h2_align_leg[ipar] = new TLegend(.75, .8, .85, .9); + TLegend* leg = h2_align_leg[ipar]; + + if (SET_RANGE) { + for (int ix = 1; ix <= NXBINS; ix++) { + for (int iy = 1; iy <= 51; iy++) { + if (h->GetBinContent(ix, iy) == 0.) + // cout<<"setting bin "<<ix<<" "<<iy<<endl; + h->SetBinContent(ix, iy, -999.); + } + } } - if (ipar==NPAR-6+3) { - cout<<"setting axis range to -2,2"<<endl; - range=RANGE_ROTS; + + pad1[ipar]->cd(); + cout << "histmin: " << histmin[ipar] << ", histmax: " << histmax[ipar] << endl; + + if (SET_RANGE) { + if (0) { + if (ipar < NPAR - 3) { + h->SetAxisRange(-range_tra, range_tra, "Z"); + if (CONSTRAIN_EM || EIGENVALUE_CUT) h->SetContour(16, contours_tra); + } else { + h->SetAxisRange(-range_rot, range_rot, "Z"); + if (CONSTRAIN_EM || EIGENVALUE_CUT) h->SetContour(16, contours_rot); + } + } else { + double range(0.); + if (ipar < NPAR - 3) { + cout << "setting axis range to -2,2" << endl; + range = RANGE_TRA; + } else { + cout << "setting axis range to -10,10" << endl; + range = RANGE_ROTZT; + } + if (ipar == NPAR - 6 + 3) { + cout << "setting axis range to -2,2" << endl; + range = RANGE_ROTS; + } + h->SetAxisRange(-range, range, "Z"); + } } - h->SetAxisRange(-range,range,"Z"); - } + + h->GetXaxis()->SetTickLength(0); + h->GetYaxis()->SetTickLength(0); + h->GetXaxis()->SetLabelSize(.02); + h->GetYaxis()->SetLabelSize(.02); + h->Draw("COLZ"); + + leg->SetFillColor(10); + int thispar = 6 - NPAR + ipar; + leg->AddEntry(h, (parstr[thispar] + " (" + unitstr[thispar] + ")").c_str(), ""); + // leg->Draw(); + + // pad2[ipar]->cd(); + pad2[ipar]->cd()->SetLogx(1); + TH2D* h2 = h2_alignVNtrks[ipar]; + h2->GetXaxis()->SetTitle("# tracks"); + h2->GetYaxis()->SetTitle((parstr[thispar] + " (" + unitstr[thispar] + ")").c_str()); + h2->Draw("COLZ"); } - - h->GetXaxis()->SetTickLength(0); - h->GetYaxis()->SetTickLength(0); - h->GetXaxis()->SetLabelSize(.02); - h->GetYaxis()->SetLabelSize(.02); - h->Draw("COLZ"); - - leg->SetFillColor(10); - int thispar=6-NPAR+ipar; - leg->AddEntry(h,(parstr[thispar]+" ("+unitstr[thispar]+")").c_str(),""); - //leg->Draw(); - - //pad2[ipar]->cd(); - pad2[ipar]->cd()->SetLogx(1); - TH2D* h2=h2_alignVNtrks[ipar]; - h2->GetXaxis()->SetTitle("# tracks"); - h2->GetYaxis()->SetTitle((parstr[thispar]+" ("+unitstr[thispar]+")").c_str()); - h2->Draw("COLZ"); - } - gStyle->SetOptFit(optfit); - gStyle->SetOptStat(optstat); + gStyle->SetOptFit(optfit); + gStyle->SetOptStat(optstat); - return; + return; } //________________________________________________________________________ -int hitMapCoord(int coord, const string& chambername) -{ - int newcoord=coord; - if (!DO_EC_ONLY && (chambername[0]=='E' || chambername.substr(0,2)=="BE")) newcoord+=NBARREL; - if (chambername.substr(4,1)=='C') newcoord*=-1; - return newcoord; +int hitMapCoord(int coord, const string& chambername) { + int newcoord = coord; + if (!DO_EC_ONLY && (chambername[0] == 'E' || chambername.substr(0, 2) == "BE")) newcoord += NBARREL; + if (chambername.substr(4, 1) == 'C') newcoord *= -1; + return newcoord; } //________________________________________________________________________ -int get1Dcoordinate(const string& chambername) -{ +int get1Dcoordinate(const string& chambername) { + if (chambername == "") return -999; - if (chambername=="") return -999; + int eta = atoi(chambername.substr(3, 1).c_str()); + int phi = atoi(chambername.substr(5, 2).c_str()); - int eta=atoi(chambername.substr(3,1).c_str()); - int phi=atoi(chambername.substr(5,2).c_str()); - - if (chambername[1]=='I' && phi>10 ) { - if (phi==11 && chambername[2]=='R') phi = 17; - if (phi==15 && chambername[2]=='R') phi = 18; - } + if (chambername[1] == 'I' && phi > 10) { + if (phi == 11 && chambername[2] == 'R') phi = 17; + if (phi == 15 && chambername[2] == 'R') phi = 18; + } - eta--; - phi--; - - // inner - bool isBarrel=chambername[0]=='B' && chambername[1]!='E'; - - int icoord=0; - int nphi=isBarrel?18:16; - int neta=isBarrel?8:4; - - // inner layer - if (chambername[1]=='I') - return icoord + eta*nphi + phi; - - if (chambername[0]=='E' || chambername.substr(0,2)=="BE") { - icoord += nphi*neta; - nphi=8; neta=2; - if (chambername.substr(0,2)=="BE") - return icoord + eta*nphi + phi; - } + eta--; + phi--; - icoord += nphi*neta; - nphi=16; - neta=(isBarrel)?6:5; + // inner + bool isBarrel = chambername[0] == 'B' && chambername[1] != 'E'; - // middle layer - if (chambername[1]=='M') { - //cout<<"eta: "<<eta<<", phi: "<<phi<<", icoord: "<<icoord<<endl; - return icoord + (eta*nphi) + phi; - } + int icoord = 0; + int nphi = isBarrel ? 18 : 16; + int neta = isBarrel ? 8 : 4; + + // inner layer + if (chambername[1] == 'I') return icoord + eta * nphi + phi; + + if (chambername[0] == 'E' || chambername.substr(0, 2) == "BE") { + icoord += nphi * neta; + nphi = 8; + neta = 2; + if (chambername.substr(0, 2) == "BE") return icoord + eta * nphi + phi; + } - icoord += nphi*neta; - nphi=16; - neta=6; - - if (chambername[1]=='O') - return icoord + eta*nphi + phi; + icoord += nphi * neta; + nphi = 16; + neta = (isBarrel) ? 6 : 5; - return -1; + // middle layer + if (chambername[1] == 'M') { + // cout<<"eta: "<<eta<<", phi: "<<phi<<", icoord: "<<icoord<<endl; + return icoord + (eta * nphi) + phi; + } + + icoord += nphi * neta; + nphi = 16; + neta = 6; + + if (chambername[1] == 'O') return icoord + eta * nphi + phi; + + return -1; } //________________________________________________________________________ -int getXcoordinate(const string& chambername) -{ - if (chambername=="") return -999; - - Int_t eta=atoi(chambername.substr(3,1).c_str()); - Int_t Xcor=(chambername[4]=='A')?eta:(eta*(-1)); - //if(chambername[0]=='B') return Xcor; - if((chambername[0]=='E')&&(chambername[4]=='A')) Xcor = Xcor + 10 ; // case Endcap A - if((chambername[0]=='E')&&(chambername[4]=='C')) Xcor = Xcor - 10 ; // case Endcap C - if((chambername[1]=='E')&&(chambername[4]=='A')) Xcor = Xcor -2 ; // case EELA and EESA - if((chambername[1]=='E')&&(chambername[4]=='C')) Xcor = Xcor +2 ; // case EELC adn EESC - if((chambername.substr(0,2)=="BE")&&(chambername[4]=='A')) Xcor = Xcor + 10 ; // case BEEA - if((chambername.substr(0,2)=="BE")&&(chambername[4]=='C')) Xcor = Xcor - 10 ; // case BEEC - - return Xcor; +int getXcoordinate(const string& chambername) { + if (chambername == "") return -999; + + Int_t eta = atoi(chambername.substr(3, 1).c_str()); + Int_t Xcor = (chambername[4] == 'A') ? eta : (eta * (-1)); + // if(chambername[0]=='B') return Xcor; + if ((chambername[0] == 'E') && (chambername[4] == 'A')) Xcor = Xcor + 10; // case Endcap A + if ((chambername[0] == 'E') && (chambername[4] == 'C')) Xcor = Xcor - 10; // case Endcap C + if ((chambername[1] == 'E') && (chambername[4] == 'A')) Xcor = Xcor - 2; // case EELA and EESA + if ((chambername[1] == 'E') && (chambername[4] == 'C')) Xcor = Xcor + 2; // case EELC adn EESC + if ((chambername.substr(0, 2) == "BE") && (chambername[4] == 'A')) Xcor = Xcor + 10; // case BEEA + if ((chambername.substr(0, 2) == "BE") && (chambername[4] == 'C')) Xcor = Xcor - 10; // case BEEC + + return Xcor; } //________________________________________________________________________ -int getYcoordinate(const string& chambername) -{ - if (chambername=="") return -999; - cout<<"chname: "<<chambername<<endl; +int getYcoordinate(const string& chambername) { + if (chambername == "") return -999; + cout << "chname: " << chambername << endl; - Int_t Ycor=atoi(chambername.substr(5,2).c_str()); - cout<<"Ycor: "<<Ycor<<endl; + Int_t Ycor = atoi(chambername.substr(5, 2).c_str()); + cout << "Ycor: " << Ycor << endl; - if((chambername[1]=='I')&&(Ycor>10)) { - if(Ycor==11 && chambername[2]=='R') Ycor = 17; - if(Ycor==15 && chambername[2]=='R') Ycor = 18; - } - if(chambername[1]=='M') Ycor = Ycor + 18 ; - if(chambername[1]=='O') Ycor = Ycor + 34 ; - if((chambername[0]=='E')&&(chambername[1]=='E')) Ycor = Ycor + 18 ; - - return Ycor; + if ((chambername[1] == 'I') && (Ycor > 10)) { + if (Ycor == 11 && chambername[2] == 'R') Ycor = 17; + if (Ycor == 15 && chambername[2] == 'R') Ycor = 18; + } + if (chambername[1] == 'M') Ycor = Ycor + 18; + if (chambername[1] == 'O') Ycor = Ycor + 34; + if ((chambername[0] == 'E') && (chambername[1] == 'E')) Ycor = Ycor + 18; + + return Ycor; } //________________________________________________________________________ -void addSoftConstraints(ChamberDerivs* chDerivs) -{ - std::cout<<"adding soft constraint"<<std::endl; - // add constraints - for (int ich=0;ich<chDerivs->nchambers();ich++) { - for (int ipar=0;ipar<NPAR;ipar++) { - //chDerivs->addConstraint(ich,ipar,1000.); - //chDerivs->addConstraint(ich,ipar,100.); - chDerivs->addConstraint(ich,ipar,10.); +void addSoftConstraints(ChamberDerivs* chDerivs) { + std::cout << "adding soft constraint" << std::endl; + // add constraints + for (int ich = 0; ich < chDerivs->nchambers(); ich++) { + for (int ipar = 0; ipar < NPAR; ipar++) { + // chDerivs->addConstraint(ich,ipar,1000.); + // chDerivs->addConstraint(ich,ipar,100.); + chDerivs->addConstraint(ich, ipar, 10.); + } } - } - return; + return; } //________________________________________________________________________ -void addExternalConstraints(ChamberDerivs* chDerivs, const std::string& filename) -{ - std::ifstream asztFileLastIter; - string dummy; - if (filename!="") { - asztFileLastIter.open(filename.c_str()); - asztFileLastIter>>dummy; - } - - string origType; - int origJff,origJzz,origJob; - - double* initPars=new double[NPAR]; - for (int ipar=0;ipar<NPAR;ipar++) initPars[ipar]=0.; - - double sigma=1.; - for (int ich=0;ich<chDerivs->nchambers();ich++) { - - if (chDerivs->chamberId(ich)<0) continue; - - string chname=m_chNames->chamberName(chDerivs->chamberId(ich)); - cout<<"in externalconstraints, ich "<<ich<<", chname: "<<chname<<endl; - - int jzz=atoi(chname.substr(3,1).c_str()); - if (chname.substr(4,1)=="C") jzz*=-1; - int detphi=atoi(chname.substr(5,2).c_str()); - if (chname.substr(2,1)=="L") detphi++; - int jff=detphi/2; - - if (filename!="") { - asztFileLastIter>>dummy>>origType>>origJff>>origJzz>>origJob; - for (int i=0;i<6;i++) { - double val; - asztFileLastIter>>val; - if (NPAR<6 && i==0) continue; - int ipar=(NPAR==6)?i:i-1; - initPars[ipar]=val; - if (ipar>NPAR-6+2) initPars[ipar]/=m_rotscale; - } - if (!L1ALIGNMENT && (origType!=chname.substr(0,3) || - jff!=origJff || jzz!=origJzz)) { - cout<<"origType: "<<origType<<", chname: "<<chname<<endl; - cout<<"origJff: "<<origJff<<", jff: "<<jff<<endl; - cout<<"origJzz: "<<origJzz<<", jzz: "<<jzz<<endl; - cout<<"bad entry"<<endl; exit(2); - } +void addExternalConstraints(ChamberDerivs* chDerivs, const std::string& filename) { + std::ifstream asztFileLastIter; + string dummy; + if (filename != "") { + asztFileLastIter.open(filename.c_str()); + asztFileLastIter >> dummy; } - /* - for (int ipar=0;ipar<NPAR-3;ipar++) { - chDerivs->addConstraint(ich,ipar,sigma); - cout<<"ich: "<<ich<<", initPars["<<ipar<<"]="<<initPars[ipar]<<endl; - chDerivs->addFirstDerivConstraint(ich,ipar,sigma*initPars[ipar]); - } - */ + string origType; + int origJff, origJzz, origJob; + + double* initPars = new double[NPAR]; + for (int ipar = 0; ipar < NPAR; ipar++) initPars[ipar] = 0.; + + double sigma = 1.; + for (int ich = 0; ich < chDerivs->nchambers(); ich++) { + if (chDerivs->chamberId(ich) < 0) continue; + + string chname = m_chNames->chamberName(chDerivs->chamberId(ich)); + cout << "in externalconstraints, ich " << ich << ", chname: " << chname << endl; + + int jzz = atoi(chname.substr(3, 1).c_str()); + if (chname.substr(4, 1) == "C") jzz *= -1; + int detphi = atoi(chname.substr(5, 2).c_str()); + if (chname.substr(2, 1) == "L") detphi++; + int jff = detphi / 2; + + if (filename != "") { + asztFileLastIter >> dummy >> origType >> origJff >> origJzz >> origJob; + for (int i = 0; i < 6; i++) { + double val; + asztFileLastIter >> val; + if (NPAR < 6 && i == 0) continue; + int ipar = (NPAR == 6) ? i : i - 1; + initPars[ipar] = val; + if (ipar > NPAR - 6 + 2) initPars[ipar] /= m_rotscale; + } + if (!L1ALIGNMENT && (origType != chname.substr(0, 3) || jff != origJff || jzz != origJzz)) { + cout << "origType: " << origType << ", chname: " << chname << endl; + cout << "origJff: " << origJff << ", jff: " << jff << endl; + cout << "origJzz: " << origJzz << ", jzz: " << jzz << endl; + cout << "bad entry" << endl; + exit(2); + } + } - std::cout<<"adding constraints0"<<std::endl; - if (FIX_T) { - double sigma_t=1.e22; - std::cout<<"fixing t"<<std::endl; - chDerivs->addConstraint(ich,1,sigma_t); - chDerivs->addFirstDerivConstraint(ich,1,sigma_t*initPars[1]); - } - if (FIX_ROTZ) { - double sigma_rotz=1.e30; - std::cout<<"fixing rotz"<<std::endl; - chDerivs->addConstraint(ich,3,sigma_rotz); - chDerivs->addFirstDerivConstraint(ich,3,sigma_rotz*initPars[3]); - } - if (FIX_ROTT) { - double sigma_rott=1.e30; - std::cout<<"fixing rott"<<std::endl; - chDerivs->addConstraint(ich,4,sigma_rott); - chDerivs->addFirstDerivConstraint(ich,4,sigma_rott*initPars[4]); + /* + for (int ipar=0;ipar<NPAR-3;ipar++) { + chDerivs->addConstraint(ich,ipar,sigma); + cout<<"ich: "<<ich<<", initPars["<<ipar<<"]="<<initPars[ipar]<<endl; + chDerivs->addFirstDerivConstraint(ich,ipar,sigma*initPars[ipar]); + } + */ + + std::cout << "adding constraints0" << std::endl; + if (FIX_T) { + double sigma_t = 1.e22; + std::cout << "fixing t" << std::endl; + chDerivs->addConstraint(ich, 1, sigma_t); + chDerivs->addFirstDerivConstraint(ich, 1, sigma_t * initPars[1]); + } + if (FIX_ROTZ) { + double sigma_rotz = 1.e30; + std::cout << "fixing rotz" << std::endl; + chDerivs->addConstraint(ich, 3, sigma_rotz); + chDerivs->addFirstDerivConstraint(ich, 3, sigma_rotz * initPars[3]); + } + if (FIX_ROTT) { + double sigma_rott = 1.e30; + std::cout << "fixing rott" << std::endl; + chDerivs->addConstraint(ich, 4, sigma_rott); + chDerivs->addFirstDerivConstraint(ich, 4, sigma_rott * initPars[4]); + } } - } - delete [] initPars; + delete[] initPars; } //________________________________________________________________________ -void addConstraints(ChamberDerivs* chDerivs) -{ +void addConstraints(ChamberDerivs* chDerivs) { + std::cout << "adding constraints1" << std::endl; - std::cout<<"adding constraints1"<<std::endl; - - // add constraints - if (CONSTRAIN_ROTZ) { - if (DEBUG) cout<<"constrain ROTZ"<<endl; - for (int ich=0;ich<chDerivs->nchambers();ich++) - chDerivs->addConstraint(ich,NPAR-6+4,50000.); - } + // add constraints + if (CONSTRAIN_ROTZ) { + if (DEBUG) cout << "constrain ROTZ" << endl; + for (int ich = 0; ich < chDerivs->nchambers(); ich++) chDerivs->addConstraint(ich, NPAR - 6 + 4, 50000.); + } - if (CONSTRAIN_EM) { - if (DEBUG) cout<<"constrain EM"<<endl; - - // EML3A05 - int ich_EML3A05=chDerivs->getChIndex(m_chNames->chamberIdFromString("EML3A05")); - cout<<"chamber: "<<m_chNames->chamberName(m_chNames->chamberIdFromString("EML3A05"))<<endl; - chDerivs->addConstraint(ich_EML3A05,0,14325./2.); // z - chDerivs->addConstraint(ich_EML3A05,1,12900./2.); // t - - // EML3A09 - int ich_EML3A09=chDerivs->getChIndex(m_chNames->chamberIdFromString("EML3A09")); - cout<<"chamber: "<<m_chNames->chamberName(m_chNames->chamberIdFromString("EML3A09"))<<endl; - chDerivs->addConstraint(ich_EML3A09,0,14325./2.); // z - chDerivs->addConstraint(ich_EML3A09,1,12900./2.); // t - - // EML3A13 - int ich_EML3A13=chDerivs->getChIndex(m_chNames->chamberIdFromString("EML3A13")); - cout<<"chamber: "<<m_chNames->chamberName(m_chNames->chamberIdFromString("EML3A13"))<<endl; - chDerivs->addConstraint(ich_EML3A13,1,12900./2.); // t - - // EML3C05 - int ich_EML3C05=chDerivs->getChIndex(m_chNames->chamberIdFromString("EML3C05")); - cout<<"chamber: "<<m_chNames->chamberName(m_chNames->chamberIdFromString("EML3C05"))<<endl; - chDerivs->addConstraint(ich_EML3C05,0,14325./2.); // z - chDerivs->addConstraint(ich_EML3C05,1,12900./2.); // t - - // EML3C09 - int ich_EML3C09=chDerivs->getChIndex(m_chNames->chamberIdFromString("EML3C09")); - cout<<"chamber: "<<m_chNames->chamberName(m_chNames->chamberIdFromString("EML3C09"))<<endl; - chDerivs->addConstraint(ich_EML3C09,0,14325./2.); // z - chDerivs->addConstraint(ich_EML3C09,1,12900./2.); // t - - // EML3C13 - int ich_EML3C13=chDerivs->getChIndex(m_chNames->chamberIdFromString("EML3C13")); - cout<<"chamber: "<<m_chNames->chamberName(m_chNames->chamberIdFromString("EML3C13"))<<endl; - chDerivs->addConstraint(ich_EML3C13,1,12900./2.); // t - } + if (CONSTRAIN_EM) { + if (DEBUG) cout << "constrain EM" << endl; + + // EML3A05 + int ich_EML3A05 = chDerivs->getChIndex(m_chNames->chamberIdFromString("EML3A05")); + cout << "chamber: " << m_chNames->chamberName(m_chNames->chamberIdFromString("EML3A05")) << endl; + chDerivs->addConstraint(ich_EML3A05, 0, 14325. / 2.); // z + chDerivs->addConstraint(ich_EML3A05, 1, 12900. / 2.); // t + + // EML3A09 + int ich_EML3A09 = chDerivs->getChIndex(m_chNames->chamberIdFromString("EML3A09")); + cout << "chamber: " << m_chNames->chamberName(m_chNames->chamberIdFromString("EML3A09")) << endl; + chDerivs->addConstraint(ich_EML3A09, 0, 14325. / 2.); // z + chDerivs->addConstraint(ich_EML3A09, 1, 12900. / 2.); // t + + // EML3A13 + int ich_EML3A13 = chDerivs->getChIndex(m_chNames->chamberIdFromString("EML3A13")); + cout << "chamber: " << m_chNames->chamberName(m_chNames->chamberIdFromString("EML3A13")) << endl; + chDerivs->addConstraint(ich_EML3A13, 1, 12900. / 2.); // t + + // EML3C05 + int ich_EML3C05 = chDerivs->getChIndex(m_chNames->chamberIdFromString("EML3C05")); + cout << "chamber: " << m_chNames->chamberName(m_chNames->chamberIdFromString("EML3C05")) << endl; + chDerivs->addConstraint(ich_EML3C05, 0, 14325. / 2.); // z + chDerivs->addConstraint(ich_EML3C05, 1, 12900. / 2.); // t + + // EML3C09 + int ich_EML3C09 = chDerivs->getChIndex(m_chNames->chamberIdFromString("EML3C09")); + cout << "chamber: " << m_chNames->chamberName(m_chNames->chamberIdFromString("EML3C09")) << endl; + chDerivs->addConstraint(ich_EML3C09, 0, 14325. / 2.); // z + chDerivs->addConstraint(ich_EML3C09, 1, 12900. / 2.); // t + + // EML3C13 + int ich_EML3C13 = chDerivs->getChIndex(m_chNames->chamberIdFromString("EML3C13")); + cout << "chamber: " << m_chNames->chamberName(m_chNames->chamberIdFromString("EML3C13")) << endl; + chDerivs->addConstraint(ich_EML3C13, 1, 12900. / 2.); // t + } - if (CONSTRAIN_EI) { - if (DEBUG) cout<<"constrain EI"<<endl; - - // EIL1A05 - int ich_EIL1A05=chDerivs->getChIndex(m_chNames->chamberIdFromString("EIL1A05")); - cout<<"chamber: "<<m_chNames->chamberName(m_chNames->chamberIdFromString("EIL1A05"))<<endl; - chDerivs->addConstraint(ich_EIL1A05,0,14325./2.); // z - chDerivs->addConstraint(ich_EIL1A05,1,12900./2.); // t - - // EIL1A09 - int ich_EIL1A09=chDerivs->getChIndex(m_chNames->chamberIdFromString("EIL1A09")); - cout<<"chamber: "<<m_chNames->chamberName(m_chNames->chamberIdFromString("EIL1A09"))<<endl; - chDerivs->addConstraint(ich_EIL1A09,0,14325./2.); // z - chDerivs->addConstraint(ich_EIL1A09,1,12900./2.); // t - - // EIL1A13 - int ich_EIL1A13=chDerivs->getChIndex(m_chNames->chamberIdFromString("EIL1A13")); - cout<<"chamber: "<<m_chNames->chamberName(m_chNames->chamberIdFromString("EIL1A13"))<<endl; - chDerivs->addConstraint(ich_EIL1A13,1,12900./2.); // t - - // EIL1C05 - int ich_EIL1C05=chDerivs->getChIndex(m_chNames->chamberIdFromString("EIL1C05")); - cout<<"chamber: "<<m_chNames->chamberName(m_chNames->chamberIdFromString("EIL1C05"))<<endl; - chDerivs->addConstraint(ich_EIL1C05,0,14325./2.); // z - chDerivs->addConstraint(ich_EIL1C05,1,12900./2.); // t - - // EIL1C09 - int ich_EIL1C09=chDerivs->getChIndex(m_chNames->chamberIdFromString("EIL1C09")); - cout<<"chamber: "<<m_chNames->chamberName(m_chNames->chamberIdFromString("EIL1C09"))<<endl; - chDerivs->addConstraint(ich_EIL1C09,0,14325./2.); // z - chDerivs->addConstraint(ich_EIL1C09,1,12900./2.); // t - - // EIL1C13 - int ich_EIL1C13=chDerivs->getChIndex(m_chNames->chamberIdFromString("EIL1C13")); - cout<<"chamber: "<<m_chNames->chamberName(m_chNames->chamberIdFromString("EIL1C13"))<<endl; - chDerivs->addConstraint(ich_EIL1C13,1,12900./2.); // t - } + if (CONSTRAIN_EI) { + if (DEBUG) cout << "constrain EI" << endl; + + // EIL1A05 + int ich_EIL1A05 = chDerivs->getChIndex(m_chNames->chamberIdFromString("EIL1A05")); + cout << "chamber: " << m_chNames->chamberName(m_chNames->chamberIdFromString("EIL1A05")) << endl; + chDerivs->addConstraint(ich_EIL1A05, 0, 14325. / 2.); // z + chDerivs->addConstraint(ich_EIL1A05, 1, 12900. / 2.); // t + + // EIL1A09 + int ich_EIL1A09 = chDerivs->getChIndex(m_chNames->chamberIdFromString("EIL1A09")); + cout << "chamber: " << m_chNames->chamberName(m_chNames->chamberIdFromString("EIL1A09")) << endl; + chDerivs->addConstraint(ich_EIL1A09, 0, 14325. / 2.); // z + chDerivs->addConstraint(ich_EIL1A09, 1, 12900. / 2.); // t + + // EIL1A13 + int ich_EIL1A13 = chDerivs->getChIndex(m_chNames->chamberIdFromString("EIL1A13")); + cout << "chamber: " << m_chNames->chamberName(m_chNames->chamberIdFromString("EIL1A13")) << endl; + chDerivs->addConstraint(ich_EIL1A13, 1, 12900. / 2.); // t + + // EIL1C05 + int ich_EIL1C05 = chDerivs->getChIndex(m_chNames->chamberIdFromString("EIL1C05")); + cout << "chamber: " << m_chNames->chamberName(m_chNames->chamberIdFromString("EIL1C05")) << endl; + chDerivs->addConstraint(ich_EIL1C05, 0, 14325. / 2.); // z + chDerivs->addConstraint(ich_EIL1C05, 1, 12900. / 2.); // t + + // EIL1C09 + int ich_EIL1C09 = chDerivs->getChIndex(m_chNames->chamberIdFromString("EIL1C09")); + cout << "chamber: " << m_chNames->chamberName(m_chNames->chamberIdFromString("EIL1C09")) << endl; + chDerivs->addConstraint(ich_EIL1C09, 0, 14325. / 2.); // z + chDerivs->addConstraint(ich_EIL1C09, 1, 12900. / 2.); // t + + // EIL1C13 + int ich_EIL1C13 = chDerivs->getChIndex(m_chNames->chamberIdFromString("EIL1C13")); + cout << "chamber: " << m_chNames->chamberName(m_chNames->chamberIdFromString("EIL1C13")) << endl; + chDerivs->addConstraint(ich_EIL1C13, 1, 12900. / 2.); // t + } - return; + return; } //________________________________________________________________________ -void getAllSingularValues(const ChamberDerivs& chDerivs, vector<double>& svArray) -{ - svArray.clear(); - - for (int ich=0;ich<chDerivs.nchambers();ich++) { - vector<double> sv; const TMatrixD *u,*vinv; - chDerivs.singularValues(sv,u,vinv,ich); - delete u; delete vinv; - - double minval=1.e20; - for (int ipar=0;ipar<(int)sv.size();ipar++) { - if (sv[ipar]<minval) minval=sv[ipar]; +void getAllSingularValues(const ChamberDerivs& chDerivs, vector<double>& svArray) { + svArray.clear(); + + for (int ich = 0; ich < chDerivs.nchambers(); ich++) { + vector<double> sv; + const TMatrixD *u, *vinv; + chDerivs.singularValues(sv, u, vinv, ich); + delete u; + delete vinv; + + double minval = 1.e20; + for (int ipar = 0; ipar < (int)sv.size(); ipar++) { + if (sv[ipar] < minval) minval = sv[ipar]; + } + svArray.push_back(minval); } - svArray.push_back(minval); - } - return; + return; } //________________________________________________________________________ -void makeSomePlots(const ChamberDerivs& chDerivs) -{ - - vector<double> svArray; - getAllSingularValues(chDerivs,svArray); - - // histogram to store t vs. determinant - TH2F* h_tVCond=new TH2F("h_tVCond","t vs. condition number",100,2.2,4.2,50,-20.,20.); - TH2F* h_tVSV =new TH2F("h_tVSV","log10(t) vs. log10(min singular value)",100,1.,9.,50,-6.,3.); - - // solve for global parameters - cout<<"-----------------------------------------------"<<endl; - cout<<"Solving for global parameters"<<endl; - double* err(0); - double* res=chDerivs.solve(err,-1,ChamberDerivs::ROOT); - for (int ich=0;ich<chDerivs.nchambers();ich++) { - - string chname=m_chNames->chamberName(chDerivs.chamberId(ich)); - cout<<"(ROOT) ch: "<<chDerivs.chamberId(ich) - <<", ntracks: "<<chDerivs.nhits(ich,ich) - <<" ("<<chname<<")"<<endl; - for (int ipar=0;ipar<NPAR;ipar++) { - int i=ich*NPAR+ipar; - cout<<" "<<i<<": "<<res[i]<<" +/- "<<err[i]<<endl; +void makeSomePlots(const ChamberDerivs& chDerivs) { + vector<double> svArray; + getAllSingularValues(chDerivs, svArray); + + // histogram to store t vs. determinant + TH2F* h_tVCond = new TH2F("h_tVCond", "t vs. condition number", 100, 2.2, 4.2, 50, -20., 20.); + TH2F* h_tVSV = new TH2F("h_tVSV", "log10(t) vs. log10(min singular value)", 100, 1., 9., 50, -6., 3.); + + // solve for global parameters + cout << "-----------------------------------------------" << endl; + cout << "Solving for global parameters" << endl; + double* err(0); + double* res = chDerivs.solve(err, -1, ChamberDerivs::ROOT); + for (int ich = 0; ich < chDerivs.nchambers(); ich++) { + string chname = m_chNames->chamberName(chDerivs.chamberId(ich)); + cout << "(ROOT) ch: " << chDerivs.chamberId(ich) << ", ntracks: " << chDerivs.nhits(ich, ich) << " (" << chname << ")" << endl; + for (int ipar = 0; ipar < NPAR; ipar++) { + int i = ich * NPAR + ipar; + cout << " " << i << ": " << res[i] << " +/- " << err[i] << endl; + } + cout << endl; + + // fill histogram with determinant for local 2nd deriv matrix + if (chname[4] == 'A' || !DO_EC_ONLY) { + double cond = chDerivs.condition(ich); + int ipar = ich * NPAR + NPAR - 6 + 2; // z-parameter + cout << "ich: " << ich << ", cond: " << cond << ", res: " << res[ipar] << endl; + h_tVCond->Fill(log10(cond), res[ipar]); + h_tVSV->Fill(log10(svArray[ich]), log10(std::fabs(res[ipar]))); + } + } + delete[] res; + delete[] err; + + TCanvas* canv_tvcond = new TCanvas("canv_tvcond", "align t vs. condition number"); + h_tVCond->Draw("colz"); + canv_tvcond->Print("tvcond.eps"); + delete canv_tvcond; + + TCanvas* canv_tvsv = new TCanvas("canv_tvsv", "align t vs. singular value"); + h_tVSV->Draw("colz"); + canv_tvsv->Print("tvsv.eps"); + delete canv_tvsv; + + int xsize = 7000; + if (DO_EC_ONLY) + xsize = 3000; + else if (DO_ASIDE_ONLY) + xsize = 4000; + + // TCanvas* canv=new TCanvas("canv","canv"); + // canv->SetFillColor(10); + // makeHitmap(chDerivs,canv); + // canv->Print("hitmap.eps"); + + TCanvas** canvAP = new TCanvas*[NPAR]; + TCanvas** canvAP2 = new TCanvas*[NPAR]; + for (int ipar = 0; ipar < NPAR; ipar++) { + stringstream canvname; + canvname << "alignPar_" << ipar; + canvAP[ipar] = new TCanvas(canvname.str().c_str(), canvname.str().c_str()); + canvAP[ipar]->SetFillColor(10); + + stringstream canvname2; + canvname2 << "alignPar_" << ipar << "_2"; + canvAP2[ipar] = new TCanvas(canvname2.str().c_str(), canvname2.str().c_str()); + canvAP2[ipar]->SetFillColor(10); } - cout<<endl; - - // fill histogram with determinant for local 2nd deriv matrix - if (chname[4]=='A' || !DO_EC_ONLY) { - double cond=chDerivs.condition(ich); - int ipar=ich*NPAR+NPAR-6+2; // z-parameter - cout<<"ich: "<<ich<<", cond: "<<cond<<", res: "<<res[ipar]<<endl; - h_tVCond->Fill(log10(cond),res[ipar]); - h_tVSV->Fill(log10(svArray[ich]),log10(std::fabs(res[ipar]))); - } - } - delete [] res; - delete [] err; - - TCanvas* canv_tvcond=new TCanvas("canv_tvcond","align t vs. condition number"); - h_tVCond->Draw("colz"); - canv_tvcond->Print("tvcond.eps"); - delete canv_tvcond; - - TCanvas* canv_tvsv=new TCanvas("canv_tvsv","align t vs. singular value"); - h_tVSV->Draw("colz"); - canv_tvsv->Print("tvsv.eps"); - delete canv_tvsv; - - int xsize=7000; - if (DO_EC_ONLY) xsize=3000; - else if (DO_ASIDE_ONLY) xsize=4000; - - //TCanvas* canv=new TCanvas("canv","canv"); - //canv->SetFillColor(10); - //makeHitmap(chDerivs,canv); - //canv->Print("hitmap.eps"); - - TCanvas** canvAP =new TCanvas*[NPAR]; - TCanvas** canvAP2=new TCanvas*[NPAR]; - for (int ipar=0;ipar<NPAR;ipar++) { - stringstream canvname; canvname<<"alignPar_"<<ipar; - canvAP[ipar]=new TCanvas(canvname.str().c_str(),canvname.str().c_str()); - canvAP[ipar]->SetFillColor(10); - - stringstream canvname2; canvname2<<"alignPar_"<<ipar<<"_2"; - canvAP2[ipar]=new TCanvas(canvname2.str().c_str(),canvname2.str().c_str()); - canvAP2[ipar]->SetFillColor(10); - } - make2DAlignHists(chDerivs,(TPad**)canvAP, (TPad**)canvAP2); - for (int ipar=0;ipar<NPAR;ipar++) { - stringstream epsname; epsname<<"alignPar_"<<ipar<<".eps"; - canvAP[ipar]->Print(epsname.str().c_str()); + make2DAlignHists(chDerivs, (TPad**)canvAP, (TPad**)canvAP2); + for (int ipar = 0; ipar < NPAR; ipar++) { + stringstream epsname; + epsname << "alignPar_" << ipar << ".eps"; + canvAP[ipar]->Print(epsname.str().c_str()); - stringstream epsname2; epsname2<<"alignParVNTrks_"<<ipar<<".eps"; - canvAP2[ipar]->Print(epsname2.str().c_str()); - } + stringstream epsname2; + epsname2 << "alignParVNTrks_" << ipar << ".eps"; + canvAP2[ipar]->Print(epsname2.str().c_str()); + } - TCanvas* canv=new TCanvas("canv","canv"); - canv->SetFillColor(10); - double ranges[NPAR]={RANGE_TRA,RANGE_TRA,RANGE_ROTS,RANGE_ROTZT,RANGE_ROTZT}; - TH1F** alignParHists=alignParDist(chDerivs,"alignParDist",ranges); - TF1** alignParFits=new TF1*[NPAR]; - for (int ipar=0;ipar<NPAR;ipar++) { - canv->Clear(); - alignParHists[ipar]->Draw(); - alignParHists[ipar]->SetLineWidth(.5); - - stringstream fitstr; fitstr<<"gaus_"<<ipar; - alignParFits[ipar]=new TF1(fitstr.str().c_str(),"gaus",-1.5,1.5); - alignParHists[ipar]->Fit(alignParFits[ipar],"QR"); - alignParFits[ipar]->SetLineWidth(1.); - - int thispar=ipar+6-NPAR; - alignParHists[ipar]->GetXaxis()->SetTitle((parstr[thispar]+" ("+unitstr[thispar]+")").c_str()); - stringstream histname; histname<<"alignParDist_"<<ipar<<".eps"; - canv->Print(histname.str().c_str()); - } - delete [] alignParHists; - delete [] alignParFits; + TCanvas* canv = new TCanvas("canv", "canv"); + canv->SetFillColor(10); + double ranges[NPAR] = {RANGE_TRA, RANGE_TRA, RANGE_ROTS, RANGE_ROTZT, RANGE_ROTZT}; + TH1F** alignParHists = alignParDist(chDerivs, "alignParDist", ranges); + TF1** alignParFits = new TF1*[NPAR]; + for (int ipar = 0; ipar < NPAR; ipar++) { + canv->Clear(); + alignParHists[ipar]->Draw(); + alignParHists[ipar]->SetLineWidth(.5); + + stringstream fitstr; + fitstr << "gaus_" << ipar; + alignParFits[ipar] = new TF1(fitstr.str().c_str(), "gaus", -1.5, 1.5); + alignParHists[ipar]->Fit(alignParFits[ipar], "QR"); + alignParFits[ipar]->SetLineWidth(1.); + + int thispar = ipar + 6 - NPAR; + alignParHists[ipar]->GetXaxis()->SetTitle((parstr[thispar] + " (" + unitstr[thispar] + ")").c_str()); + stringstream histname; + histname << "alignParDist_" << ipar << ".eps"; + canv->Print(histname.str().c_str()); + } + delete[] alignParHists; + delete[] alignParFits; } //________________________________________________________________________ -TH1F** alignParDist(const ChamberDerivs& chDerivs, const string& histname, - double* ranges) -{ - double* err(0); - double* res=chDerivs.solve(err,-1,ChamberDerivs::ROOT); - - TH1F** hists=new TH1F*[NPAR]; - for (int ipar=0;ipar<NPAR;ipar++) { - double range=10.; - if (ranges) range=ranges[ipar]; - stringstream name; name<<histname<<"_"<<ipar; - hists[ipar]=new TH1F(name.str().c_str(),name.str().c_str(), - 30,-range,range); - - for (int ich=0;ich<chDerivs.nchambers();ich++) { - int i=ich*NPAR+ipar; - double result=res[i]; - hists[ipar]->Fill(result); +TH1F** alignParDist(const ChamberDerivs& chDerivs, const string& histname, double* ranges) { + double* err(0); + double* res = chDerivs.solve(err, -1, ChamberDerivs::ROOT); + + TH1F** hists = new TH1F*[NPAR]; + for (int ipar = 0; ipar < NPAR; ipar++) { + double range = 10.; + if (ranges) range = ranges[ipar]; + stringstream name; + name << histname << "_" << ipar; + hists[ipar] = new TH1F(name.str().c_str(), name.str().c_str(), 30, -range, range); + + for (int ich = 0; ich < chDerivs.nchambers(); ich++) { + int i = ich * NPAR + ipar; + double result = res[i]; + hists[ipar]->Fill(result); + } } - } - return hists; + return hists; } //________________________________________________________________________ -void plotDiagonalCutHists(bool offdiag) -{ - const int NTRKHISTS=5; - TH1F*** trkHists=new TH1F**[NTRKHISTS]; - TF1*** trkHistFits =new TF1 **[NTRKHISTS]; - TPaveStats*** trkHistStats=new TPaveStats**[NTRKHISTS]; - - int* ntrksdiag(new int[NTRKHISTS]), *ntrksoffdiag(new int[NTRKHISTS]); - for (int itrk=0;itrk<NTRKHISTS;itrk++) { - ntrksdiag[itrk]=(offdiag)?5000:1000+2000*itrk; - ntrksoffdiag[itrk]=(offdiag)?400*400*itrk:400; - - ChamberDerivs trkChDerivs= - m_allChDerivs->trimmedChamberDerivs(ntrksdiag[itrk],ntrksoffdiag[itrk]); - stringstream histname; - histname<<"ntrks_"<<ntrksdiag[itrk]<<"_"<<ntrksoffdiag[itrk]<<"_alignPar"; - trkHists[itrk]=alignParDist(trkChDerivs,histname.str()); - trkHistFits[itrk]=new TF1*[NPAR]; - trkHistStats[itrk]=new TPaveStats*[NPAR]; - } +void plotDiagonalCutHists(bool offdiag) { + const int NTRKHISTS = 5; + TH1F*** trkHists = new TH1F**[NTRKHISTS]; + TF1*** trkHistFits = new TF1**[NTRKHISTS]; + TPaveStats*** trkHistStats = new TPaveStats**[NTRKHISTS]; + + int *ntrksdiag(new int[NTRKHISTS]), *ntrksoffdiag(new int[NTRKHISTS]); + for (int itrk = 0; itrk < NTRKHISTS; itrk++) { + ntrksdiag[itrk] = (offdiag) ? 5000 : 1000 + 2000 * itrk; + ntrksoffdiag[itrk] = (offdiag) ? 400 * 400 * itrk : 400; + + ChamberDerivs trkChDerivs = m_allChDerivs->trimmedChamberDerivs(ntrksdiag[itrk], ntrksoffdiag[itrk]); + stringstream histname; + histname << "ntrks_" << ntrksdiag[itrk] << "_" << ntrksoffdiag[itrk] << "_alignPar"; + trkHists[itrk] = alignParDist(trkChDerivs, histname.str()); + trkHistFits[itrk] = new TF1*[NPAR]; + trkHistStats[itrk] = new TPaveStats*[NPAR]; + } - TLegend** legs=new TLegend*[NPAR]; - TCanvas* ctmp=new TCanvas("ctmp","ctmp"); - int colors[NTRKHISTS]={kRed,kGreen,kBlue,kMagenta,kCyan}; - TCanvas* canvTrkHists=new TCanvas("canvTrkHists","canvTrkHists"); - int optfit=gStyle->GetOptFit(); - int optstat=gStyle->GetOptStat(); - gStyle->SetOptStat(11); - gStyle->SetOptFit(11); - canvTrkHists->SetFillColor(10); - //canvTrkHists->Divide(3,2); - for (int ipar=0;ipar<NPAR;ipar++) { - if (ipar!=1) continue; - stringstream fitname; fitname<<"trkHistFit_"<<ipar; - double y2pos(0.),deltay(0.),x2pos(0),deltax(0.); - - legs[ipar]=new TLegend(.5,.7,.7,.85); - for (int itrk=0;itrk<NTRKHISTS;itrk++) { - // fit to gaussian - ctmp->cd(); - trkHistFits[itrk][ipar]=new TF1(fitname.str().c_str(),"gaus",-8.,8.); - trkHists [itrk][ipar]->Fit(trkHistFits[itrk][ipar],"QR"); - trkHistFits[itrk][ipar]->SetLineColor(colors[itrk]); - trkHistFits[itrk][ipar]->SetLineWidth(1); - - //canvTrkHists->cd(ipar+2); - canvTrkHists->cd(); - trkHists[itrk][ipar]->SetLineColor(colors[itrk]); - trkHists[itrk][ipar]->SetLineWidth(.5); - if (itrk==0) - trkHists[itrk][ipar]->Draw(); - else - trkHists[itrk][ipar]->Draw("sames"); - trkHistFits[itrk][ipar]->Draw("sames"); - - canvTrkHists->Update(); - trkHistStats[itrk][ipar]= - (TPaveStats*)trkHists[itrk][ipar]->GetFunction("stats"); - TPaveStats* p=trkHistStats[itrk][ipar]; - if (!p) { - cout<<"no TPaveStats!"<<endl; - exit(3); - } - if (itrk==0) { - x2pos=p->GetX2NDC(); - y2pos=p->GetY2NDC(); - deltax=p->GetX2NDC()-p->GetX1NDC(); - deltay=p->GetY2NDC()-p->GetY1NDC(); - deltax*=.6; - deltay*=.6; - } - else y2pos-=deltay; - - p->SetY2NDC(y2pos); - p->SetY1NDC(y2pos-deltay); - if (itrk>NTRKHISTS/2-1) x2pos=.2+deltax; - p->SetX1NDC(x2pos-deltax); - p->SetX2NDC(x2pos); - - p->SetTextColor(colors[itrk]); - canvTrkHists->Modified(); - - cout<<"x1/x2: "<<p->GetX1NDC()<<"/"<<p->GetX2NDC()<<endl; - cout<<"y1/y2: "<<p->GetY1NDC()<<"/"<<p->GetY2NDC()<<endl<<endl; - //p->Draw(); - //canvTrkHists->Modified(); - - //stringstream legentry; legentry<<ntrksdiag[itrk]<<" "<<ntrksoffdiag[itrk]; - //legs[ipar]->AddEntry(trkHistFits[itrk][ipar],legentry.str().c_str(),"l"); + TLegend** legs = new TLegend*[NPAR]; + TCanvas* ctmp = new TCanvas("ctmp", "ctmp"); + int colors[NTRKHISTS] = {kRed, kGreen, kBlue, kMagenta, kCyan}; + TCanvas* canvTrkHists = new TCanvas("canvTrkHists", "canvTrkHists"); + int optfit = gStyle->GetOptFit(); + int optstat = gStyle->GetOptStat(); + gStyle->SetOptStat(11); + gStyle->SetOptFit(11); + canvTrkHists->SetFillColor(10); + // canvTrkHists->Divide(3,2); + for (int ipar = 0; ipar < NPAR; ipar++) { + if (ipar != 1) continue; + stringstream fitname; + fitname << "trkHistFit_" << ipar; + double y2pos(0.), deltay(0.), x2pos(0), deltax(0.); + + legs[ipar] = new TLegend(.5, .7, .7, .85); + for (int itrk = 0; itrk < NTRKHISTS; itrk++) { + // fit to gaussian + ctmp->cd(); + trkHistFits[itrk][ipar] = new TF1(fitname.str().c_str(), "gaus", -8., 8.); + trkHists[itrk][ipar]->Fit(trkHistFits[itrk][ipar], "QR"); + trkHistFits[itrk][ipar]->SetLineColor(colors[itrk]); + trkHistFits[itrk][ipar]->SetLineWidth(1); + + // canvTrkHists->cd(ipar+2); + canvTrkHists->cd(); + trkHists[itrk][ipar]->SetLineColor(colors[itrk]); + trkHists[itrk][ipar]->SetLineWidth(.5); + if (itrk == 0) + trkHists[itrk][ipar]->Draw(); + else + trkHists[itrk][ipar]->Draw("sames"); + trkHistFits[itrk][ipar]->Draw("sames"); + + canvTrkHists->Update(); + trkHistStats[itrk][ipar] = (TPaveStats*)trkHists[itrk][ipar]->GetFunction("stats"); + TPaveStats* p = trkHistStats[itrk][ipar]; + if (!p) { + cout << "no TPaveStats!" << endl; + exit(3); + } + if (itrk == 0) { + x2pos = p->GetX2NDC(); + y2pos = p->GetY2NDC(); + deltax = p->GetX2NDC() - p->GetX1NDC(); + deltay = p->GetY2NDC() - p->GetY1NDC(); + deltax *= .6; + deltay *= .6; + } else + y2pos -= deltay; + + p->SetY2NDC(y2pos); + p->SetY1NDC(y2pos - deltay); + if (itrk > NTRKHISTS / 2 - 1) x2pos = .2 + deltax; + p->SetX1NDC(x2pos - deltax); + p->SetX2NDC(x2pos); + + p->SetTextColor(colors[itrk]); + canvTrkHists->Modified(); + + cout << "x1/x2: " << p->GetX1NDC() << "/" << p->GetX2NDC() << endl; + cout << "y1/y2: " << p->GetY1NDC() << "/" << p->GetY2NDC() << endl << endl; + // p->Draw(); + // canvTrkHists->Modified(); + + // stringstream legentry; legentry<<ntrksdiag[itrk]<<" "<<ntrksoffdiag[itrk]; + // legs[ipar]->AddEntry(trkHistFits[itrk][ipar],legentry.str().c_str(),"l"); + } + // legs[ipar]->Draw(); } - //legs[ipar]->Draw(); - } - if (offdiag) - canvTrkHists->Print("trkHistsOffDiag.eps"); - else - canvTrkHists->Print("trkHistsDiag.eps"); + if (offdiag) + canvTrkHists->Print("trkHistsOffDiag.eps"); + else + canvTrkHists->Print("trkHistsDiag.eps"); - delete [] trkHists; - delete [] trkHistFits; - delete [] trkHistStats; + delete[] trkHists; + delete[] trkHistFits; + delete[] trkHistStats; - delete [] ntrksdiag; - delete [] ntrksoffdiag; + delete[] ntrksdiag; + delete[] ntrksoffdiag; - delete ctmp; - gStyle->SetOptFit(optfit); - gStyle->SetOptStat(optstat); + delete ctmp; + gStyle->SetOptFit(optfit); + gStyle->SetOptStat(optstat); -return; + return; } //________________________________________________________________________ -bool trackSelection() -{ - if (L1ALIGNMENT) return true; - - if (!DO_EE_ONLY) { - - if (m_sd_nChambers<3) return false; - - for (int ich=0;ich<m_sd_nChambers;ich++) { - int chid=m_sd_chamberIds[ich]; - string chname=m_chNames->chamberName(chid); - - // remove BEE tracks - if (chname.substr(0,4)=="EIS2" || chname.substr(0,4)=="EIS1") { - for (int jch=0;jch<m_sd_nChambers;jch++) { - int jid=m_sd_chamberIds[jch]; - string jname=m_chNames->chamberName(jid).substr(0,4); - if (jname=="EOS3"||jname=="EOS4"||jname=="EOS5"||jname=="EOS6") - return false; - } - } - - // remove CSC tracks - if (chname.substr(0,2)=="EM" - && chname.substr(3,1)=="1") return false; - if (chname.substr(0,2)=="EO" - && ( chname.substr(3,1)=="1" - || chname.substr(3,1)=="2" )) return false; - } - } - else { - - // get number of inner, middle, and outer layer hits - - // cout<<"nInnerLayerHits:"<<nInnerLayersHit<<", nMiddleLayerHits:"<<nMiddleLayersHit - // <<", nOuterLayerHits:"<<nOuterLayersHit<<endl; - if (nInnerLayersHit<8||nMiddleLayersHit<6||nOuterLayersHit<6) return false; - - bool hasEEL=false; - bool hasEE=false; - for (int ich=0;ich<m_sd_nChambers;ich++) { - int chid=m_sd_chamberIds[ich]; - string chname=m_chNames->chamberName(chid); - if (chname.substr(0,3)=="BEE" || chname.substr(0,3)=="EEL") { - hasEE=true; - if (chname.substr(0,3)=="EEL") hasEEL=true; - break; - } +bool trackSelection() { + if (L1ALIGNMENT) return true; + + if (!DO_EE_ONLY) { + if (m_sd_nChambers < 3) return false; + + for (int ich = 0; ich < m_sd_nChambers; ich++) { + int chid = m_sd_chamberIds[ich]; + string chname = m_chNames->chamberName(chid); + + // remove BEE tracks + if (chname.substr(0, 4) == "EIS2" || chname.substr(0, 4) == "EIS1") { + for (int jch = 0; jch < m_sd_nChambers; jch++) { + int jid = m_sd_chamberIds[jch]; + string jname = m_chNames->chamberName(jid).substr(0, 4); + if (jname == "EOS3" || jname == "EOS4" || jname == "EOS5" || jname == "EOS6") return false; + } + } + + // remove CSC tracks + if (chname.substr(0, 2) == "EM" && chname.substr(3, 1) == "1") return false; + if (chname.substr(0, 2) == "EO" && (chname.substr(3, 1) == "1" || chname.substr(3, 1) == "2")) return false; + } + } else { + // get number of inner, middle, and outer layer hits + + // cout<<"nInnerLayerHits:"<<nInnerLayersHit<<", nMiddleLayerHits:"<<nMiddleLayersHit + // <<", nOuterLayerHits:"<<nOuterLayersHit<<endl; + if (nInnerLayersHit < 8 || nMiddleLayersHit < 6 || nOuterLayersHit < 6) return false; + + bool hasEEL = false; + bool hasEE = false; + for (int ich = 0; ich < m_sd_nChambers; ich++) { + int chid = m_sd_chamberIds[ich]; + string chname = m_chNames->chamberName(chid); + if (chname.substr(0, 3) == "BEE" || chname.substr(0, 3) == "EEL") { + hasEE = true; + if (chname.substr(0, 3) == "EEL") hasEEL = true; + break; + } + } + if (!hasEE) return false; + /*if (hasEEL) + cout<<"nInnerLayerHits:"<<nInnerLayersHit<<", nMiddleLayerHits:"<<nMiddleLayersHit + <<", nOuterLayerHits:"<<nOuterLayersHit<<endl; + */ } - if (!hasEE) return false; - /*if (hasEEL) - cout<<"nInnerLayerHits:"<<nInnerLayersHit<<", nMiddleLayerHits:"<<nMiddleLayersHit - <<", nOuterLayerHits:"<<nOuterLayersHit<<endl; - */ - } - - return true; + return true; } /* @@ -2147,28 +2037,28 @@ void getFinalPars(double* initPar, double* deltas, double* finalPars) double tras(0.), traz(0.), trat(0.), rots(0.), rotz(0.), rott(0.); double dtras(0.),dtraz(0.),dtrat(0.),drots(0.),drotz(0.),drott(0.); int firsti=0; - if (NPAR==6) { - tras=initPar[0]; - dtras=deltas[0]; - firsti=1; + if (NPAR==6) { + tras=initPar[0]; + dtras=deltas[0]; + firsti=1; } - traz=initPar[firsti]; dtraz=deltas[firsti++]; + traz=initPar[firsti]; dtraz=deltas[firsti++]; trat=initPar[firsti]; dtrat=deltas[firsti++]; - rots=initPar[firsti]; drots=deltas[firsti++]; - rotz=initPar[firsti]; drotz=deltas[firsti++]; + rots=initPar[firsti]; drots=deltas[firsti++]; + rotz=initPar[firsti]; drotz=deltas[firsti++]; rott=initPar[firsti]; drott=deltas[firsti++]; HepGeom::Transform3D init(TranslateX3D(trat)*TranslateY3D(tras)* - TranslateZ3D(traz)*RotateX3D(rott)* - RotateY3D(rots)*RotateZ3D(rotz)); - + TranslateZ3D(traz)*RotateX3D(rott)* + RotateY3D(rots)*RotateZ3D(rotz)); + HepGeom::Transform3D delta(TranslateX3D(dtrat)*TranslateY3D(dtras)* - TranslateZ3D(dtraz)*RotateX3D(drott)* - RotateY3D(drots)*RotateZ3D(drotz)); - + TranslateZ3D(dtraz)*RotateX3D(drott)* + RotateY3D(drots)*RotateZ3D(drotz)); + //cout<<"init: "<<init[0][3]<<" "<<init[1][3]<<" "<<init[2][3]<<endl; //cout<<"delta: "<<delta[0][3]<<" "<<delta[1][3]<<" "<<delta[2][3]<<endl; - + double* vals=new double[6]; HepGeom::Transform3D prod=delta*init; //cout<<"prod: "<<prod[0][3]<<" "<<prod[1][3]<<" "<<prod[2][3]<<endl; @@ -2177,15 +2067,15 @@ void getFinalPars(double* initPar, double* deltas, double* finalPars) //for (int i=0;i<6;i++) cout<<"vals["<<i<<"]="<<vals[i]<<endl; if (NPAR==6) finalPars[0]=vals[1]; - else finalPars[0]=0.; // s + else finalPars[0]=0.; // s finalPars[1]=vals[2]; // z finalPars[2]=vals[0]; // t finalPars[3]=vals[4]; // rots finalPars[4]=vals[5]; // rotz finalPars[5]=vals[3]; // rott - for (int i=0;i<6;i++) + for (int i=0;i<6;i++) cout<<"finalPars["<<i<<"]="<<finalPars[i]<<endl; - + //delete [] vals; return; @@ -2193,85 +2083,86 @@ void getFinalPars(double* initPar, double* deltas, double* finalPars) */ //________________________________________________________________________ -void getFinalPars(double* initPar, double* deltas, double* finalPars) -{ - double tras(0.), traz(0.), trat(0.), rots(0.), rotz(0.), rott(0.); - double dtras(0.),dtraz(0.),dtrat(0.),drots(0.),drotz(0.),drott(0.); - int firsti=0; - - cout<<"s/z/t: "<<tras<<"/"<<traz<<"/"<<trat<<endl; - cout<<"rot s/z/t: "<<rots<<"/"<<rotz<<"/"<<rott<<endl; - - if (NPAR==6) { - tras=initPar[0]; - dtras=deltas[0]; - firsti=1; - } - traz=initPar[firsti]; dtraz=deltas[firsti++]; - trat=initPar[firsti]; dtrat=deltas[firsti++]; - rots=initPar[firsti]; drots=deltas[firsti++]; - rotz=initPar[firsti]; drotz=deltas[firsti++]; - rott=initPar[firsti]; drott=deltas[firsti++]; - - cout<<"d s/z/t: "<<dtras<<"/"<<dtraz<<"/"<<dtrat<<endl; - cout<<"d rot s/z/t: "<<drots<<"/"<<drotz<<"/"<<drott<<endl; - - tras += dtras; - traz += dtraz; - trat += dtrat; - rots += drots; - rotz += drotz; - rott += drott; - - cout<<"s/z/t: "<<tras<<"/"<<traz<<"/"<<trat<<endl; - cout<<"rot s/z/t: "<<rots<<"/"<<rotz<<"/"<<rott<<endl; - - if (NPAR==6) finalPars[0]=tras; - else finalPars[0]=0.; - finalPars[1]=traz; - finalPars[2]=trat; - finalPars[3]=rots; - finalPars[4]=rotz; - finalPars[5]=rott; - - return; - +void getFinalPars(double* initPar, double* deltas, double* finalPars) { + double tras(0.), traz(0.), trat(0.), rots(0.), rotz(0.), rott(0.); + double dtras(0.), dtraz(0.), dtrat(0.), drots(0.), drotz(0.), drott(0.); + int firsti = 0; + + cout << "s/z/t: " << tras << "/" << traz << "/" << trat << endl; + cout << "rot s/z/t: " << rots << "/" << rotz << "/" << rott << endl; + + if (NPAR == 6) { + tras = initPar[0]; + dtras = deltas[0]; + firsti = 1; + } + traz = initPar[firsti]; + dtraz = deltas[firsti++]; + trat = initPar[firsti]; + dtrat = deltas[firsti++]; + rots = initPar[firsti]; + drots = deltas[firsti++]; + rotz = initPar[firsti]; + drotz = deltas[firsti++]; + rott = initPar[firsti]; + drott = deltas[firsti++]; + + cout << "d s/z/t: " << dtras << "/" << dtraz << "/" << dtrat << endl; + cout << "d rot s/z/t: " << drots << "/" << drotz << "/" << drott << endl; + + tras += dtras; + traz += dtraz; + trat += dtrat; + rots += drots; + rotz += drotz; + rott += drott; + + cout << "s/z/t: " << tras << "/" << traz << "/" << trat << endl; + cout << "rot s/z/t: " << rots << "/" << rotz << "/" << rott << endl; + + if (NPAR == 6) + finalPars[0] = tras; + else + finalPars[0] = 0.; + finalPars[1] = traz; + finalPars[2] = trat; + finalPars[3] = rots; + finalPars[4] = rotz; + finalPars[5] = rott; + + return; } - //________________________________________________________________________ -void decomposeTransform(const HepGeom::Transform3D& transform, double* values) -{ - // copied from AlignModule - HepGeom::Scale3D scale; - HepGeom::Rotate3D rotation; - HepGeom::Translate3D translation; - transform.getDecomposition(scale,rotation,translation); - - values[0]=translation.dx(); - values[1]=translation.dy(); - values[2]=translation.dz(); - - - // a12 = cosbeta singamma - // a13 = -sinbeta - // a23 = sinalpha cosbeta - - double sinbeta = -rotation[0][2]; - double cosbeta = std::sqrt(1.-sinbeta*sinbeta); - - double sinalpha = rotation[1][2]/cosbeta; - double singamma = rotation[0][1]/cosbeta; - - values[3]=-std::asin(sinalpha); - values[4]=-std::asin(sinbeta); - values[5]=-std::asin(singamma); - -} +void decomposeTransform(const HepGeom::Transform3D& transform, double* values) { + // copied from AlignModule + HepGeom::Scale3D scale; + HepGeom::Rotate3D rotation; + HepGeom::Translate3D translation; + transform.getDecomposition(scale, rotation, translation); + + values[0] = translation.dx(); + values[1] = translation.dy(); + values[2] = translation.dz(); + + // a12 = cosbeta singamma + // a13 = -sinbeta + // a23 = sinalpha cosbeta + + double sinbeta = -rotation[0][2]; + double cosbeta = std::sqrt(1. - sinbeta * sinbeta); + + double sinalpha = rotation[1][2] / cosbeta; + double singamma = rotation[0][1] / cosbeta; + + values[3] = -std::asin(sinalpha); + values[4] = -std::asin(sinbeta); + values[5] = -std::asin(singamma); +} /* //________________________________________________________________________ -double* fixAlongTrack(double* secDerivs) const +double* fixAlongTrack(double* secDerivs) const { TMatrixDSym mat(5); int index(0); @@ -2280,11 +2171,11 @@ double* fixAlongTrack(double* secDerivs) const mat[i][j]=(*secDerivs)[index++]; } } - + TDecompSVD decompMat(mat); decompMat.Decompose(); const TVectorD& svV=decompMat.GetSig(); - + vector<double> sv; for (int i=0;i<svV.GetNoElements();i++) sv.push_back(svV[i]); @@ -2315,4 +2206,3 @@ double* fixAlongTrack(double* secDerivs) const return vals; } */ - diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/summaryHists_x.cpp b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/summaryHists_x.cpp index 4fcb030f67452ba18ccdce0f63dfc025b1bfee28..b66d498e5cb5d54a270c8c71f9af2e1a43c08d81 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/summaryHists_x.cpp +++ b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/summaryHists_x.cpp @@ -2,10 +2,7 @@ Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration */ -#include "TFile.h" #include "TChain.h" +#include "TFile.h" -int main() -{ - -} +int main() {} diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/unbiasedResPlots_x.cpp b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/unbiasedResPlots_x.cpp index dddb507a461fd605de789acc98bd369877856eb2..4db307b315f035b2c7f1db9e833739e70c8167dd 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/unbiasedResPlots_x.cpp +++ b/MuonSpectrometer/MuonAlignment/MuonAlignExample/scripts/unbiasedResPlots_x.cpp @@ -2,1392 +2,1491 @@ Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ +#include <dirent.h> +#include <stdlib.h> + +#include <cmath> +#include <iostream> +#include <sstream> +#include <vector> + +#include "TCanvas.h" +#include "TChain.h" +#include "TF1.h" #include "TFile.h" +#include "TGraphErrors.h" #include "TH1F.h" #include "TH2F.h" -#include "TF1.h" -#include "TCanvas.h" -#include "TStyle.h" -#include "TGraphErrors.h" -#include "TText.h" #include "TLegend.h" -#include "TChain.h" +#include "TMath.h" // for TF1 formulas #include "TPaveStats.h" #include "TProfile.h" -#include "TMath.h" // for TF1 formulas - -#include <vector> -#include <iostream> -#include <dirent.h> -#include <sstream> -#include <stdlib.h> -#include <cmath> +#include "TStyle.h" +#include "TText.h" -const bool USETGCETA=true; +const bool USETGCETA = true; -//const string outputdir=(USETGCETA)?"align_withTGCEta":"align_noTGCEta"; -const string outputdir="align_tgcEtaOutlier"; +// const string outputdir=(USETGCETA)?"align_withTGCEta":"align_noTGCEta"; +const string outputdir = "align_tgcEtaOutlier"; -const bool DOCSC=false; -const bool DOBEE=false; +const bool DOCSC = false; +const bool DOBEE = false; -const bool DOEC =true; +const bool DOEC = true; const int NVALBINS = 101; -const int NYX=(DOCSC)?2:1; +const int NYX = (DOCSC) ? 2 : 1; -const int NMOM = 16; -const double mommin= 4.; -const double mommax= 20.; +const int NMOM = 16; +const double mommin = 4.; +const double mommax = 20.; double* momMin; -double momCut=10.; +double momCut = 10.; -const int twocolors[2]={kRed,kBlue}; +const int twocolors[2] = {kRed, kBlue}; -const int phicolor[16]={kRed+4,kRed+2,kRed, - kMagenta+4,kMagenta+2,kMagenta, - kBlue+4,kBlue+2,kBlue, - kCyan+4,kCyan+2,kCyan, - kGreen+4,kGreen+2,kGreen, - kYellow+2}; +const int phicolor[16] = {kRed + 4, kRed + 2, kRed, kMagenta + 4, kMagenta + 2, kMagenta, kBlue + 4, kBlue + 2, + kBlue, kCyan + 4, kCyan + 2, kCyan, kGreen + 4, kGreen + 2, kGreen, kYellow + 2}; // Declaration of leaf types -Int_t nPixHits; -Int_t nSCTHits; -Int_t nTRTHits; -Int_t nCSCHits; -Int_t nMDTHits; -Int_t nInnerMDTHits; -Int_t nMiddleMDTHits; -Int_t nOuterMDTHits; -Int_t nTriggerPhiHits; -Int_t author; -Int_t hIndex; -Int_t phiSector; -Int_t isEndcap; -Int_t identifier; -Int_t isCSide; -Int_t detType; -Int_t layer; -Int_t stName; -Int_t stPhi; -Int_t stEta; -Double_t momentum; -Double_t charge; -Double_t d0; -Double_t z0; -Double_t phi0; -Double_t theta0; -Double_t eta0; -Double_t calEnergyLoss; -Double_t calEnergyLossErr; -Double_t materialOnTrack; -Double_t dR; -Double_t dZlocal; -Double_t dXlocal; -Double_t dYlocal; -Double_t dXlocalAngle; -Double_t dYlocalAngle; -Double_t dXglobal; -Double_t dYglobal; -Double_t dZglobal; -Int_t nInnerChambers; -Int_t nMiddleChambers; -Int_t nOuterChambers; -Int_t nOtherChambers; -Double_t detTheta; -Int_t innerStEta[10]; -Int_t middleStEta[10]; -Int_t outerStEta[10]; -Int_t otherStEta[10]; - -void setBranchAddresses(TTree* tree); -void getHistograms(bool histsDone); -void makeLargeSmallWidthPlots(TFile* outputHists); -void makePhiWidthPlots(TFile* outputHists); -void makeWidthPlots(TFile* outputHists, const string& type); -void makeCSCResPlots(TFile* outputHists); -void makeCSCResVTanThetaPlots(TFile* outputHists); -void makeMDTResPlots(TFile* outputHists); -void makeMDTResVTanThetaPlots(TFile* outputHists); -string mdtChamberNameNoPhi(int iecAC, int ilayer, int ieta); -string mdtChamberNameNoEta(int iecAC, int ilayer); -string mdtChamberName(int iecAC, int ilayer, int ieta, int iphi); -void plotLgSmSummary(TPad* canv, TH1F** hists, const string& canvname); - -TFile* inputHistsFile; - -TH2F**** lgsmHistsCSC; -TH2F**** ecHistsCSC; -TH1F**** phiSecHistsCSC; -TH1F*** phiSecHistsMDT; -TH2F**** resVTanThetaHistsCSC; +Int_t nPixHits; +Int_t nSCTHits; +Int_t nTRTHits; +Int_t nCSCHits; +Int_t nMDTHits; +Int_t nInnerMDTHits; +Int_t nMiddleMDTHits; +Int_t nOuterMDTHits; +Int_t nTriggerPhiHits; +Int_t author; +Int_t hIndex; +Int_t phiSector; +Int_t isEndcap; +Int_t identifier; +Int_t isCSide; +Int_t detType; +Int_t layer; +Int_t stName; +Int_t stPhi; +Int_t stEta; +Double_t momentum; +Double_t charge; +Double_t d0; +Double_t z0; +Double_t phi0; +Double_t theta0; +Double_t eta0; +Double_t calEnergyLoss; +Double_t calEnergyLossErr; +Double_t materialOnTrack; +Double_t dR; +Double_t dZlocal; +Double_t dXlocal; +Double_t dYlocal; +Double_t dXlocalAngle; +Double_t dYlocalAngle; +Double_t dXglobal; +Double_t dYglobal; +Double_t dZglobal; +Int_t nInnerChambers; +Int_t nMiddleChambers; +Int_t nOuterChambers; +Int_t nOtherChambers; +Double_t detTheta; +Int_t innerStEta[10]; +Int_t middleStEta[10]; +Int_t outerStEta[10]; +Int_t otherStEta[10]; + +void setBranchAddresses(TTree* tree); +void getHistograms(bool histsDone); +void makeLargeSmallWidthPlots(TFile* outputHists); +void makePhiWidthPlots(TFile* outputHists); +void makeWidthPlots(TFile* outputHists, const string& type); +void makeCSCResPlots(TFile* outputHists); +void makeCSCResVTanThetaPlots(TFile* outputHists); +void makeMDTResPlots(TFile* outputHists); +void makeMDTResVTanThetaPlots(TFile* outputHists); +string mdtChamberNameNoPhi(int iecAC, int ilayer, int ieta); +string mdtChamberNameNoEta(int iecAC, int ilayer); +string mdtChamberName(int iecAC, int ilayer, int ieta, int iphi); +void plotLgSmSummary(TPad* canv, TH1F** hists, const string& canvname); + +TFile* inputHistsFile; + +TH2F**** lgsmHistsCSC; +TH2F**** ecHistsCSC; +TH1F**** phiSecHistsCSC; +TH1F*** phiSecHistsMDT; +TH2F**** resVTanThetaHistsCSC; TH1F****** phiSecEtaHistsMDT; TH2F****** resVTanThetaHistsMDT; -double** tanThetaMin; -double** tanThetaMax; +double** tanThetaMin; +double** tanThetaMax; -int allowedInnerLayerForMiddleFixed[6]={0,1,2,2,4,0}; -int allowedOuterLayerForMiddleFixed[6]={2,3,5,6,6,0}; -//int allowedOuterLayerForMiddleFixed[6]={1,3,5,6,6,0}; +int allowedInnerLayerForMiddleFixed[6] = {0, 1, 2, 2, 4, 0}; +int allowedOuterLayerForMiddleFixed[6] = {2, 3, 5, 6, 6, 0}; +// int allowedOuterLayerForMiddleFixed[6]={1,3,5,6,6,0}; //________________________________________________________________________ -int main() -{ - // set up tan theta bins - tanThetaMin=new double*[3]; - tanThetaMax=new double*[3]; - for (int ilayer=0;ilayer<3;ilayer++) { - tanThetaMin[ilayer]=new double[6]; - tanThetaMax[ilayer]=new double[6]; - } - - tanThetaMin[0][0]=0.24; tanThetaMax[0][0]=0.44; - tanThetaMin[0][1]=0.25; tanThetaMax[0][1]=0.75; - tanThetaMin[0][2]=0.4; tanThetaMax[0][2]=0.65; - tanThetaMin[0][3]=0.4; tanThetaMax[0][3]=1.3; - tanThetaMin[0][4]=0.7; tanThetaMax[0][4]=1.2; - tanThetaMin[0][5]=0.; tanThetaMax[0][5]=1.; - - tanThetaMin[1][0]=0.17; tanThetaMax[1][0]=0.26; - tanThetaMin[1][1]=0.24; tanThetaMax[1][1]=0.36; - tanThetaMin[1][2]=0.39; tanThetaMax[1][2]=0.51; - tanThetaMin[1][3]=0.51; tanThetaMax[1][3]=0.58; - tanThetaMin[1][4]=0.72; tanThetaMax[1][4]=0.82; - tanThetaMin[1][5]=0.; tanThetaMax[1][5]=1.; - - tanThetaMin[2][0]=0.05; tanThetaMax[2][0]=0.3; - tanThetaMin[2][1]=0.12; tanThetaMax[2][1]=0.4; - tanThetaMin[2][2]=0.2; tanThetaMax[2][2]=0.5; - tanThetaMin[2][3]=0.3; tanThetaMax[2][3]=0.6; - tanThetaMin[2][4]=0.35; tanThetaMax[2][4]=0.65; - tanThetaMin[2][5]=0.4; tanThetaMax[2][5]=0.75; - - // set up momentum bins - momMin=new double[NMOM+1]; - for (int imom=0;imom<NMOM;imom++) { - momMin[imom]=mommin + (mommax-mommin)/(double)NMOM*imom; - } - momMin[NMOM]=mommax; - - // fill histograms or get from input histogram file - bool histsDone=true; - getHistograms(histsDone); - - // make output histograms - TFile* outputHists=new TFile((outputdir+"outputhists.root").c_str(),"RECREATE"); - - // make plots - if (DOCSC) { - makeWidthPlots(outputHists,"LargeSmall"); - makeWidthPlots(outputHists,"EndcapAC"); - makeCSCResPlots(outputHists); - makeCSCResVTanThetaPlots(outputHists); - } - else { - makeWidthPlots(outputHists,"LargeSmall"); - makeWidthPlots(outputHists,"EndcapAC"); - if (!DOBEE) { - makePhiWidthPlots(outputHists); - makeMDTResPlots(outputHists); - makeMDTResVTanThetaPlots(outputHists); +int main() { + // set up tan theta bins + tanThetaMin = new double*[3]; + tanThetaMax = new double*[3]; + for (int ilayer = 0; ilayer < 3; ilayer++) { + tanThetaMin[ilayer] = new double[6]; + tanThetaMax[ilayer] = new double[6]; } - - } - outputHists->Close(); -} -//________________________________________________________________________ -void makePhiWidthPlots(TFile* outputHists) -{ - gStyle->SetOptStat(1); - gStyle->SetOptFit(111); - - TCanvas* canv=new TCanvas("canv","canv"); - canv->SetFillColor(10); - - TCanvas* ctmp=new TCanvas("ctmp","ctmp"); - - for (int iecAC=0;iecAC<2;iecAC++) { - cout<<"iecAC: "<<iecAC<<endl; - canv->Clear(); - canv->Divide(4,4); - - TF1** fits=new TF1*[16]; - TH1F** hMeans =new TH1F*[2]; - TH1F** hWidths =new TH1F*[2]; - TH1F** hOuterWidths=new TH1F*[2]; - TH1F** hEntries =new TH1F*[2]; - - hMeans[0] =new TH1F("hMeanLg", "Unbiased Residual Mean vs. #phi", 16,0.,16.); - hWidths[0] =new TH1F("hWidthLg","Unbiased Residual Inner Width vs. #phi",16,0.,16.); - hOuterWidths[0]=new TH1F("hOuterWidthLg","Unbiased Residual Outer Width vs. #phi",16,0.,16.); - hEntries[0] =new TH1F("hEntriesLg", "Number Residuals vs. #phi",16,0.,16.); - - hMeans[1] =new TH1F("hMeanSm", "PhiMeansSm", 16,0.,16.); - hWidths[1] =new TH1F("hWidthSm","PhiWidthsSm",16,0.,16.); - hOuterWidths[1]=new TH1F("hOuterWidthSm","PhiOuterWidthsSm",16,0.,16.); - hEntries[1] =new TH1F("hEntriesSm", "PhiEntriesSm",16,0.,16.); - - for (int iphi=0;iphi<16;iphi++) { - cout<<"iphi: "<<iphi<<endl; - stringstream histname; - histname<<"Sector"<<iphi+1; - if (iecAC==0) histname<<"A"; else histname<<"C"; - histname<<"_dY_MDT"; - - cout<<"getting hist: "<<histname.str()<<endl; - - TH1F* hist=phiSecHistsMDT[iecAC][iphi]; - cout<<"hist has "<<hist->GetEntries()<<" entries"<<endl; - stringstream fitname; fitname<<"fit_"<<iphi; - - ctmp->cd(); - //fits[iphi]=new TF1(fitname.str().c_str(),"gaus(0)+gaus(3)",-30.,30.); - fits[iphi]=new TF1(fitname.str().c_str(), - "[0]*exp(-0.5*((x-[1])/[2])^2)+[3]*[0]*exp(-0.5*((x-[1])/[4])^2)", - -30.,30.); - fits[iphi]->SetParameters(hist->GetMaximum(),0,5.5,.6,20.); - fits[iphi]->SetParLimits(4,0.,999.); - hist->Fit(fits[iphi],"RQ"); - - int histindex=(iphi%2); - - stringstream binLabel; binLabel<<iphi+1; - if (iecAC==0) binLabel<<"A"; else binLabel<<"C"; - - // mean - double mean =fits[iphi]->GetParameter(1); - double meanerr=fits[iphi]->GetParError(1); - hMeans[histindex]->SetBinContent(iphi+1,mean); - hMeans[histindex]->SetBinError(iphi+1,meanerr); - hMeans[0]->GetXaxis()->SetBinLabel(iphi+1,binLabel.str().c_str()); - hMeans[0]->SetMinimum(-1.4); - hMeans[0]->SetMaximum(1.4); - - // inner width - double width =fits[iphi]->GetParameter(2); - double widtherr=fits[iphi]->GetParError(2); - hWidths[histindex]->SetBinContent(iphi+1,width); - hWidths[histindex]->SetBinError(iphi+1,widtherr); - hWidths[0]->GetXaxis()->SetBinLabel(iphi+1,binLabel.str().c_str()); - hWidths[0]->SetMinimum(4.); - hWidths[0]->SetMaximum(8.5); - - // outer width - double owidth =fits[iphi]->GetParameter(4); - double owidtherr=fits[iphi]->GetParError(4); - hOuterWidths[histindex]->SetBinContent(iphi+1,owidth); - hOuterWidths[histindex]->SetBinError(iphi+1,owidtherr); - hOuterWidths[0]->GetXaxis()->SetBinLabel(iphi+1,binLabel.str().c_str()); - hOuterWidths[0]->SetMinimum(14.); - hOuterWidths[0]->SetMaximum(26.); - - // # entries - double entries =hist->GetEntries(); - hEntries[histindex]->SetBinContent(iphi+1,entries); - hEntries[histindex]->SetBinError(iphi+1,sqrt(entries)); - hEntries[0]->GetXaxis()->SetBinLabel(iphi+1,binLabel.str().c_str()); - hEntries[0]->SetMinimum(0.); - hEntries[0]->SetMaximum(35000.); - - canv->cd(iphi+1); - hist->SetLineColor(phicolor[iphi]); - fits[iphi]->SetLineColor(phicolor[iphi]); - hist->Draw(); - fits[iphi]->Draw("same"); - canv->Modified(); + tanThetaMin[0][0] = 0.24; + tanThetaMax[0][0] = 0.44; + tanThetaMin[0][1] = 0.25; + tanThetaMax[0][1] = 0.75; + tanThetaMin[0][2] = 0.4; + tanThetaMax[0][2] = 0.65; + tanThetaMin[0][3] = 0.4; + tanThetaMax[0][3] = 1.3; + tanThetaMin[0][4] = 0.7; + tanThetaMax[0][4] = 1.2; + tanThetaMin[0][5] = 0.; + tanThetaMax[0][5] = 1.; + + tanThetaMin[1][0] = 0.17; + tanThetaMax[1][0] = 0.26; + tanThetaMin[1][1] = 0.24; + tanThetaMax[1][1] = 0.36; + tanThetaMin[1][2] = 0.39; + tanThetaMax[1][2] = 0.51; + tanThetaMin[1][3] = 0.51; + tanThetaMax[1][3] = 0.58; + tanThetaMin[1][4] = 0.72; + tanThetaMax[1][4] = 0.82; + tanThetaMin[1][5] = 0.; + tanThetaMax[1][5] = 1.; + + tanThetaMin[2][0] = 0.05; + tanThetaMax[2][0] = 0.3; + tanThetaMin[2][1] = 0.12; + tanThetaMax[2][1] = 0.4; + tanThetaMin[2][2] = 0.2; + tanThetaMax[2][2] = 0.5; + tanThetaMin[2][3] = 0.3; + tanThetaMax[2][3] = 0.6; + tanThetaMin[2][4] = 0.35; + tanThetaMax[2][4] = 0.65; + tanThetaMin[2][5] = 0.4; + tanThetaMax[2][5] = 0.75; + + // set up momentum bins + momMin = new double[NMOM + 1]; + for (int imom = 0; imom < NMOM; imom++) { momMin[imom] = mommin + (mommax - mommin) / (double)NMOM * imom; } + momMin[NMOM] = mommax; + + // fill histograms or get from input histogram file + bool histsDone = true; + getHistograms(histsDone); + + // make output histograms + TFile* outputHists = new TFile((outputdir + "outputhists.root").c_str(), "RECREATE"); + + // make plots + if (DOCSC) { + makeWidthPlots(outputHists, "LargeSmall"); + makeWidthPlots(outputHists, "EndcapAC"); + makeCSCResPlots(outputHists); + makeCSCResVTanThetaPlots(outputHists); + } else { + makeWidthPlots(outputHists, "LargeSmall"); + makeWidthPlots(outputHists, "EndcapAC"); + if (!DOBEE) { + makePhiWidthPlots(outputHists); + makeMDTResPlots(outputHists); + makeMDTResVTanThetaPlots(outputHists); + } } - - stringstream canvname; - canvname<<"MDTSectorPlots_"; - if (iecAC==0) canvname<<"Aside"; else canvname<<"Cside"; - canv->Print((outputdir+"/"+canvname.str()+".eps").c_str()); - - plotLgSmSummary(canv,hMeans,outputdir+"/"+canvname.str()+"_Means.eps"); - plotLgSmSummary(canv,hWidths,outputdir+"/"+canvname.str()+"_Widths.eps"); - plotLgSmSummary(canv,hOuterWidths,outputdir+"/"+canvname.str()+"_OuterWidths.eps"); - plotLgSmSummary(canv,hEntries,outputdir+"/"+canvname.str()+"_Entries.eps"); - - delete [] fits; - } - delete canv; - delete ctmp; + outputHists->Close(); } //________________________________________________________________________ -void makeCSCResPlots(TFile* outputHists) -{ - gStyle->SetOptStat(1); - gStyle->SetOptFit(111); - - // tan((detTheta-11.59)/360.*6.28), theta<25. - TH1F*** hMeans=new TH1F**[2]; - TF1**** fits=new TF1***[2]; - for (int iecAC=0;iecAC<2;iecAC++) { - hMeans[iecAC]=new TH1F*[NYX]; - fits[iecAC]=new TF1**[NYX]; - int ixy=0; - for (int iyx=NYX-1;iyx>=0;iyx--,ixy++) { - string title="#Delta "; - if (iyx==0) title+="y"; else title+="x"; - title+=" (mm)"; - - string hmeanname=(DOCSC)?"CSC":"MDT"; - if (iecAC==0) hmeanname+="_EndcapA"; - else hmeanname+="_EndcapC"; - if (iyx==0) hmeanname+="_dY"; else hmeanname+="_dX"; - hMeans[iecAC][iyx]=new TH1F(hmeanname.c_str(),hmeanname.c_str(),16,0.,16.); - fits[iecAC][iyx]=new TF1*[16]; - - TCanvas* canv=new TCanvas("canv","canv"); - canv->SetFillColor(10); - canv->Divide(4,4); - - for (int iphi=0;iphi<16;iphi++) { - canv->cd(iphi+1); - stringstream fitname; - fitname<<"fitRes_"<<iphi+1; - if (iecAC==0) fitname<<"A"; else fitname<<"C"; - if (iyx==0) fitname<<"_dY"; else fitname<<"_dX"; - double fitrange=(iyx==0) ? 40. : 80.; - fits[iecAC][iyx][iphi]= - new TF1(fitname.str().c_str(), - "[0]*exp(-0.5*((x-[1])/[2])^2)+[3]*[0]*exp(-0.5*((x-[1])/[4])^2)", - -fitrange,fitrange); - TH1F* hist=phiSecHistsCSC[iecAC][iphi][iyx]; - TF1* fit =fits[iecAC][iyx][iphi]; - - double innerwidth=(iyx==0)?8.:16.; - double outerwidth=(iyx==0)?20.:40.; - fit->SetParameters(hist->GetMaximum(),hist->GetMean(),innerwidth,0.8,outerwidth); - fit->SetParLimits(2,innerwidth/4.,outerwidth*1.5); - hist->Fit(fit,"RQ"); - - hist->GetXaxis()->SetTitle(title.c_str()); - - hist->Draw(); - fit->Draw("same"); - - stringstream binLabel; binLabel<<iphi+1; - if (iecAC==0) binLabel<<"A"; else binLabel<<"C"; - hMeans[iecAC][iyx]->GetXaxis()->SetBinLabel(iphi+1,binLabel.str().c_str()); - if (fit->GetChisquare()/fit->GetNDF()<5. && hist->GetEntries()>1000.) { - hMeans[iecAC][iyx]->SetBinContent(iphi+1,fit->GetParameter(1)); - hMeans[iecAC][iyx]->SetBinError (iphi+1,fit->GetParError(1)); - if (iyx==0) cout<<"dY: "; else cout<<"dX: "; - cout<<iphi+1; - if (iecAC==0) cout<<"A"; else cout<<"C"; - cout<<" "<<fit->GetParameter(1)<<" +/- "<<fit->GetParError(1)<<endl; - } - } - - string canvname="CSC"; - if (iecAC==0) canvname+="_EndcapA"; - else canvname+="_EndcapC"; - if (iyx==0) canvname+="_dY"; else canvname+="_dX"; - canv->Print((outputdir+"/"+canvname+".eps").c_str()); - - canv->Clear(); - - if (hMeans[iecAC][iyx]->GetMaximum()>20.) hMeans[iecAC][iyx]->SetMaximum(20.); - if (hMeans[iecAC][iyx]->GetMinimum()<-20.) hMeans[iecAC][iyx]->SetMinimum(-20.); - hMeans[iecAC][iyx]->Draw(); - hMeans[iecAC][iyx]->GetYaxis()->SetTitle(title.c_str()); - canv->Modified(); - - canv->Print((outputdir+"/"+canvname+"_allPhi.eps").c_str()); - - delete canv; +void makePhiWidthPlots(TFile* outputHists) { + gStyle->SetOptStat(1); + gStyle->SetOptFit(111); + + TCanvas* canv = new TCanvas("canv", "canv"); + canv->SetFillColor(10); + + TCanvas* ctmp = new TCanvas("ctmp", "ctmp"); + + for (int iecAC = 0; iecAC < 2; iecAC++) { + cout << "iecAC: " << iecAC << endl; + canv->Clear(); + canv->Divide(4, 4); + + TF1** fits = new TF1*[16]; + TH1F** hMeans = new TH1F*[2]; + TH1F** hWidths = new TH1F*[2]; + TH1F** hOuterWidths = new TH1F*[2]; + TH1F** hEntries = new TH1F*[2]; + + hMeans[0] = new TH1F("hMeanLg", "Unbiased Residual Mean vs. #phi", 16, 0., 16.); + hWidths[0] = new TH1F("hWidthLg", "Unbiased Residual Inner Width vs. #phi", 16, 0., 16.); + hOuterWidths[0] = new TH1F("hOuterWidthLg", "Unbiased Residual Outer Width vs. #phi", 16, 0., 16.); + hEntries[0] = new TH1F("hEntriesLg", "Number Residuals vs. #phi", 16, 0., 16.); + + hMeans[1] = new TH1F("hMeanSm", "PhiMeansSm", 16, 0., 16.); + hWidths[1] = new TH1F("hWidthSm", "PhiWidthsSm", 16, 0., 16.); + hOuterWidths[1] = new TH1F("hOuterWidthSm", "PhiOuterWidthsSm", 16, 0., 16.); + hEntries[1] = new TH1F("hEntriesSm", "PhiEntriesSm", 16, 0., 16.); + + for (int iphi = 0; iphi < 16; iphi++) { + cout << "iphi: " << iphi << endl; + stringstream histname; + histname << "Sector" << iphi + 1; + if (iecAC == 0) + histname << "A"; + else + histname << "C"; + histname << "_dY_MDT"; + + cout << "getting hist: " << histname.str() << endl; + + TH1F* hist = phiSecHistsMDT[iecAC][iphi]; + cout << "hist has " << hist->GetEntries() << " entries" << endl; + stringstream fitname; + fitname << "fit_" << iphi; + + ctmp->cd(); + // fits[iphi]=new TF1(fitname.str().c_str(),"gaus(0)+gaus(3)",-30.,30.); + fits[iphi] = new TF1(fitname.str().c_str(), "[0]*exp(-0.5*((x-[1])/[2])^2)+[3]*[0]*exp(-0.5*((x-[1])/[4])^2)", -30., 30.); + fits[iphi]->SetParameters(hist->GetMaximum(), 0, 5.5, .6, 20.); + fits[iphi]->SetParLimits(4, 0., 999.); + hist->Fit(fits[iphi], "RQ"); + + int histindex = (iphi % 2); + + stringstream binLabel; + binLabel << iphi + 1; + if (iecAC == 0) + binLabel << "A"; + else + binLabel << "C"; + + // mean + double mean = fits[iphi]->GetParameter(1); + double meanerr = fits[iphi]->GetParError(1); + hMeans[histindex]->SetBinContent(iphi + 1, mean); + hMeans[histindex]->SetBinError(iphi + 1, meanerr); + hMeans[0]->GetXaxis()->SetBinLabel(iphi + 1, binLabel.str().c_str()); + hMeans[0]->SetMinimum(-1.4); + hMeans[0]->SetMaximum(1.4); + + // inner width + double width = fits[iphi]->GetParameter(2); + double widtherr = fits[iphi]->GetParError(2); + hWidths[histindex]->SetBinContent(iphi + 1, width); + hWidths[histindex]->SetBinError(iphi + 1, widtherr); + hWidths[0]->GetXaxis()->SetBinLabel(iphi + 1, binLabel.str().c_str()); + hWidths[0]->SetMinimum(4.); + hWidths[0]->SetMaximum(8.5); + + // outer width + double owidth = fits[iphi]->GetParameter(4); + double owidtherr = fits[iphi]->GetParError(4); + hOuterWidths[histindex]->SetBinContent(iphi + 1, owidth); + hOuterWidths[histindex]->SetBinError(iphi + 1, owidtherr); + hOuterWidths[0]->GetXaxis()->SetBinLabel(iphi + 1, binLabel.str().c_str()); + hOuterWidths[0]->SetMinimum(14.); + hOuterWidths[0]->SetMaximum(26.); + + // # entries + double entries = hist->GetEntries(); + hEntries[histindex]->SetBinContent(iphi + 1, entries); + hEntries[histindex]->SetBinError(iphi + 1, sqrt(entries)); + hEntries[0]->GetXaxis()->SetBinLabel(iphi + 1, binLabel.str().c_str()); + hEntries[0]->SetMinimum(0.); + hEntries[0]->SetMaximum(35000.); + + canv->cd(iphi + 1); + hist->SetLineColor(phicolor[iphi]); + fits[iphi]->SetLineColor(phicolor[iphi]); + hist->Draw(); + fits[iphi]->Draw("same"); + canv->Modified(); + } + + stringstream canvname; + canvname << "MDTSectorPlots_"; + if (iecAC == 0) + canvname << "Aside"; + else + canvname << "Cside"; + canv->Print((outputdir + "/" + canvname.str() + ".eps").c_str()); + + plotLgSmSummary(canv, hMeans, outputdir + "/" + canvname.str() + "_Means.eps"); + plotLgSmSummary(canv, hWidths, outputdir + "/" + canvname.str() + "_Widths.eps"); + plotLgSmSummary(canv, hOuterWidths, outputdir + "/" + canvname.str() + "_OuterWidths.eps"); + plotLgSmSummary(canv, hEntries, outputdir + "/" + canvname.str() + "_Entries.eps"); + + delete[] fits; } - } - - return; + delete canv; + delete ctmp; } //________________________________________________________________________ -void makeCSCResVTanThetaPlots(TFile* outputHists) -{ - gStyle->SetOptStat(1); - gStyle->SetOptFit(111); - gStyle->SetPalette(1); - - TH1F*** hMeans =new TH1F**[2]; - TF1**** fits =new TF1***[2]; - TH1F**** resVTanTheta=new TH1F***[2]; - for (int iecAC=0;iecAC<2;iecAC++) { - hMeans [iecAC]=new TH1F*[NYX]; - fits [iecAC]=new TF1**[NYX]; - resVTanTheta[iecAC]=new TH1F**[NYX]; - int ixy=NYX-1; - for (int iyx=0;iyx<NYX;iyx++,ixy--) { - string title="#Delta "; - if (iyx==0) title+="y"; else title+="x"; - title+=" (mm)"; - - string hmeanname=(iecAC==0)?"EndcapA":"EndcapC"; - if (iyx==0) hmeanname+="_dY"; else hmeanname+="_dX"; - hMeans [iecAC][iyx]=new TH1F(hmeanname.c_str(),hmeanname.c_str(),16,0.,16.); - fits [iecAC][iyx]=new TF1*[16]; - resVTanTheta[iecAC][iyx]=new TH1F*[16]; - - TCanvas* canv=new TCanvas("canv","canv"); - canv->SetFillColor(10); - canv->Divide(4,4); - - for (int iphi=0;iphi<16;iphi++) { - canv->cd(iphi+1); - - TH2F* hist=resVTanThetaHistsCSC[iecAC][iphi][iyx]; - - double fitrange=(iyx==0)?20.:40.; - string resHistName=string(hist->GetName())+"Fits"; - resVTanTheta[iecAC][iyx][iphi]=new TH1F(resHistName.c_str(),resHistName.c_str(), - 5,-.04,.06); - TH1F** slices=new TH1F*[5]; - for (int i=0;i<5;i++) { - stringstream tmphistname; tmphistname<<hist->GetName()<<"_slice"<<i; - slices[i]=(TH1F*)hist->ProjectionY(tmphistname.str().c_str(),i+1,i+2); - slices[i]->Draw(); - TF1* fit= - new TF1("fit", "gaus",-fitrange,fitrange); - slices[i]->Fit(fit,"QR"); - resVTanTheta[iecAC][iyx][iphi]->SetBinContent(i+1,fit->GetParameter(1)); - resVTanTheta[iecAC][iyx][iphi]->SetBinError(i+1,fit->GetParError(1)); - delete fit; - } - string fitname=string(hist->GetName())+"_fit"; - fits[iecAC][iyx][iphi]=new TF1(fitname.c_str(),"pol1",-fitrange,fitrange); - resVTanTheta[iecAC][iyx][iphi]->Fit(fits[iecAC][iyx][iphi],"RQ"); - - //canv->cd(iphi+1); - hist->GetYaxis()->SetRangeUser(-fitrange,fitrange); - //hist->Draw("colz"); - resVTanTheta[iecAC][iyx][iphi]->Draw("same"); - fits[iecAC][iyx][iphi]->Draw("same"); - } - - string canvname="CSC"; - if (iecAC==0) canvname+="_EndcapA"; - else canvname+="_EndcapC"; - if (iyx==0) canvname+="_dY"; else canvname+="_dX"; - canv->Print((outputdir+"/"+canvname+"_tantheta.eps").c_str()); - - canv->Clear(); +void makeCSCResPlots(TFile* outputHists) { + gStyle->SetOptStat(1); + gStyle->SetOptFit(111); + + // tan((detTheta-11.59)/360.*6.28), theta<25. + TH1F*** hMeans = new TH1F**[2]; + TF1**** fits = new TF1***[2]; + for (int iecAC = 0; iecAC < 2; iecAC++) { + hMeans[iecAC] = new TH1F*[NYX]; + fits[iecAC] = new TF1**[NYX]; + int ixy = 0; + for (int iyx = NYX - 1; iyx >= 0; iyx--, ixy++) { + string title = "#Delta "; + if (iyx == 0) + title += "y"; + else + title += "x"; + title += " (mm)"; + + string hmeanname = (DOCSC) ? "CSC" : "MDT"; + if (iecAC == 0) + hmeanname += "_EndcapA"; + else + hmeanname += "_EndcapC"; + if (iyx == 0) + hmeanname += "_dY"; + else + hmeanname += "_dX"; + hMeans[iecAC][iyx] = new TH1F(hmeanname.c_str(), hmeanname.c_str(), 16, 0., 16.); + fits[iecAC][iyx] = new TF1*[16]; + + TCanvas* canv = new TCanvas("canv", "canv"); + canv->SetFillColor(10); + canv->Divide(4, 4); + + for (int iphi = 0; iphi < 16; iphi++) { + canv->cd(iphi + 1); + stringstream fitname; + fitname << "fitRes_" << iphi + 1; + if (iecAC == 0) + fitname << "A"; + else + fitname << "C"; + if (iyx == 0) + fitname << "_dY"; + else + fitname << "_dX"; + double fitrange = (iyx == 0) ? 40. : 80.; + fits[iecAC][iyx][iphi] = + new TF1(fitname.str().c_str(), "[0]*exp(-0.5*((x-[1])/[2])^2)+[3]*[0]*exp(-0.5*((x-[1])/[4])^2)", -fitrange, fitrange); + TH1F* hist = phiSecHistsCSC[iecAC][iphi][iyx]; + TF1* fit = fits[iecAC][iyx][iphi]; + + double innerwidth = (iyx == 0) ? 8. : 16.; + double outerwidth = (iyx == 0) ? 20. : 40.; + fit->SetParameters(hist->GetMaximum(), hist->GetMean(), innerwidth, 0.8, outerwidth); + fit->SetParLimits(2, innerwidth / 4., outerwidth * 1.5); + hist->Fit(fit, "RQ"); + + hist->GetXaxis()->SetTitle(title.c_str()); + + hist->Draw(); + fit->Draw("same"); + + stringstream binLabel; + binLabel << iphi + 1; + if (iecAC == 0) + binLabel << "A"; + else + binLabel << "C"; + hMeans[iecAC][iyx]->GetXaxis()->SetBinLabel(iphi + 1, binLabel.str().c_str()); + if (fit->GetChisquare() / fit->GetNDF() < 5. && hist->GetEntries() > 1000.) { + hMeans[iecAC][iyx]->SetBinContent(iphi + 1, fit->GetParameter(1)); + hMeans[iecAC][iyx]->SetBinError(iphi + 1, fit->GetParError(1)); + if (iyx == 0) + cout << "dY: "; + else + cout << "dX: "; + cout << iphi + 1; + if (iecAC == 0) + cout << "A"; + else + cout << "C"; + cout << " " << fit->GetParameter(1) << " +/- " << fit->GetParError(1) << endl; + } + } + + string canvname = "CSC"; + if (iecAC == 0) + canvname += "_EndcapA"; + else + canvname += "_EndcapC"; + if (iyx == 0) + canvname += "_dY"; + else + canvname += "_dX"; + canv->Print((outputdir + "/" + canvname + ".eps").c_str()); + + canv->Clear(); + + if (hMeans[iecAC][iyx]->GetMaximum() > 20.) hMeans[iecAC][iyx]->SetMaximum(20.); + if (hMeans[iecAC][iyx]->GetMinimum() < -20.) hMeans[iecAC][iyx]->SetMinimum(-20.); + hMeans[iecAC][iyx]->Draw(); + hMeans[iecAC][iyx]->GetYaxis()->SetTitle(title.c_str()); + canv->Modified(); + + canv->Print((outputdir + "/" + canvname + "_allPhi.eps").c_str()); + + delete canv; + } + } - hMeans[iecAC][iyx]->Draw(); - hMeans[iecAC][iyx]->GetYaxis()->SetTitle(title.c_str()); - canv->Modified(); + return; +} - canv->Print((outputdir+"/"+canvname+"_allPhi_tantheta.eps").c_str()); - - delete canv; +//________________________________________________________________________ +void makeCSCResVTanThetaPlots(TFile* outputHists) { + gStyle->SetOptStat(1); + gStyle->SetOptFit(111); + gStyle->SetPalette(1); + + TH1F*** hMeans = new TH1F**[2]; + TF1**** fits = new TF1***[2]; + TH1F**** resVTanTheta = new TH1F***[2]; + for (int iecAC = 0; iecAC < 2; iecAC++) { + hMeans[iecAC] = new TH1F*[NYX]; + fits[iecAC] = new TF1**[NYX]; + resVTanTheta[iecAC] = new TH1F**[NYX]; + int ixy = NYX - 1; + for (int iyx = 0; iyx < NYX; iyx++, ixy--) { + string title = "#Delta "; + if (iyx == 0) + title += "y"; + else + title += "x"; + title += " (mm)"; + + string hmeanname = (iecAC == 0) ? "EndcapA" : "EndcapC"; + if (iyx == 0) + hmeanname += "_dY"; + else + hmeanname += "_dX"; + hMeans[iecAC][iyx] = new TH1F(hmeanname.c_str(), hmeanname.c_str(), 16, 0., 16.); + fits[iecAC][iyx] = new TF1*[16]; + resVTanTheta[iecAC][iyx] = new TH1F*[16]; + + TCanvas* canv = new TCanvas("canv", "canv"); + canv->SetFillColor(10); + canv->Divide(4, 4); + + for (int iphi = 0; iphi < 16; iphi++) { + canv->cd(iphi + 1); + + TH2F* hist = resVTanThetaHistsCSC[iecAC][iphi][iyx]; + + double fitrange = (iyx == 0) ? 20. : 40.; + string resHistName = string(hist->GetName()) + "Fits"; + resVTanTheta[iecAC][iyx][iphi] = new TH1F(resHistName.c_str(), resHistName.c_str(), 5, -.04, .06); + TH1F** slices = new TH1F*[5]; + for (int i = 0; i < 5; i++) { + stringstream tmphistname; + tmphistname << hist->GetName() << "_slice" << i; + slices[i] = (TH1F*)hist->ProjectionY(tmphistname.str().c_str(), i + 1, i + 2); + slices[i]->Draw(); + TF1* fit = new TF1("fit", "gaus", -fitrange, fitrange); + slices[i]->Fit(fit, "QR"); + resVTanTheta[iecAC][iyx][iphi]->SetBinContent(i + 1, fit->GetParameter(1)); + resVTanTheta[iecAC][iyx][iphi]->SetBinError(i + 1, fit->GetParError(1)); + delete fit; + } + string fitname = string(hist->GetName()) + "_fit"; + fits[iecAC][iyx][iphi] = new TF1(fitname.c_str(), "pol1", -fitrange, fitrange); + resVTanTheta[iecAC][iyx][iphi]->Fit(fits[iecAC][iyx][iphi], "RQ"); + + // canv->cd(iphi+1); + hist->GetYaxis()->SetRangeUser(-fitrange, fitrange); + // hist->Draw("colz"); + resVTanTheta[iecAC][iyx][iphi]->Draw("same"); + fits[iecAC][iyx][iphi]->Draw("same"); + } + + string canvname = "CSC"; + if (iecAC == 0) + canvname += "_EndcapA"; + else + canvname += "_EndcapC"; + if (iyx == 0) + canvname += "_dY"; + else + canvname += "_dX"; + canv->Print((outputdir + "/" + canvname + "_tantheta.eps").c_str()); + + canv->Clear(); + + hMeans[iecAC][iyx]->Draw(); + hMeans[iecAC][iyx]->GetYaxis()->SetTitle(title.c_str()); + canv->Modified(); + + canv->Print((outputdir + "/" + canvname + "_allPhi_tantheta.eps").c_str()); + + delete canv; + } } - } - - return; + + return; } //________________________________________________________________________ -void makeMDTResVTanThetaPlots(TFile* outputHists) -{ - gStyle->SetOptStat(1); - gStyle->SetOptFit(111); - gStyle->SetPalette(1); - - TH1F***** hMeans =new TH1F****[2]; - TF1****** fits =new TF1*****[2]; - TH1F****** resVTanTheta=new TH1F*****[2]; - for (int iecAC=0;iecAC<2;iecAC++) { - hMeans [iecAC]=new TH1F***[3]; - fits [iecAC]=new TF1****[3]; - resVTanTheta[iecAC]=new TH1F****[3]; - for (int ilayer=0;ilayer<3;ilayer++) { - hMeans [iecAC][ilayer]=new TH1F**[6]; - fits [iecAC][ilayer]=new TF1***[6]; - resVTanTheta[iecAC][ilayer]=new TH1F***[6]; - for (int ieta=0;ieta<6;ieta++) { - hMeans [iecAC][ilayer][ieta]=new TH1F*[NYX]; - fits [iecAC][ilayer][ieta]=new TF1**[NYX]; - resVTanTheta[iecAC][ilayer][ieta]=new TH1F**[NYX]; - - int ixy=NYX-1; - for (int iyx=0;iyx<NYX;iyx++,ixy--) { - string title="#Delta "; - if (iyx==0) title+="y"; else title+="x"; - title+=" (mm)"; - - string hmeanname="mean_resVTanTheta"+mdtChamberNameNoPhi(iecAC,ilayer,ieta); - if (iyx==0) hmeanname+="_dY"; else hmeanname+="_dX"; - hMeans [iecAC][ilayer][ieta][iyx]=new TH1F(hmeanname.c_str(),hmeanname.c_str(),16,0.,16.); - fits [iecAC][ilayer][ieta][iyx]=new TF1*[16]; - resVTanTheta[iecAC][ilayer][ieta][iyx]=new TH1F*[16]; - - TCanvas* canv=new TCanvas("canv","canv"); - canv->SetFillColor(10); - canv->Divide(4,4); - - for (int iphi=0;iphi<16;iphi++) { - canv->cd(iphi+1); - string fitname="fitRes_"+mdtChamberName(iecAC,ilayer,ieta,iphi)+"_dY"; - double fitrange=(iyx==0)?20.:40.; - if (ilayer==1) fitrange*=0.5; - - TH2F* hist=resVTanThetaHistsMDT[iecAC][ilayer][ieta][iphi][iyx]; - cout<<"hist has "<<hist->GetEntries()<<" entries"<<endl; - - string resHistName=string(hist->GetName())+"Fits"; - resVTanTheta[iecAC][ilayer][ieta][iyx][iphi]= - new TH1F(resHistName.c_str(),resHistName.c_str(),5,tanThetaMin[ilayer][ieta],tanThetaMax[ilayer][ieta]); - TH1F** slices=new TH1F*[5]; - for (int i=0;i<5;i++) { - stringstream tmphistname; tmphistname<<hist->GetName()<<"_slice"<<i; - slices[i]=(TH1F*)hist->ProjectionY(tmphistname.str().c_str(),i+1,i+2); - slices[i]->Draw(); - TF1* fit= - new TF1("fit", "gaus",-fitrange,fitrange); - slices[i]->Fit(fit,"QR"); - cout<<"mean["<<i<<"]: "<<fit->GetParameter(1)<<" +/- "<<fit->GetParError(1)<<endl; - - resVTanTheta[iecAC][ilayer][ieta][iyx][iphi]->SetBinContent(i+1,fit->GetParameter(1)); - resVTanTheta[iecAC][ilayer][ieta][iyx][iphi]->SetBinError(i+1,fit->GetParError(1)); - delete fit; - } - fits[iecAC][ilayer][ieta][iyx][iphi]=new TF1(fitname.c_str(),"pol1",-fitrange,fitrange); - TF1* fitpol1=fits[iecAC][ilayer][ieta][iyx][iphi]; - resVTanTheta[iecAC][ilayer][ieta][iyx][iphi]-> - Fit(fitpol1,"RQ"); - - hMeans[iecAC][ilayer][ieta][iyx]->SetBinContent(iphi+1,fitpol1->GetParameter(0)); - hMeans[iecAC][ilayer][ieta][iyx]->SetBinError(iphi+1,fitpol1->GetParError(0)); - - //canv->cd(iphi+1); - hist->GetYaxis()->SetRangeUser(-fitrange,fitrange); - //hist->Draw("colz"); - resVTanTheta[iecAC][ilayer][ieta][iyx][iphi]->Draw("same"); - fits[iecAC][ilayer][ieta][iyx][iphi]->Draw("same"); - } - - string canvname=mdtChamberNameNoPhi(iecAC,ilayer,ieta); - if (iyx==0) canvname+="_dY"; else canvname+="_dX"; - canv->Print((outputdir+"/"+canvname+"_tantheta.eps").c_str()); - //exit(3); - - canv->Clear(); - - hMeans[iecAC][ilayer][ieta][iyx]->Draw(); - hMeans[iecAC][ilayer][ieta][iyx]->GetYaxis()->SetTitle(title.c_str()); - canv->Modified(); - - hMeans[iecAC][ilayer][ieta][iyx]->Write(); - - canv->Print((outputdir+"/"+canvname+"_allPhi_tantheta.eps").c_str()); - - delete canv; - } - } +void makeMDTResVTanThetaPlots(TFile* outputHists) { + gStyle->SetOptStat(1); + gStyle->SetOptFit(111); + gStyle->SetPalette(1); + + TH1F***** hMeans = new TH1F****[2]; + TF1****** fits = new TF1*****[2]; + TH1F****** resVTanTheta = new TH1F*****[2]; + for (int iecAC = 0; iecAC < 2; iecAC++) { + hMeans[iecAC] = new TH1F***[3]; + fits[iecAC] = new TF1****[3]; + resVTanTheta[iecAC] = new TH1F****[3]; + for (int ilayer = 0; ilayer < 3; ilayer++) { + hMeans[iecAC][ilayer] = new TH1F**[6]; + fits[iecAC][ilayer] = new TF1***[6]; + resVTanTheta[iecAC][ilayer] = new TH1F***[6]; + for (int ieta = 0; ieta < 6; ieta++) { + hMeans[iecAC][ilayer][ieta] = new TH1F*[NYX]; + fits[iecAC][ilayer][ieta] = new TF1**[NYX]; + resVTanTheta[iecAC][ilayer][ieta] = new TH1F**[NYX]; + + int ixy = NYX - 1; + for (int iyx = 0; iyx < NYX; iyx++, ixy--) { + string title = "#Delta "; + if (iyx == 0) + title += "y"; + else + title += "x"; + title += " (mm)"; + + string hmeanname = "mean_resVTanTheta" + mdtChamberNameNoPhi(iecAC, ilayer, ieta); + if (iyx == 0) + hmeanname += "_dY"; + else + hmeanname += "_dX"; + hMeans[iecAC][ilayer][ieta][iyx] = new TH1F(hmeanname.c_str(), hmeanname.c_str(), 16, 0., 16.); + fits[iecAC][ilayer][ieta][iyx] = new TF1*[16]; + resVTanTheta[iecAC][ilayer][ieta][iyx] = new TH1F*[16]; + + TCanvas* canv = new TCanvas("canv", "canv"); + canv->SetFillColor(10); + canv->Divide(4, 4); + + for (int iphi = 0; iphi < 16; iphi++) { + canv->cd(iphi + 1); + string fitname = "fitRes_" + mdtChamberName(iecAC, ilayer, ieta, iphi) + "_dY"; + double fitrange = (iyx == 0) ? 20. : 40.; + if (ilayer == 1) fitrange *= 0.5; + + TH2F* hist = resVTanThetaHistsMDT[iecAC][ilayer][ieta][iphi][iyx]; + cout << "hist has " << hist->GetEntries() << " entries" << endl; + + string resHistName = string(hist->GetName()) + "Fits"; + resVTanTheta[iecAC][ilayer][ieta][iyx][iphi] = + new TH1F(resHistName.c_str(), resHistName.c_str(), 5, tanThetaMin[ilayer][ieta], tanThetaMax[ilayer][ieta]); + TH1F** slices = new TH1F*[5]; + for (int i = 0; i < 5; i++) { + stringstream tmphistname; + tmphistname << hist->GetName() << "_slice" << i; + slices[i] = (TH1F*)hist->ProjectionY(tmphistname.str().c_str(), i + 1, i + 2); + slices[i]->Draw(); + TF1* fit = new TF1("fit", "gaus", -fitrange, fitrange); + slices[i]->Fit(fit, "QR"); + cout << "mean[" << i << "]: " << fit->GetParameter(1) << " +/- " << fit->GetParError(1) << endl; + + resVTanTheta[iecAC][ilayer][ieta][iyx][iphi]->SetBinContent(i + 1, fit->GetParameter(1)); + resVTanTheta[iecAC][ilayer][ieta][iyx][iphi]->SetBinError(i + 1, fit->GetParError(1)); + delete fit; + } + fits[iecAC][ilayer][ieta][iyx][iphi] = new TF1(fitname.c_str(), "pol1", -fitrange, fitrange); + TF1* fitpol1 = fits[iecAC][ilayer][ieta][iyx][iphi]; + resVTanTheta[iecAC][ilayer][ieta][iyx][iphi]->Fit(fitpol1, "RQ"); + + hMeans[iecAC][ilayer][ieta][iyx]->SetBinContent(iphi + 1, fitpol1->GetParameter(0)); + hMeans[iecAC][ilayer][ieta][iyx]->SetBinError(iphi + 1, fitpol1->GetParError(0)); + + // canv->cd(iphi+1); + hist->GetYaxis()->SetRangeUser(-fitrange, fitrange); + // hist->Draw("colz"); + resVTanTheta[iecAC][ilayer][ieta][iyx][iphi]->Draw("same"); + fits[iecAC][ilayer][ieta][iyx][iphi]->Draw("same"); + } + + string canvname = mdtChamberNameNoPhi(iecAC, ilayer, ieta); + if (iyx == 0) + canvname += "_dY"; + else + canvname += "_dX"; + canv->Print((outputdir + "/" + canvname + "_tantheta.eps").c_str()); + // exit(3); + + canv->Clear(); + + hMeans[iecAC][ilayer][ieta][iyx]->Draw(); + hMeans[iecAC][ilayer][ieta][iyx]->GetYaxis()->SetTitle(title.c_str()); + canv->Modified(); + + hMeans[iecAC][ilayer][ieta][iyx]->Write(); + + canv->Print((outputdir + "/" + canvname + "_allPhi_tantheta.eps").c_str()); + + delete canv; + } + } + } } - } - - return; + + return; } //________________________________________________________________________ -void makeMDTResPlots(TFile* outputHists) -{ - gStyle->SetOptStat("uon"); - gStyle->SetOptFit(111); - - TH1F**** hPull =new TH1F***[2]; - TH1F***** hMeans=new TH1F****[2]; - TF1****** fits =new TF1*****[2]; - for (int iecAC=0;iecAC<2;iecAC++) { - hMeans[iecAC]=new TH1F***[3]; - fits [iecAC]=new TF1****[3]; - hPull [iecAC]=new TH1F**[3]; - for (int ilayer=0;ilayer<3;ilayer++) { - hMeans[iecAC][ilayer]=new TH1F**[6]; - fits [iecAC][ilayer]=new TF1***[6]; - hPull [iecAC][ilayer]=new TH1F*[6]; - for (int ieta=0;ieta<6;ieta++) { - hMeans[iecAC][ilayer][ieta]=new TH1F*[NYX]; - fits [iecAC][ilayer][ieta]=new TF1**[NYX]; - int ixy=0; - for (int iyx=NYX-1;iyx>=0;iyx--,ixy++) { - string title="#Delta "; - if (iyx==0) title+="y"; else title+="x"; - title+=" (mm)"; - - string hmeanname="mean_"+mdtChamberNameNoPhi(iecAC,ilayer,ieta); - if (iyx==0) hmeanname+="_dY"; else hmeanname+="_dX"; - hMeans[iecAC][ilayer][ieta][iyx]=new TH1F(hmeanname.c_str(),hmeanname.c_str(),16,0.,16.); - fits [iecAC][ilayer][ieta][iyx]=new TF1*[16]; - if (ieta==0) { - string histname="mean_"+mdtChamberNameNoEta(iecAC,ilayer)+"_dY_all"; - hPull [iecAC][ilayer][iyx]=new TH1F(histname.c_str(), - histname.c_str(), - 40,-10.,10.); - } - TCanvas* canv=new TCanvas("canv","canv"); - canv->SetFillColor(10); - canv->Divide(4,4); - - for (int iphi=0;iphi<16;iphi++) { - canv->cd(iphi+1); - string fitname="fitRes_"+mdtChamberName(iecAC,ilayer,ieta,iphi); - if (iyx==0) fitname+="_dY"; else fitname+="_dX"; - double fitrange=(iyx==0) ? 25. : 40.; - if (ilayer==1) fitrange*=0.5; - - TH1F* hist=phiSecEtaHistsMDT[iecAC][ilayer][ieta][iphi][iyx]; - - double innerwidth=(iyx==0)?4.:8.; - double outerwidth=(iyx==0)?10.:20.; - //if (ilayer<2) { - //innerwidth*=2; - //outerwidth*=2; - //} - if (hist->GetEntries()>1000&&ilayer==2) { - fits[iecAC][ilayer][ieta][iyx][iphi]= - new TF1(fitname.c_str(), - "[0]*exp(-0.5*((x-[1])/[2])^2)+[3]*[0]*exp(-0.5*((x-[1])/[4])^2)", - -fitrange,fitrange); - fits[iecAC][ilayer][ieta][iyx][iphi] - ->SetParameters(hist->GetMaximum(),hist->GetMean(),innerwidth,0.8,outerwidth); - fits[iecAC][ilayer][ieta][iyx][iphi] - ->SetParLimits(4,innerwidth*2.,outerwidth*5.); - } - else { - fits[iecAC][ilayer][ieta][iyx][iphi]= - new TF1(fitname.c_str(),"gaus",-fitrange,fitrange); - fits[iecAC][ilayer][ieta][iyx][iphi] - ->SetParameters(hist->GetMaximum(),hist->GetMean(),innerwidth); - } - - TF1* fit =fits[iecAC][ilayer][ieta][iyx][iphi]; - fit->SetParLimits(2,innerwidth/4.,innerwidth*2.); - - hist->Fit(fit,"RQL"); - - hist->GetXaxis()->SetTitle(title.c_str()); - - hist->Draw(); - fit->Draw("same"); - - stringstream binLabel; binLabel<<iphi+1; - if (iecAC==0) binLabel<<"A"; else binLabel<<"C"; - hMeans[iecAC][ilayer][ieta][iyx]->GetXaxis()->SetBinLabel(iphi+1,binLabel.str().c_str()); - //if (fit->GetChisquare()/fit->GetNDF()<5. && hist->GetEntries()>1000.) { - hMeans[iecAC][ilayer][ieta][iyx]->SetBinContent(iphi+1,fit->GetParameter(1)); - hMeans[iecAC][ilayer][ieta][iyx]->SetBinError (iphi+1,fit->GetParError(1)); - if (iyx==0) cout<<"dY: "; else cout<<"dX: "; - cout<<iphi+1; - if (iecAC==0) cout<<"A"; else cout<<"C"; - cout<<" "<<fit->GetParameter(1)<<" +/- "<<fit->GetParError(1)<<endl; - - if ((ilayer==0&&ieta<2) || - (ilayer==1&&ieta<3) || - (ilayer==2)) - hPull[iecAC][ilayer][iyx]->Fill(fit->GetParameter(1)/fit->GetParError(1)); - //} - } - - - string canvname=mdtChamberNameNoPhi(iecAC,ilayer,ieta); - if (iyx==0) canvname+="_dY"; else canvname+="_dX"; - canv->Print((outputdir+"/"+canvname+".eps").c_str()); - - canv->Clear(); - - if (hMeans[iecAC][ilayer][ieta][iyx]->GetMaximum()>20. || - hMeans[iecAC][ilayer][ieta][iyx]->GetMaximum()<-20.) { - hMeans[iecAC][ilayer][ieta][iyx]->SetMaximum(20.); - hMeans[iecAC][ilayer][ieta][iyx]->SetMinimum(-20.); - } - - hMeans[iecAC][ilayer][ieta][iyx]->Draw(); - hMeans[iecAC][ilayer][ieta][iyx]->GetYaxis()->SetTitle(title.c_str()); - canv->Modified(); - - hMeans[iecAC][ilayer][ieta][iyx]->Write(); - - canv->Print((outputdir+"/"+canvname+"_allPhi.eps").c_str()); - - canv->Clear(); - if (ieta==5) { - hPull[iecAC][ilayer][iyx]->Draw(); - hPull[iecAC][ilayer][iyx]->Fit("gaus","LQ"); - hPull[iecAC][ilayer][iyx]->GetXaxis()->SetTitle("pull"); - canv->Modified(); - - hPull[iecAC][ilayer][iyx]->Write(); - string canvname2=mdtChamberNameNoEta(iecAC,ilayer)+"_dY"; - canv->Print((outputdir+"/"+canvname2+"_all.eps").c_str()); - } - delete canv; - } - } +void makeMDTResPlots(TFile* outputHists) { + gStyle->SetOptStat("uon"); + gStyle->SetOptFit(111); + + TH1F**** hPull = new TH1F***[2]; + TH1F***** hMeans = new TH1F****[2]; + TF1****** fits = new TF1*****[2]; + for (int iecAC = 0; iecAC < 2; iecAC++) { + hMeans[iecAC] = new TH1F***[3]; + fits[iecAC] = new TF1****[3]; + hPull[iecAC] = new TH1F**[3]; + for (int ilayer = 0; ilayer < 3; ilayer++) { + hMeans[iecAC][ilayer] = new TH1F**[6]; + fits[iecAC][ilayer] = new TF1***[6]; + hPull[iecAC][ilayer] = new TH1F*[6]; + for (int ieta = 0; ieta < 6; ieta++) { + hMeans[iecAC][ilayer][ieta] = new TH1F*[NYX]; + fits[iecAC][ilayer][ieta] = new TF1**[NYX]; + int ixy = 0; + for (int iyx = NYX - 1; iyx >= 0; iyx--, ixy++) { + string title = "#Delta "; + if (iyx == 0) + title += "y"; + else + title += "x"; + title += " (mm)"; + + string hmeanname = "mean_" + mdtChamberNameNoPhi(iecAC, ilayer, ieta); + if (iyx == 0) + hmeanname += "_dY"; + else + hmeanname += "_dX"; + hMeans[iecAC][ilayer][ieta][iyx] = new TH1F(hmeanname.c_str(), hmeanname.c_str(), 16, 0., 16.); + fits[iecAC][ilayer][ieta][iyx] = new TF1*[16]; + if (ieta == 0) { + string histname = "mean_" + mdtChamberNameNoEta(iecAC, ilayer) + "_dY_all"; + hPull[iecAC][ilayer][iyx] = new TH1F(histname.c_str(), histname.c_str(), 40, -10., 10.); + } + TCanvas* canv = new TCanvas("canv", "canv"); + canv->SetFillColor(10); + canv->Divide(4, 4); + + for (int iphi = 0; iphi < 16; iphi++) { + canv->cd(iphi + 1); + string fitname = "fitRes_" + mdtChamberName(iecAC, ilayer, ieta, iphi); + if (iyx == 0) + fitname += "_dY"; + else + fitname += "_dX"; + double fitrange = (iyx == 0) ? 25. : 40.; + if (ilayer == 1) fitrange *= 0.5; + + TH1F* hist = phiSecEtaHistsMDT[iecAC][ilayer][ieta][iphi][iyx]; + + double innerwidth = (iyx == 0) ? 4. : 8.; + double outerwidth = (iyx == 0) ? 10. : 20.; + // if (ilayer<2) { + // innerwidth*=2; + // outerwidth*=2; + //} + if (hist->GetEntries() > 1000 && ilayer == 2) { + fits[iecAC][ilayer][ieta][iyx][iphi] = new TF1( + fitname.c_str(), "[0]*exp(-0.5*((x-[1])/[2])^2)+[3]*[0]*exp(-0.5*((x-[1])/[4])^2)", -fitrange, fitrange); + fits[iecAC][ilayer][ieta][iyx][iphi]->SetParameters(hist->GetMaximum(), hist->GetMean(), innerwidth, 0.8, + outerwidth); + fits[iecAC][ilayer][ieta][iyx][iphi]->SetParLimits(4, innerwidth * 2., outerwidth * 5.); + } else { + fits[iecAC][ilayer][ieta][iyx][iphi] = new TF1(fitname.c_str(), "gaus", -fitrange, fitrange); + fits[iecAC][ilayer][ieta][iyx][iphi]->SetParameters(hist->GetMaximum(), hist->GetMean(), innerwidth); + } + + TF1* fit = fits[iecAC][ilayer][ieta][iyx][iphi]; + fit->SetParLimits(2, innerwidth / 4., innerwidth * 2.); + + hist->Fit(fit, "RQL"); + + hist->GetXaxis()->SetTitle(title.c_str()); + + hist->Draw(); + fit->Draw("same"); + + stringstream binLabel; + binLabel << iphi + 1; + if (iecAC == 0) + binLabel << "A"; + else + binLabel << "C"; + hMeans[iecAC][ilayer][ieta][iyx]->GetXaxis()->SetBinLabel(iphi + 1, binLabel.str().c_str()); + // if (fit->GetChisquare()/fit->GetNDF()<5. && hist->GetEntries()>1000.) { + hMeans[iecAC][ilayer][ieta][iyx]->SetBinContent(iphi + 1, fit->GetParameter(1)); + hMeans[iecAC][ilayer][ieta][iyx]->SetBinError(iphi + 1, fit->GetParError(1)); + if (iyx == 0) + cout << "dY: "; + else + cout << "dX: "; + cout << iphi + 1; + if (iecAC == 0) + cout << "A"; + else + cout << "C"; + cout << " " << fit->GetParameter(1) << " +/- " << fit->GetParError(1) << endl; + + if ((ilayer == 0 && ieta < 2) || (ilayer == 1 && ieta < 3) || (ilayer == 2)) + hPull[iecAC][ilayer][iyx]->Fill(fit->GetParameter(1) / fit->GetParError(1)); + //} + } + + string canvname = mdtChamberNameNoPhi(iecAC, ilayer, ieta); + if (iyx == 0) + canvname += "_dY"; + else + canvname += "_dX"; + canv->Print((outputdir + "/" + canvname + ".eps").c_str()); + + canv->Clear(); + + if (hMeans[iecAC][ilayer][ieta][iyx]->GetMaximum() > 20. || hMeans[iecAC][ilayer][ieta][iyx]->GetMaximum() < -20.) { + hMeans[iecAC][ilayer][ieta][iyx]->SetMaximum(20.); + hMeans[iecAC][ilayer][ieta][iyx]->SetMinimum(-20.); + } + + hMeans[iecAC][ilayer][ieta][iyx]->Draw(); + hMeans[iecAC][ilayer][ieta][iyx]->GetYaxis()->SetTitle(title.c_str()); + canv->Modified(); + + hMeans[iecAC][ilayer][ieta][iyx]->Write(); + + canv->Print((outputdir + "/" + canvname + "_allPhi.eps").c_str()); + + canv->Clear(); + if (ieta == 5) { + hPull[iecAC][ilayer][iyx]->Draw(); + hPull[iecAC][ilayer][iyx]->Fit("gaus", "LQ"); + hPull[iecAC][ilayer][iyx]->GetXaxis()->SetTitle("pull"); + canv->Modified(); + + hPull[iecAC][ilayer][iyx]->Write(); + string canvname2 = mdtChamberNameNoEta(iecAC, ilayer) + "_dY"; + canv->Print((outputdir + "/" + canvname2 + "_all.eps").c_str()); + } + delete canv; + } + } + } } - } - - return; + return; } //________________________________________________________________________ -void makeWidthPlots(TFile* outputHists, const string& type) -{ - gStyle->SetOptStat(1); - gStyle->SetOptFit(111); - - int nplots=2; - - TF1**** fits=new TF1***[nplots]; - TH1F***** slices=new TH1F****[nplots]; - TH1F**** hSigmas=new TH1F***[nplots]; - - TH2F**** hists; - if (type=="EndcapAC") hists=ecHistsCSC; - else if (type=="LargeSmall") hists=lgsmHistsCSC; - else cout<<"bad type"<<endl; - - for (int iplot=0;iplot<nplots;iplot++) { - - fits [iplot]=new TF1** [3]; - slices[iplot]=new TH1F***[3]; - hSigmas[iplot]=new TH1F**[3]; - - for (int ilayer=0;ilayer<3;ilayer++) { - - fits [iplot][ilayer]=new TF1* [3]; - slices[iplot][ilayer]=new TH1F**[3]; - hSigmas[iplot][ilayer]=new TH1F*[3]; - - - for (int iyx=NYX-1;iyx>=0;iyx--) { - double fitrange=(iyx==0)?40.:80.; - stringstream fitname; fitname<<"fit_"<<iplot<<"_"<<ilayer<<"_"<<iyx; - //fits[iplot][iyx]=new TF1(fitname.str().c_str(),"[0]*exp(-0.5*((x-[1])/[2])^2)+[3]*[0]*exp(-0.5*((x-[4])/[5])^2)",-fitrange,fitrange); - fits[iplot][ilayer][iyx]=new TF1(fitname.str().c_str(),"gaus",-fitrange,fitrange); - TObjArray aSlices; - hists[iplot][ilayer][iyx]->FitSlicesY(fits[iplot][ilayer][iyx],0,NMOM,0,"QNR",&aSlices); - const int nSlices=aSlices.GetEntriesFast(); - slices[iplot][ilayer][iyx]=new TH1F*[nSlices]; - for (int islice=0;islice<nSlices;islice++) { - slices[iplot][ilayer][iyx][islice]=(TH1F*)aSlices[islice]->Clone(); - } - string hname=hists[iplot][ilayer][iyx]->GetName()+string("_2"); - hSigmas[iplot][ilayer][iyx]=(TH1F*)gDirectory->Get(hname.c_str())->Clone((hists[iplot][ilayer][iyx]->GetName()+string("_sigma")).c_str()); - - } - } - } - - TCanvas* ctmp=new TCanvas("ctmp","ctmp"); - TF1**** fits1OverP=new TF1***[3]; - TPaveStats**** paves=new TPaveStats***[3]; - double min[2]={999.,999.}; - double max[2]={0., 0.}; - for (int ilayer=0;ilayer<3;ilayer++) { - fits1OverP[ilayer]=new TF1**[NYX]; - paves [ilayer]=new TPaveStats**[NYX]; - - for (int iyx=NYX-1;iyx>=0;iyx--) { - fits1OverP[ilayer][iyx]=new TF1*[2]; - paves[ilayer][iyx]=new TPaveStats*[2]; - - // fit to 1/p and get min/max - for (int iplot=0;iplot<nplots;iplot++) { - for (int ibin=0;ibin<(int)hSigmas[iplot][ilayer][iyx]->GetNbinsX();ibin++) { - double bc=hSigmas[iplot][ilayer][iyx]->GetBinContent(ibin+1); - if (bc>max[iyx]) max[iyx]=bc; - if (bc>0.&&bc<min[iyx]) min[iyx]=bc; - } - stringstream fitname; fitname<<"fit1OverP_"<<ilayer<<"_"<<iyx<<"_ecAC"<<iplot; - fits1OverP[ilayer][iyx][iplot]= - new TF1(fitname.str().c_str(),"TMath::Sqrt([0]*[0]+[1]*[1]/(x-3.5)/(x-3.5))",9.,mommax); - - hSigmas[iplot][ilayer][iyx]->Fit(fits1OverP[ilayer][iyx][iplot],"RQ"); - - ctmp->Update(); - paves[ilayer][iyx][iplot]=(TPaveStats*)hSigmas[iplot][ilayer][iyx]->FindObject("stats"); - if (iplot==0) { - paves[ilayer][iyx][iplot]->SetY1NDC(0.8); - paves[ilayer][iyx][iplot]->SetY2NDC(1.0); - } - if (iplot==1) { - paves[ilayer][iyx][iplot]->SetY1NDC(0.6); - paves[ilayer][iyx][iplot]->SetY2NDC(0.8); - } - paves[ilayer][iyx][iplot]->SetTextColor(twocolors[iplot]); - ctmp->Modified(); - } - if (max[iyx]>0.) max[iyx]*=1.1; else max[iyx]*=0.8; - if (min[iyx]<0.) min[iyx]*=1.1; else min[iyx]*=0.8; +void makeWidthPlots(TFile* outputHists, const string& type) { + gStyle->SetOptStat(1); + gStyle->SetOptFit(111); + + int nplots = 2; + + TF1**** fits = new TF1***[nplots]; + TH1F***** slices = new TH1F****[nplots]; + TH1F**** hSigmas = new TH1F***[nplots]; + + TH2F**** hists; + if (type == "EndcapAC") + hists = ecHistsCSC; + else if (type == "LargeSmall") + hists = lgsmHistsCSC; + else + cout << "bad type" << endl; + + for (int iplot = 0; iplot < nplots; iplot++) { + fits[iplot] = new TF1**[3]; + slices[iplot] = new TH1F***[3]; + hSigmas[iplot] = new TH1F**[3]; + + for (int ilayer = 0; ilayer < 3; ilayer++) { + fits[iplot][ilayer] = new TF1*[3]; + slices[iplot][ilayer] = new TH1F**[3]; + hSigmas[iplot][ilayer] = new TH1F*[3]; + + for (int iyx = NYX - 1; iyx >= 0; iyx--) { + double fitrange = (iyx == 0) ? 40. : 80.; + stringstream fitname; + fitname << "fit_" << iplot << "_" << ilayer << "_" << iyx; + // fits[iplot][iyx]=new + // TF1(fitname.str().c_str(),"[0]*exp(-0.5*((x-[1])/[2])^2)+[3]*[0]*exp(-0.5*((x-[4])/[5])^2)",-fitrange,fitrange); + fits[iplot][ilayer][iyx] = new TF1(fitname.str().c_str(), "gaus", -fitrange, fitrange); + TObjArray aSlices; + hists[iplot][ilayer][iyx]->FitSlicesY(fits[iplot][ilayer][iyx], 0, NMOM, 0, "QNR", &aSlices); + const int nSlices = aSlices.GetEntriesFast(); + slices[iplot][ilayer][iyx] = new TH1F*[nSlices]; + for (int islice = 0; islice < nSlices; islice++) { slices[iplot][ilayer][iyx][islice] = (TH1F*)aSlices[islice]->Clone(); } + string hname = hists[iplot][ilayer][iyx]->GetName() + string("_2"); + hSigmas[iplot][ilayer][iyx] = + (TH1F*)gDirectory->Get(hname.c_str())->Clone((hists[iplot][ilayer][iyx]->GetName() + string("_sigma")).c_str()); + } + } } - } - delete ctmp; - - TCanvas* canv=new TCanvas("canv","canv"); - canv->SetFillColor(10); - canv->Divide(NYX,1); - for (int ilayer=0;ilayer<3;ilayer++) { - int ixy=0; - for (int iyx=NYX-1;iyx>=0;iyx--,ixy++) { - canv->cd(ixy+1); - for (int iplot=0;iplot<nplots;iplot++) { - hSigmas[iplot][ilayer][iyx]->SetMinimum(min[iyx]); - hSigmas[iplot][ilayer][iyx]->SetMaximum(1.1*max[iyx]); - hSigmas[iplot][ilayer][iyx]->SetLineColor(twocolors[iplot]); - - fits1OverP[ilayer][iyx][iplot]->SetLineWidth(2); - fits1OverP[ilayer][iyx][iplot]->SetLineColor(twocolors[iplot]); - - if (iplot==0) hSigmas[iplot][ilayer][iyx]->Draw(); - else hSigmas[iplot][ilayer][iyx]->Draw("same"); - fits1OverP[ilayer][iyx][iplot]->Draw("same"); - } + + TCanvas* ctmp = new TCanvas("ctmp", "ctmp"); + TF1**** fits1OverP = new TF1***[3]; + TPaveStats**** paves = new TPaveStats***[3]; + double min[2] = {999., 999.}; + double max[2] = {0., 0.}; + for (int ilayer = 0; ilayer < 3; ilayer++) { + fits1OverP[ilayer] = new TF1**[NYX]; + paves[ilayer] = new TPaveStats**[NYX]; + + for (int iyx = NYX - 1; iyx >= 0; iyx--) { + fits1OverP[ilayer][iyx] = new TF1*[2]; + paves[ilayer][iyx] = new TPaveStats*[2]; + + // fit to 1/p and get min/max + for (int iplot = 0; iplot < nplots; iplot++) { + for (int ibin = 0; ibin < (int)hSigmas[iplot][ilayer][iyx]->GetNbinsX(); ibin++) { + double bc = hSigmas[iplot][ilayer][iyx]->GetBinContent(ibin + 1); + if (bc > max[iyx]) max[iyx] = bc; + if (bc > 0. && bc < min[iyx]) min[iyx] = bc; + } + stringstream fitname; + fitname << "fit1OverP_" << ilayer << "_" << iyx << "_ecAC" << iplot; + fits1OverP[ilayer][iyx][iplot] = new TF1(fitname.str().c_str(), "TMath::Sqrt([0]*[0]+[1]*[1]/(x-3.5)/(x-3.5))", 9., mommax); + + hSigmas[iplot][ilayer][iyx]->Fit(fits1OverP[ilayer][iyx][iplot], "RQ"); + + ctmp->Update(); + paves[ilayer][iyx][iplot] = (TPaveStats*)hSigmas[iplot][ilayer][iyx]->FindObject("stats"); + if (iplot == 0) { + paves[ilayer][iyx][iplot]->SetY1NDC(0.8); + paves[ilayer][iyx][iplot]->SetY2NDC(1.0); + } + if (iplot == 1) { + paves[ilayer][iyx][iplot]->SetY1NDC(0.6); + paves[ilayer][iyx][iplot]->SetY2NDC(0.8); + } + paves[ilayer][iyx][iplot]->SetTextColor(twocolors[iplot]); + ctmp->Modified(); + } + if (max[iyx] > 0.) + max[iyx] *= 1.1; + else + max[iyx] *= 0.8; + if (min[iyx] < 0.) + min[iyx] *= 1.1; + else + min[iyx] *= 0.8; + } } - string detStr=(DOCSC)?"CSC":"MDT"; - if (DOBEE) detStr="BEE"; - string layerStr; - switch (ilayer) { - case 0: layerStr="inner"; break; - case 1: layerStr="middle"; break; - case 2: layerStr="outer"; break; - default: layerStr=""; break; + delete ctmp; + + TCanvas* canv = new TCanvas("canv", "canv"); + canv->SetFillColor(10); + canv->Divide(NYX, 1); + for (int ilayer = 0; ilayer < 3; ilayer++) { + int ixy = 0; + for (int iyx = NYX - 1; iyx >= 0; iyx--, ixy++) { + canv->cd(ixy + 1); + for (int iplot = 0; iplot < nplots; iplot++) { + hSigmas[iplot][ilayer][iyx]->SetMinimum(min[iyx]); + hSigmas[iplot][ilayer][iyx]->SetMaximum(1.1 * max[iyx]); + hSigmas[iplot][ilayer][iyx]->SetLineColor(twocolors[iplot]); + + fits1OverP[ilayer][iyx][iplot]->SetLineWidth(2); + fits1OverP[ilayer][iyx][iplot]->SetLineColor(twocolors[iplot]); + + if (iplot == 0) + hSigmas[iplot][ilayer][iyx]->Draw(); + else + hSigmas[iplot][ilayer][iyx]->Draw("same"); + fits1OverP[ilayer][iyx][iplot]->Draw("same"); + } + } + string detStr = (DOCSC) ? "CSC" : "MDT"; + if (DOBEE) detStr = "BEE"; + string layerStr; + switch (ilayer) { + case 0: layerStr = "inner"; break; + case 1: layerStr = "middle"; break; + case 2: layerStr = "outer"; break; + default: layerStr = ""; break; + } + if (type == "EndcapAC") + canv->Print((outputdir + "/" + detStr + "_" + layerStr + "_EndcapACWidth.eps").c_str()); + else if (type == "LargeSmall") + canv->Print((outputdir + "/" + detStr + "_" + layerStr + "_LgSmWidth.eps").c_str()); + else + cout << "bad type" << endl; } - if (type=="EndcapAC") - canv->Print((outputdir+"/"+detStr+"_"+layerStr+"_EndcapACWidth.eps").c_str()); - else if (type=="LargeSmall") - canv->Print((outputdir+"/"+detStr+"_"+layerStr+"_LgSmWidth.eps").c_str()); - else - cout<<"bad type"<<endl; - } - delete canv; - delete [] hSigmas; - - return; + delete canv; + delete[] hSigmas; + + return; } //________________________________________________________________________ -void setBranchAddresses(TTree* tree) -{ - tree->SetBranchAddress("nPixHits", &nPixHits); - tree->SetBranchAddress("nSCTHits", &nSCTHits); - tree->SetBranchAddress("nTRTHits", &nTRTHits); - tree->SetBranchAddress("nCSCHits", &nCSCHits); - tree->SetBranchAddress("nMDTHits", &nMDTHits); - tree->SetBranchAddress("nInnerMDTHits", &nInnerMDTHits); - tree->SetBranchAddress("nMiddleMDTHits", &nMiddleMDTHits); - tree->SetBranchAddress("nOuterMDTHits", &nOuterMDTHits); - tree->SetBranchAddress("nTriggerPhiHits", &nTriggerPhiHits); - tree->SetBranchAddress("author", &author); - tree->SetBranchAddress("hIndex", &hIndex); - tree->SetBranchAddress("phiSector", &phiSector); - tree->SetBranchAddress("isEndcap", &isEndcap); - tree->SetBranchAddress("identifier", &identifier); - tree->SetBranchAddress("isCSide", &isCSide); - tree->SetBranchAddress("detType", &detType); - tree->SetBranchAddress("layer", &layer); - tree->SetBranchAddress("stName", &stName); - tree->SetBranchAddress("stPhi", &stPhi); - tree->SetBranchAddress("stEta", &stEta); - tree->SetBranchAddress("momentum", &momentum); - tree->SetBranchAddress("charge", &charge); - tree->SetBranchAddress("d0", &d0); - tree->SetBranchAddress("z0", &z0); - tree->SetBranchAddress("phi0", &phi0); - tree->SetBranchAddress("theta0", &theta0); - tree->SetBranchAddress("eta0", &eta0); - tree->SetBranchAddress("calEnergyLoss", &calEnergyLoss); - tree->SetBranchAddress("calEnergyLossErr", &calEnergyLossErr); - tree->SetBranchAddress("materialOnTrack", &materialOnTrack); - tree->SetBranchAddress("dR", &dR); - tree->SetBranchAddress("dZlocal", &dZlocal); - tree->SetBranchAddress("dXlocal", &dXlocal); - tree->SetBranchAddress("dYlocal", &dYlocal); - tree->SetBranchAddress("dXlocalAngle", &dXlocalAngle); - tree->SetBranchAddress("dYlocalAngle", &dYlocalAngle); - tree->SetBranchAddress("dXglobal", &dXglobal); - tree->SetBranchAddress("dYglobal", &dYglobal); - tree->SetBranchAddress("dZglobal", &dZglobal); - tree->SetBranchAddress("nInnerChambers", &nInnerChambers); - tree->SetBranchAddress("nMiddleChambers", &nMiddleChambers); - tree->SetBranchAddress("nOuterChambers", &nOuterChambers); - tree->SetBranchAddress("nOtherChambers", &nOtherChambers); - tree->SetBranchAddress("detTheta", &detTheta); - tree->SetBranchAddress("innerStEta", innerStEta); - tree->SetBranchAddress("middleStEta", middleStEta); - tree->SetBranchAddress("outerStEta", outerStEta); - tree->SetBranchAddress("otherStEta", otherStEta); - - return; +void setBranchAddresses(TTree* tree) { + tree->SetBranchAddress("nPixHits", &nPixHits); + tree->SetBranchAddress("nSCTHits", &nSCTHits); + tree->SetBranchAddress("nTRTHits", &nTRTHits); + tree->SetBranchAddress("nCSCHits", &nCSCHits); + tree->SetBranchAddress("nMDTHits", &nMDTHits); + tree->SetBranchAddress("nInnerMDTHits", &nInnerMDTHits); + tree->SetBranchAddress("nMiddleMDTHits", &nMiddleMDTHits); + tree->SetBranchAddress("nOuterMDTHits", &nOuterMDTHits); + tree->SetBranchAddress("nTriggerPhiHits", &nTriggerPhiHits); + tree->SetBranchAddress("author", &author); + tree->SetBranchAddress("hIndex", &hIndex); + tree->SetBranchAddress("phiSector", &phiSector); + tree->SetBranchAddress("isEndcap", &isEndcap); + tree->SetBranchAddress("identifier", &identifier); + tree->SetBranchAddress("isCSide", &isCSide); + tree->SetBranchAddress("detType", &detType); + tree->SetBranchAddress("layer", &layer); + tree->SetBranchAddress("stName", &stName); + tree->SetBranchAddress("stPhi", &stPhi); + tree->SetBranchAddress("stEta", &stEta); + tree->SetBranchAddress("momentum", &momentum); + tree->SetBranchAddress("charge", &charge); + tree->SetBranchAddress("d0", &d0); + tree->SetBranchAddress("z0", &z0); + tree->SetBranchAddress("phi0", &phi0); + tree->SetBranchAddress("theta0", &theta0); + tree->SetBranchAddress("eta0", &eta0); + tree->SetBranchAddress("calEnergyLoss", &calEnergyLoss); + tree->SetBranchAddress("calEnergyLossErr", &calEnergyLossErr); + tree->SetBranchAddress("materialOnTrack", &materialOnTrack); + tree->SetBranchAddress("dR", &dR); + tree->SetBranchAddress("dZlocal", &dZlocal); + tree->SetBranchAddress("dXlocal", &dXlocal); + tree->SetBranchAddress("dYlocal", &dYlocal); + tree->SetBranchAddress("dXlocalAngle", &dXlocalAngle); + tree->SetBranchAddress("dYlocalAngle", &dYlocalAngle); + tree->SetBranchAddress("dXglobal", &dXglobal); + tree->SetBranchAddress("dYglobal", &dYglobal); + tree->SetBranchAddress("dZglobal", &dZglobal); + tree->SetBranchAddress("nInnerChambers", &nInnerChambers); + tree->SetBranchAddress("nMiddleChambers", &nMiddleChambers); + tree->SetBranchAddress("nOuterChambers", &nOuterChambers); + tree->SetBranchAddress("nOtherChambers", &nOtherChambers); + tree->SetBranchAddress("detTheta", &detTheta); + tree->SetBranchAddress("innerStEta", innerStEta); + tree->SetBranchAddress("middleStEta", middleStEta); + tree->SetBranchAddress("outerStEta", outerStEta); + tree->SetBranchAddress("otherStEta", otherStEta); + + return; } //________________________________________________________________________ -void getHistograms(bool histsDone) -{ - string histname=outputdir+"/inputHists"; - string detStr=(DOCSC)?"CSC":"MDT"; - - if (!DOCSC && DOBEE) detStr="BEE"; - - if (DOCSC) histname+="_CSC.root"; - else if (!DOBEE) histname+="_MDT.root"; - else histname+="_MDT_BEE.root"; - - if (histsDone) inputHistsFile=new TFile(histname.c_str(),"READ"); - - // large/small hists - lgsmHistsCSC=new TH2F***[2]; - for (int ilgsm=0;ilgsm<2;ilgsm++) { - lgsmHistsCSC[ilgsm]=new TH2F**[3]; - for (int ilayer=0;ilayer<3;ilayer++) { - lgsmHistsCSC[ilgsm][ilayer]=new TH2F*[2]; - for (int iyx=0;iyx<NYX;iyx++) { - double valmax=(iyx==0) ? 40.4: 80.8; - double valmin=-valmax; - string name=(ilgsm==0)?"LargeHists":"SmallHists"; - if (ilayer==0) name+="_inner"; - else if (ilayer==1) name+="_middle"; - else name+="_outer"; - - if (iyx==0) name+="_dY"; else name+="_dX"; - name+="_"+detStr; - if (!histsDone) { - cout<<"writing "<<name<<endl; - lgsmHistsCSC[ilgsm][ilayer][iyx]=new TH2F(name.c_str(), name.c_str(), - NMOM,mommin,mommax,NVALBINS,valmin,valmax); - } - else { - cout<<"getting "<<name<<endl; - lgsmHistsCSC[ilgsm][ilayer][iyx]=(TH2F*)inputHistsFile->Get(name.c_str()); - cout<<"hist has "<<lgsmHistsCSC[ilgsm][ilayer][iyx]->GetEntries()<<" entries"<<endl; - } - } - } - } - - // endcap AC hists - ecHistsCSC=new TH2F***[2]; - for (int iecAC=0;iecAC<2;iecAC++) { - ecHistsCSC[iecAC]=new TH2F**[3]; - for (int ilayer=0;ilayer<3;ilayer++) { - ecHistsCSC[iecAC][ilayer]=new TH2F*[NYX]; - for (int iyx=0;iyx<NYX;iyx++) { - double valmax=(iyx==0) ? 40.4: 80.8; - double valmin=-valmax; - string name=(iecAC==0)?"EndcapA":"EndcapC"; - if (ilayer==0) name+="_inner"; - else if (ilayer==1) name+="_middle"; - else name+="_outer"; - if (iyx==0) name+="_dY"; else name+="_dX"; - name+="_"+detStr; - if (!histsDone) { - cout<<"writing "<<name<<endl; - ecHistsCSC[iecAC][ilayer][iyx]=new TH2F(name.c_str(), name.c_str(), - NMOM,mommin,mommax,NVALBINS,valmin,valmax); - } - else { - cout<<"getting "<<name<<endl; - ecHistsCSC[iecAC][ilayer][iyx]=(TH2F*)inputHistsFile->Get(name.c_str()); - cout<<"hist has "<<ecHistsCSC[iecAC][ilayer][iyx]->GetEntries()<<" entries"<<endl; - } - } - } - } - - // CSC chamber hists - phiSecHistsCSC =new TH1F***[2]; - resVTanThetaHistsCSC=new TH2F***[2]; - for (int iecAC=0;iecAC<2;iecAC++) { - phiSecHistsCSC [iecAC]=new TH1F**[16]; - resVTanThetaHistsCSC[iecAC]=new TH2F**[16]; - for (int iphi=0;iphi<16;iphi++) { - phiSecHistsCSC [iecAC][iphi]=new TH1F*[2]; - resVTanThetaHistsCSC[iecAC][iphi]=new TH2F*[2]; - for (int iyx=0;iyx<NYX;iyx++) { - double valmax=(iyx==0) ? 40.4 : 80.8; - double valmin=-valmax; - stringstream name; name<<"Sector"<<iphi+1; - if (iecAC==0) name<<"A"; else name<<"C"; - if (iyx==0) name<<"_dY"; else name<<"_dX"; - name<<"_CSC"; - if (!histsDone) { - phiSecHistsCSC[iecAC][iphi][iyx]=new TH1F(name.str().c_str(),name.str().c_str(), - NVALBINS,valmin,valmax); - double min=std::tan(-2.5*3.14159/180.); - double max=std::tan( 3.5*3.14159/180.); - - resVTanThetaHistsCSC[iecAC][iphi][iyx]= - new TH2F((name.str()+"_resVTanTheta").c_str(), - (name.str()+"_resVTanTheta").c_str(), - 5,min,max,50,valmin,valmax); - } - else { - phiSecHistsCSC[iecAC][iphi][iyx]=(TH1F*)inputHistsFile->Get(name.str().c_str()); - resVTanThetaHistsCSC[iecAC][iphi][iyx]=(TH2F*)inputHistsFile->Get((name.str()+"_resVTanTheta").c_str()); - } - } - } - } - - // MDT phi-sector hists - phiSecHistsMDT=new TH1F**[2]; - for (int iecAC=0;iecAC<2;iecAC++) { - phiSecHistsMDT[iecAC]=new TH1F*[16]; - for (int iphi=0;iphi<16;iphi++) { - double valmax=40.4; - double valmin=-valmax; - stringstream name; name<<"Sector"<<iphi+1; - if (iecAC==0) name<<"A"; else name<<"C"; - name<<"_dY_MDT"; - if (!histsDone) { - phiSecHistsMDT[iecAC][iphi]=new TH1F(name.str().c_str(),name.str().c_str(), - NVALBINS,valmin,valmax); - double min=std::tan(-2.5*3.14159/180.); - double max=std::tan( 3.5*3.14159/180.); - - } - else { - phiSecHistsMDT[iecAC][iphi]=(TH1F*)inputHistsFile->Get(name.str().c_str()); - } - } - } - - // EC MDT chamber hists - phiSecEtaHistsMDT =new TH1F*****[2]; - resVTanThetaHistsMDT=new TH2F*****[2]; - for (int iecAC=0;iecAC<2;iecAC++) { - phiSecEtaHistsMDT [iecAC]=new TH1F****[3]; - resVTanThetaHistsMDT[iecAC]=new TH2F****[3]; - for (int ilayer=0;ilayer<3;ilayer++) { - phiSecEtaHistsMDT [iecAC][ilayer]=new TH1F***[6]; - resVTanThetaHistsMDT[iecAC][ilayer]=new TH2F***[6]; - for (int ieta=0;ieta<6;ieta++) { - phiSecEtaHistsMDT [iecAC][ilayer][ieta]=new TH1F**[16]; - resVTanThetaHistsMDT[iecAC][ilayer][ieta]=new TH2F**[16]; - for (int iphi=0;iphi<16;iphi++) { - phiSecEtaHistsMDT [iecAC][ilayer][ieta][iphi]=new TH1F*[2]; - resVTanThetaHistsMDT[iecAC][ilayer][ieta][iphi]=new TH2F*[2]; - for (int iyx=0;iyx<NYX;iyx++) { - double valmax=(iyx==0) ? 40.4 : 80.8; - if (ilayer==1) valmax*=.5; - - double valmin=-valmax; - stringstream name; - name<<mdtChamberName(iecAC,ilayer,ieta,iphi); - /* - name<<"E"; - if (ilayer==0) name<<"I"; - else if (ilayer==1) name<<"M"; - else if (ilayer==2) name<<"O"; - if (iphi%2==0) name<<"L"; else name<<"S"; - name<<ieta+1; - if (iecAC==0) name<<"A"; else name<<"C"; - if (iphi%2==0) name<<iphi/2+1; - else name<<(iphi-1)/2+1; - */ - if (iyx==0) name<<"_dY"; else name<<"_dX"; - if (!histsDone) { - phiSecEtaHistsMDT[iecAC][ilayer][ieta][iphi][iyx]= - new TH1F(name.str().c_str(),name.str().c_str(), - NVALBINS,valmin,valmax); - resVTanThetaHistsMDT[iecAC][ilayer][ieta][iphi][iyx]= - new TH2F((name.str()+"VTanTheta").c_str(), - (name.str()+"VTanTheta").c_str(), - 5,tanThetaMin[ilayer][ieta],tanThetaMax[ilayer][ieta], - 50,valmin,valmax); - } - else { - phiSecEtaHistsMDT[iecAC][ilayer][ieta][iphi][iyx]= - (TH1F*)inputHistsFile->Get(name.str().c_str()); - resVTanThetaHistsMDT[iecAC][ilayer][ieta][iphi][iyx]= - (TH2F*)inputHistsFile->Get((name.str()+"VTanTheta").c_str()); - } - } - } - } - } - } - - if (!histsDone) { - //string filename=(!USETGCETA)?"/data/roberth/bfieldoff_V6_noTGC/UnbiasedMuonResiduals.root":"/data/roberth/bfieldoff_V6/UnbiasedMuonResiduals.root"; - //string filename=(!USETGCETA)?"/data/roberth/bfieldoff_V6_noTGC/UnbiasedMuonResiduals.root":"/data/roberth/bfieldoff_V6/UnbiasedMuonResiduals.root"; - string filename="/data/roberth/bfieldoff_V10/UnbiasedMuonResiduals.root"; - - /* - TFile* inputfile=new TFile(filename.c_str(),"READ"); - TTree* tree=(TTree*)inputfile->Get("unbiasedMuonResiduals"); - */ - TChain* tree=new TChain("unbiasedMuonResiduals"); - tree->Add("/data/roberth/bfieldoff_V10/UnbiasedMuonResiduals*root"); - - setBranchAddresses(tree); - - cout<<"tree has "<<tree->GetEntries()<<" entries"<<endl; - for (int ientry=0;ientry<(int)tree->GetEntries();ientry++) { - tree->GetEntry(ientry); +void getHistograms(bool histsDone) { + string histname = outputdir + "/inputHists"; + string detStr = (DOCSC) ? "CSC" : "MDT"; - // CSC hists - // single inner layer hit - if (DOCSC && nInnerChambers>1) continue; + if (!DOCSC && DOBEE) detStr = "BEE"; - if (DOBEE) { - if (nOtherChambers<1) continue; - } - else { - if (nOtherChambers>0) continue; - } + if (DOCSC) + histname += "_CSC.root"; + else if (!DOBEE) + histname += "_MDT.root"; + else + histname += "_MDT_BEE.root"; + + if (histsDone) inputHistsFile = new TFile(histname.c_str(), "READ"); + + // large/small hists + lgsmHistsCSC = new TH2F***[2]; + for (int ilgsm = 0; ilgsm < 2; ilgsm++) { + lgsmHistsCSC[ilgsm] = new TH2F**[3]; + for (int ilayer = 0; ilayer < 3; ilayer++) { + lgsmHistsCSC[ilgsm][ilayer] = new TH2F*[2]; + for (int iyx = 0; iyx < NYX; iyx++) { + double valmax = (iyx == 0) ? 40.4 : 80.8; + double valmin = -valmax; + string name = (ilgsm == 0) ? "LargeHists" : "SmallHists"; + if (ilayer == 0) + name += "_inner"; + else if (ilayer == 1) + name += "_middle"; + else + name += "_outer"; + + if (iyx == 0) + name += "_dY"; + else + name += "_dX"; + name += "_" + detStr; + if (!histsDone) { + cout << "writing " << name << endl; + lgsmHistsCSC[ilgsm][ilayer][iyx] = new TH2F(name.c_str(), name.c_str(), NMOM, mommin, mommax, NVALBINS, valmin, valmax); + } else { + cout << "getting " << name << endl; + lgsmHistsCSC[ilgsm][ilayer][iyx] = (TH2F*)inputHistsFile->Get(name.c_str()); + cout << "hist has " << lgsmHistsCSC[ilgsm][ilayer][iyx]->GetEntries() << " entries" << endl; + } + } + } + } - // CSC/MDT selection - if (DOCSC && detType==0) continue; - if (!DOCSC) { - if (detType==1) continue; - //if (layer!=0 || (stEta!=1&&stEta!=-1)) continue; - } - - // select Muid/Moore track - if (hIndex!=0) continue; - - // select endcap - if (DOEC && isEndcap==0) continue; - - // I don't know what's going on with these guys - //if ((stEta>0&&detTheta>25.) || (stEta<0&&detTheta<(180.-25.))) continue; - - // fill histogram - int ilgsm=(phiSector%2==1)?0:1; - int iecAC=(stEta>0)?0:1; - int iphi =phiSector-1; - for (int iyx=0;iyx<NYX;iyx++) { - double val=(iyx==0)?dYlocal:dXlocal; - int theta=(stEta>0)?detTheta : 180.-detTheta; - - if (layer<3) { - lgsmHistsCSC[ilgsm][layer][iyx]->Fill(momentum,val); - ecHistsCSC [iecAC][layer][iyx]->Fill(momentum,val); - } - - if (DOCSC) { - if (momentum>=momCut) { - phiSecHistsCSC[iecAC][iphi][iyx]->Fill(val); - double tanTheta=std::tan((theta-11.59)*3.14159/180.); - resVTanThetaHistsCSC[iecAC][iphi][iyx]->Fill(tanTheta,val); - } - } - else { - if (layer>2) continue; - - /* - if (layer==0&&nInnerChambers>1) continue; - if (layer==1&&nMiddleChambers>1) continue; - if (layer==2&&nOuterChambers>1) continue; - */ - // require only 1 chamber in each layer - if (nInnerChambers!=1||nMiddleChambers!=1||nOuterChambers!=1) continue; - //cout<<"stEta: "<<stEta<<", innerStEta[0]="<<innerStEta[0]<<", "<<"middleStEta[0]="<<middleStEta[0]<<", "<<"outerStEta[0]="<<outerStEta[0]<<endl; - - /* - if (layer==1) { - int ieta=(stEta>0)?stEta-1:-stEta-1; - int thisInnerEta=(stEta>0)?innerStEta[0]:-innerStEta[0]; - int thisOuterEta=(stEta>0)?outerStEta[0]:-outerStEta[0]; - - if (thisInnerEta!=allowedInnerLayerForMiddleFixed[ieta]) continue; - if (thisOuterEta!=allowedOuterLayerForMiddleFixed[ieta]) continue; - } - */ - - int ieta=abs(stEta)-1; - if (momentum>=momCut) { - phiSecEtaHistsMDT[iecAC][layer][ieta][iphi][iyx]->Fill(val); - phiSecHistsMDT[iecAC][iphi]->Fill(val); - double tanTheta=std::tan(theta*3.14159/180.); - resVTanThetaHistsMDT[iecAC][layer][ieta][iphi][iyx]->Fill(tanTheta,val); - } - } - } + // endcap AC hists + ecHistsCSC = new TH2F***[2]; + for (int iecAC = 0; iecAC < 2; iecAC++) { + ecHistsCSC[iecAC] = new TH2F**[3]; + for (int ilayer = 0; ilayer < 3; ilayer++) { + ecHistsCSC[iecAC][ilayer] = new TH2F*[NYX]; + for (int iyx = 0; iyx < NYX; iyx++) { + double valmax = (iyx == 0) ? 40.4 : 80.8; + double valmin = -valmax; + string name = (iecAC == 0) ? "EndcapA" : "EndcapC"; + if (ilayer == 0) + name += "_inner"; + else if (ilayer == 1) + name += "_middle"; + else + name += "_outer"; + if (iyx == 0) + name += "_dY"; + else + name += "_dX"; + name += "_" + detStr; + if (!histsDone) { + cout << "writing " << name << endl; + ecHistsCSC[iecAC][ilayer][iyx] = new TH2F(name.c_str(), name.c_str(), NMOM, mommin, mommax, NVALBINS, valmin, valmax); + } else { + cout << "getting " << name << endl; + ecHistsCSC[iecAC][ilayer][iyx] = (TH2F*)inputHistsFile->Get(name.c_str()); + cout << "hist has " << ecHistsCSC[iecAC][ilayer][iyx]->GetEntries() << " entries" << endl; + } + } + } } - //inputfile->Close(); - - inputHistsFile=new TFile(histname.c_str(),"RECREATE"); - for (int ilgsm=0;ilgsm<2;ilgsm++) { - for (int ilayer=0;ilayer<3;ilayer++) { - for (int iyx=0;iyx<NYX;iyx++) { - lgsmHistsCSC[ilgsm][ilayer][iyx]->Write(); - } - } + + // CSC chamber hists + phiSecHistsCSC = new TH1F***[2]; + resVTanThetaHistsCSC = new TH2F***[2]; + for (int iecAC = 0; iecAC < 2; iecAC++) { + phiSecHistsCSC[iecAC] = new TH1F**[16]; + resVTanThetaHistsCSC[iecAC] = new TH2F**[16]; + for (int iphi = 0; iphi < 16; iphi++) { + phiSecHistsCSC[iecAC][iphi] = new TH1F*[2]; + resVTanThetaHistsCSC[iecAC][iphi] = new TH2F*[2]; + for (int iyx = 0; iyx < NYX; iyx++) { + double valmax = (iyx == 0) ? 40.4 : 80.8; + double valmin = -valmax; + stringstream name; + name << "Sector" << iphi + 1; + if (iecAC == 0) + name << "A"; + else + name << "C"; + if (iyx == 0) + name << "_dY"; + else + name << "_dX"; + name << "_CSC"; + if (!histsDone) { + phiSecHistsCSC[iecAC][iphi][iyx] = new TH1F(name.str().c_str(), name.str().c_str(), NVALBINS, valmin, valmax); + double min = std::tan(-2.5 * 3.14159 / 180.); + double max = std::tan(3.5 * 3.14159 / 180.); + + resVTanThetaHistsCSC[iecAC][iphi][iyx] = new TH2F( + (name.str() + "_resVTanTheta").c_str(), (name.str() + "_resVTanTheta").c_str(), 5, min, max, 50, valmin, valmax); + } else { + phiSecHistsCSC[iecAC][iphi][iyx] = (TH1F*)inputHistsFile->Get(name.str().c_str()); + resVTanThetaHistsCSC[iecAC][iphi][iyx] = (TH2F*)inputHistsFile->Get((name.str() + "_resVTanTheta").c_str()); + } + } + } } - for (int iecAC=0;iecAC<2;iecAC++) { - for (int ilayer=0;ilayer<3;ilayer++) { - for (int iyx=0;iyx<NYX;iyx++) { - ecHistsCSC[iecAC][ilayer][iyx]->Write(); - } - } + + // MDT phi-sector hists + phiSecHistsMDT = new TH1F**[2]; + for (int iecAC = 0; iecAC < 2; iecAC++) { + phiSecHistsMDT[iecAC] = new TH1F*[16]; + for (int iphi = 0; iphi < 16; iphi++) { + double valmax = 40.4; + double valmin = -valmax; + stringstream name; + name << "Sector" << iphi + 1; + if (iecAC == 0) + name << "A"; + else + name << "C"; + name << "_dY_MDT"; + if (!histsDone) { + phiSecHistsMDT[iecAC][iphi] = new TH1F(name.str().c_str(), name.str().c_str(), NVALBINS, valmin, valmax); + double min = std::tan(-2.5 * 3.14159 / 180.); + double max = std::tan(3.5 * 3.14159 / 180.); + + } else { + phiSecHistsMDT[iecAC][iphi] = (TH1F*)inputHistsFile->Get(name.str().c_str()); + } + } } - if (DOCSC) { - for (int iecAC=0;iecAC<2;iecAC++) { - for (int iphi=0;iphi<16;iphi++) { - for (int iyx=0;iyx<NYX;iyx++) { - phiSecHistsCSC[iecAC][iphi][iyx]->Write(); - resVTanThetaHistsCSC[iecAC][iphi][iyx]->Write(); - } - } - } + + // EC MDT chamber hists + phiSecEtaHistsMDT = new TH1F*****[2]; + resVTanThetaHistsMDT = new TH2F*****[2]; + for (int iecAC = 0; iecAC < 2; iecAC++) { + phiSecEtaHistsMDT[iecAC] = new TH1F****[3]; + resVTanThetaHistsMDT[iecAC] = new TH2F****[3]; + for (int ilayer = 0; ilayer < 3; ilayer++) { + phiSecEtaHistsMDT[iecAC][ilayer] = new TH1F***[6]; + resVTanThetaHistsMDT[iecAC][ilayer] = new TH2F***[6]; + for (int ieta = 0; ieta < 6; ieta++) { + phiSecEtaHistsMDT[iecAC][ilayer][ieta] = new TH1F**[16]; + resVTanThetaHistsMDT[iecAC][ilayer][ieta] = new TH2F**[16]; + for (int iphi = 0; iphi < 16; iphi++) { + phiSecEtaHistsMDT[iecAC][ilayer][ieta][iphi] = new TH1F*[2]; + resVTanThetaHistsMDT[iecAC][ilayer][ieta][iphi] = new TH2F*[2]; + for (int iyx = 0; iyx < NYX; iyx++) { + double valmax = (iyx == 0) ? 40.4 : 80.8; + if (ilayer == 1) valmax *= .5; + + double valmin = -valmax; + stringstream name; + name << mdtChamberName(iecAC, ilayer, ieta, iphi); + /* + name<<"E"; + if (ilayer==0) name<<"I"; + else if (ilayer==1) name<<"M"; + else if (ilayer==2) name<<"O"; + if (iphi%2==0) name<<"L"; else name<<"S"; + name<<ieta+1; + if (iecAC==0) name<<"A"; else name<<"C"; + if (iphi%2==0) name<<iphi/2+1; + else name<<(iphi-1)/2+1; + */ + if (iyx == 0) + name << "_dY"; + else + name << "_dX"; + if (!histsDone) { + phiSecEtaHistsMDT[iecAC][ilayer][ieta][iphi][iyx] = + new TH1F(name.str().c_str(), name.str().c_str(), NVALBINS, valmin, valmax); + resVTanThetaHistsMDT[iecAC][ilayer][ieta][iphi][iyx] = + new TH2F((name.str() + "VTanTheta").c_str(), (name.str() + "VTanTheta").c_str(), 5, + tanThetaMin[ilayer][ieta], tanThetaMax[ilayer][ieta], 50, valmin, valmax); + } else { + phiSecEtaHistsMDT[iecAC][ilayer][ieta][iphi][iyx] = (TH1F*)inputHistsFile->Get(name.str().c_str()); + resVTanThetaHistsMDT[iecAC][ilayer][ieta][iphi][iyx] = + (TH2F*)inputHistsFile->Get((name.str() + "VTanTheta").c_str()); + } + } + } + } + } } - else { // MDT hists - for (int iecAC=0;iecAC<2;iecAC++) { - for (int iphi=0;iphi<16;iphi++) - phiSecHistsMDT[iecAC][iphi]->Write(); - for (int ilayer=0;ilayer<3;ilayer++) { - for (int ieta=0;ieta<6;ieta++) { - for (int iphi=0;iphi<16;iphi++) { - for (int iyx=0;iyx<NYX;iyx++) { - phiSecEtaHistsMDT[iecAC][ilayer][ieta][iphi][iyx]->Write(); - resVTanThetaHistsMDT[iecAC][ilayer][ieta][iphi][iyx]->Write(); - } - } - } - } - } + + if (!histsDone) { + // string + // filename=(!USETGCETA)?"/data/roberth/bfieldoff_V6_noTGC/UnbiasedMuonResiduals.root":"/data/roberth/bfieldoff_V6/UnbiasedMuonResiduals.root"; + // string + // filename=(!USETGCETA)?"/data/roberth/bfieldoff_V6_noTGC/UnbiasedMuonResiduals.root":"/data/roberth/bfieldoff_V6/UnbiasedMuonResiduals.root"; + string filename = "/data/roberth/bfieldoff_V10/UnbiasedMuonResiduals.root"; + + /* + TFile* inputfile=new TFile(filename.c_str(),"READ"); + TTree* tree=(TTree*)inputfile->Get("unbiasedMuonResiduals"); + */ + TChain* tree = new TChain("unbiasedMuonResiduals"); + tree->Add("/data/roberth/bfieldoff_V10/UnbiasedMuonResiduals*root"); + + setBranchAddresses(tree); + + cout << "tree has " << tree->GetEntries() << " entries" << endl; + for (int ientry = 0; ientry < (int)tree->GetEntries(); ientry++) { + tree->GetEntry(ientry); + + // CSC hists + // single inner layer hit + if (DOCSC && nInnerChambers > 1) continue; + + if (DOBEE) { + if (nOtherChambers < 1) continue; + } else { + if (nOtherChambers > 0) continue; + } + + // CSC/MDT selection + if (DOCSC && detType == 0) continue; + if (!DOCSC) { + if (detType == 1) continue; + // if (layer!=0 || (stEta!=1&&stEta!=-1)) continue; + } + + // select Muid/Moore track + if (hIndex != 0) continue; + + // select endcap + if (DOEC && isEndcap == 0) continue; + + // I don't know what's going on with these guys + // if ((stEta>0&&detTheta>25.) || (stEta<0&&detTheta<(180.-25.))) continue; + + // fill histogram + int ilgsm = (phiSector % 2 == 1) ? 0 : 1; + int iecAC = (stEta > 0) ? 0 : 1; + int iphi = phiSector - 1; + for (int iyx = 0; iyx < NYX; iyx++) { + double val = (iyx == 0) ? dYlocal : dXlocal; + int theta = (stEta > 0) ? detTheta : 180. - detTheta; + + if (layer < 3) { + lgsmHistsCSC[ilgsm][layer][iyx]->Fill(momentum, val); + ecHistsCSC[iecAC][layer][iyx]->Fill(momentum, val); + } + + if (DOCSC) { + if (momentum >= momCut) { + phiSecHistsCSC[iecAC][iphi][iyx]->Fill(val); + double tanTheta = std::tan((theta - 11.59) * 3.14159 / 180.); + resVTanThetaHistsCSC[iecAC][iphi][iyx]->Fill(tanTheta, val); + } + } else { + if (layer > 2) continue; + + /* + if (layer==0&&nInnerChambers>1) continue; + if (layer==1&&nMiddleChambers>1) continue; + if (layer==2&&nOuterChambers>1) continue; + */ + // require only 1 chamber in each layer + if (nInnerChambers != 1 || nMiddleChambers != 1 || nOuterChambers != 1) continue; + // cout<<"stEta: "<<stEta<<", innerStEta[0]="<<innerStEta[0]<<", "<<"middleStEta[0]="<<middleStEta[0]<<", + // "<<"outerStEta[0]="<<outerStEta[0]<<endl; + + /* + if (layer==1) { + int ieta=(stEta>0)?stEta-1:-stEta-1; + int thisInnerEta=(stEta>0)?innerStEta[0]:-innerStEta[0]; + int thisOuterEta=(stEta>0)?outerStEta[0]:-outerStEta[0]; + + if (thisInnerEta!=allowedInnerLayerForMiddleFixed[ieta]) continue; + if (thisOuterEta!=allowedOuterLayerForMiddleFixed[ieta]) continue; + } + */ + + int ieta = abs(stEta) - 1; + if (momentum >= momCut) { + phiSecEtaHistsMDT[iecAC][layer][ieta][iphi][iyx]->Fill(val); + phiSecHistsMDT[iecAC][iphi]->Fill(val); + double tanTheta = std::tan(theta * 3.14159 / 180.); + resVTanThetaHistsMDT[iecAC][layer][ieta][iphi][iyx]->Fill(tanTheta, val); + } + } + } + } + // inputfile->Close(); + + inputHistsFile = new TFile(histname.c_str(), "RECREATE"); + for (int ilgsm = 0; ilgsm < 2; ilgsm++) { + for (int ilayer = 0; ilayer < 3; ilayer++) { + for (int iyx = 0; iyx < NYX; iyx++) { lgsmHistsCSC[ilgsm][ilayer][iyx]->Write(); } + } + } + for (int iecAC = 0; iecAC < 2; iecAC++) { + for (int ilayer = 0; ilayer < 3; ilayer++) { + for (int iyx = 0; iyx < NYX; iyx++) { ecHistsCSC[iecAC][ilayer][iyx]->Write(); } + } + } + if (DOCSC) { + for (int iecAC = 0; iecAC < 2; iecAC++) { + for (int iphi = 0; iphi < 16; iphi++) { + for (int iyx = 0; iyx < NYX; iyx++) { + phiSecHistsCSC[iecAC][iphi][iyx]->Write(); + resVTanThetaHistsCSC[iecAC][iphi][iyx]->Write(); + } + } + } + } else { // MDT hists + for (int iecAC = 0; iecAC < 2; iecAC++) { + for (int iphi = 0; iphi < 16; iphi++) phiSecHistsMDT[iecAC][iphi]->Write(); + for (int ilayer = 0; ilayer < 3; ilayer++) { + for (int ieta = 0; ieta < 6; ieta++) { + for (int iphi = 0; iphi < 16; iphi++) { + for (int iyx = 0; iyx < NYX; iyx++) { + phiSecEtaHistsMDT[iecAC][ilayer][ieta][iphi][iyx]->Write(); + resVTanThetaHistsMDT[iecAC][ilayer][ieta][iphi][iyx]->Write(); + } + } + } + } + } + } } - } - - return; + return; } //________________________________________________________________________ -string mdtChamberName(int iecAC, int ilayer, int ieta, int iphi) -{ - - stringstream name; name<<"E"; - if (ilayer==0) name<<"I"; - else if (ilayer==1) name<<"M"; - else if (ilayer==2) name<<"O"; - else cout<<"bad layer"<<endl; - - if (iphi%2==0) name<<"L"; - else name<<"S"; - - name<<ieta+1; - - if (iecAC==0) name<<"A"; - else name<<"C"; - - if (iphi%2==0) name<<iphi/2+1; - else name<<(iphi-1)/2+1; - - return name.str(); +string mdtChamberName(int iecAC, int ilayer, int ieta, int iphi) { + stringstream name; + name << "E"; + if (ilayer == 0) + name << "I"; + else if (ilayer == 1) + name << "M"; + else if (ilayer == 2) + name << "O"; + else + cout << "bad layer" << endl; + + if (iphi % 2 == 0) + name << "L"; + else + name << "S"; + + name << ieta + 1; + + if (iecAC == 0) + name << "A"; + else + name << "C"; + + if (iphi % 2 == 0) + name << iphi / 2 + 1; + else + name << (iphi - 1) / 2 + 1; + + return name.str(); } //________________________________________________________________________ -string mdtChamberNameNoEta(int iecAC, int ilayer) -{ - - stringstream name; name<<"E"; - if (ilayer==0) name<<"I"; - else if (ilayer==1) name<<"M"; - else if (ilayer==2) name<<"O"; - else cout<<"bad layer"<<endl; - - name<<"X"; - - if (iecAC==0) name<<"A"; - else name<<"C"; - - return name.str(); +string mdtChamberNameNoEta(int iecAC, int ilayer) { + stringstream name; + name << "E"; + if (ilayer == 0) + name << "I"; + else if (ilayer == 1) + name << "M"; + else if (ilayer == 2) + name << "O"; + else + cout << "bad layer" << endl; + + name << "X"; + + if (iecAC == 0) + name << "A"; + else + name << "C"; + + return name.str(); } //________________________________________________________________________ -string mdtChamberNameNoPhi(int iecAC, int ilayer, int ieta) -{ - - stringstream name; name<<"E"; - if (ilayer==0) name<<"I"; - else if (ilayer==1) name<<"M"; - else if (ilayer==2) name<<"O"; - else cout<<"bad layer"<<endl; - - name<<"X"; - - name<<ieta+1; - - if (iecAC==0) name<<"A"; - else name<<"C"; - - return name.str(); +string mdtChamberNameNoPhi(int iecAC, int ilayer, int ieta) { + stringstream name; + name << "E"; + if (ilayer == 0) + name << "I"; + else if (ilayer == 1) + name << "M"; + else if (ilayer == 2) + name << "O"; + else + cout << "bad layer" << endl; + + name << "X"; + name << ieta + 1; + + if (iecAC == 0) + name << "A"; + else + name << "C"; + + return name.str(); } //________________________________________________________________________ -void plotLgSmSummary(TPad* canv, TH1F** hists, const string& canvname) -{ - gStyle->SetOptStat(0); - gStyle->SetOptFit(111); - - canv->Clear(); - /* - double max=-999.; - double min=999.; - for (int i=0;i<2;i++) { - for (int j=0;j<16;j++) { - double val=hists[i]->GetBinContent(j+1); - double err=hists[i]->GetBinError(j+1); - if (val>0) val+=err; - else val-=err; - if (val>max && val!=0.) max=val; - if (val<min && val!=0.) min=val; +void plotLgSmSummary(TPad* canv, TH1F** hists, const string& canvname) { + gStyle->SetOptStat(0); + gStyle->SetOptFit(111); + + canv->Clear(); + /* + double max=-999.; + double min=999.; + for (int i=0;i<2;i++) { + for (int j=0;j<16;j++) { + double val=hists[i]->GetBinContent(j+1); + double err=hists[i]->GetBinError(j+1); + if (val>0) val+=err; + else val-=err; + if (val>max && val!=0.) max=val; + if (val<min && val!=0.) min=val; + } } - } - if (max>0) max*=1.1; else max*=0.9; - if (min<0) min*=1.1; else min*=0.9; - - for (int i=0;i<2;i++) { - hists[i]->SetMaximum(max); - hists[i]->SetMinimum(min); - } - */ - - hists[0]->SetLineColor(twocolors[0]); - hists[0]->Draw(); - - TCanvas* ctmp=new TCanvas("ctmpLgSmSummary","ctmpLgSmSummary"); - - TF1** fits=new TF1*[2]; - TPaveStats** paves=new TPaveStats*[2]; - fits[0]=new TF1("fitLg","pol0",0.,16.); - fits[1]=new TF1("fitSm","pol0",0.,16.); - for (int i=0;i<2;i++) { - hists[i]->SetLineColor(twocolors[i]); - ctmp->cd(); - hists[i]->Fit(fits[i],"RQ"); - ctmp->Update(); - paves[i]=(TPaveStats*)hists[i]->FindObject("stats"); - if (i==0) { - paves[i]->SetY1NDC(0.92); - paves[i]->SetY2NDC(1.0); + if (max>0) max*=1.1; else max*=0.9; + if (min<0) min*=1.1; else min*=0.9; + + for (int i=0;i<2;i++) { + hists[i]->SetMaximum(max); + hists[i]->SetMinimum(min); } - else { - paves[i]->SetY1NDC(0.84); - paves[i]->SetY2NDC(0.92); + */ + + hists[0]->SetLineColor(twocolors[0]); + hists[0]->Draw(); + + TCanvas* ctmp = new TCanvas("ctmpLgSmSummary", "ctmpLgSmSummary"); + + TF1** fits = new TF1*[2]; + TPaveStats** paves = new TPaveStats*[2]; + fits[0] = new TF1("fitLg", "pol0", 0., 16.); + fits[1] = new TF1("fitSm", "pol0", 0., 16.); + for (int i = 0; i < 2; i++) { + hists[i]->SetLineColor(twocolors[i]); + ctmp->cd(); + hists[i]->Fit(fits[i], "RQ"); + ctmp->Update(); + paves[i] = (TPaveStats*)hists[i]->FindObject("stats"); + if (i == 0) { + paves[i]->SetY1NDC(0.92); + paves[i]->SetY2NDC(1.0); + } else { + paves[i]->SetY1NDC(0.84); + paves[i]->SetY2NDC(0.92); + } + paves[i]->SetTextColor(twocolors[i]); + ctmp->Modified(); + + canv->cd(); + fits[i]->SetLineColor(twocolors[i]); + if (i == 0) + hists[i]->Draw(); + else + hists[i]->Draw("same"); + fits[i]->Draw("same"); } - paves[i]->SetTextColor(twocolors[i]); - ctmp->Modified(); - - canv->cd(); - fits[i]->SetLineColor(twocolors[i]); - if (i==0) hists[i]->Draw(); - else hists[i]->Draw("same"); - fits[i]->Draw("same"); - } - canv->Update(); - canv->Print(canvname.c_str()); - delete [] fits; - delete ctmp; - - return; + canv->Update(); + canv->Print(canvname.c_str()); + delete[] fits; + delete ctmp; + + return; } diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/ALinePar.h b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/ALinePar.h index 4540ebde5c2c224f2715b84da7d15b0d1b935965..f3f5b32e825917e595feb8e31d13f9cffe9ba134 100755 --- a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/ALinePar.h +++ b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/ALinePar.h @@ -6,39 +6,30 @@ #define MUONALIGNMENTDATA_ALINEPAR_H #include "CLHEP/Geometry/Transform3D.h" - #include "MuonAlignmentData/MuonAlignmentPar.h" class ALinePar : public MuonAlignmentPar { - - public: - - // Default constructor - ALinePar(); - // destructor - virtual ~ALinePar() override = default; - - void setParameters(float s, float z, float t, - float rotS, float rotZ, float rotT); - - void getParameters(float& s, float& z, float& t, - float& rotS, float& rotZ, float& rotT) const; - - HepGeom::Transform3D deltaTransform() const; - - private: - - // translation parameters - float m_S; - float m_Z; - float m_T; - // rotation parameters - float m_rotS; - float m_rotZ; - float m_rotT; - - +public: + // Default constructor + ALinePar(); + // destructor + virtual ~ALinePar() override = default; + + void setParameters(float s, float z, float t, float rotS, float rotZ, float rotT); + + void getParameters(float& s, float& z, float& t, float& rotS, float& rotZ, float& rotT) const; + + HepGeom::Transform3D deltaTransform() const; + +private: + // translation parameters + float m_S; + float m_Z; + float m_T; + // rotation parameters + float m_rotS; + float m_rotZ; + float m_rotT; }; - #endif // MUONALIGNMENTDATA_ALINEPAR_H diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/ALineParContainer.h b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/ALineParContainer.h index df2a90f7869d432cbdb90c3fcfec4e6dcc267aa2..3dd049839636536184f2040a6df5bde2a79bd5b9 100755 --- a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/ALineParContainer.h +++ b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/ALineParContainer.h @@ -9,20 +9,15 @@ #include "AthenaKernel/CLASS_DEF.h" #include "MuonAlignmentData/ALinePar.h" -class ALineParContainer : public DataVector<ALinePar> -{ - public: - ALineParContainer(); - ~ALineParContainer(); - +class ALineParContainer : public DataVector<ALinePar> { +public: + ALineParContainer(); + ~ALineParContainer(); }; -inline ALineParContainer::ALineParContainer(): - DataVector<ALinePar>() -{ } +inline ALineParContainer::ALineParContainer() : DataVector<ALinePar>() {} -inline ALineParContainer::~ALineParContainer() -{ } +inline ALineParContainer::~ALineParContainer() {} CLASS_DEF(ALineParContainer, 1324994856, 1) diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/BLinePar.h b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/BLinePar.h index a79cc1085db911ca598303ee493ce4c94f5f2496..71abe8339060a3ec7266c4d3a9a843358753dc31 100755 --- a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/BLinePar.h +++ b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/BLinePar.h @@ -8,65 +8,40 @@ #include "MuonAlignmentData/MuonAlignmentPar.h" class BLinePar : public MuonAlignmentPar { - - public: - - // Default constructor - BLinePar(); - // destructor - virtual ~BLinePar() override = default; - - void setParameters(float bz, - float bp, - float bn, - float sp, - float sn, - float tw, - float pg, - float tr, - float eg, - float ep, - float en); - - void getParameters(float& bz, - float& bp, - float& bn, - float& sp, - float& sn, - float& tw, - float& pg, - float& tr, - float& eg, - float& ep, - float& en) const; - float bz() const {return m_bz;} - float bp() const {return m_bp;} - float bn() const {return m_bn;} - float sp() const {return m_sp;} - float sn() const {return m_sn;} - float tw() const {return m_tw;} - float pg() const {return m_pg;} - float tr() const {return m_tr;} - float eg() const {return m_eg;} - float ep() const {return m_ep;} - float en() const {return m_en;} - - private: - - - float m_bz; // tube bow in plane - float m_bp; // tube bow out of plane - float m_bn; // tube bow out of plane - float m_sp; // cross plate sag out of plane - float m_sn; // cross plate sag out of plane - float m_tw; // twist - float m_pg; // parallelogram - float m_tr; // trapezoid - float m_eg; // global expansion - float m_ep; // local expansion - float m_en; // local expansion - +public: + // Default constructor + BLinePar(); + // destructor + virtual ~BLinePar() override = default; + + void setParameters(float bz, float bp, float bn, float sp, float sn, float tw, float pg, float tr, float eg, float ep, float en); + + void getParameters(float& bz, float& bp, float& bn, float& sp, float& sn, float& tw, float& pg, float& tr, float& eg, float& ep, + float& en) const; + float bz() const { return m_bz; } + float bp() const { return m_bp; } + float bn() const { return m_bn; } + float sp() const { return m_sp; } + float sn() const { return m_sn; } + float tw() const { return m_tw; } + float pg() const { return m_pg; } + float tr() const { return m_tr; } + float eg() const { return m_eg; } + float ep() const { return m_ep; } + float en() const { return m_en; } + +private: + float m_bz; // tube bow in plane + float m_bp; // tube bow out of plane + float m_bn; // tube bow out of plane + float m_sp; // cross plate sag out of plane + float m_sn; // cross plate sag out of plane + float m_tw; // twist + float m_pg; // parallelogram + float m_tr; // trapezoid + float m_eg; // global expansion + float m_ep; // local expansion + float m_en; // local expansion }; - #endif // MUONALIGNMENTDATA_BLINEPAR_H diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/BLineParContainer.h b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/BLineParContainer.h index 36866d4d27482a680f86a6f6208a3c8f7fb764d5..9e53b9771cac6d2c35e271a45d6f3a6f9ed90fb3 100755 --- a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/BLineParContainer.h +++ b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/BLineParContainer.h @@ -9,21 +9,16 @@ #include "AthenaKernel/CLASS_DEF.h" #include "MuonAlignmentData/BLinePar.h" -class BLineParContainer : public DataVector<BLinePar> -{ - public: - BLineParContainer(); - ~BLineParContainer(); - +class BLineParContainer : public DataVector<BLinePar> { +public: + BLineParContainer(); + ~BLineParContainer(); }; -inline BLineParContainer::BLineParContainer(): - DataVector<BLinePar>() -{ } +inline BLineParContainer::BLineParContainer() : DataVector<BLinePar>() {} -inline BLineParContainer::~BLineParContainer() -{ } +inline BLineParContainer::~BLineParContainer() {} -CLASS_DEF( BLineParContainer , 1124991367 , 1 ) +CLASS_DEF(BLineParContainer, 1124991367, 1) #endif // MUONALIGNMENTDATA_BLINEPARCONTAINER_H diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/CorrContainer.h b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/CorrContainer.h index 4bf99332575de69dcf5eb148712192dca2a337c1..a67b3cf7ad6c482a15ca9a4efdc5b1c05bbb028f 100755 --- a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/CorrContainer.h +++ b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/CorrContainer.h @@ -7,32 +7,31 @@ #include "AthenaKernel/CLASS_DEF.h" #include "AthenaKernel/CondCont.h" -#include "MuonIdHelpers/MdtIdHelper.h" #include "MuonAlignmentData/ALinePar.h" #include "MuonAlignmentData/BLinePar.h" #include "MuonAlignmentData/CscInternalAlignmentPar.h" #include "MuonAlignmentData/MdtAsBuiltPar.h" - -typedef std::map<Identifier,ALinePar> ALineMapContainer; -CLASS_DEF(ALineMapContainer,1324994866,1) -CLASS_DEF( CondCont<ALineMapContainer>, 1201194425, 0) +#include "MuonIdHelpers/MdtIdHelper.h" -typedef std::map<Identifier,BLinePar> BLineMapContainer; -CLASS_DEF(BLineMapContainer,1124991377,1) -CLASS_DEF( CondCont<BLineMapContainer>, 1332301344, 0) +typedef std::map<Identifier, ALinePar> ALineMapContainer; +CLASS_DEF(ALineMapContainer, 1324994866, 1) +CLASS_DEF(CondCont<ALineMapContainer>, 1201194425, 0) -typedef std::map<Identifier,CscInternalAlignmentPar> CscInternalAlignmentMapContainer; -CLASS_DEF(CscInternalAlignmentMapContainer,1285567354,1) -CLASS_DEF( CondCont<CscInternalAlignmentMapContainer>, 1227105862, 0) +typedef std::map<Identifier, BLinePar> BLineMapContainer; +CLASS_DEF(BLineMapContainer, 1124991377, 1) +CLASS_DEF(CondCont<BLineMapContainer>, 1332301344, 0) -typedef std::map<Identifier,MdtAsBuiltPar> MdtAsBuiltMapContainer; -CLASS_DEF( MdtAsBuiltMapContainer , 1198729422 , 1 ) -CLASS_DEF( CondCont<MdtAsBuiltMapContainer>, 1076645826, 0) +typedef std::map<Identifier, CscInternalAlignmentPar> CscInternalAlignmentMapContainer; +CLASS_DEF(CscInternalAlignmentMapContainer, 1285567354, 1) +CLASS_DEF(CondCont<CscInternalAlignmentMapContainer>, 1227105862, 0) + +typedef std::map<Identifier, MdtAsBuiltPar> MdtAsBuiltMapContainer; +CLASS_DEF(MdtAsBuiltMapContainer, 1198729422, 1) +CLASS_DEF(CondCont<MdtAsBuiltMapContainer>, 1076645826, 0) typedef ALineMapContainer::iterator iALineMap; typedef BLineMapContainer::iterator iBLineMap; typedef CscInternalAlignmentMapContainer::iterator iCscInternalAlignmentMap; typedef MdtAsBuiltMapContainer::iterator iMdtAsBuiltMap; - -#endif // MUONALIGNMENTDATA_ALINEPARCONTAINER_H +#endif // MUONALIGNMENTDATA_ALINEPARCONTAINER_H diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/CscInternalAlignmentPar.h b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/CscInternalAlignmentPar.h index a93508fa63920309613921d039faa6ee742e9b51..b726b5ac2f5e02d9d91f510abcf946e783a2c294 100755 --- a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/CscInternalAlignmentPar.h +++ b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/CscInternalAlignmentPar.h @@ -5,42 +5,34 @@ #ifndef MUONALIGNMENTDATA_CSCLINEPAR_H #define MUONALIGNMENTDATA_CSCLINEPAR_H - #include "MuonAlignmentData/MuonAlignmentPar.h" class CscInternalAlignmentPar : public MuonAlignmentPar { +public: + // Default constructor + CscInternalAlignmentPar(); + // destructor + virtual ~CscInternalAlignmentPar() override = default; - public: - - // Default constructor - CscInternalAlignmentPar(); - // destructor - virtual ~CscInternalAlignmentPar() override = default; + void setAmdbId(const std::string& type, int jff, int jzz, int job, int wireLayer); + void getAmdbId(std::string& type, int& jff, int& jzz, int& job, int& wireLayer) const; - void setAmdbId(const std::string& type, int jff, int jzz, int job, int wireLayer); - void getAmdbId(std::string& type, int& jff, int& jzz, int& job, int& wireLayer) const; + void setParameters(float s, float z, float t, float rotS, float rotZ, float rotT); - void setParameters(float s, float z, float t, - float rotS, float rotZ, float rotT); + void getParameters(float& s, float& z, float& t, float& rotS, float& rotZ, float& rotT) const; - void getParameters(float& s, float& z, float& t, - float& rotS, float& rotZ, float& rotT) const; - - private: +private: // wire layer identifier - int m_wireLayer; - - // translation parameters - float m_S; - float m_Z; - float m_T; - // rotation parameters - float m_rotS; - float m_rotZ; - float m_rotT; - - + int m_wireLayer; + + // translation parameters + float m_S; + float m_Z; + float m_T; + // rotation parameters + float m_rotS; + float m_rotZ; + float m_rotT; }; - #endif // MUONALIGNMENTDATA_CSCLINEPAR_H diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/CscInternalAlignmentParContainer.h b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/CscInternalAlignmentParContainer.h index 15d39414133c10e659c1dbb172a5c21b295600f8..f33dfd87d5b7a78638635468697f30c9aa155a93 100755 --- a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/CscInternalAlignmentParContainer.h +++ b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/CscInternalAlignmentParContainer.h @@ -9,17 +9,13 @@ #include "AthenaKernel/CLASS_DEF.h" #include "MuonAlignmentData/CscInternalAlignmentPar.h" -class CscInternalAlignmentParContainer : public DataVector<CscInternalAlignmentPar> -{ - public: - CscInternalAlignmentParContainer(); - ~CscInternalAlignmentParContainer()=default; - +class CscInternalAlignmentParContainer : public DataVector<CscInternalAlignmentPar> { +public: + CscInternalAlignmentParContainer(); + ~CscInternalAlignmentParContainer() = default; }; -inline CscInternalAlignmentParContainer::CscInternalAlignmentParContainer(): - DataVector<CscInternalAlignmentPar>() -{ } +inline CscInternalAlignmentParContainer::CscInternalAlignmentParContainer() : DataVector<CscInternalAlignmentPar>() {} CLASS_DEF(CscInternalAlignmentParContainer, 1324994858, 1) diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/MdtAsBuiltPar.h b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/MdtAsBuiltPar.h index ac681355a97250b62d064a84849080892c48d64f..ca2898932f2087d7e23208da82913ede49452fd5 100755 --- a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/MdtAsBuiltPar.h +++ b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/MdtAsBuiltPar.h @@ -5,17 +5,17 @@ #ifndef MUONALIGNMENTDATA_MDTASBUILTPAR_H #define MUONALIGNMENTDATA_MDTASBUILTPAR_H -#include "MuonAlignmentData/MuonAlignmentPar.h" #include <string> +#include "MuonAlignmentData/MuonAlignmentPar.h" + /** * Container classfor the MDT as-built parameters * See parameter description in * http://atlas-muon-align.web.cern.ch/atlas-muon-align/endplug/asbuilt.pdf */ class MdtAsBuiltPar : public MuonAlignmentPar { - public: - +public: // Default constructor MdtAsBuiltPar(); @@ -25,34 +25,22 @@ class MdtAsBuiltPar : public MuonAlignmentPar { /** * MDT multi-layer index */ - enum multilayer_t { - ML1=0, - ML2, - NMLTYPES - }; + enum multilayer_t { ML1 = 0, ML2, NMLTYPES }; /** * MDT tube side */ enum tubeSide_t { - POS=0, // s>0 side - NEG, // s<0 side - NTUBESIDETYPES + POS = 0, // s>0 side + NEG, // s<0 side + NTUBESIDETYPES }; /** * Set the alignment parameters for a ML and a tube side */ - void setAlignmentParameters( - multilayer_t iML, - tubeSide_t iTubeSide, - float y0, - float z0, - float alpha, - float ypitch, - float zpitch, - int stagg - ); + void setAlignmentParameters(multilayer_t iML, tubeSide_t iTubeSide, float y0, float z0, float alpha, float ypitch, float zpitch, + int stagg); /** * Initialize from a line of an ASCII CLOB, return true on success @@ -60,32 +48,30 @@ class MdtAsBuiltPar : public MuonAlignmentPar { bool setFromAscii(const std::string& line); // Getters - double y0 (multilayer_t iML, tubeSide_t iTubeSide) const { return meas(iML, iTubeSide).y0; } - double z0 (multilayer_t iML, tubeSide_t iTubeSide) const { return meas(iML, iTubeSide).z0; } - double alpha (multilayer_t iML, tubeSide_t iTubeSide) const { return meas(iML, iTubeSide).alpha; } - double ypitch (multilayer_t iML, tubeSide_t iTubeSide) const { return meas(iML, iTubeSide).ypitch; } - double zpitch (multilayer_t iML, tubeSide_t iTubeSide) const { return meas(iML, iTubeSide).zpitch; } - int stagg (multilayer_t iML, tubeSide_t iTubeSide) const { return meas(iML, iTubeSide).stagg; } + double y0(multilayer_t iML, tubeSide_t iTubeSide) const { return meas(iML, iTubeSide).y0; } + double z0(multilayer_t iML, tubeSide_t iTubeSide) const { return meas(iML, iTubeSide).z0; } + double alpha(multilayer_t iML, tubeSide_t iTubeSide) const { return meas(iML, iTubeSide).alpha; } + double ypitch(multilayer_t iML, tubeSide_t iTubeSide) const { return meas(iML, iTubeSide).ypitch; } + double zpitch(multilayer_t iML, tubeSide_t iTubeSide) const { return meas(iML, iTubeSide).zpitch; } + int stagg(multilayer_t iML, tubeSide_t iTubeSide) const { return meas(iML, iTubeSide).stagg; } - private: +private: // Alignment parameters struct AlignmentParameters { - AlignmentParameters(); - multilayer_t iML; // ML index - tubeSide_t iTubeSide; // tube side - float y0; // y position of first wire w.r.t. reference point - float z0; // z position of first wire w.r.t. reference point - float alpha; // rotation around tube axis - float ypitch; // y pitch - float zpitch; // z pitch - int stagg; // is tube staggering ATLAS-standard or reversed? + AlignmentParameters(); + multilayer_t iML; // ML index + tubeSide_t iTubeSide; // tube side + float y0; // y position of first wire w.r.t. reference point + float z0; // z position of first wire w.r.t. reference point + float alpha; // rotation around tube axis + float ypitch; // y pitch + float zpitch; // z pitch + int stagg; // is tube staggering ATLAS-standard or reversed? }; - static const int NMEAS = NMLTYPES*NTUBESIDETYPES; - AlignmentParameters m_meas[NMEAS]; // in this order: ML1_HV, ML1_RO, ML2_HV, ML2_RO - - AlignmentParameters& meas(multilayer_t iML, tubeSide_t iTubeSide) { return m_meas[NTUBESIDETYPES*iML+iTubeSide]; } - const AlignmentParameters& meas(multilayer_t iML, tubeSide_t iTubeSide) const { return m_meas[NTUBESIDETYPES*iML+iTubeSide]; } + static const int NMEAS = NMLTYPES * NTUBESIDETYPES; + AlignmentParameters m_meas[NMEAS]; // in this order: ML1_HV, ML1_RO, ML2_HV, ML2_RO + AlignmentParameters& meas(multilayer_t iML, tubeSide_t iTubeSide) { return m_meas[NTUBESIDETYPES * iML + iTubeSide]; } + const AlignmentParameters& meas(multilayer_t iML, tubeSide_t iTubeSide) const { return m_meas[NTUBESIDETYPES * iML + iTubeSide]; } }; #endif // MUONALIGNMENTDATA_MDTASBUILTPAR_H - diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/MdtAsBuiltParContainer.h b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/MdtAsBuiltParContainer.h index 73b04821ec0181b30e7802aa621be893d5636f37..1042fe97823f8181ea089555a9b33839a3ed634b 100755 --- a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/MdtAsBuiltParContainer.h +++ b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/MdtAsBuiltParContainer.h @@ -9,21 +9,16 @@ #include "AthenaKernel/CLASS_DEF.h" #include "MuonAlignmentData/MdtAsBuiltPar.h" -class MdtAsBuiltParContainer : public DataVector<MdtAsBuiltPar> -{ - public: - MdtAsBuiltParContainer(); - ~MdtAsBuiltParContainer(); - +class MdtAsBuiltParContainer : public DataVector<MdtAsBuiltPar> { +public: + MdtAsBuiltParContainer(); + ~MdtAsBuiltParContainer(); }; -inline MdtAsBuiltParContainer::MdtAsBuiltParContainer(): - DataVector<MdtAsBuiltPar>() -{ } +inline MdtAsBuiltParContainer::MdtAsBuiltParContainer() : DataVector<MdtAsBuiltPar>() {} -inline MdtAsBuiltParContainer::~MdtAsBuiltParContainer() -{ } +inline MdtAsBuiltParContainer::~MdtAsBuiltParContainer() {} -CLASS_DEF( MdtAsBuiltParContainer , 1205288943 , 1 ) +CLASS_DEF(MdtAsBuiltParContainer, 1205288943, 1) #endif // MUONALIGNMENTDATA_MDTASBUILTPARPARCONTAINER_H diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/MuonAlignmentPar.h b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/MuonAlignmentPar.h index de4a9f8510d507225e636411c7fcbbb257acc828..60c5629a97e751b31dfa16d655b2b5cbf080aaa7 100755 --- a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/MuonAlignmentPar.h +++ b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/MuonAlignmentData/MuonAlignmentPar.h @@ -5,46 +5,38 @@ #ifndef MUONALIGNMENTDATA_MUONALIGNMENTPAR_H #define MUONALIGNMENTDATA_MUONALIGNMENTPAR_H -#include "Identifier/Identifier.h" - - #include <string> +#include "Identifier/Identifier.h" class MuonAlignmentPar { +public: + MuonAlignmentPar(); + virtual ~MuonAlignmentPar() = default; - public: + Identifier identify() const { return m_stationId; } + std::string key() const { return m_stationKey; } - MuonAlignmentPar(); - virtual ~MuonAlignmentPar()=default; + void setAmdbId(const std::string& type, int jff, int jzz, int job); + void getAmdbId(std::string& type, int& jff, int& jzz, int& job) const; - Identifier identify() const {return m_stationId;} - std::string key() const {return m_stationKey;} + bool isNew() const { return m_isNew; } + void isNew(bool newPar) { m_isNew = newPar; } - void setAmdbId(const std::string& type, int jff, int jzz, int job); - void getAmdbId(std::string& type, int& jff, int& jzz, int& job) const; +protected: + // Identifier + Identifier m_stationId; - bool isNew() const {return m_isNew;} - void isNew(bool newPar) {m_isNew = newPar;} + // geomodel key + std::string m_stationKey; - protected: - - // Identifier - Identifier m_stationId; - - // geomodel key - std::string m_stationKey; - - // Amdb identifier - std::string m_Type; - int m_Jff; - int m_Jzz; - int m_Job; - - bool m_isNew; + // Amdb identifier + std::string m_Type; + int m_Jff; + int m_Jzz; + int m_Job; + bool m_isNew; }; - - #endif // MUONALIGNMENTDATA_MUONALIGNMENTPAR_H diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/doc/packagedoc.h b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/doc/packagedoc.h index b22bb2378e094ce0ebabb11f5d87b52114ec2649..0524eae38c4b3ef59c87e41b85e6388517cfff32 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/doc/packagedoc.h +++ b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/doc/packagedoc.h @@ -11,17 +11,17 @@ This package contains the data structures used to store the alignment information retrieved from -the ConditionDB. There are stl maps and other data container. +the ConditionDB. There are stl maps and other data container. @section MuonAlignmentData_MuonAlignmentDataOverview Class Overview The MuonAlignmentData package contains of following classes: - - ALineParContainer.h - - ALinePar.h - - BLineParContainer.h - - BLinePar.h - - CorrContainer.h - - MuonAlignmentPar.h + - ALineParContainer.h + - ALinePar.h + - BLineParContainer.h + - BLinePar.h + - CorrContainer.h + - MuonAlignmentPar.h */ diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/src/ALinePar.cxx b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/src/ALinePar.cxx index df18e710507846357de8060cbb2a6ef47b3470d2..c657abd6f91ed03d24709e2ccfc5708f27cc08fd 100755 --- a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/src/ALinePar.cxx +++ b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/src/ALinePar.cxx @@ -4,42 +4,29 @@ #include "MuonAlignmentData/ALinePar.h" -ALinePar::ALinePar(): - MuonAlignmentPar(), - m_S(0.0), - m_Z(0.0), - m_T(0.0), - m_rotS(0.0), - m_rotZ(0.0), - m_rotT(0.0) -{ } +ALinePar::ALinePar() : MuonAlignmentPar(), m_S(0.0), m_Z(0.0), m_T(0.0), m_rotS(0.0), m_rotZ(0.0), m_rotT(0.0) {} -void ALinePar::setParameters(float s, float z, float t, - float rotS, float rotZ, float rotT) -{ - m_S = s; - m_Z = z; - m_T = t; - m_rotS = rotS; - m_rotZ = rotZ; - m_rotT = rotT; +void ALinePar::setParameters(float s, float z, float t, float rotS, float rotZ, float rotT) { + m_S = s; + m_Z = z; + m_T = t; + m_rotS = rotS; + m_rotZ = rotZ; + m_rotT = rotT; } -void ALinePar::getParameters(float& s, float& z, float& t, - float& rotS, float& rotZ, float& rotT) const -{ - s = m_S; - z = m_Z; - t = m_T; - rotS = m_rotS; - rotZ = m_rotZ; - rotT = m_rotT; +void ALinePar::getParameters(float& s, float& z, float& t, float& rotS, float& rotZ, float& rotT) const { + s = m_S; + z = m_Z; + t = m_T; + rotS = m_rotS; + rotZ = m_rotZ; + rotT = m_rotT; } -HepGeom::Transform3D ALinePar::deltaTransform() const -{// does NOT account for AMDB origin being different from volume centre; - // for that you would need access to full station Position info... - // see MuonGeoModel/Station::getDeltaTransform() for details. - return HepGeom::TranslateY3D(m_S)*HepGeom::TranslateZ3D(m_Z)*HepGeom::TranslateX3D(m_T) - *HepGeom::RotateY3D(m_rotS)*HepGeom::RotateZ3D(m_rotZ)*HepGeom::RotateX3D(m_rotT); +HepGeom::Transform3D ALinePar::deltaTransform() const { // does NOT account for AMDB origin being different from volume centre; + // for that you would need access to full station Position info... + // see MuonGeoModel/Station::getDeltaTransform() for details. + return HepGeom::TranslateY3D(m_S) * HepGeom::TranslateZ3D(m_Z) * HepGeom::TranslateX3D(m_T) * HepGeom::RotateY3D(m_rotS) * + HepGeom::RotateZ3D(m_rotZ) * HepGeom::RotateX3D(m_rotT); } diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/src/BLinePar.cxx b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/src/BLinePar.cxx index a7befbe2406fc84a49f8f091156ad7e403b3dc62..2bd5c874a24cd3057ef0ccf8930c1dc249d5cce2 100755 --- a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/src/BLinePar.cxx +++ b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/src/BLinePar.cxx @@ -3,68 +3,35 @@ */ #include "MuonAlignmentData/BLinePar.h" - -BLinePar::BLinePar(): - MuonAlignmentPar(), - m_bz(0.), - m_bp(0.), - m_bn(0.), - m_sp(0.), - m_sn(0.), - m_tw(0.), - m_pg(0.), - m_tr(0.), - m_eg(0.), - m_ep(0.), - m_en(0.) -{ } -void BLinePar::setParameters(float bz, - float bp, - float bn, - float sp, - float sn, - float tw, - float pg, - float tr, - float eg, - float ep, - float en) -{ - m_bz=bz; - m_bp=bp; - m_bn=bn; - m_sp=sp; - m_sn=sn; - m_tw=tw; - m_pg=pg; - m_tr=tr; - m_eg=eg; - m_ep=ep; - m_en=en; +BLinePar::BLinePar() : + MuonAlignmentPar(), m_bz(0.), m_bp(0.), m_bn(0.), m_sp(0.), m_sn(0.), m_tw(0.), m_pg(0.), m_tr(0.), m_eg(0.), m_ep(0.), m_en(0.) {} + +void BLinePar::setParameters(float bz, float bp, float bn, float sp, float sn, float tw, float pg, float tr, float eg, float ep, float en) { + m_bz = bz; + m_bp = bp; + m_bn = bn; + m_sp = sp; + m_sn = sn; + m_tw = tw; + m_pg = pg; + m_tr = tr; + m_eg = eg; + m_ep = ep; + m_en = en; } -void BLinePar::getParameters( float& bz, - float& bp, - float& bn, - float& sp, - float& sn, - float& tw, - float& pg, - float& tr, - float& eg, - float& ep, - float& en ) const -{ - bz = m_bz; - bp = m_bp; - bn = m_bn; - sp = m_sp; - sn = m_sn; - tw = m_tw; - pg = m_pg; - tr = m_tr; - eg = m_eg; - ep = m_ep; - en = m_en; +void BLinePar::getParameters(float& bz, float& bp, float& bn, float& sp, float& sn, float& tw, float& pg, float& tr, float& eg, float& ep, + float& en) const { + bz = m_bz; + bp = m_bp; + bn = m_bn; + sp = m_sp; + sn = m_sn; + tw = m_tw; + pg = m_pg; + tr = m_tr; + eg = m_eg; + ep = m_ep; + en = m_en; } diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/src/CscInternalAlignmentPar.cxx b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/src/CscInternalAlignmentPar.cxx index 505c790c4da519bf38d813d3e1779ec3025f4785..d3b8f0d84d2556773160e2fd07dd544718b135a1 100755 --- a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/src/CscInternalAlignmentPar.cxx +++ b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/src/CscInternalAlignmentPar.cxx @@ -4,57 +4,43 @@ #include "MuonAlignmentData/CscInternalAlignmentPar.h" -CscInternalAlignmentPar::CscInternalAlignmentPar(): - MuonAlignmentPar(), - m_wireLayer(0), - m_S(0.0), - m_Z(0.0), - m_T(0.0), - m_rotS(0.0), - m_rotZ(0.0), - m_rotT(0.0) -{ } - -void CscInternalAlignmentPar::setParameters(float s, float z, float t, - float rotS, float rotZ, float rotT) -{ - m_S = s; - m_Z = z; - m_T = t; - m_rotS = rotS; - m_rotZ = rotZ; - m_rotT = rotT; +CscInternalAlignmentPar::CscInternalAlignmentPar() : + MuonAlignmentPar(), m_wireLayer(0), m_S(0.0), m_Z(0.0), m_T(0.0), m_rotS(0.0), m_rotZ(0.0), m_rotT(0.0) {} + +void CscInternalAlignmentPar::setParameters(float s, float z, float t, float rotS, float rotZ, float rotT) { + m_S = s; + m_Z = z; + m_T = t; + m_rotS = rotS; + m_rotZ = rotZ; + m_rotT = rotT; } -void CscInternalAlignmentPar::getParameters(float& s, float& z, float& t, - float& rotS, float& rotZ, float& rotT) const -{ - s = m_S; - z = m_Z; - t = m_T; - rotS = m_rotS; - rotZ = m_rotZ; - rotT = m_rotT; +void CscInternalAlignmentPar::getParameters(float& s, float& z, float& t, float& rotS, float& rotZ, float& rotT) const { + s = m_S; + z = m_Z; + t = m_T; + rotS = m_rotS; + rotZ = m_rotZ; + rotT = m_rotT; } -void CscInternalAlignmentPar::setAmdbId(const std::string& type, int jff, int jzz, int job, int wireLayer) -{ - m_Type = type; - m_Jff = jff; - m_Jzz = jzz; - m_Job = job; - m_wireLayer = wireLayer; +void CscInternalAlignmentPar::setAmdbId(const std::string& type, int jff, int jzz, int job, int wireLayer) { + m_Type = type; + m_Jff = jff; + m_Jzz = jzz; + m_Job = job; + m_wireLayer = wireLayer; - return; + return; } -void CscInternalAlignmentPar::getAmdbId(std::string& type, int& jff, int& jzz, int& job, int& wireLayer) const -{ - type = m_Type; - jff = m_Jff; - jzz = m_Jzz; - job = m_Job; - wireLayer = m_wireLayer; +void CscInternalAlignmentPar::getAmdbId(std::string& type, int& jff, int& jzz, int& job, int& wireLayer) const { + type = m_Type; + jff = m_Jff; + jzz = m_Jzz; + job = m_Job; + wireLayer = m_wireLayer; - return; + return; } diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/src/MdtAsBuiltPar.cxx b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/src/MdtAsBuiltPar.cxx index 953c8ed11078c157c32ad057ae407538b404b294..f95c0219c3d0d7fcdc5591ef659cebc5ef70c2b8 100644 --- a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/src/MdtAsBuiltPar.cxx +++ b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/src/MdtAsBuiltPar.cxx @@ -3,72 +3,49 @@ */ #include "MuonAlignmentData/MdtAsBuiltPar.h" -#include <sstream> - - -MdtAsBuiltPar::MdtAsBuiltPar(): - MuonAlignmentPar() -{ } -MdtAsBuiltPar::AlignmentParameters::AlignmentParameters(): - iML(multilayer_t::ML1), - iTubeSide(tubeSide_t::POS), - y0(0.), - z0(0.), - alpha(0.), - ypitch(0.), - zpitch(0.), - stagg(1) -{ } +#include <sstream> -void MdtAsBuiltPar::setAlignmentParameters( - multilayer_t iML, - tubeSide_t iTubeSide, - float y0, - float z0, - float alpha, - float ypitch, - float zpitch, - int stagg - ) { - AlignmentParameters& params = meas(iML, iTubeSide); - params.iML = iML; - params.iTubeSide = iTubeSide; - params.y0 = y0; - params.z0 = z0; - params.alpha = alpha; - params.ypitch = ypitch; - params.zpitch = zpitch; - params.stagg = stagg; +MdtAsBuiltPar::MdtAsBuiltPar() : MuonAlignmentPar() {} + +MdtAsBuiltPar::AlignmentParameters::AlignmentParameters() : + iML(multilayer_t::ML1), iTubeSide(tubeSide_t::POS), y0(0.), z0(0.), alpha(0.), ypitch(0.), zpitch(0.), stagg(1) {} + +void MdtAsBuiltPar::setAlignmentParameters(multilayer_t iML, tubeSide_t iTubeSide, float y0, float z0, float alpha, float ypitch, + float zpitch, int stagg) { + AlignmentParameters& params = meas(iML, iTubeSide); + params.iML = iML; + params.iTubeSide = iTubeSide; + params.y0 = y0; + params.z0 = z0; + params.alpha = alpha; + params.ypitch = ypitch; + params.zpitch = zpitch; + params.stagg = stagg; } bool MdtAsBuiltPar::setFromAscii(const std::string& line) { - std::istringstream in(line); - - std::string tok; - if (!((in >> tok) && (tok=="Corr:"))) - return false; - - std::string typ; - int jff, jzz; - if (!(in >> typ >> jff >> jzz)) - return false; - setAmdbId(typ, jff, jzz, 0); - - multilayer_t ml[NMLTYPES] = { ML1, ML2 }; - tubeSide_t sid[NTUBESIDETYPES] = { POS, NEG }; - int stagg[NMLTYPES]; - if (!(in >> stagg[ML1] >> stagg[ML2])) - return false; - for (int iML=0; iML<NMLTYPES; ++iML) { - for (int iTubeSide=0; iTubeSide<NTUBESIDETYPES; ++iTubeSide) { - float y0, z0, alpha, ypitch, zpitch; - if (!(in >> y0 >> z0 >> alpha >> ypitch >> zpitch)) - return false; - setAlignmentParameters(ml[iML], sid[iTubeSide], y0, z0, alpha, ypitch, zpitch, stagg[iML]); + std::istringstream in(line); + + std::string tok; + if (!((in >> tok) && (tok == "Corr:"))) return false; + + std::string typ; + int jff, jzz; + if (!(in >> typ >> jff >> jzz)) return false; + setAmdbId(typ, jff, jzz, 0); + + multilayer_t ml[NMLTYPES] = {ML1, ML2}; + tubeSide_t sid[NTUBESIDETYPES] = {POS, NEG}; + int stagg[NMLTYPES]; + if (!(in >> stagg[ML1] >> stagg[ML2])) return false; + for (int iML = 0; iML < NMLTYPES; ++iML) { + for (int iTubeSide = 0; iTubeSide < NTUBESIDETYPES; ++iTubeSide) { + float y0, z0, alpha, ypitch, zpitch; + if (!(in >> y0 >> z0 >> alpha >> ypitch >> zpitch)) return false; + setAlignmentParameters(ml[iML], sid[iTubeSide], y0, z0, alpha, ypitch, zpitch, stagg[iML]); + } } - } - return true; + return true; } - diff --git a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/src/MuonAlignmentPar.cxx b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/src/MuonAlignmentPar.cxx index bea7e0eeb2d0846db2bc0e588ad7fe063279fae5..73ed0dd5a97c06669a6bfe0b01df0bcfd08be22f 100755 --- a/MuonSpectrometer/MuonAlignment/MuonAlignmentData/src/MuonAlignmentPar.cxx +++ b/MuonSpectrometer/MuonAlignment/MuonAlignmentData/src/MuonAlignmentPar.cxx @@ -4,27 +4,22 @@ #include "MuonAlignmentData/MuonAlignmentPar.h" -MuonAlignmentPar::MuonAlignmentPar() : - m_Jff(0), m_Jzz(0), m_Job(0), m_isNew(false) -{ } +MuonAlignmentPar::MuonAlignmentPar() : m_Jff(0), m_Jzz(0), m_Job(0), m_isNew(false) {} -void MuonAlignmentPar::setAmdbId(const std::string& type, int jff, int jzz, int job) -{ - m_Type = type; - m_Jff = jff; - m_Jzz = jzz; - m_Job = job; +void MuonAlignmentPar::setAmdbId(const std::string& type, int jff, int jzz, int job) { + m_Type = type; + m_Jff = jff; + m_Jzz = jzz; + m_Job = job; - return; + return; } -void MuonAlignmentPar::getAmdbId(std::string& type, int& jff, int& jzz, int& job) const -{ - type = m_Type; - jff = m_Jff; - jzz = m_Jzz; - job = m_Job; +void MuonAlignmentPar::getAmdbId(std::string& type, int& jff, int& jzz, int& job) const { + type = m_Type; + jff = m_Jff; + jzz = m_Jzz; + job = m_Job; - return; + return; } -