/// @file AllPixRun.cc /// @brief Implementation of the Allpix run class. #include "AllPixRun.hh" // // AllPixRun constructor. // AllPixRun::AllPixRun( AllPixDetectorConstruction * det, TString ofp, TString dataset, TString tempDir ) : m_detectorPtr(det), m_outputFilePrefix(ofp), m_currentFrame(1) { G4cout << "* INFO:==================" << G4endl << "* INFO: CONSTRUCTING RUN " << G4endl << "* INFO:==================" << G4endl; // From J. Idarraga: // "Call for an instance to write. Need to know how // many detectors do I have. I have as many as // the number of digitizers. At this point the digitizer // modules have already been created." // Get the geometry description(s). extern ReadGeoDescription * g_GeoDsc; // already loaded ! :) map * geoMap = g_GeoDsc->GetDetectorsMap(); map::iterator detItr; // Get the Digi collection information. m_datasetDigits = dataset; m_datasetDigits += "_det_"; G4cout << "* INFO: Digi coll. base name: '" << m_datasetDigits << "'" << G4endl; m_tempdir = tempDir; G4cout << "* INFO: output directory : '" << m_tempdir << "'" << G4endl; // Get the number of detectors. m_nOfDetectors = (G4int) geoMap->size(); G4cout << "* INFO: number of detectors : " << m_nOfDetectors << G4endl; G4cout << "* INFO:" << G4endl; // Get the start time (taken from the system time). m_startTime = time(&m_timer); m_currentTime = m_startTime; m_timeHandler = new TimeHandler(m_startTime); //G4cout << "* DEBUG: The start time is " << Utils::MyWid(m_startTime,20,2) << " [s]." << G4endl; //G4cout << "* DEBUG: (i.e. " << m_timeHandler->GetPixelmanTime() << ")" << G4endl; // Create as many frame handlers as there are pixel detectors. m_frames = new FramesHandler * [m_nOfDetectors]; //TString tempDataset = ""; //vector basenames; stringstream basename; // Loop over the detectors in the geometry map and create an ntuple // file for each of them with the WriteToNtuple object. int cntr = 0; for (detItr = geoMap->begin() ; detItr != geoMap->end() ; detItr++) { // Reset the base name. basename.str(""); // Add the chip ID (from the XML file/macro). basename << (*detItr).second->GetChipID() << "_"; // Add the dataset ID basename << dataset; //G4cout << "* DEBUG: basename is " << basename.str() << G4endl; // Instantiate a FramesHandler object that will, well, handle the // frames. m_frames[cntr] = new FramesHandler(dataset); // Set the non-frame dependent metadata values from the detector // description. // TODO: Move this to a separate method for clarity. // Set the detector integer ID. m_frames[cntr]->SetDetectorId((*detItr).first); // Set the dataset ID. m_frames[cntr]->getFrameStructObject()->SetDataSet(dataset); // Fill the metadata from the detector information. this->FillDetectorMetaData(detItr->first, cntr, detItr->second); // Map the XML detector ID integer to a sequential index. m_detIdToIndex[(*detItr).first] = cntr; // Create the WriteToNtuple object for the detector. m_ntuples[(*detItr).first] = new WriteToNtuple(basename.str(), tempDir); // Increment the detector counter. cntr++; }//end of loop over the detectors. /* G4DigiManager * fDM = G4DigiManager::GetDMpointer(); G4int nDC = fDM->GetDCtable()->entries(); m_nOfDetectors = nDC; m_datasetDigits = dataset; // append to dataset if there is more than 1 detector if(m_nOfDetectors > 1) m_datasetDigits += "_det_"; m_tempdir = tempDir; // create as many frame handlers as pixel detectors m_frames = new FramesHandler * [m_nOfDetectors]; TString tempDataset = m_datasetDigits; for(Int_t i = 0 ; i < m_nOfDetectors ; i++){ if(m_nOfDetectors > 1) { tempDataset = m_datasetDigits; tempDataset += i; // append detector id } // FramesHandler constructor will communicate to FrameStruct // the dataset. m_frames[i] = new FramesHandler(tempDataset); // id control ! m_frames[i]->SetDetectorId(i); // FIXME // m_frames[i]->SetnX(2048); m_frames[i]->SetnY(2048); } */ /* TW commented out 2014-06-17 ////////////////////////////////////////////////////// // Simple hits // create as many SimpleHits as SD // SD manager G4SDManager * SDman = G4SDManager::GetSDMpointer(); G4HCtable * SDTable = SDman->GetHCtable(); G4int nSD = SDTable->entries(); m_nOfSD = nSD; m_storableHits = new SimpleHits*[nSD]; for (Int_t i = 0 ; i < nSD ; i++) { // FramesHandler constructor will communicate to FrameStruct // the dataset. m_storableHits[i] = new SimpleHits; m_storableHits[i]->Rewind(); } // Append to name of digits file // Will generate the name later on //m_datasetHits = dataset; */ // TW commented out for now - 2014-02-17 // // LCIO Bridge // // coming from AllPixRunAction // m_lciobridge_f = 0x0; // m_lciobridge_dut_f = 0x0; // /TW // Clear the source particle vectors. m_pri_x.clear(); m_pri_y.clear(); m_pri_z.clear(); // m_pri_px.clear(); m_pri_py.clear(); m_pri_pz.clear(); // m_pri_kinE.clear(); m_pri_m.clear(); // m_pri_id.clear(); }//end of the AllPixRun constructor. // // AllPixRun destructor. // AllPixRun::~AllPixRun() { //G4cout << "* DEBUG: Reached AllPixRun destructor." << G4endl; /* // TW moved to AllPixRunAction destructor for now? 2014-02-18 // erase frame handlers for (int i = 0 ; i < m_nOfDetectors ; i++) { delete m_frames[i]; // delete object using pointer } delete[] m_frames; // delete array */ // /Tw //G4cout << "* DEBUG: number of ntuples = " << m_ntuples.size() << G4endl; // Delete the WriteToNtuple pointers. map::iterator nit = m_ntuples.begin(); for (; nit!=m_ntuples.end(); ++nit) { (nit->second)->closeNtuple(); } //G4cout << "* DEBUG: Deleted the WriteToNtuple objects." << G4endl; // TW commented out // // Erase the storable hits // for (int i = 0 ; i < m_nOfSD ; i++) { // delete m_storableHits[i]; // } //delete[] m_storableHits; delete m_timeHandler; G4cout << "* INFO: " << G4endl << "* INFO:================" << G4endl << "* INFO: DESTROYING RUN " << G4endl << "* INFO:================" << G4endl; }//end of AllPixRun destructor. // // // void AllPixRun::FillFramesNtuple(const G4Run* /* aRun */ ) { /* // geo description extern ReadGeoDescription * g_GeoDsc; // already loaded ! :) map * geoMap = g_GeoDsc->GetDetectorsMap(); map::iterator detItr; int cntr; for( detItr = geoMap->begin() ; detItr != geoMap->end() ; detItr++){ m_frames[cntr]->SetCurrentFrameId(aRun->GetRunID()); m_frames[cntr]->SetAsMCData(); // <--- !! MC data !! WriteToNtuple::GetInstance(m_datasetDigits, m_tempdir, m_nOfDetectors, (*detItr).first)->fillVars(m_frames[cntr]); cntr++; } */ //// TW commented out for now 2014-02-17 // // Loop over the detectors. // for(G4int i = 0 ; i < m_nOfDetectors ; i++) { // // // // fill one frame, set ID first // m_frames[i]->SetCurrentFrameId(aRun->GetRunID()); // m_frames[i]->SetAsMCData(); // <--- !! MC data !! // // //cout << " AllPixRun::FillFramesNtuple " << m_frames[i]->GetDetectorId() << endl; // // WriteToNtuple::GetInstance( // m_outputFilePrefix, // m_datasetDigits, // m_tempdir, // m_nOfDetectors, // m_frames[i]->GetDetectorId())->fillVars(m_frames[i]); // }//end of loop over the detectors. //// /TW } // // AllPixRun::RecordEvent method. // void AllPixRun::RecordEvent(const G4Event* evt) { // TW commented out 2014-06-17 // // Record the hits. // RecordHits(evt); // Record the Digis. RecordDigits(evt); /* // TW commenting out 2014-06-18 - moving to the Digitize method to ensure // that everything is done in the same place... bool dbg = false; //true; // Clear the source particles. ClearSourceParticles(); // Get the number of primary vertices. G4int nVertex = evt->GetNumberOfPrimaryVertex(); if (dbg) { G4cout << "DEBUG: * PRIMARY VERTEX INFORMATION " << G4endl << "DEBUG: *----------------------------" << G4endl << "DEBUG: * Number of primary vertices = : " << nVertex << G4endl; // << "DEBUG: * Number of source particles stored so far : " //<< "DEBUG: * " << G4endl; } // Loop over the primary vertices. for (G4int j = 0; jGetPrimaryVertex(j); G4int nPart = pv->GetNumberOfParticle(); if (dbg) { G4cout << "DEBUG: * Number of source particles in vertex " << j << " = : " << nPart << G4endl; //<< "DEBUG: * " << G4endl; } G4ThreeVector pos; G4ThreeVector mom; G4double E, kinE, m; G4double pid; // Loop over the source particles in the primary vertex. for (G4int i = 0; iGetPosition(); mom = pv->GetPrimary(i)->GetMomentum(); m = pv->GetPrimary(i)->GetMass(); E = sqrt(mom.mag2() + m*m); kinE = E - m; pid = pv->GetPrimary(i)->GetPDGcode(); // Add the source particle to the current frame. //m_run_action->GetAllPixRun()->AddSourceParticle(pos,mom,m,kinE,pid); this->AddSourceParticle(pos,mom,m,kinE,pid); if (dbg) { G4cout << "DEBUG: Primary " << i << " - ID = " << pid << " at (" << G4BestUnit(pos.x(), "Length") << ", " << G4BestUnit(pos.y(), "Length") << ", " << G4BestUnit(pos.z(), "Length") << ") " << "with P = (" << G4BestUnit(mom.x(), "Energy") << ", " << G4BestUnit(mom.y(), "Energy") << ", " << G4BestUnit(mom.z(), "Energy") << ") " << "KE = " << G4BestUnit(kinE, "Energy") << ", " << G4endl; //<< "DEBUG: From AllPixRunAction - current frame is " << m_run_action->GetCurrentFrameNum() << G4endl //<< "DEBUG: From AllPixRun - number of detectors is " << m_run_action->GetAllPixRun()->GetNumOfDetectors() << G4endl; }//end of dbg check. } }//end of loop over the primary vertices. */ // TW commenting out 2014-06-18 11:35 }//end of AllPixRun::RecordEvent method. /* // // AllPixRun::RecordHits method. // void AllPixRun::RecordHits(const G4Event* evt) { // This will be needed later. G4SDManager * SDman = G4SDManager::GetSDMpointer(); // Get the hit collection. G4HCofThisEvent* HCe = evt->GetHCofThisEvent(); //if(!m_hitsCollection){ // G4cout << "No hits in this event !" << G4endl; // return; //} G4int nHC = HCe->GetNumberOfCollections(); for (G4int itrCol = 0 ; itrCol < nHC ; itrCol++) { // Get a hit in the collection directly. m_hitsCollection = dynamic_cast (HCe->GetHC(itrCol)); G4int NbHits = m_hitsCollection->entries(); //G4cout << "Recording hits : " << NbHits << G4endl; // rewind hits m_storableHits[itrCol]->Rewind(); G4ThreeVector posTemp; TVector3 posTempStorable; for (G4int i = 0 ; i < NbHits ; i++) { //(*m_hitsCollection)[i]->Print(); // Record total energy deposited in an event in all pixels. SCALAR m_storableHits[itrCol]->edepTotal += ((*m_hitsCollection)[i]->GetEdep())/keV; // Interaction name. VECTOR m_storableHits[itrCol]->interactions.push_back( ((*m_hitsCollection)[i]->GetProcessName()).data() ); // Translate pos to storable format. VECTOR posTemp = (*m_hitsCollection)[i]->GetPos(); posTempStorable.SetXYZ( posTemp.x(), posTemp.y(), posTemp.z() ); m_storableHits[itrCol]->pos.push_back( posTempStorable ); //if(m_hitsCollection->GetName().contains("scint")) { //G4cout << "--> " << m_hitsCollection->GetName() << " : posx = " << posTemp.x()/mm << " [mm]" << G4endl; //} // pdgId of parent particle m_storableHits[itrCol]->pdgId.push_back( (*m_hitsCollection)[i]->GetTrackPdgId() ); // energy dep per hit m_storableHits[itrCol]->edep.push_back( ((*m_hitsCollection)[i]->GetEdep())/keV ); // particle Id m_storableHits[itrCol]->trackId.push_back( (*m_hitsCollection)[i]->GetTrackID() ); // parent Id m_storableHits[itrCol]->parentId.push_back( (*m_hitsCollection)[i]->GetParentID() ); // Name of volume for this hit m_storableHits[itrCol]->trackVolumeName.push_back( (*m_hitsCollection)[i]->GetTrackVolumeName() ); // Name of volume where particle was created m_storableHits[itrCol]->parentVolumeName.push_back( (*m_hitsCollection)[i]->GetParentVolumeName() ); } // event id m_storableHits[itrCol]->event = evt->GetEventID(); // run id m_storableHits[itrCol]->run = GetRunID(); // It is guaranteed by SD::ProcessHits that the hits contain // energy deposit. Thus we store every hit collection. // // fillVars rewinds values m_datasetHits = SDman->GetHCtable()->GetHCname(itrCol); // TW commenting out for now - will return to later. // Hits_WriteToNtuple::GetInstance( // m_outputFilePrefix, // m_datasetHits, // m_tempdir, // nHC, // here is the number of Hit Collections (SD), not detectors. // itrCol)->fillVars(m_storableHits[itrCol]); } }//end of AllPixRun::RecordHits method. */ // // AllPixRun::RecordDigits method. // void AllPixRun::RecordDigits(const G4Event* evt) { //G4cout << "* DEBUG: Calling RecordDigits" << G4endl; // Check if this event triggered for EUTELESCOPE only #ifdef _EUTELESCOPE G4HCofThisEvent* HCe = evt->GetHCofThisEvent(); G4int scintillatorsCntr = 0; G4int triggerCntr = 0; for(int i = 0 ; i < HCe->GetNumberOfCollections() ; i++){ AllPixTrackerHitsCollection * hc = (AllPixTrackerHitsCollection *) HCe->GetHC(i); G4String hitName = hc->GetName(); // look for scintillators if(hitName.contains("sdscint")) { // if containing hits ! if((int)hc->GetSize() > 0) scintillatorsCntr++; AllPixTrackerHit * hit = 0x0; for( int j= 0 ; j < (int)hc->GetSize() ; j++ ) { hit = (AllPixTrackerHit *) hc->GetHit(j); // pdgId of primary particle. Triggering on it. G4int pdgPrim = evt->GetPrimaryVertex()->GetPrimary(0)->GetPDGcode(); if(hit->GetTrackPdgId() == pdgPrim) // pion for now triggerCntr++; } } } // trigger desicion if(scintillatorsCntr < __magic_trigger_cntr_ack){ G4cout << "Trigger OFF --> " << scintillatorsCntr << " scintillators fired" << G4endl; return; } else { G4cout << "Trigger ON --> " << scintillatorsCntr << " scintillators fired" << G4endl; } #endif // Get the digits in this event. G4DCofThisEvent* DCe = evt->GetDCofThisEvent(); if (!DCe) { //G4cout << "WARNING: AllPixRun::RecordDigits - no digits in this event." << G4endl; return; } G4int nDC = DCe->GetNumberOfCollections(); // For now the number of DigitCollections should be // equal to the number of detectors if(m_nOfDetectors != nDC){ G4cout << "[ERROR] the number of Digit Collections should not" << G4endl << " be found to be different than the number of" << G4endl << " detectors. nDetectors = " << m_nOfDetectors << G4endl << " nDC = " << nDC << " ... Giving up." << G4endl; exit(1); } // TW commented out for now 2014-02-17 // // lcio bridge // // runId // *m_lciobridge_f << "R " << GetRunID() << endl; // *m_lciobridge_dut_f << "R " << GetRunID() << endl; // /TW /* // check event for information about the track //G4TrajectoryContainer * tC = evt->GetTrajectoryContainer(); //G4Trajectory * tr; G4TrajectoryContainer * tC = evt->GetTrajectoryContainer(); G4cout << "Trajectories : " << tC->GetVector()->size() << G4endl; TrajectoryVector * tV = tC->GetVector(); TrajectoryVector::iterator tI = tV->begin(); TrajectoryVector::iterator tIE = tV->end(); G4Trajectory * tr; G4TrajectoryPoint* tP; for ( ; tI != tIE ; tI++ ) { tr = static_cast(*tI); //G4cout << " " << tr->GetPDGEncoding() << G4endl; //G4cout << " " << tr->GetPointEntries() << G4endl; tP = static_cast((*tI)->GetPoint(0)); // Check which of the points is at the interior of the sensor // Use the G4VSolid::Inside(const G4ThreeVector& p) // Find first the Silicon G4VSolids (sensors). //G4VSolid * sol = m_detectorPtr->GetVSolidDetector(100); //G4cout << " " << tP->GetPosition().z()/mm << G4endl; //if(sol->Inside(tP->GetPosition()) == kInside){ // G4cout << " inside !!" << G4endl; //} else { // G4cout << " outside !!" << G4endl; //} } */ // Loop over the Digi collections. // The right detector must be matched to m_frames with the digit collection. for (G4int i = 0 ; i < nDC ; i++) { // Get a hit in the Collection directly AllPixDigitsCollectionInterface * digitsCollection = static_cast (DCe->GetDC(i)); G4int nDigits = digitsCollection->entries(); // Pickup the right index TString theIndex_S = digitsCollection->GetName().c_str(); int lastpos = theIndex_S.Index("_DigitCollection", 16, 0, TString::kExact); theIndex_S.Remove(lastpos, theIndex_S.Length()); // remove suffix theIndex_S.Remove(0,6); // remove BoxSD_ int detId = atoi(theIndex_S.Data()); // Clean up matrix //m_frames[m_detIdToIndex[detId]]->getFrameStructObject()->CleanUpMatrix(); // TW commented out for now 2014-02-17 // // lcio bridge // // FIXME ! // if(detId >= 300) *m_lciobridge_f << detId << " "; // if(detId < 300) *m_lciobridge_dut_f << detId << " "; // /TW // Loop over the Digis in the collection. for (G4int itr = 0 ; itr < nDigits ; itr++) { Int_t x = (*digitsCollection)[itr]->GetPixelIDX(); Int_t y = (*digitsCollection)[itr]->GetPixelIDY(); // Fill the pixel entries from the Digi. // Note that setting the energies (including truth) causes a // segfault when read with Mafalda - it doesn't like the double // branches for whatever reason - so sticking to counts only // for the moment. //G4cout // << "* DEBUG: Digit found at (" << MyWid(x,3,0) << ", " << MyWid(y,3,0) << ")" << G4endl; m_frames[m_detIdToIndex[detId]]->getFrameStructObject()->FillOneElement(x,y, m_frames[m_detIdToIndex[detId]]->getFrameStructObject()->GetFrameWidth(), (*digitsCollection)[itr]->GetPixelCounts() //, // (*digitsCollection)[itr]->GetPixelEnergyDep()/keV, // 0. ); // // loading a frame // m_frames[m_detIdToIndex[detId]]->LoadFramePixel( // (*digitsCollection)[itr]->GetPixelIDX(), // (*digitsCollection)[itr]->GetPixelIDY(), // (*digitsCollection)[itr]->GetPixelCounts(), // (*digitsCollection)[itr]->GetPixelEnergyDep()/keV, // 0. // ); // TW 2014-02-21 - need to come back to this anyway...! // m_frames[m_detIdToIndex[detId]]->LoadPrimaryVertexInfo( // (*digitsCollection)[itr]->GetPrimaryVertex().x()/mm, // (*digitsCollection)[itr]->GetPrimaryVertex().y()/mm, // (*digitsCollection)[itr]->GetPrimaryVertex().z()/mm // ); // TW commented out for now 2014-02-17 // // lcio bridge // // FIXME ! // if (detId >= 300) { // *m_lciobridge_f << (*digitsCollection)[itr]->GetPixelIDX() << " " // << (*digitsCollection)[itr]->GetPixelIDY() << " " // << (*digitsCollection)[itr]->GetPixelCounts() << " "; // } else { // *m_lciobridge_dut_f << (*digitsCollection)[itr]->GetPixelIDX() << " " // << (*digitsCollection)[itr]->GetPixelIDY() << " " // << (*digitsCollection)[itr]->GetPixelCounts() << " "; // } // /TW }//end of loop over the digits. //if(detId >= 300 and nDigits == 0) *m_lciobridge_f << '*'; // TW commented out for now 2014-02-17 // // lcio bridge // // FIXME ! // if(detId >= 300) *m_lciobridge_f << endl; // if(detId < 300) *m_lciobridge_dut_f << endl; }//end of loop over the detectors. }//end of AllPixRun::RecordDigits method. // // AllPixRun::FillDetectorMetaData method. // void AllPixRun::FillDetectorMetaData(G4int id, G4int index, AllPixGeoDsc * det) { //G4cout << "* DEBUG: AllPixRun::FillMetaData method called." << G4endl; // Get the detector ID from the index. // Payload //--------- m_frames[index]->SetAsMCData(); // Payload information //--------------------- m_frames[index]->SetnX( det->GetNPixelsX() ); m_frames[index]->SetnY( det->GetNPixelsY() ); // // The payload format should be set to 16384, which corresponds (for now) // to a non-Pixelman original format. // From the bytecode 0x4000 (see FramesConsts.h in the data-converter). m_frames[index]->getFrameStructObject()->SetPayloadFormat(16384); // // Frame ID - set per frame // Dataset ID - set by the run // Occupancy - set per frame // Occupancy % - set per frame // Dose rate - set per frame // Equivalent dose rate - set per frame // Acquisition information //------------------------- m_frames[index]->getFrameStructObject()->SetAcqMode(1); m_frames[index]->getFrameStructObject()->SetHwTimerMode(2); vector c; c.push_back(0); c.push_back(1); c.push_back(0); m_frames[index]->getFrameStructObject()->SetCounters(c); m_frames[index]->getFrameStructObject()->SetAutoEraseInterval(0.0); m_frames[index]->getFrameStructObject()->SetAutoEraseIntervalCounter(1); m_frames[index]->getFrameStructObject()->SetLastTriggerTime(0.0); m_frames[index]->getFrameStructObject()->SetCoincidenceMode(0x00); m_frames[index]->getFrameStructObject()->SetCoincidenceDelayTime(16); m_frames[index]->getFrameStructObject()->SetCoincidenceLiveTime(0.0); m_frames[index]->getFrameStructObject()->SetPixelmanVersion("2.1.1"); // Geospatial information //------------------------ m_frames[index]->getFrameStructObject()->SetLatitude(m_detectorPtr->GetLabLatitude()/deg); m_frames[index]->getFrameStructObject()->SetLongitude(m_detectorPtr->GetLabLongitude()/deg); m_frames[index]->getFrameStructObject()->SetAltitude(m_detectorPtr->GetLabAltitude()/m); m_frames[index]->getFrameStructObject()->SetRoll( m_detectorPtr->GetLabRollAngle( )/deg); m_frames[index]->getFrameStructObject()->SetPitch(m_detectorPtr->GetLabPitchAngle()/deg); m_frames[index]->getFrameStructObject()->SetYaw( m_detectorPtr->GetLabYawAngle( )/deg); // Temporal information //---------------------- // Start time - set per frame // Start time (strnig - set per frame m_frames[index]->getFrameStructObject()->SetAcqTime(det->GetAcqTime()); // Detector settings //------------------- m_frames[index]->getFrameStructObject()->SetPolarity(det->GetPolarity()); m_frames[index]->getFrameStructObject()->SetHV(det->GetHV()); m_frames[index]->getFrameStructObject()->SetDACs(det->GetDACs()); m_frames[index]->getFrameStructObject()->SetMpxClock(det->GetMpxClock()); m_frames[index]->getFrameStructObject()->SetTpxClock(det->GetTpxClock()); m_frames[index]->getFrameStructObject()->SetBsActive(det->GetBsActive()); // Detector information //---------------------- m_frames[index]->getFrameStructObject()->SetChipboardID(det->GetChipID()); m_frames[index]->getFrameStructObject()->SetCustomName(det->GetCustomName()); m_frames[index]->getFrameStructObject()->SetFirmware(det->GetFirmware()); m_frames[index]->getFrameStructObject()->SetInterface(det->GetInterface()); m_frames[index]->getFrameStructObject()->SetMpxType(det->GetMpxType()); // // // Filters //G4cout // << "DEBUG: Filter file name = '" << det->GetAppFilterFile() << "'" << G4endl; if (det->GetAppFilterFile().length() > 0) { // Read in the filter file here... ifstream filterFile(det->GetAppFilterFile()); // Read in the error function data from the file. while (!filterFile.eof()) { G4int x, y, val, X; X = 256 * y + x; filterFile >> x >> y >> val; //G4cout << "DEBUG: ["< ["< appfilters; appfilters.push_back(det->GetAppFilters()); //m_frames[index]->getFrameStructObject()->SetAppFilters(appfilters); m_frames[index]->getFrameStructObject()->SetAppFilters(det->GetAppFilters()); // OLD } // //Double_t D_x = m_detectorPtr->GetSensorPosX(id); //Double_t D_y = m_detectorPtr->GetSensorPosY(id); //Double_t D_z = m_detectorPtr->GetSensorPosZ(id); m_frames[index]->getFrameStructObject()->SetDet_x(m_detectorPtr->GetSensorPosX(id)); m_frames[index]->getFrameStructObject()->SetDet_y(m_detectorPtr->GetSensorPosY(id)); m_frames[index]->getFrameStructObject()->SetDet_z(m_detectorPtr->GetSensorPosZ(id)); // //Double_t Omega_x = m_detectorPtr->GetDetectorRotationX(id); //Double_t Omega_y = m_detectorPtr->GetDetectorRotationY(id); //Double_t Omega_z = m_detectorPtr->GetDetectorRotationZ(id); // // TW - 2014-05-10 - fixing the detector/lab rotation issue. // TODO: check that the Euler angles correspond to the x/y/x rotations... for later! //m_frames[index]->getFrameStructObject()->SetOmega_x(m_detectorPtr->GetDetectorRotationX(id)/deg); //m_frames[index]->getFrameStructObject()->SetOmega_y(m_detectorPtr->GetDetectorRotationY(id)/deg); //m_frames[index]->getFrameStructObject()->SetOmega_z(m_detectorPtr->GetDetectorRotationZ(id)/deg); m_frames[index]->getFrameStructObject()->SetEulerA(m_detectorPtr->GetDetectorRotationX(id)/deg); m_frames[index]->getFrameStructObject()->SetEulerB(m_detectorPtr->GetDetectorRotationY(id)/deg); m_frames[index]->getFrameStructObject()->SetEulerC(m_detectorPtr->GetDetectorRotationZ(id)/deg); //G4cout // << "* DEBUG: " << G4endl // << "* DEBUG: (D_x, D_y, D_z) = (" // << Utils::MyWid(D_x,8,4) << ", " // << Utils::MyWid(D_y,8,4) << ", " // << Utils::MyWid(D_z,8,4) << ")" << G4endl // << "* DEBUG:" << G4endl // << "* DEBUG: (O_x, O_y, O_Z) = (" // << Utils::MyWid(Omega_x/deg, 6, 4) << ", " // << Utils::MyWid(Omega_y/deg, 6, 4) << ", " // << Utils::MyWid(Omega_z/deg, 6, 4) << ")" << G4endl // << "* DEBUG: " << G4endl; // Source information //-------------------- m_frames[index]->getFrameStructObject()->SetSourceId(m_detectorPtr->GetSourceID()); }//end of AllPixRun::FillDetectorMetaData method. // // AllPixRun::FillFrames method. // void AllPixRun::FillFrames() { //G4cout << "* DEBUG: In AllPixRun::FillFrames() method." << G4endl; //G4cout << "* DEBUG: Number of ntuple sets found = " << m_ntuples.size() << G4endl; // Get the geometry description(s). extern ReadGeoDescription * g_GeoDsc; // already loaded ! :) map * geoMap = g_GeoDsc->GetDetectorsMap(); // Loop over the ntuples/detectors. map::iterator nit = m_ntuples.begin(); for (; nit!=m_ntuples.end(); ++nit) { //G4cout // << "* DEBUG: Attempting to fill frames for detector " << nit->first << G4endl; int detindex = m_detIdToIndex[nit->first]; //if (m_frames[detindex]) { // G4cout << "* DEBUG: Found a frame container for the detector." << G4endl; //} // Fill per-frame information //============================ // Start time. //G4cout << "* DEBUG: Filling start time for frame: " << MyWid(m_currentTime,15,2) << " [s]" << G4endl; //G4cout << "* DEBUG: *--> " << m_timeHandler->GetPixelmanTime() << G4endl; m_frames[detindex]->getFrameStructObject()->SetStartTime(m_currentTime); m_frames[detindex]->getFrameStructObject()->SetStartTimeS(m_timeHandler->GetPixelmanTime()); // The frame ID. m_frames[detindex]->getFrameStructObject()->SetId(m_currentFrame); // Occupancy. m_frames[detindex]->getFrameStructObject()->UpdateOccupancy(); // Apply the filter to the frame. m_frames[detindex]->getFrameStructObject()->ApplyFilter(m_filterMap); // TW commenting out for now 2014-06-18 11:38 // Add the source particle information. G4int nsp = m_pri_x.size(); for (G4int i = 0; igetFrameStructObject()->AddSourceParticle(pos, mom, m_pri_kinE[i], m_pri_m[i], m_pri_id[i]); }//end of loop over the source particles. //if (true) { // G4cout // << "DEBUG: FillFrames - number of source particles = " << nsp << G4endl; //} // TW commenting out 2014-06-18 11:38 // Fill the frame.. //G4cout << "* DEBUG: calling fillVars for the detectors." << G4endl; nit->second->fillVars(m_frames[detindex], false); // Clear the source particle information. m_frames[detindex]->getFrameStructObject()->ClearSourceParticles(); }// end of loop over the ntuples/detectors. // Clear the source particle vectors. m_pri_x.clear(); m_pri_y.clear(); m_pri_z.clear(); // m_pri_px.clear(); m_pri_py.clear(); m_pri_pz.clear(); // m_pri_kinE.clear(); m_pri_m.clear(); // m_pri_id.clear(); Double_t acqtime = ((*geoMap)[m_detIdToIndex.begin()->first])->GetAcqTime(); //G4cout << "* DEBUG: Acquisition time for det ID " << m_detIdToIndex.begin()->first << " = " << acqtime << " [s]." << G4endl; // Increase the current time by the detector acquisition time. m_currentTime += acqtime; // Update the time handler. m_timeHandler->SetTime(m_currentTime); // Increase the run's frame counter. m_currentFrame++; //G4cout << "* DEBUG: Leaving AllPixRun::FillFrames() method." << G4endl; }//end of AllPixRun::FillFrames method. // // AllPixRun::CloseNtupleFiles method. // void AllPixRun::CloseNtupleFiles() { G4cout << "* DEBUG: AllPixRun::CloseNtupleFiles called." << G4endl; map::iterator nit = m_ntuples.begin(); for (; nit!=m_ntuples.end(); ++nit) { nit->second->closeNtuple(); delete nit->second; } }//end of AllPixRun::CloseNtupleFiles method. void AllPixRun::AddSourceParticle( G4ThreeVector x_, G4ThreeVector p_, G4double m, G4double kinE, G4double pdgid ) { bool dbg = false; if (dbg) { G4cout << "DEBUG: Adding source particle..." << G4endl; } m_pri_x.push_back(x_.x()); m_pri_y.push_back(x_.y()); m_pri_z.push_back(x_.z()); // m_pri_px.push_back(p_.x()); m_pri_py.push_back(p_.y()); m_pri_pz.push_back(p_.z()); // m_pri_kinE.push_back(kinE); m_pri_m.push_back(m); // m_pri_id.push_back(pdgid); }//end of AddSourceParticle method. void AllPixRun::ClearSourceParticles() { // Clear the source particle vectors. m_pri_x.clear(); m_pri_y.clear(); m_pri_z.clear(); // m_pri_px.clear(); m_pri_py.clear(); m_pri_pz.clear(); // m_pri_kinE.clear(); m_pri_m.clear(); // m_pri_id.clear(); }