32 #include "TClonesArray.h" 33 #include "TDatabasePDG.h" 34 #include "TDirectory.h" 37 #include "TLorentzVector.h" 38 #include "TObjArray.h" 41 #include "TTimeStamp.h" 49 #define MAX_TRACKS 30000 66 void print_vector(ostream& out, vector<double>& v, TString desc,
bool end =
false);
72 void processSpacePoint(
const art::Event&
event, TString option, ostream& out = cout);
73 void processSpacePointTruthDepo(
const art::Event& event,
76 bool t0_corrected =
true);
79 void processMCTracks();
83 void InitProcessMap();
87 double KE(
float* momentum);
88 TString PDGName(
int pdg);
89 bool DumpMCJSON(
int id, ostream& out);
90 void DumpMCJSON(ostream& out = cout);
214 dbPDG =
new TDatabasePDG();
248 TDirectory* tmpDir = gDirectory;
253 TNamed version(
"version",
"4.0");
257 TDirectory* subDir =
fOutFile->mkdir(
"Event");
259 fEventTree =
new TTree(
"Sim",
"Event Tree from Simulation");
272 fRaw_wf =
new TClonesArray(
"TH1F");
310 "mc_pdg", &
mc_pdg,
"mc_pdg[mc_Ntrack]/I");
314 "mc_process[mc_Ntrack]/I");
317 "mc_mother[mc_Ntrack]/I");
322 "mc_startXYZT[mc_Ntrack][4]/F");
326 "mc_endXYZT[mc_Ntrack][4]/F");
330 "mc_startMomentum[mc_Ntrack][4]/F");
334 "mc_endMomentum[mc_Ntrack][4]/F");
360 gSystem->MakeDirectory(
"bee");
362 gSystem->MakeDirectory(
"bee/data");
370 TDirectory* tmpDir = gDirectory;
380 gSystem->ChangeDirectory(
"bee");
381 system(
"zip -r bee_upload data");
382 gSystem->ChangeDirectory(
"..");
396 fEvent =
event.id().event();
412 gSystem->MakeDirectory(TString::Format(
"bee/data/%i",
entryNo).Data());
414 for (
int i = 0; i < nSp; i++) {
417 std::ofstream out(jsonfile.Data());
431 std::ofstream out(jsonfile.Data());
477 for (
int j = 0; j < 4; j++) {
503 for (
int i = 0; i < 4; i++) {
522 std::vector<art::Ptr<raw::RawDigit>> wires;
528 for (
auto const& wire : wires) {
529 int chanId = wire->Channel();
532 int nSamples = wire->Samples();
533 std::vector<short> uncompressed(nSamples);
537 for (
int j = 1; j <= nSamples; j++) {
538 h->SetBinContent(j, uncompressed[j - 1]);
541 if (i == 1) { cout << nSamples <<
" samples expanding to " <<
nRawSamples << endl; }
551 cout <<
"WARNING: no label " <<
fCalibLabel << endl;
554 std::vector<art::Ptr<recob::Wire>> wires;
562 for (
auto const& wire : wires) {
563 std::vector<float> calibwf = wire->Signal();
564 int chanId = wire->Channel();
568 h->SetBinContent(j, calibwf[j]);
581 cout <<
"WARNING: no label " <<
fOpHitLabel << endl;
584 std::vector<art::Ptr<recob::OpHit>> ophits;
588 for (
auto const& oh : ophits) {
592 oh_pe.push_back(oh->PE());
604 std::vector<art::Ptr<recob::OpFlash>> flashes;
611 for (
auto const& flash : flashes) {
612 of_t.push_back(flash->Time());
614 TH1F* h =
new ((*fPEperOpDet)[a]) TH1F(
"",
"", nOpDet, 0, nOpDet);
617 for (
int i = 0; i < nOpDet; ++i) {
619 h->SetBinContent(i, flash->PE(i));
638 for (
auto const& channel : (*simChannelHandle)) {
639 auto channelNumber = channel.Channel();
644 auto const& timeSlices = channel.TDCIDEMap();
645 for (
auto const& timeSlice : timeSlices) {
646 auto const& energyDeposits = timeSlice.second;
647 for (
auto const& energyDeposit : energyDeposits) {
669 if (!event.
getByLabel(
"largeant", particleHandle))
return;
670 std::vector<art::Ptr<simb::MCParticle>> particles;
674 event.getByLabel(
"largeant", simChannelHandle);
681 for (
auto const& particle : particles) {
686 if (!(mctruth->
Origin() == 1 && particle->Mother() == 0)) {
continue; }
701 if (
mc_process[i] == 0) cout <<
"unknown process: " << particle->Process() << endl;
702 mc_id[i] = particle->TrackId();
703 mc_pdg[i] = particle->PdgCode();
707 int Ndaughters = particle->NumberDaughters();
708 vector<int> daughters;
709 for (
int i = 0; i < Ndaughters; i++) {
710 daughters.push_back(particle->Daughter(i));
713 size_t numberTrajectoryPoints = particle->NumberTrajectoryPoints();
714 int last = numberTrajectoryPoints - 1;
715 const TLorentzVector& positionStart = particle->Position(0);
716 const TLorentzVector& positionEnd = particle->Position(last);
717 const TLorentzVector& momentumStart = particle->Momentum(0);
718 const TLorentzVector& momentumEnd = particle->Momentum(last);
725 TClonesArray* Lposition =
new TClonesArray(
"TLorentzVector", numberTrajectoryPoints);
727 for (
unsigned int j = 0; j < numberTrajectoryPoints; j++) {
728 new ((*Lposition)[j]) TLorentzVector(particle->Position(j));
735 cout <<
"WARNING:: # tracks exceeded MAX_TRACKS " <<
MAX_TRACKS << endl;
744 event.getByLabel(
"generator", mctruthListHandle);
745 std::vector<art::Ptr<simb::MCTruth>> mclist;
749 if (mclist.size() > 0) {
750 mctruth = mclist.at(0);
769 const TLorentzVector& position = nu.
Nu().
Position(0);
770 const TLorentzVector& momentum = nu.
Nu().
Momentum(0);
791 bool sp_exists =
event.getByLabel(option.Data(), sp_handle);
792 bool pc_exists =
event.getByLabel(option.Data(), pc_handle);
794 cout <<
"WARNING: no label " << option << endl;
797 std::vector<art::Ptr<recob::SpacePoint>> sps;
798 std::vector<art::Ptr<recob::PointCharge>> pcs;
802 if (sps.size() != pcs.size()) {
803 cout <<
"WARNING: SpacePoint and PointCharge length mismatch" << endl;
807 double x = 0,
y = 0,
z = 0, q = 0, nq = 1;
808 vector<double> vx, vy, vz, vq, vnq;
810 for (uint i = 0; i < sps.size(); i++) {
812 x = sps[i]->XYZ()[0];
813 y = sps[i]->XYZ()[1];
814 z = sps[i]->XYZ()[2];
815 if (pc_exists && pcs[i]->hasCharge()) { q = pcs[i]->charge(); }
826 out << fixed << setprecision(1);
829 out <<
'"' <<
"runNo" <<
'"' <<
":" <<
'"' <<
fRun <<
'"' <<
"," << endl;
830 out <<
'"' <<
"subRunNo" <<
'"' <<
":" <<
'"' <<
fSubRun <<
'"' <<
"," << endl;
831 out <<
'"' <<
"eventNo" <<
'"' <<
":" <<
'"' <<
fEvent <<
'"' <<
"," << endl;
834 if (geomName.Contains(
"35t")) { geomName =
"dune35t"; }
835 else if (geomName.Contains(
"protodunevd")) {
836 geomName =
"protodunevd";
838 else if (geomName.Contains(
"protodune")) {
839 geomName =
"protodune";
841 else if (geomName.Contains(
"workspace")) {
842 geomName =
"dune10kt_workspace";
844 else if (geomName.Contains(
"icarus")) {
847 else if (geomName.Contains(
"sbnd")) {
853 out <<
'"' <<
"geom" <<
'"' <<
":" <<
'"' << geomName <<
'"' <<
"," << endl;
859 out << fixed << setprecision(0);
863 out <<
'"' <<
"type" <<
'"' <<
":" <<
'"' << option <<
'"' << endl;
879 std::vector<art::Ptr<sim::SimEnergyDeposit>> sed;
881 int size = sed.size();
882 double t = 0,
x = 0,
y = 0,
z = 0, q = 0, nq = 1, cluster_id = 1;
883 vector<double> vx, vy, vz, vq, vnq, vcluster;
886 if (geomName.Contains(
"35t")) { geomName =
"dune35t"; }
887 else if (geomName.Contains(
"protodunevd")) {
888 geomName =
"protodunevd";
890 else if (geomName.Contains(
"protodune")) {
891 geomName =
"protodune";
893 else if (geomName.Contains(
"workspace")) {
894 geomName =
"dune10kt_workspace";
896 else if (geomName.Contains(
"icarus")) {
899 else if (geomName.Contains(
"sbnd")) {
906 for (
int i = 0; i <
size; i++) {
908 x = sed[i]->MidPointX();
910 y = sed[i]->MidPointY();
911 z = sed[i]->MidPointZ();
912 q = sed[i]->NumElectrons();
913 if (q < 0) q = sed[i]->Energy() * 25000;
915 if (q < 1000)
continue;
917 if (geomName ==
"sbnd") {
929 if (t * 1
e-3 > 0 && t * 1
e-3 < 5) cluster_id = 0;
931 else if (geomName ==
"uboone") {
935 cout <<
"t0 uncorrection for drift volume(s) yet to be added for " << geomName << endl;
943 vcluster.push_back(cluster_id);
946 out << fixed << setprecision(1);
949 out <<
'"' <<
"runNo" <<
'"' <<
":" <<
'"' <<
fRun <<
'"' <<
"," << endl;
950 out <<
'"' <<
"subRunNo" <<
'"' <<
":" <<
'"' <<
fSubRun <<
'"' <<
"," << endl;
951 out <<
'"' <<
"eventNo" <<
'"' <<
":" <<
'"' <<
fEvent <<
'"' <<
"," << endl;
953 out <<
'"' <<
"geom" <<
'"' <<
":" <<
'"' << geomName <<
'"' <<
"," << endl;
959 out << fixed << setprecision(0);
964 out <<
'"' <<
"type" <<
'"' <<
":" <<
'"' << option <<
'"' << endl;
973 out <<
'"' << desc <<
'"' <<
":[";
974 for (
int i = 0; i < N; i++) {
976 if (i != N - 1) { out <<
","; }
979 if (!end) out <<
",";
999 vector<int> children;
1001 for (
int j = 0; j < nChildren; j++) {
1009 vector<int> siblings;
1012 if (
IsPrimary(j)) { siblings.push_back(j); }
1019 for (
int j = 0; j < nSiblings; j++) {
1031 std::vector<art::Ptr<raw::Trigger>> triggerlist;
1036 cout <<
"WARNING: no trigger label " <<
fTriggerLabel << endl;
1038 if (triggerlist.size()) {
1056 if (!
KeepMC(i))
return false;
1061 vector<int> saved_daughters;
1062 for (
int j = 0; j < nDaughter; j++) {
1066 if (
KeepMC(
trackIndex[daughter_id])) { saved_daughters.push_back(daughter_id); }
1069 vector<double> vx, vy, vz;
1073 int nPoints = traj->GetEntries();
1075 for (
int j = 0; j < nPoints; j++) {
1076 TLorentzVector* pos = (TLorentzVector*)(*traj)[j];
1077 vx.push_back(pos->X());
1078 vy.push_back(pos->Y());
1079 vz.push_back(pos->Z());
1083 out << fixed << setprecision(1);
1086 out <<
"\"id\":" <<
id <<
",";
1089 out <<
"\"data\":{";
1098 out <<
"\"children\":[";
1099 int nSavedDaughter = saved_daughters.size();
1100 if (nSavedDaughter == 0) {
1103 <<
"\"jstree-file\"";
1108 for (
int j = 0; j < nSavedDaughter; j++) {
1110 if (j != nSavedDaughter - 1) { out <<
","; }
1122 vector<int> primaries;
1127 if (
KeepMC(i)) { primaries.push_back(i); }
1130 int size = primaries.size();
1132 for (
int i = 0; i <
size; i++) {
1133 if (
DumpMCJSON(
mc_id[primaries[i]], out) && i != size - 1) { out <<
", "; }
1142 TLorentzVector particle(momentum);
1143 return particle.E() - particle.M();
1150 double thresh_KE_em = 5.;
1151 double thresh_KE_np = 50;
1161 if (e >= thresh_KE_em)
1167 if (e >= thresh_KE_np)
1178 TParticlePDG* p =
dbPDG->GetParticle(pdg);
1181 int z = (pdg - 1e9) / 10000;
1182 int a = (pdg - 1e9 - z * 1e4) / 10;
1203 return Form(
"%i", pdg);
1204 return Form(
"%s-%i", name.Data(), a);
1206 return Form(
"%i", pdg);
1209 return p->GetName();
1216 cout <<
" Run/SubRun/Event: " <<
fRun <<
"/" <<
fSubRun <<
"/" <<
fEvent << endl;
1217 cout <<
" Ntracks:" <<
mc_Ntrack << endl;
1220 cout <<
"\n id: " <<
mc_id[i];
1221 cout <<
"\n pdg: " <<
mc_pdg[i];
1223 cout <<
"\n Ndaughters: " <<
mc_daughters.at(i).size();
1262 processMap[
"CHIPSNuclearCaptureAtRest"] = 22;
float mc_startMomentum[MAX_TRACKS][4]
std::vector< std::vector< int > > trackChildren
vector< int > fSIMIDE_channelIdY
const TLorentzVector & Position(const int i=0) const
constexpr std::uint32_t timeLow() const
double Theta() const
angle between incoming and outgoing leptons, in radians
const simb::MCNeutrino & GetNeutrino() const
system("rm -rf microbeam.root")
std::map< int, int > trackIndex
vector< int > fSIMIDE_trackId
std::string fSimChannelLabel
float mc_endXYZT[MAX_TRACKS][4]
void processRaw(const art::Event &evt)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
const simb::MCParticle & Nu() const
constexpr std::uint32_t timeHigh() const
simb::Origin_t Origin() const
double Pt() const
transverse momentum of interaction, in GeV/c
std::vector< std::vector< int > > trackSiblings
vector< int > of_multiplicity
Definition of basic raw digits.
Information about charge reconstructed in the active volume.
vector< float > fSIMIDE_y
void processSimChannel(const art::Event &evt)
art::ServiceHandle< geo::Geometry const > fGeometry
std::string fRawDigitLabel
vector< float > fSIMIDE_x
bool DumpMCJSON(int id, ostream &out)
int mc_mother[MAX_TRACKS]
vector< unsigned short > fSIMIDE_tdc
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
std::map< int, int > savedMCTrackIdMap
float mc_endMomentum[MAX_TRACKS][4]
std::string fOpFlashLabel
int InteractionType() const
int mc_process[MAX_TRACKS]
void analyze(const art::Event &evt)
void print_vector(ostream &out, vector< double > &v, TString desc, bool end=false)
#define DEFINE_ART_MODULE(klass)
vector< double > oh_bgtime
void processOpFlash(const art::Event &evt)
vector< double > oh_trigtime
Collect all the RawData header files together.
T get(std::string const &key) const
TObjArray * fMC_trackPosition
std::vector< int > fRaw_channelId
vector< float > fSIMIDE_z
unsigned int fTriggerbits
std::string fSimEnergyDepositLabel
void processOpHit(const art::Event &evt)
std::vector< std::vector< int > > mc_daughters
void beginRun(const art::Run &run)
unsigned int NOpDets() const
Number of OpDets in the whole detector.
unsigned int fTriggernumber
double KE(float *momentum)
std::vector< int > fCalib_channelId
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
void processCalib(const art::Event &evt)
contains information for a single step in the detector simulation
void processMC(const art::Event &evt)
std::vector< std::string > fSpacePointLabels
const TLorentzVector & Momentum(const int i=0) const
object containing MC truth information necessary for making RawDigits and doing back tracking ...
TClonesArray * fPEperOpDet
vector< float > fSIMIDE_numElectrons
std::string fTriggerLabel
std::map< std::string, int > processMap
Declaration of basic channel signal object.
float mc_startXYZT[MAX_TRACKS][4]
std::string const & DetectorName() const
Returns a string with the name of the detector, as configured.
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
void processSpacePoint(const art::Event &event, TString option, ostream &out=cout)
Event generator information.
void processSpacePointTruthDepo(const art::Event &event, TString option, ostream &out=cout, bool t0_corrected=true)
vector< float > of_peTotal
art framework interface to geometry description
Event finding and building.
void processTrigger(const art::Event &evt)
std::vector< std::vector< int > > trackParents