FairRoot/PandaRoot
CbmPlane.cxx
Go to the documentation of this file.
1 
2 // -------------------------------------------------------------------------
3 
4 
5 #include "iostream.h"
6 
7 #include "TClonesArray.h"
8 #include "TGeoMCGeometry.h"
9 #include "TGeoManager.h"
10 #include "TLorentzVector.h"
11 #include "TParticle.h"
12 #include "TVirtualMC.h"
13 
14 #include "FairGeoInterface.h"
15 #include "FairGeoLoader.h"
16 #include "FairGeoNode.h"
17 #include "CbmGeoPlane.h"
18 #include "FairGeoRootBuilder.h"
19 #include "PndStack.h"
20 #include "CbmPlane.h"
21 #include "CbmPlanePoint.h"
22 #include "FairRootManager.h"
23 #include "FairVolume.h"
24 // add on for debug
25 //#include "FairGeoG3Builder.h"
26 #include "FairRuntimeDb.h"
27 #include "CbmGeoPlanePar.h"
28 #include "TObjArray.h"
29 #include "FairRun.h"
30 
31 #include "TGeant3.h"
32 
33 // ----- Default constructor -------------------------------------------
35  fPlane1Collection = new TClonesArray("CbmPlanePoint");
36  fPlane2Collection = new TClonesArray("CbmPlanePoint");
37  fPlane3Collection = new TClonesArray("CbmPlanePoint");
38 
39 // fPlaneImPlaneCollection = new TClonesArray("CbmPlanePoint");
40  fPosIndex = 0;
41  fpreflag = 0;
42  fpostflag = 0;
43  volDetector = 0;
44 
45 }
46 // -------------------------------------------------------------------------
47 
48 
49 
50 // ----- Standard constructor ------------------------------------------
51 CbmPlane::CbmPlane(const char* name, Bool_t active)
52  : FairDetector(name, active) {
53  fPlane1Collection = new TClonesArray("CbmPlanePoint");
54  fPlane2Collection = new TClonesArray("CbmPlanePoint");
55  fPlane3Collection = new TClonesArray("CbmPlanePoint");
56 
57 
58 // fPlaneImPlaneCollection = new TClonesArray("CbmPlanePoint");
59  fPosIndex = 0;
60  fpreflag = 0;
61  fpostflag = 0;
62  volDetector = 0;
63  fevent=-1;
64 }
65 // -------------------------------------------------------------------------
66 
67 
68 
69 // ----- Destructor ----------------------------------------------------
71  if (fPlane1Collection) {
72  fPlane1Collection->Delete();
73  delete fPlane1Collection;
74  }
75 
76 }
77 // -------------------------------------------------------------------------
78 
79 
80 
81 // ----- Public method Intialize ---------------------------------------
83 
84  // controlla-- forse non tutto e' necessario.
86  FairRun* sim = FairRun::Instance();
87  FairRuntimeDb* rtdb=sim->GetRuntimeDb();
88  CbmGeoPlanePar *par=(CbmGeoPlanePar*)(rtdb->getContainer("CbmGeoPlanePar"));
89  TObjArray *fSensNodes = par->GetGeoSensitiveNodes();
90 
91  // FairGeoNode *fm1= (FairGeoNode *) fSensNodes->FindObject("Plane0000");
92 // cout << "GET COPY NO: " << fm1->getCopyNo() << endl;
93 // volDetector = fm1->getMCid();
94 
95 
96 }
97 // -------------------------------------------------------------------------
99 
100 }
101 
102 
103 
104 // ----- Public method ProcessHits --------------------------------------
105 Bool_t CbmPlane::ProcessHits(FairVolume* vol) {
106 
107 
108  Int_t pdgCode = gMC->TrackPid();
109  if(pdgCode==13){
110  fmass = gMC->TrackMass(); // mass (GeV)
111  fcharge = gMC->TrackCharge(); //charge?
112  fTrackID = gMC->GetStack()->GetCurrentTrackNumber(); // trk ID
113  Int_t copyNo;
114  gMC->CurrentVolID(copyNo);
115 
116  // if entering
117  if ( gMC->IsTrackEntering() ) {
118  fpreflag = 1;
119  fELoss = 0.;
120  gMC->TrackPosition(fPosIn); // cm
121  gMC->TrackMomentum(fMomIn); // GeV
122  }
123 
124  // Sum energy loss for all steps in the active volume
125  fELoss += gMC->Edep();
126 
127  // Set additional parameters at exit of active volume. Create CbmPlanePoint.
128  if ( gMC->IsTrackExiting() ||
129  gMC->IsTrackStop() ||
130  gMC->IsTrackDisappeared() ) {
131 
132  fpostflag = 1;
133  gMC->TrackPosition(fPosOut); // cm
134  gMC->TrackMomentum(fMomOut); // GeV
135  fLength = gMC->TrackLength();
136  fTime = gMC->TrackTime() * 1e9; // time
137  // if (fELoss == 0. ) return kFALSE;
138 
139  Bool_t fmuch = kFALSE;
140 
141 // cout << vol->getMCid() << " " << gMC->CurrentVolPath() << endl;
142 
143 
144  if(fmuch == kTRUE) {
145  if(vol->getMCid()==8){
147  TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()),
148  TVector3(fPosOut.X(), fPosOut.Y(), fPosOut.Z()),
149  TVector3(fMomIn.Px(), fMomIn.Py(), fMomIn.Pz()),
150  TVector3(fMomOut.Px(), fMomOut.Py(), fMomOut.Pz()),
151  fTime, fLength, fELoss,
153  ResetParameters();
154  }else if(vol->getMCid() ==3){
156  TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()),
157  TVector3(fPosOut.X(), fPosOut.Y(), fPosOut.Z()),
158  TVector3(fMomIn.Px(), fMomIn.Py(), fMomIn.Pz()),
159  TVector3(fMomOut.Px(), fMomOut.Py(), fMomOut.Pz()),
160  fTime, fLength, fELoss,
162  ResetParameters();
163  }
164  }
165  else if(fmuch == kFALSE)
166  {
167  // 45
168  if(vol->getMCid()==3){ //36 //37 //2814 //1959
170  TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()),
171  TVector3(fPosOut.X(), fPosOut.Y(), fPosOut.Z()),
172  TVector3(fMomIn.Px(), fMomIn.Py(), fMomIn.Pz()),
173  TVector3(fMomOut.Px(), fMomOut.Py(), fMomOut.Pz()),
174  fTime, fLength, fELoss,
176  ResetParameters();
177  }
178  else if(vol->getMCid() ==4){ //37 // 38 //2815 //1960
180  TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()),
181  TVector3(fPosOut.X(), fPosOut.Y(), fPosOut.Z()),
182  TVector3(fMomIn.Px(), fMomIn.Py(), fMomIn.Pz()),
183  TVector3(fMomOut.Px(), fMomOut.Py(), fMomOut.Pz()),
184  fTime, fLength, fELoss,
186  ResetParameters();
187  }
188  else if(vol->getMCid() == 2){ //35 // 36 //2813 //1958
190  TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()),
191  TVector3(fPosOut.X(), fPosOut.Y(), fPosOut.Z()),
192  TVector3(fMomIn.Px(), fMomIn.Py(), fMomIn.Pz()),
193  TVector3(fMomOut.Px(), fMomOut.Py(), fMomOut.Pz()),
194  fTime, fLength, fELoss,
196  ResetParameters();
197  }
198  }
199  }
200  }
201  return kTRUE;
202 
203 }
204 // ----------------------------------------------------------------------------
205 
206 
207 
208 // ----- Public method EndOfEvent -----------------------------------------
210 
211  if (fVerboseLevel) Print();
212  Reset();
213  if (fevent==10000-1) plane();
214 
215 }
216 // ----------------------------------------------------------------------------
218  //
219  /* // GEANE stuff
220  //
221  cout<<"Calling GEANE..."<<endl;
222  TGeant3* gMC3 = (TGeant3*) gMC;
223  //gMC3->Gpcxyz(); //a simple test
224  Gctmed_t *afGmed = gMC3->Gctmed(); //a simple test
225  //cout<<afGmed->epsil<<endl;
226  //EUFILP
227  Ertrio_t *afErtrio=gMC3->Ertrio();
228  Eropts_t *afEropts=gMC3->Eropts();
229  for(Int_t i=0;i<15;i++) afErtrio->errin[i]=0.;
230  afErtrio->nepred=1;
231  for(Int_t i=0;i<6;i++) afEropts->erpli[i]=0.;
232  afEropts->erpli[1]=1.;
233  afEropts->erpli[5]=1.;
234  for(Int_t i=0;i<6;i++) afEropts->erplo[i]=afEropts->erpli[i];
235  afEropts->erplo[6]=1000.;
236  afEropts->erplo[7]=0.;
237  afEropts->erplo[8]=0.;
238  TVector3 v1(afEropts->erplo[0],afEropts->erplo[1],afEropts->erplo[2]);
239  TVector3 v2(afEropts->erplo[3],afEropts->erplo[4],afEropts->erplo[5]);
240  TVector3 v3=v1.Cross(v2);
241  afEropts->erplo[9]=v3(0);
242  afEropts->erplo[10]=v3(1);
243  afEropts->erplo[11]=v3(2);
244  //ERTRAK
245  Float_t x1[3]={0.,0.,0.};
246  Float_t p1[3]={1.0,0.,0.};
247  Float_t x2[3];
248  Float_t p2[3];
249  gMC3->Ertrak(x1,p1,x2,p2,5,"P");
250 
251  ofstream f("plane.out");
252  f<<x2[0]<<"\t"<<x2[1]<<"\t"<<x2[2]<<endl;
253  f<<p2[0]<<"\t"<<p2[1]<<"\t"<<p2[2]<<endl;
254  f<<x1[0]<<"\t"<<x1[1]<<"\t"<<x1[2]<<endl;
255  f<<p1[0]<<"\t"<<p1[1]<<"\t"<<p1[2]<<endl;
256  f<<afErtrio->erpout[0]<<"\t"<<afErtrio->erpout[1]<<"\t"<<afErtrio->erpout[2]<<endl;
257  f<<afEropts->erplo[9]<<"\t"<<afEropts->erplo[10]<<"\t"<<afEropts->erplo[11]<<endl;
258  f<<afEropts->leexac<<endl;
259  f<<afEropts->leleng<<endl;
260  f<<afEropts->leonly<<endl;
261  f<<afEropts->leplan<<endl;
262  f<<afEropts->lepoin<<endl;
263  f<<afEropts->levolu<<endl;
264  f<<endl;
265  for(Int_t i=0;i<15;i++) f<<i<<"\t"<<afErtrio->errout[i]<<endl;
266  f.close();
267 */
268 
269 }
270 
271 
272 
273 // ----- Public method Register -------------------------------------------
275  FairRootManager::Instance()->Register("Plane1Point","Plane1", fPlane1Collection, kTRUE);
276  FairRootManager::Instance()->Register("Plane2Point","Plane2", fPlane2Collection, kTRUE);
277  FairRootManager::Instance()->Register("Plane3Point","Plane3", fPlane3Collection, kTRUE);
278 }
279 // ----------------------------------------------------------------------------
280 
281 
282 
283 // ----- Public method GetCollection --------------------------------------
284 TClonesArray* CbmPlane::GetCollection(Int_t iColl) const {
285  if (iColl == 0) return fPlane1Collection;
286 
287  return NULL;
288 }
289 // ----------------------------------------------------------------------------
290 
291 
292 
293 
294 // ----- Public method Print ----------------------------------------------
295 void CbmPlane::Print() const {
296 
297 }
298 // ----------------------------------------------------------------------------
299 
300 
301 
302 // ----- Public method Reset ----------------------------------------------
304  fPlane1Collection->Clear();
305  fPlane2Collection->Clear();
306  fPlane3Collection->Clear();
307 
308  fPosIndex = 0;
309 }
310 // ----------------------------------------------------------------------------
311 
312 
313 // guarda in FairRootManager::CopyClones
314 // ----- Public method CopyClones -----------------------------------------
315 void CbmPlane::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset ) {
316 
317 
318 }
319 // ----------------------------------------------------------------------------
320 
321 
322 
323 // ----- Public method ConstructGeometry ----------------------------------
325 
326  FairGeoLoader* PlanegeoLoad = FairGeoLoader::Instance();
327  FairGeoInterface* PlanegeoFace = PlanegeoLoad->getGeoInterface();
328  CbmGeoPlane* PlaneGeo = new CbmGeoPlane();
329  PlaneGeo->setGeomFile(GetGeometryFileName());
330  PlanegeoFace->addGeoModule(PlaneGeo);
331 
332  Bool_t rc = PlanegeoFace->readSet(PlaneGeo);
333  if (rc) PlaneGeo->create(PlanegeoLoad->getGeoBuilder());
334  TList* volList = PlaneGeo->getListOfVolumes();
335 
336  // store geo parameter
337  FairRun *fRun = FairRun::Instance();
338  FairRuntimeDb *rtdb= FairRun::Instance()->GetRuntimeDb();
339  CbmGeoPlanePar* par=(CbmGeoPlanePar*)(rtdb->getContainer("CbmGeoPlanePar"));
340  TObjArray *fSensNodes = par->GetGeoSensitiveNodes();
341  TObjArray *fPassNodes = par->GetGeoPassiveNodes();
342 
343  TListIter iter(volList);
344  FairGeoNode* node = NULL;
345  FairGeoVolume *aVol=NULL;
346 
347  while( (node = (FairGeoNode*)iter.Next()) ) {
348  aVol = dynamic_cast<FairGeoVolume*> ( node );
349  if ( node->isSensitive() ) {
350  fSensNodes->AddLast( aVol );
351  }else{
352  fPassNodes->AddLast( aVol );
353  }
354  }
355 
356  ProcessNodes ( volList );
357  par->setChanged();
358  par->setInputVersion(fRun->GetRunId(),1);
359 
360 }
361 // ----------------------------------------------------------------------------
362 
363  CbmPlanePoint* CbmPlane::AddHit1(Int_t trackID, Int_t detID, TVector3 posIn, TVector3 posOut, TVector3 momIn, TVector3 momOut, Double_t time, Double_t length, Double_t eLoss, Double_t charge, Double_t mass, Bool_t preflag, Bool_t postflag, TString nam,Int_t evt)
364 {
365 
366  TClonesArray& clref = *fPlane1Collection;
367  Int_t size = clref.GetEntriesFast();
368 
369  return new(clref[size]) CbmPlanePoint(trackID, detID, posIn, posOut,
370  momIn, momOut, time, length, eLoss, charge,
371  mass, fpreflag, fpostflag, nam,evt);
372 
373 }
374 
375 CbmPlanePoint* CbmPlane::AddHit2(Int_t trackID, Int_t detID, TVector3 posIn, TVector3 posOut, TVector3 momIn, TVector3 momOut, Double_t time, Double_t length, Double_t eLoss, Double_t charge, Double_t mass, Bool_t preflag, Bool_t postflag, TString nam,Int_t evt)
376 {
377  TClonesArray& clref = *fPlane2Collection;
378  Int_t size = clref.GetEntriesFast();
379  return new(clref[size]) CbmPlanePoint(trackID, detID, posIn, posOut,
380  momIn, momOut, time, length, eLoss, charge,
381  mass, fpreflag, fpostflag, nam,evt);
382 }
383 
384 
385 CbmPlanePoint* CbmPlane::AddHit3(Int_t trackID, Int_t detID, TVector3 posIn, TVector3 posOut, TVector3 momIn, TVector3 momOut, Double_t time, Double_t length, Double_t eLoss, Double_t charge, Double_t mass, Bool_t preflag, Bool_t postflag, TString nam,Int_t evt)
386 {
387  TClonesArray& clref = *fPlane3Collection;
388  Int_t size = clref.GetEntriesFast();
389  return new(clref[size]) CbmPlanePoint(trackID, detID, posIn, posOut,
390  momIn, momOut, time, length, eLoss, charge,
391  mass, fpreflag, fpostflag, nam,evt);
392 }
393 
394 
395 
Double32_t fTime
momentum
Definition: CbmPlane.h:128
TLorentzVector fMomIn
position
Definition: CbmPlane.h:127
Bool_t fpostflag
Definition: CbmPlane.h:135
sim(Int_t nEvents=1, TString SimEngine="TGeant4", Float_t mom=6.231552)
CbmPlanePoint * AddHit2(Int_t trackID, Int_t detID, TVector3 posIn, TVector3 posOut, TVector3 momIn, TVector3 momOut, Double_t time, Double_t length, Double_t eLoss, Double_t charge, Double_t mass, Bool_t preflag, Bool_t postflag, TString nam, Int_t evt)
Definition: CbmPlane.cxx:375
TClonesArray * fPlane2Collection
Hit collection.
Definition: CbmPlane.h:141
virtual void CopyClones(TClonesArray *cl1, TClonesArray *cl2, Int_t offset)
Definition: CbmPlane.cxx:315
virtual void EndOfEvent()
Definition: CbmPlane.cxx:209
Double_t par[3]
Double_t fcharge
MC volume ID of Plane.
Definition: CbmPlane.h:133
int evt
Definition: checkhelixhit.C:36
void ResetParameters()
Definition: CbmPlane.h:152
void plane()
Definition: CbmPlane.cxx:217
TVector3 offset(2, 0, 0)
Bool_t fpreflag
Definition: CbmPlane.h:135
virtual void ConstructGeometry()
Definition: CbmPlane.cxx:324
CbmPlanePoint * AddHit1(Int_t trackID, Int_t detID, TVector3 posIn, TVector3 posOut, TVector3 momIn, TVector3 momOut, Double_t time, Double_t length, Double_t eLoss, Double_t charge, Double_t mass, Bool_t preflag, Bool_t postflag, TString nam, Int_t evt)
Definition: CbmPlane.cxx:363
virtual Bool_t ProcessHits(FairVolume *vol=0)
Definition: CbmPlane.cxx:105
Double32_t fELoss
length
Definition: CbmPlane.h:130
TClonesArray * fPlane3Collection
Hit collection.
Definition: CbmPlane.h:142
FairRunAna * fRun
Definition: hit_dirc.C:58
TLorentzVector fPosIn
volume id
Definition: CbmPlane.h:126
virtual void Initialize()
Definition: CbmPlane.cxx:82
Int_t volDetector
Definition: CbmPlane.h:132
TClonesArray * fPlane1Collection
Definition: CbmPlane.h:140
Double_t
CbmPlane()
Definition: CbmPlane.cxx:34
Int_t fevent
Hit collection.
Definition: CbmPlane.h:144
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
virtual ~CbmPlane()
Definition: CbmPlane.cxx:70
Int_t fVolumeID
track index
Definition: CbmPlane.h:125
TString name
Int_t fTrackID
Definition: CbmPlane.h:124
Int_t fPosIndex
energy loss
Definition: CbmPlane.h:131
Double32_t fLength
time
Definition: CbmPlane.h:129
virtual void Register()
Definition: CbmPlane.cxx:274
virtual void Print() const
Definition: CbmPlane.cxx:295
ClassImp(PndAnaContFact)
Double_t fmass
Definition: CbmPlane.h:134
virtual void BeginEvent()
Definition: CbmPlane.cxx:98
TObjArray * GetGeoPassiveNodes()
virtual void Reset()
Definition: CbmPlane.cxx:303
CbmPlanePoint * AddHit3(Int_t trackID, Int_t detID, TVector3 posIn, TVector3 posOut, TVector3 momIn, TVector3 momOut, Double_t time, Double_t length, Double_t eLoss, Double_t charge, Double_t mass, Bool_t preflag, Bool_t postflag, TString nam, Int_t evt)
Definition: CbmPlane.cxx:385
TString nam
Definition: sim_hypGe.C:48
Mvd Initialize()
TLorentzVector fPosOut
Definition: CbmPlane.h:126
TLorentzVector fMomOut
Definition: CbmPlane.h:127
virtual TClonesArray * GetCollection(Int_t iColl) const
Definition: CbmPlane.cxx:284
TObjArray * GetGeoSensitiveNodes()