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 
50 
51  string misMatFileName = "misalignMatrices-SensorsOnly-";
52  string ext = ".root";
53 
54  cout << "creating dummy geometry...\n";
55 
56  // the Geometry we want to use
57  TString geometryFile = "Luminosity-Detector.root";
58 
59  // we have to setup a dummy simulation so the gGeoManager indexes the Geometry
60  TString simOutput = "./dummy.root";
61  FairRunSim *fRun = new FairRunSim();
62  fRun->SetName("TGeant4");
63  fRun->SetOutputFile(simOutput);
64  fRun->SetMaterials("media_pnd.geo");
65  FairModule *Cave = new PndCave("CAVE");
66  Cave->SetGeometryFileName("pndcave.geo");
67  fRun->AddModule(Cave);
68  FairModule *Pipe = new PndPipe("PIPE");
69  Pipe->SetGeometryFileName("beampipe_201309.root");
70  fRun->AddModule(Pipe);
71  FairModule *Magnet = new PndMagnet("MAGNET");
72  Magnet->SetGeometryFileName("FullSolenoid_V842.root");
73  fRun->AddModule(Magnet);
74  FairModule *Dipole = new PndMagnet("MAGNET");
75  Dipole->SetGeometryFileName("dipole.geo");
76  fRun->AddModule(Dipole);
77  PndLmdDetector *Lum = new PndLmdDetector("LUM", kTRUE);
78  Lum->SetExclusiveSensorType("LumActive"); //ignore MVD
79  Lum->SetGeometryFileName(geometryFile);
80  fRun->AddModule(Lum);
81  fRun->Init();
82 
83  // after init, the geometry can't be changed anymore, but that's okay.
84  // we only want to create a matrix file that can be used in a later step.
85 
87  vector < string > paths = helper.getAllAlignPaths(true, false, false, false, false);
88 
89  cout << "got paths.\n";
90 
91  std::map<std::string, TGeoHMatrix> matrices;
92 
93  double misAlignParam;
94 
95  cout << "enter misalign parameter in um (example: 100 for 100um)\n";
96  cout << "don't go higher than 500u. Please enter now:\nmisalign: ";
97 
98  cin >> misAlignParam;
99 
100  cout << "using shift: " << misAlignParam << "um and rot: " << misAlignParam/40 << "mrad \n";
101  cout << "PndLmd: creating misalignment matrices.\n";
102 
103  for (auto &i : paths) {
104 
105  double shift = misAlignParam * 1e-4; //convert to cm for root
106  // use small angle approximation sin x = x
107  double rot = TMath::RadToDeg() * (shift / 4); // see report
108 
109  TGeoHMatrix tempMat = createRandomMatrix(rot, shift);
110  matrices[i] = tempMat;
111  }
112 
113  if (false) {
114  // checking for good measure
115  for (auto &i : matrices) {
116  cout << "\n---\n" << i.first << "\n";
117  i.second.Print();
118  }
119  }
120 
121  string paramStr = std::to_string(int(misAlignParam));
122 
123  TFile *misalignmentMatrixRootfile = new TFile((misMatFileName + paramStr + ext).c_str(), "NEW");
124  if (misalignmentMatrixRootfile->IsOpen()) {
125  printf("File opened successfully\n");
126 
127  gDirectory->WriteObject(&matrices, "PndLmdMisalignMatrices");
128  misalignmentMatrixRootfile->Write();
129  misalignmentMatrixRootfile->Close();
130 
131  cout << "All matrices written to file!\n";
132  }
133  else {
134  cerr << "WARNING! Could not write to " << misMatFileName << "\n";
135  }
136  return 0;
137 }
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()
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
PndLmdGeometryHelper * helper
FairModule * Dipole
Definition: sim_emc_apd.C:40
FairModule * Cave
Definition: sim_emc_apd.C:32
unsigned int seed
int createPndLmdMisalignmentMatrices()
TString simOutput
TNtuple * ext
Definition: reco_muo.C:24
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