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

Diff of /PamCut/CollectionActions/RefitTrackAction/RefitTrackAction.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.1.2.3

  ViewVC Help
Powered by ViewVC 1.1.23