12#include "TGeoManager.h"
13#include "TGeoPhysicalNode.h"
15#include "TVirtualMC.h"
20#include "FairLogger.h"
32 : FairDetector(name, active,
kSSD),
40 fProcessNeutrals(kFALSE)
65 TString fileName = GetGeometryFileName();
68 if ( ! fileName.EndsWith(
".root") ) {
69 LOG(fatal) << GetName() <<
": Geometry format of file "
70 << fileName.Data() <<
" not supported.";
73 LOG(info) <<
"Constructing " << GetName() <<
" geometry from ROOT file "
94 fSsdPoints =
new TClonesArray(
"BmnSsdPoint");
108 for (Int_t iUnit = 0; iUnit < nUnits; iUnit++) {
111 for (Int_t iLadd = 0; iLadd < nLadd; iLadd++) {
114 for (Int_t iHlad = 0; iHlad < nHlad; iHlad++) {
117 for (Int_t iModu = 0; iModu < nModu; iModu++) {
120 for (Int_t iSens = 0; iSens < nSens; iSens++) {
122 TString path = sensor->
GetPnode()->GetName();
123 if ( ! path.BeginsWith(
"/") ) path.Prepend(
"/");
124 pair<TString, Int_t> a(path, sensor->
GetAddress());
125 fAddressMap.insert(a);
126 TString test = sensor->
GetPnode()->GetName();
132 LOG(info) << fName <<
": Address map initialised with "
133 << Int_t(fAddressMap.size()) <<
" sensors. "
137 FairDetector::Initialize();
148 if ( gMC->IsTrackEntering() ) {
152 SetStatus(fStatusIn);
156 fEloss += gMC->Edep();
160 if ( gMC->IsTrackExiting() ||
161 gMC->IsTrackStop() ||
162 gMC->IsTrackDisappeared() ) {
164 SetStatus(fStatusOut);
167 if (fEloss == 0. && ( ! fProcessNeutrals ) )
return kFALSE;
187 fSsdPoints->Delete();
199 LOG(info) << fName <<
": " << fSsdPoints->GetEntriesFast()
200 <<
" points registered in this event.";
216 LOG(error) << GetName() <<
": inconsistent detector addresses "
224 LOG(error) << GetName() <<
": inconsistent track Id "
231 if ( fStatusIn.
fPid != fStatusOut.
fPid ) {
232 LOG(error) << GetName() <<
": inconsistent track PID "
233 << fStatusIn.
fPid <<
" " << fStatusOut.
fPid
239 TVector3 posIn(fStatusIn.
fX, fStatusIn.
fY, fStatusIn.
fZ);
240 TVector3 momIn(fStatusIn.
fPx, fStatusIn.
fPy, fStatusIn.
fPz);
243 TVector3 posOut(fStatusOut.
fX, fStatusOut.
fY, fStatusOut.
fZ);
244 TVector3 momOut(fStatusOut.
fPx, fStatusOut.
fPy, fStatusOut.
fPz);
247 Double_t time = 0.5 * ( fStatusIn.
fTime + fStatusOut.
fTime );
248 Double_t length = 0.5 * ( fStatusIn.
fLength + fStatusOut.
fLength);
252 if ( fStatusIn.
fFlag ) flag += 1;
253 if ( fStatusOut.
fFlag ) flag += 2;
256 LOG(debug2) << GetName() <<
": Creating point from track "
257 << fStatusIn.
fTrackId <<
" in sensor "
258 << fStatusIn.
fAddress <<
", position (" << posIn.X()
259 <<
", " << posIn.Y() <<
", " << posIn.Z()
260 <<
"), energy loss " << fEloss;
263 Int_t newIndex = fSsdPoints->GetEntriesFast();
264 return new ( (*fSsdPoints)[fSsdPoints->GetEntriesFast()] )
266 momIn, momOut, time, length, fEloss, fStatusIn.
fPid, 0,
278 if ( ! (gMC && gGeoManager) ) {
279 LOG(error) << fName <<
": No TVirtualMC or TGeoManager instance!"
287 TString path = gMC->CurrentVolPath();
289 auto it = fAddressMap.find(path);
290 if ( it == fAddressMap.end() ) {
291 LOG(fatal) << fName <<
": Path not found in address map! "
292 << gGeoManager->GetPath();
298 status.
fTrackId = gMC->GetStack()->GetCurrentTrackNumber();
299 status.
fPid = gMC->GetStack()->GetCurrentTrack()->GetPdgCode();
302 gMC->TrackPosition(status.
fX, status.
fY, status.
fZ);
306 gMC->TrackMomentum(status.
fPx, status.
fPy, status.
fPz, dummy);
309 status.
fTime = gMC->TrackTime() * 1.e9;
310 status.
fLength = gMC->TrackLength();
313 if ( gMC->IsTrackEntering() ) {
314 if ( gMC->IsNewTrack() ) status.
fFlag = kFALSE;
315 else status.
fFlag = kTRUE;
318 if ( gMC->IsTrackDisappeared() || gMC->IsTrackStop() )
319 status.
fFlag = kFALSE;
321 status.
fFlag = kTRUE;
329 if( IsNewGeometryFile(fgeoName) ) {
330 TGeoVolume *module1 = TGeoVolume::Import(fgeoName);
332 gGeoManager->GetTopVolume()->AddNode(module1, 0, fCombiTrans);
333 TGeoNode* node = module1->GetNode(0);
337 FairModule::ConstructRootGeometry();
347 TGeoVolume* v1=fN->GetVolume();
348 TObjArray* NodeList=v1->GetNodes();
349 for (Int_t Nod=0; Nod<NodeList->GetEntriesFast(); Nod++) {
350 TGeoNode* fNode =(TGeoNode*)NodeList->At(Nod);
356 TGeoVolume*
v= fNode->GetVolume();
364 AddSensitiveVolume(
v);
370Bool_t BmnSsdMC::IsNewGeometryFile(TString )
373 TFile*
f=
new TFile(fgeoName);
374 TList* l =
f->GetListOfKeys();
375 Int_t numKeys = l->GetSize();
377 LOG(info) <<
"Not exactly two keys in the file. File is not of new type."
383 Bool_t foundGeoVolume = kFALSE;
384 Bool_t foundGeoMatrix = kFALSE;
385 TGeoTranslation* trans = NULL;
386 TGeoRotation* rot = NULL;
387 while ((key = (TKey*)next())) {
388 if (strcmp(
key->GetClassName(),
"TGeoVolume") == 0) {
389 LOG(debug) <<
"Found TGeoVolume in geometry file.";
390 foundGeoVolume = kTRUE;
393 if (strcmp(
key->GetClassName(),
"TGeoTranslation") == 0) {
394 LOG(debug) <<
"Found TGeoTranslation in geometry file.";
395 foundGeoMatrix = kTRUE;
396 trans =
static_cast<TGeoTranslation*
>(
key->ReadObj());
397 rot =
new TGeoRotation();
398 fCombiTrans =
new TGeoCombiTrans(*trans, *rot);
401 if (strcmp(
key->GetClassName(),
"TGeoRotation") == 0) {
402 LOG(debug) <<
"Found TGeoRotation in geometry file.";
403 foundGeoMatrix = kTRUE;
404 trans =
new TGeoTranslation();
405 rot =
static_cast<TGeoRotation*
>(
key->ReadObj());
406 fCombiTrans =
new TGeoCombiTrans(*trans, *rot);
409 if (strcmp(
key->GetClassName(),
"TGeoCombiTrans") == 0) {
410 LOG(debug) <<
"Found TGeoCombiTrans in geometry file.";
411 foundGeoMatrix = kTRUE;
412 fCombiTrans =
static_cast<TGeoCombiTrans*
>(
key->ReadObj());
416 if ( foundGeoVolume && foundGeoMatrix ) {
419 if ( !foundGeoVolume) {
420 LOG(info) <<
"No TGeoVolume found in geometry file. File is not of new type.";
422 if ( !foundGeoMatrix) {
423 LOG(info) <<
"Not TGeoMatrix derived object found in geometry file. File is not of new type.";
Class representing an element of the SSD setup.
Int_t GetNofDaughters() const
BmnSsdElement * GetDaughter(Int_t index) const
TGeoPhysicalNode * GetPnode() const
virtual void EndOfEvent()
Action at end of event.
void ExpandSsdNodes(TGeoNode *fN)
virtual Bool_t ProcessHits(FairVolume *vol=0)
Action for a track step in a sensitive node of the SSD.
virtual void ConstructGeometry()
Construct the SSD geometry in the TGeoManager.
virtual Bool_t CheckIfSensitive(std::string name)
Check whether a volume is sensitive.
virtual void Print(Option_t *opt="") const
Screen log Prints current number of SsdPoints in array. Virtual from TObject.
virtual void Reset()
Clear output array and reset current track status.
virtual void Initialize()
Initialisation.
virtual void ConstructRootGeometry()
BmnSsdMC(Bool_t active=kTRUE, const char *name="SSDMC")
static BmnSsdSetup * Instance()
Bool_t Init(const char *geometryFile=nullptr, const char *sensorParameterFile=nullptr)
Initialise the setup.
Stores status of track during transport. Auxiliary for BmnSsd.
Double_t fPy
Momentum x component [GeV].
Double_t fX
x position [cm]
Int_t fAddress
Unique address.
Double_t fY
x position [cm]
Double_t fPz
Momentum x component [GeV].
Bool_t fFlag
Status flag. TRUE if normal entry/exit, else FALSE.
Int_t fPid
MCTrack PID [PDG code].
Double_t fZ
x position [cm]
Double_t fLength
Length since track creation [cm].
Int_t fTrackId
MCTrack index.
Double_t fTime
Time since track creation [ns].
Double_t fPx
Momentum x component [GeV].
void AddPoint(DetectorId iDet)