FairRoot/PandaRoot
PndMdtHitProducerIdeal.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndMdtHitProducerIdeal source file -----
3 // ----- Created 11/06/08 by S.Spataro -----
4 // -------------------------------------------------------------------------
5 
7 
8 #include "PndMdtHit.h"
9 #include "PndMdtPoint.h"
10 
11 #include "FairRootManager.h"
12 #include "FairDetector.h"
13 #include "FairRun.h"
14 #include "FairRuntimeDb.h"
15 
16 #include "TClonesArray.h"
17 #include "TGeoManager.h"
18 #include "TGeoVolume.h"
19 #include "TGeoNode.h"
20 #include "TGeoMatrix.h"
21 #include "TVector3.h"
22 #include "TRandom.h"
23 
24 #include <iostream>
25 
26 using std::cout;
27 using std::endl;
28 
29 // ----- Default constructor -------------------------------------------
31  PndPersistencyTask("Ideal MDT Hit Producer"), fPosResolution(-1.)
32 {
33  SetPersistency(kTRUE);
34 }
35 // -------------------------------------------------------------------------
36 
37 // ----- Destructor ----------------------------------------------------
39 // -------------------------------------------------------------------------
40 
41 
42 
43 // ----- Public method Init --------------------------------------------
45 
46  cout << "-I- PndMdtHitProducerIdeal::Init: "
47  << "INITIALIZATION *********************" << endl;
48 
49  //FairRun* sim = FairRun::Instance(); //[R.K. 01/2017] unused variable?
50  //FairRuntimeDb* rtdb=sim->GetRuntimeDb(); //[R.K. 01/2017] unused variable?
51 
52  // Get RootManager
53  FairRootManager* ioman = FairRootManager::Instance();
54  if ( ! ioman ) {
55  cout << "-E- PndMdtHitProducerIdeal::Init: "
56  << "RootManager not instantiated!" << endl;
57  return kFATAL;
58  }
59 
60  // Get input array
61  fPointArray = (TClonesArray*) ioman->GetObject("MdtPoint");
62  if ( ! fPointArray ) {
63  cout << "-W- PndMdtHitProducerIdeal::Init: "
64  << "No MdtPoint array!" << endl;
65  return kERROR;
66  }
67 
68  // Create and register output array
69  fHitArray = new TClonesArray("PndMdtHit");
70 
71  ioman->Register("MdtHit","Mdt",fHitArray, GetPersistency());
72 
73  if (fPosResolution>0.)
74  cout << "-I- PndMdtHitProducerIdeal::Init: "
75  << "Hit Position smearing: " << fPosResolution << " [cm]" << endl;
76 
77  cout << "-I- PndMdtHitProducerIdeal: Intialization successfull" << endl;
78 
79  return kSUCCESS;
80 
81 }
82 // -------------------------------------------------------------------------
83 
84 
85 
86 // ----- Public method Exec --------------------------------------------
88 
89  // Reset output array
90  if ( ! fHitArray ) Fatal("Exec", "No HitArray");
91 
92  fHitArray->Delete();
93 
94  // Loop over MdtPoints
95  Int_t nPoints = fPointArray->GetEntriesFast();
96  PndMdtPoint *point = 0;
97  TVector3 pos;
99 
100  for (Int_t iPoint=0; iPoint<nPoints; iPoint++) {
101  point = (PndMdtPoint*) fPointArray->At(iPoint);
102  if (point->GetEnergyLoss()==0) continue;
103  //if ( (point->GetModule()==1) && (TMath::Odd(point->GetDetectorID())) ) continue;
104  point->Position(pos);
105  if (fPosResolution>0.)
106  {
107  pos.SetX(gRandom->Gaus(pos.X(),fPosResolution));
108  pos.SetY(gRandom->Gaus(pos.Y(),fPosResolution));
109  pos.SetZ(gRandom->Gaus(pos.Z(),fPosResolution));
110  }
111  AddHit(point->GetDetectorID(), pos, sig, iPoint);
112 
113  } // Loop over MCPoints
114 
115 }
116 // -------------------------------------------------------------------------
117 
118 
119 // ----- Private method AddHit --------------------------------------------
120 PndMdtHit* PndMdtHitProducerIdeal::AddHit(Int_t detID, TVector3& pos, TVector3& dpos, Int_t index){
121  // It fills the PndMdtHit category
122 
123  TClonesArray& clref = *fHitArray;
124  Int_t size = clref.GetEntriesFast();
125  return new(clref[size]) PndMdtHit(detID, pos, dpos, index);
126 }
127 // ----
128 
129 
TVector3 pos
Float_t fPosResolution
Position smearing [cm].
void SetPersistency(Bool_t val=kTRUE)
PndMdtHit * AddHit(Int_t detID, TVector3 &pos, TVector3 &dpos, Int_t index)
TClonesArray * point
Definition: anaLmdDigi.C:29
virtual void Exec(Option_t *opt)
ClassImp(PndAnaContFact)