Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-07-03 07:05:28

0001 // Copyright (C) 2023, Christopher Dilks, Luigi Dello Stritto
0002 // Subject to the terms in the LICENSE file found in the top-level directory.
0003 //
0004 
0005 // helper functions for RICH readout
0006 
0007 #pragma once
0008 
0009 #include <DD4hep/DetElement.h>
0010 // DD4Hep
0011 #include <DD4hep/Detector.h>
0012 #include <DD4hep/Objects.h>
0013 #include <DDRec/CellIDPositionConverter.h>
0014 #include <DDSegmentation/BitFieldCoder.h>
0015 #include <Parsers/Primitives.h>
0016 #include <TRandomGen.h>
0017 #include <spdlog/logger.h>
0018 #include <functional>
0019 #include <gsl/pointers>
0020 #include <memory>
0021 #include <string>
0022 
0023 // local
0024 #include "RichGeo.h"
0025 
0026 namespace richgeo {
0027   class ReadoutGeo {
0028     public:
0029 
0030       // constructor
0031       ReadoutGeo(std::string detName_, gsl::not_null<const dd4hep::Detector*> det_, gsl::not_null<const dd4hep::rec::CellIDPositionConverter*> conv_, std::shared_ptr<spdlog::logger> log_);
0032       ~ReadoutGeo() {}
0033 
0034       // define cellID encoding
0035       CellIDType cellIDEncoding(int isec, int ipdu, int isipm, int x, int y)
0036       {
0037         // encode cellID
0038         dd4hep::rec::CellID cellID_dd4hep;
0039         m_readoutCoder->set(cellID_dd4hep, "system", m_systemID);
0040         m_readoutCoder->set(cellID_dd4hep, "sector", isec);
0041         m_readoutCoder->set(cellID_dd4hep, "pdu",    ipdu);
0042         m_readoutCoder->set(cellID_dd4hep, "sipm",   isipm);
0043         m_readoutCoder->set(cellID_dd4hep, "x",      x);
0044         m_readoutCoder->set(cellID_dd4hep, "y",      y);
0045         CellIDType cellID(cellID_dd4hep); // in case DD4hep CellID type differs from EDM type
0046         return cellID;
0047         // m_log->trace("    x={:<2} y={:<2} => cellID={:#018X}", x, y, cellID);
0048       }
0049 
0050       // loop over readout pixels, executing `lambda(cellID)` on each
0051       void VisitAllReadoutPixels(std::function<void(CellIDType)> lambda) { m_loopCellIDs(lambda); }
0052 
0053       // generated k rng cell IDs, executing `lambda(cellID)` on each
0054       void VisitAllRngPixels(std::function<void(CellIDType)> lambda, float p) { m_rngCellIDs(lambda, p); }
0055 
0056       // pixel gap mask
0057       bool PixelGapMask(CellIDType cellID, dd4hep::Position pos_hit_global);
0058 
0059       // transform global position `pos` to sensor `id` frame position
0060       // IMPORTANT NOTE: this has only been tested for the dRICH; if you use it, test it carefully...
0061       dd4hep::Position GetSensorLocalPosition(CellIDType id, dd4hep::Position pos);
0062 
0063       // set RNG seed
0064       void SetSeed(unsigned long seed) { m_random.SetSeed(seed); }
0065 
0066     protected:
0067 
0068       // common objects
0069       std::shared_ptr<spdlog::logger> m_log;
0070       std::string            m_detName;
0071       gsl::not_null<const dd4hep::Detector*> m_det;
0072       gsl::not_null<const dd4hep::rec::CellIDPositionConverter*> m_conv;
0073       dd4hep::DetElement     m_detRich;
0074       dd4hep::BitFieldCoder* m_readoutCoder;
0075       int                    m_systemID;
0076       int                    m_num_sec;
0077       int                    m_num_pdus;
0078       int                    m_num_sipms_per_pdu;
0079       int                    m_num_px;
0080       double                 m_pixel_size;
0081 
0082       // local function to loop over cellIDs; defined in initialization and called by `VisitAllReadoutPixels`
0083       std::function< void(std::function<void(CellIDType)>) > m_loopCellIDs;
0084       // local function to generate rng cellIDs; defined in initialization and called by `VisitAllRngPixels`
0085       std::function< void(std::function<void(CellIDType)>, float) > m_rngCellIDs;
0086 
0087     private:
0088 
0089       // random number generators
0090       TRandomMixMax m_random;
0091 
0092   };
0093 }