118118#include " sbnobj/Common/Trigger/ExtraTriggerInfo.h"
119119#include " sbnobj/Common/Reco/CRUMBSResult.h"
120120#include " sbnobj/Common/Reco/OpT0FinderResult.h"
121+ #include " sbnobj/SBND/CRT/CRTVeto.hh"
121122#include " sbnobj/Common/Reco/CorrectedOpFlashTiming.h"
122123#include " sbnobj/SBND/Timing/TimingInfo.hh"
123124#include " sbnobj/SBND/Timing/FrameShiftInfo.hh"
124125
125-
126126// GENIE
127127#include " Framework/EventGen/EventRecord.h"
128128#include " Framework/Ntuple/NtpMCEventRecord.h"
@@ -207,6 +207,8 @@ class CAFMaker : public art::EDProducer {
207207
208208 std::string fSourceFile ;
209209 std::uint32_t fSourceFileHash ;
210+
211+ bool fNewInputFile ;
210212
211213 bool fOverrideRealData ;
212214 bool fFirstInSubRun ;
@@ -224,6 +226,7 @@ class CAFMaker : public art::EDProducer {
224226 double fTotalEvents ;
225227 double fBlindEvents ;
226228 double fPrescaleEvents ;
229+ double fTotalGenEvents ;
227230 std::vector<caf::SRBNBInfo> fBNBInfo ; // /< Store detailed BNB info to save into the first StandardRecord of the output file
228231 std::vector<caf::SRNuMIInfo> fNuMIInfo ; // /< Store detailed NuMI info to save into the first StandardRecord of the output file
229232 std::map<unsigned int ,sbn::BNBSpillInfo> fBNBInfoEventMap ; // /< Store detailed BNB info to save for the particular spills of events
@@ -264,6 +267,8 @@ class CAFMaker : public art::EDProducer {
264267 double fGenieEvtRec_brEvtXSec = 0.0 ; // //< Cross section for selected event (1e-38 cm2)
265268 double fGenieEvtRec_brEvtDXSec = 0.0 ; // //< Cross section for selected event kinematics (1e-38 cm2 / {K^n})
266269 unsigned int fGenieEvtRec_brEvtKPS = 0 ; // //< Kinematic phase space variables. See $GENIE/src/Framework/Conventions/KinePhaseSpace.h -> KinePhaseSpace_t
270+ int fGenieEvtRec_brSctType = 0 ; // /< See [`genie::EScatteringType`](https://hep.ph.liv.ac.uk/~costasa/genie_doxygen/master/html/namespacegenie.html#ab97d2b4d1f37af8d967dadd15be88d0b)
271+ int fGenieEvtRec_brIntType = 0 ; // /< See [`genie::EInteractionType`](https://hep.ph.liv.ac.uk/~costasa/genie_doxygen/master/html/namespacegenie.html#a554f81bb9954c9e46bbabadfcd403111)
267272 double fGenieEvtRec_brEvtWght = 0.0 ; // //< Weight for that event
268273 double fGenieEvtRec_brEvtProb = 0.0 ; // //< Probability for that event (given cross section, path lengths, etc)
269274 double fGenieEvtRec_brEvtVtx [4 ] = {0.0 }; // //< Event vertex position in detector coord syst (SI)
@@ -783,6 +788,7 @@ void CAFMaker::respondToOpenInputFile(const art::FileBlock& fb) {
783788 // so should be less than or equal to 32-bit
784789 fSourceFileHash = static_cast <std::uint32_t >(fSourceFileHashFull );
785790
791+ fNewInputFile = true ;
786792}
787793
788794// ......................................................................
@@ -858,6 +864,18 @@ void CAFMaker::beginRun(art::Run& run) {
858864 fDet = override ;
859865 }
860866
867+ if (std::exchange (fNewInputFile , false )){
868+ for (const art::ProcessConfiguration &process: run.processHistory ()) {
869+ std::optional<fhicl::ParameterSet> gen_config = run.getProcessParameterSet (process.processName ());
870+ if (gen_config && gen_config->has_key (" source" ) && gen_config->has_key (" source.maxEvents" ) && gen_config->has_key (" source.module_type" ) ) {
871+ int max_events = gen_config->get <int >(" source.maxEvents" );
872+ std::string module_type = gen_config->get <std::string>(" source.module_type" );
873+ if (module_type == " EmptyEvent" ) {
874+ fTotalGenEvents += max_events;
875+ }
876+ }
877+ }
878+ }
861879
862880 if (fParams .SystWeightLabels ().empty ()) return ; // no need for globalTree
863881
@@ -1182,6 +1200,8 @@ void CAFMaker::InitializeOutfiles()
11821200 fFlatGenieTree ->Branch (" GenieEvtRec.EvtXSec" , &fGenieEvtRec_brEvtXSec , " GenieEvtRec.EvtXSec/D" );
11831201 fFlatGenieTree ->Branch (" GenieEvtRec.EvtDXSec" , &fGenieEvtRec_brEvtDXSec , " GenieEvtRec.EvtDXSec/D" );
11841202 fFlatGenieTree ->Branch (" GenieEvtRec.EvtKPS" , &fGenieEvtRec_brEvtKPS , " GenieEvtRec.EvtKPS/i" );
1203+ fFlatGenieTree ->Branch (" GenieEvtRec.SctType" , &fGenieEvtRec_brSctType , " GenieEvtRec.SctType/I" );
1204+ fFlatGenieTree ->Branch (" GenieEvtRec.IntType" , &fGenieEvtRec_brIntType , " GenieEvtRec.IntType/I" );
11851205 fFlatGenieTree ->Branch (" GenieEvtRec.EvtWght" , &fGenieEvtRec_brEvtWght , " GenieEvtRec.EvtWght/D" );
11861206 fFlatGenieTree ->Branch (" GenieEvtRec.EvtProb" , &fGenieEvtRec_brEvtProb , " GenieEvtRec.EvtProb/D" );
11871207 fFlatGenieTree ->Branch (" GenieEvtRec.EvtVtx" , fGenieEvtRec_brEvtVtx , " GenieEvtRec.EvtVtx[4]/D" );
@@ -1212,6 +1232,7 @@ void CAFMaker::InitializeOutfiles()
12121232 fTotalEvents = 0 ;
12131233 fBlindEvents = 0 ;
12141234 fPrescaleEvents = 0 ;
1235+ fTotalGenEvents = 0 ;
12151236 fIndexInFile = SRHeader::NoSourceIndex;
12161237 fFirstInSubRun = false ;
12171238 fFirstBlindInSubRun = false ;
@@ -1547,6 +1568,8 @@ void CAFMaker::produce(art::Event& evt) noexcept {
15471568 fGenieEvtRec_brEvtXSec = genie_rec->XSec () * (1e+38 /genie::units::cm2);
15481569 fGenieEvtRec_brEvtDXSec = genie_rec->DiffXSec () * (1e+38 /genie::units::cm2);
15491570 fGenieEvtRec_brEvtKPS = genie_rec->DiffXSecVars ();
1571+ fGenieEvtRec_brSctType = genie_rec->Summary ()->ProcInfo ().ScatteringTypeId ();
1572+ fGenieEvtRec_brIntType = genie_rec->Summary ()->ProcInfo ().InteractionTypeId ();
15501573 fGenieEvtRec_brEvtWght = genie_rec->Weight ();
15511574 fGenieEvtRec_brEvtProb = genie_rec->Probability ();
15521575 fGenieEvtRec_brEvtVtx [0 ] = genie_rec->Vertex ()->X ();
@@ -1713,6 +1736,7 @@ void CAFMaker::produce(art::Event& evt) noexcept {
17131736 std::vector<caf::SRCRTTrack> srcrttracks;
17141737 std::vector<caf::SRCRTSpacePoint> srcrtspacepoints;
17151738 std::vector<caf::SRSBNDCRTTrack> srsbndcrttracks;
1739+ caf::SRSBNDCRTVeto srsbndcrtveto;
17161740 caf::SRSBNDFrameShiftInfo srsbndframeshiftinfo;
17171741 caf::SRSBNDTimingInfo srsbndtiminginfo;
17181742 caf::SRSoftwareTrigger srsbndsofttrig;
@@ -1784,6 +1808,24 @@ void CAFMaker::produce(art::Event& evt) noexcept {
17841808 FillSBNDCRTTrack (sbndcrttracks[i], srsbndcrttracks.back ());
17851809 }
17861810 }
1811+
1812+ // Fill CRT Veto
1813+ art::Handle<std::vector<sbnd::crt::CRTVeto>> sbndcrtveto_handle;
1814+ GetByLabelStrict (evt, fParams .SBNDCRTVetoLabel (), sbndcrtveto_handle);
1815+ // fill into event
1816+ if (sbndcrtveto_handle.isValid ()) {
1817+ const std::vector<sbnd::crt::CRTVeto> &sbndcrtveto_vec = *sbndcrtveto_handle;
1818+ // Only one valid veto per event
1819+ if (sbndcrtveto_vec.size () == 1 ) {
1820+ // And associated SpacePoint objects
1821+ art::FindManyP<sbnd::crt::CRTSpacePoint> spAssoc (sbndcrtveto_handle, evt, fParams .SBNDCRTVetoLabel ());
1822+ if (spAssoc.isValid ()) {
1823+ // There is one vector of SpacePoints per Veto --> can be empty if no veto condition was satisfied
1824+ const std::vector<art::Ptr<sbnd::crt::CRTSpacePoint>>& veto_sp_v (spAssoc.at (0 ));
1825+ FillSBNDCRTVeto (sbndcrtveto_vec[0 ], veto_sp_v, srsbndcrtveto);
1826+ }
1827+ }
1828+ }
17871829
17881830 art::Handle<sbnd::timing::FrameShiftInfo> sbndframeshiftinfo_handle;
17891831 GetByLabelStrict (evt, fParams .SBNDFrameShiftInfoLabel (), sbndframeshiftinfo_handle);
@@ -2551,6 +2593,7 @@ void CAFMaker::produce(art::Event& evt) noexcept {
25512593 rec.ncrt_spacepoints = srcrtspacepoints.size ();
25522594 rec.sbnd_crt_tracks = srsbndcrttracks;
25532595 rec.nsbnd_crt_tracks = srsbndcrttracks.size ();
2596+ rec.sbnd_crt_veto = srsbndcrtveto;
25542597 rec.opflashes = srflashes;
25552598 rec.nopflashes = srflashes.size ();
25562599 rec.sbnd_frames = srsbndframeshiftinfo;
@@ -2781,11 +2824,11 @@ void CAFMaker::endSubRun(art::SubRun& sr) {
27812824// ......................................................................
27822825 void CAFMaker::AddHistogramsToFile (TFile* outfile,bool isBlindPOT = false , bool isPrescalePOT = false ) const
27832826{
2784-
27852827 outfile->cd ();
27862828
27872829 TH1 * hPOT = new TH1D (" TotalPOT" , " TotalPOT;; POT" , 1 , 0 , 1 );
27882830 TH1 * hEvents = new TH1D (" TotalEvents" , " TotalEvents;; Events" , 1 , 0 , 1 );
2831+ TH1 * hGen = new TH1D (" TotalGenEvents" , " TotalGenEvents;; Events" , 1 , 0 , 1 );
27892832
27902833 if (isBlindPOT) {
27912834 hPOT->Fill (0.5 ,fTotalPOT *(1 -(1 /fParams .PrescaleFactor ()))*GetBlindPOTScale ());
@@ -2797,13 +2840,15 @@ void CAFMaker::endSubRun(art::SubRun& sr) {
27972840 hPOT->Fill (0.5 ,fTotalPOT );
27982841 }
27992842 hEvents->Fill (0.5 ,fTotalEvents );
2843+ hGen->Fill (0.5 ,fTotalGenEvents );
28002844
28012845 hPOT->Write ();
28022846 hEvents->Write ();
2847+ hGen->Write ();
28032848
28042849 if (fParams .CreateBlindedCAF ()) {
28052850 TH1 *hBlindEvents = new TH1D (" BlindEvents" , " BlindEvents;; Events" , 1 , 0 , 1 );
2806- TH1 * hPrescaleEvents = new TH1D (" PrescaleEvents" , " PrescaleEvents;; Events" , 1 , 0 , 1 );
2851+ TH1 *hPrescaleEvents = new TH1D (" PrescaleEvents" , " PrescaleEvents;; Events" , 1 , 0 , 1 );
28072852 hBlindEvents->Fill (0.5 , fBlindEvents );
28082853 hPrescaleEvents->Fill (0.5 , fPrescaleEvents );
28092854 hBlindEvents->Write ();
@@ -2813,29 +2858,26 @@ void CAFMaker::endSubRun(art::SubRun& sr) {
28132858
28142859// ......................................................................
28152860void CAFMaker::endJob () {
2816- if (fTotalEvents == 0 ) {
28172861
2818- std::cerr << " No events processed in this file. Aborting rather than "
2819- " produce an empty CAF."
2862+ // Only produce empty recTree/GenieTree since it relies on non-zero art events.
2863+ // Still want to keep POT histograms.
2864+ if (fTotalEvents == 0 ) {
2865+ std::cerr << " No events processed in this file. Producing empty recTree/GenieTree."
28202866 << std::endl;
2821- // n.b. changed abort() to return so that eny exceptions thrown during startup
2822- // still get printed to the user by art
2823- return ;
28242867 }
28252868
2826-
2827-
28282869 if (fFile ){
2829-
28302870 AddHistogramsToFile (fFile );
2831- fRecTree ->SetDirectory (fFile );
2832- if (fGenieTree ){
2833- fGenieTree ->BuildIndex (" SourceFileHash" , " GENIEEntry" );
2834- fGenieTree ->SetDirectory (fFile );
2835- }
2836- if (fParams .CreateBlindedCAF ()) {
2837- fRecTreeb ->SetDirectory (fFileb );
2838- fRecTreep ->SetDirectory (fFilep );
2871+ if (fTotalEvents > 0 ) {
2872+ if (fGenieTree ){
2873+ fGenieTree ->BuildIndex (" SourceFileHash" , " GENIEEntry" );
2874+ fGenieTree ->SetDirectory (fFile );
2875+ }
2876+ fRecTree ->SetDirectory (fFile );
2877+ if (fParams .CreateBlindedCAF ()) {
2878+ fRecTreeb ->SetDirectory (fFileb );
2879+ fRecTreep ->SetDirectory (fFilep );
2880+ }
28392881 }
28402882 fFile ->cd ();
28412883 fFile ->Write ();
@@ -2851,17 +2893,19 @@ void CAFMaker::endJob() {
28512893 }
28522894
28532895 if (fFlatFile ){
2854-
28552896 AddHistogramsToFile (fFlatFile );
2856- fFlatTree ->SetDirectory (fFlatFile );
2857- if (fFlatGenieTree ){
2858- fFlatGenieTree ->BuildIndex (" SourceFileHash" , " GENIEEntry" );
2859- fFlatGenieTree ->SetDirectory (fFlatFile );
2860- }
2861- if (fParams .CreateBlindedCAF () && fFlatFileb ) {
2862- fFlatTreeb ->SetDirectory (fFlatFileb );
2863- fFlatTreep ->SetDirectory (fFlatFilep );
2897+ if (fTotalEvents > 0 ) {
2898+ if (fFlatGenieTree ){
2899+ fFlatGenieTree ->BuildIndex (" SourceFileHash" , " GENIEEntry" );
2900+ fFlatGenieTree ->SetDirectory (fFlatFile );
2901+ }
2902+ fFlatTree ->SetDirectory (fFlatFile );
2903+ if (fParams .CreateBlindedCAF () && fFlatFileb ) {
2904+ fFlatTreeb ->SetDirectory (fFlatFileb );
2905+ fFlatTreep ->SetDirectory (fFlatFilep );
2906+ }
28642907 }
2908+
28652909 fFlatFile ->cd ();
28662910 fFlatFile ->Write ();
28672911 if (fParams .CreateBlindedCAF ()) {
0 commit comments