SiPMReadout_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file SiPMReadout_module.cc
3 /// \brief Create the readout from the sipm signals
4 ///
5 /// \author eldwan.brianne@desy.de
6 ////////////////////////////////////////////////////////////////////////
7 
8 #ifndef GAR_READOUTSIMULATION_SIPMREADOUT
9 #define GAR_READOUTSIMULATION_SIPMREADOUT
10 
11 // C++ Includes
12 #include <memory>
13 #include <vector> // std::ostringstream
14 #include <iostream>
15 
16 // Framework includes
20 #include "fhiclcpp/ParameterSet.h"
25 #include "cetlib_except/exception.h"
26 #include "cetlib/search_path.h"
28 
29 // nutools extensions
30 #include "nurandom/RandomUtils/NuRandomService.h"
31 
32 // GArSoft Includes
33 #include "Utilities/AssociationUtil.h"
38 #include "Geometry/GeometryGAr.h"
39 #include "CoreUtils/ServiceUtil.h"
40 
41 // Forward declarations
42 
43 ///Geant4 interface
44 namespace gar {
45  namespace rosim {
46 
47  /**
48  * @brief Runs simulation including smearing of energy and SiPM saturation for the ECAL readout
49  *
50  *
51  * Randomness
52  * -----------
53  *
54  * The random number generators used by this process are:
55  * - 'GEANT' instance: used by Geant4
56  * - 'propagation' instance: used in electron propagation
57  *
58  */
60  public:
61 
62  /// Standard constructor and destructor for an FMWK module.
63  explicit SiPMReadout(fhicl::ParameterSet const& pset);
64  virtual ~SiPMReadout();
65 
66  // Plugins should not be copied or assigned.
67  SiPMReadout(SiPMReadout const &) = delete;
68  SiPMReadout(SiPMReadout &&) = delete;
69  SiPMReadout & operator = (SiPMReadout const &) = delete;
70  SiPMReadout & operator = (SiPMReadout &&) = delete;
71 
72  void produce (::art::Event& evt) override;
73 
74  void reconfigure(fhicl::ParameterSet const& pset);
75 
76  private:
77 
78  void CollectHits(const art::Event &evt, const std::string &label, const std::string &instance, std::vector< art::Ptr<sdp::CaloDeposit> > &hitVector);
79 
80  std::map<raw::CellID_t, std::vector< art::Ptr<sdp::CaloDeposit> > > MakeCellIDMapArtPtr(std::vector< art::Ptr<sdp::CaloDeposit> > &hitVector);
81 
82  std::string fG4Label; ///< label of G4 module
83  std::string fInstanceLabelName; ///< product instance name
84 
85  const gar::geo::GeometryCore* fGeo; ///< geometry information
86  std::unique_ptr<SiPMReadoutSimAlg> fROSimAlg; ///< algorithm to simulate the electronics
87 
88  CLHEP::HepRandomEngine &fEngine; ///< random engine
89  };
90 
91  } // namespace rosim
92 
93  namespace rosim {
94 
95  //----------------------------------------------------------------------
96  // Constructor
98  : art::EDProducer{pset},
100  {
101  fGeo = gar::providerFrom<geo::GeometryGAr>();
102 
103  this->reconfigure(pset);
104 
106  consumes< std::vector<sdp::CaloDeposit> >(tag);
107  produces< std::vector<raw::CaloRawDigit> >(fInstanceLabelName);
108  produces< art::Assns<raw::CaloRawDigit, sdp::CaloDeposit> >(fInstanceLabelName);
109 
110  return;
111  }
112 
113  //----------------------------------------------------------------------
114  // Destructor
116  {
117  }
118 
119  //----------------------------------------------------------------------
121  {
122  MF_LOG_DEBUG("SiPMReadout") << "Debug: SiPMReadout()";
123 
124  fG4Label = pset.get<std::string >("G4ModuleLabel", "geant");
125  fInstanceLabelName = pset.get<std::string >("InstanceLabelName", "");
126 
127  auto ROAlgPars = pset.get<fhicl::ParameterSet>("ReadoutSimAlgPars");
128  auto ROAlgName = ROAlgPars.get<std::string>("ReadoutSimType");
129 
130  if(ROAlgName.compare("Standard_ECAL") == 0) {
131  fROSimAlg = std::make_unique<gar::rosim::ECALReadoutSimStandardAlg>(fEngine, ROAlgPars);
132  }
133  else if(ROAlgName.compare("Standard_MuID") == 0) {
134  fROSimAlg = std::make_unique<gar::rosim::MuIDReadoutSimStandardAlg>(fEngine, ROAlgPars);
135  }
136  else {
137  throw cet::exception("SiPMReadout")
138  << "Unable to determine which readout simulation algorithm to use, bail";
139  }
140 
141  return;
142  }
143 
144  //--------------------------------------------------------------------------
146  {
147  MF_LOG_DEBUG("SiPMReadout") << "produce()";
148 
149  //Collect the hits to be passed to the algo
150  std::vector< art::Ptr<sdp::CaloDeposit> > artHits;
151  this->CollectHits(evt, fG4Label, fInstanceLabelName, artHits);
152 
153  //Get contributions per cellID for association to digi hit
154  std::map<raw::CellID_t, std::vector< art::Ptr<sdp::CaloDeposit> > > m_cIDMapArtPtrVec = this->MakeCellIDMapArtPtr(artHits);
155 
156  //Pass the sim hits to the algo
157  fROSimAlg->PrepareAlgo(artHits);
158 
159  //Perform the digitization
160  fROSimAlg->DoDigitization();
161 
162  //Get the digitized hits
163  std::vector< raw::CaloRawDigit* > digiVec = fROSimAlg->GetDigitizedHits();
164 
165  // loop over the lists and put the particles and voxels into the event as collections
166  std::unique_ptr< std::vector<raw::CaloRawDigit> > digitCol (new std::vector<raw::CaloRawDigit>);
167  std::unique_ptr< art::Assns<raw::CaloRawDigit, sdp::CaloDeposit> > DigiSimHitsAssns(new art::Assns<raw::CaloRawDigit, sdp::CaloDeposit>);
168 
170 
171  for(auto const &it : digiVec)
172  {
173  digitCol->emplace_back(*it);
174  art::Ptr<raw::CaloRawDigit> digiPtr = makeDigiPtr(digitCol->size() - 1);
175  //get the associated vector of art ptr based on cellID
176  std::vector< art::Ptr<sdp::CaloDeposit> > simPtrVec = m_cIDMapArtPtrVec[it->CellID()];
177  for(auto hitpointer : simPtrVec)
178  DigiSimHitsAssns->addSingle(digiPtr, hitpointer);
179  }
180 
181  evt.put(std::move(digitCol), fInstanceLabelName);
182  evt.put(std::move(DigiSimHitsAssns), fInstanceLabelName);
183 
184  return;
185  } // CaloReadout::produce()
186 
187  //--------------------------------------------------------------------------
189  {
190  art::InputTag itag(label, instance);
191  auto theHits = evt.getHandle< std::vector<sdp::CaloDeposit> >(itag);
192  if (!theHits)
193  return;
194 
195  for (unsigned int i = 0; i < theHits->size(); ++i)
196  {
197  const art::Ptr<sdp::CaloDeposit> hit(theHits, i);
198  hitVector.push_back(hit);
199  }
200  }
201 
202  //--------------------------------------------------------------------------
203  std::map<raw::CellID_t, std::vector< art::Ptr<sdp::CaloDeposit> > > SiPMReadout::MakeCellIDMapArtPtr(std::vector< art::Ptr<sdp::CaloDeposit> > &hitVector)
204  {
205  std::map<raw::CellID_t, std::vector< art::Ptr<sdp::CaloDeposit> > > cIDMapArtPtrVec;
206 
207  for (std::vector< art::Ptr<sdp::CaloDeposit> >::const_iterator iter = hitVector.begin(), iterEnd = hitVector.end(); iter != iterEnd; ++iter)
208  {
209  art::Ptr<sdp::CaloDeposit> hitPtr = *iter;
210  const sdp::CaloDeposit *hit = hitPtr.get();
211 
212  if( cIDMapArtPtrVec.count(hit->CellID()) == 0 )
213  {
214  std::vector< art::Ptr<sdp::CaloDeposit> > vecArtPtr;
215  vecArtPtr.push_back(hitPtr);
216  cIDMapArtPtrVec.insert( std::make_pair(hit->CellID(), vecArtPtr) );
217  }
218  else
219  {
220  cIDMapArtPtrVec[hit->CellID()].push_back(hitPtr);
221  }
222  }
223 
224  return cIDMapArtPtrVec;
225  }
226 
227 
228  } // namespace rosim
229 
230  namespace rosim {
231 
233 
234  } // namespace rosim
235 } // gar
236 #endif // GAR_READOUTSIMULATION_SIPMREADOUT
base_engine_t & createEngine(seed_t seed)
std::string fG4Label
label of G4 module
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::string string
Definition: nybbler.cc:12
Runs simulation including smearing of energy and SiPM saturation for the ECAL readout.
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
CLHEP::HepRandomEngine & fEngine
random engine
SiPMReadout(fhicl::ParameterSet const &pset)
Standard constructor and destructor for an FMWK module.
struct vector vector
std::map< raw::CellID_t, std::vector< art::Ptr< sdp::CaloDeposit > > > MakeCellIDMapArtPtr(std::vector< art::Ptr< sdp::CaloDeposit > > &hitVector)
const std::string instance
Description of geometry of one entire detector.
Definition: GeometryCore.h:436
const gar::geo::GeometryCore * fGeo
geometry information
void CollectHits(const art::Event &evt, const std::string &label, const std::string &instance, std::vector< art::Ptr< sdp::CaloDeposit > > &hitVector)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
void produce(::art::Event &evt) override
def move(depos, offset)
Definition: depos.py:107
T get(std::string const &key) const
Definition: ParameterSet.h:271
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
Definition of basic calo raw digits.
raw::CellID_t const & CellID() const
Definition: CaloDeposit.h:76
std::string fInstanceLabelName
product instance name
Detector simulation of raw signals on wires.
General GArSoft Utilities.
std::unique_ptr< SiPMReadoutSimAlg > fROSimAlg
algorithm to simulate the electronics
#define MF_LOG_DEBUG(id)
TCEvent evt
Definition: DataStructs.cxx:7
T const * get() const
Definition: Ptr.h:149
art framework interface to geometry description
Definition: fwd.h:31
SiPMReadout & operator=(SiPMReadout const &)=delete
void reconfigure(fhicl::ParameterSet const &pset)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33