Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-11-18 03:07:10

0001 #ifndef ALIGNMENT_OFFLINEVALIDATION_PREPAREDMRTRENDS_H_
0002 #define ALIGNMENT_OFFLINEVALIDATION_PREPAREDMRTRENDS_H_
0003 
0004 #include <iostream>
0005 #include <string>
0006 #include <vector>
0007 #include <algorithm>
0008 #include <map>
0009 #include <iomanip>
0010 #include <fstream>
0011 #include <experimental/filesystem>
0012 #include "TPad.h"
0013 #include "TCanvas.h"
0014 #include "TGraph.h"
0015 #include "TGraphErrors.h"
0016 #include "TMultiGraph.h"
0017 #include "TH1.h"
0018 #include "THStack.h"
0019 #include "TROOT.h"
0020 #include "TFile.h"
0021 #include "TLegend.h"
0022 #include "TLegendEntry.h"
0023 #include "TMath.h"
0024 #include "TRegexp.h"
0025 #include "TPaveLabel.h"
0026 #include "TPaveText.h"
0027 #include "TStyle.h"
0028 #include "TLine.h"
0029 #include "boost/property_tree/ptree.hpp"
0030 #include "boost/property_tree/json_parser.hpp"
0031 
0032 /*!
0033  * \def Dummy value in case a DMR would fail for instance
0034  */
0035 #define DUMMY -999.
0036 /*!
0037  * \def Scale factor value to have mean and sigmas expressed in micrometers.
0038  */
0039 #define DMRFactor 10000.
0040 
0041 /*! \struct Point
0042  *  \brief Structure Point
0043  *         Contains parameters of Gaussian fits to DMRs
0044  *  
0045  * @param run:             run number (IOV boundary)
0046  * @param scale:           scale for the measured quantity: cm->μm for DMRs, 1 for normalized residuals
0047  * @param mu:              mu/mean from Gaussian fit to DMR/DrmsNR
0048  * @param sigma:           sigma/standard deviation from Gaussian fit to DMR/DrmsNR
0049  * @param muplus:          mu/mean for the inward pointing modules
0050  * @param muminus:         mu/mean for outward pointing modules
0051  * @param sigmaplus:       sigma/standard for inward pointing modules 
0052  * @param sigmaminus: //!< sigma/standard for outward pointing modules
0053  */
0054 struct Point {
0055   float run, scale, mu, sigma, muplus, muminus, sigmaplus, sigmaminus;
0056 
0057   /*! \fn Point
0058      *  \brief Constructor of structure Point, initialising all members one by one
0059      */
0060   Point(float Run = DUMMY,
0061         float ScaleFactor = DMRFactor,
0062         float y1 = DUMMY,
0063         float y2 = DUMMY,
0064         float y3 = DUMMY,
0065         float y4 = DUMMY,
0066         float y5 = DUMMY,
0067         float y6 = DUMMY)
0068       : run(Run), scale(ScaleFactor), mu(y1), sigma(y2), muplus(y3), muminus(y5), sigmaplus(y4), sigmaminus(y6) {}
0069 
0070   /*! \fn Point
0071      *  \brief Constructor of structure Point, initialising all members from DMRs directly (with split)
0072      */
0073   Point(float Run, float ScaleFactor, TH1 *histo, TH1 *histoplus, TH1 *histominus)
0074       : Point(Run,
0075               ScaleFactor,
0076               histo->GetMean(),
0077               histo->GetMeanError(),
0078               histoplus->GetMean(),
0079               histoplus->GetMeanError(),
0080               histominus->GetMean(),
0081               histominus->GetMeanError()) {}
0082 
0083   /*! \fn Point
0084      *  \brief Constructor of structure Point, initialising all members from DMRs directly (without split)
0085      */
0086   Point(float Run, float ScaleFactor, TH1 *histo) : Point(Run, ScaleFactor, histo->GetMean(), histo->GetMeanError()) {}
0087 
0088   inline float GetRun() const { return run; }
0089   inline float GetMu() const { return scale * mu; }
0090   inline float GetMuPlus() const { return scale * muplus; }
0091   inline float GetMuMinus() const { return scale * muminus; }
0092   inline float GetSigma() const { return scale * sigma; }
0093   inline float GetSigmaPlus() const { return scale * sigmaplus; }
0094   inline float GetSigmaMinus() const { return scale * sigmaminus; }
0095   inline float GetDeltaMu() const {
0096     if (muplus == DUMMY && muminus == DUMMY)
0097       return DUMMY;
0098     else
0099       return scale * (muplus - muminus);
0100   }
0101   inline float GetSigmaDeltaMu() const {
0102     if (sigmaplus == DUMMY && sigmaminus == DUMMY)
0103       return DUMMY;
0104     else
0105       return scale * hypot(sigmaplus, sigmaminus);
0106   }
0107 };
0108 
0109 /*! \class Geometry
0110  *  \brief Class Geometry
0111  *         Contains vector for fit parameters (mean, sigma, etc.) obtained from multiple IOVs
0112  *         See Structure Point for description of the parameters.
0113  */
0114 
0115 class Geometry {
0116 public:
0117   std::vector<Point> points;
0118 
0119 private:
0120   //template<typename T> std::vector<T> GetQuantity (T (Point::*getter)() const) const {
0121   std::vector<float> GetQuantity(float (Point::*getter)() const) const {
0122     std::vector<float> v;
0123     for (Point point : points) {
0124       float value = (point.*getter)();
0125       v.push_back(value);
0126     }
0127     return v;
0128   }
0129 
0130 public:
0131   TString title;
0132   Geometry() : title("") {}
0133   Geometry(TString Title) : title(Title) {}
0134 
0135   inline void SetTitle(TString Title) { title = Title; }
0136   inline TString GetTitle() { return title; }
0137   inline std::vector<float> Run() const { return GetQuantity(&Point::GetRun); }
0138   inline std::vector<float> Mu() const { return GetQuantity(&Point::GetMu); }
0139   inline std::vector<float> MuPlus() const { return GetQuantity(&Point::GetMuPlus); }
0140   inline std::vector<float> MuMinus() const { return GetQuantity(&Point::GetMuMinus); }
0141   inline std::vector<float> Sigma() const { return GetQuantity(&Point::GetSigma); }
0142   inline std::vector<float> SigmaPlus() const { return GetQuantity(&Point::GetSigmaPlus); }
0143   inline std::vector<float> SigmaMinus() const { return GetQuantity(&Point::GetSigmaMinus); }
0144   inline std::vector<float> DeltaMu() const { return GetQuantity(&Point::GetDeltaMu); }
0145   inline std::vector<float> SigmaDeltaMu() const { return GetQuantity(&Point::GetSigmaDeltaMu); }
0146 };
0147 
0148 class PrepareDMRTrends {
0149 public:
0150   PrepareDMRTrends(const char *outputFileName, boost::property_tree::ptree &json);
0151   ~PrepareDMRTrends() {}
0152 
0153   TString getName(TString structure, int layer, TString geometry);
0154   void compileDMRTrends(std::vector<int> IOVlist,
0155                         TString Variable,
0156                         std::vector<std::string> inputFiles,
0157                         std::vector<TString> structures,
0158                         const std::map<TString, int> nlayers,
0159                         bool FORCE = false);
0160 
0161 private:
0162   const char *outputFileName_;
0163   std::vector<std::string> geometries;
0164 };
0165 
0166 #endif  // ALIGNMENT_OFFLINEVALIDATION_PREPAREDMRTRENDS_H_