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