19 #include "art_root_io/TFileService.h" 30 #include "THnSparse.h" 37 #include "TDatabasePDG.h" 38 #include "TParticlePDG.h" 79 std::map<std::string, THnSparseD *>
fPDFs;
124 void Convert(
double input_point[5], std::vector<double> minima,
125 std::vector<double> maxima,
double output_point[5]);
156 fSeed(
p.get<
int>(
"Seed")),
162 fBeamX(
p.get<
double>(
"BeamX")),
163 fBeamY(
p.get<
double>(
"BeamY")),
164 fBeamZ(
p.get<
double>(
"BeamZ")),
172 std::vector<std::pair<std::string, double>> temp_vec =
173 p.get<std::vector<std::pair<std::string, double>>>(
"ParticleTypes");
175 for (
auto it = temp_vec.begin(); it != temp_vec.end(); ++it) {
180 std::cout << it->first <<
" " << it->second <<
" " <<
fTotalParticles <<
184 fMinima =
p.get<std::vector<double>>(
"Minima");
185 fMaxima =
p.get<std::vector<double>>(
"Maxima");
187 produces<std::vector<simb::MCTruth>>();
188 produces<std::vector<beam::ProtoDUNEBeamEvent>>();
195 auto mcTruths = std::make_unique<std::vector<simb::MCTruth>>();
202 mcTruths->push_back(truth);
206 std::unique_ptr<std::vector<beam::ProtoDUNEBeamEvent>>
207 beamData(
new std::vector<beam::ProtoDUNEBeamEvent>);
211 beamData->push_back(beamEvent);
320 double running_total = 0.;
325 std::cout << it->second <<
" " << running_total <<
std::endl;
354 double kin_samples[5];
356 double pdg_sample = 0.;
359 pdg_sample =
fRNG.Rndm();
362 if (pdg_sample <= it->
second) {
364 std::cout <<
"Sampled " << it->first <<
" " <<
368 part_type = it->first;
378 bool sample_again =
true;
379 while (sample_again) {
380 fRNG.RndmArray(5, &kin_samples[0]);
381 pdf_check =
fRNG.Rndm();
394 long long bin =
fPDFs[part_type]->GetBin(&kin_point[0],
false);
397 if (bin == -1)
continue;
400 double pdf_value =
fPDFs[part_type]->GetBinContent(bin);
403 if (pdf_check <= pdf_value) {
405 std::cout <<
"bin: " << bin <<
" PDF val: " << pdf_value <<
407 std::cout << kin_samples[0] <<
" " << kin_samples[1] <<
" " <<
408 kin_samples[2] <<
" " << kin_samples[3] <<
" " <<
410 std::cout << kin_point[0] <<
" " << kin_point[1] <<
" " <<
411 kin_point[2] <<
" " << kin_point[3] <<
" " <<
423 sample_again =
false;
453 double input_point[5], std::vector<double> minima,
454 std::vector<double> maxima,
double output_point[5]) {
455 for (
int i = 0; i < 5; ++i) {
456 double delta = maxima[i] - minima[i];
457 output_point[i] = minima[i] + delta * input_point[i];
462 TLorentzVector
position(0, 0, 0, 0);
463 TLorentzVector
momentum(0., 0., 0., 0.);
467 std::cout <<
"Position: ";
469 std::cout <<
"Momentum: ";
482 mcTruth.
Add(newParticle);
509 TVector3 dR = (downstream_point - upstream_point).Unit();
512 std::cout <<
"Upstream: " << upstream_point.X() <<
" " <<
513 upstream_point.Y() <<
" " << upstream_point.Z() <<
std::endl;
514 std::cout <<
"Downstream: " << downstream_point.X() <<
" " <<
515 downstream_point.Y() <<
" " << downstream_point.Z() <<
std::endl;
516 std::cout <<
"dR: " << dR.X() <<
" " << dR.Y() <<
" " << dR.Z() <<
std::endl;
520 double deltaZ = (
fGeneratorZ - downstream_point.Z());
521 double deltaX = (dR.X() / dR.Z()) * deltaZ;
522 double deltaY = (dR.Y() / dR.Z()) * deltaZ;
524 TVector3 generator_point = downstream_point +
525 TVector3(deltaX, deltaY, deltaZ);
528 position = TLorentzVector(generator_point, 0.);
533 deltaX = (dR.X() / dR.Z()) * deltaZ;
534 deltaY = (dR.Y() / dR.Z()) * deltaZ;
536 TVector3 last_point = generator_point +
537 TVector3(deltaX, deltaY, deltaZ);
539 std::cout << last_point.X() <<
" " << last_point.Y() <<
" " <<
565 const TDatabasePDG * dbPDG = TDatabasePDG::Instance();
566 const TParticlePDG * def = dbPDG->GetParticle(pdg);
567 double mass = def->Mass();
568 double energy = sqrt(mass*mass + mom_vec.Mag2());
571 momentum = TLorentzVector(mom_vec, energy);
575 double x,
double y,
double z,
double zOffset) {
592 TVector3
result(newX/10., newY/10., newZ/10.);
609 TH1D *
hist = it->second;
610 hist->Fit(
"gaus",
"Q");
611 fResolutions[it->first] = (TF1 *)hist->GetFunction(
"gaus");
617 beamEvent.
SetTOFs(std::vector<double>{0.});
635 beamEvent.
SetT0(std::make_pair(0.,0.));
672 short f = 96 - short(floor(pos)) - 1;
674 theFBM.
active.push_back(f);
688 double x1 = 96. - fx1 - .5;
689 double y1 = 96. - fy1 - .5;
696 double x2 = 96. - fx2 - .5;
697 double y2 = 96. - fy2 - .5;
701 TVector3 dR = (pos2 - pos1).Unit();
703 double deltaZ = (-1.*pos2.Z());
704 double deltaX = (dR.X() / dR.Z()) * deltaZ;
705 double deltaY = (dR.Y() / dR.Z()) * deltaZ;
707 TVector3 tpc_point = pos2 + TVector3(deltaX, deltaY, deltaZ);
709 std::cout <<
"TPC point: " << tpc_point.X() <<
" " << tpc_point.Y() <<
713 std::vector< TVector3 > thePoints = {pos1, pos2, tpc_point};
714 std::vector< TVector3 > theMomenta = {
715 (pos2 - pos1).Unit(),
716 (pos2 - pos1).Unit(),
734 double mean = res->GetParameter(1);
735 double sigma = res->GetParameter(2);
736 double t =
fRNG.Gaus(mean, sigma);
743 std::cout <<
"Using 2D Unsmear method" <<
std::endl;
755 double true_min = res->GetYaxis()->GetXmin();
756 double true_max = res->GetYaxis()->GetXmax();
757 for (
int i = 1; i <= res->GetNbinsY(); ++i) {
758 if (res->GetBinContent(xBin, i) > 0.) {
759 true_min = res->GetYaxis()->GetBinLowEdge(i);
763 for (
int i = res->GetNbinsY(); i >= 1; --i) {
764 if (res->GetBinContent(xBin, i) > 0.) {
765 true_max = res->GetYaxis()->GetBinUpEdge(i);
771 std::cout <<
"True min and max: " << true_min <<
" " << true_max <<
std::endl;
773 double unsmeared_momentum = 0.;
775 double t =
fRNG.Uniform(true_min, true_max);
776 double pdf_check =
fRNG.Rndm();
778 int yBin = res->GetYaxis()->FindBin(t);
779 double pdf_value = res->GetBinContent(xBin, yBin);
781 std::cout <<
"True mom & bin: " << t <<
" " << yBin <<
std::endl;
782 std::cout <<
"Check & val: " << pdf_check <<
" " << pdf_value <<
785 if (pdf_check < pdf_value) {
786 unsmeared_momentum =
t;
792 return unsmeared_momentum;
798 TH2D * this_hist = it->second;
799 for (
int i = 1; i <= this_hist->GetNbinsX(); ++i) {
800 double integral = this_hist->TH1::Integral(i, i);
802 for (
int j = 1; j <= this_hist->GetNbinsY(); ++j) {
803 this_hist->SetBinContent(i, j,
804 this_hist->GetBinContent(i, j) /
integral);
805 total += this_hist->GetBinContent(i, j);
813 TH2D * this_hist = it->second;
814 for (
int i = 1; i <= this_hist->GetNbinsX(); ++i) {
815 double integral = this_hist->TH1::Integral(i, i);
817 for (
int j = 1; j <= this_hist->GetNbinsY(); ++j) {
818 this_hist->SetBinContent(i, j,
819 this_hist->GetBinContent(i, j) /
integral);
820 total += this_hist->GetBinContent(i, j);
829 TH2D * this_hist = it->second;
830 for (
int i = 1; i <= this_hist->GetNbinsX(); ++i) {
831 double integral = this_hist->TH1::Integral(i, i);
833 for (
int j = 1; j <= this_hist->GetNbinsY(); ++j) {
834 this_hist->SetBinContent(i, j,
835 this_hist->GetBinContent(i, j) /
integral);
836 total += this_hist->GetBinContent(i, j);
848 if (part_type ==
"Muons") {
857 if (part_type ==
"Muons") {
858 res_name =
"hPionsRes";
861 res_name =
"h" + part_type +
"Res";
884 if (part_type ==
"Muons") {
887 else if (part_type ==
"Kaons") {
896 if (part_type ==
"Muons") {
897 res_name =
"hPionsRes";
904 res_name =
"h" + part_type +
"Res";
925 if (part_type ==
"Muons" || part_type ==
"Electrons") {
934 if (part_type ==
"Muons") {
935 res_name =
"hPionsRes";
938 res_name =
"h" + part_type +
"Res";
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
const FBM & GetFBM(std::string) const
std::vector< double > fRandVUpstream
std::map< std::string, int > fNameToPDG
std::map< std::string, TH2D * > fResolutionHists2D
void AddTrajectoryPoint(TLorentzVector const &position, TLorentzVector const &momentum)
PDSPDataDrivenBeam & operator=(PDSPDataDrivenBeam const &)=delete
void SetOrigin(simb::Origin_t origin)
ROOT::Math::SMatrix< Double32_t, 5, 5, ROOT::Math::MatRepSym< Double32_t, 5 > > SMatrixSym55
std::map< std::string, TF1 * > fResolutions
std::vector< Vector_t > convertCollToVector(std::vector< Vector > const &coll)
std::vector< double > fMinima
void SetTimingTrigger(int theTrigger)
EDProducer(fhicl::ParameterSet const &pset)
void GenerateBeamEvent(beam::ProtoDUNEBeamEvent &beamEvent)
TrackTrajectory::Flags_t Flags_t
std::map< std::string, double > fParticleFracs
std::vector< double > fRandHUpstream
beam::FBM MakeFiberMonitor(double pos)
std::vector< int > fRandPDG
std::vector< short > active
std::map< std::string, double > fParticleNums
void SetFBMTrigger(std::string, FBM)
void BeamMonitorBasisVectors()
void SetCKov0(CKov theCKov)
double fOutputVDownstream
#define DEFINE_ART_MODULE(klass)
void SetMagnetCurrent(double theMagnetCurrent)
double UnsmearMomentum1D()
void RotateMonitorVector(TVector3 &vec)
A trajectory in space reconstructed from hits.
single particles thrown at the detector
std::vector< double > fRandMomentum
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
std::vector< Point_t > convertCollToPoint(std::vector< Point > const &coll)
void AddBeamTrack(recob::Track theTrack)
std::vector< std::string > fParticleTypes
std::string fInputFileName
void AddRecoBeamMomentum(double theMomentum)
std::map< std::string, TH1D * > fResolutionHists
std::array< short, 192 > fibers
void MakeTracks(beam::ProtoDUNEBeamEvent &beamEvent)
void Add(simb::MCParticle const &part)
std::vector< double > fRandVDownstream
std::string fResolutionFileName
double UnsmearMomentum2D()
std::map< std::string, THnSparseD * > fPDFs
void Convert(double input_point[5], std::vector< double > minima, std::vector< double > maxima, double output_point[5])
void produce(art::Event &e) override
void SetDownstreamTriggers(std::vector< size_t > theContent)
void GenerateTrueEvent(simb::MCTruth &mcTruth)
std::vector< double > fMaxima
TVector3 ConvertProfCoordinates(double x, double y, double z, double zOffset)
QTextStream & bin(QTextStream &s)
std::vector< double > fRandHDownstream
void SetUpstreamTriggers(std::vector< size_t > theContent)
std::array< short, 192 > glitch_mask
cet::LibraryManager dummy("noplugin")
std::map< int, std::string > fPDGToName
void SetT0(std::pair< double, double > theT0)
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
void SetCKov1(CKov theCKov)
double fOutputHDownstream
Event generator information.
void SetPositionAndMomentum(TLorentzVector &position, TLorentzVector &momentum)
def momentum(x1, x2, x3, scale=1.)
second_as<> second
Type of time stored in seconds, in double precision.
std::map< std::string, TH2D * > fResolutionHists2DPlus
void SetTOFs(std::vector< double > theContent)
PDSPDataDrivenBeam(fhicl::ParameterSet const &p)
double mean(sqlite3 *db, std::string const &table_name, std::string const &column_name)
void SetCalibrations(double TOFCalAA, double TOFCalBA, double TOFCalAB, double TOFCalBB)
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
std::map< std::string, TH2D * > fResolutionHists2DMinus
void SetTOFChans(std::vector< int > theContent)
QTextStream & endl(QTextStream &s)
void SetActiveTrigger(size_t theTrigger)