Public Member Functions | Private Attributes | List of all members
evgen::CRTGen Class Reference
Inheritance diagram for evgen::CRTGen:
art::EDProducer art::detail::Producer art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Public Member Functions

 CRTGen (fhicl::ParameterSet const &p)
 
void produce (art::Event &e) override
 
void beginJob () override
 
void beginRun (art::Run &run) override
 
- 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 Attributes

short int driftcoordinate =0
 
std::vector< double > CRT_TOP_center_driftY ={-581,305.7,135}
 
std::vector< double > CRT_BOT_center_driftY ={+581,-202.7,135}
 
double CRTHeight =8*14.0
 
double CRTLength =144
 
std::vector< double > CRT_TOP_center
 
std::vector< double > CRT_BOT_center
 
double CRTSizeX
 
double CRTSizeY
 
double CRTSizeZ
 
TH2D CRTTop
 
TH2D CRTBot
 
TH1D EnergyDistribution
 
int fmode
 
int fEnergyDistributionMode
 
std::pair< float, float > fEnergyRange
 
std::string fInputFileNameCRT
 Name of text file containing events to simulate. More...
 
std::string fInputFileNameEnergy
 Name of text file containing events to simulate. More...
 
TH2F * fTH2CRTTop
 
TH2F * fTH2CRTBot
 
TH1F * fTH1Energy
 
double BufferLengthOnCRTBottom
 

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

This module assumes muons cross uniformly both CRT pannels. One muon will be generated per event.

Definition at line 37 of file CRTGen_module.cc.

Constructor & Destructor Documentation

evgen::CRTGen::CRTGen ( fhicl::ParameterSet const &  p)
explicit

Definition at line 77 of file CRTGen_module.cc.

78  : EDProducer{p}
79  , fmode{p.get<int>("Mode",0)} // 0 for uniform distribution on CRT geoometry, 1 to get the distribution from TH2D
80  , fEnergyDistributionMode{p.get<int>("EnergyDistribution",0)} // 0 for uniform distribution on CRT geoometry, 1 to get the distribution from TH2D
81  , fEnergyRange{p.get<std::pair<float,float>>("EnergyRange",std::make_pair(2,3))}
82  , fInputFileNameCRT{p.get<std::string>("InputFileNameCRT","CRT_RawInputs.root")}
83  , fInputFileNameEnergy{p.get<std::string>("InputFileNameEnergy","MuonEnergy.root")}
84  , BufferLengthOnCRTBottom{p.get<float>("BufferLengthOnCRTBottom",30.0)}
85 {
86  produces< std::vector<simb::MCTruth> >();
87  produces< sumdata::RunData, art::InRun >();
88 }
std::pair< float, float > fEnergyRange
std::string string
Definition: nybbler.cc:12
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
std::string fInputFileNameEnergy
Name of text file containing events to simulate.
int fEnergyDistributionMode
std::string fInputFileNameCRT
Name of text file containing events to simulate.
p
Definition: test.py:223
double BufferLengthOnCRTBottom

Member Function Documentation

void evgen::CRTGen::beginJob ( )
overridevirtual

Reimplemented from art::EDProducer.

Definition at line 91 of file CRTGen_module.cc.

