15 #include "art/Framework/Core/EDProducer.h"
16 #include "art/Framework/Core/ModuleMacros.h"
17 #include "art/Framework/Principal/Event.h"
18 #include "art/Framework/Principal/Run.h"
19 #include "fhiclcpp/ParameterSet.h"
20 #include "art/Framework/Services/Registry/ServiceHandle.h"
21 #include "art_root_io/TFileService.h"
24 #include "nurandom/RandomUtils/NuRandomService.h"
27 #include "nusimdata/SimulationBase/MCTruth.h"
28 #include "nusimdata/SimulationBase/MCParticle.h"
29 #include "nugen/EventGeneratorBase/evgenbase.h"
30 #include "nutools/EventGeneratorBase/CRY/CRYHelper.h"
39 explicit CosmicsGen(fhicl::ParameterSet
const& pset);
45 void beginRun(art::Run& run)
override;
93 : art::EDProducer{pset}
94 , fbuffbox{pset.get<std::vector<double>>(
"BufferBox",{0.0, 0.0, 0.0, 0.0, 0.0, 0.0})}
97 ,
fEngine(art::ServiceHandle<rndm::NuRandomService>()->createEngine(*
this, pset,
"Seed"))
100 art::ServiceHandle<geo::Geometry const>{}->GetWorldVolumeName()}
102 produces< std::vector<simb::MCTruth> >();
109 art::ServiceHandle<art::TFileService const>
tfs;
111 fPhotonAngles = tfs->make<TH2F>(
"fPhotonAngles",
";#phi;cos#theta", 36,-180.0,180.0,50,-1.0,1.0);
112 fPhotonAnglesLo =
tfs->make<TH2F>(
"fPhotonAnglesLo",
";#phi;cos#theta", 36,-180.0,180.0,50,-1.0,1.0);
113 fPhotonAnglesMi =
tfs->make<TH2F>(
"fPhotonAnglesMi",
";#phi;cos#theta", 36,-180.0,180.0,50,-1.0,1.0);
114 fPhotonAnglesHi =
tfs->make<TH2F>(
"fPhotonAnglesHi",
";#phi;cos#theta", 36,-180.0,180.0,50,-1.0,1.0);
115 fPhotonCosQ =
tfs->make<TH1F>(
"fPhotonCosQ",
";cos#theta;tracks", 50,-1.0,1.0);
116 fPhotonEnergy =
tfs->make<TH1F>(
"fPhotonEnergy",
";E (GeV)", 5000,0.0,1000.0);
117 fPhotonsPerSample =
tfs->make<TH1F>(
"fPhotonsPerSample",
";Number Photons;Samples", 100, 0, 1000);
118 fPhotonsInCStat =
tfs->make<TH1F>(
"fPhotonsInCryostat",
";Number Photons;Samples", 100, 0, 1000);
119 fPhotonsInTPC =
tfs->make<TH1F>(
"fPhotonsInTPC",
";Number Photons;Samples", 100, 0, 1000);
121 fElectronAngles =
tfs->make<TH2F>(
"fElectronAngles",
";#phi;cos#theta",36,-180.0,180.0,50,-1.0,1.0);
122 fElectronAnglesLo =
tfs->make<TH2F>(
"fElectronAnglesLo",
";#phi;cos#theta",36,-180.0,180.0,50,-1.0,1.0);
123 fElectronAnglesMi =
tfs->make<TH2F>(
"fElectronAnglesMi",
";#phi;cos#theta",36,-180.0,180.0,50,-1.0,1.0);
124 fElectronAnglesHi =
tfs->make<TH2F>(
"fElectronAnglesHi",
";#phi;cos#theta",36,-180.0,180.0,50,-1.0,1.0);
125 fElectronCosQ =
tfs->make<TH1F>(
"fElectronCosQ",
";cos#theta;tracks",50,-1.0,1.0);
128 fElectronsInCStat =
tfs->make<TH1F>(
"fElectronsInCryotat",
";Number Electrons;Samples", 100, 0, 1000);
129 fElectronsInTPC =
tfs->make<TH1F>(
"fElectronsInTPC",
";Number Electrons;Samples", 100, 0, 1000);
131 fMuonAngles =
tfs->make<TH2F>(
"fMuonAngles",
";#phi;cos#theta", 36,-180.0,180.0,50,-1.0,1.0);
132 fMuonAnglesLo =
tfs->make<TH2F>(
"fMuonAnglesLo",
";#phi;cos#theta", 36,-180.0,180.0,50,-1.0,1.0);
133 fMuonAnglesMi =
tfs->make<TH2F>(
"fMuonAnglesMi",
";#phi;cos#theta", 36,-180.0,180.0,50,-1.0,1.0);
134 fMuonAnglesHi =
tfs->make<TH2F>(
"fMuonAnglesHi",
";#phi;cos#theta", 36,-180.0,180.0,50,-1.0,1.0);
135 fMuonCosQ =
tfs->make<TH1F>(
"fMuonCosQ",
";cos#theta;tracks",50,-1.0,1.0);
136 fMuonEnergy =
tfs->make<TH1F>(
"fMuonEnergy",
";E (GeV)", 5000,0.0,1000.0);
137 fMuonsPerSample =
tfs->make<TH1F>(
"fMuonsPerSample",
";Number Muons;Samples", 100, 0, 1000);
138 fMuonsInCStat =
tfs->make<TH1F>(
"fMuonsInCryostat",
";Number Muons;Samples", 100, 0, 1000);
139 fMuonsInTPC =
tfs->make<TH1F>(
"fMuonsInTPC",
";Number Muons;Samples", 100, 0, 1000);
145 art::ServiceHandle<geo::Geometry const> geo;
146 run.put(std::make_unique<sumdata::RunData>(geo->DetectorName()));
152 std::unique_ptr< std::vector<simb::MCTruth> > truthcol(
new std::vector<simb::MCTruth>);
155 art::ServiceHandle<geo::Geometry const> geom;
157 int nCrossCryostat = 0;
161 while(nCrossCryostat < 1){
163 simb::MCTruth pretruth;
171 int numElectrons = 0;
174 int allElectrons = 0;
178 for(
int i = 0; i < pretruth.NParticles(); ++i){
179 simb::MCParticle particle = pretruth.GetParticle(i);
180 const TLorentzVector& v4 = particle.Position();
181 const TLorentzVector& p4 = particle.Momentum();
182 double x0[3] = {v4.X(), v4.Y(), v4.Z() };
183 double dx[3] = {p4.Px(), p4.Py(), p4.Pz()};
185 if (
std::abs(particle.PdgCode())==13) ++allMuons;
186 else if (
std::abs(particle.PdgCode())==22) ++allPhotons;
187 else if (
std::abs(particle.PdgCode())==11) ++allElectrons;
195 if (
std::abs(particle.PdgCode())==13) {
203 else if (
std::abs(particle.PdgCode())==22) {
211 else if (
std::abs(particle.PdgCode())==11) {
222 for(
unsigned int c = 0; c < geom->Ncryostats(); ++c){
224 double bounds[6] = {0.};
225 geom->CryostatBoundaries(bounds, c);
231 for (
unsigned int cb=0; cb<6; cb++)
232 bounds[cb] = bounds[cb]+
fbuffbox[cb];
235 bool intersects_cryo =
false;
236 for (
int bnd=0; bnd!=6; ++bnd) {
238 double p2[3] = {bounds[bnd], x0[1] + (dx[1]/dx[0])*(bounds[bnd] - x0[0]), x0[2] + (dx[2]/dx[0])*(bounds[bnd] - x0[0])};
239 if ( p2[1] >= bounds[2] && p2[1] <= bounds[3] &&
240 p2[2] >= bounds[4] && p2[2] <= bounds[5] ) {
241 intersects_cryo =
true;
245 else if (bnd>=2 && bnd<4) {
246 double p2[3] = {x0[0] + (dx[0]/dx[1])*(bounds[bnd] - x0[1]), bounds[bnd], x0[2] + (dx[2]/dx[1])*(bounds[bnd] - x0[1])};
247 if ( p2[0] >= bounds[0] && p2[0] <= bounds[1] &&
248 p2[2] >= bounds[4] && p2[2] <= bounds[5] ) {
249 intersects_cryo =
true;
254 double p2[3] = {x0[0] + (dx[0]/dx[2])*(bounds[bnd] - x0[2]), x0[1] + (dx[1]/dx[2])*(bounds[bnd] - x0[2]), bounds[bnd]};
255 if ( p2[0] >= bounds[0] && p2[0] <= bounds[1] &&
256 p2[1] >= bounds[2] && p2[1] <= bounds[3] ) {
257 intersects_cryo =
true;
264 if (intersects_cryo) {
267 if (
std::abs(particle.PdgCode())==13) ++numMuons;
268 else if (
std::abs(particle.PdgCode())==22) ++numPhotons;
269 else if (
std::abs(particle.PdgCode())==11) ++numElectrons;
287 double cosq = -p4.Py()/p4.P();
288 double phi = std::atan2(p4.Pz(),p4.Px());
291 hAngles->Fill(phi,cosq);
292 if (p4.E()<1.0) hAnglesLo->Fill(phi,cosq);
293 else if (p4.E()<10.0) hAnglesMi->Fill(phi,cosq);
294 else hAnglesHi->Fill(phi,cosq);
295 hEnergy->Fill(p4.E());
303 nCrossCryostat = truth.NParticles();
318 truthcol->push_back(truth);
319 evt.put(std::move(truthcol));
327 DEFINE_ART_MODULE(CosmicsGen)
TH2F * fElectronAnglesHi
Electron rate vs angle, high momenta.
TH2F * fPhotonAngles
Photon rate vs angle.
TH2F * fMuonAnglesHi
Muon rate vs angle, high momenta.
TH1F * fElectronEnergy
Electron energy (GeV)
TH2F * fElectronAnglesLo
Electron rate vs angle, low momenta.
TH2F * fElectronAngles
Electron rate vs angle.
TH1F * fElectronCosQ
Electron rate vs cos(Q)
TH2F * fMuonAngles
Muon rate vs angle.
TH2F * fMuonAnglesLo
Muon rate vs angle, low momenta.
TH1F * fPhotonEnergy
Photon energy (GeV)
produces< sumdata::RunData, art::InRun >()
TH2F * fElectronAnglesMi
Electron rate vs angle, middle momenta.
void produce(art::Event &evt) override
TH1F * fMuonCosQ
Muon rate vs cos(Q)
TH1F * fElectronsPerSample
number of electrons in the sampled time window
CosmicsGen(fhicl::ParameterSet const &pset)
TH1F * fPhotonsPerSample
number of photons in the sampled time window
fEngine(art::ServiceHandle< rndm::NuRandomService >() ->createEngine(*this, pset,"Seed"))
TH1F * fPhotonCosQ
Photon rate vs cos(Q)
CLHEP::HepRandomEngine & fEngine
art-managed random-number engine
void beginRun(art::Run &run) override
evgb::CRYHelper fCRYHelp
CRY generator object.
TH2F * fMuonAnglesMi
Muon rate vs angle, middle momenta.
std::vector< double > fbuffbox
TH2F * fPhotonAnglesMi
Photon rate vs angle, middle momenta.
TH2F * fPhotonAnglesLo
Photon rate vs angle, low momenta.
TH2F * fPhotonAnglesHi
Photon rate vs angle, high momenta.
A module to check the results from the Monte Carlo generator.
art::ServiceHandle< art::TFileService > tfs
TH1F * fMuonsPerSample
number of muons in the sampled time window
TH1F * fMuonEnergy
Muon energy (GeV)
art framework interface to geometry description