5 #ifndef CELLTREE_MODULE 6 #define CELLTREE_MODULE 51 #include "TDirectory.h" 54 #include "TClonesArray.h" 57 #include "TLorentzVector.h" 58 #include "TUnixSystem.h" 59 #include "TDatabasePDG.h" 60 #include "TObjArray.h" 61 #include "TTimeStamp.h" 70 #define MAX_TRACKS 30000 90 void print_vector(ostream& out, vector<double>& v, TString desc,
bool end=
false);
96 void processSpacePoint(
const art::Event&
event, TString option, ostream& out=cout);
99 void processMCTracks();
103 void InitProcessMap();
107 double KE(
float* momentum);
108 TString PDGName(
int pdg);
109 bool DumpMCJSON(
int id, ostream& out);
110 void DumpMCJSON(ostream& out=cout);
233 : EDAnalyzer(parameterSet)
235 dbPDG =
new TDatabasePDG();
274 TDirectory* tmpDir = gDirectory;
279 TNamed version(
"version",
"4.0");
283 TDirectory* subDir =
fOutFile->mkdir(
"Event");
285 fEventTree =
new TTree(
"Sim",
"Event Tree from Simulation");
298 fRaw_wf =
new TClonesArray(
"TH1F");
367 gSystem->MakeDirectory(
"bee");
368 gSystem->ChangeDirectory(
"bee");
369 gSystem->MakeDirectory(
"data");
386 TDirectory* tmpDir = gDirectory;
396 system(
"zip -r bee_upload data");
397 gSystem->ChangeDirectory(
"..");
411 fEvent =
event.id().event();
427 gSystem->MakeDirectory(TString::Format(
"data/%i",
entryNo).Data());
429 for (
int i=0; i<nSp; i++) {
432 std::ofstream out(jsonfile.Data());
441 std::ofstream out(jsonfile.Data());
487 for (
int j=0; j<4; j++) {
513 for (
int i=0; i<4; i++) {
532 std::vector< art::Ptr<raw::RawDigit> > wires;
538 for (
auto const& wire: wires) {
539 int chanId = wire->Channel();
542 int nSamples = wire->Samples();
543 std::vector<short> uncompressed(nSamples);
547 for (
int j=1; j<=nSamples; j++) {
548 h->SetBinContent(j, uncompressed[j-1]);
552 cout << nSamples <<
" samples expanding to " <<
nRawSamples << endl;
564 cout <<
"WARNING: no label " <<
fCalibLabel << endl;
567 std::vector< art::Ptr<recob::Wire> > wires;
575 for (
auto const& wire: wires) {
576 std::vector<float> calibwf = wire->Signal();
577 int chanId = wire->Channel();
581 h->SetBinContent(j, calibwf[j]);
595 cout <<
"WARNING: no label " <<
fOpHitLabel << endl;
598 std::vector<art::Ptr<recob::OpHit> > ophits;
602 for(
auto const& oh : ophits){
606 oh_pe.push_back(oh->PE());
619 std::vector<art::Ptr<recob::OpFlash> > flashes;
626 for(
auto const& flash: flashes){
627 of_t.push_back(flash->Time());
629 TH1F *h =
new ((*fPEperOpDet)[a]) TH1F(
"",
"",nOpDet,0,nOpDet);
632 for(
int i=0; i<nOpDet; ++i){
636 h->SetBinContent(i, flash->PE(i));
647 event.getByLabel(
"largeant", simChannelHandle);
650 for (
auto const& channel : (*simChannelHandle) ) {
651 auto channelNumber = channel.Channel();
656 auto const& timeSlices = channel.TDCIDEMap();
657 for (
auto const& timeSlice : timeSlices ) {
658 auto const& energyDeposits = timeSlice.second;
659 for (
auto const& energyDeposit : energyDeposits ) {
684 if (! event.
getByLabel(
"largeant", particleHandle))
return;
685 std::vector< art::Ptr<simb::MCParticle> > particles;
689 event.getByLabel(
"largeant", simChannelHandle);
696 for (
auto const& particle: particles ) {
701 if ( !(mctruth->
Origin() == 1 && particle->Mother() == 0) ) {
718 if (
mc_process[i] == 0) cout <<
"unknown process: " << particle->Process() << endl;
719 mc_id[i] = particle->TrackId();
720 mc_pdg[i] = particle->PdgCode();
724 int Ndaughters = particle->NumberDaughters();
725 vector<int> daughters;
726 for (
int i=0; i<Ndaughters; i++) {
727 daughters.push_back(particle->Daughter(i));
730 size_t numberTrajectoryPoints = particle->NumberTrajectoryPoints();
731 int last = numberTrajectoryPoints - 1;
732 const TLorentzVector& positionStart = particle->Position(0);
733 const TLorentzVector& positionEnd = particle->Position(last);
734 const TLorentzVector& momentumStart = particle->Momentum(0);
735 const TLorentzVector& momentumEnd = particle->Momentum(last);
742 TClonesArray *Lposition =
new TClonesArray(
"TLorentzVector", numberTrajectoryPoints);
744 for(
unsigned int j=0; j<numberTrajectoryPoints; j++) {
745 new ((*Lposition)[j]) TLorentzVector(particle->Position(j));
752 cout <<
"WARNING:: # tracks exceeded MAX_TRACKS " <<
MAX_TRACKS << endl;
761 event.getByLabel(
"generator",mctruthListHandle);
762 std::vector<art::Ptr<simb::MCTruth> > mclist;
766 if (mclist.size()>0) {
767 mctruth = mclist.at(0);
786 const TLorentzVector& position = nu.
Nu().
Position(0);
787 const TLorentzVector& momentum = nu.
Nu().
Momentum(0);
810 bool sp_exists =
event.getByLabel(option.Data(), sp_handle);
811 bool pc_exists =
event.getByLabel(option.Data(), pc_handle);
813 cout <<
"WARNING: no label " << option << endl;
816 std::vector< art::Ptr<recob::SpacePoint> > sps;
817 std::vector< art::Ptr<recob::PointCharge> > pcs;
821 if (sps.size() != pcs.size()) {
822 cout <<
"WARNING: SpacePoint and PointCharge length mismatch" << endl;
826 double x=0,
y=0,
z=0, q=0, nq=1;
827 vector<double> vx, vy, vz, vq, vnq;
829 for (uint i=0; i < sps.size(); i++ ) {
831 x = sps[i]->XYZ()[0];
832 y = sps[i]->XYZ()[1];
833 z = sps[i]->XYZ()[2];
834 if (pc_exists && pcs[i]->hasCharge()) {
835 q = pcs[i]->charge();
846 out << fixed << setprecision(1);
849 out <<
'"' <<
"runNo" <<
'"' <<
":" <<
'"' <<
fRun <<
'"' <<
"," << endl;
850 out <<
'"' <<
"subRunNo" <<
'"' <<
":" <<
'"' <<
fSubRun <<
'"' <<
"," << endl;
851 out <<
'"' <<
"eventNo" <<
'"' <<
":" <<
'"' <<
fEvent <<
'"' <<
"," << endl;
854 if (geomName.Contains(
"35t")) { geomName =
"dune35t"; }
855 else if (geomName.Contains(
"protodune")) { geomName =
"protodune"; }
856 else if (geomName.Contains(
"workspace")) { geomName =
"dune10kt_workspace"; }
857 else { geomName =
"uboone"; }
858 out <<
'"' <<
"geom" <<
'"' <<
":" <<
'"' << geomName <<
'"' <<
"," << endl;
865 out << fixed << setprecision(0);
869 out <<
'"' <<
"type" <<
'"' <<
":" <<
'"' << option <<
'"' << endl;
878 out <<
'"' << desc <<
'"' <<
":[";
879 for (
int i=0; i<N; i++) {
886 if (!end) out <<
",";
908 vector<int> children;
910 for (
int j=0; j<nChildren; j++) {
919 vector<int> siblings;
923 siblings.push_back(j);
931 for (
int j=0; j<nSiblings; j++) {
944 std::vector<art::Ptr<raw::Trigger>> triggerlist;
951 if (triggerlist.size()){
969 if (!
KeepMC(i))
return false;
974 vector<int> saved_daughters;
975 for (
int j=0; j<nDaughter; j++) {
980 saved_daughters.push_back(daughter_id);
984 out << fixed << setprecision(1);
987 out <<
"\"id\":" <<
id <<
",";
988 out <<
"\"text\":" <<
"\"" <<
PDGName(
mc_pdg[i]) <<
" " << e <<
" MeV\",";
993 out <<
"\"children\":[";
994 int nSavedDaughter = saved_daughters.size();
995 if (nSavedDaughter == 0) {
997 out <<
"\"icon\":" <<
"\"jstree-file\"";
1002 for (
int j=0; j<nSavedDaughter; j++) {
1004 if (j!=nSavedDaughter-1) {
1018 vector<int> primaries;
1024 primaries.push_back(i);
1028 int size = primaries.size();
1030 for (
int i=0; i<size; i++) {
1042 TLorentzVector particle(momentum);
1043 return particle.E()-particle.M();
1050 double thresh_KE_em = 5.;
1051 double thresh_KE_np = 10;
1053 if (e>=thresh_KE_em)
return true;
1057 if (e>=thresh_KE_np)
return true;
1066 TParticlePDG *p =
dbPDG->GetParticle(pdg);
1069 int z = (pdg - 1e9) / 10000;
1070 int a = (pdg - 1e9 - z*1e4) / 10;
1072 if (z == 18) name =
"Ar";
1074 else if (z == 17) name =
"Cl";
1075 else if (z == 19) name =
"Ca";
1076 else if (z == 16) name =
"S";
1077 else if (z == 15) name =
"P";
1078 else if (z == 14) name =
"Si";
1079 else if (z == 1) name =
"H";
1080 else if (z == 2) name =
"He";
1082 else return Form(
"%i", pdg);
1083 return Form(
"%s-%i", name.Data(), a);
1085 return Form(
"%i", pdg);
1088 return p->GetName();
1095 cout <<
" Run/SubRun/Event: " <<
fRun <<
"/" <<
fSubRun <<
"/" <<
fEvent << endl;
1096 cout <<
" Ntracks:" <<
mc_Ntrack << endl;
1099 cout <<
"\n id: " <<
mc_id[i];
1100 cout <<
"\n pdg: " <<
mc_pdg[i];
1102 cout <<
"\n Ndaughters: " <<
mc_daughters.at(i).size();
1137 processMap[
"CHIPSNuclearCaptureAtRest"] = 22;
float mc_startMomentum[MAX_TRACKS][4]
Store parameters for running LArG4.
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
void reconfigure(fhicl::ParameterSet const &pset)
float mc_endXYZT[MAX_TRACKS][4]
void processRaw(const art::Event &evt)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Declaration of signal hit object.
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)
std::string fRawDigitLabel
vector< float > fSIMIDE_x
bool DumpMCJSON(int id, ostream &out)
int mc_mother[MAX_TRACKS]
vector< unsigned short > fSIMIDE_tdc
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)
Provides recob::Track data product.
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
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
Declaration of cluster object.
unsigned int fTriggerbits
Definition of data types for geometry description.
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
art::ServiceHandle< geo::Geometry > fGeometry
void processCalib(const art::Event &evt)
Encapsulate the construction of a single detector plane.
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
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::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
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.
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