--- PamCut/CollectionActions/RefitTrackAction/RefitTrackAction.cpp 2010/05/11 15:16:17 1.1.2.1 +++ PamCut/CollectionActions/RefitTrackAction/RefitTrackAction.cpp 2010/06/07 14:30:20 1.1.2.6 @@ -9,15 +9,38 @@ TRandom3* RefitTrackAction::_r3 = new TRandom3(0); long int RefitTrackAction::_currEvent = -1; +TString RefitTrackAction::_currTrkParamsFile = ""; + +float RefitTrackAction::_xmBackup[6], RefitTrackAction::_ymBackup[6]; +int RefitTrackAction::_layerXBackup[6], RefitTrackAction::_layerYBackup[6]; void RefitTrackAction::OnGood(PamLevel2 *event) { - TrkParams::Set("/wizard/02/pamela_software/installed/pamela/calib/trk-param/align_param-080805-GL1from7/", 5); //DA USARE SOLO PER SIMULAZIONE ROTRASL!!! + // Do something only if at least one track exists + if (event->GetTrkLevel2()->GetNTracks() == 0) + return; + // Reload the TRK parameters only if they have been changed (ie., if another instance of + // this class used a different set of parameters). + if (_trkParamsFile != _currTrkParamsFile) { + TrkParams::Set(_trkParamsFile, 5); + _currTrkParamsFile = _trkParamsFile; + } + + if (_sortingMethod) + event->SetSortingMethod(_sortingMethod); TrkTrack *trkTrack = event->GetTrack(0)->GetTrkTrack(); if (!trkTrack) return; + // Check if good clusters have meaningful energy releases + for (UInt_t ip = 0; ip < 6; ip++) { + if (trkTrack->XGood(ip) == 1 && trkTrack->GetDEDX(ip, 0) <= 0.) + trkTrack->xgood[ip] = 0; // Set it to bad + if (trkTrack->YGood(ip) == 1 && trkTrack->GetDEDX(ip, 1) <= 0.) + trkTrack->ygood[ip] = 0; // Set it to bad + } + if (_currEvent != event->GetReadEntry()) { // Saves the original track data if the current event (recorded in the static member _currEvent) is // different from the actually processed event. This way, multiple instances of the class @@ -44,6 +67,7 @@ } // Apply the gaussian spread + for (Int_t ip = 0; ip < 6; ip++) { // gaussian distributed random number Gauss(mean,sigma) (in cm) trkTrack->xm[ip] += _r3->Gaus(0., _spreadX); @@ -82,4 +106,10 @@ trkTrack->FitReset(); int fail = 0; trkTrack->Fit(0, fail, 0); + + if (fail) { + // Set a flag for the badly-refitted tracks: chi2 < 0 + if (trkTrack->chi2 >= 0.) + trkTrack->chi2 = -1.; + } }