FairRoot/PandaRoot
createPndLmdMisalignmentMatrices.C
Go to the documentation of this file.
1 // for now, we want deterministic pseudo random numbers.
2 // we can't use 0, because 0 is replaced by root by another
3 // pseudo random number which completely misses the point of
4 // a user defined seed value.
5 unsigned int seed = 128;
6 
7 #include <TRandom3.h>
8 
9 // use Mersenne Twister
10 TRandom3 *PRNG = new TRandom3(seed);
11 
12 // creates random translation and rotation matrices with the supplied values as sigma values
13 TGeoHMatrix createRandomMatrix(double angleSigma, double shiftSigma) {
14 
15  double mean = 0;
16 
17  double sigmaX, sigmaY, sigmaZ;
18  double shift[3];
19 
20  // can only rotate about z
21  //sigmaX = PRNG->Gaus(mean, angleSigma);
22  //sigmaY = PRNG->Gaus(mean, angleSigma);
23  sigmaX = 0;
24  sigmaY = 0;
25  sigmaZ = PRNG->Gaus(mean, angleSigma);
26 
27  // can't move in z
28  shift[0] = PRNG->Gaus(mean, shiftSigma);
29  shift[1] = PRNG->Gaus(mean, shiftSigma);
30  //shift[2] = PRNG->Gaus(mean, shiftSigma);
31  shift[2] = 0;
32 
33 // cout << "rand val: " << angles[0] << "\n";
34 // cout << "rand val: " << angles[1] << "\n";
35 // cout << "rand val: " << angles[2] << "\n";
36 // cout << "rand val: " << shift[0] << "\n";
37 // cout << "rand val: " << shift[1] << "\n";
38 // cout << "rand val: " << shift[2] << "\n";
39 
40  TGeoHMatrix result;
41  result.RotateZ(sigmaZ);
42  result.SetTranslation(shift);
43 
44 // result.Print();
45 
46  return result;
47 }
48 
49 int createPndLmdMisalignmentMatrices(bool debug = false) {
50 
51  string misMatricesFilePath = "misalignMatrices-SensorsOnly.root";
52 
53  cout << "creating dummy geometry...\n";
54 
55  // the Geometry we want to use
56  TString geometryFile = "Luminosity-Detector.root";
57 
58  // we have to setup a dummy simulation so the gGeoManager indexes the Geometry
59  TString simOutput = "./dummy.root";
60  FairRunSim *fRun = new FairRunSim();
61  fRun->SetName("TGeant4");
62  fRun->SetOutputFile(simOutput);
63  fRun->SetMaterials("media_pnd.geo");
64  FairModule *Cave = new PndCave("CAVE");
65  Cave->SetGeometryFileName("pndcave.geo");
66  fRun->AddModule(Cave);
67  FairModule *Pipe = new PndPipe("PIPE");
68  Pipe->SetGeometryFileName("beampipe_201309.root");
69  fRun->AddModule(Pipe);
70  FairModule *Magnet = new PndMagnet("MAGNET");
71  Magnet->SetGeometryFileName("FullSolenoid_V842.root");
72  fRun->AddModule(Magnet);
73  FairModule *Dipole = new PndMagnet("MAGNET");
74  Dipole->SetGeometryFileName("dipole.geo");
75  fRun->AddModule(Dipole);
76  PndLmdDetector *Lum = new PndLmdDetector("LUM", kTRUE);
77  Lum->SetExclusiveSensorType("LumActive"); //ignore MVD
78  Lum->SetGeometryFileName(geometryFile);
79  fRun->AddModule(Lum);
80  fRun->Init();
81 
82  // after init, the geometry can't be changed anymore, but that's okay.
83  // we only want to create a matrix file that can be used in a later step.
84 
85  cout << "PndLmd: creating misalignment matrices.\n";
86 
88  vector < string > paths = helper.getAllAlignPaths(true, false, false, false, false);
89 
90  cout << "got paths.\n";
91 
92  std::map < std::string, TGeoHMatrix > matrices;
93 
94  // for testing if ONE matrix works
95  if (debug) {
96 
97  misMatricesFilePath = "misalignMatrices-Sensor-0.root";
98 
99  // Misalign geometry
100  std::string examplePath = "/cave_1/lmd_root_0/half_0/plane_0/module_0/sensor_0/";
101 
102  TGeoHMatrix misalignTestMat;
103  double translation[3] = { 0.5, 0.5, 0.0 };
104  misalignTestMat.SetTranslation(translation);
105  matrices[examplePath] = misalignTestMat;
106 
107  } else {
108 
109  for (auto &i : paths) {
110  // TODO: cerate sigma parameters another way
111 
112  double shift = 1000e-4; // this is 1 mm!
113  double rot = TMath::RadToDeg() * 1000e-3; // this is... large
114 
115  TGeoHMatrix tempMat = createRandomMatrix(rot, shift);
116  matrices[i] = tempMat;
117  }
118  }
119 
120  if (true) {
121  // checking for good measure
122  for (auto &i : matrices) {
123  cout << "\n---\n" << i.first << "\n";
124  i.second.Print();
125  }
126  }
127 
128  TFile *misalignmentMatrixRootfile = new TFile(misMatricesFilePath.c_str(), "NEW");
129  if (misalignmentMatrixRootfile->IsOpen()) {
130  printf("File opened successfully\n");
131 
132  gDirectory->WriteObject(&matrices, "PndLmdMisalignMatrices");
133  misalignmentMatrixRootfile->Write();
134  misalignmentMatrixRootfile->Close();
135 
136  cout << "All matrices written to file!\n";
137  } else {
138  cerr << "WARNING! Could not write to " << misMatricesFilePath << "\n";
139  }
140  return 0;
141 }
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
TGeoHMatrix createRandomMatrix(double angleSigma, double shiftSigma)
Int_t i
Definition: run_full.C:25
void SetExclusiveSensorType(const TString sens)
static PndLmdGeometryHelper & getInstance()
int createPndLmdMisalignmentMatrices(bool debug=false)
std::vector< std::string > getAllAlignPaths(bool sensors=true, bool modules=false, bool planes=false, bool halfs=false, bool detector=false)
FairRunAna * fRun
Definition: hit_dirc.C:58
FairModule * Dipole
Definition: sim_emc_apd.C:40
FairModule * Cave
Definition: sim_emc_apd.C:32
unsigned int seed
TString simOutput
TGeoRotation rot
Double_t mean[nsteps]
Definition: dedx_bands.C:65
FairModule * Pipe
Definition: sim_emc_apd.C:44
FairModule * Magnet
Definition: sim_emc_apd.C:36
Definition: PndCave.h:8