20#include <TGeoManager.h>
25#include "BesVisLib/TofROOTGeo.h"
26#include "Identifier/TofID.h"
27#include "BesVisLib/BesEvent.h"
28#include "BesVisLib/BesView.h"
29#include "RawEvent/RawDataUtil.h"
38 for (
int part = 0; part < m_kPart; part++) {
39 for (
int layer = 0; layer < m_kLayerBr; layer++) {
40 m_NodeAl[part][layer] = 0;
41 m_NodeScin[part][layer] = 0;
42 for (
int scin = 0; scin < m_kScinBr; scin++) {
43 m_NodePVF[part][layer][scin] = 0;
44 m_PhysicalScin[part][layer][scin] = 0;
45 m_Tof2DScin[part][layer][scin] = 0;
52 m_ScinColor = kYellow;
80 cout <<
"TofROOTGeo::Init2DGeometry, ROOT Geometry not Initialized yet!" << endl;
85 Double_t local[3] = {0.0, 0.0, 0.0};
86 Double_t master[3] = {0.0, 0.0, 0.0};
93 for (Int_t part = 0; part < m_kPart; part++) {
94 for (Int_t layer = 0; layer <
GetLayerNb(part); layer++) {
95 for (
int scin = 0; scin <
GetScinNb(part); scin++) {
98 name = TString(
"Tof Part 1");
105 if (part == 0) name = TString(
"EastEc");
106 else if (part == 2) name = TString(
"WestEc");
107 name = TString(
"Tof Part ");
112 TGeoArb8 *scinShape = (TGeoArb8*)scinPhyNode->GetShape();
113 Double_t *localArb8Point, masterArb8Point[24];
114 localArb8Point = scinShape->GetVertices();
116 for (Int_t i = 0; i < 8; i++) {
117 local[0] = localArb8Point[2*i];
118 local[1] = localArb8Point[2*i+1];
119 if (i < 4) local[2] = scinShape->GetDz() * (-1.0);
120 else local[2] = scinShape->GetDz();
123 scinPhyNode->GetMatrix(-1*scinPhyNode->GetLevel())->LocalToMaster(local, &master[0]);
126 for (Int_t j = 0; j < 3; j++) {
127 masterArb8Point[3*i+j] = master[j];
131 m_Tof2DScin[part][layer][scin] =
new Tof2DScin(name, name, 8, &masterArb8Point[0], part);
142 if (!m_Tof) std::cout <<
"m_Tof = 0" << std::endl;
144 for (
int part = 0; part < m_kPart; part++) {
145 for (
int layer = 0; layer <
GetLayerNb(part); layer++) {
146 std::stringstream osnameAl;
147 if (part == 1) osnameAl <<
"pv_" <<
"logical" <<
"AlBr" << layer+1 <<
"_0";
148 else if (part == 0) osnameAl <<
"pv_" <<
"logical" <<
"AlEcEast" <<
"_0";
149 else osnameAl <<
"pv_" <<
"logical" <<
"AlEcWest" <<
"_0";
150 m_NodeAl[part][layer] =
GetNode( osnameAl.str() );
152 std::stringstream osnameScin;
153 if (part == 1) osnameScin <<
"pv_" <<
"logical" <<
"ScinBr" << layer+1 <<
"_0";
154 else if (part == 0) osnameScin <<
"pv_" <<
"logical" <<
"ScinEcEast" <<
"_0";
155 else osnameScin <<
"pv_" <<
"logical" <<
"ScinEcWest" <<
"_0";
157 m_NodeScin[part][layer] =
GetNode( osnameScin.str() );
159 for (
int scin = 0; scin <
GetScinNb(part); scin++) {
160 std::stringstream osnamePVF;
162 osnamePVF <<
"pv_" <<
"logicalPVFBr"<< layer+1 <<
"_" << (2*m_kScinBr*3 - 1) - (layer*m_kScinBr + scin)*3;
164 else if (part == 2) {
165 osnamePVF <<
"pv_" <<
"logicalPVFEcWest" <<
"_" << (2*m_kScinEc - 1) - scin*2;
168 else if (part == 0) {
169 osnamePVF <<
"pv_" <<
"logicalPVFEcEast" <<
"_" << (2*m_kScinEc - 1) - scin*2;
171 m_NodePVF[part][layer][scin] =
GetNode( osnamePVF.str() );
177 for (
int part = 0; part < m_kPart; part++) {
179 if (part == 1) ipart = 2;
180 if (part ==2 ) ipart = 1;
181 for (
int layer = 0; layer <
GetLayerNb(part); layer++) {
182 for (
int scin = 0; scin <
GetScinNb(part); scin++) {
194 iNode = (2*m_kScinEc - 1) - scin*2;
197 iNode = (2*m_kScinBr*3 - 1) - (layer*m_kScinBr + scin)*3;
200 m_NodePVF[part][layer][scin] = m_Tof->GetNode( ipart )->GetVolume()->GetNode(iNode);
202 m_NodeAl[part][layer] = m_NodePVF[part][layer][0]->GetVolume()->GetNode(0);
204 m_NodeScin[part][layer] = m_NodeAl[part][layer]->GetVolume()->GetNode(0);
218 m_Tof->SetLineColor(m_TofColor);
219 m_Tof->SetVisibility(0);
221 for (
int part = 0; part < m_kPart; part++) {
224 for (
int layer = 0; layer <
GetLayerNb(part); layer++) {
228 GetVolumeAl(part, layer)->SetLineColor(m_ScinColor);
254 m_Tof->SetLineColor(m_TofColor);
255 m_Tof->SetVisibility(0);
257 for (
int part = 0; part < m_kPart; part++) {
258 for (
int layer = 0; layer <
GetLayerNb(part); layer++) {
262 GetVolumeAl(part, layer)->SetLineColor(m_ScinColor);
355 if (gGeoManager == 0) std::cout <<
"Create gGeoManager first" << std::endl;
356 TGeoNode *
bes = gGeoManager->GetTopNode();
359 TGeoNode *nodeTof =
bes->GetDaughter(1);
360 for (
int part = 0; part < m_kPart; part++) {
370 if (part == 1) ipart = 2;
371 if (part ==2 ) ipart = 1;
373 nodePart = nodeTof->GetVolume()->GetNode(ipart);
375 for (
int layer = 0; layer <
GetLayerNb(part); layer++) {
376 TGeoNode *nodeAl =
GetAl(part, layer);
377 TGeoNode *nodeScin =
GetScin(part, layer);
378 for (
int scin = 0; scin <
GetScinNb(part); scin++) {
379 TGeoNode *nodePVF =
GetPVF(part, layer, scin);
380 m_PhysicalScin[part][layer][scin] = gGeoManager->MakePhysicalNode( TString(
"/") +
bes->GetName() +
381 TString(
"/") + nodeTof->GetName() +
382 TString(
"/") + nodePart->GetName() +
383 TString(
"/") + nodePVF->GetName() +
384 TString(
"/") + nodeAl->GetName() +
385 TString(
"/") + nodeScin->GetName() );
388 m_PhysicalScin[part][layer][scin]->SetVisibility(0);
389 m_PhysicalScin[part][layer][scin]->SetIsVolAtt(kFALSE);
390 m_PhysicalScin[part][layer][scin]->SetLineColor(m_ScinColor);
402 if (gPad) view = (
BesView*)gPad->GetView();
406 for (
int part = 0; part < m_kPart; part++) {
407 for (
int layer = 0; layer <
GetLayerNb(part); layer++) {
408 for (
int scin = 0; scin <
GetScinNb(part); scin++) {
409 TGeoPhysicalNode *phyNode = 0;
412 phyNode->SetVisibility(0);
430 for (
int i = 0; i <
m_HitsArray->GetEntries(); i++) {
431 TGeoPhysicalNode *phyNode = (TGeoPhysicalNode*)
m_HitsArray->At(i);
434 phyNode->SetVisibility(0);
443 aScin->
AddInfo(aScin->GetTitle());
451 for (
int i = 0; i < m_TofDigiCol->GetEntries(); i++) {
465 TGeoPhysicalNode *phyNode = 0;
472 aScin = m_Tof2DScin[part][layer][scin];
478 aScin->
AddInfo(aScin->GetTitle());
479 sprintf(
data,
"time1 = %-.3f ns, charge1 = %-.3f MeV",
time, charge);
483 sprintf(
data,
"time2 = %-.3f ns, charge2 = %-.3f MeV",
time, charge);
485 sprintf(
data,
"Fired");
512 if (gPad) view = (
BesView*)gPad->GetView();
517 phyNode->SetVisibility(0);
523 phyNode->SetVisibility(1);
532 if (gPad) view = (
BesView*)gPad->GetView();
534 for (
int i = 0; i <
m_HitsArray->GetEntries(); i++) {
535 TGeoPhysicalNode *phyNode = (TGeoPhysicalNode*)
m_HitsArray->At(i);
542 phyNode->SetVisibility(1);
543 phyNode->SetLineColor(kGreen);
547 phyNode->SetVisibility(0);
562 int nScin = m_kScinBr;
563 if (part != 1) nScin = m_kScinEc;
570 int nLayer = m_kLayerBr;
571 if (part != 1) nLayer = m_kLayerEc;
596 std::stringstream osname;
598 osname <<
"logicalBrTof";
601 osname <<
"logicalEcTofWest";
604 osname <<
"logicalEcTofEast";
616 std::stringstream osname;
618 osname <<
"logical" <<
"PVFEcEast";
621 osname <<
"logical" <<
"PVFEcWest";
625 osname <<
"logical" <<
"PVFBr" << layer+1;
635 std::stringstream osname;
637 osname <<
"logical" <<
"AlEcEast";
640 osname <<
"logical" <<
"AlEcWest";
644 osname <<
"logical" <<
"AlBr" << layer+1;
654 std::stringstream osname;
656 osname <<
"logical" <<
"ScinEcEast";
659 osname <<
"logical" <<
"ScinEcWest";
663 osname <<
"logical" <<
"ScinBr" << layer+1;
673 std::stringstream osname;
674 if (part == 0 || part == 2) {
675 osname <<
"logical" <<
"BucketEc";
679 osname <<
"logical" <<
"BucketBr" << layer+1;
689 if (m_NodePVF[part][layer][scin] != 0) {
690 return m_NodePVF[part][layer][scin];
693 std::cout <<
"Node: " <<
"Part" << part <<
"Layer" << layer <<
"PVF" << scin <<
" not found" << std::endl;
697 return m_NodePVF[part][layer][scin];
703 if (m_NodeAl[part][layer] != 0) {
704 return m_NodeAl[part][layer];
707 std::cout <<
"Node: " <<
"Part" << part <<
"Layer" << layer <<
"Al" <<
" not found" << std::endl;
711 return m_NodeAl[part][layer];
717 if (m_NodeScin[part][layer] != 0) {
718 return m_NodeScin[part][layer];
721 std::cout <<
"Node: " <<
"Part" << part <<
"Layer" << layer <<
"Scin" <<
" not found" << std::endl;
725 return m_NodeScin[part][layer];
751 if (m_PhysicalScin[part][layer][scin] != 0) {
752 return m_PhysicalScin[part][layer][scin];
755 std::cout <<
"PhysicalNode: " <<
"Part"
756 << part <<
"Layer" << layer <<
"Scin"
757 << scin <<
" not found" << std::endl;
765 if (m_Tof2DScin[part][layer][scin])
return m_Tof2DScin[part][layer][scin];
772 for (Int_t part = 0; part < m_kPart; part++) {
773 for (Int_t layer = 0; layer <
GetLayerNb(part); layer++) {
774 for (
int scin = 0; scin <
GetScinNb(part); scin++) {
783 cout <<
"TofROOTGeo::GetPart, this scintillator physical node does not exist!" << endl;
790 TString opt = option;
793 if (!
m_2DGeoInit) cout <<
"TofROOTGeo::Draw2D(), 2D Geometry not initialized!" << endl;
795 if (!view) cout <<
"TofROOTGeo::Draw(), BesView not found" << endl;
802 for (Int_t part = m_kPart-1; part >= 0; part--) {
803 for (Int_t layer = 0; layer <
GetLayerNb(part); layer++) {
804 for (
int scin = 0; scin <
GetScinNb(part); scin++) {
806 if (m_Tof2DScin[part][layer][scin]) {
809 m_Tof2DScin[part][layer][scin]->
SetFired(
false);
813 m_Tof2DScin[part][layer][scin]->
Draw(scinOpt);
826 if (!view) cout <<
"TofROOTGeo::DrawHits(), BesView not found" << endl;
836 for (Int_t part = m_kPart-1; part >= 0; part--) {
837 for (Int_t layer = 0; layer <
GetLayerNb(part); layer++) {
838 for (
int scin = 0; scin <
GetScinNb(part); scin++) {
839 if (m_Tof2DScin[part][layer][scin]) {
847 for (
int i = 0; i < m_TofDigiCol->GetEntries(); i++) {
855 Double_t charge = Double_t(aTofDigi->
getChargeChannel()) / TOF_CHARGE_FACTOR;
859 aScin = m_Tof2DScin[part][layer][scin];
R__EXTERN BesEvent * gEvent
const TObjArray * GetTofDigiCol() const
Bool_t GetVisTofHitsWest()
Bool_t GetVisTofHitsGlobal()
Bool_t GetVisTofHitsBarrel()
Bool_t GetVisTofHitsEast()
static double TofTime(unsigned int timeChannel)
static double TofCharge(unsigned int chargeChannel)
TGeoNode * GetNode(const std::string &nn)
Get a node(physical volume) by name;.
TObjArray * m_2DHitsArray
TGeoVolume * GetTopVolume()
Get the top(world) volume;.
TGeoVolume * GetLogicalVolume(const std::string &vn)
Get a logical volume by name;.
void ReadGdml(const char *gdmlFile, const char *setupName)
Initialize the instance of ROOTGeo.
TObjArray * m_DetectorsArray
UInt_t getChargeChannel() const
UInt_t getTimeChannel() const
virtual Double_t GetCharge()
virtual void Draw(Option_t *option="")
virtual void AddInfo(TString info)
virtual void ResetTimeCharge()
virtual void SetCharge(Double_t charge)
virtual void SetFired(bool status=true)
static int phi_module(const Identifier &id)
static int barrel_ec(const Identifier &id)
Values of different levels (failure returns 0)
static int layer(const Identifier &id)
TGeoNode * GetAl(int part, int layer)
Get Al node;.
void SetQuarterVisible()
Set quater visible;.
TGeoVolume * GetVolumeScin(int part)
Get scintillator volume;.
void SetVolumeTof(TGeoVolume *vol)
Set Tof volume, while initializing from ROOT;.
void InitFromROOT(TGeoVolume *vol)
Initialize ROOTGeo from TGeoVolume logicalTof.
TGeoVolume * GetVolumeAl(int part, int layer)
Get Al volume;.
void Draw(Option_t *option)
Draw function.
int GetPartNb()
Get number of part;.
void InitFromGDML(const char *gdmlFile, const char *setupName)
Initialize ROOTGeo from GDML.
TGeoVolume * GetVolumeBucket(int part)
Get bucket volume;.
void SetHalfVisible()
Set half visible;.
void SetQMatch(Bool_t input)
void SetNoEndVisible()
Set noend visible;.
void SetHits()
Set all physicalNodes corresponding to digiCol;.
TGeoVolume * GetVolumePart(int part)
Get assembly volume; part=0,2 for AssemblyEc, 1 for AssemblyBr;
void SetDetector()
Draw Detecor (what is detector depends on you)
TGeoNode * GetScin(int part, int scin)
Get scintillator node;.
void DrawHits(Option_t *option)
Draw 2D hits.
Tof2DScin * Get2DScin(Int_t part, Int_t layer, Int_t scin)
Get Tof2DScin;.
void SetVisTofDetector()
Set Tof detector visibility;.
int GetScinNb(int part)
Get number of scintillators on each part;.
void SetPhysicalNode()
Set the pointers to the physical nodes;.
TGeoNode * GetPVF(int part, int layer, int scin)
Get PVF node;.
void Init2DGeometry()
Initialize 2D Geometry.
TGeoVolume * GetVolumePVF(int part, int layer)
Get PVF volume;.
void SetTMatch(Bool_t input)
void SetVisTofHits()
Set Tof hits visibility;.
TGeoPhysicalNode * GetPhysicalScin(int part, int scin)
Get scintillator physical node;.
Int_t GetPart(TGeoPhysicalNode *phyNode)
Get part no of a scintillator physcial node.
void SetNode()
Set the pointers to theirs nodes;.
void SetVolumeDefaultVis()
Set default visual attributes;.
void SetAllVisible()
Set all visible;.