NAIA
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
RichFill.cpp
Go to the documentation of this file.
1 #include "Containers/Rich.h"
2 
3 #include "RichCharge.h"
4 #include "richidOff.h"
5 #include "richradidOff.h"
6 #include "richrecOff.h"
7 
8 namespace NAIA {
9 
10 void RichBaseData::Fill(RichRingR *ringPtr, RichRingBR *ringBPtr) {
12  if (ringPtr)
13  type = ringPtr->IsNaF() ? Rich::RichMeasType::NaF : Rich::RichMeasType::Agl;
14 
15  RichBetaVariable<float> beta;
16  if (ringPtr)
17  beta[Rich::BetaType::CIEMAT] = ringPtr->getBeta();
18 
19  if (ringBPtr)
20  beta[Rich::BetaType::LIP] = ringBPtr->Beta;
21 
22  if (type != Rich::RichMeasType::NONE)
23  m_beta.emplace_back(type, beta);
24 }
25 
26 void RichPlusData::Fill(AMSEventR *evPtr, RichRingR *ringPtr, TrTrackR *trackPtr) {
27  RichAdditionalData data;
28 
29  data.NHitsTot = evPtr->NRichHit();
30  data.NPETotUncorr = RichHitR::getCollectedPhotoElectrons();
31  if (ringPtr) {
32  data.NHitsUsed = ringPtr->getUsedHits();
33  data.NPEExpUncorr = ringPtr->getExpectedPhotoElectrons(false);
34  data.NPEMeasUncorr = ringPtr->getPhotoElectrons(false);
35  data.Probability = ringPtr->getProb();
36  data.RingPMTs = ringPtr->NpColPMT.size();
37  data.ChargeConsistency = ringPtr->getPMTChargeConsistency();
38 
39  FillHyp1Data(data, evPtr, ringPtr, trackPtr);
40  }
41 
42  m_data.push_back(data);
43 }
44 
45 void RichPlusData::FillHyp1Data(RichAdditionalData &data, AMSEventR *evPtr, RichRingR *ringPtr, TrTrackR *trackPtr) {
46  // get the PMT calibration, if available
47  RichPMTCalib *pmt_calib = (!m_isMC) ? RichPMTCalib::getHead() : nullptr;
48 
49  struct pmt_info {
50  int pmt = -1;
51  int nhit = 0;
52  float np = 0;
53  std::array<float, 3> coo{0, 0, 0};
54  float dist = 0;
55  };
56 
57  std::map<unsigned int, pmt_info> pmt_info_map;
58  std::vector<int> crossed_pmt[2]; // primary/secondary
59  std::vector<RichHitR *> rich_hit_on_ring_list;
60  std::map<int, RichHitR *> rich_hit_offline_map;
61 
62  // fill pmt info map
63  for (const RichHitR &hit : evPtr->RichHit()) {
64  int pmt = int(hit.Channel / 16);
65 
66  // discard bad PMTs
67  if ((pmt_calib) && (find(begin(pmt_calib->BadPMTs), end(pmt_calib->BadPMTs), pmt) != end(pmt_calib->BadPMTs)))
68  continue;
69 
70  float np = hit.Npe;
71  pmt_info_map[pmt].pmt = pmt;
72  pmt_info_map[pmt].nhit++;
73  pmt_info_map[pmt].np += np;
74  for (int icoo = 0; icoo < 3; icoo++)
75  pmt_info_map[pmt].coo[icoo] += np * hit.Coo[icoo];
76  }
77 
78  for (auto &it : pmt_info_map) {
79  for (int icoo = 0; icoo < 3; icoo++)
80  it.second.coo[icoo] /= it.second.np;
81  if (trackPtr) {
82  AMSPoint coo;
83  AMSDir dir;
84  trackPtr->Interpolate(it.second.coo[2], coo, dir);
85  it.second.dist = sqrt(pow(it.second.coo[0] - coo.x(), 2.) + pow(it.second.coo[1] - coo.y(), 2.));
86  }
87  if (it.second.np < 5)
88  continue;
89  crossed_pmt[(it.second.dist < 3.5) ? 0 : 1].push_back(it.first);
90  }
91  int index = 0;
92  std::vector<std::pair<int, pmt_info>> pmt_info_vec;
93  for (const auto &it : pmt_info_map) {
94  pmt_info_vec.emplace_back(it.first, it.second);
95  }
96  std::sort(begin(pmt_info_vec), end(pmt_info_vec),
97  [](const std::pair<int, pmt_info> &elem1, const std::pair<int, pmt_info> &elem2) {
98  return elem1.second.np > elem2.second.np;
99  });
100  std::array<float, 5> pmt_np_uncorr;
101  std::array<float, 5> pmt_dist;
102  for (const auto &it : pmt_info_vec) {
103  if (index > 4)
104  continue;
105  pmt_np_uncorr[index] = it.second.np;
106  pmt_dist[index] = it.second.dist;
107  index++;
108  }
109 
110  // selected ring
111  for (int ihit = 0; ihit < ringPtr->getUsedHits(false); ihit++)
112  rich_hit_on_ring_list.push_back(evPtr->pRichHit(ringPtr->iRichHit(ihit)));
113  // beta hypothesys
114  int which = 0;
115  for (RichOffline::RichRawEvent *hit = new RichOffline::RichRawEvent(evPtr); hit; hit = hit->next(), which++) {
116  rich_hit_offline_map.insert(std::make_pair(which, hit->getpointer()));
117  }
118  // loop on beta hypothesys
119  for (int i = 0; i < ringPtr->RawBetas(); i++) {
120  int ihit = ringPtr->HitBeta(i);
121  RichHitR *rich_hit = rich_hit_offline_map[ihit];
122  if (!rich_hit)
123  continue;
124 
125  int pmt = int(rich_hit->Channel / 16);
126  bool is_bad_pmt =
127  (pmt_calib) && (find(begin(pmt_calib->BadPMTs), end(pmt_calib->BadPMTs), pmt) != end(pmt_calib->BadPMTs));
128 
129  // we don't have the offline occupancy map used in the dbar analysis. Disable this for now
130  bool is_bad_occupancy = false;
131  // bool is_bad_occupancy = (pRichOcc) ? (!pRichOcc->IsGood(rich_hit->Channel)) : true;
132 
133  bool is_crossed_pri = find(begin(crossed_pmt[0]), end(crossed_pmt[0]), pmt) != end(crossed_pmt[0]);
134  bool is_crossed_sec = find(begin(crossed_pmt[1]), end(crossed_pmt[1]), pmt) != end(crossed_pmt[1]);
135  bool is_not_in_selected_ring =
136  (find(begin(rich_hit_on_ring_list), end(rich_hit_on_ring_list), rich_hit) == end(rich_hit_on_ring_list));
137  int status2 = ((is_bad_pmt) ? 0x1 : 0) + ((is_bad_occupancy) ? 0x2 : 0) + ((is_crossed_pri) ? 0x4 : 0) +
138  ((is_crossed_sec) ? 0x8 : 0) + ((is_not_in_selected_ring) ? 0x10 : 0);
139 
140  // integrate beta = 1 hypothesys with only good hits
141  if ((rich_hit->Status >> 31) & 0x1)
142  continue;
143  if ((status2 & 0xf) != 0)
144  continue;
145 
146  int kind_of_tile = ringPtr->IsNaF();
147  std::array<float, 2> simple_resolution{1.2e-3, 4e-3};
148  for (int ibeta = 0; ibeta < 2; ibeta++) {
149  if (std::fabs(ringPtr->RawBeta(i, ibeta) - 1) > 3. * simple_resolution[kind_of_tile])
150  continue;
151  data.NHitsHyp1Tot[ibeta]++;
152  if ((ringPtr->UsedBeta(i) < 0) || (ringPtr->UsedBeta(i) > 1)) {
153  data.NHitsHyp1OutOfRing[ibeta]++;
154  data.NPEHyp1UncorrTot += rich_hit->Npe;
155  }
156  }
157  }
158 
159  // Apparently re-clustering requires a valid TrTrackR. I don't know why
160  // this wasn't the case in the DBar ntuple
161  if (trackPtr) {
162  unsigned int nclus = ringPtr->ClusterizeZ1();
163  int dummy1;
164  float dummy2, mean;
165  if (nclus > 0) {
166  for (int iclu = 0; iclu < std::min(10u, nclus); iclu++) {
167  ringPtr->GetClusters(iclu, dummy1, mean, dummy2);
168  if (std::fabs(mean - ringPtr->getBeta()) > 0.01)
169  data.NBadClusters++;
170  }
171  }
172  }
173 
174  for (int is = 0; is < 5; is++) {
175  if ((pmt_np_uncorr[is] > 5) && (pmt_dist[is] > 3.5))
176  data.NSecondaryHits++;
177  }
178 }
179 
180 } // namespace NAIA
std::vector< RichAdditionalData > m_data
Definition: Rich.h:181
std::vector< std::pair< Rich::RichMeasType, RichBetaVariable< float > > > m_beta
Definition: Rich.h:93
RichMeasType
Definition: Utils.h:403
SingleTreeChain::EventItr end(SingleTreeChain &chain)
Rich container class description.
SingleTreeChain::EventItr begin(SingleTreeChain &chain)