10 #include <boost/filesystem.hpp>
24 #include <TClonesArray.h>
26 #include <TGeoManager.h>
59 TH1D histogram(parameters.
title.c_str(), parameters.
title.c_str(), parameters.
bins, parameters.
xMin,
62 histogram.GetXaxis()->SetTitle(parameters.
xtitle.c_str());
63 histogram.GetYaxis()->SetTitle(parameters.
ytitle.c_str());
64 if (
vec.size() == 0) {
65 cout <<
"Error: nothing read, data empty! (maybe not enough pairs?) \n";
70 for (
size_t iArea = 0; iArea <
vec.size(); iArea++) {
72 histogram.Fill(dataPoint);
74 std::stringstream pathname;
75 pathname << parameters.
path;
81 TCanvas canvas(
"canvas",
"canvas", 800, 600);
84 histogram.Draw(
"HIST TEXT0 SAME");
85 canvas.Print((pathname.str() + parameters.
fileName).c_str());
99 info.open(filename.c_str());
100 if (info.is_open()) {
103 std::vector<string> values;
104 int overlapid, noPairs;
105 bool alignerComplete =
true;
107 while (std::getline(info, line)) {
108 if (line.find(
"aligner") != std::string::npos && alignerComplete) {
111 if (values.size() > 1) {
112 overlapid = std::stoi(values[1]);
114 alignerComplete =
false;
117 else if (line.find(
"no of pairs") != std::string::npos) {
120 if (values.size() > 1) {
121 noPairs = std::stoi(values[1]);
123 alignerComplete =
true;
129 throw std::runtime_error(
"Unable to open file " + filename);
134 cout <<
"reading matrices from file: " << filename <<
"\n";
136 TFile *misalignmentMatrixRootfile =
new TFile(filename,
"READ");
138 if (misalignmentMatrixRootfile->IsOpen()) {
139 std::map<std::string, TGeoHMatrix> *matrices;
141 gDirectory->GetObject(
"PndLmdMisalignMatrices", matrices);
142 misalignmentMatrixRootfile->Close();
143 cout << matrices->size() <<
" matrices successfully read from file.\n";
148 cout <<
"file could not be read\n";
155 return TGeoHMatrix(toBaseMatrix * input * toBaseMatrix.Inverse());
164 return sen0to1ICPcorr * sen0to1;
173 return sen0to1ICPcorr * sen0to1;
183 return toSen0.Inverse() * toSen1;
190 cerr <<
"Error! No matrices in memory, please load them first.\n";
191 return TGeoHMatrix();
195 TGeoHMatrix misalignmentToSensor0 = (*matricesMisaligned)[info.
path1];
196 TGeoHMatrix misalignmentToSensor1 = (*matricesMisaligned)[info.
path2];
201 return misalignmentToSensor0.Inverse() * misSen1inSen0;
209 double colTest2 = 0, rowTest2 = 0;
213 TVector3 testVectorTransformed;
216 for (
int colTest1 = 0; colTest1 < 247; colTest1++) {
217 for (
int rowTest1 = 0; rowTest1 < 242; rowTest1++) {
219 testVector.SetXYZ(colTest1, rowTest1, 0.0);
224 colTest2 = testVectorTransformed.x();
225 rowTest2 = testVectorTransformed.y();
229 if (colTest2 < 0 || colTest2 > 247) {
232 if (rowTest2 < 0 || rowTest2 > 242) {
240 double coverage = (double) valid / (250.0 * 250.0) * 100;
249 cout <<
"------------ TESTING --------------\n";
254 cout <<
"------------ DONE --------------\n";
260 double areaPercent = 0;
263 for (
unsigned int i = 0;
i < overlapIDs.size();
i++) {
268 cout <<
"\\AtoB{" << id1 <<
"}{" << id2 <<
"} & " << areaPercent <<
"\n";
283 vector<string>
files;
288 if (files.size() == 0) {
293 bool tempfilefound =
false;
296 for (
size_t i = 0;
i < availableIds.size();
i++) {
299 tempfilefound =
false;
302 for (
size_t j = 0; j < files.size(); j++) {
303 if (files[j].find(matrixName) != string::npos) {
304 tempfilefound =
true;
309 if (!tempfilefound) {
310 return tempfilefound;
318 std::vector<double> result;
323 const double *translationDesign = Mtarget.GetTranslation();
324 const double *translationICP = ICP.GetTranslation();
325 const double *rotationDesign = Mtarget.GetRotationMatrix();
326 const double *rotationICP = ICP.GetRotationMatrix();
328 double dx = translationDesign[0] - translationICP[0];
329 double dy = translationDesign[1] - translationICP[1];
330 double da = rotationDesign[1] - rotationICP[1];
332 result.push_back(dx);
333 result.push_back(dy);
334 result.push_back(da);
342 for (
auto &info : infos) {
343 int smallOverlapHere = info.
overlapID % 10;
344 if (smallOverlap == smallOverlapHere) {
352 const double *translationDesign = mat1.GetTranslation();
353 const double *translationICP = mat2.GetTranslation();
354 const double *rotationDesign = mat1.GetRotationMatrix();
355 const double *rotationICP = mat2.GetRotationMatrix();
357 double dx = translationDesign[0] - translationICP[0];
358 double dy = translationDesign[1] - translationICP[1];
359 double da = rotationDesign[1] - rotationICP[1];
361 std::vector<double> result;
362 result.push_back(dx);
363 result.push_back(dy);
364 result.push_back(da);
373 TString misalignedMatrices =
"misalignMatrices-SensorsOnly-100u.root";
374 TString idealMatrices =
"idealMatrices.root";
376 "/home/arbeit/RedPro3TB/simulationData/2018-05-07-misalign-100u/LMDmatrices-inSensorOne";
380 std::map<int, TGeoHMatrix> matricesByHand;
381 std::map<int, TGeoHMatrix> matricesByGeoManager;
383 bool compareWithIdeal =
true;
384 string ext =
"cm.mat";
386 cout <<
"getting matrices by hand/ICP-like\n";
387 for (
int iHalf = 0; iHalf < 2; iHalf++) {
388 for (
int iPlane = 0; iPlane < 4; iPlane++) {
389 for (
int iModule = 0; iModule < 5; iModule++) {
405 if (compareWithIdeal) {
441 TGeoHMatrix sen1to2 = mat4 * mat5.Inverse();
442 TGeoHMatrix sen1to3 = mat4 * mat1.Inverse();
443 TGeoHMatrix sen1to4a = mat4 * mat5.Inverse() * mat6 * mat2.Inverse();
444 TGeoHMatrix sen1to4b = mat4 * mat1.Inverse() * mat7 * mat8.Inverse();
446 TGeoHMatrix sen1to5 = mat0;
447 TGeoHMatrix sen1to6 = mat4 * mat1.Inverse() * mat3;
448 TGeoHMatrix sen1to7 = mat4 * mat1.Inverse() * mat7;
449 TGeoHMatrix sen1to8 = mat4;
450 TGeoHMatrix sen1to9a = mat4 * mat5.Inverse() * mat6;
451 TGeoHMatrix sen1to9b = mat4 * mat1.Inverse() * mat7 * mat8.Inverse() * mat2;
453 int matrixId = 1000 * iHalf + 100 * iPlane + 10 * iModule;
455 matricesByHand[matrixId + 2] = sen1to2;
456 matricesByHand[matrixId + 3] = sen1to3;
457 matricesByHand[matrixId + 4] = sen1to4a;
458 matricesByHand[matrixId + 5] = sen1to5;
459 matricesByHand[matrixId + 6] = sen1to6;
460 matricesByHand[matrixId + 7] = sen1to7;
461 matricesByHand[matrixId + 8] = sen1to8;
462 matricesByHand[matrixId + 9] = sen1to9a;
469 cout <<
"getting matrices by geoManager after misalignment\n";
470 for (
int iHalf = 0; iHalf < 2; iHalf++) {
471 for (
int iPlane = 0; iPlane < 4; iPlane++) {
472 for (
int iModule = 0; iModule < 5; iModule++) {
477 int matrixId = 1000 * iHalf + 100 * iPlane + 10 * iModule;
490 int sensor0 = info0.
id1;
491 int sensor1 = info4.
id1;
493 int sensor3 = info1.
id1;
494 int sensor4 = info2.
id1;
495 int sensor5 = info0.
id2;
496 int sensor6 = info3.
id2;
497 int sensor7 = info7.
id2;
498 int sensor8 = info4.
id2;
499 int sensor9 = info6.
id2;
510 matricesByGeoManager[matrixId + 2] = sen1to2;
511 matricesByGeoManager[matrixId + 3] = sen1to3;
512 matricesByGeoManager[matrixId + 4] = sen1to4a;
513 matricesByGeoManager[matrixId + 5] = sen1to5;
514 matricesByGeoManager[matrixId + 6] = sen1to6;
515 matricesByGeoManager[matrixId + 7] = sen1to7;
516 matricesByGeoManager[matrixId + 8] = sen1to8;
517 matricesByGeoManager[matrixId + 9] = sen1to9a;
522 cout <<
"making histograms\n";
525 std::vector<std::vector<double> > data;
527 for (
auto &
i : matricesByHand) {
529 auto thisDiff =
getMatrixDiff(matricesByHand[key], matricesByGeoManager[key]);
531 std::vector<double> result;
532 result.push_back(key);
533 result.push_back(thisDiff[2]);
534 result.push_back(thisDiff[0]);
535 result.push_back(thisDiff[1]);
536 data.push_back(result);
544 parameters.
bins = 20;
545 parameters.
path = pdfdir +
"/residualsCombined/";
546 parameters.
ytitle =
"entries";
549 parameters.
title =
"matrix combined 0-9 CM - Target, #DeltaX";
550 parameters.
xtitle =
"dX [#mum]";
557 parameters.
title =
"matrix combined 0-9 CM - Target, #DeltaY";
558 parameters.
xtitle =
"dY [#mum]";
565 parameters.
title =
"matrix combined 0-9 CM - Target, #Delta#alpha";
566 parameters.
xtitle =
"d#alpha [#murad]";
588 std::vector<std::vector<double> > data;
597 for (
int i = 0;
i < 400;
i++) {
603 std::vector<double> result;
606 result.push_back(cycle.
val[0][1]);
607 result.push_back(cycle.
val[0][3]);
608 result.push_back(cycle.
val[1][3]);
609 data.push_back(result);
614 parameters.
bins = 20;
617 parameters.
path = pdfdir +
"/cyclicChecks/";
618 inCentimeters ? parameters.
title =
"matrixCM cycle check, #DeltaX" : parameters.
title =
619 "matrixPX cycle check, #DeltaX";
620 parameters.
xtitle =
"dX [#mum]";
621 parameters.
ytitle =
"entries";
625 parameters.
xMin = -1;
626 parameters.
xMax = -1;
632 inCentimeters ? parameters.
title =
"matrixCM cycle check, #DeltaY" : parameters.
title =
633 "matrixPX cycle check, #DeltaY";
634 parameters.
xtitle =
"dY [#mum]";
635 parameters.
ytitle =
"entries";
639 parameters.
xMin = -1;
640 parameters.
xMax = -1;
646 inCentimeters ? parameters.
title =
"matrixCM cycle check, #Delta#alpha" : parameters.
title =
647 "matrixPX cycle check, #Delta#alpha";
648 parameters.
xtitle =
"d#alpha [#murad]";
649 parameters.
ytitle =
"entries";
653 parameters.
xMin = -1;
654 parameters.
xMax = -1;
void setMatrixOutDir(std::string directory)
std::map< std::string, TGeoHMatrix > * matricesMisaligned
std::vector< int > getAvailableOverlapIDs()
int getSensorTwoFromOverlapID(int overlapID)
void setInCentimeters(bool inCentimeters)
PndLmdOverlapInfo & getSmallOverlapInfo(std::vector< PndLmdOverlapInfo > &infos, int smallOverlap)
double calculateOverlappingArea(int id1, int id2)
TGeoHMatrix getMisalignedOverlapFromICP(PndLmdOverlapInfo &info, std::string ICPmatrix)
static TGeoHMatrix readTGeoHMatrix(std::string filename)
static PndLmdGeometryHelper & getInstance()
static int searchFiles(std::string curr_directory, std::vector< std::string > &list, std::string extension="", bool includeSubDirs=true)
TGeoHMatrix getOverlapMatrixLikeICP(PndLmdOverlapInfo &info)
bool checkForMatrixFiles()
std::vector< double > getMatrixDiff(TGeoHMatrix &mat1, TGeoHMatrix &mat2)
PndLmdAlignManager manager
std::map< int, TString > files
void calculateOverlapingAreas()
static bool mkdir(std::string path)
int noOfPairs(int overlapID)
std::map< int, int > matrixInfo
std::vector< PndLmdOverlapInfo > getOverlapInfos(int iHalf=-1, int iPlane=-1, int iModule=-1)
static std::vector< std::string > findRegex(std::string source, std::string regex)
void checkCyclicMatrices(bool inCentimeters=true)
const TGeoHMatrix getMatrixPndGlobalToSensor(const int sensorId)
int getSensorOneFromOverlapID(int overlapID)
TGeoHMatrix getMatrixSensorToSensor(int sensorOne, int sensorTwo)
PndLmdGeometryHelper * helper
static std::string makeMatrixFileName(int overlapId=0, bool incentimeters=true)
TGeoHMatrix baseTransformation(TGeoHMatrix &input, TGeoHMatrix &toBaseMatrix)
std::vector< double > getMatrixDiffCM(PndLmdOverlapInfo &info, std::string &icpFile)
void createHist(std::vector< std::vector< double > > &vec, histParams ¶meters)
TGeoHMatrix getMisalignedOverlapFromGeoManager(PndLmdOverlapInfo &info)
std::map< std::string, TGeoHMatrix > * readRootMatrices(TString &filename)