FairRoot/PandaRoot
PndEmcApd.cxx
Go to the documentation of this file.
1 //
3 // PndEmcApd
4 //
5 // Filler of PndEmcApdPoint
6 //
7 // Created 14/08/06 by S.Spataro
8 //
10 
11 #include "PndEmcApd.h"
12 #include "PndEmcApdPoint.h"
13 #include "PndEmcReader.h"
14 
15 #include "FairGeoInterface.h"
16 #include "FairGeoLoader.h"
17 #include "FairGeoRootBuilder.h"
18 #include "FairRootManager.h"
19 #include "FairVolume.h"
20 #include "FairGeoMedia.h"
21 //#include "FairGeoG3Builder.h"
22 #include "FairRuntimeDb.h"
23 #include "FairRun.h"
24 
25 #include "TObjArray.h"
26 #include "TClonesArray.h"
27 #include "TGeoMCGeometry.h"
28 #include "TGeoManager.h"
29 #include "TLorentzVector.h"
30 #include "TParticle.h"
31 #include "TVirtualMC.h"
32 #include "TGeoArb8.h"
33 #include "TGeoMatrix.h"
34 
35 #include "FairGeoMedia.h"
36 #include "FairGeoMedium.h"
37 #include "PndStack.h"
38 #include "TString.h"
39 #include "TObject.h"
40 
41 #include <iostream>
42 
43 using std::cout;
44 using std::endl;
45 
46 // ----- Default constructor -------------------------------------------
48  FairDetector(),
49  fTrackID(0),fVolumeID(0),fEventID(-1),fPos(0,0,0,0),fMom(0,0,0,0),fTime(0),fLength(0),fELoss(0),fPosIndex(0),fApdCollection(new TClonesArray("PndEmcApdPoint"))
50 {
51  //fApdCollection = new TClonesArray("PndEmcApdPoint");
52 }
53 // -------------------------------------------------------------------------
54 
55 // ----- Standard constructor ------------------------------------------
56 PndEmcApd::PndEmcApd(const char* name, Bool_t active):
57  FairDetector(name, active),
58  fTrackID(0),fVolumeID(0),fEventID(-1),fPos(0,0,0,0),fMom(0,0,0,0),fTime(0),fLength(0),fELoss(0),fPosIndex(0),fApdCollection(new TClonesArray("PndEmcApdPoint"))
59 {
60  //fApdCollection = new TClonesArray("PndEmcApdPoint");
61 }
62 // -------------------------------------------------------------------------
63 
64 
65 
66 // ----- Destructor ----------------------------------------------------
68  if (fApdCollection) {
69  fApdCollection->Delete();
70  delete fApdCollection;
71  }
72 
73 }
74 // -------------------------------------------------------------------------
75 
76 
77 
78 // ----- Public method Intialize ---------------------------------------
80  // Init function
81 
83  //FairRun* sim = FairRun::Instance(); //[R.K. 01/2017] unused variable?
84  //FairRuntimeDb* rtdb=sim->GetRuntimeDb(); //[R.K. 01/2017] unused variable?
85 
86 }
87 // -------------------------------------------------------------------------
89  // Begin of the event
90 
91 }
92 
93 
94 
95 // ----- Public method ProcessHits --------------------------------------
96 Bool_t PndEmcApd::ProcessHits(FairVolume* ) { // vol //[R.K.03/2017] unused variable(s)
97 
98  TString nam = gMC->CurrentVolName();
99 
100  // ---------------------------------------------------------------------------------
101  // Getting parameters for the ROOT file with geometry for Forward Enc-Cap.
102  // Each of the subvolume name for FwEndCap geometry in the ROOT file contains "Vol".
103  //Int_t copyNoCrys=-1,copyNoBox=-1,copyNoSub=-1,copyNoQuar=-1; //[R.K. 01/2017] unused variable?
104  //Int_t idCrys=-1,idBox=-1,idSub=-1,idQuar=-1; //[R.K. 01/2017] unused variable?
105  Int_t copyNo = -1; //, id = -1; //[R.K.03/2017] unused variable
106  Int_t nMod = -1, nRow = -1, nCrys = -1;
107  Short_t nFlag=0
108  ;
109  if ( gMC->IsTrackEntering() ) {
110  nFlag = -1;
111  }
112  if ( gMC->IsTrackExiting() ||
113  gMC->IsTrackStop() ||
114  gMC->IsTrackDisappeared() ) {
115  nFlag = 1;
116  }
117 
118  fTrackID = gMC->GetStack()->GetCurrentTrackNumber(); // trk ID
119  fEventID = gMC->CurrentEvent();
120  fELoss = gMC->Edep();
121  fLength = gMC->TrackLength();
122  fTime = gMC->TrackTime();
123  gMC->TrackPosition(fPos); // cm
124  gMC->TrackMomentum(fMom); // GeV
125 
126  sscanf(nam,"apd%dr%dc%d", &nMod, &nRow, &nCrys);
127  gMC->CurrentVolOffID(2,copyNo); //id = //[R.K.03/2017] unused variable
128 
129  fVolumeID = nMod*100000000 + nRow*1000000 + copyNo*10000 + nCrys;
130 
131  TVector3 pos(fPos.X(), fPos.Y(), fPos.Z());
132 
134  TVector3(fPos.X(), fPos.Y(), fPos.Z()),
135  TVector3(fMom.Px(), fMom.Py(), fMom.Pz()),
136  fTime, fLength, fELoss, nMod, nRow, nCrys, copyNo, nFlag);
137 
138  ResetParameters();
139 
140  return kTRUE;
141 }
142 // ----------------------------------------------------------------------------
143 
144 // ----- Public method EndOfEvent -----------------------------------------
146  if (fVerboseLevel) Print();
147  Reset();
148 }
149 // ----------------------------------------------------------------------------
150 
151 // ----- Public method Register -------------------------------------------
153  FairRootManager::Instance()->Register("EmcApdPoint","Emc", fApdCollection, kTRUE);
154 }
155 // ----------------------------------------------------------------------------
156 
157 // ----- Public method GetCollection --------------------------------------
158 TClonesArray* PndEmcApd::GetCollection(Int_t iColl) const {
159  if (iColl == 0) return fApdCollection;
160 
161  return NULL;
162 }
163 // ----------------------------------------------------------------------------
164 
165 // ----- Public method Print ----------------------------------------------
166 void PndEmcApd::Print() const {
167  Int_t nHits = fApdCollection->GetEntriesFast();
168  //cout << "-I- PndEmcApd: " << nHits << " points registered in this event."
169  //<< endl;
170 
171  if (fVerboseLevel>1)
172  for (Int_t i=0; i<nHits; i++) (*fApdCollection)[i]->Print();
173 }
174 // ----------------------------------------------------------------------------
175 
176 
177 
178 // ----- Public method Reset ----------------------------------------------
180  fApdCollection->Clear();
181 
182  fPosIndex = 0;
183 }
184 // ----------------------------------------------------------------------------
185 
186 
187 // guarda in FairRootManager::CopyClones
188 // ----- Public method CopyClones -----------------------------------------
189 void PndEmcApd::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset ) {
190  Int_t nEntries = cl1->GetEntriesFast();
191  //cout << "-I- PndEmcApd: " << nEntries << " entries to add." << endl;
192  TClonesArray& clref = *cl2;
193  PndEmcApdPoint* oldpoint = NULL;
194  for (Int_t i=0; i<nEntries; i++) {
195  oldpoint = (PndEmcApdPoint*) cl1->At(i);
196  Int_t index = oldpoint->GetTrackID() + offset;
197  oldpoint->SetTrackID(index);
198  new (clref[fPosIndex]) PndEmcApdPoint(*oldpoint);
199  fPosIndex++;
200  }
201  // cout << " -I- PndEmcApd: " << cl2->GetEntriesFast() << " merged entries."
202  // << endl;
203 }
204 
205 
206 
207 
208 // ----------------------------------------------------------------------------
209  // ----- Public method ConstructGeometry ----------------------------------
211  TString fileName=GetGeometryFileName();
212 
213  if (fileName.EndsWith(".dat")) {
214  std::cout<< " " <<std::endl;
215  std::cout<< " ====== EMCAPD::ConstructASCIIGeometry()====== " <<std::endl;
216  std::cout<< " ============================================= " <<std::endl;
218  }
219  else
220  {
221  std::cout<< "Geometry format not supported " <<std::endl;
222  }
223 }
224 
226  // Definition of materials
227 
228  FairGeoLoader*geoLoad = FairGeoLoader::Instance();
229  FairGeoInterface *geoFace = geoLoad->getGeoInterface();
230  FairGeoMedia *Media = geoFace->getMedia();
231  FairGeoBuilder *geobuild=geoLoad->getGeoBuilder();
232 
233  FairGeoMedium *CbmMediumSi = Media->getMedium("silicon");
234  geobuild->createMedium(CbmMediumSi); //Int_t nmedSi = //[R.K.03/2017] unused variable
235 
236  TGeoVolume *flayer1 = new TGeoVolumeAssembly("ApdLayer1");
237  TGeoVolume *flayer2 = new TGeoVolumeAssembly("ApdLayer2");
238  TGeoVolume *flayer6 = new TGeoVolumeAssembly("ApdLayer6");
239 
240  Bool_t bIsModuleOn[6] = {kFALSE, kFALSE, kFALSE, kFALSE, kFALSE,kFALSE};
241  //Bool_t isFirst = kTRUE; //[R.K. 01/2017] unused variable?
242 
243  PndEmcReader read(GetGeometryFileName() );
244  for(Int_t module=read.GetMinModules(); module<=read.GetMaxModules(); module++) {
245  cout << "Emc APD module = " << module;
246  cout << endl << "******** " << endl;
247 
248  for(Int_t row=read.GetMinRows(module); row<=read.GetMaxRows(module); row++){
249  for(Int_t crystal=read.GetMinCrystals(module,row); crystal<=read.GetMaxCrystals(module,row); crystal++) {
250 
251  Text_t buffer[30];
252  sprintf(buffer,"apd0%dr%dc%d",module, row, crystal);
253  DataG4 data = read.GetData(module,row,crystal);
254 
255  if (data.module==-1) continue; //if the pad is not present, do not create geometry
256 
257  // Construction of target spectrometer geometry
258  TGeoTrap *trap = new TGeoTrap(data.pDz/10., data.pTheta, data.pPhi,
259  data.pDy1/10., data.pDx1/10., data.pDx2/10., data.pAlp1,
260  data.pDy2/10., data.pDx3/10., data.pDx4/10., data.pAlp2);
261  TGeoVolume *volume;
262  volume = new TGeoVolume(buffer, trap, gGeoManager->GetMedium("silicon"));
263 
264  volume->SetLineColor(5);
265  TGeoRotation rot;
266  rot.RotateZ(data.tau);
267  rot.RotateY(data.theta);
268  rot.RotateZ(data.phi);
269 
270  if(module ==1) flayer1->AddNode(volume,0, new TGeoCombiTrans(data.posX/10., data.posY/10., data.posZ/10.+3.7, new TGeoRotation (rot))); // shift of 37 mm with respect to interaction point
271  if(module ==2) flayer2->AddNode(volume,0, new TGeoCombiTrans(data.posX/10., data.posY/10., data.posZ/10.+3.7, new TGeoRotation (rot))); // shift of 37 mm with respect to interaction point
272  if(module ==6) flayer6->AddNode(volume,0, new TGeoCombiTrans(data.posX/10., data.posY/10., data.posZ/10., new TGeoRotation (rot)));
273  bIsModuleOn[module-1] = kTRUE;
274  AddSensitiveVolume(volume);
275 
276  }
277  }
278  }
279 
280  TGeoVolume *flayer12 = new TGeoVolumeAssembly("EmcApd12");
281  if (bIsModuleOn[0]) flayer12->AddNode(flayer1,0, new TGeoCombiTrans(0., 0., 0., new TGeoRotation(0)));
282  if (bIsModuleOn[1]) flayer12->AddNode(flayer2,0, new TGeoCombiTrans(0., 0., 0., new TGeoRotation(0)));
283  TString vname = "cave";
284  vname = vname.Strip();
285  TGeoVolume* vcave = gGeoManager->FindVolumeFast(vname.Data());
286  if (bIsModuleOn[0] || bIsModuleOn[1]) vcave->AddNode(flayer12, 1);
287  if (bIsModuleOn[5]) vcave->AddNode(flayer6, 1);
288 
289  // 15 copies for barrel part of EMC
290  if (bIsModuleOn[0] || bIsModuleOn[1])
291  for (Int_t n=1;n<=15;n++){
292  TGeoRotation rot1;
293  rot1.RotateZ(22.5*n);
294  vcave->AddNode(flayer12, n+1,new TGeoCombiTrans(0., 0., 0., new TGeoRotation (rot1)) );
295  }
296 }
297 
298 // ----- Private method AddHit --------------------------------------------
299 PndEmcApdPoint* PndEmcApd::AddHit(Int_t trackID, Int_t detID, Int_t evtID, TVector3 pos, TVector3 mom, Double_t time, Double_t length, Double_t eLoss, Short_t mod, Short_t row, Short_t crys, Short_t copy, Short_t flag) {
300  TClonesArray& clref = *fApdCollection;
301  Int_t size = clref.GetEntriesFast();
302  if (fVerboseLevel>1)
303  cout << "-I- PndEmcApd: Adding Point at IN (" << pos.X() << ", " << pos.Y()
304  << ", " << pos.Z() << ") cm, detector " << detID << ", evt " << evtID << ", track "
305  << trackID <<", energy loss " << eLoss*1e06 << " keV, module " << mod << " row " << row << " crystal " << crys << " copy " << copy << endl;
306 
307  return new(clref[size]) PndEmcApdPoint(trackID, detID, evtID, pos, mom, time, length, eLoss,
308  mod, row, crys, copy, flag);
309 }
310 
312  fTrackID = -999;
313  fVolumeID = -999;
314  fEventID = -999;
315  fPos.SetXYZT(0., 0., 0., 0.);
316  fMom.SetXYZT(0., 0., 0., 0.) ;
317  fTime = -999;
318  fLength = -999;
319  fELoss = -999;
320 }
321 
322 // ----
323 
324 
int row
Definition: anaLmdDigi.C:67
TVector3 pos
virtual void ConstructGeometry()
Definition: PndEmcApd.cxx:210
int GetMinRows(int module)
Int_t fTrackID
Definition: PndEmcApd.h:115
double pDx3
Definition: PndEmcReader.h:22
double tau
Definition: PndEmcReader.h:20
Int_t fEventID
volume id
Definition: PndEmcApd.h:117
virtual void Reset()
Definition: PndEmcApd.cxx:179
Double32_t fELoss
length
Definition: PndEmcApd.h:122
FairGeoLoader * geoLoad
Int_t i
Definition: run_full.C:25
FairGeoMedia * Media
double pAlp2
Definition: PndEmcReader.h:22
virtual void Register()
Definition: PndEmcApd.cxx:152
int GetMaxCrystals(int module, int row)
int GetMaxModules()
int n
double pDz
Definition: PndEmcReader.h:22
TLorentzVector fPos
event id
Definition: PndEmcApd.h:118
Int_t fPosIndex
energy loss
Definition: PndEmcApd.h:123
double pDx2
Definition: PndEmcReader.h:22
Double_t mom
Definition: plot_dirc.C:14
TVector3 offset(2, 0, 0)
TGeoManager * gGeoManager
TClonesArray * fApdCollection
Definition: PndEmcApd.h:125
double phi
Definition: PndEmcReader.h:20
TGeoRotation * rot1
int module
Definition: PndEmcReader.h:19
DataG4 GetData(int module, int row, int crystal)
virtual void EndOfEvent()
Definition: PndEmcApd.cxx:145
FairGeoBuilder * geobuild
int nHits
Definition: RiemannTest.C:16
int GetMinCrystals(int module, int row)
double pPhi
Definition: PndEmcReader.h:22
int GetMaxRows(int module)
Double_t
Int_t fVolumeID
track index
Definition: PndEmcApd.h:116
PndEmcApdPoint * AddHit(Int_t trackID, Int_t detID, Int_t evtID, TVector3 pos, TVector3 mom, Double_t tof, Double_t length, Double_t eLoss, Short_t mod, Short_t row, Short_t crys, Short_t copy, Short_t flag)
Definition: PndEmcApd.cxx:299
virtual Bool_t ProcessHits(FairVolume *vol=0)
Definition: PndEmcApd.cxx:96
virtual void Initialize()
Definition: PndEmcApd.cxx:79
double pDx4
Definition: PndEmcReader.h:22
TString name
double pDx1
Definition: PndEmcReader.h:22
int GetMinModules()
Double32_t fTime
momentum
Definition: PndEmcApd.h:120
double posX
Definition: PndEmcReader.h:21
void ResetParameters()
Hit collection.
Definition: PndEmcApd.cxx:311
void ConstructASCIIGeometry()
Definition: PndEmcApd.cxx:225
double posZ
Definition: PndEmcReader.h:21
double pDy2
Definition: PndEmcReader.h:22
double pTheta
Definition: PndEmcReader.h:22
virtual void Print() const
Definition: PndEmcApd.cxx:166
ClassImp(PndAnaContFact)
double pDy1
Definition: PndEmcReader.h:22
TGeoRotation rot
double posY
Definition: PndEmcReader.h:21
virtual void CopyClones(TClonesArray *cl1, TClonesArray *cl2, Int_t offset)
Definition: PndEmcApd.cxx:189
virtual TClonesArray * GetCollection(Int_t iColl) const
Definition: PndEmcApd.cxx:158
FairGeoInterface * geoFace
TString nam
Definition: sim_hypGe.C:48
Mvd Initialize()
virtual ~PndEmcApd()
Definition: PndEmcApd.cxx:67
TLorentzVector fMom
position
Definition: PndEmcApd.h:119
double theta
Definition: PndEmcReader.h:20
double pAlp1
Definition: PndEmcReader.h:22
virtual void BeginEvent()
Definition: PndEmcApd.cxx:88
Double32_t fLength
time
Definition: PndEmcApd.h:121