Message: Bug in Hits Collection ?? Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Question Bug in Hits Collection ?? 

Keywords: HitsCollection
Forum: Hits, Digitization and Pileup
Date: 24 Dec, 2003
From: Sylvian Kahane <skahane@bgumail.bgu.ac.il>

I have the following simple DetectorSD.cpp file in which I try to define 4
different hits collections corresponding to 4 physical volumes obtained
by different placements of the same logical volume:

//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....

#include "DetectorSD.hh"

#include "DetectorHit.hh"
#include "DetectorConstruction.hh"

#include "G4VPhysicalVolume.hh"
#include "G4Step.hh"
#include "G4VTouchable.hh"
#include "G4TouchableHistory.hh"
#include "G4SDManager.hh"

#include "G4ios.hh"

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....

DetectorSD::DetectorSD(G4String name, DetectorConstruction* det)
:G4VSensitiveDetector(name),Detector(det)
{
  collectionName.insert("Leaf1");
  collectionName.insert("Leaf2");
  collectionName.insert("Leaf3");
  collectionName.insert("Leaf4");
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....

DetectorSD::~DetectorSD()
{;}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....

void DetectorSD::Initialize(G4HCofThisEvent*HCE)
{
  G4int CollID;

  Leaf1 = new DetectorHitsCollection(SensitiveDetectorName,collectionName[0]);
  Leaf1->insert(new DetectorHit());
  //CollID = GetCollectionID(collectionName[0]); 
  CollID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]); 
  HCE->AddHitsCollection(CollID,Leaf1);

  Leaf2 = new DetectorHitsCollection(SensitiveDetectorName,collectionName[1]);
  Leaf2->insert(new DetectorHit());
  //CollID = GetCollectionID(collectionName[1]); 
  CollID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[1]); 
  HCE->AddHitsCollection(CollID,Leaf2);

  Leaf3 = new DetectorHitsCollection(SensitiveDetectorName,collectionName[2]);
  Leaf3->insert(new DetectorHit());
  //CollID = GetCollectionID(collectionName[2]); 
  CollID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[2]); 
  HCE->AddHitsCollection(CollID,Leaf3);

  Leaf4 = new DetectorHitsCollection(SensitiveDetectorName,collectionName[3]);
  Leaf4->insert(new DetectorHit());
  //CollID = GetCollectionID(collectionName[3]); 
  CollID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[3]); 
  HCE->AddHitsCollection(CollID,Leaf4);
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....

G4bool DetectorSD::ProcessHits(G4Step* aStep,G4TouchableHistory* ROhist)
{
  G4double edep = aStep->GetTotalEnergyDeposit();

  G4TouchableHistory* theTouchable
    = (G4TouchableHistory*)(aStep->GetPreStepPoint()->GetTouchable());

  G4VPhysicalVolume* physVol = theTouchable->GetVolume(); 

  G4int copyNo;
  copyNo = theTouchable->GetReplicaNumber();

  if(copyNo==0) (*Leaf1)[0]->AddHit();
  if(copyNo==1) (*Leaf2)[0]->AddHit();
  if(copyNo==2) (*Leaf3)[0]->AddHit();
  if(copyNo==3) (*Leaf3)[0]->AddHit();

  return true;
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....

void DetectorSD::EndOfEvent(G4HCofThisEvent* HCE)
{;}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....

void DetectorSD::clear()
{;}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....

void DetectorSD::DrawAll()
{;}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....

void DetectorSD::PrintAll()
{;}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....



In the run I am getting an error trigered by the line:

     if(copyNo==2) (*Leaf3)[0]->AddHit();

because it happened that copyNo=2. The error message is cryptical and
not usefull:

Unhandled exception at 0x0041d934 in SolidAngle2.exe: 0xC0000005: 
Access violation reading location 0xcdcdcdf9.


The debuger points to a location in the file g4thitscollection.hh and
gives the following assembly code:

  public: // with description

      inline T* operator[](size_t i) const

      { return (*((std::vector<T*>*)theCollection))[i]; }
0041D910  push        ebp  
0041D911  mov         ebp,esp 
0041D913  sub         esp,44h 
0041D916  push        ebx  
0041D917  push        esi  
0041D918  push        edi  
0041D919  push        ecx  
0041D91A  lea         edi,[ebp-44h] 
0041D91D  mov         ecx,11h 
0041D922  mov         eax,0CCCCCCCCh 
0041D927  rep stos    dword ptr [edi] 
0041D929  pop         ecx  
0041D92A  mov         dword ptr [ebp-4],ecx 
0041D92D  mov         eax,dword ptr [i] 
0041D930  push        eax  
0041D931  mov         ecx,dword ptr [this] 
0041D934  mov         ecx,dword ptr [ecx+2Ch] <-<-<-<- the debugger points here
0041D937  call        std::vector<DetectorHit *,std::allocator<DetectorHit *> >::operator[] (41DA00h) 
0041D93C  mov         eax,dword ptr [eax] 
0041D93E  pop         edi  
0041D93F  pop         esi  
0041D940  pop         ebx  
0041D941  add         esp,44h 
0041D944  cmp         ebp,esp 
0041D946  call        __chkesp (800C80h) 
0041D94B  mov         esp,ebp 
0041D94D  pop         ebp  
0041D94E  ret         4    


It seems that it has something to do with templates. I may add that
the method AddHit() I am trying to apply is a very simple hit counter:

              void AddHit () { nofHits += 1;};
              G4double GetnofHits() { return nofHits;


The program and all the libraries where compiled with VC++ 6 in the
most conservative mode, i.e. single threaded debug mode.


To all Geant gurus:  what's wrong with the program ?

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

 Add Message Add Message
to: "Bug in Hits Collection ??"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews


[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]