FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairTestDetectorHitProducerSmearing.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  ********************************************************************************/
9 
10 #include "FairLogger.h" // for FairLogger, MESSAGE_ORIGIN
11 #include "FairRootManager.h" // for FairRootManager
12 #include "FairTestDetectorHit.h" // for FairTestDetectorHit
13 #include "FairTestDetectorPoint.h" // for FairTestDetectorPoint
14 
15 #include <TClonesArray.h> // for TClonesArray
16 #include <TRandom.h> // for TRandom, gRandom
17 #include <TVector3.h> // for TVector3
18 
20  : FairTask("FairTestDetectorHitProducerSmearing")
21  , fPointsArray(nullptr)
22  , fHitsArray(new TClonesArray("FairTestDetectorHit", 100))
23 {
24  LOG(debug) << "Default Constructor of FairTestDetectorHitProducerSmearing";
25 }
26 
28 {
29  LOG(debug) << "Destructor of FairTestDetectorHitProducerSmearing";
30  fHitsArray->Delete();
31  delete fHitsArray;
32 }
33 
35 {
36  LOG(debug) << "SetParContainers of FairTestDetectorHitProducerSmearing";
37  // Load all necessary parameter containers from the runtime data base
38  /*
39  FairRunAna* ana = FairRunAna::Instance();
40  FairRuntimeDb* rtdb=ana->GetRuntimeDb();
41 
42  <FairTestDetectorHitProducerSmearingDataMember> = (<ClassPointer>*)
43  (rtdb->getContainer("<ContainerName>"));
44  */
45 }
46 
48 {
49  LOG(debug) << "Initilization of FairTestDetectorHitProducerSmearing";
50 
51  // Get a handle from the IO manager
53 
54  // Get a pointer to the previous already existing data level
55  fPointsArray = static_cast<TClonesArray*>(ioman->GetObject("FairTestDetectorPoint"));
56  if (!fPointsArray) {
57  LOG(error) << "No InputDataLevelName array!";
58  LOG(error) << "FairTestDetectorHitProducerSmearing will be inactive";
59  return kERROR;
60  }
61 
62  // Create the TClonesArray for the output data and register
63  // it in the IO manager
64  ioman->Register("FairTestDetectorHit", "FairTestDetectorHit", fHitsArray, kTRUE);
65 
66  // Do whatever else is needed at the initilization stage
67  // Create histograms to be filled
68  // initialize variables
69 
70  return kSUCCESS;
71 }
72 
74 {
75  LOG(debug) << "Reinitilization of FairTestDetectorHitProducerSmearing";
76  return kSUCCESS;
77 }
78 
80 {
81  LOG(debug) << "Exec of FairTestDetectorHitProducerSmearing";
82 
83  fHitsArray->Delete();
84 
85  // fill the map
86  FairTestDetectorPoint* point = nullptr;
87  // FairTestDetectorHit* hit = nullptr;
88  for (int iPoint = 0; iPoint < fPointsArray->GetEntriesFast(); iPoint++) {
89  point = static_cast<FairTestDetectorPoint*>(fPointsArray->At(iPoint));
90  if (!point) {
91  continue;
92  }
93 
94  TVector3 position;
95  point->Position(position);
96 
97  TVector3 dposition;
98 
99  // simulate the detector response: smear position with gaussians
100  dposition.SetXYZ(0.05, 0.05, 0.);
101  position.SetXYZ(gRandom->Gaus(position.X(), 0.05), gRandom->Gaus(position.Y(), 0.05), position.Z());
102 
103  // hit = new ((*fHitsArray)[iPoint]) FairTestDetectorHit(point->GetDetectorID(), iPoint, position, dposition);
104  new ((*fHitsArray)[iPoint]) FairTestDetectorHit(point->GetDetectorID(), iPoint, position, dposition);
105  }
106 }
107 
108 void FairTestDetectorHitProducerSmearing::Finish() { LOG(debug) << "Finish of FairTestDetectorHitProducerSmearing"; }
109 
InitStatus
Definition: FairTask.h:33
void Position(TVector3 &pos) const
Definition: FairMCPoint.h:70
static FairRootManager * Instance()
ClassImp(FairEventBuilder)
TObject * GetObject(const char *BrName)
void Register(const char *name, const char *Foldername, TNamed *obj, Bool_t toFile)
Int_t GetDetectorID() const
Definition: FairMCPoint.h:66