16 #include "art_root_io/TFileService.h" 46 #include "TTimeStamp.h" 92 bool insideFidVol(
const double posX,
const double posY,
const double posZ);
289 pot = potListHandle->totpot;
298 std::cout <<
" **************************************** analyze ************ " <<
std::endl;
304 const sim::ParticleList& plist = pi_serv->
ParticleList();
314 taulife = detProp.ElectronLifetime();
318 std::vector<art::Ptr<recob::Hit> > hitlist;
324 std::vector<art::Ptr<recob::Track> > tracklist;
330 std::vector<art::Ptr<recob::Vertex> > vtxlist;
336 std::vector<art::Ptr<recob::Shower>> shwlist;
342 std::vector<art::Ptr<recob::OpFlash> > flashlist;
349 art::FindManyP<recob::Hit, recob::TrackHitMeta> fmthm(trackListHandle, evt,
fTrackModuleLabel);
354 nhits = hitlist.size();
358 hit_plane[i] = hitlist[i]->WireID().Plane;
359 hit_wire[i] = hitlist[i]->WireID().Wire;
360 hit_tpc[i] = hitlist[i]->WireID().TPC;
364 hit_startT[i] = hitlist[i]->PeakTimeMinusRMS();
365 hit_endT[i] = hitlist[i]->PeakTimePlusRMS();
377 std::tie(trackStart, trackEnd) = tracklist[i]->Extent();
378 larStart = tracklist[i]->VertexDirection();
379 larEnd = tracklist[i]->EndDirection();
381 trkid[i] = tracklist[i]->ID();
394 trklen[i] = tracklist[i]->Length();
396 if (fmthm.isValid()){
397 auto vhit = fmthm.at(i);
398 auto vmeta = fmthm.data(i);
399 for (
size_t h = 0;
h < vhit.size(); ++
h){
410 else if (fmth.isValid()){
411 std::vector< art::Ptr<recob::Hit> > vhit = fmth.at(i);
412 for (
size_t h = 0;
h < vhit.size(); ++
h){
418 if (fmcal.isValid()){
419 unsigned maxnumhits = 0;
420 std::vector<const anab::Calorimetry*> calos = fmcal.at(i);
421 for (
auto const&
calo : calos){
422 if (
calo->PlaneID().isValid){
424 if (
calo->dEdx().size()>maxnumhits){
425 maxnumhits =
calo->dEdx().size();
430 for (
size_t ip = 0; ip<
calo->dEdx().size(); ++ip){
431 if (
calo->ResidualRange()[ip]<30){
432 pida +=
calo->dEdx()[ip]*
pow(
calo->ResidualRange()[ip],0.42);
436 if (used_trkres) pida/=used_trkres;
441 if (!
isdata&&fmth.isValid()){
444 std::vector< art::Ptr<recob::Hit> > allHits = fmth.at(i);
446 std::map<int,double> trkide;
447 for(
size_t h = 0;
h < allHits.size(); ++
h){
450 for(
size_t e = 0;
e < TrackIDs.size(); ++
e){
451 trkide[TrackIDs[
e].trackID] += TrackIDs[
e].energy;
459 if ((ii->second)>maxe){
472 float sum_energy = 0;
478 double mindis = 1e10;
480 for(
size_t h = 0;
h < allHits.size(); ++
h){
483 std::vector<art::Ptr<recob::SpacePoint> > spts = fmhs.at(hit.
key());
490 x = spts[0]->XYZ()[0];
491 y = spts[0]->XYZ()[1];
492 z = spts[0]->XYZ()[2];
497 for(
size_t h = 0;
h < allHits.size(); ++
h){
500 std::vector<art::Ptr<recob::SpacePoint> > spts = fmhs.at(hit.
key());
502 if (sqrt(
pow(spts[0]->XYZ()[0]-x,2)+
503 pow(spts[0]->XYZ()[1]-y,2)+
504 pow(spts[0]->XYZ()[2]-z,2))<3){
507 for(
size_t e = 0;
e < TrackIDs.size(); ++
e){
509 toten+=TrackIDs[
e].energy;
543 if ( pitch && numhits ) {
554 nvtx = vtxlist.size();
556 Double_t xyz[3] = {};
557 vtxlist[i]->XYZ(xyz);
558 for (
size_t j = 0; j<3; ++j)
vtx[i][j] = xyz[j];
562 if (shwListHandle.isValid()){
565 nshws = shwlist.size();
568 shwid[i] = shwlist[i]->ID();
569 shwdcosx[i] = shwlist[i]->Direction().X();
570 shwdcosy[i] = shwlist[i]->Direction().Y();
571 shwdcosz[i] = shwlist[i]->Direction().Z();
572 shwstartx[i] = shwlist[i]->ShowerStart().X();
573 shwstarty[i] = shwlist[i]->ShowerStart().Y();
574 shwstartz[i] = shwlist[i]->ShowerStart().Z();
575 for (
size_t j = 0; j<(shwlist[i]->Energy()).
size(); ++j){
576 shwenergy[i][j] = shwlist[i]->Energy()[j];
578 for (
size_t j = 0; j<(shwlist[i]->dEdx()).
size(); ++j){
579 shwdedx[i][j] = shwlist[i]->dEdx()[j];
583 auto vhit = fmsh.at(i);
584 for (
size_t h = 0;
h < vhit.size(); ++
h){
590 if (!
isdata&&fmsh.isValid()){
593 std::vector< art::Ptr<recob::Hit> > allHits = fmsh.at(i);
594 std::map<int,double> trkide;
595 for(
size_t h = 0;
h < allHits.size(); ++
h){
598 for(
size_t e = 0;
e < TrackIDs.size(); ++
e){
599 trkide[TrackIDs[
e].trackID] += TrackIDs[
e].energy;
607 if ((ii->second)>maxe){
638 std::vector<art::Ptr<simb::MCTruth> > mclist;
640 if (mctruthListHandle)
643 std::vector<art::Ptr<simb::MCFlux> > fluxlist;
645 if (mcfluxListHandle)
684 float mindist2 = 9999;
691 for(
size_t i = 0; i < vtxlist.size(); ++i){
692 Double_t xyz[3] = {};
693 vtxlist[i]->XYZ(xyz);
694 TVector3 vtxreco(xyz);
696 if (dist2 < mindist2)
707 for (
size_t i = 0; i < tracklist.size(); ++i){
709 if (dist2 < mindist2)
719 if (dist2 < mindist2)
733 if (fluxlist.size()){
745 std::vector<const simb::MCParticle* > geant_part;
748 for(
size_t p = 0;
p < plist.size(); ++
p)
751 geant_part.push_back(plist.Particle(
p));
760 int geant_particle=0;
765 for(
unsigned int i = 0; i < geant_part.size(); ++i ){
768 if(geant_part[i]->Process()==pri)
779 for(
unsigned int i = 0; i < geant_part.size(); ++i ){
782 if(geant_part[i]->Process()==pri)
789 Mother[i]=geant_part[i]->Mother();
791 TrackId[i]=geant_part[i]->TrackId();
793 pdg[i]=geant_part[i]->PdgCode();
795 Eng[i]=geant_part[i]->E();
798 Px[i]=geant_part[i]->Px();
799 Py[i]=geant_part[i]->Py();
800 Pz[i]=geant_part[i]->Pz();
806 EndPointx[i]=geant_part[i]->EndPosition()[0];
807 EndPointy[i]=geant_part[i]->EndPosition()[1];
808 EndPointz[i]=geant_part[i]->EndPosition()[2];
812 G4Process.push_back( geant_part[i]->Process() );
820 Startdcosx[i] = geant_part[i]->Momentum(0).Px() / geant_part[i]->Momentum(0).P();
821 Startdcosy[i] = geant_part[i]->Momentum(0).Py() / geant_part[i]->Momentum(0).P();
822 Startdcosz[i] = geant_part[i]->Momentum(0).Pz() / geant_part[i]->Momentum(0).P();
837 fTree = tfs->make<TTree>(
"nueana",
"analysis tree");
845 fTree->Branch(
"trkid",
trkid,
"trkid[ntracks_reco]/I");
849 fTree->Branch(
"trkendx",
trkendx,
"trkendx[ntracks_reco]/F");
850 fTree->Branch(
"trkendy",
trkendy,
"trkendy[ntracks_reco]/F");
851 fTree->Branch(
"trkendz",
trkendz,
"trkendz[ntracks_reco]/F");
858 fTree->Branch(
"trklen",
trklen,
"trklen[ntracks_reco]/F");
861 fTree->Branch(
"trkke",
trkke,
"trkke[ntracks_reco][3]/F");
862 fTree->Branch(
"trkpida",
trkpida,
"trkpida[ntracks_reco][3]/F");
863 fTree->Branch(
"trkg4id",
trkg4id,
"trkg4id[ntracks_reco]/I");
864 fTree->Branch(
"trkg4pdg",
trkg4pdg,
"trkg4pdg[ntracks_reco]/I");
870 fTree->Branch(
"shwid",
shwid,
"shwid[nshws]/I");
893 fTree->Branch(
"hit_tpc",
hit_tpc,
"hit_tpc[nhits_stored]/S");
894 fTree->Branch(
"hit_wire",
hit_wire,
"hit_wire[nhits_stored]/S");
900 fTree->Branch(
"hit_endT",
hit_endT,
"hit_endT[nhits_stored]/F");
902 fTree->Branch(
"hit_dQds",
hit_dQds,
"hit_dQds[nhits_stored]/F");
903 fTree->Branch(
"hit_dEds",
hit_dEds,
"hit_dEds[nhits_stored]/F");
908 fTree->Branch(
"vtx",
vtx,
"vtx[nvtx][3]/F");
937 fTree->Branch(
"pdg",
pdg,
"pdg[geant_list_size]/I");
938 fTree->Branch(
"Eng",
Eng,
"Eng[geant_list_size]/F");
939 fTree->Branch(
"Px",
Px,
"Px[geant_list_size]/F");
940 fTree->Branch(
"Py",
Py,
"Py[geant_list_size]/F");
941 fTree->Branch(
"Pz",
Pz,
"Pz[geant_list_size]/F");
945 fTree->Branch(
"EndPointx",
EndPointx,
"EndPointx[geant_list_size]/F");
946 fTree->Branch(
"EndPointy",
EndPointy,
"EndPointy[geant_list_size]/F");
947 fTree->Branch(
"EndPointz",
EndPointz,
"EndPointz[geant_list_size]/F");
948 fTree->Branch(
"Startdcosx",
Startdcosx,
"Startdcosx[geant_list_size]/F");
949 fTree->Branch(
"Startdcosy",
Startdcosy,
"Startdcosy[geant_list_size]/F");
950 fTree->Branch(
"Startdcosz",
Startdcosz,
"Startdcosz[geant_list_size]/F");
952 fTree->Branch(
"Mother",
Mother,
"Mother[geant_list_size]/I");
953 fTree->Branch(
"TrackId",
TrackId,
"TrackId[geant_list_size]/I");
966 fPOT = tfs->make<TTree>(
"pottree",
"pot tree");
967 fPOT->Branch(
"pot",&
pot,
"pot/D");
968 fPOT->Branch(
"run",&
run,
"run/I");
1002 for (
int j = 0; j<3; ++j){
1003 trkke[i][j] = -9999;
1023 for (
int j = 0; j<3; ++j){
1156 double vtx[3] = {posX, posY, posZ};
1157 bool inside =
false;
1164 double minx = tpcgeo.
MinX();
double maxx = tpcgeo.
MaxX();
1165 double miny = tpcgeo.
MinY();
double maxy = tpcgeo.
MaxY();
1166 double minz = tpcgeo.
MinZ();
double maxz = tpcgeo.
MaxZ();
1171 for (
size_t t = 0;
t < cryostat.
NTPC();
t++)
1174 if (tpcg.
MinX() < minx) minx = tpcg.
MinX();
1175 if (tpcg.
MaxX() > maxx) maxx = tpcg.
MaxX();
1176 if (tpcg.
MinY() < miny) miny = tpcg.
MinY();
1177 if (tpcg.
MaxY() > maxy) maxy = tpcg.
MaxY();
1178 if (tpcg.
MinZ() < minz) minz = tpcg.
MinZ();
1179 if (tpcg.
MaxZ() > maxz) maxz = tpcg.
MaxZ();
1185 double dista = fabs(minx - posX);
1186 double distb = fabs(posX - maxx);
1187 if ((posX > minx) && (posX < maxx) &&
1190 dista = fabs(maxy - posY);
1191 distb = fabs(posY - miny);
1192 if (inside && (posY > miny) && (posY < maxy) &&
1194 else inside =
false;
1197 dista = fabs(maxz - posZ);
1198 distb = fabs(posZ - minz);
1199 if (inside && (posZ > minz) && (posZ < maxz) &&
1201 else inside =
false;
double E(const int i=0) const
bool insideFidVol(const double posX, const double posY, const double posZ)
std::string fCalorimetryModuleLabel
Float_t hit_startT[kMaxHits]
int TrackId[kMaxPrimaries]
constexpr std::uint32_t timeLow() const
const simb::MCNeutrino & GetNeutrino() const
double Py(const int i=0) const
CryostatGeo const & GetElement(geo::CryostatID const &cryoid) const
Float_t flash_YWidth[kMaxFlash]
float trkenddcosy[kMaxTrack]
float trkstartdcosz[kMaxTrack]
std::vector< sim::TrackIDE > HitToTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
std::string fClusterModuleLabel
Short_t hit_wire[kMaxHits]
int Mother[kMaxPrimaries]
double Dist2(const TVector2 &v1, const TVector2 &v2)
Float_t hit_dQds[kMaxHits]
float trkg4startx[kMaxTrack]
Float_t shwdedx[kMaxShower][3]
Float_t flash_ZWidth[kMaxFlash]
Handle< PROD > getHandle(SelectorBase const &) const
Float_t shwstartx[kMaxShower]
void analyze(art::Event const &e) override
std::vector< TrackID > TrackIDs
const simb::MCParticle * TrackIdToParticle_P(int id) const
float trkg4startz[kMaxTrack]
geo::WireID WireID() const
Float_t shwdcosz[kMaxShower]
Float_t EndPointy[kMaxPrimaries]
Float_t hit_summedADC[kMaxHits]
Float_t flash_TotalPE[kMaxFlash]
const simb::MCParticle & Nu() const
constexpr std::uint32_t timeHigh() const
Float_t shwstarty[kMaxShower]
simb::Origin_t Origin() const
double MinX() const
Returns the world x coordinate of the start of the box.
Geometry information for a single TPC.
double Px(const int i=0) const
Short_t hit_plane[kMaxHits]
Float_t hit_dEds[kMaxHits]
Float_t Pz[kMaxPrimaries]
Float_t shwdcosx[kMaxShower]
float trkmomrange[kMaxTrack]
int shwbestplane[kMaxShower]
Int_t hit_trkkey[kMaxHits]
Planes which measure Z direction.
Float_t flash_abstime[kMaxFlash]
int process_primary[kMaxPrimaries]
double MaxX() const
Returns the world x coordinate of the end of the box.
float trkstartx[kMaxTrack]
float trkstartz[kMaxTrack]
Float_t hit_endT[kMaxHits]
Geometry information for a single cryostat.
std::string fVertexModuleLabel
EDAnalyzer(fhicl::ParameterSet const &pset)
NueAna & operator=(NueAna const &)=delete
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
int NumberDaughters[kMaxPrimaries]
void reconfigure(fhicl::ParameterSet const &p)
void endSubRun(const art::SubRun &sr) override
object containing MC flux information
art framework interface to geometry description
Float_t hit_charge[kMaxHits]
tracking::Vector_t Vector_t
geo::TPCID FindTPCAtPosition(double const worldLoc[3]) const
Returns the ID of the TPC at specified location.
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
float trkpida[kMaxTrack][3]
float trkg4starty[kMaxTrack]
Float_t shwdcosy[kMaxShower]
const simb::MCParticle & Lepton() const
#define DEFINE_ART_MODULE(klass)
std::string fHitsModuleLabel
Float_t Eng[kMaxPrimaries]
constexpr int kMaxPrimaries
std::string fPOTModuleLabel
Float_t flash_time[kMaxFlash]
double P(const int i=0) const
key_type key() const noexcept
T get(std::string const &key) const
double T(const int i=0) const
double MinZ() const
Returns the world z coordinate of the start of the box.
unsigned int NTPC() const
Number of TPCs in this cryostat.
CryostatGeo const & Cryostat(geo::CryostatID const &cryoid) const
Returns the specified cryostat.
SubRunNumber_t subRun() const
The data type to uniquely identify a TPC.
PlaneID_t Plane
Index of the plane within its TPC.
Float_t hit_peakT[kMaxHits]
std::string fGenieGenModuleLabel
float trkke[kMaxTrack][3]
Float_t shwenergy[kMaxShower][3]
Float_t StartPointx[kMaxPrimaries]
Detector simulation of raw signals on wires.
double MaxY() const
Returns the world y coordinate of the end of the box.
const sim::ParticleList & ParticleList() const
const simb::MCParticle & GetParticle(int i) const
Float_t flash_ZCenter[kMaxFlash]
std::vector< std::string > G4FinalProcess
bool HasTPC(geo::TPCID const &tpcid) const
Returns whether we have the specified TPC.
float trkenddcosz[kMaxTrack]
std::string fTrackModuleLabel
Float_t hit_resrange[kMaxHits]
double Vx(const int i=0) const
Float_t vtx[kMaxVertices][3]
std::string fShowerModuleLabel
Implementation of the Projection Matching Algorithm.
std::string fFlashModuleLabel
Declaration of signal hit object.
calo::CalorimetryAlg fCalorimetryAlg
float trkstartdcosx[kMaxTrack]
Float_t Startdcosx[kMaxPrimaries]
Float_t Py[kMaxPrimaries]
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
constexpr int kMaxVertices
Float_t Startdcosy[kMaxPrimaries]
const TPCGeo & TPC(unsigned int itpc) const
Return the itpc'th TPC in the cryostat.
int trkbestplane[kMaxTrack]
NueAna(fhicl::ParameterSet const &p)
Float_t shwstartz[kMaxShower]
Float_t flash_width[kMaxFlash]
double MaxZ() const
Returns the world z coordinate of the end of the box.
float trkg4initdedx[kMaxTrack]
tracking::Point_t Point_t
double TrackPitchInView(recob::Track const &track, geo::View_t view, size_t trajectory_point=0U)
Returns the projected length of track on a wire pitch step [cm].
double Pz(const int i=0) const
Provides recob::Track data product.
double dEdx_AREA(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, recob::Hit const &hit, double pitch, double T0=0) const
double Vz(const int i=0) const
Int_t hit_shwkey[kMaxHits]
Float_t EndPointx[kMaxPrimaries]
EventNumber_t event() const
Float_t StartPointz[kMaxPrimaries]
boost::graph_traits< ModuleGraph >::vertex_descriptor Vertex
Float_t Px[kMaxPrimaries]
Float_t Startdcosz[kMaxPrimaries]
auto const & get(AssnsNode< L, R, D > const &r)
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Float_t flash_YCenter[kMaxFlash]
double LifetimeCorrection(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, double time, double T0=0) const
Float_t StartPointy[kMaxPrimaries]
static constexpr double sr
float trkstarty[kMaxTrack]
double MinY() const
Returns the world y coordinate of the start of the box.
float trkenddcosx[kMaxTrack]
Utility functions to extract information from recob::Track
Float_t EndPointz[kMaxPrimaries]
Int_t hit_channel[kMaxHits]
double Vy(const int i=0) const
double GetTrackMomentum(double trkrange, int pdg) const
float trkstartdcosy[kMaxTrack]
Short_t hit_tpc[kMaxHits]
QTextStream & endl(QTextStream &s)
Event finding and building.
std::vector< std::string > G4Process