Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:00

0001 #ifndef DataFormats_Luminosity_BeamCurrentInfo_h
0002 #define DataFormats_Luminosity_BeamCurrentInfo_h
0003 
0004 /** \class BeamCurrentInfo
0005  *
0006  *
0007  * BeamCurrentInfo has been created by splitting off the
0008  * beam current information from LumiInfo. See LumiInfo
0009  * for more details.
0010  *
0011  * \author Valerie Halyo
0012  *         David Dagenhart
0013  *         Zhen Xie
0014  *         Paul Lujan
0015  * \version   October 21, 2014
0016  *
0017  ************************************************************/
0018 
0019 // To preserve space, this class stores information in uint16_t using
0020 // libminifloat. The beamIntensitiesUnpacked variables contain the expanded
0021 // float versions, and the beamIntensitiesPacked variables contain the
0022 // 16-bit versions. The intensities are also divided by 1e10 during packing
0023 // so that the values are near 1, to avoid running into the limits of
0024 // this packing.
0025 
0026 #include <vector>
0027 #include <iosfwd>
0028 #include <string>
0029 #include <cstdint>
0030 #include "DataFormats/Luminosity/interface/LumiConstants.h"
0031 
0032 class BeamCurrentInfo {
0033 public:
0034   static const float scaleFactor;  // factor to scale data by when packing/unpacking
0035 
0036   /// default constructor
0037   BeamCurrentInfo() {
0038     beam1IntensitiesUnpacked_.assign(LumiConstants::numBX, 0.0);
0039     beam2IntensitiesUnpacked_.assign(LumiConstants::numBX, 0.0);
0040     beam1IntensitiesPacked_.assign(LumiConstants::numBX, 0);
0041     beam2IntensitiesPacked_.assign(LumiConstants::numBX, 0);
0042   }
0043 
0044   /// constructor with fill
0045   BeamCurrentInfo(const std::vector<float>& beam1Intensities, const std::vector<float>& beam2Intensities) {
0046     beam1IntensitiesUnpacked_.assign(beam1Intensities.begin(), beam1Intensities.end());
0047     beam2IntensitiesUnpacked_.assign(beam2Intensities.begin(), beam2Intensities.end());
0048     packData();
0049   }
0050 
0051   /// destructor
0052   ~BeamCurrentInfo() {}
0053 
0054   // Beam intensities by bunch, or all
0055   float getBeam1IntensityBX(int bx) const;
0056   const std::vector<float>& getBeam1Intensities() const;
0057   float getBeam2IntensityBX(int bx) const;
0058   const std::vector<float>& getBeam2Intensities() const;
0059 
0060   // Get packed intensities. Only use this if you really know that this is what you want!
0061   const std::vector<uint16_t>& getBeam1IntensitiesPacked() const { return beam1IntensitiesPacked_; }
0062   const std::vector<uint16_t>& getBeam2IntensitiesPacked() const { return beam2IntensitiesPacked_; }
0063 
0064   bool isProductEqual(BeamCurrentInfo const& next) const;
0065 
0066   //
0067   //setters
0068   //
0069 
0070   // fill beam intensities
0071   void fillBeamIntensities(const std::vector<float>& beam1Intensities, const std::vector<float>& beam2Intensities);
0072   // synonym for above
0073   void fill(const std::vector<float>& beam1Intensities, const std::vector<float>& beam2Intensities);
0074 
0075   // used by ROOT iorules
0076   static void unpackData(const std::vector<uint16_t>& packed, std::vector<float>& unpacked);
0077 
0078 private:
0079   std::vector<uint16_t> beam1IntensitiesPacked_;
0080   std::vector<uint16_t> beam2IntensitiesPacked_;
0081   std::vector<float> beam1IntensitiesUnpacked_;
0082   std::vector<float> beam2IntensitiesUnpacked_;
0083   void packData();
0084   void unpackData();
0085 };
0086 
0087 std::ostream& operator<<(std::ostream& s, const BeamCurrentInfo& beamInfo);
0088 
0089 #endif  // DataFormats_Luminosity_BeamCurrentInfo_h