StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
FastJetFilter.cxx
1 #include "FastJetFilter.h"
2 
3 #include "StarGenerator/EVENT/StarGenEvent.h"
4 #include "StarGenerator/EVENT/StarGenParticle.h"
5 
6 // Defining a User Class to store PID info for particles used as input to FastJet
7 class MyParticleId : public fastjet::PseudoJet::UserInfoBase{
8  public:
9  MyParticleId(const int & pdg_id_in, const int & part_id_in) : _pdg_id(pdg_id_in), _part_id(part_id_in){}
10 
11  int pid() const{
12  return _pdg_id;
13  }
14  int partn() const{
15  return _part_id;
16  }
17  private:
18  int _pdg_id;
19  int _part_id;
20 };
21 
22 
23 // function to calculate invariant mass of a pair of objects
24 //___________________________________________________________________________________________
25 Double_t Mass(Double_t m1, Double_t m2, Double_t E1, Double_t E2, Double_t px1, Double_t px2, Double_t py1, Double_t py2, Double_t pz1, Double_t pz2) {
26  Double_t m;
27  m = TMath::Sqrt(pow(m1,2) + pow(m2,2) + 2*(E1*E2 - px1*px2 - py1*py2 - pz1*pz2));
28 
29  return m;
30 }
31 
32 Double_t standardPhi(Double_t phi){
33  Double_t phi_standard = phi;
34  if (phi_standard < 0) phi_standard+=2*(TMath::Pi()); //FIXME
35  if (phi_standard < 0) cout << "Something wrong with angle!" << endl;
36  return phi_standard;
37 }
38 
39 // This function is to count the number of events in the vertex file.
40 int countlines(const char* VertexFileName = "./VERTEXFULL/st_physics_15094070_raw_0000007.txt"){
41  int numberoflines = 0;
42  std::string line;
43  std::ifstream file(VertexFileName, ios::in);
44 
45  while (std::getline(file, line))
46  ++numberoflines;
47 
48  return numberoflines;
49 }
50 
51 //______________________________________________________________________________________________
52 FastJetFilter::FastJetFilter( const char* name ) : StarFilterMaker(name)
53 {
54 
55  SetAttr("algorithm","antikt");
56  SetAttr("radius", 0.4 );
57 
58 }
59 //______________________________________________________________________________________________
60 void FastJetFilter::AddTrigger( int id, double mnpt, double mxpt, double mneta, double mxeta, int idm )
61 {
62  mTriggers.push_back( Trigger_t( id, mnpt, mxpt, mneta, mxeta, idm ) );
63 }
64 //______________________________________________________________________________________________
65 int FastJetFilter::Init() {
66 
67  TString algo = SAttr("algorithm"); algo.ToLower();
68 
69  if ( algo == "kt" ) algorithm = fastjet::kt_algorithm;
70  else if ( algo == "cambridge" ) algorithm = fastjet::cambridge_algorithm;
71  else algorithm = fastjet::antikt_algorithm;
72 
73  double R = DAttr("radius"); assert(R>0);
74 
75  jetdefinition = new fastjet::JetDefinition(algorithm, R, recombScheme, strategy);
76 
77 }
78 //______________________________________________________________________________________________
80 {
81  // Get a reference to the current event
82  StarGenEvent& event = (_event)? *_event : *mEvent;
83 
84  // Defining Vectors for FastJet inputs
85  std::vector <fastjet::PseudoJet> fjInputs; // Will store px, py, pz, E info
86 
87  int npart = event.GetNumberOfParticles();
88 
89  // Ensure a D0 is w/in our acceptance
90  bool go = false;
91  for ( int ipart=1 /*skip header*/;
92  ipart<npart;
93  ipart++ )
94  {
95  StarGenParticle *part = event[ipart];
96  if ( part->GetStatus() != StarGenParticle::kFinal ) continue; // Must be a final state particle
97 
98  // part->Print();
99 
100  TLorentzVector momentum = part->momentum();
101  double pT = momentum.Perp();
102  double eta = momentum.Eta();
103 
104  // Make sure we're looking at something with no color
105  if ( TMath::Abs(part->GetId()) != 421 ) continue;
106  if ( pT < 0.200 || TMath::Abs(eta) > 1 ) continue;
107 
108  go = true;
109  break;
110 
111  }
112 
113  // if ( false == go ) LOG_INFO << "No candidate D0, reject event" << endm;
114 
115 
116  if ( false == go ) return StarGenEvent::kReject;
117 
118 
119 
120  for ( int ipart=1 /*skip header*/;
121  ipart<npart;
122  ipart++ )
123  {
124  StarGenParticle *part = event[ipart];
125 
126  // Make sure we're looking at something with no color
127  if ( TMath::Abs(part->GetId()) < 10 ) continue;
128 
129  if ( part->GetStatus() != StarGenParticle::kFinal ) continue; // Must be a final state particle
130 
131  TLorentzVector momentum = part->momentum();
132  double pT = momentum.Perp();
133  if ( pT < 0.05 ) continue;
134  double eta = momentum.Eta();
135  if ( pT < 0.20 || TMath::Abs(eta) > 1 ) continue;
136 
137  fastjet::PseudoJet pseudoJet(momentum[0], momentum[1], momentum[2], momentum[3]);
138  pseudoJet.set_user_info( new MyParticleId( part->GetId(), ipart ) ); // correspondance between PDG and line number
139 
140  fjInputs.push_back(pseudoJet);
141 
142  }
143 
144  vector <fastjet::PseudoJet> inclusiveJets, sortedJets, selectedJets;
145  fastjet::ClusterSequence clustSeq(fjInputs, *jetdefinition);
146 
147  // Extract Inclusive Jets sorted by pT
148  inclusiveJets = clustSeq.inclusive_jets(3.); //Only jets with pT > 3 GeV/c are selected
149  sortedJets = sorted_by_pt(inclusiveJets);
150 
151  LOG_INFO << "Inclusive jets size = " << inclusiveJets.size() << endm;
152  LOG_INFO << "Sorted jets size = " << sortedJets.size() << endm;
153 
154  fastjet::Selector eta_selector = fastjet::SelectorEtaRange(-0.6, 0.6); // Selects jets with |eta| < 0.6
155  fastjet::Selector selector = eta_selector;
156  selectedJets = eta_selector(sortedJets);
157 
158  bool fInterestingEvent = kFALSE; //Event worth writing to the file
159 
160  LOG_INFO << "Looking for D0 jet in " << selectedJets.size() << " candidates" << endm;
161 
162  for(unsigned jetid = 0; jetid < selectedJets.size(); jetid++){
163 
164  // Loop over jet constituents to get some info
165  vector <fastjet::PseudoJet> constituents = selectedJets[jetid].constituents();
166  vector <fastjet::PseudoJet> sortedconstituents = sorted_by_pt(constituents);
167 
168  bool d0Jet = kFALSE;
169 
170  for (unsigned j = 0; j < sortedconstituents.size(); j++){
171  if (sortedconstituents[j].user_info<MyParticleId>().pid() == 421){
172  d0Jet = kTRUE;
173  }
174  if (d0Jet) break;
175  }
176 
177  if (d0Jet) {
178  fInterestingEvent = kTRUE;
179  }
180 
181  if (fInterestingEvent) {
182  LOG_INFO << "D0 jet found return kAccept! " << endm;
183  return StarGenEvent::kAccept;
184  }
185  }
186 
187  // LOG_INFO << "No D0 jet found, reject event" << endm;
188 
189  return StarGenEvent::kReject;
190 
191 }
int Filter(StarGenEvent *event=0)
Int_t GetNumberOfParticles()
Obtain the number of particles in the event record.
Definition: StarGenEvent.h:187
Yet another particle class.
Int_t GetStatus()
Get the status code of the particle according to the HEPEVT standard.
Int_t GetId()
Get the id code of the particle according to the PDG standard.
Main filter class. Goes anywhere in the chain, filters StarGenEvent objects.
TLorentzVector momentum()
Return the 4-momentum of the particle.
Base class for event records.
Definition: StarGenEvent.h:81
void AddTrigger(int _pdgid, double _ptmn=0, double _ptmx=-1, double _etamn=-1, double _etamx=1, int _pdgidParent=0)