00001 #ifndef MCAST_MUONCALIBRATIONANDMEARINGTOOL_H
00002 #define MCAST_MUONCALIBRATIONANDMEARINGTOOL_H
00003
00004
00005 #include "AsgTools/AsgTool.h"
00006
00007
00008 #include "TRandom3.h"
00009 #include "TH3F.h"
00010 #include "TProfile2D.h"
00011 #include "TFile.h"
00012
00013
00014 #include <boost/unordered_map.hpp>
00015 #include <fstream>
00016 #include <string>
00017 #include <vector>
00018 #include <map>
00019
00020
00021 #include "MuonMomentumCorrections/IMuonCalibrationAndSmearingTool.h"
00022
00023 #define EPSILON 1.0E-6
00024 #define DEFAULT_INIT_VAL -999
00025 #define MCAST_MAX_PT 100000000
00026 #define MZPDG 91.1876
00027
00028 namespace CP {
00029
00030 namespace MCAST {
00031
00032 namespace DataType { enum { Data10 = 1, Data11 = 2, Data12 = 3, Data15 = 4, Data16=5}; }
00033 namespace AlgoType { enum { Muid = 1, Staco = 2, Muons = 3 }; }
00034 namespace Release { enum { Rel16_6 = 1, Rel17 = 2, Rel17_2 = 3, Rel17_2_Repro = 4, Rel17_2_Sum13 = 5, PreRec = 6, PreRec_2015_06_22 = 7, PreRec_2015_08_06 = 8, Rec_2015_11_15 = 9, Rec_2016_01_13 = 10, Rec_2016_01_19 = 11, PreRec_2016_05_23 = 12 , Recs2016_08_07=13 , Recs2016_15_07}; }
00035 namespace SmearingType { enum { Pt = 1, QoverPt = 2 }; }
00036 namespace DetectorType { enum { MS = 1, ID = 2, CB = 3 }; }
00037 namespace SystVariation { enum { Default = 0, Down = -1, Up = 1 }; }
00038 namespace SagittaCorType { enum { CB=0, ID=1, ME=2, WEIGHTS=3, AUTO=4}; }
00039 namespace SagittaSysType { enum { NOMINAL=0, RHO=1, BIAS=2}; }
00040
00041 }
00042
00043 class MuonCalibrationAndSmearingTool : public virtual IMuonCalibrationAndSmearingTool, public virtual ISystematicsTool, public asg::AsgTool {
00044
00045
00046 ASG_TOOL_CLASS2( MuonCalibrationAndSmearingTool, CP::IMuonCalibrationAndSmearingTool, CP::ISystematicsTool )
00047
00048
00049 public:
00050
00051
00052 MuonCalibrationAndSmearingTool( const std::string& name );
00053
00054
00055 MuonCalibrationAndSmearingTool( const MuonCalibrationAndSmearingTool& tool );
00056
00057
00058 virtual ~MuonCalibrationAndSmearingTool();
00059
00060 virtual StatusCode initialize();
00061
00062
00063 virtual CorrectionCode applyCorrection( xAOD::Muon& mu );
00064
00065 virtual CorrectionCode correctedCopy( const xAOD::Muon& input, xAOD::Muon*& output );
00066
00067
00068 virtual bool isAffectedBySystematic( const SystematicVariation& systematic ) const;
00069
00070 virtual SystematicSet affectingSystematics() const;
00071
00072 virtual SystematicSet recommendedSystematics() const;
00073
00074 virtual SystematicCode applySystematicVariation ( const SystematicSet& systConfig );
00075
00076 void setRandomSeed( unsigned seed = 0 ) { m_random3.SetSeed( seed ); m_useExternalSeed = true;}
00077 virtual double expectedResolution( const std::string& DetType, xAOD::Muon& mu, const bool mc = false ) const;
00078 virtual double expectedResolution( const int DetType, xAOD::Muon& mu, const bool mc = false ) const;
00079
00080
00081 double ExpectedResolution( const std::string& DetType, xAOD::Muon& mu, const bool mc = false ) const;
00082 double ExpectedResolution( const int DetType, xAOD::Muon& mu, const bool mc = false ) const;
00083
00084
00085 virtual CorrectionCode applyStatCombination( const ElementLink< xAOD::TrackParticleContainer >& inDetTrackParticle,
00086 const ElementLink< xAOD::TrackParticleContainer >& extrTrackParticle ,
00087 int charge,
00088 AmgVector(5)& parsCB,
00089 AmgSymMatrix(5)& covCB,
00090 double& chi2);
00091 virtual CorrectionCode applyStatCombination( xAOD::Muon& mu );
00092
00093 virtual void setUseStatCombination(bool flag);
00094
00095 virtual CorrectionCode applySagittaBiasCorrectionAuto(const int DetType,xAOD::Muon& mu,bool isMC=false,const unsigned int SytCase=0);
00096
00097 virtual CorrectionCode CorrectForCharge(double p2,double& pt,int q=0, bool isMC=false);
00098 virtual CorrectionCode applyiSagittaBiasCorrection(const unsigned int SgCorrType, xAOD::Muon& mu,unsigned int iter=0,bool stop=false,bool isMC=false);
00099
00100
00101
00102 protected:
00103
00104 StatusCode Regions( std::string inRegionFile, int doMacroRegionsFlag = 0 );
00105 void PrintRegions() const;
00106 unsigned int GetNRegions() const;
00107 int GetRegion( const double eta, const double phi ) const;
00108 float GetRegionInnerEta( const int r_i ) const;
00109 std::string GetRegionName( const int r_i ) const;
00110 std::string GetRegionName( const double eta, const double phi ) const;
00111 double GetSmearing( int, xAOD::Muon& );
00112 double GetSystVariation( int DetType, double var );
00113 int GetScaleRegion( xAOD::Muon& );
00114 void CalcCBWeights( xAOD::Muon& );
00115 double CalculatePt( const int DetType, const double inSmearID = DEFAULT_INIT_VAL, const double inSmearMS = DEFAULT_INIT_VAL, const double scaleVar = 0. ) const;
00116 StatusCode FillValues();
00117 void Clean();
00118 double ScaleApply( const double pt, double S = 1.0, const double S_EnLoss = 0. ) const;
00119
00120 void CleanScales();
00121 void CollectMacroRegionsSL();
00122 void CollectMacroRegionsSL_UpDn();
00123 void CollectMacroRegionsSL_SplitBAR();
00124 void CollectSectors();
00125
00126 StatusCode SetData( std::string );
00127 StatusCode SetAlgorithm( std::string );
00128 StatusCode SetRelease( std::string );
00129 StatusCode SetType( std::string );
00130
00131 virtual unsigned int setSagittaHistogramsSingle(TProfile2D *pCB=NULL,unsigned int track=0);
00132 virtual double sagitta(TProfile2D* corrM, TLorentzVector &lv);
00133
00134 virtual void ConvertToSagittaBias(TH2F *h,float mean=1);
00135 virtual TProfile2D* GetHist(std::string fname="", std::string hname="inclusive",double GlobalScale=MZPDG);
00136
00137 virtual bool isBadMuon( const xAOD::Muon& mu ) const;
00138
00139
00140 MuonCalibrationAndSmearingTool& operator=(const MuonCalibrationAndSmearingTool& );
00141 struct ParameterSet {
00142 double SmearTypeID;
00143 double SmearTypeMS;
00144 double Scale;
00145 double SagittaRho;
00146 double SagittaBias;
00147 };
00148 mutable TRandom3 m_random3;
00149 bool m_useExternalSeed;
00150 double m_smearDeltaMS, m_smearDeltaID, m_smearDeltaCB;
00151 std::string m_year, m_algo, m_type, m_release;
00152 std::string m_FilesPath;
00153 bool m_toroidOff;
00154 int m_Tsmear;
00155
00156 int m_Tdata;
00157 int m_Trel;
00158 int m_Talgo;
00159 int m_detRegion;
00160 double m_useNsigmaForICombine;
00161 double m_ptms, m_ptid, m_ptcb, m_eta, m_phi;
00162 std::vector<double> m_scale_ID, m_enLoss_MS, m_scale_MS, m_scale_CB;
00163
00164 std::vector<double> m_scaleSyst_ID, m_enLossSyst_MS, m_scaleSyst_MS, m_scaleSyst_CB;
00165 std::vector<double> m_scaleSystUp_ID, m_enLossSystUp_MS, m_scaleSystUp_MS;
00166 std::vector<double> m_scaleSystDw_ID, m_enLossSystDw_MS, m_scaleSystDw_MS;
00167
00168 std::vector<double> m_scaleBins;
00169 std::vector<double> m_p1_ID, m_p2_ID, m_p2_ID_TAN, m_p0_MS, m_p1_MS, m_p2_MS;
00170 std::vector<double> m_E_p1_ID, m_E_p2_ID, m_E_p2_ID_TAN, m_E_p0_MS, m_E_p1_MS, m_E_p2_MS;
00171
00172
00173 std::vector<double> m_S_p1_ID, m_S_p2_ID, m_S_p2_ID_TAN, m_S_p0_MS, m_S_p1_MS, m_S_p2_MS;
00174
00175 std::vector<double> m_SUp_p1_ID, m_SUp_p2_ID, m_SUp_p2_ID_TAN, m_SUp_p0_MS, m_SUp_p1_MS, m_SUp_p2_MS;
00176 std::vector<double> m_SDw_p1_ID, m_SDw_p2_ID, m_SDw_p2_ID_TAN, m_SDw_p0_MS, m_SDw_p1_MS, m_SDw_p2_MS;
00177 std::vector<double> m_MC_p1_ID, m_MC_p2_ID, m_MC_p2_ID_TAN, m_MC_p0_MS, m_MC_p1_MS, m_MC_p2_MS;
00178 double m_weightMS, m_weightID;
00179 double m_g0, m_g1, m_g2, m_g3, m_g4, m_charge;
00180
00181 std::vector<std::string> m_names;
00182 bool m_loadNames;
00183 int m_nb_regions;
00184 std::vector<float> m_eta_min, m_eta_max, m_phi_min, m_phi_max;
00185
00186 bool m_doMacroRegions;
00187 std::map< int, int > m_MacroRegionIdxMap;
00188 std::vector< std::string > m_MacroRegionName;
00189 std::vector< double > m_MacroRegionInnerEta;
00190
00191 int m_scaleRegion;
00192
00193
00194
00195 boost::unordered_map< SystematicSet, ParameterSet > m_Parameters;
00196 ParameterSet *m_currentParameters;
00197
00198 double m_StatCombPtThreshold;
00199 bool m_useStatComb;
00200
00201 std::vector <TProfile2D*> *m_sagittasCB;
00202 std::vector <TProfile2D*> *m_sagittasID;
00203 std::vector <TProfile2D*> *m_sagittasME;
00204
00205 bool m_doSagittaCorrection;
00206 std::vector <double> m_GlobalZScales;
00207 std::vector <unsigned int > m_SagittaIterations;
00208 std::string m_SagittaRelease;
00209 bool m_doSagittaMCDistortion;
00210
00211
00212 };
00213
00214 }
00215
00216 #endif