ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtTrigger.cxx
Go to the documentation of this file.
1 #include "AtTrigger.h"
2 
3 // IWYU pragma: no_include <ext/alloc_traits.h>
4 
5 #include "AtEvent.h"
6 #include "AtPad.h"
7 #include "AtRawEvent.h"
8 
9 #include <Rtypes.h>
10 #include <TMatrixDfwd.h>
11 #include <TMatrixT.h>
12 #include <TString.h>
13 
14 #include <algorithm>
15 #include <array>
16 #include <cmath>
17 #include <cstring>
18 #include <iostream>
19 #include <string>
20 
22 
23  AtTrigger::AtTrigger() = default;
24 
25 AtTrigger::~AtTrigger() = default;
26 
27 void AtTrigger::SetAtMap(TString mapPath)
28 {
29  std::ifstream file;
30  file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
31 
32  try {
33  file.open(mapPath);
34 
35  Int_t nLines = 0;
36  Int_t nPoints = 0;
37 
38  while (!file.eof()) {
39  // read a single line
40  std::string line;
41  std::getline(file, line);
42 
43  try {
44  Float_t CoboNum, asad, aget, channel, pad;
45  Int_t intCoboNum, intpad;
46 
47  // read with default seperator (space) seperated elements
48  std::istringstream iss(line);
49  iss.exceptions(std::ifstream::failbit | std::ifstream::badbit);
50  iss >> CoboNum >> asad >> aget >> channel >> pad;
51  if (CoboNum > 11 && CoboNum < 0)
52  break;
53  intCoboNum = (int)CoboNum;
54  intpad = (int)pad;
55  fCoboNumArray[intpad] = intCoboNum;
56 
57  // if(nLines<5)
58  // std::cout<< "Pad: "<<intpad<<" CoboNum: " << fCoboNumArray[intpad]<< std::endl;
59  // printf("Successfully read point: CoboNum=%8f, asad=%8f, aget=%8f, channel=%8f, pad=%8f\n", CoboNum, asad,
60  // aget, channel, pad);
61 
62  ++nPoints;
63  } catch (...) {
64  std::cout << "Malformed point in line " << (nLines + 1) << "!" << std::endl;
65  }
66 
67  ++nLines;
68  }
69 
70  file.close();
71 
72  std::cout << "Successfully read " << nPoints << " points in " << nLines << " lines!" << std::endl;
73  } catch (...) {
74  // std::cout <<cGREEN<< "Something bad happened while reading "<<mapPath<<"!" <<cNORMAL<< std::endl;
75  }
76 }
77 
78 void AtTrigger::SetTriggerParameters(Double_t read, Double_t write, Double_t MSB, Double_t LSB, Double_t width,
79  Double_t fraction, Double_t threshold, Double_t window, Double_t height)
80 {
81 
82  fMultiplicity_threshold = threshold;
83  fMultiplicity_window = window;
84  fTrigger_height = height;
85 
86  fTime_factor = read / write;
87  fTrigger_width = width * write;
88  fPad_threshold = ((MSB * pow(2, 4) + LSB) / 128) * fraction * 4096;
90  std::cout << "==== Parameters for Trigger======" << std::endl;
91  std::cout << " === Time Factor: " << fTime_factor << std::endl;
92  std::cout << " === Trigger Width: " << fTrigger_width << " us?" << std::endl;
93  std::cout << " === Pad Threshold: " << fPad_threshold << std::endl;
94  std::cout << " === Time Window: " << fTime_window << " timebuckets" << std::endl;
95  std::cout << " === Multiplicity Threshold: " << fMultiplicity_threshold << std::endl;
96 }
97 
99 {
100 
101  fEvent = event;
102  fRawEvent = rawEvent;
103  fTrigger = kFALSE;
104 
105  TMatrixD triggerSignal(10, 512); // The trigger signal is a vector with 522 positions. The first 10 one will be
106  // filled with CoBo number and the rest will be the trigger signal. [(0,10),(0,512)]
107  TMatrixD result(10, 512);
108 
109  Int_t numHits = fEvent->GetNumHits();
110 
111  // Loop over the NUMBER of SIGNALS in the EVENT
112  for (Int_t iHit = 0; iHit < numHits; iHit++) {
113  fHit = *fEvent->GetHits().at(iHit);
114  Int_t PadNumHit = fHit.GetPadNum();
115 
116  fPad = fRawEvent->GetPad(PadNumHit);
117  if (fPad == nullptr)
118  continue;
119 
120  auto fRawAdc = fPad->GetADC();
121  fPadNum = fPad->GetPadNum();
122 
123  //*************************************************************************************************
124  // Calculation of the trigger signal for the given event.
125  // Any time the input signal rises above the threshold value, a trigger signal is generated by the AGET for the
126  // corresponding channel.
127  //*************************************************************************************************
128 
129  double trigSignal[512]; // Empty Trigger Signal for each signal of the event
130  fTbIdx = 0;
131  memset(trigSignal, 0, sizeof(trigSignal));
132 
133  while (fTbIdx < 512) {
134  if (fRawAdc[fTbIdx] > fPad_threshold) {
135  for (Int_t ii = fTbIdx; ii < std::min(fTbIdx + fTrigger_width, 512.); ii++) {
136  trigSignal[ii] += fTrigger_height;
137  }
139 
140  }
141 
142  else
143  fTbIdx += 1;
144 
145  } // While
146 
148 
149  for (Int_t j = 0; j < 512; j++) {
150 
151  if (trigSignal[j] > 0) {
152  // std::cout<< "TrigSignal: "<< trigSignal[j] << std::endl;
153  triggerSignal(fCobo, j) = trigSignal[j];
154  } // Positive signal if
155 
156  } // 3rd foor loop
157  triggerSignal(fCobo, 0) = fCobo;
158 
159  //*******************************************************************************************************************************
160  // Calculation of the multiplicity signals from the trigger signals.
161  // Each AGET sums the trigger signals from its channels and outputs this trigger multiplicity to the ADC.
162  // Then the CoBo sums this digitalized multiplicity signals from the AGETs and integrates this signal over a
163  // sliding time window. The input of this part will be the triggerSignals calculated before, and the output will
164  // be the multiplicity signals.
165  //********************************************************************************************************************************
166 
167  for (Int_t l = 0; l < 512; l++) {
168  Int_t triggerWindow = l - fTime_window;
169  fMinIdx = std::max(0, triggerWindow);
170  fMaxIdx = l;
171 
172  for (Int_t ll = 0; ll < 10; ll++) {
173  fAccum = 0;
174  result(ll, 0) = fCobo;
175  for (Int_t jj = fMinIdx; jj < fMaxIdx; jj++) {
176  fAccum += triggerSignal(ll, jj);
177  }
178  result(ll, l) = fAccum * fTime_factor;
179 
180  } // ll for
181 
182  } // l for
183 
184  //*************************************************************************************************
185  // Determines if the given multiplicity signals rose above the multiplicity threshold in any CoBo.
186  //*************************************************************************************************
187 
188  for (Int_t kk = 0; kk < 10; kk++) {
189  if (kk == fCobo) {
190  for (Int_t k = 0; k < 512; k++) {
191  if (result(kk, k) > fMultiplicity_threshold) {
192  fTrigger = kTRUE;
193  }
194  }
195  }
196  }
197 
198  } // Loop on entries of the event
199  return fTrigger;
200 }
AtTrigger
Definition: AtTrigger.h:22
AtTrigger::fTime_factor
Double_t fTime_factor
Definition: AtTrigger.h:41
AtPad.h
AtTrigger::fTrigger
Bool_t fTrigger
Definition: AtTrigger.h:62
AtEvent::GetNumHits
Int_t GetNumHits() const
Definition: AtEvent.h:108
AtRawEvent.h
AtEvent.h
AtRawEvent::GetPad
AtPad * GetPad(Int_t padNum)
Definition: AtRawEvent.h:124
AtTrigger::fEvent
AtEvent * fEvent
Definition: AtTrigger.h:47
AtTrigger::fMinIdx
Int_t fMinIdx
Definition: AtTrigger.h:59
ClassImp
ClassImp(AtFindVertex)
AtTrigger::fMultiplicity_threshold
Double_t fMultiplicity_threshold
Definition: AtTrigger.h:38
AtTrigger::fAccum
Int_t fAccum
Definition: AtTrigger.h:61
AtTrigger::fRawEvent
AtRawEvent * fRawEvent
Definition: AtTrigger.h:46
AtEvent
Definition: AtEvent.h:22
AtRawEvent
Definition: AtRawEvent.h:34
AtTrigger::fHit
AtHit fHit
Definition: AtTrigger.h:48
AtTrigger::fPadNum
Int_t fPadNum
Definition: AtTrigger.h:36
AtTrigger::fCoboNumArray
Int_t fCoboNumArray[10240]
Definition: AtTrigger.h:53
AtTrigger::fPad
AtPad * fPad
Definition: AtTrigger.h:49
AtEvent::GetHits
const HitVector & GetHits() const
Definition: AtEvent.h:116
AtTrigger::SetAtMap
void SetAtMap(TString mapPath)
Definition: AtTrigger.cxx:27
AtTrigger::fTbIdx
Int_t fTbIdx
Definition: AtTrigger.h:51
AtTrigger::fMultiplicity_window
Double_t fMultiplicity_window
Definition: AtTrigger.h:39
AtTrigger::fTime_window
Double_t fTime_window
Definition: AtTrigger.h:44
AtPad::GetPadNum
Int_t GetPadNum() const
Definition: AtPad.h:96
AtPad::GetADC
const trace & GetADC() const
Definition: AtPad.cxx:97
AtTrigger::fCobo
Int_t fCobo
Definition: AtTrigger.h:52
AtTrigger::AtTrigger
AtTrigger()
AtTrigger::fTrigger_width
Double_t fTrigger_width
Definition: AtTrigger.h:42
AtTrigger::fPad_threshold
Double_t fPad_threshold
Definition: AtTrigger.h:43
AtTrigger::ImplementTrigger
Bool_t ImplementTrigger(AtRawEvent *rawEvent, AtEvent *event)
Definition: AtTrigger.cxx:98
AtTrigger::~AtTrigger
~AtTrigger()
AtTrigger::fMaxIdx
Int_t fMaxIdx
Definition: AtTrigger.h:60
AtTrigger::fTrigger_height
Double_t fTrigger_height
Definition: AtTrigger.h:40
AtHit::GetPadNum
Int_t GetPadNum() const
Definition: AtHit.h:83
AtTrigger.h
AtTrigger::SetTriggerParameters
void SetTriggerParameters(Double_t read, Double_t write, Double_t MSB, Double_t LSB, Double_t width, Double_t fraction, Double_t threshold, Double_t window, Double_t height)
Definition: AtTrigger.cxx:78