FairRoot/PandaRoot
PndFtof.cxx
Go to the documentation of this file.
1 //
3 // PndFtof
4 //
5 //
6 // created by A. Sanchez
7 // modifyed by Yu.Naryshkin
9 
10 #include "PndFtof.h"
11 
12 #include "PndFtofPoint.h"
13 
14 #include "FairGeoTransform.h"
15 #include "FairGeoInterface.h"
16 #include "FairGeoLoader.h"
17 #include "FairGeoNode.h"
18 #include "FairGeoMedium.h"
19 #include "FairGeoInterface.h"
20 #include "FairGeoMedia.h"
21 
22 #include "PndGeoFtof.h"
23 #include "FairGeoRootBuilder.h"
24 #include "PndStack.h"
25 #include "FairRootManager.h"
26 #include "FairVolume.h"
27 #include "FairRuntimeDb.h"
28 #include "FairRun.h"
29 #include "PndDetectorList.h"
30 
31 
32 #include "TClonesArray.h"
33 #include "TGeoManager.h"
34 #include "TLorentzVector.h"
35 #include "TParticle.h"
36 #include "TVirtualMC.h"
37 #include "TString.h"
38 #include "TList.h"
39 #include "TGeoBBox.h"
40 #include "TGeoMCGeometry.h"
41 #include "TObjArray.h"
42 #include "TGeoVoxelFinder.h"
43 #include "TGeoMatrix.h"
44 //#include "FairGeoG3Builder.h"
45 
46 #include <string>
47 #include <sstream>
48 #include <iostream>
49 
50 using std::cout;
51 using std::endl;
52 using std::ostringstream;
53 
54 // ----- Default constructor -------------------------------------------
56  : FairDetector(),fListOfSensitives(),
57  par(), fTrackID(-1), fVolumeID(-1), fEventID(-1), fPosIn(), fMomIn(), fPosOut(), fMomOut(),
58  fPLout(0), fPLin(0), fTime(0), fLength(0), fELoss(0), fPosIndex(-1), fpdgCode(-1),
59  SiId(0), CId(0), alId(0), beId(0), CpipeId(0), fcharge(0), fmass(0), fdist(0), fFtofCollection(0)
60 {
61  fFtofCollection = new TClonesArray("PndFtofPoint");
62  fVerboseLevel = 0;
63 
64  fListOfSensitives.push_back("Ftof_Central_Strip");//Root_Test.root
65  fListOfSensitives.push_back("Ftof_Beam_Strip");//Root_Test.root
66  fListOfSensitives.push_back("Ftof_Vertical_Strip");//Root_Test.root
67  //adding side tof plates
68  fListOfSensitives.push_back("Stof_plate");
69 
70 
71 }
72 // -------------------------------------------------------------------------
73 
74 // ----- Standard constructor ------------------------------------------
75 PndFtof::PndFtof(const char* name, Bool_t active)
76  : FairDetector(name, active),
77  fListOfSensitives(), par(), fTrackID(-1), fVolumeID(-1), fEventID(-1), fPosIn(), fMomIn(), fPosOut(), fMomOut(),
78  fPLout(0), fPLin(0), fTime(0), fLength(0), fELoss(0), fPosIndex(-1), fpdgCode(-1),
79  SiId(0), CId(0), alId(0), beId(0), CpipeId(0), fcharge(0), fmass(0), fdist(0), fFtofCollection(0)
80 {
81  fFtofCollection = new TClonesArray("PndFtofPoint");
82  fVerboseLevel = 0;
83 
84  fListOfSensitives.push_back("Ftof_Central_Strip");//Root_Test.root
85  fListOfSensitives.push_back("Ftof_Beam_Strip");//Root_Test.root
86  fListOfSensitives.push_back("Ftof_Vertical_Strip");//Root_Test.root
87  //adding side tof plates
88  fListOfSensitives.push_back("Stof_plate");
89 }
90 // -------------------------------------------------------------------------
91 
92 
93 
94 // ----- Destructor ----------------------------------------------------
96  if (fFtofCollection) {
97  fFtofCollection->Delete();
98  delete fFtofCollection;
99  }
100 
101 }
102 // -------------------------------------------------------------------------
103 
104 
105 
106 // ----- Public method Intialize ---------------------------------------
108  // Init function
109 
111  FairRun* sim = FairRun::Instance();
112  FairRuntimeDb* rtdb=sim->GetRuntimeDb();
113  par=(PndGeoFtofPar*)(rtdb->getContainer("PndGeoFtofPar"));
114  par->setChanged();
115  par->setInputVersion(sim->GetRunId(),1);
116 
117  //TObjArray *fSensNodes = par->GetGeoSensitiveNodes();
118  std::cout<<" -I- Initializing PndFtof()"<<std::endl;
119 
120  if(0==gGeoManager) {
121  std::cout<<" -E- No gGeoManager in PndFtof::Initialize()!"<<std::endl;
122  abort();
123  }
124 
125 }
126 // -------------------------------------------------------------------------
128  // Begin of the event
129 
130 }
131 
132 
133 
134 // ----- Public method ProcessHits --------------------------------------
135 
136 Bool_t PndFtof::ProcessHits(FairVolume* vol)
137 {
138  if (gMC->TrackCharge()==0) return kTRUE; // skip neutrals
139 
140  TVector3 radt;
141 
142  if ( gMC->IsTrackEntering() )
143  {
144  fELoss = 0.;
145  fEventID = gMC->CurrentEvent();
146  fTime = gMC->TrackTime() * 1.0e09;
147  fLength = gMC->TrackLength();
148  fmass = gMC->TrackMass(); // mass (GeV)
149  fcharge = gMC->TrackCharge(); // charge?
150  fpdgCode = gMC->TrackPid();
151  gMC->TrackPosition(fPosIn);
152  gMC->TrackMomentum(fMomIn);
153  fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
154  }
155 
156  // Sum energy loss for all steps in the active volume
157 
158  fELoss += gMC->Edep();
159 
160  // Set additional parameters at exit of active volume. Create CbmStsPoint.
161 
162  TLorentzVector PL;
163  gMC->TrackMomentum(PL);
164 
165  if ( (gMC->IsTrackExiting() ||
166  gMC->IsTrackStop() ||
167  gMC->IsTrackDisappeared() ))
168  {
169  Int_t TrNo=gMC->GetStack()->GetCurrentTrackNumber();
170  if ( (TrNo == fTrackID) && (fELoss >0.) )
171  {
172  Int_t cp=-1;
173  gMC->CurrentVolOffID(1,cp) ;
174  fVolumeID = vol->getMCid();
175  //Int_t fVolid = gMC->CurrentVolID(cp); //[R.K. 01/2017] unused variable?
176  TString FullName = gMC->CurrentVolPath();
177 
178  gMC->TrackPosition(fPosOut);
179  gMC->TrackMomentum(fMomOut);
180 
181  radt= fPosOut.Vect();
182  fdist=radt.Perp();
183  fPLin =fMomIn.P();
184  fPLout = fMomOut.P();
185 
186  AddHit(fTrackID, fEventID,fVolumeID, FullName,
187  TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()),
188  TVector3(fMomIn.Px(), fMomIn.Py(), fMomIn.Pz()),
189  TVector3(fPosOut.X(), fPosOut.Y(), fPosOut.Z()),
190  TVector3(fMomOut.Px(), fMomOut.Py(), fMomOut.Pz()),
192  fdist,fPLin,fPLout);
193 
194  PndStack* stack = (PndStack*) gMC->GetStack();
195  stack->AddPoint(kFTOF);
196  }
197 
198  ResetParameters();
199  }
200 
201  return kTRUE;
202 
203 
204 }//ProcessHits
205 
206 // ----------------------------------------------------------------------------
207 
208 // ----- Public method EndOfEvent -----------------------------------------
210  if (fVerboseLevel) Print();
211 
212  Reset();
213 }
214 // ----------------------------------------------------------------------------
215 
216 // ----- Public method Register -------------------------------------------
218  FairRootManager::Instance()->Register("FtofPoint","PndFtof", fFtofCollection, kTRUE);
219 
220 
221 }
222 // ----------------------------------------------------------------------------
223 
224 // ----- Public method GetCollection --------------------------------------
225 TClonesArray* PndFtof::GetCollection(Int_t iColl) const {
226  if (iColl == 0) return fFtofCollection;
227 
228 
229 
230  return NULL;
231 }
232 // ----------------------------------------------------------------------------
233 
234 // ----- Public method Print ----------------------------------------------
235 void PndFtof::Print() const {
236  Int_t nHits = fFtofCollection->GetEntriesFast();
237  cout << "-I- PndFtof: " << nHits << " points registered in this event."
238  << endl;
239 
240  if (fVerboseLevel>1)
241  for (Int_t i=0; i<nHits; i++) (*fFtofCollection)[i]->Print();
242 }
243 // ----------------------------------------------------------------------------
244 
245 
246 
247 // ----- Public method Reset ----------------------------------------------
249  if (fFtofCollection) fFtofCollection->Delete();
250 
251  fPosIndex = 0;
252 }
253 // ----------------------------------------------------------------------------
254 
255 
256 // guarda in FairRootManager::CopyClones
257 // ----- Public method CopyClones -----------------------------------------
258 void PndFtof::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset ) {
259  Int_t nEntries = cl1->GetEntriesFast();
260  //cout << "-I- PndFtof: " << nEntries << " entries to add." << endl;
261  TClonesArray& clref = *cl2;
262  PndFtofPoint* oldpoint = NULL;
263  for (Int_t i=0; i<nEntries; i++) {
264  oldpoint = (PndFtofPoint*) cl1->At(i);
265  Int_t index = oldpoint->GetTrackID() + offset;
266  oldpoint->SetTrackID(index);
267  new (clref[fPosIndex]) PndFtofPoint(*oldpoint);
268  fPosIndex++;
269  }
270  cout << " -I- PndFtof: " << cl2->GetEntriesFast() << " merged entries."
271  << endl;
272 }
273 // ----------------------------------------------------------------------------
274  // ----- Public method ConstructGeometry ----------------------------------
276 
277  TString fileName=GetGeometryFileName();
278 
279  if(fileName.EndsWith(".root")){
280  ConstructRootGeometry();
281  }else{
282 
284 
285  }
286 
287 }
289 
290 
291  FairGeoLoader* geoLoad = FairGeoLoader::Instance();
292  FairGeoInterface* geoFace = geoLoad->getGeoInterface();
293 
294  FairGeoMedia *Media = geoFace->getMedia();
295  FairGeoBuilder *geobuild=geoLoad->getGeoBuilder();
296 
297  FairGeoMedium *CbmMediumSci = Media->getMedium("polyvinyltoluene");
298 
299 
300  //Int_t nmed=
301  geobuild->createMedium(CbmMediumSci);
302  TString vname = "cave";
303  TGeoVolume* vcave = gGeoManager->FindVolumeFast(vname);
304 
305  const Double_t kBCentX = 2.5; // half length(cm) //from EMC TDR
306  const Double_t kBCentY = 70.0; //half length (cm) //?
307  const Double_t kBCentZ = 0.75; //half length (cm) //?
308 
309  const Double_t kBBeamX = 2.5; // half length(cm) //from EMC TDR
310  const Double_t kBBeamY = 30.0; //alf length (cm) //?
311  const Double_t kBBeamZ = 0.75; //half length (cm) //?
312 
313  const Double_t kBVertX = 5.0; //half length (cm) //from EMC TDR
314  const Double_t kBVertY = 70.0; //half length (cm) //?
315  const Double_t kBVertZ = 0.75; //half length (cm) //from EMC TDR
316 
317 
318  TGeoBBox *CentShape;
319  TGeoBBox *BeamShape;
320  TGeoBBox *VertShape;
321 
322  TGeoVolume* CentVol;
323  TGeoVolume* BeamVol;
324  TGeoVolume* VertVol;
325 
326 
327  Double_t bx[26];//,by[26],bz[26]; //[R.K. 01/2017] unused variable?
328  Double_t bvx[50];//,bvy[50],bvz[50]; //[R.K. 01/2017] unused variable?
329  TGeoVolumeAssembly* SubunitVol = new TGeoVolumeAssembly("Ftof_strips");
330 
331 
332  char name[17];
333  char namB[17];
334  char namV[17];
335  char name1[17];
336  char namB1[17];
337  char namV1[20];
338  //char name2[17]; //[R.K. 01/2017] unused variable?
339  //char namB2[17]; //[R.K. 01/2017] unused variable?
340  //char namV2[17]; //[R.K. 01/2017] unused variable?
341 
342 
343  for(int i=0;i<26;i++){
344  bx[i]=-40+kBCentX*((2*i)+1);
345 }
346 
347  for(int i=0;i<26;i++){
348  if(i<8||i>17){
349  TGeoCombiTrans* trc1;
350 
351  //Double_t offset; //[R.K. 01/2017] unused variable?
352  sprintf (name,"Centshape%d",i);
353  sprintf (name1,"Ftof_Central_Strip%d",i);
354 
355  CentShape = new TGeoBBox("Centshape",kBCentX,kBCentY,kBCentZ);
356  CentVol = new TGeoVolume("Ftof_Central_Strip",CentShape,gGeoManager->GetMedium("polyvinyltoluene"));
357  if(i<8)trc1= new TGeoCombiTrans(bx[i],0,750,new TGeoRotation ());
358  else if (i>17)trc1= new TGeoCombiTrans(bx[i-5],0,750,new TGeoRotation ());
359 
360  trc1->SetName(name);
361  trc1->RegisterYourself();
362  SubunitVol->AddNode(CentVol,i,trc1);
363  AddSensitiveVolume(CentVol);
364  }
365  else{
367  sprintf (namB,"Beamshape%d",i);
368  sprintf (namB1,"Ftof_Beam_Strip%02d",i);
369  BeamShape = new TGeoBBox("Beamshape",kBBeamX,kBBeamY,kBBeamZ);
370  BeamVol = new TGeoVolume("Ftof_Beam_Strip",BeamShape,gGeoManager->GetMedium("polyvinyltoluene"));
371 
372  if(i==8||i==9){
373 
374  (i==8 ? (offset = -70+kBBeamY) : (offset = 70-kBBeamY));
375  TGeoCombiTrans* trc1= new TGeoCombiTrans(bx[8],offset,750,new TGeoRotation ());
376 
377  trc1->SetName(namB);
378  trc1->RegisterYourself();
379  SubunitVol->AddNode(BeamVol,i,trc1);
380  AddSensitiveVolume(BeamVol);
381  }
382  if(i==10||i==11){
383 
384  (i==10 ? (offset = -70+kBBeamY) : (offset = 70-kBBeamY));
385  TGeoCombiTrans* trc1= new TGeoCombiTrans(bx[9],offset,750,new TGeoRotation ());
386 
387  trc1->SetName(namB);
388  trc1->RegisterYourself();
389  SubunitVol->AddNode(BeamVol,i,trc1);
390  AddSensitiveVolume(BeamVol);
391  }
392  if(i==12||i==13){
393 
394  (i==12 ? (offset = -70+kBBeamY) : (offset = 70-kBBeamY));
395  TGeoCombiTrans* trc1= new TGeoCombiTrans(bx[10],offset,750,new TGeoRotation ());
396 
397  trc1->SetName(namB);
398  trc1->RegisterYourself();
399  SubunitVol->AddNode(BeamVol,i,trc1);
400  AddSensitiveVolume(BeamVol);
401  }
402  if(i==14||i==15){
403 
404  (i==14 ? (offset = -70+kBBeamY) : (offset = 70-kBBeamY));
405  TGeoCombiTrans* trc1= new TGeoCombiTrans(bx[11],offset,750,new TGeoRotation ());
406 
407  trc1->SetName(namB);
408  trc1->RegisterYourself();
409  SubunitVol->AddNode(BeamVol,i,trc1);
410  AddSensitiveVolume(BeamVol);
411  }
412  if(i==16||i==17){
413 
414  (i==16 ? (offset = -70+kBBeamY) : (offset = 70-kBBeamY));
415  TGeoCombiTrans* trc1= new TGeoCombiTrans(bx[12],offset,750,new TGeoRotation ());
416 
417  trc1->SetName(namB);
418  trc1->RegisterYourself();
419  SubunitVol->AddNode(BeamVol,i,trc1);
420  AddSensitiveVolume(BeamVol);
421  }
422  }
423 
424  }
425 
426  for(int i=0;i<24;i++){
427  bvx[i]=-280+kBVertX*((2*i)+1);
428  }
429 
430  for(int i=0;i<26;i++){
431 
432  bvx[i+24]=60+kBVertX*((2*i)+1);
433  }
434 
435  for(int i=0;i<50;i++){
436 
437 
438  sprintf (namV,"VertShape%d",i);
439  sprintf (namV1,"Ftof_Vertical_Strip%d",i);
440 
441  VertShape = new TGeoBBox("VertShape",kBVertX,kBVertY,kBVertZ);
442  VertVol = new TGeoVolume("Ftof_Vertical_Strip",VertShape,gGeoManager->GetMedium("polyvinyltoluene"));
443  TGeoCombiTrans* trc1= new TGeoCombiTrans(bvx[i],0,750,new TGeoRotation ());
444 
445  trc1->SetName(namV);
446  trc1->RegisterYourself();
447  SubunitVol->AddNode(VertVol,i,trc1);
448  AddSensitiveVolume(VertVol);
449  }
450 
451 
452  vcave->AddNode(SubunitVol,0,new TGeoCombiTrans());
453 
454 
455 }
456 
457 // -------------------------------------------------------------------------
459 {
460  for (size_t i = 0; i < fListOfSensitives.size(); i++){
461  if (name.find(fListOfSensitives[i]) != std::string::npos)
462  return true;
463  }
464  return false;
465 }
466 
467 
468 
469 // ----- Private method AddHit --------------------------------------------
470 
471 PndFtofPoint* PndFtof::AddHit(Int_t trackID, Int_t evtID, Int_t detID, TString detName,
472  TVector3 pos, TVector3 mom,
473  TVector3 posout,
474  TVector3 momout,
475  Double_t , // time //[R.K.03/2017] unused variable(s)
476  Double_t length,
477  Double_t eLoss,
478  Double_t charge, Double_t mass,
479  Int_t pdgCode,
480  Double_t dist,
481  Double_t PLin,Double_t PLout) {
482  TClonesArray& clref = *fFtofCollection;
483  Int_t size = clref.GetEntriesFast();
484  return new(clref[size]) PndFtofPoint(trackID, evtID,detID, detName,pos, mom,
485  posout, momout,
486  fTime, length, eLoss,charge,
487  mass,pdgCode,
488  dist,PLin,PLout);
489  }
490 
Int_t fEventID
Definition: PndFtof.h:138
TVector3 pos
virtual void Print() const
Definition: PndFtof.cxx:235
Double_t fPLout
Definition: PndFtof.h:144
TLorentzVector fMomIn
Definition: PndFtof.h:140
sim(Int_t nEvents=1, TString SimEngine="TGeant4", Float_t mom=6.231552)
void ConstructASCIIGeometry()
Definition: PndFtof.cxx:288
FairGeoLoader * geoLoad
Int_t i
Definition: run_full.C:25
FairGeoMedia * Media
virtual void ConstructGeometry()
Definition: PndFtof.cxx:275
virtual void Register()
Definition: PndFtof.cxx:217
Double_t fdist
Definition: PndFtof.h:155
virtual Bool_t ProcessHits(FairVolume *vol=0)
Definition: PndFtof.cxx:136
Double32_t fELoss
Definition: PndFtof.h:149
Double_t par[3]
virtual TClonesArray * GetCollection(Int_t iColl) const
Definition: PndFtof.cxx:225
Double_t mom
Definition: plot_dirc.C:14
Double32_t fLength
Definition: PndFtof.h:148
TVector3 offset(2, 0, 0)
TGeoManager * gGeoManager
Int_t fPosIndex
Definition: PndFtof.h:150
TLorentzVector fMomOut
Definition: PndFtof.h:142
void AddPoint(DetectorId iDet)
Definition: PndStack.cxx:408
TGeoVolume * SubunitVol
Int_t fTrackID
Definition: PndFtof.h:136
FairGeoBuilder * geobuild
virtual void CopyClones(TClonesArray *cl1, TClonesArray *cl2, Int_t offset)
Definition: PndFtof.cxx:258
int nHits
Definition: RiemannTest.C:16
void ResetParameters()
Hit collection.
Definition: PndFtof.h:169
Double_t
virtual void Reset()
Definition: PndFtof.cxx:248
TLorentzVector fPosIn
Definition: PndFtof.h:139
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
Int_t fVolumeID
Definition: PndFtof.h:137
TString name
virtual void BeginEvent()
Definition: PndFtof.cxx:127
Int_t fpdgCode
Definition: PndFtof.h:151
TGeoCombiTrans * trc1
PndFtofPoint * AddHit(Int_t trackID, Int_t evtID, Int_t detID, TString detName, TVector3 posin, TVector3 momin, TVector3 posout, TVector3 momout, Double_t tof, Double_t length, Double_t eLoss, Double_t charge, Double_t mass, Int_t pdgCode, Double_t dist, Double_t PLin, Double_t PLout)
Definition: PndFtof.cxx:471
virtual ~PndFtof()
Definition: PndFtof.cxx:95
PndGeoFtofPar * par
Definition: PndFtof.h:135
TLorentzVector fPosOut
Definition: PndFtof.h:141
PndFtof()
Definition: PndFtof.cxx:55
virtual void Initialize()
Definition: PndFtof.cxx:107
ClassImp(PndAnaContFact)
std::vector< std::string > fListOfSensitives
Definition: PndFtof.h:132
Double_t fcharge
Definition: PndFtof.h:154
FairGeoInterface * geoFace
virtual void EndOfEvent()
Definition: PndFtof.cxx:209
Mvd Initialize()
Double_t fmass
Definition: PndFtof.h:155
bool CheckIfSensitive(std::string name)
Definition: PndFtof.cxx:458
Double32_t fTime
Definition: PndFtof.h:147
Double_t fPLin
Definition: PndFtof.h:144
TClonesArray * fFtofCollection
Definition: PndFtof.h:157