19 DEBUG_FLAG(p.get<bool>(
"RunDebugMode",false))
40 TH1F* hist_flash, TH1F* hist_hyp){
44 cOpDetHist_flash->SetNameTitle(
"opdet_hist_flash",
"Optical Detector Occupancy, Flash");
47 cOpDetHist_hyp->SetNameTitle(
"opdet_hist_hyp",
"Optical Detector Occupancy, Hypothesis");
57 std::vector<recob::Track>
const& trackVector,
58 std::vector<anab::CosmicTag>& cosmicTagVector,
59 std::vector<size_t>& assnTrackTagVector,
66 std::vector< const recob::OpFlash* > flashesOnBeamTime;
67 for(
auto const& flash : flashVector){
68 if(!flash.OnBeamTime())
continue;
69 flashesOnBeamTime.push_back(&flash);
74 cosmicTagVector.reserve(trackVector.size());
76 for(
size_t track_i=0; track_i<trackVector.size(); track_i++){
85 std::vector<float> xyz_begin = { (float)pt_begin.x(), (float)pt_begin.y(), (float)pt_begin.z()};
86 std::vector<float> xyz_end = {(float)pt_end.x(), (float)pt_end.y(), (float)pt_end.z()};
92 assnTrackTagVector[track_i] = cosmicTagVector.size()-1;
98 std::vector<float> lightHypothesis =
GetMIPHypotheses(track,providers,pvs,opdigip);
101 bool compatible=
false;
104 if(result==CompatibilityResultType::kCompatible) compatible=
true;
113 float cosmicScore=1.;
114 if(compatible) cosmicScore=0.;
116 assnTrackTagVector[track_i]=cosmicTagVector.size()-1;
123 unsigned int const event,
124 std::vector<recob::OpFlash>
const& flashVector,
125 std::vector<recob::Track>
const& trackVector,
135 std::vector< std::pair<unsigned int, const recob::OpFlash*> > flashesOnBeamTime;
136 for(
unsigned int i=0; i<flashVector.size(); i++){
139 flashesOnBeamTime.push_back(std::make_pair(i,&flash));
142 for(
size_t track_i=0; track_i<trackVector.size(); track_i++){
151 std::vector<float> xyz_begin = { (float)pt_begin.x(), (float)pt_begin.y(), (float)pt_begin.z()};
152 std::vector<float> xyz_end = {(float)pt_end.x(), (float)pt_end.y(), (float)pt_end.z()};
174 for(
auto flash : flashesOnBeamTime){
177 for(
size_t c=0; c<=geom.MaxOpChannel(); c++){
178 if ( geom.IsValidOpChannel( c ) ) {
179 unsigned int OpDet = geom.OpDetFromOpChannel(c);
205 unsigned int const event,
206 std::vector<recob::OpFlash>
const& flashVector,
207 std::vector<simb::MCParticle>
const& mcParticleVector,
217 std::vector< std::pair<unsigned int, const recob::OpFlash*> > flashesOnBeamTime;
218 for(
unsigned int i=0; i<flashVector.size(); i++){
221 flashesOnBeamTime.push_back(std::make_pair(i,&flash));
224 for(
size_t particle_i=0; particle_i<mcParticleVector.size(); particle_i++){
227 if(particle.
Process().compare(
"primary")!=0)
continue;
232 bool prev_inside=
false;
235 if(inside && !prev_inside) start_i = pt_i;
236 if(!inside && prev_inside) { end_i = pt_i-1;
break; }
237 prev_inside = inside;
239 TVector3
const& pt_begin = particle.
Position(start_i).Vect();
240 TVector3
const& pt_end = particle.
Position(end_i).Vect();
241 std::vector<float> xyz_begin = { (float)pt_begin.x(), (float)pt_begin.y(), (float)pt_begin.z()};
242 std::vector<float> xyz_end = {(float)pt_end.x(), (float)pt_end.y(), (float)pt_end.z()};
264 for(
auto flash : flashesOnBeamTime){
268 for(
size_t c=0; c<=geom.MaxOpChannel(); c++){
269 if ( geom.IsValidOpChannel(c) ) {
270 unsigned int OpDet = geom.OpDetFromOpChannel(c);
294 std::cout <<
"Flash/Hyp " << i <<
" : " 309 float&
y,
float& sigmay,
310 float&
z,
float& sigmaz,
312 y=0; sigmay=0; z=0; sigmaz=0; sum=0;
315 sum+=opdetVector[
opdet];
317 y += opdetVector[
opdet]*xyz[1];
318 z += opdetVector[
opdet]*xyz[2];
325 sigmay += (opdetVector[
opdet]*xyz[1]-
y)*(opdetVector[
opdet]*xyz[1]-y);
326 sigmaz += (opdetVector[
opdet]*xyz[2]-
y)*(opdetVector[
opdet]*xyz[2]-y);
329 sigmay = std::sqrt(sigmay)/sum;
330 sigmaz = std::sqrt(sigmaz)/sum;
335 if(pt.x() < 0 || pt.x() > 2*geom.
DetHalfWidth())
return false;
337 if(pt.z() < 0 || pt.z() > geom.
DetLength())
return false;
342 if(start_x < 0. || end_x < 0.)
return false;
349 std::vector<float> & lightHypothesis,
350 float & totalHypothesisPE,
353 float const& PromptMIPScintYield,
356 double xyz_segment[3];
357 xyz_segment[0] = 0.5*(pt2.x()+pt1.x()) + XOffset;
358 xyz_segment[1] = 0.5*(pt2.y()+pt1.y());
359 xyz_segment[2] = 0.5*(pt2.z()+pt1.z());
365 if(!PointVisibility)
return;
368 float LightAmount = PromptMIPScintYield*(pt2-pt1).Mag();
370 for(
size_t opdet_i=0; opdet_i<pvs.
NOpChannels(); opdet_i++){
371 lightHypothesis[opdet_i] += PointVisibility[opdet_i]*LightAmount;
372 totalHypothesisPE += PointVisibility[opdet_i]*LightAmount;
384 float const& totalHypothesisPE,
386 for(
size_t opdet_i=0; opdet_i<geom.
NOpDets(); opdet_i++)
387 lightHypothesis[opdet_i] /= totalHypothesisPE;
400 std::vector<float> lightHypothesis(geom.NOpDets(),0);
401 float totalHypothesisPE=0;
402 const float PromptMIPScintYield = larp.ScintYield()*larp.ScintYieldRatio()*opdigip.
QE()*
fMIPdQdx;
409 lightHypothesis,totalHypothesisPE,
410 geom,pvs,PromptMIPScintYield,
416 return lightHypothesis;
423 size_t start_i,
size_t end_i,
431 std::vector<float> lightHypothesis(geom.NOpDets(),0);
432 float totalHypothesisPE=0;
433 const float PromptMIPScintYield = larp.ScintYield()*larp.ScintYieldRatio()*opdigip.
QE()*
fMIPdQdx;
435 for(
size_t pt=start_i+1;
pt<=end_i;
pt++)
437 lightHypothesis,totalHypothesisPE,
438 geom,pvs,PromptMIPScintYield,
444 return lightHypothesis;
461 float hypothesis_integral=0;
462 float flash_integral=0;
463 unsigned int cumulativeChannels=0;
465 std::vector<double> PEbyOpDet(geom.
NOpDets(),0);
467 for (
unsigned int c = 0; c <= geom.
MaxOpChannel(); c++){
470 PEbyOpDet[o] += flashPointer->
PE(c);
474 float hypothesis_scale=1.;
477 for(
size_t pmt_i=0; pmt_i<lightHypothesis.size(); pmt_i++){
479 flash_integral += PEbyOpDet[pmt_i];
481 if(lightHypothesis[pmt_i] < std::numeric_limits<float>::epsilon() )
continue;
482 hypothesis_integral += lightHypothesis[pmt_i]*hypothesis_scale;
486 float diff_scaled = (lightHypothesis[pmt_i]*hypothesis_scale - PEbyOpDet[pmt_i])/std::sqrt(lightHypothesis[pmt_i]*hypothesis_scale);
488 if( diff_scaled >
fSingleChannelCut )
return CompatibilityResultType::kSingleChannelCut;
491 if(cumulativeChannels >=
fCumulativeChannelCut)
return CompatibilityResultType::kCumulativeChannelCut;
495 if( (hypothesis_integral - flash_integral)/std::sqrt(hypothesis_integral)
496 >
fIntegralCut)
return CompatibilityResultType::kIntegralCut;
498 return CompatibilityResultType::kCompatible;
503 std::vector<float>
const& light_track){
506 for(
size_t pmt_i=0; pmt_i<light_flash.size(); pmt_i++){
511 if(light_track[pmt_i] > 1) err2 = light_track[pmt_i];
513 chi2 += (light_flash[pmt_i]-light_track[pmt_i])*(light_flash[pmt_i]-light_track[pmt_i]) / err2;
522 *output <<
"----------------------------------------------" << std::endl;
523 *output <<
"Track properties: ";
524 *output <<
"\n\tLength=" << track.
Length();
527 *output <<
"\n\tBegin Location (x,y,z)=(" << pt_begin.x() <<
"," << pt_begin.y() <<
"," << pt_begin.z() <<
")";
530 *output <<
"\n\tEnd Location (x,y,z)=(" << pt_end.x() <<
"," << pt_end.y() <<
"," << pt_end.z() <<
")";
533 *output << std::endl;
534 *output <<
"----------------------------------------------" << std::endl;
539 *output <<
"----------------------------------------------" << std::endl;
540 *output <<
"Flash properties: ";
542 *output <<
"\n\tTime=" << flash.
Time();
543 *output <<
"\n\tOnBeamTime=" << flash.
OnBeamTime();
544 *output <<
"\n\ty position (center,width)=(" << flash.
YCenter() <<
"," << flash.
YWidth() <<
")";
545 *output <<
"\n\tz position (center,width)=(" << flash.
ZCenter() <<
"," << flash.
ZWidth() <<
")";
546 *output <<
"\n\tTotal PE=" << flash.
TotalPE();
548 *output << std::endl;
549 *output <<
"----------------------------------------------" << std::endl;
557 std::ostream* output)
560 *output <<
"----------------------------------------------" << std::endl;
561 *output <<
"Hypothesis-flash comparison: ";
563 float hypothesis_integral=0;
564 float flash_integral=0;
566 float hypothesis_scale=1.;
570 std::vector<double> PEbyOpDet(geom.
NOpDets(),0);
572 for (
unsigned int c = 0; c <= geom.
MaxOpChannel(); c++){
575 PEbyOpDet[o] += flashPointer->
PE(c);
579 for(
size_t pmt_i=0; pmt_i<lightHypothesis.size(); pmt_i++){
581 flash_integral += PEbyOpDet[pmt_i];
583 *output <<
"\n\t pmt_i=" << pmt_i <<
", (hypothesis,flash)=(" 584 << lightHypothesis[pmt_i]*hypothesis_scale <<
"," << PEbyOpDet[pmt_i] <<
")";
586 if(lightHypothesis[pmt_i] < std::numeric_limits<float>::epsilon() )
continue;
588 *output <<
" difference=" 589 << (lightHypothesis[pmt_i]*hypothesis_scale - PEbyOpDet[pmt_i])/std::sqrt(lightHypothesis[pmt_i]*hypothesis_scale);
591 hypothesis_integral += lightHypothesis[pmt_i]*hypothesis_scale;
594 *output <<
"\n\t TOTAL (hypothesis,flash)=(" 595 << hypothesis_integral <<
"," << flash_integral <<
")" 596 <<
" difference=" << (hypothesis_integral - flash_integral)/std::sqrt(hypothesis_integral);
598 *output << std::endl;
599 *output <<
"End result=" << result << std::endl;
600 *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)
void reconfigure(fhicl::ParameterSet const &p)
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
Access to track position at different points.
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
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.
float const * GetAllVisibilities(double const *xyz, bool wantReflected=false) const
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
T get(std::string const &key) const
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.
Description of geometry of one entire detector.
std::string leaf_structure
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 &)
size_t NOpChannels() const
double QE() const
Returns quantum efficiency.
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:
Event finding and building.
void PrintFlashProperties(recob::OpFlash const &, std::ostream *output=&std::cout)