14 #include "art_root_io/TFileService.h" 16 #include "cetlib/pow.h" 33 #include "TProfile2D.h" 106 const double X0 = 14;
130 cet::search_path sp(
"FW_SEARCH_PATH");
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);
176 energyDist = tfs->make<TH1F>(
"energyDist",
"true energy - guess energy", 41, -20.5, 20.5);
177 longLikelihoodHist = tfs->make<TH1F>(
"longLikelihoodHist",
"longitudinal likelihood", 20, 0, 2);
178 tranLikelihoodHist = tfs->make<TH1F>(
"tranLikelihoodHist",
"transverse likelihood", 20, 0, 3);
182 tfs->make<TH1F>(
"longProfHist",
"longitudinal e- profile (reco);t;Q",
LBINS,
LMIN,
LMAX);
184 "tranProfHist",
"transverse e- profile (reco) [0 <= t < 1];dist (cm);Q",
TBINS,
TMIN,
TMAX);
186 "tranProfHist",
"transverse e- profile (reco) [1 <= t < 2];dist (cm);Q",
TBINS,
TMIN,
TMAX);
188 "tranProfHist",
"transverse e- profile (reco) [2 <= t < 3];dist (cm);Q",
TBINS,
TMIN,
TMAX);
190 "tranProfHist",
"transverse e- profile (reco) [3 <= t < 4];dist (cm);Q",
TBINS,
TMIN,
TMAX);
192 "tranProfHist",
"transverse e- profile (reco) [4 <= t < 5];dist (cm);Q",
TBINS,
TMIN,
TMAX);
203 std::vector<art::Ptr<recob::Hit>> hitlist;
207 std::vector<art::Ptr<recob::Shower>> showerlist;
212 std::vector<art::Ptr<simb::MCTruth>> mclist;
218 if (showerlist.size()) {
219 auto const clock_data =
221 auto const det_prop =
223 std::vector<art::Ptr<recob::Hit>> showerhits = shwfm.at(0);
225 clock_data, det_prop, showerhits, showerlist[0]->ShowerStart(), showerlist[0]->
Direction());
227 maxt = std::ceil((90 - showerlist[0]->ShowerStart().
Z()) /
X0);
287 auto const shwvtx_p =
toPoint(shwvtx);
288 auto const shwvtx_p2 = shwvtx_p +
toVector(shwdir);
290 double shwVtxTime = detProp.
ConvertXToTicks(shwvtx_p.X(), collectionPlane);
291 double shwVtxWire = geom->
WireCoordinate(shwvtx_p, collectionPlane);
293 double shwTwoTime = detProp.
ConvertXToTicks(shwvtx_p2.X(), collectionPlane);
294 double shwTwoWire = geom->
WireCoordinate(shwvtx_p2, 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 -
317 std::hypot(ytwoorth - yvtx, xtwoorth - xvtx);
318 double tdist = ((ytwo - yvtx) * xhit - (xtwo - xvtx) * yhit + xtwo * yvtx - ytwo * xvtx) /
319 std::hypot(ytwo - yvtx, xtwo - xvtx);
321 double to3D = 1. / std::hypot(xvtx - xtwo,
325 double t = ldist /
X0;
327 double Q = showerhits[i]->Integral() *
357 <<
"Bin mismatch in longitudinal profile template \n";
361 <<
"Bin mismatch in transverse profile template \n";
363 double chi2min = 999999;
370 for (
int i = 0; i < ebins; ++i) {
383 for (
int j = 0; j < lbins; ++j) {
385 double exp = ltemp->GetBinContent(j + 1);
387 thischi2 += cet::square(obs - exp) / exp;
392 for (
int j = 0; j < tbins; ++j) {
394 double exp = ttemp_1->GetBinContent(j + 1);
396 thischi2 += cet::square(obs - exp) / exp;
401 exp = ttemp_2->GetBinContent(j + 1);
403 thischi2 += cet::square(obs - exp) / exp;
408 exp = ttemp_3->GetBinContent(j + 1);
410 thischi2 += cet::square(obs - exp) / exp;
415 exp = ttemp_4->GetBinContent(j + 1);
417 thischi2 += cet::square(obs - exp) / exp;
422 exp = ttemp_5->GetBinContent(j + 1);
424 thischi2 += cet::square(obs - exp) / exp;
429 thischi2 /= (nlbins + ntbins);
431 if (thischi2 < chi2min) {
449 double longLikelihood = 0.;
452 for (
int i = 0; i <
LBINS; ++i) {
455 int binentries =
longTemplate->GetBinContent(i + 1, energyBin, qbin);
456 int totentries =
longTemplate->Integral(i + 1, i + 1, energyBin, energyBin, 0, 100);
459 double prob = (double)binentries / totentries * 100;
460 if (binentries > 0) longLikelihood += log(prob);
464 longLikelihood /= nbins;
466 std::cout << longLikelihood << std::endl;
467 return longLikelihood;
477 double tranLikelihood_1 = 0;
478 double tranLikelihood_2 = 0;
479 double tranLikelihood_3 = 0;
480 double tranLikelihood_4 = 0;
481 double tranLikelihood_5 = 0;
484 int qbin, binentries, totentries;
488 for (
int i = 0; i <
TBINS; ++i) {
491 binentries =
tranTemplate_1->GetBinContent(i + 1, energyBin, qbin);
492 totentries =
tranTemplate_1->Integral(i + 1, i + 1, energyBin, energyBin, 0, 100);
495 double prob = (double)binentries / totentries * 100;
496 if (binentries > 0) tranLikelihood_1 += log(prob);
501 binentries =
tranTemplate_2->GetBinContent(i + 1, energyBin, qbin);
502 totentries =
tranTemplate_2->Integral(i + 1, i + 1, energyBin, energyBin, 0, 100);
505 double prob = (double)binentries / totentries * 100;
506 if (binentries > 0) tranLikelihood_2 += log(prob);
511 binentries =
tranTemplate_3->GetBinContent(i + 1, energyBin, qbin);
512 totentries =
tranTemplate_3->Integral(i + 1, i + 1, energyBin, energyBin, 0, 100);
515 double prob = (double)binentries / totentries * 100;
516 if (binentries > 0) tranLikelihood_3 += log(prob);
521 binentries =
tranTemplate_4->GetBinContent(i + 1, energyBin, qbin);
522 totentries =
tranTemplate_4->Integral(i + 1, i + 1, energyBin, energyBin, 0, 100);
525 double prob = (double)binentries / totentries * 100;
526 if (binentries > 0) tranLikelihood_4 += log(prob);
531 binentries =
tranTemplate_5->GetBinContent(i + 1, energyBin, qbin);
532 totentries =
tranTemplate_5->Integral(i + 1, i + 1, energyBin, energyBin, 0, 100);
535 double prob = (double)binentries / totentries * 100;
536 if (binentries > 0) tranLikelihood_5 += log(prob);
541 double const tranLikelihood =
542 (tranLikelihood_1 + tranLikelihood_2 + tranLikelihood_3 + tranLikelihood_4 + tranLikelihood_5) /
544 std::cout << tranLikelihood << std::endl;
545 return tranLikelihood;
double E(const int i=0) const
std::string fDigitModuleLabel
Length_t WireCoordinate(Point_t const &pos, PlaneID const &planeid) const
Returns the index of the nearest wire to the specified position.
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)
Declaration of signal hit object.
const simb::MCParticle & Nu() const
double Temperature() const
In kelvin.
::geo::Point_t toPoint(Point const &p)
Convert the specified point into a geo::Point_t.
TProfile2D * tranTemplateProf2D_3
constexpr auto abs(T v)
Returns the absolute value of the argument.
std::string fShowerModuleLabel
TH1F * tranLikelihoodHist
::geo::Vector_t toVector(Vector const &v)
Convert the specified vector into a geo::Vector_t.
TProfile2D * tranTemplateProf2D
EDAnalyzer(fhicl::ParameterSet const &pset)
calo::CalorimetryAlg fCalorimetryAlg
TProfile2D * longTemplateProf2D
TCShowerElectronLikelihood(fhicl::ParameterSet const &pset)
double Efield(unsigned int planegap=0) const
kV/cm
IDparameter< geo::PlaneID > PlaneID
Member type of validated geo::PlaneID parameter.
std::string fTemplateModuleLabel
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
std::string fHitModuleLabel
Utilities to manipulate geometry vectors.The utilities include generic vector interface facilities al...
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
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Contains all timing reference information for the detector.
TH1F * longLikelihoodHist
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.
Length_t WirePitch(PlaneID const &planeid=plane_zero) const
Returns the distance between two consecutive wires.
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception