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 
14 #include <CLHEP/Vector/LorentzVector.h>
17 // #include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
22 #include "TGraphErrors.h"
23 #include "TH2F.h"
24 #include "TMinuit.h"
25 
31 
32 #include <vector>
33 
34 // #include "Functions.h"
35 // class biasFunctionBase<std::vector<double> >;
36 // class scaleFunctionBase<double*>;
37 template <class T> class biasFunctionBase;
38 template <class T> class scaleFunctionBase;
39 class smearFunctionBase;
40 template <class T> class resolutionFunctionBase;
42 class BackgroundHandler;
43 
44 class SimTrack;
45 class TString;
46 class TTree;
47 
49 
51 public:
52 
53  // Constructor
54  // ----------
56 
57  // Destructor
58  // ----------
59  virtual ~MuScleFitUtils() {};
60 
61  // Operations
62  // ----------
63  static std::pair<SimTrack, SimTrack> findBestSimuRes( const std::vector<SimTrack>& simMuons );
64  static std::pair<MuScleFitMuon, MuScleFitMuon> findBestRecoRes( const std::vector<MuScleFitMuon>& muons );
65  static std::pair<lorentzVector, lorentzVector> findGenMuFromRes( const reco::GenParticleCollection* genParticles);
66  static std::pair<lorentzVector, lorentzVector> findGenMuFromRes( const edm::HepMCProduct* evtMC );
67  static std::pair<lorentzVector, lorentzVector> findSimMuFromRes( const edm::Handle<edm::HepMCProduct> & evtMC,
68  const edm::Handle<edm::SimTrackContainer> & simTracks);
69 
70  static std::vector<TGraphErrors*> fitMass (TH2F* histo);
71  static std::vector<TGraphErrors*> fitReso (TH2F* histo);
72 
73  static lorentzVector applyScale( const lorentzVector & muon, const std::vector<double> & parval, const int charge );
74  static lorentzVector applyScale( const lorentzVector & muon, double* parval, const int charge );
75  static lorentzVector applyBias( const lorentzVector & muon, const int charge );
77  static lorentzVector fromPtEtaPhiToPxPyPz( const double* ptEtaPhiE );
78 
79  static void minimizeLikelihood();
80 
81  static double invDimuonMass( const lorentzVector & mu1, const lorentzVector & mu2 );
82  static double massResolution( const lorentzVector & mu1, const lorentzVector & mu2 );
83  static double massResolution( const lorentzVector & mu1, const lorentzVector & mu2, const std::vector<double> & parval );
84  static double massResolution( const lorentzVector & mu1, const lorentzVector & mu2, std::auto_ptr<double> parval );
85  static double massResolution( const lorentzVector & mu1, const lorentzVector & mu2, double* parval );
86  static double massResolution( const lorentzVector& mu1, const lorentzVector& mu2, const ResolutionFunction & resolFunc );
87 
88  static double massProb( const double & mass, const double & rapidity, const int ires, const double & massResol );
89  /* static double massProb( const double & mass, const double & resEta, const double & rapidity, const double & massResol, const std::vector<double> & parval, const bool doUseBkgrWindow = false ); */
90  /* static double massProb( const double & mass, const double & resEta, const double & rapidity, const double & massResol, double * parval, const bool doUseBkgrWindow = false ); */
91  static double massProb( const double & mass, const double & resEta, const double & rapidity, const double & massResol, const std::vector<double> & parval, const bool doUseBkgrWindow, const double & eta1, const double & eta2 );
92  static double massProb( const double & mass, const double & resEta, const double & rapidity, const double & massResol, double * parval, const bool doUseBkgrWindow, const double & eta1, const double & eta2 );
93  static double computeWeight( const double & mass, const int iev, const bool doUseBkgrWindow = false );
94 
95  static double deltaPhi( const double & phi1, const double & phi2 )
96  {
97  double deltaPhi = phi1 - phi2;
98  while(deltaPhi >= TMath::Pi()) deltaPhi -= 2*TMath::Pi();
99  while(deltaPhi < -TMath::Pi()) deltaPhi += 2*TMath::Pi();
100  return fabs(deltaPhi);
101  }
103  static double deltaPhiNoFabs( const double & phi1, const double & phi2 )
104  {
105  double deltaPhi = phi1 - phi2;
106  while(deltaPhi >= TMath::Pi()) deltaPhi -= 2*TMath::Pi();
107  while(deltaPhi < -TMath::Pi()) deltaPhi += 2*TMath::Pi();
108  return deltaPhi;
109  }
110  static double deltaR(const double & eta1, const double & eta2, const double & phi1, const double & phi2)
111  {
112  return sqrt( std::pow( eta1-eta2, 2 ) + std::pow( deltaPhi(phi1, phi2), 2 ) );
113  }
114 
115  static int debug; // debug option set by MuScleFit
116  static bool ResFound; // bool flag true if best resonance found (cuts on pt and eta)
117 
118  static const int totalResNum; // Total number of resonance: 6
119  static double massWindowHalfWidth[3][6]; // parameter set by MuScleFitUtils
120  static double ResGamma[6]; // parameter set by MuScleFitUtils
121  static double ResMass[6]; // parameter set by MuScleFitUtils
122  static double ResMinMass[6]; // parameter set by MuScleFitBase
123  static double crossSection[6];
124  static const double mMu2;
125  static const double muMass;
126 
127  // Array of the pdgId of resonances
128  static const unsigned int motherPdgIdArray[6];
129 
130  static unsigned int loopCounter; // parameter set by MuScleFit
131 
132  static int SmearType;
134  static int BiasType;
135  // No error, we take functions from the same group for scale and bias.
137  static int ResolFitType;
140  static int ScaleFitType;
143  static int BgrFitType;
144  // Three background regions:
145  // - one for the Z
146  // - one for the Upsilons
147  // - one for J/Psi and Psi2S
148  static const int backgroundFunctionsRegions;
149  // static backgroundFunctionBase * backgroundFunctionForRegion[];
150  // A background function for each resonance
151  // static backgroundFunctionBase * backgroundFunction[];
152 
153  // The Cross section handler takes care of computing the relative cross
154  // sections to be used depending on the resonances that are being fitted.
155  // This corresponds to a normalization of the signal pdf.
157 
158  // The background handler takes care of using the correct function in each
159  // window, use regions or resonance windows and rescale the fractions when needed
161 
162  // Parameters used to select whether to do a fit
163  static std::vector<int> doResolFit;
164  static std::vector<int> doScaleFit;
165  static std::vector<int> doCrossSectionFit;
166  static std::vector<int> doBackgroundFit;
167 
168  static int minuitLoop_;
169  static TH1D* likelihoodInLoop_;
170  static TH1D* signalProb_;
171  static TH1D* backgroundProb_;
172 
173  static bool duringMinos_;
174 
175  static std::vector<double> parSmear;
176  static std::vector<double> parBias;
177  static std::vector<double> parResol;
178  static std::vector<double> parResolStep;
179  static std::vector<double> parResolMin;
180  static std::vector<double> parResolMax;
181  static std::vector<double> parScale;
182  static std::vector<double> parScaleStep;
183  static std::vector<double> parScaleMin;
184  static std::vector<double> parScaleMax;
185  static std::vector<double> parCrossSection;
186  static std::vector<double> parBgr;
187  static std::vector<int> parResolFix;
188  static std::vector<int> parScaleFix;
189  static std::vector<int> parCrossSectionFix;
190  static std::vector<int> parBgrFix;
191  static std::vector<int> parResolOrder;
192  static std::vector<int> parScaleOrder;
193  static std::vector<int> parCrossSectionOrder;
194  static std::vector<int> parBgrOrder;
195  static std::vector<int> resfind;
196  static int FitStrategy;
197  static bool speedup; // parameter set by MuScleFit - whether to speedup processing
198  static double x[7][10000]; // smearing values set by MuScleFit constructor
199  static int goodmuon; // number of events with a usable resonance
200  static int counter_resprob;// number of times there are resolution problems
201  static double GLZValue[40][1001][1001]; // matrix with integral values of Lorentz * Gaussian
202  static double GLZNorm[40][1001]; // normalization values per each sigma
203  static double GLValue[6][1001][1001]; // matrix with integral values of Lorentz * Gaussian
204  static double GLNorm[6][1001]; // normalization values per each sigma
205  static double ResMaxSigma[6]; // max sigma of matrix
206  static double ResHalfWidth[6]; // halfwidth in matrix
207  static int nbins; // number of bins in matrix
208  static int MuonType; // 0, 1, 2 - 0 is GM, 1 is SM, 2 is track
209  static int MuonTypeForCheckMassWindow; // Reduced to be 0, 1 or 2. It is = MuonType when MuonType < 3, = 2 otherwise.
210 
211  static std::vector<std::vector<double> > parvalue;
212  // static std::map<unsigned int,std::vector<double> > parvalue;
213  static std::vector<int> parfix;
214  static std::vector<int> parorder;
215 
216  static std::vector<std::pair<lorentzVector,lorentzVector> > SavedPair;
217  static std::vector<std::pair<MuScleFitMuon,MuScleFitMuon> > SavedPairMuScleFitMuons;
218  static std::vector<std::pair<lorentzVector,lorentzVector> > ReducedSavedPair;
219  static std::vector<std::pair<lorentzVector,lorentzVector> > genPair;
220  static std::vector<std::pair<lorentzVector,lorentzVector> > simPair;
221 
222  static bool scaleFitNotDone_;
223 
225  // Pointer to the minuit object
226  static TMinuit * rminPtr_;
227  // Value stored to check whether to apply a new normalization to the likelihood
228  static double oldNormalization_;
229  static unsigned int normalizationChanged_;
230 
231  // This must be set to true if using events generated with Sherpa
232  static bool sherpa_;
233 
234  // Decide whether to use the rapidity bins for the Z
235  static bool rapidityBinsForZ_;
236 
237  static int iev_;
238 
239  static bool useProbsFile_;
240 
241  // Cuts on the muons to use in the fit
242  static bool separateRanges_;
243  static double minMuonPt_;
244  static double maxMuonPt_;
245  static double minMuonEtaFirstRange_;
246  static double maxMuonEtaFirstRange_;
247  static double minMuonEtaSecondRange_;
248  static double maxMuonEtaSecondRange_;
249  static double deltaPhiMinCut_;
250  static double deltaPhiMaxCut_;
251 
252  static bool debugMassResol_;
254  {
255  double dmdpt1;
256  double dmdpt2;
257  double dmdphi1;
258  double dmdphi2;
259  double dmdcotgth1;
260  double dmdcotgth2;
262 
263  // Fit accuracy and debug parameters
264  static bool startWithSimplex_;
265  static bool computeMinosErrors_;
266  static bool minimumShapePlots_;
267 
269  // static bool checkMassWindow( const double & mass, const int ires, const double & resMass, const double & leftFactor = 1., const double & rightFactor = 1. );
270  static bool checkMassWindow( const double & mass, const double & leftBorder, const double & rightBorder );
271 
273  static double probability( const double & mass, const double & massResol,
274  const double GLvalue[][1001][1001], const double GLnorm[][1001],
275  const int iRes, const int iY );
276 
277 protected:
278 
279 private:
280 
281  struct byPt {
282  bool operator() (const reco::Muon &a, const reco::Muon &b) const {
283  return a.pt() > b.pt();
284  }
285  };
286 
287 };
288 
289 extern "C" void likelihood (int& npar, double* grad, double& fval, double* xval, int flag);
290 
291 #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 double deltaPhiMaxCut_
static unsigned int loopCounter
static std::vector< double > parResolMax
static std::pair< lorentzVector, lorentzVector > findSimMuFromRes(const edm::Handle< edm::HepMCProduct > &evtMC, const edm::Handle< edm::SimTrackContainer > &simTracks)
static std::vector< std::pair< MuScleFitMuon, MuScleFitMuon > > SavedPairMuScleFitMuons
static int nbins
void likelihood(int &npar, double *grad, double &fval, double *xval, int flag)
static bool startWithSimplex_
static std::vector< int > doBackgroundFit
static std::vector< double > parResol
static bool debugMassResol_
int ires[2]
static double ResMinMass[6]
static TH1D * backgroundProb_
static BackgroundHandler * backgroundHandler
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
static std::vector< double > parResolMin
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:9
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 std::pair< MuScleFitMuon, MuScleFitMuon > findBestRecoRes(const std::vector< MuScleFitMuon > &muons)
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 std::vector< double > parScaleMin
static lorentzVector applyBias(const lorentzVector &muon, const int charge)
static double GLZNorm[40][1001]
T sqrt(T t)
Definition: SSEVec.h:46
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< double > parScaleStep
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 > parScaleMax
static std::vector< double > parScale
static double oldNormalization_
static bool duringMinos_
virtual double pt() const
transverse momentum
static double ResGamma[6]
static double deltaPhiMinCut_
double b
Definition: hdecay.h:120
static bool rapidityBinsForZ_
static int ResolFitType
static int goodmuon
static bool separateRanges_
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)
tuple muons
Definition: patZpeak.py:38
static lorentzVector applySmearing(const lorentzVector &muon)
static bool normalizeLikelihoodByEventNumber_
double a
Definition: hdecay.h:121
tuple mass
Definition: scaleCards.py:27
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:25
static int FitStrategy
static double maxMuonEtaFirstRange_
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< double > parResolStep
static std::vector< int > parCrossSectionFix
static resolutionFunctionBase< double * > * resolutionFunction