CosmicsGen_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file CosmicsGen_plugin.cc
3 /// \brief Generator for cosmic-rays
4 ///
5 /// Module to produce cosmic ray MC using CRY
6 ///
7 /// \version $Id: CosmicsGen.cxx,v 1.5 2010/04/23 18:37:36 brebel Exp $
8 /// \author brebel@fnal.gov
9 ////////////////////////////////////////////////////////////////////////
10 #ifndef EVGEN_COSMICSGEN_H
11 #define EVGEN_COSMICSGEN_H
12 
13 // ROOT includes
14 #include "TRandom3.h"
15 #include "TH1.h"
16 #include "TH2.h"
17 
18 // Framework includes
22 #include "fhiclcpp/ParameterSet.h"
26 #include "art_root_io/TFileService.h"
27 #include "art_root_io/TFileDirectory.h"
30 
35 #include "nurandom/RandomUtils/NuRandomService.h"
36 
37 // garsoft includes
38 #include "Geometry/GeometryGAr.h"
40 #include "CoreUtils/ServiceUtil.h"
41 
42 namespace gar{
43  namespace evgen {
44 
45  /// A module to check the results from the Monte Carlo generator
46  class CosmicsGen : public ::art::EDProducer {
47  public:
48  explicit CosmicsGen(fhicl::ParameterSet const& pset);
49  virtual ~CosmicsGen();
50 
51 
52  void produce(::art::Event& evt);
53  void beginJob();
54  void beginRun(::art::Run& run);
55  void reconfigure(fhicl::ParameterSet const& p);
56 
57  private:
58 
59  evgb::CRYHelper* fCRYHelp; ///< CRY generator object
60 
61  std::vector<double> fbuffbox;
62 
63  TH2F* fPhotonAngles; ///< Photon rate vs angle
64  TH2F* fPhotonAnglesLo; ///< Photon rate vs angle, low momenta
65  TH2F* fPhotonAnglesMi; ///< Photon rate vs angle, middle momenta
66  TH2F* fPhotonAnglesHi; ///< Photon rate vs angle, high momenta
67  TH1F* fPhotonCosQ; ///< Photon rate vs cos(Q)
68  TH1F* fPhotonEnergy; ///< Photon energy (GeV)
69  TH1F* fPhotonsPerSample; ///< number of photons in the sampled time window
70  TH1F* fPhotonsInTPC; ///< number of photons in the tpc during
71  ///< the sampled time window
72 
73  TH2F* fElectronAngles; ///< Electron rate vs angle
74  TH2F* fElectronAnglesLo; ///< Electron rate vs angle, low momenta
75  TH2F* fElectronAnglesMi; ///< Electron rate vs angle, middle momenta
76  TH2F* fElectronAnglesHi; ///< Electron rate vs angle, high momenta
77  TH1F* fElectronCosQ; ///< Electron rate vs cos(Q)
78  TH1F* fElectronEnergy; ///< Electron energy (GeV)
79  TH1F* fElectronsPerSample; ///< number of electrons in the sampled time window
80  TH1F* fElectronsInTPC; ///< number of electrons in the tpc during
81  ///< the sampled time window
82 
83  TH2F* fMuonAngles; ///< Muon rate vs angle
84  TH2F* fMuonAnglesLo; ///< Muon rate vs angle, low momenta
85  TH2F* fMuonAnglesMi; ///< Muon rate vs angle, middle momenta
86  TH2F* fMuonAnglesHi; ///< Muon rate vs angle, high momenta
87  TH1F* fMuonCosQ; ///< Muon rate vs cos(Q)
88  TH1F* fMuonEnergy; ///< Muon energy (GeV)
89  TH1F* fMuonsPerSample; ///< number of muons in the sampled time window
90  TH1F* fMuonsInTPC; ///< number of muons in the tpc during
91  ///< the sampled time window
92 
93  rndm::NuRandomService::seed_t fSeed; ///< override seed with a fcl parameter not equal to zero
94 
95  };
96  }
97 
98  namespace evgen{
99 
100  //____________________________________________________________________________
102  art::EDProducer{pset}, fCRYHelp(0)
103  {
104 
105  //the buffer box bounds specified here will extend on the cryostat boundaries
106  fbuffbox = pset.get< std::vector<double> >("BufferBox",{0.0, 0.0, 0.0, 0.0, 0.0, 0.0});
107  fSeed = pset.get< rndm::NuRandomService::seed_t >("Seed",0);
108  this->reconfigure(pset);
109 
110  produces< std::vector<simb::MCTruth> >();
111  produces< gar::sumdata::RunData, ::art::InRun >();
112  }
113 
114  //____________________________________________________________________________
116  {
117  if(fCRYHelp) delete fCRYHelp;
118  }
119 
120  //____________________________________________________________________________
122  {
123  if(fCRYHelp){
124  delete fCRYHelp;
125  fCRYHelp = 0;
126  }
127 
128  CLHEP::HepRandomEngine &engine = art::ServiceHandle<rndm::NuRandomService>()->createEngine(*this,p,"Seed");
129 
130  auto geo = gar::providerFrom<gar::geo::GeometryGAr>();
131 
132  fCRYHelp = new evgb::CRYHelper(p, engine, geo->GetWorldVolumeName());
133 
134  return;
135  }
136 
137  //____________________________________________________________________________
139  {
141 
142  fPhotonAngles = tfs->make<TH2F>("fPhotonAngles", ";#phi;cos#theta", 36,-180.0,180.0,50,-1.0,1.0);
143  fPhotonAnglesLo = tfs->make<TH2F>("fPhotonAnglesLo", ";#phi;cos#theta", 36,-180.0,180.0,50,-1.0,1.0);
144  fPhotonAnglesMi = tfs->make<TH2F>("fPhotonAnglesMi", ";#phi;cos#theta", 36,-180.0,180.0,50,-1.0,1.0);
145  fPhotonAnglesHi = tfs->make<TH2F>("fPhotonAnglesHi", ";#phi;cos#theta", 36,-180.0,180.0,50,-1.0,1.0);
146  fPhotonCosQ = tfs->make<TH1F>("fPhotonCosQ", ";cos#theta;tracks", 50,-1.0,1.0);
147  fPhotonEnergy = tfs->make<TH1F>("fPhotonEnergy", ";E (GeV)", 5000,0.0,1000.0);
148  fPhotonsPerSample = tfs->make<TH1F>("fPhotonsPerSample", ";Number Photons;Samples", 100, 0, 1000);
149  fPhotonsInTPC = tfs->make<TH1F>("fPhotonsInTPC", ";Number Photons;Samples", 100, 0, 1000);
150 
151  fElectronAngles = tfs->make<TH2F>("fElectronAngles", ";#phi;cos#theta", 36,-180.0,180.0,50,-1.0,1.0);
152  fElectronAnglesLo = tfs->make<TH2F>("fElectronAnglesLo", ";#phi;cos#theta", 36,-180.0,180.0,50,-1.0,1.0);
153  fElectronAnglesMi = tfs->make<TH2F>("fElectronAnglesMi", ";#phi;cos#theta", 36,-180.0,180.0,50,-1.0,1.0);
154  fElectronAnglesHi = tfs->make<TH2F>("fElectronAnglesHi", ";#phi;cos#theta", 36,-180.0,180.0,50,-1.0,1.0);
155  fElectronCosQ = tfs->make<TH1F>("fElectronCosQ", ";cos#theta;tracks", 50,-1.0,1.0);
156  fElectronEnergy = tfs->make<TH1F>("fElectronEnergy", ";E (GeV)", 5000,0.0,1000.0);
157  fElectronsPerSample = tfs->make<TH1F>("fElectronsPerSample", ";Number Electrons;Samples", 100, 0, 1000);
158  fElectronsInTPC = tfs->make<TH1F>("fElectronsInTPC", ";Number Electrons;Samples", 100, 0, 1000);
159 
160  fMuonAngles = tfs->make<TH2F>("fMuonAngles", ";#phi;cos#theta", 36,-180.0,180.0,50,-1.0,1.0);
161  fMuonAnglesLo = tfs->make<TH2F>("fMuonAnglesLo", ";#phi;cos#theta", 36,-180.0,180.0,50,-1.0,1.0);
162  fMuonAnglesMi = tfs->make<TH2F>("fMuonAnglesMi", ";#phi;cos#theta", 36,-180.0,180.0,50,-1.0,1.0);
163  fMuonAnglesHi = tfs->make<TH2F>("fMuonAnglesHi", ";#phi;cos#theta", 36,-180.0,180.0,50,-1.0,1.0);
164  fMuonCosQ = tfs->make<TH1F>("fMuonCosQ", ";cos#theta;tracks", 50,-1.0,1.0);
165  fMuonEnergy = tfs->make<TH1F>("fMuonEnergy", ";E (GeV)", 5000,0.0,1000.0);
166  fMuonsPerSample = tfs->make<TH1F>("fMuonsPerSample", ";Number Muons;Samples", 100, 0, 1000);
167  fMuonsInTPC = tfs->make<TH1F>("fMuonsInTPC", ";Number Muons;Samples", 100, 0, 1000);
168 
169  }
170 
171  //____________________________________________________________________________
173  {
174  // grab the geometry object to see what geometry we are using
175  auto geo = gar::providerFrom<geo::GeometryGAr>();
176 
177  std::unique_ptr<gar::sumdata::RunData> runcol(new gar::sumdata::RunData(geo->DetectorName()));
178 
179  run.put(std::move(runcol));
180 
181  return;
182  }
183 
184  //____________________________________________________________________________
186  {
187  std::unique_ptr< std::vector<simb::MCTruth> > truthcol(new std::vector<simb::MCTruth>);
188 
189  // fill some histograms about this event
190  auto geom = gar::providerFrom<geo::GeometryGAr>();
191 
192  // int nCrossCryostat = 0; // no cryostat here.
193 
194  simb::MCTruth truth;
195 
196  // don't need to have a particle on every event
197 
198  //while(nCrossCryostat < 1){
199 
200  simb::MCTruth pretruth;
202  //std::cout << " calling CRY Helper: " << geom->SurfaceY() << " " << geom->TPCLength() << std::endl;
203  fCRYHelp->Sample(pretruth,
204  geom->SurfaceY(),
205  geom->TPCLength(),
206  0);
207 
208  int numPhotons = 0;
209  int numElectrons = 0;
210  int numMuons = 0;
211  int allPhotons = 0;
212  int allElectrons = 0;
213  int allMuons = 0;
214 
215  // loop over particles in the truth object
216  for(int i = 0; i < pretruth.NParticles(); ++i){
217  simb::MCParticle particle = pretruth.GetParticle(i);
218  const TLorentzVector& p4 = particle.Momentum();
219 
220  if (std::abs(particle.PdgCode())==13) ++allMuons;
221  else if (std::abs(particle.PdgCode())==22) ++allPhotons;
222  else if (std::abs(particle.PdgCode())==11) ++allElectrons;
223 
224  TH1F* hCosQ = 0;
225  TH2F* hAngles = 0;
226  TH2F* hAnglesLo = 0;
227  TH2F* hAnglesMi = 0;
228  TH2F* hAnglesHi = 0;
229  TH1F* hEnergy = 0;
230  if (std::abs(particle.PdgCode())==13) {
231  hCosQ = fMuonCosQ;
232  hAngles = fMuonAngles;
233  hAnglesLo = fMuonAnglesLo;
234  hAnglesMi = fMuonAnglesMi;
235  hAnglesHi = fMuonAnglesHi;
236  hEnergy = fMuonEnergy;
237  }
238  else if (std::abs(particle.PdgCode())==22) {
239  hCosQ = fPhotonCosQ;
240  hAngles = fPhotonAngles;
241  hAnglesLo = fPhotonAnglesLo;
242  hAnglesMi = fPhotonAnglesMi;
243  hAnglesHi = fPhotonAnglesHi;
244  hEnergy = fPhotonEnergy;
245  }
246  else if (std::abs(particle.PdgCode())==11) {
247  hCosQ = fElectronCosQ;
248  hAngles = fElectronAngles;
249  hAnglesLo = fElectronAnglesLo;
250  hAnglesMi = fElectronAnglesMi;
251  hAnglesHi = fElectronAnglesHi;
252  hEnergy = fElectronEnergy;
253  }
254 
255  // TODO: check if the particle goes through the detector, if it does
256  // add it to the list
257 
258  truth.Add(particle);
259 
260  if (std::abs(particle.PdgCode())==13) ++numMuons;
261  else if (std::abs(particle.PdgCode())==22) ++numPhotons;
262  else if (std::abs(particle.PdgCode())==11) ++numElectrons;
263 
264  if (hCosQ!=0) {
265  double cosq = -p4.Py()/p4.P();
266  double phi = std::atan2(p4.Pz(),p4.Px());
267  phi *= 180/M_PI;
268  hCosQ->Fill(cosq);
269  hAngles->Fill(phi,cosq);
270  if (p4.E()<1.0) hAnglesLo->Fill(phi,cosq);
271  else if (p4.E()<10.0) hAnglesMi->Fill(phi,cosq);
272  else hAnglesHi->Fill(phi,cosq);
273  hEnergy->Fill(p4.E());
274  }//end if there is a cos(theta) histogram
275 
276  }// loop on particles
277 
278  //}
279 
280  truthcol->push_back(truth);
281  evt.put(std::move(truthcol));
282 
283  return;
284  }// end produce
285 
286  }// end namespace
287 
288 
289  namespace evgen{
290 
292 
293  }
294 } // namespace gar
295 
296 #endif // EVGEN_COSMICSGEN_H
297 ////////////////////////////////////////////////////////////////////////
rndm::NuRandomService::seed_t fSeed
override seed with a fcl parameter not equal to zero
base_engine_t & createEngine(seed_t seed)
TH2F * fMuonAngles
Muon rate vs angle.
Interface to the CRY cosmic-ray generator.
Definition: CRYHelper.h:26
TH1F * fElectronsPerSample
number of electrons in the sampled time window
int PdgCode() const
Definition: MCParticle.h:212
TH2F * fMuonAnglesHi
Muon rate vs angle, high momenta.
A module to check the results from the Monte Carlo generator.
TH1F * fPhotonCosQ
Photon rate vs cos(Q)
evgb::CRYHelper * fCRYHelp
CRY generator object.
void SetOrigin(simb::Origin_t origin)
Definition: MCTruth.h:82
TH2F * fElectronAnglesLo
Electron rate vs angle, low momenta.
TH1F * fPhotonsPerSample
number of photons in the sampled time window
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
TH2F * fPhotonAngles
Photon rate vs angle.
TH1F * fElectronCosQ
Electron rate vs cos(Q)
int NParticles() const
Definition: MCTruth.h:75
Particle class.
TH2F * fElectronAnglesHi
Electron rate vs angle, high momenta.
Definition: Run.h:17
TH2F * fMuonAnglesMi
Muon rate vs angle, middle momenta.
T abs(T value)
void beginRun(::art::Run &run)
double Sample(simb::MCTruth &mctruth, double const &surfaceY, double const &detectorLength, double *w, double rantime=0)
Definition: CRYHelper.cxx:97
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
TH2F * fElectronAngles
Electron rate vs angle.
TH1F * fMuonCosQ
Muon rate vs cos(Q)
Interface to the CRY cosmic ray generator.
def move(depos, offset)
Definition: depos.py:107
TH2F * fPhotonAnglesLo
Photon rate vs angle, low momenta.
p
Definition: test.py:223
TH2F * fMuonAnglesLo
Muon rate vs angle, low momenta.
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
void reconfigure(fhicl::ParameterSet const &p)
TH2F * fPhotonAnglesHi
Photon rate vs angle, high momenta.
const simb::MCParticle & GetParticle(int i) const
Definition: MCTruth.h:76
#define M_PI
Definition: includeROOT.h:54
TH1F * fElectronEnergy
Electron energy (GeV)
General GArSoft Utilities.
TH1F * fPhotonEnergy
Photon energy (GeV)
TH2F * fPhotonAnglesMi
Photon rate vs angle, middle momenta.
std::vector< double > fbuffbox
const TLorentzVector & Momentum(const int i=0) const
Definition: MCParticle.h:220
void produce(::art::Event &evt)
TH1F * fMuonsPerSample
number of muons in the sampled time window
CosmicsGen(fhicl::ParameterSet const &pset)
TH2F * fElectronAnglesMi
Electron rate vs angle, middle momenta.
TCEvent evt
Definition: DataStructs.cxx:7
Event generator information.
Definition: MCTruth.h:32
LArSoft geometry interface.
Definition: ChannelGeo.h:16
art framework interface to geometry description
Event Generation using GENIE, cosmics or single particles.
TH1F * fMuonEnergy
Muon energy (GeV)
Cosmic rays.
Definition: MCTruth.h:24