FairRoot/PandaRoot
PndMvdConvertApv.cxx
Go to the documentation of this file.
1 // using timestamp for the clock counts
2 // and timestamperr to store the spill resets (just a temporary solution)
3 
4 #include "PndMvdConvertApv.h"
5 
6 //#include "TsEvent.h"
7 #include "PndMvdSiHit.h"
8 
9 #include "PndMvdApvHit.h"
10 #include "PndSdsDigiStrip.h"
11 #include "TString.h"
12 #include <fstream>
13 #include <vector>
14 #include <map>
15 
16 using namespace std;
17 
18 // ----- Constructor --------------------------------------------
19 
21  fCalibPars(),
22  fNofEvents(0),
23  fEvent(-1),
24  fLastEvent(0),
25  fNoCalib(kFALSE),
26  fHitFileName(""),
27  fDataFile(),
28  fhitlist(),
29  fTopModuleID(0),
30  fBottomModuleID(0),
31  fFake(kFALSE),
32  f(NULL),
33  t(NULL),
34  tsEv(NULL),
35  arr(NULL),
36  fGeoH(NULL)
37 {
38 
39  f = new TFile(HitFileName);
41  t = (TTree*) f->Get("T");
42  tsEv = new PndMvdTsEvent();
43  arr = new TClonesArray("PndMvdSiHit");
44 
45  cout << "---------------------------------------" << endl;
46  cout << "Number of events: " << t->GetEntries() << endl;
47  cout << "---------------------------------------" << endl;
48 
49  t->SetBranchAddress("events",&tsEv);
50  cout << t->GetEntries() << " events in File" << endl;
51 
52  //LoadCalibration(CalibFileName, fes);
53  LoadCalibration(CalibFileName);
54 
55  fNofEvents=t->GetEntries();
56 
57  cout<<"** end of PndMvdConvertApv::PndMvdConvertApv(const TString& , const TString&) **"<<endl;
58 }
59 
61 {
62  return kTRUE;
63 }
64 
65 
66 // ----- Load calibration for the Modules --------------------------------------------
67 
68 //void PndMvdConvertApv::LoadCalibration(TString CalibFileName, std::vector<Int_t> fes)
70 {
71 
72  std::ifstream calibfile(CalibFileName);
73  if(!calibfile)
74  {
75  cout<<"Calibration file not found"<<endl;
76  fNoCalib=true;
77  return;
78  }
79  while (!calibfile.eof()) // read data
80  {
81  char c;
82  calibfile>>c;
83  if (calibfile.eof()) break;
84  if (!isdigit(c))
85  {
86  char str[256];
87  calibfile.getline(str,256);
88  continue;
89  }
90  calibfile.putback(c);
91 
92  int boxID, channel;
93  double value;
94 
95  calibfile >> boxID >> channel >> value;
96 
97  //for(unsigned int vec=0;vec<fes.size();vec++)
98  //{
99  //if(feID==fes[vec])
100  //{
101  fCalibPars[boxID][channel]=value;
102  //}
103  //}
104  }
105  calibfile.close();
106  fNoCalib=false;
107  cout<<"Calibration succesfully read"<<endl;
108  return;
109 
110 }
111 
112 // ----- Convert adc to e if calibration was loaded --------------------------------------------
113 
114 std::vector<PndSdsDigiStrip> PndMvdConvertApv::Calc(std::vector<PndMvdApvHit> hitlist)
115 {
116  std::vector<PndSdsDigiStrip> result;
117  for(UInt_t hitnumber=0;hitnumber<hitlist.size();hitnumber++)
118  {
119  Double_t q=0.;
120  if(fNoCalib)
121  {
122  q=1.*hitlist[hitnumber].GetADC(); // no calib adc -> e !!!
123  }else{
124  if (fCalibPars[hitlist[hitnumber].GetModuleID()].size())
125  {
126  if (fCalibPars[hitlist[hitnumber].GetModuleID()][hitlist[hitnumber].GetChannel()])
127  {
128  q=fCalibPars[hitlist[hitnumber].GetModuleID()][hitlist[hitnumber].GetChannel()]*(hitlist[hitnumber].GetADC())*1000.; // in electrons
129  }
130  }
131  }
132 
133  //TString detPath="Module";
134  //Int_t modId=-1; //[R.K.02/2017] Unused variable?
135  //if(fFake) //[R.K.02/2017] Unused variable?
136  //{ //[R.K.02/2017] Unused variable?
137  //if(fTopModuleID==hitlist[hitnumber].GetModuleID() || fBottomModuleID==hitlist[hitnumber].GetModuleID())
138  //modId = 1; //[R.K.02/2017] Unused variable?
139  //if(fBottomModuleID==hitlist[hitnumber].GetModuleID()) hitlist[hitnumber].SetFeID(hitlist[hitnumber].GetFeID()+3); //[R.K.02/2017] Unused variable?
140  //}else{ //[R.K.02/2017] Unused variable?
141  //modId = hitlist[hitnumber].GetModuleID(); //[R.K.02/2017] Unused variable?
142  //} //[R.K.02/2017] Unused variable?
143  /* detPath+=modId;
144  detPath+="Rect";
145  // std::cout<<detPath.Data()<<" | "<<modId<<std::endl;
146  //TGeoVolume* Vol=gGeoManager->FindVolumeFast(detPath);
147  TGeoVolume* Vol=0;
148  if(Vol!=0) {
149  // std::cout<<Vol->GetName()<<std::endl;
150  // Vol->GetNode(-1)->cd();
151  detPath="/SiliconTestStation_1/DummysensorAss_0/";
152  detPath+=Vol->GetName();
153  detPath+="_0";
154  gGeoManager->cd(detPath.Data());
155  }
156  else {
157  // std::cout<<" -E- PndMvdConvertApv::Calc(): "<<detPath.Data()<<" does not exist"<<std::endl;
158  detPath+="_nonexistent";
159  }*/
160  // std::cout<<detPath.Data()<<std::endl;
161  // std::cout<<gGeoManager->GetPath()<<std::endl;
162  // if (0==Vol) std::cout<<"0";
163  // else std::cout<<"1";
164  // std::cout<<Vol->GetName();
165 
166  // detPath = Vol->GetName();
167  // std::cout << "write Digi with "<< detPath.Data()<<" ( "<<fGeoH->GetID(detPath)<<" )"<<std::endl;
168  if(fFake)
169  {
170  PndSdsDigiStrip DigiHit(hitlist[hitnumber].GetEventID(), // index
171  kMVDHitsStrip, // panda detID
172  -1, // No SensorID (from geopath)
173  hitlist[hitnumber].GetFeID(), // fe
174  hitlist[hitnumber].GetChannel(), // chan
175  q/*/1000/1000*/, // charge
176  hitlist[hitnumber].GetTimestamp()// timestamp
177  );
178  DigiHit.SetTimeStampError(hitlist[hitnumber].GetTriggerID());
179 
180  // cout << "Ev. " << hitlist[hitnumber].GetEventID() << ", FE: " << hitlist[hitnumber].GetFeID() << ", ch: " << hitlist[hitnumber].GetChannel() << ", FAKE" << endl;
181 
182  result.push_back(DigiHit);
183  }else{
184  PndSdsDigiStrip DigiHit(hitlist[hitnumber].GetEventID(),
186  hitlist[hitnumber].GetModuleID(),
187  hitlist[hitnumber].GetFeID(),
188  hitlist[hitnumber].GetChannel(),
189  q/*/1000/1000*/,
190  hitlist[hitnumber].GetTimestamp()
191  );
192  DigiHit.SetTimeStampError(hitlist[hitnumber].GetTriggerID());
193 
194 
195  // cout << "Ev. " << hitlist[hitnumber].GetEventID() << ", FE: " << hitlist[hitnumber].GetChannel()/128 << ", ch: " << hitlist[hitnumber].GetChannel()%128 << ", sens" << hitlist[hitnumber].GetModuleID() << endl;
196  result.push_back(DigiHit);
197  }
198  }
199  return result;
200 }
201 
202 // ----- Returns the number of events in the hit file --------------------------------------------
203 
205 {
206  return fNofEvents;
207 }
208 
209 // ----- read the next event from hitfile --------------------------------------------
210 
211 std::vector<PndSdsDigiStrip> PndMvdConvertApv::ReadNext()
212 {
213 
214 
215  std::vector<PndSdsDigiStrip> digiList;
216  //bool work=true;
217 
218  //int triggID=0;
219  int fe=0;
220  //int ts=0;
221  int frame=0;
222  int ch=0;
223  int l=0;
224  int moduleID=0;
225  double q=0.;
226  long int ev=0;
227  UInt_t ClockReset = 0.;
228  ULong64_t ClockCounts = 0.;
229 
230  if (fEvent >= -1 && fEvent <= fNofEvents)
231  {
232 
233  t->GetEvent(fEvent);
234 
235  ClockCounts = tsEv->GetExtClockTimeStamp(ClockReset);
236  // Storing ClockReset in fTriggerID
237  // Storing ClockCounts in fTimestamp
238 
239  arr = tsEv->GetSiHitList();
240  fhitlist.clear();
241 
242  for (Int_t kk = 0 ; kk < arr->GetEntries() ; kk++)
243  {
244 
245  PndMvdSiHit *hit = (PndMvdSiHit*) arr->At(kk);
246  ev = tsEv->GetEventId();
247  //fe = (Int_t) (hit->fChannel)/128;
248  //ch = (Int_t) (hit->fChannel)%128;
249  ch = (Int_t) (hit->fChannel);
250  q = hit->fAdc;
251  l = hit->fNumFrames;
252  moduleID = hit->fBox;
253 
254  //if(fhitlist.size()>20) fhitlist.clear();
255  // digiList = Calc(fhitlist);
256 
257  fLastEvent=ev;
258  //PndMvdApvHit Hit(ev, moduleID, fe, triggID, ts, frame, ch, q, l);
259  PndMvdApvHit Hit(ev, moduleID, fe, ClockReset, ClockCounts, frame, ch, q, l);
260  //cout << "Ev. " << fEvent << ", trigg: " << triggID << ", sens: " << moduleID << ", ch: " << ch << ", fe: " << (Int_t) (hit->fChannel)/128 << ", channel: " << (Int_t) (hit->fChannel)%128 << endl;
261  fhitlist.push_back(Hit);
262  }
263 
264  //if(fhitlist.size()>20) fhitlist.clear();
265  digiList = Calc(fhitlist);
266  fEvent++;
267 
268  }
269 
270  if(!(fEvent%10000)) cout<<"[ "<<(fEvent*100)/fNofEvents<<" %] "<<fEvent<<" events converted ..."<<endl;
271  if(fEvent==fNofEvents) cout<<"[100 %] "<<fEvent<<" events converted"<<endl;
272 
273  return digiList;
274 
275 }
276 
277 // ----- read all events from hitfile --------------------------------------------
278 
279 std::vector<PndSdsDigiStrip> PndMvdConvertApv::ReadAll()
280 {
281  std::vector<PndSdsDigiStrip> result;
282  while(fEvent!=fNofEvents)
283  {
284  std::vector<PndSdsDigiStrip> dummy=ReadNext();
285  for(unsigned int i=0;i<dummy.size();++i) result.push_back(dummy[i]);
286  }
287  return result;
288 }
289 
290 void PndMvdConvertApv::SetFakePair(Int_t TopModuleID, Int_t BottomModuleID)
291 {
292  fFake=true;
293  fTopModuleID=TopModuleID;
294  fBottomModuleID=BottomModuleID;
295  return;
296 }
297 
298 // PndSdsDigiStrip PndMvdConvertApv::DigiHit(hitlist [])
299 // {
300 // }
301 
Int_t fTopModuleID
stored fake module top side
ULong64_t GetExtClockTimeStamp(UInt_t &resetCount)
Definition: PndMvdTsEvent.h:38
UInt_t GetEventId()
Definition: PndMvdTsEvent.h:29
std::vector< PndSdsDigiStrip > Calc(std::vector< PndMvdApvHit > hitlist)
Int_t i
Definition: run_full.C:25
PndGeoHandling * fGeoH
Definition: anasim.C:34
void SetFakePair(Int_t TopModuleID, Int_t BottomModuleID)
std::map< Int_t, std::map< Int_t, double > > fCalibPars
Calib Parameters: &lt;moduleID&lt;FE&lt;channel&gt; &gt; &gt;
Class for digitised strip hits.
int ev
UShort_t fBox
Definition: PndMvdSiHit.h:12
Bool_t fFake
knows if fake is allowed
long int fEvent
stored current eventID
UShort_t fChannel
Definition: PndMvdSiHit.h:13
TString HitFileName
std::vector< PndSdsDigiStrip > ReadAll()
Class to store data of Apv-Sensors.
Definition: PndMvdApvHit.h:18
Double_t
std::vector< PndSdsDigiStrip > ReadNext()
long int fNofEvents
stored last eventID of the hitfile
PndMvdTsEvent * tsEv
TFile * f
Definition: bump_analys.C:12
static PndGeoHandling * Instance()
long int fLastEvent
last eventID
Int_t fBottomModuleID
stored fake module bottom side
std::vector< PndMvdApvHit > fhitlist
stored readed events
Int_t fAdc
Definition: PndMvdSiHit.h:14
TClonesArray * arr
int fe
Definition: anaLmdDigi.C:67
TClonesArray * GetSiHitList()
Definition: PndMvdTsEvent.h:30
TTree * t
Definition: bump_analys.C:13
void LoadCalibration(TString CalibFileName)
bool fNoCalib
true if calib was succesfull loaded
PndSdsMCPoint * hit
Definition: anasim.C:70
UShort_t fNumFrames
Definition: PndMvdSiHit.h:15
PndGeoHandling * fGeoH
TString CalibFileName