BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnEcal.cxx
Go to the documentation of this file.
1
2/*************************************************************************************
3 *
4 * Class BmnEcal
5 *
6 * Adopted for BMN by: Elena Litvinenko (EL)
7 * e-mail: litvin@nf.jinr.ru
8 * Version: 10-02-2016
9 * Last update: 10-02-2016 (EL)
10 * Updated: 23-06-2021 by Petr Alekseev <pnaleks@gmail.com>
11 *
12 ************************************************************************************/
13
14#include "BmnEcal.h"
15
16#include "BmnEcalGeo.h"
17#include "BmnEcalPoint.h"
18#include "CbmStack.h"
19#include "FairGeoInterface.h"
20#include "FairGeoLoader.h"
21#include "FairGeoNode.h"
22#include "FairGeoRootBuilder.h"
23#include "FairRootManager.h"
24#include "FairRun.h"
25#include "FairRuntimeDb.h"
26#include "FairVolume.h"
27#include "TClonesArray.h"
28#include "TGeoArb8.h"
29#include "TGeoMCGeometry.h"
30#include "TGeoManager.h"
31#include "TLorentzVector.h"
32#include "TObjArray.h"
33#include "TParticle.h"
34#include "TParticlePDG.h"
35#include "TVirtualMC.h"
36
37#include <iostream>
38
39// ----- Default constructor -------------------------------------------
41{
42 fEcalCollection = new TClonesArray("BmnEcalPoint");
43 fVerboseLevel = 1;
44}
45// -------------------------------------------------------------------------
46
47// ----- Standard constructor ------------------------------------------
48BmnEcal::BmnEcal(const char* name, Bool_t active)
49 : FairDetector(name, active)
50{
51 fEcalCollection = new TClonesArray("BmnEcalPoint");
52 fVerboseLevel = 1;
53}
54// -------------------------------------------------------------------------
55
56// ----- Destructor ----------------------------------------------------
58{
59 if (fEcalCollection) {
60 fEcalCollection->Delete();
61 delete fEcalCollection;
62 }
63}
64// -------------------------------------------------------------------------
65
66// ----- Public method Intialize ---------------------------------------
68{
69 // Init function
70
71 FairDetector::Initialize();
72 // FairRun* sim = FairRun::Instance();
73 // FairRuntimeDb* rtdb=sim->GetRuntimeDb();
74}
75// -------------------------------------------------------------------------
76
78{
79 // Begin of the event
80}
81
82// ----- Public method ProcessHits --------------------------------------
84{
85
86// #define EDEBUG
87#ifdef EDEBUG
88 static Int_t lEDEBUGcounter = 0;
89 if (lEDEBUGcounter < 1)
90 std::cout << "EDEBUG-- BmnEcal::ProcessHits: entered" << gMC->CurrentVolPath() << endl;
91#endif
92 // #undef EDEBUG
93
94 if (gMC->IsTrackEntering()) {
95 fELoss = 0.;
96 fTime = gMC->TrackTime() * 1.0e09;
97 fLength = gMC->TrackLength();
98 gMC->TrackPosition(fPos);
99 gMC->TrackMomentum(fMom);
100 }
101
102 fELoss += gMC->Edep();
103
104 if (gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()) {
105
106 if (fELoss == 0.)
107 return kFALSE;
108
109 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
110 fVolumeID = vol->getMCid();
111
112 // Using data of the exiting track instead of the entering (why?)
113 fTime = gMC->TrackTime() * 1.0e09;
114 fLength = gMC->TrackLength();
115 gMC->TrackPosition(fPos);
116 gMC->TrackMomentum(fMom);
117
118 Int_t copyNo;
119 gMC->CurrentVolID(copyNo);
120 Int_t copyNoMother;
121 gMC->CurrentVolOffID(1, copyNoMother);
122
123 AddHit(fTrackID, fVolumeID, copyNo, copyNoMother, TVector3(fPos.X(), fPos.Y(), fPos.Z()),
124 TVector3(fMom.Px(), fMom.Py(), fMom.Pz()), fTime, fLength, fELoss);
125
126 ((CbmStack*)gMC->GetStack())->AddPoint(kECAL);
127 }
128
129 return kTRUE;
130}
131
132// ----------------------------------------------------------------------------
133
134// ----- Public method EndOfEvent -----------------------------------------
136{
137 if (fVerboseLevel)
138 Print("");
139 Reset();
140}
141
142// ----- Public method Register -------------------------------------------
144{
145 FairRootManager::Instance()->Register("EcalPoint", "Ecal", fEcalCollection, fToFile);
146}
147
148// ----- Public method GetCollection --------------------------------------
150{
151 if (iColl == 0)
152 return fEcalCollection;
153
154 return NULL;
155}
156
157// ----- Public method Print ----------------------------------------------
159{
160 Int_t nHits = fEcalCollection->GetEntriesFast();
161 cout << "-I- BmnEcal: " << nHits << " points registered in this event." << endl;
162
163 if (fVerboseLevel > 1)
164 for (Int_t i = 0; i < nHits; i++)
165 (*fEcalCollection)[i]->Print();
166}
167
168// ----- Public method Reset ----------------------------------------------
170{
171 fEcalCollection->Clear();
172}
173
174// guarda in FairRootManager::CopyClones
175// ----- Public method CopyClones -----------------------------------------
177{
178 Int_t nEntries = cl1->GetEntriesFast();
179 // cout << "-I- BmnEcal: " << nEntries << " entries to add." << endl;
180 TClonesArray& clref = *cl2;
181 BmnEcalPoint* oldpoint = NULL;
182 for (Int_t i = 0; i < nEntries; i++) {
183 oldpoint = (BmnEcalPoint*)cl1->At(i);
184 Int_t index = oldpoint->GetTrackID() + offset;
185 oldpoint->SetTrackID(index);
186 new (clref[cl2->GetEntriesFast()]) BmnEcalPoint(*oldpoint);
187 }
188 cout << " -I- BmnEcal: " << cl2->GetEntriesFast() << " merged entries." << endl;
189}
190
191// ----- Public method ConstructGeometry ----------------------------------
193{
194
195 TString geoFileName = GetGeometryFileName();
196 if (geoFileName.EndsWith(".root")) {
197 LOG(info) << "Constructing ECAL geometry from ROOT file " << geoFileName.Data();
198 ConstructRootGeometry();
199 return;
200 }
201
202 FairGeoLoader* geoLoad = FairGeoLoader::Instance();
203 FairGeoInterface* geoFace = geoLoad->getGeoInterface();
204 BmnEcalGeo* ecalGeo = new BmnEcalGeo();
205 ecalGeo->setGeomFile(GetGeometryFileName());
206 geoFace->addGeoModule(ecalGeo);
207
208 Bool_t rc = geoFace->readSet(ecalGeo);
209 if (rc)
210 ecalGeo->create(geoLoad->getGeoBuilder());
211 TList* volList = ecalGeo->getListOfVolumes();
212
213 // store geo parameter
214 FairRun* fRun = FairRun::Instance();
215 FairRuntimeDb* rtdb = FairRun::Instance()->GetRuntimeDb();
216 BmnEcalGeoPar* par = (BmnEcalGeoPar*)(rtdb->getContainer("BmnEcalGeoPar"));
217 TObjArray* fSensNodes = par->GetGeoSensitiveNodes();
218 TObjArray* fPassNodes = par->GetGeoPassiveNodes();
219
220 TListIter iter(volList);
221 FairGeoNode* node = NULL;
222 FairGeoVolume* aVol = NULL;
223
224 while ((node = (FairGeoNode*)iter.Next())) {
225 aVol = dynamic_cast<FairGeoVolume*>(node);
226
227 if (node->isSensitive()) {
228 fSensNodes->AddLast(aVol);
229 } else {
230 fPassNodes->AddLast(aVol);
231 }
232 }
233 par->setChanged();
234 par->setInputVersion(fRun->GetRunId(), 1);
235
236 ProcessNodes(volList);
237}
238
239// ----- Public method CheckIfSensitive -----------------------------------
241{
242 TString tsname = name;
243 if (tsname.Contains("laySci"))
244 return kTRUE; // lay
245
246 return kFALSE;
247}
248
249// ----- Private method AddHit --------------------------------------------
251 Int_t detID,
252 Int_t copyNo,
253 Int_t copyNoMother,
254 TVector3 pos,
255 TVector3 mom,
256 Double_t time,
257 Double_t length,
258 Double_t eLoss)
259{
261 Int_t size = clref.GetEntriesFast();
262 return new (clref[size]) BmnEcalPoint(trackID, detID, copyNo, copyNoMother, pos, mom, time, length, eLoss);
263}
int i
Definition P4_F32vec4.h:22
bool Bool_t
int Int_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
const char Option_t
@ kECAL
TObjArray * GetGeoSensitiveNodes()
TObjArray * GetGeoPassiveNodes()
virtual ~BmnEcal()
Destructor.
Definition BmnEcal.cxx:57
virtual Bool_t ProcessHits(FairVolume *vol=0)
Virtual method ProcessHits.
Definition BmnEcal.cxx:83
virtual void CopyClones(TClonesArray *cl1, TClonesArray *cl2, Int_t offset)
Virtual method CopyClones.
Definition BmnEcal.cxx:176
virtual void Register()
Virtual method Register.
Definition BmnEcal.cxx:143
BmnEcal()
Default constructor.
Definition BmnEcal.cxx:40
Double32_t fELoss
length
Definition BmnEcal.h:120
TLorentzVector fMom
position
Definition BmnEcal.h:117
TLorentzVector fPos
volume id
Definition BmnEcal.h:116
BmnEcalPoint * AddHit(Int_t trackID, Int_t detID, Int_t copyNo, Int_t copyNoMother, TVector3 pos, TVector3 mom, Double_t tof, Double_t length, Double_t eLoss)
Definition BmnEcal.cxx:250
virtual Bool_t CheckIfSensitive(std::string name)
Definition BmnEcal.cxx:240
virtual void BeginEvent()
Definition BmnEcal.cxx:77
Int_t fVolumeID
track index
Definition BmnEcal.h:115
Double32_t fTime
momentum
Definition BmnEcal.h:118
virtual void Print(Option_t *) const
Virtual method Print.
Definition BmnEcal.cxx:158
TClonesArray * fEcalCollection
energy loss
Definition BmnEcal.h:122
virtual void EndOfEvent()
Virtual method EndOfEvent.
Definition BmnEcal.cxx:135
Int_t fTrackID
Definition BmnEcal.h:114
virtual TClonesArray * GetCollection(Int_t iColl) const
Accessor to the hit collection.
Definition BmnEcal.cxx:149
Bool_t fToFile
Hit collection.
Definition BmnEcal.h:124
Double32_t fLength
time
Definition BmnEcal.h:119
virtual void Initialize()
Virtual method Initialize Initialises detector.
Definition BmnEcal.cxx:67
virtual void ConstructGeometry()
Virtual method Construct geometry.
Definition BmnEcal.cxx:192
virtual void Reset()
Virtual method Reset.
Definition BmnEcal.cxx:169
CbmStack.h.
Definition CbmStack.h:43
TObject * Next() override
Int_t GetEntriesFast() const
TObject * At(Int_t idx) const override
void AddLast(TObject *obj) override
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
const char * Data() const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const