From 912868a4818df64cc24921d8c1b627f3e6486e11 Mon Sep 17 00:00:00 2001
From: komm <unknown>
Date: Mon, 25 Feb 2013 15:56:49 +0100
Subject: [PATCH] improve decay tree & configuration

---
 Pythia8Generator.cpp | 161 +++++++++++++++++++++++--------------------
 1 file changed, 85 insertions(+), 76 deletions(-)

diff --git a/Pythia8Generator.cpp b/Pythia8Generator.cpp
index c04a9c2..1d25799 100644
--- a/Pythia8Generator.cpp
+++ b/Pythia8Generator.cpp
@@ -34,12 +34,13 @@ private:
 
     std::vector<std::string> mode;
     std::vector<std::string> colliding_particles;
+    std::vector<std::string> configList;
 
 
     enum StoredParticles {
-    	ALL,
-    	ALL_STABLE,
-    	HARD_PROCESS
+        ALL,
+        ALL_STABLE,
+        HARD_PROCESS
     };
     StoredParticles storedParticles;
 
@@ -61,18 +62,25 @@ public:
         
         Pythia8Generator(): Module()
         {
-        	colliding_particles.push_back("proton");
-        	colliding_particles.push_back("anti proton");
-        	colliding_particles.push_back("electron");
-        	colliding_particles.push_back("anti electron");
-        	colliding_particles.push_back("muon");
-        	colliding_particles.push_back("anti muon");
-        	colliding_particles.push_back("proton");
-
-        	mode.push_back("only hard process");
-        	mode.push_back("all stable");
-        	mode.push_back("all");
-        	mode.push_back("all");
+            colliding_particles.push_back("proton");
+            colliding_particles.push_back("anti proton");
+            colliding_particles.push_back("electron");
+            colliding_particles.push_back("anti electron");
+            colliding_particles.push_back("muon");
+            colliding_particles.push_back("anti muon");
+            colliding_particles.push_back("proton");
+
+            configList.push_back("WeakZ0:gmZmode=2");
+            configList.push_back("WeakBosonExchange:all=on");
+            configList.push_back("WeakSingleBoson:all=on");
+            configList.push_back("WeakBosonAndParton:all=on");
+            configList.push_back("PhaseSpace:mHatMin=50");
+            configList.push_back("PhaseSpace:mHatMax=150");
+
+            mode.push_back("only hard process");
+            mode.push_back("all stable");
+            mode.push_back("all");
+            mode.push_back("all");
             addSource("out","");
             addOption("seed","",(int64_t)123);
             addOption("number"," ",(int64_t)10);
@@ -81,43 +89,44 @@ public:
             addOption("center mass energy","",200.0);
             addOption("eventview name","the name of the eventview","Generated");
             addOption("stored particles","the particles which are stored into a new eventview with the given name",mode,pxl::OptionDescription::USAGE_TEXT_SELECTION);
+            addOption("config strings","",configList);
             running = true;
         }
         
