1 |
pam-fi |
1.2 |
/* |
2 |
|
|
* RefitTrackAction.cpp |
3 |
|
|
* |
4 |
|
|
* Created on: 10/may/2010 |
5 |
|
|
* Author: M. Bongi, N. Mori |
6 |
|
|
*/ |
7 |
|
|
|
8 |
|
|
#include "RefitTrackAction.h" |
9 |
|
|
|
10 |
|
|
TRandom3* RefitTrackAction::_r3 = new TRandom3(0); |
11 |
|
|
long int RefitTrackAction::_currEvent = -1; |
12 |
|
|
TString RefitTrackAction::_currTrkParamsFile = ""; |
13 |
|
|
|
14 |
|
|
float RefitTrackAction::_xmBackup[6], RefitTrackAction::_ymBackup[6]; |
15 |
|
|
int RefitTrackAction::_layerXBackup[6], RefitTrackAction::_layerYBackup[6]; |
16 |
|
|
|
17 |
|
|
void RefitTrackAction::OnGood(PamLevel2 *event) { |
18 |
|
|
|
19 |
|
|
// Do something only if at least one track exists |
20 |
|
|
if (event->GetTrkLevel2()->GetNTracks() == 0) |
21 |
|
|
return; |
22 |
|
|
|
23 |
|
|
// Reload the TRK alignment parameters only if they have been changed (ie., if another instance of |
24 |
|
|
// this class used a different set of parameters). |
25 |
|
|
if (_trkParamsFile != _currTrkParamsFile) { |
26 |
|
|
TrkParams::Set(_trkParamsFile, 5); |
27 |
|
|
_currTrkParamsFile = _trkParamsFile; |
28 |
|
|
} |
29 |
|
|
|
30 |
|
|
if (_sortingMethod) |
31 |
|
|
event->SetSortingMethod(_sortingMethod); |
32 |
|
|
TrkTrack *trkTrack = event->GetTrack(0)->GetTrkTrack(); |
33 |
|
|
if (!trkTrack) |
34 |
|
|
return; |
35 |
|
|
|
36 |
|
|
// Check if good clusters have meaningful energy releases |
37 |
|
|
for (UInt_t ip = 0; ip < 6; ip++) { |
38 |
|
|
if (trkTrack->XGood(ip) == 1 && trkTrack->GetDEDX(ip, 0) <= 0.) |
39 |
|
|
trkTrack->xgood[ip] = 0; // Set it to bad |
40 |
|
|
if (trkTrack->YGood(ip) == 1 && trkTrack->GetDEDX(ip, 1) <= 0.) |
41 |
|
|
trkTrack->ygood[ip] = 0; // Set it to bad |
42 |
|
|
} |
43 |
|
|
|
44 |
|
|
if (_currEvent != event->GetReadEntry()) { |
45 |
|
|
// Saves the original track data if the current event (recorded in the static member _currEvent) is |
46 |
|
|
// different from the actually processed event. This way, multiple instances of the class |
47 |
|
|
// can run in the same analysis, the backup being done only by the first of them. |
48 |
|
|
_currEvent = event->GetReadEntry(); |
49 |
|
|
// Save the original cluster status and measured positions |
50 |
|
|
for (int i = 0; i < 6; i++) { |
51 |
|
|
_layerXBackup[i] = trkTrack->xgood[0]; |
52 |
|
|
_layerYBackup[i] = trkTrack->ygood[0]; |
53 |
|
|
_xmBackup[i] = trkTrack->xm[i]; |
54 |
|
|
_ymBackup[i] = trkTrack->ym[i]; |
55 |
|
|
} |
56 |
|
|
} |
57 |
|
|
else { |
58 |
|
|
// Current event matches the actually analyzed event, this meaning that another instance of the class |
59 |
|
|
// has already done a refit. In this case, cluster status and positions must be restored before fitting again. |
60 |
|
|
for (int i = 0; i < 6; i++) { |
61 |
|
|
trkTrack->xm[i] = _xmBackup[i]; |
62 |
|
|
trkTrack->ym[i] = _ymBackup[i]; |
63 |
|
|
_layerXBackup[i] = trkTrack->xgood[0]; |
64 |
|
|
_layerYBackup[i] = trkTrack->ygood[0]; |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
// Apply the gaussian spread |
70 |
|
|
|
71 |
|
|
for (Int_t ip = 0; ip < 6; ip++) { |
72 |
|
|
// gaussian distributed random number Gauss(mean,sigma) (in cm) |
73 |
|
|
trkTrack->xm[ip] += _r3->Gaus(0., _spreadX); |
74 |
|
|
trkTrack->ym[ip] += _r3->Gaus(0., _spreadY); |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
// Mask the layers |
78 |
|
|
if (_maskedViews) { |
79 |
|
|
if ((_maskedViews & T1X) == T1X) |
80 |
|
|
trkTrack->xgood[0] = 0; |
81 |
|
|
if ((_maskedViews & T2X) == T2X) |
82 |
|
|
trkTrack->xgood[1] = 0; |
83 |
|
|
if ((_maskedViews & T3X) == T3X) |
84 |
|
|
trkTrack->xgood[2] = 0; |
85 |
|
|
if ((_maskedViews & T4X) == T4X) |
86 |
|
|
trkTrack->xgood[3] = 0; |
87 |
|
|
if ((_maskedViews & T5X) == T5X) |
88 |
|
|
trkTrack->xgood[4] = 0; |
89 |
|
|
if ((_maskedViews & T6X) == T6X) |
90 |
|
|
trkTrack->xgood[5] = 0; |
91 |
|
|
|
92 |
|
|
if ((_maskedViews & T1Y) == T1Y) |
93 |
|
|
trkTrack->ygood[0] = 0; |
94 |
|
|
if ((_maskedViews & T2Y) == T2Y) |
95 |
|
|
trkTrack->ygood[1] = 0; |
96 |
|
|
if ((_maskedViews & T3Y) == T3Y) |
97 |
|
|
trkTrack->ygood[2] = 0; |
98 |
|
|
if ((_maskedViews & T4Y) == T4Y) |
99 |
|
|
trkTrack->ygood[3] = 0; |
100 |
|
|
if ((_maskedViews & T5Y) == T5Y) |
101 |
|
|
trkTrack->ygood[4] = 0; |
102 |
|
|
if ((_maskedViews & T6Y) == T6Y) |
103 |
|
|
trkTrack->ygood[5] = 0; |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
trkTrack->FitReset(); |
107 |
|
|
int fail = 0; |
108 |
|
|
trkTrack->Fit(0, fail, 0); |
109 |
|
|
|
110 |
|
|
if (fail) { |
111 |
|
|
// Set a flag for the badly-refitted tracks: chi2 < 0 |
112 |
|
|
if (trkTrack->chi2 >= 0.) |
113 |
|
|
trkTrack->chi2 = -1.; |
114 |
|
|
} |
115 |
|
|
} |