92 {
93  if( fmode==0 )
94  {
95  std::cout<<" fmode=0 - Sending muons uniformly distributed on the CRT panels." << std::endl;
96  }else if (fmode==1)
97  {
98  std::cout<<" fmode=1 - Sending muons following the distribution contained on file: " << fInputFileNameCRT << std::endl;}
99  else{ throw cet::exception("CRTGen") << "unknown fmode value " << fmode << " \n"; }
100 
101  if( fEnergyDistributionMode==0 )
102  {
103  std::cout<<" fEnergyDistributionMode=0 - Muons will follow a uniform distribution between the values: " << fEnergyRange.first<< " " << fEnergyRange.second << std::endl;
104  }else if (fEnergyDistributionMode==1)
105  {
106  std::cout<<" fEnergyDistributionMode=1 - Sending muons following the distribution contained on file: " << fInputFileNameEnergy << std::endl;}
107  else{ throw cet::exception("CRTGen") << "unknown fEnergyDistributionMode value " << fEnergyDistributionMode << " \n"; }
108 
109 
110  if(fmode==1)
111  {
112  TFile *fInputFileCRT = new TFile(fInputFileNameCRT.c_str(),"READ");
113  // check that the file is a good one
114  if( !fInputFileCRT->IsOpen() )
115  throw cet::exception("CRTGen") << "input text file "
117  << " cannot be read.\n";
118 
119  TH2D *h =(TH2D*)fInputFileCRT->Get("CRTTop");
120  if (!h) throw cet::exception("CRTGen") << "TH2D named CRTTop not found in "
122  << ".\n";
123  CRTTop = *h;
124  h =(TH2D*)fInputFileCRT->Get("CRTBot");
125  if (!h) throw cet::exception("CRTGen") << "TH2D named CRTBot not found in "
127  << ".\n";
128  CRTBot = *h;
129  fInputFileCRT->Close();
130 
131  }
132 
134  {
135  TFile *fInputFileEnergy = new TFile(fInputFileNameEnergy.c_str(),"READ");
136  // check that the file is a good one
137  if( !fInputFileEnergy->IsOpen() )
138  throw cet::exception("CRTGen") << "input root file "
140  << " cannot be read.\n";
141 
142  TH1D *h =(TH1D*)fInputFileEnergy->Get("EnergyDistribution");
143  if (!h) throw cet::exception("CRTGen") << "TH1D named EnergyDistribution not found in "
145  << ".\n";
147  fInputFileEnergy->Close();
148  }
149 
151 
152  fTH2CRTTop = tfs->make<TH2F>("CRTTop","Start position at CRT Top",10,0,0,10,0,0);
153  fTH2CRTBot = tfs->make<TH2F>("CRTBot","Expected end track position at CRT Bot",10,0,0,10,0,0);
154  fTH1Energy = tfs->make<TH1F>("TH1Energy","Muon energy GeV",100,0,0);
155 
156 }
std::pair< float, float > fEnergyRange
TH1D EnergyDistribution
std::string fInputFileNameEnergy
Name of text file containing events to simulate.
int fEnergyDistributionMode
std::string fInputFileNameCRT
Name of text file containing events to simulate.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
void evgen::CRTGen::beginRun ( art::Run run)
overridevirtual

Reimplemented from art::EDProducer.

Definition at line 159 of file CRTGen_module.cc.

