Diana Software
MCoincidenceMultiplicity.cc
Go to the documentation of this file.
2 #include "QBaseType.hh"
3 #include "QError.hh"
4 #include "QEvent.hh"
5 #include "QRawEvent.hh"
6 #include "QRunDataHandle.hh"
7 #include "QDetChannelCollectionHandle.hh"
8 #include "QTime.hh"
9 #include <set>
10 #include <vector>
11 
13 
14 using std::set;
15 using std::vector;
16 
17 using namespace Diana;
18 
19 
21 {
22  if ( GetIteration() == 1 ) {
23  fCoincidenceWindow = GetDouble("CoincidenceWindow", 0.100);
24 
25  fUseRunningWindow = GetBool("UseRunningWindow", true);
26 
27 
28  fEnergyLabel = GetString("EnergyLabel","ApplyCalibration@Energy");
29 
30  fUseThermistorRanking = false;
31 
32  std::string tmp = GetString("ThermistorRankingLabel",Q_STRING_DEFAULT);
33  if(tmp != Q_STRING_DEFAULT) {
34  fThermistorRankingLabel = tmp;
35  fUseThermistorRanking = true;
36  }
37 
38  ev.Add<QInt>("Multiplicity");
39  ev.Add<QInt>("OrderInMultiple");
40  ev.Add<QDouble>("TotalEnergy");
41  ev.Add<QInt>("FirstEventNumber");
42 
43 
44  }
45  ev.Require<QPulseInfo>("DAQ","PulseInfo");
46  ev.Require<QHeader>("DAQ","Header");
47 }
48 
50 {
51 
52  const QPulseInfo& pulseInfo = ev.Get<QPulseInfo>("DAQ","PulseInfo");
53  const QHeader& header = ev.Get<QHeader>("DAQ","Header");
54 
55  const int& run = header.GetRun();
56  const int& channel = pulseInfo.GetChannelId();
57  const double time_sec = header.GetTime().GetFromStartRunNs() / 1e9;
58 
59  const double energy = ev.GetByLabel<QDouble>(fEnergyLabel);
60  const int& event_number = header.GetEventNumber();
61 
62  // fChannels will contain a list of the first channel number on each crystal
63  // If no ThermistorRankingVariable is specified in the cfg file, only
64  // channels in fChannels will be used to build multiple events.
65  if ( fChannels.empty() ) {
67  GlobalData().Get("",&rHandle,"");
68  vector<int> allChannels = rHandle.Get().fBolometerChannels;
69 
70  // as the fChannels vector is built up with, those channels and
71  // their relatives are put into this set to avoid putting any
72  // relatives into fChannels
73  set<int> channelsAndRelatives;
74  QDetChannelCollectionHandle dccHandle;
75  dccHandle.SetRun(run);
76  GlobalData().Get("",&dccHandle,"");
77 
78  for ( vector<int>::const_iterator ch = allChannels.begin();
79  ch != allChannels.end();
80  ++ch ) {
81  vector<int> relativeChannels = dccHandle.Get().GetRelativeChannels(channel);
82 
83  if ( channelsAndRelatives.count(*ch) == 0 ) {
84  fChannels.insert(*ch);
85  channelsAndRelatives.insert(*ch);
86  channelsAndRelatives.insert(
87  relativeChannels.begin(), relativeChannels.end()
88  );
89  }
90  }
91  }
92 
93  const bool useThermistorRankingVariable = fUseThermistorRanking;
94 
95  if ( GetIteration() == 1) {
96  bool useEvent = false;
97 
98  if (useThermistorRankingVariable) {
99  const int thermistorRanking= ev.GetByLabel<QInt>(fThermistorRankingLabel);
100 
101  if (thermistorRanking <= 1) {
102  useEvent = true;
103  }
104  }
105  else if ( fChannels.count(channel) != 0 ) {
106  useEvent = true;
107  }
108 
109  if (useEvent) {
110  EventInfo event;
111  event.fChannel = channel;
112  event.fEnergy = energy;
113  event.fEventNumber = event_number;
114  event.fTime = time_sec;
115 
116  fEventInfos.push_back(event);
117  fEventInfosIndex[event_number] = fEventInfos.size() - 1;
118  }
119  }
120  else if ( GetIteration() == 2 ) {
121  int multiplicity = -1;
122  int orderInMultiple = -1;
123  double totalEnergy = -1;
124  int firstEventNumber = -1;
125  if ( fEventInfosIndex.count(event_number) != 0 ) {
126  int index = fEventInfosIndex[event_number];
127 
128  multiplicity = fEventInfos[index].fMultiplicity;
129  orderInMultiple = fEventInfos[index].fOrderInMultiple;
130  totalEnergy = fEventInfos[index].fTotalEnergy;
131  firstEventNumber = fEventInfos[index].fFirstEventNumber;
132  }
133 
134  ev.Get<QInt>("Multiplicity") = multiplicity;
135  ev.Get<QInt>("OrderInMultiple") = orderInMultiple;
136  ev.Get<QInt>("FirstEventNumber") = firstEventNumber;
137  ev.Get<QDouble>("TotalEnergy") = totalEnergy;
138 
139 
140 
141  }
142 
143 }
144 
146 {
147  if ( GetIteration() == 1 ) {
148  int indexFirst = 0; // index of first event in mulitiple
149  int indexLast = 0; // index of last event in multiple
150  double DeltaT = 0;
151  for (int index = 0; index < (int) fEventInfos.size(); ++index) {
152 
153  if(fUseRunningWindow) {
154  DeltaT = fEventInfos[index].fTime
155  - fEventInfos[indexLast].fTime;
156  }
157  else {
158  DeltaT = fEventInfos[index].fTime
159  - fEventInfos[indexFirst].fTime;
160  }
161 
162  if (DeltaT < fCoincidenceWindow) {
163  indexLast = index;
164  }
165  else {
166  double totalEnergy = 0;
167  for (int i = indexFirst; i <= indexLast; ++i) {
168  totalEnergy += fEventInfos[i].fEnergy;
169  }
170 
171  int order = 1;
172  for (int i = indexFirst; i <= indexLast; ++i) {
173  fEventInfos[i].fMultiplicity = indexLast - indexFirst + 1;
174  fEventInfos[i].fOrderInMultiple = order;
175  ++order;
176  fEventInfos[i].fFirstEventNumber
177  = fEventInfos[indexFirst].fEventNumber;
178  fEventInfos[i].fTotalEnergy = totalEnergy;
179  }
180 
181  indexFirst = index;
182  indexLast = index;
183  }
184  }
185 
186  // handle last event(s)
187  double totalEnergy = 0;
188  for (int i = indexFirst; i <= indexLast; ++i) {
189  totalEnergy += fEventInfos[i].fEnergy;
190  }
191 
192  int order = 1;
193  for (int i = indexFirst; i <= indexLast; ++i) {
194  fEventInfos[i].fMultiplicity = indexLast - indexFirst + 1;
195  fEventInfos[i].fOrderInMultiple = order;
196  ++order;
197  fEventInfos[i].fFirstEventNumber
198  = fEventInfos[indexFirst].fEventNumber;
199  fEventInfos[i].fTotalEnergy = totalEnergy;
200  }
201 
202  SetRunAgain(true);
203  }
204 }
205 
QRunDataHandle rHandle(753)
const int channel
#define Q_STRING_DEFAULT
Definition: QDiana.hh:38
#define REGISTER_MODULE(clazz)
Definition: QDriver.hh:133
Puts multiplicities and total energies in events.
void Do(Diana::QEvent &ev)
Do method.
base types wrapped into a QObject. Currently implemented types are QInt QDouble and QFloat....
Definition: QBaseType.hh:17
diana event
Definition: QEvent.hh:46
const Q & GetByLabel(const QEventLabel &label) const
Get a QObject in read mode by label.
Definition: QEvent.hh:135
void Require(const std::string &owner, const std::string &name) const
notify the QEvent that we need a QObject, if not found an exception is thrown
Definition: QEvent.hh:232
void Get(const char *owner, ReadHandle< Q > &handle) const
Get a QObject Handle in read mode.
Definition: QEvent.hh:74
void Add(WriteHandle< Q > &handle)
Add a QObject to the event.
Definition: QEvent.hh:193
Raw event: basic information like run number and time.
Definition: QHeader.hh:16
int GetRun() const
destructor
Definition: QHeader.hh:22
Raw event: bolometer channel, trigger positions and types.
Definition: QPulseInfo.hh:18
const int & GetChannelId() const
Get ChannelId.
Definition: QPulseInfo.hh:22
global handle for QRunData
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...