Public Member Functions | Private Member Functions | Private Attributes | List of all members
evgen::FileMuons Class Reference

module to produce single or multiple specified particles in the detector More...

Inheritance diagram for evgen::FileMuons:
art::EDProducer art::detail::Producer art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Public Member Functions

 FileMuons (fhicl::ParameterSet const &pset)
 
void produce (art::Event &evt)
 
void beginJob ()
 
void beginRun (art::Run &run)
 
void endJob ()
 
- Public Member Functions inherited from art::EDProducer
 EDProducer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDProducer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Producer
virtual ~Producer () noexcept
 
 Producer (fhicl::ParameterSet const &)
 
 Producer (Producer const &)=delete
 
 Producer (Producer &&)=delete
 
Produceroperator= (Producer const &)=delete
 
Produceroperator= (Producer &&)=delete
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Modifier
 ~Modifier () noexcept
 
 Modifier ()
 
 Modifier (Modifier const &)=delete
 
 Modifier (Modifier &&)=delete
 
Modifieroperator= (Modifier const &)=delete
 
Modifieroperator= (Modifier &&)=delete
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Member Functions

void ReadEvents (simb::MCTruth &mct)
 

Private Attributes

int fEventNumberOffset
 
std::vector< int > fPDG
 
std::vector< double > fXYZ_Off
 
std::string fFileName
 
std::string fMuonsFileType
 
std::string fTreeName
 
std::vector< std::stringfBranchNames
 
std::ifstream * fMuonFile
 
TFile * fMuonFileR
 
TTree * TNtuple
 
unsigned int countFile
 
Float_t xtmp
 
Float_t ytmp
 
Float_t ztmp
 
Float_t pxtmp
 
Float_t pytmp
 
Float_t pztmp
 
Float_t charge
 
Float_t E
 
Float_t costheta
 
Float_t phi
 
Float_t xdet
 
Float_t ydet
 
Float_t zdet
 
TBranch * b_x
 
TBranch * b_y
 
TBranch * b_z
 
TBranch * b_E
 
TBranch * b_costheta
 
TBranch * b_phi
 
TBranch * b_xdet
 
TBranch * b_ydet
 
TBranch * b_zdet
 
TBranch * b_px
 
TBranch * b_py
 
TBranch * b_pz
 
TBranch * b_charge
 

Additional Inherited Members

- Public Types inherited from art::EDProducer
using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
- Public Types inherited from art::detail::Producer
template<typename UserConfig , typename KeysToIgnore = void>
using Table = Modifier::Table< UserConfig, KeysToIgnore >
 
- Public Types inherited from art::Modifier
template<typename UserConfig , typename UserKeysToIgnore = void>
using Table = ProducerTable< UserConfig, detail::ModuleConfig, UserKeysToIgnore >
 
- Static Public Member Functions inherited from art::EDProducer
static void commitEvent (EventPrincipal &ep, Event &e)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

module to produce single or multiple specified particles in the detector

Definition at line 44 of file FileMuons_module.cc.

Constructor & Destructor Documentation

evgen::FileMuons::FileMuons ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 105 of file FileMuons_module.cc.

106  : EDProducer{pset}
107  , fEventNumberOffset(pset.get< int >("EventNumberOffset"))
108  , fPDG (pset.get< std::vector<int> >("PDG") )
109  , fXYZ_Off (pset.get< std::vector<double> >("InitialXYZOffsets"))
110  , fFileName (pset.get< std::string >("FileName") )
111  , fMuonsFileType (pset.get< std::string >("MuonsFileType") )
112  , fTreeName (pset.get< std::string >("TreeName") )
113  , fBranchNames (pset.get< std::vector<std::string> >("BranchNames") )
114  {
115 
116  produces< std::vector<simb::MCTruth> >();
117  produces< sumdata::RunData, art::InRun >();
118 
119  }
std::vector< double > fXYZ_Off
std::string string
Definition: nybbler.cc:12
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
std::string fMuonsFileType
std::vector< std::string > fBranchNames
std::string fFileName
std::vector< int > fPDG
std::string fTreeName

