FairRoot/PandaRoot
PndMdtDigiProducer.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndMdtDigiProducer source file -----
3 // ----- Created 29/03/11 by S.Spataro -----
4 // -------------------------------------------------------------------------
5 
6 #include "PndMdtDigiProducer.h"
7 
8 #include "PndMdtDigi.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 "TGeoBBox.h"
21 #include "TGeoMatrix.h"
22 #include "TVector3.h"
23 #include "TRandom.h"
24 
25 #include <iostream>
26 
27 using std::map;
28 using std::cout;
29 using std::endl;
30 
31 // ----- Default constructor -------------------------------------------
33  FairTask(" MDT Digi Producer") {
34  fStripMode = kTRUE;
35 }
36 // -------------------------------------------------------------------------
37 
38 // ----- Destructor ----------------------------------------------------
40 // -------------------------------------------------------------------------
41 
42 
43 
44 // ----- Public method Init --------------------------------------------
46 
47  cout << "-I- PndMdtDigiProducer::Init: "
48  << "INITIALIZATION *********************" << endl;
49 
50  //FairRun* sim = FairRun::Instance(); //[R.K. 01/2017] unused variable?
51  //FairRuntimeDb* rtdb=sim->GetRuntimeDb(); //[R.K. 01/2017] unused variable?
52 
53  // Get RootManager
54  FairRootManager* ioman = FairRootManager::Instance();
55  if ( ! ioman ) {
56  cout << "-E- PndMdtDigiProducer::Init: "
57  << "RootManager not instantiated!" << endl;
58  return kFATAL;
59  }
60 
61  // Get input array
62  fPointArray = (TClonesArray*) ioman->GetObject("MdtPoint");
63  if ( ! fPointArray ) {
64  cout << "-W- PndMdtDigiProducer::Init: "
65  << "No MdtPoint array!" << endl;
66  return kERROR;
67  }
68 
69  // Create and register output array
70  fDigiBoxArray = new TClonesArray("PndMdtDigi");
71  ioman->Register("MdtDigiBox","Mdt",fDigiBoxArray,kTRUE);
72 
73  if (fStripMode)
74  {
75  fDigiStripArray = new TClonesArray("PndMdtDigi");
76  ioman->Register("MdtDigiStrip","Mdt",fDigiStripArray,kTRUE);
77  }
78 
79  TGeoVolume *volBarrel = (TGeoVolume*)gGeoManager->FindVolumeFast("MdtBarrel");
80  TGeoBBox *boxBarrel = (TGeoBBox*)volBarrel->GetShape();
81  const Double_t *orBarrel = boxBarrel->GetOrigin();
82  fBarrelStart = orBarrel[2]+boxBarrel->GetDZ();
83  TGeoVolume *volEndcap = (TGeoVolume*)gGeoManager->FindVolumeFast("MdtEndcap");
84  TGeoBBox *boxEndcap = (TGeoBBox*)volEndcap->GetShape();
85  const Double_t *orEndcap = boxEndcap->GetOrigin();
86  fEndcapStart = orEndcap[0]+boxEndcap->GetDX();
87  TGeoVolume *volMF = (TGeoVolume*)gGeoManager->FindVolumeFast("MdtMF");
88  TGeoBBox *boxMF = (TGeoBBox*)volMF->GetShape();
89  const Double_t *orMF = boxMF->GetOrigin();
90  fMFStart = orMF[0]+boxMF->GetDX();
91 
92  cout << "-I- PndMdtDigiProducer: Intialization successfull" << endl;
93 
94  return kSUCCESS;
95 
96 }
97 // -------------------------------------------------------------------------
98 
99 
100 
101 // ----- Public method Exec --------------------------------------------
102 void PndMdtDigiProducer::Exec(Option_t*)
103 {
104  // Reset output array
105  fDigiBoxArray->Delete();
106  if (fStripMode) fDigiStripArray->Delete();
107 
108  map<Int_t, std::vector <Int_t> > mapStripPoint; // PointIds with same DetId - strip
109  map<Int_t, std::vector <Int_t> > mapBoxPoint; // PointIds with same DetId - box
110  map<Int_t, TVector3> mapStripPos; // Position for strip
111  map<Int_t, TVector3> mapBoxPos; // Position for box
112 
113  mapStripPoint.clear();
114  mapBoxPoint.clear();
115  mapStripPos.clear();
116  mapBoxPos.clear();
117 
118  TVector3 mdtSize(0.5, 0.5, 0.5);
119 
120  // Loop over MdtPoints
121  Int_t nPoints = fPointArray->GetEntriesFast();
122  PndMdtPoint *point = 0;
123  TVector3 inPos, outPos, meanPos;
124 
125  for (Int_t iPoint=0; iPoint<nPoints; iPoint++) {
126  point = (PndMdtPoint*) fPointArray->At(iPoint);
127  if (point->GetEnergyLoss()==0) continue;
128 
129  point->Position(inPos);
130  outPos = point->GetPosIn();
131 
132  if ((inPos-outPos).Mag()<0.2) continue; // skipped points
133 
134  meanPos = 0.5*(inPos+outPos);
135  gGeoManager->FindNode(meanPos.X(), meanPos.Y(), meanPos.Z()); // TGeoNode *mdtNode = (TGeoNode*) //[R.K.03/2017] unused variable
136  TGeoMatrix *mdtMat = (TGeoMatrix*)gGeoManager->GetCurrentMatrix();
137  const Double_t *matM = mdtMat->GetTranslation();
138  TVector3 tubePos(matM[0], matM[1], matM[2]);
139  TVector3 stripPos1, stripPos2;
140  Int_t stripNum1 = -10, stripNum2 = -10, stripId1 = -10, stripId2 = -10;
141  if (point->GetModule()==1)
142  {
143  stripNum1 = (Int_t)(fBarrelStart - point->GetZ()-0.25);
144  stripNum2 = (Int_t)(fBarrelStart - point->GetZ()+0.25);
145  if (stripNum1<0) stripNum1 = 0;
146  if (stripNum2<0) stripNum2 = 0;
147  stripPos1.SetXYZ(matM[0], matM[1], fBarrelStart - stripNum1 - 0.5);
148  stripPos2.SetXYZ(matM[0], matM[1], fBarrelStart - stripNum2 - 0.5);
149  }
150  if (point->GetModule()==2)
151  {
152  stripNum1 = (Int_t)(fEndcapStart - point->GetX()-0.25);
153  stripNum2 = (Int_t)(fEndcapStart - point->GetX()+0.25);
154  if (stripNum1<0) stripNum1 = 0;
155  if (stripNum2<0) stripNum2 = 0;
156  stripPos1.SetXYZ(fEndcapStart - stripNum1 - 0.5, matM[1], matM[2]);
157  stripPos2.SetXYZ(fEndcapStart - stripNum2 - 0.5, matM[1], matM[2]);
158  }
159  if (point->GetModule()==3)
160  {
161  stripNum1 = (Int_t)(fMFStart - point->GetX()-0.25);
162  stripNum2 = (Int_t)(fMFStart - point->GetX()+0.25);
163  if (stripNum1<0) stripNum1 = 0;
164  if (stripNum2<0) stripNum2 = 0;
165  stripPos1.SetXYZ(fMFStart - stripNum1 - 0.5, matM[1], matM[2]);
166  stripPos2.SetXYZ(fMFStart - stripNum2 - 0.5, matM[1], matM[2]);
167  }
168 
169  stripId1 = stripNum1 + 1000*point->GetLayerID() + 100000*point->GetSector() + 1000000*point->GetModule();
170  stripId2 = stripNum2 + 1000*point->GetLayerID() + 100000*point->GetSector() + 1000000*point->GetModule();
171 
172  if (fStripMode)
173  {
174  mapBoxPoint[point->GetDetectorID()].push_back(iPoint);
175  mapBoxPos[point->GetDetectorID()] = tubePos;
176  mapStripPoint[stripId1].push_back(iPoint);
177  mapStripPos[stripId1] = stripPos1;
178  if (stripNum1!=stripNum2)
179  {
180  mapStripPoint[stripId2].push_back(iPoint);
181  mapStripPos[stripId2] = stripPos2;
182  }
183  }
184  else
185  {
186  mapBoxPoint[point->GetDetectorID()].push_back(iPoint);
187  mapBoxPos[point->GetDetectorID()] = stripPos1;
188  }
189 
190  } // Loop over MdtPoints
191 
192  map<Int_t, std::vector <Int_t> >::const_iterator boxIter;
193  for( boxIter = mapBoxPoint.begin(); boxIter != mapBoxPoint.end(); ++boxIter)
194  {
195  AddDigiBox((*boxIter).first, mapBoxPos[(*boxIter).first], (*boxIter).second);
196  }
197  map<Int_t, std::vector <Int_t> >::const_iterator stripIter;
198  for( stripIter = mapStripPoint.begin(); stripIter != mapStripPoint.end(); ++stripIter)
199  {
200  AddDigiStrip((*stripIter).first, mapStripPos[(*stripIter).first], (*stripIter).second);
201  }
202 
203 
204 
205 }
206 // -------------------------------------------------------------------------
207 
208 
209 // ----- Private method AddDigi --------------------------------------------
210 PndMdtDigi* PndMdtDigiProducer::AddDigiBox(Int_t detID, TVector3& pos, std::vector<Int_t> pointList)
211 {
212  // It fills the PndMdtDigi category
213  TClonesArray& clref = *fDigiBoxArray;
214  Int_t size = clref.GetEntriesFast();
215  return new(clref[size]) PndMdtDigi(detID, pos, pointList);
216 }
217 // ----
218 
219 
220 // ----- Private method AddDigi --------------------------------------------
221 PndMdtDigi* PndMdtDigiProducer::AddDigiStrip(Int_t detID, TVector3& pos, std::vector<Int_t> pointList)
222 {
223  // It fills the PndMdtDigi category
224 
225  TClonesArray& clref = *fDigiStripArray;
226  Int_t size = clref.GetEntriesFast();
227  return new(clref[size]) PndMdtDigi(detID, pos, pointList);
228 }
229 // ----
230 
231 
std::vector< PndEmcPoint * > pointList
Definition: hit_analys.C:29
TVector3 pos
virtual void Exec(Option_t *opt)
PndTransMap * map
Definition: sim_emc_apd.C:99
TClonesArray * fDigiStripArray
PndMdtDigi * AddDigiStrip(Int_t detID, TVector3 &pos, std::vector< Int_t > pointList)
PndMdtDigi * AddDigiBox(Int_t detID, TVector3 &pos, std::vector< Int_t > pointList)
TClonesArray * fDigiBoxArray
TGeoManager * gGeoManager
TClonesArray * fPointArray
Short_t GetSector() const
Definition: PndMdtPoint.h:54
Double_t
virtual InitStatus Init()
Float_t fBarrelStart
Strip Mode.
TVector3 GetPosIn() const
Definition: PndMdtPoint.h:47
ClassImp(PndAnaContFact)
Short_t GetLayerID() const
Definition: PndMdtPoint.h:55
PndSdsMCPoint * point
Definition: anaLmdCluster.C:72
Short_t GetModule() const
Definition: PndMdtPoint.h:53