Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-09-28 07:03:48

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2022 Chao Peng, Sylvester Joosten, Whitney Armstrong, Chao Peng
0003 
0004 /*  General PhotoMultiplier Reconstruction
0005  *
0006  *  Estimate the number of photo-electrons and convert getTimeStamp to time
0007  *  Collect cell information
0008  *
0009  *  Author: Chao Peng (ANL)
0010  *  Date: 10/03/2020
0011  */
0012 
0013 #include <algorithm>
0014 
0015 #include "Gaudi/Property.h"
0016 #include "GaudiAlg/GaudiAlgorithm.h"
0017 #include "GaudiAlg/GaudiTool.h"
0018 #include "GaudiAlg/Transformer.h"
0019 #include "GaudiKernel/PhysicalConstants.h"
0020 #include "GaudiKernel/RndmGenerators.h"
0021 #include "GaudiKernel/ToolHandle.h"
0022 
0023 #include "DDRec/CellIDPositionConverter.h"
0024 #include "DDRec/Surface.h"
0025 #include "DDRec/SurfaceManager.h"
0026 
0027 #include <k4FWCore/DataHandle.h>
0028 #include <k4Interface/IGeoSvc.h>
0029 
0030 // Event Model related classes
0031 #include "edm4eic/PMTHitCollection.h"
0032 #include "edm4eic/RawTrackerHitCollection.h"
0033 
0034 using namespace Gaudi::Units;
0035 
0036 namespace Jug::Reco {
0037 
0038 /**  General PhotoMultiplier Reconstruction
0039  *
0040  *  Estimate the number of photo-electrons and convert getTimeStamp to time
0041  *  Collect cell information
0042  *
0043  * \ingroup reco
0044  */
0045 class PhotoMultiplierReco : public GaudiAlgorithm {
0046 private:
0047   DataHandle<edm4eic::RawTrackerHitCollection> m_inputHitCollection{"inputHitCollection", Gaudi::DataHandle::Reader, this};
0048   DataHandle<edm4eic::PMTHitCollection> m_outputHitCollection{"outputHitCollection", Gaudi::DataHandle::Writer, this};
0049   Gaudi::Property<double> m_timeStep{this, "timeStep", 0.0625 * ns};
0050   Gaudi::Property<double> m_minNpe{this, "minNpe", 0.0};
0051   Gaudi::Property<double> m_speMean{this, "speMean", 80.0};
0052   Gaudi::Property<double> m_pedMean{this, "pedMean", 200.0};
0053   /// Pointer to the geometry service
0054   SmartIF<IGeoSvc> m_geoSvc;
0055   std::shared_ptr<const dd4hep::rec::CellIDPositionConverter> m_converter;
0056 
0057 public:
0058   // ill-formed: using GaudiAlgorithm::GaudiAlgorithm;
0059   PhotoMultiplierReco(const std::string& name, ISvcLocator* svcLoc) : GaudiAlgorithm(name, svcLoc) {
0060     declareProperty("inputHitCollection", m_inputHitCollection, "");
0061     declareProperty("outputHitCollection", m_outputHitCollection, "");
0062   }
0063 
0064   StatusCode initialize() override {
0065     if (GaudiAlgorithm::initialize().isFailure()) {
0066       return StatusCode::FAILURE;
0067     }
0068     m_geoSvc = service("GeoSvc");
0069     if (!m_geoSvc) {
0070       error() << "Unable to locate Geometry Service. "
0071               << "Make sure you have GeoSvc and SimSvc in the right order in the configuration." << endmsg;
0072       return StatusCode::FAILURE;
0073     }
0074     m_converter = std::make_shared<const dd4hep::rec::CellIDPositionConverter>(*(m_geoSvc->getDetector()));
0075     return StatusCode::SUCCESS;
0076   }
0077 
0078   StatusCode execute() override {
0079     // input collections
0080     const auto& rawhits = *m_inputHitCollection.get();
0081     // Create output collections
0082     auto& hits = *m_outputHitCollection.createAndPut();
0083 
0084     // reconstruct number of photo-electrons and time
0085     for (const auto& rh : rawhits) {
0086       float npe = (rh.getCharge() - m_pedMean) / m_speMean;
0087       if (npe >= m_minNpe) {
0088         float time = rh.getTimeStamp() * (static_cast<float>(m_timeStep) / ns);
0089         auto id    = rh.getCellID();
0090         // global positions
0091         auto gpos = m_converter->position(id);
0092         // local positions
0093         auto pos = m_converter->findContext(id)->volumePlacement().position();
0094         // cell dimension
0095         auto dim = m_converter->cellDimensions(id);
0096         hits.push_back(edm4eic::PMTHit{
0097             rh.getCellID(),
0098             npe,
0099             time,
0100             static_cast<float>(m_timeStep / ns),
0101             {static_cast<float>(gpos.x()), static_cast<float>(gpos.y()), static_cast<float>(gpos.z())},
0102             {static_cast<float>(dim[0] / mm), static_cast<float>(dim[1] / mm), static_cast<float>(dim[2] / mm)},
0103             0, // @FIXME: Add sector similar to CalorimeterHit
0104             {static_cast<float>(pos.x()), static_cast<float>(pos.y()), static_cast<float>(pos.z())}});
0105       }
0106     }
0107 
0108     return StatusCode::SUCCESS;
0109   }
0110 };
0111 
0112 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
0113 DECLARE_COMPONENT(PhotoMultiplierReco)
0114 
0115 } // namespace Jug::Reco