31 #include "art/Framework/Core/EDAnalyzer.h"
32 #include "art/Framework/Core/ModuleMacros.h"
33 #include "art/Framework/Principal/Event.h"
34 #include "fhiclcpp/ParameterSet.h"
35 #include "art/Framework/Principal/Handle.h"
36 #include "art/Framework/Services/Registry/ServiceHandle.h"
37 #include "art_root_io/TFileService.h"
38 #include "messagefacility/MessageLogger/MessageLogger.h"
53 #include "nug4/ParticleNavigation/ParticleList.h"
54 #include "nusimdata/SimulationBase/MCParticle.h"
57 #include "RtypesCore.h"
60 #include "TLorentzVector.h"
70 class SimPhotonCounter :
public art::EDAnalyzer{
75 void analyze(art::Event
const&);
157 int channel,
int nDirectPhotons,
int nReflectedPhotons,
158 double reflectedT0 = 0.0
175 , fPVS(art::ServiceHandle<phot::PhotonVisibilityService
const>().
get())
181 fInputModule = pset.get<std::vector<std::string>>(
"InputModule",{
"largeant"});
185 fInputModule.push_back(pset.get<std::string>(
"InputModule",
"largeant"));
198 throw art::Exception(art::errors::Configuration)
199 <<
"Building a library with reflected light time is not supported when using SimPhotonsLite.\n";
208 art::ServiceHandle<art::TFileService const>
tfs;
209 art::ServiceHandle<geo::Geometry const> geo;
211 std::cout<<
"Optical Channels positions: "<<geo->Cryostat(0).NOpDet()<<std::endl;
212 for(
int ch=0; ch!=int(geo->Cryostat(0).NOpDet()); ch++) {
213 double OpDetCenter[3];
214 geo->OpDetGeoFromOpDet(ch).GetCenter(OpDetCenter);
215 std::cout<<ch<<
" "<<OpDetCenter[0]<<
" "<<OpDetCenter[1]<<
" "<<OpDetCenter[2]<<std::endl;
218 double CryoBounds[6];
219 geo->CryostatBoundaries(CryoBounds);
221 std::cout<<
"Xmin: "<<CryoBounds[0]<<
" Xmax: "<<CryoBounds[1]<<
" Ymin: "<<CryoBounds[2]
222 <<
" Ymax: "<<CryoBounds[3]<<
" Zmin: "<<CryoBounds[4]<<
" Zmax: "<<CryoBounds[5]<<std::endl;
225 pi_serv = &*(art::ServiceHandle<cheat::ParticleInventoryService const>());
227 catch (art::Exception
const&
e) {
228 if (e.categoryCode() != art::errors::ServiceNotFound)
throw;
229 mf::LogError(
"SimPhotonCounter")
230 <<
"ParticleInventoryService service is not configured!"
231 " Please add it in the job configuration."
232 " In the meanwhile, some checks to particles will be skipped."
269 fTheEventTree = tfs->make<TTree>(
"OpDetEvents",
"OpDetEvents");
303 art::ServiceHandle<phot::PhotonVisibilityService>()->StoreLibrary();
311 art::EventNumber_t
event = evt.id().event();
315 art::ServiceHandle<opdet::OpDetResponseInterface const> odresponse;
318 art::ServiceHandle<geo::Geometry const> geo;
321 std::vector<simb::MCParticle>
const* mcpartVec =
nullptr;
324 std::vector<double> totalEnergy_track;
329 mcpartVec = evt.getHandle<std::vector<simb::MCParticle>>(
"largeant").product();
331 size_t maxNtracks = 1000U;
336 for(
size_t itrack=0; itrack!=maxNtracks; itrack++) {
340 totalEnergy_track.resize(maxNtracks, 0.);
347 std::vector<const sim::SimChannel*> sccol;
350 evt.getView(mod, sccol);
351 double totalCharge=0.0;
352 double totalEnergy=0.0;
354 for(
size_t sc = 0; sc < sccol.size(); ++sc){
358 const auto & tdcidemap = sccol[sc]->TDCIDEMap();
360 for(
auto mapitr = tdcidemap.begin(); mapitr != tdcidemap.end(); mapitr++){
361 const std::vector<sim::IDE> idevec = (*mapitr).second;
362 numIDEs += idevec.size();
364 for(
size_t iv = 0; iv < idevec.size(); ++iv){
366 if(plist->find( idevec[iv].trackID ) == plist->end()
369 mf::LogWarning(
"LArG4Ana") << idevec[iv].trackID <<
" is not in particle list";
372 if(idevec[iv].trackID < 0)
continue;
373 totalCharge +=idevec[iv].numElectrons;
374 scCharge += idevec[iv].numElectrons;
375 totalEnergy +=idevec[iv].energy;
376 scEnergy += idevec[iv].energy;
378 totalEnergy_track[idevec[iv].trackID] += idevec[iv].energy/3.;
396 auto photon_handles = evt.getMany<std::vector<sim::SimPhotons>>();
397 if (photon_handles.size() == 0)
398 throw art::Exception(art::errors::ProductNotFound)<<
"sim SimPhotons retrieved and you requested them.";
404 for (
auto const& ph_handle: photon_handles) {
406 if (!ph_handle.isValid())
continue;
407 if (ph_handle.provenance()->moduleLabel() != mod)
continue;
409 bool Reflected = (ph_handle.provenance()->productInstanceName() ==
"Reflected");
411 if((*ph_handle).size()>0)
415 const int maxNtracks = 1000;
416 for(
size_t itrack=0; itrack!=maxNtracks; itrack++) {
417 for(
size_t pmt_i=0; pmt_i!=geo->NOpChannels(); pmt_i++) {
427 if(
fVerbosity > 0)
std::cout<<
"Found OpDet hit collection of size "<< (*ph_handle).size()<<std::endl;
429 if((*ph_handle).size()>0)
432 for(
auto const& itOpDet: (*ph_handle) )
562 std::cout<<
"Filling the analysis tree"<<std::endl;
565 std::vector<double> this_xyz;
568 for(simb::MCParticle
const& pPart: *mcpartVec){
570 if(pPart.Process() ==
"primary")
581 fpdg = pPart.PdgCode();
588 for(
size_t i_s=1; i_s < pPart.NumberTrajectoryPoints(); i_s++){
591 this_xyz[0] = pPart.Position(i_s).X();
592 this_xyz[1] = pPart.Position(i_s).Y();
593 this_xyz[2] = pPart.Position(i_s).Z();
595 fstepTimes.push_back(pPart.Position(i_s).T());
610 auto photon_handles = evt.getMany<std::vector<sim::SimPhotonsLite>>();
611 if (photon_handles.size() == 0)
612 throw art::Exception(art::errors::ProductNotFound)<<
"sim SimPhotons retrieved and you requested them.";
620 for (
auto const& ph_handle: photon_handles) {
622 if (!ph_handle.isValid())
continue;
623 if (ph_handle.provenance()->moduleLabel() != mod)
continue;
625 bool Reflected = (ph_handle.provenance()->productInstanceName() ==
"Reflected");
631 if(
fVerbosity > 0)
std::cout<<
"Found OpDet hit collection of size "<< (*ph_handle).size()<<std::endl;
634 if((*ph_handle).size()>0)
637 for (
auto const&
photon : (*ph_handle) )
641 std::map<int, int> PhotonsMap =
photon.DetectedPhotons;
648 for(
auto it = PhotonsMap.begin(); it!= PhotonsMap.end(); it++)
662 for(
int i = 0; i < it->second ; i++)
675 else if (Reflected) {
724 int channel,
int nDirectPhotons,
int nReflectedPhotons,
729 = *(art::ServiceHandle<phot::PhotonVisibilityService>());
742 pvs.
SetLibraryEntry(VoxID, channel,
double(nReflectedPhotons)/NProd,
true);
757 DEFINE_ART_MODULE(SimPhotonCounter)
Store parameters for running LArG4.
Int_t fCountOpDetDetected
std::vector< std::vector< double > > fstepPositions
process_name can override from command line with o or output photon
TVector3 initialPhotonPosition
void RetrieveLightProd(int &VoxID, double &N) const
Encapsulate the construction of a single cyostat.
TTree * fLightAnalysisTree
void storeVisibility(int channel, int nDirectPhotons, int nReflectedPhotons, double reflectedT0=0.0) const
bool fMakeLightAnalysisTree
std::vector< double > fPosition0
All information of a photon entering the sensitive optical detector volume.
phot::PhotonVisibilityService const * fPVS
std::vector< std::vector< double > > fSignalsvuv
static constexpr double kVUVWavelength
Value used when a typical ultraviolet light wavelength is needed.
TVector3 finalPhotonPosition
std::vector< double > fstepTimes
std::vector< std::string > fInputModule
bool StoreReflected() const
Simulation objects for optical detectors.
bool isVisible(double wavelength) const
Returns if we label as "visibile" a photon with specified wavelength [nm].
void analyze(art::Event const &)
bool fMakeDetectedPhotonsTree
static const int NoParticleId
static constexpr double kVisibleWavelength
Value used when a typical visible light wavelength is needed.
TTree * fThePhotonTreeDetected
void SetLibraryReflT0Entry(int VoxID, int OpChannel, float value)
TTree * fThePhotonTreeAll
Int_t fCountEventDetected
Class def header for mctrack data container.
bool fMakeOpDetEventsTree
const sim::ParticleList & ParticleList() const
Encapsulate the geometry of an optical detector.
Collection of photons which recorded on one channel.
void SetLibraryEntry(int VoxID, OpDetID_t libOpChannel, float N, bool wantReflected=false)
std::vector< std::vector< std::vector< double > > > fSignals_vis
object containing MC truth information necessary for making RawDigits and doing back tracking ...
bool const fUseLitePhotons
static constexpr double kVisibleThreshold
Threshold used to resolve between visible and ultraviolet light.
std::vector< std::vector< double > > fSignalsvis
Int_t fCountOpDetReflDetected
art::ServiceHandle< art::TFileService > tfs
std::vector< std::vector< std::vector< double > > > fSignals_vuv
Tools and modules for checking out the basics of the Monte Carlo.
art framework interface to geometry description
BEGIN_PROLOG could also be cout
services LArG4Parameters UseLitePhotons
cheat::ParticleInventoryService const * pi_serv