FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
run_tutorial4_createMatrices.C
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 void run_tutorial4_createMatrices(Int_t nEvents = 10, TString mcEngine = "TGeant3", Bool_t isMT = false)
9 {
10 
11  TString dir = getenv("VMCWORKDIR");
12 
13  TString tut_configdir = dir + "/simulation/Tutorial4/gconfig";
14  gSystem->Setenv("CONFIG_DIR", tut_configdir.Data());
15 
16  TString tut_geomdir = dir + "/common/geometry";
17  gSystem->Setenv("GEOMPATH", tut_geomdir.Data());
18 
19  Double_t momentum = 2.;
20 
21  Double_t theta = 2.;
22 
23  TString outDir = "./";
24 
25  // Output file name
26  TString outFile = "testrun_";
27  outFile = outFile + mcEngine + ".root";
28 
29  TString geoFile = "data/geoFile_" + mcEngine + "_full.root";
30  TString geoFileMisaligned = "data/geoFile_" + mcEngine + "_full_misaligned.root";
31 
32  TString parFile = "testparams_";
33  parFile = parFile + mcEngine + ".root";
34 
35  TList* parFileList = new TList();
36 
37  TString paramDir = dir + "/simulation/Tutorial4/parameters/";
38  TString paramFile = paramDir + "example.par";
39 
40  TObjString* tutDetDigiFile = new TObjString(paramFile);
41  parFileList->Add(tutDetDigiFile);
42 
43  // In general, the following parts need not be touched
44  // ========================================================================
45 
46  // ---- Debug option -------------------------------------------------
47  gDebug = 0;
48  // ------------------------------------------------------------------------
49 
50  // ----- Timer --------------------------------------------------------
51  TStopwatch timer;
52  timer.Start();
53  // ------------------------------------------------------------------------
54 
55  // Does not work with automatic loading pf libraries. The info is not in the rootmap file
56  // gLogger->SetLogScreenLevel("INFO");
57 
58  // ----- Create simulation run ----------------------------------------
59  FairRunSim* run = new FairRunSim();
60  run->SetName(mcEngine); // Transport engine
61  run->SetIsMT(isMT); // Multi-threading mode (Geant4 only)
62  run->SetSink(new FairRootFileSink(outFile)); // Output file
63  FairRuntimeDb* rtdb = run->GetRuntimeDb();
64  // ------------------------------------------------------------------------
65 
66  // ----- Create media -------------------------------------------------
67  run->SetMaterials("media.geo"); // Materials
68  // ------------------------------------------------------------------------
69 
70  // ----- Create geometry ----------------------------------------------
71  FairModule* cave = new FairCave("CAVE");
72  cave->SetGeometryFileName("cave_vacuum.geo");
73  run->AddModule(cave);
74 
75  FairTutorialDet4* tutdet = new FairTutorialDet4("TUTDET", kTRUE);
76  tutdet->SetGeometryFileName("tutorial4.root");
77 
78  run->AddModule(tutdet);
79  // ------------------------------------------------------------------------
80 
81  // ----- Create PrimaryGenerator --------------------------------------
83  FairBoxGenerator* boxGen = new FairBoxGenerator(2212, 1);
84 
85  boxGen->SetThetaRange(theta, theta + 0.1);
86  // boxGen->SetThetaRange ( 0., 0.);
87  boxGen->SetPRange(momentum, momentum + 0.01);
88  boxGen->SetPhiRange(0., 360.);
89  boxGen->SetBoxXYZ(-20., -20., 20., 20., 0.);
90  // boxGen->SetBoxXYZ (0.,0.,0.,0., 0.);
91 
92  // boxGen->SetDebug(kTRUE);
93 
94  primGen->AddGenerator(boxGen);
95 
96  run->SetGenerator(primGen);
97  // ------------------------------------------------------------------------
98 
99  // ----- Initialize simulation run ------------------------------------
100  run->SetStoreTraj(kTRUE);
101 
102  // ----- Runtime database ---------------------------------------------
103 
104  Bool_t kParameterMerged = kTRUE;
105  FairParRootFileIo* parOut = new FairParRootFileIo(kParameterMerged);
106  FairParAsciiFileIo* parIn = new FairParAsciiFileIo();
107  parOut->open(parFile.Data());
108  parIn->open(parFileList, "in");
109  rtdb->setFirstInput(parIn);
110  rtdb->setOutput(parOut);
111  // ------------------------------------------------------------------------
112 
113  run->Init();
114 
115  // sadly, the align parameters are only available AFTER we called fRun->Init()
116 
117  // We fill a std::map<std::string, TGeoHMatrix> map with all misalignment matrices
118  // how you get those in your geometry is up to you
119 
120  auto matrices = tutdet->getMisalignmentMatrices();
121 
122  ofstream myfile;
123  myfile.open("misalignmentMatrices.txt");
124 
125  double* rot;
126  double* trans;
127 
128  // this can probably be done more elegantly
129  for (auto& mat : matrices) {
130  myfile << mat.first << "\n";
131  rot = mat.second.GetRotationMatrix();
132  trans = mat.second.GetTranslation();
133  for (int i = 0; i < 9; i++)
134  myfile << rot[i] << "\n";
135  for (int i = 0; i < 3; i++)
136  myfile << trans[i] << "\n";
137  }
138  myfile.close();
139 
140  LOG(info) << "AlignHandler: all matrices added!";
141 
142  LOG(info) << "SUCCESS! All matrices created and saved!";
143 
144  return;
145 }
Bool_t kParameterMerged
virtual void SetGeometryFileName(TString fname, TString geoVer="0")
Definition: FairModule.cxx:199
std::map< std::string, TGeoHMatrix > getMisalignmentMatrices()
list of container factories
Definition: FairRuntimeDb.h:24
Bool_t open(const Text_t *fname, const Text_t *status="in")
void SetPRange(Double32_t pmin=0, Double32_t pmax=10)
void AddGenerator(FairGenerator *generator)
void run_tutorial4_createMatrices(Int_t nEvents=10, TString mcEngine="TGeant3", Bool_t isMT=false)
void SetGenerator(FairPrimaryGenerator *Gen)
Definition: FairRunSim.cxx:310
void SetSink(FairSink *tempSink)
Definition: FairRun.h:84
void SetIsMT(Bool_t isMT)
Definition: FairRunSim.h:184
FairParRootFileIo * parOut
void SetBoxXYZ(Double32_t x1=0, Double32_t y1=0, Double32_t x2=0, Double32_t y2=0, Double32_t z=0)
virtual void Init()
Definition: FairRunSim.cxx:143
FairRuntimeDb * GetRuntimeDb(void)
Definition: FairRun.h:80
void SetThetaRange(Double32_t thetamin=0, Double32_t thetamax=90)
void SetMaterials(const char *MatFileName)
Definition: FairRunSim.cxx:312
Bool_t setOutput(FairParIo *)
Bool_t open(const Text_t *fname, Option_t *option="READ", const Text_t *ftitle="", Int_t compress=1)
void AddModule(FairModule *Mod)
Definition: FairRunSim.cxx:118
void SetPhiRange(Double32_t phimin=0, Double32_t phimax=360)
Bool_t setFirstInput(FairParIo *)
void SetStoreTraj(Bool_t storeTraj=kTRUE)
Definition: FairRunSim.h:92