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