FairRoot/PandaRoot
PndSdsStripHitProducer.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndSdsStripHitProducer source file -----
3 // -------------------------------------------------------------------------
4 
5 
6 // This Class
8 // SDS
9 #include "PndSdsMCPoint.h"
10 #include "PndSdsCalcStrip.h"
11 #include "PndSdsDigiStrip.h"
12 //PANDA
13 #include "PndStringSeparator.h"
14 #include "PndDetectorList.h"
15 //FAIR
16 #include "FairRootManager.h"
17 #include "FairRun.h"
18 #include "FairRuntimeDb.h"
19 #include "FairContFact.h"
20 #include "FairGeoNode.h"
21 #include "FairGeoVector.h"
22 #include "FairEventHeader.h"
23 //ROOT
24 #include "TClonesArray.h"
25 #include "TArrayD.h"
26 #include "TVector2.h"
27 #include "TString.h"
28 #include "TObjString.h"
29 #include "TGeoManager.h"
30 #include "TList.h"
31 #include "TRandom.h"
32 
33 // ----- Default constructor -------------------------------------------
35 PndSdsTask("SDS Strip Digi Producer(PndSdsStripHitProducer)"),
36  fPointArray(NULL),
37  fStripArray(NULL),
38  fDataBuffer(0),
39  fDigiParameterList(NULL),
40  fChargeDigiParameterList(NULL),
41  fCurrentDigiPar(NULL),
42  fCurrentChargeConverter(NULL),
43  fStripCalcTop(),
44  fStripCalcBot(),
45  fChargeConverter(),
46  fCurrentStripCalcTop(NULL),
47  fCurrentStripCalcBot(NULL),
48  fMcEventHeader(NULL),
49  fGeoH(NULL),
50  fOverrideParams(kFALSE),
51  fTimeOrderedDigi(kFALSE),
52  fEventNr(0)
53 {
54  fDigiParameterList = new TList();
55  fChargeDigiParameterList = new TList();
56  SetPersistency(kTRUE);
57 }
58 // -------------------------------------------------------------------------
59 
60 // ----- Default constructor -------------------------------------------
62 PndSdsTask(name),
63  fPointArray(NULL),
64  fStripArray(NULL),
65  fDataBuffer(0),
66  fDigiParameterList(NULL),
67  fChargeDigiParameterList(NULL),
68  fCurrentDigiPar(NULL),
69  fCurrentChargeConverter(NULL),
70  fStripCalcTop(),
71  fStripCalcBot(),
72  fChargeConverter(),
73  fCurrentStripCalcTop(NULL),
74  fCurrentStripCalcBot(NULL),
75  fMcEventHeader(NULL),
76  fGeoH(NULL),
77  fOverrideParams(kFALSE),
78  fTimeOrderedDigi(kFALSE),
79  fEventNr(0)
80 {
81  fDigiParameterList = new TList();
82  fChargeDigiParameterList = new TList();
83  SetPersistency(kTRUE);
84 }
85 // -------------------------------------------------------------------------
86 
87 // ----- Destructor ----------------------------------------------------
89 {
92  if (0!=fDataBuffer) delete fDataBuffer;
93  // TODO: needs check: now cleared correctly?
94  for( std::map<const char*,PndSdsCalcStrip*>::iterator it = fStripCalcTop.begin(); it != fStripCalcTop.end(); it++){
95  if(0 != it->second) delete it->second;
96  it->second = 0;
97  }
98  for( std::map<const char*,PndSdsCalcStrip*>::iterator it = fStripCalcBot.begin(); it != fStripCalcBot.end(); it++){
99  if(0 != it->second) delete it->second;
100  it->second = 0;
101  }
102  for(std::map<const char*,PndSdsChargeConversion*>::iterator it = fChargeConverter.begin(); it != fChargeConverter.end(); it++){
103  if(0 != it->second) delete it->second;
104  it->second = 0;
105  }
106 }
107 // -------------------------------------------------------------------------
108 
109 
110 // -------------------------------------------------------------------------
112 {
114  SetCalculators();
115  return kSUCCESS;
116 }
117 // -------------------------------------------------------------------------
118 
119 // -------------------------------------------------------------------------
121 {
122  // After the first start if the Init() tis can be set properly.
123 
124  TIter params(fDigiParameterList);
125  while(PndSdsStripDigiPar* digipar=(PndSdsStripDigiPar*)params()){
126  if(0==digipar) {
127  Error("SetCalculators()","A Digi Parameter Set does not exist properly.");
128  continue;
129  }
130  const char* senstype = digipar->GetSensType();
131  if(fVerbose>1){
132  Info("SetCalculators()","Create a Parameter Set for %s sensors",senstype);
133  std::cout<<senstype<<"#"<<std::endl;
134  }
135  if(fVerbose>2)digipar->Print();
136  //TODO switch also with PndSdsCalcStripDif
137  fStripCalcTop[senstype]=new PndSdsCalcStrip(digipar,kTOP);
138  fStripCalcTop[senstype]->SetVerboseLevel(fVerbose);
139  fStripCalcBot[senstype]=new PndSdsCalcStrip(digipar,kBOTTOM);
140  fStripCalcBot[senstype]->SetVerboseLevel(fVerbose);
141  }
142 }
143 
144 // -------------------------------------------------------------------------
145 
147 {
148  if ( fGeoH == NULL )
150 
152  if(fVerbose>1) Info("SetParContainers","done.");
153  return;
154 }
155 
156 
157 // ----- Public method Init --------------------------------------------
159 {
160  FairRootManager* ioman = FairRootManager::Instance();
161 
162  SetBranchNames();
163 
164 
165  if ( ! ioman )
166  {
167  std::cout << "-E- PndSdsStripHitProducer::Init: "
168  << "RootManager not instantiated!" << std::endl;
169  return kFATAL;
170  }
171 
172  fPointArray = (TClonesArray*) ioman->GetObject(fInBranchName);
173  if ( ! fPointArray )
174  {
175  std::cout << "-E- PndSdsStripHitProducer::Init: "
176  << "No "<<fInBranchName<<" array!" << std::endl;
177  return kERROR;
178  }
179 
180 
182  fDataBuffer = (PndSdsDigiStripWriteoutBuffer*)ioman->RegisterWriteoutBuffer(fOutBranchName, fDataBuffer);
183 
184  fDataBuffer->ActivateBuffering(fTimeOrderedDigi);
185 
186  SetCalculators();
187 
188  if(fVerbose>0){
189  std::cout << "-I- PndSdsStripHitProducer: Initialisation successfull with these parameters:" << std::endl;
190  TIter params(fDigiParameterList);
191  while(PndSdsStripDigiPar* digipar=(PndSdsStripDigiPar*)params()){
192  if(0!=digipar) {
193  digipar->Print();
194  }
195  }
196  }
197 
198  return kSUCCESS;
199 }
200 // -------------------------------------------------------------------------
201 
202 
203 
204 // ----- Public method Exec --------------------------------------------
206 {
207  // Reset output array
209 
210  // std::cout << "EventTime: " << FairRootManager::Instance()->GetEventTime() << std::endl;
211 
212  for (std::map<const char*,PndSdsChargeConversion*>::iterator it = fChargeConverter.begin(); it != fChargeConverter.end(); it++){
213  it->second->StartExecute();
214  }
215 
216  // Declare some variables
217  PndSdsMCPoint *point = NULL;
218 
219  // Int_t detID = 0; // Detector ID
220  // Int_t trackID = 0; // Track index
221 
222  fStripArray = FairRootManager::Instance()->GetTClonesArray(fOutBranchName);
223 
224  // Loop over PndSdsMCPoints
225  Int_t nPoints = fPointArray->GetEntriesFast();
226  if (fVerbose > 0){
227  std::cout<<" Nr of Points: "<<nPoints<<std::endl;
228  }
229 
230  Int_t iStrip = 0;
231  Bool_t selected = kFALSE;
232 
233  for (Int_t iPoint = 0; iPoint < nPoints; iPoint++)
234  {
235  point = (PndSdsMCPoint*) fPointArray->At(iPoint);
236  // std::cout << "Point " << iPoint << ": " << *point << std::endl;
237  selected = SelectSensorParams(point->GetSensorID());
238  if( !selected ) { continue; }
239 
240  if (fVerbose > 2){
241  std::cout<<"***** Strip Digi for "<<fCurrentDigiPar->GetSensType()<<" ******"<<std::endl;
242  std::cout<<" DetName : "<<fGeoH->GetPath(point->GetSensorID())<<std::endl;
243  }
244  if ( ! point){
245  std::cout<< "No Point!" << std::endl;
246  continue;
247  }
248  if (fVerbose > 2){
249  std::cout << "****Global Point: " << std::endl;
250  point->Print("");
251  }
252 
253  // transform to local sensor system... (mc point has the ID not the path to the volume)
254  TVector3 posInL = fGeoH->MasterToLocalShortId(point->GetPosition(),point->GetSensorID());
255  TVector3 posOutL = fGeoH->MasterToLocalShortId(point->GetPositionOut(),point->GetSensorID());
256  if (fVerbose > 2){
257  posInL.Print();posOutL.Print();
258  std::cout << "Energy: " << point->GetEnergyLoss() << std::endl;
259  }
260  // detID = point->GetDetectorID();
261 
262  // Top Side
263  if (fVerbose > 2) std::cout << "Top Side: " << std::endl;
264  // Calculate a cluster of Strips fired
265  std::vector<PndSdsStrip> topStrips =
266  fCurrentStripCalcTop->GetStrips(posInL.X(), posInL.Y(), posInL.Z(),
267  posOutL.X(), posOutL.Y(), posOutL.Z(),
268  point->GetEnergyLoss());
269 
270  if (topStrips.size() != 0)
271  {
272  if (fVerbose > 1) std::cout << "SensorStrips: " << std::endl;
273  for(std::vector<PndSdsStrip>::const_iterator kit=topStrips.begin();
274  kit!= topStrips.end(); ++kit)
275  {
276 
277  AddDigi(iStrip,iPoint,FairRootManager::Instance()->GetBranchId(fInBranchName),point->GetSensorID(),
278  fCurrentStripCalcTop->CalcFEfromStrip(kit->GetIndex()),
279  fCurrentStripCalcTop->CalcChannelfromStrip(kit->GetIndex()),kit->GetCharge());
280 
281  if (fVerbose > 1) std::cout << *kit << std::endl;
282 
283  }
284  }else if(fVerbose>2) std::cout<<"Top side empty"<<std::endl;
285 
286  // Bottom Side
287  if (fVerbose > 2) std::cout << "Bottom Side: " << std::endl;
288  std::vector<PndSdsStrip> botStrips =
289  fCurrentStripCalcBot->GetStrips(posInL.X(), posInL.Y(), posInL.Z(),
290  posOutL.X(), posOutL.Y(), posOutL.Z(),
291  point->GetEnergyLoss());
292  if (botStrips.size() != 0)
293  {
294  if (fVerbose > 2) std::cout << " SensorStrips: " << std::endl;
295  for(std::vector<PndSdsStrip>::const_iterator kit=botStrips.begin();
296  kit!= botStrips.end();
297  ++kit)
298  {
299 
300  AddDigi(iStrip, iPoint, FairRootManager::Instance()->GetBranchId(fInBranchName),
302  fCurrentStripCalcBot->CalcChannelfromStrip(kit->GetIndex()), kit->GetCharge());
303 
304 
305  // }
306  if (fVerbose > 2) std::cout << *kit << std::endl;
307  }
308  } else if(fVerbose>2) std::cout<<"Bottom side empty"<<std::endl;
309 
310  } // Loop over MCPoints
311 
312 
313  for (std::map<const char*,PndSdsChargeConversion*>::iterator it = fChargeConverter.begin(); it != fChargeConverter.end(); it++){
314  it->second->EndExecute();
315  }
316 
317  // Event summary
318  if(fVerbose > 1) std::cout << "-I- PndSdsStripHitProducer: EventNr " << fEventNr << " from " << nPoints << " PndSdsMCPoints, "
319  << iStrip << " Digis created."<< std::endl;
320 
321  fEventNr++;
322 }
323 // -------------------------------------------------------------------------
324 
325 void PndSdsStripHitProducer::AddDigi(Int_t &iStrip, Int_t iPoint, Int_t , Int_t sensorID, Int_t fe, Int_t chan, Double_t charge) //detID //[R.K.03/2017] unused variable(s)
326 {
327 
328  PndSdsMCPoint *point = (PndSdsMCPoint*)fPointArray->At(iPoint);
330  Int_t smearedCharge = (Int_t)fCurrentChargeConverter->ChargeToDigiValue(charge);
331  Int_t timeStamp = DigitizeTime(point->GetTime(), charge);
332 
333  Double_t smearedChargeInE = fCurrentChargeConverter->DigiValueToCharge(smearedCharge);
334  Double_t timewalk = fCurrentChargeConverter->GetTimeWalk(smearedChargeInE);
335 
336  Double_t correctedTimeStamp = timeStamp - timewalk - fCurrentChargeConverter->GetTimeStep()/2;
337 
338 // std::cout << " charge: " << charge << " smeared DigiCharge: " << smearedCharge << " smeared charge in e " << smearedChargeInE << std::endl;
339 // std::cout << "MCTime: " << point->GetTime() << " TimeStamp: " << timeStamp << " timewalk " << timewalk << " corrected TimeStamp: " << correctedTimeStamp << " charge: " << charge << " smearedCharge in e: " << smearedChargeInE << std::endl;
340 
341  std::vector<Int_t>indices;
342  indices.push_back(iPoint);
343 
344  PndSdsDigiStrip* tempStrip = new PndSdsDigiStrip(indices, FairRootManager::Instance()->GetBranchId(fInBranchName),
345  sensorID, fe, chan, smearedCharge, correctedTimeStamp);
346 
347  if (fTimeOrderedDigi){
348  tempStrip->ResetLinks();
349  FairEventHeader* evtHeader = (FairEventHeader*)FairRootManager::Instance()->GetObject("EventHeader.");
350  // for (int i = 0; i < indices.size(); i++)
351  tempStrip->AddLink(FairLink(evtHeader->GetInputFileId(), evtHeader->GetMCEntryNumber(), fInBranchId, iPoint));
352  tempStrip->AddLink(FairLink(-1, fEventNr, "EventHeader.", -1));
353  tempStrip->AddLinks(*(point->GetPointerToLinks()));
354  }
355  fDataBuffer->FillNewData(tempStrip, timeStamp + 100, point->GetTime() + FairRootManager::Instance()->GetEventTime());
356  delete(tempStrip);
357 
358 // std::cout << "AddDigi called: " << *tempStrip << std::endl;
359 
360 
361 // // we're here when this channel didn't fire
362 // std::vector<Int_t>indices;
363 // indices.push_back(iPoint);
364 //
365 // PndSdsDigiStrip* tempStrip = new ((*fStripArray)[iStrip]) PndSdsDigiStrip(indices,detID,sensorID,fe,chan,charge, FairRootManager::Instance()->GetEventTime());
366 // tempStrip->SetEntryNr(FairLink(FairRootManager::Instance()->GetBranchId(fOutBranchName), iStrip));
367 //
368  iStrip++;
369  return;
370 }
371 // -------------------------------------------------------------------------
372 
373 
375 {
376  fCurrentDigiPar = NULL;
377  fCurrentStripCalcTop = NULL;
378  fCurrentStripCalcBot = NULL;
380 
381  TString detpath = fGeoH->GetPath(sensorID);
382  // std::cout << "Detector: " << detpath.Data() << std::endl;
383  if( !(detpath.Contains("Strip")) )
384  { // filter from pixel points
385  return kFALSE;
386  }
387 
388  TIter parsetiter(fDigiParameterList);
389  while ( PndSdsStripDigiPar* digipar = (PndSdsStripDigiPar*)parsetiter() )
390  {
391  const char* sensortype = digipar->GetSensType();
392  if(detpath.Contains(sensortype)) {
393  fCurrentStripCalcTop = fStripCalcTop[sensortype];
394  fCurrentStripCalcBot = fStripCalcBot[sensortype];
396  fCurrentDigiPar = digipar;
397  return kTRUE;
398  }
399  }
400  // no suiting object found
401 
402  if(fVerbose>1) Info("SelectSensorParams()","No valid sensor parameters selected, skipping this point.");
403  std::cout<<"detector name does not contain a valid parameter name."<<std::endl;
404  std::cout<<" DetName : "<<detpath<<std::endl;
405  return kFALSE;
406 }
407 
409 { // time [ns]
410  Double_t eventTime = FairRootManager::Instance()->GetEventTime();
411  return fCurrentChargeConverter->GetTimeStamp(time,charge,eventTime);
412 }
413 
414 //______________________________________________________________________________
415 // -------------------------------------------------------------------------
416 
418 {
419  // called after all Tasks did their Exex() and the data is copied to the file
420  // fStripArray->Delete();
421  FinishEvents();
422 }
423 // -------------------------------------------------------------------------
424 
426 {
427 }
428 
430 
TList * fDigiParameterList
Digitization Parameters.
int fVerbose
Definition: poormantracks.C:24
Int_t fInBranchId
Definition: PndSdsTask.h:43
TString fOutBranchName
Definition: PndSdsTask.h:40
PndGeoHandling * fGeoH
Definition: anasim.C:34
virtual Double_t GetTimeStep()
Int_t CalcFEfromStrip(Int_t stripNr) const
const char * GetSensType() const
virtual void SetParContainers()
Class for digitised strip hits.
Bool_t fTimeOrderedDigi
parameter to switch to time ordered simulation
Int_t DigitizeTime(Double_t time, Double_t charge)
FairWriteoutBuffer * fDataBuffer
void SetPersistency(Bool_t val=kTRUE)
TVector3 GetPositionOut() const
Definition: PndSdsMCPoint.h:91
Class for calculating strip indices from wafer hits.
virtual Double_t GetTimeStamp(Double_t tof, Double_t charge, Double_t MCEventTime)=0
absolute time stamp of a hit in ns (clock is taken into account)
Int_t GetSensorID() const
Definition: PndSdsMCPoint.h:89
Int_t fEventNr
EventCounter.
TString GetPath(Int_t shortID)
for a given shortID the path is returned
virtual Double_t DigiValueToCharge(Double_t digi)=0
Converts a given digitized charge into charge in electrons.
std::map< const char *, PndSdsCalcStrip * > fStripCalcBot
std::map< const char *, PndSdsChargeConversion * > fChargeConverter
PndSdsStripDigiPar * fCurrentDigiPar
Double_t
TString fInBranchName
Definition: PndSdsTask.h:39
std::map< const char *, PndSdsCalcStrip * > fStripCalcTop
Calculator objects.
Digitization Parameter Class for MVD-Strip part.
void AddDigi(Int_t &iStrip, Int_t iPoint, Int_t detID, Int_t sensorID, Int_t fe, Int_t chan, Double_t charge)
PndSdsChargeConversion * fCurrentChargeConverter
TClonesArray * fStripArray
Output array of PndSdsHits.
TString fFolderName
Definition: PndSdsTask.h:41
static PndGeoHandling * Instance()
TString name
TVector3 MasterToLocalShortId(const TVector3 &master, const Int_t &shortId)
TVector3 GetPosition() const
Definition: PndSdsMCPoint.h:90
void SetVerbose(Int_t v)
virtual void Exec(Option_t *opt)
Int_t CalcChannelfromStrip(Int_t stripNr) const
virtual Double_t ChargeToDigiValue(Double_t Charge)=0
Converts a given charge in electrons into the electronics answer e.g. ToT [ns].
Hit Producer Task for strip detectors.
int fe
Definition: anaLmdDigi.C:67
Bool_t SelectSensorParams(Int_t sensorID)
PndSdsCalcStrip * fCurrentStripCalcBot
ClassImp(PndAnaContFact)
Int_t GetNrTopFE() const
virtual Double_t GetTimeWalk(Double_t)
virtual void SetBranchNames()=0
PndSdsCalcStrip * fCurrentStripCalcTop
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)
virtual void Print(const Option_t *opt=0) const
PndSdsMCPoint * point
Definition: anaLmdCluster.C:72