Member Function Documentation

void evgen::FileMuons::beginJob ( )
virtual

Reimplemented from art::EDProducer.

Definition at line 122 of file FileMuons_module.cc.

123  {
125  mf::LogInfo("FileMuons : starting at event ") << countFile <<std::endl;
126 
127  if (fMuonsFileType.compare("source")==0)
128  {
129  std::cout << "FileMuons: Not yet equipped to walk through muons with TFS mojo."<< std::endl;
130  }
131  else if (fMuonsFileType.compare("root")==0)
132  {
133  std::cout << "FileMuons: You have chosen to read muons from Root File " << fFileName << std::endl;
134  }
135  else if (fMuonsFileType.compare("text")==0)
136  {
137  std::cout << "FileMuons: You have chosen to read muons from " << fFileName << "." << std::endl;
138  }
139  else
140  {
141  std::cout << "FileMuons: You must specify one of source/text/root file to read for muons."<< std::endl;
142 
143  }
144 
145  if (fMuonsFileType.compare("text")==0)
146  {
147  fMuonFile = new std::ifstream(fFileName.c_str());
148  long begin = fMuonFile->tellg();
149  fMuonFile->seekg (0, std::ios::end);
150  long end = fMuonFile->tellg();
151  std::cout << "FileMuons: " << fFileName << " size is: " << (end-begin) << " bytes.\n";
152  fMuonFile->seekg (0, std::ios::beg);
153 
154  for (unsigned int header=0; header<3 && fMuonFile->good(); ++header)
155  {
157  getline(*fMuonFile,line);
158  }
159  if (!fMuonFile->good())
160  {
161  std::cout << "FileMuons: Problem reading muon file header."<< std::endl;
162  }
163  } // fMuonsFileType is a text file.
164  else if (fMuonsFileType.compare("root")==0)
165  {
166  fMuonFileR = new TFile(fFileName.c_str(),"READ");
167  TNtuple = (TTree*)(fMuonFileR->Get(fTreeName.c_str()));
168 
169  TNtuple->SetBranchAddress("x", &xtmp, &b_x);
170  TNtuple->SetBranchAddress("y", &ytmp, &b_y);
171  TNtuple->SetBranchAddress("z", &ztmp, &b_z);
172  TNtuple->SetBranchAddress("E", &E, &b_E);
173  TNtuple->SetBranchAddress("costheta", &costheta, &b_costheta);
174  TNtuple->SetBranchAddress("phi", &phi, &b_phi);
175  TNtuple->SetBranchAddress("xdet", &xdet, &b_xdet);
176  TNtuple->SetBranchAddress("ydet", &ydet, &b_ydet);
177  TNtuple->SetBranchAddress("zdet", &zdet, &b_zdet);
178  TNtuple->SetBranchAddress("px", &pxtmp, &b_px);
179  TNtuple->SetBranchAddress("py", &pytmp, &b_py);
180  TNtuple->SetBranchAddress("pz", &pztmp, &b_pz);
181  TNtuple->SetBranchAddress("charge", &charge, &b_charge);
182 
183  } // fMuonsFileType is a root file.
184 
185  }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
std::string string
Definition: nybbler.cc:12
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
std::string fMuonsFileType
std::ifstream * fMuonFile
unsigned int countFile
std::string fFileName
void line(double t, double *p, double &x, double &y, double &z)
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
std::string fTreeName
QTextStream & endl(QTextStream &s)
void evgen::FileMuons::beginRun ( art::Run run)
virtual

Reimplemented from art::EDProducer.

Definition at line 197 of file FileMuons_module.cc.

198  {
200  run.put(std::make_unique<sumdata::RunData>(geo->DetectorName()));
201  }
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
LArSoft geometry interface.
Definition: ChannelGeo.h:16
void evgen::FileMuons::endJob ( )
virtual

Reimplemented from art::EDProducer.

Definition at line 188 of file FileMuons_module.cc.

