10#include "BesMdcDigi.hh"
11#include "BesCgemDigi.hh"
12#include "BesTofDigi.hh"
13#include "BesEmcDigi.hh"
14#include "BesMucDigi.hh"
15#include "BesRawDataWriter.hh"
16#include "G4DigiManager.hh"
17#include "G4Svc/IG4Svc.h"
18#include "G4Svc/G4Svc.h"
20#include "Randomize.hh"
22#include "GaudiKernel/IDataProviderSvc.h"
23#include "GaudiKernel/ISvcLocator.h"
24#include "GaudiKernel/Bootstrap.h"
25#include "GaudiKernel/RegistryEntry.h"
26#include "GaudiKernel/MsgStream.h"
28#include "MdcRawEvent/MdcDigi.h"
29#include "CgemRawEvent/CgemDigi.h"
30#include "TofRawEvent/TofDigi.h"
31#include "EmcRawEvent/EmcDigi.h"
32#include "MucRawEvent/MucDigi.h"
34#include "Identifier/Identifier.h"
35#include "Identifier/MdcID.h"
36#include "Identifier/CgemID.h"
37#include "Identifier/TofID.h"
38#include "Identifier/EmcID.h"
39#include "Identifier/MucID.h"
41#include "RawEvent/RawDataUtil.h"
42#include "RawEvent/DigiEvent.h"
43#include "GaudiKernel/SmartDataPtr.h"
48 m_DigiMan = G4DigiManager::GetDMpointer();
53 StatusCode sc=Gaudi::svcLocator()->service(
"CgemGeomSvc", ISvc);
55 G4cout <<
" BesRawDataWriter::Error,could not open CgemGeomSvc"<<G4endl;
59 sc=Gaudi::svcLocator()->service(
"G4Svc", tmpSvc);
61 G4cout <<
" BesRawDataWriter::Error,could not open G4Svc"<<G4endl;
62 m_G4Svc=
dynamic_cast<G4Svc *
>(tmpSvc);
65 StatusCode scReal = Gaudi::svcLocator()->service(
"RealizationSvc",tmpReal);
66 if (!scReal.isSuccess())
68 std::cout <<
" Could not initialize Realization Service in BesRawDataWriter" << std::endl;
84 ISvcLocator* svcLocator = Gaudi::svcLocator();
85 StatusCode sc=svcLocator->service(
"EventDataSvc", m_evtSvc);
87 G4cout<<
"Could not accesss EventDataSvc!"<<G4endl;
90 sc = m_evtSvc->registerObject(
"/Event/Digi",aDigiEvent);
91 if(sc!=StatusCode::SUCCESS) {
92 G4cout<<
"Could not register DigiEvent" <<G4endl;
107 G4int mdcDigiCollID = -1;
108 mdcDigiCollID = m_DigiMan->GetDigiCollectionID(
"BesMdcDigisCollection");
112 G4int nDigi = mdcDC->entries();
117 for(
int i=0;i<nDigi;i++)
122 charge = int(mdcDigi->
GetEdep());
131 aMdcDigiCol->push_back(aMdcDigi);
137 StatusCode scMdc = m_evtSvc->registerObject(
"/Event/Digi/MdcDigiCol", aMdcDigiCol);
138 if(scMdc!=StatusCode::SUCCESS)
139 G4cout<<
"Could not register MDC digi collection" <<G4endl;
161 bool printFlag=
false;
163 G4cout <<
"|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << G4endl;
164 G4cout <<
"INFO : BesSim::BesRawDataWriter::SaveCgemDigits(), Begin!" << G4endl;
170 G4int cgemDigiCollID = -1;
171 cgemDigiCollID = m_DigiMan->GetDigiCollectionID(
"BesCgemDigisCollection");
172 if (cgemDigiCollID >= 0)
175 G4int nDigi = cgemDC->entries();
180 for(
int i=0;i<nDigi;i++)
182 cgemDigi=(*cgemDC)[i];
186 G4double frandom = G4UniformRand();
189 if(frandom > stripEff)
continue;
214 <<
" charge=" << charge << G4endl;
218 aCgemDigiCol->push_back(aCgemDigi);
225 StatusCode scCgem = m_evtSvc->registerObject(
"/Event/Digi/CgemDigiCol", aCgemDigiCol);
226 if(scCgem!=StatusCode::SUCCESS)
228 G4cout <<
"ERROR : BesSim::BesRawDataWriter::SaveCgemDigits(), Could not register CGEM digi collection! " << G4endl;
265 G4int tofDigiCollID = -1;
266 tofDigiCollID = m_DigiMan->GetDigiCollectionID(
"BesTofDigitsCollection");
271 G4int nDigi = tofDC->entries();
278 vector<BesTofDigi*>* vecDC = tofDC->GetVector();
279 for(
int i=0;i<nDigi-1;i++)
280 for(
int j=i+1;j<nDigi;j++)
281 if((*vecDC)[i]->GetTrackIndex()>(*vecDC)[j]->GetTrackIndex())
284 (*vecDC)[i] = (*vecDC)[j];
291 for(
int i=0;i<nDigi;i++)
310 unsigned int layer = 0;
312 unsigned int time =0;
317 if(barrel_ec == 0 || barrel_ec == 1 || barrel_ec == 2)
346 charge = (charge | 0x080000);
352 charge = ( (
time & 0x07e000) | charge) ;
360 if( charge & 0x80000 )
364 aTofDigiCol->push_back(tofDigi);
367 if(barrel_ec == 0 || barrel_ec == 1 || barrel_ec == 2)
394 charge = (charge | 0x080000);
396 charge = ( (
time & 0x07e000) | charge) ;
405 if( charge & 0x80000 )
409 aTofDigiCol->push_back(tofDigi);
422 else if(barrel_ec == 3 || barrel_ec == 4 || barrel_ec == 5 || barrel_ec == 6)
501 aTofDigiCol->push_back(tofDigi);
523 StatusCode scTof = m_evtSvc->registerObject(
"/Event/Digi/TofDigiCol", aTofDigiCol);
524 if(scTof!=StatusCode::SUCCESS)
525 G4cout<<
"Could not register TOF digi collection" <<G4endl;
555 G4int emcDigiCollID = -1;
556 emcDigiCollID = m_DigiMan->GetDigiCollectionID(
"BesEmcDigitsCollection");
560 G4int nDigi = emcDC->entries();
565 vector<BesEmcDigi*>* vecDC = emcDC->GetVector();
566 for(
int i=0;i<nDigi-1;i++)
567 for(
int j=i+1;j<nDigi;j++)
568 if((*vecDC)[i]->GetTrackIndex()>(*vecDC)[j]->GetTrackIndex())
571 (*vecDC)[i] = (*vecDC)[j];
575 for(
int i=0;i<nDigi;i++)
586 aEmcDigiCol->push_back(emcDigi);
592 StatusCode scEmc = m_evtSvc->registerObject(
"/Event/Digi/EmcDigiCol", aEmcDigiCol);
593 if(scEmc!=StatusCode::SUCCESS)
594 G4cout<<
"Could not register EMC digi collection" <<G4endl;
620 G4int mucDigiCollID =-1;
621 mucDigiCollID = m_DigiMan->GetDigiCollectionID(
"BesMucDigisCollection");
625 G4int nDigi = mucDC->entries();
629 for(
int i = 0; i < nDigi; i++) {
634 aMucDigiCol->push_back(mucDigi);
640 StatusCode scMuc = m_evtSvc->registerObject(
"/Event/Digi/MucDigiCol", aMucDigiCol);
641 if(scMuc!=StatusCode::SUCCESS)
642 G4cout<<
"Could not register MUC digi collection" <<G4endl;
ObjectVector< CgemDigi > CgemDigiCol
ObjectVector< EmcDigi > EmcDigiCol
G4TDigiCollection< BesCgemDigi > BesCgemDigisCollection
G4TDigiCollection< BesEmcDigi > BesEmcDigitsCollection
ObjectVector< MdcDigi > MdcDigiCol
G4TDigiCollection< BesMdcDigi > BesMdcDigisCollection
ObjectVector< MucDigi > MucDigiCol
G4TDigiCollection< BesMucDigi > BesMucDigisCollection
ObjectVector< TofDigi > TofDigiCol
G4TDigiCollection< BesTofDigi > BesTofDigitsCollection
G4double GetGlobalTime() const
G4double GetEnergyDeposit() const
G4int GetStripType() const
static BesMdcGeoParameter * GetGeo(void)
static int strip(const Identifier &id)
static int sheet(const Identifier &id)
static int layer(const Identifier &id)
static bool is_xstrip(const Identifier &id)
static Identifier strip_id(int f_layer, int f_sheet, int f_strip_type, int f_strip)
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.
value_type get_value() const
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 CgemTimeChannel(double time)
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)
static int CgemChargeChannel(double charge)
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 value_type getPHI_BARREL_MAX()
static bool is_barrel(const Identifier &id)
Test for barrel.
static Identifier cell_id_mrpc(int partID, int scinNum)