Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PrintTowers.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PrintTowers.cc
1 #include "PrintTowers.h"
2 #include "fastjet/AreaDefinition.hh"
3 #include "fastjet/ClusterSequenceArea.hh"
4 #include "fastjet/Selector.hh"
5 #include "fastjet/tools/BackgroundEstimatorBase.hh"
6 #include "fastjet/tools/JetMedianBackgroundEstimator.hh"
7 
8 
9 #include <TFile.h>
10 #include <TH1F.h>
11 #include <TH2F.h>
12 #include <TRandom3.h>
13 #include <TString.h>
14 #include <TTree.h>
15 #include <TH2D.h>
16 #include <TVector3.h>
17 #include <algorithm>
18 #include <cassert>
20 #include <cmath>
21 #include <fastjet/ClusterSequence.hh>
22 #include <fastjet/JetDefinition.hh>
23 #include <fastjet/PseudoJet.hh>
25 #include <fun4all/Fun4AllServer.h>
26 #include <fun4all/PHTFileServer.h>
27 #include <g4eval/JetEvalStack.h>
28 #include <jetbase/Jet.h>
29 #include <jetbase/JetInput.h>
30 #include <jetbase/TowerJetInput.h>
31 #include <jetbase/JetMapv1.h>
32 #include <iostream>
33 #include <limits>
34 #include <phool/PHCompositeNode.h>
35 #include <phool/getClass.h>
36 #include <stdexcept>
39 
40 // using namespace fastjet;
41 
43  ( std::vector<std::string> jetnames
44  , std::vector<std::pair<std::string,std::string>> matchlist
45  , std::vector<std::pair<Jet::SRC,std::string>> src
46  , const float min_jet_pt
47  , const float min_tow_pt
48  )
49  : SubsysReco("PrintTowers")
50  , m_jet_names { jetnames }
51  , m_matchlist { matchlist }
52  , m_SRC { src }
53  , m_min_jet_pt { min_jet_pt }
54  , m_min_tow_pt { min_tow_pt }
55 { }
56 
58 {
59 }
60 
63 
66 
68 {
69  topNode->print();
71 }
72 
74 {
75 
76  CentralityInfo* cent_node = findNode::getClass<CentralityInfo>(topNode, "CentralityInfo");
77  float cent = cent_node->get_centile(CentralityInfo::PROP::epd_NS);
79 
80  std::cout << std::endl << " NEW EVENT " << nevnt++ << " cent("<<cent<<")" <<std::endl;
81 
82 
83 
84  for (auto& name : m_jet_names) {
85  std::cout << std::endl << " --- JetMap named " << name << " --- " << std::endl;
86  JetMap* jetmap = findNode::getClass<JetMap>(topNode, name);
87  if (jetmap == nullptr )
88  {
89  std::cout << " -> is NULL (not present) on the node tree." << std::endl;
90  continue;
91  }
92  auto jets = jetmap->vec();
93  std::sort(jets.begin(), jets.end(), [](Jet* a, Jet* b){return a->get_pt() > b->get_pt();});
94  std::cout << Form(" -> Has %i jets; printing up to %i jets w/pT>%5.2f", ((int)jets.size()), nmax_jetprint, m_min_jet_pt) << std::endl;
95  int i {0};
96  for (auto jet : jets) {
97  if (jet->get_pt() < m_min_jet_pt) break;
98  if (i==nmax_jetprint) break;
99  std::cout << Form("k[%i] pt:phi:eta[%5.2f:%5.2f:%5.2f]", i++, jet->get_pt(), jet->get_phi(), jet->get_eta()) << std::endl;
100  }
101  }
102 
103  for (auto match : m_matchlist) {
104  JetMap* jetmapA = findNode::getClass<JetMap>(topNode, match.first);
105  if (jetmapA == nullptr )
106  {
107  std::cout << " Can't jet map " << match.first << std::endl;
108  continue;
109  }
110  auto jetsA = jetmapA->vec();
111  std::sort(jetsA.begin(), jetsA.end(), [](Jet* a, Jet* b){return a->get_pt() > b->get_pt();});
112 
113  JetMap* jetmapB = findNode::getClass<JetMap>(topNode, match.second);
114  if (jetmapB == nullptr )
115  {
116  std::cout << " Can't find jet map " << match.second << std::endl;
117  continue;
118  }
119  auto jetsB = jetmapB->vec();
120  std::sort(jetsB.begin(), jetsB.end(), [](Jet* a, Jet* b){return a->get_pt() > b->get_pt();});
121 
122  std::cout << std::endl << " >>> Matching (up to " << m_pt_min_match << "GeV) " << match.first << " with " << match.second << std::endl;
123  // do the matching, assume R=0.4
124  std::vector<bool> B_is_matched (jetsB.size(),false);
125  for (auto A : jetsA) {
126  if (A->get_pt() < m_pt_min_match) break;
127  bool found_A = false;
128  for (unsigned int iB = 0; iB<jetsB.size(); ++iB) {
129  if (B_is_matched[iB]) continue;
130  auto B = jetsB[iB];
131  float dphi = fabs(A->get_phi()-B->get_phi());
132  while (dphi>M_PI) dphi = fabs(dphi - 2*M_PI);
133  const float deta = A->get_eta() - B->get_eta();
134  const float R2_comp = deta*deta + dphi*dphi;
135  if (R2_comp<=0.16) {
136  std::cout << Form("Matched pT->pT; phi->phi; eta->eta [ %6.2f->%6.2f, %6.2f->%6.2f, %6.2f->%6.2f ]",
137  A->get_pt(), B->get_pt(), A->get_phi(), B->get_phi(), A->get_eta(), B->get_eta()) << std::endl;
138  found_A = true;
139  B_is_matched[iB] = true;
140  break;
141  }
142  }
143  if (!found_A) {
144  std::cout << Form("NoMatch pT->??; phi->???? eta->????[ %6.2f->%6s, %6.2f->%6s, %6.2f->%6s ]",
145  A->get_pt(), "nf", A->get_phi(), "nf", A->get_eta(), "nf") << std::endl;
146  }
147  }
148  }
149 
150  for (auto src : m_SRC) {
151  std::cout << std::endl << " --- Printing Tower Input: " << src.second << std::endl;
152  auto tow_inp = new TowerJetInput(src.first);
153  auto tows = tow_inp->get_input(topNode);
154  std::sort(tows.begin(), tows.end(), [](Jet* a, Jet* b){return a->get_pt() > b->get_pt();});
155  std::cout << Form(" -> Has %i towers; printing all w/pT>%5.2f", ((int)tows.size()), m_min_tow_pt) << std::endl;
156  int i {0};
157  for (auto tow : tows) {
158  if (tow->get_pt() < m_min_tow_pt) break;
159  std::cout << Form("k[%i] pt:phi:eta[%5.2f:%5.2f:%5.2f]", i++, tow->get_pt(), tow->get_phi(), tow->get_eta()) << std::endl;
160  }
161  for (auto tow : tows) delete tow;
162  }
164 
165 }
166