FairRoot/PandaRoot
PndGemFindHitsAna.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndGemFindHitsAna source file -----
3 // ----- Created 02.06.2009 by R. Karabowicz -----
4 // -------------------------------------------------------------------------
5 
6 #include "PndGemFindHitsAna.h"
7 
8 // FairRoot includes
9 #include "FairRootManager.h"
10 #include "FairRunAna.h"
11 #include "FairRuntimeDb.h"
12 #include "FairBaseParSet.h"
13 #include "FairTrackParam.h"
14 #include "FairRootManager.h"
15 // Pnd includes
16 #include "PndGemDigiPar.h"
17 #include "PndGemHit.h"
18 // ROOT includes
19 #include "TClonesArray.h"
20 #include "TGeoManager.h"
21 #include "TMatrixFSym.h"
22 
23 // C++ includes
24 #include <iostream>
25 #include <iomanip>
26 #include <map>
27 #include <cmath>
28 using std::cout;
29 using std::endl;
30 using std::map;
31 using std::setw;
32 
33 // ----- Default constructor ------------------------------------------
35  : FairTask("GEM Find Hits Ana", 1),
36  fDigiPar(NULL),
37  fGemHitArray(NULL),
38  fNofEvents(0),
39  fGridSize(10.),
40  // fStatBegHist(NULL),
41  // fGridHalfLen(NULL),
42  fHistoList(NULL),
43  fhFrontBackDiff(NULL)
44 {
45 }
46 // -------------------------------------------------------------------------
47 
48 // ----- Standard constructor ------------------------------------------
50  : FairTask("GEM Find Hits Ana", iVerbose) ,
51  fDigiPar(NULL),
52  fGemHitArray(NULL),
53  fNofEvents(0),
54  fGridSize(10.),
55  // fStatBegHist(NULL),
56  // fGridHalfLen(NULL),
57  fHistoList(NULL),
58  fhFrontBackDiff(NULL)
59 {
60 }
61 // -------------------------------------------------------------------------
62 
63 // ----- Standard constructor ------------------------------------------
65  : FairTask(taskName, iVerbose) ,
66  fDigiPar(NULL),
67  fGemHitArray(NULL),
68  fNofEvents(0),
69  fGridSize(10.),
70  // fStatBegHist(NULL),
71  // fGridHalfLen(NULL),
72  fHistoList(NULL),
73  fhFrontBackDiff(NULL)
74 {
75 }
76 // -------------------------------------------------------------------------
77 
78 // ----- Destructor ----------------------------------------------------
80 
81 // ----- Init -----------------------------------------------------------
83 
84  // Get and check FairRootManager
85  FairRootManager* ioman = FairRootManager::Instance();
86  if( !ioman ) {
87  cout << "-E- "<< GetName() <<"::Init: "
88  << "RootManager not instantised!" << endl;
89  return kERROR;
90  }
91 
92  // Get the pointer to the singleton FairRunAna object
93  FairRunAna* ana = FairRunAna::Instance();
94  if(NULL == ana) {
95  cout << "-E- "<< GetName() <<"::Init :"
96  <<" no FairRunAna object!" << endl;
97  return kERROR;
98  }
99  // Get the pointer to run-time data base
100  FairRuntimeDb* rtdb = ana->GetRuntimeDb();
101  if(NULL == rtdb) {
102  cout << "-E- "<< GetName() <<"::Init :"
103  <<" no runtime database!" << endl;
104  return kERROR;
105  }
106 
107  // Get Gem hit Array
108  fGemHitArray = (TClonesArray*) ioman->GetObject("GEMHit");
109  if ( !fGemHitArray ) {
110  cout << "-E- " << GetName() << "::Init: No PndGemHit array!" << endl;
111  return kERROR;
112  }
113 
114  // Get GEM digitisation parameter container
115  fDigiPar = (PndGemDigiPar*)(rtdb->getContainer("PndGemDetectors"));
116 
117  cout << "-I- " << fName.Data() << "::Init(). There are " << fDigiPar->GetNStations() << " GEM stations." << endl;
118  cout << "-I- " << fName.Data() << "::Init(). Initialization succesfull." << endl;
119 
120  fGridSize = 5.;
121  CreateHistos();
122 
123  return kSUCCESS;
124 }
125 // -------------------------------------------------------------------------
126 
127 // ----- Private method ReInit -----------------------------------------
129 
130  return kSUCCESS;
131 }
132 // -------------------------------------------------------------------------
133 
134 // ----- Private method SetParContainers -------------------------------
136 
137  // Get run and runtime database
138  FairRunAna* run = FairRunAna::Instance();
139  if ( ! run ) Fatal("SetParContainers", "No analysis run");
140 
141  FairRuntimeDb* db = run->GetRuntimeDb();
142  if ( ! db ) Fatal("SetParContainers", "No runtime database");
143 
144  // Get GEM digitisation parameter container
145  fDigiPar = (PndGemDigiPar*)(db->getContainer("PndGemDetectors"));
146 
147  fNofEvents = 0;
148 }
149 // -------------------------------------------------------------------------
150 
151 
152 // ----- Public method Exec --------------------------------------------
153 void PndGemFindHitsAna::Exec(Option_t*) {
154 
155  if ( fVerbose ) {
156  cout << "IN EVENT GOT " << fGemHitArray->GetEntries() << " hits." << endl;
157  cout << " - - - - - > " << fhFrontBackDiff->GetEntries() << " histograms" << endl;
158  }
159 
160  Int_t nofGemHits = fGemHitArray->GetEntries();
161 
162  PndGemHit* gemHit1 = NULL;
163  PndGemHit* gemHit2 = NULL;
164 
165  for ( Int_t igem1 = 0 ; igem1 < nofGemHits ; igem1++ ) {
166  gemHit1 = (PndGemHit*)fGemHitArray->At(igem1);
167  for ( Int_t igem2 = 0 ; igem2 < nofGemHits ; igem2++ ) {
168  gemHit2 = (PndGemHit*)fGemHitArray->At(igem2);
169 
170  if ( TMath::Abs( gemHit2->GetZ() - gemHit1->GetZ() - 2. ) < 2. ) {
171  Int_t quartId = 0;
172  if ( gemHit1->GetY() < 0. ) quartId += 2;
173  if ( gemHit1->GetX() < 0. ) quartId += 1;
174  Int_t histogramToFill =
175  fStatBegHist[gemHit1->GetStationNr()-1] +
176  fGridHalfLen[gemHit1->GetStationNr()-1]*fGridHalfLen[gemHit1->GetStationNr()-1]*quartId +
177  fGridHalfLen[gemHit1->GetStationNr()-1]*(Int_t(TMath::Abs(gemHit1->GetY())/fGridSize)) +
178  (Int_t(TMath::Abs(gemHit1->GetX())/fGridSize));
179 
180  ((TH2F*)fhFrontBackDiff->At(histogramToFill))->Fill(gemHit2->GetX()-gemHit1->GetX(),
181  gemHit2->GetY()-gemHit1->GetY());
182 
183  if ( fVerbose > 1 ) {
184  cout << "will compare " << gemHit1->GetX() << " " << gemHit1->GetY() << " " << gemHit1->GetZ() << endl
185  << " with " << gemHit2->GetX() << " " << gemHit2->GetY() << " " << gemHit2->GetZ() << endl;
186  cout << " IN STATION " << gemHit1->GetStationNr() << endl;
187  cout << " 1 : " << fStatBegHist[gemHit1->GetStationNr()-1] << endl;
188  cout << " 2 : " << fGridHalfLen[gemHit1->GetStationNr()-1]*fGridHalfLen[gemHit1->GetStationNr()-1]*quartId << endl;
189  cout << " 3 : " << fGridHalfLen[gemHit1->GetStationNr()-1]*(Int_t(gemHit1->GetY()/fGridSize)) << endl;
190  cout << " 4 : " << (Int_t(gemHit1->GetX()/fGridSize)) << endl;
191  cout << " histogram to fill " << histogramToFill << endl;
192  cout << " - - - - - > "
193  << fhFrontBackDiff->At(histogramToFill)->GetName() << " / \""
194  << fhFrontBackDiff->At(histogramToFill)->GetTitle() << "\"" << endl;
195  cout << "====================================================================================" << endl;
196  }
197  }
198  }
199  }
200 
201  fNofEvents++;
202 
203 }
204 // ------------------------------------------------------------
205 
206 
207 // ----- Private method CreateHistos --------------------------------------------
209  fHistoList = new TList();
210 
211  if ( fVerbose )
212  cout << "ought to create histogram for " << fDigiPar->GetNStations() << " stations." << endl;
213 
214  Int_t nofStations = fDigiPar->GetNStations();
215  Int_t nofHists = 0;
216 
217  fhFrontBackDiff = new TClonesArray("TH2F", 5000);
218 
219  for ( Int_t istat = 0 ; istat < nofStations ; istat++ ) {
220  //PndGemStation* station = (PndGemStation*)fDigiPar->GetStation(istat);
222 
223  if ( fVerbose )
224  cout << "sensor @ z = " << sensor->GetZ0() << " has an outer radius of " << sensor->GetOuterRadius() << endl;
225 
226  Int_t gridHalfLen = TMath::Ceil(sensor->GetOuterRadius()/fGridSize);
227  fStatBegHist.push_back(nofHists);
228  fGridHalfLen.push_back(gridHalfLen);
229 
230  if ( fVerbose )
231  cout << " --> the grid of " << fGridSize << "x" << fGridSize << "cm^2 requires " << 4*gridHalfLen*gridHalfLen << " histograms" << endl;
232 
233  for ( Int_t iquart = 0 ; iquart < 4 ; iquart++ ) {
234  for ( Int_t igry = 0 ; igry < gridHalfLen ; igry++ ) {
235  for ( Int_t igrx = 0 ; igrx < gridHalfLen ; igrx++ ) {
236  new ((*fhFrontBackDiff)[nofHists++]) TH2F(Form("fhFrontBackCorr_s%d_q%d_x%d_y%d",istat,iquart,igrx,igry),
237  Form("front back corr on station %d, x(%s%.1f:%s%.1f), y(%s%.1f:%s%.1f)",istat,
238  (iquart%2?"-":""),igrx*fGridSize,(iquart%2?"-":""),(igrx+1.)*fGridSize,
239  (iquart/2?"-":""),igry*fGridSize,(iquart/2?"-":""),(igry+1.)*fGridSize),
240  200,-1.,1.,
241  200,-1.,1.);
242  if ( fVerbose )
243  cout << nofHists-1 << ": histogram " << fhFrontBackDiff->At(nofHists-1)->GetName() << " / " << fhFrontBackDiff->At(nofHists-1)->GetTitle() << endl;
244  }
245  }
246  }
247 
248  new ((*fhFrontBackDiff)[nofHists++]) TH2F(Form("fhFrontBackDiffX_s%d",istat),
249  Form("front back X difference on station %d",istat),
250  2*gridHalfLen,-gridHalfLen*fGridSize,gridHalfLen*fGridSize,
251  2*gridHalfLen,-gridHalfLen*fGridSize,gridHalfLen*fGridSize);
252  new ((*fhFrontBackDiff)[nofHists++]) TH2F(Form("fhFrontBackDiffY_s%d",istat),
253  Form("front back Y difference on station %d",istat),
254  2*gridHalfLen,-gridHalfLen*fGridSize,gridHalfLen*fGridSize,
255  2*gridHalfLen,-gridHalfLen*fGridSize,gridHalfLen*fGridSize);
256  }
257 
258  if ( fVerbose ) {
259  cout << "HM, seems that fhFrontBackDiff is filled with histograms, and there are " << nofHists << " of them" << endl;
260 
261  cout << "fStatBegHist has " << fStatBegHist.size() << " entries:" << endl;
262  for ( size_t isbh = 0 ; isbh < fStatBegHist.size() ; isbh++ )
263  cout << " ---> " << fStatBegHist[isbh] << endl;
264  cout << "fGridHalfLen has " << fGridHalfLen.size() << " entries:" << endl;
265  for ( size_t ighl = 0 ; ighl < fGridHalfLen.size() ; ighl++ )
266  cout << " ---> " << fGridHalfLen[ighl] << endl;
267  }
268 
269 }
270 // ------------------------------------------------------------
271 
272 // ----- Private method AnaHistos --------------------------------------------
274 
275  Int_t nofStations = fDigiPar->GetNStations();
276 
277  Double_t quartX[4] = {1.,-1., 1.,-1.};
278  Double_t quartY[4] = {1., 1.,-1.,-1.};
279  for ( Int_t istat = 0 ; istat < nofStations ; istat++ ) {
280 
281  Int_t histCounter = fStatBegHist[istat];
282 
283  Int_t histogramToFill = fStatBegHist[istat] + 4*fGridHalfLen[istat]*fGridHalfLen[istat];
284 
285  for ( Int_t iquart = 0 ; iquart < 4 ; iquart++ ) {
286  for ( Int_t igry = 0 ; igry < fGridHalfLen[istat] ; igry++ ) {
287  for ( Int_t igrx = 0 ; igrx < fGridHalfLen[istat] ; igrx++ ) {
288  if ( ((TH2F*)(fhFrontBackDiff->At(histCounter)))->GetEntries() > 0 ) {
289  ((TH2F*)fhFrontBackDiff->At(histogramToFill+0))->Fill(quartX[iquart]*(fGridSize/2.+fGridSize*igrx),
290  quartY[iquart]*(fGridSize/2.+fGridSize*igry),
291  ((TH2F*)fhFrontBackDiff->At(histCounter))->GetMean(1));
292  ((TH2F*)fhFrontBackDiff->At(histogramToFill+1))->Fill(quartX[iquart]*(fGridSize/2.+fGridSize*igrx),
293  quartY[iquart]*(fGridSize/2.+fGridSize*igry),
294  ((TH2F*)fhFrontBackDiff->At(histCounter))->GetMean(2));
295  }
296  else {
297  ((TH2F*)fhFrontBackDiff->At(histogramToFill+0))->Fill(quartX[iquart]*(fGridSize/2.+fGridSize*igrx),
298  quartY[iquart]*(fGridSize/2.+fGridSize*igry),
299  -1111.);
300  ((TH2F*)fhFrontBackDiff->At(histogramToFill+1))->Fill(quartX[iquart]*(fGridSize/2.+fGridSize*igrx),
301  quartY[iquart]*(fGridSize/2.+fGridSize*igry),
302  -1111.);
303  }
304  histCounter++;
305  }
306  }
307  }
308  }
309 
310 }
311 // ------------------------------------------------------------
312 
313 // ----- Private method Finish --------------------------------------------
315  cout << "-------------------- PndGemFindHitsAna : Summary ------------------" << endl;
316  cout << " Events: " << setw(10) << fNofEvents << endl;
317  cout << "---------------------------------------------------------------------" << endl;
318 
319  AnaHistos();
320 
321  TFile* temp = gFile;
322  FairRootManager* ioman = FairRootManager::Instance();
323  gFile = ioman->GetOutFile();
324  gDirectory = (TDirectory*)gFile;
325 
326  gDirectory->mkdir("GemFindHitsAna");
327  gDirectory->cd("GemFindHitsAna");
328  TIter next(fHistoList);
329  for ( Int_t ihist = 0 ; ihist < fhFrontBackDiff->GetEntries() ; ihist++ ) {
330  fhFrontBackDiff->At(ihist)->Write();
331  }
332  // while ( TH1* histo = ((TH1*)next()) ) histo->Write();
333  gDirectory->cd("..");
334 
335  gFile = temp;
336 
337 }
338 // ------------------------------------------------------------
339 
340 
analyze found GEM hits
int fVerbose
Definition: poormantracks.C:24
Int_t run
Definition: autocutx.C:47
PndGemDigiPar * fDigiPar
PndTransMap * map
Definition: sim_emc_apd.C:99
TGeoVolume * sensor
Int_t fNofEvents
event counter
Digitization Parameter Class for GEM part.
Definition: PndGemDigiPar.h:31
static T Abs(const T &x)
Definition: PndCAMath.h:39
PndGemSensor * GetSensor(Int_t stationNr, Int_t sensorNr)
Double_t
TClonesArray * fhFrontBackDiff
std::vector< Int_t > fStatBegHist
virtual InitStatus ReInit()
virtual void Exec(Option_t *opt)
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
Int_t GetNStations()
Definition: PndGemDigiPar.h:45
Int_t GetStationNr() const
Definition: PndGemHit.h:81
TClonesArray * fGemHitArray
virtual InitStatus Init()
ClassImp(PndAnaContFact)
std::vector< Int_t > fGridHalfLen
Int_t iVerbose
Double_t GetZ0() const
Definition: PndGemSensor.h:100
Double_t GetOuterRadius() const
Definition: PndGemSensor.h:103
h1 Fill(hit_theta-point_theta)
static int next[96]
Definition: ranlxd.cxx:374
virtual void SetParContainers()