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