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