/// @file AllPixEventAction.cc /// @brief Implementation of the Allpix event action class. #include "AllPixEventAction.hh" #include "G4DigiManager.hh" #include "G4SDManager.hh" #include "G4PrimaryVertex.hh" //#include "AllPixMimosa26Digitizer.hh" #include "AllPixFEI3StandardDigitizer.hh" // geometry #include "ReadGeoDescription.hh" // // AllPixEventAction constructor. // AllPixEventAction::AllPixEventAction(AllPixRunAction* run){ m_run_action = run; m_nHC = 0; m_nDigitizers = 0; }//end of constructor. // // AllPixEventAction destructor. // AllPixEventAction::~AllPixEventAction() { } // // // G4String AllPixEventAction::GetNewName(G4String oldName, G4String toErase, G4String toAppend){ string oldName_s = oldName.data(); string toErase_s = toErase.data(); string toAppend_s = toAppend.data(); string fixedString; size_t pos = oldName_s.find_last_of(toErase) - toErase_s.size(); if(pos == string::npos) // couldn't find it return oldName; fixedString = oldName_s.substr(0,pos); fixedString.append(toAppend_s); return G4String(fixedString); } // // // void AllPixEventAction::SetDetectorDigitInput(G4double thl, G4int detId){ m_digiPtrs[detId]->SetDetectorDigitInputs(thl); } // // BeginOfEventAction method // void AllPixEventAction::BeginOfEventAction(const G4Event * /* evt */) { }//end of BeginOfEventAction method. // // AllPixEventAction::EndOfEventAction method. // void AllPixEventAction::EndOfEventAction(const G4Event * evt) { //G4cout << "* DEBUG: Called EndOfEventAction" << G4endl; // Get the pointer to the digitizer manager. G4DigiManager * fDM = G4DigiManager::GetDMpointer(); // Find the digitizer module and digitise //---------------------------------------- // Create a pointer for the digitisers. //AllPixMimosa26Digitizer * myDM; AllPixTimepixDigitizer * myDM; // Get the primary vertex. G4PrimaryVertex * pv = evt->GetPrimaryVertex(); // Loop over the digitizers. for (G4int itr = 0 ; itr < m_nDigitizers ; itr++) { // Get the current digitizer. //myDM = (AllPixMimosa26Digitizer*)fDM->FindDigitizerModule( digitizerModulesNames[itr] ); myDM = (AllPixTimepixDigitizer*)fDM->FindDigitizerModule( digitizerModulesNames[itr] ); // Set the primary vertex for the digitiser. myDM->SetPrimaryVertex(pv); // Digitise! // G4cout // << "* DEBUG: Calling the Digitize() method." << G4endl; myDM->Digitize(); }//end of loop over the digitizers. // digits will be retrieved at the end of the event in AllPixRun. // TW - this is what we probably need to change... // Check if we have reached the number of events required to // store the current frame. if ( //(evt->GetEventID()+1) % m_run_action->GetEventsPerFrame() == 0 (((evt->GetEventID()) % m_run_action->GetEventsPerFrame()) == 0) && (evt->GetEventID() > 0) ) { //G4cout // << "* DEBUG: Reached the end of event " << evt->GetEventID() << G4endl // << "* DEBUG: current frame number is " << m_run_action->GetCurrentFrameNum() << G4endl // << "*" << G4endl; // //G4cout << "* DEBUG: WRITING THE FRAME INFORMATION HERE - TO IMPLEMENT" << G4endl; // Get a pointer to the current run. //G4cout << "* DEBUG: Getting a pointer to the run manager." << G4endl; G4RunManager * run_mgr = G4RunManager::GetRunManager(); //G4cout << "* DEBUG: Getting a pointer to the current run." << G4endl; AllPixRun * run = (AllPixRun*)run_mgr->GetCurrentRun(); // Fill the ntuples with the current frame content. //G4cout << "* DEBUG: Attempting to fill the frames with FillFrames()." << G4endl; run->FillFrames(); //G4cout << "* DEBUG: RESET THE FRAME INFORMATION - TO IMPLEMENT" << G4endl; // If we've reached the limit of frames per ROOT file, // create a new ROOT file. if ((m_run_action->GetCurrentFrameNum() % m_run_action->GetFramesPerFile()) == 0) { //G4cout // << "*" << G4endl // << "*--------------------------------------------------" << G4endl // << "* DEBUG: Reached the limit of frames per ROOT file " << G4endl; // //G4cout << "* DEBUG: CREATING A NEW ROOT FILE - TO IMPLEMENT " << G4endl; //G4cout << "*------------------------------------------------" << G4endl; //G4cout << "*" << G4endl; // Delete the WriteToNtuple pointers. map::const_iterator nit = run->GetNtuplesBegin(); for (; nit!=run->GetNtuplesEnd(); ++nit) { (nit->second)->NextNtuple(); } } // Increment the frame counter (will WriteToNtuple do this for us?) m_run_action->IncrementFrameNumber(); }//end of "end of frame" check. //G4cout << "* DEBUG: End of EndOfEventAction" << G4endl; //G4cout << "* DEBUG:" << G4endl; }//end of AllPixEventAction::EndOfEventAction method.