File indexing completed on 2025-08-03 08:19:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include <iostream>
0017 #include <fstream>
0018 #include <memory>
0019 #include <chrono>
0020 #include <thread>
0021
0022 #include "gzstream.h"
0023 #include "PartonShower.h"
0024 #include "JetScapeLogger.h"
0025 #include "JetScapeReader.h"
0026 #include "JetScapeBanner.h"
0027 #include "fjcore.hh"
0028
0029 #include <GTL/dfs.h>
0030
0031 #include <TH1.h>
0032 #include <TFile.h>
0033
0034 using namespace std;
0035 using namespace Jetscape;
0036
0037 using namespace fjcore;
0038
0039
0040
0041
0042 void AnalyzeGraph(shared_ptr<PartonShower> mS);
0043 ostream & operator<<(ostream & ostr, const PseudoJet & jet);
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054 int main(int argc, char** argv)
0055 {
0056
0057
0058 string inname = "test_out.dat.gz";
0059 string outname = "test_out.root";
0060 string filetype = ".dat.gz";
0061 std::size_t pos=0;
0062 switch ( argc ){
0063 break;
0064 case 3:
0065 inname = argv[1];
0066 outname = argv[2];
0067 break;
0068 case 2:
0069 inname = argv[1];
0070 outname = inname;
0071 pos = outname.find( filetype);
0072 if ( pos==std::string::npos ){
0073 throw std::runtime_error ("Please use a filename ending in .dat.gz for an automatically generated output name");
0074 return -1;
0075 }
0076 outname.replace(pos, filetype.length(), ".root");
0077 break;
0078 case 1:
0079 case 0:
0080 break;
0081 default:
0082 cout << "Usage: readerTestWithRoot [inputname] [outputname]" << endl;
0083 return -1;
0084 }
0085
0086 JetScapeLogger::Instance()->SetInfo(false);
0087 JetScapeLogger::Instance()->SetDebug(false);
0088 JetScapeLogger::Instance()->SetRemark(false);
0089 JetScapeLogger::Instance()->SetVerboseLevel(0);
0090
0091 cout<<endl;
0092
0093
0094
0095
0096 igzstream inFile;
0097 inFile.open(inname.c_str());
0098 string line;
0099 int nAccepted=-1;
0100 double sigmaGen=-1;
0101 string cs="# ";
0102 string tofind;
0103 while (getline(inFile,line)) {
0104 if ( line.compare(0, cs.length(), cs) != 0) continue;
0105
0106 tofind = "# nAccepted = ";
0107 pos = line.find( tofind );
0108 if ( pos!=std::string::npos ) nAccepted=atoi( string ( line.begin()+pos+tofind.length(), line.end()).c_str());
0109
0110 tofind = "# sigmaGen = ";
0111 pos = line.find( tofind );
0112 if ( pos!=std::string::npos ) sigmaGen=atof( string ( line.begin()+pos+tofind.length(), line.end()).c_str());
0113 }
0114 if ( sigmaGen<0 || nAccepted<0 ){
0115 throw std::runtime_error("Couldn't find sigmaGen and nAccepted in the footer.");
0116 return -1;
0117 }
0118
0119 INFO << "Using sigmaGen = " << sigmaGen << " and nAccepted = " << nAccepted;
0120
0121 double weight = sigmaGen / nAccepted;
0122
0123
0124
0125 float R=0.4;
0126 JetDefinition jet_def(antikt_algorithm, R);
0127
0128
0129
0130 float max_track_rap = 2;
0131 Selector select_track_rap = SelectorAbsRapMax(max_track_rap);
0132 Selector select_pt = SelectorPtMin( 0.2 );
0133 Selector select_cons = select_track_rap * select_pt;
0134
0135
0136 Selector select_jet_eta = SelectorAbsEtaMax( max_track_rap-R );
0137 Selector select_jet_pt = SelectorPtRange( 10,1000 );
0138 Selector select_jet = select_jet_eta * select_jet_pt;
0139
0140
0141
0142 float ptlead = 40;
0143 float ptsublead = 20;
0144
0145 auto reader=make_shared<JetScapeReaderAsciiGZ>(inname);
0146
0147
0148 TFile* fout = new TFile( outname.data(), "RECREATE");
0149
0150
0151 TH1::SetDefaultSumw2();
0152
0153
0154 TH1D* partonpt = new TH1D ("partonpt","Final Parton p_{T};p_{T} [GeV/c]",120, 0, 120);
0155 TH1D* partoneta = new TH1D ("partoneta","Final Parton #eta; #eta",100, -5, 5);
0156 TH1D* hardpartonpt = new TH1D ("hardpartonpt","Hard Parton p_{T};p_{T} [GeV/c]",80, 0, 40);
0157 TH1D* hardpartoneta = new TH1D ("hardpartoneta","Hard Parton #eta; #eta",100, -5, 5);
0158
0159 TH1D* leadjetpt = new TH1D ("leadjetpt","Leading Jet p_{T};p_{T}^{jet} [GeV/c]",120, 0, 120);
0160 TH1D* subleadjetpt = new TH1D ("subleadjetpt","Sub-Leading Jet p_{T};p_{T}^{jet} [GeV/c]",120, 0, 120);
0161
0162 TH1D* aj = new TH1D ("aj","A_{J};", 40, -1, 1 );
0163
0164 TH1D* jetpt = new TH1D ("jetpt","Jet p_{T};p_{T}^{jet} [GeV/c]",120,0,120);
0165 TH1D* jeteta = new TH1D ("jeteta","Jet #eta;#eta^{jet} [GeV/c]",100, -3, 3);
0166
0167
0168 TH1D* jetz = new TH1D ("jetz","Jet z;p_{T}^{constituent} / p_{T}^{jet}",100, 0, 1);
0169
0170 TH1D* dR = new TH1D ("dR","#DeltaR;counts",50, 0, 1);
0171
0172
0173 vector<shared_ptr<PartonShower>> mShowers;
0174
0175 long event = 0;
0176 while (!reader->Finished()){
0177 reader->Next();
0178 if ( !(event%1000) ) cout << "Working on " << event << endl;
0179 event++;
0180
0181
0182 mShowers=reader->GetPartonShowers();
0183
0184
0185 vector<PseudoJet> jets;
0186 for (int i=0;i<mShowers.size();i++){
0187
0188 vector<PseudoJet> particles = select_cons(mShowers[i]->GetFinalPartonsForFastJet());
0189 ClusterSequence cs(particles, jet_def);
0190
0191
0192
0193
0194
0195 hardpartonpt->Fill ( mShowers[i]->GetPartonAt(0)->pt(), weight );
0196 hardpartoneta->Fill ( mShowers[i]->GetPartonAt(0)->eta(), weight );
0197
0198
0199 for ( auto &p : mShowers[i]->GetFinalPartonsForFastJet() ){
0200 partonpt->Fill ( p.pt(), weight );
0201 partoneta->Fill ( p.eta(), weight );
0202 }
0203
0204
0205 for (auto j : select_jet( cs.inclusive_jets()) ){
0206
0207 jets.push_back(j);
0208
0209
0210 for ( auto &consts : j.constituents() ){
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223 jetz->Fill( consts.pt() / j.pt(), weight );
0224 dR->Fill( consts.delta_R(j), weight );
0225 }
0226
0227 }
0228
0229
0230 }
0231
0232
0233 if ( jets.size()==0 ) continue;
0234
0235 jets = sorted_by_pt( jets );
0236
0237
0238 for (auto j : jets){
0239
0240 jetpt->Fill( j.pt(), weight );
0241 jeteta->Fill( j.eta(), weight );
0242
0243 }
0244
0245
0246 if ( jets.size()<2 ) continue;
0247 PseudoJet lead = jets.at(0);
0248 PseudoJet sublead = jets.at(1);
0249
0250 if ( lead.pt()<ptlead || sublead.pt()<ptsublead ) continue;
0251
0252
0253 float dphi = lead.delta_phi_to( sublead );
0254 if ( dphi < -Jetscape::pi || dphi > Jetscape::pi ) {
0255 cerr << " dphi = " << dphi << endl;
0256 return -1;
0257 }
0258
0259 if ( dphi > -Jetscape::pi+R && dphi < Jetscape::pi-R ) continue;
0260
0261
0262 leadjetpt->Fill( lead.pt(), weight );
0263 subleadjetpt->Fill( sublead.pt(), weight );
0264 aj->Fill( (lead.pt()-sublead.pt()) / (lead.pt()+sublead.pt()), weight);
0265
0266
0267 }
0268 reader->Close();
0269 fout->Write();
0270
0271 INFO_NICE<<"Finished!";
0272 INFO << "Read from " << inname;
0273 INFO << "Wrote to " << outname;
0274 cout << endl;
0275 return 0;
0276
0277 }
0278
0279
0280
0281 void AnalyzeGraph(shared_ptr<PartonShower> mS)
0282 {
0283 INFO<<"Some GTL graph/shower analysis/dfs search output:";
0284
0285 dfs search;
0286 search.calc_comp_num(true);
0287 search.scan_whole_graph(true);
0288 search.start_node();
0289 search.run(*mS);
0290
0291 cout<<endl;
0292 cout<<"DFS graph search feature from GTL:"<<endl;
0293 cout<<"Number of Nodes reached from node 0 = "<< search.number_of_reached_nodes () <<endl;
0294 cout<<"Node/Vertex ordering result from DFS:"<<endl;
0295 dfs::dfs_iterator itt2, endt2;
0296 for (itt2 = search.begin(), endt2=search.end(); itt2 !=endt2; ++itt2)
0297 {
0298 cout<<*itt2<<" ";
0299 }
0300 cout<<endl;
0301
0302 cout<<"Edge/Parton ordering result from DFS:"<<endl;
0303 dfs::tree_edges_iterator itt, endt;
0304 for (itt = search.tree_edges_begin(), endt=search.tree_edges_end(); itt !=endt; ++itt)
0305 {
0306 cout<<*itt;
0307 }
0308 cout<<endl;
0309
0310 dfs::roots_iterator itt3, endt3;
0311 cout<<"List of root nodes found in graph/shower : ";
0312 for (itt3 = search.roots_begin(), endt3=search.roots_end(); itt3 !=endt3; ++itt3)
0313 {
0314 cout<<**itt3;
0315 }
0316 cout<<endl;
0317 cout<<endl;
0318 }
0319
0320
0321
0322 ostream & operator<<(ostream & ostr, const PseudoJet & jet) {
0323 if (jet == 0) {
0324 ostr << " 0 ";
0325 } else {
0326 ostr << " pt = " << jet.pt()
0327 << " m = " << jet.m()
0328 << " y = " << jet.rap()
0329 << " phi = " << jet.phi();
0330 }
0331 return ostr;
0332 }
0333
0334
0335