BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
BesRawDataWriter.cc
Go to the documentation of this file.
1//---------------------------------------------------------------------------//
2//// BOOST --- BESIII Object_Oriented Simulation Tool //
3////---------------------------------------------------------------------------//
4////Description:
5////Author: Dengzy
6////Created: Mar, 2004
7////Modified:
8////Comment:
9//
10#include "BesMdcDigi.hh"
11#include "BesTofDigi.hh"
12#include "BesEmcDigi.hh"
13#include "BesMucDigi.hh"
14#include "BesRawDataWriter.hh"
15#include "G4DigiManager.hh"
16#include "G4Svc/IG4Svc.h"
17#include "G4Svc/G4Svc.h"
18
19#include "GaudiKernel/IDataProviderSvc.h"
20#include "GaudiKernel/ISvcLocator.h"
21#include "GaudiKernel/Bootstrap.h"
22#include "GaudiKernel/RegistryEntry.h"
23#include "GaudiKernel/MsgStream.h"
24
25#include "MdcRawEvent/MdcDigi.h"
26#include "TofRawEvent/TofDigi.h"
27#include "EmcRawEvent/EmcDigi.h"
28#include "MucRawEvent/MucDigi.h"
29
31#include "Identifier/MdcID.h"
32#include "Identifier/TofID.h"
33#include "Identifier/EmcID.h"
34#include "Identifier/MucID.h"
35
37#include "RawEvent/DigiEvent.h"
38#include "GaudiKernel/SmartDataPtr.h"
39
40
42{
43 m_DigiMan = G4DigiManager::GetDMpointer();
44 //yuany 2005-2-28
45 mdcGeoPointer=BesMdcGeoParameter::GetGeo();
46
47 IG4Svc* tmpSvc;
48 StatusCode sc=Gaudi::svcLocator()->service("G4Svc", tmpSvc);
49 if (!sc.isSuccess())
50 G4cout <<" BesRawDataWriter::Error,could not open G4Svc"<<G4endl;
51 m_G4Svc=dynamic_cast<G4Svc *>(tmpSvc);
52
53 IRealizationSvc *tmpReal;
54 StatusCode scReal = Gaudi::svcLocator()->service("RealizationSvc",tmpReal);
55 if (!scReal.isSuccess())
56 {
57 std::cout << " Could not initialize Realization Service in BesRawDataWriter" << std::endl;
58 }
59 else
60 {
61 m_RealizationSvc=dynamic_cast<RealizationSvc*>(tmpReal);
62 }
63
64}
65
69
71{
72 //interface to event data service
73 ISvcLocator* svcLocator = Gaudi::svcLocator();
74 StatusCode sc=svcLocator->service("EventDataSvc", m_evtSvc);
75 if (sc.isFailure())
76 G4cout<<"Could not accesss EventDataSvc!"<<G4endl;
77
78 DigiEvent* aDigiEvent = new DigiEvent;
79 sc = m_evtSvc->registerObject("/Event/Digi",aDigiEvent);
80 if(sc!=StatusCode::SUCCESS) {
81 G4cout<< "Could not register DigiEvent" <<G4endl;
82 }
83
88}
89
91{
92 //mdc digis collection defined in BOSS
93 MdcDigiCol* aMdcDigiCol = new MdcDigiCol;
94
95 G4int mdcDigiCollID = -1;
96 mdcDigiCollID = m_DigiMan->GetDigiCollectionID("BesMdcDigisCollection");
97 if(mdcDigiCollID>=0)
98 {
99 BesMdcDigisCollection* mdcDC = (BesMdcDigisCollection*)m_DigiMan->GetDigiCollection(mdcDigiCollID);
100 G4int nDigi = mdcDC->entries();
101 if(nDigi>0)
102 {
103 //push back mdc digits to MdcDigiCol in BOSS
104 BesMdcDigi* mdcDigi;
105 for(int i=0;i<nDigi;i++)
106 {
107 mdcDigi=(*mdcDC)[i];
108 unsigned int charge;
109 if(m_G4Svc->GetMdcDedxFlag()==1){
110 charge = int(mdcDigi->GetEdep());
111 }else{
113 }
114 unsigned int time = RawDataUtil::MdcTimeChannel(mdcDigi->GetDriftT());
115 const Identifier ident = MdcID::wire_id ( mdcDigi->GetLayerNo(), mdcDigi->GetCellNo() );
116
117 MdcDigi* aMdcDigi = new MdcDigi(ident, time, charge);
118 aMdcDigi->setTrackIndex(mdcDigi->GetTrackID());
119 aMdcDigiCol->push_back(aMdcDigi);
120 }
121 }
122 }
123
124 //register MDC digits collection to TDS
125 StatusCode scMdc = m_evtSvc->registerObject("/Event/Digi/MdcDigiCol", aMdcDigiCol);
126 if(scMdc!=StatusCode::SUCCESS)
127 G4cout<< "Could not register MDC digi collection" <<G4endl;
128
129 //retrieve MDC digits from TDS
130 /*SmartDataPtr<MdcDigiCol> aDigiCol(m_evtSvc,"/Event/Digi/MdcDigiCol");
131 if(!aDigiCol)
132 G4cout<<"Could not retrieve MDC digi collection"<<G4endl;
133
134 MdcDigiCol::iterator iDigiCol;
135 for(iDigiCol=aDigiCol->begin(); iDigiCol!=aDigiCol->end(); iDigiCol++)
136 {
137 const Identifier ident = (*iDigiCol)->identify();
138 G4cout<<"layer: "<<MdcID::layer(ident);
139 G4cout<<" cell: "<<MdcID::wire(ident);
140 G4cout<<" charge: "<<(*iDigiCol)->getChargeChannel();
141 G4cout<<" time: "<<(*iDigiCol)->getTimeChannel()<<G4endl;
142 }
143 G4cout<<"end of retrieve MDC digi collection"<<G4endl;
144 */
145}
146
148
149 //Tof digits collection defined in BOSS
150 TofDigiCol* aTofDigiCol = new TofDigiCol;
151
152 G4int tofDigiCollID = -1;
153 tofDigiCollID = m_DigiMan->GetDigiCollectionID("BesTofDigitsCollection");
154
155 if( tofDigiCollID>=0 ) {
156 BesTofDigitsCollection* tofDC = (BesTofDigitsCollection*)m_DigiMan->GetDigiCollection(tofDigiCollID);
157 G4int nDigi = tofDC->entries();
158 if( nDigi>0 ) {
159 //arrange digis in digitsCollection in order of trackIndex
160 BesTofDigi* digi;
161 vector<BesTofDigi*>* vecDC = tofDC->GetVector();
162 for( int i=0; i<nDigi-1; i++ ) {
163 for( int j=i+1; j<nDigi; j++ ) {
164 if( (*vecDC)[i]->GetTrackIndex()>(*vecDC)[j]->GetTrackIndex() ) {
165 digi = (*vecDC)[i];
166 (*vecDC)[i] = (*vecDC)[j];
167 (*vecDC)[j] = digi;
168 }
169 }
170 }
171
172 //push back tof digits to TofDigiCol in BOSS
173 for( int i=0; i<nDigi; i++ ) {
174 digi = (*tofDC)[i];
175
176 // for Scintillator, scinNum is the number of scintillator
177 // for MRPC, scinNum is the number of module
178 G4int scinNum = digi->GetScinNb();
179 // for Scintillator, barrel_ec is 0 for east endcap, 1 for barrel, and 2 for west endcap
180 // for MRPC, barrel_ec is 100 + module number for east, 200 + module number for west
181 G4int barrel_ec = digi->GetPartId();
182
183 if( TofID::is_scin( barrel_ec ) ) { // for Scintillator
184 unsigned int layer = 0;
185 if (TofID::is_barrel(barrel_ec) && scinNum > TofID::getPHI_BARREL_MAX()) {
186 layer = 1;
187 scinNum = scinNum - TofID::getPHI_BARREL_MAX() - 1;
188 }
189
190 // Store tofDigi for end==0
191 Identifier ident = TofID::cell_id ( barrel_ec, layer, scinNum, 0);
192 unsigned int time;
193 if( digi->GetForwTDC()>0 ) {
195 }
196 else {
197 time = 0;
198 }
199
200 unsigned int charge;
201 if( digi->GetForwADC()>0 ) {
202 // ADC linear conversion
203 charge = digi->GetForwADC(); // convert ADC(pC) of bTof into Q channel in Data
204 // Treat ADC overflow
205 if( charge>=8192 ) {
206 // The overlow flag is the 20th bit of the ADC_channel.
207 charge = (charge | 0x080000); // if ADC_channel>=8192, set overflow flag = 1.
208 }
209 charge = ( (time & 0x07e000) | charge ); // Store tclock into ADC_channel as qclock
210 }
211 else {
212 charge =0;
213 }
214
215 TofDigi* tofDigi = new TofDigi(ident, time, charge);
216 if( charge & 0x80000 ) {// Treat overflow flag(20th bit)
217 tofDigi->setOverflow(0x2);
218 }
219 tofDigi->setTrackIndex(digi->GetTrackIndex());
220 aTofDigiCol->push_back(tofDigi);
221
222 // Store tofDigi for end==1
223 ident = TofID::cell_id ( barrel_ec, layer, scinNum, 1);
224 if( digi->GetBackTDC()>0 ) {
226 }
227 else {
228 time = 0;
229 }
230
231 if( digi->GetBackADC()>0 ) {
232 // ADC linear conversion
233 charge = digi->GetBackADC();
234 // Treat ADC overflow
235 if( charge>=8192 ) {
236 // The overlow flag is the 20th bit of the ADC_channel.
237 charge = (charge | 0x080000); // if ADC_channel>=8192, set overflow flag = 1.
238 }
239 charge = ( (time & 0x07e000) | charge); // Store tclock into ADC_channel as qclock
240 }
241 else {
242 charge = 0;
243 }
244
245 tofDigi = new TofDigi(ident, time, charge);
246 if( charge & 0x80000 ) { // Treat overflow flag(20th bit)
247 tofDigi->setOverflow(0x2);
248 }
249 tofDigi->setTrackIndex(digi->GetTrackIndex());
250 aTofDigiCol->push_back(tofDigi);
251 } // end if is_scin
252 else { // for ETF(MRPC)
253 if( barrel_ec==3 || barrel_ec==4 ) {
254 unsigned int endcap = 0;
255 unsigned int module = digi->GetModule();
256 unsigned int strip = digi->GetStrip();
257 if( barrel_ec==4 ) { // west end cap
258 endcap = 1;
259 }
260
261 // Store tofDigi for end==0
262 Identifier ident = TofID::cell_id( 3, endcap, module, strip, 0 );
263 unsigned int tleading;
264 if( digi->GetForwT1() > 0 ) {
265 tleading = RawDataUtil::TofTimeChannel( digi->GetForwT1() );
266 }
267 else { tleading = 0; }
268 unsigned int ttrailing;
269 if( digi->GetForwT2() > 0 ) {
270 ttrailing = RawDataUtil::TofTimeChannel( digi->GetForwT2() );
271 }
272 else { ttrailing = 0; }
273 TofDigi* tofDigi = new TofDigi( ident, tleading, ttrailing );
274 tofDigi->setTrackIndex( digi->GetTrackIndex() );
275 aTofDigiCol->push_back( tofDigi );
276 /*
277 G4cout << " --------- BesRawDataWriter: TOF ------------------ " << G4endl;
278 G4cout << " endcap=" << endcap << " module=" << module << " strip=" << strip << G4endl;
279 G4cout << " tleading=" << tleading << " ttrailing=" << ttrailing << G4endl;
280 G4cout << " --------- BesRawDataWriter: TOF ------------------ " << G4endl;
281 */
282 // Store tofDigi for end==1
283 ident = TofID::cell_id( 3, endcap, module, strip, 1 );
284 if( digi->GetBackT1() > 0 ) {
285 tleading = RawDataUtil::TofTimeChannel( digi->GetBackT1() );
286 }
287 else { tleading = 0; }
288 if( digi->GetBackT2() > 0 ) {
289 ttrailing = RawDataUtil::TofTimeChannel( digi->GetBackT2() );
290 }
291 else { ttrailing = 0; }
292 tofDigi = new TofDigi( ident, tleading, ttrailing );
293 tofDigi->setTrackIndex( digi->GetTrackIndex() );
294 aTofDigiCol->push_back( tofDigi );
295 }
296 } // end if is_MRPC
297
298 }
299 }
300 }
301
302 //register TOF digits collection to TDS
303 StatusCode scTof = m_evtSvc->registerObject("/Event/Digi/TofDigiCol", aTofDigiCol);
304 if( scTof!=StatusCode::SUCCESS ) {
305 G4cout<< "Could not register TOF digi collection" <<G4endl;
306 }
307 return;
308}
309
311{
312 //Emc digits collection defined in BOSS
313 EmcDigiCol* aEmcDigiCol = new EmcDigiCol;
314
315 G4int emcDigiCollID = -1;
316 emcDigiCollID = m_DigiMan->GetDigiCollectionID("BesEmcDigitsCollection");
317 if(emcDigiCollID>=0)
318 {
319 BesEmcDigitsCollection* emcDC = (BesEmcDigitsCollection*)m_DigiMan->GetDigiCollection(emcDigiCollID);
320 G4int nDigi = emcDC->entries();
321 if(nDigi>0)
322 {
323 //arrange digis in digitsCollection in order of trackIndex
324 BesEmcDigi* digi;
325 vector<BesEmcDigi*>* vecDC = emcDC->GetVector();
326 for(int i=0;i<nDigi-1;i++)
327 for(int j=i+1;j<nDigi;j++)
328 if((*vecDC)[i]->GetTrackIndex()>(*vecDC)[j]->GetTrackIndex())
329 {
330 digi = (*vecDC)[i];
331 (*vecDC)[i] = (*vecDC)[j];
332 (*vecDC)[j] = digi;
333 }
334 //push back EmcDigi to EmcDigiCol in BOSS
335 for(int i=0;i<nDigi;i++)
336 {
337 digi = (*emcDC)[i];
338
340 int measure = RawDataUtil::EmcChargeMeasure(digi->GetEnergy());
342 Identifier ident = EmcID::crystal_id (digi->GetPartId(), digi->GetThetaNb(), digi->GetPhiNb());
343 EmcDigi* emcDigi = new EmcDigi(ident, time, charge);
344 emcDigi->setTrackIndex(digi->GetTrackIndex());
345 emcDigi->setMeasure(measure);
346 aEmcDigiCol->push_back(emcDigi);
347 }
348 }
349 }
350
351 //register EMC digits collection to TDS
352 StatusCode scEmc = m_evtSvc->registerObject("/Event/Digi/EmcDigiCol", aEmcDigiCol);
353 if(scEmc!=StatusCode::SUCCESS)
354 G4cout<< "Could not register EMC digi collection" <<G4endl;
355
356 //retrieve EMC digits from TDS
357 /*SmartDataPtr<EmcDigiCol> aDigiCol(m_evtSvc,"/Event/Digi/EmcDigiCol");
358 if(!aDigiCol)
359 G4cout<<"Could not retrieve EMC digi collection"<<G4endl;
360
361 EmcDigiCol::iterator iDigiCol;
362 for(iDigiCol=aDigiCol->begin(); iDigiCol!=aDigiCol->end(); iDigiCol++)
363 {
364 const Identifier ident = (*iDigiCol)->identify();
365 G4cout<<"barrel_ec: "<<EmcID::barrel_ec(ident);
366 G4cout<<" theta: "<<EmcID::theta_module(ident);
367 G4cout<<" phi: "<<EmcID::phi_module(ident);
368 G4cout<<" charge: "<<(*iDigiCol)->getChargeChannel();
369 G4cout<<" time: "<<(*iDigiCol)->getTimeChannel()<<G4endl;
370 }
371 G4cout<<"end of retrieve EMC digits"<<G4endl;
372 */
373}
374
376{
377 //Muc digits collection defined in BOSS
378 MucDigiCol* aMucDigiCol = new MucDigiCol;
379
380 G4int mucDigiCollID =-1;
381 mucDigiCollID = m_DigiMan->GetDigiCollectionID("BesMucDigisCollection");
382 if(mucDigiCollID>=0)
383 {
384 BesMucDigisCollection* mucDC = (BesMucDigisCollection*)m_DigiMan->GetDigiCollection(mucDigiCollID);
385 G4int nDigi = mucDC->entries();
386
387 if(nDigi > 0) {
388 BesMucDigi* digi;
389 for(int i = 0; i < nDigi; i++) {
390 digi = (*mucDC)[i];
391 Identifier ident = MucID::channel_id( digi->GetPartId(), digi->GetSegId(),digi->GetGapId(),digi->GetStripId() );
392 MucDigi* mucDigi = new MucDigi(ident);
393 mucDigi->setTrackIndex(digi->GetTrackIndex());
394 aMucDigiCol->push_back(mucDigi);
395 }
396 }
397 }
398
399 //register MUC digits collection to TDS
400 StatusCode scMuc = m_evtSvc->registerObject("/Event/Digi/MucDigiCol", aMucDigiCol);
401 if(scMuc!=StatusCode::SUCCESS)
402 G4cout<< "Could not register MUC digi collection" <<G4endl;
403
404 //retrieve MUC digits from TDS
405 /*SmartDataPtr<MucDigiCol> aDigiCol(m_evtSvc,"/Event/Digi/MucDigiCol");
406 if(!aDigiCol)
407 G4cout<<"Could not retrieve MUC digi collection"<<G4endl;
408
409 MucDigiCol::iterator iDigiCol;
410 for(iDigiCol=aDigiCol->begin(); iDigiCol!=aDigiCol->end(); iDigiCol++)
411 {
412 const Identifier ident = (*iDigiCol)->identify();
413 G4cout<<"Part: "<<MucID::part(ident);
414 G4cout<<" Seg: "<<MucID::seg(ident);
415 G4cout<<" Gap: "<<MucID::gap(ident);
416 G4cout<<" Strip: "<<MucID::strip(ident)<<G4endl;
417 }
418 G4cout<<"end of retrieve MUC digits"<<G4endl;
419 */
420}
G4TDigiCollection< BesEmcDigi > BesEmcDigitsCollection
Definition BesEmcDigi.hh:69
G4TDigiCollection< BesMdcDigi > BesMdcDigisCollection
Definition BesMdcDigi.hh:59
G4TDigiCollection< BesMucDigi > BesMucDigisCollection
Definition BesMucDigi.hh:56
G4TDigiCollection< BesTofDigi > BesTofDigitsCollection
Definition BesTofDigi.hh:79
Double_t time
ObjectVector< EmcDigi > EmcDigiCol
Definition EmcDigi.h:43
ObjectVector< MdcDigi > MdcDigiCol
Definition MdcDigi.h:39
ObjectVector< MucDigi > MucDigiCol
Definition MucDigi.h:29
ObjectVector< TofDigi > TofDigiCol
Definition TofDigi.h:41
G4int GetTrackIndex()
Definition BesEmcDigi.hh:54
G4int GetThetaNb()
Definition BesEmcDigi.hh:50
G4double GetEnergy()
Definition BesEmcDigi.hh:52
G4int GetPhiNb()
Definition BesEmcDigi.hh:51
G4double GetTime()
Definition BesEmcDigi.hh:53
G4int GetPartId()
Definition BesEmcDigi.hh:49
G4int GetLayerNo()
Definition BesMdcDigi.hh:44
G4double GetEdep()
Definition BesMdcDigi.hh:46
G4int GetCellNo()
Definition BesMdcDigi.hh:45
G4int GetTrackID()
Definition BesMdcDigi.hh:43
G4double GetDriftT()
Definition BesMdcDigi.hh:47
static BesMdcGeoParameter * GetGeo(void)
G4int GetPartId()
Definition BesMucDigi.hh:43
G4int GetStripId()
Definition BesMucDigi.hh:46
G4int GetSegId()
Definition BesMucDigi.hh:44
G4int GetTrackIndex()
Definition BesMucDigi.hh:42
G4int GetGapId()
Definition BesMucDigi.hh:45
G4double GetBackT2()
Definition BesTofDigi.hh:66
G4int GetPartId()
Definition BesTofDigi.hh:53
G4double GetForwT1()
Definition BesTofDigi.hh:63
G4double GetBackT1()
Definition BesTofDigi.hh:64
G4double GetForwTDC()
Definition BesTofDigi.hh:58
G4int GetScinNb()
Definition BesTofDigi.hh:55
G4int GetModule()
Definition BesTofDigi.hh:61
G4int GetTrackIndex()
Definition BesTofDigi.hh:52
G4double GetBackTDC()
Definition BesTofDigi.hh:59
G4double GetForwT2()
Definition BesTofDigi.hh:65
G4int GetStrip()
Definition BesTofDigi.hh:62
G4double GetBackADC()
Definition BesTofDigi.hh:57
G4double GetForwADC()
Definition BesTofDigi.hh:56
void setMeasure(const unsigned int measure)
Definition EmcDigi.h:24
static Identifier crystal_id(const unsigned int barrel_ec, const unsigned int theta_module, const unsigned int phi_module)
For a single crystal.
Definition EmcID.cxx:71
Definition G4Svc.h:33
int GetMdcDedxFlag()
Definition G4Svc.h:102
static Identifier wire_id(int wireType, int layer, int wire)
For a single wire.
Definition MdcID.cxx:77
static Identifier channel_id(int barrel_ec, int segment, int layer, int channel)
For a single crystal.
Definition MucID.cxx:135
static int EmcChargeChannel(double charge)
Definition RawDataUtil.h:37
static int MdcTimeChannel(double time)
Definition RawDataUtil.h:9
static int EmcChargeMeasure(double charge)
Definition RawDataUtil.h:50
static int MdcChargeChannel(double charge)
Definition RawDataUtil.h:12
static unsigned int TofTimeChannel(double time)
Definition RawDataUtil.h:64
static int EmcTimeChannel(double time)
Definition RawDataUtil.h:15
void setTrackIndex(const int trackIndex)
Definition RawData.cxx:35
void setOverflow(const unsigned int overflow)
Definition TofDigi.h:23
static Identifier cell_id(int barrel_ec, int layer, int phi_module, int end)
For a single crystal.
Definition TofID.cxx:143
static bool is_scin(const Identifier &id)
Definition TofID.cxx:102
static value_type getPHI_BARREL_MAX()
Definition TofID.cxx:217
static bool is_barrel(const Identifier &id)
Test for barrel.
Definition TofID.cxx:49
float charge