189  {
190  if (fMuonsFileType.compare("text")==0)
191  fMuonFile->close();
192  if (fMuonsFileType.compare("root")==0)
193  fMuonFileR->Close();
194  }
std::string fMuonsFileType
std::ifstream * fMuonFile
void evgen::FileMuons::produce ( art::Event evt)
virtual

unique_ptr allows ownership to be transferred to the art::Event after the put statement

Implements art::EDProducer.

Definition at line 204 of file FileMuons_module.cc.

205  {
206 
207  ///unique_ptr allows ownership to be transferred to the art::Event after the put statement
208  std::unique_ptr< std::vector<simb::MCTruth> > truthcol(new std::vector<simb::MCTruth>);
209 
210  simb::MCTruth truth;
212  ReadEvents(truth);
213 
214 // std::cout << "put mctruth into the vector" << std::endl;
215  truthcol->push_back(truth);
216 
217 // std::cout << "add vector to the event " << truthcol->size() << std::endl;
218  evt.put(std::move(truthcol));
219 
220  return;
221  }
void SetOrigin(simb::Origin_t origin)
Definition: MCTruth.h:82
void ReadEvents(simb::MCTruth &mct)
single particles thrown at the detector
Definition: MCTruth.h:26
def move(depos, offset)
Definition: depos.py:107
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
Event generator information.
Definition: MCTruth.h:32
void evgen::FileMuons::ReadEvents ( simb::MCTruth mct)
private

every event will have one of each particle species in the fPDG array

Definition at line 224 of file FileMuons_module.cc.

