7 #include "art/Framework/Core/EDProducer.h"
8 #include "art/Framework/Core/ModuleMacros.h"
9 #include "art/Framework/Principal/Event.h"
10 #include "art/Framework/Principal/Handle.h"
11 #include "art/Framework/Principal/Run.h"
12 #include "art/Framework/Principal/SubRun.h"
13 #include "canvas/Utilities/InputTag.h"
14 #include "fhiclcpp/ParameterSet.h"
15 #include "messagefacility/MessageLogger/MessageLogger.h"
21 #include "artdaq-core/Data/Fragment.hh"
22 #include "sbndaq-artdaq-core/Overlays/ICARUS/ICARUSTriggerV2Fragment.hh"
28 #include "ifdh_art/IFBeamService/IFBeam_service.h"
49 void produce(art::Event&
e)
override;
64 std::unique_ptr<ifbeam_ns::BeamFolder>
bfp;
69 fTimePad(
p.get<
double>(
"TimePadding", 0.5)),
70 fBFPEpsilion(
p.get<
double>(
"BFPEpsilon", 0.02)),
71 raw_data_label_(
p.get<std::string>(
"raw_data_label")),
72 fDeviceUsedForTiming(
p.get<std::string>(
"DeviceUsedForTiming")),
73 bfp(ifbeam_handle->getBeamFolder(
p.get<std::string>(
"Bundle"),
p.get<std::string>(
"URL"),
p.get<
double>(
"TimeWindow")))
76 bfp->set_epsilon(fBFPEpsilion);
77 bfp->setValidWindow(500.);
78 produces<std::vector<sbn::NuMISpillInfo>, art::InSubRun>();
91 if (e.event() == 1)
return;
94 art::Handle< std::vector<artdaq::Fragment> > raw_data_ptr;
95 e.getByLabel(raw_data_label_,
"ICARUSTriggerV2", raw_data_ptr);
96 auto const & raw_data = (*raw_data_ptr);
98 double t_current_event = 0;
99 double t_previous_event = 0;
100 double number_of_gates_since_previous_event = 0;
102 for(
auto raw_datum : raw_data){
104 uint64_t artdaq_ts = raw_datum.timestamp();
105 icarus::ICARUSTriggerV2Fragment frag(raw_datum);
106 std::string data = frag.GetDataString();
107 char *buffer =
const_cast<char*
>(data.c_str());
108 icarus::ICARUSTriggerInfo datastream_info = icarus::parse_ICARUSTriggerV2String(buffer);
109 gate_type = datastream_info.gate_type;
110 number_of_gates_since_previous_event = frag.getDeltaGatesNuMI();
112 t_current_event =
static_cast<double>(artdaq_ts)/(1000000000.);
114 t_previous_event = (
static_cast<double>(frag.getLastTimestampNuMI()))/(1000000000.);
116 t_previous_event = (
static_cast<double>(frag.getLastTimestampOther()))/(1000000000.);
120 std::cout << std::setprecision(19) <<
"Previous : " << t_previous_event <<
", Current : " << t_current_event << std::endl;
126 TotalBeamSpills += number_of_gates_since_previous_event;
130 try{
auto cur_vec_temp = bfp->GetNamedVector((t_previous_event)-fTimePad,
"E:HP121[]");}
catch (WebAPIException &we) {}
132 try{
auto cur_vec_temp_2 = bfp->GetNamedVector((t_current_event)+fTimePad,
"E:VP121[]");}
catch (WebAPIException &we) {}
133 try{
auto packed_MTGTDS_temp = bfp->GetNamedVector((t_current_event)+fTimePad,
"E:MTGTDS[]");}
catch(WebAPIException &we) {}
134 std::vector<double> times_temps = bfp->GetTimeList(fDeviceUsedForTiming);
138 for (
size_t i = 0; i < times_temps.size(); i++) {
144 if(times_temps[i] > t_current_event){
continue;}
145 if(times_temps[i] <= t_previous_event){
continue;}
161 std::vector< double > HP121;
162 std::vector< double > VP121;
163 std::vector< double > HPTGT;
164 std::vector< double > VPTGT;
165 std::vector< double > HITGT;
166 std::vector< double > VITGT;
167 std::vector< double > MTGTDS;
168 double TRTGTD_time = -1.;
169 std::cout <<
"Grabbing IFBeam info!" << std::endl;
170 try{bfp->GetNamedData(times_temps[i],
"E:TRTGTD@",&TRTGTD,&TRTGTD_time);}
catch (WebAPIException &we) {
std::cout <<
"At time : " << times_temps[i] <<
" " <<
"got exception: " << we.what() <<
"\n";}
171 try{bfp->GetNamedData(times_temps[i],
"E:TR101D",&TR101D);}
catch (WebAPIException &we) {
std::cout <<
"At time : " << times_temps[i] <<
" " <<
"got exception: " << we.what() <<
"\n";}
172 try{bfp->GetNamedData(times_temps[i],
"E:HRNDIR",&HRNDIR);}
catch (WebAPIException &we) {
std::cout <<
"At time : " << times_temps[i] <<
" " <<
"got exception: " << we.what() <<
"\n";}
173 try{bfp->GetNamedData(times_temps[i],
"E:NSLINA",&NSLINA);}
catch (WebAPIException &we) {
std::cout <<
"At time : " << times_temps[i] <<
" " <<
"got exception: " << we.what() <<
"\n";}
174 try{bfp->GetNamedData(times_temps[i],
"E:NSLINB",&NSLINB);}
catch (WebAPIException &we) {
std::cout <<
"At time : " << times_temps[i] <<
" " <<
"got exception: " << we.what() <<
"\n";}
175 try{bfp->GetNamedData(times_temps[i],
"E:NSLINC",&NSLINC);}
catch (WebAPIException &we) {
std::cout <<
"At time : " << times_temps[i] <<
" " <<
"got exception: " << we.what() <<
"\n";}
176 try{bfp->GetNamedData(times_temps[i],
"E:NSLIND",&NSLIND);}
catch (WebAPIException &we) {
std::cout <<
"At time : " << times_temps[i] <<
" " <<
"got exception: " << we.what() <<
"\n";}
177 try{bfp->GetNamedData(times_temps[i],
"E:TOR101",&TOR101);}
catch (WebAPIException &we) {
std::cout <<
"At time : " << times_temps[i] <<
" " <<
"got exception: " << we.what() <<
"\n";}
178 try{bfp->GetNamedData(times_temps[i],
"E:TORTGT",&TORTGT);}
catch (WebAPIException &we) {
std::cout <<
"At time : " << times_temps[i] <<
" " <<
"got exception: " << we.what() <<
"\n";}
183 try{HP121 = bfp->GetNamedVector(times_temps[i],
"E:HP121[]");}
catch (WebAPIException &we) {
std::cout <<
"At time : " << times_temps[i] <<
" " <<
"got exception: " << we.what() <<
"\n";}
184 try{VP121 = bfp->GetNamedVector(times_temps[i],
"E:VP121[]");}
catch (WebAPIException &we) {
std::cout <<
"At time : " << times_temps[i] <<
" " <<
"got exception: " << we.what() <<
"\n";}
185 try{HPTGT = bfp->GetNamedVector(times_temps[i],
"E:HPTGT[]");}
catch (WebAPIException &we) {
std::cout <<
"At time : " << times_temps[i] <<
" " <<
"got exception: " << we.what() <<
"\n";}
186 try{VPTGT = bfp->GetNamedVector(times_temps[i],
"E:VPTGT[]");}
catch (WebAPIException &we) {
std::cout <<
"At time : " << times_temps[i] <<
" " <<
"got exception: " << we.what() <<
"\n";}
187 try{HITGT = bfp->GetNamedVector(times_temps[i],
"E:HITGT[]");}
catch (WebAPIException &we) {
std::cout <<
"At time : " << times_temps[i] <<
" " <<
"got exception: " << we.what() <<
"\n";}
188 try{VITGT = bfp->GetNamedVector(times_temps[i],
"E:VITGT[]");}
catch (WebAPIException &we) {
std::cout <<
"At time : " << times_temps[i] <<
" " <<
"got exception: " << we.what() <<
"\n";}
189 try{MTGTDS = bfp->GetNamedVector(times_temps[i],
"E:MTGTDS[]");}
catch (WebAPIException &we) {
std::cout <<
"At time : " << times_temps[i] <<
" " <<
"got exception: " << we.what() <<
"\n";}
191 std::cout <<
"Finished getting IFBeam info" << std::endl;
192 std::cout <<
"BFP Time: " << times_temps[i] <<
" TOROID Time: " << TRTGTD_time <<
" TOROID COUNT: " << TRTGTD << std::endl;
193 unsigned long int time_closest_int = (int) TRTGTD_time;
194 double time_closest_ns = (TRTGTD_time - time_closest_int)*1000000000;
197 NuMIbeamInfo.
TORTGT = TORTGT*1e12;
198 NuMIbeamInfo.
TOR101 = TOR101*1e12;
199 NuMIbeamInfo.
TRTGTD = TRTGTD*1e12;
200 NuMIbeamInfo.
TR101D = TR101D*1e12;
201 NuMIbeamInfo.
HRNDIR = HRNDIR;
202 NuMIbeamInfo.
NSLINA = NSLINA;
203 NuMIbeamInfo.
NSLINB = NSLINB;
204 NuMIbeamInfo.
NSLINC = NSLINC;
205 NuMIbeamInfo.
NSLIND = NSLIND;
207 NuMIbeamInfo.
HP121 = HP121;
208 NuMIbeamInfo.
VP121 = VP121;
209 NuMIbeamInfo.
HPTGT = HPTGT;
210 NuMIbeamInfo.
VPTGT = VPTGT;
211 NuMIbeamInfo.
HITGT = HITGT;
212 NuMIbeamInfo.
VITGT = VITGT;
213 NuMIbeamInfo.
MTGTDS = MTGTDS;
215 NuMIbeamInfo.
time = times_temps[i];
216 NuMIbeamInfo.
event = e.event();
220 if (spill_count == 1) {
221 NuMIbeamInfo.
daq_gates = number_of_gates_since_previous_event;
227 fOutbeamInfos.push_back(NuMIbeamInfo);
229 if(spill_count > number_of_gates_since_previous_event)
230 std::cout <<
"Event Spills : " << spill_count <<
", DAQ Spills : " << number_of_gates_since_previous_event <<
" \t \t ::: WRONG!"<< std::endl;
232 std::cout <<
"Event Spills : " << spill_count <<
", DAQ Spills : " << number_of_gates_since_previous_event << std::endl;
247 std::cout <<
"Total number of DAQ Spills : " << TotalBeamSpills << std::endl;
248 std::cout <<
"Total number of Selected Spills : " << fOutbeamInfos.size() << std::endl;
250 auto p = std::make_unique< std::vector< sbn::NuMISpillInfo > >(fOutbeamInfos);
252 sr.put(std::move(
p), art::subRunFragment());
255 fOutbeamInfos.clear();
float TOR101
Other monitored POT at Start.
std::vector< double > HP121
List of Horizontal position at start per-bunch.
void beginSubRun(art::SubRun &sr) override
void endSubRun(art::SubRun &sr) override
NuMIRetriever(fhicl::ParameterSet const &p)
NuMIRetriever & operator=(NuMIRetriever const &)=delete
float TR101D
Best monitored POT at Start.
float TRTGTD
Best monitored POT at Target.
float time
Time of device used to lookup spill.
std::vector< double > HPTGT
List of Horizontal position at target per-bunch.
std::unique_ptr< ifbeam_ns::BeamFolder > bfp
float TORTGT
Other monitored POT at Target.
Collection of exceptions for Geometry system.
unsigned long int spill_time_s
The IFDB Beam Spill Time, unit sec.
std::vector< double > VITGT
List of Vertical-Monitor intensity at tartget per bunch.
std::string fDeviceUsedForTiming
std::vector< double > MTGTDS
std::vector< double > HITGT
List of Horizontal-Monitor intensity at target per-bunch.
void produce(art::Event &e) override
unsigned long int spill_time_ns
The IFDB Beam Spill Time, unit nsec.
std::vector< sbn::NuMISpillInfo > fOutbeamInfos
Class defining a sparse vector (holes are zeroes)
std::vector< double > VP121
List of Vertical position at start per-bunch.
std::vector< double > VPTGT
List of Vertical position at target per-bunch.
BEGIN_PROLOG could also be cout
std::string raw_data_label_
art::ServiceHandle< ifbeam_ns::IFBeam > ifbeam_handle