FairRoot/PandaRoot
PndDrcDigiTask.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndDrcDigiTask source file -----
3 // ----- Created 15/04/13 by M.Patsyuk -----
4 // ----- HARPHOOL KUMAWAT h.kumawat@gsi.de -----
5 // ----- -----
6 // -------------------------------------------------------------------------
7 #include <fstream>
8 #include <iostream>
9 #include <map>
10 #include "stdio.h"
11 
12 #include "TGeoManager.h"
13 
14 #include "FairRootManager.h"
15 #include "PndDrcDigiTask.h"
16 
17 #include "FairRunAna.h"
18 #include "FairRuntimeDb.h"
19 #include "FairGeoVector.h"
20 #include "FairGeoNode.h"
21 #include "FairGeoVolume.h"
22 
23 #include "TVector3.h"
24 #include "TRandom.h"
25 #include "TString.h"
26 #include "TGeoBBox.h"
27 
28 #include "FairBaseParSet.h"
29 #include "FairGeoTransform.h"
30 
31 #include "PndGeoDrcPar.h"
32 
33 using std::endl;
34 using std::cout;
35 
36 // ----- Default constructor -------------------------------------------
38  fGeo = new PndGeoDrc();
39  fGeoH = NULL;
40  fPDPointArray = NULL;
41 
42  SetParameters();
43  Reset();
44 }
45 
46 // ----- Standard constructor with verbosity level -------------------------------------------
47 PndDrcDigiTask::PndDrcDigiTask(Int_t verbose) :PndPersistencyTask("PndDrcDigiTask",verbose){
48  fVerbose = verbose;
49  fGeo = new PndGeoDrc();
50  fGeoH = NULL;
51  fPDPointArray = NULL;
52 
53  SetParameters();
54  Reset();
55 }
56 
58  fTimeOrderedDigi = kFALSE;
59  fChargeSharing = kFALSE;
60  fDeadTime = 5;
61 
62  fDetType=1; // Detector Type =1
63  fSigmat=0.1; // Time Resolution is 100 ps ############################
64  fTimeGranularity = 0.001;// [ns] = 98 ps granularity of the time signal
67  fNpix = fGeo->Npixels();
69  fPixelStep = fMcpActiveArea/fNpix; //fPixelSize + 0.5*fPixelGap;
71  fThreshold = 0.20; //threshold to detect charge shared hits
72 }
73 
74 // ----- Destructor ----------------------------------------------------
76  Reset();
77  if (fGeo) delete fGeo;
78 }
79 
80 // ----- Initialization -----------------------------------------------
81 InitStatus PndDrcDigiTask::Init(){
82  cout << " ---------- INITIALIZATION ------------" << endl;
83  nevents = 0;
84 
85  // Get RootManager
86  FairRootManager* ioman = FairRootManager::Instance();
87  if ( ! ioman ) {
88  cout << "-E- PndDrcDigiTask::Init: "
89  << "RootManager not instantiated!" << endl;
90  return kFATAL;
91  }
92 
93  // PndGeoHandling
94  if ( fGeoH == NULL )
96 
99  if(fVerbose>1) Info("SetParContainers","done.");
100 
101  // // Get input array
102  // fMCArray = (TClonesArray*) ioman->GetObject("MCTrack");
103  // if ( ! fMCArray ) {
104  // cout << "-W- PndDrcRecoLookupMap::Init: "
105  // << "No MCTrack array!" << endl;
106  // return kERROR;
107  // }
108 
109  // Get input array
110  fBarPointArray = (TClonesArray*) ioman->GetObject("DrcBarPoint");
111  if ( ! fBarPointArray ) {
112  cout << "-W- PndDrcDigiTask::Init: "
113  << "No DrcBarPoint array!" << endl;
114  return kERROR;
115  }
116 
117  // Get Photon point array
118  fPDPointArray = (TClonesArray*) ioman->GetObject("DrcPDPoint");
119  if ( ! fPDPointArray ) {
120  cout << "-W- PndDrcAna::Init: "
121  << "No DrcPDPoint array!" << endl;
122  return kERROR;
123  }
124 
125  // Create and register output buffer
126  fDataBuffer = new PndDrcDigiWriteoutBuffer("DrcDigi","PndDrc", GetPersistency());
127  fDataBuffer = (PndDrcDigiWriteoutBuffer*)ioman->RegisterWriteoutBuffer("DrcDigi", fDataBuffer);
128  fDataBuffer->SetVerbose(fVerbose);
129  fDataBuffer->ActivateBuffering(fTimeOrderedDigi);
130 
131  cout << "-I- PndDrcDigiTask: Intialization successfull" << endl;
132 
133  return kSUCCESS;
134 }
135 
136 // ----- Execution of Task ---------------------------------------------
137 void PndDrcDigiTask::Exec(Option_t*){ // ion //[R.K.03/2017] unused variable(s)
138  Reset();
139  if (fVerbose > 0) cout << "-I- PndDrcDigiTask: Event # " << nevents
140  << " has " << fPDPointArray->GetEntriesFast()
141  << " PD points" << endl;
143  nevents++;
144 }
145 
146 //-------- Photon Detector Hit production with efficiency-------------
148  for(Int_t k=0; k < fPDPointArray->GetEntriesFast(); k++) {
149 
150  fPpt = (PndDrcPDPoint*)fPDPointArray->At(k);
151  // fMCtrk = (PndMCTrack*)fMCArray->At(fPpt->GetTrackID());
152  Int_t bpId=fPpt->GetBarPointID();
153  if(bpId<0){
154  std::cout<<" Error: bpId = "<<bpId <<std::endl;
155 
156  continue;
157  }
158 
160 
161  // transform to local sensor system
162  TVector3 PptPosition;
163  fPpt->Position(PptPosition);
164  TVector3 posL = fGeoH->MasterToLocalShortId(PptPosition,fPpt->GetDetectorID());
165  TVector3 sensorDim = GetSensorDimensions(fPpt->GetDetectorID());
166 
167  //usually sensors have origin in the middle, let's move it to the left lower corner:
168  TVector3 posLshifted = posL + sensorDim;
169 
170  // calculate the number of the fired pixel
171  Int_t Ncol = (Int_t)TMath::Floor(posLshifted.X()/fPixelStep);
172  Int_t Nrow = (Int_t)TMath::Floor(posLshifted.Y()/fPixelStep);
173  Int_t NpixelLocal = Ncol + Nrow * fNpix;
174 
175  fDetectorID = fPpt->GetDetectorID() * 100 + NpixelLocal;
176  Int_t mcpId = fPpt->GetMcpId();
177  Int_t sensorId = mcpId * 100 + NpixelLocal;
178 
179  // time is smeared and digitized = has granularity
180  fTime=(Int_t)(fPpt->GetTime()/fTimeGranularity)*fTimeGranularity;
181  fTime=fPpt->GetTime();
182  if(fSigmat>0) Smear(fTime,fSigmat);
183 
184  ActivatePixel(sensorId, k, 0);
185 
186  if(fChargeSharing){
187  Double_t distance = 999.;
188  TVector3 corner, point;
189 
190  // left pixel
191  distance = posLshifted.X() - TMath::Floor(posLshifted.X()/fPixelStep)*fPixelStep;
192  if(exp(- distance/fPixelSigma) > gRandom->Uniform(0.,1.) && exp(- distance/fPixelSigma) > fThreshold){
193  if((Ncol-1) >= 0){
194  ActivatePixel(mcpId * 100 +Ncol-1+Nrow*fNpix,k, 1);
195  }
196  }
197  // right pixel
198  distance = TMath::Ceil(posLshifted.X()/fPixelStep)*fPixelStep - posLshifted.X();
199  if(exp(- distance/fPixelSigma) > gRandom->Uniform(0.,1.) && exp(- distance/fPixelSigma) > fThreshold){
200  if(Ncol+1 < fNpix){
201  ActivatePixel(mcpId * 100 +Ncol+1+Nrow*fNpix, k, 1);
202  }
203  }
204  // lower pixel
205  distance = posLshifted.Y() - TMath::Floor(posLshifted.Y()/fPixelStep)*fPixelStep;
206  if(exp(- distance/fPixelSigma) > gRandom->Uniform(0.,1.) && exp(- distance/fPixelSigma) > fThreshold){
207  if(Nrow-1 >= 0){
208  ActivatePixel(mcpId * 100 +Ncol+(Nrow-1)*fNpix, k, 1);
209  }
210  }
211  // upper pixel
212  distance = TMath::Ceil(posLshifted.Y()/fPixelStep)*fPixelStep - posLshifted.Y();
213  if(exp(- distance/fPixelSigma) > gRandom->Uniform(0.,1.) && exp(- distance/fPixelSigma) > fThreshold){
214  if(Nrow+1 < fNpix){
215  ActivatePixel(mcpId * 100 +Ncol+(Nrow+1)*fNpix, k, 1);
216  }
217  }
218 
219  point.SetXYZ(posLshifted.X(),posLshifted.Y(),0.);
220 
221  // upper left pixel
222  corner.SetXYZ(TMath::Floor(posLshifted.X()/fPixelStep)*fPixelStep,
223  TMath::Ceil(posLshifted.Y()/fPixelStep)*fPixelStep,0.);
224  distance = (point-corner).Mag();
225  if(exp(-distance/fPixelSigma) > gRandom->Uniform(0.,1.) && exp(- distance/fPixelSigma) > fThreshold){
226  if(Ncol-1 >= 0 && Nrow+1 < fNpix){
227  ActivatePixel(mcpId * 100 +Ncol-1+(Nrow+1)*fNpix, k, 1);
228 
229  }
230  }
231 
232  // bottom left pixel
233  corner.SetXYZ(TMath::Floor(posLshifted.X()/fPixelStep)*fPixelStep,
234  TMath::Floor(posLshifted.Y()/fPixelStep)*fPixelStep,0.);
235  distance = (point-corner).Mag();
236  if(exp(-distance/fPixelSigma) > gRandom->Uniform(0.,1.) && exp(- distance/fPixelSigma) > fThreshold){
237  if(Ncol-1 >= 0 && Nrow-1 >= 0){
238  ActivatePixel(mcpId * 100 +Ncol-1+(Nrow-1)*fNpix, k, 1);
239  }
240  }
241 
242  // bottom right pixel
243  corner.SetXYZ(TMath::Ceil(posLshifted.X()/fPixelStep)*fPixelStep,
244  TMath::Floor(posLshifted.Y()/fPixelStep)*fPixelStep,0.);
245  distance = (point-corner).Mag();
246  if(exp(-distance/fPixelSigma) > gRandom->Uniform(0.,1.) && exp(- distance/fPixelSigma) > fThreshold){
247  if(Ncol+1 < fNpix && Nrow-1 >= 0){
248  ActivatePixel(mcpId * 100 +Ncol+1+(Nrow-1)*fNpix, k, 1);
249  }
250  }
251 
252  // upper right pixel
253  corner.SetXYZ(TMath::Ceil(posLshifted.X()/fPixelStep)*fPixelStep,
254  TMath::Ceil(posLshifted.Y()/fPixelStep)*fPixelStep,0.);
255  distance = (point-corner).Mag();
256  if(exp(-distance/fPixelSigma) > gRandom->Uniform(0.,1.) && exp(- distance/fPixelSigma) > fThreshold){
257  if(Ncol+1 < fNpix && Nrow+1 < fNpix){
258  ActivatePixel(mcpId * 100 +Ncol+1+(Nrow+1)*fNpix, k, 1);
259  }
260  }
261  }
262  }
263 }
264 
265 // ----- Private method ActivatePixel -------------------------------
266 void PndDrcDigiTask::ActivatePixel(Int_t sensorId, Int_t k, Int_t csflag) {
267  // in case when the same pixel was fired by two different photons this function takes care of which hits from that pixel to write
268  PndDrcDigi* digi = new PndDrcDigi(k, fDetectorID, sensorId, 0., fTime, csflag, 0.);
269  Double_t timeStamp = fTime + FairRootManager::Instance()->GetEventTime();
270 
271  digi->SetPdgCode(fBarPoint->GetPdgCode());
272  digi->SetTimeStamp(timeStamp);
273  digi->SetTimeAtBar(fBarPoint->GetTime());
274  if(fSigmat>0) digi->SetTimeStampError(fSigmat/TMath::Sqrt(fSigmat));
275  else digi->SetTimeStampError(0);
276 
277  FairEventHeader* evtHeader = (FairEventHeader*)FairRootManager::Instance()->GetObject("EventHeader.");
278 
279  digi->SetLink(fPpt->GetLink(0)); // MCTrack
280  digi->AddLink(FairLink(evtHeader->GetInputFileId(), evtHeader->GetMCEntryNumber(), "DrcPDPoint", k));
281 
282  fDataBuffer->FillNewData(digi, timeStamp, timeStamp + fDeadTime);
283 
284  // if ( fPixelMap.find(sensorId) == fPixelMap.end() ){
285  // // pixel not yet active, create new digi
286  // fDataBuffer->FillNewData(digi, fTime, fTime + fDeadTime);
287  // fPixelMap[sensorId] = fNDigis;
288  // fNDigis++;
289  // }else{
290  // // // if there was already hit in this pixel...
291  // // PndDrcDigi* ddigi = dynamic_cast<PndDrcDigi*>(fDrcDigiArray->At(fPixelMap[sensorId]));
292 
293  // // // ... check the time difference with another one in the same pixel
294  // // if(fabs(ddigi->GetTimeStamp() - fTime) > fDeadTime){
295  // fDataBuffer->FillNewData(digi, fTime, fTime + fDeadTime);
296  // fPixelMap[sensorId] = fNDigis;
297  // fNDigis++;
298  // // }
299  // }
300 }
301 
302 //--------------------------------------------------------------
303 TVector3 PndDrcDigiTask::GetSensorDimensions(Int_t sensorID){
304  gGeoManager->cd(fGeoH->GetPath(sensorID));
305  TGeoVolume* actVolume = gGeoManager->GetCurrentVolume();
306  TGeoBBox* actBox = (TGeoBBox*)(actVolume->GetShape());
307  TVector3 result(actBox->GetDX(),actBox->GetDY(),actBox->GetDZ());
308  return result;
309 }
310 
311 //-------------Smear Time---------------------------------------
313  time += gRandom->Gaus(0,sigt);
314 }
315 
316 // ----- Private method Reset ------------------------------
318  fNDigis = 0;
319  fPixelMap.clear();
320 }
321 
322 // ----- Finish Task ---------------------------------------
324  cout << "-I- PndDrcDigiTask: Finish" << endl;
325 }
326 
Double_t SigmaCharge()
Definition: PndGeoDrc.h:178
Int_t GetPdgCode() const
TClonesArray * digi
Double_t fPixelGap
friend F32vec4 exp(const F32vec4 &a)
Definition: P4_F32vec4.h:109
void SetTimeAtBar(Double_t TimeAtBar)
Definition: PndDrcDigi.cxx:46
void ActivatePixel(Int_t sensorId, Int_t k, Int_t csflag)
PndDrcBarPoint * fBarPoint
virtual InitStatus Init()
Int_t GetMcpId() const
Definition: PndDrcPDPoint.h:57
virtual void Finish()
static T Sqrt(const T &x)
Definition: PndCAMath.h:37
Int_t GetDetectorID() const
Definition: PndDrcPDPoint.h:55
TClonesArray * fPDPointArray
#define verbose
Double_t fTimeGranularity
virtual void SetParContainers()
Double_t fPixelSigma
TGeoManager * gGeoManager
TString GetPath(Int_t shortID)
for a given shortID the path is returned
Double_t fMcpActiveArea
Bool_t fTimeOrderedDigi
Double_t fThreshold
std::map< Int_t, Int_t > fPixelMap
Int_t GetBarPointID() const
Definition: PndDrcPDPoint.h:56
TVector3 corner
Double_t
Double_t McpActiveArea()
Definition: PndGeoDrc.h:166
TClonesArray * point
Definition: anaLmdDigi.C:29
TClonesArray * fBarPointArray
PndGeoHandling * fGeoH
static PndGeoHandling * Instance()
TVector3 MasterToLocalShortId(const TVector3 &master, const Int_t &shortId)
void SetVerbose(Int_t v)
Double_t fPixelStep
TVector3 GetSensorDimensions(Int_t sensorID)
ClassImp(PndAnaContFact)
PndDrcPDPoint * fPpt
virtual void Exec(Option_t *option)
Int_t Npixels()
Definition: PndGeoDrc.h:172
void SetPdgCode(Int_t Pdg)
Definition: PndDrcDigi.cxx:37
void Smear(Double_t &time, Double_t sigt)
PndGeoDrc * fGeo
Double_t fPixelSize
PndDrcDigiWriteoutBuffer * fDataBuffer
void ProcessPhotonPoint()
///< converter for detector names
Double_t PixelSize()
Definition: PndGeoDrc.h:175
Double_t fDeadTime
virtual ~PndDrcDigiTask()