33 #include "art/Framework/Core/EDProducer.h"
34 #include "art/Framework/Core/ModuleMacros.h"
35 #include "art/Framework/Principal/Event.h"
36 #include "art/Framework/Principal/Handle.h"
37 #include "art_root_io/TFileService.h"
38 #include "canvas/Persistency/Common/FindManyP.h"
39 #include "canvas/Persistency/Common/Ptr.h"
40 #include "fhiclcpp/ParameterSet.h"
78 void produce(art::Event&
e)
override;
160 produces<std::vector<anab::T0>>();
161 produces<art::Assns<recob::Track, anab::T0>>();
162 produces<art::Assns<recob::Shower, anab::T0>>();
164 fTrackModuleLabel = (
p.get<std::string>(
"TrackModuleLabel"));
165 fShowerModuleLabel = (
p.get<std::string>(
"ShowerModuleLabel"));
166 fHitsModuleLabel = (
p.get<std::string>(
"HitsModuleLabel"));
167 fFlashModuleLabel = (
p.get<std::string>(
"FlashModuleLabel"));
168 fTruthT0ModuleLabel = (
p.get<std::string>(
"TruthT0ModuleLabel"));
170 fPredictedXConstant = (
p.get<
double>(
"PredictedXConstant"));
171 fPredictedExpConstant = (
p.get<
double>(
"PredictedExpConstant"));
172 fPredictedExpGradient = (
p.get<
double>(
"PredictedExpGradient"));
174 fDriftWindowSize = (
p.get<
double>(
"DriftWindowSize"));
175 fWeightOfDeltaYZ = (
p.get<
double>(
"WeightOfDeltaYZ"));
176 fMatchCriteria = (
p.get<
double>(
"MatchCriteria"));
177 fPEThreshold = (
p.get<
double>(
"PEThreshold"));
179 fVerbosity = (
p.get<
bool>(
"Verbose",
false));
186 art::ServiceHandle<art::TFileService const>
tfs;
187 fTree = tfs->make<TTree>(
"PhotonCounterT0Matching",
"PhotonCounterT0");
188 fTree->Branch(
"TrackCentre_X", &BestTrackCentre_X,
"TrackCentre_X/D");
189 fTree->Branch(
"PredictedX", &BestPredictedX,
"PredictedX/D");
190 fTree->Branch(
"TrackTimeCent", &BesttrkTimeCentre,
"TimeSepPredX/D");
191 fTree->Branch(
"FlashTime", &BestFlashTime,
"FlashTime/D");
192 fTree->Branch(
"TimeSep", &BestTimeSep,
"TimeSep/D");
193 fTree->Branch(
"TimeSepPredX", &BestTimeSepPredX,
"TimeSepPredX/D");
194 fTree->Branch(
"minYZSep", &BestminYZSep,
"minYZSep/D");
195 fTree->Branch(
"FitParam", &BestFitParam,
"FitParam/D");
196 fTree->Branch(
"MCTruthT0", &MCTruthT0,
"MCTruthT0/D");
198 hPredX_T = tfs->make<TH2D>(
"hPredX_T",
199 "Predicted X from timing information against reconstructed X; "
200 "Reconstructed X (cm); Predicted X (cm)",
207 hPredX_PE = tfs->make<TH2D>(
"hPredX_PE",
208 "Predicted X from PE information against reconstructed X; "
209 "Reconstructed X (cm); Predicted X (cm)",
216 hPredX_T_PE = tfs->make<TH2D>(
"hPredX_T_PE",
217 "Predicted X position from time and PE information; Predicted X "
218 "from timing information (cm); Predicted X from PE information",
225 hdeltaX_deltaYZ = tfs->make<TH2D>(
227 "Difference between X predicted from PE's and T agaisnt distance of flash from track in YZ; "
228 "Difference in X predicted from PE's and T (cm); Distance of flash from track in YZ (cm)",
235 hdeltaYZ_Length = tfs->make<TH2D>(
"hdeltaYZ_Length",
236 "Distance of flash from track against track length; Distance "
237 "from flash to track (cm); Track length (cm)",
245 tfs->make<TH2D>(
"hFitParam_Length",
246 "How fit correlates with track length; Fit correlation; Track Length (cm)",
253 hPhotonT0_MCT0 = tfs->make<TH2D>(
"hPhotonT0_MCT0",
254 "Comparing Photon Counter reconstructed T0 against MCTruth T0; "
255 "Photon Counter T0 (us); MCTruthT0 T0 (us)",
262 hT0_diff_full = tfs->make<TH1D>(
264 "Difference between MCTruth T0 and photon detector T0; Time difference (us); Number",
268 hT0_diff_zoom = tfs->make<TH1D>(
270 "Difference between MCTruth T0 and photon detector T0; Time difference (us); Number",
280 art::ServiceHandle<geo::Geometry const> geom;
281 auto const clock_data =
282 art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
284 art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(evt, clock_data);
287 art::Handle<std::vector<recob::Track>> trackListHandle;
288 std::vector<art::Ptr<recob::Track>> tracklist;
289 if (evt.getByLabel(fTrackModuleLabel, trackListHandle))
290 art::fill_ptr_vector(tracklist, trackListHandle);
293 art::Handle<std::vector<recob::Shower>> showerListHandle;
294 std::vector<art::Ptr<recob::Shower>> showerlist;
295 if (evt.getByLabel(fShowerModuleLabel, showerListHandle))
296 art::fill_ptr_vector(showerlist, showerListHandle);
299 art::Handle<std::vector<recob::Hit>> hitListHandle;
300 std::vector<art::Ptr<recob::Hit>> hitlist;
301 if (evt.getByLabel(fHitsModuleLabel, hitListHandle)) art::fill_ptr_vector(hitlist, hitListHandle);
304 art::Handle<std::vector<recob::OpFlash>> flashListHandle;
305 std::vector<art::Ptr<recob::OpFlash>> flashlist;
306 if (evt.getByLabel(fFlashModuleLabel, flashListHandle))
307 art::fill_ptr_vector(flashlist, flashListHandle);
311 std::unique_ptr<std::vector<anab::T0>> T0col(
new std::vector<anab::T0>);
312 std::unique_ptr<art::Assns<recob::Track, anab::T0>> Trackassn(
313 new art::Assns<recob::Track, anab::T0>);
314 std::unique_ptr<art::Assns<recob::Shower, anab::T0>> Showerassn(
315 new art::Assns<recob::Shower, anab::T0>);
317 if (trackListHandle.isValid() && flashListHandle.isValid()) {
319 art::FindManyP<recob::Hit> fmtht(trackListHandle, evt, fTrackModuleLabel);
320 art::FindMany<anab::T0> fmtruth(trackListHandle, evt, fTruthT0ModuleLabel);
322 size_t NTracks = tracklist.size();
323 size_t NFlashes = flashlist.size();
326 std::cout <<
"There were " << NTracks <<
" tracks and " << NFlashes
327 <<
" flashes in this event." << std::endl;
330 for (
size_t iTrk = 0; iTrk < NTracks; ++iTrk) {
331 if (fVerbosity)
std::cout <<
"\n New Track " << (int)iTrk << std::endl;
333 BestFlashTime = BestFitParam = BestTrackCentre_X = BestTrackLength = 9999;
334 BestTimeSepPredX = BestPredictedX = BestDeltaPredX = BestminYZSep = MCTruthT0 = 9999;
335 bool ValidTrack =
false;
339 std::tie(trackStart, trackEnd) = tracklist[iTrk]->Extent();
340 std::vector<art::Ptr<recob::Hit>> allHits = fmtht.at(iTrk);
341 size_t nHits = allHits.size();
342 trkTimeStart = allHits[nHits - 1]->PeakTime() /
343 clock_data.TPCClock().Frequency();
345 allHits[0]->PeakTime() / clock_data.TPCClock().Frequency();
346 TrackProp(trackStart.X(),
366 std::cout << trackStart.X() <<
" " << trackEnd.X() <<
" " << TrackLength_X <<
" "
367 << TrackCentre_X <<
"\n"
368 << trackStart.Y() <<
" " << trackEnd.Y() <<
" " << TrackLength_Y <<
" "
369 << TrackCentre_Y <<
"\n"
370 << trackStart.Z() <<
" " << trackEnd.Z() <<
" " << TrackLength_Z <<
" "
371 << TrackCentre_Z <<
"\n"
372 << trkTimeStart <<
" " << trkTimeEnd <<
" " << trkTimeLengh <<
" "
373 << trkTimeCentre << std::endl;
376 for (
size_t iFlash = 0; iFlash < NFlashes; ++iFlash) {
378 YZSep = minYZSep = 9999;
379 FlashTime = TimeSep = 9999;
380 PredictedX = TimeSepPredX = DeltaPredX = FitParam = 9999;
382 FlashTime = flashlist[iFlash]->Time();
383 TimeSep = trkTimeCentre - FlashTime;
384 if (TimeSep < 0 || TimeSep > (fDriftWindowSize / clock_data.TPCClock().Frequency()))
388 if (flashlist[iFlash]->TotalPE() < fPEThreshold)
continue;
393 (fPredictedXConstant / pow(flashlist[iFlash]->TotalPE(), fPredictedXPower)) +
394 (
exp(fPredictedExpConstant + (fPredictedExpGradient * flashlist[iFlash]->TotalPE())));
395 TimeSepPredX = TimeSep * detprop.DriftVelocity();
396 DeltaPredX = fabs(TimeSepPredX - PredictedX);
398 for (
size_t Point = 1;
Point < tracklist[iTrk]->NumberTrajectoryPoints(); ++
Point) {
399 auto NewPoint = tracklist[iTrk]->LocationAtPoint(
Point);
400 auto PrevPoint = tracklist[iTrk]->LocationAtPoint(
Point - 1);
401 YZSep = DistFromPoint(NewPoint.Y(),
405 flashlist[iFlash]->YCenter(),
406 flashlist[iFlash]->ZCenter());
407 if (
Point == 1) minYZSep = YZSep;
408 if (YZSep < minYZSep) minYZSep = YZSep;
412 if (fMatchCriteria == 0)
414 pow(((DeltaPredX * DeltaPredX) + (minYZSep * minYZSep * fWeightOfDeltaYZ)), 0.5);
415 else if (fMatchCriteria == 1)
417 else if (fMatchCriteria == 2)
418 FitParam = DeltaPredX;
422 std::cout <<
"\nFlash " << (int)iFlash <<
" " << TrackCentre_X <<
", " << TimeSepPredX
423 <<
" - " << PredictedX <<
" = " << DeltaPredX <<
", " << minYZSep <<
" -> "
424 << FitParam << std::endl;
427 if (FitParam < BestFitParam) {
429 BestFlash = (int)iFlash;
430 BestFitParam = FitParam;
431 BestTrackCentre_X = TrackCentre_X;
432 BestTrackLength = TrackLength;
433 BesttrkTimeCentre = trkTimeCentre;
434 BestTimeSepPredX = TimeSepPredX;
435 BestPredictedX = PredictedX;
436 BestDeltaPredX = DeltaPredX;
437 BestminYZSep = minYZSep;
438 BestFlashTime = FlashTime;
439 BestTimeSep = TimeSep;
447 hPredX_T->Fill(BestTrackCentre_X, BestTimeSepPredX);
448 hPredX_PE->Fill(BestTrackCentre_X, BestPredictedX);
449 hPredX_T_PE->Fill(BestTimeSepPredX, BestPredictedX);
450 hdeltaX_deltaYZ->Fill(BestDeltaPredX, BestminYZSep);
451 hdeltaYZ_Length->Fill(BestminYZSep, BestTrackLength);
452 hFitParam_Length->Fill(BestFitParam, BestTrackLength);
454 if (fmtruth.isValid()) {
455 std::vector<const anab::T0*> T0s = fmtruth.at((
int)iTrk);
456 for (
size_t i = 0; i < T0s.size(); ++i) {
457 MCTruthT0 = T0s[i]->Time() / 1e3;
458 hPhotonT0_MCT0->Fill(BestFlashTime, MCTruthT0);
459 hT0_diff_full->Fill(MCTruthT0 - BestFlashTime);
460 hT0_diff_zoom->Fill(MCTruthT0 - BestFlashTime);
467 BestFlashTime * 1e3, FlashTriggerType, (
int)BestFlash, (*T0col).size(), BestFitParam));
472 evt.put(std::move(T0col));
473 evt.put(std::move(Trackassn));
474 evt.put(std::move(Showerassn));
481 double& TrackLength_X,
482 double& TrackCentre_X,
485 double& TrackLength_Y,
486 double& TrackCentre_Y,
489 double& TrackLength_Z,
490 double& TrackCentre_Z,
493 double& trkTimeLengh,
494 double& trkTimeCentre,
498 TrackLength_X = fabs(TrackEnd_X - TrackStart_X);
499 if (TrackStart_X < TrackEnd_X)
500 TrackCentre_X = TrackStart_X + 0.5 * TrackLength_X;
502 TrackCentre_X = TrackStart_X - 0.5 * TrackLength_X;
504 TrackLength_Y = fabs(TrackEnd_Y - TrackStart_Y);
505 if (TrackStart_Y < TrackEnd_Y)
506 TrackCentre_Y = TrackStart_Y + 0.5 * TrackLength_Y;
508 TrackCentre_Y = TrackStart_Y - 0.5 * TrackLength_Y;
510 TrackLength_Z = fabs(TrackEnd_Z - TrackStart_Z);
511 if (TrackStart_Z < TrackEnd_Z)
512 TrackCentre_Z = TrackStart_Z + 0.5 * TrackLength_Z;
514 TrackCentre_Z = TrackStart_Z - 0.5 * TrackLength_Z;
516 trkTimeLengh = trkTimeEnd - trkTimeStart;
517 trkTimeCentre = trkTimeStart + 0.5 * trkTimeLengh;
519 TrackLength = pow(pow((TrackEnd_X - TrackStart_X), 2) + pow((TrackEnd_Y - TrackStart_Y), 2) +
520 pow((TrackEnd_Z - TrackStart_Z), 2),
535 double Length = hypot(fabs(EndY - StartY), fabs(EndZ - StartZ));
537 ((PointZ - StartZ) * (EndY - StartY) - (PointY - StartY) * (EndZ - StartZ)) / Length;
538 return fabs(distance);
float Length(const PFPStruct &pfp)
std::string fShowerModuleLabel
std::string fFlashModuleLabel
Declaration of signal hit object.
double DistFromPoint(double StartY, double EndY, double StartZ, double EndZ, double PointY, double PointZ)
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
double fPredictedXConstant
void TrackProp(double TrackStart_X, double TrackEnd_X, double &TrackLength_X, double &TrackCentre_X, double TrackStart_Y, double TrackEnd_Y, double &TrackLength_Y, double &TrackCentre_Y, double TrackStart_Z, double TrackEnd_Z, double &TrackLength_Z, double &TrackCentre_Z, double trkTimeStart, double trkTimeEnd, double &trkTimeLengh, double &trkTimeCentre, double &TrackLength)
Provides recob::Track data product.
double fPredictedExpGradient
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
PhotonCounterT0Matching(fhicl::ParameterSet const &p)
std::string fTruthT0ModuleLabel
tracking::Point_t Point_t
double fPredictedExpConstant
std::string fTrackModuleLabel
PhotonCounterT0Matching & operator=(PhotonCounterT0Matching const &)=delete
art::ServiceHandle< art::TFileService > tfs
void produce(art::Event &e) override
art framework interface to geometry description
BEGIN_PROLOG could also be cout
std::string fHitsModuleLabel