CbmRoot
CbmPsdMCbmHitProducer.cxx
Go to the documentation of this file.
2 
3 #include "CbmDigiManager.h"
4 #include "CbmEvent.h"
5 #include "CbmPsdDigi.h"
6 #include "CbmPsdMCbmHit.h"
7 #include "FairLogger.h"
8 #include "TClonesArray.h"
9 
10 
11 #include <iostream>
12 
13 using namespace std;
14 
15 
17  : FairTask("CbmPsdMCbmHitProducer")
18  , fPsdHits(NULL)
19  , fEventNum(0)
20  , fHitError(10) /*half a module in cm*/
21 {}
22 
24  FairRootManager* manager = FairRootManager::Instance();
25  manager->Write();
26 }
27 
29 
31  FairRootManager* manager = FairRootManager::Instance();
32 
33  fCbmEvents = dynamic_cast<TClonesArray*>(manager->GetObject("CbmEvent"));
34  if (fCbmEvents == nullptr) {
35  LOG(info) << ": CbmEvent NOT found \n \n \n";
36  } else {
37  LOG(info) << ": CbmEvent found \n \n \n";
38  }
39 
41  fDigiMan->Init();
43  Fatal("CbmPsdMCbmHitProducer::Init", "No PsdDigi array!");
44 
45  fPsdHits = new TClonesArray("CbmPsdMCbmHit"); //TODO
46  manager->Register(
47  "PsdHit", "PSD", fPsdHits, IsOutputBranchPersistent("PsdHit"));
48 
49  //InitMapping();
50 
51  return kSUCCESS;
52 }
53 
54 /*
55 void CbmPsdMCbmHitProducer::InitMapping() //TODO change for psd
56 {
57 
58  string line;
59  ifstream file (fMappingFile);
60  if (!file.is_open()){
61  std::cout<<"<CbmPsdMCbmHitProducer::InitMapping>: Unable to open mapping file:" << fMappingFile.c_str()<<std::endl;
62  }
63 
64  fPsdMapping.clear();
65 
66  while ( getline (file,line) ) {
67 
68  istringstream iss(line);
69  vector<std::string> results(istream_iterator<string>{iss}, std::istream_iterator<string>());
70  if (results.size() != 8) continue;
71 
72  CbmRichMCbmMappingData data;
73  data.fTrbId = stoi(results[0], nullptr, 16);
74  data.fChannel = stoi(results[1]);
75  data.fX = stod(results[6]);
76  data.fY = stod(results[7]);
77  data.fZ = 348.;
78 
79  data.fX -= 6.3; //Shift by 1Pmt + PmtGap + 1cm
80 
81  Int_t adr = ((data.fTrbId << 16) | (data.fChannel & 0x00FF));
82 
83  // cout << data.fTrbId << " " << data.fChannel << " " << data.fX << " " << data.fY << " " << adr << endl;
84 
85  fPsdMapping[adr] = data;
86  }
87  file.close();
88 
89  //cout << "Mapping size:" << fPsdMapping.size() <<endl;
90 
91 }
92 */
93 
94 void CbmPsdMCbmHitProducer::Exec(Option_t* /*option*/) {
95  fEventNum++;
96  LOG(info) << "CbmPsdMCbmHitProducer Event " << fEventNum;
97 
98  fPsdHits->Delete();
99 
100  // if CbmEvent does not exist then process standard event.
101  // if CbmEvent exists then proceed all events in time slice.
102  Int_t nUnits = (fCbmEvents != nullptr) ? fCbmEvents->GetEntriesFast() : 1;
103 
104  for (Int_t iUnit = 0; iUnit < nUnits; iUnit++) {
105  CbmEvent* event = (fCbmEvents != nullptr)
106  ? static_cast<CbmEvent*>(fCbmEvents->At(iUnit))
107  : nullptr;
108  ProcessData(event);
109  }
110 }
111 
113  if (event != NULL) {
114  LOG(info) << "CbmPsdMCbmHitProducer CbmEvent mode. CbmEvent # "
115  << event->GetNumber();
116  Int_t nofDigis = event->GetNofData(ECbmDataType::kPsdDigi);
117  LOG(info) << "nofDigis: " << nofDigis;
118 
119  for (Int_t iDigi = 0; iDigi < nofDigis; iDigi++) {
120  Int_t digiIndex = event->GetIndex(ECbmDataType::kPsdDigi, iDigi);
121  ProcessDigi(event, digiIndex);
122  }
123 
124  } else {
125  for (Int_t iDigi = 0; iDigi < fDigiMan->GetNofDigis(ECbmModuleId::kPsd);
126  iDigi++) {
127  ProcessDigi(event, iDigi);
128  }
129  }
130 }
131 
132 void CbmPsdMCbmHitProducer::ProcessDigi(CbmEvent* event, Int_t digiIndex) {
133  const CbmPsdDigi* digi = fDigiMan->Get<CbmPsdDigi>(digiIndex);
134  if (digi == nullptr) return;
135  if (digi->GetAddress() < 0) return;
136  if (isInEnRange(digi->GetEdep())) {
137  AddHit(event,
138  digi->GetTime(),
139  digi->GetEdep(),
140  digi->GetModuleID(),
141  digi->GetSectionID(),
142  digiIndex);
143  }
144 }
145 
147  Double_t time,
148  Double_t energy,
149  UInt_t moduleId,
150  UInt_t sectionId,
151  Int_t /*index*/) {
152 
153  Int_t nofHits = fPsdHits->GetEntriesFast();
154  new ((*fPsdHits)[nofHits]) CbmPsdMCbmHit();
155  CbmPsdMCbmHit* hit = (CbmPsdMCbmHit*) fPsdHits->At(nofHits);
156  hit->SetEdep(energy);
157  hit->SetTime(time);
158  hit->SetModuleID(moduleId);
159  hit->SetSectionID(sectionId);
160 
161  if (event != NULL) { event->AddData(ECbmDataType::kPsdHit, nofHits); }
162 }
163 
164 
166 
167 
168 bool CbmPsdMCbmHitProducer::isInEnRange(const double energy) {
169 
170  if (!fDoEnCut) return true;
171 
172  if ((energy > fEnLimitLow) && (energy < fEnLimitHigh)) {
173  return true;
174  } else {
175  return false;
176  }
177 }
178 
CbmPsdMCbmHitProducer.h
CbmPsdDigi.h
CbmPsdMCbmHitProducer::Finish
virtual void Finish()
Inherited from FairTask.
Definition: CbmPsdMCbmHitProducer.cxx:165
CbmPsdMCbmHitProducer::fDoEnCut
bool fDoEnCut
Definition: CbmPsdMCbmHitProducer.h:83
CbmPsdMCbmHit::SetSectionID
void SetSectionID(UInt_t sec)
Definition: CbmPsdMCbmHit.h:76
CbmDigiManager::Init
InitStatus Init()
Initialisation.
Definition: CbmDigiManager.cxx:71
CbmPsdMCbmHitProducer::isInEnRange
bool isInEnRange(const double energy)
Definition: CbmPsdMCbmHitProducer.cxx:168
CbmPsdMCbmHitProducer::ProcessDigi
void ProcessDigi(CbmEvent *event, Int_t digiIndex)
Definition: CbmPsdMCbmHitProducer.cxx:132
CbmDigiManager::GetNofDigis
static Int_t GetNofDigis(ECbmModuleId systemId)
Definition: CbmDigiManager.cxx:62
CbmPsdMCbmHitProducer::ProcessData
void ProcessData(CbmEvent *event)
Definition: CbmPsdMCbmHitProducer.cxx:112
CbmPsdMCbmHitProducer::fEnLimitHigh
double fEnLimitHigh
Definition: CbmPsdMCbmHitProducer.h:85
CbmPsdDigi::GetAddress
Int_t GetAddress() const
Address.
Definition: CbmPsdDigi.h:79
CbmDigiManager::IsPresent
static Bool_t IsPresent(ECbmModuleId systemId)
Presence of a digi branch.
Definition: CbmDigiManager.cxx:112
CbmDigiManager::Instance
static CbmDigiManager * Instance()
Static instance.
Definition: CbmDigiManager.h:93
CbmPsdMCbmHitProducer
Definition: CbmPsdMCbmHitProducer.h:14
CbmPsdMCbmHit::SetEdep
void SetEdep(Double_t edep)
Definition: CbmPsdMCbmHit.h:77
CbmPsdMCbmHitProducer::Init
virtual InitStatus Init()
Inherited from FairTask.
Definition: CbmPsdMCbmHitProducer.cxx:30
CbmEvent.h
CbmPsdMCbmHitProducer::Exec
virtual void Exec(Option_t *option)
Inherited from FairTask.
Definition: CbmPsdMCbmHitProducer.cxx:94
CbmPsdMCbmHitProducer::fEnLimitLow
double fEnLimitLow
Definition: CbmPsdMCbmHitProducer.h:84
CbmPsdMCbmHitProducer::fDigiMan
CbmDigiManager * fDigiMan
Definition: CbmPsdMCbmHitProducer.h:80
CbmDigiManager::Get
const Digi * Get(Int_t index) const
Get a digi object.
Definition: CbmDigiManager.h:52
ECbmDataType::kPsdDigi
@ kPsdDigi
CbmPsdMCbmHitProducer::fEventNum
Int_t fEventNum
Definition: CbmPsdMCbmHitProducer.h:89
CbmPsdDigi::GetTime
Double_t GetTime() const
Time.
Definition: CbmPsdDigi.h:127
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmPsdMCbmHitProducer::fPsdHits
TClonesArray * fPsdHits
Definition: CbmPsdMCbmHitProducer.h:81
CbmPsdMCbmHit.h
CbmPsdDigi::GetModuleID
Double_t GetModuleID() const
Module Identifier.
Definition: CbmPsdDigi.h:105
CbmDigiManager.h
CbmPsdMCbmHitProducer::CbmPsdMCbmHitProducer
CbmPsdMCbmHitProducer()
Default constructor.
Definition: CbmPsdMCbmHitProducer.cxx:16
CbmEvent
Class characterising one event by a collection of links (indices) to data objects,...
Definition: CbmEvent.h:30
CbmPsdMCbmHit
data class for hit information in PSD
Definition: CbmPsdMCbmHit.h:24
CbmPsdMCbmHitProducer::SetParContainers
virtual void SetParContainers()
Inherited from FairTask.
Definition: CbmPsdMCbmHitProducer.cxx:28
CbmPsdMCbmHit::SetModuleID
void SetModuleID(UInt_t mod)
Definition: CbmPsdMCbmHit.h:75
ECbmModuleId::kPsd
@ kPsd
Projectile spectator detector.
CbmPsdDigi
Data class for PSD digital information.
Definition: CbmPsdDigi.h:31
ECbmDataType::kPsdHit
@ kPsdHit
CbmPsdMCbmHit::SetTime
void SetTime(Double_t time)
Definition: CbmPsdMCbmHit.h:78
CbmPsdMCbmHitProducer::~CbmPsdMCbmHitProducer
virtual ~CbmPsdMCbmHitProducer()
Destructor.
Definition: CbmPsdMCbmHitProducer.cxx:23
CbmPsdMCbmHitProducer::AddHit
void AddHit(CbmEvent *event, Double_t time, Double_t energy, UInt_t moduleId, UInt_t sectionId, Int_t index)
Add hit to the output array (and) CbmEvent if it is not NULL.
Definition: CbmPsdMCbmHitProducer.cxx:146
CbmPsdDigi::GetSectionID
Double_t GetSectionID() const
Section Identifier.
Definition: CbmPsdDigi.h:113
CbmPsdMCbmHitProducer::fCbmEvents
TClonesArray * fCbmEvents
Definition: CbmPsdMCbmHitProducer.h:82
CbmPsdDigi::GetEdep
Double_t GetEdep() const
Energy deposit.
Definition: CbmPsdDigi.h:99