File indexing completed on 2025-08-06 08:14:20
0001 #include "RandomConeTree.h"
0002
0003
0004 #include <randomcones/RandomCone.h>
0005 #include <randomcones/RandomConev1.h>
0006
0007
0008 #include <towerrho/TowerRho.h>
0009 #include <towerrho/TowerRhov1.h>
0010
0011
0012 #include <fun4all/Fun4AllReturnCodes.h>
0013 #include <fun4all/PHTFileServer.h>
0014
0015
0016 #include <phool/PHCompositeNode.h>
0017 #include <phool/getClass.h>
0018
0019
0020 #include <jetbase/Jet.h>
0021 #include <jetbase/JetMap.h>
0022 #include <jetbase/Jetv1.h>
0023 #include <jetbase/JetMapv1.h>
0024 #include <jetbase/JetContainer.h>
0025 #include <jetbase/JetContainerv1.h>
0026 #include <jetbase/Jetv2.h>
0027
0028
0029
0030 #include <centrality/CentralityInfo.h>
0031
0032
0033 #include <globalvertex/GlobalVertex.h>
0034 #include <globalvertex/GlobalVertexMap.h>
0035 #include <globalvertex/GlobalVertexMapv1.h>
0036
0037
0038 #include <mbd/MbdOut.h>
0039
0040
0041 #include <TTree.h>
0042
0043
0044 #include <cmath>
0045 #include <utility>
0046 #include <cstdlib>
0047 #include <iostream>
0048 #include <vector>
0049 #include <string>
0050 #include <array>
0051
0052
0053 RandomConeTree::RandomConeTree(const std::string& outputfilename)
0054 : SubsysReco("RandomConeTree")
0055 , m_outputfile_name(outputfilename)
0056 {
0057 }
0058
0059 RandomConeTree::~RandomConeTree()
0060 {
0061
0062 if(m_run_info_tree) delete m_run_info_tree;
0063 if(m_event_tree) delete m_event_tree;
0064 }
0065
0066 int RandomConeTree::Init(PHCompositeNode *topNode)
0067 {
0068
0069 PHTFileServer::get().open(m_outputfile_name, "RECREATE");
0070
0071
0072 m_run_info_tree = new TTree("run_info", "RunInfo");
0073 m_event_tree = new TTree("event_info", "EventInfo");
0074
0075
0076 if(m_do_gvtx_cut)
0077 {
0078 m_run_info_tree->Branch("zvtx_low", &m_gvtx_cut.first, "zvtx_low/F");
0079 m_run_info_tree->Branch("zvtx_high", &m_gvtx_cut.second, "zvtx_high/F");
0080 }
0081 if(m_MC_do_event_selection)
0082 {
0083 m_run_info_tree->Branch("MC_event_selection_jetpT_low", &m_MC_event_selection_jetpT_range.first, "MC_event_selection_jetpT_low/F");
0084 m_run_info_tree->Branch("MC_event_selection_jetpT_high", &m_MC_event_selection_jetpT_range.second, "MC_event_selection_jetpT_high/F");
0085 }
0086 if(m_MC_add_weight_to_ttree)
0087 {
0088 m_run_info_tree->Branch("MC_event_weight", &m_MC_event_weight, "MC_event_weight/D");
0089 }
0090
0091
0092 m_run_info_tree->Fill();
0093
0094
0095 m_event_tree->Branch("event_id", &m_event_id, "event_id/I");
0096 if(m_do_cent_info)
0097 {
0098 m_event_tree->Branch("centrality", &m_centrality, "centrality/I");
0099 if(!m_do_data) m_event_tree->Branch("impactparam", &m_impactparam, "impactparam/F");
0100 m_event_tree->Branch("mbd_NS", &m_mbd_NS, "mbd_NS/D");
0101 }
0102 m_event_tree->Branch("zvtx", &m_zvtx, "zvtx/F");
0103
0104
0105 for(unsigned int i = 0; i < m_rho_nodes.size(); ++i)
0106 {
0107 std::string name = m_rho_nodes.at(i)+"_rho";
0108 m_event_tree->Branch(name.c_str(), &m_rhos[i], (name + "/F").c_str());
0109 name = m_rho_nodes.at(i)+"_sigma";
0110 m_event_tree->Branch(name.c_str(), &m_sigma_rhos[i], (name + "/F").c_str());
0111 }
0112
0113
0114 for(unsigned int i = 0; i < m_random_cone_nodes.size(); ++i)
0115 {
0116 std::string name = m_random_cone_nodes.at(i)+"_R";
0117 m_event_tree->Branch(name.c_str(), &m_cone_R[i], (name + "/F").c_str());
0118 name = m_random_cone_nodes.at(i)+"_eta";
0119 m_event_tree->Branch(name.c_str(), &m_cone_etas[i], (name + "/F").c_str());
0120 name = m_random_cone_nodes.at(i)+"_phi";
0121 m_event_tree->Branch(name.c_str(), &m_cone_phis[i], (name + "/F").c_str());
0122 name = m_random_cone_nodes.at(i)+"_pt";
0123 m_event_tree->Branch(name.c_str(), &m_cone_pts[i], (name + "/F").c_str());
0124 name = m_random_cone_nodes.at(i)+"_nclustered";
0125 m_event_tree->Branch(name.c_str(), &m_cone_nclustereds[i], (name + "/I").c_str());
0126 }
0127
0128
0129 m_event_id = -1;
0130
0131
0132 return Fun4AllReturnCodes::EVENT_OK;
0133
0134 }
0135
0136 int RandomConeTree::ResetEvent(PHCompositeNode *topNode)
0137 {
0138
0139 m_centrality = -1;
0140 m_impactparam = NAN;
0141 m_zvtx = NAN;
0142 m_mbd_NS = NAN;
0143
0144 for(unsigned int i = 0; i < m_rho_nodes.size(); ++i)
0145 {
0146 m_rhos[i] = NAN;
0147 m_sigma_rhos[i] = NAN;
0148 }
0149
0150 for(unsigned int i = 0; i < m_random_cone_nodes.size(); ++i)
0151 {
0152 m_cone_R[i] = NAN;
0153 m_cone_etas[i] = NAN;
0154 m_cone_phis[i] = NAN;
0155 m_cone_pts[i] = NAN;
0156 m_cone_nclustereds[i] = -1;
0157 }
0158
0159 return Fun4AllReturnCodes::EVENT_OK;
0160 }
0161
0162 int RandomConeTree::process_event(PHCompositeNode *topNode)
0163 {
0164
0165 ++m_event_id;
0166
0167
0168 if(!GoodEvent(topNode)) return Fun4AllReturnCodes::ABORTEVENT;
0169
0170
0171 if(m_do_cent_info) GetCentInfo(topNode);
0172
0173
0174
0175 for(unsigned int i = 0; i < m_rho_nodes.size(); ++i)
0176 {
0177 TowerRho* towerrho = findNode::getClass<TowerRhov1>(topNode, m_rho_nodes.at(i));
0178 if (!towerrho)
0179 {
0180 std::cout << "RandomConeTree - Error can not find towerrho " << m_rho_nodes.at(i) << std::endl;
0181 exit(-1);
0182 }
0183 m_rhos[i] = towerrho->get_rho();
0184 m_sigma_rhos[i] = towerrho->get_sigma();
0185 }
0186
0187
0188 for(unsigned int i = 0; i < m_random_cone_nodes.size(); ++i)
0189 {
0190 RandomCone* rcone = findNode::getClass<RandomConev1>(topNode, m_random_cone_nodes.at(i));
0191 if (!rcone)
0192 {
0193 std::cout << "RandomConeTree - Error can not find random cone " << m_random_cone_nodes.at(i) << std::endl;
0194 exit(-1);
0195 }
0196 m_cone_R[i] = rcone->get_R();
0197 m_cone_etas[i] = rcone->get_eta();
0198 m_cone_phis[i] = rcone->get_phi();
0199 m_cone_pts[i] = rcone->get_pt();
0200 m_cone_nclustereds[i] = rcone->n_clustered();
0201 }
0202
0203
0204 m_event_tree->Fill();
0205
0206 return Fun4AllReturnCodes::EVENT_OK;
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372
0373
0374
0375 }
0376
0377 int RandomConeTree::End(PHCompositeNode *topNode)
0378 {
0379 std::cout << "RandomConeTree::End - Output to " << m_outputfile_name << std::endl;
0380
0381 PHTFileServer::get().cd(m_outputfile_name);
0382
0383
0384 PHTFileServer::get().write(m_outputfile_name);
0385 std::cout << "RandomConeTree::End(PHCompositeNode *topNode) This is the End..." << std::endl;
0386 return Fun4AllReturnCodes::EVENT_OK;
0387 }
0388
0389
0390
0391
0392 bool RandomConeTree::GoodEvent(PHCompositeNode *topNode)
0393 {
0394
0395 if(m_MC_do_event_selection)
0396 {
0397
0398 JetMap *truthjets = findNode::getClass<JetMap>(topNode, "AntiKt_Truth_r04");
0399 if(!truthjets)
0400 {
0401 std::cout << "RandomConeTree::GoodEvent(PHCompositeNode *topNode) Could not find truth jet nodes" << std::endl;
0402 exit(-1);
0403 }
0404
0405
0406 float leading_truth_pt = -1;
0407 for(JetMap::Iter iter = truthjets->begin(); iter != truthjets->end(); ++iter)
0408 {
0409
0410 Jet *jet = iter->second;
0411
0412 if(jet->get_pt() > leading_truth_pt) leading_truth_pt = jet->get_pt();
0413
0414 }
0415
0416
0417 if( (leading_truth_pt < m_MC_event_selection_jetpT_range.first) ||
0418 (leading_truth_pt > m_MC_event_selection_jetpT_range.second)
0419 )
0420 {
0421
0422 if(Verbosity() > 0) std::cout << "RandomConeTree::GoodEvent(PHCompositeNode *topNode) Event failed MC event selection" << std::endl;
0423 return false;
0424
0425 }
0426 }
0427
0428
0429 if(m_do_gvtx_cut)
0430 {
0431
0432 GlobalVertexMap *vtxMap = findNode::getClass<GlobalVertexMapv1>(topNode,"GlobalVertexMap");
0433 if (!vtxMap)
0434 {
0435 std::cout << "RandomConeTree::GoodEvent(PHCompositeNode *topNode) Could not find global vertex map node" << std::endl;
0436 exit(-1);
0437 }
0438
0439 if (!vtxMap->get(0))
0440 {
0441 if(Verbosity() > 0) std::cout << "RandomConeTree::GoodEvent(PHCompositeNode *topNode) No primary vertex" << std::endl;
0442 return false;
0443 }
0444
0445
0446 m_zvtx = vtxMap->get(0)->get_z();
0447
0448 if( (m_zvtx < m_gvtx_cut.first) || (m_zvtx > m_gvtx_cut.second))
0449 {
0450 if(Verbosity() > 0) std::cout << "RandomConeTree::GoodEvent(PHCompositeNode *topNode) Vertex cut failed" << std::endl;
0451 return false;
0452 }
0453
0454 }
0455
0456 return true;
0457
0458 }
0459
0460
0461
0462 void RandomConeTree::GetCentInfo(PHCompositeNode *topNode)
0463 {
0464
0465
0466
0467 CentralityInfo* cent_node = findNode::getClass<CentralityInfo>(topNode, "CentralityInfo");
0468 if (!cent_node)
0469 {
0470 std::cout << "RandomConeTree::process_event() ERROR: Can't find CentralityInfo" << std::endl;
0471 exit(-1);
0472 }
0473
0474 if (!m_do_data)
0475 {
0476 m_centrality = cent_node->get_centile(CentralityInfo::PROP::bimp);
0477 m_impactparam = cent_node->get_quantity(CentralityInfo::PROP::bimp);
0478 m_mbd_NS = cent_node->get_quantity(CentralityInfo::PROP::mbd_NS);
0479 }
0480 else
0481 {
0482 m_centrality = (int)(100*cent_node->get_centile(CentralityInfo::PROP::mbd_NS));
0483
0484 PHNodeIterator iter(topNode);
0485 PHCompositeNode *mbdNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "MBD"));
0486 if(!mbdNode)
0487 {
0488 std::cerr << Name() << "::" << __PRETTY_FUNCTION__ << "MBD Node missing, doing nothing." << std::endl;
0489 throw std::runtime_error("Failed to find MBD node in RandomConeTree::GetCentInfo");
0490 }
0491
0492 MbdOut *_data_MBD = findNode::getClass<MbdOut>(mbdNode, "MbdOut");
0493
0494 if(!_data_MBD)
0495 {
0496 std::cerr << Name() << "::" << __PRETTY_FUNCTION__ << "MbdOut Node missing, doing nothing." << std::endl;
0497 throw std::runtime_error("Failed to find MbdOut node in RandomConeTree::GetCentInfo");
0498 }
0499
0500 m_mbd_NS = _data_MBD->get_q(0) + _data_MBD->get_q(1);
0501 }
0502
0503 return ;
0504 }