BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
BesMucEfficiency.cc
Go to the documentation of this file.
1//
2//
3//
4//
5
6#include "GaudiKernel/Bootstrap.h"
7#include "GaudiKernel/ISvcLocator.h"
8#include "GaudiKernel/MsgStream.h"
9
10#include "G4Box.hh"
11#include "G4VSolid.hh"
12#include "TFile.h"
13#include "TTree.h"
14#include <fstream>
15#include <iostream>
16#include <sstream>
17
18#include "MucSim/BesMucEfficiency.hh"
19
20using namespace std;
21BesMucEfficiency* BesMucEfficiency::fPointer = 0;
23 if ( !fPointer ) fPointer = new BesMucEfficiency();
24 return fPointer;
25}
26
28 if ( fPointer )
29 {
30 G4cout << "BesMucEfficiency constructed twice." << G4endl;
31 exit( -1 );
32 }
33 fPointer = this;
34}
35
37
38void BesMucEfficiency::Initialize( G4String filename ) {
39 G4int part, seg, gap, strip, pad;
40 G4double effi;
41 // for(G4int part=0;part<3;part++){
42 // for(G4int seg=0;seg<8;seg++){
43 // for(G4int gap=0;gap<gap_Max;gap++){
44 // for(G4int strip=0;strip<strip_Max;strip++){
45 // for(G4int pad=0;pad<pad_Max;pad++){
46 // m_effi[part][seg][gap][strip][pad]=1;
47 // }
48 // }
49 // }
50 // }
51 //}
52 // G4cout<<"in BesMucEfficiency::Initialize()"<<G4endl;
53
54 // TFile *f=new TFile("muc-effi.root");
55 // TTree *t1=(TTree*)f->Get("t1");
56
57 std::ifstream fin( filename );
58
59 char buffer[100];
60 G4int num = 0;
61
62 fin.getline( buffer, 100, '\n' ); // get info whether add effi or not
63 std::istringstream stringBuf( buffer );
64 stringBuf >> IsAddEffi;
65 // G4cout<<"IsAddEffi ="<<IsAddEffi<<G4endl;
66 fin.getline( buffer, 100, '\n' );
67
68 if ( !fin )
69 {
70 G4cout << "error opening effi data" << G4endl;
71 IsAddEffi = 1.0; // no effi data. set effi = 1.0
72 }
73
74 // fin.getline(buffer,100,'\n');
75 // std::istringstream stringBuf2(buffer);
76 // stringBuf2>>part>>seg>>gap>>strip>>pad;
77 // G4cout<<"---------- "<<pad<<endl;
78
79 while ( fin.getline( buffer, 100, '\n' ) )
80 {
81 std::istringstream stringBuf2( buffer );
82 stringBuf2 >> part >> seg >> gap >> strip >> pad >> effi;
83 m_effi[part][seg][gap][strip][pad] = effi;
84 num++;
85 }
86 for ( G4int seg = 0; seg < 8; seg++ )
87 {
88 for ( G4int strip = 0; strip < strip_Max; strip++ ) { m_effi[1][seg][0][strip][105] = 0; }
89 }
90
91 // G4cout<<"------------in Effi::init()---- "<<num<<G4endl;
92}
93
95
96 ISvcLocator* svcLocator = Gaudi::svcLocator();
97 // IMucCalibConstSvc* m_ptrCalibSvc;
98 StatusCode sc = svcLocator->service( "MucCalibConstSvc", m_ptrCalibSvc, true );
99
100 if ( sc != StatusCode::SUCCESS ) { G4cout << "Can not use MucCalibConstSvc!" << G4endl; }
101}
102
104 m_pHit = hit;
105 G4int part = m_pHit->GetPart();
106 G4int gap = m_pHit->GetGap();
107 m_Pos_Hit = m_pHit->GetPosLocal().y(); // different from BesMucdigit
108 if ( ( part == 1 && gap % 2 != 0 ) || ( part != 1 && gap % 2 == 0 ) )
109 { m_Pos_Hit = m_pHit->GetPosLocal().x(); }
110
111 // set m_Strip, m_Pos_Strip, m_Length, m_Width
112 BesMucDigit aDigit;
113 aDigit.SetHit( m_pHit );
114 m_Strip = aDigit.GetNearestStripNo();
115 // G4VPhysicalVolume* pvGasChamber = m_pHit->GetVolume();
117
118 // G4cout<<"m_Pos_Hit = "<<m_Pos_Hit<<G4endl;
119}
120
121G4int BesMucEfficiency::GetPad() { // it will be better to put this function into Class
122 // BesMucDigit
123 G4double pad1 = ( m_Pos_Hit + m_Length / 2 - m_Pos_Strip ) / m_Width;
124 G4int pad = G4int( pad1 );
125 // G4cout<<"---in Effi::GetPad()--- hit: "<<m_Pos_Hit<<" part: "<<m_pHit->GetPart()<<" gap:
126 // "<<m_pHit->GetGap()<<" L: "<<m_Length<<" strip: "<<m_Pos_Strip<<" width: "<<m_Width<<"
127 // pad: "<<pad<<G4endl;
128 if ( abs( m_Pos_Hit - m_Pos_Strip ) < m_Length / 2 ) return pad;
129 else return -999;
130}
131
133 // look up table with (part;seg;gap;m_Strip)
134 G4int part = m_pHit->GetPart();
135 G4int seg = m_pHit->GetSeg();
136 G4int gap = m_pHit->GetGap();
137 G4int strip = m_Strip;
138 G4int pad = GetPad();
139
140 G4double eff = 0;
141 if ( 0 != m_ptrCalibSvc )
142 {
143 eff = m_ptrCalibSvc->getEff( part, seg, gap, strip );
144 // G4cout << "Prt: " << part << "\tseg: " << seg << "\tlay: " << gap << "\tstr: " <<
145 // m_Strip
146 // << "\t:" << eff << endl;
147 }
148 else
149 {
150 // G4cout << "CalibSvc unavailable!" << G4endl;
151 eff = 0.95;
152 }
153 // G4cout<<part<<"\t"<<seg<<"\t"<<gap<<"\t"<<m_Strip<<"\t"<<eff<<G4endl;
154 return eff;
155}
156
157void BesMucEfficiency::GetPosLengthWidth( G4VPhysicalVolume* pvStrip ) {
158 m_Pos_Strip = 1.0e38;
159
160 G4int part = m_pHit->GetPart();
161 G4int gap = m_pHit->GetGap();
162
163 m_Pos_Strip = pvStrip->GetObjectTranslation().y();
164 if ( ( part == 1 && gap % 2 != 0 ) || ( part != 1 && gap % 2 == 0 ) )
165 { m_Pos_Strip = pvStrip->GetObjectTranslation().x(); }
166
167 G4String striptype = pvStrip->GetLogicalVolume()->GetSolid()->GetEntityType();
168 // G4String striplenght= pvStrip->GetLogicalVolume()->GetName();
169 G4Box* temp;
170 temp = (G4Box*)pvStrip->GetLogicalVolume()->GetSolid();
171 m_Width = temp->GetXHalfLength() * 2;
172 m_Length = temp->GetYHalfLength() * 2;
173 if ( ( part == 1 && gap % 2 != 0 ) || ( part != 1 && gap % 2 == 0 ) )
174 {
175 m_Width = temp->GetYHalfLength() * 2;
176 m_Length = temp->GetXHalfLength() * 2;
177 }
178 // G4cout<<"in Set "<<m_Length<<" "<<temp->GetXHalfLength()<<" "<<m_Width<<"
179 // "<<m_Pos_Strip<<G4endl;
180}
G4int GetNearestStripNo()
G4VPhysicalVolume * GetNearestStrip()
void SetHit(BesMucHit *hit)
void SetHit(BesMucHit *hit)
void Initialize(G4String filename)
static BesMucEfficiency * Instance(void)
void GetPosLengthWidth(G4VPhysicalVolume *pvStrip)