26 #include "nusimdata/SimulationBase/MCParticle.h"
27 #include "nusimdata/SimulationBase/MCTruth.h"
30 #include "art/Framework/Core/EDAnalyzer.h"
31 #include "art/Framework/Principal/Event.h"
32 #include "art/Framework/Principal/Handle.h"
33 #include "art/Framework/Services/Registry/ServiceHandle.h"
34 #include "art_root_io/TFileService.h"
35 #include "art/Framework/Core/ModuleMacros.h"
36 #include "canvas/Persistency/Common/FindManyP.h"
37 #include "canvas/Utilities/Exception.h"
42 #include "messagefacility/MessageLogger/MessageLogger.h"
43 #include "fhiclcpp/ParameterSet.h"
44 #include "fhiclcpp/types/Table.h"
45 #include "fhiclcpp/types/Atom.h"
46 #include "cetlib/pow.h"
73 Name(
"SimModuleLabel"),
74 Comment(
"tag of particle simulation data product")
78 Name(
"SimChannelModuleLabel"),
79 Comment(
"tag of channel simulation data product")
84 Comment(
"tag of CRT simulation data product")
89 Comment(
"Print information about what's going on")
101 Name(
"ClockSpeedCRT"),
102 Comment(
"Clock speed of the CRT system [MHz]")
106 Name(
"CrtBackTrack"),
120 virtual void analyze(
const art::Event& event)
override;
123 virtual void endJob()
override;
138 std::map<std::string, TH1D*>
hADC;
139 std::map<std::string, TH1D*>
hNpe;
174 , fSimModuleLabel (config().SimModuleLabel())
175 , fSimChannelModuleLabel(config().SimChannelModuleLabel())
176 , fCRTSimLabel (config().CRTSimLabel())
177 , fVerbose (config().
Verbose())
178 , fQPed (config().QPed())
179 , fQSlope (config().QSlope())
180 , fClockSpeedCRT (config().ClockSpeedCRT())
181 , fCrtBackTrack (config().CrtBackTrack())
190 art::ServiceHandle<art::TFileService>
tfs;
193 hADC[tagger] = tfs->make<TH1D>(Form(
"ADC_%s", tagger.c_str()),
"", 40, 0, 10000);
194 hNpe[tagger] = tfs->make<TH1D>(Form(
"Npe_%s", tagger.c_str()),
"", 40, 0, 300);
195 hNpeRatio[tagger] = tfs->make<TH1D>(Form(
"NpeRatio_%s", tagger.c_str()),
"", 40, 0, 10);
196 hTime[tagger] = tfs->make<TH1D>(Form(
"Time_%s", tagger.c_str()),
"", 40, -5000, 5000);
197 hStripDist[tagger] = tfs->make<TH1D>(Form(
"StripDist_%s", tagger.c_str()),
"", 40, 0, 450);
198 hSipmDist[tagger] = tfs->make<TH1D>(Form(
"SipmDist_%s", tagger.c_str()),
"", 40, 0, 11.2);
200 hEffSipmDistTotal[tagger] = tfs->make<TH1D>(Form(
"EffSipmDistTotal_%s", tagger.c_str()),
"", 20, 0, 11.2);
201 hEffSipmDistReco[tagger] = tfs->make<TH1D>(Form(
"EffSipmDistReco_%s", tagger.c_str()),
"", 20, 0, 11.2);
202 hEffStripDistTotal[tagger] = tfs->make<TH1D>(Form(
"EffStripDistTotal_%s", tagger.c_str()),
"", 20, 0, 450);
203 hEffStripDistReco[tagger] = tfs->make<TH1D>(Form(
"EffStripDistReco_%s", tagger.c_str()),
"", 20, 0, 450);
204 hEffEDepTotal[tagger] = tfs->make<TH1D>(Form(
"EffEdepTotal_%s", tagger.c_str()),
"", 20, 0, 0.01);
205 hEffEDepReco[tagger] = tfs->make<TH1D>(Form(
"EffEdepReco_%s", tagger.c_str()),
"", 20, 0, 0.01);
206 hEffLengthTotal[tagger] = tfs->make<TH1D>(Form(
"EffLengthTotal_%s", tagger.c_str()),
"", 20, 0, 10);
207 hEffLengthReco[tagger] = tfs->make<TH1D>(Form(
"EffLengthReco_%s", tagger.c_str()),
"", 20, 0, 10);
209 hStripDistADC[tagger] = tfs->make<TH2D>(Form(
"StripDistADC_%s", tagger.c_str()),
"", 20, 0, 450, 20, 0, 10000);
210 hSipmDistADC[tagger] = tfs->make<TH2D>(Form(
"SipmDistADC_%s", tagger.c_str()),
"", 20, 0, 11.2, 20, 0, 10000);
211 hStripDistNpe[tagger] = tfs->make<TH2D>(Form(
"StripDistNpe_%s", tagger.c_str()),
"", 20, 0, 450, 20, 0, 300);
212 hSipmDistNpe[tagger] = tfs->make<TH2D>(Form(
"SipmDistNpe_%s", tagger.c_str()),
"", 20, 0, 11.2, 20, 0, 300);
213 hSipmDistNpeRatio[tagger] = tfs->make<TH2D>(Form(
"SipmDistNpeRatio_%s", tagger.c_str()),
"", 20, 0, 11.2, 20, 0, 10);
218 std::cout<<
"----------------- Full CRT Detector Simulation Analysis Module -------------------"<<std::endl;
227 std::cout<<
"============================================"<<std::endl
228 <<
"Run = "<<
event.run()<<
", SubRun = "<<
event.subRun()<<
", Event = "<<
event.id().event()<<std::endl
229 <<
"============================================"<<std::endl;
238 art::ServiceHandle<cheat::ParticleInventoryService> pi_serv;
239 auto particleHandle =
event.getValidHandle<std::vector<simb::MCParticle>>(
fSimModuleLabel);
242 art::Handle< std::vector<sbnd::crt::CRTData>> crtDataHandle;
243 std::vector<art::Ptr<sbnd::crt::CRTData> > crtDataList;
245 art::fill_ptr_vector(crtDataList, crtDataHandle);
247 art::FindManyP<sim::AuxDetIDE> findManyIdes(crtDataHandle, event,
fCRTSimLabel);
250 art::Handle<std::vector<sim::AuxDetSimChannel> > channels;
257 std::map<int, simb::MCParticle> particles;
259 for (
auto const& particle: (*particleHandle)){
262 int partID = particle.TrackId();
263 particles[partID] = particle;
271 std::map<int, std::vector<sbnd::crt::CRTData>> crtData;
272 for(
size_t i = 0; i < crtDataList.size(); i++){
276 for(
auto const&
id : trueIDs){
277 crtData[id].push_back(*crtDataList[i]);
282 if(particles.find(trueID) == particles.end())
continue;
283 if(!(
std::abs(particles[trueID].PdgCode()) == 13 && particles[trueID].Mother() == 0))
continue;
286 std::vector<art::Ptr<sim::AuxDetIDE>> ides = findManyIdes.at(i);
288 double x = 0,
y = 0,
z = 0;
289 for(
auto const& ide : ides){
290 x += (ide->entryX + ide->exitX)/2.;
291 y += (ide->entryY + ide->exitY)/2.;
292 z += (ide->entryZ + ide->exitZ)/2.;
299 int channel = crtDataList[i]->Channel();
303 double npe = ((double)crtDataList[i]->ADC() -
fQPed)/
fQSlope;
308 hSipmDistADC[tagger]->Fill(sipmDist, crtDataList[i]->ADC());
311 if(channel % 2 == 0){
312 double npe1 = ((double)crtDataList[i+1]->ADC() -
fQPed)/
fQSlope;
320 hStripDistADC[tagger]->Fill(stripDist, crtDataList[i]->ADC());
323 hADC[tagger]->Fill(crtDataList[i]->ADC());
324 hNpe[tagger]->Fill(npe);
329 hTime[tagger]->Fill(time);
336 for (
auto& adsc : *channels) {
338 if(adsc.AuxDetSensitiveID() == UINT_MAX) {
339 mf::LogWarning(
"CRTDetSimAna") <<
"AuxDetSimChannel with ID: UINT_MAX\n"
340 <<
"skipping channel...";
346 std::vector<sim::AuxDetIDE> ides = adsc.AuxDetIDEs();
348 for(
auto const& ide : ides){
350 (ide.entryY + ide.exitY)/2,
351 (ide.entryZ + ide.exitZ)/2};
352 int trueID = ide.trackID;
354 double length = std::sqrt(std::pow(ide.entryX - ide.exitX, 2)
355 + std::pow(ide.entryY - ide.exitY, 2)
356 + std::pow(ide.entryZ - ide.exitZ, 2));
362 if(particles.find(trueID) == particles.end())
continue;
363 if(!(
std::abs(particles[trueID].PdgCode()) == 13 && particles[trueID].Mother() == 0))
continue;
372 if(crtData.find(trueID) == crtData.end())
continue;
375 for(
auto const& data : crtData[trueID]){
377 if(stripName == stripNameData) match =
true;
art::EDAnalyzer::Table< Config > Parameters
process_name opflash particleana ie ie ie z
fhicl::Atom< double > QSlope
std::vector< int > AllTrueIds(const art::Event &event, const sbnd::crt::CRTData &data)
Utilities related to art service access.
process_name opflash particleana ie x
std::map< std::string, TH1D * > hEffStripDistReco
std::map< std::string, TH1D * > hSipmDist
CRTTaggerGeo GetTagger(std::string taggerName) const
CRTBackTracker fCrtBackTrack
std::map< std::string, TH1D * > hEffStripDistTotal
fhicl::Atom< art::InputTag > SimModuleLabel
fhicl::Atom< double > QPed
std::map< std::string, TH1D * > hEffLengthTotal
art::InputTag fCRTSimLabel
name of CRT producer
bool fVerbose
print information about what's going on
fhicl::Atom< art::InputTag > CRTSimLabel
std::map< std::string, TH1D * > hNpe
int TrueIdFromTotalEnergy(const art::Event &event, const sbnd::crt::CRTData &data)
art::InputTag fSimModuleLabel
name of MCParticle producer in g4
fhicl::Table< CRTBackTracker::Config > CrtBackTrack
CRTDetSimAna(Parameters const &config)
virtual void beginJob() override
Access the description of detector geometry.
object containing MC truth information necessary for making RawDigits and doing back tracking ...
process_name opflash particleana ie ie y
virtual void analyze(const art::Event &event) override
std::string ChannelToStripName(size_t channel) const
art framework interface to geometry description for auxiliary detectors
double DistanceDownStrip(geo::Point_t position, std::string stripName) const
BEGIN_PROLOG vertical distance to the surface Name
CRTStripGeo GetStrip(std::string stripName) const
std::map< std::string, TH2D * > hSipmDistNpeRatio
fhicl::Atom< double > ClockSpeedCRT
size_t NumTaggers() const
Description of geometry of one entire detector.
Definition of data types for geometry description.
std::string GetTaggerName(std::string name) const
std::map< std::string, TH1D * > hNpeRatio
fhicl::Atom< art::InputTag > SimChannelModuleLabel
std::map< std::string, TH2D * > hSipmDistNpe
std::map< std::string, TH1D * > hADC
std::map< std::string, TH1D * > hEffSipmDistReco
virtual void endJob() override
std::map< std::string, TH1D * > hEffEDepTotal
fhicl::Atom< bool > Verbose
std::map< std::string, TH2D * > hSipmDistADC
stream1 can override from command line with o or output services user sbnd
std::map< std::string, TH1D * > hEffEDepReco
art::ServiceHandle< art::TFileService > tfs
std::map< std::string, TH2D * > hStripDistADC
std::map< std::string, TH1D * > hStripDist
art::InputTag fSimChannelModuleLabel
name of SimChannel producer in g4
Vector cross(Vector const &a, Vector const &b)
Return cross product of two vectors.
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
std::map< std::string, TH1D * > hTime
std::map< std::string, TH1D * > hEffLengthReco
std::map< std::string, TH1D * > hEffSipmDistTotal
std::map< std::string, TH2D * > hStripDistNpe
art framework interface to geometry description
BEGIN_PROLOG could also be cout
geo::GeometryCore const * fGeometryService
double DistanceBetweenSipms(geo::Point_t position, size_t channel) const