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