00001 #ifndef MuScleFitUtils_H
00002 #define MuScleFitUtils_H
00003
00013 #include <CLHEP/Vector/LorentzVector.h>
00014 #include "DataFormats/MuonReco/interface/Muon.h"
00015 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00016
00017 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00018 #include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h"
00019 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
00020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00021 #include "TGraphErrors.h"
00022 #include "TH2F.h"
00023 #include "TMinuit.h"
00024
00025 #include "MuonAnalysis/MomentumScaleCalibration/interface/CrossSectionHandler.h"
00026 #include "MuonAnalysis/MomentumScaleCalibration/interface/BackgroundHandler.h"
00027
00028 #include <vector>
00029
00030
00031
00032
00033 template <class T> class biasFunctionBase;
00034 template <class T> class scaleFunctionBase;
00035 class smearFunctionBase;
00036 template <class T> class resolutionFunctionBase;
00037 class backgroundFunctionBase;
00038 class BackgroundHandler;
00039
00040 class SimTrack;
00041 class TString;
00042 class TTree;
00043
00044 typedef reco::Particle::LorentzVector lorentzVector;
00045
00046 class MuScleFitUtils {
00047 public:
00048
00049
00050
00051 MuScleFitUtils() {};
00052
00053
00054
00055 virtual ~MuScleFitUtils() {};
00056
00057
00058
00059 static std::pair<SimTrack, SimTrack> findBestSimuRes( const std::vector<SimTrack>& simMuons );
00060 static std::pair<lorentzVector, lorentzVector> findBestRecoRes( const std::vector<reco::LeafCandidate>& muons );
00061 static std::pair <lorentzVector, lorentzVector> findGenMuFromRes( const reco::GenParticleCollection* genParticles);
00062 static std::pair<lorentzVector, lorentzVector> findGenMuFromRes( const edm::HepMCProduct* evtMC );
00063 static std::pair<lorentzVector, lorentzVector> findSimMuFromRes( const edm::Handle<edm::HepMCProduct> & evtMC,
00064 const edm::Handle<edm::SimTrackContainer> & simTracks);
00065
00066 static std::vector<TGraphErrors*> fitMass (TH2F* histo);
00067 static std::vector<TGraphErrors*> fitReso (TH2F* histo);
00068
00069 static lorentzVector applyScale( const lorentzVector & muon, const std::vector<double> & parval, const int charge );
00070 static lorentzVector applyScale( const lorentzVector & muon, double* parval, const int charge );
00071 static lorentzVector applyBias( const lorentzVector & muon, const int charge );
00072 static lorentzVector applySmearing( const lorentzVector & muon );
00073 static lorentzVector fromPtEtaPhiToPxPyPz( const double* ptEtaPhiE );
00074
00075 static void minimizeLikelihood();
00076
00077 static double invDimuonMass( const lorentzVector & mu1, const lorentzVector & mu2 );
00078 static double massResolution( const lorentzVector & mu1, const lorentzVector & mu2 );
00079 static double massResolution( const lorentzVector & mu1, const lorentzVector & mu2, const std::vector<double> & parval );
00080 static double massResolution( const lorentzVector & mu1, const lorentzVector & mu2, std::auto_ptr<double> parval );
00081 static double massResolution( const lorentzVector & mu1, const lorentzVector & mu2, double* parval );
00082
00083 static double massProb( const double & mass, const double & rapidity, const int ires, const double & massResol );
00084 static double massProb( const double & mass, const double & resEta, const double & rapidity, const double & massResol, const std::vector<double> & parval, const bool doUseBkgrWindow = false );
00085 static double massProb( const double & mass, const double & resEta, const double & rapidity, const double & massResol, double * parval, const bool doUseBkgrWindow = false );
00086 static double computeWeight( const double & mass, const int iev, const bool doUseBkgrWindow = false );
00087
00088 static double deltaPhi( const double & phi1, const double & phi2 )
00089 {
00090 double deltaPhi = phi1 - phi2;
00091 while(deltaPhi >= TMath::Pi()) deltaPhi -= 2*TMath::Pi();
00092 while(deltaPhi < -TMath::Pi()) deltaPhi += 2*TMath::Pi();
00093 return fabs(deltaPhi);
00094 }
00096 static double deltaPhiNoFabs( const double & phi1, const double & phi2 )
00097 {
00098 double deltaPhi = phi1 - phi2;
00099 while(deltaPhi >= TMath::Pi()) deltaPhi -= 2*TMath::Pi();
00100 while(deltaPhi < -TMath::Pi()) deltaPhi += 2*TMath::Pi();
00101 return deltaPhi;
00102 }
00103 static double deltaR(const double & eta1, const double & eta2, const double & phi1, const double & phi2)
00104 {
00105 return sqrt( std::pow( eta1-eta2, 2 ) + std::pow( deltaPhi(phi1, phi2), 2 ) );
00106 }
00107
00108 static int debug;
00109 static bool ResFound;
00110
00111 static const int totalResNum;
00112 static double massWindowHalfWidth[3][6];
00113 static double ResGamma[6];
00114 static double ResMass[6];
00115 static double ResMinMass[6];
00116 static double crossSection[6];
00117 static const double mMu2;
00118 static const double muMass;
00119
00120
00121 static const unsigned int motherPdgIdArray[6];
00122
00123 static unsigned int loopCounter;
00124
00125 static int SmearType;
00126 static smearFunctionBase * smearFunction;
00127 static int BiasType;
00128
00129 static scaleFunctionBase<std::vector<double> > * biasFunction;
00130 static int ResolFitType;
00131 static resolutionFunctionBase<double *> * resolutionFunction;
00132 static resolutionFunctionBase<std::vector<double> > * resolutionFunctionForVec;
00133 static int ScaleFitType;
00134 static scaleFunctionBase<double*> * scaleFunction;
00135 static scaleFunctionBase<std::vector<double> > * scaleFunctionForVec;
00136 static int BgrFitType;
00137
00138
00139
00140
00141 static const int backgroundFunctionsRegions;
00142
00143
00144
00145
00146
00147
00148
00149 static CrossSectionHandler * crossSectionHandler;
00150
00151
00152
00153 static BackgroundHandler * backgroundHandler;
00154
00155
00156 static std::vector<int> doResolFit;
00157 static std::vector<int> doScaleFit;
00158 static std::vector<int> doCrossSectionFit;
00159 static std::vector<int> doBackgroundFit;
00160
00161 static int minuitLoop_;
00162 static TH1D* likelihoodInLoop_;
00163 static TH1D* signalProb_;
00164 static TH1D* backgroundProb_;
00165
00166 static bool duringMinos_;
00167
00168 static std::vector<double> parSmear;
00169 static std::vector<double> parBias;
00170 static std::vector<double> parResol;
00171 static std::vector<double> parScale;
00172 static std::vector<double> parCrossSection;
00173 static std::vector<double> parBgr;
00174 static std::vector<int> parResolFix;
00175 static std::vector<int> parScaleFix;
00176 static std::vector<int> parCrossSectionFix;
00177 static std::vector<int> parBgrFix;
00178 static std::vector<int> parResolOrder;
00179 static std::vector<int> parScaleOrder;
00180 static std::vector<int> parCrossSectionOrder;
00181 static std::vector<int> parBgrOrder;
00182 static std::vector<int> resfind;
00183 static int FitStrategy;
00184 static bool speedup;
00185 static double x[7][10000];
00186 static int goodmuon;
00187 static int counter_resprob;
00188 static double GLZValue[40][1001][1001];
00189 static double GLZNorm[40][1001];
00190 static double GLValue[6][1001][1001];
00191 static double GLNorm[6][1001];
00192 static double ResMaxSigma[6];
00193 static double ResHalfWidth[6];
00194 static int nbins;
00195 static int MuonType;
00196 static int MuonTypeForCheckMassWindow;
00197
00198 static std::vector<std::vector<double> > parvalue;
00199
00200 static std::vector<int> parfix;
00201 static std::vector<int> parorder;
00202
00203 static std::vector<std::pair<lorentzVector,lorentzVector> > SavedPair;
00204 static std::vector<std::pair<lorentzVector,lorentzVector> > ReducedSavedPair;
00205 static std::vector<std::pair<lorentzVector,lorentzVector> > genPair;
00206 static std::vector<std::pair<lorentzVector,lorentzVector> > simPair;
00207
00208 static bool scaleFitNotDone_;
00209
00210 static bool normalizeLikelihoodByEventNumber_;
00211
00212 static TMinuit * rminPtr_;
00213
00214 static double oldNormalization_;
00215 static unsigned int normalizationChanged_;
00216
00217
00218 static bool sherpa_;
00219
00220
00221 static bool rapidityBinsForZ_;
00222
00223 static int iev_;
00224
00225 static bool useProbsFile_;
00226
00227
00228 static double minMuonPt_;
00229 static double maxMuonPt_;
00230 static double minMuonEtaFirstRange_;
00231 static double maxMuonEtaFirstRange_;
00232 static double minMuonEtaSecondRange_;
00233 static double maxMuonEtaSecondRange_;
00234
00235 static bool debugMassResol_;
00236 static struct massResolComponentsStruct
00237 {
00238 double dmdpt1;
00239 double dmdpt2;
00240 double dmdphi1;
00241 double dmdphi2;
00242 double dmdcotgth1;
00243 double dmdcotgth2;
00244 } massResolComponents;
00245
00246
00247 static bool startWithSimplex_;
00248 static bool computeMinosErrors_;
00249 static bool minimumShapePlots_;
00250
00252
00253 static bool checkMassWindow( const double & mass, const double & leftBorder, const double & rightBorder );
00254
00256 static double probability( const double & mass, const double & massResol,
00257 const double GLvalue[][1001][1001], const double GLnorm[][1001],
00258 const int iRes, const int iY );
00259
00260 protected:
00261
00262 private:
00263
00264 struct byPt {
00265 bool operator() (const reco::Muon &a, const reco::Muon &b) const {
00266 return a.pt() > b.pt();
00267 }
00268 };
00269
00270 };
00271
00272 extern "C" void likelihood (int& npar, double* grad, double& fval, double* xval, int flag);
00273
00274 #endif