FairRoot/PandaRoot
PndEmcApdHitProducer.cxx
Go to the documentation of this file.
1 //
3 // PndEmcApdHitProducer
4 //
5 // Filler of PndEmcApdHit
6 //
7 // Created 14/08/06 by S.Spataro
8 //
10 
11 #include "PndEmcApdHitProducer.h"
12 
13 #include "PndEmcStructure.h"
14 #include "PndEmcMapper.h"
15 #include "PndEmcApdHit.h"
16 #include "PndEmcApdPoint.h"
17 
18 #include "FairRootManager.h"
19 #include "FairRunAna.h"
20 #include "FairRuntimeDb.h"
21 #include "FairDetector.h"
22 #include "FairRun.h"
23 #include "FairRuntimeDb.h"
24 
25 #include "TClonesArray.h"
26 #include "TROOT.h"
27 #include "TGeoVolume.h"
28 #include "TGeoMatrix.h"
29 #include "TVector3.h"
30 
31 #include <string>
32 
33 using std::cout;
34 using std::endl;
35 using std::map;
36 
37 
38 // ----- Default constructor -------------------------------------------
40  PndPersistencyTask("Ideal EMC APD hit Producer"), fPointArray(0), fDigiArray(0), fVolumeArray(new TObjArray),
41  fMapVersion(0), emcX(), emcY(), emcZ(), fEmcStr()
42 {
43 }
44 // -------------------------------------------------------------------------
45 
46 // ----- Destructor ----------------------------------------------------
48 // -------------------------------------------------------------------------
49 
50 
51 
52 // ----- Public method Init --------------------------------------------
54 
55  cout << " INITIALIZATION *********************" << endl;
56 
57  //FairDetector::Initialize();
58  //FairRun* sim = FairRun::Instance();
59  //FairRuntimeDb* rtdb=sim->GetRuntimeDb();
60 
61  // Get RootManager
62  FairRootManager* ioman = FairRootManager::Instance();
63  if ( ! ioman ) {
64  cout << "-E- PndEmcApdHitProducer::Init: "
65  << "RootManager not instantiated!" << endl;
66  return kFATAL;
67  }
68 
69  // Get input array
70  fPointArray = (TClonesArray*) ioman->GetObject("EmcApdPoint");
71  if ( ! fPointArray ) {
72  cout << "-W- PndEmcApdHitProducer::Init: "
73  << "No EmcApdPoint array!" << endl;
74  return kERROR;
75  }
76 
77  // Create and register output array
78  fDigiArray = new TClonesArray("PndEmcApdHit");
79 
80  ioman->Register("EmcApdHit","Emc",fDigiArray, GetPersistency());
81 
82  // Geometry loading
83 // TFile *infile = ioman->GetInFile();
84 // TGeoManager *geoMan = (TGeoManager*) infile->Get("FAIRGeom");
85 // TGeoManager *geoMan = (TGeoManager*) gROOT->FindObject("FAIRGeom");
86 
87  //fMapVersion=1;
88  //PndEmcMapper::Init(fMapVersion);
90 
91  emcX=fEmcStr->GetEmcX();
92  emcY=fEmcStr->GetEmcY();
93  emcZ=fEmcStr->GetEmcZ();;
94 
95  cout << "-I- PndEmcApdHitProducer: Intialization successfull" << endl;
96 
97  return kSUCCESS;
98 
99 }
100 
101 // -------------------------------------------------------------------------
102 
103 // ----- Public method Exec --------------------------------------------
104 void PndEmcApdHitProducer::Exec(Option_t*) {
105  //cout << " DIGI EXECUTION *********************" << endl;
106  // Reset output array
107  if ( ! fDigiArray ) Fatal("Exec", "No DigiArray");
108  fDigiArray->Delete();
109 
110  // Declare some variables
111  PndEmcApdPoint* point = NULL;
112  map<Int_t, Float_t> fTrackEnergy;
113  map<Int_t, Float_t> fTrackTime; //time of first point
114  map<Int_t, TArrayI> fPointIndex; // index of MC points
115 
116  fTrackEnergy.clear();
117  fTrackTime.clear();
118  fPointIndex.clear();
119 
120 
121  map<Int_t, Float_t>::const_iterator p;
122 
123  std::vector<PndEmcApdPoint*> fPointList;// to pass to EmcApdHit
124 
125  // Loop over EmcApdPoints
126  Int_t nPoints = fPointArray->GetEntriesFast();
127 
128  //Double_t point_time; //[R.K. 01/2017] unused variable
129  for (Int_t iPoint=0; iPoint<nPoints; iPoint++)
130  {
131  point = (PndEmcApdPoint*) fPointArray->At(iPoint);
132  fTrackEnergy[point->GetDetectorID()] += point->GetEnergyLoss();
133  //point_time=point ->GetTime(); //[R.K. 01/2017] unused variable
134  if (point->GetFlag()==-1) {
135  fPointIndex[point->GetDetectorID()].Set(fPointIndex[point->GetDetectorID()].GetSize()+1);
136  fPointIndex[point->GetDetectorID()].AddAt(point->GetTrackID(),fPointIndex[point->GetDetectorID()].GetSize()-1);
137  }
138  }
139  // Loop over EmcApdPoint
140 
141 
142  // Loop to register EmcApdHit
143  for(p=fTrackEnergy.begin(); p!=fTrackEnergy.end(); ++p) {
144  if ((*p).second>0.) {
145  Int_t index[10] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1} ;
146  for (Int_t ii=0; ii< (fPointIndex[(*p).first].GetSize()); ii++)
147  if (ii<10) index[ii] = fPointIndex[(*p).first].At(ii);
148  AddHit(1, (*p).first, (*p).second, fTrackTime[(*p).first],fPointIndex[(*p).first].GetSize(), index);
149  }
150  }
151 
152 
153 }
154 // -------------------------------------------------------------------------
155 
156 // ----- Private method AddDigi --------------------------------------------
157 PndEmcApdHit* PndEmcApdHitProducer::AddHit(Int_t trackID,Int_t detID, Float_t energy, Float_t time, Int_t npoint, Int_t pointIndex[10]){
158  // It fills the PndEmcApdHit category
159  //cout << "PndEmcApdHitProducer: track " << trackID << " evt " << eventID << " sec " << sec << " plane " << pla << " strip " << strip << "box " << box << " tube " << tub << endl;
160  TClonesArray& clref = *fDigiArray;
161  Int_t size = clref.GetEntriesFast();
162  return new(clref[size]) PndEmcApdHit(trackID, detID, energy, time, emcX[detID], emcY[detID], emcZ[detID], npoint, pointIndex);
163 }
164 // ----
165 
166 
Double_t p
Definition: anasim.C:58
virtual InitStatus Init()
PndTransMap * map
Definition: sim_emc_apd.C:99
const mapper & GetEmcY() const
virtual void Exec(Option_t *opt)
int npoint
Short_t GetFlag() const
PndEmcStructure * fEmcStr
ClassImp(PndAnaContFact)
static PndEmcStructure * Instance()
PndEmcApdHit * AddHit(Int_t trackID, Int_t detID, Float_t energy, Float_t time, Int_t npoint, Int_t pointIndex[10])
const mapper & GetEmcZ() const
const mapper & GetEmcX() const
Double_t energy
Definition: plot_dirc.C:15
PndSdsMCPoint * point
Definition: anaLmdCluster.C:72