コード例 #1
0
//________________________________________________________________________________
void StarMCHits::Step() {
  //  static Int_t Idevt0 = -1;
  static Double_t Gold = 0;
#if 0
  if (Debug() && gMC->IsA()->InheritsFrom("TGeant3TGeo")) {
    TGeant3TGeo *geant3 = (TGeant3TGeo *)gMC;
    geant3->Gdebug();
  }
#endif
  //  cout << "Call StarMCHits::Step" << endl;
  TGeoNode *nodeT = gGeoManager->GetCurrentNode();
  assert(nodeT);
  TGeoVolume *volT = nodeT->GetVolume();
  assert(volT);
  const TGeoMedium   *med = volT->GetMedium(); 
  /*   fParams[0] = isvol;
       fParams[1] = ifield;
       fParams[2] = fieldm;
       fParams[3] = tmaxfd;
       fParams[4] = stemax;
       fParams[5] = deemax;
       fParams[6] = epsil;
       fParams[7] = stmin; */
  Int_t Isvol = (Int_t) med->GetParam(0);
  fCurrentDetector = 0;
  if (Isvol <= 0) return;
  fCurrentDetector = (StarVMCDetector *) fVolUserInfo->At(volT->GetNumber());
  if (! fCurrentDetector) {
    volT = nodeT->GetMotherVolume();
    fCurrentDetector = (StarVMCDetector *) fVolUserInfo->At(volT->GetNumber());
    if (! fCurrentDetector) {
      TString path(gGeoManager->GetPath());
      TObjArray *obj = path.Tokenize("_/");
      Int_t N = obj->GetEntries();
      for (Int_t i = N-2; i >= 0; i -= 2) {
	TObjString *o = (TObjString  *) obj->At(i);
	const Char_t *name = o->GetName();
	volT = gGeoManager->GetVolume(name);
	assert (volT);
	fCurrentDetector = (StarVMCDetector *) fVolUserInfo->At(volT->GetNumber());
	if (fCurrentDetector) break;
      }
      delete obj;
    }
  }
  if (Isvol && ! fCurrentDetector && Debug()) {
    cout << "Active medium:" << med->GetName() << "\t for volume " << volT->GetName() 
	 << " has no detector description" << endl;
  }
  //  Int_t Idevt =  gMC->CurrentEvent();
  gMC->TrackPosition(fHit.Current.Global.xyzT);
  gMC->TrackMomentum(fHit.Current.Global.pxyzE);
  TGeoHMatrix  *matrixC = gGeoManager->GetCurrentMatrix();
  fHit.Current.Global2Local(matrixC);
  if (gMC->IsTrackEntering()) {
    fHit.Detector= fCurrentDetector;
    fHit.Entry = fHit.Current;
    fHit.Sleng = gMC->TrackLength();
    fHit.Charge = (Int_t) gMC->TrackCharge();
    fHit.Mass = gMC->TrackMass();
    fHit.AdEstep = fHit.AStep = 0;
    return;
  }
  Double_t GeKin = fHit.Current.Global.pxyzE.E() - fHit.Mass;
  fHit.Sleng = gMC->TrackLength();
  if (fHit.Sleng == 0.) Gold = GeKin;
  Double_t dEstep = gMC->Edep();
  Double_t Step = gMC->TrackStep();
  fHit.iPart = gMC->TrackPid();
  fHit.iTrack = StarVMCApplication::Instance()->GetStack()->GetCurrentTrackId(); // GetCurrentTrackNumber() + 1 to be consistent with g2t
  // - - - - - - - - - - - - - energy correction - - - - - - - - - -
  if (gMC->IsTrackStop() && TMath::Abs(fHit.iPart) == kElectron) {
    TArrayI proc;
    Int_t Nproc = gMC->StepProcesses(proc);
    Int_t Mec = 0;
    for (Int_t i = 0; i < Nproc; i++) if (proc[i] == kPAnnihilation || proc[i] == kPStop) Mec = proc[i];
    Int_t Ngkine = gMC->NSecondaries();
    if (fHit.iPart == kElectron && Ngkine == 0 && Mec == kPStop) dEstep = Gold;
    else {
      if (fHit.iPart == kPositron && Ngkine < 2 && Mec == kPAnnihilation) {
	dEstep = Gold + 2*fHit.Mass;
	if (Ngkine == 1) {
	  TLorentzVector x;
	  TLorentzVector p;
	  Int_t IpartSec;
	  gMC->GetSecondary(0,IpartSec,x,p);
	  dEstep -= p.E();
	}
      }
    }
  }
  // - - - - - - - - - - - - - - - - user - - - - - - - - - - - - - - -
  // user step
  // - - - - - - - - - - - - - - - sensitive - - - - - - - - - - - - -
  fHit.AdEstep += dEstep;  
  fHit.AStep   += Step;
  if (fHit.AdEstep == 0) return;
  if (! gMC->IsTrackExiting() && ! gMC->IsTrackStop()) return;
  fHit.Exit     = fHit.Current;
  fHit.Middle   = fHit.Entry;
  fHit.Middle  += fHit.Exit;
  fHit.Middle  *= 0.5;
  if (! fCurrentDetector) return;
  fHit.VolumeId = fCurrentDetector->GetVolumeId(gGeoManager->GetPath());
  FillG2Table();
}
コード例 #2
0
ファイル: get_target_mass.C プロジェクト: abercell/GENIE_2_8
//____________________________________________________________________________
void get_mass(Double_t length_unit, Double_t density_unit)
{
   //tables of Z and A
   const Int_t lcin_Z = 150;
   const Int_t lcin_A = 300;

   // calc unit conversion factors
   Double_t density_unit_to_SI = density_unit / units::kg_m3;
   Double_t length_unit_to_SI  = length_unit  / units::m;
   Double_t volume_unit_to_SI  = TMath::Power(length_unit_to_SI, 3.);
#ifdef _debug_
   cout << "Input density unit --> kg/m^3 : x" << density_unit_to_SI << endl;
   cout << "Input length  unit --> m      : x" << length_unit_to_SI  << endl;
#endif

   // get materials in geometry
   TList *matlist = gGeoManager->GetListOfMaterials();
   if (!matlist ) { 
     cout << "Null list of materials!" << endl; 
     return; 
   } else {
#ifdef _debug_
     matlist->Print();
#endif
   }

   int max_idx = 0; // number of mixtures in geometry
   Int_t nmat = matlist->GetEntries();
   for( Int_t imat = 0; imat < nmat; imat++ )
   {
      Int_t idx = gGeoManager->GetMaterial(imat)->GetIndex();
      max_idx = TMath::Max(max_idx, idx);
   }

   //check if material index is unique
   Int_t * checkindex = new Int_t[max_idx+1];
   for( Int_t i = 0; i<max_idx+1; i++ ) checkindex[i] = 0;
   for( Int_t imat = 0; imat < nmat; imat++ )
   {
      if( !checkindex[imat] ) checkindex[imat] = 1;
      else 
      {
         cout << "material index is not unique" << endl;
        return;
      }
   }

#ifdef _debug_
   cout << "max_idx = " << max_idx << endl;
   cout << "nmat    = " << nmat    << endl;
#endif

   TGeoVolume * topvol = gGeoManager->GetTopVolume(); //get top volume
   if (!topvol) {
     cout << "volume does not exist" << endl;
     return;
   }

   TGeoIterator NodeIter(topvol);
   TGeoNode *node;
   NodeIter.SetType(0); // include  all daughters

   Double_t * volume = new Double_t[max_idx+1];
   Double_t * mass   = new Double_t[max_idx+1];

   for( Int_t i = 0; i<max_idx+1; i++ ){ volume[i]=0.; mass[i]=0.; } // IMPORTANT! force empty arrays, allows repated calls without ending ROOT session

   volume[ topvol->GetMaterial()->GetIndex() ] = topvol->Capacity() * volume_unit_to_SI; //iterator does not include topvolume  

   while ( (node=NodeIter()) )
   {
      Int_t momidx = node->GetMotherVolume()->GetMaterial()->GetIndex() ;
      Int_t idx    = node->GetVolume()      ->GetMaterial()->GetIndex() ;

      Double_t node_vol = node->GetVolume()->Capacity() * volume_unit_to_SI;

      volume[ momidx ] -= node_vol; //substract subvolume from mother
      volume[ idx    ] += node_vol;
   }


   Double_t larr_MassIsotopes[lcin_Z][lcin_A] = {0.}; //[Z][A], no map in pure ROOT
   Double_t larr_VolumeIsotopes[lcin_Z][lcin_A] = {0.}; //[Z][A], no map in pure ROOT

   for( Int_t i=0; i<gGeoManager->GetListOfMaterials()->GetEntries(); i++ )
   {
      TGeoMaterial *lgeo_Mat = gGeoManager->GetMaterial(i);
      Int_t    idx     = gGeoManager->GetMaterial(i)->GetIndex();

      if( lgeo_Mat->IsMixture() )
      {
         TGeoMixture * lgeo_Mix = dynamic_cast <TGeoMixture*> ( lgeo_Mat );
         Int_t lint_Nelements = lgeo_Mix->GetNelements();

         for ( Int_t j=0; j<lint_Nelements; j++) 
         {
            Int_t lint_Z = TMath::Nint( (Double_t) lgeo_Mix->GetZmixt()[j] );
            Int_t lint_A = TMath::Nint( (Double_t) lgeo_Mix->GetAmixt()[j] );
            Double_t ldou_Fraction = lgeo_Mix->GetWmixt()[j];
            Double_t ldou_Density = lgeo_Mix->GetDensity() * density_unit_to_SI;

            larr_MassIsotopes[ lint_Z ][ lint_A ] += volume[idx] * ldou_Fraction * ldou_Density;
            larr_VolumeIsotopes[ lint_Z ][ lint_A ] += volume[idx] * ldou_Fraction;
         }
      }
   }

   //
   // print out volume/mass for each `material'
   //

   Double_t ldou_MinimumVolume = 1e-20;

   cout << endl
        << " Geometry: \"" <<  gFileName << "\"" << endl
        << " TopVolume: \"" << topvol->GetName() << "\"" 
        << endl;

   cout <<endl << "materials:" << endl;
   cout << setw(5) << "index"
        << setw(15) << "name"
        << setprecision(6) 
        << setw(14) << "volume (m^3)"
        << setw(14) << "mass (kg)"
        << setw(14) << "mass (%)"
        <<  endl;

   double total_mass_materials = 0;
   for( Int_t i=0; i<gGeoManager->GetListOfMaterials()->GetEntries(); i++ )
   {
     Int_t    idx     = gGeoManager->GetMaterial(i)->GetIndex();
     Double_t density = gGeoManager->GetMaterial(i)->GetDensity() * density_unit_to_SI;
     Double_t mass_material = density * volume[idx];
     if ( volume[idx] > ldou_MinimumVolume ) {
       total_mass_materials += mass_material;
     }
   }


   for( Int_t i=0; i<gGeoManager->GetListOfMaterials()->GetEntries(); i++ )
   {
      Int_t    idx     = gGeoManager->GetMaterial(i)->GetIndex();
      Double_t density = gGeoManager->GetMaterial(i)->GetDensity() * density_unit_to_SI;

      mass[idx] = density * volume[idx];

      if( volume[idx] > ldou_MinimumVolume ) {
        cout << setw(5) << i 
             << setw(15) << gGeoManager->GetMaterial(i)->GetName() 
             << setprecision(6) 
             << setw(14) << volume[idx] 
             << setw(14) << mass[idx] 
             << setw(14) << mass[idx]*100./total_mass_materials
             <<  endl;
      }
   }


   //
   // print out mass contribution for each nuclear target
   //
   PDGLibrary* pdglib = PDGLibrary::Instance();

   cout <<endl << "isotopes:" << endl;
   cout << setw(4) << "Z" 
        << setw(4) << "A"
        << setw(14) << "PDG isotope"
        << setw(5) << "     "
        << setprecision(6)
        << setw(14) << "volume (m^3)"
        << setw(14) << "mass (kg)"
        << setw(10) << "mass (%)"
        <<  endl;

   double total_mass_isotopes = 0;
   for( Int_t i=0; i<lcin_Z; i++ ) {
     for( Int_t j=0; j<lcin_A; j++ ) {
       if( larr_VolumeIsotopes[ i ][ j ] > ldou_MinimumVolume ) {
         total_mass_isotopes += larr_MassIsotopes[ i ][ j ];
       }
     }
   }

   for( Int_t i=0; i<lcin_Z; i++ )
   {
      for( Int_t j=0; j<lcin_A; j++ )
      {
         if( larr_VolumeIsotopes[ i ][ j ] > ldou_MinimumVolume ) {
           int pdgcode = 1000000000 + i*10000 + j*10;
              cout << setw(4) << i
             << setw(4)<< j
             << setw(14) << pdgcode
             << setw(5) << pdglib->Find(pdgcode)->GetName()
             << setprecision(6) 
             << setw(14) << larr_VolumeIsotopes[ i ][ j ]
             << setw(14) << larr_MassIsotopes[ i ][ j ] 
             << setw(10) << larr_MassIsotopes[ i ][ j ]*100.0/total_mass_isotopes
             <<  endl;
         }
         else if ( larr_VolumeIsotopes[ i ][ j ] < -ldou_MinimumVolume ) {
            cout << "negative volume, check geometry " << larr_VolumeIsotopes[ i ][ j ] << endl;
         }
      }
   }

   cout << endl << " mass totals: " << total_mass_materials << " " << total_mass_isotopes 
        << endl << endl;

   delete [] volume;
   delete [] mass;

}