KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
KVFAZIADetector.cpp
Go to the documentation of this file.
1 //Created by KVClassFactory on Fri Jan 23 18:44:27 2015
2 //Author: ,,,
3 
4 #include "KVFAZIADetector.h"
5 #include "KVIDTelescope.h"
6 #include "KVFAZIA.h"
7 #include "KVSignal.h"
8 #include "TClass.h"
9 #include "KVDataSet.h"
10 
12 
13 
14 //________________________________________________________________
15 
16 
19 void KVFAZIADetector::init()
20 {
21  //default initialisations
22  fSignals.SetOwner();
23 
24  fBlock = -1;
25  fIdentifier = kOTHER;
26  fQuartet = -1;
27  fTelescope = -1;
28  fIndex = -1;
29  fIsRutherford = kFALSE;
30  fLabel = -1;
31 }
32 
33 
34 
36 
38 {
39 
40  Double_t lval = -1;
41  if (gDataSet) lval = gDataSet->GetDataSetEnv(parname, 0.0);
42  else lval = gEnv->GetValue(parname, 0.0);
43  return lval;
44 
45 }
46 
47 
48 
51 
53 {
54  // Default constructor
55  init();
56 }
57 
58 
59 
62 
63 KVFAZIADetector::KVFAZIADetector(const Char_t* type, const Float_t thick) : KVDetector(type, thick)
64 {
65  // Create detector of given material type and thickness (in centimetres)
66  init();
67 }
68 
69 
70 
73 
75 {
76  // Destructor
77 }
78 
79 
80 
88 
90 {
91  // This method copies the current state of 'this' object into 'obj'
92  // You should add here any member variables, for example:
93  // (supposing a member variable KVFAZIADetector::fToto)
94  // CastedObj.fToto = fToto;
95  // or
96  // CastedObj.SetToto( GetToto() );
97 
98  KVDetector::Copy(obj);
99  //KVFAZIADetector& CastedObj = (KVFAZIADetector&)obj;
100 }
101 
102 
103 
106 
108 {
109  //If opt="N" we do not reset any raw data, signals, etc
110 
111  KVDetector::Clear(opt);
112  if (strncmp(opt, "N", 1)) fSignals.Execute("Set", "0");
113 }
114 
115 
116 
118 
119 void KVFAZIADetector::SetName(const char* name)
120 {
121  TNamed::SetName(name);
122  SetProperties();
123 }
124 
125 
126 
136 
138 {
139  // detector name are assumed to be defined as
140  // label-xxx
141  // where xxx is computed as follow :
142  // 100*block number+10*quartet number+telescope number
143  // and label can be SI1, SI2 or CSI
144  // For example SI1-123 is the Silicon Si1 of the block 1, the quartet 2 and the telescope 3
145  //
146  //
147 
148  KVString tmp;
149  KVString sname(GetName());
150 
151  sname.Begin("-");
152  SetLabel(sname.Next());
153  if (!strcmp(GetLabel(), "SI1")) fIdentifier = kSI1;
154  else if (!strcmp(GetLabel(), "SI2")) fIdentifier = kSI2;
155  else if (!strcmp(GetLabel(), "CSI")) fIdentifier = kCSI;
156 
158 
159  // read thresholds to be applied on FPGA energies to decide if detector is fired
160  fQH1Threshold = GetSetupParameter("QH1.MinimumAmplitude");
161  fQ2Threshold = GetSetupParameter("Q2.MinimumAmplitude");
162  fQ3Threshold = GetSetupParameter("Q3.MinimumAmplitude");
163 
164  // if f[DET]FiredFromSignals = true, use the signal to decide if detector is fired
165  // instead of FPGA energies (old fashion)
166  fIsFiredFromSignals = GetSetupParameter(Form("%s.IsFiredFromSignal", GetLabel())) > 0.5;
167 
168  tmp = sname.Next();
169  if (tmp == "RUTH") {
171  fIndex = fTelescope = fQuartet = fBlock = 0;
172  }
173  else if (tmp.IsDigit()) {
174  fIndex = tmp.Atoi();
175  fBlock = fIndex / 100;
176  fQuartet = (fIndex - fBlock * 100) / 10;
177  fTelescope = fIndex - fBlock * 100 - fQuartet * 10;
178  }
179  else {
180  Info("SetProperties", "Unkown format for the detector %s", GetName());
181  }
182 
183  KVSignal* sig = 0;
184  //"QH1", "I1", "QL1", "Q2", "I2", "Q3
185  fSignals.Clear();
186  KVString lsignals = "";
187  KVString dsigs = "DetTag,GTTag";
188  if (!strcmp(GetLabel(), "SI1")) {
189  lsignals = "QH1,I1,QL1";
190  }
191  else if (!strcmp(GetLabel(), "SI2")) {
192  lsignals = "Q2,I2";
193  }
194  else if (!strcmp(GetLabel(), "CSI")) {
195  lsignals = "Q3";
196  dsigs += ",Q3.FastAmplitude,Q3.FastFPGAEnergy";
197  }
198  else {
199  Warning("SetProperties", "Unknown label \"%s\" for this detector : %s\n", GetLabel(), GetName());
200  lsignals = "";
201  dsigs = "";
202  }
203  KVString sigtypes = "Amplitude,RawAmplitude,FPGAEnergy,RiseTime,BaseLine,SigmaBaseLine";
204  lsignals.Begin(",");
205  while (!lsignals.End()) {
206  sigtypes.Begin(",");
207  KVString sig = lsignals.Next();
208  while (!sigtypes.End()) {
209  KVString stype = sigtypes.Next();
210  if (sig.BeginsWith("I") && (stype == "FPGAEnergy" || stype == "RiseTime")) continue;
211  if (sig == "QL1" && stype == "FPGAEnergy") continue;
212  dsigs += Form(",%s.%s", sig.Data(), stype.Data());
213  }
214  }
215  dsigs.Begin(",");
216  while (!dsigs.End()) AddDetectorSignal(new KVDetectorSignal(dsigs.Next(), this));
217  if (lsignals == "Q3") AddDetectorSignalExpression("Q3.SlowAmplitude", "Q3.Amplitude - 0.8*Q3.FastAmplitude");
218 
219  lsignals.Begin(",");
220  while (!lsignals.End()) {
221 
222  KVString ssig = lsignals.Next();
223  sig = KVSignal::MakeSignal(ssig);
224 
225  sig->SetName(Form("%s-%s", ssig.Data(), tmp.Data()));
226  sig->SetType(ssig.Data());
227 
228  sig->LoadPSAParameters();
229  sig->SetDetectorName(GetName());
230 
231  fSignals.Add(sig);
232  }
233 
234  //SetCalibrators();
235 
236  return kTRUE;
237 }
238 
239 
243 
245 {
246  // Translate an old-style FAZIA detector name (e.g. "SI1-T1-Q2-B001")
247  // to the new format ("SI1-121")
248 
249  Int_t tt = 0, qq = 0, bb = 0;
250  KVString tmp = "";
251  KVString lab = "";
252  oldname.Begin("-");
253 
254  if (!oldname.End()) {
255  lab = oldname.Next();
256  }
257  if (!oldname.End()) {
258  tmp = oldname.Next();
259  tmp.ReplaceAll("T", "");
260  tt = tmp.Atoi();
261  }
262  if (!oldname.End()) {
263  tmp = oldname.Next();
264  tmp.ReplaceAll("Q", "");
265  qq = tmp.Atoi();
266  }
267  if (!oldname.End()) {
268  tmp = oldname.Next();
269  tmp.ReplaceAll("B", "");
270  bb = tmp.Atoi();
271  }
272  static KVString newname;
273  newname.Form("%s-%d", lab.Data(), bb * 100 + qq * 10 + tt);
274  return newname.Data();
275 
276 }
277 
278 
279 
291 
293 {
294  // Returns kTRUE if detector was hit (fired) in an event
295  //
296  // The test is made on charge signals of the detectors
297  // if one of them return kTRUE to KVSignal::IsFired() method KVDetector::Fired() return kTRUE
298  // if not return kFALSE and the detector will not be considered in following analysis
299  // except if one detector after it has been fired
300  //
301  // If the detector is in "simulation mode", i.e. if SetSimMode(kTRUE) has been called,
302  // this method returns kTRUE if the calculated energy loss in the active layer is > 0.
303  //
304 
305  if (!IsDetecting()) return kFALSE; //detector not working, no answer at all
306  if (IsSimMode()) return (GetActiveLayer()->GetEnergyLoss() > 0.); // simulation mode: detector fired if energy lost in active layer
307 
308  if (!fIsFiredFromSignals) {
309  switch (GetIdentifier()) {
310  case kSI1:
311  if (GetDetectorSignalValue("QH1.FPGAEnergy") > fQH1Threshold) return kTRUE;
312  else return kFALSE;
313  break;
314  case kSI2:
315  if (GetDetectorSignalValue("Q2.FPGAEnergy") > fQ2Threshold) return kTRUE;
316  else return kFALSE;
317  break;
318  case kCSI:
319  if (GetDetectorSignalValue("Q3.FPGAEnergy") > fQ3Threshold) return kTRUE;
320  else return kFALSE;
321  break;
322  default:
323  return kFALSE;
324  break;
325  }
326  }
327 
328 // hereafter : old way of doing...
329  KVSignal* sig;
330  if (fSignals.GetSize()) {
331  TIter next(&fSignals);
332  while ((sig = (KVSignal*)next())) {
333  if (sig->IsOK()) {
334  if (sig->IsCharge()) {
335  //pre process to use the test method KVSignal::IsFired()
336  if (!sig->PSAHasBeenComputed()) {
337  sig->ComputeEndLine();
338  sig->TreateSignal();
339  }
340  if (sig->IsFired()) {
341  return kTRUE;
342  }
343  else {
344  }
345  }
346  }
347  else {
348  //Warning("Fired", "%s has empty signal %s", GetName(), sig->GetName());
349  }
350  }
351  }
352  else {
353  Warning("Fired", "%s : No signal attached to this detector ...", GetName());
354  }
355  return kFALSE;
356 }
357 
358 
359 
364 
365 void KVFAZIADetector::SetSignal(TGraph* signal, const Char_t* signal_name)
366 {
367  // Copy waveform data from TGraph into the signal with the given name (QH1-345 etc.)
368  //
369  // Then perform analysis of signal and set the values of the corresponding KVDetectorSignalValue objects
370 
371  KVSignal* sig = GetSignal(signal_name);
372  if (sig) {
373  sig->SetData(signal->GetN(), signal->GetX(), signal->GetY());
374  sig->TreateSignal();
375  sig->GetPSAResult(this);
376  }
377  else {
378  Warning("SetSignal", "%s : No signal of name #%s# is available", GetName(), signal_name);
379  }
380 }
381 
382 
383 
386 
388 {
389  // Returns kTRUE if detector has at least 1 associated signal
390  return (fSignals.GetEntries() > 0);
391 }
392 
393 
394 
398 
400 {
401  // Access detector signal by name, i.e. as in FAZIA raw data
402  // e.g. "QL1-231"
403  return (KVSignal*)fSignals.FindObject(name);
404 }
405 
406 
407 
410 
412 {
413  // Access detector signal of given type: "I1", "I2", "Q2", "Q3", "QH1", "QL1"
415 }
416 
417 
418 
422 
424 {
425  // Access signal with given index in list of detector's signals
426  // 0 <= idx < KVFAZIADetector::GetNumberOfSignals()
427  if (0 <= idx && idx < fSignals.GetEntries())
428  return (KVSignal*)fSignals.At(idx);
429  return nullptr;
430 }
431 
432 
433 
435 
437 {
438  return fSignals.GetEntries();
439 }
440 
441 
442 
444 
446 {
447  return &fSignals;
448 }
449 
450 
451 
454 
456 {
457  // Perform Pulse Shape Analysis on all signals
458  KVSignal* sig = 0;
459  TIter nexts(GetListOfSignals());
460  while ((sig = (KVSignal*)nexts())) {
461  sig->TreateSignal();
462  }
463 }
464 
465 
466 
470 
472 {
473  // Set FPGA energy value in appropriate KVDetectorSignal of detector and set its state
474  // to 'fired'. Returns address of the signal which was set.
475 
476  switch (sigid) {
477  case KVSignal::kQH1:
478  if (idx == 0) return SetQH1FPGAEnergy(energy);
479  break;
480  case KVSignal::kI1:
481  break;
482  case KVSignal::kQL1:
483  break;
484  case KVSignal::kQ2:
485  if (idx == 0) return SetQ2FPGAEnergy(energy);
486  break;
487  case KVSignal::kI2:
488  break;
489  case KVSignal::kQ3:
490  if (idx == 0) return SetQ3FPGAEnergy(energy);
491  if (idx == 1) return SetQ3FastFPGAEnergy(energy);
492  break;
493  }
494  return nullptr;
495 }
496 
497 
int Int_t
KVDataSet * gDataSet
Definition: KVDataSet.cpp:29
KVFAZIA * gFazia
Definition: KVFAZIA.cpp:45
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
static Double_t energy[]
char Char_t
const Bool_t kFALSE
bool Bool_t
double Double_t
float Float_t
const Bool_t kTRUE
const char Option_t
R__EXTERN TEnv * gEnv
int type
char * Form(const char *fmt,...)
void SetLabel(const Char_t *lab)
Definition: KVBase.h:194
const Char_t * GetLabel() const
Definition: KVBase.h:198
const Char_t * GetDataSetEnv(const Char_t *type, const Char_t *defval="") const
Definition: KVDataSet.cpp:758
Base class for output signal data produced by a detector.
Base class for detector geometry description.
Definition: KVDetector.h:159
virtual Bool_t IsSimMode() const
Definition: KVDetector.h:652
void AddDetectorSignal(KVDetectorSignal *ds)
Definition: KVDetector.h:260
virtual Double_t GetEnergyLoss() const
Definition: KVDetector.h:368
virtual void Clear(Option_t *opt="")
Definition: KVDetector.cpp:596
KVMaterial * GetActiveLayer() const
Definition: KVDetector.h:289
Bool_t AddDetectorSignalExpression(const KVString &type, const KVString &_expr)
Double_t GetDetectorSignalValue(const KVString &type, const KVNameValueList &params="") const
Definition: KVDetector.h:492
virtual Bool_t IsDetecting() const
Definition: KVDetector.h:671
virtual void Copy(TObject &obj) const
Definition: KVDetector.cpp:127
Base class for FAZIA detectors.
Bool_t fIsFiredFromSignals
KVSignal * GetSignal(const Char_t *name) const
Bool_t Fired(Option_t *opt="any") const
const KVSeqCollection * GetListOfSignals() const
virtual void Clear(Option_t *opt="")
If opt="N" we do not reset any raw data, signals, etc.
Double_t fQH1Threshold
thresholds defined for this detector
virtual ~KVFAZIADetector()
Destructor.
KVUniqueNameList fSignals
list of electronics signal (current, charge, etc... )
void SetSignal(TGraph *signal, const Char_t *signal_name)
KVFAZIADetector()
Default constructor.
Int_t GetIdentifier() const
virtual void SetName(const char *name)
Double_t fQ3Threshold
Bool_t HasSignal() const
Returns kTRUE if detector has at least 1 associated signal.
void Copy(TObject &obj) const
KVSignal * GetSignalByType(const Char_t *type) const
Access detector signal of given type: "I1", "I2", "Q2", "Q3", "QH1", "QL1".
Double_t GetSetupParameter(const Char_t *parname)
Double_t fQ2Threshold
Int_t GetNumberOfSignals() const
void ComputePSA()
Perform Pulse Shape Analysis on all signals.
Int_t fIdentifier
SI1=0(kSI1) SI2=1(kSI2) CSI=2(kCSI)
static const Char_t * GetNewName(KVString oldname)
void init()
default initialisations
KVDetectorSignal * SetFPGAEnergy(int sigid, Int_t idx, Double_t energy)
Int_t fIndex
100*block+10*quartet+telescope
void AddDetectorLabel(const Char_t *label)
Definition: KVFAZIA.cpp:254
KaliVeda extensions to ROOT collection classes.
virtual void Clear(Option_t *option="")
virtual Int_t GetSize() const
virtual TObject * At(Int_t idx) const
virtual void Execute(const char *method, const char *params, Int_t *error=0)
virtual TObject * FindObjectByType(const Char_t *) const
virtual TObject * FindObject(const char *name) const
@ kQH1
Definition: KVSignal.h:17
@ kQL1
Definition: KVSignal.h:19
virtual Bool_t IsCharge() const
Definition: KVSignal.h:109
virtual void TreateSignal()
Definition: KVSignal.cpp:406
void SetData(Int_t nn, Double_t *xx, Double_t *yy)
operation on data arrays
Definition: KVSignal.cpp:207
void SetDetectorName(const Char_t *name)
Definition: KVSignal.h:89
virtual void LoadPSAParameters()
Definition: KVSignal.cpp:387
virtual bool IsOK()
Definition: KVSignal.cpp:149
static KVSignal * MakeSignal(const char *sig_type)
Create new KVSignal instance corresponding to sig_type.
Definition: KVSignal.cpp:1852
virtual void GetPSAResult(KVDetector *) const
Definition: KVSignal.h:155
Bool_t IsFired()
ComputeBaseLine and ComputeEndLine methods have to be called before.
Definition: KVSignal.cpp:581
void SetType(const Char_t *type)
Definition: KVSignal.h:94
Bool_t PSAHasBeenComputed() const
Definition: KVSignal.h:159
virtual Double_t ComputeEndLine()
Definition: KVSignal.cpp:564
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:72
void Begin(TString delim) const
Definition: KVString.cpp:565
Bool_t End() const
Definition: KVString.cpp:634
KVString Next(Bool_t strip_whitespace=kFALSE) const
Definition: KVString.cpp:695
virtual void Add(TObject *obj)
virtual Int_t GetEntries() const
virtual const char * GetValue(const char *name, const char *dflt) const
virtual void SetName(const char *name="")
Int_t GetN() const
Double_t * GetX() const
Double_t * GetY() const
virtual const char * GetName() const
virtual void SetName(const char *name)
virtual void Warning(const char *method, const char *msgfmt,...) const
virtual void Info(const char *method, const char *msgfmt,...) const
Int_t Atoi() const
Bool_t IsDigit() const
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
const char * Data() const
void Form(const char *fmt,...)
TString & ReplaceAll(const char *s1, const char *s2)
auto * tt
size_t fIndex