BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
BesTofDigitizer.cc
Go to the documentation of this file.
1//---------------------------------------------------------------------------//
2// BOOST --- BESIII Object_Oriented Simulation Tool //
3//---------------------------------------------------------------------------//
4// Description: Chief control center for digitizing modes.Also define 'group hits'.
5// Author: Dengzy
6// Created: Mar, 2004
7// Modified: Sun Shengsen based on Matthias Ullrich for MRPC Endcap TOF 2014.04.28.
8// Comment: Double Side Readout Version
9//---------------------------------------------------------------------------//
10//$Id: BesTofDigitizer.cc
11
12#include "TofSim/BesTofDigitizer.hh"
13#include "G4DigiManager.hh"
14#include "G4Svc/IG4Svc.h"
15#include "GaudiKernel/Bootstrap.h"
16#include "GaudiKernel/IDataProviderSvc.h"
17#include "GaudiKernel/ISvcLocator.h"
18#include "GaudiKernel/MsgStream.h"
19#include "Randomize.hh"
20#include "SimUtil/ReadBoostRoot.hh"
21#include "TofSim/ScintSingle.hh"
22
23BesTofDigitizer::BesTofDigitizer( G4String modName ) : G4VDigitizerModule( modName ) {
24
25 collectionName.push_back( "BesTofDigitsCollection" );
26 m_besTofDigitsCollection = 0;
27 // m_digiMessenger = new BesTofDigitizerMessenger(this);
28
29 tofDMBr1 = new BesTofDigitizerBrV1();
30 tofDMEc1 = new BesTofDigitizerEcV1();
31 tofDMBr2 = new BesTofDigitizerBrV2();
32 tofDMEc2 = new BesTofDigitizerEcV2();
33 tofDMEc3 = new BesTofDigitizerEcV3(); // Scintillator
34 tofDMEc4 = new BesTofDigitizerEcV4(); // MRPC Double End
35
36 // retrieve RealizationSvc
37 StatusCode scReal = Gaudi::svcLocator()->service( "RealizationSvc", m_RealizationSvc );
38 if ( !scReal.isSuccess() )
39 {
40 std::cout << " Could not initialize Realization Service in BesTofDigitizerBrV2"
41 << std::endl;
42 exit( 1 );
43 }
44
45 m_versionBr = 2;
46
47 if ( ReadBoostRoot::GetTof() == 3 || ReadBoostRoot::GetTof() == 4 )
48 {
49 m_versionEc = 4;
50 std::cout
51 << std::endl
52 << "TofSim: BesTofDigitizer You are using the new End Cap Tof (MRPC) Digitizer!"
53 << std::endl;
54 }
55 else
56 {
57 m_versionEc = 3;
58 std::cout << std::endl
59 << "TofSim: BesTofDigitizer You are using the old End Cap Tof "
60 "(Scintillator) Digitizer!"
61 << std::endl;
62 }
63}
64
66 // delete m_digiMessenger;
67 delete tofDMBr1;
68 delete tofDMEc1;
69 delete tofDMBr2;
70 delete tofDMEc2;
71 delete tofDMEc3;
72 delete tofDMEc4;
73}
74
76
77 m_besTofDigitsCollection = new BesTofDigitsCollection( moduleName, collectionName[0] );
78 G4DigiManager* digiManager = G4DigiManager::GetDMpointer();
79 G4int THCID = digiManager->GetHitsCollectionID( "BesTofHitsCollection" );
80 m_THC = (BesTofHitsCollection*)( digiManager->GetHitsCollection( THCID ) );
81
82 if ( m_THC )
83 {
84 m_scintGroup = new vector<ScintSingle*>; // ScintSingle contains: partId, scintnb, edep
85 // <--only the basics
86 GroupHits(); // If one finds more hits in one scintillator, they are grouped together
87 G4int size = m_scintGroup->size();
88
89 // std::cout << "TofSim: BesTofDigitizer m_scintGroup->size(): " << size <<
90 // std::endl;
91
92 ScintSingle* scint;
93 G4int partId;
94 for ( G4int i = 0; i < size; i++ )
95 {
96 scint = ( *m_scintGroup )[i];
97 partId = scint->GetPartId();
98
99 // std::cout << "TofSim: BesTofDigitizer scint->GetPartId(): " << partId <<
100 // std::endl;
101
102 if ( partId == 1 )
103 { // for barrel part
104 if ( m_versionBr == 1 ) tofDMBr1->Digitize( scint, m_besTofDigitsCollection );
105 else if ( m_versionBr == 2 )
106 {
107 // std::cout << "TofSim: tofDMBr2->Digitize" << std::endl;
108 tofDMBr2->Digitize( scint, m_besTofDigitsCollection );
109 }
110 else { tofDMBr2->Digitize( scint, m_besTofDigitsCollection ); }
111 }
112 else
113 { // for endcap part
114 if ( m_versionEc == 1 ) { tofDMEc1->Digitize( scint, m_besTofDigitsCollection ); }
115 else if ( m_versionEc == 2 ) { tofDMEc2->Digitize( scint, m_besTofDigitsCollection ); }
116 else if ( m_versionEc == 3 ) { tofDMEc3->Digitize( scint, m_besTofDigitsCollection ); }
117 else if ( m_versionEc == 4 ) { tofDMEc4->Digitize( scint, m_besTofDigitsCollection ); }
118 else
119 {
120 cout << "TofSim: Warning: BesTofDigitizerEcV2 is utilized otherwise!" << endl;
121 tofDMEc2->Digitize( scint, m_besTofDigitsCollection );
122 }
123 } // Close endcap part
124 }
125
126 if ( m_scintGroup )
127 {
128 for ( size_t i = 0; i < m_scintGroup->size(); i++ )
129 {
130 delete ( *m_scintGroup )[i];
131 // std::cout << "TofSim: i: " << i << std::endl;
132 // std::cout << "TofSim: delete m_scintGroup[i] successfully " << std::endl;
133 }
134 m_scintGroup->clear();
135 delete m_scintGroup;
136 }
137 } // close if(m_THC)
138
139 StoreDigiCollection( m_besTofDigitsCollection );
140}
141
143
144 G4int partId, scinNb, size, flag, trackId;
145 G4double edep;
146 BesTofHit* hit;
147 G4int nHits = m_THC->entries();
148
149 // sunss 20140508 add to suppress the efficiency of TOF signal
150 vector<G4int> deadTrackVec;
151 deadTrackVec.clear();
152 G4int runId = m_RealizationSvc->getRunId();
153 if ( ( runId >= -11396 && runId <= -8093 ) || ( runId > -1000000 && runId <= -23463 ) )
154 {
155 G4int previousTrack = -999;
156 vector<G4int> trackVec;
157 trackVec.clear();
158 for ( G4int i = 0; i < nHits; i++ )
159 {
160 hit = ( *m_THC )[i];
161 trackId = hit->GetTrackIndex();
162 if ( trackId != previousTrack )
163 {
164 previousTrack = trackId;
165 bool same = false;
166 vector<G4int>::iterator iter = trackVec.begin();
167 for ( ; iter != trackVec.end(); iter++ )
168 {
169 if ( ( *iter ) == trackId )
170 {
171 same = true;
172 break;
173 }
174 }
175 if ( !same )
176 {
177 trackVec.push_back( trackId );
178 G4double ranSignal = G4UniformRand();
179 if ( ranSignal > 0.988 )
180 { // hhliu 20140613
181 deadTrackVec.push_back( trackId );
182 }
183 }
184 }
185 }
186 }
187 // sunss 20140508
188
189 // group the hits which are in the same scintillator
190 for ( G4int i = 0; i < nHits; i++ )
191 {
192 hit = ( *m_THC )[i];
193 // sunss 20140508
194 if ( ( runId >= -11396 && runId <= -8093 ) || ( runId > -1000000 && runId <= -23463 ) )
195 {
196 trackId = hit->GetTrackIndex();
197 partId = hit->GetPartId();
198 bool aband = false;
199 vector<G4int>::iterator iter = deadTrackVec.begin();
200 for ( ; iter != deadTrackVec.end(); iter++ )
201 {
202 if ( ( trackId == ( *iter ) ) && ( partId != 3 && partId != 4 ) ) { aband = true; }
203 }
204 if ( aband ) continue;
205 }
206 // sunss 20140508
207 partId = hit->GetPartId();
208 scinNb = hit->GetScinNb();
209 edep = hit->GetEdep();
210 size = m_scintGroup->size();
211 flag = 0;
212 if ( size > 0 )
213 {
214 ScintSingle* oldScint;
215 for ( G4int j = 0; j < size; j++ )
216 {
217 oldScint = ( *m_scintGroup )[j];
218 if ( oldScint->GetPartId() == partId && oldScint->GetScinNb() == scinNb )
219 {
220 // std::cout << "BesTodDigitizer: GroupHits: 'Oldhit:' partID | scinnb : "
221 // << partId << " | "
222 // << scinNb << std::endl;
223 oldScint->GetHitIndexes()->push_back( i );
224 // ATTENTION!!! sum over all deposited energy!
225 oldScint->AddEdep( edep );
226 flag = 1;
227 break;
228 }
229 }
230 }
231
232 if ( flag == 0 )
233 {
234 ScintSingle* newScint = new ScintSingle;
235 newScint->SetPartId( partId );
236 newScint->SetScinNb( scinNb );
237 newScint->SetEdep( edep );
238 newScint->GetHitIndexes()->push_back( i );
239 m_scintGroup->push_back( newScint );
240
241 // std::cout << "BesTofDigitizer: GroupHits: NewHitGroup: " << partId <<
242 // " " << scinNb << std::endl;
243 }
244 }
245}
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
G4TDigiCollection< BesTofDigi > BesTofDigitsCollection
G4THitsCollection< BesTofHit > BesTofHitsCollection
virtual void Digitize()
BesTofDigitizer(G4String modName)