11 #include "art/Framework/Core/EDProducer.h"
12 #include "art/Framework/Core/ModuleMacros.h"
13 #include "art/Framework/Principal/Event.h"
14 #include "art/Framework/Principal/Handle.h"
15 #include "art/Framework/Principal/Run.h"
16 #include "art/Framework/Principal/SubRun.h"
17 #include "canvas/Utilities/InputTag.h"
18 #include "canvas/Persistency/Common/FindManyP.h"
19 #include "canvas/Persistency/Common/Ptr.h"
20 #include "canvas/Persistency/Common/PtrVector.h"
21 #include "fhiclcpp/ParameterSet.h"
22 #include "messagefacility/MessageLogger/MessageLogger.h"
23 #include "art_root_io/TFileService.h"
24 #include "art/Persistency/Common/PtrMaker.h"
62 void produce(art::Event &
e)
override;
82 void vmanip(std::vector<float> v,
float* ave,
float* rms);
106 float b,
float c,
float d,
float e,
float f,
float g,
107 int p, std::string t);
120 : EDProducer(p), trackAlg(p.
get<fhicl::ParameterSet>(
"TrackAlg"))
130 if(fStoreTrack == 1){
131 produces< std::vector<sbn::crt::CRTTrack> >();
132 produces< art::Assns<sbn::crt::CRTTrack , sbn::crt::CRTHit> >();
147 std::unique_ptr<std::vector<sbn::crt::CRTTrack> > CRTTrackCol(
new std::vector<sbn::crt::CRTTrack>);
148 std::unique_ptr< art::Assns<sbn::crt::CRTTrack, sbn::crt::CRTHit> > Trackassn(
new art::Assns<sbn::crt::CRTTrack, sbn::crt::CRTHit>);
149 art::PtrMaker<sbn::crt::CRTTrack> makeTrackPtr(evt);
152 art::Handle< std::vector<sbn::crt::CRTHit> > rawHandle;
156 if(!rawHandle.isValid()){
157 mf::LogWarning(
"CRTTrackProducer")
166 std::vector<art::Ptr<sbn::crt::CRTHit> > hitlist;
168 art::fill_ptr_vector(hitlist, rawHandle);
170 std::map<art::Ptr<sbn::crt::CRTHit>,
int> hitIds;
171 for(
size_t i = 0; i<hitlist.size(); i++){
172 hitIds[hitlist[i]] = i;
178 for(
size_t i = 0; i<CRTTzeroVect.size(); i++){
181 std::map<std::string, std::vector<art::Ptr<sbn::crt::CRTHit>>> hits;
182 for (
size_t ah = 0; ah< CRTTzeroVect[i].size(); ++ah){
183 std::string ip = CRTTzeroVect[i][ah]->tagger;
184 hits[ip].push_back(CRTTzeroVect[i][ah]);
188 std::vector<std::pair<sbn::crt::CRTHit, std::vector<int>>> allHits;
189 for (
auto &keyVal : hits){
190 std::string ip = keyVal.first;
191 std::vector<std::pair<sbn::crt::CRTHit, std::vector<int>>> ahits =
trackAlg.
AverageHits(hits[ip], hitIds);
192 allHits.insert(allHits.end(), ahits.begin(), ahits.end());
196 std::vector<std::pair<sbn::crt::CRTTrack, std::vector<int>>> trackCandidates =
trackAlg.
CreateTracks(allHits);
197 nTrack += trackCandidates.size();
198 for(
size_t j = 0; j < trackCandidates.size(); j++){
199 CRTTrackCol->emplace_back(trackCandidates[j].
first);
201 art::Ptr<sbn::crt::CRTTrack> trackPtr = makeTrackPtr(CRTTrackCol->size()-1);
202 for (
size_t ah = 0; ah< CRTTzeroVect[i].size(); ++ah){
203 Trackassn->addSingle(trackPtr, CRTTzeroVect[i][ah]);
205 if(trackCandidates[j].first.complete) nCompTrack++;
214 art::Handle< std::vector<sbn::crt::CRTTzero> > rawHandletzero;
218 if(!rawHandletzero.isValid()){
219 mf::LogWarning(
"CRTTrackProducer")
224 std::vector<art::Ptr<sbn::crt::CRTTzero> > tzerolist;
226 art::fill_ptr_vector(tzerolist, rawHandletzero);
228 art::FindManyP<sbn::crt::CRTHit> fmht(rawHandletzero, evt,
fDataLabelTZeros);
231 for(
size_t tzIter = 0; tzIter < tzerolist.size(); ++tzIter){
236 for (
int ip=0;ip<7;++ip) {
237 if (tzerolist[tzIter]->nhits[ip]>0) { np++; tothits+=tzerolist[tzIter]->nhits[ip];}
241 std::vector<art::Ptr<sbn::crt::CRTHit> > hitlist=fmht.at(tzIter);
244 double time_s_A = hitlist[0]->ts0_s;
247 for (
size_t ah = 0; ah< hitlist.size()-1; ++ah){
250 int planeA = hitlist[ah]->plane;
252 for (
size_t bh = ah+1; bh< hitlist.size(); ++bh){
253 int planeB = hitlist[bh]->plane;
255 if (planeB!=planeA && !((planeA==3&&planeB==4)||(planeA==4&&planeB==3))) {
256 temphit=*hitlist[bh];
259 CRTTrackCol->emplace_back(CRTcanTrack);
271 std::vector<float> thittime0[7];
272 std::vector<float> thittime1[7];
273 std::vector<float> tx[7];
274 std::vector<float> ty[7];
275 std::vector<float> tz[7];
276 std::vector<float> pe[7];
278 double time_s_A = hitlist[0]->ts0_s;
280 double time_s_err = 0.;
281 double time1_ns_A = hitlist[0]->ts1_ns;
282 double time0_ns_A = hitlist[0]->ts0_ns;
285 for (
size_t ah = 0; ah< hitlist.size(); ++ah){
286 int ip = hitlist[ah]->plane;
287 thittime0[ip].push_back(hitlist[ah]->ts0_ns-time0_ns_A);
288 thittime1[ip].push_back(hitlist[ah]->ts1_ns-time1_ns_A);
289 tx[ip].push_back(hitlist[ah]->x_pos);
290 ty[ip].push_back(hitlist[ah]->y_pos);
291 tz[ip].push_back(hitlist[ah]->z_pos);
292 pe[ip].push_back(hitlist[ah]->peshit);
297 for (
int ip = 0; ip < 7; ip++){
298 if (tx[ip].
size()>0){
299 uint32_t at0; int32_t at1; uint16_t rt0,rt1;
301 float avet1=0.0;
float rmst1 =0.0;
302 float avet0=0.0;
float rmst0 =0.0;
303 float avex=0.0;
float rmsx =0.0;
304 float avey=0.0;
float rmsy =0.0;
305 float avez=0.0;
float rmsz =0.0;
306 vmanip(thittime0[ip],&avet0,&rmst0);
307 vmanip(thittime1[ip],&avet1,&rmst1);
308 at0 = (uint32_t)(avet0+time0_ns_A); rt0 = (uint16_t)rmst0;
309 at1 = (int32_t)(avet1+time1_ns_A); rt1 = (uint16_t)rmst1;
310 vmanip(tx[ip],&avex,&rmsx);
311 vmanip(ty[ip],&avey,&rmsy);
312 vmanip(tz[ip],&avez,&rmsz);
313 totpe=std::accumulate(pe[ip].
begin(), pe[ip].
end(), 0.0);
314 CRTavehit aveHit =
fillme(at0,rt0,at1,rt1,avex,rmsx,avey,rmsy,avez,rmsz,totpe,ip,
"");
315 aveHits[ip] = aveHit;
318 CRTavehit aveHit =
fillme(0,0,0,0,-99999,-99999,-99999,-99999,-99999,-99999,-99999,ip,
"");
319 aveHits[ip] = aveHit;
324 for (
size_t ah = 0; ah< 6; ++ah){
326 if( Ahit.
x_pos==-99999 )
continue;
328 for (
size_t bh = ah+1; bh< 7; ++bh){
329 if ( aveHits[bh].x_pos==-99999 )
continue;
331 if (ah!=bh && !(ah==3&&bh==4)) {
334 CRTTrackCol->emplace_back(CRTcanTrack);
347 mf::LogInfo(
"CRTTrackProducer")
348 <<
"Number of tracks = "<<CRTTrackCol->size()<<
"\n"
349 <<
"Number of complete tracks = "<<CRTTrackCol->size()-nIncTrack<<
"\n"
350 <<
"Number of incomplete tracks = "<<nIncTrack;
354 evt.put(std::move(CRTTrackCol));
355 evt.put(std::move(Trackassn));
374 void vmanip(std::vector<float> v,
float* ave,
float* rms)
381 double sum = std::accumulate(v.begin(), v.end(), 0.0);
382 double mean = sum / v.size();
386 double sq_sum = std::inner_product(v.begin(), v.end(), v.begin(), 0.0);
387 double stdev = std::sqrt(sq_sum / v.size() - mean *
mean);
397 CRTavehit fillme(uint32_t ts0_ns, uint16_t ts0_ns_err, int32_t ts1_ns, uint16_t ts1_ns_err,
398 float x_pos,
float x_err,
float y_pos,
float y_err,
float z_pos,
float z_err,
399 float pe,
int plane, std::string
tagger)
455 newtr.
ts0_s = time0s;
481 newtr.
length = sqrt(deltax*deltax+deltay*deltay+deltaz*deltaz);
482 newtr.
thetaxy = atan2(deltax,deltay);
483 newtr.
phizy = atan2(deltaz,deltay);
491 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.
CRTavehit copyme(sbn::crt::CRTHit myhit)
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.
CRTTrackProducer & operator=(CRTTrackProducer const &)=delete
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).
struct sbnd::CRTavehit tempah
float peshit
Total photo-electron (PE) in a crt hit.
float y_err
position uncertainty in y-direction (cm).
void vmanip(std::vector< float > v, float *ave, float *rms)
std::vector< std::pair< sbn::crt::CRTTrack, std::vector< int > > > CreateTracks(std::vector< std::pair< sbn::crt::CRTHit, std::vector< int >>> hits)
double ts0_s_err
Average time (second) spread of the two hits making the track.
float x1_pos
X position of first CRTHit.
std::size_t size(FixedBins< T, C > const &) noexcept
std::vector< std::pair< sbn::crt::CRTHit, std::vector< int > > > AverageHits(std::vector< art::Ptr< sbn::crt::CRTHit >> hits, std::map< art::Ptr< sbn::crt::CRTHit >, int > hitIds)
float y1_err
Y position error of first CRTHit.
CRTTrackProducer(fhicl::ParameterSet const &p)
double ts0_ns_h1
T0 time of first CRTHit.
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, std::string t)
std::vector< std::vector< art::Ptr< sbn::crt::CRTHit > > > CreateCRTTzeros(std::vector< art::Ptr< sbn::crt::CRTHit >>)
sbn::crt::CRTTrack shcut(CRTavehit ppA, CRTavehit ppb, uint32_t time0s, uint16_t terr)
float z_pos
position in z-direction (cm).
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.
auto end(FixedBins< T, C > const &) noexcept
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)
double ts0_ns_err_h1
T0 time error of first CRTHit.
std::string fDataLabelTZeros
void produce(art::Event &e) override
float z1_pos
Z position of first CRTHit.
double ts0_ns_h2
T0 time of second CRTHit.
auto begin(FixedBins< T, C > const &) noexcept
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).
std::string fDataLabelHits
float y2_pos
Y position of second CRTHit.
float y1_pos
Y position of first CRTHit.
float x2_pos
X position of second CRTHit.
stream1 can override from command line with o or output services user sbnd
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.
float x2_err
X position error of second CRTHit.
float thetaxy
Track angle on the X-Y plane.