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"
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"
25#include "MdcRawEvent/MdcDigi.h"
26#include "TofRawEvent/TofDigi.h"
27#include "EmcRawEvent/EmcDigi.h"
28#include "MucRawEvent/MucDigi.h"
30#include "Identifier/Identifier.h"
31#include "Identifier/MdcID.h"
32#include "Identifier/TofID.h"
33#include "Identifier/EmcID.h"
34#include "Identifier/MucID.h"
36#include "RawEvent/RawDataUtil.h"
37#include "RawEvent/DigiEvent.h"
38#include "GaudiKernel/SmartDataPtr.h"
43 m_DigiMan = G4DigiManager::GetDMpointer();
48 StatusCode sc=Gaudi::svcLocator()->service(
"G4Svc", tmpSvc);
50 G4cout <<
" BesRawDataWriter::Error,could not open G4Svc"<<G4endl;
51 m_G4Svc=
dynamic_cast<G4Svc *
>(tmpSvc);
54 StatusCode scReal = Gaudi::svcLocator()->service(
"RealizationSvc",tmpReal);
55 if (!scReal.isSuccess())
57 std::cout <<
" Could not initialize Realization Service in BesRawDataWriter" << std::endl;
73 ISvcLocator* svcLocator = Gaudi::svcLocator();
74 StatusCode sc=svcLocator->service(
"EventDataSvc", m_evtSvc);
76 G4cout<<
"Could not accesss EventDataSvc!"<<G4endl;
79 sc = m_evtSvc->registerObject(
"/Event/Digi",aDigiEvent);
80 if(sc!=StatusCode::SUCCESS) {
81 G4cout<<
"Could not register DigiEvent" <<G4endl;
95 G4int mdcDigiCollID = -1;
96 mdcDigiCollID = m_DigiMan->GetDigiCollectionID(
"BesMdcDigisCollection");
100 G4int nDigi = mdcDC->entries();
105 for(
int i=0;i<nDigi;i++)
110 charge = int(mdcDigi->
GetEdep());
119 aMdcDigiCol->push_back(aMdcDigi);
125 StatusCode scMdc = m_evtSvc->registerObject(
"/Event/Digi/MdcDigiCol", aMdcDigiCol);
126 if(scMdc!=StatusCode::SUCCESS)
127 G4cout<<
"Could not register MDC digi collection" <<G4endl;
152 G4int tofDigiCollID = -1;
153 tofDigiCollID = m_DigiMan->GetDigiCollectionID(
"BesTofDigitsCollection");
155 if( tofDigiCollID>=0 ) {
157 G4int nDigi = tofDC->entries();
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() ) {
166 (*vecDC)[i] = (*vecDC)[j];
173 for(
int i=0; i<nDigi; i++ ) {
184 unsigned int layer = 0;
207 charge = (charge | 0x080000);
209 charge = ( (
time & 0x07e000) | charge );
216 if( charge & 0x80000 ) {
220 aTofDigiCol->push_back(tofDigi);
237 charge = (charge | 0x080000);
239 charge = ( (
time & 0x07e000) | charge);
246 if( charge & 0x80000 ) {
250 aTofDigiCol->push_back(tofDigi);
253 if( barrel_ec==3 || barrel_ec==4 ) {
254 unsigned int endcap = 0;
256 unsigned int strip = digi->
GetStrip();
263 unsigned int tleading;
267 else { tleading = 0; }
268 unsigned int ttrailing;
272 else { ttrailing = 0; }
275 aTofDigiCol->push_back( tofDigi );
287 else { tleading = 0; }
291 else { ttrailing = 0; }
292 tofDigi =
new TofDigi( ident, tleading, ttrailing );
294 aTofDigiCol->push_back( tofDigi );
303 StatusCode scTof = m_evtSvc->registerObject(
"/Event/Digi/TofDigiCol", aTofDigiCol);
304 if( scTof!=StatusCode::SUCCESS ) {
305 G4cout<<
"Could not register TOF digi collection" <<G4endl;
315 G4int emcDigiCollID = -1;
316 emcDigiCollID = m_DigiMan->GetDigiCollectionID(
"BesEmcDigitsCollection");
320 G4int nDigi = emcDC->entries();
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())
331 (*vecDC)[i] = (*vecDC)[j];
335 for(
int i=0;i<nDigi;i++)
346 aEmcDigiCol->push_back(emcDigi);
352 StatusCode scEmc = m_evtSvc->registerObject(
"/Event/Digi/EmcDigiCol", aEmcDigiCol);
353 if(scEmc!=StatusCode::SUCCESS)
354 G4cout<<
"Could not register EMC digi collection" <<G4endl;
380 G4int mucDigiCollID =-1;
381 mucDigiCollID = m_DigiMan->GetDigiCollectionID(
"BesMucDigisCollection");
385 G4int nDigi = mucDC->entries();
389 for(
int i = 0; i < nDigi; i++) {
394 aMucDigiCol->push_back(mucDigi);
400 StatusCode scMuc = m_evtSvc->registerObject(
"/Event/Digi/MucDigiCol", aMucDigiCol);
401 if(scMuc!=StatusCode::SUCCESS)
402 G4cout<<
"Could not register MUC digi collection" <<G4endl;
ObjectVector< EmcDigi > EmcDigiCol
G4TDigiCollection< BesEmcDigi > BesEmcDigitsCollection
ObjectVector< MdcDigi > MdcDigiCol
G4TDigiCollection< BesMdcDigi > BesMdcDigisCollection
ObjectVector< MucDigi > MucDigiCol
G4TDigiCollection< BesMucDigi > BesMucDigisCollection
ObjectVector< TofDigi > TofDigiCol
G4TDigiCollection< BesTofDigi > BesTofDigitsCollection
static BesMdcGeoParameter * GetGeo(void)
void setMeasure(const unsigned int measure)
static Identifier crystal_id(const unsigned int barrel_ec, const unsigned int theta_module, const unsigned int phi_module)
For a single crystal.
static Identifier wire_id(int wireType, int layer, int wire)
For a single wire.
static Identifier channel_id(int barrel_ec, int segment, int layer, int channel)
For a single crystal.
static int EmcChargeChannel(double charge)
static int MdcTimeChannel(double time)
static int EmcChargeMeasure(double charge)
static int MdcChargeChannel(double charge)
static unsigned int TofTimeChannel(double time)
static int EmcTimeChannel(double time)
void setTrackIndex(const int trackIndex)
void setOverflow(const unsigned int overflow)
static Identifier cell_id(int barrel_ec, int layer, int phi_module, int end)
For a single crystal.
static bool is_scin(const Identifier &id)
static value_type getPHI_BARREL_MAX()
static bool is_barrel(const Identifier &id)
Test for barrel.