FairRoot/PandaRoot
PndMvdDigiAna.cxx
Go to the documentation of this file.
1 #include "PndMvdDigiAna.h"
2 
3 #include "PndSdsDigiPixel.h"
4 #include "PndSdsDigiStrip.h"
5 #include "PndSdsMCPoint.h"
6 
7 #include "FairRun.h"
8 #include "FairRuntimeDb.h"
9 #include "FairGeoNode.h"
10 #include "FairGeoVector.h"
11 #include "PndStringSeparator.h"
12 #include "FairRootManager.h"
13 
14 #include "TClonesArray.h"
15 #include "TArrayD.h"
16 #include "TGeoManager.h"
17 #include "TCanvas.h"
18 
19 using std::string;
20 
22  FairTask("PndMvd Digi Ana")
23 {
24  fBranchName = "MVDPixelDigis";
25 // fBranchName = "MVDDigiStrip";
26  fPixelPos = new TH3F("pPos","pPos",200,-15,15,200,-15,15,200,-20,20);
27  fStripPos = new TH3F("sPos","sPos",128,0,127,16,0,15,200,0,20);
28 
29 // fHitArray = new TClonesArray("PndSdsDigiPixel");
30 // fPixelArray = new TClonesArray("PndSdsDigiPixel");
31 }
32 // -------------------------------------------------------------------------
33 
35  FairTask("MVD Digi Ana")
36 {
37  fBranchName = "MVDPixelDigis";
38 // fBranchName = "MVDDigiStrip";
39  fDetName = DetName;
40  fPixelPos = new TH3F("pPos","pPos",200,-15,15,200,-15,15,200,-20,20);
41  fStripPos = new TH3F("sPos","sPos",128,0,127,16,0,15,200,0,20);
42 
43 }
44 // -------------------------------------------------------------------------
45 
46 
47 // ----- Destructor ----------------------------------------------------
49 {
50 }
51 // -------------------------------------------------------------------------
52 
53 // ----- Initialization of Parameter Containers -------------------------
55 {
56  // Get Base Container
57  FairRun* ana = FairRun::Instance();
58  FairRuntimeDb* rtdb=ana->GetRuntimeDb();
59  fDigiPar = (PndSdsPixelDigiPar*)(rtdb->getContainer("MVDPixelDigiPar"));
60 
61 }
62 
64 {
66  return kSUCCESS;
67 }
68 
69 // ----- Public method Init --------------------------------------------
70 InitStatus PndMvdDigiAna::Init()
71 {
72 
73  FairRootManager* ioman = FairRootManager::Instance();
74 
75  if ( ! ioman )
76  {
77  std::cout << "-E- PndMvdDigiAna::Init: "
78  << "RootManager not instantiated!" << std::endl;
79  return kFATAL;
80  }
81  std::cout << "within init" << std::endl;
82 
83  // Get input array
84  fHitArray = (TClonesArray*) ioman->GetObject(fBranchName);
85 
86  if ( ! fHitArray )
87  {
88  std::cout << "-W- PndMvdDigiAna::Init: "
89  << "No MVDHit array!" << std::endl;
90  return kERROR;
91  }
92 
93  // register output histograms
94  ioman->Register("MVDHist1", "MVD", fStripPos, kTRUE);
95  ioman->Register("MVDHist2", "MVD", fPixelPos, kTRUE);
96 
97  std::cout << "-I- PndMvdDigiAna: Intialisation successfull" << std::endl;
98  return kSUCCESS;
99 }
100 // -------------------------------------------------------------------------
101 
102 void PndMvdDigiAna::Exec(Option_t*)
103 {
104  // Reset output array
105  std::cout << "Within Exec! " << fHitArray << " " << fPixelArray << std::endl;
106  if ( ! fHitArray )
107  Fatal("Exec", "No HitArray");
108 
109  // Loop over PndMvdMCPoints
110  Int_t
111  nPoints = fHitArray->GetEntriesFast();
112 
113  PndSdsDigiStrip* hit = 0;
114 
115  for (Int_t iPoint = 0; iPoint < nPoints; iPoint++)
116  {
117 // hit = (PndSdsDigiPixel*) fHitArray->At(iPoint);
118  hit = (PndSdsDigiStrip*) fHitArray->At(iPoint);
119 
120  if ( !hit){
121  std::cout<< "No Hit!" << std::endl;
122  continue;
123  }
124 
125  // std::cout << "****Hit Point: " << std::endl;
126  // hit->Print("");
127 
128  std::string det = hit->GetDetName().Data();
129 
130  PndStringSeparator sAna(det,"/");
131  std::vector<std::string> sVector = sAna.GetStringVector();
132  if (sVector[sVector.size()-1].find("Strip") != string::npos){
133  fStripPos->Fill(hit->GetChannel(), hit->GetFE(), hit->GetCharge());
134  std::cout << "Strip Found" << std::endl;
135 // std::cout<<"col "<<hit->GetPixelColumn()<<"\trow "
136 // <<hit->GetPixelRow()<<" charge "<<hit->GetCharge()<<std::endl;
137  }
138  else
139  {
140  /*
141  fPixelPos->Fill(hit->GetPixelColumn(), hit->GetPixelRow(), hit->GetCharge());
142  std::cout << "Pixel Found" << std::endl;
143  std::cout<<"col "<<hit->GetPixelColumn()<<"\trow "
144  <<hit->GetPixelRow()<<" charge "<<hit->GetCharge()<<std::endl;
145  */
146  }
147  } // Loop over HitPoints
148 
149  // Event summary
150  std::cout << "-I- PndMvdDigiAna: " << nPoints << " PndMvdHits" << std::endl;
151  PrintHistograms("PndMvdDigiAna.ps");
152 
153 }
154 
155 
156 
158 {
159  TFile* file = new TFile(filename,"UPDATE");
160  file->mkdir("PndMvdDigiAna");
161  file->cd("PndMvdDigiAna");
162 
163  fStripPos->Write();
164  delete fStripPos;
165  fStripPos=NULL;
166 
167  fPixelPos->Write();
168  delete fPixelPos;
169  fPixelPos=NULL;
170 
171  file->Close();
172  delete file;
173 }
174 
176 {
177  TCanvas* can1 = new TCanvas("can1","MVD digitization analysis",0,0,600,800);
178  Int_t a = 2, b = 4, zaehl = 1;
179  can1->Divide(a,b);
180  can1->Print(outpsfile+"[");//opens the ps file, no writing
181 
182  if(zaehl>(a*b)) // new page
183  {zaehl=1;can1->Print(outpsfile);can1->Clear("D");}
184  can1->cd(zaehl);
185  fStripPos->DrawCopy();
186  delete fStripPos;
187  fStripPos=NULL;
188 
189  if(zaehl>(a*b)) // new page
190  {zaehl=1;can1->Print(outpsfile);can1->Clear("D");}
191  can1->cd(zaehl);
192  fPixelPos->DrawCopy();
193  delete fPixelPos;
194  fPixelPos=NULL;
195 
196  // finish plotting
197  can1->Print(outpsfile);//writes in file
198  can1->Print(outpsfile+"]");//closes the file
199  delete can1;
200 }
201 
202 
203 
TClonesArray * fHitArray
Definition: PndMvdDigiAna.h:52
std::vector< std::string > GetStringVector(void)
virtual void Exec(Option_t *opt)
TTree * b
TFile * file
virtual InitStatus ReInit()
Class for digitised strip hits.
void WriteHistograms(const TString &filename)
Double_t GetCharge() const
Definition: PndSdsDigi.h:60
Int_t GetFE() const
Definition: PndSdsDigi.h:57
TString fBranchName
Definition: PndMvdDigiAna.h:49
TH3F * fPixelPos
Definition: PndMvdDigiAna.h:57
Int_t a
Definition: anaLmdDigi.C:126
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
TH3F * fStripPos
Definition: PndMvdDigiAna.h:58
virtual ~PndMvdDigiAna()
virtual InitStatus Init()
PndSdsPixelDigiPar * fDigiPar
Definition: PndMvdDigiAna.h:60
TString fDetName
Definition: PndMvdDigiAna.h:68
int hit(Int_t nEvents=0, TString inFile="sim.root", TString parFile="par.root", TString inDigi="digi.root", TString outFile="hit.root", Int_t timeBased=0)
Definition: hit.C:1
virtual void SetParContainers()
ClassImp(PndAnaContFact)
Int_t GetChannel() const
TCanvas * can1
TClonesArray * fPixelArray
Definition: PndMvdDigiAna.h:53
void PrintHistograms(const TString &outpsfile)
const string filename
Digitization Parameter Class for SDS-Pixel part.