FairRoot/PandaRoot
PndHypStripHitProducer.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndHypStripHitProducer -----
3 // -------------------------------------------------------------------------
4 
5 
6 #include "TClonesArray.h"
7 #include "TArrayD.h"
8 #include "TVector2.h"
9 #include "TGeoManager.h"
10 
11 #include "FairRootManager.h"
12 #include "PndHypStripHitProducer.h"
13 #include "PndHypHit.h"
14 #include "PndHypPoint.h"
15 #include "FairRunAna.h"
16 #include "FairRuntimeDb.h"
17 #include "FairGeoNode.h"
18 //#include "FairRuntimeDb.h"
19 #include "FairGeoNode.h"
20 #include "FairGeoVector.h"
21 //#include "StringVector.h"
22 #include "PndHypCalcStrip.h"
23 #include "PndHypDigiStrip.h"
24 //#include "PndHypDigiStrip.h"
25 //enum SensorSide { kTOP, kBOTTOM };
26 // ----- Default constructor -------------------------------------------
28 FairTask("Hyp Strip Hit Producer")
29 {
30  fBranchName = "HypPoint";
31 
32  /*ftopPitch = 0.;
33  fbotPitch = 0.;
34  forient = 0.;
35  fskew = 0.;
36  fTopAnchor = TVector2(0,0);
37  fBotAnchor = TVector2(0,0);
38  fnrTopFE = 0;
39  fnrBotFE = 0;
40  fnrFECh = 0;
41  fthreshold = 0.;
42  fnoise = 0.;*/
43 
44  fOverrideParams = false;
45  // stripHits = 0;
46  // fHitArray = new TClonesArray("PndHypHit");
47  // fStripArray = new TClonesArray("PndHypStripHit");
48 }
49 // -------------------------------------------------------------------------
50 
52  Double_t ori, Double_t skew,
53  TVector2 topAnchor, TVector2 botAnchor,
54  Int_t nrTopFE, Int_t nrBotFE, Int_t nrFECh,
56  TString , TString feType) : // sensorType //[R.K.03/2017] unused variable(s)
57 FairTask("Hyp Strip Hit Producer")
58 {
59  fBranchName = "HypPoint";
60  // ftopPitch = topPitch;
61  // fbotPitch = botPitch;
62  // forient = ori;
63  // fskew = skew;
64  // fTopAnchor = topAnchor;
65  // fBotAnchor = botAnchor;
66  // fnrTopFE = nrTopFE;
67  // fnrBotFE = nrBotFE;
68  // fnrFECh = nrFECh;
69  // fthreshold = threshold;
70  // fnoise = noise;
71 
72  fOverrideParams = true;
73  SetParamSet(topPitch,botPitch,ori,skew,topAnchor,botAnchor,nrTopFE,nrBotFE,
74  nrFECh,threshold,noise,"Rect",feType);
75  //stripHits = 0;
76  std::cout << "Hyp Strip Hit Producer initiated" << std::endl;
77 }
78 // -------------------------------------------------------------------------
79 
81  Double_t ori, Double_t skew,
82  TVector2 topAnchor, TVector2 botAnchor,
83  Int_t nrTopFE, Int_t nrBotFE, Int_t nrFECh,
85  TString sensorType, TString feType)
86 {
87  FairRunAna* ana = FairRunAna::Instance();
88  //FairRootManager* ioman = FairRootManager::Instance(); //[R.K. 01/2017] unused variable
89  if ( fDigiPar==0 ) SetParContainers();
90  if (fOverrideParams){
91  if (sensorType.Contains("Rect"))fCurrentDigiPar = fDigiPar;
92  else if (sensorType.Contains("Trap")) fCurrentDigiPar = fDigiPar;
93  fCurrentDigiPar->SetTopPitch(topPitch);
94  fCurrentDigiPar->SetBotPitch(botPitch);
95  fCurrentDigiPar->SetSkew(skew);
97  fCurrentDigiPar->SetTopAnchor(topAnchor);
98  fCurrentDigiPar->SetBotAnchor(botAnchor);
99  fCurrentDigiPar->SetNrFECh(nrFECh);
100  fCurrentDigiPar->SetNrTopFE(nrTopFE);
101  fCurrentDigiPar->SetNrBotFE(nrBotFE);
102  fCurrentDigiPar->SetThreshold(threshold);
103  fCurrentDigiPar->SetNoise(noise);
104  fCurrentDigiPar->SetSensType(sensorType);
105  fCurrentDigiPar->SetFeType(feType);
106  fCurrentDigiPar->setChanged();
107  fCurrentDigiPar->setInputVersion(ana->GetRunId(),1);
108  }
109 
110 
111 }
112 
113 // ----- Destructor ----------------------------------------------------
115 {
116  delete fGeoH;
117 }
118 // -------------------------------------------------------------------------
119 
120 // ----- Initialization of Parameter Containers -------------------------
122 {
123  // Get Base Container
124 
125  FairRunAna* ana = FairRunAna::Instance();
126  FairRuntimeDb* rtdb=ana->GetRuntimeDb();
127  //fGeoPar = (PndGeoHypPar*)(rtdb->getContainer("PndGeoHypPar"));
128  fDigiPar = (PndHypStripDigiPar*)(rtdb->getContainer("PndHypStripDigiPar"));
129  //fGeoMappingPar = (PndHypGeoMappingPar*)(rtdb->getContainer("PndHypGeoMappingPar"));
130  std::cout << "fdigi par init" << std::endl;
131 }
132 
134 {
135  /*
136  FairRunAna* ana = FairRunAna::Instance();
137  FairRuntimeDb* rtdb=ana->GetRuntimeDb();
138  //fGeoPar = (PndGeoHypPar*)(rtdb->getContainer("PndGeoHypPar"));
139  fDigiPar=(PndHypStripDigiPar*)(rtdb->getContainer("PndHypStripDigiPar"));
140  //fGeoMappingPar = (PndHypGeoMappingPar*)(rtdb->getContainer("PndHypGeoMappingPar"));
141  std::cout << "fdigi par 2 init" << std::endl;
142  */
144  return kSUCCESS;
145 
146 }
147 
148 
149 // ----- Public method Init --------------------------------------------
151 {
152  //FairRunAna* ana = FairRunAna::Instance(); //[R.K. 01/2017] unused variable
153  FairRootManager* ioman = FairRootManager::Instance();
154 
156 
157  if ( ! ioman )
158  {
159  std::cout << "-E- PndHypStripHitProducer::Init: "
160  << "RootManager not instantiated!" << std::endl;
161  return kFATAL;
162  }
163 
164  fPointArray = (TClonesArray*) ioman->GetObject(fBranchName);
165  if ( ! fPointArray )
166  {
167  std::cout << "-W- PndHypStripHitProducer::Init: "
168  << "No HypPoint array!" << std::endl;
169  return kERROR;
170  }
171 
172  // Create and register output array
173  //fHitArray = new TClonesArray("PndHypHit");
174  //ioman->Register("HypHit", "Hyp", fHitArray, kTRUE);
175 
176  // Create and register output array
177  fStripArray = new TClonesArray("PndHypDigiStrip");
178  ioman->Register("HypStripDigis", "Hyp", fStripArray, kTRUE);
179 
180  // Create and register parameter array
181  // fStripArray = new TClonesArray("PndHypDigiPar");
182  // ioman->Register("HypDigiParam", "Hyp", fDigiPar, kTRUE);
183 
184  // SetParContainers();
185 
186  std::cout << "-I- PndHypStripHitProducer: Initialisation successfull" << std::endl;
187  //std::cout << "-I- Test: " << fGeoMappingPar->detIdPairArray->GetEntries() << std::endl;
188 
189 
190  if (!fDigiPar) {
191  std::cout<<"-E- MvdStripHitProducer: DigiPar Container does not exist!"<<std::endl;
192  return kERROR;
193  }
194  // if (fOverrideParams)
195  // {
196  // fDigiPar->SetTopPitch(ftopPitch);
197  // fDigiPar->SetBotPitch(fbotPitch);
198  // fDigiPar->SetSkew(fskew);
199  // fDigiPar->SetOrient(forient);
200  // fDigiPar->SetTopAnchor(fTopAnchor);
201  // fDigiPar->SetBotAnchor(fBotAnchor);
202  // fDigiPar->SetNrFECh(fnrFECh);
203  // fDigiPar->SetNrTopFE(fnrTopFE);
204  // fDigiPar->SetNrBotFE(fnrBotFE);
205  // fDigiPar->SetThreshold(fthreshold);
206  // fDigiPar->SetNoise(fnoise);
207  // fDigiPar->setChanged();
208  // fDigiPar->setInputVersion(ana->GetRunId(),1);
209 
210  // }
211 
212  fDigiPar->print();
213 
218 
219  return kSUCCESS;
220 }
221 // -------------------------------------------------------------------------
222 
223 
224 
225 // ----- Public method Exec --------------------------------------------
227 {
228  // Reset output array
229  //if ( ! fHitArray )
230  // Fatal("Exec", "No HitArray");
231 
232  //fHitArray->Delete();
233 
234  fStripArray->Delete();
235 
236  // fFeStripArray->Delete();
237 
238  // Declare some variables
239  PndHypPoint *point = NULL;
240 
241  Int_t detID = 0; // Detector ID
242  //trackID = 0; // Track index //[R.K.03/2017] unused variable
243 
244  // Loop over PndHypPoints
245  Int_t
246  nPoints = fPointArray->GetEntriesFast();
247  if (fVerbose > 0){
248  std::cout<<" Nr of Points: "<<nPoints<<std::endl;
249  }
250 
251 
252  Int_t iStrip = 0;
253  //Int_t iFeStrip = 0;
254  Int_t nSiL =-1;
255 
256  /*PndHypCalcStrip StripCalcTop(fDigiPar->topPitch, fDigiPar->orient,
257  fDigiPar->topNrFE * fDigiPar->feChannels , fDigiPar->feChannels,
258  fDigiPar->topAnchor,
259  fDigiPar->threshold, fDigiPar->noise);
260 
261  PndHypCalcStrip StripCalcBot(fDigiPar->botPitch, fDigiPar->orient + fDigiPar->skew,
262  fDigiPar->botNrFE * fDigiPar->feChannels, fDigiPar->feChannels,
263  fDigiPar->botAnchor,
264  fDigiPar->threshold, fDigiPar->noise);
265 
266  PndHypCalcStrip StripCalcTop(ftopPitch, forient,
267  fnrTopFE * fnrFECh , fnrFECh,
268  fTopAnchor,
269  fthreshold, fnoise);
270 
271  PndHypCalcStrip StripCalcBot(fbotPitch, forient + fskew,
272  fnrBotFE * fnrFECh, fnrFECh,
273  fBotAnchor,
274  fthreshold, fnoise);
275  */
276 
277  for (Int_t iPoint = 0; iPoint < nPoints; iPoint++)
278  {
279  point = (PndHypPoint*) fPointArray->At(iPoint);
280  //if (!((point->GetDetName()).Contains("Strip"))) continue;
281  //if ((point->GetDetName()).Contains("Disk")) continue;
282  // if ((point->GetDetName()).Contains("SideChips")) continue;
283 
284  //if (fVerbose > 1){
285  //std::cout<<"***** Strip Hit ******"<<std::endl;
286  //std::cout<<" DetName : "<<point->GetDetName()<<std::endl;
287  //}
288  if ( ! point){
289  std::cout<< "No Point!" << std::endl;
290  continue;
291  }
292  if (fVerbose > 1){
293  std::cout << "****Global Point: " << std::endl;
294  point->Print("");
295  }
296  //FairGeoVector posInL, posOutL, meanPos, meanPosL;
297  //GetLocalHitPoints(point, posInL, posOutL);
298  TVector3 posIn,posOut;
299  point->PositionIn(posIn);
300  point->PositionOut(posOut);
301 
302  TVector3 posInL = fGeoH->MasterToLocalId(posIn,point->GetDetName());
303  TVector3 posOutL = fGeoH->MasterToLocalId(posOut,point->GetDetName());
304 
305  if (fVerbose > 1){
306  std::cout << "Local Hits: " << std::endl;
307 
308  }
309 
310  if (fVerbose > 1){
311 
312  std::cout << "Energy: " << point->GetEnergyLoss() << std::endl;
313  }
314 
315  //TVector3 size = GetSensorDimensions(point->GetDetName().Data());
316  TVector3 size = GetSensorDimensions(fGeoH->GetPath(point->GetDetName()).Data());
317 
318  if (fVerbose > 2) std::cout<< "Sensor Size : x="
319  <<size.x()*2.<<" , y="
320  <<size.y()*2.<<" , z ="
321  <<size.z()*2.<<std::endl;
322 
323  TVector2 anchor(-size.x(),size.y());
324 
325  // Top Side
326  if (fVerbose > 0)
327  std::cout << "Top Side: " << std::endl;
328  // PndHypCalcStrip StripCalc(ftopPitch, forient, fnrTopFE * fnrFECh ,
329  // //FairGeoVector(-size.x(),-size.y(),0.),
330  // TVector2(0.,0.),
331  // fthreshold, fnoise);
332 
333  //StripCalcTop.SetVerboseLevel(fVerbose);
334  Double_t sttop = ((size.x()*2)/fDigiPar->GetTopPitch());
335 
336  Int_t rfetop = Int_t(sttop+0.5);
337  Int_t rtfe = Int_t((rfetop/128)+0.5);
338 
339  if(rfetop>=rtfe*128)fStripCalcTop->SetreStrip(rtfe*128);
340  else fStripCalcTop->SetreStrip(rfetop);
341  std::cout<<" tof fe "<<Int_t(rfetop/128)<<" total strips "<<rfetop<<std::endl;
342 
343  nSiL = point->GetVolumeID();
344 
345  fStripCalcTop->SetAnchor(anchor);
346  // Calculate a cluster of Strips fired
347  std::vector<PndHypStrip> topStrips =
348  fStripCalcTop->GetStrips(posInL.X(), posInL.Y(), posInL.Z(),
349  posOutL.X(), posOutL.Y(), posOutL.Z(),
350  point->GetEnergyLoss(),nSiL);
351 
352  if (topStrips.size() != 0){
353  //stripHits += topStrips.size();
354  if (fVerbose > 0)
355  std::cout << "SensorStrips: top " << topStrips.size()<<std::endl;
356 
357  //trackID = point->GetTrackID(); //[R.K.03/2017] unused variable
358  detID = point->GetVolumeID();
359 
360  // for(uint i = 0; i < myStrips.size(); i++)
361  //iStrip = 0;
362  //Int_t sp;SensorSide si; //[R.K. 01/2017] unused variable
363 
364 
365 
366  for(std::vector<PndHypStrip>::const_iterator it=topStrips.begin();
367  it!= topStrips.end();it++)
368 
369  {
370 
371  new ((*fStripArray)[iStrip]) PndHypDigiStrip(iPoint,detID,
372  point->GetDetName(),
373  fStripCalcTop->CalcFEfromStrip(it->GetIndex()),
374  fStripCalcTop->CalcChannelfromStrip(it->GetIndex()),it->GetCharge());
375  //dynamic_cast<PndHypDigiStrip*>(fStripArray->operator[](iStrip))->SetMCID(trackID);
376 
377 
378  if (fVerbose > 1)std::cout << *it <<" "<<topStrips[iStrip] << std::endl;
379  iStrip++;
380  }
381  }else if(fVerbose>2) std::cout<<"Top side empty"<<std::endl;
382 
383 
384  // Bottom Side
385  //MVD x-y local coordinates,TVector2(0.,size.y()*2.)
386  //HYP x-z,y-z local coor. TVector2(0.,size.z()*2.)
387  if (fVerbose > 0)
388  std::cout << "Bottom Side: " << std::endl;
389  // StripCalc = PndHypCalcStrip(fbotPitch, forient + fskew, fnrBotFE * fnrFECh ,
390  // //FairGeoVector(-size.x(),-size.y(),0.),
391  // TVector2(0.,size.y()*2.),
392  // fthreshold, fnoise);
393 
395  Double_t stbot;
396  stbot = ((size.y()*2)/fDigiPar->GetBotPitch());
397 
398  Int_t rfebot = Int_t(stbot);Int_t rbfe = Int_t(rfebot/128);
399 
400  if(rfebot>=rbfe*128)fStripCalcBot->SetreStrip(rbfe*128);
401  else fStripCalcBot->SetreStrip(rfebot);
402 
403  std::cout<<" bof fe "<<Int_t(rfebot/128)<<" total strips "<<rfebot<<std::endl;
404  fStripCalcBot->SetAnchor(anchor);
405 
406  // Calculate a cluster of Strips fired
407 
408  std::vector<PndHypStrip> botStrips =
409  fStripCalcBot->GetStrips(posInL.X(), posInL.Y(), posInL.Z(),
410  posOutL.X(), posOutL.Y(), posOutL.Z(),
411  point->GetEnergyLoss(),nSiL);
412 
413  if (botStrips.size() != 0){
414  //std::cout << "Deposited charge below threshold" << std::endl;
415  // continue;
416  //}
417  // stripHits += botStrips.size();
418  if (fVerbose > 1)
419  std::cout << "SensorStrips: bot " << botStrips.size()<<std::endl;
420 
421  //trackID = point->GetTrackID(); //[R.K.03/2017] unused variable
422  detID = point->GetVolumeID();
423  //uint iStrip = 0;
424  //Int_t sp;SensorSide si; //[R.K. 01/2017] unused variable
425 
426  for(std::vector<PndHypStrip>::const_iterator it=botStrips.begin();
427  it!= botStrips.end();++it)
428  {
429  new ((*fStripArray)[iStrip]) PndHypDigiStrip(iPoint,detID,
430  point->GetDetName(),
431  fStripCalcBot->CalcFEfromStrip(it->GetIndex()) + rtfe,
432  //StripCalcBot.CalcFEfromStrip(it->GetIndex()) + fnrTopFE,
433  fStripCalcBot->CalcChannelfromStrip(it->GetIndex()),it->GetCharge());
434  // dynamic_cast<PndHypDigiStrip*>(fStripArray->operator[](iStrip))->SetMCID(trackID);
435 
436 
437  if (fVerbose > 1)
438  std::cout << *it << std::endl;
439 
440  iStrip++;
441  }
442 
443  }else if(fVerbose>2) std::cout<<"Bottom side empty"<<std::endl;
444  // TODO read Parameters from Database
445  } // Loop over MCPoints
446 
447  // Event summary
448  std::cout << "-I- PndHypStripHitProducer: " << nPoints << " HypPoints, "
449  <<" Hits created." << " " << iStrip<< std::endl;
450 
451 }
452 
453 
454 // void PndHypStripHitProducer::GetLocalHitPoints(PndHypPoint* myPoint, FairGeoVector& myHitIn, FairGeoVector& myHitOut)
455 // {
456 
457 // if (fVerbose > 1)
458 // std::cout << "GetLocalHitPoints" << std::endl;
459 // //TGeoHMatrix trans = GetTransformation(myPoint->GetDetName().Data());
460 // TGeoHMatrix trans = GetTransformation(fGeoH->GetPath(myPoint->GetDetName()).Data());
461 
462 // double posIn[3];
463 // double posOut[3];
464 // double posInLocal[3];
465 // double posOutLocal[3];
466 
467 // posIn[0] = myPoint->GetXin();
468 // posIn[1] = myPoint->GetYin();
469 // posIn[2] = myPoint->GetZin();
470 
471 // posOut[0] = myPoint->GetXout();
472 // posOut[1] = myPoint->GetYout();
473 // posOut[2] = myPoint->GetZout();
474 
475 // if (fVerbose > 1){
476 // for (int i = 0; i < 3; i++)
477 // std::cout << "posIn "<< i << ": " << posIn[i] << std::endl;
478 
479 // trans.Print("");
480 // }
481 
482 // trans.MasterToLocal(posIn, posInLocal);
483 // trans.MasterToLocal(posOut, posOutLocal);
484 
485 // if (fVerbose > 1) {
486 // for (int i = 0; i < 3; i++){
487 // std::cout << "posInLocal "<< i << ": " << posInLocal[i] << std::endl;
488 // std::cout << "posOutLocal "<< i << ": " << posOutLocal[i] << std::endl;
489 // }
490 // }
491 
492 
493 // //posIn/OutLocal have the center of the coordinate system in the center of the shape
494 // //typically sensors have their coordinate system centered at the lower left corner
495 
496 // TVector3 offset = GetSensorDimensions(fGeoH->GetPath(myPoint->GetDetName()).Data());
497 // //TVector3 offset = GetSensorDimensions(myPoint->GetDetName().Data());
498 
499 // posInLocal[0] += offset.x();
500 // posInLocal[1] += offset.y();
501 // //posInLocal[2] += offset.z();
502 
503 // posOutLocal[0] += offset.x();
504 // posOutLocal[1] += offset.y();
505 // //posOutLocal[2] += offset.z();
506 
507 
508 // myHitIn.setVector(posInLocal);
509 // myHitOut.setVector(posOutLocal);
510 
511 // }
512 
513 
514 
515 
516 // TGeoHMatrix PndHypStripHitProducer::GetTransformation(std::string detName) const
517 // {
518 // gGeoManager->cd(detName.c_str());
519 // TGeoHMatrix* transMat = gGeoManager->GetCurrentMatrix();
520 // if (fVerbose > 1)
521 // transMat->Print("");
522 // return *transMat;
523 // }
524 
525 TVector3 PndHypStripHitProducer::GetSensorDimensions(std::string detName) const
526 {
527  gGeoManager->cd(detName.c_str());
528  TGeoVolume* actVolume = gGeoManager->GetCurrentVolume();
529  TGeoBBox* actBox = (TGeoBBox*)(actVolume->GetShape());
530  TVector3 result;
531  result.SetX(actBox->GetDX());
532  result.SetY(actBox->GetDY());
533  result.SetZ(actBox->GetDZ());
534 
535  // //result.Dump();
536 
537  return result;
538 }
539 // -------------------------------------------------------------------------
540 
541 
543 
int fVerbose
Definition: poormantracks.C:24
PndHypStripDigiPar * fCurrentDigiPar
Double_t GetBotPitch() const
Int_t CalcFEfromStrip(Int_t stripNr) const
void SetTopAnchor(TVector2 x)
void SetreStrip(Int_t reStp)
void SetBotPitch(Double_t x)
Class to access the naming information of the MVD.
virtual void Print(const Option_t *opt) const
Definition: PndHypPoint.cxx:77
TVector3 GetSensorDimensions(std::string detName) const
Int_t GetVolumeID() const
Definition: PndHypPoint.h:91
Int_t CalcChannelfromStrip(Int_t stripNr) const
void SetBotAnchor(TVector2 x)
TGeoManager * gGeoManager
TVector2 botAnchor(0., 0.)
void SetNoise(Double_t x)
double skew
void SetSensType(TString x)
void PositionIn(TVector3 &pos)
Definition: PndHypPoint.h:125
TString GetPath(TString id)
for a given ID the path is returned
Bool_t fOverrideParams
internal Flag that controls use of Parameter Invocations
Double_t
void SetAnchor(TVector2 edge)
TClonesArray * point
Definition: anaLmdDigi.C:29
std::vector< PndHypStrip > GetStrips(Double_t inx, Double_t iny, Double_t inz, Double_t outx, Double_t outy, Double_t outz, Double_t eLoss, int id)
void SetTopPitch(Double_t x)
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
void SetVerboseLevel(Int_t level)
double botPitch
double threshold
void PositionOut(TVector3 &pos)
Definition: PndHypPoint.h:128
void SetNrTopFE(Int_t x)
void SetFeType(TString x)
void SetSkew(Double_t x)
TString GetDetName() const
Definition: PndHypPoint.h:119
TVector3 MasterToLocalId(const TVector3 &master, const TString &id)
ClassImp(PndAnaContFact)
void SetThreshold(Double_t x)
void SetOrient(Double_t x)
double topPitch
PndHypStripDigiPar * fDigiPar
Hit Producer Task for strip detectors.
Double_t GetTopPitch() const
virtual void Exec(Option_t *opt)
void SetNrFECh(Int_t x)
double noise
void SetNrBotFE(Int_t x)
void SetParamSet(Double_t topPitch, Double_t botPitch, Double_t ori, Double_t skew, TVector2 topAnchor, TVector2 botAnchor, Int_t nrTopFE, Int_t nrBotFE, Int_t nrFECh, Double_t threshold, Double_t noise, TString sensorType, TString feType)
TVector2 topAnchor(0., 0.)