11 #include "Pythia8/ColourTracing.h"
23 bool ColourTracing::setupColList(
Event& event) {
27 iColAndAcol.resize(0);
28 for (
int i = 0; i <
event.size(); ++i)
29 if (event[i].isFinal()) {
30 if (event[i].col() > 0 &&
event[i].acol() > 0) iColAndAcol.push_back(i);
31 else if (event[i].col() > 0) iColEnd.push_back(i);
32 else if (event[i].acol() > 0) iAcolEnd.push_back(i);
34 if (event[i].col() < 0) iAcolEnd.push_back(-i);
35 else if (event[i].acol() < 0) iColEnd.push_back(-i);
39 if (
int(iColEnd.size()) == 0 &&
int(iAcolEnd.size()) == 0 &&
40 int(iColAndAcol.size()) == 0)
return true;
49 bool ColourTracing::traceFromAcol(
int indxCol,
Event& event,
int iJun,
50 int iCol, vector<int>& iParton) {
53 int kindJun = (iJun >= 0) ? event.kindJunction(iJun) : 0;
57 int loopMax = iColAndAcol.size() + 2;
58 bool hasFound =
false;
65 for (
int i = 0; i < int(iColEnd.size()); ++i) {
66 if (event[ abs(iColEnd[i]) ].col() == indxCol
67 ||
event[ abs(iColEnd[i]) ].acol() == -indxCol) {
68 iParton.push_back( abs(iColEnd[i]) );
70 iColEnd[i] = iColEnd.back();
79 for (
int i = 0; i < int(iColAndAcol.size()); ++i)
80 if (event[ iColAndAcol[i] ].col() == indxCol) {
81 iParton.push_back( iColAndAcol[i] );
83 indxCol =
event[ iColAndAcol[i] ].acol();
84 if (kindJun > 0)
event.endColJunction(iJun, iCol, indxCol);
85 iColAndAcol[i] = iColAndAcol.back();
86 iColAndAcol.pop_back();
93 for (
int iAntiJun = 0; iAntiJun <
event.sizeJunction(); ++iAntiJun)
94 if (iAntiJun != iJun && event.kindJunction(iAntiJun) % 2 == 0)
95 for (
int iColAnti = 0; iColAnti < 3; ++iColAnti)
96 if (event.endColJunction(iAntiJun, iColAnti) == indxCol) {
97 iParton.push_back( -(10 + 10 * iAntiJun + iColAnti) );
107 if (!hasFound && kindJun % 2 == 1 && event.sizeJunction() > 1)
108 for (
int iAntiJun = 0; iAntiJun <
event.sizeJunction(); ++iAntiJun)
109 if (iAntiJun != iJun && event.kindJunction(iAntiJun) % 2 == 0)
110 for (
int iColAnti = 0; iColAnti < 3; ++iColAnti)
111 if (event.endColJunction(iAntiJun, iColAnti) == indxCol) {
112 iParton.push_back( -(10 + 10 * iAntiJun + iColAnti) );
119 }
while (hasFound && indxCol > 0 && loop < loopMax);
122 if (!hasFound || loop == loopMax) {
123 infoPtr->errorMsg(
"Error in ColourTracing::traceFromAcol: "
124 "colour tracing failed");
137 bool ColourTracing::traceFromCol(
int indxCol,
Event& event,
int iJun,
138 int iCol, vector<int>& iParton) {
141 if (iJun < 0 && iCol < 0) {
142 int iColEndBack = iColEnd.back();
143 if (iColEndBack > 0) indxCol =
event[iColEnd.back()].col();
145 else indxCol = -
event[-iColEnd.back()].acol();
146 iParton.push_back(iColEnd.back());
151 int kindJun = (iJun >= 0) ? event.kindJunction(iJun) : 0;
155 int loopMax = iColAndAcol.size() + 2;
156 bool hasFound =
false;
163 for (
int i = 0; i < int(iAcolEnd.size()); ++i) {
164 if (event[ abs(iAcolEnd[i]) ].acol() == indxCol
165 ||
event[ abs(iAcolEnd[i]) ].col() == -indxCol) {
166 iParton.push_back( abs(iAcolEnd[i]) );
168 iAcolEnd[i] = iAcolEnd.back();
177 for (
int i = 0; i < int(iColAndAcol.size()); ++i)
178 if (event[ iColAndAcol[i] ].acol() == indxCol) {
179 iParton.push_back( iColAndAcol[i] );
182 indxCol =
event[ iColAndAcol[i] ].col();
183 if (kindJun > 0)
event.endColJunction(iJun, iCol, indxCol);
184 iColAndAcol[i] = iColAndAcol.back();
185 iColAndAcol.pop_back();
192 for (
int iAntiJun = 0; iAntiJun <
event.sizeJunction(); ++iAntiJun)
193 if (iAntiJun != iJun && event.kindJunction(iAntiJun) %2 == 1)
194 for (
int iColAnti = 0; iColAnti < 3; ++iColAnti)
195 if (event.endColJunction(iAntiJun, iColAnti) == indxCol) {
196 iParton.push_back( -(10 + 10 * iAntiJun + iColAnti) );
206 if (!hasFound && kindJun % 2 == 0 && event.sizeJunction() > 1)
207 for (
int iAntiJun = 0; iAntiJun <
event.sizeJunction(); ++iAntiJun)
208 if (iAntiJun != iJun && event.kindJunction(iAntiJun) %2 == 1)
209 for (
int iColAnti = 0; iColAnti < 3; ++iColAnti)
210 if (event.endColJunction(iAntiJun, iColAnti) == indxCol) {
211 iParton.push_back( -(10 + 10 * iAntiJun + iColAnti) );
218 }
while (hasFound && indxCol > 0 && loop < loopMax);
221 if (!hasFound || loop == loopMax) {
222 infoPtr->errorMsg(
"Error in ColourTracing::traceFromCol: "
223 "colour tracing failed");
236 bool ColourTracing::traceInLoop(
Event& event, vector<int>& iParton) {
239 iParton.push_back( iColAndAcol[0] );
240 int indxCol =
event[ iColAndAcol[0] ].col();
241 int indxAcol =
event[ iColAndAcol[0] ].acol();
242 iColAndAcol[0] = iColAndAcol.back();
243 iColAndAcol.pop_back();
247 int loopMax = iColAndAcol.size() + 2;
248 bool hasFound =
false;
254 for (
int i = 0; i < int(iColAndAcol.size()); ++i)
255 if (event[ iColAndAcol[i] ].acol() == indxCol) {
256 iParton.push_back( iColAndAcol[i] );
257 indxCol =
event[ iColAndAcol[i] ].col();
258 iColAndAcol[i] = iColAndAcol.back();
259 iColAndAcol.pop_back();
263 }
while (hasFound && indxCol != indxAcol && loop < loopMax);
266 if (!hasFound || loop == loopMax) {
267 infoPtr->errorMsg(
"Error in ColourTracing::traceInLoop: "
268 "colour tracing failed");
282 vector<vector<int > > ColourTracing::getJunChains(
Event& event) {
285 vector<vector<int> > junChains;
286 vector<bool> usedJuncs(event.sizeJunction(),
false);
289 for (
int i = 0; i <
event.sizeJunction(); ++i) {
292 std::list<int> curJun;
296 junList.push_back(i);
299 while (!curJun.empty()) {
300 for (
int iLeg = 0;iLeg < 3; ++iLeg)
301 for (
int j = 0;j <
event.sizeJunction(); ++j) {
304 for (
int jLeg = 0;jLeg < 3; ++jLeg) {
305 if (event.colJunction(curJun.front(),iLeg) ==
306 event.colJunction(j,jLeg)) {
308 junList.push_back(j);
316 junChains.push_back(junList);