3 #include "FairLogger.h"
4 #include "FairRootManager.h"
7 #include "TClonesArray.h"
11 #include "TGeoManager.h"
18 #include "FairTrackParam.h"
19 #include "TMatrixFSym.h"
36 FairRootManager* fmanager = FairRootManager::Instance();
41 LOG(info) <<
"CbmRichProjectionProducerAnalytical::Init()";
42 FairRootManager* manager = FairRootManager::Instance();
44 fTrackParams = (TClonesArray*) manager->GetObject(
"RichTrackParamZ");
46 Fatal(
"CbmRichProjectionProducerAnalytical::Init",
47 "No RichTrackParamZ array !");
50 fMCTracks = (TClonesArray*) manager->GetObject(
"MCTrack");
52 Fatal(
"CbmRichCorrectionVector::Init",
"No MCTracks array !");
55 fRichPoints = (TClonesArray*) manager->GetObject(
"RichPoint");
57 Fatal(
"CbmRichCorrectionVector::Init",
"No RichPoint array !");
64 "--------------------------------------------------------------------"
65 "------------------------------------------//"
67 cout <<
"//-------------------------------- CbmRichProjectionProducer2: Do "
68 "Projection ---------------------------------//"
72 "--------------------------------------------------------------------"
73 "--------------------------------------------------//"
78 cout <<
"CbmRichProjectionProducer2 : Event #" <<
fEventNum << endl;
86 projectedPoint->Delete();
87 TMatrixFSym covMat(5);
88 for (Int_t iMatrix = 0; iMatrix < 5; iMatrix++) {
89 for (Int_t jMatrix = 0; jMatrix <= iMatrix; jMatrix++) {
90 covMat(iMatrix, jMatrix) = 0;
93 covMat(0, 0) = covMat(1, 1) = covMat(2, 2) = covMat(3, 3) = covMat(4, 4) =
96 for (Int_t j = 0; j <
fTrackParams->GetEntriesFast(); j++) {
97 FairTrackParam* point = (FairTrackParam*)
fTrackParams->At(j);
98 new ((*projectedPoint)[j]) FairTrackParam(0., 0., 0., 0., 0., 0., covMat);
101 if (point->GetX() == 0 && point->GetY() == 0 && point->GetZ() == 0
102 && point->GetTx() == 0 && point->GetTy() == 0)
104 if (point->GetQp() == 0)
continue;
106 Double_t xDet = 0., yDet = 0., zDet = 0.;
114 Double_t marginX = 2.;
115 Double_t marginY = 2.;
117 Double_t pmtYTop = TMath::Abs(pmtPlaneY) + pmtHeight + marginY;
118 Double_t pmtYBottom = TMath::Abs(pmtPlaneY) - pmtHeight - marginY;
119 Double_t absYDet = TMath::Abs(yDet);
120 Bool_t isYOk = (absYDet <= pmtYTop && absYDet >= pmtYBottom);
122 Double_t pmtXMin = -TMath::Abs(pmtPlaneX) - pmtWidth - marginX;
123 Double_t pmtXMax = TMath::Abs(pmtPlaneX) + pmtWidth + marginX;
125 Bool_t isXOk = (xDet >= pmtXMin && xDet <= pmtXMax);
127 if (isYOk && isXOk) {
128 FairTrackParam richtrack(xDet, yDet, zDet, 0., 0., 0., covMat);
129 *(FairTrackParam*) (projectedPoint->At(j)) = richtrack;
136 cout <<
"//------------------------------ CbmRichProjectionProducer2: "
137 "Projection Producer ------------------------------//"
141 static Double_t pmtPt[3];
143 Int_t NofPMTPoints =
fRichPoints->GetEntriesFast();
146 Double_t sphereRadius = 300., constantePMT = 0.;
147 vector<Double_t> ptM(3), ptC(3), ptCNew(3), momR1(3), ptR1(3), normalPMT(3),
148 ptR2Mirr(3), ptR2Center(3), ptPMirr(3), ptPR2(3), ptTileCenter(3);
149 vector<Double_t> ptCIdeal(3), ptR2CenterUnCorr(3), ptR2CenterIdeal(3),
150 ptR2MirrUnCorr(3), ptR2MirrIdeal(3), ptPMirrUnCorr(3), ptPMirrIdeal(3),
151 ptPR2UnCorr(3), ptPR2Ideal(3);
152 TVector3 outPos, outPosUnCorr, outPosIdeal;
154 Double_t ringCenter[] = {0., 0., 0.}, distToExtrapTrackHit = 0.,
155 distToExtrapTrackHitInPlane = 0.;
157 Int_t pmtTrackID = -1, pmtMotherID = -100;
160 ptR1.at(0) = trackParam->GetX();
161 ptR1.at(1) = trackParam->GetY();
162 ptR1.at(2) = trackParam->GetZ();
163 Double_t nx = 0., ny = 0., nz = 0.;
166 dirCos.SetXYZ(nx, ny, nz);
168 cout <<
"Calculated normal vector to PMT plane = {" << normalPMT.at(0) <<
", "
169 << normalPMT.at(1) <<
", " << normalPMT.at(2)
170 <<
"} and constante d = " << constantePMT << endl
173 TVector3 mirrorPoint;
175 trackParam, mirrorPoint,
"mirror_tile_type", navi);
176 ptM.at(0) = mirrorPoint.x();
177 ptM.at(1) = mirrorPoint.y();
178 ptM.at(2) = mirrorPoint.z();
179 cout <<
"mirrorIntersection1: " << mirrorIntersection1 << endl;
180 cout <<
"Mirror point coordinates = {" << mirrorPoint.x() <<
", "
181 << mirrorPoint.y() <<
", " << mirrorPoint.z() <<
"}" << endl;
182 TString mirrorIntersection =
183 "/cave_1/rich1_0/richContainer_333/rich_gas_329/mirror_full_half_321/"
184 "mirror_tile_2_0_148/mirror_tile_type2"
185 "_inter_108/mirror_tile_type2_94/"
186 + mirrorIntersection1;
187 cout <<
"mirrorIntersection: " << mirrorIntersection << endl;
189 if (mirrorIntersection1) {
193 cout <<
"Navigator path: " << navi->GetPath() << endl;
194 cout <<
"Coordinates of sphere center: " << endl;
195 navi->GetCurrentMatrix()->Print();
196 ptCIdeal.at(0) = navi->GetCurrentMatrix()->GetTranslation()[0];
197 ptCIdeal.at(1) = navi->GetCurrentMatrix()->GetTranslation()[1];
198 ptCIdeal.at(2) = navi->GetCurrentMatrix()->GetTranslation()[2];
199 cout <<
"Coordinates of tile center: " << endl;
200 navi->GetMotherMatrix()->Print();
201 ptC.at(0) = 0., ptC.at(1) = 132.594000,
202 ptC.at(2) = 54.267226;
203 cout <<
"Sphere center coordinates of the aligned mirror tile, ideal = {"
204 << ptCIdeal.at(0) <<
", " << ptCIdeal.at(1) <<
", " << ptCIdeal.at(2)
206 cout <<
"Sphere center coordinates of the rotated mirror tile, w/ "
208 << ptC.at(0) <<
", " << ptC.at(1) <<
", " << ptC.at(2)
209 <<
"} and sphere inner radius = " << sphereRadius << endl
213 cout <<
"FairTrackParam Point coordinates = {" << ptR1.at(0) <<
", "
214 << ptR1.at(1) <<
", " << ptR1.at(2) <<
"}" << endl;
215 cout <<
"And FairTrackParam Point direction cosines = {" << ptR1.at(3)
216 <<
", " << ptR1.at(4) <<
", " << ptR1.at(5) <<
"}" << endl;
217 cout <<
"Mirror Point coordinates = {" << ptM.at(0) <<
", " << ptM.at(1)
218 <<
", " << ptM.at(2) <<
"}" << endl;
221 ptR2CenterUnCorr, ptR2MirrUnCorr, ptM, ptC, ptR1, navi,
"Uncorrected");
222 ComputeR2(ptR2Center, ptR2Mirr, ptM, ptC, ptR1, navi,
"Corrected");
224 ptR2CenterIdeal, ptR2MirrIdeal, ptM, ptCIdeal, ptR1, navi,
"Uncorrected");
227 ptPMirrUnCorr, ptPR2UnCorr, normalPMT, ptM, ptR2MirrUnCorr, constantePMT);
228 ComputeP(ptPMirr, ptPR2, normalPMT, ptM, ptR2Mirr, constantePMT);
230 ptPMirrIdeal, ptPR2Ideal, normalPMT, ptM, ptR2MirrIdeal, constantePMT);
232 TVector3 inPosUnCorr(
233 ptPMirrUnCorr.at(0), ptPMirrUnCorr.at(1), ptPMirrUnCorr.at(2));
235 cout <<
"New mirror points coordinates = {" << outPosUnCorr.x() <<
", "
236 << outPosUnCorr.y() <<
", " << outPosUnCorr.z() <<
"}" << endl;
237 TVector3 inPos(ptPMirr.at(0), ptPMirr.at(1), ptPMirr.at(2));
239 cout <<
"New mirror points coordinates = {" << outPos.x() <<
", "
240 << outPos.y() <<
", " << outPos.z() <<
"}" << endl;
242 ptPMirrIdeal.at(0), ptPMirrIdeal.at(1), ptPMirrIdeal.at(2));
245 <<
"New mirror points coordinates = {" << outPosIdeal.x() <<
", "
246 << outPosIdeal.y() <<
", " << outPosIdeal.z() <<
"}" << endl
249 cout <<
"No mirror intersection found ..." << endl;
250 outPos.SetXYZ(0, 0, 0);
253 pmtPt[0] = outPos.x();
254 pmtPt[1] = outPos.y();
255 pmtPt[2] = outPos.z();
260 vector<Double_t>& normalPMT,
261 Double_t& normalCste) {
264 Int_t pmtTrackID, pmtMotherID;
265 Double_t buffNormX = 0., buffNormY = 0., buffNormZ = 0., k = 0.,
267 Double_t pmtPt[] = {0., 0., 0.};
268 Double_t a[] = {0., 0., 0.}, b[] = {0., 0., 0.}, c[] = {0., 0., 0.};
276 for (Int_t iPmt = 0; iPmt < NofPMTPoints; iPmt++) {
278 pmtTrackID = pmtPoint->GetTrackID();
282 cout <<
"a[0] = " << a[0] <<
", a[1] = " << a[1] <<
" et a[2] = " << a[2]
286 for (Int_t iPmt = 0; iPmt < NofPMTPoints; iPmt++) {
288 pmtTrackID = pmtPoint->GetTrackID();
292 if (TMath::Sqrt(TMath::Power(a[0] - pmtPoint->GetX(), 2)
293 + TMath::Power(a[1] - pmtPoint->GetY(), 2)
294 + TMath::Power(a[2] - pmtPoint->GetZ(), 2))
297 cout <<
"b[0] = " << b[0] <<
", b[1] = " << b[1] <<
" et b[2] = " << b[2]
302 for (Int_t iPmt = 0; iPmt < NofPMTPoints; iPmt++) {
304 pmtTrackID = pmtPoint->GetTrackID();
308 if (TMath::Sqrt(TMath::Power(a[0] - pmtPoint->GetX(), 2)
309 + TMath::Power(a[1] - pmtPoint->GetY(), 2)
310 + TMath::Power(a[2] - pmtPoint->GetZ(), 2))
312 && TMath::Sqrt(TMath::Power(b[0] - pmtPoint->GetX(), 2)
313 + TMath::Power(b[1] - pmtPoint->GetY(), 2)
314 + TMath::Power(b[2] - pmtPoint->GetZ(), 2))
316 c[0] = pmtPoint->GetX(), c[1] = pmtPoint->GetY(), c[2] = pmtPoint->GetZ();
322 k = (b[0] - a[0]) / (c[0] - a[0]);
323 if ((b[1] - a[1]) - (k * (c[1] - a[1])) == 0
324 || (b[2] - a[2]) - (k * (c[2] - a[2])) == 0) {
325 cout <<
"Error in normal calculation, vect_AB and vect_AC are collinear."
328 buffNormX = (b[1] - a[1]) * (c[2] - a[2]) - (b[2] - a[2]) * (c[1] - a[1]);
329 buffNormY = (b[2] - a[2]) * (c[0] - a[0]) - (b[0] - a[0]) * (c[2] - a[2]);
330 buffNormZ = (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
333 / TMath::Sqrt(TMath::Power(buffNormX, 2) + TMath::Power(buffNormY, 2)
334 + TMath::Power(buffNormZ, 2));
337 / TMath::Sqrt(TMath::Power(buffNormX, 2) + TMath::Power(buffNormY, 2)
338 + TMath::Power(buffNormZ, 2));
341 / TMath::Sqrt(TMath::Power(buffNormX, 2) + TMath::Power(buffNormY, 2)
342 + TMath::Power(buffNormZ, 2));
346 scalarProd = normalPMT.at(0) * (pmtPoint1->GetX() - a[0])
347 + normalPMT.at(1) * (pmtPoint1->GetY() - a[1])
348 + normalPMT.at(2) * (pmtPoint1->GetZ() - a[2]);
353 * (normalPMT.at(0) * pmtPoint1->GetX() + normalPMT.at(1) * pmtPoint1->GetY()
354 + normalPMT.at(2) * pmtPoint1->GetZ());
356 scalarProd = normalPMT.at(0) * (pmtPoint2->GetX() - a[0])
357 + normalPMT.at(1) * (pmtPoint2->GetY() - a[1])
358 + normalPMT.at(2) * (pmtPoint2->GetZ() - a[2]);
361 scalarProd = normalPMT.at(0) * (pmtPoint3->GetX() - a[0])
362 + normalPMT.at(1) * (pmtPoint3->GetY() - a[1])
363 + normalPMT.at(2) * (pmtPoint3->GetZ() - a[2]);
368 vector<Double_t>& ptR2Mirr,
369 vector<Double_t> ptM,
370 vector<Double_t> ptC,
371 vector<Double_t> ptR1,
375 <<
"//------------------------------ CbmRichCorrection: ComputeR2 "
376 "------------------------------//"
380 vector<Double_t> normalMirr(3), ptCNew(3), ptTileCenter(3);
381 Double_t t1 = 0., t2 = 0., t3 = 0.;
383 if (s ==
"Corrected") {
386 vector<Double_t> outputFit(4);
390 if (corr_file.is_open()) {
391 for (Int_t
i = 0;
i < 4;
i++) {
392 corr_file >> outputFit.at(
i);
396 cout <<
"Error in CbmRichCorrection: unable to open parameter file!"
401 cout <<
"Misalignment parameters read from file = [" << outputFit.at(0)
402 <<
" ; " << outputFit.at(1) <<
" ; " << outputFit.at(2) <<
" ; "
403 << outputFit.at(3) <<
"]" << endl;
405 ptCNew.at(0) = TMath::Abs(ptC.at(0) - TMath::Abs(outputFit.at(3)));
406 ptCNew.at(1) = TMath::Abs(ptC.at(1) - TMath::Abs(outputFit.at(2)));
409 ptCNew.at(2) = ptC.at(2);
410 ptTileCenter.at(0) = navi->GetMotherMatrix()->GetTranslation()[0];
411 ptTileCenter.at(1) = navi->GetMotherMatrix()->GetTranslation()[1];
412 ptTileCenter.at(2) = navi->GetMotherMatrix()->GetTranslation()[2];
413 cout <<
"Mirror tile center coordinates = {" << ptTileCenter.at(0) <<
", "
414 << ptTileCenter.at(1) <<
", " << ptTileCenter.at(2) <<
"}" << endl;
415 Double_t
x = 0.,
y = 0., z = 0., dist = 0., dist2 = 0.,
z2 = 0.;
416 x = TMath::Power(ptCNew.at(0) - ptTileCenter.at(0), 2);
417 y = TMath::Power(ptCNew.at(1) - ptTileCenter.at(1), 2);
418 z = TMath::Power(ptCNew.at(2) - ptTileCenter.at(2), 2);
419 dist = TMath::Sqrt(
x +
y + z);
420 z2 = ptTileCenter.at(2) - TMath::Sqrt(TMath::Power(300, 2) -
x -
y)
422 cout <<
"{x, y, z} = {" <<
x <<
", " <<
y <<
", " << z
423 <<
"}, dist = " << dist <<
" and z2 = " <<
z2 << endl;
424 dist2 = TMath::Sqrt(
x +
y + TMath::Power(
z2 - ptTileCenter.at(2), 2));
425 cout <<
"dist2 = " << dist2 << endl;
427 cout <<
"Sphere center coordinates of the rotated mirror tile, after "
429 << ptCNew.at(0) <<
", " << ptCNew.at(1) <<
", " << ptCNew.at(2) <<
"}"
431 }
else if (s ==
"Uncorrected") {
434 cout <<
"Sphere center coordinates of the rotated mirror tile, without "
436 << ptCNew.at(0) <<
", " << ptCNew.at(1) <<
", " << ptCNew.at(2) <<
"}"
439 cout <<
"No input given in function ComputeR2! Uncorrected parameters for "
440 "the sphere center of the tile will be used!"
443 cout <<
"Sphere center coordinates of the rotated mirror tile, without "
445 << ptCNew.at(0) <<
", " << ptCNew.at(1) <<
", " << ptCNew.at(2) <<
"}"
449 normalMirr.at(0) = (ptCNew.at(0) - ptM.at(0))
450 / TMath::Sqrt(TMath::Power(ptCNew.at(0) - ptM.at(0), 2)
451 + TMath::Power(ptCNew.at(1) - ptM.at(1), 2)
452 + TMath::Power(ptCNew.at(2) - ptM.at(2), 2));
453 normalMirr.at(1) = (ptCNew.at(1) - ptM.at(1))
454 / TMath::Sqrt(TMath::Power(ptCNew.at(0) - ptM.at(0), 2)
455 + TMath::Power(ptCNew.at(1) - ptM.at(1), 2)
456 + TMath::Power(ptCNew.at(2) - ptM.at(2), 2));
457 normalMirr.at(2) = (ptCNew.at(2) - ptM.at(2))
458 / TMath::Sqrt(TMath::Power(ptCNew.at(0) - ptM.at(0), 2)
459 + TMath::Power(ptCNew.at(1) - ptM.at(1), 2)
460 + TMath::Power(ptCNew.at(2) - ptM.at(2), 2));
463 t1 = ((ptR1.at(0) - ptM.at(0)) * (ptCNew.at(0) - ptM.at(0))
464 + (ptR1.at(1) - ptM.at(1)) * (ptCNew.at(1) - ptM.at(1))
465 + (ptR1.at(2) - ptM.at(2)) * (ptCNew.at(2) - ptM.at(2)))
466 / (TMath::Power(ptCNew.at(0) - ptM.at(0), 2)
467 + TMath::Power(ptCNew.at(1) - ptM.at(1), 2)
468 + TMath::Power(ptCNew.at(2) - ptM.at(2), 2));
470 2 * (ptM.at(0) + t1 * (ptCNew.at(0) - ptM.at(0))) - ptR1.at(0);
472 2 * (ptM.at(1) + t1 * (ptCNew.at(1) - ptM.at(1))) - ptR1.at(1);
474 2 * (ptM.at(2) + t1 * (ptCNew.at(2) - ptM.at(2))) - ptR1.at(2);
475 t2 = ((ptR1.at(0) - ptCNew.at(0)) * (ptCNew.at(0) - ptM.at(0))
476 + (ptR1.at(1) - ptCNew.at(1)) * (ptCNew.at(1) - ptM.at(1))
477 + (ptR1.at(2) - ptCNew.at(2)) * (ptCNew.at(2) - ptM.at(2)))
478 / (TMath::Power(ptCNew.at(0) - ptM.at(0), 2)
479 + TMath::Power(ptCNew.at(1) - ptM.at(1), 2)
480 + TMath::Power(ptCNew.at(2) - ptM.at(2), 2));
482 2 * (ptCNew.at(0) + t2 * (ptCNew.at(0) - ptM.at(0))) - ptR1.at(0);
484 2 * (ptCNew.at(1) + t2 * (ptCNew.at(1) - ptM.at(1))) - ptR1.at(1);
486 2 * (ptCNew.at(2) + t2 * (ptCNew.at(2) - ptM.at(2))) - ptR1.at(2);
488 cout <<
"Coordinates of point R2 on reflective plane after reflection on the "
492 cout <<
"* using sphere center C to define \U00000394: {" << ptR2Mirr.at(0)
493 <<
", " << ptR2Mirr.at(1) <<
", " << ptR2Mirr.at(2) <<
"}" << endl;
497 vector<Double_t>& ptPR2,
498 vector<Double_t> normalPMT,
499 vector<Double_t> ptM,
500 vector<Double_t> ptR2Mirr,
501 Double_t constantePMT) {
503 <<
"//------------------------------ CbmRichCorrection: ComputeP "
504 "------------------------------//"
508 Double_t k1 = 0., k2 = 0., checkCalc1 = 0., checkCalc2 = 0.;
511 * ((normalPMT.at(0) * ptM.at(0) + normalPMT.at(1) * ptM.at(1)
512 + normalPMT.at(2) * ptM.at(2) + constantePMT)
513 / (normalPMT.at(0) * (ptR2Mirr.at(0) - ptM.at(0))
514 + normalPMT.at(1) * (ptR2Mirr.at(1) - ptM.at(1))
515 + normalPMT.at(2) * (ptR2Mirr.at(2) - ptM.at(2))));
516 ptPMirr.at(0) = ptM.at(0) + k1 * (ptR2Mirr.at(0) - ptM.at(0));
517 ptPMirr.at(1) = ptM.at(1) + k1 * (ptR2Mirr.at(1) - ptM.at(1));
518 ptPMirr.at(2) = ptM.at(2) + k1 * (ptR2Mirr.at(2) - ptM.at(2));
520 * ((normalPMT.at(0) * ptR2Mirr.at(0) + normalPMT.at(1) * ptR2Mirr.at(1)
521 + normalPMT.at(2) * ptR2Mirr.at(2) + constantePMT)
522 / (normalPMT.at(0) * (ptR2Mirr.at(0) - ptM.at(0))
523 + normalPMT.at(1) * (ptR2Mirr.at(1) - ptM.at(1))
524 + normalPMT.at(2) * (ptR2Mirr.at(2) - ptM.at(2))));
525 ptPR2.at(0) = ptR2Mirr.at(0) + k2 * (ptR2Mirr.at(0) - ptM.at(0));
526 ptPR2.at(1) = ptR2Mirr.at(1) + k2 * (ptR2Mirr.at(1) - ptM.at(1));
527 ptPR2.at(2) = ptR2Mirr.at(2) + k2 * (ptR2Mirr.at(2) - ptM.at(2));
528 cout <<
"Coordinates of point P on PMT plane, after reflection on the mirror "
529 "tile and extrapolation to the PMT plane:"
531 cout <<
"* using mirror point M to define \U0001D49F ': {" << ptPMirr.at(0)
532 <<
", " << ptPMirr.at(1) <<
", " << ptPMirr.at(2) <<
"}" << endl;
534 checkCalc1 = ptPMirr.at(0) * normalPMT.at(0) + ptPMirr.at(1) * normalPMT.at(1)
535 + ptPMirr.at(2) * normalPMT.at(2) + constantePMT;
536 cout <<
"Check whether extrapolated track point on PMT plane verifies its "
537 "equation (value should be 0.):"
539 cout <<
"* using mirror point M, checkCalc = " << checkCalc1 << endl;
540 checkCalc2 = ptPR2.at(0) * normalPMT.at(0) + ptPR2.at(1) * normalPMT.at(1)
541 + ptPR2.at(2) * normalPMT.at(2) + constantePMT;