27 #include "canvas/Persistency/Common/FindOneP.h" 34 #include "TDirectory.h" 36 #include "TClonesArray.h" 38 #include "TLorentzVector.h" 39 #include "TDatabasePDG.h" 40 #include "TObjArray.h" 42 #include "TTimeStamp.h" 49 #define MAX_TRACKS 30000 68 void print_vector(ostream& out, vector<double>& v, TString
desc,
bool end=
false);
74 void processSpacePoint(
const art::Event&
event, TString option, ostream& out=cout);
75 void processSpacePointTruthDepo(
const art::Event& event, TString option, ostream& out=cout);
78 void processMCTracks();
82 void InitProcessMap();
84 bool IsPrimary(
int i) {
return mc_mother[i] == 0 ; }
87 TString PDGName(
int pdg);
88 bool DumpMCJSON(
int id, ostream& out);
89 void DumpMCJSON(ostream& out=cout);
214 dbPDG =
new TDatabasePDG();
246 TDirectory* tmpDir = gDirectory;
251 TNamed
version(
"version",
"4.0");
255 TDirectory* subDir =
fOutFile->mkdir(
"Event");
257 fEventTree =
new TTree(
"Sim",
"Event Tree from Simulation");
270 fRaw_wf =
new TClonesArray(
"TH1F");
337 system(
"rm -rf bee");
338 gSystem->MakeDirectory(
"bee");
340 gSystem->MakeDirectory(
"bee/data");
349 TDirectory* tmpDir = gDirectory;
359 gSystem->ChangeDirectory(
"bee");
360 system(
"zip -r bee_upload data");
361 gSystem->ChangeDirectory(
"..");
375 fEvent =
event.id().event();
393 for (
int i=0; i<nSp; i++) {
396 std::ofstream out(jsonfile.Data());
410 std::ofstream out(jsonfile.Data());
456 for (
int j=0; j<4; j++) {
482 for (
int i=0; i<4; i++) {
501 std::vector< art::Ptr<raw::RawDigit> > wires;
507 for (
auto const& wire: wires) {
508 int chanId = wire->Channel();
511 int nSamples = wire->Samples();
512 std::vector<short> uncompressed(nSamples);
516 for (
int j=1; j<=nSamples; j++) {
517 h->SetBinContent(j, uncompressed[j-1]);
536 std::vector< art::Ptr<recob::Wire> > wires;
544 for (
auto const& wire: wires) {
545 std::vector<float> calibwf = wire->Signal();
546 int chanId = wire->Channel();
550 h->SetBinContent(j, calibwf[j]);
567 std::vector<art::Ptr<recob::OpHit> > ophits;
571 for(
auto const& oh : ophits){
575 oh_pe.push_back(oh->PE());
588 std::vector<art::Ptr<recob::OpFlash> > flashes;
595 for(
auto const& flash: flashes){
596 of_t.push_back(flash->Time());
598 TH1F *
h =
new ((*fPEperOpDet)[
a]) TH1F(
"",
"",nOpDet,0,nOpDet);
601 for(
int i=0; i<nOpDet; ++i){
605 h->SetBinContent(i, flash->PE(i));
624 for (
auto const&
channel : (*simChannelHandle) ) {
625 auto channelNumber =
channel.Channel();
630 auto const& timeSlices =
channel.TDCIDEMap();
631 for (
auto const& timeSlice : timeSlices ) {
632 auto const& energyDeposits = timeSlice.second;
633 for (
auto const& energyDeposit : energyDeposits ) {
658 if (! event.
getByLabel(
"largeant", particleHandle))
return;
659 std::vector< art::Ptr<simb::MCParticle> > particles;
663 event.getByLabel(
"largeant", simChannelHandle);
666 art::FindOneP<simb::MCTruth> fo(particleHandle, event,
"largeant");
670 for (
auto const& particle: particles ) {
675 if ( !(mctruth->
Origin() == 1 && particle->Mother() == 0) ) {
692 if (
mc_process[i] == 0) cout <<
"unknown process: " << particle->Process() <<
endl;
693 mc_id[i] = particle->TrackId();
694 mc_pdg[i] = particle->PdgCode();
698 int Ndaughters = particle->NumberDaughters();
699 vector<int> daughters;
700 for (
int i=0; i<Ndaughters; i++) {
701 daughters.push_back(particle->Daughter(i));
704 size_t numberTrajectoryPoints = particle->NumberTrajectoryPoints();
705 int last = numberTrajectoryPoints - 1;
706 const TLorentzVector& positionStart = particle->Position(0);
707 const TLorentzVector& positionEnd = particle->Position(last);
708 const TLorentzVector& momentumStart = particle->Momentum(0);
709 const TLorentzVector& momentumEnd = particle->Momentum(last);
716 TClonesArray *Lposition =
new TClonesArray(
"TLorentzVector", numberTrajectoryPoints);
718 for(
unsigned int j=0; j<numberTrajectoryPoints; j++) {
719 new ((*Lposition)[j]) TLorentzVector(particle->Position(j));
726 cout <<
"WARNING:: # tracks exceeded MAX_TRACKS " <<
MAX_TRACKS <<
endl;
735 event.getByLabel(
"generator",mctruthListHandle);
736 std::vector<art::Ptr<simb::MCTruth> > mclist;
740 if (mclist.size()>0) {
741 mctruth = mclist.at(0);
784 bool sp_exists =
event.getByLabel(option.Data(), sp_handle);
785 bool pc_exists =
event.getByLabel(option.Data(), pc_handle);
787 cout <<
"WARNING: no label " << option <<
endl;
790 std::vector< art::Ptr<recob::SpacePoint> > sps;
791 std::vector< art::Ptr<recob::PointCharge> > pcs;
795 if (sps.size() != pcs.size()) {
796 cout <<
"WARNING: SpacePoint and PointCharge length mismatch" <<
endl;
800 double x=0,
y=0,
z=0, q=0, nq=1;
801 vector<double> vx, vy, vz, vq, vnq;
803 for (
uint i=0; i < sps.size(); i++ ) {
805 x = sps[i]->XYZ()[0];
806 y = sps[i]->XYZ()[1];
807 z = sps[i]->XYZ()[2];
808 if (pc_exists && pcs[i]->hasCharge()) {
809 q = pcs[i]->charge();
823 out <<
'"' <<
"runNo" <<
'"' <<
":" <<
'"' <<
fRun <<
'"' <<
"," <<
endl;
824 out <<
'"' <<
"subRunNo" <<
'"' <<
":" <<
'"' <<
fSubRun <<
'"' <<
"," <<
endl;
825 out <<
'"' <<
"eventNo" <<
'"' <<
":" <<
'"' <<
fEvent <<
'"' <<
"," <<
endl;
828 if (geomName.Contains(
"35t")) { geomName =
"dune35t"; }
829 else if (geomName.Contains(
"protodune")) { geomName =
"protodune"; }
830 else if (geomName.Contains(
"workspace")) { geomName =
"dune10kt_workspace"; }
831 else if (geomName.Contains(
"icarus")) { geomName =
"icarus"; }
832 else { geomName =
"uboone"; }
833 out <<
'"' <<
"geom" <<
'"' <<
":" <<
'"' << geomName <<
'"' <<
"," <<
endl;
844 out <<
'"' <<
"type" <<
'"' <<
":" <<
'"' << option <<
'"' <<
endl;
857 std::vector< art::Ptr<sim::SimEnergyDeposit> > sed;
859 int size = sed.size();
860 double x=0,
y=0,
z=0, q=0, nq=1;
861 vector<double> vx, vy, vz, vq, vnq;
863 for (
int i=0; i <
size; i++ ) {
865 x = sed[i]->MidPointX();
866 y = sed[i]->MidPointY();
867 z = sed[i]->MidPointZ();
868 q = sed[i]->NumElectrons();
869 if (q<0) q = sed[i]->Energy()*25000;
871 if (q<1000)
continue;
882 out <<
'"' <<
"runNo" <<
'"' <<
":" <<
'"' <<
fRun <<
'"' <<
"," <<
endl;
883 out <<
'"' <<
"subRunNo" <<
'"' <<
":" <<
'"' <<
fSubRun <<
'"' <<
"," <<
endl;
884 out <<
'"' <<
"eventNo" <<
'"' <<
":" <<
'"' <<
fEvent <<
'"' <<
"," <<
endl;
887 if (geomName.Contains(
"35t")) { geomName =
"dune35t"; }
888 else if (geomName.Contains(
"protodune")) { geomName =
"protodune"; }
889 else if (geomName.Contains(
"workspace")) { geomName =
"dune10kt_workspace"; }
890 else if (geomName.Contains(
"icarus")) { geomName =
"icarus"; }
891 else { geomName =
"uboone"; }
892 out <<
'"' <<
"geom" <<
'"' <<
":" <<
'"' << geomName <<
'"' <<
"," <<
endl;
902 out <<
'"' <<
"type" <<
'"' <<
":" <<
'"' << option <<
'"' <<
endl;
911 out <<
'"' << desc <<
'"' <<
":[";
912 for (
int i=0; i<
N; i++) {
919 if (!end) out <<
",";
941 vector<int> children;
943 for (
int j=0; j<nChildren; j++) {
952 vector<int> siblings;
956 siblings.push_back(j);
964 for (
int j=0; j<nSiblings; j++) {
977 std::vector<art::Ptr<raw::Trigger>> triggerlist;
984 if (triggerlist.size()){
1002 if (!
KeepMC(i))
return false;
1007 vector<int> saved_daughters;
1008 for (
int j=0; j<nDaughter; j++) {
1013 saved_daughters.push_back(daughter_id);
1017 vector<double> vx, vy, vz;
1021 int nPoints = traj->GetEntries();
1023 for(
int j=0; j<nPoints; j++) {
1024 TLorentzVector*
pos = (TLorentzVector*)(*traj)[j];
1025 vx.push_back(pos->X());
1026 vy.push_back(pos->Y());
1027 vz.push_back(pos->Z());
1034 out <<
"\"id\":" <<
id <<
",";
1035 out <<
"\"text\":" <<
"\"" <<
PDGName(
mc_pdg[i]) <<
" " << e <<
" MeV\",";
1036 out <<
"\"data\":{";
1043 out <<
"\"children\":[";
1044 int nSavedDaughter = saved_daughters.size();
1045 if (nSavedDaughter == 0) {
1047 out <<
"\"icon\":" <<
"\"jstree-file\"";
1052 for (
int j=0; j<nSavedDaughter; j++) {
1054 if (j!=nSavedDaughter-1) {
1068 vector<int> primaries;
1074 primaries.push_back(i);
1078 int size = primaries.size();
1080 for (
int i=0; i<
size; i++) {
1092 TLorentzVector particle(momentum);
1093 return particle.E()-particle.M();
1100 double thresh_KE_em = 5.;
1101 double thresh_KE_np = 50;
1111 if (e>=thresh_KE_em)
return true;
1115 if (e>=thresh_KE_np)
return true;
1124 TParticlePDG *
p =
dbPDG->GetParticle(pdg);
1127 int z = (pdg - 1e9) / 10000;
1128 int a = (pdg - 1e9 - z*1e4) / 10;
1130 if (z == 18) name =
"Ar";
1132 else if (z == 17) name =
"Cl";
1133 else if (z == 19) name =
"Ca";
1134 else if (z == 16) name =
"S";
1135 else if (z == 15) name =
"P";
1136 else if (z == 14) name =
"Si";
1137 else if (z == 1) name =
"H";
1138 else if (z == 2) name =
"He";
1140 else return Form(
"%i", pdg);
1141 return Form(
"%s-%i", name.Data(),
a);
1143 return Form(
"%i", pdg);
1146 return p->GetName();
1157 cout <<
"\n id: " <<
mc_id[i];
1158 cout <<
"\n pdg: " <<
mc_pdg[i];
1160 cout <<
"\n Ndaughters: " <<
mc_daughters.at(i).size();
1195 processMap[
"CHIPSNuclearCaptureAtRest"] = 22;
def analyze(root, level, gtrees, gbranches, doprint)
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
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
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
void processSpacePointTruthDepo(const art::Event &event, TString option, ostream &out=cout)
double Pt() const
transverse momentum of interaction, in GeV/c
std::vector< std::vector< int > > trackSiblings
vector< int > of_multiplicity
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
Q_EXPORT QTSManip setprecision(int p)
art framework interface to geometry description
vector< float > fSIMIDE_x
bool DumpMCJSON(int id, ostream &out)
int mc_mother[MAX_TRACKS]
vector< unsigned short > fSIMIDE_tdc
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]
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
QTextStream & reset(QTextStream &s)
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
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
void processOpFlash(const art::Event &evt)
vector< double > oh_trigtime
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
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
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]
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
def momentum(x1, x2, x3, scale=1.)
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.
vector< float > of_peTotal
QTextStream & endl(QTextStream &s)
Event finding and building.
void processTrigger(const art::Event &evt)
std::vector< std::vector< int > > trackParents