20 #include "art_root_io/TFileService.h" 41 #include "TTimeStamp.h" 114 std::pair<double,size_t>
FlashMatch(
const double reco_time);
116 double MatchTracks(std::vector<TVector3>& sorted_trk, std::vector<TLorentzVector> mcpart);
117 std::vector<std::vector< TLorentzVector>>
BuildMCParticleList(
const art::Handle<std::vector<simb::MCParticle>>& mcpart_h,
const double& fTPCResolution,
const double& width);
182 auto const* geom = lar::providerFrom<geo::Geometry>();
189 for (
geo::TPCID const& tID: geom->IterateTPCIDs()) {
203 if (top > TOP) TOP =
top;
213 double efield = detProp.Efield();
214 double temp = detProp.Temperature();
222 tree = tfs->make<TTree>(
"tree",
"SCE calibrations variables");
249 tree->Branch(
"run",&
run,
"run/I");
254 evTree = tfs->make<TTree>(
"evTree",
"Event information");
260 caloTree = tfs->make<TTree>(
"caloTree",
"Uncorrected calorimetry information");
307 std::vector<std::vector<TLorentzVector>> mcpart_list;
324 std::cerr<<
"\033[93m[ERROR]\033[00m ... could not locate Flash!"<<
std::endl;
335 trigger_time = trigger_h->at(0).Time();
343 if(!track_h.isValid()) {
344 std::cerr<<
"\033[93m[ERROR]\033[00m ... could not locate Track!"<<
std::endl;
348 std::vector<art::Ptr<recob::Track> > TrkVec;
352 art::FindMany<recob::Hit> trk_hit_assn_v(track_h, e,
fHitProducer);
355 art::FindMany<anab::Calorimetry> trk_calo_assn_v(track_h,e,
fCaloProducer);
358 std::cout <<
"Number of tracks: " << TrkVec.size() <<
std::endl;
359 std::cout <<
"Number of hits: " << trk_hit_assn_v.size() <<
std::endl;
360 std::cout <<
"Number of calorimetry products: " << trk_calo_assn_v.size() <<
"\n" <<
std::endl;
364 auto mcpart_h = e.
getHandle<std::vector<simb::MCParticle> >(
"largeant");
369 if(!mcpart_h.isValid()) {
370 std::cerr<<
"\033[93m[ERROR]\033[00m ... could not locate MCParticle!"<<
std::endl;
378 art::FindMany<anab::T0> trk_t0_assn_v(track_h, e,
fT0Producer );
383 size_t flash_ctr = 0;
384 for (
auto const& flash : *flash_h){
385 if (flash.TotalPE() >
fPEmin){
388 if (
_debug) std::cout <<
"\t flash time : " << flash.Time() - trigger_time <<
", PE : " << flash.TotalPE() <<
std::endl;
397 size_t trk_ctr2 = -1;
399 for (
auto& track : TrkVec){
404 const std::vector<const recob::Hit*>& Hit_v = trk_hit_assn_v.at(trk_ctr2);
406 const std::vector<const anab::Calorimetry*>& Calo_v = trk_calo_assn_v.at(trk_ctr2);
447 std::vector<TVector3> sorted_trk;
449 if(
_debug) std::cout <<
"\tTrack goes from (" << sorted_trk.at(0).X() <<
", " << sorted_trk.at(0).Y() <<
", " << sorted_trk.at(0).Z() <<
") --> (" << sorted_trk.at(sorted_trk.size()-1).
X() <<
", " << sorted_trk.at(sorted_trk.size()-1).
Y() <<
", " << sorted_trk.at(sorted_trk.size()-1).
Z() <<
")" <<
std::endl;
451 if( sqrt(
pow(sorted_trk.at(0).X() - sorted_trk.at(sorted_trk.size()-1).
X(),2.0) +
pow(sorted_trk.at(0).Y() - sorted_trk.at(sorted_trk.size()-1).
Y(),2.0) +
pow(sorted_trk.at(0).Z() - sorted_trk.at(sorted_trk.size()-1).
Z(),2.0)) < 50 ){
457 auto const* geom = lar::providerFrom<geo::Geometry>();
458 auto const*
hit = Hit_v.at(0);
460 const auto TPCGeoObject = geom->TPC(wireID.
TPC,wireID.
Cryostat);
461 short int driftDir1 = TPCGeoObject.DetectDriftDirection();
462 bool cross_cathode =
false;
463 for (
size_t ii = 1; ii < Hit_v.size(); ii++) {
464 const geo::WireID wireID2 = Hit_v.at(ii)->WireID();
465 const auto TPCGeoObject2 = geom->TPC(wireID2.
TPC,wireID2.
Cryostat);
466 short int driftDir2 = TPCGeoObject2.DetectDriftDirection();
468 if(driftDir1 + driftDir2 == 0){
469 cross_cathode =
true;
475 if(
_debug) std::cout <<
"\tCross cathode = " << cross_cathode <<
std::endl;
505 std::vector<TVector3> top_trk = {sorted_trk.at(0), sorted_trk.at(1)};
506 std::vector<TVector3> bottom_trk = {sorted_trk.at(2), sorted_trk.at(3)};
508 if(
_debug)std::cout <<
"\tCathode-crossing track from (" << top_trk.at(0).X() <<
", " << top_trk.at(0).Y() <<
", " << top_trk.at(0).Z() <<
") --> (" << top_trk.at(1).X() <<
", " << top_trk.at(1).Y() <<
", " << top_trk.at(1).Z() <<
") --> (" << bottom_trk.at(0).X() <<
", " << bottom_trk.at(0).Y() <<
", " << bottom_trk.at(0).Z() <<
") --> (" << bottom_trk.at(1).X() <<
", " << bottom_trk.at(1).Y() <<
", " << bottom_trk.at(1).Z() <<
")" <<
std::endl;
514 auto const &
top = top_trk.at(0);
515 auto const &
bottom = top_trk.at(1);
537 auto const &top2 = bottom_trk.at(0);
538 auto const &bottom2 = bottom_trk.at(1);
557 for (
size_t ii = 0; ii < Calo_v.size(); ii++) {
563 for (
size_t jj = 0; jj < calo_obj->
dEdx().size(); jj++){
564 x = calo_obj->
XYZ().at(jj).X();
565 y = calo_obj->
XYZ().at(jj).Y();
566 z = calo_obj->
XYZ().at(jj).Z();
582 if(
fCathode) {std::cout <<
"\tSKIPPING ANODE-PEIRCING TRACKS" <<
std::endl;
continue;}
584 if(
_debug) std::cout <<
"\t\tThis track starts in TPC " << wireID.
TPC <<
" which has a drift direction of " << driftDir1 <<
std::endl;
588 auto const &
top = sorted_trk.at(0);
589 auto const &
bottom = sorted_trk.at(1);
644 if (tagged ==
false)
continue;
688 if (tagged ==
false)
continue;
710 std::cout <<
"\t this track has a reconstructed time = " <<
rc_time <<
std::endl;
717 for (
auto& hits : Hit_v){
718 auto peakHit = hits->PeakTime();
720 if( (peakHit > detProp.ReadOutWindowSize() - 50.0) || (peakHit < 50.0) ){
722 if(
_debug) std::cout <<
"\t\tHit time out of range (0 - " << detProp.ReadOutWindowSize() <<
"): " << peakHit <<
std::endl;
736 std::cout <<
"\t matched to flash w/ index " << flash_match_result.second <<
" w/ PE " << flash_ptr->
TotalPE() <<
" and time " << flash_ptr->
Time() - trigger_time <<
" vs reco time " <<
rc_time <<
std::endl;
747 double displacement = 1.0;
749 for (
size_t j=0; j < mcpart_list.size(); j++){
751 std::vector<TLorentzVector> mcpart = mcpart_list.at(j);
757 if ((tmp_disp > displacement)||isnan(tmp_disp))
761 displacement = tmp_disp;
762 mc_time = mcpart.at(0).T() / 1000.;
764 if(
_debug) std::cout <<
"\tParticle number: " << j <<
" with sigma comparison value of " << displacement <<
"\n\t\tTrack matched to MC value with t0 of " <<
mc_time <<
", flash t0 of " <<
t_match <<
" and reconstructed time of " << rc_time <<
std::endl;
772 for (
size_t ii = 0; ii < Calo_v.size(); ii++) {
779 for (
size_t jj = 0; jj < calo_obj->
dEdx().size(); jj++){
780 x = calo_obj->
XYZ().at(jj).X();
781 y = calo_obj->
XYZ().at(jj).Y();
782 z = calo_obj->
XYZ().at(jj).Z();
814 double mcX = mcpart.at(0).X(), mcY = mcpart.at(0).Y(), mcZ = mcpart.at(0).Z();
815 double mcX_end = mcpart.at(1).X(), mcY_end = mcpart.at(1).Y(), mcZ_end = mcpart.at(1).Z();
816 double trkX = sorted_trk.at(0).X(), trkY = sorted_trk.at(0).Y(), trkZ = sorted_trk.at(0).Z();
817 double trkX_end = sorted_trk.at(sorted_trk.size()-1).
X(), trkY_end = sorted_trk.at(sorted_trk.size()-1).
Y(), trkZ_end = sorted_trk.at(sorted_trk.size()-1).
Z();
820 double tmpX = mcX, tmpY = mcY, tmpZ = mcZ;
829 double trkThXZ = atan((trkZ_end - trkZ)/(trkX_end - trkX));
830 double trkThYZ = atan((trkZ_end - trkZ)/(trkY_end - trkY));
833 double mcThXZ = atan((mcZ_end - mcZ)/(mcX_end - mcX));
834 double mcThYZ = atan((mcZ_end - mcZ)/(mcY_end - mcY));
871 double dt_min = 8000.;
876 double dt = fabs(
time - reco_time);
883 std::pair<double,size_t> ret(dt_min,idx_min);
894 if (sorted_trk.at(0).Y() >
TOP)
910 auto const& top_pt = sorted_trk.at(0);
912 if (top_pt.Z() <
FRONT)
935 auto const& top_pt = sorted_trk.at(0);
937 if (top_pt.Z() >
BACK)
961 auto const&
top = sorted_trk.at(0);
962 auto const&
bottom = sorted_trk.at( sorted_trk.size() - 1 );
964 if ( ( (
top.X() <
bottom.X()) && driftDir<0 ) || ( (
top.X() >
bottom.X()) && driftDir>0 ) )
978 auto const& top_pt = sorted_trk.at(0);
981 if (top_pt.Y() >
TOP)
986 if ( (top_pt.Z() <
FRONT) or (top_pt.Z() >
BACK) )
1000 if ( sorted_trk.at( sorted_trk.size() - 1).
Y() <
BOTTOM )
1016 auto const& bottom_pt = sorted_trk.at(sorted_trk.size() - 1);
1018 if (bottom_pt.Z() <
FRONT)
1034 auto const& bottom_pt = sorted_trk.at(sorted_trk.size() - 1);
1036 if (bottom_pt.Z() >
BACK)
1051 auto const&
top = sorted_trk.at(0);
1052 auto const&
bottom = sorted_trk.at(sorted_trk.size() - 1);
1057 if ( ( (
bottom.X() <
top.X()) && driftDir<0 ) || ( (
bottom.X() >
top.X()) && driftDir>0 ) )
1071 auto const& bottom_pt = sorted_trk.at(sorted_trk.size() - 1);
1076 if (bottom_pt.Y() <
BOTTOM)
1083 if ( (bottom_pt.Z() <
FRONT) or (bottom_pt.Z() >
BACK) )
1093 TVector3 track_neg, track_neg_c, track_pos_c,track_pos;
1102 if ((trk_loc.X() < -998.)||(trk_loc.Y() < -998.)||(trk_loc.Z() < -998))
continue;
1104 if (trk_loc.X() < neg_x){
1105 neg_x = trk_loc.X();
1106 track_neg = {trk_loc.X(), trk_loc.Y(), trk_loc.Z()};
1108 if (trk_loc.X() > pos_x){
1109 pos_x = trk_loc.X();
1110 track_pos = {trk_loc.X(), trk_loc.Y(), trk_loc.Z()};
1112 if ((trk_loc.X() < 0.0) && (trk_loc.X() > neg_c)){
1113 neg_c = trk_loc.X();
1114 track_neg_c = {trk_loc.X(), trk_loc.Y(), trk_loc.Z()};
1116 if ((trk_loc.X() > 0.0) && (trk_loc.X() < pos_c)){
1117 pos_c = trk_loc.X();
1118 track_pos_c = {trk_loc.X(), trk_loc.Y(), trk_loc.Z()};
1122 if( track_neg.Y() > track_pos.Y()){
1123 sorted_trk.push_back(track_neg);
1124 sorted_trk.push_back(track_neg_c);
1125 sorted_trk.push_back(track_pos_c);
1126 sorted_trk.push_back(track_pos);
1128 sorted_trk.push_back(track_pos);
1129 sorted_trk.push_back(track_pos_c);
1130 sorted_trk.push_back(track_neg_c);
1131 sorted_trk.push_back(track_neg);
1140 TVector3 track_start, track_end;
1147 if ((trk_loc.X() < -998.)||(trk_loc.Y() < -998.)||(trk_loc.Z() < -998))
continue;
1149 if (trk_loc.Y() < end_y){
1150 end_y = trk_loc.Y();
1151 track_end = {trk_loc.X(), trk_loc.Y(), trk_loc.Z()};
1153 if (trk_loc.Y() > start_y){
1154 start_y = trk_loc.Y();
1155 track_start = {trk_loc.X(), trk_loc.Y(), trk_loc.Z()};
1159 sorted_trk.push_back(track_start);
1160 sorted_trk.push_back(track_end);
1199 return sorted_trk.at(0).X();
1209 return sorted_trk.at(sorted_trk.size() - 1).
X();
1214 std::vector<std::vector< TLorentzVector>> mcVec;
1216 for (
size_t j=0; j < mcpart_h->size(); j++){
1218 auto const& mcpart = mcpart_h->at(j);
1220 double x0 = mcpart.Position(0).X();
1221 double y0 = mcpart.Position(0).Y();
1222 double z0 = mcpart.Position(0).Z();
1223 double t0 = mcpart.T(0);
1224 double x1 = mcpart.Position(mcpart.NumberTrajectoryPoints()-1).
X();
1225 double y1 = mcpart.Position(mcpart.NumberTrajectoryPoints()-1).
Y();
1226 double z1 = mcpart.Position(mcpart.NumberTrajectoryPoints()-1).
Z();
1227 double t1 = mcpart.T(mcpart.NumberTrajectoryPoints()-1);
1233 bool top_ok =
false, bot_ok =
false;
1234 std::cout << mcpart.NumberTrajectoryPoints() <<
std::endl;
1235 if(mcpart.NumberTrajectoryPoints()<2900){
1236 for(
size_t k = 0;
k<mcpart.NumberTrajectoryPoints();
k++){
1238 x0 = mcpart.Position(
k+1).X();
1239 y0 = mcpart.Position(
k+1).Y();
1240 z0 = mcpart.Position(
k+1).Z();
1242 }
else top_ok =
true;
1244 if ((x1 > width) || (x1 < -width) || (y1 >
TOP + fTPCResolution) || (y1 <
BOTTOM - fTPCResolution) || (z1 <
FRONT - fTPCResolution) || (z1 >
BACK + fTPCResolution) ){
1245 x1 = mcpart.Position(mcpart.NumberTrajectoryPoints()-2-
k).
X();
1246 y1 = mcpart.Position(mcpart.NumberTrajectoryPoints()-2-
k).
Y();
1247 z1 = mcpart.Position(mcpart.NumberTrajectoryPoints()-2-
k).
Z();
1248 t1 = mcpart.T(mcpart.NumberTrajectoryPoints()-2-
k);
1249 }
else bot_ok =
true;
1251 if(top_ok&&bot_ok)
k = mcpart.NumberTrajectoryPoints();
1255 double xs = x0,
ys = y0,
zs = z0, ts =
t0;
1256 double xe =
x1, ye = y1, ze = z1, te =
t1;
1258 TLorentzVector mc_top(TVector3(xs,ys,zs),ts);
1259 TLorentzVector mc_bot(TVector3(xe,ye,ze),te);
1262 if (ys > ye) mcVec.push_back({mc_top, mc_bot});
1263 else mcVec.push_back({mc_bot, mc_top});
code to link reconstructed objects back to the MC truth information
constexpr std::uint32_t timeLow() const
double GetEnteringTimeCoord(const std::vector< TVector3 > &sorted_trk)
EventNumber_t event() const
void SplitTrack(const recob::Track &track, std::vector< TVector3 > &sorted_trk)
Handle< PROD > getHandle(SelectorBase const &) const
Point_t const & LocationAtPoint(size_t i) const
constexpr std::uint32_t timeHigh() const
Geometry information for a single TPC.
bool TrackExitsBack(const std::vector< TVector3 > &sorted_trk)
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
const std::vector< Point_t > & XYZ() const
CryostatID_t Cryostat
Index of cryostat.
double HalfLength() const
Length is associated with z coordinate [cm].
std::vector< size_t > flash_idx_v
double MatchTracks(std::vector< TVector3 > &sorted_trk, std::vector< TLorentzVector > mcpart)
EDAnalyzer(fhicl::ParameterSet const &pset)
std::pair< double, size_t > FlashMatch(const double reco_time)
art framework interface to geometry description
const std::vector< float > & ResidualRange() const
std::string fTriggerProducer
bool isValid() const noexcept
timescale_traits< TriggerTimeCategory >::time_point_t trigger_time
A point in time on the trigger time scale.
bool TrackExitsAnode(const std::vector< TVector3 > &sorted_trk, const int driftDir)
const std::vector< float > & dQdx() const
#define DEFINE_ART_MODULE(klass)
void SortTrackPoints(const recob::Track &track, std::vector< TVector3 > &sorted_trk)
bool TrackEntersSide(const std::vector< TVector3 > &sorted_trk)
bool TrackExitsFront(const std::vector< TVector3 > &sorted_trk)
T get(std::string const &key) const
std::string fFlashProducer
bool TrackExitsBottom(const std::vector< TVector3 > &sorted_trk)
T0RecoSCECalibrations & operator=(T0RecoSCECalibrations const &)=delete
T0RecoSCECalibrations(fhicl::ParameterSet const &p)
bool TrackEntersAnode(const std::vector< TVector3 > &sorted_trk, const int driftDir)
SubRunNumber_t subRun() const
std::vector< std::vector< TLorentzVector > > BuildMCParticleList(const art::Handle< std::vector< simb::MCParticle >> &mcpart_h, const double &fTPCResolution, const double &width)
bool TrackEntersTop(const std::vector< TVector3 > &sorted_trk)
The data type to uniquely identify a TPC.
Class def header for mctrack data container.
Detector simulation of raw signals on wires.
bool TrackEntersBack(const std::vector< TVector3 > &sorted_trk)
const std::vector< float > & dEdx() const
std::string fCaloProducer
double HalfHeight() const
Height is associated with y coordinate [cm].
std::vector< double > flash_times
Declaration of signal hit object.
const std::vector< float > & TrkPitchVec() const
double DriftDistance() const
bool TrackEntersFront(const std::vector< TVector3 > &sorted_trk)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Provides recob::Track data product.
bool TrackExitsSide(const std::vector< TVector3 > &sorted_trk)
const float & KineticEnergy() const
static constexpr double zs
constexpr WireID()=default
Default constructor: an invalid TPC ID.
double GetExitingTimeCoord(const std::vector< TVector3 > &sorted_trk)
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
TPCID_t TPC
Index of the TPC within its cryostat.
static constexpr double ys
std::string fTrackProducer
const float & Range() const
void LocalToWorld(const double *tpc, double *world) const
Transform point from local TPC frame to world frame.
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
constexpr Point origin()
Returns a origin position with a point of the specified type.
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)
void analyze(art::Event const &e) override
Event finding and building.