File indexing completed on 2025-08-06 08:17:42
0001 #include "InttZVertexFinder.h"
0002 #include "INTTZvtx.h"
0003 #include "InttVertexMapv1.h"
0004 #include "InttVertexv1.h"
0005
0006
0007 #include <trackbase/ActsGeometry.h>
0008 #include <trackbase/InttDefs.h>
0009 #include <trackbase/TrkrCluster.h>
0010 #include <trackbase/TrkrClusterContainer.h>
0011 #include <trackbase/TrkrHit.h>
0012 #include <trackbase/TrkrHitSet.h>
0013 #include <trackbase/TrkrHitSetContainer.h>
0014
0015 #include <fun4all/Fun4AllReturnCodes.h>
0016
0017 #include <phool/PHCompositeNode.h>
0018 #include <phool/getClass.h>
0019
0020 #include <cmath>
0021 #include <filesystem>
0022
0023
0024
0025 std::string sDataType = "data";
0026 std::string sOutFolderDirectory = "./";
0027 std::pair<double, double> beam_origin = {-0.23436750, 2.5985125};
0028 double phi_diff_cut = 1;
0029
0030 std::pair<double, double> DCA_cut = {-3, 3};
0031 int N_clu_cut = 10000;
0032 int N_clu_cutl = 4;
0033 unsigned int zvtx_cal_require = 3;
0034 std::pair<double, double> zvtx_QA_width = {40, 70};
0035 double zvtx_QA_ratio = 0.00006;
0036 bool draw_event_display = false;
0037 bool enable_qa = false;
0038
0039 int clu_sum_adc_cut = 31;
0040 int clu_size_cut = 4;
0041
0042 int data_type = 2;
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083 InttZVertexFinder::InttZVertexFinder(const std::string& name)
0084 : SubsysReco(name)
0085 , m_inttzvtx(new INTTZvtx(sDataType,
0086 sOutFolderDirectory,
0087 beam_origin,
0088 phi_diff_cut,
0089 DCA_cut,
0090 N_clu_cutl,
0091 N_clu_cut,
0092 zvtx_cal_require,
0093 zvtx_QA_width,
0094 draw_event_display,
0095 enable_qa))
0096 {
0097 std::cout << "InttZVertexFinder::InttZVertexFinder(const std::string &name) Calling ctor" << std::endl;
0098 }
0099
0100
0101 InttZVertexFinder::~InttZVertexFinder()
0102 {
0103 std::cout << "InttZVertexFinder::~InttZVertexFinder() Calling dtor" << std::endl;
0104 delete m_inttzvtx;
0105 }
0106
0107
0108 int InttZVertexFinder::Init(PHCompositeNode* )
0109 {
0110 std::cout << "InttZVertexFinder::Init(PHCompositeNode *topNode) Initializing" << std::endl;
0111
0112
0113 return Fun4AllReturnCodes::EVENT_OK;
0114 }
0115
0116
0117 int InttZVertexFinder::InitRun(PHCompositeNode* topNode)
0118 {
0119 std::cout << "InttZVertexFinder::InitRun(PHCompositeNode *topNode) Initializing for Run XXX" << std::endl;
0120
0121 if (createNodes(topNode) == Fun4AllReturnCodes::ABORTEVENT)
0122 {
0123 return Fun4AllReturnCodes::ABORTEVENT;
0124 }
0125
0126 m_inttzvtx->SetPrintMessageOpt(Verbosity() > 0);
0127
0128 m_inttzvtx->Init();
0129
0130 return Fun4AllReturnCodes::EVENT_OK;
0131 }
0132
0133 int InttZVertexFinder::createNodes(PHCompositeNode* topNode)
0134 {
0135 PHNodeIterator iter(topNode);
0136 PHCompositeNode* dstNode = dynamic_cast<PHCompositeNode*>(iter.findFirst("PHCompositeNode", "DST"));
0137 if (!dstNode)
0138 {
0139 std::cout << PHWHERE << "DST Node missing doing nothing" << std::endl;
0140 return Fun4AllReturnCodes::ABORTEVENT;
0141 }
0142
0143
0144 PHCompositeNode* inttNode = dynamic_cast<PHCompositeNode*>(iter.findFirst("PHCompositeNode", "INTT"));
0145 if (!inttNode)
0146 {
0147 inttNode = new PHCompositeNode("INTT");
0148 dstNode->addNode(inttNode);
0149 }
0150
0151 m_inttvertexmap = findNode::getClass<InttVertexMap>(inttNode, "InttVertexMap");
0152 if (!m_inttvertexmap)
0153 {
0154 m_inttvertexmap = new InttVertexMapv1();
0155 PHIODataNode<PHObject>* VertexMapNode = new PHIODataNode<PHObject>(m_inttvertexmap, "InttVertexMap", "PHObject");
0156 inttNode->addNode(VertexMapNode);
0157 }
0158
0159 return Fun4AllReturnCodes::EVENT_OK;
0160 }
0161
0162
0163 int InttZVertexFinder::process_event(PHCompositeNode* topNode)
0164 {
0165 if (Verbosity() > 1)
0166 {
0167 std::cout << "InttZVertexFinder::process_event(PHCompositeNode *topNode) Processing Event" << std::endl;
0168 }
0169
0170
0171
0172
0173 static int event_i = 0;
0174
0175 ActsGeometry* tGeometry = findNode::getClass<ActsGeometry>(topNode, "ActsGeometry");
0176 if (!tGeometry)
0177 {
0178 std::cout << PHWHERE << "No ActsGeometry on node tree. Bailing." << std::endl;
0179 return Fun4AllReturnCodes::ABORTEVENT;
0180 }
0181
0182 TrkrClusterContainer* clusterMap =
0183 findNode::getClass<TrkrClusterContainer>(topNode, "TRKR_CLUSTER");
0184 if (!clusterMap)
0185 {
0186 std::cout << PHWHERE << "TrkrClusterContainer node is missing." << std::endl;
0187 return Fun4AllReturnCodes::ABORTEVENT;
0188 }
0189
0190
0191
0192
0193 std::vector<INTTZvtx::clu_info> temp_sPH_inner_nocolumn_vec;
0194 std::vector<INTTZvtx::clu_info> temp_sPH_outer_nocolumn_vec;
0195
0196 std::vector<std::vector<double> > temp_sPH_nocolumn_vec(2);
0197 std::vector<std::vector<double> > temp_sPH_nocolumn_rz_vec(2);
0198
0199 for (unsigned int inttlayer = 0; inttlayer < 4; inttlayer++)
0200 {
0201 std::vector<INTTZvtx::clu_info>* p_temp_sPH_nocolumn_vec =
0202 (inttlayer < 2) ? (&temp_sPH_inner_nocolumn_vec)
0203 : (&temp_sPH_outer_nocolumn_vec);
0204
0205 for (const auto& hitsetkey : clusterMap->getHitSetKeys(TrkrDefs::TrkrId::inttId, inttlayer + 3))
0206 {
0207 auto range = clusterMap->getClusters(hitsetkey);
0208
0209 for (auto clusIter = range.first; clusIter != range.second; ++clusIter)
0210 {
0211 const auto cluskey = clusIter->first;
0212 const auto cluster = clusIter->second;
0213
0214 const auto globalPos = tGeometry->getGlobalPosition(cluskey, cluster);
0215 double clu_x = globalPos.x() * 10.;
0216 double clu_y = globalPos.y() * 10.;
0217 double clu_z = globalPos.z() * 10.;
0218
0219 double clu_phi = (clu_y < 0) ? atan2(clu_y, clu_x) * (180. / M_PI) + 360
0220 : atan2(clu_y, clu_x) * (180. / M_PI);
0221
0222 double clu_radius = sqrt(pow(clu_x, 2) + pow(clu_y, 2));
0223
0224
0225 int adc = cluster->getAdc();
0226
0227 if (adc < 40)
0228 {
0229 continue;
0230 }
0231
0232 p_temp_sPH_nocolumn_vec->push_back({-1,
0233 -1,
0234 (int) cluster->getAdc(),
0235 (int) cluster->getAdc(),
0236 (int) cluster->getPhiSize(),
0237 clu_x,
0238 clu_y,
0239 clu_z,
0240 (int) inttlayer + 3,
0241 clu_phi});
0242
0243 temp_sPH_nocolumn_vec[0].push_back(clu_x);
0244 temp_sPH_nocolumn_vec[1].push_back(clu_y);
0245
0246 temp_sPH_nocolumn_rz_vec[0].push_back(clu_z);
0247 temp_sPH_nocolumn_rz_vec[1].push_back((clu_phi > 180) ? clu_radius * -1 : clu_radius);
0248
0249
0250
0251
0252
0253 }
0254 }
0255 }
0256
0257
0258
0259 int NvtxMC = 1;
0260 double TrigZvtxMC = 0.;
0261 Long64_t bcofull = 0;
0262
0263 bool status = m_inttzvtx->ProcessEvt(
0264 event_i,
0265 temp_sPH_inner_nocolumn_vec,
0266 temp_sPH_outer_nocolumn_vec,
0267 temp_sPH_nocolumn_vec,
0268 temp_sPH_nocolumn_rz_vec,
0269 NvtxMC,
0270 TrigZvtxMC,
0271 true,
0272 bcofull,
0273 5
0274 );
0275
0276 std::cout << "InttZVertex:process_evt status = " << (status ? "good" : "failed") << std::endl;
0277
0278 std::vector<double> vtxout = m_inttzvtx->GetEvtZPeak();
0279 std::pair<double, double> beamorigin = m_inttzvtx->GetBeamOrigin();
0280
0281 std::vector<double> final_vtx{beamorigin.first * 0.1,
0282 beamorigin.second * 0.1,
0283 vtxout[1] * 0.1};
0284
0285 INTTZvtx::ZvtxInfo& zvtxinfo = m_inttzvtx->GetZvtxInfo();
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297 auto vertex = std::make_unique<InttVertexv1>();
0298 vertex->set_x(final_vtx[0]);
0299 vertex->set_y(final_vtx[1]);
0300 vertex->set_z(final_vtx[2]);
0301
0302 vertex->set_chi2ndf(zvtxinfo.chi2ndf);
0303 vertex->set_width(zvtxinfo.width);
0304 vertex->set_good(zvtxinfo.good);
0305 vertex->set_nclus(zvtxinfo.nclus);
0306 vertex->set_ntracklet(zvtxinfo.ntracklets);
0307 vertex->set_ngroup(zvtxinfo.ngroup);
0308 vertex->set_peakratio(zvtxinfo.peakratio);
0309 vertex->set_peakwidth(zvtxinfo.peakwidth);
0310
0311
0312 m_inttvertexmap->insert(vertex.release());
0313
0314
0315 if (Verbosity() > 0)
0316 {
0317 std::cout << "vecsize in : " << temp_sPH_inner_nocolumn_vec.size()
0318 << ", out: " << temp_sPH_outer_nocolumn_vec.size()
0319 << ", zvtx : " << vtxout[1] << " +- " << vtxout[2]
0320 << " sts : " << vtxout[0]
0321 << std::endl;
0322 }
0323
0324 m_inttzvtx->ClearEvt();
0325
0326 event_i++;
0327
0328 return Fun4AllReturnCodes::EVENT_OK;
0329 }
0330
0331
0332 int InttZVertexFinder::End(PHCompositeNode* )
0333 {
0334 if (Verbosity())
0335 {
0336 std::cout << "InttZVertexFinder::End(PHCompositeNode *topNode) " << std::endl;
0337 }
0338
0339 m_inttzvtx->PrintPlots();
0340 m_inttzvtx->EndRun();
0341
0342 return Fun4AllReturnCodes::EVENT_OK;
0343 }
0344
0345
0346 void InttZVertexFinder::Print(const std::string& what) const
0347 {
0348 std::cout << "InttZVertexFinder::Print(const std::string &what) const Printing info for " << what << std::endl;
0349 }
0350
0351 void InttZVertexFinder::SetBeamCenter(const double beamx, const double beamy)
0352 {
0353 if (m_inttzvtx != nullptr)
0354 {
0355 m_inttzvtx->SetBeamOrigin(beamx * 10., beamy * 10.);
0356 }
0357 }
0358
0359 void InttZVertexFinder::SetOutDirectory(const std::string& outDirectory)
0360 {
0361 if (m_inttzvtx != nullptr)
0362 {
0363 m_inttzvtx->SetOutDirectory(outDirectory);
0364 }
0365 }
0366
0367 void InttZVertexFinder::EnableQA(const bool enableQA)
0368 {
0369 if (m_inttzvtx != nullptr)
0370 {
0371 m_inttzvtx->EnableQA(enableQA);
0372 }
0373 }
0374
0375 void InttZVertexFinder::EnableEventDisplay(const bool enableEvtDisp)
0376 {
0377 if (m_inttzvtx != nullptr)
0378 {
0379 m_inttzvtx->EnableEventDisplay(enableEvtDisp);
0380 }
0381 }