Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:08

0001 #ifndef CondFormats_EcalShowerContainmentCorrections_h
0002 #define CondFormats_EcalShowerContainmentCorrections_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     CondFormats
0006 // Class  :     EcalShowerContainmentCorrections
0007 //
0008 /**\class EcalShowerContainmentCorrections EcalShowerContainmentCorrections.h src/CondFormats/interface/EcalShowerContainmentCorrections.h
0009 
0010  * Description: Holds the coefficients of a polynomial that describes
0011  *             the shower containment.
0012  *
0013  * Usage example(for real code see 
0014  * CalibCalorimetry/EcalCorrectionModules/test) : 
0015  * \code
0016 
0017  ESHandle<EcalShowerContainmentCorrections> pGapCorr;
0018  iESetup.get<EcalShowerContainmentCorrectionsRcd>().get(pGapCorr);
0019   
0020  PositionCalc pos(...);
0021  
0022  Hep3Vector clusterPos= pos.CalculatePos(...);        
0023  math::XYZPoint mathpoint(clusterPos.x(),clusterPos.y(),clusterPos.z());
0024  
0025  double correction3x3 = pGapCorr->correction3x3(centerXtal,mathpoint);
0026  double correction5x5 = pGapCorr->correction5x5(centerXtal,mathpoint);
0027 
0028 
0029  * \endcode
0030  * \author       Stefano Argiro'
0031  * \date         Fri Mar  2 16:50:49 CET 2007
0032  * \id           $Id: EcalShowerContainmentCorrections.h,v 1.1 2007/05/15 20:37:22 argiro Exp $
0033 */
0034 
0035 #include "CondFormats/Serialization/interface/Serializable.h"
0036 
0037 #include <vector>
0038 #include <algorithm>
0039 #include <map>
0040 
0041 #include <DataFormats/Math/interface/Point3D.h>
0042 
0043 class EBDetId;
0044 
0045 class EcalShowerContainmentCorrections {
0046 public:
0047   /// Structure defining the container for correction coefficients
0048   /**  data[0-3]    : 3x3, x, right
0049    *   data[4-7]    : 3x3, x, left
0050    *   data[8-11]   : 3x3, y, right
0051    *   data[12-15]  : 3x3, y, left
0052    *   data[16-19]  : 5x5, x, right
0053    *   data[20-23]  : 5x5, x, left
0054    *   data[24-27]  : 5x5, y, right
0055    *   data[28-31]  : 5x5, y, left
0056    */
0057 
0058   struct Coefficients {
0059     Coefficients() {
0060       for (unsigned int i = 0; i < Coefficients::kSize; ++i)
0061         data[i] = 0;
0062     }
0063     Coefficients(const Coefficients& coeff) { std::copy(coeff.data, coeff.data + Coefficients::kSize, data); }
0064 
0065     Coefficients& operator=(const Coefficients& coeff) {
0066       if (this == &coeff)
0067         return *this;
0068       std::copy(coeff.data, coeff.data + Coefficients::kSize, data);
0069       return *this;
0070     }
0071 
0072     ///The degree of the polynomial used as correction function plus one
0073     static const int kPolynomialDegree = 4;
0074 
0075     ///Number of types of correction:  Left, right, 3x3, 5x5, x, y
0076     static const int kNTypes = 8;
0077     static const unsigned int kSize = kPolynomialDegree * kNTypes;
0078 
0079     double data[kSize];
0080 
0081     COND_SERIALIZABLE;
0082   };
0083 
0084   /// Get the correction coefficients for the given xtal
0085   /** Return zero coefficients in case the correction is not available
0086       for that xtal */
0087   const Coefficients correctionCoefficients(const EBDetId& centerxtal) const;
0088 
0089   /// Fill the correction coefficients for a given xtal, part of group @group
0090   /** Do not replace if xtal is already there*/
0091   void fillCorrectionCoefficients(const EBDetId& xtal, int group, const Coefficients& coefficients);
0092 
0093   /// Fill the correction coefficients for a given Ecal module
0094   /** Assume that corresponding  modules in different supermodules use
0095       the same coefficients*/
0096   void fillCorrectionCoefficients(const int supermodule, const int module, const Coefficients& coefficients);
0097 
0098   /// The correction factor for 3x3 matrix
0099   /** @param pos is the distance in cm from the center of the xtal
0100    *  as calculated in RecoEcal/EgammaCoreTools/interface/PositionCalc.h 
0101    *  The valid return value is in the range (0,1] (divide by this
0102    *  value to apply the correction)
0103    *  Returns -1 if correction is not avaiable for that xtal*/
0104   const double correction3x3(const EBDetId& xtal, const math::XYZPoint& pos) const;
0105 
0106   /// The correction factor for 5x5 matrix
0107   /** @param pos is the distance in cm from the center of the xtal
0108    *  as calculated in RecoEcal/EgammaCoreTools/interface/PositionCalc.h 
0109    *  The return value is in the range (0,1] (divide by this
0110    *  value to apply the correction)
0111    *  Returns -1 if correction is not avaiable for that xtal*/
0112   const double correction5x5(const EBDetId& xtal, const math::XYZPoint& pos) const;
0113 
0114 private:
0115   enum Direction { eX, eY };
0116   enum Type { e3x3, e5x5 };
0117 
0118   /** Calculate the correction for the given direction and type  */
0119   const double correctionXY(const EBDetId& xtal, double position, Direction dir, Type type) const;
0120 
0121   typedef std::map<EBDetId, int> GroupMap;
0122 
0123   /// Maps in which group a particular xtal has been placed
0124   GroupMap groupmap_;
0125 
0126   /// Holds the coeffiecients. The index corresponds to the group
0127   std::vector<Coefficients> coefficients_;
0128 
0129   COND_SERIALIZABLE;
0130 };
0131 
0132 #endif