~christopher-hunt08/maus/maus_integrated_kalman

« back to all changes in this revision

Viewing changes to src/common_cpp/Recon/Global/ComPIDVarB.cc

merging in changes in merge branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of MAUS: http://  micewww.pp.rl.ac.uk:8080/projects/maus
 
2
 * 
 
3
 * MAUS is free software: you can redistribute it and/or modify
 
4
 * it under the terms of the GNU General Public License as published by
 
5
 * the Free Software Foundation, either version 3 of the License, or
 
6
 * (at your option) any later version.
 
7
 * 
 
8
 * MAUS is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 * 
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with MAUS.  If not, see <http://  www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
#include <string>
 
18
#include <vector>
 
19
#include <utility>
 
20
#include "Recon/Global/ComPIDVarB.hh"
 
21
#include "Utils/Exception.hh"
 
22
 
 
23
namespace MAUS {
 
24
namespace recon {
 
25
namespace global {
 
26
 
 
27
  const std::string ComPIDVarB::VARIABLE = "KLChargeProdvsDiffTOF1TOF2";
 
28
 
 
29
  ComPIDVarB::ComPIDVarB(std::string hypothesis, std::string unique_identifier)
 
30
    : PIDBase2D(VARIABLE, hypothesis, unique_identifier, XminBinComB,
 
31
                XmaxBinComB, XnumBins, YminBinComB, YmaxBinComB, YnumBins) {
 
32
    _nonZeroHistEntries = true;
 
33
  }
 
34
 
 
35
  ComPIDVarB::ComPIDVarB(TFile* file, std::string hypothesis, int XminComB,
 
36
                         int XmaxComB, int YminComB, int YmaxComB)
 
37
    : PIDBase2D(file, VARIABLE, hypothesis, XminComB, XmaxComB, YminComB,
 
38
                YmaxComB, XminBinComB, XmaxBinComB, YminBinComB, YmaxBinComB) {
 
39
  }
 
40
 
 
41
  ComPIDVarB::~ComPIDVarB() {}
 
42
 
 
43
  std::pair<double, double> ComPIDVarB::Calc_Var(MAUS::DataStructure::Global::Track* track) {
 
44
    int total_ADC_charge_product = 0;
 
45
    MAUS::DataStructure::Global::DetectorPoint KL_DP =
 
46
      MAUS::DataStructure::Global::kCalorimeter;
 
47
    double TOF1_t = 0;
 
48
    double TOF2_t = 0;
 
49
    MAUS::DataStructure::Global::DetectorPoint TOF1_DP =
 
50
      MAUS::DataStructure::Global::kTOF1;
 
51
    MAUS::DataStructure::Global::DetectorPoint TOF2_DP =
 
52
      MAUS::DataStructure::Global::kTOF2;
 
53
    // Get trackpoint array from track
 
54
    global_track_points = track->GetTrackPoints();
 
55
    std::vector<const MAUS::DataStructure::Global::TrackPoint*>
 
56
      ::iterator eachTP;
 
57
    for (eachTP = global_track_points.begin();
 
58
         eachTP != global_track_points.end(); ++eachTP) {
 
59
      if (!(*eachTP)) continue;
 
60
      if ((*eachTP)->get_mapper_name() == "MapCppGlobalTrackMatching-Through") {
 
61
        if ((*eachTP)->get_detector() == KL_DP) {
 
62
          kl_track_points.push_back(*eachTP);
 
63
        } else if ((*eachTP)->get_detector() == TOF1_DP) {
 
64
          tof1_track_points.push_back(*eachTP);
 
65
        } else if ((*eachTP)->get_detector() == TOF2_DP) {
 
66
          tof2_track_points.push_back(*eachTP);
 
67
        } else {
 
68
          continue;
 
69
        }
 
70
      }
 
71
    }
 
72
    if (kl_track_points.size() < 1) {
 
73
      Squeak::mout(Squeak::debug) << "Global track contained no KL" <<
 
74
        " trackpoints, Recon::Global::ComPIDVarB::Calc_Var()" << std::endl;
 
75
      kl_track_points.clear();
 
76
      tof2_track_points.clear();
 
77
      tof1_track_points.clear();
 
78
      return std::make_pair(-1, 0);
 
79
    } else if (tof2_track_points.size() > 1 || tof1_track_points.size() > 1) {
 
80
      Squeak::mout(Squeak::debug) << "Multiple measurements for TOF2/TOF1" <<
 
81
        " times, Recon::Global::ComPIDVarB::Calc_Var()" << std::endl;
 
82
      tof2_track_points.clear();
 
83
      tof1_track_points.clear();
 
84
      kl_track_points.clear();
 
85
      return std::make_pair(-1, 0);
 
86
    } else if ( tof2_track_points.size() == 0 ||
 
87
                tof1_track_points.size() == 0 ) {
 
88
      Squeak::mout(Squeak::debug) << "Missing measurements for " <<
 
89
        "TOF2/TOF1 times, Recon::Global::ComPIDVarB::Calc_Var()" << std::endl;
 
90
      tof2_track_points.clear();
 
91
      tof1_track_points.clear();
 
92
      kl_track_points.clear();
 
93
      return std::make_pair(-1, 0);
 
94
    } else {
 
95
      for (size_t i = 0; i < kl_track_points.size(); i++) {
 
96
        total_ADC_charge_product += kl_track_points[i]->get_ADC_charge_product();
 
97
      }
 
98
      kl_track_points.clear();
 
99
      if ( YminBinComB > (total_ADC_charge_product) || (total_ADC_charge_product) > YmaxBinComB ) {
 
100
        Squeak::mout(Squeak::debug) << "KL ADC charge product " <<
 
101
          "outside of allowed range, Recon::Global::ComPIDVarB::Calc_Var()" <<
 
102
          std::endl;
 
103
      }
 
104
      TOF2_t = (tof2_track_points[0])->get_position().T();
 
105
      tof2_track_points.clear();
 
106
      TOF1_t = (tof1_track_points[0])->get_position().T();
 
107
      tof1_track_points.clear();
 
108
      if ( XminBinComB > (TOF2_t - TOF1_t) || (TOF2_t - TOF1_t) > XmaxBinComB ) {
 
109
        Squeak::mout(Squeak::debug) << "Difference between TOF2 and TOF1 " <<
 
110
          "times out of PDF range, Recon::Global::ComPIDVarB::Calc_Var()" <<
 
111
          std::endl;
 
112
      }
 
113
      return std::make_pair((TOF2_t - TOF1_t), (total_ADC_charge_product));
 
114
    }
 
115
  }
 
116
}
 
117
}
 
118
}
 
119