FairRoot/PandaRoot
PndGemDetector.cxx
Go to the documentation of this file.
1 // PndGemDetector
3 //
4 // Class for PndGemDetector
5 //
7 
8 #include "PndGemDetector.h"
9 
10 #include "FairRootManager.h"
11 #include "FairVolume.h"
12 
13 #include "PndDetectorList.h"
14 #include "PndGemMCPoint.h"
15 #include "PndStack.h"
16 
17 #include "TClonesArray.h"
18 #include "TVirtualMC.h"
19 #include "TGeoManager.h"
20 #include "TGeoPhysicalNode.h"
21 
22 #include <iostream>
23 #include <string>
24 #include <sstream>
25 
26 class FairGeoLoader;
27 class FairGeoMedia;
28 class FairRunSim;
29 class FairGeoInterface;
30 class FairGeoRootBuilder;
31 class FairGeoNode;
32 class FairRun;
33 class FairRuntimeDb;
34 class FairGeoVolume;
35 
36 class TGeoVoxelFinder;
37 class TObjArray;
38 class TList;
39 class TGeoMatrix;
40 class TParticle;
41 class TLorentzVector;
42 class TKey;
43 
44 
45 // ----- Default constructor -------------------------------------------
46 PndGemDetector::PndGemDetector() : fUseRadDamOption(false) {
47  fPndGemCollection = new TClonesArray("PndGemMCPoint");
48  fPosIndex = 0;
49  fListOfSensitives.push_back("Sensor");
50  if (fVerboseLevel>0) {
51  std::cout<<"-I- PndGemDetector: fListOfSensitives contains:";
52  for(size_t k=0;k<fListOfSensitives.size();k++)
53  std::cout<<"\n\t"<<fListOfSensitives[k];
54  std::cout<<std::endl;
55  }
56 }
57 // -------------------------------------------------------------------------
58 
59 
60 
61 // ----- Standard constructor ------------------------------------------
63  : FairDetector(name, active), fUseRadDamOption(false) {
64  fPndGemCollection = new TClonesArray("PndGemMCPoint");
65  fPosIndex = 0;
66  fListOfSensitives.push_back("Sensor");
67  if (fVerboseLevel>0) {
68  std::cout<<"- I - PndGemDetector: fListOfSensitives contains:";
69  for(size_t k=0;k<fListOfSensitives.size();k++)
70  std::cout<<"\n\t"<<fListOfSensitives[k];
71  std::cout<<std::endl;
72  }
73 }
74 // -------------------------------------------------------------------------
75 
76 
77 
78 
79 // ----- Destructor ----------------------------------------------------
81 {
83  {
84  fPndGemCollection->Delete();
85  delete fPndGemCollection;
86  }
87 // delete fGeoH;
88 }
89 // -------------------------------------------------------------------------
91 {
92  std::cout<<" -I- Initializing PndGemDetector()"<<std::endl;
94  if(0==gGeoManager) {
95  std::cout<<" -E- No gGeoManager in PndGemDetector::Initialize()!"<<std::endl;
96  abort();
97  }
98 // fGeoH = new PndGemGeoHandling(gGeoManager);
99 }
100 
101 
102 // ----- Public method ProcessHits --------------------------------------
104 {
105 
106  if ( gMC->IsTrackEntering() )
107  {
108  // Set parameters at entrance of volume. Reset ELoss.
109  fELoss = 0.;
110  fTime = gMC->TrackTime() * 1.0e09;
111  fLength = gMC->TrackLength();
112  gMC->TrackPosition(fPosIn);
113  gMC->TrackMomentum(fMomIn);
114  }
115 
116  // Sum energy loss for all steps in the active volume
117  fELoss += gMC->Edep();
118 
119 
120  // Create PndGemMCPoint at exit of active volume
121 
122  if ( gMC->IsTrackExiting() ||
123  gMC->IsTrackStop() ||
124  gMC->IsTrackDisappeared() ) {
125 
126  fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
127 
128 /* if(0==fGeoH) {
129  std::cout<<" -E- No PndGemGeoHandling loaded."<<std::endl;
130  abort();
131  }*/
132  if (fVerboseLevel > 1){
133  std::cout << "******* Info from gMC *************" << std::endl;
134  std::cout << "Hit in " << gMC->CurrentVolPath() << " with MCiD: " << vol->getMCid() << " PixelDetectorID: " << kGEM << std::endl;
135 // std::cout<<"VolumeID: "<<fGeoH->GetID(gMC->CurrentVolPath())<<std::endl;
136  std::cout << "PosIn: " << fPosIn.X() << " " << fPosIn.Y() << " " << fPosIn.Z() << " " << fELoss << std::endl;
137  }
138 
139  gMC->TrackPosition(fPosOut);
140  gMC->TrackMomentum(fMomOut);
141 
142  if (fUseRadDamOption == false){
143  if (fELoss == 0.) return kFALSE;
144  }
145 
146  TString detPath = gMC->CurrentVolPath();
147  Int_t sensID = GetSensorId(detPath);
148  AddHit(fTrackID, kGEM, sensID,
149  TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()),
150  TVector3(fPosOut.X(), fPosOut.Y(), fPosOut.Z()),
151  TVector3(fMomIn.Px(), fMomIn.Py(), fMomIn.Pz()),
152  TVector3(fMomOut.Px(), fMomOut.Py(), fMomOut.Pz()),
153  fTime, fLength, fELoss);
154 
155  // Increment number of PndGem points for TParticle
156  PndStack* stack = (PndStack*) gMC->GetStack();
157  stack->AddPoint(kGEM);
158 
159  ResetParameters();
160  }
161 
162  return kTRUE;
163 }
164 // -------------------------------------------------------------------------
165 
166 
167 
168 // ----- Public method EndOfEvent --------------------------------------
170 {
171  if (fVerboseLevel)
172  Print();
173 
174  fPndGemCollection->Delete();
175  fPosIndex = 0;
176 }
177 // -------------------------------------------------------------------------
178 
180 {
181 
182 }
183 
184 // ----- Public method Register ----------------------------------------
186 {
187  FairRootManager::Instance()->Register("GEMPoint", "PndGem", fPndGemCollection, kTRUE);
188 }
189 // -------------------------------------------------------------------------
190 
191 
192 
193 // ----- Public method GetCollection -----------------------------------
194 TClonesArray* PndGemDetector::GetCollection(Int_t iColl) const
195 {
196  if (iColl == 0)
197  return fPndGemCollection;
198  else
199  return NULL;
200 }
201 // -------------------------------------------------------------------------
202 
203 
204 
205 // ----- Public method Print -------------------------------------------
207 {
208  Int_t
209  nHits = fPndGemCollection->GetEntriesFast();
210 
211  std::cout << "-I- PndGemDetector: " << nHits << " points registered in this event." << std::endl;
212 
213  if (fVerboseLevel>1)
214  for (Int_t i=0; i<nHits; i++)
215  (*fPndGemCollection)[i]->Print();
216 }
217 // -------------------------------------------------------------------------
218 
219 
220 
221 // ----- Public method Reset -------------------------------------------
223 {
224  fPndGemCollection->Delete();
225  ResetParameters();
226 }
227 // -------------------------------------------------------------------------
228 
229 
230 
231 // ----- Public method CopyClones --------------------------------------
232 void PndGemDetector::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset)
233 {
234  Int_t
235  nEntries = cl1->GetEntriesFast();
236 
237  std::cout << "-I- PndGemDetector: " << nEntries << " entries to add." << std::endl;
238 
239  TClonesArray& clref = *cl2;
240 
242  *oldpoint = NULL;
243  for (Int_t i=0; i<nEntries; i++)
244  {
245  oldpoint = (PndGemMCPoint*) cl1->At(i);
246 
247  Int_t
248  index = oldpoint->GetTrackID() + offset;
249 
250  oldpoint->SetTrackID(index);
251  new (clref[fPosIndex]) PndGemMCPoint(*oldpoint);
252  fPosIndex++;
253  }
254  std::cout << "-I- PndGemDetector: " << cl2->GetEntriesFast() << " merged entries."
255  << std::endl;
256 }
257 
258 // -------------------------------------------------------------------------
260 {
261  TString fileName=GetGeometryFileName();
262 // if(fileName.EndsWith(".geo")){
263 // ConstructASCIIGeometry();
264 // }else
265  if(fileName.EndsWith(".root")){
266  ConstructRootGeometry();
267  }else{
268  std::cout<< "Geometry format not supported " <<std::endl;
269  }
270 }
271 
272 // -------------------------------------------------------------------------
274 {
275  std::cout << "-----------------------------------" << std::endl;
276  std::cout << " M I S A L I G N D E T E C T O R " << std::endl;
277 
278  /* TGeoPhysicalNode* pn1 = gGeoManager->MakePhysicalNode("/cave_1/Gem_Disks_0/Gem_Disk1_Volume_0/Gem_Disk1_Seg1_Gem1_Sensor_GEMmixture_0");
279  cout << "got the node " << pn1 << endl;
280  cout << "print the orig rot matrix:" << endl;
281  pn1->GetOriginalMatrix()->Print();
282  cout << "print the rot matrix:" << endl;
283  pn1->GetMatrix()->Print();
284 
285  TGeoHMatrix* dummyRot = new TGeoHMatrix();
286  // dummyRot->RotateZ(90);
287  dummyRot->RotateX(0.3);
288  dummyRot->RotateY(0.1);
289  Double_t trans[3] = {0.,-0.1,-1.123400};
290  dummyRot->SetTranslation(trans);
291 
292  cout << "dummyRot ---> " << endl;
293  dummyRot->Print();
294 
295  cout << "aligning to dummyRot" << endl;
296  pn1->Align(dummyRot); // in Align, if (!newmat&&!newshape)return;*/
297 
298  Int_t nofSeg = 2;
299  for ( Int_t ist = 0 ; ist < 3 ; ist++ ) {
300  if ( ist == 2 ) nofSeg = 3;
301  for ( Int_t isg = 0 ; isg < nofSeg ; isg++ ) {
302  for ( Int_t isp = 0 ; isp < 2 ; isp++ ) {
303  TString tName = Form("/cave_1/Gem_Disks_0/Gem_Disk%d_Volume_0/Gem_Disk%d_Seg%d_Gem%d_Sensor_GEMmixture_0",ist+1,ist+1,isg+1,isp*5+1);
304  cout << tName.Data() << endl;
305  TGeoPhysicalNode* tgpn = gGeoManager->MakePhysicalNode(tName.Data());
306  TGeoHMatrix* tghm = (TGeoHMatrix*)tgpn->GetOriginalMatrix();
307  cout << " * * * o r i g * * * o r i g * * * o r i g * * * o r i g * * * " << endl;
308  tghm->Print();
309  tghm->RotateX(gRandom->Gaus(0.,.1));
310  tghm->RotateY(gRandom->Gaus(0.,.1));
311  tghm->RotateZ(gRandom->Gaus(0.,.1));
312  Double_t* trans = tghm->GetTranslation();
313  cout << "trans = " << trans[0] << " " << trans[1] << " " << trans[2] << endl;
314  for ( Int_t ic = 0 ; ic < 3 ; ic++ )
315  trans[0] += gRandom->Gaus(0.,.03);
316  tghm->SetTranslation(trans);
317  cout << " * * * m o v e d * * * m o v e d * * * m o v e d * * * m o v e d * * * " << endl;
318  tghm->Print();
319  cout << " * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * " << endl;
320  tgpn->Align(tghm);
321  }
322  }
323  }
324 
325  std::cout << "-----------------------------------" << std::endl;
326 }
327 
328 // -------------------------------------------------------------------------
330 {
331  for (size_t i = 0; i < fListOfSensitives.size(); i++){
332  if (name.find(fListOfSensitives[i]) != std::string::npos)
333  return true;
334  }
335  return false;
336 }
337 
338 // -------------------------------------------------------------------------
340 {
341  // std::cout << "name is " << detName.Data() << " -> " << std::flush;
342  detName.Remove(0,detName.Last('/')+1);
343  detName.Remove(0,detName.First("Disk")+4);
344  Int_t stationNr = detName.Atoi();
345  detName.Remove(0,detName.First("Seg")+3);
346  Int_t segmentNr = detName.Atoi();
347  detName.Remove(0,detName.First("Gem")+3);
348  Int_t sensorNr = detName.Atoi();
349  if ( sensorNr == 6 ) sensorNr = 2;
350 // std::cout << "stat " << stationNr << " sens " << sensorNr << " seg " << segmentNr << " > "
351 // << stationNr*256+sensorNr*16+segmentNr << std::endl;
352  return stationNr*256+sensorNr*16+segmentNr;
353 }
354 
355 // ----- Public method ConstructGeometry -------------------------------
356 // void PndGemDetector::ConstructASCIIGeometry()
357 // {
358 // // get pointer to the instantons which interface
359 // // to monte carlo
360 //
361 // FairGeoLoader *geoLoad = FairGeoLoader::Instance();
362 // FairGeoInterface *geoFace = geoLoad->getGeoInterface();
363 // PndGemGeo *thePndGemGeo = new PndGemGeo();
364 //
365 // thePndGemGeo->setGeomFile(GetGeometryFileName());
366 // geoFace->addGeoModule(thePndGemGeo);
367 //
368 // Bool_t rc = geoFace->readSet(thePndGemGeo);
369 //
370 // if (rc)
371 // thePndGemGeo->create(geoLoad->getGeoBuilder());
372 //
373 // TList* volList = thePndGemGeo->getListOfVolumes();
374 //
375 // // store geo parameter
376 // FairRun *fRun = FairRun::Instance();
377 //
378 // FairRuntimeDb *rtdb= FairRun::Instance()->GetRuntimeDb();
379 //
380 // PndGemGeoPar *par= (PndGemGeoPar*)(rtdb->getContainer("PndGemGeoPar"));
381 //
382 // TObjArray *fSensNodes = par->GetGeoSensitiveNodes();
383 //
384 // TObjArray *fPassNodes = par->GetGeoPassiveNodes();
385 //
386 // TListIter iter(volList);
387 //
388 // FairGeoNode *node = NULL;
389 // FairGeoVolume *aVol = NULL;
390 //
391 // while( (node = (FairGeoNode*)iter.Next()) ) {
392 // aVol = dynamic_cast<FairGeoVolume*> ( node );
393 // if ( node->isSensitive() ) {
394 // fSensNodes->AddLast( aVol );
395 // }else{
396 // fPassNodes->AddLast( aVol );
397 // }
398 // }
399 //
400 // par->setChanged();
401 // par->setInputVersion(fRun->GetRunId(),1);
402 //
403 // ProcessNodes ( volList );
404 // }
405 // -------------------------------------------------------------------------
406 
407 // ----- Public method SetExclusiveSensorType -------------------------------
409 {
410  //Set one exclusive sensor type for testing purposes
411  fListOfSensitives.clear();
412  fListOfSensitives.push_back(sens.Data());
413  std::cout<<"-I- PndGemDetector: Only active sensor type is set to \""<<sens.Data()<<"\","<<std::endl;
414  std::cout<<" this is not a default setting."<<std::endl;
415 }
416 
417 // -------------------------------------------------------------------------
418 
419 
420 
421 // ----- Private method AddHit -----------------------------------------
422 PndGemMCPoint* PndGemDetector::AddHit(Int_t trackID, Int_t detID, Int_t sensID,
423  TVector3 posIn, TVector3 posOut,TVector3 momIn, TVector3 momOut,
424  Double_t time, Double_t length, Double_t eLoss)
425 {
426  TClonesArray&
427  clref = *fPndGemCollection;
428 
429  Int_t
430  size = clref.GetEntriesFast();
431 
432  if (fVerboseLevel >= 2)
433  std::cout << "-I- PndGemDetector: Adding Point at (" << posIn.X() << ", " << posIn.Y()
434  << ", " << posIn.Z() << ") cm, (" << posOut.X() << ", " << posOut.Y()
435  << ", " << posOut.Z() << ") cm, sensor " << sensID << " " << detID << ", track "
436  << trackID << ", energy loss " << eLoss*1e06 << " keV" << std::endl;
437 
438  return new(clref[size]) PndGemMCPoint(trackID, detID, sensID, posIn, posOut,
439  momIn, momOut, time, length, eLoss);
440 }
441 // -------------------------------------------------------------------------
442 
443 
444 
virtual void Register()
virtual TClonesArray * GetCollection(Int_t iColl) const
void ResetParameters()
TLorentzVector fMomIn
exit position in global frame
virtual void Print() const
std::vector< std::string > fListOfSensitives
enables the detection of neutral particles
Int_t i
Definition: run_full.C:25
Double32_t fELoss
length
bool fUseRadDamOption
Hit collection.
TVector3 offset(2, 0, 0)
virtual void CopyClones(TClonesArray *cl1, TClonesArray *cl2, Int_t offset)
TGeoManager * gGeoManager
bool CheckIfSensitive(std::string name)
virtual void EndOfEvent()
void AddPoint(DetectorId iDet)
Definition: PndStack.cxx:408
TGeoTranslation * trans
int nHits
Definition: RiemannTest.C:16
Double_t
Int_t GetSensorId(TString detName)
virtual void Initialize()
TClonesArray * fPndGemCollection
virtual void Reset()
TLorentzVector fPosIn
Det id.
PndGemMCPoint * AddHit(Int_t trackID, Int_t detID, Int_t sensID, TVector3 posIn, TVector3 posOut, TVector3 momIn, TVector3 momOut, Double_t time, Double_t length, Double_t eLoss)
void SetExclusiveSensorType(const TString sens)
TString name
virtual void ConstructGeometry()
virtual void FinishRun()
TLorentzVector fMomOut
momentum
Double32_t fLength
time
ClassImp(PndGemDetector)
Int_t fPosIndex
energy loss
virtual ~PndGemDetector()
Mvd Initialize()
TLorentzVector fPosOut
entry position in global frame
virtual Bool_t ProcessHits(FairVolume *vol=0)
Double32_t fTime
momentum