KaliVeda
Toolkit for HIC analysis
KVFAZIADetector.cpp
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 {
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 
157  gFazia->AddDetectorLabel(GetLabel());
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 
240 
243 
245 {
246  // Restrict list of signals which are used to fill raw data TTrees
247 
248  if(TString(GetLabel())=="SI1")
249  {
250  if(type=="QH1.FPGAEnergy"
251  || type=="I1.Amplitude"
252  || type=="QL1.Amplitude"
253  )
254  return true;
255  }
256  else if(TString(GetLabel())=="SI2")
257  {
258  if(type=="Q2.FPGAEnergy")
259  return true;
260  }
261  else if(TString(GetLabel())=="CSI")
262  {
263  if(type=="Q3.FastFPGAEnergy"
264  || type=="Q3.FPGAEnergy"
265  )
266  return true;
267  }
268  return false;
269 }
270 
271 
275 
277 {
278  // Translate an old-style FAZIA detector name (e.g. "SI1-T1-Q2-B001")
279  // to the new format ("SI1-121")
280 
281  Int_t tt = 0, qq = 0, bb = 0;
282  KVString tmp = "";
283  KVString lab = "";
284  oldname.Begin("-");
285 
286  if (!oldname.End()) {
287  lab = oldname.Next();
288  }
289  if (!oldname.End()) {
290  tmp = oldname.Next();
291  tmp.ReplaceAll("T", "");
292  tt = tmp.Atoi();
293  }
294  if (!oldname.End()) {
295  tmp = oldname.Next();
296  tmp.ReplaceAll("Q", "");
297  qq = tmp.Atoi();
298  }
299  if (!oldname.End()) {
300  tmp = oldname.Next();
301  tmp.ReplaceAll("B", "");
302  bb = tmp.Atoi();
303  }
304  static KVString newname;
305  newname.Form("%s-%d", lab.Data(), bb * 100 + qq * 10 + tt);
306  return newname.Data();
307 
308 }
309 
310 
311 
332 
334 {
335  // Returns kTRUE if detector was hit (fired) in an event
336  //
337  // Several methods are implemented.
338  //
339  // If the detector has a "Fired" signal (defined by a calibration file containing threshold
340  // values for individual detectors), we simply test it (if "Fired" > 0, then we are above threshold).
341  //
342  // If the detector is fired based on FPGA energy values (i.e. the `[dataset].*.IsFiredFromSignal` value is
343  // set to 0 for the dataset), thresholds are given for all SI1/SI2/CSI detectors using "[dataset].*.MinimumAmplitude" values
344  // for the QH1/QL1, Q2 and/or Q3 FPGA values, these will be used to test the corresponding "*.FPGAEnergy"
345  // signal of the detector.
346  //
347  // Otherwise, the test is made on charge signals of the detectors:
348  // - if one of them return kTRUE to KVSignal::IsFired() method KVDetector::Fired() return kTRUE
349  // - if not return kFALSE and the detector will not be considered in following analysis except if a detector behind it has been fired
350  //
351  // If the detector is in "simulation mode", i.e. if SetSimMode(kTRUE) has been called,
352  // this method returns kTRUE if the calculated energy loss in the active layer is > 0.
353  //
354 
355  if (!IsDetecting()) return kFALSE; //detector not working, no answer at all
356  if (IsSimMode()) return (GetActiveLayer()->GetEnergyLoss() > 0.); // simulation mode: detector fired if energy lost in active layer
357 
358  if(HasDetectorSignal("Fired"))
359  return GetDetectorSignalValue("Fired")>0;
360 
361  if (!fIsFiredFromSignals) {
362 
363  switch (GetIdentifier()) {
364  case kSI1:
365  if (GetDetectorSignalValue("QH1.FPGAEnergy") > fQH1Threshold) return kTRUE;
366  else return kFALSE;
367  break;
368  case kSI2:
369  if (GetDetectorSignalValue("Q2.FPGAEnergy") > fQ2Threshold) return kTRUE;
370  else return kFALSE;
371  break;
372  case kCSI:
373  if (GetDetectorSignalValue("Q3.FPGAEnergy") > fQ3Threshold) return kTRUE;
374  else return kFALSE;
375  break;
376  default:
377  return kFALSE;
378  break;
379  }
380  }
381 
382 // hereafter : old way of doing...
383  KVSignal* sig;
384  if (fSignals.GetSize()) {
385  TIter next(&fSignals);
386  while ((sig = (KVSignal*)next())) {
387  if (sig->IsOK()) {
388  if (sig->IsCharge()) {
389  //pre process to use the test method KVSignal::IsFired()
390  if (!sig->PSAHasBeenComputed()) {
391  sig->ComputeEndLine();
392  sig->TreateSignal();
393  }
394  if (sig->IsFired()) {
395  return kTRUE;
396  }
397  else {
398  }
399  }
400  }
401  else {
402  //Warning("Fired", "%s has empty signal %s", GetName(), sig->GetName());
403  }
404  }
405  }
406  else {
407  Warning("Fired", "%s : No signal attached to this detector ...", GetName());
408  }
409  return kFALSE;
410 }
411 
412 
413 
418 
419 void KVFAZIADetector::SetSignal(TGraph* signal, const Char_t* signal_name)
420 {
421  // Copy waveform data from TGraph into the signal with the given name (QH1-345 etc.)
422  //
423  // Then perform analysis of signal and set the values of the corresponding KVDetectorSignalValue objects
424 
425  KVSignal* sig = GetSignal(signal_name);
426  if (sig) {
427  sig->SetData(signal->GetN(), signal->GetX(), signal->GetY());
428  sig->TreateSignal();
429  sig->GetPSAResult(this);
430  }
431  else {
432  Warning("SetSignal", "%s : No signal of name #%s# is available", GetName(), signal_name);
433  }
434 }
435 
436 
437 
440 
442 {
443  // Returns kTRUE if detector has at least 1 associated signal
444  return (fSignals.GetEntries() > 0);
445 }
446 
447 
448 
452 
454 {
455  // Access detector signal by name, i.e. as in FAZIA raw data
456  // e.g. "QL1-231"
457  return (KVSignal*)fSignals.FindObject(name);
458 }
459 
460 
461 
464 
466 {
467  // Access detector signal of given type: "I1", "I2", "Q2", "Q3", "QH1", "QL1"
469 }
470 
471 
472 
476 
478 {
479  // Access signal with given index in list of detector's signals
480  // 0 <= idx < KVFAZIADetector::GetNumberOfSignals()
481  if (0 <= idx && idx < fSignals.GetEntries())
482  return (KVSignal*)fSignals.At(idx);
483  return nullptr;
484 }
485 
486 
487 
489 
491 {
492  return fSignals.GetEntries();
493 }
494 
495 
496 
498 
500 {
501  return &fSignals;
502 }
503 
504 
505 
508 
510 {
511  // Perform Pulse Shape Analysis on all signals
512  KVSignal* sig = 0;
513  TIter nexts(GetListOfSignals());
514  while ((sig = (KVSignal*)nexts())) {
515  sig->TreateSignal();
516  }
517 }
518 
519 
520 
524 
526 {
527  // Set FPGA energy value in appropriate KVDetectorSignal of detector and set its state
528  // to 'fired'. Returns address of the signal which was set.
529 
530  switch (sigid) {
531  case KVSignal::kQH1:
532  if (idx == 0) return SetQH1FPGAEnergy(energy);
533  break;
534  case KVSignal::kI1:
535  break;
536  case KVSignal::kQL1:
537  break;
538  case KVSignal::kQ2:
539  if (idx == 0) return SetQ2FPGAEnergy(energy);
540  break;
541  case KVSignal::kI2:
542  break;
543  case KVSignal::kQ3:
544  if (idx == 0) return SetQ3FPGAEnergy(energy);
545  if (idx == 1) return SetQ3FastFPGAEnergy(energy);
546  break;
547  }
548  return nullptr;
549 }
550 
551 
552 
556 
558 {
559  // Set signal baseline computed inside the FPGA.
560  // Returns address of the signal which was set.
561 
562  switch (sigid) {
563  case KVSignal::kQH1:
564  return SetQH1BaseLine(baseline);
565  break;
566  case KVSignal::kI1:
567  break;
568  case KVSignal::kQL1:
569  break;
570  case KVSignal::kQ2:
571  return SetQ2BaseLine(baseline);
572  break;
573  case KVSignal::kI2:
574  break;
575  case KVSignal::kQ3:
576  return SetQ3BaseLine(baseline);
577  break;
578  }
579  return nullptr;
580 }
581 
582 
int Int_t
bool Bool_t
char Char_t
float Float_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
const char Option_t
R__EXTERN TEnv * gEnv
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
char * Form(const char *fmt,...)
ValType GetDataSetEnv(const Char_t *type, const ValType &defval) const
Definition: KVDataSet.h:268
Base class for output signal data produced by a detector.
Base class for FAZIA detectors.
Bool_t fIsFiredFromSignals
KVSignal * GetSignal(const Char_t *name) const
Bool_t Fired(Option_t *opt="any") const override
const KVSeqCollection * GetListOfSignals() const
Double_t fQH1Threshold
thresholds defined for this detector
virtual ~KVFAZIADetector()
Destructor.
KVUniqueNameList fSignals
list of electronics signal (current, charge, etc... )
void Clear(Option_t *opt="") override
If opt="N" we do not reset any raw data, signals, etc.
void SetSignal(TGraph *signal, const Char_t *signal_name)
KVFAZIADetector()
Default constructor.
Int_t GetIdentifier() const
Double_t fQ3Threshold
Bool_t HasSignal() const
Returns kTRUE if detector has at least 1 associated signal.
void SetName(const char *name) override
KVDetectorSignal * SetBaseLine(int sigid, Float_t baseline)
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)
Bool_t use_signal_for_raw_data_tree(const TString &) const override
Restrict list of signals which are used to fill raw data TTrees.
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 Copy(TObject &obj) const override
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:304
KaliVeda extensions to ROOT collection classes.
void Execute(const char *method, const char *params, Int_t *error=0) override
TObject * FindObject(const char *name) const override
Int_t GetSize() const override
void Clear(Option_t *option="") override
virtual TObject * FindObjectByType(const Char_t *) const
TObject * At(Int_t idx) const override
@ 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:73
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
void Add(TObject *obj) override
virtual Int_t GetEntries() const
virtual const char * GetValue(const char *name, const char *dflt) const
Double_t * GetY() const
Int_t GetN() const
Double_t * GetX() const
void SetName(const char *name="") override
virtual void SetName(const char *name)
Int_t Atoi() const
const char * Data() const
Bool_t IsDigit() const
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
void Form(const char *fmt,...)
TString & ReplaceAll(const char *s1, const char *s2)
void Info(const char *location, const char *fmt,...)
void Warning(const char *location, const char *fmt,...)
auto * tt
ClassImp(TPyArg)
size_t fIndex