17 #include "art/Framework/Core/EDProducer.h"
18 #include "art/Framework/Core/ModuleMacros.h"
19 #include "art/Framework/Principal/Event.h"
20 #include "art/Framework/Principal/Handle.h"
21 #include "art/Framework/Services/Registry/ServiceHandle.h"
22 #include "art_root_io/TFileService.h"
23 #include "canvas/Persistency/Common/FindManyP.h"
24 #include "canvas/Persistency/Common/Ptr.h"
25 #include "canvas/Persistency/Common/PtrVector.h"
26 #include "fhiclcpp/ParameterSet.h"
27 #include "messagefacility/MessageLogger/MessageLogger.h"
30 #include "nusimdata/SimulationBase/MCTruth.h"
31 #include "nurandom/RandomUtils/NuRandomService.h"
57 #include "CLHEP/Random/RandFlat.h"
58 #include "CLHEP/Random/RandGaussQ.h"
110 bool sp_sort_3dz(
const art::Ptr<recob::SpacePoint>& h1,
const art::Ptr<recob::SpacePoint>& h2)
112 const double* xyz1 = h1->XYZ();
113 const double* xyz2 = h2->XYZ();
114 return xyz1[2] < xyz2[2];
123 , fSpacePtsModuleLabel{pset.get< std::string >(
"SpacePtsModuleLabel")}
124 , fGenieGenModuleLabel{pset.get< std::string >(
"GenieGenModuleLabel")}
125 , fG4ModuleLabel{pset.get< std::string >(
"G4ModuleLabel")}
126 , fGenfPRINT{pset.get<
bool >(
"GenfPRINT")}
127 , fPosErr{pset.get< std::vector < double > >(
"PosErr3")}
128 , fMomErr{pset.get< std::vector < double > >(
"MomErr3")}
129 , fMomStart{pset.get< std::vector < double > >(
"MomStart3")}
132 ,
fEngine(art::ServiceHandle<rndm::NuRandomService>()->createEngine(*
this, pset,
"Seed"))
134 produces< std::vector<recob::Track> >();
135 produces< std::vector<recob::SpacePoint> >();
136 produces< art::Assns<recob::Track, recob::Cluster> >();
137 produces< art::Assns<recob::Track, recob::SpacePoint> >();
138 produces< art::Assns<recob::Track, recob::Hit> >();
144 art::ServiceHandle<art::TFileService const>
tfs;
146 stMCT =
new TMatrixT<Double_t>(5,1);
147 covMCT =
new TMatrixT<Double_t>(5,5);
148 stREC =
new TMatrixT<Double_t>(5,1);
149 covREC =
new TMatrixT<Double_t>(5,5);
151 fpMCT =
new Float_t[4];
152 fpREC =
new Float_t[4];
161 tree = tfs->make<TTree>(
"GENFITttree",
"GENFITttree");
164 tree->Branch(
"stMCT",
"TMatrixD",&
stMCT,64000,0);
166 tree->Branch(
"covMCT",
"TMatrixD",&covMCT,64000,0);
168 tree->Branch(
"stREC",
"TMatrixD",&stREC,64000,0);
170 tree->Branch(
"covREC",
"TMatrixD",&covREC,64000,0);
173 tree->Branch(
"chi2",&
chi2,
"chi2/F");
175 tree->Branch(
"ndf",&
ndf,
"ndf/I");
176 tree->Branch(
"evtNo",&
evtt,
"evtNo/I");
181 tree->Branch(
"shx",
fshx,
"shx[ptsNo]/F");
182 tree->Branch(
"shy",
fshy,
"shy[ptsNo]/F");
183 tree->Branch(
"shz",
fshz,
"shz[ptsNo]/F");
185 tree->Branch(
"pMCT",fpMCT,
"pMCT[4]/F");
186 tree->Branch(
"pRECKalF",
fpREC,
"pRECKalF[4]/F");
187 tree->Branch(
"pRECKalL",
fpRECL,
"pRECKalL[4]/F");
206 art::ServiceHandle<geo::Geometry const> geom;
207 CLHEP::RandGaussQ gauss(
fEngine);
213 std::unique_ptr<std::vector<recob::Track> > tcol(
new std::vector<recob::Track>);
214 std::unique_ptr< std::vector<recob::SpacePoint> > spcol (
new std::vector<recob::SpacePoint>);
215 std::unique_ptr< art::Assns<recob::Track, recob::SpacePoint> > tspassn(
new art::Assns<recob::Track, recob::SpacePoint>);
216 std::unique_ptr< art::Assns<recob::Track, recob::Cluster> > tcassn (
new art::Assns<recob::Track, recob::Cluster>);
217 std::unique_ptr< art::Assns<recob::Track, recob::Hit> > thassn (
new art::Assns<recob::Track, recob::Hit>);
220 TString tpcName = geom->GetLArTPCVolumeName();
224 art::Handle< std::vector<recob::Track> > trackListHandle;
227 art::PtrVector<simb::MCTruth> mclist;
229 if (!evt.isRealData())
231 art::Handle< std::vector<simb::MCTruth> > mctruthListHandle;
234 for (
unsigned int ii = 0; ii < mctruthListHandle->size(); ++ii)
236 art::Ptr<simb::MCTruth> mctparticle(mctruthListHandle,ii);
237 mclist.push_back(mctparticle);
242 std::vector< art::Ptr<recob::SpacePoint> > spacepoints;
243 art::PtrVector<recob::Track> trackIn;
245 mf::LogInfo(
"Track3DKalman: ") <<
"There are " << trackListHandle->size() <<
" Track3Dreco/SpacePt tracks/groups (whichever) in this event.";
251 for(
unsigned int ii = 0; ii < trackListHandle->size(); ++ii)
253 art::Ptr<recob::Track>
track(trackListHandle, ii);
254 trackIn.push_back(track);
267 if (!evt.isRealData())
272 for(
unsigned int ii = 0; ii < mclist.size(); ++ii )
275 art::Ptr<simb::MCTruth> mc(mclist[ii]);
276 for(
int jj = 0; jj < mc->NParticles(); ++jj)
278 simb::MCParticle part(mc->GetParticle(jj));
279 mf::LogInfo(
"Track3DKalman: ") <<
"FROM MC TRUTH, the particle's pdg code is: "<<part.PdgCode()<<
" with energy = "<<part.E() <<
", with energy = "<<part.E()<<
" and vtx and momentum in Global (not volTPC) coords are " ;
280 MCOrigin.SetXYZ(part.Vx(),part.Vy(),part.Vz());
281 MCMomentum.SetXYZ(part.Px(),part.Py(),part.Pz());
298 mf::LogInfo(
"Track3DKalman: ") <<
" repMC, covMC are ... " ;
304 art::PtrVector<recob::Track>::const_iterator trackIter = trackIn.begin();
307 while(trackIter!=trackIn.end()) {
309 spacepoints = fmsp.at(
nTrks);
311 mf::LogInfo(
"Track3DKalman: ") <<
"found "<< spacepoints.size() <<
" 3D spacepoint(s).";
314 if(spacepoints.size()>0){
316 const double resolution = 0.5;
324 momM.SetX(gauss.fire(momM.X(),momErr.X()));
325 momM.SetY(gauss.fire(momM.Y(),momErr.Y()));
326 momM.SetZ(gauss.fire(momM.Z(),momErr.Z()));
329 std::sort(spacepoints.begin(), spacepoints.end(),
sp_sort_3dz);
340 (TVector3)(spacepoints[0]->XYZ()),
354 for (
unsigned int point=0;point<spacepoints.size();++point)
357 TVector3 spt3(spacepoints[point]->XYZ());
361 TVector3 magNew(spt3[0],spt3[1],spt3[2]);
362 TVector3 magLast(spacepoints.back()->XYZ()[0],
363 spacepoints.back()->XYZ()[1],
364 spacepoints.back()->XYZ()[2]
366 if (!(magNew.Mag()>=magLast.Mag()+eps ||
367 magNew.Mag()<=magLast.Mag()-eps)
388 MF_LOG_DEBUG(
"Track3DKalman: ") <<
"ihit xyz..." << spt3[0]<<
","<< spt3[1]<<
","<< spt3[2];
407 mf::LogError(
"Track3DKalman: ") <<
"just caught a GFException."<<std::endl;
409 mf::LogError(
"Track3DKalman: ") <<
"Exceptions won't be further handled ->exit(1) "<<__LINE__;
416 MF_LOG_DEBUG(
"Track3DKalman: ") << __FILE__ <<
" " << __LINE__ ;
417 MF_LOG_DEBUG(
"Track3DKalman: ") <<
"Track3DKalman.cxx: Original plane:";
420 MF_LOG_DEBUG(
"Track3DKalman: ") <<
"Current (fit) reference Plane:";
423 MF_LOG_DEBUG(
"Track3DKalman: ") <<
"Track3DKalman.cxx: Last reference Plane:";
429 MF_LOG_DEBUG(
"Track3DKalman: ") <<
"Track3DKalman: Original hit plane (not surprisingly) not current reference Plane!"<<std::endl;
438 MF_LOG_DEBUG(
"Track3DKalman: ") <<
" Final State and Cov:";
446 TVector3 dircoss = (*trackIter)->VertexDirection<TVector3>();
448 for (
int ii=0;ii<3;++ii)
450 fpMCT[ii] = MCMomentum[ii]/MCMomentum.Mag();
455 fpMCT[3] = MCMomentum.Mag();
456 fpREC[3] = -1.0/(*stREC)[0][0];
458 evtt = (
unsigned int) evt.id().event();
459 mf::LogInfo(
"Track3DKalman: ") <<
"Track3DKalman about to do tree->Fill(). Chi2/ndf is " <<
chi2/
ndf <<
". All in volTPC coords .... pMCT[0-3] is " <<
fpMCT[0] <<
", " <<
fpMCT[1] <<
", " <<
fpMCT[2] <<
", " <<
fpMCT[3] <<
". pREC[0-3] is " <<
fpREC[0] <<
", "<<
fpREC[1] <<
", " <<
fpREC[2] <<
", " <<
fpREC[3] <<
".";
464 std::vector< art::Ptr<recob::Cluster> > clusters = fmc.at(
nTrks);
465 std::vector< art::Ptr<recob::Hit> > hits = fmh.at(
nTrks);
468 std::vector<TVector3> dircos(spacepoints.size());
469 dircos[0] = TVector3(fpREC);
470 dircos.back() = TVector3(
fpRECL);
473 std::vector<TVector3> xyz(spacepoints.size());
474 size_t spStart = spcol->size();
475 for(
size_t tv = 0; tv < spacepoints.size(); ++tv){
476 xyz[tv] = TVector3(spacepoints[tv]->XYZ());
477 spcol->push_back(*(spacepoints[tv].
get()));
479 size_t spEnd = spcol->size();
498 if(trackIter!=trackIn.end()) trackIter++;
504 evt.put(std::move(tcol));
505 evt.put(std::move(spcol));
506 evt.put(std::move(tcassn));
507 evt.put(std::move(thassn));
508 evt.put(std::move(tspassn));
std::string fG4ModuleLabel
unsigned int getNDF() const
static bool sp_sort_3dz(const art::Ptr< recob::SpacePoint > &h1, const art::Ptr< recob::SpacePoint > &h2)
const GFDetPlane & getReferencePlane() const
GFDetPlane getLastPlane() const
ROOT::Math::SMatrix< Double32_t, 5, 5, ROOT::Math::MatRepSym< Double32_t, 5 > > SMatrixSym55
std::vector< Vector_t > convertCollToVector(std::vector< Vector > const &coll)
Declaration of signal hit object.
std::vector< double > fMomStart
virtual const char * what() const
standard error message handling for exceptions. use like "std::cerr << e.what();" ...
TrackTrajectory::Flags_t Flags_t
process_name use argoneut_mc_hitfinder track
void Print(std::ostream &out=std::cout) const
const TMatrixT< Double_t > & getState() const
std::vector< double > fMomErr
genf::GFAbsTrackRep * rep
Base Class for genfit track representations. Defines interface for track parameterizations.
TVector3 getNormal() const
A trajectory in space reconstructed from hits.
void setNumIterations(Int_t i)
Set number of iterations for Kalman Filter.
fEngine(art::ServiceHandle< rndm::NuRandomService >() ->createEngine(*this, pset,"Seed"))
int getFailedHits(int repId=-1)
return the number of failed Hits in track fit repId == -1 will use cardinal rep
void processTrack(GFTrack *)
Performs fit on a GFTrack.
static GFFieldManager * getInstance()
std::string fGenieGenModuleLabel
genf::GFAbsTrackRep * repMC
std::vector< Point_t > convertCollToPoint(std::vector< Point > const &coll)
Declaration of cluster object.
const TMatrixT< Double_t > & getCov() const
Track3DKalman(fhicl::ParameterSet const &pset)
Provides recob::Track data product.
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
std::string fSpacePtsModuleLabel
Exception class for error handling in GENFIT (provides storage for diagnostic information) ...
TMatrixT< Double_t > * stMCT
void produce(art::Event &evt) override
TMatrixT< Double_t > * stREC
void init(GFAbsBField *b)
set the magntic field here. Magnetic field classes must be derived from GFAbsBField ...
CLHEP::HepRandomEngine & fEngine
art::ServiceHandle< art::TFileService > tfs
void addHit(GFAbsRecoHit *theHit)
deprecated!
std::vector< double > fPosErr
art framework interface to geometry description
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
TMatrixT< Double_t > * covMCT
TMatrixT< Double_t > * covREC