Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:39

0001 #ifndef MUSCLEFITBASE_H
0002 #define MUSCLEFITBASE_H
0003 /**
0004  * This class is used as a base for MuSlceFit. The reason for putting some of the methods
0005  * inside this base class is that they are used also by the TestCorrection analyzer.
0006  */
0007 
0008 #include <map>
0009 #include <string>
0010 #include "TFile.h"
0011 #include "Histograms.h"
0012 #include "MuScleFitUtils.h"
0013 #include "FWCore/Utilities/interface/InputTag.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 #include "MuonAnalysis/MomentumScaleCalibration/interface/MuonPair.h"
0016 #include "MuonAnalysis/MomentumScaleCalibration/interface/GenMuonPair.h"
0017 
0018 class MuScleFitBase {
0019 public:
0020   MuScleFitBase(const edm::ParameterSet& iConfig)
0021       : probabilitiesFileInPath_(iConfig.getUntrackedParameter<std::string>(
0022             "ProbabilitiesFileInPath", "MuonAnalysis/MomentumScaleCalibration/test/Probs_new_Horace_CTEQ_1000.root")),
0023         probabilitiesFile_(iConfig.getUntrackedParameter<std::string>("ProbabilitiesFile", "")),
0024         theMuonType_(iConfig.getParameter<int>("MuonType")),
0025         theMuonLabel_(iConfig.getParameter<edm::InputTag>("MuonLabel")),
0026         theCompressionSettings_(iConfig.getUntrackedParameter<int>("compressionSettings", -1)),
0027         theRootFileName_(iConfig.getUntrackedParameter<std::string>("OutputFileName")),
0028         theGenInfoRootFileName_(
0029             iConfig.getUntrackedParameter<std::string>("OutputGenInfoFileName", "genSimRecoPlots.root")),
0030         debug_(iConfig.getUntrackedParameter<int>("debug", 0)) {}
0031   virtual ~MuScleFitBase() noexcept(false) {}
0032 
0033 protected:
0034   /// Create the histograms map
0035   void fillHistoMap(TFile* outputFile, unsigned int iLoop);
0036   /// Clean the histograms map
0037   void clearHistoMap();
0038   /// Save the histograms map to file
0039   void writeHistoMap(const unsigned int iLoop);
0040 
0041   /// Read probability distributions from a local root file.
0042   void readProbabilityDistributionsFromFile();
0043 
0044   std::string probabilitiesFileInPath_;
0045   std::string probabilitiesFile_;
0046 
0047   int theMuonType_;
0048   edm::InputTag theMuonLabel_;
0049   int theCompressionSettings_;
0050   std::string theRootFileName_;
0051   std::string theGenInfoRootFileName_;
0052 
0053   int debug_;
0054 
0055   /// Functor used to compute the normalization integral of probability functions
0056   class ProbForIntegral {
0057   public:
0058     ProbForIntegral(const double& massResol, const int iRes, const int iY, const bool isZ)
0059         : massResol_(massResol), iRes_(iRes), iY_(iY), isZ_(isZ) {}
0060     double operator()(const double* mass, const double*) {
0061       if (isZ_) {
0062         return (MuScleFitUtils::probability(
0063             *mass, massResol_, MuScleFitUtils::GLZValue, MuScleFitUtils::GLZNorm, iRes_, iY_));
0064       }
0065       return (
0066           MuScleFitUtils::probability(*mass, massResol_, MuScleFitUtils::GLValue, MuScleFitUtils::GLNorm, iRes_, iY_));
0067     }
0068 
0069   protected:
0070     double massResol_;
0071     int iRes_, iY_;
0072     bool isZ_;
0073   };
0074 
0075   /// The files were the histograms are saved
0076   std::vector<TFile*> theFiles_;
0077 
0078   /// The map of histograms
0079   std::map<std::string, Histograms*> mapHisto_;
0080 
0081   /// Used to store the muon pairs plus run and event number prior to the creation of the internal tree
0082   std::vector<MuonPair> muonPairs_;
0083   /// Stores the genMuon pairs and the motherId prior to the creation of the internal tree
0084   std::vector<GenMuonPair> genMuonPairs_;
0085 };
0086 
0087 #endif