er  dev
ERN15B11Digitizer.cxx
1 /********************************************************************************
2  * Copyright (C) Joint Institute for Nuclear Research *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence version 3 (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 
9 #include "ERN15B11Digitizer.h"
10 
11 #include <TClonesArray.h>
12 
13 #include "ERDigi.h"
14 #include "ERPoint.h"
15 
17  : FairTask()
18 {
19 }
20 
22 {
23 }
24 
25 InitStatus ERN15B11Digitizer::Init()
26 {
27  FairRootManager* ioman = FairRootManager::Instance();
28  if ( ! ioman ) Fatal("Init", "No FairRootManager");
29 
30  TList* BranchsNamesList = ioman->GetBranchNameList();
31  TIter next(BranchsNamesList);
32  TObjString* branchName;
33  while (branchName = (TObjString*)next()) {
34  TString curBranchName = branchName->GetString();
35  if (curBranchName.Contains("Point")) {
36  // Input
37  fPoints[curBranchName] = (TClonesArray*) ioman->GetObject(curBranchName); // input branch name
38  if (!fPoints[curBranchName]) {
39  Fatal("Init", "Can't find input collection DetectorvDetGasPartPoint!");
40  }
41 
42  // Output
43  fDigis[curBranchName] = new TClonesArray("ERDigi"); // class name
44  ioman->Register(curBranchName(0, curBranchName.Length()-5)+"Digi", curBranchName, fDigis[curBranchName], kTRUE);
45  }
46  }
47  return kSUCCESS;
48 }
49 
50 void ERN15B11Digitizer::Exec(Option_t* option)
51 {
52  for(const auto &itPoints: fPoints) {
53  TClonesArray* curBranchArray = itPoints.second;
54  Double_t curEdep = 0.;
55  Double_t curTime = 0.;
56  Int_t curEntries = curBranchArray->GetEntries();
57  for (UInt_t i = 0; i < curEntries; i++) {
58  ERPoint* curPoint = (ERPoint*)curBranchArray->At(i);
59  curEdep = curEdep + curPoint->GetEnergyLoss();
60  curTime = curTime + curPoint->GetTime();
61  } // for end
62  TClonesArray* curOutBra = fDigis[itPoints.first];
63  AddOutputDigi(*curOutBra, curEdep, curTime);
64  } // for end
65 }
66 
67 void ERN15B11Digitizer::AddOutputDigi(TClonesArray& clref, Double_t Edep, Double_t Time)
68 {
69  UInt_t size = clref.GetEntries();
70  new(clref[size])ERDigi(Edep, Time, 1); // id = 1, Edep = Edep, time = Time, volNb = 1
71 }
72 
73 void ERN15B11Digitizer::FinishEvent()
74 {
75  for (const auto &itfDigis: fDigis) {
76  itfDigis.second->Clear();
77  }
78 }
79 
80 ClassImp(ERN15B11Digitizer)
Definition: ERDigi.h:15
Class for the detectors response simulate.
ERN15B11Digitizer()
Default constructor.
void AddOutputDigi(TClonesArray &clref, Double_t Edep=0., Double_t Time=0.)
Write data to output file.
virtual ~ERN15B11Digitizer()
Destructor.
The data class for storing pieces of charged tracks in sensitive volumes in NeuRad.
Definition: ERPoint.h:23