~christopher-hunt08/maus/maus_integrated_kalman

« back to all changes in this revision

Viewing changes to src/common_cpp/Recon/Global/ComPIDVarE.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 "Recon/Global/ComPIDVarE.hh"
 
20
#include "Utils/Exception.hh"
 
21
 
 
22
namespace MAUS {
 
23
namespace recon {
 
24
namespace global {
 
25
 
 
26
  const std::string ComPIDVarE::VARIABLE = "CommissioningEMRrangevsDiffTOF1TOF2";
 
27
 
 
28
  ComPIDVarE::ComPIDVarE(std::string hypothesis, std::string unique_identifier)
 
29
    : PIDBase2D(VARIABLE, hypothesis, unique_identifier, XminBinComE,
 
30
                XmaxBinComE, XnumBins, YminBinComE, YmaxBinComE, YnumBins) {
 
31
    _nonZeroHistEntries = true;
 
32
  }
 
33
 
 
34
  ComPIDVarE::ComPIDVarE(TFile* file, std::string hypothesis, int XminComE,
 
35
                         int XmaxComE, int YminComE, int YmaxComE)
 
36
    : PIDBase2D(file, VARIABLE, hypothesis, XminComE, XmaxComE, YminComE,
 
37
                YmaxComE, XminBinComE, XmaxBinComE, YminBinComE, YmaxBinComE) {
 
38
  }
 
39
 
 
40
  ComPIDVarE::~ComPIDVarE() {}
 
41
 
 
42
  std::pair<double, double> ComPIDVarE::Calc_Var(MAUS::DataStructure::Global::Track* track) {
 
43
    EMR_range = track->get_emr_range_primary();
 
44
    if (EMR_range == 0.0) {
 
45
      Squeak::mout(Squeak::debug) << "Global track records no range " <<
 
46
        " of particle in EMR, Recon::Global::ComPIDVarE::Calc_Var()" << std::endl;
 
47
      return std::make_pair(0, -1);
 
48
    } else if ( YminBinComE > EMR_range || EMR_range > YmaxBinComE ) {
 
49
      Squeak::mout(Squeak::debug) << "Range of particle in EMR " <<
 
50
        "outside of PDF range, Recon::Global::ComPIDVarE::Calc_Var()" <<
 
51
        std::endl;
 
52
      return std::make_pair(0, -1);
 
53
    } else {
 
54
      double TOF2_t = 0;
 
55
      double TOF1_t = 0;
 
56
      int checkCount2 = 0;
 
57
      int checkCount1 = 0;
 
58
      std::vector<const MAUS::DataStructure::Global::TrackPoint*>
 
59
        track_points = track->GetTrackPoints();
 
60
      MAUS::DataStructure::Global::DetectorPoint TOF2_DP =
 
61
        MAUS::DataStructure::Global::kTOF2;
 
62
      MAUS::DataStructure::Global::DetectorPoint TOF1_DP =
 
63
        MAUS::DataStructure::Global::kTOF1;
 
64
      std::vector<const MAUS::DataStructure::Global::TrackPoint*>
 
65
        ::iterator eachTP;
 
66
      for (eachTP = track_points.begin(); eachTP != track_points.end();
 
67
           ++eachTP) {
 
68
        if (!(*eachTP)) continue;
 
69
        if ((*eachTP)->get_mapper_name() == "MapCppGlobalTrackMatching-Through") {
 
70
          if ((*eachTP)->get_detector() == TOF2_DP) {
 
71
            TOF2_t = (*eachTP)->get_position().T();
 
72
            ++checkCount2;
 
73
          } else if ((*eachTP)->get_detector() == TOF1_DP) {
 
74
            TOF1_t = (*eachTP)->get_position().T();
 
75
            ++checkCount1;
 
76
          }
 
77
        } else {
 
78
          continue;
 
79
        }
 
80
      }
 
81
      if (checkCount2 > 1 || checkCount1 > 1) {
 
82
        Squeak::mout(Squeak::debug) << "Multiple measurements for TOF2/TOF1" <<
 
83
          " times, Recon::Global::ComPIDVarE::Calc_Var()" << std::endl;
 
84
        return std::make_pair(-1, EMR_range);
 
85
      } else if (checkCount2 == 0 ||
 
86
                 checkCount1 == 0 || (TOF2_t -TOF1_t) <= 0) {
 
87
        Squeak::mout(Squeak::debug) << "Missing/invalid measurements for " <<
 
88
          "TOF0/TOF1 times, Recon::Global::ComPIDVarE::Calc_Var()" << std::endl;
 
89
        return std::make_pair(-1, EMR_range);
 
90
      } else if ( XminBinComE > (TOF2_t - TOF1_t) ||
 
91
                  (TOF2_t - TOF1_t) > XmaxBinComE ) {
 
92
        Squeak::mout(Squeak::debug) << "Difference between TOF1 & TOF2 times" <<
 
93
          " out of PDF range, Recon::Global::ComPIDVarE::Calc_Var()" << std::endl;
 
94
        return std::make_pair(-1, EMR_range);
 
95
      } else {
 
96
        return std::make_pair((TOF2_t - TOF1_t), EMR_range);
 
97
      }
 
98
    }
 
99
  }
 
100
}
 
101
}
 
102
}
 
103
 
 
104