00001
00002
00003 #include "VisSimulation/VisSimBase/interface/VisG4TrackPtTwig.h"
00004 #include "VisSimulation/VisSimBase/interface/VisG4TracksTwig.h"
00005 #include "Iguana/Inventor/interface/IgSbColorMap.h"
00006 #include "Iguana/Framework/interface/IgRepSet.h"
00007 #include "Iguana/Models/interface/IgTextRep.h"
00008 #include "Iguana/GLModels/interface/Ig3DRep.h"
00009 #include "Inventor/nodes/SoLineSet.h"
00010 #include "Inventor/nodes/SoVertexProperty.h"
00011 #include "Inventor/nodes/SoDrawStyle.h"
00012 #include "Inventor/nodes/SoSeparator.h"
00013 #include "Inventor/nodes/SoGroup.h"
00014 #include "G4TrajectoryContainer.hh"
00015 #include "G4TrajectoryPoint.hh"
00016 #include "G4Trajectory.hh"
00017 #include <qapplication.h>
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 static unsigned darken (unsigned rgba, float amount)
00028 {
00029 float rgbcomponents [4];
00030 float hsvcomponents [4];
00031 IgSbColorMap::unpack (rgba, rgbcomponents);
00032 IgSbColorMap::rgb2hsv (rgbcomponents, hsvcomponents);
00033 hsvcomponents [2] *= amount;
00034 IgSbColorMap::hsv2rgb (hsvcomponents, rgbcomponents);
00035 return IgSbColorMap::pack (rgbcomponents);
00036 }
00037
00038
00039
00040
00041 VisG4TrackPtTwig::VisG4TrackPtTwig (IgState *state, IgTwig *parent, std::string name,
00042 unsigned colour, bool highpt, VisG4TracksTwig *tracks,
00043 const int *ids)
00044 : VisQueuedTwig (state, parent, name),
00045 m_tracks (tracks),
00046 m_isHighPt (highpt),
00047 m_ids (ids),
00048 m_rgba (colour)
00049 {}
00050
00051 void
00052 VisG4TrackPtTwig::cutChanged (void)
00053 { IgRepSet::invalidate (this, SELF_MASK); }
00054
00055 bool
00056 VisG4TrackPtTwig::rejectTrajectory (const G4Trajectory *traj) const
00057 {
00058
00059 Hep3Vector p = traj->GetInitialMomentum ();
00060 double px = p.x () / GeV;
00061 double py = p.y () / GeV;
00062 double pt = sqrt (px * px + py * py);
00063
00064 if ((m_isHighPt)
00065 || (! m_isHighPt))
00066 return true;
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 const int *ids = m_ids;
00079
00080
00081 if (ids [0] == VisG4TracksTwig::CHARGE)
00082 {
00083 int charge = (int) traj->GetCharge ();
00084
00085 if (ids [1] == VisG4TracksTwig::CHARGED)
00086 {
00087 if (charge == 0)
00088 return true;
00089 }
00090 else if (ids [1] == VisG4TracksTwig::NEUTRAL)
00091 {
00092 if (charge != 0)
00093 return true;
00094 }
00095 else
00096 ASSERT (false);
00097
00098 ids += 2;
00099 }
00100
00101
00102 ASSERT (ids [0] == VisG4TracksTwig::PARTICLE
00103 || ids [0] == -VisG4TracksTwig::PARTICLE);
00104
00105 int partId = traj->GetPDGEncoding ();
00106 bool inclusive = (ids [0] == VisG4TracksTwig::PARTICLE);
00107 int nparts = ids [1];
00108 bool isOfType = false;
00109
00110 for (int i = 0; !isOfType && i < nparts; ++i)
00111 isOfType = isOfType || (partId == ids [2 + i]);
00112
00113 return inclusive != isOfType;
00114 }
00115
00116 void
00117 VisG4TrackPtTwig::update (IgTextRep *rep)
00118 {
00119
00120 VisQueuedTwig::update (rep);
00121
00122
00123 G4TrajectoryContainer *trajs = m_tracks->trajectories ();
00124 std::ostringstream text;
00125 std::ostringstream preamble;
00126 int nSelected = 0;
00127
00128 text << std::setiosflags (std::ios::showpoint | std::ios::fixed);
00129 text.setf (std::ios::right, std::ios::adjustfield);
00130
00131 for (int i = 0; i < trajs->entries (); ++i)
00132 {
00133 ASSERT (dynamic_cast<G4Trajectory *> ((*trajs) [i]));
00134 G4Trajectory *traj = static_cast<G4Trajectory *> ((*trajs) [i]);
00135 if (rejectTrajectory (traj))
00136 continue;
00137
00138 if (++nSelected == 1)
00139 {
00140 text << "<table width='100%' border='1'>\n"
00141 << "<tr align='center'>"
00142 << "<th>ID</th>"
00143 << "<th>Parent ID</th>"
00144 << "<th>Name</th>"
00145 << "<th>Charge</th>"
00146 << "<th>p<sub>T</sub></th>"
00147 << "<th>p<sub>x</sub></th>"
00148 << "<th>p<sub>y</sub></th>"
00149 << "<th>p<sub>z</sub></th>"
00150 << "<th>Points</th>"
00151
00152
00153
00154
00155
00156
00157 << "</tr>";
00158 }
00159
00160 Hep3Vector p = traj->GetInitialMomentum ();
00161 double px = p.x () / GeV;
00162 double py = p.y () / GeV;
00163 double pz = p.z () / GeV;
00164 double pt = sqrt (px * px + py * py);
00165
00166 text << "<tr align='right'>"
00167 << "<td>" << traj->GetTrackID () << "</td>"
00168 << "<td>" << traj->GetParentID () << "</td>"
00169 << "<td>" << traj->GetParticleName () << "</td>"
00170 << "<td>" << (int) traj->GetCharge () << "</td>"
00171 << "<td>" << std::setprecision (2) << pt << "</td>"
00172 << "<td>" << std::setprecision (2) << px << "</td>"
00173 << "<td>" << std::setprecision (2) << py << "</td>"
00174 << "<td>" << std::setprecision (2) << pz << "</td>"
00175 << "<td>" << traj->GetPointEntries () << "</td>"
00176 << "</tr>";
00177 }
00178
00179 if (nSelected)
00180 {
00181 text << "</table>\n";
00182 preamble << "<p>" << name () << " with p<sub>T</sub> "
00183 << (m_isHighPt ? "over " : "under ")
00184 << std::setprecision (2) << "FIXME: NO CUT"
00185 << ": " << nSelected << " trajectories</p>";
00186 }
00187 else
00188 text << "<p>No " << name () << " with p<sub>T</sub> "
00189 << (m_isHighPt ? "over " : "under ")
00190 << std::setprecision (2) << "FIXME: NO CUT" << "</p>";
00191
00192
00193 qApp->lock ();
00194 rep->setText (preamble.str () + text.str ());
00195 qApp->unlock (false);
00196 }
00197
00198 void
00199 VisG4TrackPtTwig::update (Ig3DRep *rep)
00200 {
00201
00202 VisQueuedTwig::update (rep);
00203
00204
00205 qApp->lock ();
00206 SoGroup *contents = rep->node ();
00207 contents->removeAllChildren ();
00208
00209
00210 G4TrajectoryContainer *trajs = m_tracks->trajectories ();
00211 for (int i = 0; i < trajs->entries (); ++i)
00212 {
00213
00214
00215 ASSERT (dynamic_cast<G4Trajectory *> ((*trajs) [i]));
00216 G4Trajectory *traj = static_cast<G4Trajectory *> ((*trajs) [i]);
00217 if (rejectTrajectory (traj))
00218 continue;
00219
00220 static SoDrawStyle *thick = 0;
00221 static SoDrawStyle *thin = 0;
00222 if (! thick)
00223 {
00224 thick = new SoDrawStyle;
00225 thick->lineWidth = 2.0;
00226 thick->ref ();
00227
00228 thin = new SoDrawStyle;
00229 thin->lineWidth = 1.0;
00230 thin->ref ();
00231 }
00232
00233 SoSeparator *group = new SoSeparator;
00234 SoLineSet *line = new SoLineSet;
00235 SoVertexProperty *vtx = new SoVertexProperty;
00236 int npoints = traj->GetPointEntries ();
00237 SbVec3f *points;
00238
00239
00240
00241 Hep3Vector p = traj->GetInitialMomentum ();
00242 double px = p.x () / GeV;
00243 double py = p.y () / GeV;
00244 double pt = sqrt (px * px + py * py);
00245 double ptscale = (pt <= 2 ? .5
00246 : pt <= 20 ? .5 + log(pt) / log(20.) * .5
00247 : 1);
00248 SoDrawStyle *style = pt < 20 ? thin : thick;
00249 vtx->materialBinding = SoVertexProperty::OVERALL;
00250 vtx->orderedRGBA = darken (m_rgba, ptscale);
00251
00252
00253 int step = 1;
00254
00255
00256 int nVertices = 0;
00257
00258 vtx->vertex.setNum (npoints);
00259 points = vtx->vertex.startEditing ();
00260 for (int j = 0; j < npoints; ++j)
00261 {
00262 G4VTrajectoryPoint *vp = traj->GetPoint (j);
00263 ASSERT (dynamic_cast<G4TrajectoryPoint *> (vp));
00264 G4ThreeVector pt = static_cast<G4TrajectoryPoint *> (vp)->GetPosition ();
00265 if (j % step == 0 || j == npoints - 1)
00266 {
00267 points [nVertices] = SbVec3f (pt.x () / m, pt.y () / m, pt.z () / m);
00268 nVertices++;
00269 }
00270 }
00271
00272 vtx->vertex.finishEditing ();
00273 line->numVertices = nVertices;
00274 line->vertexProperty = vtx;
00275 group->addChild (style);
00276 group->addChild (line);
00277 contents->addChild (group);
00278 }
00279
00280 qApp->unlock (false);
00281 }