14 #include "art_root_io/TFileService.h" 15 #include "canvas/Persistency/Common/FindManyP.h" 33 #include "TProfile2D.h" 106 const double X0 = 14;
133 <<
"cannot find the root template file: \n" 158 "tranProfile_1",
"transverse shower profile [0 <= t < 1];dist (cm);Q",
TBINS,
TMIN,
TMAX);
160 "tranProfile_2",
"transverse shower profile [1 <= t < 2];dist (cm);Q",
TBINS,
TMIN,
TMAX);
162 "tranProfile_3",
"transverse shower profile [2 <= t < 3];dist (cm);Q",
TBINS,
TMIN,
TMAX);
164 "tranProfile_4",
"transverse shower profile [3 <= t < 4];dist (cm);Q",
TBINS,
TMIN,
TMAX);
166 "tranProfile_5",
"transverse shower profile [4 <= t < 5];dist (cm);Q",
TBINS,
TMIN,
TMAX);
177 energyDist = tfs->make<TH1F>(
"energyDist",
"true energy - guess energy", 41, -20.5, 20.5);
178 longLikelihoodHist = tfs->make<TH1F>(
"longLikelihoodHist",
"longitudinal likelihood", 20, 0, 2);
179 tranLikelihoodHist = tfs->make<TH1F>(
"tranLikelihoodHist",
"transverse likelihood", 20, 0, 3);
183 tfs->make<TH1F>(
"longProfHist",
"longitudinal e- profile (reco);t;Q",
LBINS,
LMIN,
LMAX);
185 "tranProfHist",
"transverse e- profile (reco) [0 <= t < 1];dist (cm);Q",
TBINS,
TMIN,
TMAX);
187 "tranProfHist",
"transverse e- profile (reco) [1 <= t < 2];dist (cm);Q",
TBINS,
TMIN,
TMAX);
189 "tranProfHist",
"transverse e- profile (reco) [2 <= t < 3];dist (cm);Q",
TBINS,
TMIN,
TMAX);
191 "tranProfHist",
"transverse e- profile (reco) [3 <= t < 4];dist (cm);Q",
TBINS,
TMIN,
TMAX);
193 "tranProfHist",
"transverse e- profile (reco) [4 <= t < 5];dist (cm);Q",
TBINS,
TMIN,
TMAX);
205 std::vector<art::Ptr<recob::Hit>> hitlist;
209 std::vector<art::Ptr<recob::Shower>> showerlist;
214 std::vector<art::Ptr<simb::MCTruth>> mclist;
220 if (showerlist.size()) {
221 auto const clock_data =
223 auto const det_prop =
225 std::vector<art::Ptr<recob::Hit>> showerhits = shwfm.at(0);
227 clock_data, det_prop, showerhits, showerlist[0]->ShowerStart(), showerlist[0]->
Direction());
229 maxt = std::ceil((90 - showerlist[0]->ShowerStart().
Z()) /
X0);
289 double shwVtxTime = detProp.
ConvertXToTicks(shwvtx[0], collectionPlane);
290 double shwVtxWire = geom->
WireCoordinate(shwvtx[1], shwvtx[2], collectionPlane);
292 double shwTwoTime = detProp.
ConvertXToTicks(shwvtx[0] + shwdir[0], collectionPlane);
294 geom->
WireCoordinate(shwvtx[1] + shwdir[1], shwvtx[2] + shwdir[2], collectionPlane);
296 for (
size_t i = 0; i < showerhits.size(); ++i) {
297 if (showerhits[i]->
WireID().Plane != collectionPlane.Plane)
continue;
303 double xvtx = shwVtxTime * tickToDist;
304 double yvtx = shwVtxWire * wirePitch;
306 double xtwo = shwTwoTime * tickToDist;
307 double ytwo = shwTwoWire * wirePitch;
309 double xtwoorth = (ytwo - yvtx) + xvtx;
310 double ytwoorth = -(xtwo - xvtx) + yvtx;
312 double xhit = showerhits[i]->PeakTime() * tickToDist;
313 double yhit = showerhits[i]->WireID().Wire * wirePitch;
315 double ldist =
std::abs((ytwoorth - yvtx) * xhit - (xtwoorth - xvtx) * yhit + xtwoorth * yvtx -
318 double tdist = ((ytwo - yvtx) * xhit - (xtwo - xvtx) * yhit + xtwo * yvtx - ytwo * xvtx) /
325 double t = ldist /
X0;
327 double Q = showerhits[i]->Integral() *
358 <<
"Bin mismatch in longitudinal profile template \n";
362 <<
"Bin mismatch in transverse profile template \n";
364 double chi2min = 999999;
371 for (
int i = 0; i < ebins; ++i) {
384 for (
int j = 0; j < lbins; ++j) {
386 double exp = ltemp->GetBinContent(j + 1);
393 for (
int j = 0; j < tbins; ++j) {
395 double exp = ttemp_1->GetBinContent(j + 1);
402 exp = ttemp_2->GetBinContent(j + 1);
409 exp = ttemp_3->GetBinContent(j + 1);
416 exp = ttemp_4->GetBinContent(j + 1);
423 exp = ttemp_5->GetBinContent(j + 1);
430 thischi2 /= (nlbins + ntbins);
432 if (thischi2 < chi2min) {
451 double longLikelihood = 0.;
454 for (
int i = 0; i <
LBINS; ++i) {
457 int binentries =
longTemplate->GetBinContent(i + 1, energyBin, qbin);
458 int totentries =
longTemplate->Integral(i + 1, i + 1, energyBin, energyBin, 0, 100);
461 double prob = (double)binentries / totentries * 100;
462 if (binentries > 0) longLikelihood += log(prob);
466 longLikelihood /=
nbins;
468 std::cout << longLikelihood <<
std::endl;
469 return longLikelihood;
480 double tranLikelihood_1 = 0;
481 double tranLikelihood_2 = 0;
482 double tranLikelihood_3 = 0;
483 double tranLikelihood_4 = 0;
484 double tranLikelihood_5 = 0;
487 int qbin, binentries, totentries;
491 for (
int i = 0; i <
TBINS; ++i) {
494 binentries =
tranTemplate_1->GetBinContent(i + 1, energyBin, qbin);
495 totentries =
tranTemplate_1->Integral(i + 1, i + 1, energyBin, energyBin, 0, 100);
498 double prob = (double)binentries / totentries * 100;
499 if (binentries > 0) tranLikelihood_1 += log(prob);
504 binentries =
tranTemplate_2->GetBinContent(i + 1, energyBin, qbin);
505 totentries =
tranTemplate_2->Integral(i + 1, i + 1, energyBin, energyBin, 0, 100);
508 double prob = (double)binentries / totentries * 100;
509 if (binentries > 0) tranLikelihood_2 += log(prob);
514 binentries =
tranTemplate_3->GetBinContent(i + 1, energyBin, qbin);
515 totentries =
tranTemplate_3->Integral(i + 1, i + 1, energyBin, energyBin, 0, 100);
518 double prob = (double)binentries / totentries * 100;
519 if (binentries > 0) tranLikelihood_3 += log(prob);
524 binentries =
tranTemplate_4->GetBinContent(i + 1, energyBin, qbin);
525 totentries =
tranTemplate_4->Integral(i + 1, i + 1, energyBin, energyBin, 0, 100);
528 double prob = (double)binentries / totentries * 100;
529 if (binentries > 0) tranLikelihood_4 += log(prob);
534 binentries =
tranTemplate_5->GetBinContent(i + 1, energyBin, qbin);
535 totentries =
tranTemplate_5->Integral(i + 1, i + 1, energyBin, energyBin, 0, 100);
538 double prob = (double)binentries / totentries * 100;
539 if (binentries > 0) tranLikelihood_5 += log(prob);
544 double const tranLikelihood =
545 (tranLikelihood_1 + tranLikelihood_2 + tranLikelihood_3 + tranLikelihood_4 + tranLikelihood_5) /
547 std::cout << tranLikelihood <<
std::endl;
548 return tranLikelihood;
double E(const int i=0) const
geo::Length_t WireCoordinate(double YPos, double ZPos, geo::PlaneID const &planeid) const
Returns the index of the nearest wire to the specified position.
std::string fDigitModuleLabel
const simb::MCNeutrino & GetNeutrino() const
TProfile2D * tranTemplateProf2D_5
TProfile2D * tranTemplateProf2D_4
void getShowerProfile(detinfo::DetectorClocksData const &clockdata, detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit >> showerhits, TVector3 shwvtx, TVector3 shwdir)
const simb::MCParticle & Nu() const
double Temperature() const
In kelvin.
TProfile2D * tranTemplateProf2D_3
std::string fShowerModuleLabel
TH1F * tranLikelihoodHist
TProfile2D * tranTemplateProf2D
EDAnalyzer(fhicl::ParameterSet const &pset)
calo::CalorimetryAlg fCalorimetryAlg
geo::Length_t WirePitch(geo::PlaneID const &planeid) const
Returns the distance between two consecutive wires.
TProfile2D * longTemplateProf2D
art framework interface to geometry description
std::enable_if_t< std::is_arithmetic_v< T >, T > hypot(T x, T y)
TCShowerElectronLikelihood(fhicl::ParameterSet const &pset)
double Efield(unsigned int planegap=0) const
kV/cm
std::string fTemplateModuleLabel
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
std::string fHitModuleLabel
const simb::MCParticle & Lepton() const
#define DEFINE_ART_MODULE(klass)
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
T get(std::string const &key) const
double getTranLikelihood()
TProfile2D * tranTemplateProf2D_2
TProfile2D * tranTemplateProf2D_1
double ConvertXToTicks(double X, int p, int t, int c) const
double DriftVelocity(double efield=0., double temperature=0.) const
cm/us
double getLongLikelihood()
std::string fGenieGenModuleLabel
std::string fTemplateFile
Declaration of signal hit object.
Contains all timing reference information for the detector.
TH1F * longLikelihoodHist
detail::Node< FrameID, bool > PlaneID
auto const & get(AssnsNode< L, R, D > const &r)
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
void analyze(const art::Event &evt) override
double LifetimeCorrection(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, double time, double T0=0) const
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)