00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "GaudiKernel/ISvcLocator.h"
00013 #include "GaudiKernel/Bootstrap.h"
00014 #include "GaudiKernel/IDataProviderSvc.h"
00015 #include "GaudiKernel/MsgStream.h"
00016 #include "G4Svc/IG4Svc.h"
00017 #include "G4Svc/G4Svc.h"
00018 #include "G4DigiManager.hh"
00019 #include "ReadBoostRoot.hh"
00020 #include "ScintSingle.hh"
00021 #include "Randomize.hh"
00022 #include "BesTofDigitizer.hh"
00023
00024
00025 BesTofDigitizer::BesTofDigitizer(G4String modName):G4VDigitizerModule(modName) {
00026
00027 collectionName.push_back("BesTofDigitsCollection");
00028 m_besTofDigitsCollection=0;
00029
00030
00031 tofDMBr1 = new BesTofDigitizerBrV1();
00032 tofDMEc1 = new BesTofDigitizerEcV1();
00033 tofDMBr2 = new BesTofDigitizerBrV2();
00034 tofDMEc2 = new BesTofDigitizerEcV2();
00035 tofDMEc3 = new BesTofDigitizerEcV3();
00036 tofDMEc4 = new BesTofDigitizerEcV4();
00037
00038
00039
00040
00041
00042
00043
00044
00045 ISvcLocator* svcLocator = Gaudi::svcLocator();
00046 IRealizationSvc *tmpReal;
00047 StatusCode scReal = svcLocator->service("RealizationSvc",tmpReal);
00048 if (!scReal.isSuccess()) {
00049 std::cout << " Could not initialize Realization Service in BesTofDigitizerBrV2" << std::endl;
00050 }
00051 else {
00052 m_RealizationSvc = dynamic_cast<RealizationSvc*>(tmpReal);
00053 }
00054
00055 m_versionBr=2;
00056
00057 if( ReadBoostRoot::GetTof()==3 || ReadBoostRoot::GetTof()==4 ) {
00058 m_versionEc=4;
00059 std::cout << std::endl << "TofSim: BesTofDigitizer You are using the new End Cap Tof (MRPC) Digitizer!" << std::endl;
00060 }
00061 else {
00062 m_versionEc=3;
00063 std::cout << std::endl << "TofSim: BesTofDigitizer You are using the old End Cap Tof (Scintillator) Digitizer!" << std::endl;
00064 }
00065
00066 }
00067
00068
00069 BesTofDigitizer::~BesTofDigitizer() {
00070
00071 delete tofDMBr1;
00072 delete tofDMEc1;
00073 delete tofDMBr2;
00074 delete tofDMEc2;
00075 delete tofDMEc3;
00076 delete tofDMEc4;
00077 }
00078
00079
00080 void BesTofDigitizer::Digitize() {
00081
00082 m_besTofDigitsCollection = new BesTofDigitsCollection( moduleName, collectionName[0] );
00083 G4DigiManager* digiManager = G4DigiManager::GetDMpointer();
00084 G4int THCID = digiManager->GetHitsCollectionID("BesTofHitsCollection");
00085 m_THC = (BesTofHitsCollection*) (digiManager->GetHitsCollection(THCID));
00086
00087 if( m_THC ) {
00088 m_scintGroup = new vector<ScintSingle*>;
00089 GroupHits();
00090 G4int size = m_scintGroup->size();
00091
00092
00093
00094 ScintSingle* scint;
00095 G4int partId;
00096 for( G4int i=0; i<size; i++ ) {
00097 scint = (*m_scintGroup)[i];
00098 partId = scint->GetPartId();
00099
00100
00101
00102 if( partId==1 ) {
00103 if( m_versionBr==1 )
00104 tofDMBr1->Digitize(scint,m_besTofDigitsCollection);
00105 else if( m_versionBr==2 ) {
00106
00107 tofDMBr2->Digitize(scint,m_besTofDigitsCollection);
00108 }
00109 else {
00110 tofDMBr2->Digitize(scint,m_besTofDigitsCollection);
00111 }
00112 }
00113 else {
00114 if( m_versionEc==1 ) {
00115 tofDMEc1->Digitize(scint,m_besTofDigitsCollection);
00116 }
00117 else if( m_versionEc==2 ) {
00118 tofDMEc2->Digitize(scint,m_besTofDigitsCollection);
00119 }
00120 else if( m_versionEc==3 ) {
00121 tofDMEc3->Digitize(scint,m_besTofDigitsCollection);
00122 }
00123 else if( m_versionEc==4 ) {
00124 tofDMEc4->Digitize(scint,m_besTofDigitsCollection);
00125 }
00126 else {
00127 cout << "TofSim: Warning: BesTofDigitizerEcV2 is utilized otherwise!" << endl;
00128 tofDMEc2->Digitize(scint,m_besTofDigitsCollection);
00129 }
00130 }
00131 }
00132
00133 if( m_scintGroup ) {
00134 for( size_t i=0; i<m_scintGroup->size(); i++ ) {
00135 delete (*m_scintGroup)[i];
00136
00137
00138 }
00139 m_scintGroup->clear();
00140 delete m_scintGroup;
00141 }
00142 }
00143
00144 StoreDigiCollection(m_besTofDigitsCollection);
00145 }
00146
00147
00148 void BesTofDigitizer::GroupHits() {
00149
00150 G4int partId, scinNb,size,flag,trackId;
00151 G4double edep;
00152 BesTofHit* hit;
00153 G4int nHits = m_THC->entries();
00154
00155
00156 vector<G4int> deadTrackVec;
00157 deadTrackVec.clear();
00158 G4int runId = m_RealizationSvc->getRunId();
00159 if( ( runId>=-11396 && runId<=-8093 ) || ( runId>-80000 && runId<=-23463 ) ) {
00160 G4int previousTrack = -999;
00161 vector<G4int> trackVec;
00162 trackVec.clear();
00163 for( G4int i=0; i<nHits; i++ ) {
00164 hit = (*m_THC)[i];
00165 trackId = hit->GetTrackIndex();
00166 if( trackId != previousTrack ) {
00167 previousTrack = trackId;
00168 bool same = false;
00169 vector<G4int>::iterator iter = trackVec.begin();
00170 for( ; iter!=trackVec.end(); iter++ ) {
00171 if( (*iter) == trackId ) {
00172 same = true;
00173 break;
00174 }
00175 }
00176 if( !same ) {
00177 trackVec.push_back( trackId );
00178 G4double ranSignal = G4UniformRand();
00179 if( ranSignal>0.988 ) {
00180 deadTrackVec.push_back( trackId );
00181 }
00182 }
00183 }
00184 }
00185 }
00186
00187
00188
00189 for (G4int i=0;i<nHits;i++) {
00190 hit=(*m_THC)[i];
00191
00192 if( ( runId>=-11396 && runId<=-8093 ) || ( runId>-80000 && runId<=-23463 ) ) {
00193 trackId = hit->GetTrackIndex();
00194 partId = hit->GetPartId();
00195 bool aband = false;
00196 vector<G4int>::iterator iter = deadTrackVec.begin();
00197 for( ; iter!=deadTrackVec.end(); iter++ ) {
00198 if( ( trackId == (*iter) ) && ( partId!=3 && partId!=4 ) ) { aband = true; }
00199 }
00200 if( aband ) continue;
00201 }
00202
00203 partId = hit->GetPartId();
00204 scinNb = hit->GetScinNb();
00205 edep = hit->GetEdep();
00206 size = m_scintGroup->size();
00207 flag = 0;
00208 if( size>0 ) {
00209 ScintSingle* oldScint;
00210 for( G4int j=0; j<size; j++ ) {
00211 oldScint = (*m_scintGroup)[j];
00212 if( oldScint->GetPartId()==partId && oldScint->GetScinNb()==scinNb ) {
00213
00214 oldScint->GetHitIndexes()->push_back(i);
00215
00216 oldScint->AddEdep(edep);
00217 flag=1;
00218 break;
00219 }
00220 }
00221 }
00222
00223 if( flag==0 ) {
00224 ScintSingle* newScint = new ScintSingle;
00225 newScint->SetPartId(partId);
00226 newScint->SetScinNb(scinNb);
00227 newScint->SetEdep(edep);
00228 newScint->GetHitIndexes()->push_back(i);
00229 m_scintGroup->push_back(newScint);
00230
00231
00232 }
00233 }
00234
00235 }