All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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:

Public Member Functions

 FileMuons (fhicl::ParameterSet const &pset)
 
void produce (art::Event &evt)
 
void beginJob ()
 
void beginRun (art::Run &run)
 
void endJob ()
 

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::string > fBranchNames
 
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
 

Detailed Description

module to produce single or multiple specified particles in the detector

Definition at line 45 of file FileMuons_module.cc.

Constructor & Destructor Documentation

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

Definition at line 106 of file FileMuons_module.cc.

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

Member Function Documentation

void evgen::FileMuons::beginJob ( )

Definition at line 123 of file FileMuons_module.cc.

124  {
126  mf::LogInfo("FileMuons : starting at event ") << countFile <<std::endl;
127 
128  if (fMuonsFileType.compare("source")==0)
129  {
130  std::cout << "FileMuons: Not yet equipped to walk through muons with TFS mojo."<< std::endl;
131  }
132  else if (fMuonsFileType.compare("root")==0)
133  {
134  std::cout << "FileMuons: You have chosen to read muons from Root File " << fFileName << std::endl;
135  }
136  else if (fMuonsFileType.compare("text")==0)
137  {
138  std::cout << "FileMuons: You have chosen to read muons from " << fFileName << "." << std::endl;
139  }
140  else
141  {
142  std::cout << "FileMuons: You must specify one of source/text/root file to read for muons."<< std::endl;
143 
144  }
145 
146  if (fMuonsFileType.compare("text")==0)
147  {
148  fMuonFile = new std::ifstream(fFileName.c_str());
149  long begin = fMuonFile->tellg();
150  fMuonFile->seekg (0, std::ios::end);
151  long end = fMuonFile->tellg();
152  std::cout << "FileMuons: " << fFileName << " size is: " << (end-begin) << " bytes.\n";
153  fMuonFile->seekg (0, std::ios::beg);
154 
155  for (unsigned int header=0; header<3 && fMuonFile->good(); ++header)
156  {
157  std::string line;
158  getline(*fMuonFile,line);
159  }
160  if (!fMuonFile->good())
161  {
162  std::cout << "FileMuons: Problem reading muon file header."<< std::endl;
163  }
164  } // fMuonsFileType is a text file.
165  else if (fMuonsFileType.compare("root")==0)
166  {
167  fMuonFileR = new TFile(fFileName.c_str(),"READ");
168  TNtuple = (TTree*)(fMuonFileR->Get(fTreeName.c_str()));
169 
170  TNtuple->SetBranchAddress("x", &xtmp, &b_x);
171  TNtuple->SetBranchAddress("y", &ytmp, &b_y);
172  TNtuple->SetBranchAddress("z", &ztmp, &b_z);
173  TNtuple->SetBranchAddress("E", &E, &b_E);
174  TNtuple->SetBranchAddress("costheta", &costheta, &b_costheta);
175  TNtuple->SetBranchAddress("phi", &phi, &b_phi);
176  TNtuple->SetBranchAddress("xdet", &xdet, &b_xdet);
177  TNtuple->SetBranchAddress("ydet", &ydet, &b_ydet);
178  TNtuple->SetBranchAddress("zdet", &zdet, &b_zdet);
179  TNtuple->SetBranchAddress("px", &pxtmp, &b_px);
180  TNtuple->SetBranchAddress("py", &pytmp, &b_py);
181  TNtuple->SetBranchAddress("pz", &pztmp, &b_pz);
182  TNtuple->SetBranchAddress("charge", &charge, &b_charge);
183 
184  } // fMuonsFileType is a root file.
185 
186  }
std::string fMuonsFileType
std::ifstream * fMuonFile
unsigned int countFile
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
std::string fFileName
auto begin(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:573
BEGIN_PROLOG could also be cout
std::string fTreeName
void evgen::FileMuons::beginRun ( art::Run &  run)

Definition at line 198 of file FileMuons_module.cc.

199  {
200  art::ServiceHandle<geo::Geometry const> geo;
201  run.put(std::make_unique<sumdata::RunData>(geo->DetectorName()));
202  }
void evgen::FileMuons::endJob ( )

Definition at line 189 of file FileMuons_module.cc.

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

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

Definition at line 205 of file FileMuons_module.cc.

206  {
207 
208  ///unique_ptr allows ownership to be transferred to the art::Event after the put statement
209  std::unique_ptr< std::vector<simb::MCTruth> > truthcol(new std::vector<simb::MCTruth>);
210 
211  simb::MCTruth truth;
212  truth.SetOrigin(simb::kSingleParticle);
213  ReadEvents(truth);
214 
215 // std::cout << "put mctruth into the vector" << std::endl;
216  truthcol->push_back(truth);
217 
218 // std::cout << "add vector to the event " << truthcol->size() << std::endl;
219  evt.put(std::move(truthcol));
220 
221  return;
222  }
void ReadEvents(simb::MCTruth &mct)
TCEvent evt
Definition: DataStructs.cxx:8
void evgen::FileMuons::ReadEvents ( simb::MCTruth &  mct)
private

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

Definition at line 225 of file FileMuons_module.cc.

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

Member Data Documentation

TBranch* evgen::FileMuons::b_charge
private

Definition at line 95 of file FileMuons_module.cc.

TBranch* evgen::FileMuons::b_costheta
private

Definition at line 87 of file FileMuons_module.cc.

TBranch* evgen::FileMuons::b_E
private

Definition at line 86 of file FileMuons_module.cc.

TBranch* evgen::FileMuons::b_phi
private

Definition at line 88 of file FileMuons_module.cc.

TBranch* evgen::FileMuons::b_px
private

Definition at line 92 of file FileMuons_module.cc.

TBranch* evgen::FileMuons::b_py
private

Definition at line 93 of file FileMuons_module.cc.

TBranch* evgen::FileMuons::b_pz
private

Definition at line 94 of file FileMuons_module.cc.

TBranch* evgen::FileMuons::b_x
private

Definition at line 83 of file FileMuons_module.cc.

TBranch* evgen::FileMuons::b_xdet
private

Definition at line 89 of file FileMuons_module.cc.

TBranch* evgen::FileMuons::b_y
private

Definition at line 84 of file FileMuons_module.cc.

TBranch* evgen::FileMuons::b_ydet
private

Definition at line 90 of file FileMuons_module.cc.

TBranch* evgen::FileMuons::b_z
private

Definition at line 85 of file FileMuons_module.cc.

TBranch* evgen::FileMuons::b_zdet
private

Definition at line 91 of file FileMuons_module.cc.

Float_t evgen::FileMuons::charge
private

Definition at line 75 of file FileMuons_module.cc.

Float_t evgen::FileMuons::costheta
private

Definition at line 77 of file FileMuons_module.cc.

unsigned int evgen::FileMuons::countFile
private

Definition at line 71 of file FileMuons_module.cc.

Float_t evgen::FileMuons::E
private

Definition at line 76 of file FileMuons_module.cc.

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

Definition at line 66 of file FileMuons_module.cc.

int evgen::FileMuons::fEventNumberOffset
private

Definition at line 60 of file FileMuons_module.cc.

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

Definition at line 63 of file FileMuons_module.cc.

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

Definition at line 68 of file FileMuons_module.cc.

TFile* evgen::FileMuons::fMuonFileR
private

Definition at line 69 of file FileMuons_module.cc.

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

Definition at line 64 of file FileMuons_module.cc.

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

Definition at line 61 of file FileMuons_module.cc.

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

Definition at line 65 of file FileMuons_module.cc.

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

Definition at line 62 of file FileMuons_module.cc.

Float_t evgen::FileMuons::phi
private

Definition at line 78 of file FileMuons_module.cc.

Float_t evgen::FileMuons::pxtmp
private

Definition at line 74 of file FileMuons_module.cc.

Float_t evgen::FileMuons::pytmp
private

Definition at line 74 of file FileMuons_module.cc.

Float_t evgen::FileMuons::pztmp
private

Definition at line 74 of file FileMuons_module.cc.

TTree* evgen::FileMuons::TNtuple
private

Definition at line 70 of file FileMuons_module.cc.

Float_t evgen::FileMuons::xdet
private

Definition at line 79 of file FileMuons_module.cc.

Float_t evgen::FileMuons::xtmp
private

Definition at line 73 of file FileMuons_module.cc.

Float_t evgen::FileMuons::ydet
private

Definition at line 80 of file FileMuons_module.cc.

Float_t evgen::FileMuons::ytmp
private

Definition at line 73 of file FileMuons_module.cc.

Float_t evgen::FileMuons::zdet
private

Definition at line 81 of file FileMuons_module.cc.

Float_t evgen::FileMuons::ztmp
private

Definition at line 73 of file FileMuons_module.cc.


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