Commit 2e311090 authored by Eoin Clerkin's avatar Eoin Clerkin
Browse files

BFTC detector

As a skeleton detector system for the BFTC
parent 7f6a2088
...@@ -12,8 +12,10 @@ add_subdirectory(detectors/rich) ...@@ -12,8 +12,10 @@ add_subdirectory(detectors/rich)
add_subdirectory(detectors/much) add_subdirectory(detectors/much)
add_subdirectory(detectors/tof) add_subdirectory(detectors/tof)
add_subdirectory(detectors/sts) add_subdirectory(detectors/sts)
add_subdirectory(detectors/bftc)
add_subdirectory(detectors/psd) add_subdirectory(detectors/psd)
Execute_Process(COMMAND ${ROOT_CONFIG_EXECUTABLE} --has-opengl Execute_Process(COMMAND ${ROOT_CONFIG_EXECUTABLE} --has-opengl
OUTPUT_VARIABLE EveIsBuild OUTPUT_VARIABLE EveIsBuild
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_STRIP_TRAILING_WHITESPACE
......
################################################################################
# Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
# #
# This software is distributed under the terms of the #
# GNU Lesser General Public Licence (LGPL) version 3, #
# copied verbatim in the file "LICENSE" #
################################################################################
# Create a library called "libCbmBftc" which includes the source files given in
# the array .
# The extension is already found. Any number of sources could be listed here.
set(INCLUDE_DIRECTORIES
${ROOT_INCLUDE_DIR}
#put here all directories where header files are located
${BASE_INCLUDE_DIRECTORIES}
#${CMAKE_SOURCE_DIR}/<directory which contains the DetectorList>
#${CMAKE_SOURCE_DIR}/<directory which contains the stack>
${CMAKE_SOURCE_DIR}/bftc
)
include_directories( ${INCLUDE_DIRECTORIES})
set(LINK_DIRECTORIES
${ROOT_LIBRARY_DIR}
)
link_directories( ${LINK_DIRECTORIES})
Include_Directories(SYSTEM ${SYSTEM_INCLUDE_DIRECTORIES})
set(SRCS
#Put here your sourcefiles
CbmBftc.cxx
CbmBftcContFact.cxx
CbmBftcGeo.cxx
CbmBftcGeoPar.cxx
CbmBftcPoint.cxx
)
Set(HEADERS )
Set(LINKDEF CbmBftcLinkDef.h)
Set(LIBRARY_NAME CbmBftc)
Set(DEPENDENCIES
Base
)
GENERATE_LIBRARY()
/********************************************************************************
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#include "CbmBftc.h"
#include "CbmBftcPoint.h"
#include "CbmBftcGeo.h"
#include "CbmBftcGeoPar.h"
#include "FairVolume.h"
#include "FairGeoVolume.h"
#include "FairGeoNode.h"
#include "FairRootManager.h"
#include "FairGeoLoader.h"
#include "FairGeoInterface.h"
#include "FairRun.h"
#include "FairRuntimeDb.h"
#include "MyProjDetectorList.h"
#include "MyProjStack.h"
#include "TClonesArray.h"
#include "TVirtualMC.h"
#include "TGeoManager.h"
#include "TGeoBBox.h"
#include "TGeoCompositeShape.h"
#include "TGeoTube.h"
#include "TGeoMaterial.h"
#include "TGeoMedium.h"
#include <iostream>
using std::cout;
using std::endl;
CbmBftc::CbmBftc()
: FairDetector("CbmBftc", kTRUE, kCbmBftc),
fTrackID(-1),
fVolumeID(-1),
fPos(),
fMom(),
fTime(-1.),
fLength(-1.),
fELoss(-1),
fCbmBftcPointCollection(new TClonesArray("CbmBftcPoint"))
{
}
CbmBftc::CbmBftc(const char* name, Bool_t active)
: FairDetector(name, active, kCbmBftc),
fTrackID(-1),
fVolumeID(-1),
fPos(),
fMom(),
fTime(-1.),
fLength(-1.),
fELoss(-1),
fCbmBftcPointCollection(new TClonesArray("CbmBftcPoint"))
{
}
CbmBftc::CbmBftc(const CbmBftc& right)
: FairDetector(right),
fTrackID(-1),
fVolumeID(-1),
fPos(),
fMom(),
fTime(-1.),
fLength(-1.),
fELoss(-1),
fCbmBftcPointCollection(new TClonesArray("CbmBftcPoint"))
{
}
CbmBftc::~CbmBftc()
{
if (fCbmBftcPointCollection) {
fCbmBftcPointCollection->Delete();
delete fCbmBftcPointCollection;
}
}
void CbmBftc::Initialize()
{
/**
* WORKAROUND needed for Geant4 in MT mode
* Call AddSensitiveVolume for sensitive volumes in order to fill
* thread-local FairModule::svList.
*/
DefineSensitiveVolumes();
FairDetector::Initialize();
FairRuntimeDb* rtdb= FairRun::Instance()->GetRuntimeDb();
CbmBftcGeoPar* par=(CbmBftcGeoPar*)(rtdb->getContainer("CbmBftcGeoPar"));
}
Bool_t CbmBftc::ProcessHits(FairVolume* vol)
{
/** This method is called from the MC stepping */
//Set parameters at entrance of volume. Reset ELoss.
if ( TVirtualMC::GetMC()->IsTrackEntering() ) {
fELoss = 0.;
fTime = TVirtualMC::GetMC()->TrackTime() * 1.0e09;
fLength = TVirtualMC::GetMC()->TrackLength();
TVirtualMC::GetMC()->TrackPosition(fPos);
TVirtualMC::GetMC()->TrackMomentum(fMom);
}
// Sum energy loss for all steps in the active volume
fELoss += TVirtualMC::GetMC()->Edep();
// Create CbmBftcPoint at exit of active volume
if ( TVirtualMC::GetMC()->IsTrackExiting() ||
TVirtualMC::GetMC()->IsTrackStop() ||
TVirtualMC::GetMC()->IsTrackDisappeared() ) {
fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber();
fVolumeID = vol->getMCid();
if (fELoss == 0. ) { return kFALSE; }
AddHit(fTrackID, fVolumeID, TVector3(fPos.X(), fPos.Y(), fPos.Z()),
TVector3(fMom.Px(), fMom.Py(), fMom.Pz()), fTime, fLength,
fELoss);
// Increment number of CbmBftc det points in TParticle
MyProjStack* stack = (MyProjStack*) TVirtualMC::GetMC()->GetStack();
stack->AddPoint(kCbmBftc);
}
return kTRUE;
}
void CbmBftc::EndOfEvent()
{
LOG(info) << "CbmBftc: " << fCbmBftcPointCollection->GetEntriesFast()
<< " points registered in this event";
fCbmBftcPointCollection->Clear();
}
void CbmBftc::Register()
{
/** This will create a branch in the output tree called
CbmBftcPoint, setting the last parameter to kFALSE means:
this collection will not be written to the file, it will exist
only during the simulation.
*/
if ( ! gMC->IsMT() ) {
FairRootManager::Instance()->Register("CbmBftcPoint", "CbmBftc",
fCbmBftcPointCollection, kTRUE);
} else {
FairRootManager::Instance()->RegisterAny("CbmBftcPoint",
fCbmBftcPointCollection, kTRUE);
}
}
TClonesArray* CbmBftc::GetCollection(Int_t iColl) const
{
if (iColl == 0) { return fCbmBftcPointCollection; }
else { return NULL; }
}
void CbmBftc::Reset()
{
fCbmBftcPointCollection->Clear();
}
void CbmBftc::ConstructGeometry()
{
TGeoVolume *top=gGeoManager->GetTopVolume();
TGeoMedium *Si =gGeoManager->GetMedium("Si");
TGeoMedium *Carbon = gGeoManager->GetMedium("C");
if(Si==0){
TGeoMaterial *matSi = new TGeoMaterial("Si", 28.0855, 14, 2.33);
Si = new TGeoMedium("Si", 2, matSi);
}
if(Carbon==0){
TGeoMaterial *matCarbon = new TGeoMaterial("C", 12.011, 6.0, 2.265);
Carbon = new TGeoMedium("C", 3, matCarbon);
}
TGeoVolume *det1= gGeoManager->MakeTubs("Det1",Si,5,80,0.1,0,360);
TGeoRotation r1;
r1.SetAngles(0,0,0);
TGeoTranslation t1(0, 0, 0);
TGeoCombiTrans c1(t1, r1);
TGeoHMatrix *h1 = new TGeoHMatrix(c1);
top->AddNode(det1,1,h1);
det1->SetLineColor(kGreen);
AddSensitiveVolume(det1);
TGeoVolume *passive1= gGeoManager->MakeTubs("Pass1",Si,5,120,10,0,360);
TGeoRotation rp1;
rp1.SetAngles(0,0,0);
TGeoTranslation tp1(0, 0, 20);
TGeoCombiTrans cp1(tp1, rp1);
TGeoHMatrix *hp1 = new TGeoHMatrix(cp1);
top->AddNode(passive1,1,hp1);
passive1->SetLineColor(kRed);
TGeoVolume *det2= gGeoManager->MakeTubs("Det2",Si,5,150,0.1,0,360);
TGeoRotation r2;
r2.SetAngles(0,0,0);
TGeoTranslation t2(0, 0, 70);
TGeoCombiTrans c2(t2, r2);
TGeoHMatrix *h2 = new TGeoHMatrix(c2);
top->AddNode(det2,1,h2);
det2->SetLineColor(kGreen);
AddSensitiveVolume(det2);
TGeoVolume *det3= gGeoManager->MakeTubs("Det3",Si,5,150,0.1,0,360);
TGeoRotation r3;
r3.SetAngles(0,0,0);
TGeoTranslation t3(0, 0, 150);
TGeoCombiTrans c3(t3, r3);
TGeoHMatrix *h3 = new TGeoHMatrix(c3);
top->AddNode(det3,1,h3);
det3->SetLineColor(kGreen);
AddSensitiveVolume(det3);
}
CbmBftcPoint* CbmBftc::AddHit(Int_t trackID, Int_t detID,
TVector3 pos, TVector3 mom,
Double_t time, Double_t length,
Double_t eLoss)
{
TClonesArray& clref = *fCbmBftcPointCollection;
Int_t size = clref.GetEntriesFast();
return new(clref[size]) CbmBftcPoint(trackID, detID, pos, mom,
time, length, eLoss);
}
FairModule* CbmBftc::CloneModule() const
{
return new CbmBftc(*this);
}
void CbmBftc::DefineSensitiveVolumes()
{
TObjArray* volumes = gGeoManager->GetListOfVolumes();
TIter next(volumes);
TGeoVolume* volume;
while ( ( volume = static_cast<TGeoVolume*>(next()) ) ) {
if ( CheckIfSensitive(volume->GetName()) ) {
LOG(debug2)<<"Sensitive Volume "<< volume->GetName();
AddSensitiveVolume(volume);
}
}
}
Bool_t CbmBftc::CheckIfSensitive(std::string name)
{
if(TString(name).Contains("Det"))
{
return kTRUE;
}
return kFALSE;
}
ClassImp(CbmBftc)
/********************************************************************************
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#ifndef CBMBFTC_H
#define CBMBFTC_H
#include "FairDetector.h"
#include "TVector3.h"
#include "TLorentzVector.h"
class CbmBftcPoint;
class FairVolume;
class TClonesArray;
class CbmBftc: public FairDetector
{
public:
/** Name : Detector Name
* Active: kTRUE for active detectors (ProcessHits() will be called)
* kFALSE for inactive detectors
*/
CbmBftc(const char* Name, Bool_t Active);
/** default constructor */
CbmBftc();
/** destructor */
virtual ~CbmBftc();
/** Initialization of the detector is done here */
virtual void Initialize();
/** this method is called for each step during simulation
* (see FairMCApplication::Stepping())
*/
virtual Bool_t ProcessHits( FairVolume* v=0);
/** Registers the produced collections in FAIRRootManager. */
virtual void Register();
/** Gets the produced collections */
virtual TClonesArray* GetCollection(Int_t iColl) const ;
/** has to be called after each event to reset the containers */
virtual void Reset();
/** Create the detector geometry */
void ConstructGeometry();
/** This method is an example of how to add your own point
* of type CbmBftcPoint to the clones array
*/
CbmBftcPoint* AddHit(Int_t trackID, Int_t detID,
TVector3 pos, TVector3 mom,
Double_t time, Double_t length,
Double_t eLoss);
/** The following methods can be implemented if you need to make
* any optional action in your detector during the transport.
*/
virtual void SetSpecialPhysicsCuts() {;}
virtual void EndOfEvent();
virtual void FinishPrimary() {;}
virtual void FinishRun() {;}
virtual void BeginPrimary() {;}
virtual void PostTrack() {;}
virtual void PreTrack() {;}
virtual void BeginEvent() {;}
virtual FairModule* CloneModule() const;
virtual Bool_t CheckIfSensitive(std::string name);
private:
/** Track information to be stored until the track leaves the
active volume.
*/
Int_t fTrackID; //! track index
Int_t fVolumeID; //! volume id
TLorentzVector fPos; //! position at entrance
TLorentzVector fMom; //! momentum at entrance
Double32_t fTime; //! time
Double32_t fLength; //! length
Double32_t fELoss; //! energy loss
/** container for data points */
TClonesArray* fCbmBftcPointCollection; //!
CbmBftc(const CbmBftc&);
CbmBftc& operator=(const CbmBftc&);
void DefineSensitiveVolumes();
ClassDef(CbmBftc,2)
};
#endif //CBMBFTC_H
/********************************************************************************
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#include "CbmBftcContFact.h"
#include "CbmBftcGeoPar.h"
#include "FairRuntimeDb.h"
#include <iostream>
ClassImp(CbmBftcContFact)
static CbmBftcContFact gCbmBftcContFact;
CbmBftcContFact::CbmBftcContFact()
: FairContFact()
{
/** Constructor (called when the library is loaded) */
fName="CbmBftcContFact";
fTitle="Factory for parameter containers in libCbmBftc";
setAllContainers();
FairRuntimeDb::instance()->addContFactory(this);
}
void CbmBftcContFact::setAllContainers()
{
/** Creates the Container objects with all accepted
contexts and adds them to
the list of containers for the CbmBftc library.
*/
FairContainer* p= new FairContainer("CbmBftcGeoPar",
"CbmBftc Geometry Parameters",
"TestDefaultContext");
p->addContext("TestNonDefaultContext");
containers->Add(p);
}
FairParSet* CbmBftcContFact::createContainer(FairContainer* c)
{
/** Calls the constructor of the corresponding parameter container.
For an actual context, which is not an empty string and not
the default context
of this container, the name is concatinated with the context.
*/
const char* name=c->GetName();
FairParSet* p=NULL;
if (strcmp(name,"CbmBftcGeoPar")==0) {
p=new CbmBftcGeoPar(c->getConcatName().Data(),
c->GetTitle(),c->getContext());
}
return p;
}
/********************************************************************************
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#ifndef CBMBFTCCONTFACT_H
#define CBMBFTCCONTFACT_H
#include "FairContFact.h"
class FairContainer;
class CbmBftcContFact : public FairContFact
{
private:
void setAllContainers();
public:
CbmBftcContFact();
~CbmBftcContFact() {}
FairParSet* createContainer(FairContainer*);
ClassDef( CbmBftcContFact,0) // Factory for all CbmBftc parameter containers
};
#endif
/********************************************************************************
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#include "CbmBftcGeo.h"
#include "FairGeoNode.h"
ClassImp(CbmBftcGeo)
// ----- Default constructor -------------------------------------------
CbmBftcGeo::CbmBftcGeo()
: FairGeoSet()
{
// Constructor
// fName has to be the name used in the geometry for all volumes.
// If there is a mismatch the geometry cannot be build.
fName="newdetector";
maxSectors=0;
maxModules=10;
}
// -------------------------------------------------------------------------
const char* CbmBftcGeo::getModuleName(Int_t m)
{
/** Returns the module name of CbmBftc number m
Setting CbmBftc here means that all modules names in the
ASCII file should start with CbmBftc otherwise they will
not be constructed
*/
sprintf(modName,"CbmBftc%i",m+1);
return modName;
}
const char* CbmBftcGeo::getEleName(Int_t m)
{
/** Returns the element name of Det number m */
sprintf(eleName,"CbmBftc%i",m+1);
return eleName;
}
/********************************************************************************
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#ifndef CBMBFTCGEO_H
#define CBMBFTCGEO_H
#include "FairGeoSet.h"
class CbmBftcGeo : public FairGeoSet
{
protected:
char modName[20]; // name of module
char eleName[20]; // substring for elements in module
public:
CbmBftcGeo();
~CbmBftcGeo() {}
const char* getModuleName(Int_t);
const char* getEleName(Int_t);
inline Int_t getModNumInMod(const TString&);
ClassDef(CbmBftcGeo,1)
};
inline Int_t CbmBftcGeo::getModNumInMod(const TString& name)
{
/** returns the module index from module name
?? in name[??] has to be the length of the detector name in the
.geo file. For example if all nodes in this file starts with
newdetector ?? has to be 11.
*/
return (Int_t)(name[11]-'0')-1; //
}
#endif
/********************************************************************************
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *