KaliVeda
Toolkit for HIC analysis
KVINDRADSTConverter.cpp
1 #include "KVDataAnalyser.h"
2 #define KVDSTTreeConverter_cxx
3 
4 #include "KVINDRADSTConverter.h"
5 #include "KVUserAnalysisOptionList.h"
6 #include "KVINDRADB.h"
7 #include <KVDetectorStack.h>
8 #include <KVReconNucTrajectory.h>
9 
10 
15 
17 {
18  // The Begin() function is called at the start of the query.
19  // When running with PROOF Begin() is only called on the client.
20  // The tree argument is deprecated (on PROOF 0 is passed).
21 
22  Info("Begin", "Reading %lld events from file", total_events);
23  events_read = 0;
24  KVUserAnalysisOptionList option_list;
25  option_list.ParseOptions(GetOption());
26  run_number = option_list.GetOpt("run_number").Atoi();
28  if (!gIndra)
30  else
31  gIndra->SetParameters(run_number);
32 
33  with_phoswich = gIndra->GetListOfPhoswich() && !gIndra->GetListOfPhoswich()->IsEmpty();
34  camp1 = gDataSet->IsCalled("INDRA_camp1");
35  camp2 = gDataSet->IsCalled("INDRA_camp2");
36  camp4 = gDataSet->IsCalled("INDRA_camp4");
37 
39 
40  output_file = gDataSet->NewRunfile("recon", run_index);
41  output_tree = new TTree("ReconEvents", Form("%s : %s : root events converted from DST",
42  gIndraDB->GetDBRunFile(run_index).GetName(),
43  gIndraDB->GetDBRunFile(run_index).GetTitle()));
45 }
46 
47 
48 
53 
55 {
56  // The SlaveBegin() function is called after the Begin() function.
57  // When running with PROOF SlaveBegin() is called on each slave server.
58  // The tree argument is deprecated (on PROOF 0 is passed).
59 
61 }
62 
63 
64 
66 
68 {
69  fReader.SetLocalEntry(entry);
70 
71  the_event->Clear();
72 
73  for (int i = 0; i < *npart_traite; ++i) {
74  if (idcode[i] >= KVINDRA::NO_IDENTIFICATION) continue;
75 
76  if (idcode[i] == KVINDRA::ID_GAMMA) {
77  KVDetector* CSI = nullptr;
78  if (with_phoswich && icou[i] == 1)
79  CSI = get_phos(i);
80  else
81  CSI = get_csi(i);
82  if (!CSI) {
83  Error("Process", "Got no CSI for cod=%d cou=%d mod=%d", idcode[i], icou[i], imod[i]);
84  }
85  else {
86  the_event->GetParameters()->IncrementValue("INDRA_GAMMA_MULT", 1);
87  the_event->GetParameters()->IncrementValue("INDRA_GAMMA_DETS", CSI->GetName());
88  }
89  continue;
90  }
91  KVINDRADetector* det = nullptr;
92 
93  if (stopped_in_csi(i)) det = get_csi(i);
94  else if (stopped_in_si(i)) det = get_si(i);
95  else if (stopped_in_ci(i)) det = get_ci(i);
96  else if (stopped_in_phos(i)) det = get_phos(i);
97  else if (stopped_in_si75(i)) det = get_si75(i);
98  else if (stopped_in_sili(i)) det = get_sili(i);
99  if (!det) {
100  // nothing fired? try direct approach?
101  switch (idcode[i]) {
102  case KVINDRA::ID_CSI_PSA:
104  if (!with_phoswich || icou[i] > 1)
105  det = gIndra->GetDetectorByType((UInt_t)icou[i], (UInt_t)imod[i], CsI_T);
106  else
107  det = gIndra->GetDetectorByType((UInt_t)icou[i], (UInt_t)imod[i], Phos_T);
108  break;
109 
110  default:
111  det = nullptr;
112  }
113  }
114 
115  auto idtelescope_code = idcode[i];
116  switch (idcode[i]) {
118  if (!with_phoswich && icou[i] == 1)
119  idtelescope_code = KVINDRA::ID_SI_CSI;
120  else if (icou[i] < 10)
121  idtelescope_code = KVINDRA::ID_CI_SI;
122  else if (icou[i] >= 10) {
123  if (si75_fired(i)) idtelescope_code = KVINDRA::ID_CI_SI75;
124  else idtelescope_code = KVINDRA::ID_CI_CSI;
125  }
126  break;
127 
129  if (icou[i] > 1 && icou[i] < 10) {
130  idtelescope_code = KVINDRA::ID_CI_SI;
131  }
132  else if (icou[i] > 9) {
133  idtelescope_code = KVINDRA::ID_CI_CSI;
134  det = get_csi(i);
135  }
136  break;
137 
138  case KVINDRA::ID_NEUTRON:
139  if (icou[i] < 10) {
140  idtelescope_code = KVINDRA::ID_SI_CSI;
141  }
142  break;
143 
145  if (icou[i] > 1 && icou[i] < 10) {
146  idtelescope_code = KVINDRA::ID_CI_SI;
147  }
148  else if (icou[i] > 9) {
149  idtelescope_code = KVINDRA::ID_CI_CSI;
150  }
151  break;
152 
154  if (icou[i] > 1 && icou[i] < 10) {
155  idtelescope_code = KVINDRA::ID_CI_SI;
156  det = get_si(i);
157  }
158  else if (icou[i] > 9) {
159  idtelescope_code = KVINDRA::ID_CI_CSI;
160  det = get_csi(i);
161  }
162  break;
163 
165  if (with_phoswich && icou[i] == 1) {
166  idtelescope_code = KVINDRA::ID_PHOSWICH;
167  }
168  else {
169  idtelescope_code = KVINDRA::ID_CSI_PSA;
170  }
171  break;
172 
174  if (icou[i] > 1) {
175  idtelescope_code = KVINDRA::ID_CSI_PSA;
176  }
177  break;
178  }
179  if (!det) {
180  Warning("Process",
181  "Got no detector with id=%d cou=%d mod=%d z=%d a=%d ecod=%d ener=%f",
182  idcode[i], icou[i], imod[i], z[i], a[i], ecode[i], ener[i]);
183  continue;
184  }
185  auto node = det->GetNode();
186  auto traj = (KVGeoDNTrajectory*)node->GetTrajectories()->First();
187  bool etalon = sili_fired(i) || si75_fired(i);
188  auto chio = det->GetChIo();
189  if (node->GetNTrajForwards() > 1) {
190  // Stopped in CsI behind etalon telescope - we have a particle stopped in CsI which may have gone CI-CsI or CI-Si75-SiLi-CsI
191  if (etalon) {
192  if (stopped_in_csi(i)) {
193  // particles stopping in CsI can only be on etalon trajectory if they have energy necessary
194  // to punch through CI-SI75-SILI detectors
195  KVDetectorStack etalon_dets;
196  etalon_dets.Add(chio);
197  etalon_dets.Add(get_si75(i));
198  etalon_dets.Add(get_sili(i));
199  if (z[i] > 0 && z[i] < 92 && std::abs(a[i]) > 0 && ecode[i] > 0 && ecode[i] < 4 && ener[i] > 0) {
200  if (ener[i] < etalon_dets.GetPunchThroughEnergy(z[i], std::abs(a[i]))) {
201  etalon = false;
202  traj = (KVGeoDNTrajectory*)node->GetTrajectories()->FindObjectWithMethod("2", "GetN");
203  }
204  }
205  else
206  traj = (KVGeoDNTrajectory*)node->GetTrajectories()->FindObjectWithMethod("4", "GetN");
207  }
208  else
209  traj = (KVGeoDNTrajectory*)node->GetTrajectories()->FindObjectWithMethod("4", "GetN");
210  }
211  else
212  traj = (KVGeoDNTrajectory*)node->GetTrajectories()->FindObjectWithMethod("2", "GetN");
213  }
214  // correct idtelescope code in case of code=6 or code=10 stopped in SiLi or Si75 (1st campaign data)
216  if (stopped_in_sili(i))
217  idtelescope_code = KVINDRA::ID_SI75_SILI;
218  else if (stopped_in_si75(i))
219  idtelescope_code = KVINDRA::ID_CI_SI75;
220  }
221 
222  if (!node->GetTrajectories()) {
223  Warning("Process", "node %s has no trajectories", node->GetName());
224  }
225  auto rtraj = (KVReconNucTrajectory*)det->GetGroup()->GetTrajectoryForReconstruction(traj, node);
226  TIter next_id(rtraj->GetIDTelescopes());
227  KVIDTelescope* idt = nullptr;
228  while ((idt = (KVIDTelescope*)next_id())) {
229  if (idt->GetIDCode() == idtelescope_code) break;
230  }
231  if (!idt || idt->GetIDCode() != idtelescope_code) {
232  idt = (KVIDTelescope*)rtraj->GetIDTelescopes()->First();
233  }
234  // idt may still = nullptr here if e.g. particle stopped in ChIo (idcode=stopped_in_first_stage)
235  // i.e. normally only in cases where no identification is available
236 
237  auto nuc = the_event->AddParticle();
238  nuc->SetParameter("ARRAY", "INDRA");
239  nuc->SetMassFormula(KVNucleus::kVedaMass);
240  nuc->SetReconstructionTrajectory(rtraj);
241  if (phos_fired(i)) {
242  the_event->SetParameter(Form("ACQPAR.INDRA.PHOS_%02d_R", imod[i]), ci_gg[i]);
243  the_event->SetParameter(Form("ACQPAR.INDRA.PHOS_%02d_L", imod[i]), ci_pg[i]);
244  }
245  if (ci_fired(i)) {
246  if (chio) {
247  the_event->SetParameter(Form("ACQPAR.INDRA.%s_GG", chio->GetName()), ci_gg[i]);
248  the_event->SetParameter(Form("ACQPAR.INDRA.%s_PG", chio->GetName()), ci_pg[i]);
249  }
250  };
251  if (si_fired(i)) {
252  the_event->SetParameter(Form("ACQPAR.INDRA.SI_%02d%02d_GG", icou[i], imod[i]), si_gg[i]);
253  the_event->SetParameter(Form("ACQPAR.INDRA.SI_%02d%02d_PG", icou[i], imod[i]), si_pg[i]);
254  }
255  if (csi_fired(i)) {
256  the_event->SetParameter(Form("ACQPAR.INDRA.CSI_%02d%02d_R", icou[i], imod[i]), csi_r[i]);
257  the_event->SetParameter(Form("ACQPAR.INDRA.CSI_%02d%02d_L", icou[i], imod[i]), csi_l[i]);
258  }
259 
260  // set up identification result
261  auto idr = nuc->GetIdentificationResult(1);
262  idr->IDattempted = true;
263  if (idt) {
264  idr->SetIDType(idt->GetType());
265  idr->IDOK = true;
266  idr->Zident = true;
267  }
268  idr->IDcode = idcode[i];
269  // correction for 1st campaign data: ALL masses are positive!!!
270  if (camp1) {
271  // after inspection of data, only CsI R/L provides isotopic identification (for Z<5)
272  if (idcode[i] != 2) {
273  a_indra[i] = -TMath::Abs(a_indra[i]);
274  a[i] = -TMath::Abs(a[i]);
275  }
276  }
277  idr->Aident = (a[i] > 0);
278  if (idr->Aident) idr->PID = a_indra[i];
279  else idr->PID = z_indra[i];
280  if (z[i] < 0 || z[i] > 92)
281  idr->Z = 0;
282  else
283  idr->Z = z[i];
284  idr->A = TMath::Abs(a[i]);
290  nuc->SetIsIdentified();
291  nuc->SetIdentification(idr, idt);
292 
293  if (ecode[i] > 0 && ecode[i] < 4 && ener[i] > 0) {
294  nuc->SetIsCalibrated();
295  nuc->SetECode(ecode[i]);
296  nuc->SetEnergy(ener[i]);
297  nuc->GetAnglesFromReconstructionTrajectory();
298  if (phos_fired(i)) {
299  nuc->SetParameter("INDRA.EPHOS", de1[i]);
300  }
301  if (ci_fired(i)) {
302  nuc->SetParameter("INDRA.ECHIO", de1[i]);
303  nuc->SetParameter("INDRA.DE_MYLAR", de_mylar[i]);
304  };
305  if (si_fired(i)) {
306  nuc->SetParameter("INDRA.ESI", de2[i]);
307  }
308  if (csi_fired(i)) {
309  nuc->SetParameter("INDRA.ECSI", de3[i]);
310  }
311  if (si75_fired(i)) nuc->SetParameter("INDRA.ESI75", de4[i]);
312  if (sili_fired(i)) nuc->SetParameter("INDRA.ESILI", de5[i]);
313  }
314  else
315  nuc->SetIsUncalibrated();
316  }
317 
318  output_tree->Fill();
319 
320  ++events_read;
321  if (!(events_read % 1000)) std::cout << "Read " << events_read << "/" << total_events << " events...\n";
322 
323  return kTRUE;
324 }
325 
326 
327 
332 
334 {
335  // The SlaveTerminate() function is called after all entries or objects
336  // have been processed. When running with PROOF SlaveTerminate() is called
337  // on each slave server.
338 
339 }
340 
341 
342 
347 
349 {
350  // The Terminate() function is the last function to be called during
351  // a query. It always runs on the client, it can be used to present
352  // the results graphically or save the results to file.
353 
354  output_file->cd();
355  gDataAnalyser->WriteBatchInfo(output_tree);
356  output_tree->Write(); //write tree to file
357 
358  //add new file to repository
359  gDataSet->CommitRunfile("recon", run_index, output_file);
360 }
361 
362 
unsigned int UInt_t
bool Bool_t
constexpr Bool_t kTRUE
Option_t Option_t option
char * Form(const char *fmt,...)
virtual const Char_t * GetType() const
Definition: KVBase.h:176
virtual Bool_t IsCalled(const Char_t *name) const
Definition: KVBase.h:189
void WriteBatchInfo(TTree *)
void CommitRunfile(const KVString &type, const run_index_t &run, TFile *file)
Definition: KVDataSet.cpp:1420
TFile * NewRunfile(const KVString &type, const run_index_t &run)
Definition: KVDataSet.cpp:1119
Easily calculate energy losses etc. in a stack of detectors.
Double_t GetPunchThroughEnergy(Int_t Z, Int_t A)
void Add(KVDetector *)
Base class for detector geometry description, interface to energy-loss calculations.
Definition: KVDetector.h:159
KVGroup * GetGroup() const
KVGeoDetectorNode * GetNode()
Definition: KVDetector.h:345
KVNameValueList * GetParameters() const
Definition: KVEvent.h:180
static void MakeEventBranch(TTree *tree, const TString &branchname, T &event, Int_t bufsize=10000000)
Definition: KVEvent.h:211
void Clear(Option_t *opt="") override
Definition: KVEvent.h:239
void SetParameter(const Char_t *name, ValType value) const
Definition: KVEvent.h:198
const KVDBRunFile & GetDBRunFile(const run_index_t &r) const
Definition: KVExpDB.h:139
Path taken by particles through multidetector geometry.
const KVSeqCollection * GetTrajectories() const
const KVGeoDNTrajectory * GetTrajectoryForReconstruction(const KVGeoDNTrajectory *t, const KVGeoDetectorNode *n) const
Definition: KVGroup.h:117
Base class for all detectors or associations of detectors in array which can identify charged particl...
Definition: KVIDTelescope.h:85
virtual UShort_t GetIDCode()
TTreeReaderArray< Float_t > si_gg
TTreeReaderArray< Int_t > z
TTreeReaderArray< Float_t > de1
TTreeReaderArray< Float_t > z_indra
KVINDRADetector * get_sili(int i)
TTreeReaderValue< Int_t > npart_traite
pointer to the analyzed TTree or TChain
TTreeReaderArray< Float_t > a_indra
KVINDRADetector * get_ci(int i)
void SlaveBegin(TTree *tree) override
TTreeReaderArray< Float_t > de5
TTreeReaderArray< Float_t > de3
TTreeReaderArray< Float_t > de4
TTreeReaderArray< Float_t > ci_gg
TTreeReaderArray< Float_t > si_pg
TTreeReaderArray< Int_t > a
TTreeReaderArray< Float_t > csi_r
KVINDRADetector * get_phos(int i)
KVINDRADetector * get_si75(int i)
Bool_t Process(Long64_t entry) override
TTreeReaderArray< Float_t > csi_l
TTreeReaderArray< Float_t > ci_pg
TTreeReaderArray< Int_t > icou
KVINDRADetector * get_csi(int i)
TTreeReaderArray< Float_t > de_mylar
TTreeReaderArray< Int_t > imod
KVReconstructedEvent * the_event
TTreeReaderArray< Int_t > idcode
TTreeReaderArray< Float_t > ener
TTreeReader fReader
the tree reader
void SlaveTerminate() override
KVINDRADetector * get_si(int i)
TTreeReaderArray< Float_t > de2
TTreeReaderArray< Int_t > ecode
void Begin(TTree *tree) override
Base class for detectors of INDRA array.
KVINDRADetector * GetChIo() const
@ ID_CI_SI75
particle identified in ChIo-Si75 etalon telescope
Definition: KVINDRA.h:136
@ ID_SI_CSI
particle identified in Si-CsI telescope
Definition: KVINDRA.h:131
@ ID_NEUTRON
'neutron' discriminated by coherency between CsI and Si-CsI identifications
Definition: KVINDRA.h:128
@ ID_CI_SI
particle identified in ChIo-Si telescope
Definition: KVINDRA.h:134
@ ID_CI_SI_COHERENCY
particle identified in ChIo-Si telescope in coincidence with light particle identified in CsI
Definition: KVINDRA.h:137
@ ID_STOPPED_IN_FIRST_STAGE
particle stopped in first detector of telescope, only minimum Z can be estimated
Definition: KVINDRA.h:126
@ ID_CSI_PSA
particle identified in CsI detector by pulse shape analysis
Definition: KVINDRA.h:130
@ ID_PHOSWICH
particle identified in phoswich (campaigns 1-3)
Definition: KVINDRA.h:129
@ NO_IDENTIFICATION
no identification either attempted or available for particle
Definition: KVINDRA.h:125
@ ID_CI_COHERENCY
particle stopped in ChIo revealed by coherency tests (Zmin)
Definition: KVINDRA.h:138
@ ID_CI_MULTIHIT
particles stopped in multiple Si (ring<10) or CsI (ring>9) behind same ChIo, bad identification
Definition: KVINDRA.h:139
@ ID_CSI_FRAGMENT
particle partially identified in CsI detector, with Z greater than identifiable
Definition: KVINDRA.h:140
@ ID_GAMMA
'gamma' particle detected in CsI
Definition: KVINDRA.h:127
@ ID_CSI_MASS_OUT_OF_RANGE
particle partially identified in CsI detector, mass out of range of apparent Z (pile-up?...
Definition: KVINDRA.h:141
@ ID_SI75_SILI
particle identified in Si75-SiLi etalon telescope
Definition: KVINDRA.h:132
@ ID_CI_CSI
particle identified in ChIo-CsI telescope
Definition: KVINDRA.h:135
virtual KVINDRADetector * GetDetectorByType(UInt_t cou, UInt_t mod, UInt_t type) const
Definition: KVINDRA.cpp:240
const KVSeqCollection * GetListOfPhoswich() const
Definition: KVINDRA.h:247
static KVMultiDetArray * MakeMultiDetector(const Char_t *dataset_name, Int_t run=-1, TString classname="KVMultiDetArray", KVExpDB *db=nullptr)
virtual void SetParameters(UInt_t n, Bool_t physics_parameters_only=kFALSE)
void IncrementValue(const Char_t *name, value_type value)
void SetParameter(const Char_t *name, ValType value) const
Definition: KVParticle.h:822
Path through detector array used to reconstruct detected particle.
Event containing KVReconstructedNucleus nuclei reconstructed from hits in detectors.
TObject * First() const override
Particle * AddParticle()
Handle list of options and input parameters for user analyis .
TString GetOpt(const Char_t *opt) const
void ParseOptions(const KVString &optlist)
virtual Bool_t IsEmpty() const
Bool_t cd() override
const char * GetName() const override
const char * GetTitle() const override
virtual void Warning(const char *method, const char *msgfmt,...) const
virtual void Error(const char *method, const char *msgfmt,...) const
virtual void Info(const char *method, const char *msgfmt,...) const
const char * GetOption() const override
Int_t Atoi() const
EEntryStatus SetLocalEntry(Long64_t entry)
virtual Int_t Fill()
Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0) const override
void set_run(int r)
Definition: run_index.h:63
long long Long64_t
Double_t Abs(Double_t d)