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