#include "WCSimEventAction.hh" #include "WCSimTrajectory.hh" #include "WCSimRunAction.hh" #include "WCSimPrimaryGeneratorAction.hh" #include "WCSimWCHit.hh" #include "WCSimWCDigi.hh" #include "WCSimWCDigitizer.hh" #include "WCSimWCTrigger.hh" #include "WCSimWCAddDarkNoise.hh" #include "WCSimWCPMT.hh" #include "WCSimDetectorConstruction.hh" #include "G4Event.hh" #include "G4RunManager.hh" #include "G4EventManager.hh" #include "G4UImanager.hh" #include "G4TrajectoryContainer.hh" #include "G4VVisManager.hh" #include "G4ios.hh" #include "globals.hh" #include "G4ThreeVector.hh" #include "G4TransportationManager.hh" #include "G4Navigator.hh" #include "G4SDManager.hh" #include "G4DigiManager.hh" #include "G4UnitsTable.hh" #include "G4UIcmdWith3VectorAndUnit.hh" #include "G4PhysicalConstants.hh" #include "G4SystemOfUnits.hh" #include #include #include #include #include "jhfNtuple.h" #include "TTree.h" #include "TFile.h" #include "WCSimRootEvent.hh" #include "TStopwatch.h" #ifndef _SAVE_RAW_HITS #define _SAVE_RAW_HITS #ifndef _SAVE_RAW_HITS_VERBOSE //#define _SAVE_RAW_HITS_VERBOSE #endif #endif #ifndef SAVE_DIGITS_VERBOSE //#define SAVE_DIGITS_VERBOSE #endif #ifndef TIME_DAQ_STEPS //#define TIME_DAQ_STEPS #endif #ifndef NPMTS_VERBOSE #define NPMTS_VERBOSE 10 #endif WCSimEventAction::WCSimEventAction(WCSimRunAction* myRun, WCSimDetectorConstruction* myDetector, WCSimPrimaryGeneratorAction* myGenerator) :runAction(myRun), generatorAction(myGenerator), detectorConstructor(myDetector), ConstructedDAQClasses(false), SavedOptions(false) { DAQMessenger = new WCSimWCDAQMessenger(this); G4DigiManager* DMman = G4DigiManager::GetDMpointer(); //create PMT response module WCSimWCPMT* WCDMPMT = new WCSimWCPMT( "WCReadoutPMT", myDetector); DMman->AddNewModule(WCDMPMT); //create dark noise module WCSimWCAddDarkNoise* WCDNM = new WCSimWCAddDarkNoise("WCDarkNoise", detectorConstructor); DMman->AddNewModule(WCDNM); } WCSimEventAction::~WCSimEventAction() { delete DAQMessenger; } void WCSimEventAction::CreateDAQInstances() { if(ConstructedDAQClasses) { G4cerr << "WCSimEventAction::CreateDAQInstances() has already been called. Exiting..." << G4endl; exit(-1); } G4cout << "Creating digitizer and trigger class instances in WCSimEventAction::CreateDAQInstances()" << G4endl; G4DigiManager* DMman = G4DigiManager::GetDMpointer(); //create your choice of digitizer module if(DigitizerChoice == "SKI") { WCSimWCDigitizerSKI* WCDM = new WCSimWCDigitizerSKI("WCReadoutDigits", detectorConstructor, DAQMessenger); DMman->AddNewModule(WCDM); } else { G4cerr << "Unknown DigitizerChoice " << DigitizerChoice << G4endl; exit(-1); } //create your choice of trigger module if(TriggerChoice == "NDigits") { WCSimWCTriggerNDigits* WCTM = new WCSimWCTriggerNDigits("WCReadout", detectorConstructor, DAQMessenger); DMman->AddNewModule(WCTM); } else if(TriggerChoice == "NDigits2") { WCSimWCTriggerNDigits2* WCTM = new WCSimWCTriggerNDigits2("WCReadout", detectorConstructor, DAQMessenger); DMman->AddNewModule(WCTM); } else { G4cerr << "Unknown TriggerChoice " << TriggerChoice << G4endl; exit(-1); } ConstructedDAQClasses = true; } void WCSimEventAction::BeginOfEventAction(const G4Event*) { if(!ConstructedDAQClasses) { CreateDAQInstances(); //and save options in output file G4DigiManager* DMman = G4DigiManager::GetDMpointer(); } } void WCSimEventAction::EndOfEventAction(const G4Event* evt) { // ---------------------------------------------------------------------- // Get Particle Table // ---------------------------------------------------------------------- G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); // ---------------------------------------------------------------------- // Get Trajectory Container // ---------------------------------------------------------------------- G4TrajectoryContainer* trajectoryContainer = evt->GetTrajectoryContainer(); G4int n_trajectories = 0; if (trajectoryContainer) n_trajectories = trajectoryContainer->entries(); // ---------------------------------------------------------------------- // Get Event Information // ---------------------------------------------------------------------- G4int event_id = evt->GetEventID(); G4int mode = generatorAction->GetMode(); G4ThreeVector vtx = generatorAction->GetVtx(); G4int vtxvol = WCSimEventFindStartingVolume(vtx); G4int vecRecNumber = generatorAction->GetVecRecNumber(); // ---------------------------------------------------------------------- // Get WC Hit Collection // ---------------------------------------------------------------------- G4SDManager* SDman = G4SDManager::GetSDMpointer(); // Get Hit collection of this event G4HCofThisEvent* HCE = evt->GetHCofThisEvent(); WCSimWCHitsCollection* WCHC = 0; G4String WCIDCollectionName = detectorConstructor->GetIDCollectionName(); if (HCE) { G4String name = WCIDCollectionName; G4int collectionID = SDman->GetCollectionID(name); WCHC = (WCSimWCHitsCollection*)HCE->GetHC(collectionID); } // To use Do like This: // -------------------- // if (WCHC) // for (G4int i=0; i< WCHC->entries() ;i++) // G4cout << (*WCHC)[i]->GetTotalPe() << G4endl; // ---------------------------------------------------------------------- // Get Digitized Hit Collection // ---------------------------------------------------------------------- // Get a pointer to the Digitizing Module Manager G4DigiManager* DMman = G4DigiManager::GetDMpointer(); // Get a pointer to the WC PMT module WCSimWCPMT* WCDMPMT = (WCSimWCPMT*)DMman->FindDigitizerModule("WCReadoutPMT"); // new MFechner, aug 2006 // need to clear up the old info inside PMT WCDMPMT->ReInitialize(); #ifdef TIME_DAQ_STEPS TStopwatch* ms = new TStopwatch(); ms->Start(); #endif //Convert the hits to PMT pulse WCDMPMT->Digitize(); // // Do the Dark Noise, then Digitization, then Trigger // // // First, add Dark noise hits before digitizing //Get a pointer to the WC Dark Noise Module WCSimWCAddDarkNoise* WCDNM = (WCSimWCAddDarkNoise*)DMman->FindDigitizerModule("WCDarkNoise"); //Add the dark noise WCDNM->AddDarkNoise(); // // Next, do the digitization //Get a pointer to the WC Digitizer Module WCSimWCDigitizerBase* WCDM = (WCSimWCDigitizerBase*)DMman->FindDigitizerModule("WCReadoutDigits"); //Digitize the hits WCDM->Digitize(); // // Finally, apply the trigger //Get a pointer to the WC Trigger Module WCSimWCTriggerBase* WCTM = (WCSimWCTriggerBase*)DMman->FindDigitizerModule("WCReadout"); //tell it the dark noise rate (for calculating the average dark occupancy -> can adjust the NDigits threshold) WCTM->SetDarkRate(WCDNM->GetDarkRate()); //Apply the trigger // This takes the digits, and places them into trigger gates // Also throws away digits not contained in an trigger gate WCTM->Digitize(); #ifdef TIME_DAQ_STEPS ms->Stop(); G4cout << " Digtization : Real = " << ms->RealTime() << " ; CPU = " << ms->CpuTime() << "\n"; #endif // Get the post-noise hit collection for the WC G4int WCDChitsID = DMman->GetDigiCollectionID("WCRawPMTSignalCollection"); WCSimWCDigitsCollection * WCDC_hits = (WCSimWCDigitsCollection*) DMman->GetDigiCollection(WCDChitsID); // Get the digitized collection for the WC G4int WCDCID = DMman->GetDigiCollectionID("WCDigitizedCollection"); WCSimWCTriggeredDigitsCollection * WCDC = (WCSimWCTriggeredDigitsCollection*) DMman->GetDigiCollection(WCDCID); /* // To use Do like This: // -------------------- if(WCDC) for (G4int i=0; i < WCDC->entries(); i++) { G4int tubeID = (*WCDC)[i]->GetTubeID(); G4float photoElectrons = (*WCDC)[i]->GetPe(i); G4float time = (*WCDC)[i]->GetTime(i); // G4cout << "time " << i << " " <