Adding new detector

To create a new detector you have to implement some classes which will describe your detector. The framework deliver you with the base classes which will do most of the work concerning the I/O and geometry construction, ..etc. The following will explain in step by step how to implement a detector MyDet in this framework:
To describe a detector (e.g MyDet ) in FairRoot you have to implement:

Creating the CMakefile




CMakeLists.txt

# Create a library called "libTutorial1" which includes the source files given in
# the array .
# The extension is already found.  Any number of sources could be listed here.

# Create a library called "libTutorial1" 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
${BASE_INCLUDE_DIRECTORIES}
${CMAKE_SOURCE_DIR}/example/Tutorial1/src
${CMAKE_SOURCE_DIR}/example/mcstack
)

include_directories( ${INCLUDE_DIRECTORIES})

set(LINK_DIRECTORIES
${ROOT_LIBRARY_DIR}
) 

link_directories( ${LINK_DIRECTORIES})

set(SRCS
#Put here your sourcefiles
FairTutorialDet1.cxx
FairTutorialDet1ContFact.cxx
FairTutorialDet1Geo.cxx
FairTutorialDet1GeoPar.cxx
FairTutorialDet1Point.cxx
)

Set(HEADERS )
Set(LINKDEF Tutorial1LinkDef.h)
Set(LIBRARY_NAME Tutorial1)
Set(DEPENDENCIES MCStack Base)

GENERATE_LIBRARY()



Detector MC Point class




FairTutorialDetPoint.h

#ifndef FAIRTUTORIALDETPOINT_H
#define FAIRTUTORIALDETPOINT_H 1


#include "FairMCPoint.h"

#include "TObject.h"
#include "TVector3.h"

class FairTutorialDetPoint : public FairMCPoint
{

  public:

    /** Default constructor **/
    FairTutorialDetPoint();


    /** Constructor with arguments
     *@param trackID  Index of MCTrack
     *@param detID    Detector ID
     *@param pos      Ccoordinates at entrance to active volume [cm]
     *@param mom      Momentum of track at entrance [GeV]
     *@param tof      Time since event start [ns]
     *@param length   Track length since creation [cm]
     *@param eLoss    Energy deposit [GeV]
     **/
    FairTutorialDetPoint(Int_t trackID, Int_t detID, TVector3 pos, TVector3 mom,
                         Double_t tof, Double_t length, Double_t eLoss);


    /** Copy constructor **/
    //    FairTutorialDetPoint(const FairTutorialDetPoint& point) { *this = point; };


    /** Destructor **/
    virtual ~FairTutorialDetPoint();

    /** Output to screen **/
    virtual void Print(const Option_t* opt) const;


    ClassDef(FairTutorialDetPoint,1)

};

#endif


Detector class

A detector class should inherits from the FairDetector class, the header file will looks like:




mydet.h


#ifndef FAIRTUTORIALDET_H
#define FAIRTUTORIALDET_H

#include "FairDetector.h"
class FairVolume;
class TClonesArray;

class FairTutorialDet: public FairDetector {
public:
    /**  Name :  Detector Name
        Active: kTRUE for active detectors  (ProcessHits() will be called)
                kFALSE for inactive detectors
    */
    FairTutorialDet(const char * Name, Bool_t Active);
    /** default constructor    */
    FairTutorialDet();
    /** destructor     */
    virtual ~FairTutorialDet();
    /** Initialization of the detector is done here    */
    virtual void   Initialize();
    /** this method is called for each step during dsimulation (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 FairTutorialDetPoint to the clones array */
     FairTutorialDetPoint* FairTutorialDet::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.
    */

    /**Special cuts on media specific for this detector can be implemneted here*/
    virtual void   SetSpecialPhysicsCuts(){;}
    /** This method is called after proccessing an event*/
    virtual void   EndOfEvent(){;}
    /**This method is called after tracking of a primary particle is finished */
    virtual void   FinishPrimary(){;}
    /**This is called at the end of a run*/
    virtual void   FinishRun(){;}
    /**This method is called when primary track start*/
    virtual void   BeginPrimary(){;}
    /**called after a track is finished (stopped/vanished/absorbed)*/
    virtual void   PostTrack(){;}
    /**called before a new track start stepping*/
    virtual void   PreTrack(){;}
    /**called at the begining of an event*/
    virtual void   BeginEvent(){;}

Private:

     /** container for data points */
     TClonesArray  *fMyPointCollection;
     ClassDef(FairTutorialDet,1)
};
#endif //FAIRTUTORIALDET_H