00001 #include "LCDG4CalSD.hh"
00002
00003
00004
00005
00006
00007
00008
00009 #include <map>
00010 using std::map;
00011 #include <fstream>
00012 using std::ifstream;
00013
00014
00015
00016
00017 LCDG4CalSD::LCDG4CalSD(G4String name)
00018 : G4VSensitiveDetector(G4String("/lcddet/")+name)
00019 , HCID(-1)
00020 , layer0CenterDepth(0)
00021 , layerThickness(0)
00022 , debugLevel(0)
00023 {
00024
00025
00026
00027 ifstream* debfile = new ifstream("debfile");
00028 if(debfile) {
00029 *debfile >> debugLevel;
00030 debfile->close();
00031 delete debfile;
00032 debfile = 0;
00033 }
00034
00035
00036 G4String HCname = name+"Collection";
00037 collectionName.insert( HCname );
00038
00039 G4cout<< "SensitiveDetectorName = "<< SensitiveDetectorName << G4endl;
00040 }
00041
00042
00043
00044
00045 LCDG4CalSD::~LCDG4CalSD() {
00046
00047
00048 }
00049
00050
00051
00052
00053 void LCDG4CalSD::Initialize(G4HCofThisEvent* HCE) {
00054
00055 _hitCollection =
00056 new LCDG4CalHitsCollection(SensitiveDetectorName,
00057 collectionName[0]);
00058
00059 if(HCID < 0) HCID = GetCollectionID(0);
00060
00061 HCE->AddHitsCollection(HCID,_hitCollection);
00062 }
00063
00064
00065
00066
00067 G4bool LCDG4CalSD::ProcessHits(G4Step* aStep, G4TouchableHistory* ROhist) {
00068
00069 G4double edep = aStep->GetTotalEnergyDeposit();
00070 if(edep==0) return false;
00071
00072 const G4VPhysicalVolume* physVol
00073 = aStep->GetPreStepPoint()->GetPhysicalVolume();
00074 if( ROhist!=NULL ) {
00075 G4VPhysicalVolume* ROvol = ROhist->GetVolume();
00076 if(ROvol!=physVol) {
00077 G4cout<<"ROvol="<< ROvol <<", physVol="<< physVol <<G4endl;
00078 }
00079 }
00080
00081
00082 unsigned int& sysNo = index[0];
00083 unsigned int& layno = index[1];
00084
00085 G4LogicalVolume* logVol=physVol->GetLogicalVolume();
00086 #ifndef TXT_MODE
00087
00088 if (!_mapsens[logVol]) return false;
00089 #endif
00090
00091 sysNo = _mapsys[logVol];
00092 layno = _maplayer[logVol];
00093 barend = _mapbe[logVol];
00094 north = _mapns[logVol];
00095
00096 G4Track* ptrk = aStep->GetTrack();
00097 G4int trkID = ptrk->GetTrackID();
00098 G4double tdep = ptrk->GetGlobalTime();
00099
00100
00101 G4ThreeVector pos = 0.5*(aStep->GetPreStepPoint()->GetPosition()+
00102 aStep->GetPostStepPoint()->GetPosition() );
00103
00104 if(debugLevel) {
00105 G4cout << "\nCheck PhysVol on pre/post step: "
00106 <<aStep->GetPreStepPoint()->GetPhysicalVolume()->GetName() <<' '
00107 <<aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName()<<G4endl;
00108 G4cout << "Hit in layer " << layno << G4endl
00109 << "hit info (x,y,z)=("<< pos.x() <<';'<< pos.y() <<';'<< pos.z()
00110 <<"), cylRho="<< pos.rho() <<", th="<< pos.theta() <<", phi="<< pos.phi()
00111 << G4endl;
00112 }
00113
00114
00115 unsigned int cellIndex = findCell(pos);
00116 G4ThreeVector cellCenter = getCellCenter(cellIndex);
00117 if(debugLevel) {
00118 G4cout<< "cellIndex="<< cellIndex
00119 <<'/'<< getIndex3(cellIndex)
00120 <<'/'<< getIndex2(cellIndex)
00121 <<'/'<< getIndex1(cellIndex) <<'/'<< sysNo
00122 << " -> cell center info (x,y,z)=("<< cellCenter.x() <<';'<< cellCenter.y() <<';'<< cellCenter.z()
00123 <<"), cylRho="<< cellCenter.rho() <<", th="<< cellCenter.theta() <<", phi="<< cellCenter.phi() <<' '<<", north="<< north << G4endl;
00124 }
00125
00126
00127 LCDG4CalHit *hit = NULL;
00128 map<int,LCDG4CalHit*>::iterator pcellhit = _cellhit.find(cellIndex);
00129 if( pcellhit!=_cellhit.end() ) hit = _cellhit.find(cellIndex)->second;
00130 if(hit == NULL) {
00131 if (debugLevel>3) G4cout << "creating new hit cell" << G4endl;
00132 hit = new LCDG4CalHit();
00133 hit->SetSystem(sysNo);
00134 hit->SetBarEnd(barend);
00135 hit->SetNorth(north);
00136 hit->SetLayer(layno);
00137
00138
00139 hit->SetPos(cellCenter);
00140
00141
00142 hit->SetPhi( getIndex1(cellIndex) );
00143 hit->SetTheta( getIndex2(cellIndex) );
00144
00145
00146 _hitCollection->insert(hit);
00147 _cellhit.insert( std::pair<G4int,LCDG4CalHit*>( cellIndex, hit) );
00148 }
00149
00150 if (_mapsens[logVol]) {
00151
00152 hit->AddMcPart(trkID,edep,tdep);
00153 } else {
00154
00155 hit->AddMcPartAbs(edep);
00156 }
00157 if(debugLevel>3) {
00158 G4cout<<"After adding hit: hit(edep,edepa) = "
00159 << hit->GetEdep() <<' '<< hit->GetEdepAbs() << G4endl;
00160 }
00161
00162
00163
00164
00165
00166
00167
00168 return true;
00169 }
00170
00171
00172
00173
00174
00175 void LCDG4CalSD::EndOfEvent(G4HCofThisEvent* HCE) {
00176 if(HCE) ;
00177
00178
00179 _cellhit.clear();
00180 }
00181
00182
00183
00184
00185
00186 G4int LCDG4CalSD::AddLogVolInfo(G4LogicalVolume* g4logvol,
00187 G4int startlayerNo,
00188 G4int sysNo, G4int be,
00189 G4int ns, G4int sens)
00190 {
00191 _maplayer.insert(std::pair<G4LogicalVolume*,G4int>(g4logvol,startlayerNo));
00192 _mapsys.insert(std::pair<G4LogicalVolume*,G4int>(g4logvol,sysNo));
00193 _mapbe.insert(std::pair<G4LogicalVolume*,G4int>(g4logvol,be));
00194 _mapns.insert(std::pair<G4LogicalVolume*,G4int>(g4logvol,ns));
00195 _mapsens.insert(std::pair<G4LogicalVolume*,G4int>(g4logvol,sens));
00196 return _maplayer.size();
00197 }
00198
00199
00200
00201
00202 void LCDG4CalSD::clear() {
00203 }
00204
00205
00206
00207
00208 void LCDG4CalSD::DrawAll() {
00209 }
00210
00211
00212
00213
00214 void LCDG4CalSD::PrintAll() {
00215 }