Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:24

0001 #ifndef FastSimulation_TrackingRecHitProducer_PixelResolutionHistograms_h
0002 #define FastSimulation_TrackingRecHitProducer_PixelResolutionHistograms_h 1
0003 
0004 class TFile;
0005 class TH1F;
0006 class TH2F;
0007 class TAxis;
0008 class RandomEngineAndDistribution;
0009 class SimpleHistogramGenerator;
0010 
0011 #include <memory>
0012 #include <string>
0013 
0014 /// #define COTBETA_HIST_MAX  30
0015 /// #define COTALPHA_HIST_MAX 20
0016 /// #define QBIN_HIST_MAX      4
0017 
0018 static constexpr unsigned int COTBETA_HIST_MAX = 30;
0019 static constexpr unsigned int COTALPHA_HIST_MAX = 20;
0020 static constexpr unsigned int QBIN_HIST_MAX = 4;
0021 
0022 class PixelResolutionHistograms {
0023 public:
0024   //--- Constructor to use when generating resolution histograms.
0025   //    We make empty histograms (which we own), but generator pointers
0026   //    remain null.
0027   //
0028   PixelResolutionHistograms(std::string filename,     // ROOT file for histograms
0029                             std::string rootdir,      // Subdirectory in the file, "" if none
0030                             std::string descTitle,    // Descriptive title
0031                             unsigned int detType,     // Where we are... (&&& do we need this?)
0032                             double cotbetaBinWidth,   // cot(beta) : bin width,
0033                             double cotbetaLowEdge,    //           : low endpoint,
0034                             int cotbetaBins,          //           : # of bins
0035                             double cotalphaBinWidth,  // cot(alpha): bin width,
0036                             double cotalphaLowEdge,   //           : low endpoint,
0037                             int cotalphaBins);        //           : # of bins
0038                                                       //int qbinWidth,
0039                                                       //int qbins )
0040 
0041   //--- Constructor to use when reading the histograms from a file (e.g. when
0042   //    inside a running FastSim job).  We get the histograms from a
0043   //    ROOT file, and we do *not* own them.  But we do own the
0044   //    generators.
0045   //
0046   PixelResolutionHistograms(std::string filename,        // ROOT file for histograms
0047                             std::string rootdir = "",    // ROOT dir, "" if none
0048                             int detType = -1,            // default: read from ROOT file.
0049                             bool ignore_multi = false,   // Forward Big is always single
0050                             bool ignore_single = false,  // Edge does not need single pixels
0051                             bool ignore_qBin = false);   // qBin histograms not used right now (future expansion)
0052 
0053   //--- Destructor (virtual, just in case)
0054   virtual ~PixelResolutionHistograms();
0055 
0056   //--- Status after construction (esp.loading from file). Non-zero if there
0057   //    were problems.
0058   inline int status() { return status_; }
0059 
0060   //--- Fill one entry in one resolution histogram.  Use when making histograms.
0061   int Fill(double dx,
0062            double dy,  // the difference wrt true hit
0063            double cotalpha,
0064            double cotbeta,  // cotangent of local angles
0065            int qbin,        // Qbin = category for how much charge we have
0066            int nxpix,
0067            int nypix);  // length of cluster along x,y (only care if ==1 or not)
0068 
0069   //--- Get generators, for resolution in X and Y.  Use in FastSim.
0070   const SimpleHistogramGenerator* getGeneratorX(double cotalpha, double cotbeta, int qbin, bool singlex);
0071 
0072   const SimpleHistogramGenerator* getGeneratorY(double cotalpha, double cotbeta, int qbin, bool singley);
0073 
0074 private:
0075   // Do we own the histograms, or not?
0076   bool weOwnHistograms_;
0077 
0078   // Where we are.
0079   unsigned int detType_;  // 1 for barrel, 0 for forward  /// May not need this?
0080 
0081   // Resolution binning
0082   double cotbetaBinWidth_;
0083   double cotbetaLowEdge_;
0084   int cotbetaBins_;
0085   double cotalphaBinWidth_;
0086   double cotalphaLowEdge_;
0087   int cotalphaBins_;
0088   int qbinWidth_;
0089   int qbins_;
0090 
0091   // The dummy histogram to hold the binning, and the two cached axes.
0092   TH2F* binningHisto_;
0093   TAxis* cotbetaAxis_;
0094   TAxis* cotalphaAxis_;
0095 
0096   // Resolution histograms.  I (Petar) tried to dynamically allocate
0097   // these histograms, but all possible implementations were somewhat
0098   // complicated, which would make the code harder to understand,
0099   // debug, and thus support in the long term.  Since we are here only
0100   // booking pointers of histograms, we will instead book larger
0101   // matrices, and leave them partially empty.  But who cares -- the
0102   // wasted memory of a few hundred null pointers is negligible.
0103   //
0104   // The constructor will then fill only the first cotbetaBins_ x
0105   // cotalphaBins_ x qbinBins_ histograms in the matrix, and we'll
0106   // ignore the rest.
0107   //
0108   TH1F* resMultiPixelXHist_[COTBETA_HIST_MAX][COTALPHA_HIST_MAX][QBIN_HIST_MAX];
0109   TH1F* resSinglePixelXHist_[COTBETA_HIST_MAX][COTALPHA_HIST_MAX];
0110   TH1F* resMultiPixelYHist_[COTBETA_HIST_MAX][COTALPHA_HIST_MAX][QBIN_HIST_MAX];
0111   TH1F* resSinglePixelYHist_[COTBETA_HIST_MAX][COTALPHA_HIST_MAX];
0112   TH1F* qbinHist_[COTBETA_HIST_MAX][COTALPHA_HIST_MAX];
0113 
0114   // File with histograms to load.
0115   std::unique_ptr<TFile> file_;
0116 
0117   // Status of loading.  Check if there were errors.
0118   int status_;
0119 
0120   // Identical binning and parameterization for FastSim generators.
0121   SimpleHistogramGenerator* resMultiPixelXGen_[COTBETA_HIST_MAX][COTALPHA_HIST_MAX][QBIN_HIST_MAX];
0122   SimpleHistogramGenerator* resSinglePixelXGen_[COTBETA_HIST_MAX][COTALPHA_HIST_MAX];
0123   SimpleHistogramGenerator* resMultiPixelYGen_[COTBETA_HIST_MAX][COTALPHA_HIST_MAX][QBIN_HIST_MAX];
0124   SimpleHistogramGenerator* resSinglePixelYGen_[COTBETA_HIST_MAX][COTALPHA_HIST_MAX];
0125   SimpleHistogramGenerator* qbinGen_[COTBETA_HIST_MAX][COTALPHA_HIST_MAX];
0126 };
0127 #endif