BmnRoot
Loading...
Searching...
No Matches
BmnTOF1Detector.cxx
Go to the documentation of this file.
1#include "BmnTOF1Detector.h"
2
3#include <iomanip>
4
6
7BmnTOF1Detector::BmnTOF1Detector(Int_t tofId, Int_t NPlane, Int_t fill_hist = 0, Int_t Verbose = 0)
8{
9 // cout << "BmnTOF1Detector::BmnTOF1Detector tofId = " << tofId << "; NPlane = " << NPlane << endl;
10 fTofId = (DetectorId)tofId;
11 fVerbose = Verbose;
12 memset(fKilled, 0, sizeof(fKilled));
13 memset(fCorrLR, 0, sizeof(fCorrLR));
14 memset(fCorrTimeShift, 0, sizeof(fCorrTimeShift));
15 fKillSide = -1;
16 fNEvents = 0;
17 // KillStrip(0);
18 // KillStrip(47);
19 fFillHist = fill_hist;
20 fNPlane = NPlane;
21 fNStr = fNStrMax;
22 fStripLength = 30; // cm
23 fSignalVelosity = 0.06; // 0.06 ns/cm
24 if (fNPlane >= 41) {
25 fStripLength = 56;
26 fSignalVelosity = 0.0585;
27 }
28 fMaxDelta = (fStripLength * 0.5 + 3.0) * fSignalVelosity; // + 20 mm on the strip edge
29 fCommonTimeShift = 0;
30
31 for (Int_t i = 0; i < fNStrMax; i++) {
32 fSignalVelosityStr[i] = fSignalVelosity;
33 gSlew[i] = NULL;
34 funT0[i] = NULL;
35 funRPC[i] = NULL;
36 }
37
38 if (fTofId == kTOF1)
39 fName = Form("TOF400_Plane_%d", NPlane);
40 if (fTofId == kTOF701)
41 fName = Form("TOF700_Plane_%d", NPlane);
42 TString Name;
43
44 if (fFillHist > 0) {
45 fHistListStat = new TList();
46 fHistListdt = new TList();
47
48 Name.Clear();
49 Name = Form("Hist_HitByCh_%s", fName.Data());
50 hHitByCh = new TH1I(Name, Name, fNStrMax + 1, -0.5, fNStrMax + 0.5);
51 fHistListStat->Add(hHitByCh);
52
53 Name.Clear();
54 Name = Form("Hist_HitPerEv_%s", fName.Data());
55 hHitPerEv = new TH1I(Name, Name, fNStrMax + 1, -0.5, fNStrMax + 0.5);
56 fHistListStat->Add(hHitPerEv);
57
58 Name.Clear();
59 Name = Form("Hist_HitLR_%s", fName.Data());
60 hHitLR = new TH2I(Name, Name, fNStrMax, 0, fNStrMax, fNStrMax, 0, fNStrMax);
61 fHistListStat->Add(hHitLR);
62
63 Name.Clear();
64 Name = Form("Hist_XY_%s", fName.Data());
65 hXY = new TH2I(Name, Name, 400, -250, 250, 120, -75, 75);
66 fHistListStat->Add(hXY);
67
68 hDy_near = new TH1S(Form("hDy_near_%s", fName.Data()), Form("hDy_near_%s", fName.Data()), 400, -20, 20);
69 hDtime_near =
70 new TH1S(Form("hDtime_near_%s", fName.Data()), Form("hDtime_near_%s", fName.Data()), 400, -10, 10);
71 hDWidth_near =
72 new TH1S(Form("hDWidth_near_%s", fName.Data()), Form("hDWidth_near_%s", fName.Data()), 256, -28., 28.);
73 hTempDtimeDy_near = new TH2S(Form("hTempDtimeDy_near_%s", fName.Data()),
74 Form("hTempDtimeDy_near_%s", fName.Data()), 400, -10, 10, 200, -10, 10);
75 hDy_acros = new TH1S(Form("hDy_acros_%s", fName.Data()), Form("hDy_acros_%s", fName.Data()), 400, -20, 20);
76 hDtime_acros =
77 new TH1S(Form("hDtime_acros_%s", fName.Data()), Form("hDtime_acros_%s", fName.Data()), 400, -10, 10);
78 hDWidth_acros =
79 new TH1S(Form("hDWidth_acros_%s", fName.Data()), Form("hDWidth_acros_%s", fName.Data()), 256, -28., 28.);
80 hTempDtimeDy_acros = new TH2S(Form("hTempDtimeDy_acros_%s", fName.Data()),
81 Form("hTempDtimeDy_acros_%s", fName.Data()), 400, -10, 10, 200, -10, 10);
82 fHistListStat->Add(hDy_near);
83 fHistListStat->Add(hDtime_near);
84 fHistListStat->Add(hDWidth_near);
85 fHistListStat->Add(hTempDtimeDy_near);
86 fHistListStat->Add(hDy_acros);
87 fHistListStat->Add(hDtime_acros);
88 fHistListStat->Add(hDWidth_acros);
89 fHistListStat->Add(hTempDtimeDy_acros);
90
91 for (Int_t i = 0; i < fNStrMax + 1; i++) {
92 hdT_vs_WidthDet[i] =
93 new TH2S(Form("dt_vs_WidthDet_str_%d_%s", i, fName.Data()),
94 Form("dt_vs_WidthDet_str_%d_%s", i, fName.Data()), 1024, 0, 50, 1024, -12, 12);
95 fHistListdt->Add(hdT_vs_WidthDet[i]);
96 }
97 for (Int_t i = 0; i < fNStrMax + 1; i++) {
98 hdT_vs_WidthT0[i] = new TH2S(Form("dt_vs_WidthT0_str_%d_%s", i, fName.Data()),
99 Form("dt_vs_WidthT0_str_%d_%s", i, fName.Data()), 1024, 0, 50, 1024, -12, 12);
100 fHistListdt->Add(hdT_vs_WidthT0[i]);
101 }
102 for (Int_t i = 0; i < fNStrMax + 1; i++) {
103 hdT[i] =
104 new TH1I(Form("dt_str_%d_%s", i, fName.Data()), Form("dt_str_%d_%s", i, fName.Data()), 1024, -12, 12);
105 fHistListdt->Add(hdT[i]);
106 }
107
108 } else {
109
110 hHitByCh = NULL;
111 hHitPerEv = NULL;
112 hHitLR = NULL;
113 hXY = NULL;
114
115 hDy_near = NULL;
116 hDtime_near = NULL;
117 hDWidth_near = NULL;
118 hTempDtimeDy_near = NULL;
119 hDy_acros = NULL;
120 hDtime_acros = NULL;
121 hDWidth_acros = NULL;
122 hTempDtimeDy_acros = NULL;
123
124 for (Int_t i = 0; i < fNStrMax + 1; i++) {
125 hdT_vs_WidthDet[i] = NULL;
126 hdT_vs_WidthT0[i] = NULL;
127 hdT[i] = NULL;
128 }
129 }
130 Clear();
131}
132
133//----------------------------------------------------------------------------------------
134
136{
137 memset(fTimeL, 0, sizeof(fTimeL));
138 memset(fTimeR, 0, sizeof(fTimeR));
139 memset(fTimeLtemp, 0, sizeof(fTimeLtemp));
140 memset(fTimeRtemp, 0, sizeof(fTimeRtemp));
141 memset(fTime, 0, sizeof(fTime));
142 memset(fWidthL, 0, sizeof(fWidthL));
143 memset(fWidthR, 0, sizeof(fWidthR));
144 memset(fWidthLtemp, 0, sizeof(fWidthLtemp));
145 memset(fWidthRtemp, 0, sizeof(fWidthRtemp));
146 memset(fWidth, 0, sizeof(fWidth));
147 memset(fFlagHit, 0, sizeof(fFlagHit));
148 memset(fTof, 0, sizeof(fTof));
149 memset(fDigitL, 0, sizeof(fDigitL));
150 memset(fDigitR, 0, sizeof(fDigitR));
151 memset(fHit, 0, sizeof(fHit));
152 memset(fIndexL, 0, sizeof(fIndexL));
153 memset(fIndexR, 0, sizeof(fIndexR));
154 fHit_Per_Ev = 0;
155
156 vHitsL.clear();
157 vHitsL.reserve(fNStrMax);
158 vHitsL.resize(fNStrMax);
159
160 vHitsR.clear();
161 vHitsR.reserve(fNStrMax);
162 vHitsR.resize(fNStrMax);
163
164 for (Int_t i = 0; i < fNStrMax; i++) {
165 fCrossPoint[i].SetXYZ(0., 0., 0.);
166 fIndexLtemp[i] = -1;
167 fIndexRtemp[i] = -1;
168 }
169}
170
171//----------------------------------------------------------------------------------------
172
173Bool_t BmnTOF1Detector::SetDigitNew(BmnTof1Digit* TofDigit, Int_t ind)
174{
175 fStrip = TofDigit->GetStrip();
176
177 if (fStrip < 0 || fStrip > fNStr || fKilled[fStrip])
178 return kFALSE;
179
180 if (fVerbose > 3)
181 cout << endl
182 << " Plane = " << TofDigit->GetPlane() << "; Strip " << TofDigit->GetStrip() << "; Side "
183 << TofDigit->GetSide() << "; Time " << TofDigit->GetTime() << "; Amp " << TofDigit->GetAmplitude() << endl;
184
185 if (TofDigit->GetSide() == 0 && fKillSide != 0)
186 fTimeLtemp[fStrip] = TofDigit->GetTime() - 2. * fCorrLR[fStrip];
187 else if (TofDigit->GetSide() == 1 && fKillSide != 1)
188 fTimeLtemp[fStrip] = TofDigit->GetTime();
189 else
190 return kFALSE;
191
192 if (fVerbose > 3)
193 cout << "Setting Shift: strip # " << fStrip << " shift val " << fCorrLR[fStrip] << "; shifted timeL "
194 << fTimeLtemp[fStrip] << "\n";
195
196 fWidthLtemp[fStrip] = TofDigit->GetAmplitude();
197
198 fIndexLtemp[fStrip] = ind;
199
200 std::vector<Double_t> tempVector;
201 tempVector.reserve(3);
202 tempVector.push_back(fTimeLtemp[fStrip]);
203 tempVector.push_back(fWidthLtemp[fStrip]);
204 tempVector.push_back(ind);
205
206 if (TofDigit->GetSide() == 0) {
207 vHitsL.at(fStrip).push_back(tempVector);
208 fDigitL[fStrip]++;
209
210 if (fKillSide == 1)
211 vHitsR.at(fStrip).push_back(tempVector);
212
213 return kTRUE;
214 } else {
215 vHitsR.at(fStrip).push_back(tempVector);
216 fDigitR[fStrip]++;
217
218 if (fKillSide == 0)
219 vHitsL.at(fStrip).push_back(tempVector);
220
221 return kTRUE;
222 }
223
224 return kFALSE;
225}
226
227//----------------------------------------------------------------------------------------
228
229void BmnTOF1Detector::KillStrip(Int_t NumberOfStrip)
230{
231 fKilled[NumberOfStrip] = kTRUE;
232}
233
234//----------------------------------------------------------------------------------------
235
236void BmnTOF1Detector::KillSide(Int_t NumberOfSide)
237{
238 fKillSide = NumberOfSide;
239}
240
241//----------------------------------------------------------------------------------------
242
243Int_t BmnTOF1Detector::FindHitsNew(BmnTrigDigit* T0, TClonesArray* TofHit, int printnow)
244{
245 fT0 = T0;
246 if (fT0 == NULL)
247 fT0 = new BmnTrigDigit(-1, 0, 20, -1);
248
249 fNEvents++;
250
251 if (printnow != 0)
252 cout << endl << " Plane " << fNPlane << endl;
253 for (Int_t i = 0; i < fNStr; i++) {
254 if (vHitsL[i].empty() || vHitsR[i].empty())
255 continue;
256 if (printnow != 0)
257 cout << " Strip " << i << endl;
258
259 for (Int_t iL = 0; iL < (int)vHitsL.at(i).size(); iL++)
260 for (Int_t iR = 0; iR < (int)vHitsR.at(i).size(); iR++) {
261
262 fTimeL[i] = vHitsL.at(i).at(iL).at(0);
263 fTimeR[i] = vHitsR.at(i).at(iR).at(0);
264
265 fWidthL[i] = vHitsL.at(i).at(iL).at(1);
266 fWidthR[i] = vHitsR.at(i).at(iR).at(1);
267
268 fIndexL[i] = vHitsL.at(i).at(iL).at(2);
269 fIndexR[i] = vHitsR.at(i).at(iR).at(2);
270
271 if (printnow != 0) {
272 cout << "iL = " << iL << ": time = " << fTimeL[i] << "; amp = " << fWidthL[i]
273 << "; ind = " << fIndexL[i] << endl;
274 cout << "iR = " << iR << ": time = " << fTimeR[i] << "; amp = " << fWidthR[i]
275 << "; ind = " << fIndexR[i] << endl;
276 }
277 if (!GetCrossPoint(i, fTimeL[i], fTimeR[i]))
278 continue;
279
280 fWidth[i] = fWidthL[i] + fWidthR[i];
281 fTime[i] = (fTimeL[i] + fTimeR[i]) * 0.5;
282 fTof[i] = CalculateDt(i);
283
284 fHit_Per_Ev++;
285
286 if (fVerbose > 2 || printnow != 0)
287 printf("Hit on Plane#%d Strip#%d\n\tTime = %.3f; (X,Y,Z) = %.3f, %.3f, %.3f\n", fNPlane, i,
288 fTof[i], fCrossPoint[i].X(), fCrossPoint[i].Y(), fCrossPoint[i].Z());
289 if (fFillHist > 0) {
290 hdT_vs_WidthDet[i]->Fill(fWidth[i], fTof[i]);
291 hdT_vs_WidthT0[i]->Fill(fT0->GetAmp(), fTof[i]);
292 hdT[i]->Fill(fTof[i]);
293 hdT_vs_WidthDet[fNStr]->Fill(fWidth[i], fTof[i]);
294 hdT_vs_WidthT0[fNStr]->Fill(fT0->GetAmp(), fTof[i]);
295 hdT[fNStr]->Fill(fTof[i]);
296 if (i > 2)
297 if (fFlagHit[i - 1] == kTRUE) {
298 hDy_near->Fill(fCrossPoint[i].Y() - fCrossPoint[i - 1].Y());
299 hDtime_near->Fill(fTof[i] - fTof[i - 1]);
300 hDWidth_near->Fill(fWidth[i] - fWidth[i - 1]);
301 hTempDtimeDy_near->Fill(fTof[i] - fTof[i - 1], fCrossPoint[i].Y() - fCrossPoint[i - 1].Y());
302 }
303 if (i > 3)
304 if (fFlagHit[i - 2] == kTRUE) {
305 hDy_acros->Fill(fCrossPoint[i].Y() - fCrossPoint[i - 2].Y());
306 hDtime_acros->Fill(fTof[i] - fTof[i - 2]);
307 hDWidth_acros->Fill(fWidth[i] - fWidth[i - 2]);
308 hTempDtimeDy_acros->Fill(fTof[i] - fTof[i - 2],
309 fCrossPoint[i].Y() - fCrossPoint[i - 2].Y());
310 }
311 }
312 TString Name = TofHit->GetClass()->GetName();
313 if (Name == "BmnTofHit") {
314 // cout << " Fill BmnTofHit" << endl;
315 AddHit(i, TofHit);
316 } else if (Name == "BmnTOF1Conteiner") {
317 // cout << " Fill BmnTOF1Conteiner" << endl;
318 AddConteiner(i, TofHit);
319 }
320 } // end loop over Left/Right sides of the strip
321 } // end loop over strips for (Int_t i = 0; i < fNStrMax; i++)
322
323 if (printnow != 0)
324 getchar();
325 if (fFillHist > 0)
326 FillHist();
327
328 if (fVerbose > 2)
329 printf("Total number of hits on Plane#%d is %d\n\n", fNPlane, fHit_Per_Ev);
330 return fHit_Per_Ev;
331}
332
333//------------------------------------------------------------------------------------------------------------------------
334
335void BmnTOF1Detector::AddHit(Int_t Str, TClonesArray* TofHit)
336{
337
338 fVectorTemp.SetXYZ(0.5, 0.36, 1.); // error for point dx = 0.5 cm; dy = 1.25/SQRT(12) = 0.36 cm; dz = 1(?)cm
339 Int_t UID = BmnTOF1Point::GetVolumeUID(0, fNPlane + 1, Str + 1); // strip [0,47] -> [1, 48]
340
341 BmnTofHit* pHit = new ((*TofHit)[TofHit->GetEntriesFast()])
342 BmnTofHit(UID, fCrossPoint[Str], fVectorTemp, FormIndex(fIndexL[Str], fIndexR[Str]));
343
344 pHit->SetModule(fNPlane);
345 pHit->SetStation(Str);
346 pHit->SetTimeStamp(fTof[Str]);
347 pHit->AddLink(FairLink(0x1, -1));
348 pHit->AddLink(FairLink(0x2, -1));
349 pHit->AddLink(FairLink(0x4, UID));
350 pHit->SetUpperClusterIndex(fIndexL[Str]);
351 pHit->SetLowerClusterIndex(fIndexR[Str]);
352 pHit->SetDetId(fTofId);
353
354 // cout << "Add hit to Array# " << TofHit->GetEntriesFast() << " : fNPlane = " << fNPlane << "; Str = " << Str
355 // << "; iR = " << fIndexL[Str] << "; iR = " << fIndexR[Str] << "; pointIndex";
356}
357
358//------------------------------------------------------------------------------------------------------------------------
359
360void BmnTOF1Detector::AddConteiner(Int_t Str, TClonesArray* TofHit)
361{
362
363 new ((*TofHit)[TofHit->GetEntriesFast()])
364 BmnTOF1Conteiner(fNPlane, Str, fTimeL[Str], fTimeR[Str], fTime[Str], fWidthL[Str], fWidthR[Str], fWidth[Str],
365 fCrossPoint[Str].x(), fCrossPoint[Str].y(), fCrossPoint[Str].z(), fT0->GetTime(),
366 fT0->GetAmp(), fTof[Str], fIndexL[Str], fIndexR[Str]);
367}
368
369//----------------------------------------------------------------------------------------
370
371void BmnTOF1Detector::FillHist()
372{
373 hHitPerEv->Fill(fHit_Per_Ev);
374 for (Int_t i = 0; i < fNStr; i++)
375 for (Int_t j = 0; j < fNStr; j++) {
376 if (fWidthL[i] != 0 && fWidthR[j] != 0) {
377 hHitLR->Fill(i, j);
378 if (i == j) {
379 hHitByCh->Fill(i);
380 hXY->Fill(fCrossPoint[i].x(), fCrossPoint[i].y());
381 }
382 }
383 }
384}
385
386//----------------------------------------------------------------------------------------
387
388Double_t BmnTOF1Detector::CalculateDt(Int_t Str = 0)
389{
390
391 Double_t dt = 0;
392 Double_t T0Amp;
393 dt = fTime[Str] - fT0->GetTime() + fCommonTimeShift;
394 if (fVerbose > 3)
395 printf("Calculate dt\n raw dt = %.3f\n", dt);
396 T0Amp = fT0->GetAmp();
397
398 /*dt = dt - (1.947 - 0.5363 * T0Amp
399 + 0.03428 * T0Amp * T0Amp
400 - 0.0005853 * T0Amp * T0Amp * T0Amp);// RUN6 */
401
402 if (funT0[Str] != NULL)
403 dt = dt - funT0[Str]->Eval(T0Amp);
404 if (fVerbose > 3)
405 printf("After T0 corr dt = %.3f\t", dt);
406
407 if (gSlew[Str] != NULL) {
408 dt = dt - gSlew[Str]->Eval(fWidth[Str]);
409 if (fVerbose > 3)
410 printf("After RPC corr dt = %.3f\t", dt);
411 }
412
413 if (funRPC[Str] != NULL) {
414 dt = dt - funRPC[Str]->Eval(fWidth[Str]);
415 if (fVerbose > 3)
416 printf("After RPC corr dt = %.3f\t", dt);
417 }
418
419 dt = dt + fCorrTimeShift[Str]; // CorrTimeShift is ToF for Gamma
420 if (fVerbose > 3)
421 printf("After Shift on Proton mass dt = %.3f\n", dt);
422
423 // cout << dt << endl;
424 return dt;
425}
426
427//----------------------------------------------------------------------------------------
428
429TList* BmnTOF1Detector::GetList(Int_t n = 0)
430{
431 if (fFillHist > 0) {
432 if (n == 0)
433 return fHistListStat;
434 } else
435 return NULL;
436
437 return NULL;
438}
439
440//----------------------------------------------------------------------------------------
441
443{
444 return fName;
445}
446
447//----------------------------------------------------------------------------------------
448
449Bool_t BmnTOF1Detector::SetCorrLR(TString NameFile)
450{
451 // cout << "BmnTOF1Detector::SetCorrLR" << endl;
452 char line[256];
453 Int_t Pl, St;
454 Double_t CorrFit, CorrMean;
455 ifstream f_corr;
456 TString dir = Form("%s%s%s", getenv("VMCWORKDIR"), "/input/", NameFile.Data());
457 // cout << "Open file " << dir << endl;
458 f_corr.open(dir);
459 f_corr.getline(line, 256);
460 f_corr.getline(line, 256);
461 if (f_corr.is_open() == kTRUE) {
462 while (!f_corr.eof()) {
463 if (fTofId == kTOF1)
464 f_corr >> Pl >> St >> CorrFit >> CorrMean;
465 if (fTofId == kTOF701)
466 f_corr >> Pl >> St >> CorrMean;
467 if (Pl == fNPlane) {
468 fCorrLR[St] = CorrMean;
469 // If diff between my shift and old shift is greater than the actual cable, throw
470 // strip out
471 // if (TMath::Abs(Temp - fCorrLR[St]) > 2.) fCorrLR[St] = -11.9766;
472 // cout << Pl << " " << St << " " << fCorrLR[St] << " " << CorrMean << "\n";
473 }
474 }
475 } else {
476 cout << "File " << NameFile.Data() << " for LR correction is not found" << endl;
477 cout << "Check " << dir.Data() << " folder for file" << endl;
478 return kFALSE;
479 }
480 f_corr.close();
481 return kTRUE;
482}
483//----------------------------------------------------------------------------------------
484
485Bool_t BmnTOF1Detector::SetCorrSlewing(TString NameFile)
486{
487 TString PathToFile = Form("%s%s%s", getenv("VMCWORKDIR"), "/input/", NameFile.Data());
488 TString name, dirname;
489 TDirectory* Dir;
490 TFile* f_corr = new TFile(PathToFile.Data(), "READ");
491 if (f_corr->IsOpen()) {
492 dirname = Form("Plane_%d", fNPlane);
493 f_corr->cd(dirname.Data());
494 Dir = f_corr->CurrentDirectory();
495 for (Int_t i = 0; i < fNStr; i++) {
496 name = Form("T0_TA_Plane%d_Str%d", fNPlane, i);
497 funT0[i] = (TF1*)Dir->Get(name.Data());
498 if (funT0[i] == NULL && fVerbose >= 1)
499 printf("funT0[%d] is NULL\n", i);
500 name = Form("Rpc_TA_Plane%d_Str%d", fNPlane, i);
501 gSlew[i] = (TGraphErrors*)Dir->Get(name.Data());
502 if (gSlew[i] == NULL && fVerbose >= 1)
503 printf("gSlew[%d] is NULL\n", i);
504 }
505 } else {
506 cout << "File " << NameFile.Data() << " for Slewing correction is not found" << endl;
507 cout << "Check " << PathToFile.Data() << " folder for file" << endl;
508 return kFALSE;
509 }
510 return kTRUE;
511}
512
513//----------------------------------------------------------------------------------------
514
515Bool_t BmnTOF1Detector::SetCorrTimeShift(TString NameFile)
516{
517 char line[256];
518 Int_t Pl, St;
519 Double_t Temp;
520 ifstream f_corr;
521 TString dir = Form("%s%s%s", getenv("VMCWORKDIR"), "/input/", NameFile.Data());
522 f_corr.open(dir);
523 f_corr.getline(line, 256);
524 // cout << line << endl;
525
526 f_corr.getline(line, 256);
527 // cout << line << endl;
528 fCommonTimeShift = atof(line);
529 // cout << fCommonTimeShift << endl;
530
531 f_corr.getline(line, 256);
532 // cout << line << endl;
533
534 // char ccc = getchar();
535 // if (ccc == 'q') return kFALSE;
536
537 if (f_corr.is_open() == kTRUE) {
538 while (!f_corr.eof()) {
539 f_corr >> Pl >> St >> Temp;
540 if (Pl == fNPlane) {
541 fCorrTimeShift[St] = Temp;
542 // cout << Pl << " " << St << " " << fCorrTimeShift[St] << "\n";
543 }
544 }
545 } else {
546 cout << "File " << NameFile.Data() << " for TimeShift correction is not found" << endl;
547 cout << "Check " << dir.Data() << " folder for file" << endl;
548 return kFALSE;
549 }
550 f_corr.close();
551 return kTRUE;
552}
553
554//----------------------------------------------------------------------------------------
555
556Bool_t BmnTOF1Detector::GetCrossPoint(Int_t NStrip, Double_t tL, Double_t tR)
557{
558
559 fVectorTemp.SetXYZ(0., 0., 0.);
560
561 double dtt = (tL - tR) * 0.5;
562 double dL = dtt / fSignalVelosityStr[NStrip];
563 // cout << "fSignalVelosityStr[NStrip] = " << fSignalVelosityStr[NStrip] << endl;
564 // cout << "dl = " << dL << endl;
565
566 // if (TMath::Abs(dtt) > fMaxDelta)
567 // return kFALSE;
568
569 // cout << "accept this hit" << endl;
570 // should be checked
571 fVectorTemp(0) = dL * TMath::Cos(fStripAngle[NStrip].X());
572 fVectorTemp(1) = dL * TMath::Cos(fStripAngle[NStrip].Y());
573 fVectorTemp(2) = dL * TMath::Cos(fStripAngle[NStrip].Z());
574
575 fCrossPoint[NStrip].SetXYZ(0., 0., 0.);
576 fCrossPoint[NStrip] = fCentrStrip[NStrip] + fVectorTemp;
577
578 return kTRUE;
579 // cout << "Z = " << fCrossPoint[NStrip].Z() << endl;
580 // return kTRUE;
581}
582//----------------------------------------------------------------------------------------
583
584Bool_t BmnTOF1Detector::SetGeoFile(TString NameFile)
585{
586
587 // get gGeoManager from ROOT file
588 TString PathToFile = Form("%s%s%s", getenv("VMCWORKDIR"), "/macro/run/geometry_run/", NameFile.Data());
589 TFile* geoFile = new TFile(PathToFile, "READ");
590 if (!geoFile->IsOpen()) {
591 cout << "Error: could not open ROOT file with geometry: " + NameFile << endl;
592 return kFALSE;
593 }
594 TList* keyList = geoFile->GetListOfKeys();
595 TIter next(keyList);
596 TKey* key = (TKey*)next();
597 TString className(key->GetClassName());
598 if (className.BeginsWith("TGeoManager"))
599 key->ReadObj();
600 else {
601 cout << "Error: TGeoManager isn't top element in geometry file " + NameFile << endl;
602 return kFALSE;
603 }
604
605 BmnTof1GeoUtils* pGeoUtils = new BmnTof1GeoUtils();
606 if (fTofId == kTOF1)
607 pGeoUtils->ParseTGeoManager(false, NULL, true);
608 else if (fTofId == kTOF701)
609 pGeoUtils->ParseTGeoManager701(false, NULL, true);
610 else
611 return kFALSE;
612
613 SetGeo(pGeoUtils);
614
615 geoFile->Close();
616 pGeoUtils->~BmnTof1GeoUtils();
617 return kTRUE;
618}
619
620//----------------------------------------------------------------------------------------
621
623{
624 Int_t UID;
625 TVector3 x(1, 0, 0);
626 TVector3 y(0, 1, 0);
627 TVector3 z(0, 0, 1);
628 for (Int_t i = 0; i < fNStrMax; i++) {
629 UID = BmnTOF1Point::GetVolumeUID(0, fNPlane + 1, i + 1); // strip [0,47] -> [1, 48]
630 // cout << "Plane = " << fNPlane << "; Strip = " << i << "; UID = " << UID << endl;
631 const LStrip1* pStrip = pGeoUtils->FindStrip(UID);
632 if (pStrip == NULL) {
633 fNStr = i;
634 break;
635 }
636 if (fTofId == kTOF701)
637 SetStripLength(pStrip->GetLength());
638 fCentrStrip[i] = pStrip->center;
639
640 if (fTofId == kTOF1)
641 fVectorTemp = (pStrip->C + pStrip->D) * 0.5 - (pStrip->A + pStrip->B) * 0.5;
642 else if (fTofId == kTOF701)
643 fVectorTemp = (pStrip->B + pStrip->C) * 0.5 - (pStrip->A + pStrip->D) * 0.5;
644 else
645 return kFALSE;
646
647 fStripAngle[i](0) = fVectorTemp.Angle(x);
648 fStripAngle[i](1) = fVectorTemp.Angle(y);
649 fStripAngle[i](2) = fVectorTemp.Angle(z);
650
651 // printf("Plane%d, Strip%d\t A=%.3f\t B=%.3f\t C=%.3f\n", fNPlane, i, fStripAngle[i](0), fStripAngle[i](1),
652 // fStripAngle[i](2));
653
654 // if (fNPlane >= 5) fCentrStrip[i].SetX(fCentrStrip[i].X()+5.5); // for field run only
655 // else fCentrStrip[i].SetX(fCentrStrip[i].X()+2.5);
656 }
657 return kTRUE;
658}
659
660//----------------------------------------------------------------------------------------
661
662Bool_t BmnTOF1Detector::GetXYZTime(Int_t Str, TVector3* XYZ, Double_t* ToF)
663{
664
665 if (Str < 0 || Str > fNStr)
666 return kFALSE;
667 if (NULL != XYZ)
668 XYZ->SetXYZ(fCrossPoint[Str].x(), fCrossPoint[Str].y(), fCrossPoint[Str].z());
669 if (NULL != ToF)
670 *ToF = fTof[Str];
671
672 return kTRUE;
673}
674
675//----------------------------------------------------------------------------------------
676
677Bool_t BmnTOF1Detector::GetLRTime(Int_t Str, Double_t* LMinusRTime)
678{
679
680 // if (fTof[Str] == 0) return kFALSE;
681 if (NULL == LMinusRTime)
682 return kFALSE;
683 *LMinusRTime = (fTimeL[Str] - fTimeR[Str]) * 0.5;
684 return kTRUE;
685}
686
687//----------------------------------------------------------------------------------------
688
689Double_t BmnTOF1Detector::GetWidth(Int_t Str = 1)
690{
691 return fWidth[Str];
692}
693
694//----------------------------------------------------------------------------------------
695
696Double_t BmnTOF1Detector::GetWidthL(Int_t Str = 1)
697{
698 return fWidthL[Str];
699}
700
701//----------------------------------------------------------------------------------------
702
703Double_t BmnTOF1Detector::GetWidthR(Int_t Str = 1)
704{
705 return fWidthR[Str];
706}
707
708//----------------------------------------------------------------------------------------
709
710Double_t BmnTOF1Detector::GetTime(Int_t Str = 1)
711{
712 return fTime[Str];
713}
714
715//----------------------------------------------------------------------------------------
716
717Bool_t BmnTOF1Detector::SaveHistToFile(TString NameFile)
718{
719
720 if (fFillHist > 0) {
721 TFile* fileout = new TFile(NameFile.Data(), "UPDATE");
722 // Int_t ResWrite;
723
724 TDirectory* Dir;
725 TString Name;
726 Name = Form("Tof400_%s", fName.Data());
727 Dir = fileout->mkdir(Name.Data());
728 Dir->cd();
729 // Dir->pwd();
730
731 TDirectory* DirStat;
732 DirStat = Dir->mkdir("Statistic");
733 DirStat->cd();
734 // DirStat->pwd();
735 // ResWrite = 0;
736 /*ResWrite = */ fHistListStat->Write();
737 // cout << "Res write = " << ResWrite << endl;
738
739 TDirectory* DirdT;
740 DirdT = Dir->mkdir("dt");
741 DirdT->cd();
742 // DirStat->pwd();
743 // ResWrite = 0;
744 /*ResWrite = */ fHistListdt->Write();
745 // cout << "Res write = " << ResWrite << endl;
746
747 fileout->Close(); //*/
748 return kTRUE; //*/
749
750 } else
751 return kFALSE;
752}
753
754//----------------------------------------------------------------------------------------
755
756Int_t BmnTOF1Detector::FormIndex(Int_t IndL, Int_t IndR)
757{
758 if (IndL > fHalfMaxInt || IndR > fHalfMaxInt)
759 return -1;
760 Int_t Index = 0;
761 Index = (IndL << 16) + IndR;
762 return Index;
763}
764
765//----------------------------------------------------------------------------------------
766
767Bool_t BmnTOF1Detector::SetSpeedOfSignal(TString NameFile) // Should be used after BmnTOF1Detector::SetGeo
768{
769 char line[256];
770 Int_t Pl, St;
771 Double_t Temp;
772 ifstream f_corr;
773 TString dir = Form("%s%s%s", getenv("VMCWORKDIR"), "/input/", NameFile.Data());
774 f_corr.open(dir);
775 f_corr.getline(line, 256);
776 // cout << line << endl;
777
778 if (f_corr.is_open() == kTRUE) {
779 while (!f_corr.eof()) {
780 f_corr >> Pl >> St >> Temp;
781 if (Pl == fNPlane && St == fNStr) {
782 fSignalVelosity = Temp;
783 fMaxDelta = (fStripLength * 0.5 + 3.0) * fSignalVelosity;
784 // cout << Pl << " " << St << "fStripLength = " << fStripLength << "; Speed = " << fSignalVelosity
785 // << " MaxDelta = " << fMaxDelta << "\n";
786 }
787 if (Pl == fNPlane && St < fNStr) {
788 fSignalVelosityStr[St] = Temp;
789 }
790 }
791 } else {
792 cout << "File " << NameFile.Data() << " for TimeShift correction is not found" << endl;
793 cout << "Check " << dir.Data() << " folder for file" << endl;
794 return kFALSE;
795 }
796 f_corr.close();
797 return kTRUE;
798}
799
800//----------------------------------------------------------------------------------------
void memset(T *dest, T i, size_t num)
uses binary expansion of copied volume for speed up
Definition L1Grid.h:25
int i
Definition P4_F32vec4.h:22
DetectorId
@ kTOF1
@ kTOF701
void SetModule(Int_t mod)
Definition BmnHit.h:73
void SetUpperClusterIndex(Int_t idx)
Definition BmnHit.h:133
void SetDetId(DetectorId det)
Definition BmnHit.h:65
void SetStation(Short_t st)
Definition BmnHit.h:69
void SetLowerClusterIndex(Int_t idx)
Definition BmnHit.h:137
Bool_t GetXYZTime(Int_t Str, TVector3 *XYZ, Double_t *ToF)
void SetStripLength(Double_t l)
Bool_t SetGeoFile(TString NameFile)
Int_t FindHitsNew(BmnTrigDigit *T0, TClonesArray *TofHit, int printnaw)
Bool_t SetCorrLR(TString NameFile)
void KillSide(Int_t NumberOfSide)
Double_t GetWidth(Int_t Str)
Bool_t GetLRTime(Int_t Str, Double_t *LMinusRTime)
Bool_t SetCorrTimeShift(TString NameFile)
Double_t GetWidthR(Int_t Str)
void KillStrip(Int_t NumberOfStrip)
Bool_t SetDigitNew(BmnTof1Digit *TofDigit, Int_t ind=-1)
Double_t GetTime(Int_t Str)
Double_t GetWidthL(Int_t Str)
Bool_t SetGeo(BmnTof1GeoUtils *pGeoUtils)
Bool_t SetSpeedOfSignal(TString NameFile)
TList * GetList(Int_t n)
Bool_t SetCorrSlewing(TString NameFile)
Bool_t SaveHistToFile(TString NameFile)
Int_t GetVolumeUID() const
Short_t GetPlane() const
Short_t GetSide() const
Short_t GetStrip() const
Float_t GetTime() const
Float_t GetAmplitude() const
const LStrip1 * FindStrip(Int_t UID)
Int_t ParseTGeoManager701(bool useMCinput, bool forced=false, Int_t verbose=0)
Int_t ParseTGeoManager(bool useMCinput, bool forced=false, Int_t verbose=0)
Double_t GetAmp() const
Double_t GetTime() const
Double_t GetLength() const
TVector3 center