00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00039
00040
00041
00042 PTGuiRollGMinos::PTGuiRollGMinos(TFile* file) : fFile(file),
00043 fMaterials(0), fMedia(0) {
00044
00045
00046 if ( !fFile ) {
00047 MSG("PTGui",Msg::kError) << "PTGuiRollGMinos ctor received null ptr."
00048 << endl;
00049 abort();
00050 }
00051
00052
00053 RollMaterials();
00054 RollMedia();
00055
00056 }
00057
00058
00059 PTGuiRollGMinos::~PTGuiRollGMinos() {
00060
00061
00062
00063 if ( fFile ) {
00064 fFile -> Close();
00065 delete fFile; fFile = 0;
00066 }
00067
00068
00069
00070
00071
00072 }
00073
00074
00075 PTGuiMedium* PTGuiRollGMinos::GetMedium(std::string ptname) const {
00076
00077
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
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
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;
00124
00125 }
00126
00127
00128
00129 void PTGuiRollGMinos::RollMaterials() {
00130
00131
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
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
00157
00158
00159
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
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