BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
BesMucDigit.cc
Go to the documentation of this file.
1//---------------------------------------------------------------------------//
2// BOOST --- BESIII Object_Oriented Simulation Tool //
3//---------------------------------------------------------------------------//
4// Description:
5// Author: Youzy Peking University mail: youzy@hep.pku.cn
6// Created: Dec, 2003
7// Modified:
8// Comment:
9//---------------------------------------------------------------------------//
10
11//
12// $Id: BesMucDigit
13
14#include "MucSim/BesMucDigit.hh"
15
16#include "G4Box.hh"
17#include "G4VSolid.hh"
18#include "G4ios.hh"
19#include "strstream"
20class G4VSolid;
21
23
25
27 m_pHit = hit;
28
29 G4int part = m_pHit->GetPart();
30 G4int seg = m_pHit->GetSeg();
31 G4int gap = m_pHit->GetGap();
32 m_Pos = m_pHit->GetPosLocal().x();
33 if ( ( part == 1 && gap % 2 != 0 ) || ( part != 1 && gap % 2 == 0 ) )
34 { m_Pos = m_pHit->GetPosLocal().y(); }
35
36 if ( part == 1 && seg == 2 && gap % 2 != 0 ) m_Pos2 = m_pHit->GetPosLocal().x();
37
38 G4VPhysicalVolume* pvGasChamber = m_pHit->GetVolume();
39 if ( m_pHit->GetTrackID() != -1 )
40 {
41 m_lvGap =
42 pvGasChamber->GetMotherLogical(); // after update gdml, mother of gaschamber change to
43 // be aluminumbox, but i still use the name m_lvGap
44 m_lvGapName = m_lvGap->GetName();
45
46 // G4cout<<"in digit----"<<m_lvGapName<<"
47 // "<<m_lvGap->GetDaughter(1)->GetLogicalVolume()->GetName()<<G4endl;
48 }
49}
50
51G4VPhysicalVolume* BesMucDigit::GetNearestStrip() {
52 m_pvStripDigit = GetStrip( GetNearestStripNo() );
53 if ( !m_pvStripDigit ) { G4cerr << "Nearest Strip is not found." << G4endl; }
54
55 return m_pvStripDigit;
56}
57
59 if ( m_pHit->GetTrackID() != -1 )
60 {
61 G4float posStrip0 = GetStripPos( GetStrip( 0 ) );
62 G4float posStrip1 = GetStripPos( GetStrip( 1 ) );
63 G4float width = posStrip1 - posStrip0;
64 // G4cout << "posStrip0 " << posStrip0 << " posStrip1 " << posStrip1 << G4endl;
65
66 G4int iGuessStrip = G4int( ( m_Pos - posStrip0 ) / width + 0.5 );
67 // confine iGuessStrip to an extend before check IsNearest.
68 if ( iGuessStrip < 0 ) { iGuessStrip = 0; }
69 else if ( iGuessStrip >= 112 ) { iGuessStrip = 112; }
70 // G4cout << "m_pos=" << m_Pos << "firstly, I guess: " << iGuessStrip << G4endl;
71
72 G4int step = IsNearest( iGuessStrip );
73 while ( step != 0 )
74 {
75 // G4cout << "guess " << iGuessStrip << " wrong , iGuess " << step << G4endl;
76 iGuessStrip += step;
77 step = IsNearest( iGuessStrip );
78 }
79 // G4cout << " guess " << iGuessStrip << " right " << G4endl;
80
81 // deal with barrel segment 2 gap%2!=0
82 G4int part = m_pHit->GetPart();
83 G4int seg = m_pHit->GetSeg();
84 G4int gap = m_pHit->GetGap();
85 // G4cout<<" in Digit iGuessStrip = "<< iGuessStrip <<G4endl;
86 if ( part == 1 && seg == 2 && gap % 2 != 0 && iGuessStrip > 79 )
87 {
88 if ( iGuessStrip > 79 && iGuessStrip <= 95 && m_Pos2 < 0 ) iGuessStrip += 16;
89 if ( iGuessStrip > 95 && iGuessStrip <= 111 && m_Pos2 > 0 ) iGuessStrip -= 16;
90 // G4cout<<" in barrel segment 2 and gap%2!=0, and strip > 79 strip="<< iGuessStrip<<"
91 // posx="<<m_Pos2<<" "<<" posy="<<m_Pos<<G4endl;
92 }
93
94 return iGuessStrip;
95 }
96 else return m_pHit->GetStrip();
97}
98
99G4VPhysicalVolume* BesMucDigit::GetStrip( G4int i ) {
100 // If no strip get, return 0.
101 // If i > daughtersNo, there will be run error.
102 G4LogicalVolume* lvStripPlane = m_lvGap->GetDaughter( 0 )->GetLogicalVolume();
103 G4int daughtersNo = lvStripPlane->GetNoDaughters();
104
105 if ( i >= 0 && i < daughtersNo )
106 {
107 G4VPhysicalVolume* pvStrip = lvStripPlane->GetDaughter( i );
108 G4String strStrip = pvStrip->GetLogicalVolume()->GetName();
109 // G4cout << "length " << strStrip.length() << G4endl;
110 // if(strStrip.length() == 30) { //use name length to determine whether it is a strip
111
112 if ( strStrip.find( "s" ) == 10 )
113 { //"Strip" at 23 of "logicalMucPart1Seg0Gap0Strip111"
114 //"s" at 10 of lMucP0S0G0s001
115 return pvStrip;
116 }
117 // return pvStrip;
118 }
119
120 return 0;
121}
122
123G4float BesMucDigit::GetStripPos( G4VPhysicalVolume* pvStrip ) {
124 G4float pos = 1.0e38;
125 if ( !pvStrip ) return pos;
126
127 G4int part = m_pHit->GetPart();
128 G4int gap = m_pHit->GetGap();
129
130 pos = pvStrip->GetObjectTranslation().x();
131 if ( ( part == 1 && gap % 2 != 0 ) || ( part != 1 && gap % 2 == 0 ) )
132 { pos = pvStrip->GetObjectTranslation().y(); }
133
134 G4String striptype = pvStrip->GetLogicalVolume()->GetSolid()->GetEntityType();
135 // G4String striplenght= pvStrip->GetLogicalVolume()->GetName();
136 G4Box* temp;
137 temp = (G4Box*)pvStrip->GetLogicalVolume()->GetSolid();
138 G4double length = temp->GetXHalfLength();
139 // std::ostream length;
140 // pvStrip->GetLogicalVolume()->GetSolid()->StreamInfo( length);
141
142 G4float box1, box2, box3;
143 // length>>box1>>box2>>box3;
144 // G4cout<<length<<" "<<striptype<<" in GetStripPos
145 // "<<pvStrip->GetObjectTranslation().x()<<" "<<pvStrip->GetObjectTranslation().y()<<"
146 // "<<pvStrip->GetObjectTranslation().z()<<G4endl;
147 return pos;
148}
149
150G4int BesMucDigit::IsNearest( G4int i ) {
151 G4float posMax = 1.0e38;
152 G4float posLeftStrip;
153 G4float posRightStrip;
154 G4float posCurrentStrip;
155
156 G4VPhysicalVolume* pvLeftStrip = GetStrip( i - 1 );
157 G4VPhysicalVolume* pvRightStrip = GetStrip( i + 1 );
158 G4VPhysicalVolume* pvCurrentStrip = GetStrip( i );
159
160 if ( i < 0 ) { return i; }
161 else if ( i == 0 )
162 {
163 posLeftStrip = -1.0 * posMax;
164 posRightStrip = GetStripPos( pvRightStrip );
165 }
166 else if ( !pvCurrentStrip )
167 {
168 // i > Max.
169 return -1;
170 }
171 else if ( !pvRightStrip )
172 {
173 // i = Max.
174 posLeftStrip = GetStripPos( pvLeftStrip );
175 posRightStrip = posMax;
176 }
177 else
178 {
179 // 0 < i < Max.
180 posLeftStrip = GetStripPos( pvLeftStrip );
181 posRightStrip = GetStripPos( pvRightStrip );
182 }
183 posCurrentStrip = GetStripPos( pvCurrentStrip );
184
185 G4float distCurrent = std::abs( m_Pos - posCurrentStrip );
186 G4float distLeft = std::abs( m_Pos - posLeftStrip );
187 G4float distRight = std::abs( m_Pos - posRightStrip );
188
189 // G4cout << "left " << distLeft << " current " << distCurrent << " right " << distRight <<
190 // G4endl;
191
192 if ( ( distCurrent <= distLeft ) && ( distCurrent <= distRight ) ) { return 0; }
193 else if ( distCurrent > distLeft ) { return -1; }
194 else { return 1; }
195}
G4VPhysicalVolume * GetStrip(G4int i)
G4float GetStripPos(G4VPhysicalVolume *pvStrip)
G4int GetNearestStripNo()
G4VPhysicalVolume * GetNearestStrip()
G4int IsNearest(G4int i)
void SetHit(BesMucHit *hit)