16 #include <FairLogger.h>
18 #include <Math/Point3D.h>
19 #include <TAttMarker.h>
21 #include <TEveBrowser.h>
22 #include <TEveEventManager.h>
23 #include <TEveGeoNode.h>
24 #include <TEveManager.h>
25 #include <TEvePointSet.h>
26 #include <TEveViewer.h>
27 #include <TEveWindow.h>
28 #include <TGLCamera.h>
29 #include <TGLViewer.h>
31 #include <TGeoManager.h>
32 #include <TGeoVolume.h>
37 #include <TRootEmbeddedCanvas.h>
40 #include <TVirtualPad.h>
41 #include <TVirtualX.h>
54 constexpr
auto cRED =
"\033[1;31m";
57 constexpr
auto cGREEN =
"\033[1;32m";
58 constexpr
auto cBLUE =
"\033[1;34m";
65 throw "AtViewerManager must be initialized before creating tabs!";
94 std::cout <<
" ===== AtTabMain::Init =====" << std::endl;
105 gStyle->SetPalette(55);
107 std::cout <<
" AtTabMain::Init : Initialization complete! "
111 void AtTabMain::ExpandNumPatterns(
int num)
116 LOG(info) <<
"Expanding number of patterns to " << num <<
" from " <<
fPatternHitSets.size() << std::endl;
120 auto trackSet = std::make_unique<TEvePointSet>(TString::Format(
"Track_%d", trackID));
121 trackSet->SetDestroyOnZeroRefCnt(
false);
131 std::vector<Color_t> colors = {kBlue - 7, kGreen - 8, kOrange, kViolet, kYellow, kTeal - 6,
132 kMagenta + 1, kBlue, kViolet, kYellow, kCyan};
133 if (i < colors.size()) {
144 UpdateEventElements();
147 UpdatePatternEventElements();
155 gEve->Redraw3D(
false);
159 void AtTabMain::DrawPadPlane()
172 gStyle->SetOptStat(0);
173 gStyle->SetPalette(103);
177 void AtTabMain::DrawPadWave()
180 sprintf(name,
"fPadWave_DT%i",
fTabId);
181 fPadWave =
new TH1I(name, name, 512, 0, 511);
189 auto fEvent = GetFairRootInfo<AtEvent>();
190 if (fEvent ==
nullptr) {
191 std::cout <<
"CRITICAL ERROR: Event missing for TabMain. Aborting draw." << std::endl;
195 std::ofstream dumpEvent;
196 dumpEvent.open(fileName);
197 dumpEvent <<
" Event ID : " << fEvent->GetEventID() << std::endl;
199 for (
auto &hit : fEvent->GetHits())
200 dumpEvent << hit->GetPosition().X() <<
"," << hit->GetPosition().Y() <<
"," << hit->GetPosition().Z() <<
","
201 << hit->GetCharge() << std::endl;
212 void AtTabMain::UpdatePatternEventElements()
217 auto fPatternEvent = GetFairRootInfo<AtPatternEvent>();
218 if (fPatternEvent ==
nullptr) {
219 LOG(debug) <<
"Cannot update AtPatternEvent elements: no event availible";
224 auto &tracks = fPatternEvent->GetTrackCand();
225 ExpandNumPatterns(tracks.size());
229 for (
int i = 0; i < tracks.size(); ++i) {
230 if (tracks[i].GetPattern() ==
nullptr)
241 auto pattern = tracks[i].GetPattern()->GetEveElement();
242 pattern->SetDestroyOnZeroRefCnt(
false);
248 void AtTabMain::UpdateEventElements()
250 auto fEvent = GetFairRootInfo<AtEvent>();
251 if (fEvent ==
nullptr) {
252 LOG(debug) <<
"Cannot update AtEvent elements: no event availible";
256 auto &hits = fEvent->GetHits();
257 LOG(info) <<
cBLUE <<
" Number of hits : " << hits.size() <<
" in " << fEvent->GetEventID() <<
cNORMAL;
262 void AtTabMain::UpdatePadPlane()
270 LOG(debug) <<
"Updating pad plane ";
272 auto fEvent = GetFairRootInfo<AtEvent>();
273 if (fEvent ==
nullptr) {
274 LOG(debug) <<
"Cannot fill pad plane histogram: no event availible";
277 auto &hits = fEvent->GetHits();
279 for (
auto &hit : hits) {
280 int padMultiHit = GetFairRootInfo<AtEvent>()->GetHitPadMult(hit->GetPadNum());
283 auto position = hit->GetPosition();
284 fPadPlane->Fill(position.X(), position.Y(), hit->GetCharge());
297 Int_t nHits = hits.size();
300 hitSet.SetOwnIds(
true);
303 for (Int_t iHit = 0; iHit < nHits; iHit++) {
305 auto &hit = *hits.at(iHit);
306 Int_t PadMultHit = 0;
307 if (GetFairRootInfo<AtEvent>())
308 PadMultHit = GetFairRootInfo<AtEvent>()->GetHitPadMult(hit.GetPadNum());
313 auto position = hit.GetPosition();
315 hitSet.SetNextPoint(position.X() / 10., position.Y() / 10., position.Z() / 10.);
316 hitSet.SetPointId(
new TNamed(Form(
"Hit %d", iHit),
""));
319 gEve->ElementChanged(&hitSet);
327 hitSet.SetOwnIds(
true);
329 for (Int_t i = 0; i < nHits; i++) {
336 auto position = hit.GetPosition();
337 hitSet.SetNextPoint(position.X() / 10., position.Y() / 10., position.Z() / 10.);
338 hitSet.SetPointId(
new TNamed(Form(
"Hit %d", i),
""));
341 gEve->ElementChanged(&hitSet);
344 bool AtTabMain::DrawWave(Int_t PadNum)
347 auto fRawEvent = GetFairRootInfo<AtRawEvent>();
350 if (fRawEvent ==
nullptr) {
354 AtPad *fPad = fRawEvent->GetPad(PadNum);
355 if (fPad ==
nullptr) {
356 LOG(error) <<
"Pad in event is null!";
359 LOG(debug) <<
"Drawing pad " << fPad->
GetPadNum();
361 auto adc = fPad->
GetADC();
363 for (Int_t i = 0; i < 512; i++) {
377 TEveWindowPack *pack =
nullptr;
380 pack = slot->MakePack();
381 pack->SetElementName(
"Main");
382 pack->SetHorizontal();
384 pack->SetShowTitleBar(kFALSE);
386 pack->NewSlot()->MakeCurrent();
387 TEveViewer *view3D = gEve->SpawnNewViewer(
"3D View",
"");
388 view3D->AddScene(gEve->GetGlobalScene());
389 view3D->AddScene(gEve->GetEventScene());
392 slot = pack->NewSlot();
393 TEveWindowPack *pack2 = slot->MakePack();
394 pack2->SetShowTitleBar(kFALSE);
395 pack2->SetVertical();
396 slot = pack2->NewSlot();
397 slot->StartEmbedding();
400 slot->StopEmbedding();
403 slot = pack2->NewSlotWithWeight(1.5);
404 auto *ecvs =
new TRootEmbeddedCanvas();
405 TEveWindowFrame *frame = slot->MakeFrame(ecvs);
406 frame->SetElementName(
"AtTPC Pad Plane");
407 pack->GetEveFrame()->SetShowTitleBar(kFALSE);
418 TGeoNode *geoNode = gGeoManager->GetTopNode();
421 Int_t nNodes = 10000;
422 auto *topNode =
new TEveGeoTopNode(gGeoManager, geoNode, option, level, nNodes);
423 gEve->AddGlobalElement(topNode);
425 Int_t transparency = 80;
426 gGeoManager->GetVolume(
"drift_volume")->SetTransparency(transparency);
427 gEve->FullRedraw3D(kTRUE);
430 gEve->GetBrowser()->GetTabRight()->SetTab(1);
432 gEve->Redraw3D(
true,
true);
434 TGLViewer *dfViewer = gEve->GetDefaultGLViewer();
435 dfViewer->CurrentCamera().RotateRad(-.7, 0.5);
444 if (gPad->GetEvent() != 11)
446 auto *h =
dynamic_cast<TH2Poly *
>(gPad->GetSelected());
450 gPad->GetCanvas()->FeedbackMode(
true);
452 int pyold = gPad->GetUniqueID();
453 int px = gPad->GetEventX();
454 int py = gPad->GetEventY();
455 float uxmin = gPad->GetUxmin();
456 float uxmax = gPad->GetUxmax();
457 int pxmin = gPad->XtoAbsPixel(uxmin);
458 int pxmax = gPad->XtoAbsPixel(uxmax);
460 gVirtualX->DrawLine(pxmin, pyold, pxmax, pyold);
461 gVirtualX->DrawLine(pxmin, py, pxmax, py);
462 gPad->SetUniqueID(py);
463 Float_t upx = gPad->AbsPixeltoX(px);
464 Float_t upy = gPad->AbsPixeltoY(py);
465 Double_t x = gPad->PadtoX(upx);
466 Double_t
y = gPad->PadtoY(upy);
467 Int_t bin = h->FindBin(x,
y);
468 const char *bin_name = h->GetBinName(bin);
469 LOG(debug) <<
" ==========================";
470 LOG(debug) <<
" Bin number selected : " << bin <<
" Bin name :" << bin_name;
473 if (tmap ==
nullptr) {
474 LOG(fatal) <<
"AtMap not set! Pass a valid map to the constructor of AtViewerManager!";
476 Int_t tPadNum = tmap->
BinToPad(bin);
477 LOG(debug) <<
" Bin : " << bin <<
" to Pad : " << tPadNum;
478 LOG(debug) <<
" Electronic mapping: " << tmap->
GetPadRef(tPadNum);
479 LOG(debug) <<
" Raw Event Pad Num " << tPadNum;