~chris-rogers/maus/emr_mc_digitization

« back to all changes in this revision

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

  • Committer: Chris Rogers
  • Date: 2014-04-16 11:48:45 UTC
  • mfrom: (707 merge)
  • mto: This revision was merged to the branch mainline in revision 711.
  • Revision ID: chris.rogers@stfc.ac.uk-20140416114845-h3u3q7pdcxkxvovs
Update to trunk

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/PIDVarA.hh"
 
20
#include "Utils/Exception.hh"
 
21
 
 
22
namespace MAUS {
 
23
namespace recon {
 
24
namespace global {
 
25
 
 
26
  const std::string PIDVarA::VARIABLE = "diffTOF1TOF0";
 
27
 
 
28
  PIDVarA::PIDVarA(std::string hypothesis, std::string unique_identifier)
 
29
    : PIDBase(minBin, maxBin, numBins, VARIABLE, hypothesis,
 
30
              unique_identifier) {
 
31
    _nonZeroHistEntries = true;
 
32
  }
 
33
 
 
34
  PIDVarA::PIDVarA(TFile* file, std::string hypothesis)
 
35
    : PIDBase(file, VARIABLE, hypothesis) {
 
36
  }
 
37
 
 
38
  PIDVarA::~PIDVarA() {}
 
39
 
 
40
  double PIDVarA::Calc_Var(MAUS::DataStructure::Global::Track* track) {
 
41
    double TOF0_t = 0;
 
42
    double TOF1_t = 0;
 
43
    int checkCount0 = 0;
 
44
    int checkCount1 = 0;
 
45
    std::vector<const MAUS::DataStructure::Global::TrackPoint*>
 
46
      track_points = track->GetTrackPoints();
 
47
    // TODO(Pidcott) check that right detector enums are used
 
48
    MAUS::DataStructure::Global::DetectorPoint TOF0_DP =
 
49
      MAUS::DataStructure::Global::kTOF0_1;
 
50
    MAUS::DataStructure::Global::DetectorPoint TOF1_DP =
 
51
      MAUS::DataStructure::Global::kTOF1_1;
 
52
    std::vector<const MAUS::DataStructure::Global::TrackPoint*>
 
53
      ::iterator eachTP;
 
54
    for (eachTP = track_points.begin(); eachTP != track_points.end();
 
55
         ++eachTP) {
 
56
      if (!(*eachTP)) continue;
 
57
      if ((*eachTP)->get_detector() == TOF0_DP) {
 
58
        TOF0_t = (*eachTP)->get_position().T();
 
59
        ++checkCount0;
 
60
      } else if ((*eachTP)->get_detector() == TOF1_DP) {
 
61
        TOF1_t = (*eachTP)->get_position().T();
 
62
        ++checkCount1;
 
63
      }
 
64
    }
 
65
    if (checkCount0 > 1 || checkCount1 > 1) {
 
66
      Squeak::mout(Squeak::error) << "Multiple measurements for TOF0/TOF1" <<
 
67
        " times, Recon::Global::PIDVarA::Calc_Var()" << std::endl;
 
68
      return -1;
 
69
    } else if (checkCount0 == 0 ||
 
70
               checkCount1 == 0 || (TOF1_t -TOF0_t) <= 0) {
 
71
      Squeak::mout(Squeak::error) << "Missing/invalid measurements for " <<
 
72
        "TOF0/TOF1 times, Recon::Global::PIDVarA::Calc_Var()" << std::endl;
 
73
      return -1;
 
74
    } else if ( minBin > (TOF1_t - TOF0_t) || (TOF1_t - TOF0_t) > maxBin ) {
 
75
      Squeak::mout(Squeak::error) << "Difference between TOF0 and TOF1 times" <<
 
76
        " outside of range, Recon::Global::PIDVarA::Calc_Var()" << std::endl;
 
77
      return -1;
 
78
    } else {
 
79
      return (TOF1_t - TOF0_t);
 
80
    }
 
81
  }
 
82
}
 
83
}
 
84
}
 
85