9 #include "art/Framework/Core/EDAnalyzer.h"
10 #include "art/Framework/Core/ModuleMacros.h"
11 #include "art/Framework/Principal/Event.h"
12 #include "art/Framework/Principal/Handle.h"
13 #include "art/Framework/Services/Registry/ServiceHandle.h"
14 #include "art_root_io/TFileService.h"
15 #include "canvas/Persistency/Common/FindManyP.h"
16 #include "cetlib/pow.h"
17 #include "fhiclcpp/ParameterSet.h"
25 #include "nusimdata/SimulationBase/MCNeutrino.h"
26 #include "nusimdata/SimulationBase/MCParticle.h"
27 #include "nusimdata/SimulationBase/MCTruth.h"
33 #include "TProfile2D.h"
106 const double X0 = 14;
124 , fHitModuleLabel(pset.
get<
std::string>(
"HitModuleLabel",
"trajcluster"))
125 , fShowerModuleLabel(pset.
get<
std::string>(
"ShowerModuleLabel",
"tcshower"))
126 , fGenieGenModuleLabel(pset.
get<
std::string>(
"GenieGenModuleLabel",
"generator"))
127 , fCalorimetryAlg(pset.
get<fhicl::ParameterSet>(
"CalorimetryAlg"))
130 cet::search_path sp(
"FW_SEARCH_PATH");
132 throw cet::exception(
"TCShowerElectronLikelihood")
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);
175 art::ServiceHandle<art::TFileService const>
tfs;
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);
204 art::Handle<std::vector<recob::Hit>> hitListHandle;
205 std::vector<art::Ptr<recob::Hit>> hitlist;
206 if (evt.getByLabel(
fHitModuleLabel, hitListHandle)) art::fill_ptr_vector(hitlist, hitListHandle);
208 art::Handle<std::vector<recob::Shower>> showerListHandle;
209 std::vector<art::Ptr<recob::Shower>> showerlist;
211 art::fill_ptr_vector(showerlist, showerListHandle);
213 art::Handle<std::vector<simb::MCTruth>> mctruthListHandle;
214 std::vector<art::Ptr<simb::MCTruth>> mclist;
216 art::fill_ptr_vector(mclist, mctruthListHandle);
220 if (showerlist.size()) {
221 auto const clock_data =
222 art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
223 auto const det_prop =
224 art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(evt, clock_data);
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);
238 art::Ptr<simb::MCTruth> mctruth = mclist[0];
239 if (mctruth->NeutrinoSet()) {
240 if (
std::abs(mctruth->GetNeutrino().Nu().PdgCode()) == 12 &&
241 mctruth->GetNeutrino().CCNC() == 0) {
242 double elep = mctruth->GetNeutrino().Lepton().E();
285 art::ServiceHandle<geo::Geometry const> geom;
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;
299 double wirePitch = geom->WirePitch(showerhits[i]->
WireID());
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 throw cet::exception(
"TCShowerElectronLikelihood")
358 <<
"Bin mismatch in longitudinal profile template \n";
361 throw cet::exception(
"TCShowerElectronLikelihood")
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);
388 thischi2 += cet::square(obs - exp) /
exp;
393 for (
int j = 0; j < tbins; ++j) {
395 double exp = ttemp_1->GetBinContent(j + 1);
397 thischi2 += cet::square(obs - exp) /
exp;
402 exp = ttemp_2->GetBinContent(j + 1);
404 thischi2 += cet::square(obs - exp) /
exp;
409 exp = ttemp_3->GetBinContent(j + 1);
411 thischi2 += cet::square(obs - exp) /
exp;
416 exp = ttemp_4->GetBinContent(j + 1);
418 thischi2 += cet::square(obs - exp) /
exp;
423 exp = ttemp_5->GetBinContent(j + 1);
425 thischi2 += cet::square(obs - exp) /
exp;
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 std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
std::string fDigitModuleLabel
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.
double Temperature() const
In kelvin.
TProfile2D * tranTemplateProf2D_3
std::string fShowerModuleLabel
TH1F * tranLikelihoodHist
TProfile2D * tranTemplateProf2D
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
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
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
Contains all timing reference information for the detector.
TH1F * longLikelihoodHist
art::ServiceHandle< art::TFileService > tfs
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.
art framework interface to geometry description
BEGIN_PROLOG could also be cout