FairRoot/PandaRoot
PndSdsStripHitProducerDif.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndSdsStripHitProducer source file -----
3 // ----- WITH CHARGE DIFFUSION -----
4 // -------------------------------------------------------------------------
5 
6 
7 #include "TClonesArray.h"
8 #include "TArrayD.h"
9 #include "TVector2.h"
10 #include "TGeoManager.h"
11 
12 #include "FairRootManager.h"
14 #include "PndSdsMCPoint.h"
15 #include "FairRun.h"
16 #include "FairRuntimeDb.h"
17 #include "FairGeoNode.h"
18 #include "FairRuntimeDb.h"
19 #include "FairGeoNode.h"
20 #include "FairGeoVector.h"
21 #include "PndStringSeparator.h"
22 #include "PndSdsCalcStripDif.h"
23 #include "PndSdsDigiStrip.h"
24 #include "PndDetectorList.h"
25 
26 // ----- Default constructor -------------------------------------------
28  PndSdsTask("SSD Strip Digi Producer(PndSdsStripHitProducerDif)")
29 {
30  fBranchName = "SSDPoint";
31 // stripHits = 0;
32 
33 /* fTopPitch = 0.;
34  fBotPitch = 0.;
35  fOrient = 0.;
36  fSkew = 0.;
37  fTopAnchor = TVector2(0,0);
38  fBotAnchor = TVector2(0,0);
39  fNrTopFE = 0;
40  fNrBotFE = 0;
41  fNrFECh = 0;
42  fThreshold = 0.;
43  fNoise = 0.;*/
44  fOverrideParams = false;
45 // fHitArray = new TClonesArray("PndSdsHit");
46 // fStripArray = new TClonesArray("PndSdsStripHit");
47  fPersistance = kTRUE;
49 }
50 // -------------------------------------------------------------------------
51 
53  Double_t ori, Double_t skew,
54  TVector2 topAnchor, TVector2 botAnchor,
55  Int_t nrTopFE, Int_t nrBotFE, Int_t nrFECh,
57  TString sensorType, TString feType) :
58  PndSdsTask("SSD Strip Digi Producer")
59 {
60  // This constructor is probably not needed anymore, since the parameters are
61  // read in via an ascii file.
62  std::cout <<" -W- Obsolete constructor for PndSdsStripHitProducer called."
63  <<"Ssd strip sensors in barrel and disk are set to the SAME."<< std::endl;
64 
65  fBranchName = "SSDPoint";
66  fOverrideParams = true;
67  SetParamSet(topPitch,botPitch,ori,skew,topAnchor,botAnchor,nrTopFE,nrBotFE,
68  nrFECh,threshold,noise,"Rect",feType);
69  SetParamSet(topPitch,botPitch,ori,skew,topAnchor,botAnchor,nrTopFE,nrBotFE,
70  nrFECh,threshold,noise,"Trap",feType);
71  std::cout << "SSD Strip Digi Producer initiated" << std::endl;
73 }
74 
76  Double_t ori, Double_t skew,
77  TVector2 topAnchor, TVector2 botAnchor,
78  Int_t nrTopFE, Int_t nrBotFE, Int_t nrFECh,
80  TString sensorType, TString feType)
81 {
82  FairRun* ana = FairRun::Instance();
83  // FairRootManager* ioman = FairRootManager::Instance();
84  if ( 0==fDigiParRect || 0==fDigiParTrap ) SetParContainers();
85  if (fOverrideParams){
86  if (sensorType.Contains("Rect")) fCurrentDigiPar = fDigiParRect;
87  else if (sensorType.Contains("Trap")) fCurrentDigiPar = fDigiParTrap;
88  fCurrentDigiPar->SetTopPitch(topPitch);
89  fCurrentDigiPar->SetBotPitch(botPitch);
90  fCurrentDigiPar->SetSkew(skew);
92  fCurrentDigiPar->SetTopAnchor(topAnchor);
93  fCurrentDigiPar->SetBotAnchor(botAnchor);
94  fCurrentDigiPar->SetNrFECh(nrFECh);
95  fCurrentDigiPar->SetNrTopFE(nrTopFE);
96  fCurrentDigiPar->SetNrBotFE(nrBotFE);
97  fCurrentDigiPar->SetThreshold(threshold);
98  fCurrentDigiPar->SetNoise(noise);
99  fCurrentDigiPar->SetSensType(sensorType);
100  fCurrentDigiPar->SetFeType(feType);
101  fCurrentDigiPar->setChanged();
102  fCurrentDigiPar->setInputVersion(ana->GetRunId(),1);
103  }
104 
105 
106 }
107 // -------------------------------------------------------------------------
108 
109 
110 // ----- Destructor ----------------------------------------------------
112 {
113 }
114 // -------------------------------------------------------------------------
115 
116 // ----- Initialization of Parameter Containers -------------------------
118 {
119  // called from the FairRun::Init()
120  // Get Base Container
121 
123  FairRun* ana = FairRun::Instance();
124  FairRuntimeDb* rtdb=ana->GetRuntimeDb();
125  fDigiParRect = (PndSdsStripDigiPar*)(rtdb->getContainer("SSDStripDigiParRect"));
126  fDigiParTrap = (PndSdsStripDigiPar*)(rtdb->getContainer("SSDStripDigiParTrap"));
127 }
128 
130 {
132  return kSUCCESS;
133 }
134 
135 
136 // ----- Public method Init --------------------------------------------
138 {
139  // FairRun* ana = FairRun::Instance();
140  FairRootManager* ioman = FairRootManager::Instance();
141 
142  SetBranchNames();
143  SetMCPointType();
144 
145  //std::cout << "-I- PndSdsStripHitProucer::Init() " << fGeoH->GetPath("1_1/212_0/") << std::endl;
146 
147  if ( ! ioman )
148  {
149  std::cout << "-E- PndSdsStripHitProducer::Init: "
150  << "RootManager not instantiated!" << std::endl;
151  return kFATAL;
152  }
153 
154  fPointArray = (TClonesArray*) ioman->GetObject(fBranchName);
155  if ( ! fPointArray )
156  {
157  std::cout << "-W- PndSdsStripHitProducer::Init: "
158  << "No SSDPoint array!" << std::endl;
159  return kERROR;
160  }
161 
162  // Create and register output array
163 // fHitArray = new TClonesArray("PndSdsHit");
164 // ioman->Register("SSDHit", "SSD", fHitArray, kTRUE);
165 
166  // Create and register output array
167  fStripArray = new TClonesArray("PndSdsDigiStrip");
168  ioman->Register("SSDStripDigis", "SSD", fStripArray, GetPersistency());
169 
170  // Create and register parameter array
171 // fStripArray = new TClonesArray("PndSdsDigiPar");
172 // ioman->Register("SSDDigiParam", "SSD", fDigiParRect, fPersistance);
173 
174  std::cout << "-I- PndSdsStripHitProducer: Initialisation successfull" << std::endl;
175 
176 
177  if (!fDigiParRect){
178  std::cout<<"-E- PndSdsStripHitProducer: DigiPar Rect Container does not exist!"<<std::endl;
179  return kERROR;
180  }
181  if (!fDigiParTrap){
182  std::cout<<"-E- PndSdsStripHitProducer: DigiPar Trap Container does not exist!"<<std::endl;
183  return kERROR;
184  }
185 
186 
187  if(fVerbose>2) fDigiParRect->Print();
188  if(fVerbose>2) fDigiParTrap->Print();
189 
198 
199  return kSUCCESS;
200 }
201 // -------------------------------------------------------------------------
202 
203 
204 
205 // ----- Public method Exec --------------------------------------------
207 {
208  // Reset output array
209  fStripArray->Clear();
210 
211  // Declare some variables
212  PndSdsMCPoint *point = NULL;
213 
214 // Int_t detID = 0; // Detector ID
215 // Int_t trackID = 0; // Track index
216 
217  // Loop over PndSdsMCPoints
218  Int_t
219  nPoints = fPointArray->GetEntriesFast();
220  if (fVerbose > 0){
221  std::cout<<" Nr of Points: "<<nPoints<<std::endl;
222  }
223 
224  Int_t iStrip = 0;
225 
226  for (Int_t iPoint = 0; iPoint < nPoints; iPoint++)
227  {
228  point = (PndSdsMCPoint*) fPointArray->At(iPoint);
229  if( kFALSE == SelectSensorParams(point->GetSensorID()) ) continue;
230 
231  if (fVerbose > 2){
232  std::cout<<"***** Strip Digi for "<<fCurrentDigiPar->GetSensType()<<" ******"<<std::endl;
233  std::cout<<" DetName : "<<fGeoH->GetPath(point->GetSensorID())<<std::endl;
234  }
235  if ( ! point){
236  std::cout<< "No Point!" << std::endl;
237  continue;
238  }
239  if (fVerbose > 2){
240  std::cout << "****Global Point: " << std::endl;
241  point->Print("");
242  }
243 
244  // transform to local sensor system... (mc point has the ID not the path to the volume)
245  TVector3 posInL = fGeoH->MasterToLocalShortId(point->GetPosition(),point->GetSensorID());
246  TVector3 posOutL = fGeoH->MasterToLocalShortId(point->GetPositionOut(),point->GetSensorID());
247 
248  if (fVerbose > 2){
249  posInL.Print();posOutL.Print();
250  std::cout << "Energy: " << point->GetEnergyLoss() << std::endl;
251  }
252 // detID = point->GetDetectorID();
253 
254  // Top Side
255  if (fVerbose > 2) std::cout << "Top Side: " << std::endl;
256  // Calculate a cluster of Strips fired
257  std::vector<PndSdsStrip> topStrips =
258  fCurrentStripCalcTop->GetStrips(posInL.X(), posInL.Y(), posInL.Z(),
259  posOutL.X(), posOutL.Y(), posOutL.Z(),
260  point->GetEnergyLoss());
261 
262  if (topStrips.size() != 0)
263  {
264  if (fVerbose > 1) std::cout << "SensorStrips: " << std::endl;
265  for(std::vector<PndSdsStrip>::const_iterator kit=topStrips.begin();
266  kit!= topStrips.end(); ++kit)
267  {
268  AddDigi(iStrip,iPoint,kMVDHitsStrip,point->GetSensorID(),
269  fCurrentStripCalcTop->CalcFEfromStrip(kit->GetIndex()),
270  fCurrentStripCalcTop->CalcChannelfromStrip(kit->GetIndex()),kit->GetCharge());
271  if (fVerbose > 1) std::cout << *kit << std::endl;
272  }
273  }else if(fVerbose>2) std::cout<<"Top side empty"<<std::endl;
274 
275  // Bottom Side
276  if (fVerbose > 2) std::cout << "Bottom Side: " << std::endl;
277  std::vector<PndSdsStrip> botStrips =
278  fCurrentStripCalcBot->GetStrips(posInL.X(), posInL.Y(), posInL.Z(),
279  posOutL.X(), posOutL.Y(), posOutL.Z(),
280  point->GetEnergyLoss());
281  if (botStrips.size() != 0)
282  {
283  if (fVerbose > 2) std::cout << " SensorStrips: " << std::endl;
284  for(std::vector<PndSdsStrip>::const_iterator kit=botStrips.begin();
285  kit!= botStrips.end();
286  ++kit)
287  {
288  AddDigi(iStrip,iPoint,kMVDHitsStrip,point->GetSensorID(),
290  fCurrentStripCalcBot->CalcChannelfromStrip(kit->GetIndex()),kit->GetCharge());
291  if (fVerbose > 2) std::cout << *kit << std::endl;
292  }
293  } else if(fVerbose>2) std::cout<<"Bottom side empty"<<std::endl;
294 
295  } // Loop over MCPoints
296 
297  // Event summary
298  if(fVerbose > 1) std::cout << "-I- PndSdsStripHitProducer: " << nPoints << " PndSdsMCPoints, "
299  << iStrip << " Digis created."<< std::endl;
300 }
301 // -------------------------------------------------------------------------
302 
303 void PndSdsStripHitProducerDif::AddDigi(Int_t &iStrip, Int_t iPoint, Int_t detID, Int_t sensorID, Int_t fe, Int_t chan, Double_t charge)
304 {
305  Bool_t found = kFALSE;
306  PndSdsDigiStrip* aDigi = 0;
307  for(Int_t kstr = 0; kstr < iStrip && found==kFALSE ; kstr++)
308  {
309  aDigi = (PndSdsDigiStrip*)fStripArray->At(kstr);
310  if ( aDigi->GetDetID() == detID &&
311  aDigi->GetSensorID() == sensorID &&
312  aDigi->GetFE() == fe &&
313  aDigi->GetChannel() == chan )
314  {
315  aDigi->AddCharge(charge);
316  aDigi->AddIndex(iPoint);
317  found = kTRUE;
318 // ((PndSdsDigiStrip*)(*fStripArray)[kstr])->AddCarge(charge);
319 // ((PndSdsDigiStrip*)(*fStripArray)[kstr])->AddIndex(iPoint);
320 // return;
321  }
322  }
323  if(found == kFALSE){//TODO: Simulate a timestamp
324  new ((*fStripArray)[iStrip]) PndSdsDigiStrip(iPoint,detID,sensorID,fe,chan,0,fMCPointType, charge) ;
325  iStrip++;
326  }
327 }
328 
329 // -------------------------------------------------------------------------
330 
331 // void PndSdsStripHitProducerDif::GetLocalHitPoints(PndSdsMCPoint* myPoint, TVector3& myHitIn, TVector3& myHitOut)
332 // {
333 //
334 // if (fVerbose > 1)
335 // std::cout << "GetLocalHitPoints" << std::endl;
336 // TGeoHMatrix trans = GetTransformation(fGeoH->GetPath(myPoint->GetDetName()).Data());
337 //
338 // Double_t posIn[3];
339 // Double_t posOut[3];
340 // Double_t posInLocal[3];
341 // Double_t posOutLocal[3];
342 //
343 // posIn[0] = myPoint->GetX();
344 // posIn[1] = myPoint->GetY();
345 // posIn[2] = myPoint->GetZ();
346 //
347 // posOut[0] = myPoint->GetXOut();
348 // posOut[1] = myPoint->GetYOut();
349 // posOut[2] = myPoint->GetZOut();
350 //
351 // if (fVerbose > 1){
352 // for (Int_t i = 0; i < 3; i++)
353 // std::cout << "posIn "<< i << ": " << posIn[i] << std::endl;
354 //
355 // trans.Print("");
356 // }
357 //
358 // trans.MasterToLocal(posIn, posInLocal);
359 // trans.MasterToLocal(posOut, posOutLocal);
360 //
361 // if (fVerbose > 1) {
362 // for (Int_t i = 0; i < 3; i++){
363 // std::cout << "posInLocal "<< i << ": " << posInLocal[i] << std::endl;
364 // std::cout << "posOutLocal "<< i << ": " << posOutLocal[i] << std::endl;
365 // }
366 // }
367 //
368 // //posIn/OutLocal have the center of the coordinate system in the center of the shape
369 // //typically sensors have their coordinate system centered at the lower left corner
370 //
371 // // TVector3 offset = GetSensorDimensions(fGeoH->GetPath(myPoint->GetDetName()).Data());
372 //
373 // // posInLocal[0] += 0.5*offset.x();
374 // // posInLocal[1] += 0.5*offset.y();
375 // // //posInLocal[2] += offset.z();
376 // //
377 // // posOutLocal[0] += 0.5*offset.x();
378 // // posOutLocal[1] += 0.5*offset.y();
379 // // //posOutLocal[2] += offset.z();
380 //
381 // myHitIn.setVector(posInLocal);
382 // myHitOut.setVector(posOutLocal);
383 //
384 // }
385 // -------------------------------------------------------------------------
386 
387 
388 
389 
390 // TGeoHMatrix PndSdsStripHitProducerDif::GetTransformation(std::string detName) const
391 // {
392 // gGeoManager->cd(detName.c_str());
393 // TGeoHMatrix* transMat = gGeoManager->GetCurrentMatrix();
394 // if (fVerbose > 1)
395 // transMat->Print("");
396 // return *transMat;
397 // }
398 // -------------------------------------------------------------------------
399 //
400 // TVector3 PndSdsStripHitProducerDif::GetSensorDimensions(std::string detName) const
401 // {
402 // gGeoManager->cd(detName.c_str());
403 // TGeoVolume* actVolume = gGeoManager->GetCurrentVolume();
404 // TGeoBBox* actBox = (TGeoBBox*)(actVolume->GetShape());
405 // TVector3 result;
406 // result.SetX(actBox->GetDX());
407 // result.SetY(actBox->GetDY());
408 // result.SetZ(actBox->GetDZ());
409 //
410 // //result.Dump();
411 //
412 // return result;
413 // }
414 // -------------------------------------------------------------------------
415 
416 
418 {
420  TString detpath = fGeoH->GetPath(sensorID);
421  if( !(detpath.Contains("Strip")) )
422  return kFALSE;
423 
424  if(detpath.Contains(fDigiParRect->GetSensType())) {
428  }else if(detpath.Contains(fDigiParTrap->GetSensType())) {
432  }else{
433  if (fVerbose > 1) std::cout<<"detector name does not contain 'Rect' or 'Trap'"<<std::endl;
434  if (fVerbose > 2) std::cout<<" DetName : "<<detpath<<std::endl;
435  return kFALSE;
436  }
437  return kTRUE;
438 }
439 
440 // -------------------------------------------------------------------------
441 
442 
444 
void SetOrient(Double_t x)
virtual void Exec(Option_t *opt)
int fVerbose
Definition: poormantracks.C:24
PndSdsCalcStripDif * fCurrentStripCalcTop
Int_t GetSensorID() const
Definition: PndSdsDigi.h:59
virtual void AddIndex(int index)
Definition: PndSdsDigi.h:66
void SetNrBotFE(Int_t x)
virtual void SetBranchNames()=0
const char * GetSensType() const
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)
void AddCharge(double charge)
Definition: PndSdsDigi.h:78
void SetBotPitch(Double_t x)
Class for calculating strip indices from wafer hits.
virtual void SetParContainers()
void SetVerboseLevel(Int_t level)
Class for digitised strip hits.
void SetTopPitch(Double_t x)
void AddDigi(Int_t &iStrip, Int_t iPoint, Int_t detID, Int_t sensorID, Int_t fe, Int_t chan, Double_t charge)
TVector3 GetPositionOut() const
Definition: PndSdsMCPoint.h:91
Int_t GetFE() const
Definition: PndSdsDigi.h:57
PndSdsCalcStripDif * fStripCalcBotRect
Int_t GetSensorID() const
Definition: PndSdsMCPoint.h:89
ClassImp(PndSdsStripHitProducerDif)
TString GetPath(Int_t shortID)
for a given shortID the path is returned
PndSdsCalcStripDif * fCurrentStripCalcBot
TVector2 botAnchor(0., 0.)
double skew
Int_t CalcChannelfromStrip(Int_t stripNr) const
void SetBotAnchor(TVector2 x)
PndSdsCalcStripDif * fStripCalcBotTrap
void SetNoise(Double_t x)
Double_t
Int_t CalcFEfromStrip(Int_t stripNr) const
virtual void SetMCPointType()=0
TClonesArray * point
Definition: anaLmdDigi.C:29
void SetTopAnchor(TVector2 x)
Digitization Parameter Class for MVD-Strip part.
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
void SetNrFECh(Int_t x)
PndSdsStripDigiPar * fDigiParRect
Digitization Parameters.
double botPitch
TClonesArray * fStripArray
Output array of PndSdsHits.
Hit Producer Task for strip detectors with electron diffusion.
static PndGeoHandling * Instance()
double threshold
TVector3 MasterToLocalShortId(const TVector3 &master, const Int_t &shortId)
void SetSensType(TString x)
std::vector< PndSdsStrip > GetStrips(Double_t inx, Double_t iny, Double_t inz, Double_t outx, Double_t outy, Double_t outz, Double_t eLoss)
TVector3 GetPosition() const
Definition: PndSdsMCPoint.h:90
Bool_t SelectSensorParams(Int_t sensorID)
void SetNrTopFE(Int_t x)
Int_t GetDetID() const
Definition: PndSdsDigi.h:61
void SetFeType(TString x)
int fe
Definition: anaLmdDigi.C:67
double topPitch
Int_t GetNrTopFE() const
PndSdsCalcStripDif * fStripCalcTopRect
Calculator objects.
Int_t GetChannel() const
void SetThreshold(Double_t x)
PndSdsCalcStripDif * fStripCalcTopTrap
double noise
virtual void Print(const Option_t *opt=0) const
TVector2 topAnchor(0., 0.)
void SetSkew(Double_t x)