Diana Software
MCoincidenceMultiplicity.cc
Go to the documentation of this file.
2 #include "QCalibData.hh"
3 #include "QDbDetector.hh"
4 #include "QError.hh"
5 #include "QEvent.hh"
6 #include "QFiltersData.hh"
7 #include "QMainPulse.hh"
8 #include "QRawEvent.hh"
9 #include "QTime.hh"
10 #include <set>
11 #include <vector>
12 
14 
15 using std::set;
16 using std::vector;
17 
19  : QModule("CoincidenceMultiplicity",s)
20 {
21 }
22 
24 {
25 }
26 
28 {
29  if ( GetIteration() == 1 ) {
30  fCoincidenceWindow = GetDouble("CoincidenceWindow", 0.100);
31 
32  fUseRunningWindow = GetBool("UseRunningWindow", true);
33 
34  fRelativeChannelsSource = GetString("RelativeChannelsSource",
36 
37  fThermistorRankingVariable = GetString("ThermistorRankingVariable",
38  Q_STRING_DEFAULT, false);
39 
40  fPrefix = GetString("AuxDataPrefix", "", false);
41  }
42 }
43 
45 {
46  const QRawEvent& rawEvent = ev->GetRawEvent();
47 
48  const int& channel = rawEvent.GetPulse().GetChannelId();
49  const int& run = rawEvent.GetRun();
50  const int& event_number = rawEvent.GetEventNumber();
51  const double& time_sec = rawEvent.GetTime().GetFromStartRunNs() / 1e9;
52  const double& energy = ev->GetCalib().GetEnergy();
53 
54  // fChannels will contain a list of the first channel number on each crystal
55  // If no ThermistorRankingVariable is specified in the cfg file, only
56  // channels in fChannels will be used to build multiple events.
57  if ( fChannels.empty() ) {
58  vector<int> allChannels( QDbDetector::ActiveChannelList(run) );
59 
60  set<int> channelsAndRelatives;
61  // as the fChannels vector is built up with, those channels and
62  // their relatives are put into this set to avoid putting any
63  // relatives into fChannels
64 
65  for ( vector<int>::const_iterator ch = allChannels.begin();
66  ch != allChannels.end();
67  ++ch ) {
68  vector<int> relativeChannels;
69  if (fRelativeChannelsSource != "NONE") {
70  // by specifying RelativeChannelsSource = NONE in the cfg file,
71  // one allows events on relative channels to be considered
72  // multiple events
73  try {
74  relativeChannels = QDbDetector::GetRelativeChannels(
75  run,
76  *ch,
78  );
79  }
80  catch (const QError& err) {
81  Warn( err.GetDescription().c_str() );
82  }
83  }
84 
85  if ( channelsAndRelatives.count(*ch) == 0 ) {
86  fChannels.insert(*ch);
87  channelsAndRelatives.insert(*ch);
88  channelsAndRelatives.insert(
89  relativeChannels.begin(), relativeChannels.end()
90  );
91  }
92  }
93  }
94 
95  const bool useThermistorRankingVariable
97 
98  if ( GetIteration() == 1 && ev->GetFilters().GetPassed() ) {
99  bool useEvent = false;
100 
101  if (useThermistorRankingVariable) {
102  const int thermistorRanking
103  = ev->AuxData().GetInt(fThermistorRankingVariable);
104  if (thermistorRanking <= 1) {
105  useEvent = true;
106  }
107  }
108  else if ( fChannels.count(channel) != 0 ) {
109  useEvent = true;
110  }
111 
112  if (useEvent) {
113  EventInfo event;
114  event.fChannel = channel;
115  event.fEnergy = energy;
116  event.fEventNumber = event_number;
117  event.fTime = time_sec;
118 
119  fEventInfos.push_back(event);
120  fEventInfosIndex[event_number] = fEventInfos.size() - 1;
121  }
122  }
123  else if ( GetIteration() == 2 ) {
124  int multiplicity = -1;
125  int orderInMultiple = -1;
126  double totalEnergy = -1;
127  int firstEventNumber = -1;
128  if ( fEventInfosIndex.count(event_number) != 0 ) {
129  int index = fEventInfosIndex[event_number];
130 
131  multiplicity = fEventInfos[index].fMultiplicity;
132  orderInMultiple = fEventInfos[index].fOrderInMultiple;
133  totalEnergy = fEventInfos[index].fTotalEnergy;
134  firstEventNumber = fEventInfos[index].fFirstEventNumber;
135  }
136  ev->AuxData().SetInt(fPrefix + "Multiplicity", multiplicity, "save");
137  ev->AuxData().SetInt(fPrefix + "OrderInMultiple", orderInMultiple,
138  "save");
139  ev->AuxData().SetDouble(fPrefix + "TotalEnergy", totalEnergy,
140  "save");
141  ev->AuxData().SetInt(fPrefix + "FirstEventNumber", firstEventNumber,
142  "save");
143  }
144  return ev;
145 }
146 
148 {
149  if ( GetIteration() == 1 ) {
150  int indexFirst = 0; // index of first event in mulitiple
151  int indexLast = 0; // index of last event in multiple
152  double DeltaT = 0;
153  for (int index = 0; index < (int) fEventInfos.size(); ++index) {
154 
155  if(fUseRunningWindow) {
156  DeltaT = fEventInfos[index].fTime
157  - fEventInfos[indexLast].fTime;
158  }
159  else {
160  DeltaT = fEventInfos[index].fTime
161  - fEventInfos[indexFirst].fTime;
162  }
163 
164  if (DeltaT < fCoincidenceWindow) {
165  indexLast = index;
166  }
167  else {
168  double totalEnergy = 0;
169  for (int i = indexFirst; i <= indexLast; ++i) {
170  totalEnergy += fEventInfos[i].fEnergy;
171  }
172 
173  int order = 1;
174  for (int i = indexFirst; i <= indexLast; ++i) {
175  fEventInfos[i].fMultiplicity = indexLast - indexFirst + 1;
176  fEventInfos[i].fOrderInMultiple = order;
177  ++order;
178  fEventInfos[i].fFirstEventNumber
179  = fEventInfos[indexFirst].fEventNumber;
180  fEventInfos[i].fTotalEnergy = totalEnergy;
181  }
182 
183  indexFirst = index;
184  indexLast = index;
185  }
186  }
187 
188  // handle last event(s)
189  double totalEnergy = 0;
190  for (int i = indexFirst; i <= indexLast; ++i) {
191  totalEnergy += fEventInfos[i].fEnergy;
192  }
193 
194  int order = 1;
195  for (int i = indexFirst; i <= indexLast; ++i) {
196  fEventInfos[i].fMultiplicity = indexLast - indexFirst + 1;
197  fEventInfos[i].fOrderInMultiple = order;
198  ++order;
199  fEventInfos[i].fFirstEventNumber
200  = fEventInfos[indexFirst].fEventNumber;
201  fEventInfos[i].fTotalEnergy = totalEnergy;
202  }
203 
204  SetRunAgain(true);
205  }
206 }
207 
err
Definition: CheckOF.C:114
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.
std::set< int > fChannels
List of channels to use.
std::string fPrefix
AuxData variable prefix string.
std::string fRelativeChannelsSource
Source file name or 'DB' for relative channels.
std::string fThermistorRankingVariable
AuxData variable containing thermistor rankings.
std::map< int, int > fEventInfosIndex
map from EventNumber to fEventInfos index
std::vector< EventInfo > fEventInfos
time ordered vector of event info
bool fUseRunningWindow
Flag to use running or fixed window.
void Do(Diana::QEvent &ev)
Do method.
double fCoincidenceWindow
Maximum time (in seconds) between coincident events.
MCoincidenceMultiplicity(QSequence *s)
constructor
const std::string & GetString(const std::string &parname, const std::string &defVal, bool warnCfg=true) const
Get a string parameter from config file ( see GetDouble() )
Definition: QBaseModule.cc:297
void Warn(const char *descr,...) const
Send a warning message (an error that the framework can recover) with printf syntax.
Definition: QBaseModule.hh:228
unsigned int GetIteration() const
Get Current sequence iteration.
Definition: QBaseModule.hh:122
double GetDouble(const std::string &parname, double defVal, bool warnCfg=true) const
Get a double parameter from config file.
Definition: QBaseModule.cc:184
bool GetBool(const std::string &parname, bool defVal, bool warnCfg=true) const
Get a bool parameter from config file ( see GetDouble() )
Definition: QBaseModule.cc:256
void SetRunAgain(bool b)
Set that the sequence will be reiterated.
Definition: QBaseModule.hh:120
error class with error type and description
Definition: QError.hh:115
diana event
Definition: QEvent.hh:46
Base class for diana modules.
Definition: QModule.hh:54
Diana Reconstruction program.
Definition: QSequence.hh:40