Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

PTGuiRollGMinos.cxx

Go to the documentation of this file.
00001 
00002 //
00003 // PTGuiRollGMinos
00004 //
00005 // A conversion class to roll parameters (media, materials, cuts, etc.)
00006 // from a TGeant3 simulation to a format used by the PTGui
00007 //
00008 // This code is based on that of geant3_vmc/TGeant3/G3toRoot class:
00009 //   * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
00010 //   *                                                                        *
00011 //   * Author: The ALICE Off-line Project.                                    *
00012 //   * Contributors are mentioned in the code where appropriate.              *
00013 //   Primary Author: Andreas Morsch
00014 //
00015 // but has been adapted for the MINOS PTSim simulation.
00016 //
00017 // Adapted for MINOS: S. Kasahara 8/2006
00018 //
00020 
00021 #include <iostream>
00022 using namespace std;
00023 
00024 #include <TClonesArray.h>
00025 #include <TFile.h>
00026 #include <TGraph.h>
00027 #include <TH1F.h>
00028 
00029 #include "MessageService/MsgService.h"
00030 #include "ParticleTransportSim/Gui/PTGuiRollGMinos.h"
00031 #include "ParticleTransportSim/Gui/PTGuiMedium.h"
00032 #include "ParticleTransportSim/Gui/PTGuiMaterial.h"
00033 
00034 CVSID("$Id: PTGuiRollGMinos.cxx,v 1.3 2007/08/28 23:37:37 schubert Exp $");
00035 
00036 ClassImp(PTGuiRollGMinos)
00037 
00038 // Definition of methods
00039 // *********************
00040 
00041 //_____________________________________________________________________________
00042 PTGuiRollGMinos::PTGuiRollGMinos(TFile* file) : fFile(file),
00043                                    fMaterials(0), fMedia(0) {
00044   // Normal Constructor
00045   
00046   if ( !fFile ) {
00047     MSG("PTGui",Msg::kError) << "PTGuiRollGMinos ctor received null ptr." 
00048                              << endl;
00049     abort();
00050   }
00051   
00052   // Convert GMinos objects to PTGui objects
00053   RollMaterials();
00054   RollMedia();
00055     
00056 }
00057 
00058 //_____________________________________________________________________________
00059 PTGuiRollGMinos::~PTGuiRollGMinos() {
00060   // Destructor
00061 
00062   // Delete TFile and contained objects
00063   if ( fFile ) { 
00064     fFile -> Close();
00065     delete fFile; fFile = 0;
00066   }
00067   
00068   // Delete TClonesArrays and contained objects
00069   //if ( fMaterials ) { fMaterials->Delete(); delete fMaterials; }
00070   //if ( fMedia ) { fMedia -> Delete(); delete fMedia; }
00071   
00072 }
00073 
00074 //_____________________________________________________________________________
00075 PTGuiMedium* PTGuiRollGMinos::GetMedium(std::string ptname) const {
00076   // Method to find corresponding gminos medium
00077   // during construction of medium list.
00078 
00079   PTGuiMedium* medium = 0;
00080   std::map<std::string,std::string>::const_iterator itr 
00081                                            = fPTtoGMinosMap.find(ptname);
00082   if ( itr != fPTtoGMinosMap.end() ) {
00083     std::string gminosname = itr->second;
00084     medium 
00085         = dynamic_cast<PTGuiMedium*>(fMedia->FindObject(gminosname.c_str()));
00086   }
00087 
00088   return medium;
00089   
00090 }
00091 
00092 //_____________________________________________________________________________
00093 TGraph* PTGuiRollGMinos::GetGraph(Int_t imat, Int_t ipart, Int_t imec) const {
00094   // Method to pull corresponding gminos histogram from file
00095 
00096   TGraph* graph = 0;
00097   Int_t id = 10000*imat + 100*ipart + imec;
00098 
00099   std::string histname;
00100   
00101   if ( imat < 10 ) {
00102     // This is kind of stupid but I'm tired
00103     char buf[6];
00104     sprintf(buf,"%5i",id);
00105     buf[5] = '\0';
00106     histname = "h"+std::string(buf);
00107   }
00108   else {
00109     char buf[7];
00110     sprintf(buf,"%6i",id);
00111     buf[6] = '\0';
00112     histname = "h"+std::string(buf);
00113   }
00114   
00115   TH1* hist = dynamic_cast<TH1*>(fFile->Get(histname.c_str()));
00116   if ( hist ) {
00117     graph = new TGraph(hist);
00118   }
00119   else {
00120     cout << "Unable to find histogram." << endl;
00121   }
00122    
00123   return graph; // graph is owned by caller
00124   
00125 }
00126 
00127   
00128 //_____________________________________________________________________________
00129 void PTGuiRollGMinos::RollMaterials() {
00130   // Read materials from TGeoManager arrays and puts in a TClonesArray
00131   // of PTGuiMaterial objects
00132 
00133   Int_t nentries = 0;
00134   
00135   fMaterials = dynamic_cast<TClonesArray*>(fFile->Get("GMinosMaterial"));
00136   TIter iter(fMaterials);
00137   while ( TObject* obj = iter.Next() ) {
00138     PTGuiMaterial* mat = dynamic_cast<PTGuiMaterial*>(obj);
00139     std::string matName = mat->GetName();
00140     // Fuss with material name to remove trailing spaces
00141     
00142     int pos(matName.size());
00143     for ( ; pos && matName[pos-1]==' '; --pos );
00144     matName.erase(pos,matName.size()-pos);
00145     mat->SetName(matName.c_str());
00146       
00147     mat -> Print();
00148     nentries++;
00149     
00150   }
00151 
00152 }
00153   
00154 //_____________________________________________________________________________
00155 void PTGuiRollGMinos::RollMedia() {
00156   // Read materials from TGeoManager arrays and puts in a TClonesArray
00157   // of PTGuiMedia objects
00158 
00159   // Set up media map names to navigate from PT to GMINOS names
00160   fPTtoGMinosMap.insert(make_pair("ALUM","ALUMINIUM"));
00161   fPTtoGMinosMap.insert(make_pair("ALUM_B","ALUB MAGNETIC AL"));
00162   fPTtoGMinosMap.insert(make_pair("IRON","STEEL"));
00163   fPTtoGMinosMap.insert(make_pair("IRON_B","IRON"));
00164   fPTtoGMinosMap.insert(make_pair("AIR","AIR"));
00165   fPTtoGMinosMap.insert(make_pair("AIR_B","AIRB MAGNETIC AIR"));
00166   fPTtoGMinosMap.insert(make_pair("CONCRETE","CONCRETE"));
00167   fPTtoGMinosMap.insert(make_pair("ROCK","ROCK"));
00168   fPTtoGMinosMap.insert(make_pair("PSTYRENE SCINT","PSTYRENE SCINT"));
00169   fPTtoGMinosMap.insert(make_pair("COEX TIO2 PSTYRENE",
00170                                   "COEX TIO2 PSTYRENE"));
00171   fPTtoGMinosMap.insert(make_pair("FARCOIL","<no match>"));
00172   fPTtoGMinosMap.insert(make_pair("FARCOIL_B","FARCOIL"));
00173   fPTtoGMinosMap.insert(make_pair("DOLOMITE","DOLOMITE"));
00174   fPTtoGMinosMap.insert(make_pair("FEPL","STPL"));
00175   fPTtoGMinosMap.insert(make_pair("FEPL_B","FEPL"));
00176   fPTtoGMinosMap.insert(make_pair("WATER","WATER"));
00177   fPTtoGMinosMap.insert(make_pair("WATER_B","WATB MATGNETIC WATER"));
00178 
00179   Int_t nentries = 0;
00180   
00181   fMedia = dynamic_cast<TClonesArray*>(fFile->Get("GMinosMedium"));
00182   TIter iter(fMedia);
00183   while ( TObject* obj = iter.Next() ) {
00184 
00185     PTGuiMedium* med = dynamic_cast<PTGuiMedium*>(obj);
00186     std::string medName = med->GetName();
00187 
00188     // Fuss with the medium name to remove trailing spaces
00189     int pos(medName.size());
00190     for ( ; pos && medName[pos-1]==' '; --pos );
00191     medName.erase(pos,medName.size()-pos);
00192     med -> SetName(medName.c_str());
00193     
00194     med -> Print();
00195     nentries++;
00196   }
00197 
00198   PTGuiMedium* medium = new PTGuiMedium("<no match>",-1,-1,-1,-1,
00199                                         -1,-1,-1,-1,-1,-1);
00200   (*fMedia)[nentries] = medium;
00201   
00202 }
00203 
00204   
00205 
00206 
00207 
00208 

Generated on Mon Feb 15 11:07:26 2010 for loon by  doxygen 1.3.9.1