225  {
226 
227 // std::cout << "size of particle vector is " << fPDG.size() << std::endl;
228 
229  ///every event will have one of each particle species in the fPDG array
230  for (unsigned int i=0; i<fPDG.size(); ++i) {
231 
232  // Choose momentum
233  //double p = 0.0;
234  double m(0.108);
235 
236  TVector3 x;
237  TVector3 p;
238  Double_t q = 0.;
239  Int_t pdgLocal;
240 
241  if (fMuonsFileType.compare("text")==0)
242  {
243 
245  getline(*fMuonFile,line);
246  if (!fMuonFile->good())
247  {
248  std::cout << "FileMuons: Problem reading muon file line ...."<< countFile << ". Perhaps you've exhausted the events in " << fFileName << std::endl; exit(0);
249  }
250  else
251  {
252  // std::cout << "FileMuons: getline() gives "<< line << " for event " << countFile << std::endl;
253  }
254  countFile++;
255 
256  MF_LOG_DEBUG("FileMuons: countFile is ") << countFile <<std::endl;
257  char * cstr, *ptok;
258 
259  // Split this line into tokens
260  cstr = new char [line.size()+1];
261  strcpy (cstr, line.c_str());
262  // cstr now contains a c-string copy of str
263  ptok=strtok (cstr,"*");
264  unsigned int fieldCount = 0;
265  unsigned int posIndex = 0;
266  unsigned int pIndex = 0;
267  while (ptok!=NULL)
268  {
269  // std::cout << ptok << std::endl;
270  ptok=strtok(NULL,"*");
271  if (fieldCount==9 || fieldCount==10 || fieldCount==11)
272  {
273  p[pIndex] = atof(ptok); pIndex++;
274  // std::cout << ptok << std::endl;
275  }
276  if (fieldCount==6 || fieldCount==7 || fieldCount==8)
277  {
278  x[posIndex] = atof(ptok);
279  // make the z axis point up for x, as with p
280  if (posIndex==2) {x[posIndex] = -1.0*x[posIndex];}
281  posIndex++;
282  }
283  if (fieldCount==12)
284  {
285  q = atof(ptok);
286  }
287  fieldCount++;
288  }
289 
290  delete[] cstr;
291 
292  }
293  else if (fMuonsFileType.compare("root")==0) // from root file
294  {
295  /*
296  // Don't use this yet. Keep the specific branch-by-branch identification.
297  for (unsigned int ii=0;ii<fBranchNames.size();ii++)
298  {
299  TNtuple->SetBranchAddress(fBranchNames[ii], x+ii);
300  }
301  */
302  // TNtuple->ResetBranchAddresses();
303  TNtuple->GetEntry(countFile);
304  //TNtuple->Show(countFile);
305 
306  x.SetXYZ(xdet,ydet,-zdet); // as with txt file, make z point up.
307  // Watch for units change to mm in Modern JdJ files!!
308  // This is for pre Spring-2012 JdJ Ntuples.
309  p.SetXYZ(pxtmp,pytmp,pztmp);
310  q = charge;
311 
312  countFile++;
313 
314  } // End read.
315 
316  static TDatabasePDG pdgt;
317  pdgLocal = -q*fPDG[i];
318 
319  TParticlePDG* pdgp = pdgt.GetParticle(pdgLocal);
320  if (pdgp) m = pdgp->Mass();
321 
322 
323  // std::cout << "set the position "<<std::endl;
324  // This gives coordinates at the center of the 300mx300m plate that is 3m above top of
325  // cavern. Got these by histogramming deJong's xdet,ydet,zdet.
326  const double cryoGap = 15.0;
327  x[0] -= fXYZ_Off[0];
328  x[1] -= fXYZ_Off[1];
329  x[2] -= fXYZ_Off[2]; // 3 for plate height above top of cryostat.
330  // Now, must rotate to TPC coordinates. Let's orient TPC axis along z axis,
331  // Cosmics, mostly going along deJong's +z axis must be going along TPC -y axis.
332  x.RotateX(-M_PI/2);
333  p.RotateX(-M_PI/2);
334  //add vector of the position of the center of the point between Cryostats
335  // level with top. (To which I've added 3m - in above code - in height.)
336  // This is referenced from origin at center-right of first cryostat.
338  TVector3 off3(geom->CryostatHalfWidth()*0.01,geom->CryostatHalfHeight()*0.01,geom->CryostatLength()*0.01+cryoGap*0.01/2.0) ;
339  x += off3;
340 
341  TLorentzVector pos(x[0]*100.0, x[1]*100.0, x[2]*100.0, 0.0);
342  TLorentzVector pvec(p[0]*1000.0,p[1]*1000.0,p[2]*1000.0,std::sqrt(p.Mag2()*1000.0*1000.0+m*m));
343  std::cout << "x[m] and p [TeV] are " << std::endl;
344  x.Print();
345  p.Print();
346 
347  int trackid = -1*(i+1); // set track id to -i as these are all primary particles and have id <= 0
348  std::string primary("primary");
349  simb::MCParticle part(trackid, pdgLocal, primary);
350  part.AddTrajectoryPoint(pos, pvec);
351 
352  // std::cout << "add the particle to the primary" << std::endl;
353 
354  mct.Add(part);
355 
356  }//end loop over particles
357 
358  return;
359  }
std::vector< double > fXYZ_Off
geo::Length_t CryostatHalfHeight(geo::CryostatID const &cid) const
Returns the height of the cryostat (y direction)
std::string string
Definition: nybbler.cc:12
std::string fMuonsFileType
std::ifstream * fMuonFile
unsigned int countFile
p
Definition: test.py:223
std::string fFileName
#define M_PI
Definition: includeROOT.h:54
void Add(simb::MCParticle const &part)
Definition: MCTruth.h:80
geo::Length_t CryostatHalfWidth(geo::CryostatID const &cid) const
Returns the half width of the cryostat (x direction)
void line(double t, double *p, double &x, double &y, double &z)
#define MF_LOG_DEBUG(id)
geo::Length_t CryostatLength(geo::CryostatID const &cid) const
Returns the length of the cryostat (z direction)
list x
Definition: train.py:276
std::vector< int > fPDG
QTextStream & endl(QTextStream &s)

Member Data Documentation

TBranch* evgen::FileMuons::b_charge
private

Definition at line 94 of file FileMuons_module.cc.

