CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuScleFitUtils.h
Go to the documentation of this file.
1 #ifndef MuScleFitUtils_H
2 #define MuScleFitUtils_H
3 
13 #include <CLHEP/Vector/LorentzVector.h>
16 // #include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
21 #include "TGraphErrors.h"
22 #include "TH2F.h"
23 #include "TMinuit.h"
24 
27 
28 #include <vector>
29 
30 // #include "Functions.h"
31 // class biasFunctionBase<std::vector<double> >;
32 // class scaleFunctionBase<double*>;
33 template <class T> class biasFunctionBase;
34 template <class T> class scaleFunctionBase;
35 class smearFunctionBase;
36 template <class T> class resolutionFunctionBase;
38 class BackgroundHandler;
39 
40 class SimTrack;
41 class TString;
42 class TTree;
43 
45 
47 public:
48 
49  // Constructor
50  // ----------
52 
53  // Destructor
54  // ----------
55  virtual ~MuScleFitUtils() {};
56 
57  // Operations
58  // ----------
59  static std::pair<SimTrack, SimTrack> findBestSimuRes( const std::vector<SimTrack>& simMuons );
60  static std::pair<lorentzVector, lorentzVector> findBestRecoRes( const std::vector<reco::LeafCandidate>& muons );
61  static std::pair <lorentzVector, lorentzVector> findGenMuFromRes( const reco::GenParticleCollection* genParticles);
62  static std::pair<lorentzVector, lorentzVector> findGenMuFromRes( const edm::HepMCProduct* evtMC );
63  static std::pair<lorentzVector, lorentzVector> findSimMuFromRes( const edm::Handle<edm::HepMCProduct> & evtMC,
64  const edm::Handle<edm::SimTrackContainer> & simTracks);
65 
66  static std::vector<TGraphErrors*> fitMass (TH2F* histo);
67  static std::vector<TGraphErrors*> fitReso (TH2F* histo);
68 
69  static lorentzVector applyScale( const lorentzVector & muon, const std::vector<double> & parval, const int charge );
70  static lorentzVector applyScale( const lorentzVector & muon, double* parval, const int charge );
71  static lorentzVector applyBias( const lorentzVector & muon, const int charge );
73  static lorentzVector fromPtEtaPhiToPxPyPz( const double* ptEtaPhiE );
74 
75  static void minimizeLikelihood();
76 
77  static double invDimuonMass( const lorentzVector & mu1, const lorentzVector & mu2 );
78  static double massResolution( const lorentzVector & mu1, const lorentzVector & mu2 );
79  static double massResolution( const lorentzVector & mu1, const lorentzVector & mu2, const std::vector<double> & parval );
80  static double massResolution( const lorentzVector & mu1, const lorentzVector & mu2, std::auto_ptr<double> parval );
81  static double massResolution( const lorentzVector & mu1, const lorentzVector & mu2, double* parval );
82 
83  static double massProb( const double & mass, const double & rapidity, const int ires, const double & massResol );
84  static double massProb( const double & mass, const double & resEta, const double & rapidity, const double & massResol, const std::vector<double> & parval, const bool doUseBkgrWindow = false );
85  static double massProb( const double & mass, const double & resEta, const double & rapidity, const double & massResol, double * parval, const bool doUseBkgrWindow = false );
86  static double computeWeight( const double & mass, const int iev, const bool doUseBkgrWindow = false );
87 
88  static double deltaPhi( const double & phi1, const double & phi2 )
89  {
90  double deltaPhi = phi1 - phi2;
91  while(deltaPhi >= TMath::Pi()) deltaPhi -= 2*TMath::Pi();
92  while(deltaPhi < -TMath::Pi()) deltaPhi += 2*TMath::Pi();
93  return fabs(deltaPhi);
94  }
96  static double deltaPhiNoFabs( const double & phi1, const double & phi2 )
97  {
98  double deltaPhi = phi1 - phi2;
99  while(deltaPhi >= TMath::Pi()) deltaPhi -= 2*TMath::Pi();
100  while(deltaPhi < -TMath::Pi()) deltaPhi += 2*TMath::Pi();
101  return deltaPhi;
102  }
103  static double deltaR(const double & eta1, const double & eta2, const double & phi1, const double & phi2)
104  {
105  return sqrt( std::pow( eta1-eta2, 2 ) + std::pow( deltaPhi(phi1, phi2), 2 ) );
106  }
107 
108  static int debug; // debug option set by MuScleFit
109  static bool ResFound; // bool flag true if best resonance found (cuts on pt and eta)
110 
111  static const int totalResNum; // Total number of resonance: 6
112  static double massWindowHalfWidth[3][6]; // parameter set by MuScleFitUtils
113  static double ResGamma[6]; // parameter set by MuScleFitUtils
114  static double ResMass[6]; // parameter set by MuScleFitUtils
115  static double ResMinMass[6]; // parameter set by MuScleFitBase
116  static double crossSection[6];
117  static const double mMu2;
118  static const double muMass;
119 
120  // Array of the pdgId of resonances
121  static const unsigned int motherPdgIdArray[6];
122 
123  static unsigned int loopCounter; // parameter set by MuScleFit
124 
125  static int SmearType;
127  static int BiasType;
128  // No error, we take functions from the same group for scale and bias.
130  static int ResolFitType;
133  static int ScaleFitType;
136  static int BgrFitType;
137  // Three background regions:
138  // - one for the Z
139  // - one for the Upsilons
140  // - one for J/Psi and Psi2S
141  static const int backgroundFunctionsRegions;
142  // static backgroundFunctionBase * backgroundFunctionForRegion[];
143  // A background function for each resonance
144  // static backgroundFunctionBase * backgroundFunction[];
145 
146  // The Cross section handler takes care of computing the relative cross
147  // sections to be used depending on the resonances that are being fitted.
148  // This corresponds to a normalization of the signal pdf.
150 
151  // The background handler takes care of using the correct function in each
152  // window, use regions or resonance windows and rescale the fractions when needed
154 
155  // Parameters used to select whether to do a fit
156  static std::vector<int> doResolFit;
157  static std::vector<int> doScaleFit;
158  static std::vector<int> doCrossSectionFit;
159  static std::vector<int> doBackgroundFit;
160 
161  static int minuitLoop_;
162  static TH1D* likelihoodInLoop_;
163  static TH1D* signalProb_;
164  static TH1D* backgroundProb_;
165 
166  static bool duringMinos_;
167 
168  static std::vector<double> parSmear;
169  static std::vector<double> parBias;
170  static std::vector<double> parResol;
171  static std::vector<double> parScale;
172  static std::vector<double> parCrossSection;
173  static std::vector<double> parBgr;
174  static std::vector<int> parResolFix;
175  static std::vector<int> parScaleFix;
176  static std::vector<int> parCrossSectionFix;
177  static std::vector<int> parBgrFix;
178  static std::vector<int> parResolOrder;
179  static std::vector<int> parScaleOrder;
180  static std::vector<int> parCrossSectionOrder;
181  static std::vector<int> parBgrOrder;
182  static std::vector<int> resfind;
183  static int FitStrategy;
184  static bool speedup; // parameter set by MuScleFit - whether to speedup processing
185  static double x[7][10000]; // smearing values set by MuScleFit constructor
186  static int goodmuon; // number of events with a usable resonance
187  static int counter_resprob;// number of times there are resolution problems
188  static double GLZValue[40][1001][1001]; // matrix with integral values of Lorentz * Gaussian
189  static double GLZNorm[40][1001]; // normalization values per each sigma
190  static double GLValue[6][1001][1001]; // matrix with integral values of Lorentz * Gaussian
191  static double GLNorm[6][1001]; // normalization values per each sigma
192  static double ResMaxSigma[6]; // max sigma of matrix
193  static double ResHalfWidth[6]; // halfwidth in matrix
194  static int nbins; // number of bins in matrix
195  static int MuonType; // 0, 1, 2 - 0 is GM, 1 is SM, 2 is track
196  static int MuonTypeForCheckMassWindow; // Reduced to be 0, 1 or 2. It is = MuonType when MuonType < 3, = 2 otherwise.
197 
198  static std::vector<std::vector<double> > parvalue;
199  // static std::map<unsigned int,std::vector<double> > parvalue;
200  static std::vector<int> parfix;
201  static std::vector<int> parorder;
202 
203  static std::vector<std::pair<lorentzVector,lorentzVector> > SavedPair;
204  static std::vector<std::pair<lorentzVector,lorentzVector> > ReducedSavedPair;
205  static std::vector<std::pair<lorentzVector,lorentzVector> > genPair;
206  static std::vector<std::pair<lorentzVector,lorentzVector> > simPair;
207 
208  static bool scaleFitNotDone_;
209 
211  // Pointer to the minuit object
212  static TMinuit * rminPtr_;
213  // Value stored to check whether to apply a new normalization to the likelihood
214  static double oldNormalization_;
215  static unsigned int normalizationChanged_;
216 
217  // This must be set to true if using events generated with Sherpa
218  static bool sherpa_;
219 
220  // Decide whether to use the rapidity bins for the Z
221  static bool rapidityBinsForZ_;
222 
223  static int iev_;
224 
225  static bool useProbsFile_;
226 
227  // Cuts on the muons to use in the fit
228  static double minMuonPt_;
229  static double maxMuonPt_;
230  static double minMuonEtaFirstRange_;
231  static double maxMuonEtaFirstRange_;
232  static double minMuonEtaSecondRange_;
233  static double maxMuonEtaSecondRange_;
234 
235  static bool debugMassResol_;
237  {
238  double dmdpt1;
239  double dmdpt2;
240  double dmdphi1;
241  double dmdphi2;
242  double dmdcotgth1;
243  double dmdcotgth2;
245 
246  // Fit accuracy and debug parameters
247  static bool startWithSimplex_;
248  static bool computeMinosErrors_;
249  static bool minimumShapePlots_;
250 
252  // static bool checkMassWindow( const double & mass, const int ires, const double & resMass, const double & leftFactor = 1., const double & rightFactor = 1. );
253  static bool checkMassWindow( const double & mass, const double & leftBorder, const double & rightBorder );
254 
256  static double probability( const double & mass, const double & massResol,
257  const double GLvalue[][1001][1001], const double GLnorm[][1001],
258  const int iRes, const int iY );
259 
260 protected:
261 
262 private:
263 
264  struct byPt {
265  bool operator() (const reco::Muon &a, const reco::Muon &b) const {
266  return a.pt() > b.pt();
267  }
268  };
269 
270 };
271 
272 extern "C" void likelihood (int& npar, double* grad, double& fval, double* xval, int flag);
273 
274 #endif
static double deltaPhiNoFabs(const double &phi1, const double &phi2)
Without fabs at the end, used to have a symmetric distribution for the resolution fits and variance c...
static std::vector< std::pair< lorentzVector, lorentzVector > > simPair
const double Pi
static std::vector< int > doScaleFit
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
static std::vector< int > doResolFit
static std::pair< lorentzVector, lorentzVector > findGenMuFromRes(const reco::GenParticleCollection *genParticles)
static double GLValue[6][1001][1001]
static std::vector< double > parBias
static std::vector< int > parCrossSectionOrder
static smearFunctionBase * smearFunction
static std::vector< int > parScaleOrder
long int flag
Definition: mlp_lapack.h:47
static std::vector< int > doCrossSectionFit
static void minimizeLikelihood()
static double maxMuonEtaSecondRange_
static std::vector< int > parBgrOrder
static std::vector< int > parfix
static unsigned int loopCounter
static std::pair< lorentzVector, lorentzVector > findSimMuFromRes(const edm::Handle< edm::HepMCProduct > &evtMC, const edm::Handle< edm::SimTrackContainer > &simTracks)
static int nbins
static bool startWithSimplex_
static std::vector< int > doBackgroundFit
static std::vector< double > parResol
static bool debugMassResol_
static double ResMinMass[6]
static TH1D * backgroundProb_
static BackgroundHandler * backgroundHandler
void likelihood(int &npar, double *grad, double &fval, double *xval, int flag)
static double x[7][10000]
static int debug
static std::vector< TGraphErrors * > fitMass(TH2F *histo)
static double ResMass[6]
static double massWindowHalfWidth[3][6]
static bool speedup
static bool scaleFitNotDone_
static unsigned int normalizationChanged_
static bool ResFound
static scaleFunctionBase< std::vector< double > > * biasFunction
static bool checkMassWindow(const double &mass, const double &leftBorder, const double &rightBorder)
Method to check if the mass value is within the mass window of the i-th resonance.
static std::vector< int > parBgrFix
tuple histo
Definition: trackerHits.py:12
static bool minimumShapePlots_
virtual ~MuScleFitUtils()
static int MuonTypeForCheckMassWindow
static double minMuonEtaFirstRange_
static double massProb(const double &mass, const double &rapidity, const int ires, const double &massResol)
static struct MuScleFitUtils::massResolComponentsStruct massResolComponents
double charge(const std::vector< uint8_t > &Ampls)
static int BiasType
static std::vector< int > parScaleFix
static bool computeMinosErrors_
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:8
static scaleFunctionBase< std::vector< double > > * scaleFunctionForVec
static std::pair< SimTrack, SimTrack > findBestSimuRes(const std::vector< SimTrack > &simMuons)
static std::vector< std::vector< double > > parvalue
static double maxMuonPt_
static int ScaleFitType
static std::vector< std::pair< lorentzVector, lorentzVector > > genPair
static std::vector< std::pair< lorentzVector, lorentzVector > > ReducedSavedPair
static const int totalResNum
static const double muMass
static double massResolution(const lorentzVector &mu1, const lorentzVector &mu2)
static const unsigned int motherPdgIdArray[6]
static int minuitLoop_
static lorentzVector applyBias(const lorentzVector &muon, const int charge)
static double GLZNorm[40][1001]
T sqrt(T t)
Definition: SSEVec.h:28
static std::vector< double > parBgr
static int SmearType
static lorentzVector fromPtEtaPhiToPxPyPz(const double *ptEtaPhiE)
static double ResMaxSigma[6]
static double computeWeight(const double &mass, const int iev, const bool doUseBkgrWindow=false)
static std::vector< std::pair< lorentzVector, lorentzVector > > SavedPair
static double invDimuonMass(const lorentzVector &mu1, const lorentzVector &mu2)
static lorentzVector applyScale(const lorentzVector &muon, const std::vector< double > &parval, const int charge)
static TH1D * signalProb_
static std::vector< int > parResolFix
static double GLZValue[40][1001][1001]
static TMinuit * rminPtr_
static std::vector< double > parSmear
static std::vector< int > parResolOrder
static bool sherpa_
static int BgrFitType
static TH1D * likelihoodInLoop_
static const int backgroundFunctionsRegions
static std::vector< double > parScale
static double oldNormalization_
static bool duringMinos_
virtual double pt() const
transverse momentum
static double ResGamma[6]
double b
Definition: hdecay.h:120
static bool rapidityBinsForZ_
static int ResolFitType
static int goodmuon
static double minMuonEtaSecondRange_
static int iev_
static std::vector< double > parCrossSection
static const double mMu2
static double GLNorm[6][1001]
static std::vector< TGraphErrors * > fitReso(TH2F *histo)
static lorentzVector applySmearing(const lorentzVector &muon)
static bool normalizeLikelihoodByEventNumber_
double a
Definition: hdecay.h:121
static int MuonType
static double deltaPhi(const double &phi1, const double &phi2)
static double probability(const double &mass, const double &massResol, const double GLvalue[][1001][1001], const double GLnorm[][1001], const int iRes, const int iY)
Computes the probability given the mass, mass resolution and the arrays with the probabilities and th...
static double minMuonPt_
static scaleFunctionBase< double * > * scaleFunction
static bool useProbsFile_
static std::vector< int > resfind
static double ResHalfWidth[6]
static int counter_resprob
static resolutionFunctionBase< std::vector< double > > * resolutionFunctionForVec
static std::vector< int > parorder
static double crossSection[6]
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:26
static int FitStrategy
static double maxMuonEtaFirstRange_
static std::pair< lorentzVector, lorentzVector > findBestRecoRes(const std::vector< reco::LeafCandidate > &muons)
bool operator()(const reco::Muon &a, const reco::Muon &b) const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
static double deltaR(const double &eta1, const double &eta2, const double &phi1, const double &phi2)
static CrossSectionHandler * crossSectionHandler
static std::vector< int > parCrossSectionFix
static resolutionFunctionBase< double * > * resolutionFunction