Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-10 07:55:36

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   // constructor
0030   ReadoutGeo(std::string detName_, std::string readoutClass_,
0031              gsl::not_null<const dd4hep::Detector*> det_,
0032              gsl::not_null<const dd4hep::rec::CellIDPositionConverter*> conv_,
0033              std::shared_ptr<spdlog::logger> log_);
0034   ~ReadoutGeo() {}
0035 
0036   // define cellID encoding
0037   CellIDType cellIDEncoding(int isec, int ipdu, int isipm, int x, int y) {
0038     // encode cellID
0039     dd4hep::rec::CellID cellID_dd4hep;
0040     m_readoutCoder->set(cellID_dd4hep, "system", m_systemID);
0041     m_readoutCoder->set(cellID_dd4hep, "sector", isec);
0042     m_readoutCoder->set(cellID_dd4hep, "pdu", ipdu);
0043     m_readoutCoder->set(cellID_dd4hep, "sipm", isipm);
0044     m_readoutCoder->set(cellID_dd4hep, "x", x);
0045     m_readoutCoder->set(cellID_dd4hep, "y", y);
0046     CellIDType cellID(cellID_dd4hep); // in case DD4hep CellID type differs from EDM type
0047     return cellID;
0048     // m_log->trace("    x={:<2} y={:<2} => cellID={:#018X}", x, y, cellID);
0049   }
0050 
0051   // loop over readout pixels, executing `lambda(cellID)` on each
0052   void VisitAllReadoutPixels(std::function<void(CellIDType)> lambda) { m_loopCellIDs(lambda); }
0053 
0054   // generated k rng cell IDs, executing `lambda(cellID)` on each
0055   void VisitAllRngPixels(std::function<void(CellIDType)> lambda, float p) {
0056     m_rngCellIDs(lambda, p);
0057   }
0058 
0059   // pixel gap mask
0060   bool PixelGapMask(CellIDType cellID, dd4hep::Position pos_hit_global) const;
0061 
0062   // transform global position `pos` to sensor `id` frame position
0063   // IMPORTANT NOTE: this has only been tested for the dRICH; if you use it, test it carefully...
0064   dd4hep::Position GetSensorLocalPosition(CellIDType id, dd4hep::Position pos) const;
0065 
0066   // set RNG seed
0067   void SetSeed(unsigned long seed) { m_random.SetSeed(seed); }
0068 
0069 protected:
0070   // common objects
0071   std::shared_ptr<spdlog::logger> m_log;
0072   std::string m_detName;
0073   std::string m_readoutClass;
0074   gsl::not_null<const dd4hep::Detector*> m_det;
0075   gsl::not_null<const dd4hep::rec::CellIDPositionConverter*> m_conv;
0076   dd4hep::DetElement m_detRich;
0077   dd4hep::BitFieldCoder* m_readoutCoder;
0078   int m_systemID;
0079   int m_num_sec;
0080   int m_num_pdus;
0081   int m_num_sipms_per_pdu;
0082   int m_num_px;
0083   double m_pixel_size;
0084 
0085   // local function to loop over cellIDs; defined in initialization and called by `VisitAllReadoutPixels`
0086   std::function<void(std::function<void(CellIDType)>)> m_loopCellIDs;
0087   // local function to generate rng cellIDs; defined in initialization and called by `VisitAllRngPixels`
0088   std::function<void(std::function<void(CellIDType)>, float)> m_rngCellIDs;
0089 
0090 private:
0091   // random number generators
0092   TRandomMixMax m_random;
0093 };
0094 } // namespace richgeo