TBranch* evgen::FileMuons::b_costheta
private

Definition at line 86 of file FileMuons_module.cc.

TBranch* evgen::FileMuons::b_E
private

Definition at line 85 of file FileMuons_module.cc.

TBranch* evgen::FileMuons::b_phi
private

Definition at line 87 of file FileMuons_module.cc.

TBranch* evgen::FileMuons::b_px
private

Definition at line 91 of file FileMuons_module.cc.

TBranch* evgen::FileMuons::b_py
private

Definition at line 92 of file FileMuons_module.cc.

TBranch* evgen::FileMuons::b_pz
private

Definition at line 93 of file FileMuons_module.cc.

TBranch* evgen::FileMuons::b_x
private

Definition at line 82 of file FileMuons_module.cc.

TBranch* evgen::FileMuons::b_xdet
private

Definition at line 88 of file FileMuons_module.cc.

TBranch* evgen::FileMuons::b_y
private

Definition at line 83 of file FileMuons_module.cc.

TBranch* evgen::FileMuons::b_ydet
private

Definition at line 89 of file FileMuons_module.cc.

TBranch* evgen::FileMuons::b_z
private

Definition at line 84 of file FileMuons_module.cc.

TBranch* evgen::FileMuons::b_zdet
private

Definition at line 90 of file FileMuons_module.cc.

Float_t evgen::FileMuons::charge
private

Definition at line 74 of file FileMuons_module.cc.

Float_t evgen::FileMuons::costheta
private

Definition at line 76 of file FileMuons_module.cc.

unsigned int evgen::FileMuons::countFile
private

Definition at line 70 of file FileMuons_module.cc.

Float_t evgen::FileMuons::E
private

Definition at line 75 of file FileMuons_module.cc.

std::vector<std::string> evgen::FileMuons::fBranchNames
private

Definition at line 65 of file FileMuons_module.cc.

int evgen::FileMuons::fEventNumberOffset
private

Definition at line 59 of file FileMuons_module.cc.

std::string evgen::FileMuons::fFileName
private

Definition at line 62 of file FileMuons_module.cc.

std::ifstream* evgen::FileMuons::fMuonFile
private

Definition at line 67 of file FileMuons_module.cc.

TFile* evgen::FileMuons::fMuonFileR
private

Definition at line 68 of file FileMuons_module.cc.

std::string evgen::FileMuons::fMuonsFileType
private

Definition at line 63 of file FileMuons_module.cc.

std::vector<int> evgen::FileMuons::fPDG
private

Definition at line 60 of file FileMuons_module.cc.

std::string evgen::FileMuons::fTreeName
private

Definition at line 64 of file FileMuons_module.cc.

std::vector<double> evgen::FileMuons::fXYZ_Off
private

Definition at line 61 of file FileMuons_module.cc.

Float_t evgen::FileMuons::phi
private

Definition at line 77 of file FileMuons_module.cc.

Float_t evgen::FileMuons::pxtmp
private

Definition at line 73 of file FileMuons_module.cc.

Float_t evgen::FileMuons::pytmp
private

Definition at line 73 of file FileMuons_module.cc.

Float_t evgen::FileMuons::pztmp
private

Definition at line 73 of file FileMuons_module.cc.

TTree* evgen::FileMuons::TNtuple
private

Definition at line 69 of file FileMuons_module.cc.

Float_t evgen::FileMuons::xdet
private

Definition at line 78 of file FileMuons_module.cc.

Float_t evgen::FileMuons::xtmp
private

Definition at line 72 of file FileMuons_module.cc.

Float_t evgen::FileMuons::ydet
private

Definition at line 79 of file FileMuons_module.cc.

Float_t evgen::FileMuons::ytmp
private

Definition at line 72 of file FileMuons_module.cc.

Float_t evgen::FileMuons::zdet
private

Definition at line 80 of file FileMuons_module.cc.

Float_t evgen::FileMuons::ztmp
private

Definition at line 72 of file FileMuons_module.cc.


The documentation for this class was generated from the following file: