Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:38

0001 // @(#)root/eve:$Id$
0002 // Author: Matevz Tadel 2007
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_REveCaloData
0013 #define ROOT_REveCaloData
0014 
0015 #include <vector>
0016 #include "ROOT/REveElement.hxx"
0017 #include "ROOT/REveSecondarySelectable.hxx"
0018 
0019 #include "TMath.h"
0020 #include "TAxis.h"
0021 
0022 class TH2F;
0023 class THStack;
0024 
0025 namespace ROOT {
0026 namespace Experimental {
0027 
0028 class REveCaloDataSelector;
0029 
0030 class REveCaloData: public REveElement,
0031                     public REveAuntAsList,
0032                     public REveSecondarySelectable
0033 {
0034 public:
0035    struct SliceInfo_t
0036    {
0037       TString  fName;      // Name of the slice, eg. ECAL, HCAL.
0038       Float_t  fThreshold; // Only display towers with higher energy.
0039       Color_t  fColor;     // Color used to draw this longitudinal slice.
0040       Color_t  fTransparency; // Transparency used to draw this longitudinal slice.
0041 
0042       SliceInfo_t(): fName(""), fThreshold(0), fColor(kRed), fTransparency(0) {}
0043 
0044       virtual ~SliceInfo_t() {}
0045 
0046       void Setup(const char* name, Float_t threshold, Color_t col, Char_t transp = 101)
0047       {
0048          fName      = name;
0049          fThreshold = threshold;
0050          fColor     = col;
0051          if (transp <= 100) fTransparency = transp;
0052       };
0053    };
0054 
0055    typedef std::vector<SliceInfo_t>           vSliceInfo_t;
0056    typedef std::vector<SliceInfo_t>::iterator vSliceInfo_i;
0057 
0058    /**************************************************************************/
0059 
0060    struct CellId_t
0061    {
0062       // Cell ID inner structure.
0063 
0064       Int_t fTower;
0065       Int_t fSlice;
0066 
0067       Float_t fFraction;
0068 
0069       CellId_t() : fTower(0), fSlice(0), fFraction(0) {}
0070       CellId_t(Int_t t, Int_t s, Float_t f=1.0f) : fTower(t), fSlice(s), fFraction(f) {}
0071 
0072       bool operator<(const CellId_t& o) const
0073       { return (fTower == o.fTower) ? fSlice < o.fSlice : fTower < o.fTower; }
0074    };
0075 
0076    struct CellGeom_t
0077    {
0078       // Cell geometry inner structure.
0079 
0080       Float_t fPhiMin;
0081       Float_t fPhiMax;
0082       Float_t fEtaMin;
0083       Float_t fEtaMax;
0084 
0085       Float_t fThetaMin; // cached
0086       Float_t fThetaMax; // cached
0087 
0088       CellGeom_t(): fPhiMin(0), fPhiMax(0), fEtaMin(0), fEtaMax(0), fThetaMin(0), fThetaMax(0) {}
0089       CellGeom_t(Float_t etaMin, Float_t etaMax, Float_t phiMin, Float_t phiMax) {Configure(etaMin, etaMax, phiMin, phiMax);}
0090       virtual ~CellGeom_t() {}
0091 
0092       void Configure(Float_t etaMin, Float_t etaMax, Float_t phiMin, Float_t phiMax);
0093 
0094       Float_t EtaMin()   const { return fEtaMin; }
0095       Float_t EtaMax()   const { return fEtaMax; }
0096       Float_t Eta()      const { return (fEtaMin+fEtaMax)*0.5f; }
0097       Float_t EtaDelta() const { return fEtaMax-fEtaMin; }
0098 
0099       Float_t PhiMin()   const { return fPhiMin; }
0100       Float_t PhiMax()   const { return fPhiMax; }
0101       Float_t Phi()      const { return (fPhiMin+fPhiMax)*0.5f; }
0102       Float_t PhiDelta() const { return fPhiMax-fPhiMin; }
0103 
0104       Float_t ThetaMin() const { return fThetaMin; }
0105       Float_t ThetaMax() const { return fThetaMax; }
0106       Float_t Theta() const { return (fThetaMax+fThetaMin)*0.5f; }
0107       Float_t ThetaDelta() const { return fThetaMax-fThetaMin; }
0108 
0109       Bool_t  IsUpperRho() const
0110       {
0111          const Float_t phi = Phi();
0112          return ((phi > 0 && phi <= TMath::Pi()) || phi < - TMath::Pi());
0113       }
0114 
0115       virtual void  Dump() const;
0116    };
0117 
0118    struct CellData_t : public CellGeom_t
0119    {
0120       // Cell data inner structure.
0121 
0122       Float_t fValue;
0123 
0124       CellData_t() : CellGeom_t(), fValue(0) {}
0125       ~CellData_t() override {}
0126 
0127       Float_t Value(Bool_t) const;
0128       void Dump() const override;
0129    };
0130 
0131 
0132    struct RebinData_t
0133    {
0134       Int_t fNSlices;
0135 
0136       std::vector<Float_t> fSliceData;
0137       std::vector<Int_t>   fBinData;
0138 
0139       Float_t* GetSliceVals(Int_t bin);
0140 
0141       void Clear()
0142       {
0143          fSliceData.clear();
0144          fBinData.clear();
0145       }
0146    };
0147 
0148    /**************************************************************************/
0149 
0150    typedef std::vector<CellId_t>               vCellId_t;
0151    typedef std::vector<CellId_t>::iterator     vCellId_i;
0152 
0153    typedef std::vector<CellGeom_t>             vCellGeom_t;
0154    typedef std::vector<CellGeom_t>::iterator   vCellGeom_i;
0155    typedef std::vector<CellGeom_t>::const_iterator   vCellGeom_ci;
0156 
0157 private:
0158    REveCaloData& operator=(const REveCaloData&) = delete;
0159 
0160 protected:
0161    vSliceInfo_t fSliceInfos;
0162 
0163    std::unique_ptr<TAxis>   fEtaAxis;
0164    std::unique_ptr<TAxis>   fPhiAxis;
0165 
0166    Bool_t       fWrapTwoPi;
0167 
0168    Float_t      fMaxValEt; // cached
0169    Float_t      fMaxValE;  // cached
0170 
0171    Float_t      fEps;
0172 
0173    std::unique_ptr<REveCaloDataSelector> fSelector;
0174 
0175 public:
0176    REveCaloData(const char* n="REveCaloData", const char* t="");
0177    ~REveCaloData() override {}
0178 
0179    void    FillImpliedSelectedSet(Set_t& impSelSet, const std::set<int>& sec_idcs) override;
0180 
0181    virtual void    GetCellList(Float_t etaMin, Float_t etaMax,
0182                                Float_t phi,    Float_t phiRng,
0183                                vCellId_t &out) const = 0;
0184 
0185    void            ProcessSelection(vCellId_t& sel_cells, UInt_t selectionId, Bool_t multi);
0186 
0187    virtual void    Rebin(TAxis *ax, TAxis *ay, vCellId_t &in, Bool_t et, RebinData_t &out) const = 0;
0188 
0189 
0190    virtual void    GetCellData(const CellId_t &id, CellData_t& data) const = 0;
0191 
0192    virtual void    InvalidateUsersCellIdCache();
0193    virtual void    DataChanged();
0194 
0195    Int_t           GetNSlices()    const { return fSliceInfos.size(); }
0196    SliceInfo_t&    RefSliceInfo(Int_t s) { return fSliceInfos[s]; }
0197    void            SetSliceThreshold(Int_t slice, Float_t threshold);
0198    Float_t         GetSliceThreshold(Int_t slice) const;
0199    void            SetSliceColor(Int_t slice, Color_t col);
0200    Color_t         GetSliceColor(Int_t slice) const;
0201    void            SetSliceTransparency(Int_t slice, Char_t t);
0202    Char_t          GetSliceTransparency(Int_t slice) const;
0203 
0204    virtual void    GetEtaLimits(Double_t &min, Double_t &max) const = 0;
0205 
0206    virtual void    GetPhiLimits(Double_t &min, Double_t &max) const = 0;
0207 
0208    virtual Float_t GetMaxVal(Bool_t et) const { return et ? fMaxValEt : fMaxValE; }
0209    Bool_t  Empty() const { return fMaxValEt < 1e-5; }
0210 
0211    virtual TAxis*  GetEtaBins()    const { return fEtaAxis.get(); }
0212    virtual void    SetEtaBins(std::unique_ptr<TAxis> ax) { fEtaAxis = std::move(ax); }
0213 
0214    virtual TAxis*  GetPhiBins()    const { return fPhiAxis.get(); }
0215    virtual void    SetPhiBins(std::unique_ptr<TAxis> ax) { fPhiAxis= std::move(ax); }
0216 
0217    virtual Float_t GetEps()      const { return fEps; }
0218    virtual void    SetEps(Float_t eps) { fEps=eps; }
0219 
0220    Bool_t   GetWrapTwoPi() const { return fWrapTwoPi; }
0221    void     SetWrapTwoPi(Bool_t w) { fWrapTwoPi=w; }
0222 
0223    void     SetSelector(REveCaloDataSelector* iSelector) { fSelector.reset(iSelector); }
0224    REveCaloDataSelector* GetSelector() { return fSelector.get(); }
0225 
0226    Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override;
0227 
0228    static  Float_t EtaToTheta(Float_t eta);
0229 
0230    bool RequiresExtraSelectionData() const override { return true; };
0231    void FillExtraSelectionData(nlohmann::json&, const std::set<int>&) const override;
0232 
0233    using REveElement::GetHighlightTooltip;
0234    std::string GetHighlightTooltip(const std::set<int>& secondary_idcs) const override;
0235 };
0236 
0237 /**************************************************************************/
0238 /**************************************************************************/
0239 
0240 class REveCaloDataVec: public REveCaloData
0241 {
0242 
0243 private:
0244    REveCaloDataVec& operator=(const REveCaloDataVec&) = delete;
0245 
0246 protected:
0247    typedef std::vector<Float_t>               vFloat_t;
0248    typedef std::vector<Float_t>::iterator     vFloat_i;
0249 
0250    typedef std::vector<vFloat_t>              vvFloat_t;
0251    typedef std::vector<vFloat_t>::iterator    vvFloat_i;
0252 
0253    vvFloat_t   fSliceVec;
0254    vCellGeom_t fGeomVec;
0255 
0256    Int_t       fTower; // current tower
0257 
0258    Float_t     fEtaMin;
0259    Float_t     fEtaMax;
0260 
0261    Float_t     fPhiMin;
0262    Float_t     fPhiMax;
0263 
0264 public:
0265    REveCaloDataVec(Int_t nslices);
0266    ~REveCaloDataVec() override;
0267 
0268    Int_t AddSlice();
0269    Int_t AddTower(Float_t etaMin, Float_t etaMax, Float_t phiMin, Float_t phiMax);
0270    void  FillSlice(Int_t slice, Float_t value);
0271    void  FillSlice(Int_t slice, Int_t tower, Float_t value);
0272 
0273    Int_t GetNCells() { return fGeomVec.size(); }
0274    std::vector<Float_t>&  GetSliceVals(Int_t slice) { return fSliceVec[slice]; }
0275    std::vector<REveCaloData::CellGeom_t>& GetCellGeom() { return fGeomVec; }
0276 
0277    void GetCellList(Float_t etaMin, Float_t etaMax,
0278                             Float_t phi,    Float_t phiRng,
0279                             vCellId_t &out) const override;
0280 
0281    void Rebin(TAxis *ax, TAxis *ay, vCellId_t &in, Bool_t et, RebinData_t &out) const override;
0282 
0283    void GetCellData(const REveCaloData::CellId_t &id, REveCaloData::CellData_t& data) const override;
0284    void GetEtaLimits(Double_t &min, Double_t &max) const override { min=fEtaMin, max=fEtaMax;}
0285    void GetPhiLimits(Double_t &min, Double_t &max) const override { min=fPhiMin; max=fPhiMax;}
0286 
0287 
0288    void  DataChanged() override;
0289    void          SetAxisFromBins(Double_t epsX=0.001, Double_t epsY=0.001);
0290 };
0291 
0292 /**************************************************************************/
0293 /**************************************************************************/
0294 
0295 class REveCaloDataHist: public REveCaloData
0296 {
0297 private:
0298    REveCaloDataHist& operator=(const REveCaloDataHist&) = delete;
0299 
0300 protected:
0301    THStack*    fHStack{nullptr};
0302 
0303 public:
0304    REveCaloDataHist();
0305    ~REveCaloDataHist() override;
0306 
0307    void GetCellList( Float_t etaMin, Float_t etaMax,
0308                              Float_t phi, Float_t phiRng, vCellId_t &out) const override;
0309 
0310    void Rebin(TAxis *ax, TAxis *ay, vCellId_t &in, Bool_t et, RebinData_t &out) const override;
0311 
0312    void GetCellData(const REveCaloData::CellId_t &id, REveCaloData::CellData_t& data) const override;
0313 
0314    void GetEtaLimits(Double_t &min, Double_t &max) const override;
0315    void GetPhiLimits(Double_t &min, Double_t &max) const override;
0316 
0317 
0318    void DataChanged() override;
0319 
0320    THStack* GetStack() { return fHStack; }
0321 
0322    TH2F*    GetHist(Int_t slice) const;
0323 
0324    Int_t   AddHistogram(TH2F* hist);
0325 };
0326 
0327 /**************************************************************************/
0328 /**************************************************************************/
0329 class REveCaloDataSliceSelector
0330 {
0331 private:
0332    int fSliceIdx{-1};
0333 
0334 public:
0335    REveCaloDataSliceSelector(int s):fSliceIdx(s) {}
0336    int GetSliceIndex() {return fSliceIdx;}
0337 
0338    virtual ~REveCaloDataSliceSelector() = default;
0339 
0340    virtual void ProcessSelection(REveCaloData::vCellId_t& sel_cells, UInt_t selectionId, bool multi) = 0;
0341    virtual void GetCellsFromSecondaryIndices(const std::set<int>& idcs, REveCaloData::vCellId_t& out) = 0;
0342 };
0343 
0344 class REveCaloDataSelector
0345 {
0346 private:
0347    int fActiveSlice{-1};
0348    std::vector< std::unique_ptr<REveCaloDataSliceSelector> > fSliceSelectors;
0349 
0350 public:
0351    void ProcessSelection( REveCaloData::vCellId_t& sel_cells, UInt_t selectionId, Bool_t multi);
0352    void GetCellsFromSecondaryIndices(const std::set<int>&, REveCaloData::vCellId_t& out);
0353 
0354    void AddSliceSelector(std::unique_ptr<REveCaloDataSliceSelector> s) {fSliceSelectors.push_back(std::move(s));}
0355    void SetActiveSlice(int s){ fActiveSlice = s;}
0356 
0357    virtual ~REveCaloDataSelector() = default;
0358 };
0359 
0360 } // namespace Experimental
0361 } // namespace ROOT
0362 #endif
0363