| 1 |
// $Id: PamVMCApplication.cxx,v 1.0 2007/06/01 |
// $Id: PamVMCApplication.cxx,v 1.0 2007/06/01 |
| 2 |
// |
// |
| 3 |
// Geant4 ExampleN06 adapted to Virtual Monte Carlo |
// Geant4 PAMELA VMC |
| 4 |
#include <cstdlib> |
#include <cstdlib> |
| 5 |
#include <string> |
#include <string> |
| 6 |
|
#include <iostream> |
| 7 |
#include <TROOT.h> |
#include <TROOT.h> |
| 8 |
#include <TInterpreter.h> |
#include <TInterpreter.h> |
| 9 |
#include <TVirtualMC.h> |
#include <TVirtualMC.h> |
| 10 |
#include <Riostream.h> |
#include <Riostream.h> |
| 11 |
#include <TGeoManager.h> |
#include <TGeoManager.h> |
| 12 |
#include <TVirtualGeoTrack.h> |
#include <TVirtualGeoTrack.h> |
| 13 |
|
#include <TLorentzVector.h> |
| 14 |
#include "PamVMCApplication.h" |
#include "PamVMCApplication.h" |
| 15 |
#include "PamVMCStack.h" |
#include "PamVMCStack.h" |
|
#include "PamVMCDetectorConstruction.h" |
|
| 16 |
#include "PamVMCPrimaryGenerator.h" |
#include "PamVMCPrimaryGenerator.h" |
| 17 |
|
|
| 18 |
|
#include "PamVMCFieldMgr.h" |
| 19 |
|
|
| 20 |
|
#include "PamVMCSDMgr.h" |
| 21 |
|
|
| 22 |
|
#include "PamVMCVolCrossMgr.h" |
| 23 |
|
|
| 24 |
|
#include "PamVMCDetPamela.h" |
| 25 |
|
|
| 26 |
|
//#include "TFluka.h" |
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
ClassImp(PamVMCApplication) |
ClassImp(PamVMCApplication) |
| 31 |
|
|
| 32 |
PamVMCApplication::PamVMCApplication(const char *name, const char *title) |
PamVMCApplication::PamVMCApplication(const char *name, const char *title, const char* filename, Int_t seed) |
| 33 |
: TVirtualMCApplication(name,title), |
: TVirtualMCApplication(name,title), |
| 34 |
fEventNo(0), |
fEventNo(0), |
| 35 |
fVerbose(0), |
fVerbose(2), |
| 36 |
fStack(0), |
fStack(0), |
| 37 |
fDetConstruction(0), |
fdetector(0), |
| 38 |
fPrimaryGenerator(0) |
fPrimaryGenerator(0), |
| 39 |
|
fRootManager(filename,kWrite) |
| 40 |
{ |
{ |
| 41 |
// Standard constructor |
// Standard constructor |
| 42 |
|
|
| 43 |
// Create a user stack |
// Create a user stack |
| 44 |
fStack = new PamVMCStack(10000); |
fStack = new PamVMCStack(1000); |
| 45 |
|
|
|
// Create detector construction |
|
|
fDetConstruction = new PamVMCDetectorConstruction(); |
|
|
|
|
| 46 |
// Create a primary generator |
// Create a primary generator |
| 47 |
fPrimaryGenerator = new PamVMCPrimaryGenerator(fStack); |
fPrimaryGenerator = new PamVMCPrimaryGenerator(fStack); |
|
#ifdef PAMFIELD |
|
|
// Load the PAMELA magnetic field |
|
| 48 |
|
|
| 49 |
std::string pamcal=getenv("PAM_CALIB"); pamcal+="/trk-param/field_param-0/"; |
//Create random object |
| 50 |
std::cout << "PAMELA env: " << pamcal << std::endl; |
frandom = new TRandom3(seed); |
| 51 |
pamfield.LoadField(pamcal.c_str()); |
std::cout<<"!!! THE SEED of this MONTE CARLO is: "<<frandom->GetSeed()<<std::endl; |
|
#endif |
|
|
} |
|
| 52 |
|
|
| 53 |
|
fdetector = new PamVMCDetPamela(); |
| 54 |
|
|
| 55 |
PamVMCApplication::PamVMCApplication() |
PamVMCFieldMgr::Instance()->LoadField(); |
| 56 |
: TVirtualMCApplication(), |
|
| 57 |
fEventNo(0), |
TString fname=filename; fname+=".pam"; |
| 58 |
fVerbose(0), |
|
| 59 |
fStack(0), |
PamVMCRawMgr::Instance()-> CreateOutFile(fname.Data()); |
|
fDetConstruction(0), |
|
|
fPrimaryGenerator(0) |
|
|
{ |
|
|
// Default constructor |
|
| 60 |
} |
} |
| 61 |
|
|
| 62 |
|
|
| 63 |
PamVMCApplication::~PamVMCApplication() |
PamVMCApplication::~PamVMCApplication() |
| 64 |
{ |
{ |
| 65 |
// Destructor |
// Destructor |
| 66 |
|
delete frandom; |
| 67 |
delete fStack; |
delete fStack; |
| 68 |
delete fDetConstruction; |
delete fdetector; |
| 69 |
delete fPrimaryGenerator; |
delete fPrimaryGenerator; |
| 70 |
delete gMC; |
delete gMC; |
| 71 |
gMC = 0; |
gMC = 0; |
| 72 |
} |
} |
| 73 |
|
|
|
// |
|
|
// public methods |
|
|
// |
|
| 74 |
|
|
| 75 |
void PamVMCApplication::InitMC(const char* setup) |
void PamVMCApplication::InitMC(const char* setup) |
| 76 |
{ |
{ |
| 78 |
|
|
| 79 |
fVerbose.InitMC(); |
fVerbose.InitMC(); |
| 80 |
|
|
| 81 |
gROOT->LoadMacro(setup); |
gROOT->LoadMacro(setup); |
| 82 |
gInterpreter->ProcessLine("Config()"); |
gInterpreter->ProcessLine("Config()"); |
| 83 |
gMC->SetStack(fStack); |
gMC->SetStack(fStack); |
| 84 |
gMC->Init(); |
gMC->SetRandom(frandom); |
| 85 |
gMC->BuildPhysics(); |
|
| 86 |
|
std::cout<<"!!! BEFORE INIT GMC"<<std::endl; |
| 87 |
|
|
| 88 |
|
gMC->Init(); |
| 89 |
|
cout<<"INIT MC"<<endl; |
| 90 |
|
gMC->BuildPhysics(); |
| 91 |
|
cout<<"PHYSICS BUILDED"<<endl; |
| 92 |
|
|
| 93 |
|
#if ROOT_VERSION_CODE >= 333572 |
| 94 |
|
gMC->SetMagField(PamVMCFieldMgr::Instance()); |
| 95 |
|
cout<<"Magnetic field setted"<<endl; |
| 96 |
|
#endif |
| 97 |
|
|
| 98 |
|
fdetector->InitMC(); |
| 99 |
|
|
| 100 |
|
// fdetector->Print(); |
| 101 |
|
|
| 102 |
|
PamVMCSDMgr::Instance()->Register(); |
| 103 |
|
|
| 104 |
|
PamVMCDigMgr::Instance()->Initialize(gMC->GetRandom()); |
| 105 |
|
|
| 106 |
|
PamVMCRawMgr::Instance()->WriteToFile(); |
| 107 |
|
|
| 108 |
|
fPrimaryGenerator->SetRandom(gMC->GetRandom()); |
| 109 |
|
fPrimaryGenerator->Register(); |
| 110 |
|
|
| 111 |
|
std::cout<<"LIST OF ACTIVE SD'S:"<<std::endl; |
| 112 |
|
|
| 113 |
|
PamVMCSDMgr::Instance()->Print(); |
| 114 |
} |
} |
| 115 |
|
|
| 116 |
void PamVMCApplication::RunMC(Int_t nofEvents) |
void PamVMCApplication::RunMC(Int_t nofEvents) |
| 117 |
{ |
{ |
| 118 |
// MC run. |
// MC run. |
| 119 |
|
|
| 120 |
fVerbose.RunMC(nofEvents); |
fVerbose.RunMC(nofEvents); |
| 121 |
|
|
| 122 |
gMC->ProcessRun(nofEvents); |
gMC->ProcessRun(nofEvents); |
| 123 |
|
|
| 124 |
//// fVerbose.FinishRun(); |
fVerbose.FinishRun(); |
| 125 |
} |
} |
| 126 |
|
|
| 127 |
|
void PamVMCApplication::AddIons(){ |
| 128 |
|
|
| 129 |
|
fVerbose.AddIons(); |
| 130 |
|
//Arguments are: |
| 131 |
|
//name |
| 132 |
|
//Z (atomic number) |
| 133 |
|
//A (atomic mass) |
| 134 |
|
//Q (charge eplus) |
| 135 |
|
//exitation exitation energy [GeV] 0. if in ground state |
| 136 |
|
//mass [GeV], if not specified, calculated approx |
| 137 |
|
|
| 138 |
|
gMC->DefineIon("He3",2,3,2,0.,2.808); |
| 139 |
|
gMC->DefineIon("He4",2,4,2,0.,3.727); |
| 140 |
|
|
| 141 |
|
//gMC->DefineIon("He7",2,7,2,0.); |
| 142 |
|
//gMC->DefineIon("Boron",5,10,5,0.); |
| 143 |
|
//gMC->DefineIon("Carbon",6,12,6,0.); |
| 144 |
|
} |
| 145 |
|
|
| 146 |
|
|
| 147 |
void PamVMCApplication::ConstructGeometry() |
void PamVMCApplication::ConstructGeometry() |
| 148 |
{ |
{ |
| 149 |
// Construct geometry using detector contruction class |
// Construct geometry using detector contruction class |
| 150 |
|
|
| 151 |
fVerbose.ConstructGeometry(); |
fVerbose.ConstructGeometry(); |
| 152 |
fDetConstruction->ConstructGeometry(); |
new TGeoManager("PAM_GEOM","PAMELA GEOMETRY"); |
| 153 |
|
fdetector->ConstructGeometry(); |
| 154 |
|
//TGeoManager::Import("/home/pamela/PamCAL210508/gp2tgeo.root"); |
| 155 |
|
gGeoManager->CloseGeometry(); |
| 156 |
|
gMC->SetRootGeometry(); |
| 157 |
|
|
| 158 |
|
cout<<"!!CONSTRUCT GEOMETRY!!"<<endl; |
| 159 |
|
fdetector->ConstructCuts(); |
| 160 |
|
|
| 161 |
} |
} |
| 162 |
|
|
| 163 |
void PamVMCApplication::InitGeometry() |
void PamVMCApplication::InitGeometry() |
| 164 |
{ |
{ |
| 165 |
// Initialize geometry |
// Initialize geometry |
| 166 |
|
|
| 167 |
fVerbose.InitGeometry(); |
cout<<"!!SETUP CUTS"<<endl; |
| 168 |
|
//fdetector->InitGeometry(); |
| 169 |
|
|
| 170 |
|
fVerbose.InitGeometry(); |
| 171 |
} |
} |
| 172 |
|
|
| 173 |
|
|
| 174 |
void PamVMCApplication::GeneratePrimaries() |
void PamVMCApplication::GeneratePrimaries() |
| 175 |
{ |
{ |
| 176 |
// Fill the user stack (derived from TVirtualMCStack) with primary particles. |
// Fill the user stack (derived from TVirtualMCStack) with primary particles. |
| 177 |
|
|
| 178 |
///// fVerbose.GeneratePrimaries(); |
fPrimaryGenerator->GeneratePrimary(); |
|
|
|
|
fPrimaryGenerator->GeneratePrimaries(); |
|
| 179 |
} |
} |
| 180 |
|
|
| 181 |
void PamVMCApplication::BeginEvent() |
void PamVMCApplication::BeginEvent() |
| 182 |
{ |
{ |
| 183 |
// User actions at beginning of event |
// User actions at beginning of event |
| 184 |
|
PamVMCSDMgr::Instance()->PreEvent(); |
|
///// fVerbose.BeginEvent(); |
|
|
|
|
| 185 |
fEventNo++; |
fEventNo++; |
| 186 |
} |
} |
| 187 |
|
|
| 188 |
void PamVMCApplication::BeginPrimary() |
void PamVMCApplication::BeginPrimary() |
| 189 |
{ |
{ |
| 190 |
// User actions at beginning of a primary track |
// User actions at beginning of a primary track |
| 191 |
|
fPrimaryGenerator->SetGood(kTRUE); |
| 192 |
//// fVerbose.BeginPrimary(); |
fVerbose.BeginPrimary(); |
| 193 |
} |
} |
| 194 |
|
|
| 195 |
void PamVMCApplication::PreTrack() |
void PamVMCApplication::PreTrack() |
| 196 |
{ |
{ |
| 197 |
// User actions at beginning of each track |
// User actions at beginning of each track |
| 198 |
|
|
| 199 |
|
} |
| 200 |
|
|
| 201 |
////// fVerbose.PreTrack(); |
|
| 202 |
|
#define CAVITY_X 8.07 |
| 203 |
|
#define CAVITY_Y 6.57 |
| 204 |
|
#define ZCAVITY_MIN 27.399 |
| 205 |
|
#define ZCAVITY_MAX 71.059 |
| 206 |
|
|
| 207 |
|
|
| 208 |
|
Bool_t PamVMCApplication::IsInsideCavity(){ |
| 209 |
|
Double_t x,y,z; |
| 210 |
|
gMC->TrackPosition(x,y,z); |
| 211 |
|
if( (z<ZCAVITY_MIN) || (z>ZCAVITY_MAX)) return kTRUE; |
| 212 |
|
if( (TMath::Abs(x) > CAVITY_X) || (TMath::Abs(y) > CAVITY_Y)) return kFALSE; |
| 213 |
|
return kTRUE; |
| 214 |
} |
} |
| 215 |
|
|
| 216 |
|
|
| 217 |
void PamVMCApplication::Stepping() |
void PamVMCApplication::Stepping() |
| 218 |
{ |
{ |
| 219 |
|
if (fStack->GetCurrentTrack()->IsPrimary()){ |
| 220 |
|
if(!IsInsideCavity()) fPrimaryGenerator->SetGood(kFALSE); |
| 221 |
|
} |
| 222 |
|
|
| 223 |
// User actions at each step |
// User actions at each step |
| 224 |
|
fVerbose.Stepping(); |
| 225 |
////// fVerbose.Stepping(); |
PamVMCDetectorSD* temp=(PamVMCDetectorSD*) PamVMCSDMgr::Instance()->GetSD(gMC->CurrentVolName()); |
| 226 |
|
if(temp){ |
| 227 |
|
fdstatus=INSIDE; |
| 228 |
|
if(gMC->IsTrackEntering()){ fdstatus=ENTERING; } |
| 229 |
|
if(gMC->IsTrackExiting() || gMC->IsTrackOut() || gMC->IsTrackStop() ) { fdstatus=EXITING;} |
| 230 |
|
temp->FillHit(fdstatus,gMC,fStack->GetCurrentTrack()->IsPrimary()); |
| 231 |
|
} |
| 232 |
|
|
| 233 |
} |
} |
| 234 |
|
|
| 235 |
void PamVMCApplication::PostTrack() |
void PamVMCApplication::PostTrack() |
| 236 |
{ |
{ |
| 237 |
// User actions after finishing of each track |
// User actions after finishing of each track |
| 238 |
|
|
|
|
|
|
///// fVerbose.PostTrack(); |
|
| 239 |
} |
} |
| 240 |
|
|
| 241 |
void PamVMCApplication::FinishPrimary() |
void PamVMCApplication::FinishPrimary() |
| 242 |
{ |
{ |
| 243 |
// User actions after finishing of a primary track |
// User actions after finishing of a primary track |
| 244 |
|
//fPrimaryGenerator->SetGood(PamVMCVolCrossMgr::Instance()->IsTrackGood()); |
| 245 |
///// fVerbose.FinishPrimary(); |
//PamVMCVolCrossMgr::Instance()->Reset(); |
| 246 |
|
fVerbose.FinishPrimary(); |
| 247 |
} |
} |
| 248 |
|
|
| 249 |
void PamVMCApplication::FinishEvent() |
void PamVMCApplication::FinishEvent() |
| 250 |
{ |
{ |
| 251 |
// User actions after finishing of an event |
// User actions after finishing of an event |
| 252 |
|
|
| 253 |
|
|
| 254 |
|
|
| 255 |
/////fVerbose.FinishEvent(); |
PamVMCSDMgr::Instance()->Digitize(); |
| 256 |
|
//EventNo needs for trigger, particle PDG needs for TOF.. |
| 257 |
|
PamVMCDigMgr::Instance()->Digitize(fEventNo,fPrimaryGenerator->GetParticle()); |
| 258 |
|
|
| 259 |
|
PamVMCSDMgr::Instance()->Compress(); |
| 260 |
|
|
| 261 |
|
PamVMCRawMgr::Instance()->WriteEvent(); |
| 262 |
|
|
| 263 |
|
fRootManager.Fill(); |
| 264 |
|
|
| 265 |
|
fPrimaryGenerator->ClearPrimCol(); |
| 266 |
|
|
| 267 |
fStack->Reset(); |
PamVMCSDMgr::Instance()->Clear(); |
| 268 |
|
|
| 269 |
|
fStack->Reset(); |
| 270 |
|
|
| 271 |
} |
} |
| 272 |
|
|
| 273 |
void PamVMCApplication::Field(const Double_t* x, Double_t* b) const |
void PamVMCApplication::FinishRun() |
| 274 |
{ |
{ |
| 275 |
// Uniform magnetic field |
fVerbose.FinishRun(); |
| 276 |
|
|
| 277 |
|
fRootManager.WriteAll(); |
| 278 |
|
|
| 279 |
#ifdef PAMFIELD |
PamVMCDigMgr::Instance()->FinishRun(); //write RunTrailer to buffer |
| 280 |
b[0] = pamfield.GetBX((float *)x); |
|
| 281 |
b[1] = pamfield.GetBY((float *)x); |
PamVMCRawMgr::Instance()->FinishRun(); //write RunTrailer to file and close; |
| 282 |
b[2] = pamfield.GetBZ((float *)x); |
|
| 283 |
#else |
PamVMCDigMgr::Instance()->PrintCollections(); |
| 284 |
for (Int_t i=0; i<3; i++) b[i] = 0.0; |
|
| 285 |
#endif |
} |
| 286 |
|
|
| 287 |
|
#if ROOT_VERSION_CODE < 333572 |
| 288 |
|
void PamVMCApplication::Field(const Double_t* x, Double_t* b) const |
| 289 |
|
{ |
| 290 |
|
PamVMCFieldMgr::Instance()->Field(x,b); |
| 291 |
} |
} |
| 292 |
|
#endif |