29 #include "cetlib_except/exception.h" 52 #include "nurandom/RandomUtils/NuRandomService.h" 53 #include "art_root_io/TFileService.h" 57 #include <TLorentzVector.h> 58 #include <TDatabasePDG.h> 59 #include <TParticlePDG.h> 61 #include "CLHEP/Random/RandFlat.h" 147 TVector3
ProjectToTPC(TVector3 firstPoint, TVector3 secondPoint);
427 "HepJamesRandom", instanceName))
430 produces< std::vector<simb::MCTruth> >();
431 produces<std::vector<sim::ProtoDUNEbeamsim>>();
432 produces< sumdata::RunData, art::InRun >();
433 produces< std::vector< beam::ProtoDUNEBeamEvent > >();
439 std::cout <<
"All particles tree name = " << fAllParticlesTreeName <<
std::endl;
456 auto const&
ps =
p.second;
457 if (
ps.has_key(
"source") &&
ps.has_key(
"source.skipEvents"))
459 fStartEvent +=
ps.get<
int>(
"source.skipEvents");
466 auto const&
ps =
p.second;
467 if (
ps.has_key(
"source") &&
ps.has_key(
"source.firstEvent"))
469 int fe =
ps.get<
int>(
"source.firstEvent") - 1;
470 if (fe > 0) fStartEvent += fe;
474 mf::LogInfo(
"ProtoDUNEBeam") <<
"Skip " << fStartEvent <<
" first events from the input file.";
479 fBeamX = pset.get<
float>(
"BeamX");
480 fBeamY = pset.get<
float>(
"BeamY");
481 fBeamZ = pset.get<
float>(
"BeamZ");
510 fL1 = pset.get<
float>(
"L1");
511 fL2 = pset.get<
float>(
"L2");
512 fL3 = pset.get<
float>(
"L3");
516 fLMag = pset.get<
float>(
"LMag");
517 fB = pset.get<
float>(
"B");
528 fLB = fB * fLMag * fNominalP / 7.;
598 std::cout <<
"Name prefix for good particle tree = " << namePrefix <<
std::endl;
714 fRecoTree = tfs->make<TTree>(
"tree",
"");
789 auto truthcol = std::make_unique< std::vector<simb::MCTruth> >();
792 std::unique_ptr<std::vector<sim::ProtoDUNEbeamsim>> beamsimcol (
new std::vector<sim::ProtoDUNEbeamsim>);
793 std::unique_ptr<std::vector<beam::ProtoDUNEBeamEvent> > beamData(
new std::vector<beam::ProtoDUNEBeamEvent>);
802 truthcol->push_back(truth);
810 beamData->push_back( beamEvent );
824 int goodEventCounter = 0;
851 mf::LogInfo(
"ProtoDUNEBeam") <<
"About to loop over the beam simulation tree, this could take some time.";
857 if (i%100000==0) std::cout <<
"Looking at entry " << i <<
std::endl;
864 unsigned int nMatches = 0;
867 if(nMatches == goodEventList.size())
break;
870 if(std::find(goodEventList.begin(),goodEventList.end(),spill.fGoodEvent) == goodEventList.end())
continue;
873 spill.fAllSpillTracks[
event].push_back(i);
879 mf::LogInfo(
"ProtoDUNEBeam") <<
"Found " <<
fGoodEventList.size() <<
" good events containing " << goodEventCounter <<
" good particles.";
881 mf::LogInfo(
"ProtoDUNEBeam") <<
"All maps built, beginning event generation.";
894 <<
" but tree only has entries 0 to " 898 size_t nBeamEvents = 0;
917 bool trigEvent = (
event.first == spill.
fGoodEvent);
928 for(
auto const t :
event.second){
983 std::cout <<
"TrackID: " << (
int)fAllTrackID<< std::endl;
1010 mcTruth.
Add(newParticle);
1013 if(trigEvent && (spill.
fGoodTrack == (
int)fAllTrackID)){
1017 sim::ProtoDUNEBeamInstrument tof1(
"TOF1",
fGoodTOF1_x,
fGoodTOF1_y,
fGoodTOF1_z,
fGoodTOF1_t,
fGoodTOF1_Px,
fGoodTOF1_Py,
fGoodTOF1_Pz,
fGoodTOF1_PDGid,
fGoodTOF1_EventID,
fGoodTOF1_TrackID,
fT_Resolution);
1018 sim::ProtoDUNEBeamInstrument trig2(
"TRIG2",
fGoodTRIG2_x,
fGoodTRIG2_y,
fGoodTRIG2_z,
fGoodTRIG2_t,
fGoodTRIG2_Px,
fGoodTRIG2_Py,
fGoodTRIG2_Pz,
fGoodTRIG2_PDGid,
fGoodTRIG2_EventID,
fGoodTRIG2_TrackID,
fT_Resolution);
1023 sim::ProtoDUNEBeamInstrument bprof4(
"BPROF4",bprof4Pos.X(),bprof4Pos.Y(),bprof4Pos.Z(),
fGoodBPROF4_t,bprof4Mom.X(),bprof4Mom.Y(),bprof4Mom.Z(),
fGoodBPROF4_PDGid,
fGoodBPROF4_EventID,
fGoodBPROF4_TrackID,
fPos_Resolution);
1028 sim::ProtoDUNEBeamInstrument bprofext(
"BPROFEXT",bprofextPos.X(),bprofextPos.Y(),bprofextPos.Z(),
fGoodBPROFEXT_t,bprofextMom.X(),bprofextMom.Y(),bprofextMom.Z(),
fGoodBPROFEXT_PDGid,
fGoodBPROFEXT_EventID,
fGoodBPROFEXT_TrackID,
fPos_Resolution);
1035 sim::ProtoDUNEBeamInstrument trig1(
"TRIG1",
fGoodTRIG1_x,
fGoodTRIG1_y,
fGoodTRIG1_z,
fGoodTRIG1_t,
fGoodTRIG1_Px,
fGoodTRIG1_Py,
fGoodTRIG1_Pz,
fGoodTRIG1_PDGid,
fGoodTRIG1_EventID,
fGoodTRIG1_TrackID,
fT_Resolution);
1036 sim::ProtoDUNEBeamInstrument bprof3(
"BPROF3",
fGoodBPROF3_x,
fGoodBPROF3_y,
fGoodBPROF3_z,
fGoodBPROF3_t,
fGoodBPROF3_Px,
fGoodBPROF3_Py,
fGoodBPROF3_Pz,
fGoodBPROF3_PDGid,
fGoodBPROF3_EventID,
fGoodBPROF3_TrackID,
fPos_Resolution);
1037 sim::ProtoDUNEBeamInstrument bprof2(
"BPROF2",
fGoodBPROF2_x,
fGoodBPROF2_y,
fGoodBPROF2_z,
fGoodBPROF2_t,
fGoodBPROF2_Px,
fGoodBPROF2_Py,
fGoodBPROF2_Pz,
fGoodBPROF2_PDGid,
fGoodBPROF2_EventID,
fGoodBPROF2_TrackID,
fPos_Resolution);
1038 sim::ProtoDUNEBeamInstrument bprof1(
"BPROF1",
fGoodBPROF1_x,
fGoodBPROF1_y,
fGoodBPROF1_z,
fGoodBPROF1_t,
fGoodBPROF1_Px,
fGoodBPROF1_Py,
fGoodBPROF1_Pz,
fGoodBPROF1_PDGid,
fGoodBPROF1_EventID,
fGoodBPROF1_TrackID,
fPos_Resolution);
1041 sim::ProtoDUNEBeamInstrument cherenkov1(
"CHERENKOV1",
fGoodBPROFEXT_x,
fGoodBPROFEXT_y,
fGoodBPROFEXT_z,
fGoodBPROFEXT_t,
fGoodBPROFEXT_Px,
fGoodBPROFEXT_Py,
fGoodBPROFEXT_Pz,
fGoodBPROFEXT_PDGid,fGoodBPROFEXT_EventID,fGoodBPROFEXT_TrackID,
fCh_Efficiency);
1042 sim::ProtoDUNEBeamInstrument cherenkov2(
"CHERENKOV2",
fGoodBPROFEXT_x,
fGoodBPROFEXT_y,
fGoodBPROFEXT_z,
fGoodBPROFEXT_t,
fGoodBPROFEXT_Px,
fGoodBPROFEXT_Py,
fGoodBPROFEXT_Pz,
fGoodBPROFEXT_PDGid,fGoodBPROFEXT_EventID,fGoodBPROFEXT_TrackID,
fCh_Efficiency);
1060 beamsimcol.push_back(temp);
1087 mf::LogInfo(
"ProtoDUNEBeam") <<
"Got " << nBeamEvents <<
" beam events";
1102 fIFDH =
new ifdh_ns::ifdh;
1105 const char* ifdh_debug_env =
std::getenv(
"IFDH_DEBUG_LEVEL");
1106 if ( ifdh_debug_env )
1108 mf::LogInfo(
"ProtoDUNEBeam") <<
"IFDH_DEBUG_LEVEL: " << ifdh_debug_env<<
"\n";
1109 fIFDH->set_debug(ifdh_debug_env);
1115 auto flist =
fIFDH->findMatchingFiles(path,pattern);
1121 throw cet::exception(
"ProtoDUNEBeam") <<
"No files returned for path:pattern: "<<path<<
":"<<pattern<<
std::endl;
1130 std::pair<std::string, long>
f =
flist.front();
1137 <<
"Fetching: " << f.first <<
" " << f.second <<
"\n";
1139 MF_LOG_DEBUG(
"ProtoDUNEBeam") <<
" Fetched; local path: " << fetchedfile;
1150 float finalX = x +
fBeamX;
1151 float finalY = y +
fBeamY;
1153 float finalZ = z +
fBeamZ;
1155 TLorentzVector newPos(finalX,finalY,finalZ,t);
1167 TVector3 momVec(px,py,pz);
1178 momVec.RotateY(
fRotateXZ * TMath::Pi() / 180.);
1179 momVec.RotateX(
fRotateYZ * TMath::Pi() / 180.);
1184 const TDatabasePDG* databasePDG = TDatabasePDG::Instance();
1185 const TParticlePDG* definition = databasePDG->GetParticle(pdg);
1186 float mass = definition->Mass();
1188 float energy = sqrt(mass*mass + momVec.Mag2());
1190 TLorentzVector newMom(momVec,energy);
1216 if(fabs(event -
e) < nOverlay/2){
1227 std::vector<int> nMatches;
1229 if(fabs(event -
e) < nOverlay/2){
1230 nMatches.push_back(
e);
1244 TLorentzVector old(x,y,z,t);
1257 TLorentzVector
result(newX,newY,newZ,t);
1269 TVector3 old(x,y,z);
1279 TVector3
result(newX/10., newY/10., newZ/10.);
1285 TVector3 newMom(px,py,pz);
1315 TVector3
pos(x,y,z);
1316 TVector3
dir = TVector3(px,py,pz).Unit();
1322 return pos - shiftLength*
dir;
1347 beamevt.
SetT0( std::make_pair(0.,0.) );
1436 short f = 96 - short( floor(pos) ) - 1;
1438 theFBM.
active.push_back(f);
1445 return ((96 - fiber) - .5);
1456 short fx1 = beamEvent.
GetFBM(
"XBPF022707" ).
active[0];
1457 short fy1 = beamEvent.
GetFBM(
"XBPF022708" ).
active[0];
1464 short fx2 = beamEvent.
GetFBM(
"XBPF022716" ).
active[0];
1465 short fy2 = beamEvent.
GetFBM(
"XBPF022717" ).
active[0];
1472 std::vector< TVector3 > thePoints = { pos1, pos2,
ProjectToTPC( pos1, pos2 ) };
1473 std::vector< TVector3 > theMomenta = {
1474 ( pos2 - pos1 ).Unit(),
1475 ( pos2 - pos1 ).Unit(),
1476 ( pos2 - pos1 ).Unit()
1492 TVector3 dR = (secondPoint - firstPoint);
1494 double deltaZ = -1.*secondPoint.Z();
1495 double deltaX = deltaZ * (dR.X() / dR.Z());
1496 double deltaY = deltaZ * (dR.Y() / dR.Z());
1498 TVector3 lastPoint = secondPoint + TVector3(deltaX, deltaY, deltaZ);
1513 double momentum = 299792458*
fLB/(1.E9 * acos(cos_theta));
1524 double denomTerm1, denomTerm2, denom;
1525 denomTerm1 = sqrt(
fL1*
fL1 + (a - x1)*(a - x1) );
1527 + TMath::Power( ( (
fL3 -
fL2) ),2) );
1528 denom = denomTerm1 * denomTerm2;
1530 double cosTheta = numTerm/denom;
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
base_engine_t & createEngine(seed_t seed)
TTree * fGoodParticleTree
const FBM & GetFBM(std::string) const
beam::FBM MakeFiberMonitor(float pos)
void MakeTracks(beam::ProtoDUNEBeamEvent &beamEvent)
Float_t fGoodNP04front_EventID
double GetPosition(short fiber)
std::string fAllParticlesTreeName
const recob::Track & GetBeamTrack(size_t i) const
Float_t fGoodBPROFEXT_EventID
const std::vector< double > & GetTOFs() const
void AddTrajectoryPoint(TLorentzVector const &position, TLorentzVector const &momentum)
Float_t fGoodBPROF4_PDGid
void SetOrigin(simb::Origin_t origin)
Float_t fGoodTOF1_TrackID
ROOT::Math::SMatrix< Double32_t, 5, 5, ROOT::Math::MatRepSym< Double32_t, 5 > > SMatrixSym55
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Float_t fGoodNP04front_PDGid
std::vector< Vector_t > convertCollToVector(std::vector< Vector > const &coll)
void SetTimingTrigger(int theTrigger)
ProtoDUNEBeam & operator=(ProtoDUNEBeam const &)=delete
EDProducer(fhicl::ParameterSet const &pset)
static collection_type const & get() noexcept
TrackTrajectory::Flags_t Flags_t
Float_t fGoodTRIG1_EventID
Float_t fGoodBPROF3_PDGid
Float_t fGoodBPROFEXT_PDGid
unsigned int fCurrentGoodEvent
std::map< int, std::vector< int > > fAllSpillTracks
std::vector< short > active
art framework interface to geometry description
void SetFBMTrigger(std::string, FBM)
Float_t fGoodTRIG2_EventID
void SetCKov0(CKov theCKov)
TVector3 ConvertProfCoordinates(double x, double y, double z, double zOffset)
ProtoFullSpill(int event, int track, float time, int id)
Float_t fGoodNP04front_Pz
int IsOverlayEvent(int event, int nOverlay)
std::vector< int > GetAllOverlays(int event, int nOverlay)
#define DEFINE_ART_MODULE(klass)
void SetMagnetCurrent(double theMagnetCurrent)
void GenerateTrueEvent(simb::MCTruth &mcTruth, std::vector< sim::ProtoDUNEbeamsim > &beamsimcol, beam::ProtoDUNEBeamEvent &beamEvent)
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
Float_t fGoodBPROF4_EventID
A trajectory in space reconstructed from hits.
single particles thrown at the detector
Float_t fGoodBPROF2_EventID
const double & GetTOF() const
std::string getenv(std::string const &name)
Float_t fGoodBPROFEXT_TrackID
std::vector< int > fGoodEventList
Float_t fGoodNP04front_Py
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Float_t fGoodNP04front_TrackID
std::vector< Point_t > convertCollToPoint(std::vector< Point > const &coll)
TVector3 GetBackgroundPosition(float x, float y, float z, float px, float py, float pz)
void RotateMonitorVector(TVector3 &vec)
static constexpr double ps
std::string fGoodParticleTreeName
void AddBeamTrack(recob::Track theTrack)
double MomentumCosTheta(double, double, double)
Float_t fGoodTOF1_EventID
void CalculateNOverlays()
TLorentzVector ConvertBeamMonitorCoordinates(float x, float y, float z, float t, float offset)
void MomentumSpectrometer(beam::ProtoDUNEBeamEvent &beamEvent)
Float_t fGoodBPROF3_TrackID
void AddRecoBeamMomentum(double theMomentum)
std::array< short, 192 > fibers
void Add(simb::MCParticle const &part)
Float_t fGoodBPROF1_EventID
Float_t fGoodNP04front_Px
void produce(art::Event &e) override
Float_t fGoodBPROF1_PDGid
Float_t fGoodBPROF2_TrackID
void SetDownstreamTriggers(std::vector< size_t > theContent)
Provides recob::Track data product.
TTree * fAllParticlesTree
void SetUpstreamTriggers(std::vector< size_t > theContent)
std::vector< ProtoFullSpill > fAllSpills
TVector3 ProjectToTPC(TVector3 firstPoint, TVector3 secondPoint)
std::array< short, 192 > glitch_mask
cet::LibraryManager dummy("noplugin")
Point_t const & End() const
Float_t fGoodTRIG2_TrackID
void BeamMonitorBasisVectors()
Float_t fGoodTRIG1_TrackID
void SetT0(std::pair< double, double > theT0)
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
void SetCKov1(CKov theCKov)
Event generator information.
Float_t fGoodBPROF1_TrackID
def momentum(x1, x2, x3, scale=1.)
Float_t fGoodBPROF3_EventID
LArSoft geometry interface.
const double & GetRecoBeamMomentum(size_t i) const
Event Generation using GENIE, cosmics or single particles.
void SetTOFs(std::vector< double > theContent)
Float_t fGoodBPROF4_TrackID
void SetBeamEvent(beam::ProtoDUNEBeamEvent &beamevt)
TLorentzVector ConvertCoordinates(float x, float y, float z, float t)
void SetCalibrations(double TOFCalAA, double TOFCalBA, double TOFCalAB, double TOFCalBB)
TVector3 ConvertBeamMonitorMomentumVec(float px, float py, float pz)
ProtoDUNEBeam(fhicl::ParameterSet const &p)
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
cet::coded_exception< error, detail::translate > exception
void AddInstrument(ProtoDUNEBeamInstrument newInst)
void SetTOFChans(std::vector< int > theContent)
void beginRun(art::Run &run) override
QTextStream & endl(QTextStream &s)
Event finding and building.
TLorentzVector MakeMomentumVector(float px, float py, float pz, int pdg, bool shifts)
Float_t fGoodBPROF2_PDGid
void SetActiveTrigger(size_t theTrigger)