FairRoot/PandaRoot
PndEmcTmpWaveformToDigi.cxx
Go to the documentation of this file.
1 //----------------------------------------------------------------------
2 // File and Version Information:
3 // $Id: //
4 // Description:
5 // Class PndEmcTmpWaveformToDigi. Module to take the ADC waveforms and produces digi.
6 //
7 // Software developed for the BaBar Detector at the SLAC B-Factory.
8 // Adapted for the PANDA experiment at GSI
9 //
10 // Author List:
11 // Phil Strother Original Author
12 // Dima Melnichuk - adaption for PANDA
13 // Copyright Information:
14 // Copyright (C) 1996 Imperial College
15 //
16 //----------------------------------------------------------------------
17 
19 
20 #include "PndEmcWaveform.h"
21 #include "PndEmcDigi.h"
22 #include "PndEmcDigiPar.h"
23 #include "PndEmcRecoPar.h"
24 
25 #include "FairRootManager.h"
26 #include "FairRunAna.h"
27 #include "FairRuntimeDb.h"
28 
29 #include "TClonesArray.h"
30 #include "TStopwatch.h"
31 
32 #include "IfdProxyDict.h"
33 #include "IfdStdVectorProxy.h"
34 #include "Ifd.h"
35 
36 #include "AbsEnv.h"
37 
38 #include <iostream>
39 #include <assert.h>
40 //#include <map>
41 
42 using std::cout;
43 using std::endl;
44 using std::fstream;
45 
47 {
49  fDigiPosMethod="depth";// "surface" or "depth"
51  SetPersistency(storedigis);
52  //fPndEmcDigiPositionDepth=6.2;
53 }
54 
55 //--------------
56 // Destructor --
57 //--------------
58 
60 {
61 }
62 
63 
65 {
66  // Get RootManager
67  FairRootManager* ioman = FairRootManager::Instance();
68  if ( ! ioman )
69  {
70  cout << "-E- PndEmcTmpWaveformToDigi::Init: "
71  << "RootManager not instantiated!" << endl;
72  return kFATAL;
73  }
74 
75  // Get input array
76 // fWaveformArray = (TClonesArray*) ioman->GetObject("EmcWaveform");
77 // if ( ! fWaveformArray ) {
78 // cout << "-W- PndEmcTmpWaveformToDigi::Init: "
79 // << "No PndEmcWaveform array!" << endl;
80 // return kERROR;
81 // }
82 
83  // Create and register output array
84  fDigiArray = new TClonesArray("PndEmcDigi");
85 
86  ioman->Register("EmcDigi","Emc",fDigiArray,GetPersistency());
89  fEmcDigiPositionDepth=fRecoPar->GetEmcDigiPositionDepth();
90 
91  cout<<"fEmcDigiPositionDepth: "<<fEmcDigiPositionDepth<<endl;
92 
93  if (!fDigiPosMethod.compare("surface"))
94  {
96  }
97  else if (!fDigiPosMethod.compare("depth"))
98  {
101  }
102  else
103  {
104  cout << "-W- PndEmcTmpWaveformToDigi::Init: "
105  << "Unknown digi position method!" << endl;
106  return kERROR;
107  }
108 
109  cout << "-I- PndEmcTmpWaveformToDigi: Intialization successfull" << endl;
110 
111  return kSUCCESS;
112 }
113 
115 {
116  TStopwatch timer;
117  if (fVerbose>0){
118  timer.Start();
119  }
120 // Reset output array
121  if ( ! fDigiArray ) Fatal("Exec", "No Digi Array");
122  fDigiArray->Delete();
123  Double_t peakPosition;
125  Double_t digi_time;
126  Int_t i_digi=0; //index of digi in TClonesArray
127  Int_t hitIndex;
128 // Int_t nWaveforms = fWaveformArray->GetEntriesFast();
129  //cout<<"PndEmcTmpWaveformToDigi: "<<nWaveforms<<" waveforms to convert"<<endl;
130 
131 // for (Int_t iWaveform=0; iWaveform<nWaveforms; iWaveform++) {
132 // PndEmcWaveform* theWaveform = (PndEmcWaveform*) fWaveformArray->At(iWaveform);
133 // hitIndex=theWaveform->GetHitIndex();
134 // Int_t detId=theWaveform->GetDetectorId();
135 // Int_t trackId=theWaveform->GetTrackId();
136 // theWaveform->fitPeak(max_energy,peakPosition);
137 // max_energy/=theWaveform->get_scale();
138 // digi_time=peakPosition/fSampleRate;
139 // if (max_energy>fEnergyDigiThreshold)
140 // {
141 // new((*fDigiArray)[i_digi]) PndEmcDigi(trackId,detId, max_energy, peakPosition,hitIndex);
142 // i_digi++;
143 
144 // }
145 // }
146 
147 
148  vector<PndEmcWaveform*> *waveformList= Ifd< std::vector<PndEmcWaveform*> >::get(gblEvtDict);
149 
150  Int_t nWaveforms = waveformList->size();
151  if (0==waveformList) {
152  cout << "Failed to recover std::vector from the dictionary"
153  << endl;
154  assert(0);
155  }
156 
157  vector<PndEmcWaveform*>::const_iterator it=waveformList->begin();
158  for (it; it!=waveformList->end();it++)
159  {
160  hitIndex=(*it)->GetHitIndex();
161  Int_t detId=(*it)->GetDetectorId();
162  Int_t trackId=(*it)->GetTrackId();
163  (*it)->fitPeak(max_energy,peakPosition);
164  max_energy/=(*it)->get_scale();
165  digi_time=peakPosition/fSampleRate;
166  if (max_energy>fEnergyDigiThreshold)
167  {
168  new((*fDigiArray)[i_digi]) PndEmcDigi(trackId,detId, max_energy, peakPosition,hitIndex);
169  i_digi++;
170 
171  }
172 
173  }
174 
175  if (fVerbose>0){
176  timer.Stop();
177  Double_t rtime = timer.RealTime();
178  Double_t ctime = timer.CpuTime();
179  cout << "PndEmcTmpWaveformToDigi, Real time " << rtime << " s, CPU time " << ctime << " s" << endl;
180  }
181 
182 }
183 
185 
186  // Get run and runtime database
187  FairRun* run = FairRun::Instance();
188  if ( ! run ) Fatal("SetParContainers", "No analysis run");
189 
190  FairRuntimeDb* db = run->GetRuntimeDb();
191  if ( ! db ) Fatal("SetParContainers", "No runtime database");
192 
193  // Get Emc digitisation parameter container
194  fDigiPar = (PndEmcDigiPar*) db->getContainer("PndEmcDigiPar");
195 
196  // Get Emc reconstruction parameter container
197  fRecoPar = (PndEmcRecoPar*) db->getContainer("PndEmcRecoPar");
198 
199 }
200 
202 {
203  SetPersistency(val);
204  return;
205 }
206 
currently not used, not in CMakeLists.txt
Double_t GetSampleRate()
Definition: PndEmcDigiPar.h:39
static void selectDigiPositionMethod(PositionMethod, double positionDepthPWO=0., double positionDepthShahslyk=0., double rescaleFactor=1.)
Definition: PndEmcDigi.cxx:153
Int_t run
Definition: autocutx.C:47
represents the reconstructed hit of one emc crystal
Definition: PndEmcDigi.h:40
virtual void Exec(Option_t *opt)
Double_t val[nBoxes][nFEBox]
Definition: createCalib.C:11
#define verbose
void SetPersistency(Bool_t val=kTRUE)
Double_t GetEnergyDigiThreshold()
Definition: PndEmcDigiPar.h:42
Double_t
TStopwatch timer
Definition: hit_dirc.C:51
parameter set of Emc digitisation
Definition: PndEmcDigiPar.h:12
Double_t ctime
Definition: hit_dirc.C:114
PndEmcTmpWaveformToDigi(Int_t verbose=0, Bool_t storedigis=kTRUE)
ClassImp(PndAnaContFact)
Double_t rtime
Definition: hit_dirc.C:113
Parameter set for Emc Reco.
Definition: PndEmcRecoPar.h:12