160 {
162  run.put(std::make_unique<sumdata::RunData>(geo->DetectorName()));
163  driftcoordinate = (geo->TPC(0)).DetectDriftDirection();
164 
165  if( driftcoordinate==1 || driftcoordinate==2 )
166  {
167  std::cout<<" drift coordinate: "<<driftcoordinate<<std::endl;
168  }else{ throw cet::exception("CRTGen") << "unknown drift coordinate " << driftcoordinate << " \n"; }
169 
170 
171  /* +1: positive x
172  +2: positive y
173  +3: positive z
174  -1: negative x
175  -2: negative y
176  -3: negative z
177  0: other (or algorithm failed)
178  */
179 
180 
181  // We fix the CRT coordinates assuming drift in Y geometry
182  CRT_TOP_center=CRT_TOP_center_driftY; //{-581,305.7,135};//drift in Y geometry in cm
183  CRT_BOT_center=CRT_BOT_center_driftY;//{+581,-202.7,135}; //drift in Y geometry in cm
185  CRTSizeX=0.0;
186  CRTSizeZ=CRTLength; //size in Z for drift in Y and X
187 
188  //We correct for the drift in X geometry
189  if(driftcoordinate==1) // Y->X, X->-Y
190  {
191  // CRT_TOP_center {305.7,581,135};//drift in X geometry in cm
192  // CRT_BOT_center {-202.7,-581,135};//drift in X geometry in cm
193 
199  CRTSizeY=0;
201  }
202 
203  }
std::vector< double > CRT_TOP_center
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
short int driftcoordinate
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
std::vector< double > CRT_BOT_center_driftY
std::vector< double > CRT_TOP_center_driftY
TPCGeo const & TPC(unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified TPC.
LArSoft geometry interface.
Definition: ChannelGeo.h:16
std::vector< double > CRT_BOT_center
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
void evgen::CRTGen::produce ( art::Event e)
overridevirtual

Implements art::EDProducer.

Definition at line 206 of file CRTGen_module.cc.

207 {
208 
209  std::unique_ptr< std::vector<simb::MCTruth> > truthcol(new std::vector<simb::MCTruth>);
210  simb::MCTruth truth;
211 
212  // declare the variables for reading in the event record
213  int pdg = 13;
214  double energy;
215 
216  if(fEnergyDistributionMode==1) energy = EnergyDistribution.GetRandom();
217  else energy = CLHEP::RandFlat::shoot(fEnergyRange.first,fEnergyRange.second); //uniform distribution among values set in the range
218 
219  double mass = 0.1056583745;//muon mass in GeV
220  double xPosition, yPosition, zPosition, xPositionEnd, yPositionEnd, zPositionEnd;
221  if(fmode==1)
222  {
223  if(driftcoordinate==1)
224  { //drift in X
225  CRTTop.GetRandom2(zPosition,xPosition);
226  CRTBot.GetRandom2(zPositionEnd,xPositionEnd);
227  yPosition = CRT_TOP_center[1];
228  yPositionEnd = CRT_BOT_center[1];
229 
230  fTH2CRTTop->Fill(zPosition,xPosition);
231  fTH2CRTBot->Fill(zPositionEnd,xPositionEnd);
232  }
233  if(driftcoordinate==2)
234  { //drift in Y
235  CRTTop.GetRandom2(zPosition,yPosition);
236  CRTBot.GetRandom2(zPositionEnd,yPositionEnd);
237  xPosition = CRT_TOP_center[0];
238  xPositionEnd = CRT_BOT_center[0];
239  fTH2CRTTop->Fill(zPosition,yPosition);
240  fTH2CRTBot->Fill(zPositionEnd,yPositionEnd);
241 
242  }
243  }
244  else
245  {
246  xPosition = CLHEP::RandFlat::shoot(CRT_TOP_center[0]-0.5*CRTSizeX,CRT_TOP_center[0]+0.5*CRTSizeX);
247  yPosition = CLHEP::RandFlat::shoot(CRT_TOP_center[1]-0.5*CRTSizeY,CRT_TOP_center[1]+0.5*CRTSizeY);
248  zPosition = CLHEP::RandFlat::shoot(CRT_TOP_center[2]-0.5*CRTSizeZ,CRT_TOP_center[2]+0.5*CRTSizeZ);
249 
250  if(driftcoordinate==1)
251  { //drift in X
252  xPositionEnd = CLHEP::RandFlat::shoot(CRT_BOT_center[0]-0.5*CRTSizeX-BufferLengthOnCRTBottom,CRT_BOT_center[0]+0.5*CRTSizeX+BufferLengthOnCRTBottom);
253  yPositionEnd = CLHEP::RandFlat::shoot(CRT_BOT_center[1]-0.5*CRTSizeY,CRT_BOT_center[1]+0.5*CRTSizeY);
254  zPositionEnd = CLHEP::RandFlat::shoot(CRT_BOT_center[2]-0.5*CRTSizeZ-BufferLengthOnCRTBottom,CRT_BOT_center[2]+0.5*CRTSizeZ+BufferLengthOnCRTBottom);
255  }
256  if(driftcoordinate==2)
257  { //drift in Y
258  xPositionEnd = CLHEP::RandFlat::shoot(CRT_BOT_center[0]-0.5*CRTSizeX,CRT_BOT_center[0]+0.5*CRTSizeX);
259  yPositionEnd = CLHEP::RandFlat::shoot(CRT_BOT_center[1]-0.5*CRTSizeY-BufferLengthOnCRTBottom,CRT_BOT_center[1]+0.5*CRTSizeY+BufferLengthOnCRTBottom);
260  zPositionEnd = CLHEP::RandFlat::shoot(CRT_BOT_center[2]-0.5*CRTSizeZ-BufferLengthOnCRTBottom,CRT_BOT_center[2]+0.5*CRTSizeZ+BufferLengthOnCRTBottom);
261  }
262  }
263 
264  if(driftcoordinate==1)
265  { //drift in X
266  fTH2CRTTop->Fill(zPosition,xPosition);
267  fTH2CRTBot->Fill(zPositionEnd,xPositionEnd);
268  }
269  if(driftcoordinate==2)
270  { //drift in Y
271  fTH2CRTTop->Fill(zPosition,yPosition);
272  fTH2CRTBot->Fill(zPositionEnd,yPositionEnd);
273  }
274 
275  double time = 0.;
276  double totmom = sqrt(pow(energy,2)-pow(mass,2));
277 
278  double dx=xPositionEnd-xPosition;
279  double dy=yPositionEnd-yPosition;
280  double dz=zPositionEnd-zPosition;
281  double norm=sqrt(pow(dx,2)+pow(dy,2)+pow(dz,2));
282  dx/=norm;
283  dy/=norm;
284  dz/=norm;
285 
286  double xMomentum = dx*totmom;
287  double yMomentum = dy*totmom;
288  double zMomentum = dz*totmom;
289  mf::LogPrint("CRTGen") << "Shooting muon on " << xPosition << " " << yPosition << " " << zPosition << "to "<< xPositionEnd << " " << yPositionEnd << " " << zPositionEnd <<" With momentum: " << xMomentum << " " << yMomentum << " " << zMomentum << " E=" << energy << " m=" << mass;
290 
291  TLorentzVector pos(xPosition, yPosition, zPosition, time);
292  TLorentzVector mom(xMomentum, yMomentum, zMomentum, energy);
293 
294  fTH1Energy->Fill(energy);
295 
296  simb::MCParticle part(-1, pdg, "primary");
297  part.AddTrajectoryPoint(pos, mom);
298 
299  truth.Add(part);
300 
301  truthcol->push_back(truth);
302 
303  e.put(std::move(truthcol));
304 }
std::pair< float, float > fEnergyRange
constexpr T pow(T x)
Definition: pow.h:72
TH1D EnergyDistribution
std::vector< double > CRT_TOP_center
short int driftcoordinate
def move(depos, offset)
Definition: depos.py:107
int fEnergyDistributionMode
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
auto norm(Vector const &v)
Return norm of the specified vector.
double BufferLengthOnCRTBottom
void Add(simb::MCParticle const &part)
Definition: MCTruth.h:80
Event generator information.
Definition: MCTruth.h:32
std::vector< double > CRT_BOT_center
MaybeLogger_< ELseverityLevel::ELsev_warning, true > LogPrint

Member Data Documentation

double evgen::CRTGen::BufferLengthOnCRTBottom
private

Definition at line 73 of file CRTGen_module.cc.

std::vector<double> evgen::CRTGen::CRT_BOT_center
private

Definition at line 53 of file CRTGen_module.cc.

std::vector<double> evgen::CRTGen::CRT_BOT_center_driftY ={+581,-202.7,135}
private

Definition at line 48 of file CRTGen_module.cc.

std::vector<double> evgen::CRTGen::CRT_TOP_center
private

Definition at line 52 of file CRTGen_module.cc.

std::vector<double> evgen::CRTGen::CRT_TOP_center_driftY ={-581,305.7,135}
private

Definition at line 47 of file CRTGen_module.cc.

TH2D evgen::CRTGen::CRTBot
private

Definition at line 58 of file CRTGen_module.cc.

double evgen::CRTGen::CRTHeight =8*14.0
private

Definition at line 49 of file CRTGen_module.cc.

double evgen::CRTGen::CRTLength =144
private

Definition at line 50 of file CRTGen_module.cc.

double evgen::CRTGen::CRTSizeX
private

Definition at line 54 of file CRTGen_module.cc.

double evgen::CRTGen::CRTSizeY
private

Definition at line 55 of file CRTGen_module.cc.

double evgen::CRTGen::CRTSizeZ
private

Definition at line 56 of file CRTGen_module.cc.

TH2D evgen::CRTGen::CRTTop
private

Definition at line 58 of file CRTGen_module.cc.

short int evgen::CRTGen::driftcoordinate =0
private

Definition at line 46 of file CRTGen_module.cc.

TH1D evgen::CRTGen::EnergyDistribution
private

Definition at line 59 of file CRTGen_module.cc.

int evgen::CRTGen::fEnergyDistributionMode
private

Definition at line 62 of file CRTGen_module.cc.

std::pair<float,float> evgen::CRTGen::fEnergyRange
private

Definition at line 63 of file CRTGen_module.cc.

std::string evgen::CRTGen::fInputFileNameCRT
private

Name of text file containing events to simulate.

Definition at line 64 of file CRTGen_module.cc.

std::string evgen::CRTGen::fInputFileNameEnergy
private

Name of text file containing events to simulate.

Definition at line 65 of file CRTGen_module.cc.

int evgen::CRTGen::fmode
private

Definition at line 61 of file CRTGen_module.cc.

TH1F* evgen::CRTGen::fTH1Energy
private

Definition at line 70 of file CRTGen_module.cc.

TH2F* evgen::CRTGen::fTH2CRTBot
private

Definition at line 69 of file CRTGen_module.cc.

TH2F* evgen::CRTGen::fTH2CRTTop
private

Definition at line 68 of file CRTGen_module.cc.


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