23 #include <TEveBoxSet.h>
24 #include <TEveBrowser.h>
25 #include <TEveCompound.h>
26 #include <TEveGeoNode.h>
27 #include <TEveManager.h>
28 #include <TEveRGBAPalette.h>
29 #include <TEvePointSet.h>
30 #include <TEveQuadSet.h>
31 #include <TEveStraightLineSet.h>
32 #include <TEveTrack.h>
33 #include <TEveTrackPropagator.h>
34 #include <TEveVSDStructs.h>
36 #include <TGeometry.h>
37 #include <TGeoManager.h>
38 #include <TGeoMaterial.h>
39 #include <TGeoMatrix.h>
43 #include <TGListBox.h>
44 #include <TGListTree.h>
49 #include <gearimpl/Util.h>
50 #include <gearxml/GearXML.h>
51 #include <gear/GearMgr.h>
52 #include <gear/GEAR.h>
53 #include <gear/TPCParameters.h>
59 #include "EVENT/LCIO.h"
60 #include "IO/LCReader.h"
61 #include "IO/LCWriter.h"
62 #include "IMPL/LCEventImpl.h"
63 #include "IMPL/LCCollectionVec.h"
64 #include "EVENT/Track.h"
65 #include "EVENT/TrackerData.h"
66 #include "EVENT/TrackerHit.h"
67 #include "EVENT/TrackerPulse.h"
68 #include "Exceptions.h"
80 readoutFrequency(40.),
87 TStyle* style =
new TStyle();
88 TGeoManager* geom =
new TGeoManager(
"DetectorGeometry",
"detector geometry");
91 materials[
"Vacuum"] =
new TGeoMaterial(
"Vacuum", 0,0,0);
92 materials[
"Al"] =
new TGeoMaterial(
"Al", 26.98,13,2.7);
95 media[
"Vacuum"] =
new TGeoMedium(
"Vacuum", 1,
materials[
"Vacuum"]);
99 options[
"module.parallelBorders"] = 0;
100 options[
"module.drawPadsByDefault"] = kFALSE;
101 options[
"module.drawOutlineByDefault"] = kTRUE;
116 if (nDivisions == 0) {
139 float dPhi = (phi_max - phi_min) / nDivisions;
142 while (j < nDivisions) {
143 ls->AddLine(r*cos(dPhi*j + phi_min), r*sin(dPhi*j + phi_min), z,
144 r*cos(dPhi*(j+1) + phi_min), r*sin(dPhi*(j+1) + phi_min), z);
150 void VisTPC::drawEvent(EVENT::LCEvent* event, TList &selectedEntries, TEveElement* parent,
const char* name) {
151 std::vector<std::string> entries;
153 TIter next(&selectedEntries);
154 while (TGTextLBEntry* entry = (TGTextLBEntry*) next()) {
155 entries.push_back(entry->GetTitle());
161 void VisTPC::drawEvent(EVENT::LCEvent* event, std::vector<std::string> &selectedEntries, TEveElement* parent,
const char* name) {
162 TEveElementList *eveNode =
new TEveElementList(name);
163 TEveElement *eveChild = NULL;
164 TGListTreeItem *listTreeItem = 0;
166 LCCollectionVec *collection = 0;
170 eveNode->SetRnrSelfChildren(kFALSE, kFALSE);
175 std::vector<std::string>::iterator it = selectedEntries.begin();
176 it != selectedEntries.end();
185 collection =
dynamic_cast<LCCollectionVec*
>(
event->getCollection(*it));
195 }
catch (DataNotAvailableException &) {
197 std::cout <<
"Collection \"" << *it
198 <<
"\" not available" << std::endl;
212 eveChild->SetElementName(it->c_str());
215 parent->AddElement(eveChild);
217 gEve->AddElement(eveChild);
224 eveChild->SetElementName(it->c_str());
225 eveChild->SetRnrSelf(kFALSE);
228 parent->AddElement(eveChild);
230 gEve->AddElement(eveChild);
237 eveChild->SetElementName(it->c_str());
248 listTreeItem = gEve->GetListTree()->FindItemByPathname(
"/Event/All hits");
251 eveChild =
static_cast<TEveElement*
>( listTreeItem->GetUserData() );
253 it->append(
" - All hits");
254 eveChild->SetElementName(it->c_str());
273 throw "VisTPC::drawHit() : parent can't be null.";
275 TEvePointSet *point = 0;
277 const double *pos = hit->getPosition();
278 const FloatVec &covariance = hit->getCovMatrix();
284 case PadRowLayout2D::CARTESIAN:
285 position[0] = pos[0];
286 position[1] = pos[1];
287 position[2] = pos[2];
290 case PadRowLayout2D::POLAR:
291 position[0] = pos[0]*cos(pos[1]);
292 position[1] = pos[0]*sin(pos[1]);
293 position[2] = pos[2];
296 throw "Unknown coordinate type.";
299 std::stringstream tooltip;
304 <<
"Position [mm]: ("
305 << position[0] <<
", "
306 << position[1] <<
", "
307 << position[2] <<
")"
310 << covariance[0] <<
", "
311 << covariance[1] <<
", "
312 << covariance[2] <<
")"
314 <<
"Energy [GeV]: " << hit->getEDep() << std::endl
315 <<
"Time [ns]: " << hit->getTime() << std::endl
316 <<
"Type: " << hit->getType() << std::endl
317 <<
"Quality: " << hit->getQuality() << std::endl;
319 point =
new TEvePointSet();
320 point->SetOwnIds(kTRUE);
321 point->SetMarkerSize(0.2);
322 point->SetMarkerStyle(2);
323 point->SetMarkerColor(kMagenta);
324 point->SetElementTitle(tooltip.str().c_str());
326 parent->AddElement(point);
334 parent->SetNextPoint(position[0], position[1], position[2]);
338 parent->SetNextPoint(position[0], position[1],
maxDriftLength + 1);
343 TEvePointSet* ps =
new TEvePointSet();
345 const double* pos = NULL;
349 ps->SetOwnIds(kTRUE);
350 ps->SetMarkerColor(kMagenta);
351 ps->SetMarkerSize(0.2);
352 ps->SetMarkerStyle(2);
356 LCCollectionVec::iterator inputHitsIter = hits->begin();
357 inputHitsIter < hits->end();
364 th =
dynamic_cast<TrackerHit *
>( *inputHitsIter );
374 TEvePointSet* ps =
new TEvePointSet();
376 const double* pos = NULL;
380 ps->SetOwnIds(kTRUE);
381 ps->SetMarkerColor(kMagenta);
382 ps->SetMarkerSize(0.2);
383 ps->SetMarkerStyle(2);
387 TrackerHitVec::const_iterator inputHitsIter = hits.begin();
388 inputHitsIter != hits.end();
405 const std::vector<double>& extent = aModule->getLocalPadLayout().getPlaneExtent();
406 double border = aModule->getBorderWidth();
411 float x1_min = extent[0];
412 float x1_max = extent[1];
413 float x2_min = extent[2];
414 float x2_max = extent[3];
416 float r_min, phi_min, r_max, phi_max = 0.;
419 int nDivisions = 100;
421 TEveStraightLineSet* module_outline =
new TEveStraightLineSet(
"Outline");
422 std::stringstream tooltip;
427 module_outline->SetLineColor(kBlue);
428 module_outline->SetRnrSelf(
options[
"module.drawOutlineByDefault"]);
430 switch (aModule->getLocalPadLayout().getCoordinateType()) {
431 case PadRowLayout2D::CARTESIAN:
438 module_outline->AddLine(x1_min, x2_min, pos_z,
439 x1_min, x2_max, pos_z);
441 module_outline->AddLine(x1_max, x2_min, pos_z,
442 x1_max, x2_max, pos_z);
444 module_outline->AddLine(x1_min, x2_min, pos_z,
445 x1_max, x2_min, pos_z);
447 module_outline->AddLine(x1_min, x2_max, pos_z,
448 x1_max, x2_max, pos_z);
450 case PadRowLayout2D::POLAR:
457 if (fabs((x2_max - x2_min) - 2*TMath::Pi()) > 1e-5) {
459 if (!
options[
"module.parallelBorders"]) {
463 x2_min -= border / x1_min;
464 x2_max += border / x1_min;
469 module_outline->AddLine(x1_min*cos(x2_min), x1_min*sin(x2_min), pos_z,
470 x1_max*cos(x2_min), x1_max*sin(x2_min), pos_z);
472 module_outline->AddLine(x1_min*cos(x2_max), x1_min*sin(x2_max), pos_z,
473 x1_max*cos(x2_max), x1_max*sin(x2_max), pos_z);
488 phi_min = x2_min - border / x1_min;
489 r_min = x1_min / cos(border / x1_min);
491 phi_max = x2_min - border / x1_max;
492 r_max = x1_max / cos(border / x1_max);
494 module_outline->AddLine(r_min*cos(phi_min), r_min*sin(phi_min), pos_z,
495 r_max*cos(phi_max), r_max*sin(phi_max), pos_z);
497 module_outline->AddLine(x1_min*cos(x2_min), x1_min*sin(x2_min), pos_z,
498 r_min*cos(phi_min), r_min*sin(phi_min), pos_z);
500 module_outline->AddLine(x1_max*cos(x2_min), x1_min*sin(x2_min), pos_z,
501 r_max*cos(phi_max), r_max*sin(phi_max), pos_z);
507 phi_min = x2_max + border / x1_min;
508 r_min = x1_min / cos(border / x1_min);
510 phi_max = x2_max + border / x1_max;
511 r_max = x1_max / cos(border / x1_max);
513 module_outline->AddLine(r_min*cos(phi_min), r_min*sin(phi_min), pos_z,
514 r_max*cos(phi_max), r_max*sin(phi_max), pos_z);
516 module_outline->AddLine(x1_min*cos(x2_max), x1_min*sin(x2_max), pos_z,
517 r_min*cos(phi_min), r_min*sin(phi_min), pos_z);
519 module_outline->AddLine(x1_max*cos(x2_max), x1_max*sin(x2_max), pos_z,
520 r_max*cos(phi_max), r_max*sin(phi_max), pos_z);
534 throw "Unknown coordinate type.";
541 parent->AddElement(module_outline);
543 tooltip << parent->GetElementName() <<
" outline";
544 module_outline->SetElementTitle(tooltip.str().c_str());
547 gEve->AddGlobalElement(module_outline);
565 const std::vector<TPCModule *> & tpcModules =
tpcParameters->getModules();
566 TPCModule* tpcModule;
567 TEveElementList* elements = NULL;
574 std::cout <<
tpcParameters->getNModules() <<
" Module(s)" << std::endl;
581 std::vector<TPCModule *>::const_iterator iterator = tpcModules.begin();
582 iterator != tpcModules.end();
585 tpcModule = *iterator;
587 elements =
new TEveElementList(Form(
"Module %i", tpcModule->getModuleID()));
588 elements->SetPickable(kFALSE);
597 parent->AddElement(elements);
599 gEve->AddGlobalElement(elements);
613 void VisTPC::drawNearestPad(
const gear::TPCModule& tpcModule, TEveElement* parent,
int padIndex,
const gear::Vector2D& position,
int i) {
616 TEveElementList* node =
new TEveElementList(Form(
"%i", i));
617 TEvePointSet* point =
new TEvePointSet(Form(
"Test hit %i", i));
618 TEvePointSet* padcenter = 0;
619 TEveQuadSet* pad =
new TEveQuadSet(Form(
"Pad %i", i));
620 TEveStraightLineSet* line =
new TEveStraightLineSet(Form(
"Line %i", i));
628 const PadRowLayout2D &layout = tpcModule.getLocalPadLayout();
630 std::stringstream tooltip;
634 point->SetOwnIds(kTRUE);
635 point->SetMarkerColor(kRed);
636 point->SetMarkerSize(0.2);
637 point->SetMarkerStyle(2);
639 pad->Reset(TEveQuadSet::kQT_FreeQuad, kTRUE, 32);
641 pad->SetOwnIds(kTRUE);
645 padcenter =
new TEvePointSet(Form(
"padcenter %i", i));
646 padcenter->SetOwnIds(kTRUE);
647 padcenter->SetMarkerColor(kGreen);
648 padcenter->SetMarkerSize(0.2);
649 padcenter->SetMarkerStyle(2);
651 line->SetLineColor(kYellow);
659 tooltip <<
"Test hit: (" << a_pos <<
", " << b_pos <<
")" << std::endl;
661 padPos = layout.getPadCenter(padIndex);
663 tooltip <<
"Padcenter: (" << padPos[0] <<
", " << padPos[1] <<
")" << std::endl;
665 tooltip <<
"Difference: ("
666 << a_pos - padPos[0] <<
", "
667 << b_pos - padPos[1] <<
")"
672 if (layout.getCoordinateType() == PadRowLayout2D::POLAR) {
675 x = a_pos*cos(b_pos);
676 y = a_pos*sin(b_pos);
682 tooltip <<
"Test hit (cartesian): (" << a_pos <<
", " << b_pos <<
")" << std::endl;
684 point->SetNextPoint(a_pos, b_pos, 1);
692 tooltip <<
"padMetric.center(cartesian): (" << padMetric.
center_x <<
", " << padMetric.
center_y <<
")" << std::endl;
695 pad->QuadColor(kBlack);
706 toGlobal(&tpcModule, dynamic_cast<TEveElement*>(point));
707 toGlobal(&tpcModule, dynamic_cast<TEveElement*>(pad));
708 toGlobal(&tpcModule, dynamic_cast<TEveElement*>(padcenter));
709 toGlobal(&tpcModule, dynamic_cast<TEveElement*>(line));
713 node->SetElementTitle(Form(
"%i\n%s", i, tooltip.str().c_str()));
714 point->SetElementTitle(Form(
"Test hit %i\n%s", i, tooltip.str().c_str()));
715 pad->SetElementTitle(Form(
"Pad %i\n%s", i, tooltip.str().c_str()));
716 padcenter->SetElementTitle(Form(
"Pad center %i\n%s", i, tooltip.str().c_str()));
717 line->SetElementTitle(Form(
"Line %i\n%s", i, tooltip.str().c_str()));
719 node->AddElement(point);
720 node->AddElement(pad);
721 node->AddElement(padcenter);
722 node->AddElement(line);
725 parent->AddElement(node);
727 gEve->AddElement(node);
731 float boxCorners[24];
736 boxCorners[2] = z_back;
741 boxCorners[5] = z_back;
746 boxCorners[8] = z_front;
751 boxCorners[11] = z_front;
756 boxCorners[14] = z_back;
761 boxCorners[17] = z_back;
766 boxCorners[20] = z_front;
771 boxCorners[23] = z_front;
773 bs->AddBox(boxCorners);
777 float quadCorners[12];
799 qs->AddQuad(quadCorners);
811 const PadRowLayout2D &layout = aModule->getLocalPadLayout();
813 std::stringstream tooltip;
817 int nRows = layout.getNRows();
822 const std::vector<int> * padsInRow = NULL;
823 std::vector<int>::const_iterator iterator;
825 TEveStraightLineSet* ls =
new TEveStraightLineSet(
"Pad borders");
826 TEvePointSet* ps =
new TEvePointSet(
"Pad centers");
828 float x_pos, y_pos = 0.;
833 const std::vector<double>& extent = layout.getPlaneExtent();
837 double row_extent_min = 0.;
838 double row_extent_max = 0.;
839 double padRowHeightDiff = 0.;
848 ls->SetRnrSelf(
options[
"module.drawPadsByDefault"]);
849 ls->SetLineColor(kRed);
850 ls->SetPickable(kFALSE);
852 ps->SetRnrSelf(kFALSE);
853 ps->SetOwnIds(kTRUE);
854 ps->SetMarkerColor(kGreen);
855 ps->SetMarkerSize(1);
856 ps->SetMarkerStyle(1);
857 ps->SetPickable(kFALSE);
861 switch (layout.getCoordinateType()) {
862 case PadRowLayout2D::CARTESIAN:
863 row_extent_min = extent[0];
864 row_extent_max = extent[1];
867 case PadRowLayout2D::POLAR:
868 row_extent_min = extent[2];
869 row_extent_max = extent[3];
873 throw "Unknown coordinate type.";
878 for (
int i = 0; i < nRows; i++) {
879 padsInRow = &layout.getPadsInRow(i);
880 iterator = padsInRow->begin();
881 nPadsInRow = padsInRow->size();
893 padGap = layout.getPadPitch(*(padsInRow->begin())) - layout.getPadWidth(*(padsInRow->begin()));
895 while (iterator != padsInRow->end()) {
908 switch (layout.getCoordinateType()) {
909 case PadRowLayout2D::CARTESIAN:
910 if (iterator == padsInRow->begin() || padGap > 1e-6) {
920 case PadRowLayout2D::POLAR:
921 if (iterator == padsInRow->begin() || padGap > 1e-6) {
932 throw "Unknown coordinate type.";
937 ps->SetNextPoint(x_pos, y_pos, z_pos);
946 padRowHeightDiff = layout.getRowHeight(i) - layout.getPadHeight(*(padsInRow->begin()));
948 switch (layout.getCoordinateType()) {
949 case PadRowLayout2D::CARTESIAN:
953 if (i == nRows - 1 || padRowHeightDiff > 1e-6) {
960 case PadRowLayout2D::POLAR:
961 nDivisions = ceil(nPadsInRow / 5.);
965 if (i == nRows - 1 || padRowHeightDiff > 1e-6) {
972 throw "Unknown coordinate type.";
984 parent->AddElement(ls);
985 parent->AddElement(ps);
987 tooltip << parent->GetElementName() <<
" pads";
988 ls->SetElementTitle(tooltip.str().c_str());
991 tooltip << parent->GetElementName() <<
" pads";
992 ps->SetElementTitle(tooltip.str().c_str());
995 gEve->AddGlobalElement(ls);
996 gEve->AddGlobalElement(ps);
1010 TEveRGBAPalette* pal =
new TEveRGBAPalette();
1012 TEveElementList* topElement =
new TEveElementList();
1014 TEveElementList* el =
new TEveElementList(
"Pulses");
1015 TEveBoxSet* bs =
new TEveBoxSet (
"Boxes");
1016 TEvePointSet* ps =
new TEvePointSet (
"Markers");
1018 TEveElementList* el2 =
new TEveElementList(
"Max charge deposit");
1019 TEveBoxSet* bs2 =
new TEveBoxSet (
"3D lego");
1020 TEveQuadSet* qs2 =
new TEveQuadSet (
"2D projection");
1021 TEvePointSet* ps2 =
new TEvePointSet (
"Markers");
1030 float localMaxCharge = 0.;
1031 float overallCharge = 0.;
1032 float startTime = 0.;
1035 typedef std::map<int, float> MapPadCharge;
1036 typedef std::map<int, MapPadCharge> MapModulePadCharge;
1038 MapModulePadCharge globalCharge;
1039 MapPadCharge* moduleCharge;
1043 const TPCModule* tpcModule = NULL;
1046 float x_pos, y_pos = 0;
1055 gStyle->SetPalette(1, 0);
1056 pal->SetMinMax(0, 1023);
1057 pal->SetInterpolate(kTRUE);
1058 pal->SetOverColor(kWhite);
1059 pal->SetOverflowAction(TEveRGBAPalette::kLA_Mark);
1060 pal->SetUnderColor(kBlack);
1061 pal->SetUnderflowAction(TEveRGBAPalette::kLA_Mark);
1063 bs->Reset(TEveBoxSet::kBT_FreeBox, kFALSE, 64);
1065 bs->SetMainAlpha(0.9);
1066 bs->SetPalette(pal);
1068 ps->SetRnrSelf(kFALSE);
1070 ps->SetMarkerColor(kYellow);
1071 ps->SetMarkerSize(0.2);
1072 ps->SetMarkerStyle(2);
1074 bs2->Reset(TEveBoxSet::kBT_FreeBox, kFALSE, 64);
1075 bs2->SetRnrSelf(kFALSE);
1077 bs2->SetPalette(pal);
1079 ps2->SetRnrSelf(kFALSE);
1081 ps2->SetMarkerColor(kYellow);
1082 ps2->SetMarkerSize(0.2);
1083 ps2->SetMarkerStyle(2);
1085 qs2->Reset(TEveQuadSet::kQT_FreeQuad, kFALSE, 32);
1086 qs2->SetPalette(pal);
1092 LCCollectionVec::iterator inputPulsIter = pulses->begin();
1093 inputPulsIter < pulses->end();
1100 tp =
dynamic_cast<TrackerPulse *
>( *inputPulsIter );
1101 td = tp->getTrackerData();
1105 moduleId = tp->getCellID1();
1106 padId = tp->getCellID0();
1108 time = tp->getTime();
1124 FloatVec::const_iterator i = td->getChargeValues().begin();
1125 i != td->getChargeValues().end();
1128 if (*i > localMaxCharge) {
1129 localMaxCharge = *i;
1133 if (!globalCharge.count(moduleId)) {
1134 globalCharge[moduleId] = MapPadCharge();
1137 moduleCharge = &globalCharge[moduleId];
1139 if (!moduleCharge->count(padId)) {
1140 (*moduleCharge)[padId] = 0;
1143 if ((*moduleCharge)[padId] < localMaxCharge) {
1144 (*moduleCharge)[padId] = localMaxCharge;
1149 ps->SetNextPoint(x_pos, y_pos, z_pos - startTime*
driftVelocity);
1153 z_pos - endTime * driftVelocity,
1154 z_pos - startTime * driftVelocity,
1157 bs->DigitValue(localMaxCharge);
1163 MapModulePadCharge::iterator j = globalCharge.begin();
1164 j != globalCharge.end();
1168 moduleId = (*j).first;
1172 MapPadCharge::iterator k = (*j).second.begin();
1173 k != (*j).second.end();
1178 localMaxCharge = (*k).second;
1188 qs2->DigitValue(localMaxCharge);
1190 ps2->SetNextPoint(x_pos, y_pos, z_pos + 1);
1194 drawPadBox(pad, z_pos, z_pos + localMaxCharge / 10, bs2);
1195 bs2->DigitValue(localMaxCharge);
1208 topElement->AddElement(el);
1212 topElement->AddElement(el2);
1213 el2->AddElement(bs2);
1214 el2->AddElement(ps2);
1215 el2->AddElement(qs2);
1222 volumes[
"top"] = gGeoManager->MakeBox(
"Detector",
media[
"Vacuum"],
1231 volumes[
"TPC"]->SetTransparency(75);
1232 volumes[
"top"]->AddNode(
volumes[
"TPC"], 0,
new TGeoTranslation(0,0,0));
1234 gGeoManager->SetTopVolume(
volumes[
"top"]);
1236 TGeoNode* node = gGeoManager->GetTopNode();
1237 TEveGeoTopNode* en =
new TEveGeoTopNode(gGeoManager, node);
1240 en->GetNode()->GetVolume()->SetVisibility(kFALSE);
1242 gEve->AddGlobalElement(en);
1269 const float cm = 1.;
1270 const float mm = 0.1 * cm;
1272 Track *lcio_track = NULL;
1273 const TrackerHitVec *lcio_hits = NULL;
1277 TEveTrackList *track_list =
new TEveTrackList();
1278 TEveTrackPropagator *propagator = track_list->GetPropagator();
1279 TEveRecTrack *eve_track_rec = NULL;
1280 TEveTrack *eve_track = NULL;
1281 TEveStraightLineSet *eve_line = NULL;
1282 TEveElement *eve_hits = NULL;
1283 TEveElementList *eve_all_hits =
new TEveElementList(
"All hits");
1285 Vector3D b_field(0,0,0);
1287 float p_transversal = 0.;
1289 const float *reference_point = NULL;
1290 float start_point[3];
1291 float d0, phi0, z0, tanLambda, omega = 0.;
1301 const int FITFAILEDBIT = 30;
1309 b_field =
gearMgr->getBField().at(Vector3D(0, 0, 0));
1311 catch (UnknownParameterException & e) {
1312 std::cout <<
"WARNING:" << e.what() << std::endl;
1313 std::cout <<
"B field is assumed to be 0" << std::endl;
1318 propagator->SetMagFieldObj(
1319 new TEveMagFieldConst(
1328 propagator->SetMaxOrbs(50);
1335 LCCollectionVec::iterator tracksIter = tracks->begin();
1336 tracksIter != tracks->end();
1343 lcio_track =
dynamic_cast<Track*
>( *tracksIter );
1347 reference_point = lcio_track->getReferencePoint();
1348 d0 = lcio_track->getD0();
1349 omega = lcio_track->getOmega();
1350 phi0 = lcio_track->getPhi();
1351 tanLambda = lcio_track->getTanLambda();
1352 z0 = lcio_track->getZ0();
1354 start_point[0] = reference_point[0] - d0 * sin(phi0);
1355 start_point[1] = reference_point[1] + d0 * cos(phi0);
1356 start_point[2] = reference_point[2] + z0;
1358 fitFailed = (lcio_track->getType() >> FITFAILEDBIT) & 0x1 ? 1 : 0;
1364 charge = b_field.z() / omega >= 0. ? 1 : -1;
1371 std::stringstream tooltip;
1373 tooltip << std::left <<
"d0 = " << d0 << std::endl
1374 << std::left <<
"omega = " << omega << std::endl
1375 << std::left <<
"phi0 = " << phi0 << std::endl
1376 << std::left <<
"tanLambda = " << tanLambda << std::endl
1377 << std::left <<
"starting point = ("
1378 << start_point[0] <<
", "
1379 << start_point[1] <<
", "
1380 << start_point[2] <<
")" << std::endl
1381 << std::left <<
"fitFailed = " << fitFailed << std::endl;
1386 lcio_hits = &lcio_track->getTrackerHits();
1389 ((TEvePointSet*) eve_hits)->SetMarkerColor(!fitFailed ? kRed : kGreen);
1390 ((TEvePointSet*) eve_hits)->SetRnrSelfChildren(kFALSE, kFALSE);
1392 eve_all_hits->AddElement(eve_hits);
1406 if (fabs(b_field.z()) > 0. && omega) {
1423 eve_track_rec =
new TEveRecTrack();
1424 eve_track_rec->fV.Set(
1440 p_transversal = 3. * pow(10, -2) * fabs(b_field.z() / omega);
1442 eve_track_rec->fP.Set(
1443 static_cast<float>( (direction?-1:1) * p_transversal * cos(phi0) ) * mm,
1444 static_cast<float>( (direction?-1:1) * p_transversal * sin(phi0) ) * mm,
1445 static_cast<float>( (direction?-1:1) * p_transversal * tanLambda ) * mm
1447 eve_track_rec->fSign = (direction?1:-1) * charge;
1451 eve_track =
new TEveTrack(eve_track_rec, propagator);
1452 eve_track->SetElementTitle(tooltip.str().c_str());
1453 eve_track->SetLineColor(fitFailed ? kRed : kGreen);
1454 eve_track->SetLineWidth(1);
1458 track_list->AddElement(eve_track);
1459 eve_track->MakeTrack();
1461 eve_track->AddElement(eve_hits);
1467 if ( eve_line == NULL ) {
1468 eve_line =
new TEveStraightLineSet();
1475 + pow(start_point[1] + sin(phi0) * innerFieldCageRadius, 2));
1476 float scaling_min_z = (
maxDriftLength - start_point[2]) / tanLambda;
1477 float scaling_min = tanLambda * scaling_min_xy >
maxDriftLength ? scaling_min_z : scaling_min_xy;
1480 + pow(start_point[1] + sin(phi0) * outerFieldCageRadius, 2));
1481 float scaling_max_z = (
maxDriftLength - start_point[2]) / tanLambda;
1482 float scaling_max = tanLambda * scaling_max_xy >
maxDriftLength ? scaling_max_z : scaling_max_xy;
1485 start_point[0] + cos(phi0) * scaling_min,
1486 start_point[1] + sin(phi0) * scaling_min,
1487 start_point[2] + tanLambda * scaling_min,
1488 start_point[0] + cos(phi0) * scaling_max,
1489 start_point[1] + sin(phi0) * scaling_max,
1490 start_point[2] + tanLambda * scaling_max
1493 eve_line->SetElementTitle(tooltip.str().c_str());
1494 eve_line->SetLineColor(fitFailed ? kRed : kGreen);
1495 eve_line->SetLineWidth(1);
1499 eve_line->AddElement(eve_hits);
1510 if (track_list) parent->AddElement(track_list);
1511 if (eve_line) parent->AddElement(eve_line);
1512 if (eve_all_hits) parent->AddElement(eve_all_hits);
1514 if (track_list) gEve->AddElement(track_list);
1515 if (eve_line) gEve->AddElement(eve_line);
1516 if (eve_all_hits) gEve->AddElement(eve_all_hits);
1524 const PadRowLayout2D &layout = tpcModule.getLocalPadLayout();
1526 TEveElementList* eNode = 0;
1527 TEveQuadSet* ePad =
new TEveQuadSet(Form(
"Pad %i", pad1));
1528 TEveQuadSet* eNeighbour =
new TEveQuadSet(Form(
"Neighbour %i - %i", pad1, pad2));
1529 TEveStraightLineSet* eLine =
new TEveStraightLineSet(Form(
"Line %i", pad1));
1531 if (leftright ==
kLEFT) {
1532 eNode =
new TEveElementList(Form(
"Left %i", pad1));
1534 eNode =
new TEveElementList(Form(
"Right %i", pad1));
1538 Vector2D padPos = layout.getPadCenter(pad1);
1539 Vector2D neighbourPos = layout.getPadCenter(pad2);
1543 ePad->Reset(TEveQuadSet::kQT_FreeQuad, kTRUE, 32);
1545 ePad->SetOwnIds(kTRUE);
1547 eNeighbour->Reset(TEveQuadSet::kQT_FreeQuad, kTRUE, 32);
1548 eNeighbour->RefitPlex();
1549 eNeighbour->SetOwnIds(kTRUE);
1555 ePad->QuadColor(kYellow);
1561 eNeighbour->QuadColor(kRed);
1565 if (layout.getCoordinateType() == PadRowLayout2D::POLAR) {
1568 x = padPos[0]*cos(padPos[1]);
1569 y = padPos[0]*sin(padPos[1]);
1574 x = neighbourPos[0]*cos(neighbourPos[1]);
1575 y = neighbourPos[0]*sin(neighbourPos[1]);
1577 neighbourPos[0] = x;
1578 neighbourPos[1] = y;
1582 padPos[0], padPos[1], 1,
1583 neighbourPos[0], neighbourPos[1], 1
1585 eLine->SetLineColor(kCyan);
1589 toGlobal(&tpcModule, dynamic_cast<TEveElement*>(ePad));
1590 toGlobal(&tpcModule, dynamic_cast<TEveElement*>(eNeighbour));
1591 toGlobal(&tpcModule, dynamic_cast<TEveElement*>(eLine));
1595 eNode->AddElement(ePad);
1596 eNode->AddElement(eNeighbour);
1597 eNode->AddElement(eLine);
1600 parent->AddElement(eNode);
1602 gEve->AddElement(eNode);
1606 if (!strcmp(collectionType.c_str(), EVENT::LCIO::TRACKERHIT)) {
return kHIT;}
1607 else if (!strcmp(collectionType.c_str(), EVENT::LCIO::TRACKERPULSE)) {
return kPULSE;}
1608 else if (!strcmp(collectionType.c_str(), EVENT::LCIO::TRACK)) {
return kTRACK;}
1614 const PadRowLayout2D* layout = &aModule->getLocalPadLayout();
1615 Vector2D center = layout->getPadCenter(padIndex);
1622 pad.
height = layout->getPadHeight(padIndex);
1623 pad.
width = layout->getPadWidth(padIndex);
1630 switch (layout->getCoordinateType()) {
1631 case PadRowLayout2D::CARTESIAN:
1635 x1_min = center[0] - pad.
width / 2.;
1636 x1_max = center[0] + pad.
width / 2.;
1637 x2_min = center[1] - pad.
height / 2.;
1638 x2_max = center[1] + pad.
height / 2.;
1666 case PadRowLayout2D::POLAR:
1668 x1_min = center[0] - pad.
height / 2.;
1669 x1_max = center[0] + pad.
height / 2.;
1670 x2_min = center[1] - pad.
width / 2.;
1671 x2_max = center[1] + pad.
width / 2.;
1675 pad.
center_x = center[0] * cos(center[1]);
1676 pad.
center_y = center[0] * sin(center[1]);
1701 throw "Unknown coordinate type.";
1706 double angle = aModule->getAngle();
1707 const Vector2D offset = aModule->getOffset();
1708 Vector2D center = aModule->getPadCenter(padIndex);
1725 case PadRowLayout2D::CARTESIAN:
1730 case PadRowLayout2D::POLAR:
1731 pad.
center_x = center[0] * cos(center[1]);
1732 pad.
center_y = center[0] * sin(center[1]);
1735 throw "Unknown coordinate type.";
1741 double sinangle = sin(angle);
1742 double cosangle = cos(angle);
1775 const TPCModule &tpcModule =
tpcParameters->getModule(moduleID);
1776 const PadRowLayout2D &layout = tpcModule.getLocalPadLayout();
1778 std::vector<int> pads;
1784 nRow < layout.getNRows();
1788 const std::vector<int> &padsInRow = layout.getPadsInRow(nRow);
1791 std::vector<int>::const_iterator it = padsInRow.begin();
1792 it != padsInRow.end();
1796 pads.push_back(*it);
1809 const TPCModule &tpcModule =
tpcParameters->getModule(moduleID);
1810 const PadRowLayout2D &layout = tpcModule.getLocalPadLayout();
1815 Vector2D neighbourPos;
1822 TEveElementList* eParent = 0;
1824 if (leftright ==
kLEFT) {
1825 eParent =
new TEveElementList(
"Test getLeftNeighbour");
1827 eParent =
new TEveElementList(
"Test getRightNeighbour");
1833 std::vector<int>::const_iterator it = pads.begin();
1842 if (leftright ==
kLEFT)
1843 neighbour = layout.getLeftNeighbour(pad);
1845 neighbour = layout.getRightNeighbour(pad);
1847 padPos = layout.getPadCenter(pad);
1848 neighbourPos = layout.getPadCenter(neighbour);
1852 switch (layout.getCoordinateType()) {
1853 case PadRowLayout2D::CARTESIAN:
1855 pow(padPos[0] - neighbourPos[0], 2)
1856 + pow(padPos[1] - neighbourPos[1], 2)
1859 threshold = 1.5 * layout.getPadWidth(pad);
1863 case PadRowLayout2D::POLAR:
1866 + pow(neighbourPos[0], 2)
1867 - 2*padPos[0]*neighbourPos[0]*cos(padPos[1] - neighbourPos[1])
1870 threshold = 1.5 * padPos[0] * layout.getPadWidth(pad);
1879 if (distance > threshold)
1882 }
catch (gear::Exception e) {
1884 int rowNumber = layout.getRowNumber(*it);
1886 int firstPad = layout.getPadIndex(rowNumber, 0);
1887 int lastPad = firstPad + layout.getPadsInRow(rowNumber).size() - 1;
1892 (leftright ==
kLEFT)
1902 && (*it == firstPad)
1919 std::cout <<
"exception on pad " << pad << std::endl;
1925 gEve->AddElement(eParent);
1933 const TPCModule &tpcModule =
tpcParameters->getModule(moduleID);
1934 const PadRowLayout2D &layout = tpcModule.getLocalPadLayout();
1936 const std::vector<double> &planeExtent = layout.getPlaneExtent();
1937 std::vector<double> testExtent;
1939 std::vector<Vector2D> points;
1944 gRandom =
new TRandom(0);
1946 TRandom& r= *gRandom;
1951 testExtent.resize(4);
1952 testExtent[0] = planeExtent[0] - (planeExtent[1] - planeExtent[0]) / 10;
1953 testExtent[1] = planeExtent[1] + (planeExtent[1] - planeExtent[0]) / 10;
1954 testExtent[2] = planeExtent[2] - (planeExtent[3] - planeExtent[2]) / 10;
1955 testExtent[3] = planeExtent[3] + (planeExtent[3] - planeExtent[2]) / 10;
1964 for (
int i = 0; i < 25; i++) {
1965 points.push_back(Vector2D(
1967 r.Uniform(testExtent[2], testExtent[3])
1971 for (
int i = 0; i < 100; i++) {
1972 points.push_back(Vector2D(
1973 (planeExtent[0] + planeExtent[1]) / 2,
1974 r.Uniform(planeExtent[2], planeExtent[3])
1978 for (
int i = 0; i < 25; i++) {
1979 points.push_back(Vector2D(
1981 r.Uniform(testExtent[2], testExtent[3])
1987 for (
int i = 0; i < 25; i++) {
1988 points.push_back(Vector2D(
1989 r.Uniform(testExtent[0], testExtent[1]),
1994 for (
int i = 0; i < 100; i++) {
1995 points.push_back(Vector2D(
1996 r.Uniform(planeExtent[0], planeExtent[1]),
1997 (planeExtent[2] + planeExtent[3]) / 2
2001 for (
int i = 0; i < 25; i++) {
2002 points.push_back(Vector2D(
2003 r.Uniform(testExtent[0], testExtent[1]),
2010 for (
int i = 0; i < 100; i++) {
2011 points.push_back(Vector2D(
2012 r.Uniform(testExtent[0], testExtent[1]),
2013 r.Uniform(testExtent[2], testExtent[3])
2019 }
catch (std::out_of_range e) {
2020 std::cout << e.what() << std::endl;
2027 TEveElementList* parent =
new TEveElementList(
"Test getNearestPad (module)");
2029 const TPCModule &tpcModule =
tpcParameters->getModule(moduleID);
2030 const PadRowLayout2D &layout = tpcModule.getLocalPadLayout();
2032 std::stringstream tooltip;
2041 std::vector<Vector2D>::const_iterator it = points.begin();
2047 padIndex = layout.getNearestPad((*it)[0], (*it)[1]);
2049 drawNearestPad(tpcModule, (TEveElement*) parent, padIndex, *it, i);
2052 gEve->AddElement(parent);
2060 const std::vector<double> &planeExtent =
tpcParameters->getPlaneExtent();
2061 std::vector<double> testExtent;
2063 std::vector<Vector2D> points;
2068 gRandom =
new TRandom(0);
2070 TRandom& r= *gRandom;
2075 testExtent.resize(4);
2076 testExtent[0] = planeExtent[0] - (planeExtent[1] - planeExtent[0]) / 10;
2077 testExtent[1] = planeExtent[1] + (planeExtent[1] - planeExtent[0]) / 10;
2078 testExtent[2] = planeExtent[2] - (planeExtent[3] - planeExtent[2]) / 10;
2079 testExtent[3] = planeExtent[3] + (planeExtent[3] - planeExtent[2]) / 10;
2088 for (
int i = 0; i < 5000; i++) {
2089 points.push_back(Vector2D(
2090 r.Uniform(testExtent[0], testExtent[1]),
2091 r.Uniform(testExtent[2], testExtent[3])
2097 }
catch (std::out_of_range e) {
2098 std::cout << e.what() << std::endl;
2105 TEveElementList* parent =
new TEveElementList(
"Test getNearestPad (global)");
2107 const TPCModule *tpcModule = 0;
2115 std::vector<Vector2D>::const_iterator it = points.begin();
2121 GlobalPadIndex gpi =
tpcParameters->getNearestPad((*it)[0], (*it)[1]);
2124 local = tpcModule->globalToLocal((*it)[0], (*it)[1]);
2126 drawNearestPad(*tpcModule, (TEveElement*) parent, gpi.getPadIndex(), local, i);
2129 gEve->AddElement(parent);
2135 TEveTrans* transformation = NULL;
2137 const Vector2D* offset = &aModule->getOffset();
2138 double angle = aModule->getAngle();
2139 double x_pos, y_pos = 0.;
2142 switch (aModule->getTPCCoordinateType()) {
2143 case PadRowLayout2D::CARTESIAN:
2144 x_pos = (*offset)[0];
2145 y_pos = (*offset)[1];
2147 case PadRowLayout2D::POLAR:
2148 x_pos = (*offset)[0] * cos((*offset)[1]);
2149 y_pos = (*offset)[0] * sin((*offset)[1]);
2152 throw "Unknown coordinate type.";
2155 transformation = element->PtrMainTrans();
2156 transformation->SetRotByAngles(angle, 0., 0.);
2157 transformation->Move3PF(x_pos, y_pos, z_pos);
2161 transformation = NULL;
2182 const std::vector<double>& extent =
tpcParameters->getPlaneExtent();
2186 case PadRowLayout2D::CARTESIAN:
2191 double rMaxSquare = extent[0]*extent[0] + extent[2]*extent[2];
2193 double rSquare = (extent[0]*extent[0] + extent[3]*extent[3]);
2194 if ( rSquare > rMaxSquare ) rMaxSquare = rSquare;
2196 rSquare = (extent[1]*extent[1] + extent[2]*extent[2]);
2197 if ( rSquare > rMaxSquare ) rMaxSquare = rSquare;
2199 rSquare = (extent[1]*extent[1] + extent[3]*extent[3]);
2200 if ( rSquare > rMaxSquare ) rMaxSquare = rSquare;
2206 case PadRowLayout2D::POLAR:
2212 throw gear::Exception(
"Unknown coordinate type in TPCParameters");
void drawModule(gear::TPCModule *aModule, TEveElement *parent=NULL)
TEveElement * drawTracks(IMPL::LCCollectionVec *tracks, TEveElement *parent=NULL)
void testNearestPadGlobal()
void drawPadBox(const PadMetric &pad, float z_front, float z_back, TEveBoxSet *bs)
std::map< std::string, TGeoMedium * > media
void toGlobal(const gear::TPCModule *aModule, TEveElement *element)
Transform a TEveElement to the global coordinate system of the detector using OpenGL matrix transform...
TEveElement * drawHits(IMPL::LCCollectionVec *hits, int wantTooltip=true)
void drawPadQuad(const PadMetric &pad, float z, TEveQuadSet *qs)
void drawNearestPad(const gear::TPCModule &aModule, TEveElement *parent, int padIndex, const gear::Vector2D &position, int i)
The PadMetric is used for holding the geometric properties of a pad.
float corners_cartesian[8]
void testLeftRightNeighbour(int moduleID=0)
void testNearestPad(int moduleID=0)
std::map< std::string, int > options
float maxDriftLength
This is used for the z-position of the endcap/modules.
void drawCircularPolygon(TEveStraightLineSet *ls, float r, int nDivisions, float z)
void drawTwoConnectingPads(const gear::TPCModule &aModule, TEveElement *parent, int pad1, int pad2, LeftRight_enum leftright)
std::map< std::string, TGeoMaterial * > materials
float outerFieldCageRadius
Radius of the outer field cage cylinder.
TEveElement * drawPulses(IMPL::LCCollectionVec *pulses)
void updateGearMgr(gear::GearMgr *aGearMgr)
A function to update the vistpc with information from a new gear file.
std::map< std::string, TGeoVolume * > volumes
void getGlobalPadMetric(const gear::TPCModule *aModule, const int padIndex, PadMetric &pad)
Get the pad geometric properties in the global coordinate system of the detector. ...
VisTPC(gear::GearMgr *aGearMgr=0)
void testNearestPadGlobalWithPoints(const std::vector< gear::Vector2D > &points)
const LCCollectionType_enum getCollectionType(const std::string &)
void drawModules(TEveElement *parent=NULL)
gear::TPCParameters const * tpcParameters
void testLeftRightNeighbourWithPads(int moduleID, const std::vector< int > &pads, LeftRight_enum leftright)
float innerFieldCageRadius
Radius of the inner field cage cylinder.
void getLocalPadMetric(const gear::TPCModule *aModule, const int padIndex, PadMetric &pad)
Get the pad geometric properties in the local coordinate system of the module.
void drawHit(EVENT::TrackerHit *hit, TEvePointSet *parent, int wantTooltip=false)
void drawEvent(EVENT::LCEvent *event, std::vector< std::string > &selectedEntries, TEveElement *parent=NULL, const char *name="Event")
void drawPads(gear::TPCModule *aModule, TEveElement *parent=NULL)
void testNearestPadWithPoints(int moduleID, const std::vector< gear::Vector2D > &points)