12 #include "art/Framework/Core/EDProducer.h"
13 #include "art/Framework/Core/ModuleMacros.h"
14 #include "art/Framework/Principal/Event.h"
15 #include "art/Framework/Principal/Handle.h"
16 #include "art/Framework/Principal/Run.h"
17 #include "art/Framework/Principal/SubRun.h"
18 #include "canvas/Utilities/InputTag.h"
19 #include "canvas/Persistency/Common/FindManyP.h"
20 #include "canvas/Persistency/Common/Ptr.h"
21 #include "canvas/Persistency/Common/PtrVector.h"
22 #include "fhiclcpp/ParameterSet.h"
23 #include "messagefacility/MessageLogger/MessageLogger.h"
24 #include "art_root_io/TFileService.h"
25 #include "art/Persistency/Common/PtrMaker.h"
64 void produce(art::Event &
e)
override;
82 void vmanip(vector<float> v,
float* ave,
float* rms);
105 float b,
float c,
float d,
float e,
float f,
float g,
116 : EDProducer{p}, trackAlg(
p.get<fhicl::ParameterSet>(
"TrackAlg"))
119 fDataLabelHits =
p.get<
string>(
"DataLabelHits");
121 fStoreTrack =
p.get<
int> (
"StoreTrack");
122 fTrackMethodType =
p.get<
int> (
"TrackMethodType");
123 fUseTopPlane =
p.get<
bool> (
"UseTopPlane");
126 if(fStoreTrack == 1){
127 produces< vector<sbn::crt::CRTTrack> >();
128 produces< art::Assns<sbn::crt::CRTTrack , sbn::crt::CRTHit> >();
141 std::unique_ptr<vector<sbn::crt::CRTTrack> > CRTTrackCol(
new vector<sbn::crt::CRTTrack>);
142 std::unique_ptr< art::Assns<sbn::crt::CRTTrack, sbn::crt::CRTHit> > Trackassn(
new art::Assns<sbn::crt::CRTTrack, sbn::crt::CRTHit>);
143 art::PtrMaker<sbn::crt::CRTTrack> makeTrackPtr(evt);
146 art::Handle< vector<sbn::crt::CRTHit> > rawHandle;
150 if(!rawHandle.isValid()){
151 mf::LogWarning(
"CRTTrackProducer")
157 if(fTrackMethodType == 4){
160 vector<art::Ptr<sbn::crt::CRTHit> > hitlist;
163 art::fill_ptr_vector(hitlist, rawHandle);
165 map<art::Ptr<sbn::crt::CRTHit>,
int> hitIds;
167 for(
size_t i = 0; i<hitlist.size(); i++){
168 hitIds[hitlist[i]] = i;
174 for(
size_t i = 0; i<CRTTzeroVect.size(); i++){
178 map<int, vector<art::Ptr<sbn::crt::CRTHit>>> hits;
180 for (
size_t ah = 0; ah< CRTTzeroVect[i].size(); ++ah){
183 int ip = CRTTzeroVect[i][ah]->plane;
184 hits[ip].push_back(CRTTzeroVect[i][ah]);
188 vector<pair<sbn::crt::CRTHit, vector<int>>> allHits;
190 for (
auto &keyVal : hits){
193 int ip = keyVal.first;
194 vector<pair<sbn::crt::CRTHit, vector<int>>> ahits =
trackAlg.
AverageHits(hits[ip], hitIds);
196 allHits.insert(allHits.end(), ahits.begin(), ahits.end());
211 nTrack += trackCandidates.size();
213 for(
size_t j = 0; j < trackCandidates.size(); j++){
215 CRTTrackCol->emplace_back(trackCandidates[j].
first);
216 art::Ptr<sbn::crt::CRTTrack> trackPtr = makeTrackPtr(CRTTrackCol->size()-1);
218 for (
size_t ah = 0; ah< CRTTzeroVect[i].size(); ++ah){
219 Trackassn->addSingle(trackPtr, CRTTzeroVect[i][ah]);
222 if(trackCandidates[j].first.complete)
374 if(fStoreTrack == 1){
375 evt.put(std::move(CRTTrackCol));
376 evt.put(std::move(Trackassn));
378 mf::LogInfo(
"CRTTrackProducer")
379 <<
"Number of tracks = "<<nTrack<<
"\n"
380 <<
"Number of complete tracks = "<<nCompTrack<<
"\n"
381 <<
"Number of incomplete tracks = "<<nIncTrack;
394 void vmanip(std::vector<float> v,
float* ave,
float* rms)
399 double sum = std::accumulate(v.begin(), v.end(), 0.0);
400 double mean = sum / v.size();
404 double sq_sum = std::inner_product(v.begin(), v.end(), v.begin(), 0.0);
405 double stdev = std::sqrt(sq_sum / v.size() - mean *
mean);
412 CRTavehit fillme(uint32_t ts0_ns, uint16_t ts0_ns_err, int32_t ts1_ns, uint16_t ts1_ns_err,
413 float x_pos,
float x_err,
float y_pos,
float y_err,
float z_pos,
float z_err,
414 float pe,
int plane,
string tagger)
458 newtr.
ts0_s = time0s;
484 newtr.
length = sqrt(deltax*deltax+deltay*deltay+deltaz*deltaz);
485 newtr.
thetaxy = atan2(deltax,deltay);
486 newtr.
phizy = atan2(deltaz,deltay);
494 DEFINE_ART_MODULE(CRTTrackProducer)
float z_err
position uncertainty in z-direction (cm).
float x_err
position uncertainty in x-direction (cm).
double ts0_ns_err_h2
T0 time error of second CRTHit.
double ts1_ns_err
Error on average T1 (nanosecond) of the two hits making the track.
double ts0_s
Average time (second) of the two hits making the track.
void produce(art::Event &e) override
double ts1_ns
Timestamp T1 ([signal time w.r.t. Trigger time]), in UTC absolute time scale in nanoseconds from the ...
double ts0_ns_err
Error on average T0 (nanosecond) of the two hits making the track.
int plane
Name of the CRT wall (in the form of numbers).
float peshit
Total photo-electron (PE) in a crt hit.
float y_err
position uncertainty in y-direction (cm).
double ts0_s_err
Average time (second) spread of the two hits making the track.
sbn::crt::CRTTrack shcut(CRTavehit ppA, CRTavehit ppb, uint32_t time0s, uint16_t terr)
float x1_pos
X position of first CRTHit.
float y1_err
Y position error of first CRTHit.
vector< vector< art::Ptr< sbn::crt::CRTHit > > > CreateCRTTzeros(vector< art::Ptr< sbn::crt::CRTHit >>)
struct icarus::crt::CRTavehit tempah
double ts0_ns_h1
T0 time of first CRTHit.
CRTavehit copyme(sbn::crt::CRTHit myhit)
void vmanip(vector< float > v, float *ave, float *rms)
CRTTrackProducer & operator=(CRTTrackProducer const &)=delete
float z_pos
position in z-direction (cm).
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
double ts0_ns
Timestamp T0 (from White Rabbit), in UTC absolute time scale in nanoseconds from the Epoch...
float z1_err
Z position error of first CRTHit.
float y2_err
Y position error of second CRTHit.
double ts1_ns
Average T1 (nanosecond) of the two hits making the track.
CRTavehit fillme(uint32_t i, uint16_t j, int32_t k, uint16_t l, float a, float b, float c, float d, float e, float f, float g, int p, string t)
float length
Track length.
double ts0_ns
Average T0 (nanosecond) of the two hits making the track.
float peshit
Total photoelectrons for this track (sum of PEs from the two CRTHits)
vector< pair< sbn::crt::CRTHit, vector< int > > > AverageHits(vector< art::Ptr< sbn::crt::CRTHit >> hits, map< art::Ptr< sbn::crt::CRTHit >, int > hitIds)
double ts0_ns_err_h1
T0 time error of first CRTHit.
float z1_pos
Z position of first CRTHit.
double ts0_ns_h2
T0 time of second CRTHit.
float y_pos
position in y-direction (cm).
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
float phizy
Track angle on the Z-Y plane.
int plane1
Plane ID of first CRTHit.
float z2_pos
Z position of second CRTHit.
float x_pos
position in x-direction (cm).
float y2_pos
Y position of second CRTHit.
float y1_pos
Y position of first CRTHit.
float x2_pos
X position of second CRTHit.
vector< pair< sbn::crt::CRTTrack, vector< int > > > CreateTracks(vector< pair< sbn::crt::CRTHit, vector< int >>> hits)
float x1_err
X position error of first CRTHit.
std::string tagger
Name of the CRT wall (in the form of strings).
int plane2
Plane ID of second CRTHit.
float z2_err
Z position error of second CRTHit.
CRTTrackProducer(fhicl::ParameterSet const &p)
float x2_err
X position error of second CRTHit.
float thetaxy
Track angle on the X-Y plane.