FairRoot/PandaRoot
PndSdsChargeWeightedPixelMapping.cxx
Go to the documentation of this file.
2 #include "TGeoManager.h"
3 #include "TGeoBBox.h"
4 #include "TClonesArray.h"
5 #include "TMath.h"
6 
9  fChargeConverter(NULL),
10  flx(0.),
11  fly(0.),
12  fcols(0),
13  frows(0)
14 {}
17  fChargeConverter(NULL),
18  flx(0.),
19  fly(0.),
20  fcols(0),
21  frows(0)
22 {}
23 
24 PndSdsHit PndSdsChargeWeightedPixelMapping::GetCluster(std::vector<PndSdsDigiPixel> pixelArray)
25 {
26 fDigiArray = pixelArray;
27  Double_t col = 0, row = 0, charge = 0;
28  Double_t tempCol = 0, tempRow = 0;
29  std::vector<Double_t> timeValues;
30  std::vector<Double_t> timeValueErrors;
31 
32  Int_t count = 0, mcindex=-1;
33  //Double_t local[2], master[2];
34  //TODO: Get away from default 10 Frontends per column?
35 
36  if (fDigiArray.size() == 1){
38  col = fDigiArray[0].GetPixelColumn() + ((Int_t)(fDigiArray[0].GetFE()%10)) * fcols;
39  if (col < 0){
40  col -= 0.5;
41  col += frows / 2;
42  }
43  else col += 0.5;
44  row = fDigiArray[0].GetPixelRow()+ (fDigiArray[0].GetFE()/10) * frows;
45  if (row < 0){
46  row -= 0.5;
47  row += flx /2;
48  }
49  else row += 0.5;
50  if (fVerbose > 1)
51  std::cout << "GetCluster:col/row " << col << " " << row << std::endl;
52  count = 1;
54  for(Int_t mcI = 0; mcI<fDigiArray[0].GetNIndices();mcI++){
55  if (fDigiArray[0].GetIndex(mcI) > -1) {
56  mcindex = fDigiArray[0].GetIndex(mcI);
57  break;
58  }
59  }
60  timeValues.push_back(fDigiArray[0].GetTimeStamp());
61  timeValueErrors.push_back(fDigiArray[0].GetTimeStampError());
62  }
63  }
64  else {
65  //cout << "Multiple Hits!" << std::endl;
66  for (UInt_t i = 0; i < fDigiArray.size(); i++){
67  //cout << "ActCol / Row" << col << " " << row << " added Col/Row " << fDigiArray[i].GetPixelColumn() << " " << fDigiArray[i].GetPixelRow() << endl;
69  tempCol = fDigiArray[i].GetPixelColumn() + (Int_t)(fDigiArray[0].GetFE()%10) * fcols;
70  tempRow = fDigiArray[i].GetPixelRow() + fDigiArray[0].GetFE()/10 * frows;
71  col += (tempCol*fChargeConverter->DigiValueToCharge(fDigiArray[i]));
74  timeValues.push_back(fDigiArray[i].GetTimeStamp());
75  timeValueErrors.push_back(fDigiArray[i].GetTimeStampError());
76  count++;
77  if(mcindex < 0){
78  for(Int_t mcI = 0; mcI<fDigiArray[i].GetNIndices();mcI++){
79  if (fDigiArray[i].GetIndex(mcI) > -1) {
80  mcindex = fDigiArray[i].GetIndex(mcI);
81  break;
82  }
83  }
84  }//mcindex
85 
86  }
87  }
88  if (count > 0){
89  if (charge > 0){
90  col /= charge;
91  row /= charge;
92  }
93  col += 0.5;
94  row += 0.5;
95  }
96  else col = row = 0;
97  }
98  if (fVerbose > 1){
99  std::cout << "Col: " << col << " Row: " << row << std::endl;
100  }
101 
102  TVector3 offset = GetSensorDimensions(fDigiArray[0].GetSensorID());
103  TVector3 locpos( col*flx - offset.X(), row*fly - offset.Y(), 0);
104  TVector3 pos = fGeoH->LocalToMasterShortId(locpos,fDigiArray[0].GetSensorID());
105 
106  Double_t errZ = 2.*fGeoH->GetSensorDimensionsShortId(fDigiArray[0].GetSensorID()).Z();
107  TMatrixD locCov(3,3);
108  locCov[0][0]=flx*flx/12.;
109  locCov[1][1]=fly*fly/12.;
110  locCov[2][2]=errZ*errZ/12;
111  TMatrixD hitCov=fGeoH->LocalToMasterErrorsShortId(locCov,fDigiArray[0].GetSensorID());
112  TVector3 dpos(sqrt(hitCov[0][0]),sqrt(hitCov[1][1]),sqrt(hitCov[2][2]));
113  //std::cout << "-I- PndSdsChargeWeightedPixelMapping Error DPos: " << dpos.x() << " " << dpos.y() << " " << dpos.z() << std::endl;
114 
115  Double_t meanTime = 0;
116  //Double_t meanTimeError = 0;
117  Double_t sumVar = 0;
118 
119  for (UInt_t t = 0; t < timeValues.size(); t++){
120  meanTime += timeValues[t] / (timeValueErrors[t] * timeValueErrors[t]);
121  sumVar += 1/(timeValueErrors[t] * timeValueErrors[t]);
122  }
123 
124  if (sumVar > 0)
125  meanTime /= sumVar;
126 
127 
128 
129  PndSdsHit thehit(fDigiArray[0].GetDetID(),fDigiArray[0].GetSensorID(), pos, dpos, -1, charge, fDigiArray.size(),mcindex);
130  thehit.SetCov(hitCov);
131  thehit.SetTimeStamp(meanTime);
132  thehit.SetTimeStampError(1/sumVar);
133  //std::cout << "-I- PndSdsChargeWeightedPixelMapping TimeStamp: " << tempTime/count << std::endl;
134  return thehit;
135 }
136 
138 {
139  gGeoManager->cd(fGeoH->GetPath(sensorID));
140  TGeoHMatrix* transMat = gGeoManager->GetCurrentMatrix();
141  if (fVerbose > 2)
142  transMat->Print("");
143  return *transMat;
144 }
145 
147 {
148  gGeoManager->cd(fGeoH->GetPath(sensorID));
149  TGeoVolume* actVolume = gGeoManager->GetCurrentVolume();
150  TGeoBBox* actBox = (TGeoBBox*)(actVolume->GetShape());
151  TVector3 result;
152  result.SetX(actBox->GetDX());
153  result.SetY(actBox->GetDY());
154  result.SetZ(actBox->GetDZ());
155 
156  //result.Dump();
157 
158  return result;
159 }
int row
Definition: anaLmdDigi.C:67
TVector3 pos
Int_t i
Definition: run_full.C:25
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
int col
Definition: anaLmdDigi.C:67
TVector3 offset(2, 0, 0)
TGeoManager * gGeoManager
TString GetPath(Int_t shortID)
for a given shortID the path is returned
virtual Double_t DigiValueToCharge(Double_t digi)=0
Converts a given digitized charge into charge in electrons.
TVector3 GetSensorDimensionsShortId(Int_t shortId)
PndSdsHit GetCluster(std::vector< PndSdsDigiPixel > pixelArray)
Main function of class to calculate the PndSdsHit out of the given PndSdsDigis.
TMatrixD LocalToMasterErrorsShortId(const TMatrixD &local, const Int_t &shortId)
Class to access the naming information of the MVD.
Double_t
std::vector< PndSdsDigiPixel > fDigiArray
TVector3 LocalToMasterShortId(const TVector3 &local, const Int_t &shortId)
TTree * t
Definition: bump_analys.C:13
int count
void SetCov(TMatrixD cov)
Definition: PndSdsHit.cxx:70
TMatrixT< double > TMatrixD
Definition: PndLmdDim.h:52