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 
323 
325 {
326  // Returns kTRUE if detector was hit (fired) in an event
327  //
328  // The test is made on charge signals of the detectors
329  // if one of them return kTRUE to KVSignal::IsFired() method KVDetector::Fired() return kTRUE
330  // if not return kFALSE and the detector will not be considered in following analysis
331  // except if one detector after it has been fired
332  //
333  // If the detector is in "simulation mode", i.e. if SetSimMode(kTRUE) has been called,
334  // this method returns kTRUE if the calculated energy loss in the active layer is > 0.
335  //
336 
337  if (!IsDetecting()) return kFALSE; //detector not working, no answer at all
338  if (IsSimMode()) return (GetActiveLayer()->GetEnergyLoss() > 0.); // simulation mode: detector fired if energy lost in active layer
339 
340  if (!fIsFiredFromSignals) {
341  switch (GetIdentifier()) {
342  case kSI1:
343  if (GetDetectorSignalValue("QH1.FPGAEnergy") > fQH1Threshold) return kTRUE;
344  else return kFALSE;
345  break;
346  case kSI2:
347  if (GetDetectorSignalValue("Q2.FPGAEnergy") > fQ2Threshold) return kTRUE;
348  else return kFALSE;
349  break;
350  case kCSI:
351  if (GetDetectorSignalValue("Q3.FPGAEnergy") > fQ3Threshold) return kTRUE;
352  else return kFALSE;
353  break;
354  default:
355  return kFALSE;
356  break;
357  }
358  }
359 
360 // hereafter : old way of doing...
361  KVSignal* sig;
362  if (fSignals.GetSize()) {
363  TIter next(&fSignals);
364  while ((sig = (KVSignal*)next())) {
365  if (sig->IsOK()) {
366  if (sig->IsCharge()) {
367  //pre process to use the test method KVSignal::IsFired()
368  if (!sig->PSAHasBeenComputed()) {
369  sig->ComputeEndLine();
370  sig->TreateSignal();
371  }
372  if (sig->IsFired()) {
373  return kTRUE;
374  }
375  else {
376  }
377  }
378  }
379  else {
380  //Warning("Fired", "%s has empty signal %s", GetName(), sig->GetName());
381  }
382  }
383  }
384  else {
385  Warning("Fired", "%s : No signal attached to this detector ...", GetName());
386  }
387  return kFALSE;
388 }
389 
390 
391 
396 
397 void KVFAZIADetector::SetSignal(TGraph* signal, const Char_t* signal_name)
398 {
399  // Copy waveform data from TGraph into the signal with the given name (QH1-345 etc.)
400  //
401  // Then perform analysis of signal and set the values of the corresponding KVDetectorSignalValue objects
402 
403  KVSignal* sig = GetSignal(signal_name);
404  if (sig) {
405  sig->SetData(signal->GetN(), signal->GetX(), signal->GetY());
406  sig->TreateSignal();
407  sig->GetPSAResult(this);
408  }
409  else {
410  Warning("SetSignal", "%s : No signal of name #%s# is available", GetName(), signal_name);
411  }
412 }
413 
414 
415 
418 
420 {
421  // Returns kTRUE if detector has at least 1 associated signal
422  return (fSignals.GetEntries() > 0);
423 }
424 
425 
426 
430 
432 {
433  // Access detector signal by name, i.e. as in FAZIA raw data
434  // e.g. "QL1-231"
435  return (KVSignal*)fSignals.FindObject(name);
436 }
437 
438 
439 
442 
444 {
445  // Access detector signal of given type: "I1", "I2", "Q2", "Q3", "QH1", "QL1"
447 }
448 
449 
450 
454 
456 {
457  // Access signal with given index in list of detector's signals
458  // 0 <= idx < KVFAZIADetector::GetNumberOfSignals()
459  if (0 <= idx && idx < fSignals.GetEntries())
460  return (KVSignal*)fSignals.At(idx);
461  return nullptr;
462 }
463 
464 
465 
467 
469 {
470  return fSignals.GetEntries();
471 }
472 
473 
474 
476 
478 {
479  return &fSignals;
480 }
481 
482 
483 
486 
488 {
489  // Perform Pulse Shape Analysis on all signals
490  KVSignal* sig = 0;
491  TIter nexts(GetListOfSignals());
492  while ((sig = (KVSignal*)nexts())) {
493  sig->TreateSignal();
494  }
495 }
496 
497 
498 
502 
504 {
505  // Set FPGA energy value in appropriate KVDetectorSignal of detector and set its state
506  // to 'fired'. Returns address of the signal which was set.
507 
508  switch (sigid) {
509  case KVSignal::kQH1:
510  if (idx == 0) return SetQH1FPGAEnergy(energy);
511  break;
512  case KVSignal::kI1:
513  break;
514  case KVSignal::kQL1:
515  break;
516  case KVSignal::kQ2:
517  if (idx == 0) return SetQ2FPGAEnergy(energy);
518  break;
519  case KVSignal::kI2:
520  break;
521  case KVSignal::kQ3:
522  if (idx == 0) return SetQ3FPGAEnergy(energy);
523  if (idx == 1) return SetQ3FastFPGAEnergy(energy);
524  break;
525  }
526  return nullptr;
527 }
528 
529 
530 
534 
536 {
537  // Set signal baseline computed inside the FPGA.
538  // Returns address of the signal which was set.
539 
540  switch (sigid) {
541  case KVSignal::kQH1:
542  return SetQH1BaseLine(baseline);
543  break;
544  case KVSignal::kI1:
545  break;
546  case KVSignal::kQL1:
547  break;
548  case KVSignal::kQ2:
549  return SetQ2BaseLine(baseline);
550  break;
551  case KVSignal::kI2:
552  break;
553  case KVSignal::kQ3:
554  return SetQ3BaseLine(baseline);
555  break;
556  }
557  return nullptr;
558 }
559 
560 
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,...)
KVString GetDataSetEnv(const Char_t *type, const Char_t *defval="") const
Definition: KVDataSet.cpp:784
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