FairRoot/PandaRoot
PndMvdConvertApvTask.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 // libc includes
5 #include <iostream>
6 #include <map>
7 
8 // Root includes
9 #include "TROOT.h"
10 #include "TClonesArray.h"
11 
12 
13 // framework includes
14 #include "FairRootManager.h"
15 // PndMvd includes
16 #include "PndMvdConvertApvTask.h"
17 #include "PndMvdConvertApv.h"
18 #include "PndMvdBoxMap.h"
19 
20 #include "FairRun.h"
21 #include "FairRuntimeDb.h"
22 #include "PndMvdContFact.h"
23 #include "PndSdsStripDigiPar.h"
24 
25 #include "PndSdsDigiStrip.h"
26 #include <vector>
27 
28 using namespace std;
29 
30 // ----- Default constructor -------------------------------------------
32  fPersistance(kTRUE),
33  fApvConvert(Apvconvert),
34  fApvMapper(Apvmapper),
35  fStripArray(NULL),
36  fGeoH(PndGeoHandling::Instance()),
37  iStrip(0),
38  fDigiParameterList(new TList()),
39  fBotSides()
40 {
41 }
42 // ----- Destructor ----------------------------------------------------
44 {
45 }
46 
48 { // in this task we even don't need the digitization info
49 
50 cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
51 cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
52 cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
53 cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
54 cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
55 
56  FairRun* ana = FairRun::Instance();
57  FairRuntimeDb* rtdb=ana->GetRuntimeDb();
58  PndMvdContFact* themvdcontfact = (PndMvdContFact*)rtdb->getContFactory("PndMvdContFact");
59  TList* theContNames = themvdcontfact->GetDigiParNames();
60  Info("SetParContainers()","The container names list contains %i entries",theContNames->GetEntries());
61  TIter cfIter(theContNames);
62  while (TObjString* contname = (TObjString*)cfIter()) {
63  TString parsetname = contname->String();
64  if(parsetname.BeginsWith("MVDStripDigiPar")){
65  PndSdsStripDigiPar* digipar = (PndSdsStripDigiPar*)(rtdb->getContainer(parsetname.Data()));
66  Info("SetParcontiners()","check some values. fDigiParameterList: %p digipar: %p",fDigiParameterList,digipar);
67  fDigiParameterList->Add(digipar);
68 
69 
70  Info("SetParContainers()","Loaded container %s",parsetname.Data());
71  }
72  }
73 
74  return;
75 
76 }
77 
78 // ----- Public method Init --------------------------------------------
80 {
81 
82  // Get RootManager
83  FairRootManager* ioman = FairRootManager::Instance();
84  if ( ! ioman )
85  {
86  std::cout << "-E- PndMvdStripHitProducer::Init: "
87  << "RootManager not instantiated!" << std::endl;
88  return kFATAL;
89  }
90 
91  // Create and register output array
92  fStripArray = new TClonesArray("PndSdsDigiStrip");
93  ioman->Register("MVDStripDigis", "MVD", fStripArray, fPersistance);
94  fApvConvert->Init();
95  fApvMapper->Init();
96  cout<<"Init of Task finished"<<endl;
97 
98  // set up the geohandler
99  std::vector<std::string> listOfSensitives;
100  listOfSensitives.push_back("StripActive");
101  fGeoH->CreateUniqueSensorId("", listOfSensitives);
102 
104 
105  TIter parsetiter(fDigiParameterList);
106  while ( PndSdsStripDigiPar* digipar = (PndSdsStripDigiPar*)parsetiter() )
107  {
108  cout << "Debugging, sens type: " << (TString)digipar->GetSensType() << ", num of bot FE: " << digipar->GetNrBotFE() << endl;
109  if(digipar->GetNrBotFE()==1)
110  { // we count top side first from 0; Bot side strarts at #top fe's
111  fBotSides[(TString)digipar->GetSensType()]=digipar->GetNrTopFE();
112  }
113  }
114 
115  return kSUCCESS;
116 
117 }
118 
119 
120 // ----- Public method Exec --------------------------------------------
122 {
123 
124  // cout << "--*--" << endl;
125 
126 
127  // Reset output array
128  fStripArray->Delete();
129 
130  std::map<Int_t,Double_t> singleSidedBacksideMap;
131  std::map<Int_t,std::vector<Int_t> > buffIndex;
132 
133  Int_t nbox, ch;
134  //Int_t rw=-1;
135  Int_t sw=-1, botfe=-1;
136  TString detpath="";
137  Int_t detnameid;
138  Int_t stripnum;
139  Int_t buffCh = -1;
140  Double_t buffClock;
141  Double_t buffSpill;
142 
143  std::vector<PndSdsDigiStrip> strips = fApvConvert->ReadNext();
144  for (std::vector<PndSdsDigiStrip>::iterator strip=strips.begin(); strip!=strips.end(); ++strip)
145  {
146  //rw=strip->GetFE();
147  //sw=strip->GetFE();
148 
149  nbox = strip -> GetSensorID();
150  //ch = strip -> GetChannel();
151  buffCh = strip -> GetChannel();
152  fApvMapper->DoMapping(nbox,buffCh,detpath);
153  detnameid=fGeoH->GetShortID(detpath);
154 
155  buffClock = strip->GetTimeStamp();
156  buffSpill = strip->GetTimeStampError();
157 
158  if(fVerbose>1) Info("Exec","Write a Digi from detector %s %i",detpath.Data(),detnameid);
159  stripnum = fStripArray->GetEntriesFast();
160  //cout << "stripnum: " << stripnum << endl;
161 
162  sw = (Int_t) buffCh/128.;
163  ch = (Int_t) buffCh%128;
164 
165  if (IsSingleSided(detpath))
166  {
167  //cout << "Detected as single sided: " << detpath.Data() << endl;
168  if (sw > 2)
169  {
170  sw = sw - 3;
171  }
172  }
173 
174  //cout << "Box: " << nbox << ", channel: " << buffCh << ", nome: " << detpath.Data() << ", iD: " << detnameid << ", FE: " << sw << ", corrCh: " << ch << endl;
175 
176  PndSdsDigiStrip *buffStr = new PndSdsDigiStrip(strip->GetIndices(), strip->GetDetID(),detnameid, sw, ch, strip->GetCharge(),strip->GetTimeStamp());
177  buffStr->SetTimeStampError(strip->GetTimeStampError());
178 
179  new ((*fStripArray)[stripnum]) PndSdsDigiStrip(*buffStr);
180 
181  //new ((*fStripArray)[stripnum]) PndSdsDigiStrip(strip->GetIndices(), strip->GetDetID(),detnameid, sw, ch, strip->GetCharge() ,0);
182  // collect information of fake bottom sides if singlesided
183  if (IsSingleSided(detpath))
184  { // collect information of fake bottom sides if singlesided
185  singleSidedBacksideMap[detnameid]+= strip->GetCharge();
186  (buffIndex[detnameid]).push_back(strip->GetIndex());
187  }
188  }
189 
190  // writing the single sided fake backside
191  for (std::map<Int_t,Double_t>::iterator it=singleSidedBacksideMap.begin();it!=singleSidedBacksideMap.end();++it)
192  {
193  stripnum = fStripArray->GetEntriesFast();
194  botfe=CalcBotFakeFE( fGeoH->GetPath(it->first) );
195 
196  PndSdsDigiStrip *buffStr2 = new PndSdsDigiStrip(buffIndex[it->first], kMVDHitsStrip,it->first, botfe, 0, it->second, buffClock);
197  buffStr2->SetTimeStampError(buffSpill);
198 
199  new ((*fStripArray)[stripnum])PndSdsDigiStrip(*buffStr2);
200 
201  //new ((*fStripArray)[stripnum])PndSdsDigiStrip(buffIndex[it->first], kMVDHitsStrip,it->first, botfe, 0, it->second, 0);
202  }
203 
204 }
205 
206 
208 {
209 
210  if( !(detpath.Contains("Strip")) ) return kFALSE;
211 
212  for(std::map<TString,Int_t>::iterator it=fBotSides.begin();it!=fBotSides.end();it++)
213  {
214  if( detpath.Contains(it->first) )
215  {
216  //cout << "Sensor type: " << it->first << endl;
217  //cout << "Path: " << detpath << endl;
218  return kTRUE;
219  }
220  }
221 
222  return kFALSE;
223 }
224 
226 {
227 
228  for(std::map<TString,Int_t>::iterator it=fBotSides.begin();it!=fBotSides.end();it++)
229  {
230  if( detpath.Contains(it->first) )
231  {
232  return it->second;
233  }
234  }
235  return -99999; //return something silly
236 
237 }
238 
240 {}
241 
TClonesArray * fStripArray
array of results
int fVerbose
Definition: poormantracks.C:24
virtual void Exec(Option_t *opt)
PndGeoHandling * fGeoH
Definition: anasim.C:34
virtual InitStatus Init()
PndMvdConvertApvTask(PndMvdConvertApv *Apvconvert, PndMvdBoxMap *Apvmapper)
labels push_back("electron")
Class for digitised strip hits.
void CreateUniqueSensorId(TString startName, std::vector< std::string > listOfSensitives)
Has to be called during simulation to create unique sensor id.
TString GetPath(Int_t shortID)
for a given shortID the path is returned
Convert meassured data into PndSdsDigiStrip.
Convert Task of data.
Bool_t IsSingleSided(TString &detpath)
void DoMapping(Int_t nbox, Int_t chan, TString &detpath)
TList * GetDigiParNames()
Class to access the naming information of the MVD.
int strip
Definition: anaMvdDigi.C:135
void PrintSensorNames()
Bool_t Init()
Double_t
std::vector< PndSdsDigiStrip > ReadNext()
Digitization Parameter Class for MVD-Strip part.
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
Int_t GetShortID(TString path)
for a given path the (unique) position of the sensor path in the fSensorNamePar-List is given...
PndGeoHandling * fGeoH
Geohandler for name string compression.
PndMvdConvertApv * fApvConvert
class which convert the read in and hold the streams
std::map< TString, Int_t > fBotSides
Int_t CalcBotFakeFE(TString detpath)
ClassImp(PndAnaContFact)