5 #ifndef CELLTREE_MODULE 6 #define CELLTREE_MODULE 50 #include "TDirectory.h" 53 #include "TClonesArray.h" 56 #include "TLorentzVector.h" 57 #include "TUnixSystem.h" 58 #include "TDatabasePDG.h" 59 #include "TObjArray.h" 60 #include "TTimeStamp.h" 69 #define MAX_TRACKS 30000 89 void print_vector(ostream& out, vector<double>& v, TString desc,
bool end=
false);
95 void processSpacePoint(
const art::Event&
event, TString option, ostream& out=cout);
98 void processMCTracks();
102 void InitProcessMap();
106 double KE(
float* momentum);
107 TString PDGName(
int pdg);
108 bool DumpMCJSON(
int id, ostream& out);
109 void DumpMCJSON(ostream& out=cout);
232 : EDAnalyzer(parameterSet)
234 dbPDG =
new TDatabasePDG();
273 TDirectory* tmpDir = gDirectory;
278 TNamed version(
"version",
"4.0");
282 TDirectory* subDir =
fOutFile->mkdir(
"Event");
284 fEventTree =
new TTree(
"Sim",
"Event Tree from Simulation");
297 fRaw_wf =
new TClonesArray(
"TH1F");
366 gSystem->MakeDirectory(
"bee");
367 gSystem->ChangeDirectory(
"bee");
368 gSystem->MakeDirectory(
"data");
385 TDirectory* tmpDir = gDirectory;
395 system(
"zip -r bee_upload data");
396 gSystem->ChangeDirectory(
"..");
410 fEvent =
event.id().event();
426 gSystem->MakeDirectory(TString::Format(
"data/%i",
entryNo).Data());
428 for (
int i=0; i<nSp; i++) {
431 std::ofstream out(jsonfile.Data());
440 std::ofstream out(jsonfile.Data());
486 for (
int j=0; j<4; j++) {
512 for (
int i=0; i<4; i++) {
531 std::vector< art::Ptr<raw::RawDigit> > wires;
537 for (
auto const& wire: wires) {
538 int chanId = wire->Channel();
541 int nSamples = wire->Samples();
542 std::vector<short> uncompressed(nSamples);
546 for (
int j=1; j<=nSamples; j++) {
547 h->SetBinContent(j, uncompressed[j-1]);
551 cout << nSamples <<
" samples expanding to " <<
nRawSamples << endl;
563 cout <<
"WARNING: no label " <<
fCalibLabel << endl;
566 std::vector< art::Ptr<recob::Wire> > wires;
574 for (
auto const& wire: wires) {
575 std::vector<float> calibwf = wire->Signal();
576 int chanId = wire->Channel();
580 h->SetBinContent(j, calibwf[j]);
594 cout <<
"WARNING: no label " <<
fOpHitLabel << endl;
597 std::vector<art::Ptr<recob::OpHit> > ophits;
601 for(
auto const& oh : ophits){
605 oh_pe.push_back(oh->PE());
618 std::vector<art::Ptr<recob::OpFlash> > flashes;
625 for(
auto const& flash: flashes){
626 of_t.push_back(flash->Time());
628 TH1F *h =
new ((*fPEperOpDet)[a]) TH1F(
"",
"",nOpDet,0,nOpDet);
631 for(
int i=0; i<nOpDet; ++i){
635 h->SetBinContent(i, flash->PE(i));
646 event.getByLabel(
"largeant", simChannelHandle);
649 for (
auto const& channel : (*simChannelHandle) ) {
650 auto channelNumber = channel.Channel();
655 auto const& timeSlices = channel.TDCIDEMap();
656 for (
auto const& timeSlice : timeSlices ) {
657 auto const& energyDeposits = timeSlice.second;
658 for (
auto const& energyDeposit : energyDeposits ) {
683 if (! event.
getByLabel(
"largeant", particleHandle))
return;
684 std::vector< art::Ptr<simb::MCParticle> > particles;
688 event.getByLabel(
"largeant", simChannelHandle);
695 for (
auto const& particle: particles ) {
700 if ( !(mctruth->
Origin() == 1 && particle->Mother() == 0) ) {
717 if (
mc_process[i] == 0) cout <<
"unknown process: " << particle->Process() << endl;
718 mc_id[i] = particle->TrackId();
719 mc_pdg[i] = particle->PdgCode();
723 int Ndaughters = particle->NumberDaughters();
724 vector<int> daughters;
725 for (
int i=0; i<Ndaughters; i++) {
726 daughters.push_back(particle->Daughter(i));
729 size_t numberTrajectoryPoints = particle->NumberTrajectoryPoints();
730 int last = numberTrajectoryPoints - 1;
731 const TLorentzVector& positionStart = particle->Position(0);
732 const TLorentzVector& positionEnd = particle->Position(last);
733 const TLorentzVector& momentumStart = particle->Momentum(0);
734 const TLorentzVector& momentumEnd = particle->Momentum(last);
741 TClonesArray *Lposition =
new TClonesArray(
"TLorentzVector", numberTrajectoryPoints);
743 for(
unsigned int j=0; j<numberTrajectoryPoints; j++) {
744 new ((*Lposition)[j]) TLorentzVector(particle->Position(j));
751 cout <<
"WARNING:: # tracks exceeded MAX_TRACKS " <<
MAX_TRACKS << endl;
760 event.getByLabel(
"generator",mctruthListHandle);
761 std::vector<art::Ptr<simb::MCTruth> > mclist;
765 if (mclist.size()>0) {
766 mctruth = mclist.at(0);
785 const TLorentzVector& position = nu.
Nu().
Position(0);
786 const TLorentzVector& momentum = nu.
Nu().
Momentum(0);
808 if (! event.
getByLabel(option.Data(), handle)) {
809 cout <<
"WARNING: no label " << option << endl;
812 std::vector< art::Ptr<recob::SpacePoint> > sps;
815 double x=0,
y=0,
z=0, q=0, nq=1;
816 vector<double> vx, vy, vz, vq, vnq;
818 for (
auto const& sp: sps ) {
830 out << fixed << setprecision(1);
833 out <<
'"' <<
"runNo" <<
'"' <<
":" <<
'"' <<
fRun <<
'"' <<
"," << endl;
834 out <<
'"' <<
"subRunNo" <<
'"' <<
":" <<
'"' <<
fSubRun <<
'"' <<
"," << endl;
835 out <<
'"' <<
"eventNo" <<
'"' <<
":" <<
'"' <<
fEvent <<
'"' <<
"," << endl;
838 if (geomName.Contains(
"35t")) { geomName =
"dune35t"; }
839 else if (geomName.Contains(
"protodune")) { geomName =
"protodune"; }
840 else if (geomName.Contains(
"workspace")) { geomName =
"dune10kt_workspace"; }
841 else { geomName =
"uboone"; }
842 out <<
'"' <<
"geom" <<
'"' <<
":" <<
'"' << geomName <<
'"' <<
"," << endl;
849 out << fixed << setprecision(0);
853 out <<
'"' <<
"type" <<
'"' <<
":" <<
'"' << option <<
'"' << endl;
862 out <<
'"' << desc <<
'"' <<
":[";
863 for (
int i=0; i<N; i++) {
870 if (!end) out <<
",";
892 vector<int> children;
894 for (
int j=0; j<nChildren; j++) {
903 vector<int> siblings;
907 siblings.push_back(j);
915 for (
int j=0; j<nSiblings; j++) {
928 std::vector<art::Ptr<raw::Trigger>> triggerlist;
935 if (triggerlist.size()){
953 if (!
KeepMC(i))
return false;
958 vector<int> saved_daughters;
959 for (
int j=0; j<nDaughter; j++) {
964 saved_daughters.push_back(daughter_id);
968 out << fixed << setprecision(1);
971 out <<
"\"id\":" <<
id <<
",";
972 out <<
"\"text\":" <<
"\"" <<
PDGName(
mc_pdg[i]) <<
" " << e <<
" MeV\",";
977 out <<
"\"children\":[";
978 int nSavedDaughter = saved_daughters.size();
979 if (nSavedDaughter == 0) {
981 out <<
"\"icon\":" <<
"\"jstree-file\"";
986 for (
int j=0; j<nSavedDaughter; j++) {
988 if (j!=nSavedDaughter-1) {
1002 vector<int> primaries;
1008 primaries.push_back(i);
1012 int size = primaries.size();
1014 for (
int i=0; i<size; i++) {
1026 TLorentzVector particle(momentum);
1027 return particle.E()-particle.M();
1034 double thresh_KE_em = 5.;
1035 double thresh_KE_np = 10;
1037 if (e>=thresh_KE_em)
return true;
1041 if (e>=thresh_KE_np)
return true;
1050 TParticlePDG *p =
dbPDG->GetParticle(pdg);
1053 int z = (pdg - 1e9) / 10000;
1054 int a = (pdg - 1e9 - z*1e4) / 10;
1056 if (z == 18) name =
"Ar";
1058 else if (z == 17) name =
"Cl";
1059 else if (z == 19) name =
"Ca";
1060 else if (z == 16) name =
"S";
1061 else if (z == 15) name =
"P";
1062 else if (z == 14) name =
"Si";
1063 else if (z == 1) name =
"H";
1064 else if (z == 2) name =
"He";
1066 else return Form(
"%i", pdg);
1067 return Form(
"%s-%i", name.Data(), a);
1069 return Form(
"%i", pdg);
1072 return p->GetName();
1079 cout <<
" Run/SubRun/Event: " <<
fRun <<
"/" <<
fSubRun <<
"/" <<
fEvent << endl;
1080 cout <<
" Ntracks:" <<
mc_Ntrack << endl;
1083 cout <<
"\n id: " <<
mc_id[i];
1084 cout <<
"\n pdg: " <<
mc_pdg[i];
1086 cout <<
"\n Ndaughters: " <<
mc_daughters.at(i).size();
1121 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.
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)
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
Provides recob::Track data product.
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