FairRoot/PandaRoot
PndEmcHighLowPSA.cxx
Go to the documentation of this file.
1 #include "PndEmcHighLowPSA.h"
2 #include "PndEmcWaveform.h"
3 #include "PndEmcMultiWaveform.h"
5 
6 #include <iostream>
7 
8 
9 PndEmcHighLowPSA::PndEmcHighLowPSA(Int_t verbose) : fHighgainPSA(NULL), fLowgainPSA(NULL),fVerbose(verbose) {
10 };
11 
12 void PndEmcHighLowPSA::Init(PndEmcPSAFPGASampleAnalyser* highgainPSA, PndEmcPSAFPGASampleAnalyser* lowgainPSA, Double_t overflowThreshold, Int_t highgainWfIndex, Int_t lowgainWfIndex) {
13  fHighgainPSA = highgainPSA;
14  fLowgainPSA = lowgainPSA;
15  fIdx_high = highgainWfIndex;
16  fIdx_low = lowgainWfIndex;
17  fOverflowThreshold = overflowThreshold;
18 }
19 
21  //fActivePSA=0;
22  fHitsInFE.clear();
24  fLowgainPSA->Reset();
25 }
26 
27 
28 Int_t PndEmcHighLowPSA::Process(const PndEmcWaveform* waveform) {
29 
30  Reset();
31 
32  PndEmcMultiWaveform* multiWf = const_cast<PndEmcMultiWaveform*>(dynamic_cast<const PndEmcMultiWaveform*>(waveform));
33 
34  if(!multiWf) {
35  std::cerr << "passed waveform is not of type PndEmcMultiwaveform" << std::endl;
36  return -1;
37  }
38 
39  //active method
40 
41  Int_t activeWf = multiWf->GetActiveWaveform();
42 
43  multiWf->SetActiveWaveform(fIdx_low);
44  std::vector<double> signal_low = waveform->GetSignal();
45  std::vector<double>::iterator it_low=signal_low.begin();
46 
47  multiWf->SetActiveWaveform(fIdx_high);
48  std::vector<double> signal_high = waveform->GetSignal();
49  std::vector<double>::iterator it_high=signal_high.begin();
50 
51  multiWf->SetActiveWaveform(activeWf);
52 
53  bool active_high = false;
54  bool active_low = false;
55 
56  Int_t counter_low=0;
57  Int_t counter_high=0;
58 
61 
62  std::set<Int_t> hits_lowgain;
63  bool overflow = false;
64 
65  while(it_low!=signal_low.end() && it_high!=signal_high.end()) {
66 
67  fHighgainPSA->put(*it_high);
68  fLowgainPSA->put(*it_low);
69  status_high = fHighgainPSA->GetStatus();
70  status_low = fLowgainPSA->GetStatus();
71 
73  active_high = false;
74  if(!overflow) {
75  fHitsInFE.push_back(std::make_pair(fHighgainPSA, counter_high));
76  if(fVerbose>=2) {
77  std::cout << "I- PndEmcHighLowPSA: adding highgain hit: #:"<< counter_high << std::endl;
78  }
79  }
80  counter_high++;
81  } else if(status_high==PndEmcPSAFPGASampleAnalyser::kPileupFinished) {
82  active_high = false;
83  if(!overflow) {
84  fHitsInFE.push_back(std::make_pair(fHighgainPSA, counter_high));
85  fHitsInFE.push_back(std::make_pair(fHighgainPSA, counter_high+1));
86  if(fVerbose>=2) {
87  //std::cout << "I- PndEmcHighLowPSA: adding highgain hits #:" << counter_high << "," << counter_high++ << std::endl; //FIXME Implicit operation is bad style!
88  std::cout << "I- PndEmcHighLowPSA: adding highgain hits #:" << counter_high << ",";
89  counter_high++; // [R.K. 9/2018] made implicit operation explicit
90  std::cout << counter_high << std::endl;
91  }
92  }
93  counter_high+=2;
94  } else if(status_high==PndEmcPSAFPGASampleAnalyser::kPulseDetected) {
95  active_high = true;
96  }
97 
98  if(active_high && ((*it_high) > fOverflowThreshold) && !overflow) {
99  if(fVerbose>=2) {
100  std::cout << "I- PndEmcHighLowPSA: overflow detected" << std::endl;
101  }
102  overflow = true;
103  }
104 
106  hits_lowgain.insert(counter_low);
107  counter_low++;
108  active_low = false;
109  } else if(status_low==PndEmcPSAFPGASampleAnalyser::kPileupFinished) {
110  if(fVerbose>=3) {
111  std::cout << "I- PndEmcHighLowPSA: pileup in lowgain candidate: #" << counter_low << ", #" << counter_low+1 << std::endl;
112  }
113  hits_lowgain.insert(counter_low);
114  hits_lowgain.insert(counter_low+1);
115  counter_low+=2;
116  active_low = false;
117  } else if(status_low==PndEmcPSAFPGASampleAnalyser::kPulseDetected) {
118  active_low = true;
119  }
120 
121  if((!active_high) && (!active_low)) {
122  if(overflow) {
123  if(fVerbose>=2) {
124  std::cout << "I- PndEmcHighLowPSA: adding lowgain hit(s) #:";
125  for(std::set<Int_t>::iterator it=hits_lowgain.begin(); it!=hits_lowgain.end(); ++it) {
126  std::cout << *it << ",";
127  }
128  std::cout << "\b\n" << std::flush;
129  }
130  for(std::set<Int_t>::iterator it=hits_lowgain.begin(); it!=hits_lowgain.end(); ++it) {
131  fHitsInFE.push_back(std::make_pair(fLowgainPSA, *it));
132  }
133  }
134  hits_lowgain.clear();
135  overflow = false;
136  }
137  it_low++;
138  it_high++;
139  }
140 
141  return fHitsInFE.size();
142 }
143 
144 
146 
148  if(psa!=NULL) {
149  psa->GetHit(fHitsInFE[i].second, energy, time);
150  } else {
151  //std::cerr << "-E PndEmcHighLowPSA::GetHit: No suitable PSA available" << std::cout;
152  energy = 0;
153  time = 0;
154  }
155 
156 }
157 
159 
160  if(i<(int)fHitsInFE.size() && i>=0) {
162  if(psa==fHighgainPSA) return fIdx_high;
163  else if(psa==fLowgainPSA) return fIdx_low;
164  }
165 
166  return -1; //error
167 }
168 
169 
PndEmcPSAFPGASampleAnalyser * fHighgainPSA
virtual void GetHit(Int_t i, Double_t &energy, Double_t &time)
Get energy and time of hit.
int fVerbose
Definition: poormantracks.C:24
std::vector< std::pair< PndEmcPSAFPGASampleAnalyser *, int > > fHitsInFE
virtual std::vector< double > GetSignal() const
Int_t i
Definition: run_full.C:25
virtual void put(float valueToStore)=0
#define verbose
PndEmcHighLowPSA(Int_t verbose=0)
virtual void GetHit(Int_t i, Double_t &energy, Double_t &time)
Get energy and time of hit.
virtual void Init(PndEmcPSAFPGASampleAnalyser *highgainPSA, PndEmcPSAFPGASampleAnalyser *lowgainPSA, Double_t overflowThreshold, Int_t highgainWfIndex=0, Int_t lowgainWfIndex=1)
Double_t
virtual void Reset()
reset found hits
virtual void Reset()
reset found hits
virtual Int_t Process(const PndEmcWaveform *waveform)
Find Hits in Waveform.
represents a simulated waveform in an emc crystal
Class to hold multiple waveforms from one Emc Hit / ADC readout.
Int_t GetActiveWaveform() const
Double_t fOverflowThreshold
virtual Int_t GetWaveformIdx(Int_t i)
void SetActiveWaveform(Int_t active=1)
PndEmcPSAFPGASampleAnalyser * fLowgainPSA
Double_t energy
Definition: plot_dirc.C:15