JHUGen MELA  v2.4.1
Matrix element calculations as used in JHUGen. MELA is an important tool that was used for the Higgs boson discovery and for precise measurements of its structure and interactions. Please see the website https://spin.pha.jhu.edu/ and papers cited there for more details, and kindly cite those papers when using this code.
PDGHelpers.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include "PDGHelpers.h"
3 #include "MELAStreamHelpers.hh"
4 
5 
8 
9 
10 namespace PDGHelpers{
12 }
13 
14 bool PDGHelpers::isAKnownJet(const int id){
15  if (PDGHelpers::isAQuark(id) || PDGHelpers::isAGluon(id)) return true;
16  else return false;
17 }
18 bool PDGHelpers::isAJet(const int id){
19  if (PDGHelpers::isAnUnknownJet(id) || PDGHelpers::isAQuark(id) || PDGHelpers::isAGluon(id)) return true;
20  else return false;
21 }
22 bool PDGHelpers::isAnUnknownJet(const int id){
23  if (id==0) return true;
24  else return false;
25 }
26 bool PDGHelpers::isInvalid(const int id){
27  if (id==-9000) return true;
28  else return false;
29 }
30 bool PDGHelpers::isALightQuark(const int id){
31  const int abs_id = std::abs(id);
32  if (abs_id<=5 && abs_id>0) return true;
33  else return false;
34 }
35 bool PDGHelpers::isAQuark(const int id){
36  const int abs_id = std::abs(id);
37  if (abs_id<=6 && abs_id>0) return true;
38  else return false;
39 }
40 bool PDGHelpers::isUpTypeQuark(const int id){
41  const int abs_id = std::abs(id);
42  if (abs_id==2 || abs_id==4 || abs_id==6) return true;
43  else return false;
44 }
45 bool PDGHelpers::isDownTypeQuark(const int id){
46  const int abs_id = std::abs(id);
47  if (abs_id==1 || abs_id==3 || abs_id==5) return true;
48  else return false;
49 }
50 bool PDGHelpers::isATopQuark(const int id){
51  if (std::abs(id)==6) return true;
52  else return false;
53 }
54 bool PDGHelpers::isATauLepton(const int id){
55  if (std::abs(id)==15) return true;
56  else return false;
57 }
58 bool PDGHelpers::isAGluon(const int id){
59  if (std::abs(id)==21) return true;
60  else return false;
61 }
62 bool PDGHelpers::isALepton(const int id){
63  const int abs_id = std::abs(id);
64  if (abs_id==11 || abs_id==13 || abs_id==15) return true;
65  else return false;
66 }
67 bool PDGHelpers::isANeutrino(const int id){
68  const int abs_id = std::abs(id);
69  if (abs_id==12 || abs_id==14 || abs_id==16) return true;
70  else return false;
71 }
72 bool PDGHelpers::isAPhoton(const int id){
73  if (std::abs(id)==22) return true;
74  else return false;
75 }
76 bool PDGHelpers::isAZBoson(const int id){
77  if (std::abs(id)==23) return true;
78  else return false;
79 }
80 bool PDGHelpers::isAWBoson(const int id){
81  if (std::abs(id)==24) return true;
82  else return false;
83 }
84 bool PDGHelpers::isAHiggs(const int id){
85  if (std::abs(id)==25) return true;
86  else return false;
87 }
89  const std::vector<int>& idlist,
90  const std::vector<bool(*)(const int)>& testlist,
91  std::vector<int>& ordering,
92  bool allowUnknown
93  ){
94  ordering.clear();
95  if (testlist.size() != idlist.size()){ MELAerr << "PDGHelpers::orderParticles: List of ids and list of their tests do not have the same size!" << std::endl; return; }
96  for (std::vector<bool(*)(const int)>::const_iterator it_test=testlist.cbegin(); it_test!=testlist.cend(); it_test++){
97  bool testFilled=false;
98  for (unsigned int ipart=0; ipart<idlist.size(); ipart++){
99  bool isAvailable=true;
100  for (int const& ord:ordering){
101  if (ord==(int)ipart){ isAvailable=false; break; }
102  }
103  if (!isAvailable) continue;
104  int tested = idlist.at(ipart);
105  if (PDGHelpers::isAnUnknownJet(tested)) continue;
106  if ((*it_test)(tested)){
107  ordering.push_back(tested);
108  testFilled=true;
109  }
110  }
111  if (!testFilled && allowUnknown){
112  for (unsigned int ipart=0; ipart<idlist.size(); ipart++){
113  bool isAvailable=true;
114  for (int const& ord:ordering){
115  if (ord==(int) ipart){ isAvailable=false; break; }
116  }
117  if (!isAvailable) continue;
118  int tested = idlist.at(ipart);
119  if (!PDGHelpers::isAnUnknownJet(tested)) continue;
120  if ((*it_test)(tested)){
121  ordering.push_back(tested);
122  testFilled=true;
123  }
124  }
125  }
126  if (!testFilled) break; // No need to try to order further, ordering is unsuccessful
127  }
128  if (idlist.size()!=ordering.size()) ordering.clear(); // This means not all particles were matched
129 }
131  const std::vector<int>& ids,
132  std::vector<std::vector<int>>& ordering,
133  bool* hasUnknownParticles
134  ){
135  ordering.clear();
136  if (hasUnknownParticles) *hasUnknownParticles=false;
137 
138  for (unsigned int ipart=0; ipart<ids.size(); ipart++){
139  int const& id_part = ids.at(ipart);
140  if (PDGHelpers::isAnUnknownJet(id_part)) continue; // Group them the last
141  bool grouped=false;
142  for (auto& ord:ordering){
143  if (ord.at(0)==id_part){ ord.push_back(ipart); grouped=true; break; }
144  }
145  if (!grouped){ std::vector<int> newgroup; newgroup.push_back(ipart); ordering.push_back(newgroup); }
146  }
147  bool firstUnknown=true;
148  for (unsigned int ipart=0; ipart<ids.size(); ipart++){
149  int const& id_part = ids.at(ipart);
150  if (!PDGHelpers::isAnUnknownJet(id_part)) continue; // Unknwon parton group
151  if (hasUnknownParticles!=0) *hasUnknownParticles=true;
152  if (firstUnknown){
153  std::vector<int> newgroup; newgroup.push_back(ipart); ordering.push_back(newgroup);
154  firstUnknown=false;
155  }
156  else ordering.at(ordering.size()-1).push_back(id_part);
157  }
158 }
160  const std::vector<int>& ids,
161  std::vector<std::pair<int, int>>& ordering,
162  bool allowUnknown
163  ){
164  ordering.clear();
165 
166  std::vector<std::vector<int>> grouping;
167  bool hasUnknown=false;
168  PDGHelpers::groupIdenticalParticles(ids, grouping, &hasUnknown);
169 
170  for (auto const& group:grouping){
171  unsigned int group_rep = group.at(0);
172  if (group_rep>=ids.size()){ MELAerr << "PDGHelpers::pairIdenticalParticles: Group " << group << " has a representative location >=ids.size (" << ids.size() << ")!" << std::endl; continue; }
173  int group_flag = ids.at(group_rep);
174  if (!PDGHelpers::isAnUnknownJet(group_flag)){ // Known particles first!
175  unsigned int npairs = group.size()/2;
176  bool isOdd=(group.size() % 2 == 1);
177  if (isOdd) npairs++;
178  for (unsigned int ip=0; ip<npairs; ip++){
179  if (isOdd && ip==npairs-1) ordering.push_back(std::pair<int, int>(group.at(2*ip), -1));
180  else ordering.push_back(std::pair<int, int>(group.at(2*ip), group.at(2*ip+1)));
181  }
182  }
183  }
184  if (allowUnknown){
185  for (auto const& group:grouping){
186  unsigned int group_rep = group.at(0);
187  if (group_rep>=ids.size()){ MELAerr << "PDGHelpers::pairIdenticalParticles: Group " << group << " has a representative location >=ids.size (" << ids.size() << ")!" << std::endl; continue; }
188  int group_flag = ids.at(group_rep);
189  if (!PDGHelpers::isAnUnknownJet(group_flag)) continue; // Unknown particles
190  // Now that we found the unknown particles group, loop over it
191  for (int const& pos:group){
192  bool paired=false;
193  // Check if there are unpaired particles left
194  for (auto& order:ordering){
195  if (order.second==-1 && PDGHelpers::isAJet(ids.at(order.first))){
196  order.second = pos;
197  paired=true;
198  break;
199  }
200  }
201  if (paired) continue;
202  // All pairs are filled, create a new pair
203  ordering.push_back(std::pair<int, int>(pos, -1)); // Since this is a new pair, the second position is yet to be filled.
204  }
205  }
206  }
207 }
208 bool PDGHelpers::allEquivalent(std::vector<int> const& ids, bool allowUnknown){
209  bool result=true;
210  bool hasNonJet=false;
211  for (std::vector<int>::const_iterator it_first=ids.cbegin(); it_first!=ids.cend(); it_first++){
212  int const& id_first = *it_first;
213  if (!PDGHelpers::isAJet(id_first)) hasNonJet=true;
214  if (allowUnknown && PDGHelpers::isAnUnknownJet(id_first)){
215  if (hasNonJet){ result = false; break; }
216  else continue;
217  }
218  for (std::vector<int>::const_iterator it_second=it_first; it_second!=ids.cend(); it_second++){
219  int const& id_second = *it_second;
220  if (allowUnknown && PDGHelpers::isAnUnknownJet(id_second)){
221  if (hasNonJet){ result = false; break; }
222  else continue;
223  }
224  if (id_first!=id_second){ result = false; break; }
225  }
226  if (!result) break;
227  }
228  return result;
229 }
230 
231 
233 
234 // Test everything in outgoing conventions, do not pass ud or uu for example, pass outgoing u,-(incoming d) or outgoing u,-(incoming u)
235 int PDGHelpers::getCoupledVertex(const int idfirst, const int idsecond, int* hel, int* useAHcoupl){
236  int ids[2]={ idfirst, idsecond };
237  int ids_jhu[2]={ -9000, -9000 };
238  for (unsigned int ip=0; ip<2; ip++){ if (!PDGHelpers::isInvalid(ids[ip])) ids_jhu[ip] = convertLHEreverse(&(ids[ip])); }
239  int zahswitch=0;
240  if (useAHcoupl) zahswitch = *useAHcoupl;
241  // Left-handed couplings always exist; right handed ones may or may not exist. This is why the default below is -1 for left-handed.
242  // Example: Z->nu nub does not have Z->nu_R nub_L counterpart because nu_R or nub_L do not exist!
243  int heleff=-1;
244  if (hel) heleff = *hel;
245  int Vid_jhu = CoupledVertex(ids_jhu, &heleff, &zahswitch);
246  return convertLHE(&Vid_jhu);
247 }
249  if (pSt==0) return 1;
250  else if (pSt==1 || pSt==23) return 1;
251  else if (pSt==21) return -1;
252  else if (pSt==22 || pSt==62) return 2;
253  else{
254  MELAerr << "Unknown Pythia particle status: " << pSt << std::endl;
255  return -99;
256  }
257 }
PDGHelpers::isALepton
bool isALepton(const int id)
Definition: PDGHelpers.cc:62
PDGHelpers::allEquivalent
bool allEquivalent(std::vector< int > const &ids, bool allowUnknown=false)
Definition: PDGHelpers.cc:208
PDGHelpers::HDecayMode
TVar::CandidateDecayMode HDecayMode
Definition: PDGHelpers.cc:11
convertLHE
#define convertLHE
Definition: TModParameters.hh:16
PDGHelpers::isInvalid
bool isInvalid(const int id)
Definition: PDGHelpers.cc:26
TVar::CandidateDecay_ZZ
@ CandidateDecay_ZZ
Definition: TVar.hh:41
PDGHelpers
Definition: PDGHelpers.h:12
TVar::CandidateDecayMode
CandidateDecayMode
Definition: TVar.hh:37
PDGHelpers::isAHiggs
bool isAHiggs(const int id)
Definition: PDGHelpers.cc:84
PDGHelpers::isAZBoson
bool isAZBoson(const int id)
Definition: PDGHelpers.cc:76
PDGHelpers::isAnUnknownJet
bool isAnUnknownJet(const int id)
Definition: PDGHelpers.cc:22
PDGHelpers::isAQuark
bool isAQuark(const int id)
Definition: PDGHelpers.cc:35
PDGHelpers::isANeutrino
bool isANeutrino(const int id)
Definition: PDGHelpers.cc:67
PDGHelpers::isAPhoton
bool isAPhoton(const int id)
Definition: PDGHelpers.cc:72
MELAStreamHelpers::MELAout
MELAOutputStreamer MELAout
PDGHelpers::isDownTypeQuark
bool isDownTypeQuark(const int id)
Definition: PDGHelpers.cc:45
PDGHelpers::isATopQuark
bool isATopQuark(const int id)
Definition: PDGHelpers.cc:50
PDGHelpers::getCoupledVertex
int getCoupledVertex(const int idfirst, const int idsecond, int *hel=0, int *useAHcoupl=0)
Definition: PDGHelpers.cc:235
PDGHelpers::isAWBoson
bool isAWBoson(const int id)
Definition: PDGHelpers.cc:80
PDGHelpers::isAKnownJet
bool isAKnownJet(const int id)
Definition: PDGHelpers.cc:14
PDGHelpers::setCandidateDecayMode
void setCandidateDecayMode(TVar::CandidateDecayMode mode)
Definition: PDGHelpers.cc:232
PDGHelpers::convertPythiaStatus
int convertPythiaStatus(int pSt)
Definition: PDGHelpers.cc:248
PDGHelpers::orderParticles
void orderParticles(const std::vector< int > &idlist, const std::vector< bool(*)(const int)> &testlist, std::vector< int > &ordering, bool allowUnknown=false)
Definition: PDGHelpers.cc:88
PDGHelpers::groupIdenticalParticles
void groupIdenticalParticles(const std::vector< int > &ids, std::vector< std::vector< int >> &ordering, bool *hasUnknownParticles=0)
Definition: PDGHelpers.cc:130
MELAStreamHelpers::MELAerr
MELAOutputStreamer MELAerr
convertLHEreverse
#define convertLHEreverse
Definition: TModParameters.hh:12
PDGHelpers::pairIdenticalParticles
void pairIdenticalParticles(const std::vector< int > &ids, std::vector< std::pair< int, int >> &ordering, bool allowUnknown=false)
Definition: PDGHelpers.cc:159
PDGHelpers::isAGluon
bool isAGluon(const int id)
Definition: PDGHelpers.cc:58
PDGHelpers.h
MELAStreamHelpers.hh
CoupledVertex
#define CoupledVertex
Definition: TModParameters.hh:19
PDGHelpers::isATauLepton
bool isATauLepton(const int id)
Definition: PDGHelpers.cc:54
PDGHelpers::isUpTypeQuark
bool isUpTypeQuark(const int id)
Definition: PDGHelpers.cc:40
PDGHelpers::isAJet
bool isAJet(const int id)
Definition: PDGHelpers.cc:18
PDGHelpers::isALightQuark
bool isALightQuark(const int id)
Definition: PDGHelpers.cc:30