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 "KVDataSet.h"
8 
10 
11 
12 //________________________________________________________________
13 
14 
17 void KVFAZIADetector::init()
18 {
19  //default initialisations
20  fSignals.SetOwner();
21 
22  fBlock = -1;
23  fIdentifier = kOTHER;
24  fQuartet = -1;
25  fTelescope = -1;
26  fIndex = -1;
27  fIsRutherford = kFALSE;
28  fLabel = -1;
29 }
30 
31 
32 
34 
36 {
37 
38  Double_t lval = -1;
39  if (gDataSet) lval = gDataSet->GetDataSetEnv(parname, 0.0);
40  else lval = gEnv->GetValue(parname, 0.0);
41  return lval;
42 
43 }
44 
45 
46 
49 
51 {
52  // Default constructor
53  init();
54 }
55 
56 
57 
60 
61 KVFAZIADetector::KVFAZIADetector(const Char_t* type, const Float_t thick) : KVDetector(type, thick)
62 {
63  // Create detector of given material type and thickness (in centimetres)
64  init();
65 }
66 
67 
68 
71 
73 {
74  // Destructor
75 }
76 
77 
78 
86 
88 {
89  // This method copies the current state of 'this' object into 'obj'
90  // You should add here any member variables, for example:
91  // (supposing a member variable KVFAZIADetector::fToto)
92  // CastedObj.fToto = fToto;
93  // or
94  // CastedObj.SetToto( GetToto() );
95 
96  KVDetector::Copy(obj);
97  //KVFAZIADetector& CastedObj = (KVFAZIADetector&)obj;
98 }
99 
100 
101 
104 
106 {
107  //If opt="N" we do not reset any raw data, signals, etc
108 
109  KVDetector::Clear(opt);
110  if (strncmp(opt, "N", 1)) fSignals.Execute("Set", "0");
111 }
112 
113 
114 
116 
117 void KVFAZIADetector::SetName(const char* name)
118 {
120  SetProperties();
121 }
122 
123 
124 
134 
136 {
137  // detector name are assumed to be defined as
138  // label-xxx
139  // where xxx is computed as follow :
140  // 100*block number+10*quartet number+telescope number
141  // and label can be SI1, SI2 or CSI
142  // For example SI1-123 is the Silicon Si1 of the block 1, the quartet 2 and the telescope 3
143  //
144  //
145 
146  KVString tmp;
147  KVString sname(GetName());
148 
149  sname.Begin("-");
150  SetLabel(sname.Next());
151  if (!strcmp(GetLabel(), "SI1")) fIdentifier = kSI1;
152  else if (!strcmp(GetLabel(), "SI2")) fIdentifier = kSI2;
153  else if (!strcmp(GetLabel(), "CSI")) fIdentifier = kCSI;
154 
155  gFazia->AddDetectorLabel(GetLabel());
156 
157  // read thresholds to be applied on FPGA energies to decide if detector is fired
158  fQH1Threshold = GetSetupParameter("QH1.MinimumAmplitude");
159  fQ2Threshold = GetSetupParameter("Q2.MinimumAmplitude");
160  fQ3Threshold = GetSetupParameter("Q3.MinimumAmplitude");
161 
162  // if f[DET]FiredFromSignals = true, use the signal to decide if detector is fired
163  // instead of FPGA energies (old fashion)
164  fIsFiredFromSignals = GetSetupParameter(Form("%s.IsFiredFromSignal", GetLabel())) > 0.5;
165 
166  tmp = sname.Next();
167  if (tmp == "RUTH") {
169  fIndex = fTelescope = fQuartet = fBlock = 0;
170  }
171  else if (tmp.IsDigit()) {
172  fIndex = tmp.Atoi();
173  fBlock = fIndex / 100;
174  fQuartet = (fIndex - fBlock * 100) / 10;
175  fTelescope = fIndex - fBlock * 100 - fQuartet * 10;
176  }
177  else {
178  Info("SetProperties", "Unkown format for the detector %s", GetName());
179  }
180 
181  KVFAZIASignal* sig = 0;
182  //"QH1", "I1", "QL1", "Q2", "I2", "Q3
183  fSignals.Clear();
184  KVString lsignals = "";
185  KVString dsigs = "DetTag,GTTag";
186  if (!strcmp(GetLabel(), "SI1")) {
187  lsignals = "QH1,I1,QL1";
188  }
189  else if (!strcmp(GetLabel(), "SI2")) {
190  lsignals = "Q2,I2";
191  }
192  else if (!strcmp(GetLabel(), "CSI")) {
193  lsignals = "Q3";
194  dsigs += ",Q3.FastAmplitude,Q3.FastFPGAEnergy";
195  }
196  else {
197  Warning("SetProperties", "Unknown label \"%s\" for this detector : %s\n", GetLabel(), GetName());
198  lsignals = "";
199  dsigs = "";
200  }
201  KVString sigtypes = "Amplitude,RawAmplitude,FPGAEnergy,RiseTime,BaseLine,SigmaBaseLine";
202  lsignals.Begin(",");
203  while (!lsignals.End()) {
204  sigtypes.Begin(",");
205  KVString sig = lsignals.Next();
206  while (!sigtypes.End()) {
207  KVString stype = sigtypes.Next();
208  if (sig.BeginsWith("I") && (stype == "FPGAEnergy" || stype == "RiseTime")) continue;
209  if (sig == "QL1" && stype == "FPGAEnergy") continue;
210  dsigs += Form(",%s.%s", sig.Data(), stype.Data());
211  }
212  }
213  dsigs.Begin(",");
214  while (!dsigs.End()) AddDetectorSignal(new KVDetectorSignal(dsigs.Next(), this));
215  if (lsignals == "Q3") AddDetectorSignalExpression("Q3.SlowAmplitude", "Q3.Amplitude - 0.8*Q3.FastAmplitude");
216 
217  lsignals.Begin(",");
218  while (!lsignals.End()) {
219 
220  KVString ssig = lsignals.Next();
221  sig = KVFAZIASignal::MakeSignal(ssig);
222 
223  sig->SetName(Form("%s-%s", ssig.Data(), tmp.Data()));
224  sig->SetType(ssig.Data());
225 
226  sig->LoadPSAParameters();
227  sig->SetDetectorName(GetName());
228 
229  fSignals.Add(sig);
230  }
231 
232  //SetCalibrators();
233 
234  return kTRUE;
235 }
236 
237 
238 
241 
243 {
244  // Restrict list of signals which are used to fill raw data TTrees
245 
246  if(TString(GetLabel())=="SI1")
247  {
248  if(type=="QH1.FPGAEnergy"
249  || type=="I1.Amplitude"
250  || type=="QL1.Amplitude"
251  )
252  return true;
253  }
254  else if(TString(GetLabel())=="SI2")
255  {
256  if(type=="Q2.FPGAEnergy")
257  return true;
258  }
259  else if(TString(GetLabel())=="CSI")
260  {
261  if(type=="Q3.FastFPGAEnergy"
262  || type=="Q3.FPGAEnergy"
263  )
264  return true;
265  }
266  return false;
267 }
268 
269 
273 
275 {
276  // Translate an old-style FAZIA detector name (e.g. "SI1-T1-Q2-B001")
277  // to the new format ("SI1-121")
278 
279  Int_t tt = 0, qq = 0, bb = 0;
280  KVString tmp = "";
281  KVString lab = "";
282  oldname.Begin("-");
283 
284  if (!oldname.End()) {
285  lab = oldname.Next();
286  }
287  if (!oldname.End()) {
288  tmp = oldname.Next();
289  tmp.ReplaceAll("T", "");
290  tt = tmp.Atoi();
291  }
292  if (!oldname.End()) {
293  tmp = oldname.Next();
294  tmp.ReplaceAll("Q", "");
295  qq = tmp.Atoi();
296  }
297  if (!oldname.End()) {
298  tmp = oldname.Next();
299  tmp.ReplaceAll("B", "");
300  bb = tmp.Atoi();
301  }
302  static KVString newname;
303  newname.Form("%s-%d", lab.Data(), bb * 100 + qq * 10 + tt);
304  return newname.Data();
305 
306 }
307 
308 
309 
330 
332 {
333  // Returns kTRUE if detector was hit (fired) in an event
334  //
335  // Several methods are implemented.
336  //
337  // If the detector has a "Fired" signal (defined by a calibration file containing threshold
338  // values for individual detectors), we simply test it (if "Fired" > 0, then we are above threshold).
339  //
340  // If the detector is fired based on FPGA energy values (i.e. the `[dataset].*.IsFiredFromSignal` value is
341  // set to 0 for the dataset), thresholds are given for all SI1/SI2/CSI detectors using "[dataset].*.MinimumAmplitude" values
342  // for the QH1/QL1, Q2 and/or Q3 FPGA values, these will be used to test the corresponding "*.FPGAEnergy"
343  // signal of the detector.
344  //
345  // Otherwise, the test is made on charge signals of the detectors:
346  // - if one of them return kTRUE to KVSignal::IsFired() method KVDetector::Fired() return kTRUE
347  // - if not return kFALSE and the detector will not be considered in following analysis except if a detector behind it has been fired
348  //
349  // If the detector is in "simulation mode", i.e. if SetSimMode(kTRUE) has been called,
350  // this method returns kTRUE if the calculated energy loss in the active layer is > 0.
351  //
352 
353  if (!IsDetecting()) return kFALSE; //detector not working, no answer at all
354  if (IsSimMode()) return (GetActiveLayer()->GetEnergyLoss() > 0.); // simulation mode: detector fired if energy lost in active layer
355 
356  if(HasDetectorSignal("Fired"))
357  return GetDetectorSignalValue("Fired")>0;
358 
359  if (!fIsFiredFromSignals) {
360 
361  switch (GetIdentifier()) {
362  case kSI1:
363  if (GetDetectorSignalValue("QH1.FPGAEnergy") > fQH1Threshold) return kTRUE;
364  else return kFALSE;
365  break;
366  case kSI2:
367  if (GetDetectorSignalValue("Q2.FPGAEnergy") > fQ2Threshold) return kTRUE;
368  else return kFALSE;
369  break;
370  case kCSI:
371  if (GetDetectorSignalValue("Q3.FPGAEnergy") > fQ3Threshold) return kTRUE;
372  else return kFALSE;
373  break;
374  default:
375  return kFALSE;
376  break;
377  }
378  }
379 
380 // hereafter : old way of doing...
381  KVSignal* sig;
382  if (fSignals.GetSize()) {
383  TIter next(&fSignals);
384  while ((sig = (KVSignal*)next())) {
385  if (sig->IsOK()) {
386  if (sig->IsCharge()) {
387  //pre process to use the test method KVSignal::IsFired()
388  if (!sig->PSAHasBeenComputed()) {
389  sig->ComputeEndLine();
390  sig->TreateSignal();
391  }
392  if (sig->IsFired()) {
393  return kTRUE;
394  }
395  else {
396  }
397  }
398  }
399  else {
400  //Warning("Fired", "%s has empty signal %s", GetName(), sig->GetName());
401  }
402  }
403  }
404  else {
405  Warning("Fired", "%s : No signal attached to this detector ...", GetName());
406  }
407  return kFALSE;
408 }
409 
410 
411 
416 
417 void KVFAZIADetector::SetSignal(TGraph* signal, const Char_t* signal_name)
418 {
419  // Copy waveform data from TGraph into the signal with the given name (QH1-345 etc.)
420  //
421  // Then perform analysis of signal and set the values of the corresponding KVDetectorSignalValue objects
422 
423  KVSignal* sig = GetSignal(signal_name);
424  if (sig) {
425  sig->SetData(signal->GetN(), signal->GetX(), signal->GetY());
426  sig->TreateSignal();
427  SetPSAResults(sig);
428  }
429  else {
430  Warning("SetSignal", "%s : No signal of name #%s# is available", GetName(), signal_name);
431  }
432 }
433 
434 
435 
438 
440 {
441  // Returns kTRUE if detector has at least 1 associated signal
442  return (fSignals.GetEntries() > 0);
443 }
444 
445 
446 
450 
452 {
453  // Access detector signal by name, i.e. as in FAZIA raw data
454  // e.g. "QL1-231"
455  return (KVSignal*)fSignals.FindObject(name);
456 }
457 
458 
459 
465 
467 {
468  // Access detector signal of given type: "I1", "I2", "Q2", "Q3", "QH1", "QL1"
469  //
470  // \note KVSignal does not inherit from KVBase, so FindObjectByType does not work
471  // (even though KVSignal::GetType() method exists)
473 }
474 
475 
476 
480 
482 {
483  // Access signal with given index in list of detector's signals
484  // 0 <= idx < KVFAZIADetector::GetNumberOfSignals()
485  if (0 <= idx && idx < fSignals.GetEntries())
486  return (KVSignal*)fSignals.At(idx);
487  return nullptr;
488 }
489 
490 
491 
493 
495 {
496  return fSignals.GetEntries();
497 }
498 
499 
500 
502 
504 {
505  return &fSignals;
506 }
507 
508 
509 
512 
514 {
515  // Perform Pulse Shape Analysis on all signals
516  KVSignal* sig = 0;
517  TIter nexts(GetListOfSignals());
518  while ((sig = (KVSignal*)nexts())) {
519  sig->TreateSignal();
520  }
521 }
522 
523 
524 
525 
526 
527 
528 
529 
530 
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,...)
void SetLabel(const Char_t *lab)
Definition: KVBase.h:194
const Char_t * GetLabel() const
Definition: KVBase.h:198
void Warning(const char *method, const char *msgfmt,...) const override
Definition: KVBase.cpp:1696
ValType GetDataSetEnv(const Char_t *type, const ValType &defval={}) const
Definition: KVDataSet.h:269
Base class for output signal data produced by a detector.
Base class for detector geometry description, interface to energy-loss calculations.
Definition: KVDetector.h:160
virtual Bool_t IsSimMode() const
Definition: KVDetector.h:643
KVMaterial * GetActiveLayer() const override
Definition: KVDetector.h:313
void AddDetectorSignal(KVDetectorSignal *ds)
Definition: KVDetector.h:278
Bool_t HasDetectorSignal(const KVString &type) const
Definition: KVDetector.h:548
Double_t GetEnergyLoss() const override
Definition: KVDetector.h:385
void Copy(TObject &obj) const override
Definition: KVDetector.cpp:130
Bool_t AddDetectorSignalExpression(const KVString &type, const KVString &_expr)
Double_t GetDetectorSignalValue(const KVString &type, const KVNameValueList &params="") const
Definition: KVDetector.h:499
virtual Bool_t IsDetecting() const
Definition: KVDetector.h:662
void Clear(Option_t *opt="") override
Definition: KVDetector.cpp:565
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 SetPSAResults(const KVSignal *sig)
void SetName(const char *name) override
KVSignal * GetSignalByType(const Char_t *type) const
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
Int_t fIndex
100*block+10*quartet+telescope
static KVFAZIASignal * MakeSignal(const char *sig_type)
Definition: KVFAZIASignal.h:70
void SetDetectorName(const Char_t *name)
Definition: KVFAZIASignal.h:43
void AddDetectorLabel(const Char_t *label)
Definition: KVFAZIA.cpp:348
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
TObject * At(Int_t idx) const override
virtual TObject * FindObjectByTitle(const Char_t *) const
Will return object with given title (value of TObject::GetTitle() method).
virtual Bool_t IsCharge() const
Definition: KVSignal.h:62
virtual void TreateSignal()
Definition: KVSignal.cpp:212
void SetData(Int_t nn, Double_t *xx, Double_t *yy)
operation on data arrays
Definition: KVSignal.cpp:130
virtual void LoadPSAParameters()
Definition: KVSignal.cpp:193
bool IsOK()
Definition: KVSignal.cpp:99
Bool_t IsFired()
ComputeBaseLine and ComputeEndLine methods have to be called before.
Definition: KVSignal.cpp:393
void SetType(const Char_t *type)
Definition: KVSignal.h:77
Bool_t PSAHasBeenComputed() const
Definition: KVSignal.h:129
virtual Double_t ComputeEndLine()
Definition: KVSignal.cpp:376
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
const char * GetName() const override
virtual void SetName(const char *name)
virtual void Info(const char *method, const char *msgfmt,...) const
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)
auto * tt
ClassImp(TPyArg)
size_t fIndex