23 DEBUG_FLAG(p.
get<
bool>(
"RunDebugMode",false)),
24 fMinTrackLength(p.
get<
float>(
"MinTrackLength")),
25 fMinOpHitPE(p.
get<
float>(
"MinOpHitPE",0.1)),
26 fMIPdQdx(p.
get<
float>(
"MIPdQdx",2.1)),
27 fOpDetSaturation(p.
get<
float>(
"OpDetSaturation",200.)),
28 fSingleChannelCut(p.
get<
float>(
"SingleChannelCut")),
29 fCumulativeChannelThreshold(p.
get<
float>(
"CumulativeChannelThreshold")),
30 fCumulativeChannelCut(p.
get<unsigned
int>(
"CumulativeChannelCut")),
31 fIntegralCut(p.
get<
float>(
"IntegralCut")),
32 fMakeOutsideDriftTags(p.
get<
bool>(
"MakeOutsideDriftTags",false)),
33 fNormalizeHypothesisToFlash(p.
get<
bool>(
"NormalizeHypothesisToFlash"))
37 TH1F* hist_flash, TH1F* hist_hyp){
41 cOpDetHist_flash->SetNameTitle(
"opdet_hist_flash",
"Optical Detector Occupancy, Flash");
44 cOpDetHist_hyp->SetNameTitle(
"opdet_hist_hyp",
"Optical Detector Occupancy, Hypothesis");
54 std::vector<recob::Track>
const& trackVector,
55 std::vector<anab::CosmicTag>& cosmicTagVector,
56 std::vector<size_t>& assnTrackTagVector,
63 std::vector< const recob::OpFlash* > flashesOnBeamTime;
64 for(
auto const& flash : flashVector){
65 if(!flash.OnBeamTime())
continue;
66 flashesOnBeamTime.push_back(&flash);
71 cosmicTagVector.reserve(trackVector.size());
73 for(
size_t track_i=0; track_i<trackVector.size(); track_i++){
82 std::vector<float> xyz_begin = { (
float)pt_begin.x(), (
float)pt_begin.y(), (
float)pt_begin.z()};
83 std::vector<float> xyz_end = {(
float)pt_end.x(), (
float)pt_end.y(), (
float)pt_end.z()};
89 assnTrackTagVector[track_i] = cosmicTagVector.size()-1;
95 std::vector<float> lightHypothesis =
GetMIPHypotheses(track,providers,pvs,opdigip);
98 bool compatible=
false;
101 if(result==CompatibilityResultType::kCompatible) compatible=
true;
110 float cosmicScore=1.;
111 if(compatible) cosmicScore=0.;
113 assnTrackTagVector[track_i]=cosmicTagVector.size()-1;
120 unsigned int const event,
121 std::vector<recob::OpFlash>
const& flashVector,
122 std::vector<recob::Track>
const& trackVector,
132 std::vector< std::pair<unsigned int, const recob::OpFlash*> > flashesOnBeamTime;
133 for(
unsigned int i=0; i<flashVector.size(); i++){
136 flashesOnBeamTime.push_back(std::make_pair(i,&flash));
139 for(
size_t track_i=0; track_i<trackVector.size(); track_i++){
148 std::vector<float> xyz_begin = { (
float)pt_begin.x(), (
float)pt_begin.y(), (
float)pt_begin.z()};
149 std::vector<float> xyz_end = {(
float)pt_end.x(), (
float)pt_end.y(), (
float)pt_end.z()};
171 for(
auto flash : flashesOnBeamTime){
174 for(
size_t c=0;
c<=geom.MaxOpChannel();
c++){
175 if ( geom.IsValidOpChannel(
c ) ) {
176 unsigned int OpDet = geom.OpDetFromOpChannel(
c);
202 unsigned int const event,
203 std::vector<recob::OpFlash>
const& flashVector,
204 std::vector<simb::MCParticle>
const& mcParticleVector,
214 std::vector< std::pair<unsigned int, const recob::OpFlash*> > flashesOnBeamTime;
215 for(
unsigned int i=0; i<flashVector.size(); i++){
218 flashesOnBeamTime.push_back(std::make_pair(i,&flash));
221 for(
size_t particle_i=0; particle_i<mcParticleVector.size(); particle_i++){
224 if(particle.
Process().compare(
"primary")!=0)
continue;
229 bool prev_inside=
false;
232 if(inside && !prev_inside) start_i = pt_i;
233 if(!inside && prev_inside) { end_i = pt_i-1;
break; }
234 prev_inside = inside;
236 TVector3
const& pt_begin = particle.
Position(start_i).Vect();
237 TVector3
const& pt_end = particle.
Position(end_i).Vect();
238 std::vector<float> xyz_begin = { (
float)pt_begin.x(), (
float)pt_begin.y(), (
float)pt_begin.z()};
239 std::vector<float> xyz_end = {(
float)pt_end.x(), (
float)pt_end.y(), (
float)pt_end.z()};
261 for(
auto flash : flashesOnBeamTime){
265 for(
size_t c=0;
c<=geom.MaxOpChannel();
c++){
266 if ( geom.IsValidOpChannel(
c) ) {
267 unsigned int OpDet = geom.OpDetFromOpChannel(
c);
291 std::cout <<
"Flash/Hyp " << i <<
" : " 306 float&
y,
float& sigmay,
307 float&
z,
float& sigmaz,
309 y=0; sigmay=0; z=0; sigmaz=0; sum=0;
312 sum+=opdetVector[
opdet];
314 y += opdetVector[
opdet]*xyz[1];
315 z += opdetVector[
opdet]*xyz[2];
322 sigmay += (opdetVector[
opdet]*xyz[1]-
y)*(opdetVector[
opdet]*xyz[1]-y);
323 sigmaz += (opdetVector[
opdet]*xyz[2]-
y)*(opdetVector[
opdet]*xyz[2]-y);
326 sigmay = std::sqrt(sigmay)/sum;
327 sigmaz = std::sqrt(sigmaz)/sum;
332 if(pt.x() < 0 || pt.x() > 2*geom.
DetHalfWidth())
return false;
334 if(pt.z() < 0 || pt.z() > geom.
DetLength())
return false;
339 if(start_x < 0. || end_x < 0.)
return false;
346 std::vector<float> & lightHypothesis,
347 float & totalHypothesisPE,
350 float const& PromptMIPScintYield,
353 double xyz_segment[3];
354 xyz_segment[0] = 0.5*(pt2.x()+pt1.x()) + XOffset;
355 xyz_segment[1] = 0.5*(pt2.y()+pt1.y());
356 xyz_segment[2] = 0.5*(pt2.z()+pt1.z());
362 if(!PointVisibility)
return;
365 float LightAmount = PromptMIPScintYield*(pt2-pt1).Mag();
367 for(
size_t opdet_i=0; opdet_i<pvs.
NOpChannels(); opdet_i++){
368 lightHypothesis[opdet_i] += PointVisibility[opdet_i]*LightAmount;
369 totalHypothesisPE += PointVisibility[opdet_i]*LightAmount;
381 float const& totalHypothesisPE,
383 for(
size_t opdet_i=0; opdet_i<geom.
NOpDets(); opdet_i++)
384 lightHypothesis[opdet_i] /= totalHypothesisPE;
397 std::vector<float> lightHypothesis(geom.NOpDets(),0);
398 float totalHypothesisPE=0;
399 const float PromptMIPScintYield = larp.ScintYield()*larp.ScintYieldRatio()*opdigip.
QE()*
fMIPdQdx;
406 lightHypothesis,totalHypothesisPE,
407 geom,pvs,PromptMIPScintYield,
413 return lightHypothesis;
420 size_t start_i,
size_t end_i,
428 std::vector<float> lightHypothesis(geom.NOpDets(),0);
429 float totalHypothesisPE=0;
430 const float PromptMIPScintYield = larp.ScintYield()*larp.ScintYieldRatio()*opdigip.
QE()*
fMIPdQdx;
432 for(
size_t pt=start_i+1; pt<=end_i; pt++)
434 lightHypothesis,totalHypothesisPE,
435 geom,pvs,PromptMIPScintYield,
441 return lightHypothesis;
458 float hypothesis_integral=0;
459 float flash_integral=0;
460 unsigned int cumulativeChannels=0;
462 std::vector<double> PEbyOpDet(geom.
NOpDets(),0);
467 PEbyOpDet[o] += flashPointer->
PE(
c);
471 float hypothesis_scale=1.;
474 for(
size_t pmt_i=0; pmt_i<lightHypothesis.size(); pmt_i++){
476 flash_integral += PEbyOpDet[pmt_i];
478 if(lightHypothesis[pmt_i] < std::numeric_limits<float>::epsilon() )
continue;
479 hypothesis_integral += lightHypothesis[pmt_i]*hypothesis_scale;
483 float diff_scaled = (lightHypothesis[pmt_i]*hypothesis_scale - PEbyOpDet[pmt_i])/std::sqrt(lightHypothesis[pmt_i]*hypothesis_scale);
485 if( diff_scaled >
fSingleChannelCut )
return CompatibilityResultType::kSingleChannelCut;
488 if(cumulativeChannels >=
fCumulativeChannelCut)
return CompatibilityResultType::kCumulativeChannelCut;
492 if( (hypothesis_integral - flash_integral)/std::sqrt(hypothesis_integral)
493 >
fIntegralCut)
return CompatibilityResultType::kIntegralCut;
495 return CompatibilityResultType::kCompatible;
500 std::vector<float>
const& light_track){
503 for(
size_t pmt_i=0; pmt_i<light_flash.size(); pmt_i++){
508 if(light_track[pmt_i] > 1) err2 = light_track[pmt_i];
510 chi2 += (light_flash[pmt_i]-light_track[pmt_i])*(light_flash[pmt_i]-light_track[pmt_i]) / err2;
519 *output <<
"----------------------------------------------" <<
std::endl;
520 *output <<
"Track properties: ";
521 *output <<
"\n\tLength=" << track.
Length();
524 *output <<
"\n\tBegin Location (x,y,z)=(" << pt_begin.x() <<
"," << pt_begin.y() <<
"," << pt_begin.z() <<
")";
527 *output <<
"\n\tEnd Location (x,y,z)=(" << pt_end.x() <<
"," << pt_end.y() <<
"," << pt_end.z() <<
")";
531 *output <<
"----------------------------------------------" <<
std::endl;
536 *output <<
"----------------------------------------------" <<
std::endl;
537 *output <<
"Flash properties: ";
539 *output <<
"\n\tTime=" << flash.
Time();
540 *output <<
"\n\tOnBeamTime=" << flash.
OnBeamTime();
541 *output <<
"\n\ty position (center,width)=(" << flash.
YCenter() <<
"," << flash.
YWidth() <<
")";
542 *output <<
"\n\tz position (center,width)=(" << flash.
ZCenter() <<
"," << flash.
ZWidth() <<
")";
543 *output <<
"\n\tTotal PE=" << flash.
TotalPE();
546 *output <<
"----------------------------------------------" <<
std::endl;
557 *output <<
"----------------------------------------------" <<
std::endl;
558 *output <<
"Hypothesis-flash comparison: ";
560 float hypothesis_integral=0;
561 float flash_integral=0;
563 float hypothesis_scale=1.;
567 std::vector<double> PEbyOpDet(geom.
NOpDets(),0);
572 PEbyOpDet[o] += flashPointer->
PE(
c);
576 for(
size_t pmt_i=0; pmt_i<lightHypothesis.size(); pmt_i++){
578 flash_integral += PEbyOpDet[pmt_i];
580 *output <<
"\n\t pmt_i=" << pmt_i <<
", (hypothesis,flash)=(" 581 << lightHypothesis[pmt_i]*hypothesis_scale <<
"," << PEbyOpDet[pmt_i] <<
")";
583 if(lightHypothesis[pmt_i] < std::numeric_limits<float>::epsilon() )
continue;
585 *output <<
" difference=" 586 << (lightHypothesis[pmt_i]*hypothesis_scale - PEbyOpDet[pmt_i])/std::sqrt(lightHypothesis[pmt_i]*hypothesis_scale);
588 hypothesis_integral += lightHypothesis[pmt_i]*hypothesis_scale;
591 *output <<
"\n\t TOTAL (hypothesis,flash)=(" 592 << hypothesis_integral <<
"," << flash_integral <<
")" 593 <<
" difference=" << (hypothesis_integral - flash_integral)/std::sqrt(hypothesis_integral);
596 *output <<
"End result=" << result <<
std::endl;
597 *output <<
"----------------------------------------------" <<
std::endl;
unsigned int NumberTrajectoryPoints() const
const TLorentzVector & Position(const int i=0) const
CompatibilityResultType CheckCompatibility(std::vector< float > const &lightHypothesis, const recob::OpFlash *flashPointer, geo::GeometryCore const &geom)
geo::Length_t DetHalfWidth(geo::TPCID const &tpcid) const
Returns the half width of the active volume of the specified TPC.
BeamFlashTrackMatchTaggerAlg(fhicl::ParameterSet const &p)
float fCumulativeChannelThreshold
const simb::MCTrajectory & Trajectory() const
enum anab::cosmic_tag_id CosmicTagID_t
Point_t const & LocationAtPoint(size_t i) const
bool fNormalizeHypothesisToFlash
void RunHypothesisComparison(unsigned int const, unsigned int const, std::vector< recob::OpFlash > const &, std::vector< recob::Track > const &, Providers_t, phot::PhotonVisibilityService const &, opdet::OpDigiProperties const &)
float CalculateChi2(std::vector< float > const &, std::vector< float > const &)
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
Provider const * get() const
Returns the provider with the specified type.
void GetCenter(double *xyz, double localz=0.0) const
double PE(unsigned int i) const
std::string Process() const
void RunCompatibilityCheck(std::vector< recob::OpFlash > const &, std::vector< recob::Track > const &, std::vector< anab::CosmicTag > &, std::vector< size_t > &, Providers_t, phot::PhotonVisibilityService const &, opdet::OpDigiProperties const &)
unsigned int OpDetFromOpChannel(int opChannel) const
Convert unique channel to detector number.
std::vector< float > GetMIPHypotheses(recob::Track const &track, Providers_t providers, phot::PhotonVisibilityService const &pvs, opdet::OpDigiProperties const &, float XOffset=0)
const anab::CosmicTagID_t COSMIC_TYPE_OUTSIDEDRIFT
double QE() const noexcept
Returns quantum efficiency.
std::vector< float > cOpDetVector_flash
geo::Length_t DetHalfHeight(geo::TPCID const &tpcid) const
Returns the half height of the active volume of the specified TPC.
double Length(size_t p=0) const
Access to various track properties.
void NormalizeLightHypothesis(std::vector< float > &lightHypothesis, float const &totalHypothesisPE, geo::GeometryCore const &geom)
const OpDetGeo & OpDet(unsigned int iopdet) const
Return the iopdet'th optical detector in the cryostat.
void AddLightFromSegment(TVector3 const &pt1, TVector3 const &pt2, std::vector< float > &lightHypothesis, float &totalHypothesisPE, geo::GeometryCore const &geom, phot::PhotonVisibilityService const &pvs, float const &PromptMIPScintYield, float XOffset)
FlashComparisonProperties_t cFlashComparison_p
bool fMakeOutsideDriftTags
void PrintTrackProperties(recob::Track const &, std::ostream *output=&std::cout)
unsigned int flash_nOpDet
geo::Length_t DetLength(geo::TPCID const &tpcid) const
Returns the length of the active volume of the specified TPC.
CryostatGeo const & Cryostat(geo::CryostatID const &cryoid) const
Returns the specified cryostat.
unsigned int MaxOpChannel() const
Largest optical channel number.
static int max(int a, int b)
Description of geometry of one entire detector.
std::string leaf_structure
MappedCounts_t GetAllVisibilities(Point const &p, bool wantReflected=false) const
void SetHypothesisComparisonTree(TTree *, TH1F *, TH1F *)
unsigned int NOpDets() const
Number of OpDets in the whole detector.
Encapsulate the geometry of an optical detector.
unsigned int fCumulativeChannelCut
double TotalLength() const
std::vector< float > cOpDetVector_hyp
void PrintHypothesisFlashComparison(std::vector< float > const &, const recob::OpFlash *, geo::GeometryCore const &geom, CompatibilityResultType, std::ostream *output=&std::cout)
Container for a list of pointers to providers.
bool InDriftWindow(double, double, geo::GeometryCore const &)
void FillFlashProperties(std::vector< float > const &opdetVector, float &, float &, float &, float &, float &, geo::GeometryCore const &geom)
const anab::CosmicTagID_t COSMIC_TYPE_FLASHMATCH
bool InDetector(TVector3 const &, geo::GeometryCore const &)
auto const & get(AssnsNode< L, R, D > const &r)
size_t NOpChannels() const
bool IsValidOpChannel(int opChannel) const
Is this a valid OpChannel number?
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
QTextStream & endl(QTextStream &s)
Event finding and building.
void PrintFlashProperties(recob::OpFlash const &, std::ostream *output=&std::cout)