23 #include <TGeoMatrix.h>
25 #include <TVirtualMC.h>
26 #include <TVirtualMCStack.h>
39 , fFairTutorialDet4PointCollection(new TClonesArray(
"FairTutorialDet4Point"))
41 , fMisalignPar(nullptr)
49 , fModifyGeometry(kFALSE)
50 , fGlobalCoordinates(kFALSE)
62 , fFairTutorialDet4PointCollection(new TClonesArray(
"FairTutorialDet4Point"))
64 , fMisalignPar(nullptr)
72 , fModifyGeometry(kFALSE)
73 , fGlobalCoordinates(kFALSE)
85 , fFairTutorialDet4PointCollection(new TClonesArray(
"FairTutorialDet4Point"))
87 , fMisalignPar(nullptr)
95 , fModifyGeometry(kFALSE)
96 , fGlobalCoordinates(kFALSE)
101 LOG(debug4) <<
"Entering Destructor of FairTutorialDet4";
102 if (fFairTutorialDet4PointCollection) {
103 fFairTutorialDet4PointCollection->Delete();
104 delete fFairTutorialDet4PointCollection;
106 LOG(debug4) <<
"Leaving Destructor of FairTutorialDet4";
112 LOG(info) <<
"Set tutdet missallign parameters";
115 LOG_IF(
FATAL, !sim) <<
"No run object";
117 LOG_IF(
FATAL, !rtdb) <<
"No runtime database";
128 if (fModifyGeometry) {
129 if (fGlobalCoordinates) {
130 LOG(warn) <<
"Storing MCPoints in global coordinates and modifying the geometry was set.";
131 LOG(warn) <<
"When modifying the geometry is set the MCPoints has to be stored in local coordinates.";
132 LOG(warn) <<
"Store MCPoints in local coordinate system.";
133 fGlobalCoordinates = kFALSE;
141 Bool_t isSimulation = kTRUE;
142 fGeoHandler->
Init(isSimulation);
147 LOG(info) <<
"Initialize tutdet missallign parameters";
152 fRotX = fMisalignPar->
GetRotX();
153 fRotY = fMisalignPar->
GetRotY();
154 fRotZ = fMisalignPar->
GetRotZ();
162 if (TVirtualMC::GetMC()->IsTrackEntering()) {
164 fTime = TVirtualMC::GetMC()->TrackTime() * 1.0e09;
165 fLength = TVirtualMC::GetMC()->TrackLength();
166 TVirtualMC::GetMC()->TrackPosition(fPos);
167 TVirtualMC::GetMC()->TrackMomentum(fMom);
171 fELoss += TVirtualMC::GetMC()->Edep();
174 if (TVirtualMC::GetMC()->IsTrackExiting() || TVirtualMC::GetMC()->IsTrackStop()
175 || TVirtualMC::GetMC()->IsTrackDisappeared()) {
176 fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber();
183 if (!fGlobalCoordinates) {
186 Double_t master[3] = {fPos.X(), fPos.Y(), fPos.Z()};
189 TVirtualMC::GetMC()->Gmtod(master, local, 1);
192 TVector3(local[0], local[1], local[2]),
193 TVector3(fMom.Px(), fMom.Py(), fMom.Pz()),
200 TVector3(fPos.X(), fPos.Y(), fPos.Z()),
201 TVector3(fMom.Px(), fMom.Py(), fMom.Pz()),
231 return fFairTutorialDet4PointCollection;
242 if (fileName.EndsWith(
".geo")) {
243 LOG(info) <<
"Constructing Tutorial4 geometry from ASCII file " << fileName;
244 ConstructASCIIGeometry();
245 }
else if (fileName.EndsWith(
".root")) {
246 LOG(info) <<
"Constructing Tutorial4 geometry from ROOT file " << fileName;
249 LOG(fatal) <<
"Geometry format not supported.";
255 if (name.find(
"tut4") != std::string::npos) {
261 void FairTutorialDet4::ConstructASCIIGeometry()
267 FairModule::ConstructASCIIGeometry<FairTutorialDet4Geo, FairTutorialDet4GeoPar>(fgGeo,
"FairTutorialDet4GeoPar");
273 TString volStr =
"/cave_1/tutorial4_0/tut4_det_";
275 std::map<std::string, TGeoHMatrix> matrices;
277 for (Int_t iDet = 0; iDet < fNrOfDetectors; ++iDet) {
278 LOG(debug) <<
"Create Matrix for detector nr " << iDet;
282 LOG(debug) <<
"Path: " << volPath;
285 Double_t dx = fShiftX[iDet];
286 Double_t dy = fShiftY[iDet];
287 Double_t dz = fShiftZ[iDet];
288 Double_t dphi = fRotX[iDet];
289 Double_t dtheta = fRotY[iDet];
290 Double_t dpsi = fRotZ[iDet];
292 TGeoRotation* rrot =
new TGeoRotation(
"rot", dphi, dtheta, dpsi);
293 TGeoCombiTrans localdelta = *(
new TGeoCombiTrans(dx, dy, dz, rrot));
294 TGeoHMatrix ldm = TGeoHMatrix(localdelta);
296 std::string thisPath(volPath.Data());
297 matrices[thisPath] = ldm;
300 LOG(info) << fNrOfDetectors <<
" misalignment matrices created!";
307 if (fModifyGeometry) {
309 TString volStr =
"/cave_1/tutorial4_0/tut4_det_";
311 std::map<std::string, TGeoHMatrix> matrices;
313 for (Int_t iDet = 0; iDet < fNrOfDetectors; ++iDet) {
314 LOG(debug) <<
"Create Matrix for detector nr " << iDet;
318 LOG(debug) <<
"Path: " << volPath;
321 Double_t dx = fShiftX[iDet];
322 Double_t dy = fShiftY[iDet];
323 Double_t dz = fShiftZ[iDet];
324 Double_t dphi = fRotX[iDet];
325 Double_t dtheta = fRotY[iDet];
326 Double_t dpsi = fRotZ[iDet];
328 TGeoRotation* rrot =
new TGeoRotation(
"rot", dphi, dtheta, dpsi);
329 TGeoCombiTrans localdelta = *(
new TGeoCombiTrans(dx, dy, dz, rrot));
330 TGeoHMatrix ldm = TGeoHMatrix(localdelta);
332 std::string thisPath(volPath.Data());
333 matrices[thisPath] = ldm;
336 LOG(info) << fNrOfDetectors <<
" misalignment matrices created!";
351 TClonesArray& clref = *fFairTutorialDet4PointCollection;
352 Int_t size = clref.GetEntriesFast();
std::map< std::string, TGeoHMatrix > getMisalignmentMatrices()
virtual void see Tutorial4 for examples LOG(warn)<< "This function is deprecated. Use FairAlignmentHandler instead
list of container factories
void SetGlobalCoordinates(Bool_t globalCoordinates)
virtual void InitParContainers()
Int_t GetUniqueDetectorId()
static FairRun * Instance()
virtual ~FairTutorialDet4()
void setChanged(Bool_t flag=kTRUE)
static FairRootManager * Instance()
ClassImp(FairEventBuilder)
virtual void RegisterAlignmentMatrices()
virtual FairModule * CloneModule() const
FairParSet * getContainer(const Text_t *)
virtual void Initialize()
virtual void EndOfEvent()
virtual void Initialize()
FairMQExParamsParOne * par
void AddAlignmentMatrices(const std::map< std::string, TGeoHMatrix > &alignmentMatrices, bool invertMatrices=false)
virtual Bool_t ProcessHits(FairVolume *v=0)
void setInputVersion(Int_t v=-1, Int_t i=0)
virtual void ConstructRootGeometry(TGeoMatrix *shiftM=nullptr)
FairTutorialDet4Point * AddHit(Int_t trackID, Int_t detID, TVector3 pos, TVector3 mom, Double_t time, Double_t length, Double_t eLoss)
FairRuntimeDb * GetRuntimeDb(void)
void Register(const char *name, const char *Foldername, TNamed *obj, Bool_t toFile)
virtual TString GetGeometryFileName()
virtual TClonesArray * GetCollection(Int_t iColl) const
void AddPoint(DetectorId iDet)
Int_t Init(Bool_t isSimulation=kFALSE)
virtual Bool_t IsSensitive(const std::string &name)