FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairTutorialDet4HitProducerIdealMisalign.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 // -------------------------------------------------------------------------
9 // ----- FairTutorialDet4HitProducerIdealMissallign source file -----
10 // ----- Created 11.02.13 by F. Uhlig -----
11 // -------------------------------------------------------------------------
13 
14 #include "FairLogger.h" // for FairLogger, etc
15 #include "FairRootManager.h" // for FairRootManager
16 #include "FairRunAna.h" // for FairRunAna
17 #include "FairRuntimeDb.h" // for FairRuntimeDb
18 #include "FairTutorialDet4GeoHandler.h" // for FairTutorialDet4GeoHandler
19 #include "FairTutorialDet4GeoPar.h"
20 #include "FairTutorialDet4Hit.h" // for FairTutorialDet4Hit
22 #include "FairTutorialDet4Point.h" // for FairTutorialDet4Point
23 
24 #include <TClonesArray.h> // for TClonesArray
25 #include <TMath.h> // for Cos, Sin
26 #include <TMathBase.h> // for Abs
27 #include <TRandom.h> // for TRandom, gRandom
28 #include <TVector3.h> // for TVector3
29 
31  : FairTask("Missallign Hit Producer for the TutorialDet")
32  , fPointArray(nullptr)
33  , fHitArray(nullptr)
34  , fShiftX()
35  , fShiftY()
36  , fShiftZ()
37  , fRotX()
38  , fRotY()
39  , fRotZ()
40  , fDigiPar(nullptr)
41  , fGeoHandler(new FairTutorialDet4GeoHandler)
42  , fGeoPar(nullptr)
43  , fDoMisalignment(kFALSE)
44 {}
45 
47 {
48 
49  LOG(info) << "Set tutdet missallign parameters";
50  // Get Base Container
52  FairRuntimeDb* rtdb = ana->GetRuntimeDb();
53 
54  fDigiPar = static_cast<FairTutorialDet4MisalignPar*>(rtdb->getContainer("FairTutorialDet4MissallignPar"));
55  fGeoPar = static_cast<FairTutorialDet4GeoPar*>(rtdb->getContainer("FairTutorialDet4GeoPar"));
56 }
57 
59 {
60  // Get Base Container
62  FairRuntimeDb* rtdb = ana->GetRuntimeDb();
63 
64  fDigiPar = static_cast<FairTutorialDet4MisalignPar*>(rtdb->getContainer("FairTutorialDet4MissallignPar"));
65 
66  fShiftX = fDigiPar->GetShiftX();
67  fShiftY = fDigiPar->GetShiftY();
68  fShiftZ = fDigiPar->GetShiftZ();
69  fRotX = fDigiPar->GetRotX();
70  fRotY = fDigiPar->GetRotY();
71  fRotZ = fDigiPar->GetRotZ();
72 
73  return kSUCCESS;
74 }
75 
77 {
78  // Get RootManager
80  if (!ioman) {
81  LOG(fatal) << "RootManager not instantised!";
82  return kFATAL;
83  }
84 
85  // Get input array
86  fPointArray = static_cast<TClonesArray*>(ioman->GetObject("TutorialDetPoint"));
87  if (!fPointArray) {
88  LOG(fatal) << "No TutorialDetPoint array!";
89  return kFATAL;
90  }
91 
92  // Create and register output array
93  fHitArray = new TClonesArray("FairTutorialDet4Hit");
94  ioman->Register("TutorialDetHit", "TutorialDet", fHitArray, kTRUE);
95 
96  LOG(info) << "HitProducerIdealMissallign: Initialisation successfull";
97 
98  fShiftX = fDigiPar->GetShiftX();
99  fShiftY = fDigiPar->GetShiftY();
100  fShiftZ = fDigiPar->GetShiftZ();
101  fRotX = fDigiPar->GetRotX();
102  fRotY = fDigiPar->GetRotY();
103  fRotZ = fDigiPar->GetRotZ();
104 
105  Bool_t isGlobalCoordinateSystem = fGeoPar->IsGlobalCoordinateSystem();
106  if (isGlobalCoordinateSystem) {
107  LOG(fatal) << "Task can only work with local coordinates.";
108  }
109  /*
110  Int_t num = fDigiPar->GetNrOfDetectors();
111  Int_t size = fShiftX.GetSize();
112  LOG(info)<<"Array has a size of "<< size << "elements";
113  for (Int_t i=0; i< num; ++i) {
114  LOG(info)<< i <<": "<<fShiftX.At(i);
115  }
116  */
117  return kSUCCESS;
118 }
119 
121 {
122  fHitArray->Clear();
123 
124  // Declare some variables
125  FairTutorialDet4Point* point = nullptr;
126  Int_t detID = 0; // Detector ID
127  // Int_t trackID = 0; // Track index
128  Double_t x, y, z; // Position
129  Double_t dx = 0.1; // Position error
130  // Double_t tof = 0.; // Time of flight
131  TVector3 pos, dpos; // Position and error vectors
132 
133  // Loop over TofPoints
134  Int_t nHits = 0;
135  Int_t nPoints = fPointArray->GetEntriesFast();
136  for (Int_t iPoint = 0; iPoint < nPoints; iPoint++) {
137  point = static_cast<FairTutorialDet4Point*>(fPointArray->At(iPoint));
138  if (!point) {
139  continue;
140  }
141 
142  // Detector ID
143  detID = point->GetDetectorID();
144 
145  // MCTrack ID
146  // trackID = point->GetTrackID();
147 
148  if (fDoMisalignment) {
149 
150  Float_t cosAlpha = TMath::Cos(fRotZ.At(detID));
151  Float_t sinAlpha = TMath::Sin(fRotZ.At(detID));
152 
153  // Determine hit position
154  x = (point->GetX() * cosAlpha + point->GetY() * sinAlpha) - fShiftX.At(detID);
155  y = (-point->GetX() * sinAlpha + point->GetY() * cosAlpha) - fShiftY.At(detID);
156  z = point->GetZ();
157 
158  LOG(debug) << "Pos before misalignment: " << point->GetX() << ", " << point->GetY() << ", "
159  << point->GetZ();
160  LOG(debug) << "Pos after misalignment: " << x << ", " << y << ", " << z;
161 
162  x = x + GetHitErr(0.1);
163  y = y + GetHitErr(0.1);
164 
165  LOG(debug2) << "Missallign hit by " << fShiftX.At(detID) << " cm in x- and " << fShiftY.At(detID)
166  << " cm in y-direction.";
167 
168  // Time of flight
169  // tof = point->GetTime();
170 
171  // Create new hit
172  pos.SetXYZ(x, y, z);
173  dpos.SetXYZ(dx, dx, 0.);
174  new ((*fHitArray)[nHits]) FairTutorialDet4Hit(detID, iPoint, pos, dpos);
175  nHits++;
176  } else {
177  // Determine hit position
178  x = point->GetX();
179  y = point->GetY();
180  z = point->GetZ();
181 
182  LOG(info) << "Position: " << x << ", " << y << ", " << z;
183 
184  Double_t local[3] = {x, y, z};
185  Double_t global[3];
186 
187  fGeoHandler->LocalToGlobal(local, global, detID);
188 
189  x = global[0] + GetHitErr(0.1);
190  y = global[1] + GetHitErr(0.1);
191  z = global[2];
192 
193  LOG(info) << "Position: " << x << ", " << y << ", " << z;
194  LOG(info) << "****";
195  // Time of flight
196  // tof = point->GetTime();
197 
198  // Create new hit
199  pos.SetXYZ(x, y, z);
200  dpos.SetXYZ(dx, dx, 0.);
201  new ((*fHitArray)[nHits]) FairTutorialDet4Hit(detID, iPoint, pos, dpos);
202  nHits++;
203  }
204  }
205  // Event summary
206  LOG(debug) << "Create " << nHits << " TutorialDetHits out of " << nPoints << " TutorilaDetPoints created.";
207 }
208 
209 Double_t FairTutorialDet4HitProducerIdealMisalign::GetHitErr(Double_t sigma)
210 {
211  Double_t err = gRandom->Gaus(0, sigma);
212  return (TMath::Abs(err) < 3 * sigma) ? err : (err > 0) ? 3 * sigma : -3 * sigma;
213 }
214 
list of container factories
Definition: FairRuntimeDb.h:24
InitStatus
Definition: FairTask.h:33
Double_t GetZ() const
Definition: FairMCPoint.h:69
Double_t GetX() const
Definition: FairMCPoint.h:67
static FairRootManager * Instance()
ClassImp(FairEventBuilder)
TObject * GetObject(const char *BrName)
FairParSet * getContainer(const Text_t *)
static FairRunAna * Instance()
Definition: FairRunAna.cxx:61
FairRuntimeDb * GetRuntimeDb(void)
Definition: FairRun.h:80
void Register(const char *name, const char *Foldername, TNamed *obj, Bool_t toFile)
Double_t GetY() const
Definition: FairMCPoint.h:68
void LocalToGlobal(Double_t *local, Double_t *global, Int_t detID)
Int_t GetDetectorID() const
Definition: FairMCPoint.h:66