6 #ifndef PrimaryVertexFinder_H 7 #define PrimaryVertexFinder_H 79 bool IsInVertexCollection(
int a,
std::vector<std::vector<int> > vertex_collection);
80 int IndexInVertexCollection(
int a,
int b,
std::vector<std::vector<int> > vertex_collection);
81 bool IsInNewVertex(
int a, std::vector<int> newvertex);
82 double gammavalue(TVector3 startpoint1, TVector3 startpoint2, TVector3 dircos1, TVector3 dircos2);
83 double alphavalue(
double gamma, TVector3 startpoint1, TVector3 startpoint2, TVector3 dircos1, TVector3 dircos2);
84 double MinDist(
double alpha,
double gamma, TVector3 startpoint1, TVector3 startpoint2, TVector3 dircos1, TVector3 dircos2);
85 TVector3 PointOnExtendedTrack(
double alphagamma, TVector3 startpoint, TVector3 dircos);
108 this->reconfigure(pset);
109 produces< std::vector<recob::Vertex> >();
110 produces< art::Assns<recob::Vertex, recob::Hit> >();
111 produces< art::Assns<recob::Vertex, recob::Track> >();
112 produces< art::Assns<recob::Vertex, recob::Shower> >();
116 PrimaryVertexFinder::~PrimaryVertexFinder()
123 fTrackModuleLabel = p.
get< std::string >(
"TrackModuleLabel");
124 fVertexWindow = p.
get<
double > (
"VertexWindow");
133 fNoTracks= tfs->
make<TH2F>(
"fNoTracks",
";Event No; No of Tracks", 10,0, 10, 10, 0, 10);
134 fLength_1stTrack = tfs->
make<TH1F>(
"fLength_Track1",
"Muon Track Length", 100,0,100);
135 fLength_2ndTrack = tfs->
make<TH1F>(
"fLength_Track2",
"2nd Track Length", 100,0,100);
136 fLength_3rdTrack = tfs->
make<TH1F>(
"fLength_Track3",
"3rd Track Length", 100,0,100);
137 fLength_4thTrack = tfs->
make<TH1F>(
"fLength_Track4",
"4th Track Length", 100,0,100);
138 fLength_5thTrack = tfs->
make<TH1F>(
"fLength_Track5",
"5th Track Length", 100,0,100);
145 mf::LogInfo(
"PrimaryVertexFinder") <<
"------------------------------------------------------------------------------";
159 evt.
getByLabel(fTrackModuleLabel,trackListHandle);
162 std::unique_ptr< std::vector<recob::Vertex> > vcol(
new std::vector<recob::Vertex>);
168 std::vector<recob::Track>
const& trkIn = *trackListHandle;
170 mf::LogInfo(
"PrimaryVertexFinder") <<
"number of tracks in this event = " << trkIn.size();
171 fNoTracks->Fill(evt.
id().
event(),trkIn.size());
173 std::vector<recob::SpacePoint> startpoints_vec;
175 std::vector <TVector3> startvec;
178 std::vector <TVector3> endvec;
181 std::vector <TVector3> dircosvec;
184 std::vector< std::pair<art::Ptr<recob::Track>,
double> > trackpair;
187 (trackListHandle, evt, fTrackModuleLabel);
189 for(
unsigned int i = 0; i<trkIn.size(); ++i){
191 std::tie(start, end) = trkIn[i].Extent();
192 startXYZ.SetXYZ(start.X(),start.Y(),start.Z());
193 endXYZ.SetXYZ(end.X(),end.Y(),end.Z());
196 double length = (endXYZ-startXYZ).Mag();
201 for(
size_t i = 0; i<trackpair.size(); ++i){
202 mf::LogInfo(
"PrimaryVertexFinder") <<
"track id is = " << (trackpair[i].first)->ID()
203 <<
" track length = " << (trackpair[i].second);
206 std::sort(trackpair.rbegin(), trackpair.rend(),
sort_pred2);
208 mf::LogInfo(
"PrimaryVertexFinder") <<
"AFTER SORTING ";
209 for(
size_t i = 0; i < trackpair.size(); ++i){
210 mf::LogInfo(
"PrimaryVertexFinder") <<
"track id is = " << (trackpair[i].first)->ID()
211 <<
" track length = " << (trackpair[i].second);
214 if(trackpair.size()>0)
215 fLength_1stTrack->Fill(trackpair[0].second);
217 if(trackpair.size()>1)
218 fLength_2ndTrack->Fill(trackpair[1].second);
220 if(trackpair.size()>2)
221 fLength_3rdTrack->Fill(trackpair[2].second);
223 if(trackpair.size()>3)
224 fLength_4thTrack->Fill(trackpair[3].second);
226 if(trackpair.size()>4)
227 fLength_5thTrack->Fill(trackpair[4].second);
229 for(
size_t j = 0; j < trackpair.size(); ++j) {
234 std::vector<recob::SpacePoint const*>
const& spacepoints
235 = TrackSpacePoints.at(track.
key());
237 startXYZ = trackpair[j].first->Vertex();
238 endXYZ = trackpair[j].first->End();
239 dircosXYZ = trackpair[j].first->VertexDirection();
241 startvec.push_back(startXYZ);
242 endvec.push_back(endXYZ);
243 dircosvec.push_back(dircosXYZ);
245 mf::LogInfo(
"PrimaryVertexFinder") <<
"PrimaryVertexFinder got "<< spacepoints.size()
246 <<
" 3D spacepoint(s) from Track3Dreco.cxx";
249 startpoints_vec.emplace_back(
250 spacepoints[0]->XYZ(), spacepoints[0]->ErrXYZ(),
251 spacepoints[0]->Chisq(), startpoints_vec.size()
256 for(
size_t i = 0; i < startvec.size(); ++i){
257 mf::LogInfo(
"PrimaryVertexFinder") <<
"Tvector3 start point SORTED = ";
260 for(
size_t i = 0; i < dircosvec.size(); ++i){
261 mf::LogInfo(
"PrimaryVertexFinder") <<
"Tvector3 dir cos SORTED = ";
262 dircosvec[i].Print();
265 std::vector<std::vector<int> > vertex_collection_int;
266 std::vector <std::vector <TVector3> > vertexcand_vec;
268 for (
unsigned int i=0; i<trackpair.size(); ++i){
269 for (
unsigned int j=i+1; j<trackpair.size(); ++j){
270 mf::LogInfo(
"PrimaryVertexFinder") <<
"distance between " << i <<
" and " << j
272 << StartPointSeperation(startpoints_vec[i], startpoints_vec[j]);
273 double GAMMA = gammavalue(startvec[i], startvec[j], dircosvec[i], dircosvec[j]);
274 double ALPHA = alphavalue(GAMMA, startvec[i], startvec[j], dircosvec[i], dircosvec[j]);
275 double MINDIST = MinDist(ALPHA, GAMMA, startvec[i], startvec[j], dircosvec[i], dircosvec[j]);
276 mf::LogInfo(
"PrimaryVertexFinder") <<
"alpha = " << ALPHA <<
" gamma = " 277 << GAMMA <<
" MINIMUM DISTANCE = " << MINDIST;
279 TVector3 TRACK1POINT = PointOnExtendedTrack(ALPHA, startvec[i], dircosvec[i]);
280 TVector3 TRACK2POINT = PointOnExtendedTrack(GAMMA, startvec[j], dircosvec[j]);
282 mf::LogInfo(
"PrimaryVertexFinder") <<
"POINTS ON THE TRACKS ARE:: ";
288 if(MINDIST < fVertexWindow && ((TRACK1POINT-startvec[i]).Mag()) < fVertexWindow){
290 if((!IsInVertexCollection(i, vertex_collection_int)) && (!IsInVertexCollection(j, vertex_collection_int))){
291 std::vector<int> newvertex_int;
292 std::vector <TVector3> vertexcand;
293 newvertex_int.push_back(i);
294 newvertex_int.push_back(j);
295 vertex_collection_int.push_back(newvertex_int);
297 vertexcand.push_back(TRACK1POINT);
298 vertexcand.push_back(TRACK2POINT);
299 vertexcand_vec.push_back(vertexcand);
302 int index = IndexInVertexCollection(i, j, vertex_collection_int);
304 if(!IsInNewVertex(i, vertex_collection_int[index])){
305 vertex_collection_int[index].push_back(i);
306 vertexcand_vec[index].push_back(TRACK1POINT);
308 if(!IsInNewVertex(j, vertex_collection_int[index])){
309 vertex_collection_int[index].push_back(j);
310 vertexcand_vec[index].push_back(TRACK2POINT);
319 for(
size_t i = 0; i < trackpair.size(); ++i){
320 if(!IsInVertexCollection(i, vertex_collection_int)){
322 std::vector<int> temp;
323 std::vector <TVector3> temp1;
325 temp1.push_back(startvec[i]);
326 vertex_collection_int.push_back(temp);
327 vertexcand_vec.push_back(temp1);
333 std::vector<size_t> vTrackIndices, vShowerIndices;
343 for(
size_t i = 0; i < vertex_collection_int.size(); ++i){
349 mf::LogInfo(
"PrimaryVertexFinder") <<
"vector elements at index " << i <<
" are " << *itr
350 <<
"\ntrack original ID = " << (trackpair[*itr].first)->ID();
352 vTrackIndices.push_back(trackpair[*itr].first.key());
354 mf::LogInfo(
"PrimaryVertexFinder") <<
"------------";
362 elemsize = vertexcand_vec[i].size();
365 double avgx = x/elemsize;
366 double avgy = y/elemsize;
367 double avgz = z/elemsize;
369 Double_t vtxcoord[3];
375 vcol->push_back(the3Dvertex);
377 if(!vTrackIndices.empty()){
380 vcol->size() - 1, vTrackIndices.begin(), vTrackIndices.end());
381 for(
size_t tIndex: vTrackIndices) {
382 std::vector<art::Ptr<recob::Hit>>
const&
hits = TrackHits.at(tIndex);
385 vTrackIndices.clear();
388 if(!vShowerIndices.empty()){
391 vcol->size() - 1, vShowerIndices.begin(), vShowerIndices.end());
392 for(
size_t sIndex: vShowerIndices){
393 std::vector<art::Ptr<recob::Hit>>
const&
hits = ShowerHits.at(sIndex);
396 vShowerIndices.clear();
402 LOG_VERBATIM(
"Summary") << std::setfill(
'-') << std::setw(175) <<
"-" << std::setfill(
' ');
403 LOG_VERBATIM(
"Summary") <<
"PrimaryVertexFinder Summary:";
404 for(
size_t i = 0; i < vcol->size(); ++i)
LOG_VERBATIM(
"Summary") << vcol->at(i) ;
406 evt.
put(std::move(vcol));
407 evt.
put(std::move(vtassn));
408 evt.
put(std::move(vhassn));
409 evt.
put(std::move(vsassn));
417 double x= (sp2.
XYZ()[0])-(sp1.
XYZ()[0]);
418 double y= (sp2.
XYZ()[1])-(sp1.
XYZ()[1]);
419 double z= (sp2.
XYZ()[2])-(sp1.
XYZ()[2]);
420 double distance = std::sqrt(pow(x,2)+pow(y,2)+pow(z,2));
428 for(
unsigned int i = 0; i < vertex_collection.size() ; i++){
444 for(
unsigned int i = 0; i < vertex_collection.size() ; i++){
446 if (a == *itr || b == *itr)
456 for(
unsigned int i = 0; i < newvertex.size() ; i++){
457 if (a == newvertex[i]){
470 double gamma = ((startpoint1*dircos2)-(startpoint2*dircos2)+((dircos1*dircos2)*(startpoint2*dircos1))-((dircos1*dircos2)*(startpoint1*dircos1)))/(1-((dircos1*dircos2)*(dircos1*dircos2)));
477 double alpha = (gamma*(dircos1*dircos2)) + (startpoint2*dircos1) - (startpoint1*dircos1);
484 TVector3 mindis_vector = startpoint1 - startpoint2 + alpha*dircos1 - gamma*dircos2;
485 double mindis = mindis_vector.Mag();
491 TVector3 PointOnExtendedTrack = startpoint + (alphagamma * dircos);
492 return PointOnExtendedTrack;
503 #endif // PrimaryVertexFinder_H
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Reconstruction base classes.
TVector3 PointOnExtendedTrack(double alphagamma, TVector3 startpoint, TVector3 dircos)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Declaration of signal hit object.
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)
ProductID put(std::unique_ptr< PROD > &&product)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
#define DEFINE_ART_MODULE(klass)
T get(std::string const &key) const
std::vector< evd::details::RawDigitInfo_t >::const_iterator begin(RawDigitCacheDataClass const &cache)
bool CreateAssn(PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t indx=UINT_MAX)
Creates a single one-to-one association.
std::string fTrackModuleLabel
Provides recob::Track data product.
double MinDist(double alpha, double gamma, TVector3 startpoint1, TVector3 startpoint2, TVector3 dircos1, TVector3 dircos2)
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
T * make(ARGS...args) const
const double * XYZ() const
Utility object to perform functions of 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 getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
bool IsInVertexCollection(int a, std::vector< std::vector< int > > vertex_collection)
tracking::Point_t Point_t
EventNumber_t event() const
double gammavalue(TVector3 startpoint1, TVector3 startpoint2, TVector3 dircos1, TVector3 dircos2)
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
double alphavalue(double gamma, TVector3 startpoint1, TVector3 startpoint2, TVector3 dircos1, TVector3 dircos2)
#define LOG_VERBATIM(category)
art framework interface to geometry description