GGS(GenericGEANT4Simulation)Software  2.7.0
 All Data Structures Namespaces Files Functions Variables Typedefs Macros
SetDetectorHits.cpp
1 /*
2  * SetDetectorHits.cpp
3  *
4  * Created on: 27 Nov 2017
5  * Author: Valerio Formato
6  */
7 
8 /*
9  * This function reads hits for a generic detector and lights the corresponding geometry shapes
10  * depending on the hit type. shapes are color-coded and sized according to energy
11  * release (w.r.t. maximum energy released in a cell for this event).
12  */
13 
14 #include "TEveBrowser.h"
15 #include "TEveScene.h"
16 #include "TEveTrans.h"
17 #include "TGButton.h"
18 #include "TGTab.h"
19 #include "TGeoBBox.h"
20 #include "TGeoNode.h"
21 #include "TSystem.h"
22 
23 #include "utils/GGSSmartLog.h"
24 
25 #include "application/Application.h"
26 #include "application/gui/MainWindow.h"
27 
28 void MainWindow::SetDetectorHits(TString det, GGSTHitsReader *reader) {
29  static const std::string routineName("MainWindow::SetDetectorHits");
30 
31  COUT(DEBUG) << "We are in SetDetectorHits for hit " << det << ENDL;
32 
33  EDApplication *thisApp = (EDApplication *)gApplication;
34 
35  // READING hits
36  double eMax = 0;
37  int nHits = reader->GetNHits(det);
38  COUT(DEBUG) << nHits << " " << det << " hits " << ENDL;
39  if (nHits == 0)
40  return;
41 
42  std::string volName, volPath;
43  Float_t *volPos;
44  GGSTIntHitBase *thisHit = nullptr;
45 
46  for (int iHit = 0; iHit < nHits; iHit++) {
47  thisHit = reader->GetHit(det, iHit);
48  if (thisHit->eDep > eMax)
49  eMax = thisHit->eDep;
50  }
51 
52  COUT(DEBUG) << "_DetectorHitMap has " << _DetectorHitMap.size() << " entries" << ENDL;
53  auto _dhitIter = _DetectorHitMap.find(det.Data());
54  if (_dhitIter == _DetectorHitMap.end()) {
55  COUT(ERROR) << "container for detector " << det << " not found!!!" << ENDL;
56  return;
57  }
58  DetectorHit *_dhit = _dhitIter->second;
59 
60  auto thisTEveGeoShapeMap = *(_dhit->GetTEveGeoShapeMap());
61  COUT(DEBUG) << "map for detector " << det << " has " << thisTEveGeoShapeMap.size() << " entries" << ENDL;
62  COUT(DEBUG) << "Threshold set at " << _dhit->GetThreshold() << " GeV" << ENDL;
63 
64  for (int iHit = 0; iHit < nHits; iHit++) {
65  thisHit = reader->GetHit(det, iHit);
66  if (thisHit->eDep < _dhit->GetThreshold() || thisHit->eDep == 0)
67  continue;
68  volPos = const_cast<float *>(thisHit->GetVolumePosition());
69  TGeoNode *tempnode = thisApp->GetGeoManager()->FindNode(volPos[0], volPos[1], volPos[2]);
70  volName = tempnode->GetName();
71  volPath = thisApp->GetGeoManager()->GetNodePath(tempnode);
72 
73  COUT(DEBUG) << volPos[0] << " " << volPos[1] << " " << volPos[2] << ENDL;
74  COUT(DEBUG) << volPath << " " << thisHit->eDep << " " << ENDL;
75 
76  TEveGeoShape *tempshape = thisTEveGeoShapeMap[volPath];
77 
78  switch (_dhit->GetType()) {
79  // Hit colorcoded and transparency coded
80  case DetectorHit::kColorCodedScaleHit: {
81  _dhit->GetPalette()->Rebin(0, eMax); // change this
82 
83  double scale = 0.25 + 0.75 * sqrt(2 * thisHit->eDep / eMax);
84  if (scale > 1)
85  scale = 1;
86  tempshape->RefMainTrans().SetScale(scale, scale, scale);
87 
88  double tscale = 0.5 + 0.5 * sqrt(2 * thisHit->eDep / eMax);
89  if (tscale > 1)
90  tscale = 1;
91  tempshape->SetMainTransparency(100 * (1 - tscale) + 1);
92 
93  tempshape->SetMainColor(_dhit->GetPalette()->GetValueColor2(thisHit->eDep));
94  break;
95  }
96 
97  // Hit opaque and colorcoded
98  case DetectorHit::kColorCodedHit: {
99  _dhit->GetPalette()->Rebin(0, eMax); // change this
100 
101  double tscale = 0.5 + 0.5 * sqrt(2 * thisHit->eDep / eMax);
102  if (tscale > 1)
103  tscale = 1;
104  tempshape->SetMainTransparency(100 * (1 - tscale) + 1);
105 
106  tempshape->RefMainTrans().SetScale(1, 1, 1);
107 
108  tempshape->SetMainColor(_dhit->GetPalette()->GetValueColor2(thisHit->eDep));
109  break;
110  }
111 
112  // Hit transparency coded
113  case DetectorHit::kOpacityHit: {
114  tempshape->SetMainColor(_dhit->GetColor());
115  tempshape->SetMainTransparency(85 * (1 - thisHit->eDep / eMax));
116  tempshape->RefMainTrans().SetScale(1, 1, 1);
117  break;
118  }
119 
120  // Draw a point, not really supported for now...
121  case DetectorHit::kClusterHit: {
122  tempshape->SetMainColor(_dhit->GetColor());
123  break;
124  }
125 
126  default: { // kFullHit
127  tempshape->SetMainColor(_dhit->GetColor());
128  tempshape->SetMainTransparency(0);
129  tempshape->RefMainTrans().SetScale(1, 1, 1);
130  break;
131  }
132  }
133 
134  tempshape->IncDenyDestroy();
135  _dhit->GetTEveElementList()->AddElement(tempshape);
136  }
137 }
Class for reading output of GGSHitsAction.
GGSTIntHitBase * GetHit(const char *detector, unsigned int iHit)
Get the specified hit.
const Float_t * GetVolumePosition()
Retrieves the position of the volume associated to the hit.
Definition: GGSTHits.h:289
#define ENDL
Definition: GGSSmartLog.h:105
#define COUT(level)
Smart log macro. It writes on stdout only if the specified verbosity level is lesser than the maximum...
Definition: GGSSmartLog.h:76
Float_t eDep
Deposited energy (transient).
Definition: GGSTHits.h:222
Int_t GetNHits(const char *detector)
Gets the number of hits for the specified detector.
Base class for storing G4 integrated hits.
Definition: GGSTHits.h:218