00001
00002
00003 #include "Iguana/Inventor/interface/IgParticleChar.h"
00004 #include <iostream>
00005 #include <string>
00006 #include <algorithm>
00007
00008
00009
00010
00011
00012
00013
00014
00015 SbBool IgParticleChar::inited = FALSE;
00016 IgParticleChar::CMapToParticleList *IgParticleChar::particleList = NULL;
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 IgParticleChar::IgParticleChar (int g, int p, int isa, const char *nm, const char *lbl,
00027 float mas, float q)
00028 : geantCode (g),
00029 pythiaCode (p),
00030 isajetCode (isa),
00031 name (nm),
00032 label (lbl),
00033 mass (mas),
00034 charge (q)
00035 {
00036 std::pair< CMapToParticleList::iterator, bool > test;
00037 test = particleList->insert (CMapToParticleList::value_type (std::string (nm), this));
00038 if (!test.second)
00039 {
00040 std::cout << "IgParticleChar: error creating particle " << name.getString () << std::endl;
00041 }
00042 }
00043
00045 void
00046 IgParticleChar::setMaterial (SoMaterial* m)
00047 {
00048 particleMaterial = m;
00049 m->ref ();
00050 }
00051
00053 void
00054 IgParticleChar::setStyle (SoDrawStyle* s)
00055 {
00056 particleStyle = s;
00057 s->ref ();
00058 }
00059
00061 float
00062 IgParticleChar::getMass () const
00063 { return mass; }
00064
00066 float
00067 IgParticleChar::getCharge () const
00068 { return charge; }
00069
00071 const char *
00072 IgParticleChar::getName () const
00073 { return name.getString (); }
00074
00075 IgParticleChar::~IgParticleChar ()
00076 {
00077 particleMaterial->unref ();
00078 particleMaterial = NULL;
00079 particleStyle->unref ();
00080 particleStyle = NULL;
00081 }
00082
00084 void
00085 IgParticleChar::initParticles ()
00086 {
00087 if (inited)
00088 return;
00089
00090 inited = TRUE;
00091 particleList = new CMapToParticleList ();
00092 IgParticleChar* unknown = new IgParticleChar (-1, 0, 0, "unknown", "unk-", 1.0F, -1.0F);
00093 IgParticleChar* antiunknown = new IgParticleChar (-1, 0, 0, "antiunknown", "unk+", 1.0F, +1.0F);
00094 new IgParticleChar (-1, 0, 0, "neutralunknown", "unk0", 1.0F, +0.0F);
00095 IgParticleChar* electron = new IgParticleChar (3, 11, 12, "electron", "e-", 0.000510999F, -1.0F);
00096 IgParticleChar* positron = new IgParticleChar (2, -11, -12, "positron", "e+", 0.000510999F, +1.0F);
00097 IgParticleChar* muon = new IgParticleChar (6, 13, 14, "muon", "mu-", 0.105658F, -1.0F);
00098 IgParticleChar* antimuon = new IgParticleChar (5, -13, -14, "antimuon", "mu+", 0.105658F, +1.0F);
00099 IgParticleChar* proton = new IgParticleChar (14, 2212, 1120, "proton", "p", 0.9382723F, 1.0F);
00100 IgParticleChar* antiproton = new IgParticleChar (15, -2212, -1120, "antiproton", "pbar", 0.9382723F, -1.0F);
00101 new IgParticleChar (1, 22, 0, "gamma", "gamma", 0.0000E+00F, 0.0F);
00102 new IgParticleChar (4, 12, 11, "eneutrino", "eneu", 0.F, 0.0F);
00103 new IgParticleChar (4, 14, 13, "muneutrino", "muneu", 0.F, 0.0F);
00104 new IgParticleChar (4, 16, 15, "tauneutrino","tauneu", 0.F, 0.0F);
00105 new IgParticleChar (4, -12, -11, "antieneutrino","eneubar", 0.F, 0.0F);
00106 new IgParticleChar (4, -14, -13, "antimuneutrino","muneubar", 0.F, 0.0F);
00107 new IgParticleChar (4, -16, -15, "antitauneutrino","tauneubar", 0.F, 0.0F);
00108 new IgParticleChar (13, 2112, 1220, "neutron", "n", 0.939566F, 0.0F);
00109 new IgParticleChar (25, -2112, -1220, "antineutron", "nbar", 0.939566F, 0.0F);
00110 IgParticleChar* pion = new IgParticleChar (9, -211, -120, "pion", "pi-", 0.139567F, -1.0F);
00111 IgParticleChar* antipion = new IgParticleChar (8, 211, 120, "antipion", "pi+", 0.139567F, +1.0F);
00112 new IgParticleChar (45, 0, 0, "deuteron", "d", 1.875613F, 1.0F);
00113 new IgParticleChar (46, 0, 0, "tritium", "tritium", 2.80925F, 1.0F);
00114 new IgParticleChar (47, 0, 0, "alpha", "alpha", 3.727417F, 2.0F);
00115 new IgParticleChar (49, 0, 0, "he3", "he3", 2.80923F, 2.0F);
00116 IgParticleChar* kplus = new IgParticleChar (11, 321, 130, "kplus", "k+", 0.493677F, +1.0F);
00117 IgParticleChar* kminus = new IgParticleChar (12, -321, -130, "kminus", "k-", 0.493677F, -1.0F);
00118 new IgParticleChar (10, 130, -20, "klong", "k0l", 0.497672F, 0.F);
00119 new IgParticleChar (16, 310, 20, "kshort", "k0s", 0.497672F, 0.F);
00120 IgParticleChar* ximinus = new IgParticleChar (11, 3312, 2330, "ximinus", "Xi-", 1.32132F, -1.0F);
00121
00122 SoDrawStyle* curveStyle = new SoDrawStyle ();
00123 curveStyle->lineWidth = 1.0;
00124 curveStyle->pointSize = 4;
00125 SoDrawStyle* dottedCurveStyle = new SoDrawStyle ();
00126 dottedCurveStyle->lineWidth = 1.0;
00127 dottedCurveStyle->pointSize = 4;
00128 dottedCurveStyle->linePattern = 0xff00;
00129 SoMaterial* curveColour = new SoMaterial ();
00130 curveColour->diffuseColor.setValue (0.4F, 0.4F, 0.4F);
00131
00132 CMapToParticleList::const_iterator i = particleList->begin ();
00133 for (i = particleList->begin (); i != particleList->end (); i++)
00134 {
00135 IgParticleChar* pChar = i->second;
00136 pChar-> setMaterial (curveColour);
00137 if ( pChar->charge == 0 )
00138 {
00139 pChar->setStyle (dottedCurveStyle);
00140 }
00141 else
00142 {
00143 pChar-> setStyle (curveStyle);
00144 }
00145 }
00146
00147
00148
00149 curveColour = new SoMaterial ();
00150 curveColour->diffuseColor.setValue (1.0, 0.0, 0.0);
00151 muon->setMaterial (curveColour);
00152 antimuon->setMaterial (curveColour);
00153
00154 curveColour = new SoMaterial ();
00155 curveColour->diffuseColor.setValue (0.0, 1.0, 0.0);
00156 electron->setMaterial (curveColour);
00157 positron->setMaterial (curveColour);
00158
00159 curveColour = new SoMaterial ();
00160 curveColour->diffuseColor.setValue (0.0, 0.0, 1.0);
00161 pion->setMaterial (curveColour);
00162 antipion->setMaterial (curveColour);
00163
00164 curveColour = new SoMaterial ();
00165 curveColour->diffuseColor.setValue (0.5, 0.5, 0.0);
00166 proton->setMaterial (curveColour);
00167
00168 curveColour = new SoMaterial ();
00169 curveColour->diffuseColor.setValue (0.45F, 0.55F, 0.0F);
00170 antiproton->setMaterial (curveColour);
00171
00172 curveColour = new SoMaterial ();
00173 curveColour->diffuseColor.setValue (0.2F, 0.2F, 0.2F);
00174 unknown->setMaterial (curveColour);
00175 antiunknown->setMaterial (curveColour);
00176
00177 curveColour = new SoMaterial ();
00178 curveColour->diffuseColor.setValue (0.0, 0.65F, 0.65F);
00179 kplus->setMaterial (curveColour);
00180 kminus->setMaterial (curveColour);
00181 ximinus->setMaterial (curveColour);
00182
00183 }
00184
00186 void
00187 IgParticleChar::deleteParticles ()
00188 {}
00189
00191 IgParticleChar *
00192 IgParticleChar::getByName (const char *string)
00193 {
00194 CMapToParticleList::iterator it = particleList->find (string);
00195 return it != particleList->end () ? it->second : 0;
00196 }
00197
00199 IgParticleChar *
00200 IgParticleChar::getByGeantID (const int p_code)
00201 {
00202 CMapToParticleList::const_iterator i = particleList->begin ();
00203 for (i = particleList->begin (); i != particleList->end (); i++)
00204 {
00205 IgParticleChar* pChar = i->second;
00206 if (pChar->geantCode == p_code)
00207 return pChar;
00208 }
00209
00210 return getByName ("unknown");
00211 }
00212
00214 IgParticleChar *
00215 IgParticleChar::getByPythiaID (const int p_code)
00216 {
00217 CMapToParticleList::const_iterator i = particleList->begin ();
00218 for (i = particleList->begin (); i != particleList->end (); i++)
00219 {
00220 IgParticleChar* pChar = i->second;
00221 if (pChar->pythiaCode == p_code)
00222 return pChar;
00223 }
00224
00225 return getByName ("unknown");
00226 }
00227
00229 IgParticleChar *
00230 IgParticleChar::getByIsajetID (const int p_code)
00231 {
00232 CMapToParticleList::const_iterator i = particleList->begin ();
00233 for (i = particleList->begin (); i != particleList->end (); i++)
00234 {
00235 IgParticleChar* pChar = i->second;
00236 if (pChar->isajetCode == p_code)
00237 return pChar;
00238 }
00239
00240 return getByName ("unknown");
00241 }
00242
00244 void
00245 IgParticleChar::dumpDB (std::ostream & os)
00246 {
00247 os << "Dumping the ParticleChar Database..." << std::endl;
00248 for (CMapToParticleList::const_iterator it=particleList->begin (); it != particleList->end (); it++)
00249 {
00250 os << it->first << std::endl;
00251 if (it->second) os << *it->second;
00252 }
00253 }
00254
00256 void
00257 IgParticleChar::print (std::ostream & os) const
00258 {
00259 os << "Particle: " << name.getString ()
00260 << ", Label: " << label.getString ()
00261 << ", Charge: " << charge
00262 << ", Mass: " << mass << std::endl;
00263 }