Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHAJMaker.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHAJMaker.cc
1 //----------------------------------------------------------
2 // Module for flow jet reconstruction in sPHENIX
3 // J. Orjuela-Koop
4 // May 5 2015
5 //----------------------------------------------------------
6 
7 #include"PHAJMaker.h"
8 #include"PseudoJetPlus.h"
9 
10 #include<calobase/RawCluster.h>
11 #include<calobase/RawClusterContainer.h>
12 
13 #include <g4hough/SvtxTrackMap.h>
14 #include <g4hough/SvtxTrack.h>
15 
17 #include<phool/PHNodeIterator.h>
18 #include<phool/PHNodeReset.h>
19 #include<fun4all/getClass.h>
20 
21 #include <fastjet/JetDefinition.hh>
22 #include <fastjet/PseudoJet.hh>
23 #include <fastjet/ClusterSequence.hh>
24 #include <fastjet/SISConePlugin.hh>
25 
26 #include <TF1.h>
27 #include <TFile.h>
28 #include <TH1.h>
29 #include <TH2.h>
30 #include <TLorentzVector.h>
31 #include <TNtuple.h>
32 
33 #include <cmath>
34 
35 using namespace std;
36 
37 typedef std::map<int,TLorentzVector*> tlvmap;
38 
39 /*
40  * Constructor
41  */
42 
43 // Standard ctor
45  double R,
46  double jet_ptmin, double jet_ptmax,
47  double LeadPtMin, double SubLeadPtMin,
48  double max_track_rap, double PtConsLo, double PtConsHi,
49  double dPhiCut
50  )
51  : SubsysReco(name),
52  R(R),
53  jet_ptmin(jet_ptmin), jet_ptmax(jet_ptmax),
54  LeadPtMin(LeadPtMin), SubLeadPtMin(SubLeadPtMin),
55  max_track_rap (max_track_rap), PtConsLo (PtConsLo), PtConsHi (PtConsHi),
56  dPhiCut (dPhiCut),
57  pJAhi (0), pJAlo(0), pOtherJAlo(0)
58 {
59  // derived rapidity cuts
60  // ---------------------
61  max_rap = max_track_rap-R;
62  ghost_maxrap = max_rap + 2.0 * R;
63 
64  // Constituent selectors
65  // ---------------------
67  select_lopt = fastjet::SelectorPtMin( PtConsLo );
68  select_hipt = fastjet::SelectorPtMin( PtConsHi );
69 
70  // Provide but turn off charge selector
71  // fastjet::Selector select_track_charge= SelectorChargeRange( -3, 3);
72  fastjet::Selector select_track_charge= fastjet::SelectorIdentity();
73  slo = select_track_rap * select_lopt * select_track_charge;
74  shi = select_track_rap * select_hipt * select_track_charge;
75 
76  // Jet candidate selectors
77  // -----------------------
82 
83  // Choose a jet and area definition
84  // --------------------------------
85  jet_def = fastjet::JetDefinition(fastjet::antikt_algorithm, R);
86 
87  // create an area definition for the clustering
88  //----------------------------------------------------------
89  // ghosts should go up to the acceptance of the detector or
90  // (with infinite acceptance) at least 2R beyond the region
91  // where you plan to investigate jets.
93  // // DEBUG
94  // // area_spec.set_grid_scatter(0);
95  // // area_spec.set_pt_scatter(0);
96  area_def = fastjet::AreaDefinition(fastjet::active_area_explicit_ghosts, area_spec);
97 
98  // DEBUG
99  // area_spec = fastjet::VoronoiAreaSpec( 0.9 );
100  // area_def = fastjet::AreaDefinition( fastjet::VoronoiAreaSpec( 0.9 ) );
101 
102  std::cout << " ################################################### " << std::endl;
103  std::cout << "Leading jet above " << LeadPtMin << std::endl;
104  std::cout << "Sub-Leading jet above " << SubLeadPtMin << std::endl;
105  std::cout << "Clustered with " << jet_def.description() << std::endl;
106  std::cout << "Area Spec " << area_spec.description() << std::endl;
107  std::cout << "Area Def " << area_def.description() << std::endl;
108  std::cout << " ################################################### " << std::endl;
109 
110  // std::cout << slo.applies_jet_by_jet() << std::endl;
111  // std::cout << shi.applies_jet_by_jet() << std::endl;
112  // std::cout << sjet.applies_jet_by_jet() << std::endl;
113  // std::cout << " ################################################### " << std::endl;
114 
115 }
116 
117 /*
118  * Empty destructor
119  */
121 {
122 }
123 
124 /*
125  * Initialize module
126  */
128 {
129  cout << "------PHAJMaker::Init(PHCompositeNode*)------" << endl;
130 
131  // Histo Manager
132  // -------------
133  MyHistos = new Fun4AllHistoManager("MyHistos");
134  MyHistos->setOutfileName( "AjHistos.root");
137 
138  // Histos
139  // ------
140  TH1::SetDefaultSumw2(true);
141  TH2::SetDefaultSumw2(true);
142  TH3::SetDefaultSumw2(true);
143 
144  UnmatchedAJ_hi = new TH2D( "UnmatchedAJ_hi","Unmatched A_{J} for hard constituent jets;A_{J};Refmult;fraction", 40, -0.3, 0.9, 800, -0.5, 799.5 );
145  AJ_hi = new TH2D( "AJ_hi","A_{J} for hard constituent jets;A_{J};Refmult;fraction", 40, -0.3, 0.9, 800, -0.5, 799.5 );
146  AJ_lo = new TH2D( "AJ_lo","A_{J} for soft constituent jets;A_{J};Refmult;fraction", 40, -0.3, 0.9, 800, -0.5, 799.5 );
147 
151 
152  return 0;
153 }
154 
155 /*
156  * Process event
157  */
159 {
160  cout << "------PHAJMaker::process_event(PHCompositeNode*)------" << endl;
161 
162  //-------------------------------------------------
163  // Get Information from Node Tree
164  //-------------------------------------------------
165  PJContainer* particlesCont = findNode::getClass<PJContainer> (topNode,"PJ");
166  std::vector<fastjet::PseudoJet>& particles = particlesCont->data;
167 
168  // Classifier, such as Centrality.
169  double EventClassifier=0;
170 
171  // We want to hold onto the jetanalyzer objects, so they're created dynamically
172  // Need to delete them by hand
173  if (pJAhi){ delete pJAhi; pJAhi=0; }
174  if (pJAlo){ delete pJAlo; pJAlo=0; }
175  if ( pOtherJAlo ){ delete pOtherJAlo; pOtherJAlo=0; }
176 
177 
178  DiJetsHi.clear();
179  DiJetsLo.clear();
180  OtherDiJetsLo.clear();
181 
182  pLo.clear();
183  pHi.clear();
184 
185  Has10Gev=false;
186 
187  // Select particles to perform analysis on
188  // ---------------------------------------
189  pLo = slo( particles );
190  pHi = shi( particles );
191 
192  // Background selector
193  // -------------------
194  // It is unclear to me why, but it leads to segfaults if only a once-initialized member :-/
195  fastjet::Selector selector_bkgd = fastjet::SelectorAbsRapMax( max_rap ) * (!fastjet::SelectorNHardest(2));
196  // selector_bkgd=fastjet::SelectorAbsRapMax( max_rap );
197 
198  // find high constituent pT jets
199  // -----------------------------
200  pJAhi = new JetAnalyzer( pHi, jet_def ); // NO background subtraction
201  JetAnalyzer& JAhi = *pJAhi;
202  // std::cout << 0 << std::endl;
203  JAhiResult = fastjet::sorted_by_pt( sjet ( JAhi.inclusive_jets() ) );
204  // std::cout << 1 << std::endl;
205 
206 
207  // DEBUG
208  // -----
209  cout << " -------------------------------------------------------------------- " << endl;
210  cout << "particles.size() = " << particles.size() << endl;
211  cout << "pLo.size() = " << pLo.size() << endl;
212  cout << "pHi.size() = " << pHi.size() << endl;
213  cout << "JAhiResult.size() = " << JAhiResult.size() << endl;
214  for ( unsigned int i=0; i<JAhiResult.size() ; ++i ){
215  cout << "JAhiResult.at(" << i<< ").pT() = " << JAhiResult.at(i).pt() << endl;
216  }
217  cout << " -------------------------------------------------------------------- " << endl;
218 
219 
220  if ( JAhiResult.size() < 1 ) { return 0; }
221  if ( JAhiResult.at(0).pt() > 10 ) { Has10Gev=true; }
222 
223  if ( JAhiResult.size() < 2 ) { return 0; }
224  if ( JAhiResult.at(0).pt() < LeadPtMin ) { return 0; }
225  if ( JAhiResult.at(1).pt() < SubLeadPtMin ) { return 0; }
226 
227  // back to back? Answer this question with a selector
228  // ---------------------------------------------------
230  if ( DiJetsHi.size() == 0 ) {
231  // std::cout << " NO dijet found" << std::endl;
232  return 0;
233  }
234  assert ( DiJetsHi.size() == 2 && "SelectorDijets returned impossible number of Dijets." );
235 
236  // // FOR EMBEDDING: At least one matched to the reference jet?
237  // // ---------------------------------------------------------
238  // if ( ToMatch ){
239  // if ( !IsMatched( DiJetsHi, *ToMatch, R ) ) return 0;
240  // }
241 
242  // Calculate Aj and fill histos -- for unmatched high constituent pT di-jets
243  // -------------------------------------------------------------------------
244  UnmatchedAJ_hi->Fill ( CalcAj( DiJetsHi ), EventClassifier );
245 
246  // find corresponding jets with soft constituents
247  // ----------------------------------------------
248  pJAlo = new JetAnalyzer( pLo, jet_def, area_def, selector_bkgd ); // WITH background subtraction
249  JetAnalyzer& JAlo = *pJAlo;
250  fastjet::Subtractor* BackgroundSubtractor = JAlo.GetBackgroundSubtractor();
251  JAloResult = fastjet::sorted_by_pt( (*BackgroundSubtractor)( JAlo.inclusive_jets() ) );
252 
253  // Using selectors mostly because I can :)
254  fastjet::Selector SelectClose = fastjet::SelectorCircle( R );
255 
256  // Leading:
257  SelectClose.set_reference( DiJetsHi.at(0) );
258  // Pulling apart this one-liner, DiJetsLo.push_back ( ((SelectClose && fastjet::SelectorNHardest(1)) ( JAloResult )).at(0));
259  // More readable and we can catch abnormalities
260  std::vector<fastjet::PseudoJet> MatchedToLead = sorted_by_pt(SelectClose( JAloResult ));
261  if ( MatchedToLead.size() == 0 ) {
262  std::cerr << "PROBLEM: SelectorClose returned no match to leading jet." << std::endl;
263  // return 2;
264  return 0;
265  }
266  DiJetsLo.push_back ( MatchedToLead.at(0) );
267 
268  SelectClose.set_reference( DiJetsHi.at(1) );
269  std::vector<fastjet::PseudoJet> MatchedToSubLead = sorted_by_pt(SelectClose( JAloResult ));
270  if ( MatchedToSubLead.size() == 0 ) {
271  std::cerr << "PROBLEM: SelectorClose returned no match to sub-leading jet." << std::endl;
272  // return 2;
273  return 0;
274  }
275  DiJetsLo.push_back ( MatchedToSubLead.at(0) );
276 
277  if ( fabs(DiJetsLo.at(0).eta())>max_rap ) std:: cerr << "Uh-oh... Lead jet eta = " << DiJetsLo.at(0).eta() << std::endl;
278  if ( fabs(DiJetsLo.at(1).eta())>max_rap ) std:: cerr << "Uh-oh... SubLead jet eta = " << DiJetsLo.at(1).eta() << std::endl;
279 
280  // And we're done! Calculate A_J
281  // -----------------------------
282  AJ_hi->Fill( CalcAj( DiJetsHi ), EventClassifier );
283  AJ_lo->Fill( CalcAj( DiJetsLo ), EventClassifier );
284 
285  // DEBUG
286  // -----
287  cout << " -------------------------------------------------------------------- " << endl;
288  cout << "DiJetsHi.at(0).pT() = " << DiJetsHi.at(0).pt() << endl;
289  cout << "DiJetsHi.at(1).pT() = " << DiJetsHi.at(1).pt() << endl;
290  cout << "AJ, hi: " << CalcAj( DiJetsHi ) << endl;
291  cout << "DiJetsLo.at(0).pT() = " << DiJetsLo.at(0).pt() << endl;
292  cout << "DiJetsLo.at(1).pT() = " << DiJetsLo.at(1).pt() << endl;
293  cout << "AJ, lo: " << CalcAj( DiJetsLo ) << endl;
294  cout << " -------------------------------------------------------------------- " << endl;
295 
296 
297 
298  return 0;
299 }
300 
301 /*
302  * Write jets to node tree
303  */
304 /*
305 todo - we are working on a jet object
306 void PHAJMaker::save_jets_to_nodetree()
307 {
308  flow_jet_container = new PHPyJetContainerV2();
309 }
310 */