FairRoot/PandaRoot
PndEmcFWEndcapDigi.cxx
Go to the documentation of this file.
1 #include "PndEmcFWEndcapDigi.h"
2 
3 #include "PndEmcWaveformData.h"
4 #include "PndEmcMultiWaveform.h"
7 #include "PndEmcDigi.h"
8 #include "PndEmcFWEndcapDigiPar.h"
9 #include "PndEmcGeoPar.h"
10 #include "PndEmcRecoPar.h"
11 #include "PndEmcMapper.h"
12 #include "PndEmcStructure.h"
14 
15 #include "FairRootManager.h"
16 #include "FairRunAna.h"
17 #include "FairRuntimeDb.h"
18 
19 #include "TClonesArray.h"
20 #include "TStopwatch.h"
21 #include "TF1.h"
22 
23 #include <iostream>
24 #include <vector>
25 #include <utility>
26 
27 using std::cout;
28 using std::endl;
29 
31  fWaveformArray(NULL), fDigiArray(NULL), fEnergyDigiThreshold(0), fDigiPosMethod(""), fEmcDigiRescaleFactor(0.), fEmcDigiPositionDepthPWO(0), fEmcDigiPositionDepthShashlyk(0), fHighgainPSA(NULL), fLowgainPSA(NULL), fHighLowPSA(verbose), fCalibrator(NULL), fDigiPar(NULL), fRecoPar(NULL), fGeoPar(NULL), fVerbose(verbose), fTimeOrderedDigi(kFALSE)
32 {
33  SetPersistency(storedigis);
34 }
35 
36 //--------------
37 // Destructor --
38 //--------------
40 {
41  if (fDigiArray!= 0) delete fDigiArray;
42 }
43 
56 {
57  // Get RootManager
58  FairRootManager* ioman = FairRootManager::Instance();
59  if ( ! ioman )
60  {
61  cout << "-E- PndEmcFWEndcapDigi::Init: "
62  << "RootManager not instantiated!" << endl;
63  return kFATAL;
64  }
65 
66  // Get input array
67  fWaveformArray = (TClonesArray*) ioman->GetObject("EmcMultiWaveform");
68  if (!fWaveformArray) {
69  //check if EmcWaveform contains MultiWaveforms
70  fWaveformArray = (TClonesArray*) ioman->GetObject("EmcWaveform");
71  if((!fWaveformArray) || (!fWaveformArray->GetClass()->InheritsFrom("PndEmcMultiWaveform"))){
72  cout << "-W- PndEmcFWEndcapDigi::Init: "
73  << "No PndEmcWaveform array containing multi waveforms!" << endl;
74  return kERROR;
75  }
76 
77  }
78 
79  if(!fDigiPar) {
80  cout << "-E- PndEmcFWEndcapTimebasedWaveforms::Init: "
81  << "no DigiPar containter found" << endl;
82  return kFATAL;
83  }
84 
85  // Create and register output array
86  fDigiArray = ioman->Register("EmcDigi","PndEmcDigi", "Emc", GetPersistency());
87 
88  //position methods
91 
92  cout<<"fEmcDigiPositionDepthPWO: "<<fEmcDigiPositionDepthPWO<<endl;
93  cout<<"fEmcDigiPositionDepthShashlyk: "<<fEmcDigiPositionDepthShashlyk<<endl;
94 
95  //digi pos method
96  fDigiPosMethod = "depth"; //ATTN: hardcoded...do we need this at all?
97  fEmcDigiRescaleFactor = 1.08;
98  if (!fDigiPosMethod.CompareTo("surface")) {
100  } else if (!fDigiPosMethod.CompareTo("depth")) {
102  } else {
103  cout << "-W- PndEmcFWEndcapDigi::Init: " << "Unknown digi position method!" << endl;
104  return kERROR;
105  }
106 
107  // psa
108  if(!fDigiPar->GetPsaTypeLow().IsNull()) {
109 
110  if(fLowgainPSA) {
111  std::cout << "-W in PndEmcFWEndcapDigi::Init: Lowgain PSA already set. Skipping default initialization" << std::endl;
112  } else if(!fDigiPar->GetPsaTypeLow().CompareTo("PSAFPGAPileupAnalyser")) {
114  psa->SetVerbose(fVerbose);
115 
116  TObjArray* rparas = fDigiPar->GetRValueParLow().Tokenize(";");
117  TF1 R_thres("R_thres_Low", rparas->GetEntriesFast()>0 ? rparas->UncheckedAt(0)->GetName() : "", 1, TMath::Power(2, fDigiPar->GetNBits()));
118  TF1 R_mean("R_mean_Low", rparas->GetEntriesFast()>1 ? rparas->UncheckedAt(1)->GetName() : "", 1, TMath::Power(2, fDigiPar->GetNBits()));
119 
120  delete rparas;
121 
122  psa->Init(std::vector<Double_t>(fDigiPar->GetPsaParLow().GetArray(), fDigiPar->GetPsaParLow().GetArray()+fDigiPar->GetPsaParLow().GetSize()), R_thres.IsZombie() ? NULL : &R_thres, R_mean.IsZombie() ? NULL : & R_mean);
123 
124  fLowgainPSA = psa;
125 
126  } else {
127  std::cerr << "-E in PndEmcFWEndcapDigi::Init could not find PSA of type: " << fDigiPar->GetPsaTypeLow() << std::endl;
128  }
129  }
130 
131  if(!fDigiPar->GetPsaTypeHigh().IsNull()) {
132 
133  if(fHighgainPSA) {
134  std::cout << "-W in PndEmcFWEndcapDigi::Init: Highgain PSA already set. Skipping default initialization" << std::endl;
135  } else if(!fDigiPar->GetPsaTypeHigh().CompareTo("PSAFPGAPileupAnalyser")) {
137  psa->SetVerbose(fVerbose);
138 
139  TObjArray* rparas = fDigiPar->GetRValueParHigh().Tokenize(";");
140  TF1 R_thres("R_thres_High", rparas->GetEntriesFast()>0 ? rparas->UncheckedAt(0)->GetName() : "", 1, TMath::Power(2, fDigiPar->GetNBits()));
141  TF1 R_mean("R_mean_High", rparas->GetEntriesFast()>1 ? rparas->UncheckedAt(1)->GetName() : "", 1, TMath::Power(2, fDigiPar->GetNBits()));
142 
143  delete rparas;
144 
145  psa->Init(std::vector<Double_t>(fDigiPar->GetPsaParHigh().GetArray(), fDigiPar->GetPsaParHigh().GetArray()+fDigiPar->GetPsaParHigh().GetSize()), R_thres.IsZombie() ? NULL : &R_thres, R_mean.IsZombie() ? NULL : & R_mean);
146 
147  fHighgainPSA = psa;
148  } else {
149  std::cerr << "-E in PndEmcFWEndcapDigi::Init could not find PSA of type: " << fDigiPar->GetPsaTypeHigh() << std::endl;
150  }
151  }
152 
153 
154  if(fHighgainPSA && fLowgainPSA) {
156  } else {
157  std::cerr << "-E- PndEmcFWEndcapDigi::Init " << "No highgain and/or lowgain psa" << std::endl;
158  return kFATAL;
159  }
160 
161  //calibration
162  if(fCalibrator != NULL) {
163  std::cout << "-W in PndEmcFWEndcapDigi::Init: Calibrator already set. Skipping default initialization" << std::endl;
164  } else {
166  for(Int_t imod=1; imod<=5; ++imod) { //TODO: different calibration constants for different modules
167  fCalibrator->SetCalibration(imod, fDigiPar->GetCalibHigh(), 0, fDigiPar->GetSignalOverflowHigh()); //idx:0 <-> highgain
168  fCalibrator->SetCalibration(imod, fDigiPar->GetCalibLow(), 1, 0); //idx:1 <-> lowgain
169  }
170  fCalibrator->Init();
171  }
172 
174 
177 
178  cout << "-I- PndEmcFWEndcapDigi: Intialization successfull" << endl;
179  return kSUCCESS;
180 }
181 
194 {
195  TStopwatch timer;
196  if (fVerbose>2){
197  timer.Start();
198  }
199 
200  fDigiArray->Delete();
201 
203  Double_t digi_time;
204  Int_t hitIndex;
205  Int_t nHits;
206  Int_t detId;
207  Int_t trackId;
208  Int_t nWaveforms = fWaveformArray->GetEntriesFast();
209  PndEmcWaveform* theWaveform;
210 
211  for (Int_t iWaveform=0; iWaveform<nWaveforms; iWaveform++) {
212 
213  theWaveform = (PndEmcWaveform*) fWaveformArray->At(iWaveform);
214  hitIndex=theWaveform->GetHitIndex();
215  detId=theWaveform->GetDetectorId();
216  trackId=theWaveform->GetTrackId();
217 
218  //Double_t timeshift; // how maximum is shifted //[R.K. 01/2017] unused variable?
219 
220  nHits = fHighLowPSA.Process(theWaveform);
221 
222  for(Int_t iHit=0; iHit<nHits; ++iHit) {
223  fHighLowPSA.GetHit(iHit, energy, digi_time);
224  //PndEmcAbsCrystalCalibrator::CalibrationStatus_t CalS //[R.K. 03/2017] unused variable?tat;
225 
226  //cout << "#" << iHit << ".\tDetId: " << detId << "\tsample time: " << digi_time << "\traw energy: " << energy << "\t";
227  //CalStat = //[R.K. 03/2017] unused variable?
228  fCalibrator->Calibrate(energy, detId, fHighLowPSA.GetWaveformIdx(iHit));
229 
230  Double_t sampleRate = theWaveform->GetSampleRate();
231 
232  digi_time/=sampleRate;
233  digi_time*=1e9; //ns
234 
235  if (energy>fEnergyDigiThreshold) {
236  Double_t timestamp=theWaveform->GetTimeStamp() + digi_time;
237  //std::cout << "PndEmcFWEndcapDigi::Exec Waveform TS: " << theWaveform->GetTimeStamp() << " digiTime: " << digi_time << std::endl;
238 
239  PndEmcDigi* myDigi = new((*fDigiArray)[fDigiArray->GetEntriesFast()]) PndEmcDigi(trackId,detId, energy, timestamp, hitIndex);
240  myDigi->ResetLinks();
241  myDigi->AddLinks(theWaveform->GetLinksWithType(FairRootManager::Instance()->GetBranchId("EmcHit")));
242 
243  //std::cout << "-I- PndEmcFWEndcapDigi Links MyDigi: " << *myDigi->GetPointerToLinks() << std::endl;
244  //std::cout << "Waveform: " << *theWaveform->GetPointerToLinks() << std::endl;
245  //myDigi->AddLink(FairLink(-1, FairRootManager::Instance()->GetEntryNr(), "EmcWaveform", iWaveform));
246  //std::cout << "\t accepted" << std::endl;
247  //std::cout << "digi at:" << fDigiArray->GetEntriesFast()-1 << " links to: " << myDigi->GetLink(0).GetIndex() << " iwaveform: " << iWaveform << " number of links: " << myDigi->GetNLinks() << std::endl;
248  //std::cout << "#0: " << myDigi->GetLink(0) << "\n#1:" << myDigi->GetLink(1) << std::endl;
249  //std::cout << "\t rejected" << std::endl;
250  }
251 
252  }
253  }
254 
255  if (fVerbose>2) {
256  timer.Stop();
257  Double_t rtime = timer.RealTime();
258  Double_t ctime = timer.CpuTime();
259  cout << "PndEmcFWEndcapDigi, Real time " << rtime << " s, CPU time " << ctime << " s" << endl;
260  }
261 }
262 
264 {
265  // Get run and runtime database
266  FairRun* run = FairRun::Instance();
267  if ( ! run ) Fatal("SetParContainers", "No analysis run");
268 
269  FairRuntimeDb* db = run->GetRuntimeDb();
270  if ( ! db ) Fatal("SetParContainers", "No runtime database");
271 
272  // Get Emc digitisation parameter container
273  fDigiPar = dynamic_cast<PndEmcFWEndcapDigiPar*>(db->getContainer("PndEmcFWEndcapDigiPar"));
274 
275  // Get Emc reconstruction parameter container
276  fRecoPar = (PndEmcRecoPar*) db->getContainer("PndEmcRecoPar");
277 
278  // Get Emc geometry parameter container
279  fGeoPar = (PndEmcGeoPar*) db->getContainer("PndEmcGeoPar");
280 }
281 
283 {
284  SetPersistency(val);
285  return;
286 }
287 
289 
const TString & GetPsaTypeHigh()
virtual void GetHit(Int_t i, Double_t &energy, Double_t &time)
Get energy and time of hit.
int fVerbose
Definition: poormantracks.C:24
Double_t GetEmcDigiPositionDepthShashlyk()
Definition: PndEmcRecoPar.h:25
static void selectDigiPositionMethod(PositionMethod, double positionDepthPWO=0., double positionDepthShahslyk=0., double rescaleFactor=1.)
Definition: PndEmcDigi.cxx:153
Int_t run
Definition: autocutx.C:47
virtual void Exec(Option_t *opt)
Runs the task.
represents the reconstructed hit of one emc crystal
Definition: PndEmcDigi.h:40
virtual InitStatus Init()
Init Task.
Double_t val[nBoxes][nFEBox]
Definition: createCalib.C:11
#define verbose
const TArrayD & GetPsaParLow()
Int_t GetHitIndex() const
void SetPersistency(Bool_t val=kTRUE)
virtual void SetVerbose(Int_t verbose=0)
PndEmcFWEndcapDigi(Int_t verbose=0, Bool_t storedigis=kTRUE)
void InitEmcMapper()
Task to create digis from waveforms.
virtual void Init(PndEmcPSAFPGASampleAnalyser *highgainPSA, PndEmcPSAFPGASampleAnalyser *lowgainPSA, Double_t overflowThreshold, Int_t highgainWfIndex=0, Int_t lowgainWfIndex=1)
PndEmcFWEndcapDigiPar * fDigiPar
Digitisation parameter container.
virtual void SetParContainers()
parameter set for the FWEndcap variant of waveform simulation
int nHits
Definition: RiemannTest.C:16
PndEmcPSAFPGASampleAnalyser * fLowgainPSA
Double_t
int GetTrackId() const
virtual void SetCalibration(Int_t ModId, Double_t cal, Int_t SignalNr=1, Double_t overflow=-1)
Set Calibration for a Module.
TStopwatch timer
Definition: hit_dirc.C:51
Double_t fEmcDigiPositionDepthShashlyk
PndEmcHighLowPSA fHighLowPSA
Class to simulate a Calibration.
TClonesArray * fWaveformArray
long GetDetectorId() const
const TString & GetRValueParLow()
virtual Int_t Process(const PndEmcWaveform *waveform)
Find Hits in Waveform.
represents a simulated waveform in an emc crystal
Double_t ctime
Definition: hit_dirc.C:114
const TString & GetRValueParHigh()
virtual CalibrationStatus_t Calibrate(Double_t &Energy, Long_t DetId, Int_t SignalNr=1)
Apply CrystalCalibration to Energy of Crystal derId.
Double_t fEmcDigiPositionDepthPWO
ClassImp(PndAnaContFact)
virtual Int_t GetWaveformIdx(Int_t i)
Double_t GetSampleRate() const
PndEmcRecoPar * fRecoPar
Reconstruction parameter container.
static PndEmcStructure * Instance()
const TString & GetPsaTypeLow()
Double_t rtime
Definition: hit_dirc.C:113
const TArrayD & GetPsaParHigh()
virtual void Init(const std::vector< Double_t > &params, TF1 *R_thres, TF1 *R_mean, float extBaselineValue=0)
PndEmcPSAFPGASampleAnalyser * fHighgainPSA
Parameter set for Emc Reco.
Definition: PndEmcRecoPar.h:12
TClonesArray * fDigiArray
PndEmcSimCrystalCalibrator * fCalibrator
void SetStorageOfData(Bool_t val)
PndEmcGeoPar * fGeoPar
Digitisation parameter container.
Double_t energy
Definition: plot_dirc.C:15
Double_t GetEmcDigiPositionDepthPWO()
Definition: PndEmcRecoPar.h:24