-		int64_t getParticleId(std::string name)
-		{
-			if (name=="proton") {
-				return 2212;
-			}
-			if (name=="anti proton") {
-				return -2212;
-			}
-			if (name=="electron") {
-				return 11;
-			}
-			if (name=="anti electron") {
-				return -11;
-			}
-			if (name=="muon") {
-				return 13;
-			}
-			if (name=="anti muon") {
-				return -13;
-			}
-		}
-
-		StoredParticles getStoredParticles(std::string name)
-		{
-			if (name=="only hard process"){
-				return HARD_PROCESS;
-			}
-			if (name=="all stable"){
-				return ALL_STABLE;
-			}
-			if (name=="all"){
-				return ALL;
-			}
-		}
+        int64_t getParticleId(std::string name)
+        {
+            if (name=="proton") {
+                return 2212;
+            }
+            if (name=="anti proton") {
+                return -2212;
+            }
+            if (name=="electron") {
+                return 11;
+            }
+            if (name=="anti electron") {
+                return -11;
+            }
+            if (name=="muon") {
+                return 13;
+            }
+            if (name=="anti muon") {
+                return -13;
+            }
+        }
+
+        StoredParticles getStoredParticles(std::string name)
+        {
+            if (name=="only hard process"){
+                return HARD_PROCESS;
+            }
+            if (name=="all stable"){
+                return ALL_STABLE;
+            }
+            if (name=="all"){
+                return ALL;
+            }
+        }
 
         ~Pythia8Generator()
         {
@@ -126,15 +135,13 @@ public:
         void beginJob() 
         {
             getOption("number",numberOfObjects);
-			getOption("seed",seed);
+            getOption("seed",seed);
             pythia8.readString("Random:setSeed = on");
             pythia8.readString("Random:seed = "+seed);
-            pythia8.readString("WeakZ0:gmZmode=2");
-            pythia8.readString("WeakBosonExchange:all=on");
-            pythia8.readString("WeakSingleBoson:all=on");
-            pythia8.readString("WeakBosonAndParton:all=on");
-            pythia8.readString("PhaseSpace:mHatMin=50");
-            pythia8.readString("PhaseSpace:mHatMax=150");
+            getOption("config strings",configList);
+            for (int cnt=0; cnt<configList.size(); ++cnt ){
+                pythia8.readString(configList[cnt]);
+            }
             getOption("colliding particle 1",coll_particle1);
             getOption("colliding particle 2",coll_particle2);
             getOption("center mass energy",cme);
@@ -173,11 +180,11 @@ public:
                     	accepted=(fabs(status)>=21 and fabs(status)<=29);
                     }
                     if (storedParticles==ALL_STABLE) {
-						accepted=particle.isFinal();
-					}
+                        accepted=particle.isFinal();
+                    }
                     if (storedParticles==ALL) {
-						accepted=true;
-					}
+                        accepted=true;
+                    }
                     if (accepted)
                     {
                         pxl::Particle* pxl_part = new pxl::Particle();
@@ -192,22 +199,13 @@ public:
                         idMap[cnt]=pxl_part;
                     }
                 }
-                map<int, pxl::Particle*>::iterator it;
-                for (int cnt=0; cnt<num;++cnt) {
-                    Pythia8::Particle particle = pEvent[cnt];
-                    if (idMap.find(cnt)!=idMap.end()) {
-                        
-                        int mother1ID = particle.mother1();
-                        if (mother1ID>0) {
-                            if (idMap.find(mother1ID)!=idMap.end()) {
-                                (idMap[mother1ID])->linkDaughter(idMap[cnt]);
-                            }
-                        }
-                        int mother2ID = particle.mother2();
-                        if (mother2ID>0) {
-                            if (idMap.find(mother2ID)!=idMap.end()) {
-                                (idMap[mother2ID])->linkDaughter(idMap[cnt]);
-                            }
+                if ((storedParticles==ALL) || (storedParticles==HARD_PROCESS)) {
+                    for (int cnt=0; cnt<num;++cnt) {
+                        if (idMap.find(cnt)!=idMap.end()) {
+                            int mother1ID = pEvent[cnt].mother1();
+                            linkMother(cnt,mother1ID,idMap,pEvent);
+                            int mother2ID = pEvent[cnt].mother2();
+                            linkMother(cnt,mother2ID,idMap,pEvent);
                         }
                     }
                 }
@@ -219,6 +217,17 @@ public:
             return false;
         }
         
+        void linkMother(int daugtherID, int motherID, map<int, pxl::Particle*> selectedParticles, Pythia8::Event pEvent) {
+            if (motherID>0) {
+                if (selectedParticles.find(motherID)!=selectedParticles.end()) {
+                    (selectedParticles[motherID])->linkDaughter(selectedParticles[daugtherID]);
+                } else  {
+                    linkMother(daugtherID, pEvent[motherID].mother1(), selectedParticles, pEvent);
+                    linkMother(daugtherID, pEvent[motherID].mother2(), selectedParticles, pEvent);
+                }
+            }
+        }
+
         void endRun()
         {
         }
-- 
GitLab