~m-a-uchida/maus/RKdEdxDevel

« back to all changes in this revision

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

  • Committer: Adam Dobbs
  • Date: 2015-02-07 14:55:51 UTC
  • mfrom: (659.1.101 release-candidate)
  • Revision ID: phuccj@gmail.com-20150207145551-ehmmqm9uxyesib7q
Tags: MAUS-v0.9.3
MAUS-v0.9.3

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/PIDVarC.hh"
 
21
#include "Utils/Exception.hh"
 
22
 
 
23
namespace MAUS {
 
24
namespace recon {
 
25
namespace global {
 
26
 
 
27
  const std::string PIDVarC::VARIABLE = "KLChargeProdvsDSTrackerMom";
 
28
 
 
29
  PIDVarC::PIDVarC(std::string hypothesis, std::string unique_identifier)
 
30
    : PIDBase2D(VARIABLE, hypothesis, unique_identifier,
 
31
                 XminBin, XmaxBin, XnumBins, YminBin, YmaxBin, YnumBins) {
 
32
    _nonZeroHistEntries = true;
 
33
  }
 
34
 
 
35
  PIDVarC::PIDVarC(TFile* file, std::string hypothesis)
 
36
    : PIDBase2D(file, VARIABLE, hypothesis) {
 
37
  }
 
38
 
 
39
  PIDVarC::~PIDVarC() {}
 
40
 
 
41
  std::pair<double, double> PIDVarC::Calc_Var(MAUS::DataStructure::Global::Track* track) {
 
42
    int total_ADC_charge_product = 0;
 
43
    MAUS::DataStructure::Global::DetectorPoint KL_DP =
 
44
      MAUS::DataStructure::Global::kCalorimeter;
 
45
    // Get trackpoint array from track
 
46
    global_track_points = track->GetTrackPoints();
 
47
    std::vector<const MAUS::DataStructure::Global::TrackPoint*>
 
48
      ::iterator eachTP;
 
49
    for (eachTP = global_track_points.begin();
 
50
         eachTP != global_track_points.end(); ++eachTP) {
 
51
      if (!(*eachTP)) continue;
 
52
      if ((*eachTP)->get_mapper_name() == "MapCppGlobalTrackMatching") {
 
53
        if ((*eachTP)->get_detector() == KL_DP) {
 
54
          kl_track_points.push_back(*eachTP);
 
55
        } else if ((*eachTP)->get_detector() >=
 
56
                   MAUS::DataStructure::Global::kTracker1_1 &&
 
57
                   (*eachTP)->get_detector() <=
 
58
                   MAUS::DataStructure::Global::kTracker1_5) {
 
59
          tracker1_track_points.push_back(*eachTP);
 
60
        } else {
 
61
          continue;
 
62
        }
 
63
      }
 
64
    }
 
65
    if (kl_track_points.size() < 1) {
 
66
      Squeak::mout(Squeak::debug) << "Global track contained no KL" <<
 
67
        " trackpoints, Recon::Global::PIDVarC::Calc_Var()" << std::endl;
 
68
      kl_track_points.clear();
 
69
      return std::make_pair(-1, 0);
 
70
    } else if (tracker1_track_points.size() < 1) {
 
71
      Squeak::mout(Squeak::debug) << "Global track contained no downstream" <<
 
72
        " tracker trackpoints, Recon::Global::PIDVarC::Calc_Var()" << std::endl;
 
73
      tracker1_track_points.clear();
 
74
      kl_track_points.clear();
 
75
      return std::make_pair(-1, 0);
 
76
    } else {
 
77
      for (size_t i = 0; i < kl_track_points.size(); i++) {
 
78
        total_ADC_charge_product += kl_track_points[i]->get_ADC_charge_product();
 
79
      }
 
80
      if ( YminBin > (total_ADC_charge_product) || (total_ADC_charge_product) > YmaxBin ) {
 
81
        Squeak::mout(Squeak::debug) << "KL ADC charge product " <<
 
82
          "outside of allowed range, Recon::Global::PIDVarC::Calc_Var()" <<
 
83
          std::endl;
 
84
        kl_track_points.clear();
 
85
        tracker1_track_points.clear();
 
86
        return std::make_pair(-1, 0);
 
87
      } else {
 
88
        double tracker1_trackpoint_mom = 0;
 
89
        int tracker1_tp_count = 0;
 
90
        double tracker1_momentum = 0;
 
91
        const MAUS::DataStructure::Global::TrackPoint* tracker1_trackpoint;
 
92
        for (size_t i = 0; i < tracker1_track_points.size(); i++) {
 
93
          tracker1_trackpoint = tracker1_track_points[i];
 
94
          if (tracker1_trackpoint) {
 
95
            TLorentzVector trackpoint_4mom = tracker1_trackpoint->get_momentum();
 
96
            tracker1_trackpoint_mom +=
 
97
              sqrt(trackpoint_4mom.Px()*trackpoint_4mom.Px() +
 
98
                   trackpoint_4mom.Py()*trackpoint_4mom.Py() +
 
99
                   trackpoint_4mom.Pz()*trackpoint_4mom.Pz());
 
100
            tracker1_tp_count++;
 
101
          } else {
 
102
            continue;
 
103
          }
 
104
        }
 
105
        kl_track_points.clear();
 
106
        tracker1_track_points.clear();
 
107
        tracker1_momentum = tracker1_trackpoint_mom/tracker1_tp_count;
 
108
        if ( XminBin > tracker1_momentum || tracker1_momentum > XmaxBin ) {
 
109
          Squeak::mout(Squeak::debug) << "Momentum for tracker 1 is outside " <<
 
110
            "of range, Recon::Global::PIDVarC::Calc_Var()" << std::endl;
 
111
          return std::make_pair(0, -1);
 
112
        } else {
 
113
          return std::make_pair(tracker1_momentum, (total_ADC_charge_product));
 
114
        }
 
115
      }
 
116
    }
 
117
  }
 
118
}
 
119
}
 
120
}
 
121