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);
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){
249 CRTavehit Ahit =
copyme(temphit);
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];
257 CRTavehit Bhit =
copyme(temphit);
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);
295 CRTavehit aveHits[7];
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){
325 CRTavehit Ahit = aveHits[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)) {
332 CRTavehit Bhit = aveHits[bh];
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));
CRTavehit copyme(sbn::crt::CRTHit myhit)
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)
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)
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)
auto end(FixedBins< T, C > const &) noexcept
std::string fDataLabelTZeros
auto begin(FixedBins< T, C > const &) noexcept
std::string fDataLabelHits