FairRoot/PandaRoot
PndDrcLutReco.cxx
Go to the documentation of this file.
1 // -----------------------------------------
2 // PndDrcLutReco.cpp
3 //
4 // Created on: 13.07.2013
5 // Author: R.Dzhygadlo at gsi.de
6 // -----------------------------------------
7 
8 #include "PndDrcLutReco.h"
9 
10 #include "FairRootManager.h"
11 #include "PndMCTrack.h"
12 #include "PndDrcPDPoint.h"
13 #include "PndDrcHit.h"
14 #include "PndDrcPDHit.h"
15 #include "PndDrcLutNode.h"
16 
17 #include "PndGeoHandling.h"
18 #include "TRandom.h"
19 #include "TSystem.h"
20 
21 #include "TCanvas.h"
22 
23 using std::cout;
24 using std::endl;
25 
26 // ----- Default constructor -------------------------------------------
27 PndDrcLutReco::PndDrcLutReco() : FairTask("PndDrcLutReco"){
28  fInputFile = "luttab.root";
29 }
30 
31 // ----- Standard constructors -----------------------------------------
33  :FairTask("PndDrcLutReco",verbose){
34  fVerbose = verbose;
35  fInputFile = "luttab.root";
36 }
37 
39  :FairTask("PndDrcLutReco",verbose){
40  fVerbose = verbose;
41  fInputFile = infilename;
42 }
43 
44 // ----- Destructor ----------------------------------------------------
46 
47 }
48 
49 // ----- Initialization ------------------------------------------------
50 InitStatus PndDrcLutReco::Init(){
51  cout << " ---------- INITIALIZATION ------------" << endl;
52  nevents = -1;
53  // Get RootManager
54  FairRootManager* ioman = FairRootManager::Instance();
55  if ( ! ioman ) {
56  cout << "-E- PndDrcLutReco::Init: " << "RootManager not instantiated!" << endl;
57  return kFATAL;
58  }
59 
60  // Get input array
61  fMCArray = (TClonesArray*) ioman->GetObject("MCTrack");
62  if ( ! fMCArray ) {
63  cout << "-W- PndDrcLutReco::Init: " << "No MCTrack array!" << endl;
64  return kERROR;
65  }
66 
67  // Get bar points array
68  fBarPointArray = (TClonesArray*) ioman->GetObject("DrcBarPoint");
69  if ( ! fBarPointArray ) {
70  cout << "-W- PndDrcLutReco::Init: " << "No DrcBarPoint array!" << endl;
71  return kERROR;
72  }
73 
74  // Get ev points array
75  fEVPointArray = (TClonesArray*) ioman->GetObject("DrcEVPoint");
76  if ( ! fEVPointArray ) {
77  cout << "-W- PndDrcLutReco::Init: " << "No DrcEVPoint array!" << endl;
78  return kERROR;
79  }
80 
81  // Get Photon point array
82  fPDPointArray = (TClonesArray*) ioman->GetObject("DrcPDPoint");
83  if ( ! fPDPointArray ) {
84  cout << "-W- PndDrcLutReco::Init: " << "No DrcPDPoint array!" << endl;
85  return kERROR;
86  }
87  // // Get digi array
88  // fDigiArray = (TClonesArray*) ioman->GetObject("DrcDigi");
89  // if ( ! fDigiArray ) {
90  // cout << "-W- PndDrcLutReco::Init: " << "No DrcDigi array!" << endl;
91  // return kERROR;
92  // }
93  // Get input array
94  fPDHitArray = (TClonesArray*) ioman->GetObject("DrcPDHit");
95  if ( ! fPDHitArray ) {
96  cout << "-W- PndDrcLutReco::Init: " << "No DrcPDHit array!" << endl;
97  return kERROR;
98  }
99 
101  name.Remove(0,name.Last('/')+1);
102  sscanf(name, "lut_e%d_b%d_l%d", &fEvType,&fRadType,&fLensType);
103 
104  fFile = new TFile(fInputFile);
105  fTree=(TTree *) fFile->Get("dircsim") ;
106  for(Int_t l=0; l<5; l++){
107  fLut[l] = new TClonesArray("PndDrcLutNode");
108  fTree->SetBranchAddress(Form("LUT%d",l),&fLut[l]);
109  }
110  fTree->GetEntry(0);
111 
112  // Create and register output array
113  fDrcTrackInfoArray = new TClonesArray("PndDrcTrackInfo");
114  ioman->Register("DrcTrackInfo","Drc",fDrcTrackInfoArray, kTRUE);
115 
116  fGeo = new PndGeoDrc();
117  fBboxNum = fGeo->BBoxNum();
119  Double_t barwidth = fGeo->BarWidth();
120  if(fRadType==3) barwidth = 5.41333;
121  fBarPhi = 2*atan(((barwidth + fGeo->barhGap())/2.)/fGeo->radius())*180/TMath::Pi();
122  fDphi = 2.*(180. - 2*fPipehAngle)/(Double_t)fGeo->BBoxNum();
123 
124  fHist = new TH1F("chrenkov_angle_hist","chrenkov_angle_hist", 100,0.4,0.9);
125  // fHist2 = new TH1F("chrenkov_angle_hist2","chrenkov_angle_hist2", 100,0.35,0.85);
126  fHist2 = new TH1F("chrenkov_angle_hist2","", 400,-30,30);
127  fFit = new TF1("fgaus","[0]*exp(-0.5*((x-[1])/[2])*(x-[1])/[2])",0.35,0.85);
128  fSpect = new TSpectrum(10);
129 
130  cout << "-I- PndDrcLutReco: Intialization successfull" << endl;
131  return kSUCCESS;
132 }
133 
134 // ----- Execution of Task ---------------------------------------------
135 void PndDrcLutReco::Exec(Option_t*){
136  nevents++;
137  fDetectorID = 0;
138  if ( ! fDrcTrackInfoArray ) Fatal("Exec", "No fDrcTrackInfoArray");
139  fDrcTrackInfoArray->Clear();
140  Int_t nHits = fPDHitArray->GetEntriesFast();
141  if(fVerbose>1) std::cout<<"Event # "<< nevents<<" has "<<nHits<<" hits."<< std::endl;
142  else if(fVerbose==1 && nevents%100==0) std::cout<<"Event # "<< nevents<<" has "<<nHits<<" hits."<< std::endl;
143 
145 }
146 
148  TVector3 momInBar, posInBar;
149 
150  for(Int_t itrack=0; itrack<fMCArray->GetEntriesFast(); itrack++){
151  fMCTrack = (PndMCTrack*)fMCArray->At(itrack);
152  if( fMCTrack->GetMotherID() != -1) continue;
153 
154  Int_t mcBoxId(-1); //mcBarId, //[R.K.03/2017] unused variable
155  for(int i=0; i<fBarPointArray->GetEntriesFast(); i++){
157  if(itrack == fBarPoint->GetTrackID()){
158  mcBoxId = fBarPoint->GetBoxId();
159  break;
160  }
161  }
162  if(mcBoxId == -1) {
163  std::cout<<"mcBoxId "<<mcBoxId <<std::endl;
164  continue;
165  }
166  fBarPoint->Momentum(momInBar);
167  fBarPoint->Position(posInBar);
168  //mcBarId = fBarPoint->GetBarId(); //[R.K.03/2017] unused variable
169 
170  PndDrcTrackInfo trackinfo;
171  trackinfo.SetMcMomentum(fMCTrack->GetMomentum());
172  trackinfo.SetMcPdg(fMCTrack->GetPdgCode());
173  trackinfo.SetMcCherenkov( fBarPoint->GetThetaC());
174  trackinfo.SetMcMomentumInBar(momInBar);
175  trackinfo.SetMcPositionInBar(posInBar);
176  trackinfo.SetMcTimeInBar(fBarPoint->GetTime());
177 
178  if(fVerbose<2) gROOT->SetBatch(kTRUE);
179  DetermineCherenkov(&trackinfo,mcBoxId);
180  if(fVerbose<2) gROOT->SetBatch(kFALSE);
181  // std::cout<<"dCh = "<< trackinfo.GetMcCherenkov()-trackinfo.GetCherenkov()
182  // << " pdg = "<< trackinfo.GetPdg()<<std::endl;
183 
184  new ((*fDrcTrackInfoArray)[fDrcTrackInfoArray->GetEntriesFast()]) PndDrcTrackInfo(trackinfo);
185  }
186 }
187 
189 
190  TVector3 momInBar = trackinfo->GetMcMomentumInBar();
191  TVector3 posInBar = trackinfo->GetMcPositionInBar();
192  Double_t barHitTime = trackinfo->GetMcTimeInBar();
193  Double_t boxPhi;//, cangle, bartime, lutboxPhi=10.825, window1, window2, angdiv; //[R.K. 01/2017] unused variable?
194  Int_t lutboxId(3), barId(-1), evpointcount(0);
195  Bool_t reflected;
196  Int_t boxId1;
197 
198  DetermineBarId(posInBar.Phi(),boxPhi, boxId1, barId);
199 
200  if(barId<0) return;
201  momInBar.RotateZ(-boxPhi/180.*TMath::Pi());
202 
203 
204  // window1 = (mcboxId)*17-17;
205  // window2 = (mcboxId+1)*17+17;
206 
207  // Loop over PndDrcPDHits
208  for(Int_t ihit=0; ihit<fPDHitArray->GetEntriesFast(); ihit++) {
209  fPDHit = (PndDrcPDHit*)fPDHitArray->At(ihit);
210  //Int_t wsensorId = fPDHit->GetSensorId()/100; //[R.K. 01/2017] unused variable?
211  // if(wsensorId < window1 || wsensorId > window2) continue;
212 
213  Int_t sensorId = fPDHit->GetSensorId();
214  Double_t pdHitTime = fPDHit->GetTime();
215 
216  //((FairMultiLinkedData*)fPDHit)->Print();
217  Int_t pointID = fPDHit->GetLink(1).GetIndex();
218  Int_t eventID = fPDHit->GetLink(1).GetEntry();
219 
220  if(eventID != nevents) continue;
221  if( fPDPointArray->GetEntriesFast()<= pointID ){
222  std::cout<<" name "<< FairRootManager::Instance()->GetBranchName(fPDHit->GetLink(1).GetType()) <<std::endl;
223  std::cout<<"ERROR 83 " << pointID <<" out of " <<fPDPointArray->GetEntriesFast() <<" "<< eventID<<"/"<<nevents<<std::endl;
224  continue;
225  }
226 
227  fPDPoint = (PndDrcPDPoint*)fPDPointArray->At(pointID);
228 
229  Int_t trackID = fPDPoint->GetTrackID();
230  evpointcount = 0;
231  for(int i=0; i<fEVPointArray->GetEntriesFast(); i++){
233  if(trackID == fEVPoint->GetTrackID()) evpointcount++;
234  }
235  if(((PndMCTrack*)fMCArray->At(trackID))->GetMomentum().Z()>0) reflected = kTRUE;
236  else reflected = kFALSE;
237 
238  Int_t recalculatedSensorId = sensorId;
239  if(fEvType<3) recalculatedSensorId = (sensorId/100 - (boxId - lutboxId)*17)*100 + sensorId%100; // for tank EV
240 
241  if(sensorId>27200 || recalculatedSensorId>27200 || recalculatedSensorId <0) {
242  std::cout<<"LUT reco: ignore vertical MCPblock for now. sensorId = "<<sensorId
243  << " recalculatedSensorId = "<< recalculatedSensorId <<std::endl;
244  continue;
245  }
246 
247  PndDrcPhotonInfo photoninfo;
248  photoninfo.SetMcPrimeMomentumInBar(momInBar);
249  photoninfo.SetHitTime(pdHitTime);
250  photoninfo.SetReflected(reflected);
251  photoninfo.SetEvReflections(evpointcount);
252  FillAmbiguities(&photoninfo, barId, recalculatedSensorId, posInBar.Z()+119, barHitTime);
253  trackinfo->AddPhoton(photoninfo);
254  }
255 
256  Double_t cherenkovreco = FindPeak();
257  Int_t pdgreco = FindPdg(momInBar.Mag(), cherenkovreco);
258 
259  trackinfo->SetPdg(pdgreco);
260  trackinfo->SetCherenkov(cherenkovreco);
261 }
262 
263 void PndDrcLutReco::FillAmbiguities(PndDrcPhotonInfo *photoninfo, Int_t barId, Int_t recalculatedSensorId, Double_t lenz, Double_t barHitTime){
264  TVector3 dird, dir,
265  fnX1 = TVector3(1,0,0),
266  fnY1 = TVector3(0,1,0),
267  momInBar = photoninfo->GetMcPrimeMomentumInBar();
268 
269  Double_t evtime, bartime, luttheta, tangle;
270  Double_t reflected = photoninfo->GetReflected();
271  Double_t pdHitTime = photoninfo->GetHitTime();
272  Double_t criticalAngle = asin(1.00028/fGeo->nQuartz());
273  if(reflected) lenz = 2*240 - lenz;
274 
275  PndDrcLutNode *node = (PndDrcLutNode*) fLut[barId]->At(recalculatedSensorId);
276  Int_t size = node->Entries();
277 
278  for(int i=0; i<size; i++){
279  dird = node->GetEntry(i);
280 
281  //dird.RotateZ(-lutboxPhi/180.*TMath::Pi());
282 
283  evtime = node->GetTime(i);
284  for(int u=0; u<4; u++){
285  if(u == 0) dir = dird;
286  if(u == 1) dir.SetXYZ(-dird.X(), dird.Y(), dird.Z());
287  if(u == 2) dir.SetXYZ( dird.X(),-dird.Y(), dird.Z());
288  if(u == 3) dir.SetXYZ(-dird.X(),-dird.Y(), dird.Z());
289  if(reflected) dir.SetXYZ( dir.X(), dir.Y(),-dir.Z());
290 
291  if(dir.Angle(fnX1) < criticalAngle || dir.Angle(fnY1) < criticalAngle) continue;
292 
293  luttheta = dir.Theta();
294  if(luttheta > TMath::Pi()/2.) luttheta = TMath::Pi()-luttheta;
295  bartime = lenz/cos(luttheta)/19.8;
296 
297  if(fabs((bartime + evtime)-(pdHitTime-barHitTime))>1.5) continue;
298  tangle = momInBar.Angle(dir);
299  //if(tangle>TMath::Pi()/2.) tangle = TMath::Pi()-tangle;
300 
301  PndDrcAmbiguityInfo ambinfo;
302  ambinfo.SetBarTime(bartime);
303  ambinfo.SetEvTime(evtime);
304  ambinfo.SetCherencov(tangle);
305 
306  photoninfo->AddAmbiguity(ambinfo);
307  if(tangle > 0.4 && tangle < 0.9) fHist->Fill(tangle);
308  }
309  }
310 }
311 
312 void PndDrcLutReco::DetermineBarId(Double_t phi, Double_t &boxPhi, Int_t &, Int_t &barId){ // boxId //[R.K.03/2017] unused variable(s)
313  Double_t startPhi = phi/TMath::Pi()*180;
314  if(startPhi < 0) startPhi = 360 + startPhi;
315  if(startPhi >= 0 && startPhi < 90) boxPhi = TMath::Floor(startPhi/fDphi) *fDphi + fDphi/2.;
316  if(startPhi >= 90 && startPhi < 270) boxPhi = 90 + fPipehAngle + TMath::Floor((startPhi-90-fPipehAngle)/fDphi) *fDphi + fDphi/2.;
317  if(startPhi >= 270 && startPhi < 360) boxPhi = 270 + fPipehAngle + TMath::Floor((startPhi-270-fPipehAngle)/fDphi) *fDphi + fDphi/2.;
318 
319  if(fRadType==5) barId = (int) (2.5 + (boxPhi-startPhi)/fBarPhi);
320  if(fRadType==3) barId = (int) (1.5 + (boxPhi-startPhi)/fBarPhi);
321  if(barId>4 || barId<0){
322  std::cout<<"Error in PndDrcLutReco: Bar Id is wrong. barId = "<< barId <<std::endl;
323  barId = -1;
324  }
325  std::cout<<"phi="<<phi<<" boxPhi "<<boxPhi<<" startPhi " <<startPhi<<" 8235fBarPhi "<<fBarPhi<<std::endl;
326 
327 }
328 
329 Int_t g_num =0;
331  Double_t cherenkovreco = -1;
332 
333  if(fHist->GetEntries()>20 ){
334  TCanvas* c = new TCanvas("c","c",0,0,800,600);
335  Int_t nfound = fSpect->Search(fHist,1,"",0.6);
336  Float_t *xpeaks = (Float_t*)fSpect->GetPositionX();
337  if(nfound>0) cherenkovreco = xpeaks[0];
338  fFit->SetParameter(1,cherenkovreco); // peak
339  fFit->SetParameter(2,0.01); // width
340  fHist->Fit("fgaus","Q","",cherenkovreco-0.02,cherenkovreco+0.02);
341  cherenkovreco = fFit->GetParameter(1);
342  std::cout<<"sigma "<< fFit->GetParameter(2) <<std::endl;
343 
344  if(cherenkovreco<0 || cherenkovreco>1 ) cherenkovreco = 0;
345 
346  if(fVerbose>1){
347  fHist->GetXaxis()->SetTitle("#theta_{C}, [rad]");
348  fHist->GetYaxis()->SetTitle("Entries, [#]");
349  fHist->Draw();
350  // fHist2->SetLineColor(4);
351  // fHist2->Draw("same");
352  c->Modified();
353  c->Update();
354  c->WaitPrimitive();
355  // c->Print(Form("pic/animpid/animpid_%d.png",g_num++));
356  }
357  }
358  fHist2->Reset();
359  fHist->Reset();
360 
361  return cherenkovreco;
362 }
363 
365  Int_t pdg[]={11,13,211,321,2212};
366  Double_t mass[] = {0.000511,0.1056584,0.139570,0.49368,0.9382723};
367  Double_t tdiff, diff=100;
368  Int_t minid=0;
369  for(Int_t i=0; i<5; i++){
370  tdiff = fabs(cangle - acos(sqrt(mom*mom + mass[i]*mass[i])/mom/1.46907)); //1.46907 - fused silica
371  if(tdiff<diff){
372  diff = tdiff;
373  minid = i;
374  }
375  }
376  return pdg[minid];
377 }
378 
379 // ----- Finish Task ---------------------------------------------------
381  for(Int_t l=0; l<5; l++){
382  fLut[l]->Clear();
383  }
384  cout << "-I- PndDrcLutReco: Finish" << endl;
385 }
386 
void SetMcCherenkov(Double_t val)
friend F32vec4 acos(const F32vec4 &a)
Definition: P4_F32vec4.h:113
TClonesArray * fDrcTrackInfoArray
Definition: PndDrcLutReco.h:77
friend F32vec4 cos(const F32vec4 &a)
Definition: P4_F32vec4.h:112
void SetPdg(Int_t val)
void SetEvReflections(Int_t val)
TClonesArray * fEVPointArray
Definition: PndDrcLutReco.h:72
Double_t fBboxNum
Definition: PndDrcLutReco.h:68
Double_t BBoxNum()
Definition: PndGeoDrc.h:136
Int_t i
Definition: run_full.C:25
Int_t GetSensorId()
Definition: PndDrcPDHit.h:59
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
Int_t GetPdgCode() const
Definition: PndMCTrack.h:73
TSpectrum * fSpect
#define verbose
Double_t BarWidth()
Definition: PndGeoDrc.h:100
virtual ~PndDrcLutReco()
void DetermineBarId(Double_t phi, Double_t &boxPhi, Int_t &boxId, Int_t &barId)
TClonesArray * fPDHitArray
Definition: PndDrcLutReco.h:75
TVector3 GetMomentum() const
Definition: PndMCTrack.h:78
Double_t mom
Definition: plot_dirc.C:14
void SetMcMomentum(TVector3 val)
virtual void Finish()
TClonesArray * fMCArray
Definition: PndDrcLutReco.h:70
void LoopOverMcTracks()
Double_t GetThetaC() const
PndDrcPDHit * fPDHit
Definition: PndDrcLutReco.h:87
Double_t fBarPhi
Definition: PndDrcLutReco.h:68
virtual Double_t GetTime()
Definition: PndDrcPDHit.h:55
virtual void Exec(Option_t *option)
cout<< "blue = Monte Carlo "<< endl;cout<< "red = Helix Hit "<< endl;cout<< "green = Center Of Tubes "<< endl;for(Int_t k=0;k< track->GetEntriesFast();k++){PndSttTrack *stttrack=(PndSttTrack *) track-> At(k)
Definition: checkhelixhit.C:56
TClonesArray * fPDPointArray
Definition: PndDrcLutReco.h:73
Double_t PipehAngle()
Definition: PndGeoDrc.h:139
void SetEvTime(Double_t val)
PndDrcEVPoint * fEVPoint
Definition: PndDrcLutReco.h:84
void SetReflected(Bool_t val)
int nHits
Definition: RiemannTest.C:16
Int_t GetBoxId() const
Double_t
TClonesArray * fBarPointArray
Definition: PndDrcLutReco.h:71
void FillAmbiguities(PndDrcPhotonInfo *photoninfo, Int_t barId, Int_t recalculatedSensorId, Double_t directz, Double_t barHitTime)
void SetBarTime(Double_t val)
Double_t GetMcTimeInBar()
Double_t nQuartz()
Definition: PndGeoDrc.h:70
void AddAmbiguity(PndDrcAmbiguityInfo ambiguity)
TVector3 GetMcPositionInBar()
Int_t FindPdg(Double_t mom, Double_t cangle)
void AddPhoton(PndDrcPhotonInfo photon)
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
PndMCTrack * fMCTrack
Definition: PndDrcLutReco.h:82
TString fInputFile
Definition: PndDrcLutReco.h:95
TVector3 GetEntry(Int_t entry)
Definition: PndDrcLutNode.h:39
TString name
Double_t fDphi
Definition: PndDrcLutReco.h:68
TVector3 GetMcMomentumInBar()
Double_t barhGap()
Definition: PndGeoDrc.h:112
Double_t fPipehAngle
Definition: PndDrcLutReco.h:68
TClonesArray * fLut[5]
Definition: PndDrcLutReco.h:76
Double_t GetTime(Int_t entry)
Definition: PndDrcLutNode.h:42
void SetMcPositionInBar(TVector3 val)
Int_t Entries()
Definition: PndDrcLutNode.h:36
void SetMcPrimeMomentumInBar(TVector3 val)
virtual InitStatus Init()
Double_t GetHitTime()
PndDrcBarPoint * fBarPoint
Definition: PndDrcLutReco.h:83
ClassImp(PndAnaContFact)
PndGeoDrc * fGeo
Definition: PndDrcLutReco.h:66
void SetCherencov(Double_t val)
void SetCherenkov(Double_t val)
void SetMcTimeInBar(Double_t val)
void SetMcMomentumInBar(TVector3 val)
Int_t GetMotherID() const
Definition: PndMCTrack.h:74
void SetHitTime(Double_t val)
Double_t Pi
PndDrcPDPoint * fPDPoint
Definition: PndDrcLutReco.h:85
void SetMcPdg(Int_t val)
void DetermineCherenkov(PndDrcTrackInfo *trackinfo, Int_t boxId)
Double_t FindPeak()
TVector3 GetMcPrimeMomentumInBar()
Double_t radius()
Definition: PndGeoDrc.h:92
Int_t g_num