25 #include "cetlib_except/exception.h" 39 #include "nurandom/RandomUtils/NuRandomService.h" 40 #include "art_root_io/TFileService.h" 46 #include "THnSparse.h" 49 #include <TLorentzVector.h> 50 #include <TDatabasePDG.h> 51 #include <TParticlePDG.h> 52 #include "CLHEP/Random/RandFlat.h" 58 class ProtoDUNETriggeredBeam;
93 BeamParticle(
int trackid,
int pdg,
int parentid,
float posX,
float posY,
float posZ,
float posT,
94 float momX,
float momY,
float momZ){
121 fHasInteracted =
false;
126 fHasInteracted =
false;
130 fParticlesFront.insert(std::make_pair(particle.
fTrackID,particle));
153 fTriggerEventID = trigID;
157 fOverlayEventIDs.push_back(overlayID);
190 const BeamParticle &beamParticle,
const int outputTrackID,
191 const float triggerParticleTime,
195 TLorentzVector &
momentum,
double sampledHUp,
196 double sampledVUp,
double sampledHDown,
197 double sampledVDown,
double sampledMomentum,
204 double sampledHUp,
double sampledVUp,
double sampledHDown,
205 double sampledVDown,
double sampledMomentum);
208 std::vector<double> minima,
209 std::vector<double> maxima,
210 double output_point[5]);
226 TVector3
ProjectToTPC(TVector3 firstPoint, TVector3 secondPoint);
313 std::vector<double>
fMinima = {0.8, 0., 0., 0., 0.};
314 std::vector<double>
fMaxima = {1.2, 192., 192., 192., 192.};
331 std::map<std::string, THnSparseD *>
fPDFs;
375 "HepJamesRandom", instanceName))
378 produces< std::vector<simb::MCTruth> >();
379 produces< sumdata::RunData, art::InRun >();
380 produces< std::vector< beam::ProtoDUNEBeamEvent > >();
410 if (
p.second.has_key(
"source"))
413 if (
p.second.has_key(
"source.skipEvents"))
415 fStartEvent +=
p.second.get<
int>(
"source.skipEvents");
423 if (
p.second.has_key(
"source"))
425 if (
p.second.has_key(
"source.firstEvent"))
427 int fe =
p.second.get<
int>(
"source.firstEvent") - 1;
428 if (fe > 0) fStartEvent += fe;
433 mf::LogInfo(
"ProtoDUNETriggeredBeam") <<
"Skip " << fStartEvent <<
" first events from the input file.";
438 fBeamX = pset.get<
float>(
"BeamX");
439 fBeamY = pset.get<
float>(
"BeamY");
440 fBeamZ = pset.get<
float>(
"BeamZ");
449 fTRIG2Pos = pset.get<
float>(
"TRIG2PosZ");
456 fL1 = pset.get<
float>(
"L1");
457 fL2 = pset.get<
float>(
"L2");
458 fL3 = pset.get<
float>(
"L3");
462 fLMag = pset.get<
float>(
"LMag");
463 fB = pset.get<
float>(
"B");
465 fLB = fB * fLMag * std::stod(fNominalP) / 7.;
469 fRNG = TRandom3(pset.get<
int>(
"Seed", 0));
470 fVerbose = pset.get<
bool>(
"Verbose",
false);
486 fSamplingFileName =
FindFile(fSamplingFileName);
489 fResolutionFileName =
FindFile(fResolutionFileName);
510 if(inputFile == 0x0){
516 if(frontFaceTree == 0x0){
527 TTree *trig1Tree = (TTree*)inputFile->Get(
fTRIG1TreeName.c_str());
528 TTree *trig2Tree = (TTree*)inputFile->Get(
fTRIG2TreeName.c_str());
532 std::cout <<
"Proto trigger list has " << triggeredEventIDs.size() <<
" events" <<
std::endl;
535 std::vector<std::string> otherInstrumentTreeNames;
543 for(
const std::string treeName : otherInstrumentTreeNames){
544 TTree *instrumentTree = (TTree*)inputFile->Get(treeName.c_str());
546 std::cout <<
" - Finished adding information from " << treeName <<
std::endl;
548 std::cout <<
"Final trigger list has " << triggeredEventIDs.size() <<
" events" <<
std::endl;
624 <<
" but tree only has entries 0 to " 629 auto truthcol = std::make_unique< std::vector<simb::MCTruth> >();
631 std::unique_ptr<std::vector<beam::ProtoDUNEBeamEvent> > beamData(
new std::vector<beam::ProtoDUNEBeamEvent>);
644 truthcol->push_back(truth);
649 beamData->push_back( beamEvent );
662 float eventID, trackID, pdgCode, parentID;
663 float posX, posY, posZ, posT;
664 float momX, momY, momZ;
666 frontFaceTree->SetBranchAddress(
"EventID",&eventID);
667 frontFaceTree->SetBranchAddress(
"TrackID",&trackID);
668 frontFaceTree->SetBranchAddress(
"PDGid",&pdgCode);
669 frontFaceTree->SetBranchAddress(
"ParentID",&parentID);
670 frontFaceTree->SetBranchAddress(
"x",&posX);
671 frontFaceTree->SetBranchAddress(
"y",&posY);
672 frontFaceTree->SetBranchAddress(
"z",&posZ);
673 frontFaceTree->SetBranchAddress(
"t",&posT);
674 frontFaceTree->SetBranchAddress(
"Px",&momX);
675 frontFaceTree->SetBranchAddress(
"Py",&momY);
676 frontFaceTree->SetBranchAddress(
"Pz",&momZ);
679 for(
unsigned int p = 0;
p < frontFaceTree->GetEntries(); ++
p){
681 frontFaceTree->GetEntry(
p);
684 const int intPdgCode =
static_cast<int>(pdgCode);
685 if(intPdgCode > 10000)
continue;
688 if(momZ < 0)
continue;
695 if(posX < -500 || posX > 500)
continue;
696 if(posY < -150 || posY > 850)
continue;
702 const int intEventID =
static_cast<int>(eventID);
703 const int intTrackID =
static_cast<int>(trackID);
704 const int intParentID=
static_cast<int>(parentID);
705 BeamParticle newParticle(intTrackID, intPdgCode, intParentID,
706 posX, posY, posZ, posT, momX, momY, momZ);
715 evIter->second.AddParticle(newParticle);
723 frontFaceTree->ResetBranchAddresses();
731 const std::vector<int> allowedPDGs = {11,-11,13,-13,211,-211,321,-321,2212};
733 float eventID, trackID, pdgCode, parentID;
734 float posX, posY, posZ, posT;
735 float momX, momY, momZ;
738 trig2Tree->SetBranchAddress(
"EventID",&eventID);
739 trig2Tree->SetBranchAddress(
"TrackID",&trackID);
740 trig2Tree->SetBranchAddress(
"PDGid",&pdgCode);
741 trig2Tree->SetBranchAddress(
"ParentID",&parentID);
742 trig2Tree->SetBranchAddress(
"x",&posX);
743 trig2Tree->SetBranchAddress(
"y",&posY);
744 trig2Tree->SetBranchAddress(
"z",&posZ);
745 trig2Tree->SetBranchAddress(
"t",&posT);
746 trig2Tree->SetBranchAddress(
"Px",&momX);
747 trig2Tree->SetBranchAddress(
"Py",&momY);
748 trig2Tree->SetBranchAddress(
"Pz",&momZ);
752 std::map<int,BeamParticle> trig2Particles;
754 for(
unsigned int p = 0;
p < trig2Tree->GetEntries(); ++
p){
756 trig2Tree->GetEntry(
p);
758 const int intEventID =
static_cast<int>(eventID);
764 if(trig2Particles.find(intEventID) != trig2Particles.end())
continue;
767 if(std::find(allowedPDGs.begin(),allowedPDGs.end(),
static_cast<int>(pdgCode))==allowedPDGs.end())
continue;
771 BeamParticle particle(static_cast<int>(trackID), static_cast<int>(pdgCode), static_cast<int>(parentID),
772 det_pos.X(), det_pos.Y(), det_pos.Z(), posT, momX, momY, momZ);
774 trig2Particles.insert(std::make_pair(intEventID,particle));
777 trig2Tree->ResetBranchAddresses();
780 trig1Tree->SetBranchAddress(
"EventID",&eventID);
781 trig1Tree->SetBranchAddress(
"TrackID",&trackID);
782 trig1Tree->SetBranchAddress(
"PDGid",&pdgCode);
783 trig1Tree->SetBranchAddress(
"ParentID",&parentID);
784 trig1Tree->SetBranchAddress(
"x",&posX);
785 trig1Tree->SetBranchAddress(
"y",&posY);
786 trig1Tree->SetBranchAddress(
"z",&posZ);
787 trig1Tree->SetBranchAddress(
"t",&posT);
788 trig1Tree->SetBranchAddress(
"Px",&momX);
789 trig1Tree->SetBranchAddress(
"Py",&momY);
790 trig1Tree->SetBranchAddress(
"Pz",&momZ);
792 std::map<int,BeamParticle> trig1Particles;
793 for(
unsigned int p = 0;
p < trig1Tree->GetEntries(); ++
p){
795 trig1Tree->GetEntry(
p);
796 const int intEventID =
static_cast<int>(eventID);
799 if(trig2Particles.find(intEventID) == trig2Particles.end())
continue;
801 if(std::find(allowedPDGs.begin(),allowedPDGs.end(),
static_cast<int>(pdgCode))==allowedPDGs.end())
continue;
803 BeamParticle particle(static_cast<int>(trackID), static_cast<int>(pdgCode), static_cast<int>(parentID),
804 posX, posY, posZ, posT, momX, momY, momZ);
805 trig1Particles.insert(std::make_pair(intEventID,particle));
812 std::vector<int> trigEventIDs;
813 for(
auto const &element : trig1Particles){
816 if((element.second.fTrackID != trig2Particles.at(element.first).fTrackID) &&
817 (element.second.fTrackID != trig2Particles.at(element.first).fParentID))
continue;
819 event.fTriggerID = trig2Particles.at(element.first).fTrackID;
820 event.fTriggeredParticleInfo.insert(std::make_pair(trig1TreeName,element.second));
821 event.fTriggeredParticleInfo.insert(std::make_pair(trig2TreeName,trig2Particles.at(element.first)));
823 bool isTriggerEvent =
false;
825 if(
event.fParticlesFront.find(
event.fTriggerID) ==
event.fParticlesFront.end()){
826 event.fHasInteracted =
true;
828 std::cout <<
"- Candidate event " << trigEventIDs.size() <<
" trigger particle of type " << trig2Particles.at(element.first).fPDG <<
" not at the front face... searching for children" <<
std::endl;
829 for(
const std::pair<int,BeamParticle> &partPair :
event.fParticlesFront){
830 if(partPair.second.fParentID ==
event.fTriggerID){
831 std::cout <<
" - Found child with PDG = " << partPair.second.fPDG <<
std::endl;
832 event.fSecondaryTrackIDs.push_back(partPair.first);
833 isTriggerEvent =
true;
838 isTriggerEvent =
true;
841 if(isTriggerEvent) trigEventIDs.push_back(element.first);
844 trig1Tree->ResetBranchAddresses();
853 float eventID, trackID, pdgCode, parentID;
854 float posX, posY, posZ, posT;
855 float momX, momY, momZ;
857 instrumentTree->SetBranchAddress(
"EventID",&eventID);
858 instrumentTree->SetBranchAddress(
"TrackID",&trackID);
859 instrumentTree->SetBranchAddress(
"PDGid",&pdgCode);
860 instrumentTree->SetBranchAddress(
"ParentID",&parentID);
861 instrumentTree->SetBranchAddress(
"x",&posX);
862 instrumentTree->SetBranchAddress(
"y",&posY);
863 instrumentTree->SetBranchAddress(
"z",&posZ);
864 instrumentTree->SetBranchAddress(
"t",&posT);
865 instrumentTree->SetBranchAddress(
"Px",&momX);
866 instrumentTree->SetBranchAddress(
"Py",&momY);
867 instrumentTree->SetBranchAddress(
"Pz",&momZ);
870 std::map<const int,std::vector<unsigned int>> triggerIndices;
871 std::map<const int,const bool> arePionDecays;
872 std::map<const int,const int> trig1TrackIDs;
873 std::map<const int,const int> trig2TrackIDs;
874 std::map<const int,bool> foundTrackInEvent;
875 for(
const int &trigEventID : eventIDs){
877 const int trig1TrackID =
event.fTriggeredParticleInfo.at(
"TRIG1").fTrackID;
878 const int trig2TrackID =
event.fTriggeredParticleInfo.at(
"TRIG2").fTrackID;
879 const int trig1TrackPDG =
event.fTriggeredParticleInfo.at(
"TRIG1").fPDG;
880 const int trig2TrackPDG =
event.fTriggeredParticleInfo.at(
"TRIG2").fPDG;
881 const bool isPionDecay = ((trig1TrackPDG==211) && (trig2TrackPDG==-13)) ||
882 ((trig1TrackPDG==-211) && (trig2TrackPDG==13));
884 arePionDecays.insert(std::make_pair(trigEventID,isPionDecay));
885 trig1TrackIDs.insert(std::make_pair(trigEventID,trig1TrackID));
886 trig2TrackIDs.insert(std::make_pair(trigEventID,trig2TrackID));
887 foundTrackInEvent.insert(std::make_pair(trigEventID,
false));
889 triggerIndices.insert(std::make_pair(trigEventID,std::vector<unsigned int>()));
894 treeName = treeName.substr(treeName.find(
"/")+1);
896 for(
unsigned int p = 0;
p < instrumentTree->GetEntries(); ++
p){
897 instrumentTree->GetEntry(
p);
899 const int thisEvent =
static_cast<int>(eventID);
900 if(std::find(eventIDs.begin(),eventIDs.end(),thisEvent)==eventIDs.end())
continue;
902 triggerIndices.at(thisEvent).push_back(
p);
903 const int thisParticle =
static_cast<int>(trackID);
904 if(trig2TrackIDs.at(thisEvent) == thisParticle){
905 BeamParticle particle(static_cast<int>(trackID), static_cast<int>(pdgCode), static_cast<int>(parentID),
906 posX, posY, posZ, posT, momX, momY, momZ);
907 fAllBeamEvents.at(thisEvent).fTriggeredParticleInfo.insert(std::make_pair(treeName,particle));
908 foundTrackInEvent.at(thisEvent) =
true;
913 for (
auto it = eventIDs.begin(); it != eventIDs.end();) {
915 if(foundTrackInEvent.at(ev)) {
921 for(
const unsigned int index : triggerIndices.at(ev)){
922 instrumentTree->GetEntry(
index);
923 const int thisEvent =
static_cast<int>(eventID);
924 const int thisParticle =
static_cast<int>(trackID);
925 if(trig1TrackIDs.at(thisEvent) == thisParticle){
926 BeamParticle particle(static_cast<int>(trackID), static_cast<int>(pdgCode), static_cast<int>(parentID),
927 posX, posY, posZ, posT, momX, momY, momZ);
928 fAllBeamEvents.at(thisEvent).fTriggeredParticleInfo.insert(std::make_pair(treeName,particle));
929 foundTrackInEvent.at(thisEvent) =
true;
935 if(foundTrackInEvent.at(ev)) {
940 const int parentTrack =
fAllBeamEvents.at(ev).fTriggeredParticleInfo.at(
"TRIG1").fParentID;
941 for(
const unsigned int index : triggerIndices.at(ev)){
942 instrumentTree->GetEntry(
index);
943 const int thisEvent =
static_cast<int>(eventID);
944 const int thisParticle =
static_cast<int>(trackID);
945 if(parentTrack == thisParticle){
946 BeamParticle particle(static_cast<int>(trackID), static_cast<int>(pdgCode), static_cast<int>(parentID),
947 posX, posY, posZ, posT, momX, momY, momZ);
948 fAllBeamEvents.at(thisEvent).fTriggeredParticleInfo.insert(std::make_pair(treeName,particle));
949 foundTrackInEvent.at(thisEvent) =
true;
956 if(foundTrackInEvent.at(ev) ==
false){
959 it = eventIDs.erase(it);
960 std::cout <<
"Issue found with event " << ev <<
". Removing it from the trigger list - " << eventIDs.size() <<
" remain" <<
std::endl;
974 instrumentTree->ResetBranchAddresses();
984 for(
int overlayID = trigEventID - (
fOverlays / 2); overlayID < trigEventID + (
fOverlays/2); ++overlayID){
990 return newTriggerEvent;
1005 int primaryStatus = 1;
1015 std::cout <<
"- Generating event with trigger particle type " << trigParticle.
fPDG <<
std::endl;
1018 const float triggerParticleTime = trigParticle.
fPosT;
1021 int trigOutputTrackID = -1*(mcTruth.
NParticles() + 1);
1026 triggerParticle =
BeamParticleToMCParticle(trigParticle, trigOutputTrackID, triggerParticleTime, primaryStatus,
"primary");
1030 std::cout <<
" - Created trigger particle using pure simulation" <<
std::endl;
1031 std::cout <<
" - Active? " << primaryStatus <<
std::endl;
1032 std::cout <<
" - Located at " << triggerParticle.
EndX() <<
" " <<
1033 triggerParticle.
EndY() <<
" " << triggerParticle.
EndZ() <<
1037 triggerParticle =
DataDrivenMCParticle(trigParticle, trigOutputTrackID, triggerParticleTime, beamEvent, primaryStatus,
"primary");
1038 std::cout <<
" - Created trigger particle using data driven method" <<
std::endl;
1039 std::cout <<
" - Located at " << triggerParticle.
EndX() <<
" " <<
1040 triggerParticle.
EndY() <<
" " << triggerParticle.
EndZ() <<
1046 std::vector<simb::MCParticle> secondaries;
1047 std::vector<int> secondary_pdgs;
1052 trigOutputTrackID = -1*(count + 2);
1055 secondary, trigOutputTrackID, triggerParticleTime+secondary.
fPosT, 1,
1057 secondaries.push_back(secondaryParticle);
1059 secondary_pdgs.push_back(secondary.
fPDG);
1065 if(!secondaries.empty()){
1066 std::cout <<
" - Trigger particle has daughters:";
1068 std::cout <<
" " << triggerParticle.
Daughter(i);
1078 mcTruth.
Add(triggerParticle);
1082 std::cout <<
" - Added secondary " << sec.TrackId() <<
1083 " of type " << sec.PdgCode() <<
" with process " <<
1085 " from interacting primary " << triggerParticle.
PdgCode() <<
1087 std::cout <<
" - Located at " << sec.EndX() <<
" " <<
1088 sec.EndY() <<
" " <<
1097 if(overlayEvent.
fTriggerEventID == eventID) baseTime = triggerParticleTime;
1099 for (std::pair<int,BeamParticle> element :
fAllBeamEvents.at(eventID).fParticlesFront){
1104 const int outputTrackID = -1*(mcTruth.
NParticles() + 1);
1108 mcTruth.
Add(backgroundParticle);
1120 simb::MCParticle newParticle(outputTrackID,beamParticle.
fPDG,process, motherID, -1.0, primaryStatus);
1123 const TLorentzVector
pos(beamParticle.
fPosX,beamParticle.
fPosY,beamParticle.
fPosZ,beamParticle.
fPosT - timeOffset);
1126 const TDatabasePDG* databasePDG = TDatabasePDG::Instance();
1127 const TParticlePDG* definition = databasePDG->GetParticle(beamParticle.
fPDG);
1128 const float mass = definition->Mass();
1129 const float energy = sqrt(mass*mass + TVector3(beamParticle.
fMomX,beamParticle.
fMomY,beamParticle.
fMomZ).Mag2());
1131 const TLorentzVector mom(beamParticle.
fMomX,beamParticle.
fMomY,beamParticle.
fMomZ,energy);
1141 const BeamParticle &beamParticle,
const int outputTrackID,
1145 simb::MCParticle newParticle(outputTrackID, pdg, process, -1, -1.0, primaryStatus);
1147 double kin_samples[5];
1149 bool sample_again =
true;
1151 double sampled_momentum = 0.;
1152 double sampled_h_upstream = 0.;
1153 double sampled_v_upstream = 0.;
1154 double sampled_h_downstream = 0.;
1155 double sampled_v_downstream = 0.;
1157 while (sample_again) {
1163 fRNG.RndmArray(5, &kin_samples[0]);
1164 pdf_check =
fRNG.Rndm();
1168 double kin_point[5];
1179 if (bin == -1)
continue;
1182 const double pdf_value =
fPDFs.at(
fPDGToName.at(pdg))->GetBinContent(bin);
1185 if (pdf_check <= pdf_value) {
1187 std::cout <<
"bin: " << bin <<
" PDF val: " << pdf_value <<
1189 std::cout << kin_samples[0] <<
" " << kin_samples[1] <<
" " <<
1190 kin_samples[2] <<
" " << kin_samples[3] <<
" " <<
1192 std::cout << kin_point[0] <<
" " << kin_point[1] <<
" " <<
1193 kin_point[2] <<
" " << kin_point[3] <<
" " <<
1199 sampled_momentum = kin_point[0];
1200 sampled_v_upstream = kin_point[1];
1201 sampled_h_upstream = kin_point[2];
1202 sampled_v_downstream = kin_point[3];
1203 sampled_h_downstream = kin_point[4];
1205 sample_again =
false;
1210 TLorentzVector
position(0, 0, 0, 0);
1211 TLorentzVector
momentum(0., 0., 0., 0.);
1213 sampled_v_upstream, sampled_h_downstream,
1214 sampled_v_downstream, sampled_momentum,
1219 sampled_v_upstream, sampled_h_downstream,
1220 sampled_v_downstream, sampled_momentum);
1239 double input_point[5], std::vector<double> minima,
1240 std::vector<double> maxima,
double output_point[5]) {
1241 for (
int i = 0; i < 5; ++i) {
1242 const double delta = maxima[i] - minima[i];
1243 output_point[i] = minima[i] + delta * input_point[i];
1249 double sampledVUp,
double sampledHDown,
double sampledVDown,
1250 double sampledMomentum,
int beamPDG) {
1252 const double upstreamX = 96. - sampledHUp;
1253 const double upstreamY = 96. - sampledVUp;
1254 const double downstreamX = 96. - sampledHDown;
1255 const double downstreamY = 96. - sampledVDown;
1263 TVector3 dR = (downstream_point - upstream_point).Unit();
1266 double deltaZ = (
fBeamZ - downstream_point.Z());
1267 double deltaX = (dR.X() / dR.Z()) * deltaZ;
1268 double deltaY = (dR.Y() / dR.Z()) * deltaZ;
1270 TVector3 generator_point = downstream_point +
1271 TVector3(deltaX, deltaY, deltaZ);
1274 position = TLorentzVector(generator_point, 0.);
1279 deltaX = (dR.X() / dR.Z()) * deltaZ;
1280 deltaY = (dR.Y() / dR.Z()) * deltaZ;
1282 TVector3 last_point = generator_point +
1283 TVector3(deltaX, deltaY, deltaZ);
1285 std::cout << last_point.X() <<
" " << last_point.Y() <<
" " <<
1289 double unsmeared_momentum = 0.;
1306 const TVector3 mom_vec = unsmeared_momentum*dR;
1310 const TDatabasePDG * dbPDG = TDatabasePDG::Instance();
1311 const TParticlePDG * def = dbPDG->GetParticle(beamPDG);
1312 const double mass = def->Mass();
1313 const double energy = sqrt(mass*mass + mom_vec.Mag2());
1316 momentum = TLorentzVector(mom_vec, energy);
1331 std::cout <<
"Using 2D Unsmear method" <<
std::endl;
1336 const int xBin = res->GetXaxis()->FindBin(momentum);
1338 std::cout <<
"Momentum & bin: " << momentum <<
" " <<
1342 double true_min = res->GetYaxis()->GetXmin();
1343 double true_max = res->GetYaxis()->GetXmax();
1344 for (
int i = 1; i <= res->GetNbinsY(); ++i) {
1345 if (res->GetBinContent(xBin, i) > 0.) {
1346 true_min = res->GetYaxis()->GetBinLowEdge(i);
1350 for (
int i = res->GetNbinsY(); i >= 1; --i) {
1351 if (res->GetBinContent(xBin, i) > 0.) {
1352 true_max = res->GetYaxis()->GetBinUpEdge(i);
1358 std::cout <<
"True min and max: " << true_min <<
" " << true_max <<
std::endl;
1360 double unsmeared_momentum = 0.;
1362 const double t =
fRNG.Uniform(true_min, true_max);
1363 const double pdf_check =
fRNG.Rndm();
1365 const int yBin = res->GetYaxis()->FindBin(t);
1366 const double pdf_value = res->GetBinContent(xBin, yBin);
1368 std::cout <<
"True mom & bin: " << t <<
" " << yBin <<
std::endl;
1369 std::cout <<
"Check & val: " << pdf_check <<
" " << pdf_value <<
1372 if (pdf_check < pdf_value) {
1373 unsmeared_momentum =
t;
1379 return unsmeared_momentum;
1383 const int &primary_pdg,
const std::vector<int> &secondary_pdgs) {
1385 if (primary_pdg == 2212) {
1386 return "protonInelastic";
1388 else if (primary_pdg == 211) {
1389 if (std::find(secondary_pdgs.begin(), secondary_pdgs.end(), -13) !=
1390 secondary_pdgs.end()) {
1394 return "pi+Inelastic";
1397 else if (primary_pdg == -211) {
1398 if (std::find(secondary_pdgs.begin(), secondary_pdgs.end(), 13) !=
1399 secondary_pdgs.end()) {
1403 return "pi-Inelastic";
1406 else if (primary_pdg == 321) {
1414 const int &primary_pdg,
const int &secondary_pdg) {
1417 if (primary_pdg == 2212) {
1418 return preamble +
"protonInelastic";
1420 else if (primary_pdg == 211) {
1421 if (secondary_pdg == -13) {
1422 return preamble +
"Decay";
1424 else if (secondary_pdg == 211 || secondary_pdg == -211 ||
1425 secondary_pdg == 2212 || secondary_pdg == 2112 ||
1426 secondary_pdg > 2212 || secondary_pdg == 22) {
1427 return preamble +
"pi+Inelastic";
1430 else if (primary_pdg == -211) {
1431 if (secondary_pdg == 13) {
1432 return preamble +
"Decay";
1434 else if (secondary_pdg == 211 || secondary_pdg == -211 ||
1435 secondary_pdg == 2212 || secondary_pdg == 2112 ||
1436 secondary_pdg > 2212 || secondary_pdg == 22) {
1437 return preamble +
"pi-Inelastic";
1440 else if (primary_pdg == 321) {
1441 return preamble +
"Decay";
1444 std::cout <<
"Notice! Unknown secondary option " << primary_pdg <<
" " <<
1446 return preamble +
"default";
1475 TH2D * this_hist = it->second;
1476 for (
int i = 1; i <= this_hist->GetNbinsX(); ++i) {
1477 const double integral = this_hist->TH1::Integral(i, i);
1479 for (
int j = 1; j <= this_hist->GetNbinsY(); ++j) {
1480 this_hist->SetBinContent(i, j,
1481 this_hist->GetBinContent(i, j) /
integral);
1482 total += this_hist->GetBinContent(i, j);
1523 std::vector<std::string> particle_types = {
1524 "Muons",
"Pions",
"Protons",
"Electrons" 1526 for (
size_t i = 0; i < particle_types.size(); ++i) {
1528 if (part_type ==
"Muons") {
1537 if (part_type ==
"Muons") {
1538 res_name =
"hPionsRes";
1541 res_name =
"h" + part_type +
"Res";
1561 std::vector<std::string> particle_types = {
1562 "Muons",
"Pions",
"Protons",
"Electrons",
"Kaons" 1565 for (
size_t i = 0; i < particle_types.size(); ++i) {
1567 if (part_type ==
"Muons") {
1570 else if (part_type ==
"Kaons") {
1579 if (part_type ==
"Muons") {
1580 res_name =
"hPionsRes";
1587 res_name =
"h" + part_type +
"Res";
1606 std::vector<std::string> particle_types = {
1607 "Muons",
"Pions",
"Protons",
"Electrons",
"Kaons" 1610 for (
size_t i = 0; i < particle_types.size(); ++i) {
1612 if (part_type ==
"Muons" || part_type ==
"Electrons") {
1621 if (part_type ==
"Muons") {
1622 res_name =
"hPionsRes";
1625 res_name =
"h" + part_type +
"Res";
1645 double sampledHUp,
double sampledVUp,
double sampledHDown,
1646 double sampledVDown,
double sampledMomentum) {
1648 beamEvent.
SetTOFs(std::vector<double>{0.});
1666 beamEvent.
SetT0(std::make_pair(0.,0.));
1674 const double upstream_x = sampledHUp;
1675 const double upstream_y = sampledVUp;
1676 const double downstream_x = sampledHDown;
1677 const double downstream_y = sampledVDown;
1696 fIFDH =
new ifdh_ns::ifdh;
1699 const char* ifdh_debug_env =
std::getenv(
"IFDH_DEBUG_LEVEL");
1700 if ( ifdh_debug_env )
1702 mf::LogInfo(
"ProtoDUNETriggeredBeam") <<
"IFDH_DEBUG_LEVEL: " << ifdh_debug_env<<
"\n";
1703 fIFDH->set_debug(ifdh_debug_env);
1706 const std::string path(gSystem->DirName(filename.c_str()));
1709 auto const flist =
fIFDH->findMatchingFiles(path,pattern);
1713 if (
stat(filename.c_str(), &buffer) != 0)
1715 throw cet::exception(
"ProtoDUNETriggeredBeam") <<
"No files returned for path:pattern: "<<path<<
":"<<pattern<<
std::endl;
1719 mf::LogInfo(
"ProtoDUNETriggeredBeam") <<
"For "<< filename <<
"\n";
1724 std::pair<std::string, long>
f =
flist.front();
1726 mf::LogInfo(
"ProtoDUNETriggeredBeam") <<
"For "<< filename <<
"\n";
1731 <<
"Fetching: " << f.first <<
" " << f.second <<
"\n";
1733 MF_LOG_DEBUG(
"ProtoDUNETriggeredBeam") <<
" Fetched; local path: " << fetchedfile;
1735 filename = fetchedfile;
1760 TVector3 momVec(px,py,pz);
1800 TLorentzVector
result(newX,newY,newZ,t);
1824 TVector3
result(newX/10., newY/10., newZ/10.);
1832 TVector3 newMom(px,py,pz);
1873 const TVector3 shiftedPos = pos - shiftLength*
dir;
1875 particle.
fPosX = shiftedPos.X();
1876 particle.
fPosY = shiftedPos.Y();
1877 particle.
fPosZ = shiftedPos.Z();
1897 beamevt.
SetTOFs(std::vector<double>{trig2Time - tof1Time});
1935 beamevt.
SetT0( std::make_pair(0.,0.) );
2053 const short f = 96 - short( floor(pos) ) - 1;
2055 theFBM.
active.push_back(f);
2064 return ((96 - fiber) - .5);
2077 const short fx1 = beamEvent.
GetFBM(
"XBPF022707" ).
active[0];
2078 const short fy1 = beamEvent.
GetFBM(
"XBPF022708" ).
active[0];
2085 const short fx2 = beamEvent.
GetFBM(
"XBPF022716" ).
active[0];
2086 const short fy2 = beamEvent.
GetFBM(
"XBPF022717" ).
active[0];
2093 std::vector< TVector3 > thePoints = { pos1, pos2,
ProjectToTPC( pos1, pos2 ) };
2094 std::vector< TVector3 > theMomenta = {
2095 ( pos2 - pos1 ).Unit(),
2096 ( pos2 - pos1 ).Unit(),
2097 ( pos2 - pos1 ).Unit()
2115 const TVector3 dR = (secondPoint - firstPoint);
2117 const double deltaZ = -1.*secondPoint.Z();
2118 const double deltaX = deltaZ * (dR.X() / dR.Z());
2119 const double deltaY = deltaZ * (dR.Y() / dR.Z());
2121 TVector3 lastPoint = secondPoint + TVector3(deltaX, deltaY, deltaZ);
2138 const double momentum = 299792458*
fLB/(1.E9 * acos(cos_theta));
2150 const double denomTerm1 = sqrt(
fL1*
fL1 + (a - x1)*(a - x1) );
2152 + TMath::Power( ( (
fL3 -
fL2) ),2) );
2153 const double denom = denomTerm1 * denomTerm2;
2155 const double cosTheta = numTerm/denom;
2163 mf::LogInfo(
"evgen::ProtoDUNETriggeredBeam::FindFile") <<
"File exists. Opening " <<
filename;
2173 mf::LogInfo(
"evgen::ProtoDUNETriggeredBeam::FindFile") <<
"File does not exist here. Searching FW_SEARCH_PATH";
2176 auto found = sp.find_file(filename, found_filename);
2181 mf::LogInfo(
"evgen::ProtoDUNETriggeredBeam::FindFile") <<
"Found file " << found_filename;
2189 return found_filename;
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
std::map< std::string, BeamParticle > fTriggeredParticleInfo
base_engine_t & createEngine(seed_t seed)
std::string GetSecondaryProcess(const int &primary_pdg, const int &secondary_pdg)
const FBM & GetFBM(std::string) const
void AddDaughter(const int trackID)
void MomentumSpectrometer(beam::ProtoDUNEBeamEvent &beamEvent)
void beginRun(art::Run &run) override
void AddTrajectoryPoint(TLorentzVector const &position, TLorentzVector const &momentum)
void AddOverlay(int overlayID)
std::map< std::string, THnSparseD * > fPDFs
void SetOrigin(simb::Origin_t origin)
void SetDataDrivenPosMom(TLorentzVector &position, TLorentzVector &momentum, double sampledHUp, double sampledVUp, double sampledHDown, double sampledVDown, double sampledMomentum, int beamPDG)
ROOT::Math::SMatrix< Double32_t, 5, 5, ROOT::Math::MatRepSym< Double32_t, 5 > > SMatrixSym55
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
void OpenInputFile(std::string &filename)
std::vector< Vector_t > convertCollToVector(std::vector< Vector > const &coll)
void SetTimingTrigger(int theTrigger)
EDProducer(fhicl::ParameterSet const &pset)
std::string fTRIG1TreeName
void ConvertSamplingPoint(double input_point[5], std::vector< double > minima, std::vector< double > maxima, double output_point[5])
double MomentumCosTheta(double, double, double)
std::string fTOF1TreeName
static collection_type const & get() noexcept
TrackTrajectory::Flags_t Flags_t
std::string FindFile(const std::string filename)
void SetDataDrivenBeamEvent(beam::ProtoDUNEBeamEvent &beamEvent, double sampledHUp, double sampledVUp, double sampledHDown, double sampledVDown, double sampledMomentum)
std::string fTRIG2TreeName
void BeamMonitorBasisVectors()
BeamParticle(int trackid, int pdg, int parentid, float posX, float posY, float posZ, float posT, float momX, float momY, float momZ)
simb::MCParticle BeamParticleToMCParticle(const BeamParticle &beamParticle, const int outputTrackID, const float triggerParticleTime, const int primaryStatus, const std::string process, const int motherID=-1)
ProtoDUNETriggeredBeam(fhicl::ParameterSet const &p)
simb::MCParticle DataDrivenMCParticle(const BeamParticle &beamParticle, const int outputTrackID, const float triggerParticleTime, beam::ProtoDUNEBeamEvent &beamEvent, const int primaryStatus, const std::string process)
OverlaidTriggerEvent GenerateOverlaidEvent(const int &trigEventID)
std::vector< short > active
int NumberDaughters() const
TVector3 ConvertBeamMonitorMomentumVec(float px, float py, float pz)
art framework interface to geometry description
void AddParticle(BeamParticle particle)
int Daughter(const int i) const
void FillParticleMaps(TTree *frontFaceTree)
void RotateMonitorVector(TVector3 &vec)
void SetFBMTrigger(std::string, FBM)
void SetCKov0(CKov theCKov)
#define DEFINE_ART_MODULE(klass)
void SetMagnetCurrent(double theMagnetCurrent)
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
double fOutputUnsmearedMomentum
std::string fNP04frontTreeName
A trajectory in space reconstructed from hits.
single particles thrown at the detector
std::string getenv(std::string const &name)
std::vector< int > fOverlayEventIDs
ProtoDUNETriggeredBeam & operator=(ProtoDUNETriggeredBeam const &)=delete
TVector3 ProjectToTPC(TVector3 firstPoint, TVector3 secondPoint)
std::string fSamplingFileName
std::map< int, BeamParticle > fParticlesFront
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
void FillInstrumentInformation(std::vector< int > &eventIDs, TTree *instrumentTree)
std::vector< int > fFinalTriggerEventIDs
std::vector< Point_t > convertCollToPoint(std::vector< Point > const &coll)
void GenerateTrueEvent(simb::MCTruth &mcTruth, const OverlaidTriggerEvent &overlayEvent, beam::ProtoDUNEBeamEvent &beamEvent)
std::string GetPrimaryEndProcess(const int &primary_pdg, const std::vector< int > &secondary_pdgs)
std::vector< int > fSecondaryTrackIDs
double UnsmearMomentum2D(double momentum, int pdg)
void AddBeamTrack(recob::Track theTrack)
beam::FBM MakeFiberMonitor(float pos)
std::map< std::string, TH2D * > fResolutionHists2D
void SetEndProcess(std::string s)
std::string fBPROFEXTTreeName
std::vector< double > fMinima
void AddRecoBeamMomentum(double theMomentum)
double GetPosition(short fiber)
void SetBeamEvent(beam::ProtoDUNEBeamEvent &beamevt, const BeamEvent &triggerEvent)
std::array< short, 192 > fibers
void Add(simb::MCParticle const &part)
void MakeTracks(beam::ProtoDUNEBeamEvent &beamEvent)
std::string fResolutionFileName
std::vector< int > FindTriggeredEvents(TTree *trig1Tree, TTree *trig2Tree)
double fOutputVDownstream
void SetDownstreamTriggers(std::vector< size_t > theContent)
double fOutputHDownstream
QTextStream & bin(QTextStream &s)
std::string fBPROF2TreeName
void SetUpstreamTriggers(std::vector< size_t > theContent)
void SetBackgroundPosition(BeamParticle &particle)
std::array< short, 192 > glitch_mask
std::map< int, std::string > fPDGToName
cet::LibraryManager dummy("noplugin")
EventNumber_t event() const
void CalculateNOverlays()
std::string fBaseFileName
void SetT0(std::pair< double, double > theT0)
bool file_exists(std::string const &qualified_filename)
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
void SetCKov1(CKov theCKov)
Event generator information.
std::string fBPROF3TreeName
~ProtoDUNETriggeredBeam()
OverlaidTriggerEvent(int trigID)
def momentum(x1, x2, x3, scale=1.)
std::map< int, BeamEvent > fAllBeamEvents
TVector3 ConvertProfCoordinates(double x, double y, double z, double zOffset)
void ConvertCoordinates(float &x, float &y, float &z)
LArSoft geometry interface.
std::vector< double > fMaxima
Event Generation using GENIE, cosmics or single particles.
void SetTOFs(std::vector< double > theContent)
void ConvertMomentum(float &px, float &py, float &pz)
std::string fBPROF4TreeName
std::string fBPROF1TreeName
TLorentzVector ConvertBeamMonitorCoordinates(float x, float y, float z, float t, float offset)
void SetCalibrations(double TOFCalAA, double TOFCalBA, double TOFCalAB, double TOFCalBB)
void produce(art::Event &e) override
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 SetTOFChans(std::vector< int > theContent)
std::vector< OverlaidTriggerEvent > fAllOverlaidTriggerEvents
QTextStream & endl(QTextStream &s)
Event finding and building.
bool fReduceNP04frontArea
void SetActiveTrigger(size_t theTrigger)