Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:35

0001 // Classname: TFitConstraintMGaus
0002 // Author: Jan E. Sundermann, Verena Klose (TU Dresden)
0003 
0004 //________________________________________________________________
0005 //
0006 // TFitConstraintMGaus::
0007 // --------------------
0008 //
0009 // Fit constraint: mass conservation ( m_i - m_j - alpha * MassConstraint == 0 )
0010 //
0011 
0012 #include <iostream>
0013 #include <iomanip>
0014 #include "PhysicsTools/KinFitter/interface/TFitConstraintMGaus.h"
0015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0016 #include "TClass.h"
0017 
0018 //----------------
0019 // Constructor --
0020 //----------------
0021 TFitConstraintMGaus::TFitConstraintMGaus() : TFitConstraintM() { init(); }
0022 
0023 TFitConstraintMGaus::TFitConstraintMGaus(std::vector<TAbsFitParticle*>* ParList1,
0024                                          std::vector<TAbsFitParticle*>* ParList2,
0025                                          Double_t Mass,
0026                                          Double_t Width)
0027     : TFitConstraintM(ParList1, ParList2, Mass) {
0028   init();
0029   setMassConstraint(Mass, Width);
0030 }
0031 
0032 TFitConstraintMGaus::TFitConstraintMGaus(const TString& name,
0033                                          const TString& title,
0034                                          std::vector<TAbsFitParticle*>* ParList1,
0035                                          std::vector<TAbsFitParticle*>* ParList2,
0036                                          Double_t Mass,
0037                                          Double_t Width)
0038     : TFitConstraintM(name, title, ParList1, ParList2, Mass) {
0039   init();
0040   setMassConstraint(Mass, Width);
0041 }
0042 
0043 void TFitConstraintMGaus::init() {
0044   _nPar = 1;
0045   _iniparameters.ResizeTo(1, 1);
0046   _iniparameters(0, 0) = 1.;
0047   _parameters.ResizeTo(1, 1);
0048   _parameters = _iniparameters;
0049 }
0050 
0051 //--------------
0052 // Destructor --
0053 //--------------
0054 TFitConstraintMGaus::~TFitConstraintMGaus() {}
0055 
0056 //--------------
0057 // Operations --
0058 //--------------
0059 
0060 void TFitConstraintMGaus::setMassConstraint(Double_t Mass, Double_t Width) {
0061   _TheMassConstraint = Mass;
0062   _width = Width;
0063   setCovMatrix(nullptr);
0064   if (!Mass)
0065     throw cms::Exception("Configuration") << "Error occured!\n"
0066                                           << "Object type : TFitConstraintMGaus\n"
0067                                           << "Object name : " << GetName() << "\n"
0068                                           << "Object title: " << GetTitle() << "\n"
0069                                           << "Mass of 0 GeV not supported, please choose a larger mass!\n";
0070   _covMatrix(0, 0) = (Width * Width) / (Mass * Mass);
0071 }
0072 
0073 Double_t TFitConstraintMGaus::getInitValue() {
0074   // Get initial value of constraint (before the fit)
0075 
0076   Double_t InitValue =
0077       CalcMass(&_ParList1, true) - CalcMass(&_ParList2, true) - _iniparameters(0, 0) * _TheMassConstraint;
0078 
0079   return InitValue;
0080 }
0081 
0082 Double_t TFitConstraintMGaus::getCurrentValue() {
0083   // Get value of constraint after the fit
0084 
0085   Double_t CurrentValue =
0086       CalcMass(&_ParList1, false) - CalcMass(&_ParList2, false) - _parameters(0, 0) * _TheMassConstraint;
0087 
0088   return CurrentValue;
0089 }
0090 
0091 TMatrixD* TFitConstraintMGaus::getDerivativeAlpha() {
0092   // Calculate dF/dAlpha = -1 * M
0093 
0094   TMatrixD* DerivativeMatrix = new TMatrixD(1, 1);
0095   DerivativeMatrix->Zero();
0096 
0097   (*DerivativeMatrix)(0, 0) = -1. * _TheMassConstraint;
0098 
0099   return DerivativeMatrix;
0100 }
0101 
0102 TString TFitConstraintMGaus::getInfoString() {
0103   // Collect information to be used for printout
0104 
0105   std::stringstream info;
0106   info << std::scientific << std::setprecision(6);
0107 
0108   info << "__________________________" << std::endl << std::endl;
0109   info << "OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << std::endl;
0110 
0111   info << "initial value: " << getInitValue() << std::endl;
0112   info << "current value: " << getCurrentValue() << std::endl;
0113   info << "mean mass: " << _TheMassConstraint << std::endl;
0114   info << "width: " << _width << std::endl;
0115   info << "initial mass: " << _iniparameters(0, 0) * _TheMassConstraint << std::endl;
0116   info << "current mass: " << _parameters(0, 0) * _TheMassConstraint << std::endl;
0117 
0118   return info.str();
0119 }
0120 
0121 void TFitConstraintMGaus::print() {
0122   // Print constraint contents
0123 
0124   edm::LogVerbatim("KinFitter") << this->getInfoString();
0125 }