Changeset 268 in Idarraga


Ignore:
Timestamp:
Mar 8, 2012, 3:10:30 PM (12 years ago)
Author:
idarraga
Message:

check hit collection valid

File:
1 edited

Legend:

Unmodified
Added
Removed
  • allpix/src/AllPixTrackerSD.cc

    r87 r268  
    7575
    7676/*
    77  * Second constructor for sensitive devices wich are
     77 * Second constructor for sensitive devices which are
    7878 * not actual pixel detectors
    7979 */
    80 AllPixTrackerSD::AllPixTrackerSD(G4String name,
    81                 G4ThreeVector absPos,
    82                 G4RotationMatrix * rot)
     80AllPixTrackerSD::AllPixTrackerSD(G4String name, G4ThreeVector absPos, G4RotationMatrix * rot)
    8381:G4VSensitiveDetector(name)
    8482{
     
    103101//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
    104102
     103/**
     104 * Runs once per event.  The hitsCollections pointers are retrieved
     105 *      I have a set of pointers to control that I get them right
     106 */
    105107void AllPixTrackerSD::Initialize(G4HCofThisEvent* HCE)
    106108{
    107109
     110        // Create the hit collection
    108111        hitsCollection = new AllPixTrackerHitsCollection
    109112                        (SensitiveDetectorName, collectionName[0]);
    110113
    111         //G4cout << "TrackerSD : " << SensitiveDetectorName << " " << collectionName[0] << G4endl;
    112 
    113114        static G4int HCID = -1;
    114115        HCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
    115116
     117        // Add to hits collection of this event
    116118        HCE->AddHitsCollection( HCID, hitsCollection );
    117119
     120        // Insert the pointer in a set to check its existence later
     121        // Normally there is only one instance of AllPixTrackerSD per sensitive volume
     122        m_hitsCollectionSet.insert(hitsCollection);
     123
    118124}
    119125
     
    124130{
    125131
     132        // Check first if we are working in a valid HitCollection
     133        try {
     134                if( m_hitsCollectionSet.find(hitsCollection) == m_hitsCollectionSet.end()) // not found !
     135                        throw hitsCollection;
     136        } catch (AllPixTrackerHitsCollection * h) {
     137                G4cout << "[WARNING] The following pointer to hitsCollection is invalid : " << h << G4endl;
     138                G4cout << "          The available set contains " << m_hitsCollectionSet.size() << " collections." << G4endl;
     139                G4cout << "          Trying to recover by ignoring this hit where this hitCollection" << G4endl;
     140                G4cout << "          has been given. AllPixTrackerSD::ProcessHits returns false." << G4endl;
     141                return false;
     142        }
     143
     144        // Work with the Hit
    126145        G4double edep = aStep->GetTotalEnergyDeposit();
    127146        if(edep==0.) return false;
     
    139158        G4ThreeVector correctedPos(0,0,0);
    140159
    141         if(m_thisIsAPixelDetector){
     160        if (m_thisIsAPixelDetector) {
    142161                // This positions are global, I will bring them to pixel-centered frame
    143162                // I can use the physical volumes for that
     
    174193                copyIDx_pre  = touchablepre->GetCopyNumber(1);
    175194        }
     195
    176196        // Look at the touchablepost only if in the same volume, i.e. in the sensitive Si Box
    177197        // If the hit is in a different pixel, it is still the same phys volume
     
    222242        newHit->SetParentVolumeName(aTrack->GetLogicalVolumeAtVertex()->GetName());
    223243
     244        //G4cout << "hitsCollection : " << hitsCollection << G4endl;
     245        //G4cout << "     entries --> " << hitsCollection->entries() << G4endl;
    224246        hitsCollection->insert(newHit);
    225 
    226247        //newHit->Print();
    227248        //newHit->Draw();
     
    238259        if(NbHits > 0)
    239260                G4cout << "--------> Hits Collection : " << collectionName[0] << " has " << NbHits << " hits " << G4endl;
     261
     262        // clear the Set of pointers to hitCollection used for verification
     263        m_hitsCollectionSet.clear();
    240264
    241265}
Note: See TracChangeset for help on using the changeset viewer.