/[PAMELA software]/PamCut/CollectionActions/RefitTrackAction/RefitTrackAction.cpp
ViewVC logotype

Contents of /PamCut/CollectionActions/RefitTrackAction/RefitTrackAction.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.2.4 - (show annotations) (download)
Mon Jun 7 13:33:15 2010 UTC (14 years, 8 months ago) by pam-fi
Branch: V8
Changes since 1.1.2.3: +7 -1 lines
Bug fixed in handling the original parameters of the track.

1 /*
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 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 if (_currEvent != event->GetReadEntry()) {
37 // Saves the original track data if the current event (recorded in the static member _currEvent) is
38 // different from the actually processed event. This way, multiple instances of the class
39 // can run in the same analysis, the backup being done only by the first of them.
40 _currEvent = event->GetReadEntry();
41 // Save the original cluster status and measured positions
42 for (int i = 0; i < 6; i++) {
43 _layerXBackup[i] = trkTrack->xgood[0];
44 _layerYBackup[i] = trkTrack->ygood[0];
45 _xmBackup[i] = trkTrack->xm[i];
46 _ymBackup[i] = trkTrack->ym[i];
47 }
48 }
49 else {
50 // Current event matches the actually analyzed event, this meaning that another instance of the class
51 // has already done a refit. In this case, cluster status and positions must be restored before fitting again.
52 for (int i = 0; i < 6; i++) {
53 trkTrack->xm[i] = _xmBackup[i];
54 trkTrack->ym[i] = _ymBackup[i];
55 _layerXBackup[i] = trkTrack->xgood[0];
56 _layerYBackup[i] = trkTrack->ygood[0];
57 }
58
59 }
60
61 // Apply the gaussian spread
62
63 cout << GetName() << " " << trkTrack->xm[0];
64 cout.flush();
65 for (Int_t ip = 0; ip < 6; ip++) {
66 // gaussian distributed random number Gauss(mean,sigma) (in cm)
67 trkTrack->xm[ip] += _r3->Gaus(0., _spreadX);
68 trkTrack->ym[ip] += _r3->Gaus(0., _spreadY);
69 }
70 cout << GetName() << " " << trkTrack->xm[0] << endl;
71 // Mask the layers
72 if (_maskedViews) {
73 if ((_maskedViews & T1X) == T1X)
74 trkTrack->xgood[0] = 0;
75 if ((_maskedViews & T2X) == T2X)
76 trkTrack->xgood[1] = 0;
77 if ((_maskedViews & T3X) == T3X)
78 trkTrack->xgood[2] = 0;
79 if ((_maskedViews & T4X) == T4X)
80 trkTrack->xgood[3] = 0;
81 if ((_maskedViews & T5X) == T5X)
82 trkTrack->xgood[4] = 0;
83 if ((_maskedViews & T6X) == T6X)
84 trkTrack->xgood[5] = 0;
85
86 if ((_maskedViews & T1Y) == T1Y)
87 trkTrack->ygood[0] = 0;
88 if ((_maskedViews & T2Y) == T2Y)
89 trkTrack->ygood[1] = 0;
90 if ((_maskedViews & T3Y) == T3Y)
91 trkTrack->ygood[2] = 0;
92 if ((_maskedViews & T4Y) == T4Y)
93 trkTrack->ygood[3] = 0;
94 if ((_maskedViews & T5Y) == T5Y)
95 trkTrack->ygood[4] = 0;
96 if ((_maskedViews & T6Y) == T6Y)
97 trkTrack->ygood[5] = 0;
98 }
99
100 trkTrack->FitReset();
101 int fail = 0;
102 trkTrack->Fit(0, fail, 0);
103
104 if (fail) {
105 // Set a flag for the badly-refitted tracks: chi2 < 0
106 if (trkTrack->chi2 >= 0.)
107 trkTrack->chi2 = -1.;
108 }
109 }

  ViewVC Help
Powered by ViewVC 1.1.23