Message: sensitive detector Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

None sensitive detector 

Keywords: sensitive detector
Forum: Hits, Digitization and Pileup
Date: 15 Mar, 2006
From: Raffaello Trentadue <Raffaello Trentadue>

Dear all, I need help about the "sensitive Detector".

To make it, I used the following procedure:

in the DetectorConstruction.cc, inside the definition of function construct() I inserted the code:

G4VSensitiveDetector* target;

.........................

  G4ThreeVector positionTarget = G4ThreeVector(0,0,0);

  G4Box* solidTarget = new G4Box("target",expTarget_x,expTarget_y,expTarget_z);
  logicTarget = new G4LogicalVolume(solidTarget,Bakelite,"Target",0,0,0);
  physTarget = new G4PVPlacement(0,               // no rotation
				  positionTarget,  // at (x,y,z)
				  logicTarget,     // its logical volume				  
				  "Target",        // its name
			          experimentalHall_log,      // its mother  volume

..........................

  // sensitive detectors -----------------------------------------------------

  G4SDManager* SDman = G4SDManager::GetSDMpointer();
  G4String SDname;

  //  target = new ExN01Target(SDname="target");
  target = new ExN01Target("target");

  SDman->AddNewDetector(target);
  logicTarget->SetSensitiveDetector(target);

______________________________________________________________________

Then I defined the a class called ExN01Target, introducing this code:

ExN01Target::ExN01Target(G4String name)
:G4VSensitiveDetector(name)
{
  G4String HCname;
  collectionName.insert(HCname="targetCollection");
  HCID = -1;
}

ExN01Target::~ExN01Target(){;}

void ExN01Target::Initialize(G4HCofThisEvent*HCE)
{
  hitsCollection = new ExN01TargetHitsCollection
                   (SensitiveDetectorName,collectionName[0]);
  if(HCID<0)
  { HCID = G4SDManager::GetSDMpointer()->GetCollectionID(hitsCollection); }
  HCE->AddHitsCollection(HCID,hitsCollection);
}

G4bool ExN01Target::ProcessHits.......................

______________________________________________________________________

After that I created the class ExN01TargetHit, following the exemple4 of the tutorial done at CERN.

At the end, I put in EventAction.cc:

ExN01EventAction::ExN01EventAction()
{
  G4String colName;
  G4SDManager* SDman = G4SDManager::GetSDMpointer();
  HHC1ID = SDman->GetCollectionID(colName="target/targetCollection");
  verboseLevel = 1;
  messenger = new ExN01EventActionMessenger(this);
}

ExN01EventAction::~ExN01EventAction() { }

void ExN01EventAction::BeginOfEventAction(const G4Event*) { }

void ExN01EventAction::EndOfEventAction(const G4Event* evt)
{
  G4HCofThisEvent * HCE = evt->GetHCofThisEvent();
  ExN01TargetHitsCollection* HHC1 = 0;

  if(HCE)
  {
    HHC1 = (ExN01TargetHitsCollection*)(HCE->GetHC(HHC1ID));
      }

  // Diagnostics

  if (verboseLevel==0 || evt->GetEventID() % verboseLevel != 0) return;

  G4PrimaryParticle* primary = evt->GetPrimaryVertex(0)->GetPrimary(0);
  G4cout << G4endl
         << ">>> Event " << evt->GetEventID() << " >>> Simulation truth : "
         << primary->GetG4code()->GetParticleName()
         << " " << primary->GetMomentum() << G4endl;

// if(HCE) // { // int n_hit = HHC1->entries(); // G4cout << "Target 1 has " << n_hit << " hits." << G4endl; // for(int i1=0;i1<n_hit;i1++) // { // ExN01TargetHit* aHit = (*HHC1)[i1]; // aHit->Print(); // } // } }

If I uncomment the commented piece the software crash when I run the command /run/beamOn. On the other hand when it is commented it seam working but there is a message:

<target/targetCollection> is not found

Therefore there is no output about the sensitive detector.

Could anybody help me about this?

Thanks Raffaello

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

1 None: Re: sensitive detector   (Makoto Asai - 15 Mar, 2006)
 Add Message Add Message
to: "sensitive detector"

 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 ]