Diana Software
MAlphaDelayedCoincidence.cc
Go to the documentation of this file.
2 #include "QEvent.hh"
3 #include "QRawEvent.hh"
4 #include "QCoincidenceData.hh"
5 #include "QBaseType.hh"
6 #include "QOFData.hh"
7 #include "QMatrix.hh"
8 #include "QDetChannelCollectionHandle.hh"
9 #include <cmath>
10 
11 
12 using namespace Diana;
13 using namespace std;
14 
16 
17 
19 {
20  // called before event loop
21  fEnergyLabel = GetString("EnergyLabel","ApplyCalibration@Energy");
22 
23  vector<string> defaults;
24  fPSALabels = GetVectorString("PSALabels",defaults);
25  fCoincidenceDataOwner = GetString("CoincidenceDataOwner","Coincidence",false);
26  fMotherSelectionLabel = GetString("MotherSelectionLabel",Q_STRING_DEFAULT);
27  fDaughterSelectionLabel = GetString("DaughterSelectionLabel",Q_STRING_DEFAULT);
28  // events flagged as mother nuclides
29  ev.Add<QCoincidenceData>("CoincidenceData");
30  ev.RequireByLabel<QBool>(fMotherSelectionLabel);
31  ev.RequireByLabel<QBool>(fDaughterSelectionLabel);
32  if(!fPSALabels.empty()) {
33  for(size_t p = 0; p < fPSALabels.size(); p++) {
34  ev.RequireByLabel<QDouble>(fPSALabels[p]);
35  }
36  }
37 
38  GetBool("SkipEvents",false,false);
39 
40 }
41 
43 {
44  const bool isMother = ev.GetByLabel<QBool>(fMotherSelectionLabel);
45  const bool isDaughter = ev.GetByLabel<QBool>(fDaughterSelectionLabel);
46  if(!isMother && !isDaughter) return;
47 
48  // get info on this event
49  const QHeader& hdr = ev.Get<QHeader>("DAQ","Header");
50  const QPulseInfo& pi = ev.Get<QPulseInfo>("DAQ","PulseInfo");
51  const int run = hdr.GetRun();
52  const int chan = pi.GetChannelId();
53  QDetChannelCollectionHandle dccHandle;
54  dccHandle.SetRun(run);
55  GlobalData().Get("",&dccHandle,"");
56  int floor = dccHandle.Get().Get(chan).fTd.fTdFloor;
57  const QCoincidenceData& coincData = ev.Get<QCoincidenceData>(fCoincidenceDataOwner.c_str(),"CoincidenceData");
58  const double time = ev.Get<QDouble>(fCoincidenceDataOwner.c_str(),"Time");
59 
60  // Act on this event as daughter
61 
62  if(isDaughter){
63  // reset data related to mothers
64  QCoincidenceData& backData = ev.Get<QCoincidenceData>("CoincidenceData");
65  backData.fOrderInMultiple = -1; // meaningless
66  backData.fMultiplicity = 1;
67  backData.fCoincidentChannels.clear();
68  backData.fNearestCoincidentIndex = 0;
69  backData.fFarthestCoincidentIndex = 0;
70 
71  // look for mothers of this multiplet closest, with time precedence
72  std::map<double,int>::reverse_iterator timeOrderedFloorIter = fTimeOrderedFloors.rbegin();
73  while(timeOrderedFloorIter != fTimeOrderedFloors.rend()) {
74  const int o_floor = timeOrderedFloorIter->second;
75  const double deltaT = timeOrderedFloorIter->first-time;
76  // veto 2 seconds
77  if(fabs(deltaT) < 2.) {
78  timeOrderedFloorIter++;
79  continue;
80  }
81  int deltaFloor = o_floor-floor;
82 
83  // in case this event is a multiplet, check whether deltaFloor
84  // of an event in the multiplet is smaller than 3
85  const std::vector<QCoincidentChannel>& multChannels = coincData.fCoincidentChannels;
86  int numMultChannels = multChannels.size();
87  int countMultChannels = numMultChannels;
88  while(abs(deltaFloor) > 2 && countMultChannels>0) {
89  const QCoincidentChannel& multChannel = multChannels[numMultChannels-countMultChannels];
90  deltaFloor = o_floor-(floor+multChannel.fDeltaFloor);
91  countMultChannels--;
92  }
93 
94  if(abs(deltaFloor) <=2) {
95  // store in this event the info of the back alpha(s)
96  QCoincidentChannel backCoinc = fFloors[o_floor];
97  backCoinc.fDeltaT -= time;
98  backCoinc.fDeltaFloor = deltaFloor;
99  backData.fMultiplicity++;
100  backData.fCoincidentChannels.push_back(backCoinc);
101  backData.fFarthestCoincidentIndex = backData.fMultiplicity-2;
102  }
103  timeOrderedFloorIter++;
104  }
105  }
106 
107  // Act on this event as mother
108 
109  if(isMother && coincData.fMultiplicity <= 2 ) {
110  const double total_energy = ev.Get<QDouble>(fCoincidenceDataOwner.c_str(),"TotalEnergy");
111  QCoincidentChannel backChannel;
112  backChannel.fChannelId = chan;
113  backChannel.fDeltaT = time;
114  backChannel.fEnergy = total_energy;
115  for(size_t p = 0; p < fPSALabels.size(); p++) {
116  backChannel.fPSAVariables.push_back(ev.GetByLabel<QDouble>(fPSALabels[p]));
117  }
118  backChannel.fDeltaFloor = -1;
119  backChannel.fDeltaPosition = -1;
120  if(coincData.fMultiplicity == 1) {
121  fFloors[floor] = backChannel;
122  } else if(coincData.fMultiplicity == 2) {
123  const double energy = ev.GetByLabel<QDouble>(fEnergyLabel);
124  const double energy2 = coincData.fCoincidentChannels[0].fEnergy;
125  // the crystal with less energy contains the contamination so we save only this among the two
126  if(energy < energy2) {
127  fFloors[floor] = backChannel;
128  }
129  }
130  // update time ordering of floors
131  fTimeOrderedFloors.clear();
132  std::map<int,QCoincidentChannel>::const_iterator floorIter = fFloors.begin();
133  while(floorIter != fFloors.end()) {
134  const int backFloor = floorIter->first;
135  const double backTime = floorIter->second.fDeltaT;
136  fTimeOrderedFloors[backTime] = backFloor;
137  floorIter++;
138  }
139  }
140  return;
141 }
142 
144 {
145  // called at the end of the event loop
146 }
#define Q_STRING_DEFAULT
Definition: QDiana.hh:38
#define REGISTER_MODULE(clazz)
Definition: QDriver.hh:133
Diana::QVector abs(const Diana::QVector &v)
Definition: QVector.cc:811
module to tag delayed coincidences.
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
bool wrapped into a QObject
Definition: QBool.hh:17
coincidence data
std::vector< QCoincidentChannel > fCoincidentChannels
data of coincident channel
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 Get(const char *owner, ReadHandle< Q > &handle) const
Get a QObject Handle in read mode.
Definition: QEvent.hh:74
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
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...