8 #include "art/Framework/Core/ModuleMacros.h"
9 #include "art/Framework/Principal/Event.h"
10 #include "fhiclcpp/ParameterSet.h"
11 #include "art/Framework/Principal/Handle.h"
12 #include "canvas/Persistency/Common/Ptr.h"
13 #include "art/Framework/Services/Registry/ServiceHandle.h"
14 #include "art_root_io/TFileService.h"
15 #include "messagefacility/MessageLogger/MessageLogger.h"
16 #include "art/Framework/Core/EDProducer.h"
17 #include "canvas/Persistency/Common/FindMany.h"
18 #include "canvas/Persistency/Common/FindManyP.h"
60 double gammavalue(TVector3 startpoint1, TVector3 startpoint2, TVector3 dircos1, TVector3 dircos2);
61 double alphavalue(
double gamma, TVector3 startpoint1, TVector3 startpoint2, TVector3 dircos1, TVector3 dircos2);
62 double MinDist(
double alpha,
double gamma, TVector3 startpoint1, TVector3 startpoint2, TVector3 dircos1, TVector3 dircos2);
76 bool sort_pred2(
const std::pair<art::Ptr<recob::Track>,
double>&
left,
const std::pair<art::Ptr<recob::Track>,
double>&
right)
87 fTrackModuleLabel = pset.get< std::string >(
"TrackModuleLabel");
88 fVertexWindow = pset.get<
double > (
"VertexWindow");
90 produces< std::vector<recob::Vertex> >();
91 produces< art::Assns<recob::Vertex, recob::Hit> >();
92 produces< art::Assns<recob::Vertex, recob::Track> >();
93 produces< art::Assns<recob::Vertex, recob::Shower> >();
99 art::ServiceHandle<art::TFileService const>
tfs;
102 fNoTracks= tfs->make<TH2F>(
"fNoTracks",
";Event No; No of Tracks", 10,0, 10, 10, 0, 10);
103 fLength_1stTrack = tfs->make<TH1F>(
"fLength_Track1",
"Muon Track Length", 100,0,100);
104 fLength_2ndTrack = tfs->make<TH1F>(
"fLength_Track2",
"2nd Track Length", 100,0,100);
105 fLength_3rdTrack = tfs->make<TH1F>(
"fLength_Track3",
"3rd Track Length", 100,0,100);
106 fLength_4thTrack = tfs->make<TH1F>(
"fLength_Track4",
"4th Track Length", 100,0,100);
107 fLength_5thTrack = tfs->make<TH1F>(
"fLength_Track5",
"5th Track Length", 100,0,100);
114 mf::LogInfo(
"PrimaryVertexFinder") <<
"------------------------------------------------------------------------------";
120 mf::LogInfo(
"PrimaryVertexFinder") <<
"event : " << evt.id().event();
123 art::ServiceHandle<geo::Geometry const> geom;
127 art::Handle< std::vector<recob::Track> > trackListHandle;
131 std::unique_ptr< std::vector<recob::Vertex> > vcol(
new std::vector<recob::Vertex>);
132 std::unique_ptr< art::Assns<recob::Vertex, recob::Hit> > vhassn(
new art::Assns<recob::Vertex, recob::Hit>);
133 std::unique_ptr< art::Assns<recob::Vertex, recob::Track> > vtassn(
new art::Assns<recob::Vertex, recob::Track>);
134 std::unique_ptr< art::Assns<recob::Vertex, recob::Shower> > vsassn(
new art::Assns<recob::Vertex, recob::Shower>);
137 std::vector<recob::Track>
const& trkIn = *trackListHandle;
139 mf::LogInfo(
"PrimaryVertexFinder") <<
"number of tracks in this event = " << trkIn.size();
140 fNoTracks->Fill(evt.id().event(),trkIn.size());
142 std::vector<recob::SpacePoint> startpoints_vec;
144 std::vector <TVector3> startvec;
147 std::vector <TVector3> endvec;
150 std::vector <TVector3> dircosvec;
153 std::vector< std::pair<art::Ptr<recob::Track>,
double> > trackpair;
155 art::FindMany<recob::SpacePoint> TrackSpacePoints
158 for(
unsigned int i = 0; i<trkIn.size(); ++i){
160 std::tie(start, end) = trkIn[i].Extent();
161 startXYZ.SetXYZ(start.X(),start.Y(),start.Z());
162 endXYZ.SetXYZ(end.X(),end.Y(),end.Z());
165 double length = (endXYZ-startXYZ).Mag();
167 trackpair.push_back(std::pair<art::Ptr<recob::Track>,
double>({ trackListHandle, i },length));
170 for(
size_t i = 0; i<trackpair.size(); ++i){
171 mf::LogInfo(
"PrimaryVertexFinder") <<
"track id is = " << (trackpair[i].first)->ID()
172 <<
" track length = " << (trackpair[i].second);
175 std::sort(trackpair.rbegin(), trackpair.rend(),
sort_pred2);
177 mf::LogInfo(
"PrimaryVertexFinder") <<
"AFTER SORTING ";
178 for(
size_t i = 0; i < trackpair.size(); ++i){
179 mf::LogInfo(
"PrimaryVertexFinder") <<
"track id is = " << (trackpair[i].first)->ID()
180 <<
" track length = " << (trackpair[i].second);
183 if(trackpair.size()>0)
186 if(trackpair.size()>1)
189 if(trackpair.size()>2)
192 if(trackpair.size()>3)
195 if(trackpair.size()>4)
198 for(
size_t j = 0; j < trackpair.size(); ++j) {
199 art::Ptr<recob::Track>
const&
track = trackpair[j].first;
203 std::vector<recob::SpacePoint const*>
const& spacepoints
204 = TrackSpacePoints.at(track.key());
206 startXYZ = trackpair[j].first->Vertex<TVector3>();
207 endXYZ = trackpair[j].first->End<TVector3>();
208 dircosXYZ = trackpair[j].first->VertexDirection<TVector3>();
210 startvec.push_back(startXYZ);
211 endvec.push_back(endXYZ);
212 dircosvec.push_back(dircosXYZ);
214 mf::LogInfo(
"PrimaryVertexFinder") <<
"PrimaryVertexFinder got "<< spacepoints.size()
215 <<
" 3D spacepoint(s) from Track3Dreco.cxx";
218 startpoints_vec.emplace_back(
219 spacepoints[0]->XYZ(), spacepoints[0]->ErrXYZ(),
220 spacepoints[0]->Chisq(), startpoints_vec.size()
225 for(
size_t i = 0; i < startvec.size(); ++i){
226 mf::LogInfo(
"PrimaryVertexFinder") <<
"Tvector3 start point SORTED = ";
229 for(
size_t i = 0; i < dircosvec.size(); ++i){
230 mf::LogInfo(
"PrimaryVertexFinder") <<
"Tvector3 dir cos SORTED = ";
231 dircosvec[i].Print();
234 std::vector<std::vector<int> > vertex_collection_int;
235 std::vector <std::vector <TVector3> > vertexcand_vec;
237 for (
unsigned int i=0; i<trackpair.size(); ++i){
238 for (
unsigned int j=i+1; j<trackpair.size(); ++j){
239 mf::LogInfo(
"PrimaryVertexFinder") <<
"distance between " << i <<
" and " << j
242 double GAMMA =
gammavalue(startvec[i], startvec[j], dircosvec[i], dircosvec[j]);
243 double ALPHA =
alphavalue(GAMMA, startvec[i], startvec[j], dircosvec[i], dircosvec[j]);
244 double MINDIST =
MinDist(ALPHA, GAMMA, startvec[i], startvec[j], dircosvec[i], dircosvec[j]);
245 mf::LogInfo(
"PrimaryVertexFinder") <<
"alpha = " << ALPHA <<
" gamma = "
246 << GAMMA <<
" MINIMUM DISTANCE = " << MINDIST;
251 mf::LogInfo(
"PrimaryVertexFinder") <<
"POINTS ON THE TRACKS ARE:: ";
260 std::vector<int> newvertex_int;
261 std::vector <TVector3> vertexcand;
262 newvertex_int.push_back(i);
263 newvertex_int.push_back(j);
264 vertex_collection_int.push_back(newvertex_int);
266 vertexcand.push_back(TRACK1POINT);
267 vertexcand.push_back(TRACK2POINT);
268 vertexcand_vec.push_back(vertexcand);
274 vertex_collection_int[index].push_back(i);
275 vertexcand_vec[index].push_back(TRACK1POINT);
278 vertex_collection_int[index].push_back(j);
279 vertexcand_vec[index].push_back(TRACK2POINT);
288 for(
size_t i = 0; i < trackpair.size(); ++i){
291 std::vector<int> temp;
292 std::vector <TVector3> temp1;
294 temp1.push_back(startvec[i]);
295 vertex_collection_int.push_back(temp);
296 vertexcand_vec.push_back(temp1);
302 std::vector<size_t> vTrackIndices, vShowerIndices;
312 for(
size_t i = 0; i < vertex_collection_int.size(); ++i){
317 for(std::vector<int>::iterator itr = vertex_collection_int[i].
begin(); itr < vertex_collection_int[i].end(); ++itr){
318 mf::LogInfo(
"PrimaryVertexFinder") <<
"vector elements at index " << i <<
" are " << *itr
319 <<
"\ntrack original ID = " << (trackpair[*itr].first)->ID();
321 vTrackIndices.push_back(trackpair[*itr].
first.key());
323 mf::LogInfo(
"PrimaryVertexFinder") <<
"------------";
326 for(std::vector<TVector3>::iterator itr = vertexcand_vec[i].
begin(); itr < vertexcand_vec[i].end(); ++itr){
331 elemsize = vertexcand_vec[i].size();
334 double avgx = x/elemsize;
335 double avgy = y/elemsize;
336 double avgz = z/elemsize;
338 Double_t vtxcoord[3];
344 vcol->push_back(the3Dvertex);
346 if(!vTrackIndices.empty()){
349 vcol->size() - 1, vTrackIndices.begin(), vTrackIndices.end());
350 for(
size_t tIndex: vTrackIndices) {
351 std::vector<art::Ptr<recob::Hit>>
const& hits = TrackHits.at(tIndex);
354 vTrackIndices.clear();
357 if(!vShowerIndices.empty()){
360 vcol->size() - 1, vShowerIndices.begin(), vShowerIndices.end());
361 for(
size_t sIndex: vShowerIndices){
362 std::vector<art::Ptr<recob::Hit>>
const& hits = ShowerHits.at(sIndex);
365 vShowerIndices.clear();
371 MF_LOG_VERBATIM(
"Summary") << std::setfill(
'-') << std::setw(175) <<
"-" << std::setfill(
' ');
372 MF_LOG_VERBATIM(
"Summary") <<
"PrimaryVertexFinder Summary:";
373 for(
size_t i = 0; i < vcol->size(); ++i) MF_LOG_VERBATIM(
"Summary") << vcol->at(i) ;
375 evt.put(std::move(vcol));
376 evt.put(std::move(vtassn));
377 evt.put(std::move(vhassn));
378 evt.put(std::move(vsassn));
386 double x= (sp2.
XYZ()[0])-(sp1.
XYZ()[0]);
387 double y= (sp2.
XYZ()[1])-(sp1.
XYZ()[1]);
388 double z= (sp2.
XYZ()[2])-(sp1.
XYZ()[2]);
389 double distance = std::sqrt(pow(x,2)+pow(y,2)+pow(z,2));
397 for(
unsigned int i = 0; i < vertex_collection.size() ; i++){
398 for(std::vector<int>::iterator itr = vertex_collection[i].
begin(); itr < vertex_collection[i].end(); ++itr){
413 for(
unsigned int i = 0; i < vertex_collection.size() ; i++){
414 for(std::vector<int>::iterator itr = vertex_collection[i].
begin(); itr < vertex_collection[i].end(); ++itr){
415 if (a == *itr || b == *itr)
425 for(
unsigned int i = 0; i < newvertex.size() ; i++){
426 if (a == newvertex[i]){
439 double gamma = ((startpoint1*dircos2)-(startpoint2*dircos2)+((dircos1*dircos2)*(startpoint2*dircos1))-((dircos1*dircos2)*(startpoint1*dircos1)))/(1-((dircos1*dircos2)*(dircos1*dircos2)));
446 double alpha = (gamma*(dircos1*dircos2)) + (startpoint2*dircos1) - (startpoint1*dircos1);
453 TVector3 mindis_vector = startpoint1 - startpoint2 + alpha*dircos1 - gamma*dircos2;
454 double mindis = mindis_vector.Mag();
460 TVector3 PointOnExtendedTrack = startpoint + (alphagamma * dircos);
461 return PointOnExtendedTrack;
process_name opflash particleana ie ie ie z
PrimaryVertexFinder(fhicl::ParameterSet const &pset)
process_name opflash particleana ie x
void produce(art::Event &evt)
TVector3 PointOnExtendedTrack(double alphagamma, TVector3 startpoint, TVector3 dircos)
then echo unknown compiler flag
Declaration of signal hit object.
process_name use argoneut_mc_hitfinder track
Definition of vertex object for LArSoft.
bool IsInNewVertex(int a, std::vector< int > newvertex)
int IndexInVertexCollection(int a, int b, std::vector< std::vector< int > > vertex_collection)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
process_name opflash particleana ie ie y
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
auto end(FixedBins< T, C > const &) noexcept
const Double32_t * XYZ() const
std::string fTrackModuleLabel
double MinDist(double alpha, double gamma, TVector3 startpoint1, TVector3 startpoint2, TVector3 dircos1, TVector3 dircos2)
Provides recob::Track data product.
auto begin(FixedBins< T, C > const &) noexcept
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.
double StartPointSeperation(recob::SpacePoint sp1, recob::SpacePoint sp2)
bool sort_pred2(const std::pair< art::Ptr< recob::Track >, double > &left, const std::pair< art::Ptr< recob::Track >, double > &right)
bool IsInVertexCollection(int a, std::vector< std::vector< int > > vertex_collection)
tracking::Point_t Point_t
double gammavalue(TVector3 startpoint1, TVector3 startpoint2, TVector3 dircos1, TVector3 dircos2)
double alphavalue(double gamma, TVector3 startpoint1, TVector3 startpoint2, TVector3 dircos1, TVector3 dircos2)
art::ServiceHandle< art::TFileService > tfs
art framework interface to geometry description