KaliVeda
Toolkit for HIC analysis
KVIDTelescope.cpp
1 /***************************************************************************
2 $Id: KVIDTelescope.cpp,v 1.52 2009/05/05 15:54:04 franklan Exp $
3 Author : $Author: franklan $
4  KVIDTelescope.cpp - description
5  -------------------
6  begin : Wed Jun 18 2003
7  copyright : (C) 2003 by J.D Frankland
8  email : frankland@ganil.fr
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  ***************************************************************************/
19 #include "TROOT.h"
20 #include "KVIDTelescope.h"
21 #include "KVGroup.h"
22 #include "KVNucleus.h"
23 #include "KVReconstructedNucleus.h"
24 #include "KVIDGraph.h"
25 #include "KVIDGrid.h"
26 #include "Riostream.h"
27 #include "TPluginManager.h"
28 #include "KVMultiDetArray.h"
29 #include "KVDataSet.h"
30 #include "KVIDGridManager.h"
31 #include "KVIDZALine.h"
32 #include "KVIDCutLine.h"
33 #include "KVIdentificationResult.h"
34 #include "TMath.h"
35 #include "TClass.h"
36 #include "TH2.h"
37 #include "KVParticleCondition.h"
38 
39 #include <KVDetectorSignalExpression.h>
40 #include <KVIDZAGrid.h>
41 
42 using namespace std;
43 
46 
47 
49 
51  : fGroup(nullptr)
52 {
53  init();
54 }
55 
56 
57 
60 
62 {
63  //default init
66 }
67 
68 
69 
101 
103 {
104  // Default initialisation for ID telescopes.
105  // If telescope has at least 1 grid then it is ready to identify
106  // particles after initialising the grid(s) (kReadyForID=true);
107  // otherwise kReadyForID is set to kFALSE, unless the current dataset (if defined)
108  // has been declared to have no associated identification/calibration parameters,
109  // in which case kReadyForID is by default set to kTRUE (for filtering simulations).
110  //
111  // In order to enable mass identification for certain telescopes without a dedicated
112  // implementation (e.g. for simulating array response), put the following lines
113  // in your .kvrootrc:
114  //
115  // [dataset].[telescope label].MassID: yes
116  //
117  // If you want to limit mass identification to certain values of Z and/or A,
118  // add the following line:
119  //
120  // [dataset].[telescope label].MassID.Validity: [expression]
121  //
122  // where [expression] is some valid C++ boolean expression involving Z and/or A,
123  // for example
124  //
125  // [dataset].[telescope label].MassID.Validity: (Z>3)&&(A<20)
126  //
127  //For identifications using more than one grid, the default behaviour is to try identification
128  //with each grid in turn until a successful identification is obtained. The order in which
129  //the grids should be tried should be specified by a variable with the following format:
130  //
131  //~~~~~~~~~~~~~~~~
132  //[Dataset].[telescope label].GridOrder: [Grid1],[Grid2],...
133  //~~~~~~~~~~~~~~~~
134 
136 
137  // for datasets with no calib/ident infos, all id telescopes work
138  if (gDataSet && !gDataSet->HasCalibIdentInfos()) {
140  }
141  else { // for datasets with calib/ident infos, we need a grid & all detectors working
142  // looping over detectors to check they are working
143  // if one of them is not -> set kReadyForID to false
144  TIter it(GetDetectors());
145  KVDetector* det = 0;
146  while ((det = (KVDetector*)it())) if (!det->IsOK()) {
148  return;
149  }
150 
151  if (GetIDGrid()) {
152  KVIDGraph* gr;
153  TIter it(GetListOfIDGrids());
154  bool ok = kTRUE;
155  KVUniqueNameList tmp_list;// for re-ordering grids
156  bool mass_id = false;
157  while ((gr = (KVIDGraph*)it())) {
158  tmp_list.Add(gr);
159  if (gr->HasMassIDCapability()) mass_id = true;
160  gr->Initialize();
161  // make sure both x & y axes' signals are well set up
162  if (!fGraphCoords[gr].fVarX || !fGraphCoords[gr].fVarY) {
163  ok = kFALSE;
164  Warning("Initialize",
165  "ID tel. %s: grid %s has undefined VarX(%s:%p) or VarY(%s:%p) - WILL NOT USE",
166  GetName(), gr->GetName(), gr->GetVarX(), fGraphCoords[gr].fVarX, gr->GetVarY(), fGraphCoords[gr].fVarY);
167  }
168  }
169  // set to true if at least one grid can provide mass identification
170  SetHasMassID(mass_id);
171  // if more than one grid, need to re-order them according to [Dataset].[telescope label].GridOrder
172  if (GetListOfIDGrids()->GetEntries() > 1 && gDataSet) {
173  KVString grid_list = gDataSet->GetDataSetEnv(Form("%s.GridOrder", GetLabel()));
174  ok = kFALSE;
175  if (grid_list == "")
176  Warning("Initialize", "ID telescope %s has %d grids but no %s variable defined",
177  GetName(), GetListOfIDGrids()->GetEntries(), Form("%s.GridOrder", GetLabel()));
178  else if (grid_list.GetNValues(",") != GetListOfIDGrids()->GetEntries())
179  Warning("Initialize", "ID telescope %s has %d grids but %d grids appear in variable %s",
180  GetName(), GetListOfIDGrids()->GetEntries(), grid_list.GetNValues(","), Form("%s.GridOrder", GetLabel()));
181  else {
182  fIDGrids.Clear();
183  grid_list.Begin(",");
184  while (!grid_list.End()) {
185  auto gr_name = grid_list.Next();
186  auto gr_ob = tmp_list.FindObject(gr_name);
187  if (!gr_ob) {
188  Info("Initialize", "IDtel=%s grid %s missing", GetName(), gr_name.Data());
189  }
190  else {
191  fIDGrids.Add(gr_ob);
192  }
193  }
194  ok = kTRUE;
195  }
196  }
197  if (ok) SetBit(kReadyForID);
198  }
199  }
200 
201  if (gDataSet) {
202  SetHasMassID(gDataSet->GetDataSetEnv(Form("%s.MassID", GetLabel()), kFALSE));
203  KVString valid;
204  if ((valid = gDataSet->GetDataSetEnv(Form("%s.MassID.Validity", GetLabel()), "")) != "") {
205  valid.ReplaceAll("Z", "_NUC_->GetZ()");
206  valid.ReplaceAll("A", "_NUC_->GetA()");
207  fMassIDValidity.reset(new KVParticleCondition(valid));
208  }
209  }
210 }
211 
212 
213 
222 
223 void KVIDTelescope::AddDetector(KVDetector* d)
224 {
225  // Add a detector to the telescope.
226  //
227  // Detectors must be added in the order they will be hit by impinging particles,
228  // with the last detector being the one particles stopped in the telescope will stop in.
229  // i.e. dE1, dE2, ..., Eres
230  //
231  // Update name of telescope to "ID_[name of 1st detector]_[name of 2nd detector]_ ... _[name of last detector]"
232 
233  if (d) {
234  fDetectors.Add(d);
235  if (GetSize() > 1) {
236  TString old_name = GetName();
237  old_name += Form("_%s", GetDetectors()->Last()->GetName());
238  SetName(old_name);
239  }
240  else SetName(Form("ID_%s", GetDetector(1)->GetName()));
241  //d->AddIDTelescope(this); <= caused multiple copies to exist in detector's list
242  }
243  else {
244  Warning("AddDetector", "Called with null pointer");
245  }
246 }
247 
248 
249 
253 
255 {
256  // print out telescope structure
257  //if opt="fired" only fired detectors are printed
258 
259  TIter next(GetDetectors());
260  KVDetector* obj;
261 
262  if (!strcmp(opt, "fired")) {
263  while ((obj = (KVDetector*) next())) {
264 
265  if (obj->Fired() || obj->GetEnergy())
266  obj->Print("data");
267  }
268  }
269  else {
270  cout << "\n" << opt << "Structure of KVIDTelescope object: " <<
271  GetName() << " " << GetType() << endl;
272  cout << opt <<
273  "--------------------------------------------------------" <<
274  endl;
275  while ((obj = (KVDetector*) next())) {
276  cout << opt << "Detector: " << obj->GetName() << endl;
277  }
278  }
279 }
280 
281 
282 
283 
286 
287 KVDetector* KVIDTelescope::GetDetector(const Char_t* name) const
288 {
289  // Return a pointer to the detector in the telescope with the name "name".
290 
291  KVDetector* tmp = (KVDetector*) GetDetectors()->FindObject(name);
292  if (!tmp)
293  Warning("GetDetector(const Char_t *name)",
294  "Detector %s not found in telescope %s", name, GetName());
295  return tmp;
296 }
297 
298 
299 
300 
302 
304 {
305  return fGroup;
306 }
307 
308 
309 
310 
312 
314 {
315  fGroup = kvg;
316 }
317 
318 
319 
321 
323 {
324  return (GetGroup() ? GetGroup()->GetNumber() : 0);
325 }
326 
327 
328 
351 
353 {
354  //Default identification method.
355  //
356  //Works for ID telescopes for which one or more identification grids are defined, each
357  //with VARX/VARY parameters corresponding to a KVDetectorSignal or KVDetectorSignalExpression
358  //associated with one or other of the detectors constituting the telescope.
359  //
360  //For identifications using more than one grid, the default behaviour is to try identification
361  //with each grid in turn until a successful identification is obtained. The order in which
362  //the grids should be tried should be specified by a variable with the following format:
363  //
364  //~~~~~~~~~~~~~~~~
365  //[Dataset].[Array Name].[ID type].GridOrder: [Grid1],[Grid2],...
366  //~~~~~~~~~~~~~~~~
367  //
368  //where the name of each grid is given as "VARY_VARX". If no variable defining the order is found,
369  //the grids will be tried in the order they were found in the file containing the grids for this
370  //telescope.
371  //
372  // The KVIdentificationResult is first Clear()ed; then it is filled with IDtype = GetType()
373  // of this identification telescope, IDattempted = true, and the results of the identification
374  // procedure.
375 
376  idr->Clear();
377  idr->IDattempted = true;
378  idr->SetIDType(GetType());
379 
380  KVIDGraph* grid;
381  TIter it(GetListOfIDGrids());
382  while ((grid = (KVIDGraph*)it())) { //loop over grids in order given by [Dataset].[Array Name].[ID type].GridOrder:
383  Double_t de, e;
384  auto fired = GetIDGridCoords(e, de, grid, x, y);// true if all signals required by e & de fired/present in event
385  idr->SetGridName(grid->GetName());
386  if (fired && grid->IsIdentifiable(e, de, &idr->Rejecting_Cut)) {
387  grid->Identify(e, de, idr);
388  if (idr->IDOK) break; // stop on first successful identification
389  }
390  else {
391  // either all signals required to calculate coordinates in grid are not present/fired,
392  // or particle rejected by cut in grid, in which case idr->Rejecting_Cut contains its name.
393  idr->IDOK = kFALSE;
395  }
396  }
397  idr->IDcode = GetIDCode();
398 
399  return kTRUE;
400 }
401 
402 
403 
404 
440 
442 {
443  // Add an identification grid to the list of grids used by this telescope.
444  //
445  // If the grid's VARX and VARY parameters are set and contain the names of valid
446  // detector signals (see formatting rules below) they will be used by
447  // GetIDGridXCoord() and GetIDGridYCoord() to return the coordinates
448  // needed to perform particle identification using the grid.
449  //
450  // The name of the grid is set to "VARY_VARX" (just the signal names, not the detector
451  // label part - see below). This value will be stored in the
452  // KVIdentificationResult corresponding to an attempted identification of a
453  // KVReconstructedNucleus by this grid.
454  //
455  // VARX/VARY Formatting
456  //
457  // To be valid, grid VARX/Y parameters should be set as follows:
458  //
459  //~~~~~~~~~~~~~~~~~~
460  // [signal name]
461  // or [det_label]::[signal name]
462  //~~~~~~~~~~~~~~~~~~
463  //
464  // where
465  //
466  //~~~~~~~~~~~~~~~~~~
467  // [det_label] (optional) = detector label i.e. string returned by KVDetector::GetLabel()
468  // method for detector. By default, VARX is assumed to be the Eres detector
469  // or last detector and VARY the DE detector or first detector
470  // [signal_name] = name of a signal defined for the detector, possibly depending
471  // on availability of calibration
472  //
473  // To see all available signals for a detector, use
474  //
475  // KVDetector::GetListOfDetectorSignals()
476  //~~~~~~~~~~~~~~~~~~
477 
478  if (grid) {
479  fIDGrids.Add(grid);
480  KVString det_labels_x, det_labels_y;
481  KVDetectorSignal* xx = GetSignalFromGridVar(grid->GetVarX(), "X", det_labels_x);
482  KVDetectorSignal* yy = GetSignalFromGridVar(grid->GetVarY(), "Y", det_labels_y);
483  GraphCoords gc;
484  gc.fVarX = xx;
485  gc.fDetLabelsX = det_labels_x;
486  gc.fVarY = yy;
487  gc.fDetLabelsY = det_labels_y;
488  fGraphCoords[grid] = gc;
489  TString grid_name;
490  if (xx && yy) {
491  grid_name.Form("%s_%s", yy->GetName(), xx->GetName());
492  grid->SetName(grid_name);
493  }
494  }
495 }
496 
497 
498 
544 
546 {
547  // Deduce & return pointer to detector signal from grid VARX/VARY parameter
548  //
549  // To be valid, grid VARX/Y parameters should be set using mathematical expressions
550  // which use the following references to detector signals for the telescope:
551  //
552  //~~~~~~~~~~~~~~~~~~
553  // [signal name]
554  // OR [det_label]::[signal name]
555  //~~~~~~~~~~~~~~~~~~
556  //
557  // where
558  //
559  //~~~~~~~~~~~~~~~~~~
560  // [signal_name] = name of a signal defined for 1 of the detectors of the telescope
561  // [det_label] = optional detector label i.e. string returned by
562  // KVDetector::GetLabel() method for detector
563  //~~~~~~~~~~~~~~~~~~
564  //
565  // If `[det_label]` is not given, we assume for `VARX` the last (E) detector,
566  // while for `VARY` we assume the first (dE) detector. If this telescope has only
567  // one detector, we use it for both variables.
568  //
569  // To see all available signals for a detector, use
570  //
571  //~~~~~~~~~~~~~~~~~~
572  // KVDetector::GetListOfDetectorSignals()
573  //~~~~~~~~~~~~~~~~~~
574  //
575  // #### Example ####
576  // Imagine a telescope which combines 2 detectors, with labels SI and CSI (in that order, i.e. SI is the dE detector,
577  // CSI is the residual energy detector). The following cases are valid:
578  //
579  //~~~~~
580  // VARX = Energy : use 'Energy' signal of CSI detector (default for VARX)
581  // VARY = ADC : use 'ADC' signal of SI detector (default for VARY)
582  // VARY = CSI::Energy : use 'Energy' signal of CSI detector (overrides default for VARY, SI)
583  // VARX = (Q3-Q3Fast)/(0.8*Q3) : uses 'Q3' and 'Q3Fast' signals of CSI detector (default for VARX)
584  // VARY = 1.5*SI::ADC - CSI::Q3Fast/CSI::Q3 : combination of signals from both detectors
585  //~~~~~
586  //
587  // The 'det_labels' string will be filled with a comma-separated list of the labels of each detector used
588  // in the expressions.
589  //
590  // \note if any signals are not defined, they will be evaluated as zero
591 
592  if (var == "") {
593  Warning("GetSignalFromGridVar",
594  "No VAR%s defined for grid for telescope %s. KVIDTelescope-derived class handling identification must override GetIDMapX/GetIDMapY",
595  axe.Data(), GetName());
596  return nullptr;
597  }
598 
599  KVString dum = var;
600  KVDetector* det = nullptr;
601  KVDetectorSignal* ds(nullptr);
602  KVString sig_type;
603 
604  // check if VARX/Y is a mathematical expression
605  Bool_t is_expression = var.GetNValues("+-*/()") > 1;
606  // examine each term in expression (this will split the elements in a mathematical expression,
607  // or just take the whole expression if no math operators are present)
608  var.Begin("+-*/()");
609  bool explicit_det_ref = false;
610  bool multidetexpr = false;
611  KVString det_label;
612  while (!var.End()) {
613  KVString t = var.Next();
614  // check if we have an explicit reference to a detector
615  if (t.Contains("::")) {
616  t.Begin("::");
617  det_label = t.Next();
618  auto _det = (KVDetector*)GetDetectors()->FindObjectByLabel(det_label);
619  if (_det) {
620  explicit_det_ref = true;
621  sig_type = t.Next();
622  // check signal is defined for detector
623  if (_det->GetDetectorSignal(sig_type)) {
624  if (det_labels.Length()) {
625  if (!det_labels.Contains(det_label)) det_labels += Form(",%s", det_label.Data());
626  }
627  else
628  det_labels = det_label;
629  }
630  else {
631  Warning("GetSignalFromGridVar", "signal '%s' not found in det '%s' -> replaced by '0'", sig_type.Data(), _det->GetName());
632  dum.ReplaceAll(Form("%s::%s", _det->GetLabel(), sig_type.Data()), "0");
633  }
634  }
635  if (det && (_det != det)) multidetexpr = true; // more than 1 detector is referenced
636  det = _det;
637  }
638  }
639  // treat all cases with explicit detector references
640  if (explicit_det_ref) {
641  if (!multidetexpr) {
642  // only 1 detector is directly referenced
643  if (!is_expression) {
644  // it is not a mathematical expression: this is just the name of a detector signal
645  return det->GetDetectorSignal(sig_type);
646  }
647  else {
648  // math expression with explicit reference to signal(s) of 1 detector
649  sig_type = var;
650  // remove all explicit references to detector: 'det' pointer has been set
651  sig_type.ReplaceAll(Form("%s::", det_label.Data()), "");
652  // expression will be handled below
653  }
654  }
655  else {
656  // use specific constructor for explicit detector references
657  ds = new KVDetectorSignalExpression(var, dum, GetDetectors());
658  if (!ds->IsValid()) {
659  delete ds;
660  ds = nullptr;
661  Error("GetSignalFromGridVar",
662  "Problem initialising ID-grid %s coordinate for telescope %s."
663  " Check definition of VAR%s for grid (=%s)",
664  axe.Data(), GetName(), axe.Data(), var.Data());
665  return ds;
666  }
668  return ds;
669  }
670  }
671  else {
672  // no explicit reference to detectors - by default, use detector (1) for Y axis,
673  // and the last detector for X axis
674  if (axe == "Y" || GetSize() == 1) det = GetDetector(1);
675  else det = GetDetector(GetSize());
676  sig_type = var;
677  det_labels = det->GetLabel();
678  }
679  ds = det->GetDetectorSignal(sig_type);
680  if (!ds) {
681  // sig_type is not the name of a known signal: assume it is an expression using known signal names
682  if (!det->AddDetectorSignalExpression(sig_type, sig_type)) {
683  Error("GetSignalFromGridVar",
684  "Problem initialising ID-grid %s coordinate for telescope %s. Request for unknown signal %s for detector %s. Check definition of VAR%s for grid (=%s)",
685  axe.Data(), GetName(), sig_type.Data(), det->GetName(), axe.Data(), var.Data());
686  ds = nullptr;
687  }
688  else
689  ds = det->GetDetectorSignal(sig_type);
690  }
691  return ds;
692 }
693 
694 
695 
697 
699 {
701  if (!cl || !cl->InheritsFrom("KVIDZAGrid")) cl = TClass::GetClass("KVIDZAGrid");
702  KVIDGrid* idgrid = (KVIDGrid*)cl->New();
703 
704  idgrid->AddIDTelescope(this);
705  idgrid->SetOnlyZId(onlyZ);
706  idgrid->SetRunList("1-10000");
707 
708  KVIDCutLine* B_line = (KVIDCutLine*)idgrid->Add("OK", "KVIDCutLine");
709  Int_t npoi_bragg = 0;
710  B_line->SetName("Bragg_line");
711  B_line->SetAcceptedDirection("right");
712 
713  return idgrid;
714 }
715 
716 
717 
727 
728 void KVIDTelescope::addLineToGrid(KVIDGrid* idgrid, int zz, int aa, int npoints, std::optional<Double_t> einc_max)
729 {
730 
731  //loop over energy
732  //first find :
733  // ****E1 = energy at which particle passes 1st detector and starts to enter in the 2nd one****
734  // E2 = energy at which particle passes the 2nd detector
735  //then perform npoints calculations between these two energies and use these
736  //to construct a KVIDZALine
737  //
738  // if einc_max is given, limit incident energy of particles
739 
740  double xfactor = 1.;
741 
742  KVNucleus part;
743 
744  KVDetector* det_de = GetDetector(1);
745  KVDetector* det_eres = GetDetector(2);
746 
747  Double_t SeuilE = 0.1;
748 
749  part.SetZ(zz);
750  part.SetA(aa);
751 
752  Double_t E1, E2;
753  //find E1
754  //go from SeuilE MeV to det_de->GetEIncOfMaxDeltaE(part.GetZ(),part.GetA()))
755  Double_t E1min = SeuilE, E1max = det_de->GetEIncOfMaxDeltaE(zz, aa);
756  E1 = (E1min + E1max) / 2.;
757 
758  while ((E1max - E1min) > SeuilE) {
759 
760  part.SetEnergy(E1);
761  det_de->Clear();
762  det_eres->Clear();
763 
764  det_de->DetectParticle(&part);
765  det_eres->DetectParticle(&part);
766  if (det_eres->GetEnergy() > SeuilE) {
767  //particle got through - decrease energy
768  E1max = E1;
769  E1 = (E1max + E1min) / 2.;
770  }
771  else {
772  //particle stopped - increase energy
773  E1min = E1;
774  E1 = (E1max + E1min) / 2.;
775  }
776  }
777 
778  //add point to Bragg line
779  Double_t dE_B = det_de->GetMaxDeltaE(zz, aa);
780  Double_t E_B = det_de->GetEIncOfMaxDeltaE(zz, aa);
781  Double_t Eres_B = det_de->GetERes(zz, aa, E_B);
782 
783  KVIDCutLine* B_line = (KVIDCutLine*)idgrid->GetCut("Bragg_line");
784  if (B_line) B_line->SetPoint(B_line->GetN(), Eres_B, dE_B);
785 
786  //find E2
787  //go from E1 MeV to maximum value where the energy loss formula is valid
788  Double_t E2min = E1, E2max = det_eres->GetEmaxValid(part.GetZ(), part.GetA());
789  E2 = (E2min + E2max) / 2.;
790 
791  while ((E2max - E2min > SeuilE)) {
792 
793  part.SetEnergy(E2);
794  det_de->Clear();
795  det_eres->Clear();
796 
797  det_de->DetectParticle(&part);
798  det_eres->DetectParticle(&part);
799  if (part.GetEnergy() > SeuilE) {
800  //particle got through - decrease energy
801  E2max = E2;
802  E2 = (E2max + E2min) / 2.;
803  }
804  else {
805  //particle stopped - increase energy
806  E2min = E2;
807  E2 = (E2max + E2min) / 2.;
808  }
809  }
810  E2 *= xfactor;
811  if ((!strcmp(det_eres->GetType(), "CSI")) && (E2 > 5000)) E2 = 5000;
812  if(einc_max) E2 = std::min(E2, einc_max.value());
813  // printf("z=%d a=%d E1=%lf E2=%lf\n",zz,aa,E1,E2);
814  KVIDZALine* line = (KVIDZALine*)idgrid->Add("ID", "KVIDZALine");
815  if (TMath::Even(zz)) line->SetLineColor(4);
816  line->SetZ(zz);
817  line->SetA(aa);
818 
819  Double_t logE1 = TMath::Log(E1);
820  Double_t logE2 = TMath::Log(E2);
821  Double_t dLog = (logE2 - logE1) / (npoints - 1.);
822 
823  for (Int_t i = 0; i < npoints; i++) {
824  // Double_t E = E1 + i*(E2-E1)/(npoints-1.);
825  Double_t E = TMath::Exp(logE1 + i * dLog);
826 
827  Double_t Eres = 0.;
828  Int_t niter = 0;
829  while (Eres < SeuilE && niter <= 20) {
830  det_de->Clear();
831  det_eres->Clear();
832 
833  part.SetEnergy(E);
834 
835  det_de->DetectParticle(&part);
836  det_eres->DetectParticle(&part);
837 
838  Eres = det_eres->GetEnergy();
839  E += SeuilE;
840  niter += 1;
841  }
842  if (!(niter > 20)) {
843  Double_t dE = det_de->GetEnergy();
844  Double_t gEres, gdE;
845  line->GetPoint(i - 1, gEres, gdE);
846  line->SetPoint(i, Eres, dE);
847 
848  }
849  }
850  //printf("sort de boucle points");
851 
852 
853 }
854 
855 
856 
865 
867 {
868  // Returns a comma-separated list of the labels of the detectors used to determine
869  // the "x" or "y" coordinates of the identification grid(s)
870  //
871  // If there is more than 1 grid and the list is not the same for all grids,
872  // prints a warning message.
873  //
874  // \param[in] axis name of grid axis i.e. "x", "X", "y" or "Y" (case insensitive)
875 
876  KVString _axis = axis;
877  _axis.ToUpper();
878 
879  if (_axis != "X" && _axis != "Y") {
880  Error("GetDetectorLabelsForGridCoord", "Called with illegal axis name '%s'", axis.Data());
881  return "";
882  }
883  KVString lab_list;
884 
885  for (auto& __gc : fGraphCoords) {
886  KVString labs;
887  if (_axis == "X") labs = __gc.second.fDetLabelsX;
888  else labs = __gc.second.fDetLabelsY;
889  if (lab_list.Length() && lab_list != labs) {
890  Error("GetDetectorLabelsForGridCoord", "Grids for telescope %s use different detector types for %s-coordinate: "
891  "%s and %s", GetName(), _axis.Data(), lab_list.Data(), labs.Data());
892  return "";
893  }
894  lab_list = labs;
895  }
896  return lab_list;
897 }
898 
899 
900 
901 
905 
907 {
908  //Return the first in the list of identification grids used by this telescope
909  //(this is for backwards compatibility with ID telescopes which had only one grid).
910  return (KVIDGraph*)GetListOfIDGrids()->First();
911 }
912 
913 
914 
915 
918 
920 {
921  //Return pointer to grid using position in list. First grid has index = 1.
922  if (index < 1) {
923  Error("GetIDGrid(int)", "Index must be >=1!");
924  return nullptr;
925  }
926  return (KVIDGraph*)GetListOfIDGrids()->At(index - 1);
927 }
928 
929 
930 
931 
935 
937 {
938  //Return pointer to grid using "label" to search in list of grids associated
939  //to this telescope.
940  return (KVIDGraph*)GetListOfIDGrids()->FindObjectByLabel(label);
941 }
942 
943 
944 
945 
947 
949 {
950  AbstractMethod("GetIDMapX");
951  return -1.;
952 }
953 
954 
955 
960 
962 {
963  // Returns the pedestal associated with the 2nd detector of the telescope,
964  // optionally depending on the given option string.
965  // By default this returns 0, and should be overridden in specific implementations.
966 
967  return 0.;
968 }
969 
970 
971 
976 
978 {
979  // Returns the pedestal associated with the 1st detector of the telescope,
980  // optionally depending on the given option string.
981  // By default this returns 0, and should be overridden in specific implementations.
982 
983  return 0.;
984 }
985 
986 
987 
994 
996 {
997  // \return value of X coordinate to be used with the given ID grid
998  //
999  // This corresponds to whatever was given as parameter "VARX" for the grid
1000  //
1001  // \param[out] fired set to true or false depending on whether detector signal(s) used for X were fired (read from last raw event)
1002 
1003  KVDetectorSignal* ds = fGraphCoords[g].fVarX;
1004  if (ds) {
1005  fired = ds->IsFired();
1006  return ds->GetValue();
1007  }
1008  fired = false;
1009  return -1;
1010 }
1011 
1012 
1013 
1020 
1022 {
1023  // \return value of Y coordinate to be used with the given ID grid
1024  //
1025  // This corresponds to whatever was given as parameter "VARY" for the grid
1026  //
1027  // \param[out] fired set to true or false depending on whether detector signal(s) used for Y were fired (read from last raw event)
1028 
1029  KVDetectorSignal* ds = fGraphCoords[g].fVarY;
1030  if (ds) {
1031  fired = ds->IsFired();
1032  return ds->GetValue();
1033  }
1034  fired = false;
1035  return -1;
1036 }
1037 
1038 
1039 
1040 
1042 
1044 {
1045  AbstractMethod("GetIDMapY");
1046  return -1.;
1047 }
1048 
1049 
1050 
1051 
1055 
1057 {
1058  //Remove all identification grids for this ID telescope
1059  //Grids are not deleted as this is handled by gIDGridManager
1060  fIDGrids.Clear();
1061  fGraphCoords.clear();
1062 }
1063 
1064 
1065 
1066 
1085 
1087 {
1088  //Static function which will create an instance of the KVIDTelescope-derived class
1089  //corresponding to 'name'
1090  //These are defined as 'Plugin' objects in the file $KVROOT/KVFiles/.kvrootrc :
1091  //~~~~~~~
1092  // # The KVMultiDetArray::GetIDTelescopes(KVDetector*de, KVDetector*e) method uses these plugins to
1093  // # create KVIDTelescope instances adapted to the specific array geometry and detector types.
1094  // # For each pair of detectors we look for a plugin with one of the following names:
1095  // # [name_of_dataset].de_detector_type[de detector thickness]-e_detector_type[de detector thickness]
1096  // # Each characteristic in [] brackets may or may not be present in the name; first we test for names
1097  // # with these characteristics, then all combinations where one or other of the characteristics is not present.
1098  // # In addition, we first test all combinations which begin with [name_of_dataset].
1099  // # The first plugin found in this order will be used.
1100  // # In addition, if for one of the two detectors there is a plugin called
1101  // # [name_of_dataset].de_detector_type[de detector thickness]
1102  // # [name_of_dataset].e_detector_type[e detector thickness]
1103  // # then we add also an instance of this 1-detector identification telescope.
1104  //~~~~~~~
1105 
1106  TPluginHandler* ph;
1107  //check and load plugin library
1108  if (!(ph = LoadPlugin("KVIDTelescope", uri)))
1109  return 0;
1110 
1111  //execute constructor/macro for identification telescope
1112  KVIDTelescope* mda = (KVIDTelescope*) ph->ExecPlugin(0);
1113  if (mda) {
1114  //set label of telescope with URI used to find plugin (minus dataset name)
1115  mda->SetLabelFromURI(uri);
1116  }
1117 
1118  return mda;
1119 }
1120 
1121 
1122 
1123 
1127 
1129 {
1130  //PRIVATE METHOD
1131  //Sets label of telescope based on URI of plugin describing child class for this telescope
1132 
1133  TString _uri(uri);
1134  if (gDataSet && _uri.BeginsWith(gDataSet->GetName())) _uri.Remove(0, strlen(gDataSet->GetName()) + 1);
1135  SetLabel(_uri.Data());
1136 }
1137 
1138 
1139 
1140 
1173 
1175 {
1176  // Initialise the identification parameters (grids, etc.) of ALL identification telescopes of this
1177  // kind (label) in the multidetector array. Therefore this method need only be called once, and not
1178  // called for each telescope. The kind/label (returned by GetLabel) of the telescope corresponds
1179  // to the URI used to find the plugin class in $KVROOT/KVFiles/.kvrootrc.
1180  //
1181  // By default, this method first looks for a file containing the list of all files containing the
1182  // identification grids. The default name of this file is:
1183  //
1184  //~~~
1185  // [label].IdentificationFiles.dat
1186  //~~~
1187  //
1188  // or any name given by the environment variable
1189  //
1190  //~~~
1191  // [dataset].IdentificationParameterList.[label]: [filename]
1192  //~~~
1193  //
1194  // If neither file is found, we look for a file with name:
1195  //
1196  //~~~
1197  // IDGrids.[label].dat
1198  //~~~
1199  //
1200  // or any name given by the environment variable
1201  //
1202  //~~~
1203  // [dataset].IdentificationParameterFile.[label]: [filename]
1204  //~~~
1205  //
1206  // which is assumed to contain all identification grids for this type of telescope.
1207 
1209  if(!ok) ok = LoadIdentificationParameters(multidet);
1210 
1211  if (!ok)
1212  Warning("SetIdentificationParameters", "No files found. See doc for this method.");
1213 
1214  return ok;
1215 }
1216 
1217 
1218 
1219 
1237 
1239 {
1240  // In the case where the identification grids are stored in several files, this method looks
1241  // for a file with name
1242  //
1243  //~~~
1244  // [label].IdentificationFiles.dat
1245  //~~~
1246  //
1247  // or any name given by the environment variable
1248  //
1249  //~~~
1250  // [dataset].IdentificationParameterList.[label]: [filename]
1251  //~~~
1252  //
1253  // and if found reads from it the list of files containing the identification grids.
1254  //
1255  // \returns kTRUE if file found and read, kFALSE if no file found
1256 
1257  TString filename = gDataSet->GetDataSetEnv(Form("IdentificationParameterList.%s", GetLabel()),
1258  Form("%s.IdentificationFiles.dat", GetLabel()));
1259 
1260  if(gDataSet->FindDataSetFile(filename))
1261  {
1262  KVFileReader fr;
1263  auto path = gDataSet->GetFullPathToDataSetFile(filename);
1264  Info("ReadIdentificationParameterFiles", "Using file %s", path.Data());
1265  fr.OpenFileToRead(path);
1266  Bool_t ok = kTRUE;
1267  while (fr.IsOK()) {
1268  fr.ReadLine(0);
1269 
1270  if (fr.GetCurrentLine() != "")
1271  ok &= LoadIdentificationParameters(multidet, fr.GetCurrentLine().Data());
1272  }
1273 
1274  fr.CloseFile();
1275  return ok;
1276  }
1277 
1278  return kFALSE;
1279 }
1280 
1281 
1282 
1283 
1301 
1303 {
1304  // \param[in] _filename optional name of dataset file containing grids for this telescope type
1305  // \returns kTRUE if a file is found and read in
1306  //
1307  // If no value for _filename is given, this method looks for a dataset file named
1308  //
1309  //~~~
1310  // IDGrids.[label].dat
1311  //~~~
1312  //
1313  // or any name given by the environment variable
1314  //
1315  //~~~
1316  // [dataset].IdentificationParameterFile.[label]: [filename]
1317  //~~~
1318  //
1319  // which is assumed to contain all identification grids for this type of telescope.
1320 
1321  TString filename;
1322  if(_filename.IsNull())
1323  {
1324  filename = gDataSet->GetDataSetEnv(Form("IdentificationParameterFile.%s", GetLabel()),
1325  Form("IDGrids.%s.dat",GetLabel()));
1326  }
1327  else
1328  filename = _filename;
1329 
1330  if(gDataSet->FindDataSetFile(filename))
1331  {
1332  auto path = gDataSet->GetFullPathToDataSetFile(filename);
1333  //Read grids from file
1334  Info("LoadIdentificationParameters", "Using file %s", path.Data());
1335  multidet->ReadGridsFromAsciiFile(path);
1336  return kTRUE;
1337  }
1338  else if (!_filename.IsNull())
1339  {
1340  // if the method was called with a definite filename to look for, we assume that this
1341  // file is supposed to exist, therefore if it is not found, there is a problem!
1342  Error("LoadIdentificationParameters",
1343  "File %s not found. Should be in %s",
1344  _filename.Data(), gDataSet->GetDataSetDir());
1345  return kFALSE;
1346  }
1347  return kFALSE;
1348 }
1349 
1350 
1351 
1352 
1364 
1366 {
1367  //Remove identification parameters from telescope in such a way that they
1368  //can subsequently be reset e.g. with a new version.
1369  //This is used by KVMultiDetArray::UpdateIdentifications.
1370  //Child classes with specific SetIdentificationParameters methods should
1371  //also redefine this method in order to remove (destroy) cleanly the objects
1372  //created in SetIdentificationParameters.
1373  //
1374  //This default method takes the list of grids associated to the telescope,
1375  //and for each one: 1) checks if it is still in the gIDGridManager's list
1376  //2) if yes, delete the grid and remove it from gIDGridManager
1377 
1378  TIter next_grid(GetListOfIDGrids());
1379  KVIDGrid* grid;
1380  while ((grid = (KVIDGrid*)next_grid())) {
1381 
1382  if (gIDGridManager->GetGrids()->FindObject(grid)) { //this only works if KVIDTelescope uses TObject:IsEqual method (i.e. compares pointers)
1383 
1384  gIDGridManager->DeleteGrid(grid);
1385 
1386  }
1387  }
1388  //clear list of grids
1389  fIDGrids.Clear();
1391 }
1392 
1393 
1394 
1395 //void KVIDTelescope::CalculateParticleEnergy(KVReconstructedNucleus* nuc)
1396 //{
1397 // // The energy of each particle is calculated as follows:
1398 // //
1399 // // E = dE_1 + dE_2 + ... + dE_N
1400 // //
1401 // // dE_1, dE_2, ... = energy losses measured in each detector through which
1402 // // the particle has passed (or stopped, in the case of dE_N).
1403 // // These energy losses are corrected for (Z,A)-dependent effects
1404 // // such as pulse-heigth defect in silicon detectors, losses in
1405 // // windows of gas detectors, etc.
1406 // //
1407 // // Whenever possible, the energy loss for fired detectors which are uncalibrated
1408 // // or not functioning is calculated. In this case the status returned by GetCalibStatus()
1409 // // will be KVIDTelescope::kCalibStatus_Calculated.
1410 // // If none of the detectors is calibrated, the particle's energy cannot be calculated &
1411 // // the status will be KVIDTelescope::kCalibStatus_NoCalibrations.
1412 // // Otherwise, the status code will be KVIDTelescope::kCalibStatus_OK.
1413 
1414 // //status code
1415 // fCalibStatus = kCalibStatus_NoCalibrations;
1416 
1417 // UInt_t z = nuc->GetZ();
1418 // //uncharged particles
1419 // if (z == 0) return;
1420 
1421 // KVDetector* d1 = GetDetector(1);
1422 // KVDetector* d2 = (GetSize() > 1 ? GetDetector(2) : 0);
1423 // Bool_t d1_cal = d1->IsCalibrated();
1424 // Bool_t d2_cal = (d2 ? d2->IsCalibrated() : kFALSE);
1425 
1426 // //no calibrations
1427 // if (!d1_cal && !d2)
1428 // return;
1429 // if ((d1 && d2) && !d1_cal && !d2_cal)
1430 // return;
1431 
1432 // //status code
1433 // fCalibStatus = kCalibStatus_OK;
1434 
1435 // UInt_t a = nuc->GetA();
1436 
1437 // // particles stopped in first member of telescope
1438 // if (nuc->GetStatus() == 3) {
1439 // if (d1_cal) {
1440 // nuc->SetEnergy(d1->GetCorrectedEnergy(nuc, -1, kFALSE)); //N.B.: transmission=kFALSE because particle stop in d1
1441 // }
1442 // return;
1443 // }
1444 
1445 // Double_t e1, e2, einc;
1446 // e1 = e2 = einc = 0.0;
1447 
1448 // if (!d1_cal) {//1st detector not calibrated - calculate from residual energy in 2nd detector
1449 
1450 // //second detector must exist and have all acquisition parameters fired with above-pedestal value
1451 // if (d2 && d2->Fired("Pall")) e2 = d2->GetCorrectedEnergy(nuc, -1, kFALSE); //N.B.: transmission=kFALSE because particle stop in d2
1452 // if (e2 <= 0.0) {
1453 // // zero energy loss in 2nd detector ? can't do anything...
1454 // fCalibStatus = kCalibStatus_NoCalibrations;
1455 // return;
1456 // }
1457 // //calculate & set energy loss in dE detector
1458 // //N.B. using e2 for the residual energy after detector 1 means
1459 // //that we are assuming the particle stops in detector 2.
1460 // //if this is not true, we will underestimate the energy of the particle.
1461 // e1 = d1->GetDeltaEFromERes(z, a, e2);
1462 // if (e1 < 0.0) e1 = 0.0;
1463 // else {
1464 // d1->SetEnergyLoss(e1);
1465 // d1->SetEResAfterDetector(e2);
1466 // e1 = d1->GetCorrectedEnergy(nuc);
1467 // //status code
1468 // fCalibStatus = kCalibStatus_Calculated;
1469 // }
1470 // }
1471 // else { //1st detector is calibrated too: get corrected energy loss
1472 
1473 // e1 = d1->GetCorrectedEnergy(nuc);
1474 
1475 // }
1476 
1477 // if (d2 && !d2_cal) {//2nd detector not calibrated - calculate from energy loss in 1st detector
1478 
1479 // e1 = d1->GetCorrectedEnergy(nuc);
1480 // if (e1 <= 0.0) {
1481 // // zero energy loss in 1st detector ? can't do anything...
1482 // fCalibStatus = kCalibStatus_NoCalibrations;
1483 // return;
1484 // }
1485 // //calculate & set energy loss in 2nd detector
1486 // e2 = d1->GetEResFromDeltaE(z, a);
1487 // if (e2 < 0.0) e2 = 0.0;
1488 // else {
1489 // e2 = d2->GetDeltaE(z, a, e2);
1490 // d2->SetEnergyLoss(e2);
1491 // e2 = d2->GetCorrectedEnergy(nuc);
1492 // //status code
1493 // fCalibStatus = kCalibStatus_Calculated;
1494 // }
1495 // }
1496 // else if (d2) { //2nd detector is calibrated too: get corrected energy loss
1497 
1498 // e2 = d2->GetCorrectedEnergy(nuc, -1, kFALSE);//N.B.: transmission=kFALSE because particle assumed to stop in d2
1499 // // recalculate corrected energy in first stage using info on Eres
1500 // d1->SetEResAfterDetector(e2);
1501 // e1 = d1->GetCorrectedEnergy(nuc);
1502 // }
1503 
1504 // //incident energy of particle (before 1st member of telescope)
1505 // einc = e1 + e2;
1506 
1507 // Double_t coherence_tolerance = gEnv->GetValue("KVIDTelescope.CoherencyTolerance", 1.05);
1508 // if (coherence_tolerance < 1) coherence_tolerance += 1.00;
1509 
1510 // //Now we have to work our way up the list of detectors from which the particle was
1511 // //reconstructed. For each fired & calibrated detector which is only associated with
1512 // //one particle in the events, we add the corrected measured energy loss
1513 // //to the particle. For uncalibrated, unfired detectors and detectors through which
1514 // //more than one particle has passed, we calculate the corrected energy loss and add it
1515 // //to the particle.
1516 // int ndets = nuc->GetNumDet();
1517 // if (ndets > (int)GetSize()) { //particle passed through other detectors before this idtelesocpe
1518 // //look at detectors not in this id telescope
1519 // int idet = GetSize();//next detector after delta-e member of IDTelescope (stopping detector = 0)
1520 // while (idet < ndets) {
1521 
1522 // KVDetector* det = nuc->GetDetector(idet);
1523 // if (det->Fired() && det->IsCalibrated() && det->GetNHits() == 1) {
1524 // Double_t dE = det->GetEnergy();
1525 // //in order to check if particle was really the only one to
1526 // //hit each detector, we calculate the particle's energy loss
1527 // //from its residual energy. if the measured energy loss is
1528 // //significantly larger, there may be a second particle.
1529 // e1 = det->GetDeltaEFromERes(z, a, einc);
1530 // if (e1 < 0.0) e1 = 0.0;
1531 // det->SetEResAfterDetector(einc);
1532 // dE = det->GetCorrectedEnergy(nuc);
1533 // einc += dE;
1534 // }
1535 // else {
1536 // // Uncalibrated/unfired/multihit detector. Calculate energy loss.
1537 // //calculate energy of particle before detector from energy after detector
1538 // e1 = det->GetDeltaEFromERes(z, a, einc);
1539 // if (e1 < 0.0) e1 = 0.0;
1540 // if (det->GetNHits() > 1) {
1541 // //Info("CalculateParticleEnergy",
1542 // // "Detector %s was hit by %d particles. Calculated energy loss for particle %f MeV",
1543 // // det->GetName(), det->GetNHits(), e1);
1544 // if (!(det->Fired() && det->IsCalibrated())) {
1545 // det->SetEnergyLoss(e1 + det->GetEnergy());// sum up calculated energy losses in uncalibrated detector
1546 // }
1547 // //status code
1548 // fCalibStatus = kCalibStatus_Multihit;
1549 // }
1550 // else if (!det->Fired() || !det->IsCalibrated()) {
1551 // //Info("CalculateParticleEnergy",
1552 // // "Detector %s uncalibrated/not fired. Calculated energy loss for particle %f MeV",
1553 // // det->GetName(), e1);
1554 // det->SetEnergyLoss(e1);
1555 // //status code
1556 // fCalibStatus = kCalibStatus_Calculated;
1557 // }
1558 // det->SetEResAfterDetector(einc);
1559 // e1 = det->GetCorrectedEnergy(nuc, e1);
1560 // einc += e1;
1561 // }
1562 // idet++;
1563 // }
1564 // }
1565 // //einc is now the energy of the particle before crossing the first detector
1566 // nuc->SetEnergy(einc);
1567 //}
1568 
1569 
1570 
1580 
1582 {
1583  // Returns name of default ID grid class for this ID telescope.
1584  // This is defined in a .kvrootrc configuration file by one of the following:
1585  // KVIDTelescope.DefaultGrid:
1586  // KVIDTelescope.DefaultGrid.[type]:
1587  // where [type] is the type of this identification telescope (which is given
1588  // by the character string returned by method GetLabel()... sorry :( )
1589  // If no default grid is defined for the specific type of this telescope,
1590  // the default defined by KVIDTelescope.DefaultGrid is used.
1591 
1592  TString specific;
1593  specific.Form("KVIDTelescope.DefaultGrid.%s", GetLabel());
1594  return gEnv->GetValue(specific.Data(), gEnv->GetValue("KVIDTelescope.DefaultGrid", "KVIDGraph"));
1595 }
1596 
1597 
1598 
1604 
1606 {
1607  //Create a dE-E grid (energy loss in detector 1 versus residual energy in detector 2) for a given list of isotopes
1608  // - AperZ : list of A for each Z. (ex: "1=1-3,2=3-4 5,3=6-8,4=7 9-12"...)
1609  // - npoints : number of points in each generated line
1610  // - xfactor : scales the detector 2 thickness to prolongate the lines
1611 
1612  if (GetSize() <= 1) return 0;
1613  if (!GetDetector(1) || !GetDetector(2)) return 0;
1614  double thickness = GetDetector(2)->GetThickness();
1615  GetDetector(2)->SetThickness(thickness * xfactor);
1616 
1617  Info("CalculateDeltaE_EGrid", "called with KVNameValueList");
1618 
1619  KVIDGrid* idgrid = newGrid(0);
1620 
1621  for (auto& par : AperZ) {
1622  KVString tmp = par.GetName();
1623  int zz = tmp.Atoi();
1624  KVNumberList alist = par.GetString();
1625  for (auto aa : alist) {
1626  addLineToGrid(idgrid, zz, aa, npoints);
1627  }
1628  }
1629 
1630  GetDetector(2)->SetThickness(thickness);
1631 
1632  return idgrid;
1633 
1634 }
1635 
1636 
1637 
1645 
1646 KVIDGrid* KVIDTelescope::CalculateDeltaE_EGrid(const KVNumberList& Zrange, Int_t deltaA, Int_t npoints, Double_t lifetime, UChar_t massformula, Double_t xfactor)
1647 {
1648  //Create a dE-E grid (energy loss in detector 1 versus residual energy in detector 2) for a given list of isotopes
1649  // - Zrange : list of element for which we create lines
1650  // - deltaA : number of isotopes generated for each Z around massformula (ex: deltaA=1, Aref-1 Aref Aref+1)
1651  // - npoints : number of points in each generated line
1652  // - lifetime: remove isotopes with lifetime lower than this value
1653  // - xfactor : scales the detector 2 thickness to prolongate the lines
1654 
1655  if (GetSize() <= 1) return 0;
1656  if (!GetDetector(1) || !GetDetector(2)) return 0;
1657  double thickness = GetDetector(2)->GetThickness();
1658  GetDetector(2)->SetThickness(thickness * xfactor);
1659 
1660  Info("CalculateDeltaE_EGrid", "called with KVNumberList");
1661 
1662  KVIDGrid* idgrid = newGrid(0);
1663  KVNucleus part;
1664 
1665  Zrange.Begin();
1666  while (!Zrange.End()) {
1667  Int_t zz = Zrange.Next();
1668  part.SetZ(zz, massformula);
1669  Int_t aref = part.GetA();
1670  for (Int_t aa = aref - deltaA; aa <= aref + deltaA; aa += 1) {
1671  part.SetA(aa);
1672  if (part.IsKnown() && (part.GetLifeTime() > lifetime)) {
1673  addLineToGrid(idgrid, zz, aa, npoints);
1674 
1675  }
1676  }
1677  }
1678  GetDetector(2)->SetThickness(thickness);
1679  return idgrid;
1680 }
1681 
1682 
1683 
1686 
1687 KVIDGrid* KVIDTelescope::CalculateDeltaE_EGrid(const KVNumberList& Zrange, Int_t npoints, Double_t Einc_max, UChar_t massformula)
1688 {
1689  // Generate ID grid for given list of Z values (1 line per Z), up to the given maximum incident energy
1690  if (GetSize() <= 1) return 0;
1691  if (!GetDetector(1) || !GetDetector(2)) return 0;
1692 
1693  Info("CalculateDeltaE_EGrid", "called with Einc_max=%f", Einc_max);
1694 
1695  KVIDGrid* idgrid = newGrid(0);
1696  KVNucleus part;
1697 
1698  Zrange.Begin();
1699  while (!Zrange.End()) {
1700  Int_t zz = Zrange.Next();
1701  part.SetZ(zz, massformula);
1702  addLineToGrid(idgrid, zz, part.GetA(), npoints, Einc_max);
1703  }
1704  return idgrid;
1705 }
1706 
1707 
1708 
1714 
1716 {
1717  //Create a dE-E grid (energy loss in detector 1 versus residual energy in detector 2) for a given list of isotopes
1718  // - haa_zz : lines will be generated for A,Z filled with 1 in this histogram
1719  // - Zonly : if true, generate only one line per Z with the <A>(Z) of the histogram
1720  // - npoints : number of points in each generated line
1721 
1722  if (GetSize() <= 1) return 0;
1723  if (!GetDetector(1) || !GetDetector(2)) return 0;
1724  double thickness = GetDetector(2)->GetThickness();
1725 
1726  Info("CalculateDeltaE_EGrid", "called with TH2");
1727 
1728  KVIDGrid* idgrid = newGrid(0);
1729  KVNucleus part;
1730 
1731  for (Int_t nx = 1; nx <= haa_zz->GetNbinsX(); nx += 1) {
1732 
1733  Int_t zz = TMath::Nint(haa_zz->GetXaxis()->GetBinCenter(nx));
1734  KVNumberList nlA;
1735  Double_t sumA = 0, sum = 0;
1736  for (Int_t ny = 1; ny <= haa_zz->GetNbinsY(); ny += 1) {
1737  Double_t stat = haa_zz->GetBinContent(nx, ny);
1738  if (stat > 0) {
1739  Double_t val = haa_zz->GetYaxis()->GetBinCenter(ny);
1740  nlA.Add(TMath::Nint(val));
1741  sumA += val * stat;
1742  sum += stat;
1743  }
1744  }
1745  sumA /= sum;
1746  Int_t nA = nlA.GetNValues();
1747  if (nA == 0) {
1748  Warning("CalculateDeltaE_EGrid", "no count for Z=%d", zz);
1749  }
1750  else {
1751  if (Zonly) {
1752  nlA.Clear();
1753  nlA.Add(TMath::Nint(sumA));
1754  }
1755  else {
1756  if (nA == 1) {
1757  Int_t aref = nlA.Last();
1758  nlA.Add(aref - 1);
1759  nlA.Add(aref + 1);
1760  }
1761  }
1762  part.SetZ(zz);
1763  nlA.Begin();
1764  while (!nlA.End()) {
1765  Int_t aa = nlA.Next();
1766  part.SetA(aa);
1767  if (part.IsKnown()) {
1768  addLineToGrid(idgrid, zz, aa, npoints);
1769  }
1770  }
1771  }
1772  }
1773  return idgrid;
1774 }
1775 
1776 
1777 
1793 
1795 {
1796  // Returns the Y-axis value in the 2D identification map containing isotope (Z,A)
1797  // corresponding to either the given X-axis/Eres value or the current X-axis value given by GetIDGridXCoord()
1798  // If no mass information is available, just give Z.
1799  //
1800  // In this (default) implementation this means scanning the ID grids associated with
1801  // this telescope until we find an identification line Z or (Z,A), and then interpolating
1802  // the Y-coordinate for the current X-coordinate value.
1803  //
1804  // Status variable can take one of following values:
1805  //
1806  // KVIDTelescope::kMeanDE_OK all OK
1807  // KVIDTelescope::kMeanDE_XtooSmall X-coordinate is smaller than smallest X-coordinate of ID line
1808  // KVIDTelescope::kMeanDE_XtooLarge X-coordinate is larger than largest X-coordinate of ID line
1809  // KVIDTelescope::kMeanDE_NoIdentifie No identifier found for Z or (Z,A)
1810 
1811  status = kMeanDE_OK;
1812  // loop over grids
1813  TIter next(GetListOfIDGrids());
1814  KVIDGrid* grid;
1815  KVIDLine* idline = 0;
1816  while ((grid = (KVIDGrid*)next())) {
1817  idline = (KVIDLine*)grid->GetIdentifier(Z, A);
1818  if (idline) break;
1819  }
1820  if (!idline) {
1821  status = kMeanDE_NoIdentifier;
1822  return -1.;
1823  }
1824  Double_t x, x1, y1, x2, y2; bool f;
1825  x = (Eres < 0 ? GetIDGridXCoord(grid,f) : Eres);
1826  idline->GetEndPoint(x2, y2);
1827  if (x > x2) {
1828  status = kMeanDE_XtooLarge;
1829  return -1;
1830  }
1831  idline->GetStartPoint(x1, y1);
1832  if (x < x1) {
1833  status = kMeanDE_XtooSmall;
1834  return -1.;
1835  }
1836  return idline->Eval(x);
1837 }
1838 
1839 
1840 
1841 
1850 
1852 {
1853  // Return kTRUE if energy of ION is > minimum incident energy required for identification
1854  // This theoretical limit is defined here to be the incident energy for which the
1855  // dE in the first detector of a dE-E telescope is maximum.
1856  // If EINC>0 it is assumed to be the energy of the ion just before the first detector
1857  // (case where ion would have to pass other detectors before reaching this telescope).
1858  //
1859  // If this is not a dE-E telescope, we return kTRUE by default.
1860 
1861  if (GetSize() < 2) return kTRUE;
1862 
1863  KVDetector* dEdet = GetDetector(1);
1864  Double_t emin = dEdet->GetEIncOfMaxDeltaE(ION->GetZ(), ION->GetA());
1865  if (EINC > 0.0) return (EINC > emin);
1866  return (ION->GetEnergy() > emin);
1867 }
1868 
1869 
1870 
1899 
1901 {
1902  // For filtering simulations
1903  //
1904  // \param IDR identification result object for this telescope
1905  // \param n the simulated particle currently being considered
1906  //
1907  // Set the IDR->Zident and IDR->Aident status of the identification of n.
1908  // In principle this depends on whether this telescope provides mass
1909  // identification or not, but this may depend on the particle's energy.
1910  //
1911  // In order to enable mass identification for certain telescopes without a dedicated
1912  // implementation (e.g. for simulating array response), put the following lines
1913  // in your .kvrootrc:
1914  //
1915  // [dataset].[telescope label].MassID: yes
1916  //
1917  // If you want to limit mass identification to certain values of Z and/or A,
1918  // add the following line:
1919  //
1920  // [dataset].[telescope label].MassID.Validity: [expression]
1921  //
1922  // where [expression] is some valid C++ boolean expression involving Z and/or A,
1923  // for example
1924  //
1925  // [dataset].[telescope label].MassID.Validity: (Z>3)&&(A<20)
1926  //
1927  // Then this expression will be tested here in order to determine particle
1928  // identification status
1929 
1930  KVNucleus test(IDR->Z, IDR->A);
1931  if (!test.IsKnown()) { // reject weird identifications as pile-up (in between lines)
1932  IDR->Zident = false;
1933  IDR->IDquality = 4;
1934  IDR->IDOK = false;
1935  return;
1936  }
1937  IDR->Zident = true;
1938  if (!HasMassID()) {
1939  IDR->Aident = false;
1940  }
1941  else {
1942  if (fMassIDValidity) IDR->Aident = fMassIDValidity->Test(n); // test expression for mass ID validity
1943  else IDR->Aident = true; // no expression set; all nuclei are identified in mass
1944  }
1945 }
1946 
1947 
1948 
1951 
1953 {
1954  // Open IdentificationBilan.dat file with given path
1955 
1957  fgIdentificationBilan = new TEnv(path);
1958 }
1959 
1960 
1961 
1964 
1966 {
1967  // Set status of ID Telescope for given system
1968  if (!(fgIdentificationBilan->GetValue(Form("%s.%s", system.Data(), GetName()), kTRUE))) ResetBit(kReadyForID);
1969 }
1970 
1971 
int Int_t
unsigned int UInt_t
#define d(i)
#define f(i)
#define e(i)
bool Bool_t
unsigned char UChar_t
char Char_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 filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char y2
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 g
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void gc
Option_t Option_t TPoint TPoint const char y1
char name[80]
char * Form(const char *fmt,...)
void SetLabel(const Char_t *lab)
Definition: KVBase.h:194
virtual const Char_t * GetType() const
Definition: KVBase.h:176
void Error(const char *method, const char *msgfmt,...) const override
Definition: KVBase.cpp:1650
const Char_t * GetLabel() const
Definition: KVBase.h:198
static TPluginHandler * LoadPlugin(const Char_t *base, const Char_t *uri="0")
Definition: KVBase.cpp:772
void Warning(const char *method, const char *msgfmt,...) const override
Definition: KVBase.cpp:1637
UInt_t GetNumber() const
Definition: KVBase.h:219
const Char_t * GetDataSetDir() const
Definition: KVDataSet.cpp:670
ValType GetDataSetEnv(const Char_t *type, const ValType &defval) const
Definition: KVDataSet.h:268
Bool_t HasCalibIdentInfos() const
Definition: KVDataSet.h:393
TString GetFullPathToDataSetFile(const Char_t *filename)
Definition: KVDataSet.cpp:1875
static Bool_t FindDataSetFile(const TString &dataset, const Char_t *filename)
Definition: KVDataSet.cpp:1909
Signal output from a mathematical combination of other signals.
Base class for output signal data produced by a detector.
virtual Bool_t IsFired() const
virtual Bool_t IsValid() const
virtual Double_t GetValue(const KVNameValueList &params="") const
Handle reading columns of numeric data in text files.
Definition: KVFileReader.h:121
KVString GetCurrentLine()
Definition: KVFileReader.h:320
void CloseFile()
Definition: KVFileReader.h:237
ReadStatus ReadLine(const KVString &pattern="")
Definition: KVFileReader.h:243
Bool_t IsOK()
Definition: KVFileReader.h:231
Bool_t OpenFileToRead(const KVString &filename)
Definition: KVFileReader.h:210
Group of detectors which can be treated independently of all others in array.
Definition: KVGroup.h:20
Line in ID grid used to delimit regions where no identification is possible.
Definition: KVIDCutLine.h:23
void SetName(const char *name) override
This is redeclared to make it appear in context menus for KVIDCutLines.
Definition: KVIDCutLine.h:84
virtual void SetAcceptedDirection(const Char_t *dir)
Definition: KVIDCutLine.cpp:74
Base class for particle identification in a 2D map.
Definition: KVIDGraph.h:32
void Add(TString, KVIDentifier *)
Definition: KVIDGraph.cpp:844
void SetRunList(const char *runlist)
Definition: KVIDGraph.h:184
void SetName(const char *name) override
Definition: KVIDGraph.h:168
void AddIDTelescope(KVBase *t)
Definition: KVIDGraph.h:435
KVIDentifier * GetCut(const Char_t *name) const
Definition: KVIDGraph.h:308
virtual void Identify(Double_t, Double_t, KVIdentificationResult *) const =0
const Char_t * GetName() const override
Definition: KVIDGraph.cpp:1344
KVIDentifier * GetIdentifier(Int_t Z, Int_t A) const
Definition: KVIDGraph.cpp:310
virtual Bool_t IsIdentifiable(Double_t, Double_t, TString *rejected_by=nullptr) const
Definition: KVIDGraph.cpp:1281
virtual void SetOnlyZId(Bool_t yes=kTRUE)
Definition: KVIDGraph.cpp:1508
KVList * GetGrids()
void DeleteGrid(KVIDGraph *, Bool_t update=kTRUE)
Abstract base class for 2D identification grids in e.g. (dE,E) maps.
Definition: KVIDGrid.h:74
Base class for lines/cuts used for particle identification in 2D data maps.
Definition: KVIDLine.h:143
void GetStartPoint(Double_t &x, Double_t &y) const
void GetEndPoint(Double_t &x, Double_t &y) const
Base class for all detectors or associations of detectors in array which can identify charged particl...
Definition: KVIDTelescope.h:85
KVIDGrid * newGrid(bool onlyZ)
virtual Double_t GetIDMapY(Option_t *opt="")
void init()
default init
KVIDGrid * CalculateDeltaE_EGrid(const KVNameValueList &AperZ, Int_t npoints=30, Double_t xfactor=1.)
void SetGroup(KVGroup *kvg)
KVList fMultiDetExpressions
used to clean up any multi-detector signal expressions generated to calculate X/Y coordinates
void SetLabelFromURI(const Char_t *uri)
virtual Bool_t Identify(KVIdentificationResult *, Double_t x=-1., Double_t y=-1.)
virtual Double_t GetIDMapX(Option_t *opt="")
static KVIDTelescope * MakeIDTelescope(const Char_t *name)
virtual Double_t GetPedestalY(Option_t *opt="")
virtual Bool_t SetIdentificationParameters(const KVMultiDetArray *)
void SetIDGrid(KVIDGraph *)
Bool_t HasMassID() const
KVDetector * GetDetector(UInt_t n) const
virtual Bool_t CheckTheoreticalIdentificationThreshold(KVNucleus *, Double_t=0.0)
UInt_t GetGroupNumber()
KVGroup * GetGroup() const
virtual Double_t GetPedestalX(Option_t *opt="")
Double_t GetIDGridXCoord(KVIDGraph *, bool &) const
virtual void AddDetector(KVDetector *d)
virtual Double_t GetMeanDEFromID(Int_t &status, Int_t Z, Int_t A=-1, Double_t Eres=-1.0)
Bool_t ReadIdentificationParameterFiles(const KVMultiDetArray *multidet)
const KVList * GetDetectors() const
KVDetectorSignal * GetSignalFromGridVar(const KVString &var, const KVString &axe, KVString &det_labels)
bool GetIDGridCoords(Double_t &X, Double_t &Y, KVIDGraph *grid, Double_t x=-1, Double_t y=-1)
KVIDGraph * GetIDGrid()
void Print(Option_t *opt="") const override
Double_t GetIDGridYCoord(KVIDGraph *, bool &) const
std::unordered_map< KVIDGraph *, GraphCoords > fGraphCoords
X/Y coordinates from detector signals for ID maps.
virtual UShort_t GetIDCode()
Bool_t LoadIdentificationParameters(const KVMultiDetArray *multidet, const TString &_filename="")
void CheckIdentificationBilan(const TString &system)
Set status of ID Telescope for given system.
virtual void RemoveIdentificationParameters()
static void OpenIdentificationBilan(const TString &path)
Open IdentificationBilan.dat file with given path.
void SetHasMassID(Bool_t yes=kTRUE)
virtual void Initialize(void)
const Char_t * GetDefaultIDGridClass()
UInt_t GetSize() const
KVUnownedList fIDGrids
identification grid(s)
Definition: KVIDTelescope.h:94
KVUnownedList fDetectors
list of detectors in telescope
Definition: KVIDTelescope.h:92
KVString GetDetectorLabelsForGridCoord(const KVString &axis) const
const KVList * GetListOfIDGrids() const
std::unique_ptr< KVParticleCondition > fMassIDValidity
may be used to limit mass identification to certain Z and/or A range
KVGroup * fGroup
group to which telescope belongs
Definition: KVIDTelescope.h:93
static TEnv * fgIdentificationBilan
Definition: KVIDTelescope.h:88
virtual void SetIdentificationStatus(KVIdentificationResult *IDR, const KVNucleus *)
virtual void RemoveGrids()
void addLineToGrid(KVIDGrid *gg, int zz, int aa, int npoints, std::optional< Double_t > einc_max=std::nullopt)
Base class for identification ridge lines corresponding to different nuclear species.
Definition: KVIDZALine.h:33
Full result of one attempted particle identification.
Bool_t IDattempted
=kTRUE if identification was attempted
Bool_t IDOK
general quality of identification, =kTRUE if acceptable identification made
void SetGridName(const Char_t *n)
TString Rejecting_Cut
name of cut in grid which rejected particle for identification
Bool_t Aident
= kTRUE if A of particle established
Int_t A
A of particle found (if Aident==kTRUE)
Int_t Z
Z of particle found (if Zident==kTRUE)
Int_t IDquality
specific quality code returned by identification procedure
void Clear(Option_t *opt="") override
Reset to initial values.
Int_t IDcode
a general identification code for this type of identification
void SetIDType(const Char_t *t)
Bool_t Zident
=kTRUE if Z of particle established
Base class for describing the geometry of a detector array.
Bool_t ReadGridsFromAsciiFile(const Char_t *) const
Handles lists of named parameters with different types, a list of KVNamedParameter objects.
Description of properties and kinematics of atomic nuclei.
Definition: KVNucleus.h:123
Bool_t IsKnown(int z=-1, int a=-1) const
Definition: KVNucleus.cpp:1272
Int_t GetA() const
Definition: KVNucleus.cpp:792
void SetA(Int_t a)
Definition: KVNucleus.cpp:647
void SetZ(Int_t z, Char_t mt=-1)
Definition: KVNucleus.cpp:696
Int_t GetZ() const
Return the number of proton / atomic number.
Definition: KVNucleus.cpp:763
Double_t GetLifeTime(Int_t z=-1, Int_t a=-1) const
Definition: KVNucleus.cpp:1033
Strings used to represent a set of ranges of values.
Definition: KVNumberList.h:85
void Clear(Option_t *="") override
Empty number list, reset it to initial state.
Bool_t End(void) const
Definition: KVNumberList.h:199
Int_t GetNValues() const
void Begin(void) const
void Add(Int_t)
Add value 'n' to the list.
Int_t Last() const
Returns largest number included in list.
Int_t Next(void) const
Implement selections for KVNucleus objects.
Double_t GetEnergy() const
Definition: KVParticle.h:624
void SetEnergy(Double_t e)
Definition: KVParticle.h:602
virtual TObject * FindObjectByLabel(const Char_t *) const
TObject * First() const override
void Add(TObject *obj) override
TObject * FindObject(const char *name) const override
void Clear(Option_t *option="") override
virtual void SetCleanup(Bool_t enable=kTRUE)
TObject * At(Int_t idx) const override
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
Int_t GetNValues(TString delim) const
Definition: KVString.cpp:886
Optimised list in which named objects can only be placed once.
void Add(TObject *obj) override
virtual void SetLineColor(Color_t lcolor)
virtual Double_t GetBinCenter(Int_t bin) const
static TClass * GetClass(Bool_t load=kTRUE, Bool_t silent=kFALSE)
const char * GetVarX() const
const char * GetVarY() const
virtual const char * GetValue(const char *name, const char *dflt) const
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Int_t GetN() const
virtual Double_t Eval(Double_t x, TSpline *spline=nullptr, Option_t *option="") const
virtual Int_t GetNbinsY() const
TAxis * GetXaxis()
virtual Int_t GetNbinsX() const
TAxis * GetYaxis()
virtual Double_t GetBinContent(Int_t bin) const
const char * GetName() const override
virtual void SetName(const char *name)
void AbstractMethod(const char *method) const
void SetBit(UInt_t f)
void ResetBit(UInt_t f)
virtual void Info(const char *method, const char *msgfmt,...) const
Longptr_t ExecPlugin(int nargs)
Ssiz_t Length() const
Int_t Atoi() const
const char * Data() const
void ToUpper()
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Bool_t IsNull() const
void Form(const char *fmt,...)
TString & Remove(EStripType s, char c)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
TString & ReplaceAll(const char *s1, const char *s2)
TLine * line
Double_t y[n]
Double_t x[n]
const Int_t n
TGraphErrors * gr
Int_t Nint(T x)
Double_t Exp(Double_t x)
constexpr Double_t E()
Double_t Log(Double_t x)
Bool_t Even(Long_t a)
ClassImp(TPyArg)