CbmRoot
Loading...
Searching...
No Matches
CbmRichAlignment.cxx
Go to the documentation of this file.
1/* Copyright (C) 2016-2021 Justus-Liebig-Universitaet Giessen, Giessen
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Jordan Bendarouach [committer] */
4
5// ---------- Original Headers ---------- //
6#include "CbmRichAlignment.h"
7
8#include "CbmDrawHist.h"
9#include "CbmRichHit.h"
10#include "FairRootManager.h"
11#include "TCanvas.h"
12#include "TClonesArray.h"
13#include "TF1.h"
14#include "TH1D.h"
15#include "TH2D.h"
16
17#include <Logger.h>
18
19#include <iostream>
20#include <vector>
21
22// ---------- Included Headers ---------- //
23#include "CbmMCTrack.h"
24#include "CbmRichConverter.h"
25#include "CbmRichPoint.h"
28#include "CbmRichRingLight.h"
29#include "CbmTrackMatchNew.h"
30#include "CbmUtils.h"
31#include "FairTrackParam.h"
32#include "FairVolume.h"
33#include "TEllipse.h"
34#include "TGeoManager.h"
35
36#include <algorithm>
37#include <fstream>
38#include <iomanip>
39
40#include <stdlib.h>
41//#include <stdio.h>
42#include "CbmGlobalTrack.h"
43#include "CbmRichGeoManager.h"
44#include "CbmRichHitProducer.h"
45
46//#include "TLorentzVector.h"
47#include "TGeoSphere.h"
48#include "TVirtualMC.h"
49class TGeoNode;
50class TGeoVolume;
51class TGeoShape;
52class TGeoMatrix;
53#include <sstream>
54
56 : FairTask()
57 , fRichHits(NULL)
58 , fRichRings(NULL)
59 , fRichProjections(NULL)
60 , fRichMirrorPoints(NULL)
61 , fMCTracks(NULL)
62 , fRichRingMatches(NULL)
63 , fRichPoints(NULL)
64 , fHM(NULL)
65 ,
66 //fGP(),
67 fEventNum(0)
68 , fOutputDir("")
69 , fRunTitle("")
70 , fAxisRotTitle("")
71 , fNumbAxis(0)
72 , fTile(0)
73 , fDrawAlignment(kTRUE)
74 , fCopFit(NULL)
75 , fTauFit(NULL)
76 , fPhi()
77{
78}
79
81
83{
84 FairRootManager* manager = FairRootManager::Instance();
85
86 fRichHits = (TClonesArray*) manager->GetObject("RichHit");
87 if (NULL == fRichHits) {
88 Fatal("CbmRichAlignment::Init", "No RichHit array !");
89 }
90
91 fRichRings = (TClonesArray*) manager->GetObject("RichRing");
92 if (NULL == fRichRings) {
93 Fatal("CbmRichAlignment::Init", "No RichRing array !");
94 }
95
96 fRichProjections = (TClonesArray*) manager->GetObject("RichProjection");
97 if (NULL == fRichProjections) {
98 Fatal("CbmRichAlignment::Init", "No RichProjection array !");
99 }
100
101 fRichPoints = (TClonesArray*) manager->GetObject("RichPoint");
102 if (NULL == fRichPoints) {
103 Fatal("CbmRichAlignment::Init", "No RichPoint array !");
104 }
105
106 fMCTracks = (TClonesArray*) manager->GetObject("MCTrack");
107 if (NULL == fMCTracks) {
108 Fatal("CbmRichAlignment::Init", "No MCTracks array !");
109 }
110
111 fRichRingMatches = (TClonesArray*) manager->GetObject("RichRingMatch");
112 if (NULL == fRichRingMatches) {
113 Fatal("CbmRichAlignment::Init", "No RichRingMatches array !");
114 }
115
116 fRichMirrorPoints = (TClonesArray*) manager->GetObject("RichMirrorPoint");
117 if (NULL == fRichMirrorPoints) {
118 Fatal("CbmRichAlignment::Init", "No RichMirrorPoints array !");
119 }
120
121 /* fRichRefPlanePoints = (TClonesArray*) manager->GetObject("RefPlanePoint");
122 if (NULL == fRichRefPlanePoints) { Fatal("CbmRichAlignment::Init", "No RichRefPlanePoint array !"); }
123
124 fRichMCPoints = (TClonesArray*) manager->GetObject("RichPoint");
125 if (NULL == fRichMCPoints) { Fatal("CbmRichAlignment::Init", "No RichMCPoints array !"); }
126
127 fGlobalTracks = (TClonesArray*) manager->GetObject("GlobalTrack");
128 if (NULL == fGlobalTracks) { Fatal("CbmAnaDielectronTask::Init","No GlobalTrack array!"); }
129*/
130
134
136
137 return kSUCCESS;
138}
139
141{
142 fHM = new CbmHistManager();
143
144 fHM->Create1<TH1D>("fHCenterDistance", "fHCenterDistance;Distance C-C';Nb of entries", 100, -0.1, 5.);
145 fHM->Create1<TH1D>("fHPhi", "fHPhi;Phi_Ch [rad];Nb of entries", 200, -3.4, 3.4);
146 fHM->Create1<TH1D>("fHThetaDiff", "fHThetaDiff;Th_Ch-Th_0 [cm];Nb of entries", 252, -5., 5.);
147 fHM->Create2<TH2D>("fHCherenkovHitsDistribTheta0", "fHCherenkovHitsDistribTheta0;Phi_0 [rad];Theta_0 [cm];Entries",
148 200, -2., 2., 600, 2., 8.);
149 fHM->Create2<TH2D>("fHCherenkovHitsDistribThetaCh",
150 "fHCherenkovHitsDistribThetaCh;Phi_Ch [rad];Theta_Ch [cm];Entries", 200, -3.4, 3.4, 600, 0., 20);
151 fHM->Create2<TH2D>("fHCherenkovHitsDistribReduced",
152 "fHCherenkovHitsDistribReduced;Phi_Ch [rad];Th_Ch-Th_0 [cm];Entries", 200, -3.4, 3.4, 500, -5.,
153 5.);
154}
155
156void CbmRichAlignment::Exec(Option_t* option)
157{
158 cout << endl
159 << "//"
160 "--------------------------------------------------------------------"
161 "-----------------------------------------------//"
162 << endl;
163 cout << "//------------------------------------------ CbmRichAlignment: EXEC "
164 "Function ------------------------------------------//"
165 << endl;
166 cout << "//"
167 "--------------------------------------------------------------------"
168 "--------------------------------------------------//"
169 << endl;
170 fEventNum++;
171 //LOG(debug2) << "CbmRichAlignment : Event #" << fEventNum;
172 cout << "CbmRichAlignment : Event #" << fEventNum << endl;
173
174 Int_t nofRingsInEvent = fRichRings->GetEntriesFast();
175 Int_t nofMirrorPoints = fRichMirrorPoints->GetEntriesFast();
176 Int_t nofHitsInEvent = fRichHits->GetEntriesFast();
177 Int_t NofMCTracks = fMCTracks->GetEntriesFast();
178 // Int_t NofMCPoints = fRichMCPoints->GetEntriesFast();
179 cout << "Nb of rings in evt = " << nofRingsInEvent << ", nb of mirror points = " << nofMirrorPoints
180 << ", nb of hits in evt = " << nofHitsInEvent << " and nb of Monte-Carlo tracks = " << NofMCTracks << endl
181 << endl; //", nb of Monte-Carlo points = " << NofMCPoints <<
182
183 if (nofRingsInEvent == 0) {
184 cout << "Error no rings registered in event." << endl << endl;
185 }
186 else {
188 }
189}
190
192{
193 cout << "//------------------------------ CbmRichAlignment: Calculate Angles "
194 "& Draw Distrib ------------------------------//"
195 << endl
196 << endl;
197
198 Double_t trackX = 0., trackY = 0.;
199 GetTrackPosition(trackX, trackY);
200
201 Int_t nofRingsInEvent = fRichRings->GetEntriesFast();
202 Float_t DistCenters, Theta_Ch, Theta_0, Angles_0;
203 Float_t Pi = 3.14159265;
204 Float_t TwoPi = 2. * 3.14159265;
205 fPhi.resize(kMAX_NOF_HITS);
206
207 // ------------------------- Loop to get ring center coordinates and photon hit coordinates per ring and per event ------------------------- //
208 if (nofRingsInEvent >= 1) {
209 cout << "Number of Rings in event: " << nofRingsInEvent << endl;
210 //sleep(2);
211 for (Int_t iR = 0; iR < nofRingsInEvent; iR++) {
212 // ----- Convert Ring to Ring Light ----- //
213 CbmRichRing* ring = static_cast<CbmRichRing*>(fRichRings->At(iR));
214 CbmRichRingLight ringL;
216 fCopFit->DoFit(&ringL);
217 // ----- Distance between mean center and fitted center calculation ----- //
218 DistCenters = sqrt(TMath::Power(ringL.GetCenterX() - trackX, 2) + TMath::Power(ringL.GetCenterY() - trackY, 2));
219 fHM->H1("fHCenterDistance")->Fill(DistCenters);
220 // ----- Declaration of new variables ----- //
221 Int_t NofHits = ringL.GetNofHits();
222 Float_t xRing = ringL.GetCenterX();
223 Float_t yRing = ringL.GetCenterY();
224
225 for (Int_t iH = 0; iH < NofHits; iH++) {
226 // ----- Phi angle calculation ----- //
227 Int_t HitIndex = ring->GetHit(iH);
228 CbmRichHit* hit = static_cast<CbmRichHit*>(fRichHits->At(HitIndex));
229 Float_t xHit = hit->GetX();
230 Float_t yHit = hit->GetY();
231 Angles_0 = TMath::ATan2((hit->GetX() - ringL.GetCenterX()),
232 (ringL.GetCenterY() - hit->GetY())); //* TMath::RadToDeg();
233 //cout << "Angles_0 = " << Angles_0[iH] << endl;
234
235 if (xRing - xHit == 0 || yRing - yHit == 0) continue;
236 fPhi[iH] = TMath::ATan2(yHit - yRing, xHit - xRing);
237 fHM->H1("fHPhi")->Fill(fPhi[iH]);
238
239 // ----- Theta_Ch and Theta_0 calculations ----- //
240 Theta_Ch = sqrt(TMath::Power(trackX - hit->GetX(), 2) + TMath::Power(trackY - hit->GetY(), 2));
241 Theta_0 =
242 sqrt(TMath::Power(ringL.GetCenterX() - hit->GetX(), 2) + TMath::Power(ringL.GetCenterY() - hit->GetY(), 2));
243 //cout << "Theta_0 = " << Theta_0 << endl;
244 fHM->H1("fHThetaDiff")->Fill(Theta_Ch - Theta_0);
245
246 // ----- Filling of final histograms ----- //
247 fHM->H2("fHCherenkovHitsDistribTheta0")->Fill(Angles_0, Theta_0);
248 fHM->H2("fHCherenkovHitsDistribThetaCh")->Fill(fPhi[iH], Theta_Ch);
249 fHM->H2("fHCherenkovHitsDistribReduced")->Fill(fPhi[iH], (Theta_Ch - Theta_0));
250 }
251 //cout << endl;
252 }
253 }
254}
255
256void CbmRichAlignment::GetTrackPosition(Double_t& x, Double_t& y)
257{
258 Int_t NofProjections = fRichProjections->GetEntriesFast();
259 //cout << "!!! NB PROJECTIONS !!! " << NofProjections << endl;
260 for (Int_t iP = 0; iP < NofProjections; iP++) {
261 FairTrackParam* pr = (FairTrackParam*) fRichProjections->At(iP);
262 if (NULL == pr) {
263 x = 0.;
264 y = 0.;
265 cout << "Error: CbmRichAlignment::GetTrackPosition. No fair track param "
266 "found."
267 << endl;
268 }
269 x = pr->GetX();
270 y = pr->GetY();
271 //cout << "Center X: " << *x << " and Center y: " << *y << endl;
272 }
273}
274
276{
277 TCanvas* c1 = new TCanvas(fRunTitle + "_Data_Histograms_" + fAxisRotTitle,
278 fRunTitle + "_Data_Histograms_" + fAxisRotTitle, 800, 400);
279 c1->Divide(2, 1);
280 c1->cd(1);
281 /*c1->SetGridx(1);
282 c1->SetGridy(1);
283 fHM2->H1("fHCenterDistance")->GetXaxis()->SetLabelSize(0.03);
284 fHM2->H1("fHCenterDistance")->GetXaxis()->SetTitleSize(0.03);
285 fHM2->H1("fHCenterDistance")->GetXaxis()->CenterTitle();
286 fHM2->H1("fHCenterDistance")->GetXaxis()->SetNdivisions(612,kTRUE);
287 fHM2->H1("fHCenterDistance")->GetYaxis()->CenterTitle();
288 fHM2->H1("fHCenterDistance")->GetYaxis()->SetTitleSize(0.03);
289 fHM2->H1("fHCenterDistance")->GetYaxis()->SetTitleOffset(1.);
290 fHM2->H1("fHCenterDistance")->Draw();*/
291 DrawH1(fHM->H1("fHCenterDistance"));
292 c1->cd(2);
293 DrawH2(fHM->H2("fHCherenkovHitsDistribReduced"));
294 /* c1->cd(3);
295 DrawH1(fHM->H1("fHThetaDiff"));
296 c1->cd(4);
297 DrawH2(fHM->H2("fHCherenkovHitsDistribTheta0"));
298 c1->cd(5);
299 DrawH1(fHM->H1("fHPhi"));
300 c1->cd(6);
301 DrawH2(fHM->H2("fHCherenkovHitsDistribThetaCh"));
302*/
303 Cbm::SaveCanvasAsImage(c1, string(fOutputDir.Data()), "png");
304}
305
306void CbmRichAlignment::DrawFit(vector<Double_t>& outputFit, Int_t thresh)
307{
308 //vector<Double_t> paramVect;
309 //paramVect.reserve(5);
310
311 TCanvas* c3 = new TCanvas(fRunTitle + "_Fit_Histograms_" + fAxisRotTitle,
312 fRunTitle + "_Fit_Histograms_" + fAxisRotTitle, 1100, 600);
313 c3->SetFillColor(42);
314 c3->Divide(4, 2);
315 gPad->SetTopMargin(0.1);
316 gPad->SetFillColor(33);
317 c3->cd(1);
318 // TH2D* CloneArr = (TH2D*)fHM2->H2("fHCherenkovHitsDistribThetaCh")->Clone();
319 TH2D* CloneArr = (TH2D*) fHM->H2("fHCherenkovHitsDistribReduced")->Clone();
320 CloneArr->GetXaxis()->SetLabelSize(0.03);
321 CloneArr->GetXaxis()->SetTitleSize(0.03);
322 CloneArr->GetXaxis()->CenterTitle();
323 CloneArr->GetXaxis()->SetNdivisions(612, kTRUE);
324 CloneArr->GetYaxis()->SetLabelSize(0.03);
325 CloneArr->GetYaxis()->SetTitleSize(0.03);
326 CloneArr->GetYaxis()->SetNdivisions(612, kTRUE);
327 CloneArr->GetYaxis()->CenterTitle();
328 //CloneArr->GetYaxis()->SetRangeUser(-2.5,2.5);
329 CloneArr->GetZaxis()->SetLabelSize(0.03);
330 CloneArr->GetZaxis()->SetTitleSize(0.03);
331 CloneArr->GetYaxis()->SetTitleOffset(1.0);
332 CloneArr->Draw("colz");
333 //Double_t ymax = CloneArr->GetYaxis()->GetXmax();
334 //Double_t ymin = CloneArr->GetYaxis()->GetXmin();
335 //TF1 *fgauss = TF1 fgauss("gauss", "[0]*exp(-0.5*((x-[1])/[2])**2)", 0, 100);
336
337 // ------------------------------ APPLY THRESHOLD TO 2D-HISTO ------------------------------ //
338 // TH2D* CloneArr_2 = (TH2D*)fHM2->H2("fHCherenkovHitsDistribThetaCh")->Clone();
339 TH2D* CloneArr_2 = (TH2D*) fHM->H2("fHCherenkovHitsDistribReduced")->Clone();
340 for (Int_t y_bin = 1; y_bin <= 500; y_bin++) {
341 for (Int_t x_bin = 1; x_bin <= 200; x_bin++) {
342 /*if (CloneArr_2->GetBinContent(x_bin, y_bin)!=0) {
343 cout << "Bin Content: " << CloneArr_2->GetBinContent(x_bin, y_bin) << endl;
344 sleep(1);
345 }
346 else;*/
347 if (CloneArr_2->GetBinContent(x_bin, y_bin) < thresh) {
348 CloneArr_2->SetBinContent(x_bin, y_bin, 0);
349 }
350 }
351 }
352 c3->cd(2);
353 CloneArr_2->GetXaxis()->SetLabelSize(0.03);
354 CloneArr_2->GetXaxis()->SetTitleSize(0.03);
355 CloneArr_2->GetXaxis()->CenterTitle();
356 CloneArr_2->GetXaxis()->SetNdivisions(612, kTRUE);
357 CloneArr_2->GetYaxis()->SetLabelSize(0.03);
358 CloneArr_2->GetYaxis()->SetTitleSize(0.03);
359 CloneArr_2->GetYaxis()->SetNdivisions(612, kTRUE);
360 CloneArr_2->GetYaxis()->CenterTitle();
361 //CloneArr_2->GetYaxis()->SetRangeUser(-2.5,2.5);
362 CloneArr_2->GetZaxis()->SetLabelSize(0.03);
363 CloneArr_2->GetZaxis()->SetTitleSize(0.03);
364 CloneArr_2->GetYaxis()->SetTitleOffset(1.0);
365 CloneArr_2->Draw("colz");
366 CloneArr_2->Write();
367
368 // -------------------- FIT SLICES AND FIT THE MEAN OF THE RESULT TO A SIN FUNCTION -------------------- //
369 CloneArr_2->FitSlicesY(0, 0, -1, 1);
370 c3->cd(3);
371 TH1D* histo_0 = gDirectory->Get<TH1D>("fHCherenkovHitsDistribReduced_0");
372 histo_0->Draw();
373 c3->cd(4);
374 TH1D* histo_1 = gDirectory->Get<TH1D>("fHCherenkovHitsDistribReduced_1");
375 //histo_1->GetYaxis()->SetRangeUser(-2.5, 2.5);
376 histo_1->Draw();
377 c3->cd(5);
378 TH1D* histo_2 = gDirectory->Get<TH1D>("fHCherenkovHitsDistribReduced_2");
379 histo_2->Draw();
380 c3->cd(6);
381 TH1D* histo_chi2 = gDirectory->Get<TH1D>("fHCherenkovHitsDistribReduced_chi2");
382 histo_chi2->Draw();
383
384 c3->cd(7);
385 TF1* f1 = new TF1("f1", "[2]+[0]*cos(x)+[1]*sin(x)", -3.5, 3.5);
386 f1->SetParameters(0, 0, 0);
387 f1->SetParNames("Delta_phi", "Delta_lambda", "Offset");
388 histo_1->Fit("f1", "", "");
389 TF1* fit = histo_1->GetFunction("f1");
390 Double_t p1 = fit->GetParameter("Delta_phi");
391 Double_t p2 = fit->GetParameter("Delta_lambda");
392 Double_t p3 = fit->GetParameter("Offset");
393 Double_t chi2 = fit->GetChisquare();
394 //cout << setprecision(6) << "Delta_phi = " << fit->GetParameter(0) << " and delta_lambda = " << fit->GetParameter(1) << endl;
395 //cout << "Delta_phi error = " << fit->GetParError(0) << " and delta_lambda error = " << fit->GetParError(1) << endl;
396 //cout << endl << "Chi2: " << chi2 << endl;
397
398 /* paramVect.push_back(fit->GetParameter("Delta_phi"));
399 paramVect.push_back(fit->GetParameter("Delta_lambda"));
400 paramVect.push_back(fit->GetParameter("Offset"));
401 paramVect.push_back(fit->GetChisquare());
402 //cout << "Vectors: Delta_phi = " << paramVect[0] << ", Delta_lambda = " << paramVect[1] << ", Offset = " << paramVect[2] << endl;
403*/
404 f1->SetParameters(fit->GetParameter(0), fit->GetParameter(1));
405 char leg[128];
406 f1->SetLineColor(2);
407 f1->Draw();
408 f1->Write();
409
410 // ------------------------------ CALCULATION OF MISALIGNMENT ANGLE ------------------------------ //
411 Double_t Focal_length = 150., q = 0., A = 0., Alpha = 0., mis_x = 0., mis_y = 0.;
412 // mis_x && mis_y corresponds respect. to rotation angles around the Y and X axes.
413 // !!! BEWARE: AXES INDEXES ARE SWITCHED !!!
414 q = TMath::ATan(fit->GetParameter(0) / fit->GetParameter(1));
415 cout << endl << "fit_1 = " << fit->GetParameter(0) << " and fit_2 = " << fit->GetParameter(1) << endl;
416 //cout << "q = " << q << endl;
417 A = fit->GetParameter(1) / TMath::Cos(q);
418 //cout << "Parameter a = " << A << endl;
419 Alpha =
420 TMath::ATan(A / 1.5) * 0.5
421 * TMath::Power(
422 10,
423 3); // *0.5, because a mirror rotation of alpha implies a rotation in the particle trajectory of 2*alpha ; 1.5 meters = Focal length = Radius_of_curvature/2
424 //cout << setprecision(6) << "Total angle of misalignment alpha = " << Alpha << endl; // setprecision(#) gives the number of digits in the cout.
425 mis_x = TMath::ATan(fit->GetParameter(0) / Focal_length) * 0.5 * TMath::Power(10, 3);
426 mis_y = TMath::ATan(fit->GetParameter(1) / Focal_length) * 0.5 * TMath::Power(10, 3);
427 //cout << "Horizontal displacement = " << outputFit[0] << " [mrad] and vertical displacement = " << outputFit[1] << " [mrad]." << endl;
428
429 TLegend* LEG = new TLegend(0.27, 0.7, 0.85, 0.87); // Set legend position
430 LEG->SetBorderSize(1);
431 LEG->SetFillColor(0);
432 LEG->SetMargin(0.2);
433 LEG->SetTextSize(0.03);
434 sprintf(leg, "Fitted sinusoid");
435 LEG->AddEntry(f1, leg, "l");
436 sprintf(leg, "Rotation angle around X = %f", mis_y);
437 LEG->AddEntry("", leg, "l");
438 sprintf(leg, "Rotation angle around Y = %f", mis_x);
439 LEG->AddEntry("", leg, "l");
440 sprintf(leg, "Offset = %f", fit->GetParameter(2));
441 LEG->AddEntry("", leg, "l");
442 LEG->Draw();
443 //Cbm::SaveCanvasAsImage(c3, string(fOutputDir.Data()), "png");
444
445 TCanvas* c4 =
446 new TCanvas(fRunTitle + "_Sinus_Fit_" + fAxisRotTitle, fRunTitle + "_Sinus_Fit_" + fAxisRotTitle, 400, 400);
447 c4->SetGrid(1, 1);
448 CloneArr_2->Draw("colz");
449 f1->Draw("same");
450 TLegend* LEG1 = new TLegend(0.35, 0.7, 0.72, 0.85); // Set legend position
451 LEG1->SetBorderSize(1);
452 LEG1->SetFillColor(0);
453 LEG1->SetMargin(0.2);
454 LEG1->SetTextSize(0.03);
455 sprintf(leg, "Fitted sinusoid");
456 LEG1->AddEntry(f1, leg, "l");
457 sprintf(leg, "Misalign in X = %f", mis_x);
458 LEG1->AddEntry("", leg, "l");
459 sprintf(leg, "Misalign in Y = %f", mis_y);
460 LEG1->AddEntry("", leg, "l");
461 sprintf(leg, "Offset = %f", fit->GetParameter(2));
462 LEG1->AddEntry("", leg, "l");
463 LEG1->Draw();
464 Cbm::SaveCanvasAsImage(c4, string(fOutputDir.Data()), "png");
465
466 // ------------------------------ APPLY SECOND FIT USING LOG-LIKELIHOOD METHOD ------------------------------ //
467 /* TCanvas* c4 = new TCanvas(fRunTitle + "_Second_Fit_" + fAxisRotTitle, fRunTitle + "_Second_Fit_" + fAxisRotTitle, 600, 600);
468 c4->SetFillColor(42);
469 gPad->SetTopMargin(0.1);
470 gPad->SetFillColor(33);
471 f1->SetParameters(fit->GetParameter(0), fit->GetParameter(1), fit->GetParameter(2));
472 histo_1->Fit("f1","L","");
473 TF1 *fit2 = histo_1->GetFunction("f1");
474 f1->SetParameters(fit2->GetParameter(0), fit2->GetParameter(1), fit2->GetParameter(2));
475 f1->Draw();
476
477 Double_t q_2 = TMath::ATan(fit2->GetParameter(0)/fit2->GetParameter(1));
478 //cout << endl << "fit2_1 = " << fit2->GetParameter(0) << " and fit2_2 = " << fit2->GetParameter(1) << endl;
479 //cout << "q_2 = " << q_2 << endl;
480 Double_t A_2 = fit2->GetParameter(1)/TMath::Cos(q_2);
481 //cout << "Parameter a_2 = " << A_2 << endl;
482 Double_t Alpha_2 = TMath::ATan(A_2/1.5)*0.5*TMath::Power(10,3);
483 //cout << setprecision(6) << "Total angle of misalignment alpha_2 = " << Alpha_2 << endl;
484 Double_t mis_x_2 = TMath::ATan(fit2->GetParameter(0)/Focal_length)*0.5*TMath::Power(10,3);
485 Double_t mis_y_2 = TMath::ATan(fit2->GetParameter(1)/Focal_length)*0.5*TMath::Power(10,3);
486
487 TLegend* LEG2= new TLegend(0.31,0.7,0.72,0.85); // Set legend position
488 LEG2->SetBorderSize(1);
489 LEG2->SetFillColor(0);
490 LEG2->SetMargin(0.2);
491 LEG2->SetTextSize(0.03);
492 sprintf(leg, "Fitted sinusoid");
493 LEG2->AddEntry(f1, leg, "l");
494 sprintf(leg, "Misalign in X = %f", mis_x_2);
495 LEG2->AddEntry("", leg, "l");
496 sprintf(leg, "Misalign in Y = %f", mis_y_2);
497 LEG2->AddEntry("", leg, "l");
498 sprintf(leg, "Offset = %f", fit2->GetParameter(2));
499 LEG2->AddEntry("", leg, "l");
500 LEG2->Draw();
501 Cbm::SaveCanvasAsImage(c4, string(fOutputDir.Data()), "png");*/
502
503 outputFit.at(0) = mis_y;
504 outputFit.at(1) = mis_x;
505 outputFit.at(2) = fit->GetParameter(1);
506 outputFit.at(3) = fit->GetParameter(0);
507}
508
510{
512 TFile* oldFile = gFile;
513 TDirectory* oldDir = gDirectory;
514
515 fHM = new CbmHistManager();
516 TFile* file = new TFile(fileName, "READ");
517 LOG_IF(fatal, !file) << "Could not open file " << fileName;
518
519 fHM->ReadFromFile(file);
521
523 gFile = oldFile;
524 gDirectory = oldDir;
525}
526
528{
529 cout << endl
530 << "// "
531 "-----------------------------------------------------------------------"
532 "----------------------------------------------------------------- //"
533 << endl;
534 cout << "// -------------------------------------------------- CbmRichAlignment "
535 "- Finish Function -------------------------------------------------- //"
536 << endl;
537 cout << "// "
538 "-----------------------------------------------------------------------"
539 "----------------------------------------------------------------- //"
540 << endl
541 << endl;
542
543 if (fDrawAlignment) {
545 Int_t thresh = 5;
546 vector<Double_t> outputFit(4);
547 DrawFit(outputFit, thresh);
548 cout << setprecision(6) << endl;
549 cout << "Horizontal displacement = " << outputFit[0] << " [mrad] and vertical displacement = " << outputFit[1]
550 << " [mrad]." << endl;
551
552 fHM->Create2<TH2D>("fHCherenkovHitsDistribReduced",
553 "fHCherenkovHitsDistribReduced;Phi_Ch [rad];Th_Ch-Th_0 [cm];Entries", 200, -3.4, 3.4, 500, -5.,
554 5.);
555
556 ofstream corr_file;
557 /* // Converting double to string.
558 TString s;
559 std::ostringstream strs;
560 strs << fNumb;
561 std::string str = strs.str();
562 s = "/data/misalignment_correction/Sim_Outputs/Alignment_Correction/correction_param" + str + ".txt";
563*/
564 TString s = fOutputDir + "correction_param_" + fNumbAxis + fTile + ".txt";
565 corr_file.open(s);
566 if (corr_file.is_open()) {
567 corr_file << setprecision(7) << outputFit[0] << "\t";
568 corr_file << setprecision(7) << outputFit[1] << "\t";
569 corr_file << setprecision(7) << outputFit[2] << "\t";
570 corr_file << setprecision(7) << outputFit[3] << "\t";
571 corr_file.close();
572 cout << "Wrote correction parameters to: " << s << endl;
573 }
574 else {
575 cout << "Error in CbmRichAlignment::Finish ; unable to open parameter file!" << endl;
576 }
577 }
578
579 //cout << setprecision(6) << endl;
580}
ClassImp(CbmConverterManager)
void DrawH1(TH1 *hist, HistScale logx, HistScale logy, const string &drawOpt, Int_t color, Int_t lineWidth, Int_t lineStyle, Int_t markerSize, Int_t markerStyle)
void DrawH2(TH2 *hist, HistScale logx, HistScale logy, HistScale logz, const string &drawOpt)
Helper functions for drawing 1D and 2D histograms and graphs.
Convert internal data classes to cbmroot common data classes.
Class for producing RICH hits directly from MCPoints.
Here the ring is fitted with the COP algorithm from A. Ayriyan/G. Ososkov.
Here the ring is fitted with Taubin algorithm from A. Ayriyan, G. Ososkov, N. Chernov.
friend fvec sqrt(const fvec &a)
Histogram manager.
TH2 * H2(const std::string &name) const
Return pointer to TH2 histogram.
void Create2(const std::string &name, const std::string &title, Int_t nofBinsX, Double_t minBinX, Double_t maxBinX, Int_t nofBinsY, Double_t minBinY, Double_t maxBinY)
Helper function for creation of 2-dimensional histograms and profiles. Template argument is a real ob...
void ReadFromFile(TFile *file)
Read histograms from file.
void Create1(const std::string &name, const std::string &title, Int_t nofBins, Double_t minBin, Double_t maxBin)
Helper function for creation of 1-dimensional histograms and profiles. Template argument is a real ob...
TH1 * H1(const std::string &name) const
Return pointer to TH1 histogram.
double GetY() const
Definition CbmPixelHit.h:74
double GetX() const
Definition CbmPixelHit.h:73
TClonesArray * fMCTracks
CbmRichRingFitterCOP * fCopFit
void GetTrackPosition(Double_t &x, Double_t &y)
void DrawHistFromFile(TString fileName)
virtual void Finish()
Inherited from FairTask.
CbmHistManager * fHM
void DrawFit(vector< Double_t > &outputFit, Int_t thresh)
TClonesArray * fRichHits
vector< Float_t > fPhi
TClonesArray * fRichRings
TClonesArray * fRichPoints
TClonesArray * fRichMirrorPoints
virtual void Exec(Option_t *option)
Inherited from FairTask.
TClonesArray * fRichProjections
static const int kMAX_NOF_HITS
CbmRichRingFitterEllipseTau * fTauFit
TClonesArray * fRichRingMatches
virtual InitStatus Init()
Inherited from FairTask.
static void Init()
Initialize array of RICH hits.
static void CopyHitsToRingLight(const CbmRichRing *ring1, CbmRichRingLight *ring2)
Copy hits from CbmRichRing to CbmRichRingLight.
Here the ring is fitted with the COP algorithm from A. Ayriyan/G. Ososkov.
virtual void DoFit(CbmRichRingLight *ring)
Inherited from CbmRichRingFitterBase.
Here the ring is fitted with Taubin algorithm from A. Ayriyan, G. Ososkov, N. Chernov.
float GetCenterX() const
float GetCenterY() const
int GetNofHits() const
Return number of hits in ring.
uint32_t GetHit(int32_t i) const
Definition CbmRichRing.h:39
void SaveCanvasAsImage(TCanvas *c, const string &dir, const string &option)
Definition CbmUtils.cxx:36