FairRoot/PandaRoot
PndDrcRecoLookupMapS.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndDrcRecoLookupMapS source file -----
3 // ----- Created 10/11/10 by Maria Patsyuk -----
4 // ----- -----
5 // ----- -----
6 // -------------------------------------------------------------------------
7 #include <fstream>
8 #include <iostream>
9 #include "stdio.h"
10 
11 #include "PndGeoDrc.h"
12 #include "PndDrcRecoLookupMapS.h"
13 #include "FairRootManager.h"
14 #include "PndMCTrack.h"
15 #include "PndDrcBarPoint.h"
16 #include "PndDrcPDPoint.h"
17 #include "PndDrcHit.h"
18 #include "PndDrcPDHit.h"
19 #include "TVector3.h"
20 #include "TRandom.h"
21 #include "FairRunAna.h"
22 #include "FairRuntimeDb.h"
23 #include "FairBaseParSet.h"
24 #include "FairGeoVolume.h"
25 #include "TString.h"
26 #include "FairGeoTransform.h"
27 #include "FairGeoVector.h"
28 #include "FairGeoMedium.h"
29 #include "FairGeoNode.h"
30 
31 #include "PndGeoDrcPar.h"
32 #include "TFormula.h"
33 #include "TMath.h"
34 #include "TParticlePDG.h"
35 #include "TDatabasePDG.h"
36 #include "TPDGCode.h"
37 #include "TGeoManager.h"
38 #include "TCanvas.h"
39 #include "TFile.h"
40 #include "TLegend.h"
41 #include "TStyle.h"
42 #include "TF1.h"
43 #include "TExec.h"
44 #include "TLine.h"
45 #include "TPolyLine.h"
46 //#include "PndChPho.h"
47 #include "PndDrcLutInfo.h"
48 #include "PndDrcDigiPar.h"
49 #include "TVectorD.h"
50 
51 using std::endl;
52 using std::cout;
53 
54 // ----- Default constructor -------------------------------------------
56 :FairTask("PndDrcRecoLookupMapS")
57 {
58  fGeo = new PndGeoDrc();
59  fGeoH=NULL;
60  fDigiPar = NULL;
61 }
62 // ----- Standard constructor with verbosity level -------------------------------------------
63 
65  :FairTask("PndDrcRecoLookupMapS")
66 {
67  fVerbose = verbose;
68  fGeo = new PndGeoDrc();
69  fGeoH=NULL;
70  fDigiPar = NULL;
71 }
72 // ----- Destructor ----------------------------------------------------
74 {
75  if (fGeo) delete fGeo;
76  if (fGeoH) delete fGeoH;
77  fHistoList->Delete();
78  delete fHistoList;
79 }
80 
81 // ----- Initialization -----------------------------------------------
83 {
84  cout << " ---------- INITIALIZATION ------------" << endl;
85  nevents = 0;
86  // Get RootManager
87  FairRootManager* ioman = FairRootManager::Instance();
88  if ( ! ioman ) {
89  cout << "-E- PndDrcRecoLookupMapS::Init: "
90  << "RootManager not instantiated!" << endl;
91  return kFATAL;
92  }
93 
94  // Get input array
95  fMCArray = (TClonesArray*) ioman->GetObject("MCTrack");
96  if ( ! fMCArray ) {
97  cout << "-W- PndDrcRecoLookupMapS::Init: "
98  << "No MCTrack array!" << endl;
99  return kERROR;
100  }
101  // Get input array
102  fBarPointArray = (TClonesArray*) ioman->GetObject("DrcBarPoint");
103  if ( ! fBarPointArray ) {
104  cout << "-W- PndDrcRecoLookupMapS::Init: "
105  << "No DrcBarPoint array!" << endl;
106  return kERROR;
107  }
108  // Get Photon point array
109  fPDPointArray = (TClonesArray*) ioman->GetObject("DrcPDPoint");
110  if ( ! fPDPointArray ) {
111  cout << "-W- PndDrcRecoLookupMapS::Init: "
112  << "No DrcPDPoint array!" << endl;
113  return kERROR;
114  }
115 /* // Get input array
116  fHitArray = (TClonesArray*) ioman->GetObject("DrcHit");
117  if ( ! fHitArray ) {
118  cout << "-W- PndDrcRecoLookupMapS::Init: "
119  << "No DrcHit array!" << endl;
120  return kERROR;
121  }
122 */
123 
124  // Get digi array
125  fDigiArray = (TClonesArray*) ioman->GetObject("DrcDigi");
126  if ( ! fDigiArray ) {
127  cout << "-W- PndDrcRecoLookupMapS::Init: " << "No DrcDigi array!" << endl;
128  return kERROR;
129  }
130 
131  // Get input array
132  fPDHitArray = (TClonesArray*) ioman->GetObject("DrcPDHit");
133  if ( ! fPDHitArray ) {
134  cout << "-W- PndDrcRecoLookupMapS::Init: "
135  << "No DrcPDHit array!" << endl;
136  return kERROR;
137  }
138 
139  // Create and register output array
140  // fChPhoArray = new TClonesArray("PndChPho");
141  // ioman->Register("ChPho","Drc",fChPhoArray, kTRUE);
142  fDrcLutInfoArray = new TClonesArray("PndDrcLutInfo");
143  ioman->Register("DrcLutInfo","Drc",fDrcLutInfoArray, kTRUE);
144 
145  // Get parameters:
146  fpi = TMath::Pi();
147 
148  fR = fGeo->radius();
149  fzup = fGeo->barBoxZUp();
150  fzdown = fGeo->barBoxZDown();
152  fBboxNum = fGeo->BBoxNum();
153  fBarNum = fGeo->barNum();
155  fBarBoxGap = fGeo->BBoxGap();
156  //fLength = (180. - 2.*fPipehAngle - fBarBoxGap/fR*(fBboxNum/2. - 1.)/fpi*180.)/(fBboxNum/2.) * fR/ 180.*fpi;
157  fDphi = 2.*(180. - 2*fPipehAngle)/ fBboxNum; //[degrees]
158  fLSide = fGeo->Lside();//(180. - 2.*fPipehAngle - fBarBoxGap/fR*(fBboxNum/2. - 1.)/fpi*180.)/(fBboxNum/2.) * fR/ 180.*fpi;
159  fBarWidth = fGeo->BarWidth();//fLSide/fBarNum;
160 
161  // vectors of bar surfaces:
162  fnX1.SetXYZ(-1., 0.,0.);
163  fnY1.SetXYZ( 0., 1.,0.);
164 
165  cout << "-I- PndDrcRecoLookupMapS: Intialization successfull" << endl;
166  CreateHisto();
167  return kSUCCESS;
168 
169 }
170 
171 // ----- Private method SetParContainers -------------------------------
173 
174  // Get run and runtime database
175  FairRunAna* run = FairRunAna::Instance();
176  if ( ! run ) Fatal("SetParContainers", "No analysis run");
177 
178  FairRuntimeDb* db = run->GetRuntimeDb();
179  if ( ! db ) Fatal("SetParContainers", "No runtime database");
180 
181  // Get DIRC digitisation parameter container
182  fDigiPar = (PndDrcDigiPar*)(db->getContainer("DIRCLookupTable"));
183  cout << "-I- PndDrcRecoLookupMapS::SetParContainers(). read parameters" << endl;
184  cout<<"read them!"<<endl;
185  //cout << "-I- PndDrcRecoLookupMapS: Number of hit pixels "<< fDigiPar->GetNHitPixels()<< endl;
186  cout << "-I- PndDrcRecoLookupMapS: Number of hit pixels "<< fDigiPar->GetNAmbiguities()<< endl;
187 
188  if ( fGeoH == NULL ) fGeoH = PndGeoHandling::Instance();
190  if(fVerbose>1) Info("SetParContainers","done.");
191  return;
192 }
193 // -------------------------------------------------------------------------
194 
195 // ----- Execution of Task ---------------------------------------------
196 void PndDrcRecoLookupMapS::Exec(Option_t*ion)
197 {
198  //if ( ! fChPhoArray ) Fatal("Exec", "No fChPhoArray");
199  //fChPhoArray->Clear();
201 
202  nevents++;
203  fDetectorID = 0;
204 
205  cout<<"EVENT # "<<nevents<<endl;
206  // fNHits = 0;
207  //ProcessBarHit();
209  //ProcessPhotonMC();
210 }
211 
212 //--------------Process Photon MC Points----------------------------------------------------
214 {
215  if (fVerbose > 0) {
216  cout <<"PndDrcRecoLookupMapS: Number of Detected MC Tracks : "<<fMCArray->GetEntries()<<endl;
217  PndMCTrack* ptr = NULL;
218  PndMCTrack* trMr=NULL;
219 
220  }
221 }
222 //--------------Process Bar Hits----------------------------------------------------
224 {
225  PndDrcBarPoint* pt=NULL;
226  PndDrcHit* hit=NULL;
227  PndMCTrack* tr = NULL;
228 
229  for(Int_t j=0; j<fHitArray->GetEntriesFast(); j++) {
230  hit = (PndDrcHit*)fHitArray->At(j);
231  Int_t mcRef= hit->GetRefIndex();
232  pt= (PndDrcBarPoint*)fBarPointArray->At(mcRef);
233 
234  Int_t chtrID= pt->GetTrackID();
235  tr = (PndMCTrack*)fMCArray->At(chtrID);
236 
237  cout<<"nother track px = "<<pt->GetPx()<<", py = "<<pt->GetPy()<<endl;
238 
239  }
240 }
241 
242 //--------------Process Photon Hits----------------------------------------------------
244 {
245  //Int_t nofChPho = 0;
246  fDrcLutInfoArray->Clear();
247  PndDrcLutInfo lutinfo;
248 
249  PndDrcPDPoint* Ppt=NULL;
250  PndDrcPDHit* pdhit=NULL;
251  PndMCTrack* tr = NULL;
252  PndMCTrack* trMr;
253 
254  if (fVerbose > 0) {
255  cout <<"PndDrcRecoLookupMapS: Number of Detected Photon MCPDPoints : "<<fPDPointArray->GetEntries()<<endl;
256  cout <<"PndDrcRecoLookupMapS: Number of Detected Photon PDHits : "<<fPDHitArray->GetEntries()<<endl;
257  }
258 
259  // Loop over PndDrcPDHits
260  for(Int_t k=0; k<fPDHitArray->GetEntriesFast(); k++) {
261 
262  pdhit = (PndDrcPDHit*)fPDHitArray->At(k);
263 
264  Int_t mcPDRef= pdhit->GetRefIndex();
265 
266  if(mcPDRef < 0)continue;
267  Ppt = (PndDrcPDPoint*)fPDPointArray->At(mcPDRef);
268 
269  if(Ppt->GetBarPointID() < 0) continue;
270  PndDrcBarPoint *fBarPoint= (PndDrcBarPoint*)fBarPointArray->At(Ppt->GetBarPointID());
271  fBarId = fBarPoint->GetDetectorID();
272  if(fBarId < 0)continue;
273  //cout<<"bar name - "<<fGeoH->GetPath(fBarId)<<endl;
274 
275  Int_t trID= Ppt->GetTrackID();
276  tr = (PndMCTrack*)fMCArray->At(trID);
277 
278  Int_t trMID=tr->GetMotherID();
279 
280  //if(trMID > -1){
281  trMr = (PndMCTrack*)fMCArray->At(trMID);
282  Int_t trMpdg=trMr->GetPdgCode();
283 
284  if(trMr->GetMotherID()==-1){ // charged track is a primary
285 
286  lutinfo.SetChPartPdg(trMpdg);
287 
288  // expected cherenkov angle
289  Double_t Mrmass;
290  Int_t MoSign;
291  if(fabs(trMpdg) == 11){Mrmass = 0.000511; MoSign = 1;}
292  if(fabs(trMpdg) == 13){Mrmass = 0.105658; MoSign = 1;}
293  if(fabs(trMpdg) == 211){Mrmass = 0.139570; MoSign = -1;}
294  if(fabs(trMpdg) == 321){Mrmass = 0.49368; MoSign = -1;}
295  if(fabs(trMpdg) == 2212){Mrmass = 0.938; MoSign = -1;}
296  if(fabs(trMpdg) == 50000050){Mrmass = 0.0; MoSign = -1;}
297  Double_t Mrmom = trMr->GetMomentum().Mag();
298  CHexp = acos(sqrt(pow(Mrmom,2) + pow(Mrmass,2))/Mrmom/fGeo->nQuartz());
299  lutinfo.SetCherenkovMC(CHexp);
300  //cout<<"+++++++++++++++++++++++++++"<<endl;
301  //cout<<"CH expected = "<<CHexp<<endl;
302 
303  fxPHit= pdhit->GetX();
304  fyPHit= pdhit->GetY();
305  fzPHit= pdhit->GetZ();
306  ftime = pdhit->GetTime();
307  //ftime = Ppt->GetTime();
308 
309  //get the pixel id
310  fpixID = pdhit->GetDetectorID();
311  if(fpixID<0)continue;
312 
313  //cout<<"hit id "<<fpixID<<", x = "<<pdhit->GetX()<<", y = "<<pdhit->GetY()<<", time = "<<ftime<<endl;
314 
315  Double_t xPPoi= Ppt->GetX();
316  Double_t yPPoi= Ppt->GetY();
317 
318  lutinfo.AddTruePath(Ppt->GetLength());
319 
320  // momentum of a photon on the PD Plane
321  fPphoPD.SetXYZ(Ppt->GetPx(), Ppt->GetPy(), Ppt->GetPz());
322 
323  {
324  // mother momentum/direction
325  fPMo.SetXYZ(trMr->GetMomentum().X(), trMr->GetMomentum().Y(), trMr->GetMomentum().Z());
326  //fPMo.Print();
327  lutinfo.SetChPartDir(fPMo);
328  //cout<<"mother phi = "<<fPMo.Phi()/3.1415*180.<<endl;
329  if(fB > 0.){
330  Double_t PtMo = sqrt(pow(trMr->GetMomentum().X(),2)+pow(trMr->GetMomentum().Y(),2));
331  Double_t Rratio = fR*fR/2./pow((PtMo/0.29979/fB)*100.,2);
332  Double_t phi_extra = fPMo.Phi() + MoSign * trMpdg/fabs(trMpdg) * acos(1. - Rratio);
333  fHAngleInBDeg = 0.5 * MoSign * trMpdg/fabs(trMpdg) * (acos(1. - Rratio) /TMath::Pi())*180.;
334  //cout<<"B = "<<fB<<", R = "<<fR<<", trMpdg = "<<trMpdg<<", half angle in B = "<<fHAngleInBDeg<<endl;
335  fPMo.SetPhi(phi_extra);
336  }
337  lutinfo.SetChPartDirInBar2(fPMo);
338  }
339 
340  {
341  //mother momentum/direction from the bar point
342  fBarPoint->Momentum(fPMo);
343  lutinfo.SetChPartDirInBar(fPMo);
344  }
345 
346  //cout<<"Mother vector (global cs) : "<<endl;
347  TVector3 motherMom = fPMo.Unit();
348  //motherMom.Print();
349 
350  // initial momentum of the photon
351  fPphoInit = tr->GetMomentum();
352  //cout<<"Initial momentum of the photon :"<<endl;
353  //fPphoInit.Print();
354 
355  // real = generated cherenkov angle
356  CHreal = fPphoInit.Angle(fPMo);
357  lutinfo.SetCherenkovReal(CHreal);
358  //cout<<"CH real (generated) = "<<CHreal<<endl;
359 
360  Double_t etot = sqrt(pow(fPphoPD.X(),2) + pow(fPphoPD.Y(),2) +pow(fPphoPD.Z(),2));
361  flambdah=197.0*2.0*TMath::Pi()/(etot*1.0E9);//wavelength of photon in nm
362  lutinfo.AddLambda(flambdah);
363 
364  // production point of the photon
366 
367  //cout<<"start: phi = "<<fStartVertex.Phi()<<endl;
368  //fStartVertex.Print();
369  ftime0 = tr->GetStartTime()/1.0E9;
370  lutinfo.AddHitTime(ftime-ftime0);
371 
372  //cout<<"fstart time = "<<ftime0<<endl;
373  //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
374  // proceed only if photon was born in the bar for which the LUT is used!!!
375  //if(fStartVertex.Phi() >0./180.*fpi && fStartVertex.Phi() < 6./180.*fpi){
376  if(fPphoInit.Z() > 0. || fPphoInit.Z() < 0.){ // reflected photons
377 
378  // Transformation of the photon initial direction to the local bar coodr system:
379  // to get to the bar coord system.
381 
382  // Photon initial momentum in the bar coord. syst.
383  fPphoB = (fGeoH->MasterToLocalShortId(fPphoInit, fBarId) - fGeoH->MasterToLocalShortId((0.,0.,0.),fBarId)).Unit(); // vector
384  //fPphoB.Print();
385 
386  // mother momentum in the bar' (and bar) coord syst:
387  fPMoB = (fGeoH->MasterToLocalShortId(fPMo, fBarId) - fGeoH->MasterToLocalShortId((0.,0.,0.),fBarId)).Unit(); // vector
388  //PMBar.Print();
389 
390  // to find Cherenkov Phi (NOT THETA!!!):
391  TVector3 kB;
392  kB.SetXYZ(fkxBar, fkyBar, fkzBar);
393 
394  // use lookups to get the kXbar and kYbar of photons:
396  //cout<<"N pixels = "<<NHitPix<<endl;
398  //cout<<"N amb = "<<NAmb<<endl;
400  Double_t par[NPixPar];
401 
402  if (fDigiPar->GetParamsForPixel(fpixID, par) == kFALSE) {
403  cout<<"NO SUCH HIT IN LUT!!!"<<endl;
404  continue;
405  }
406 
407  //cout<<"LOOKUP!!!!"<<endl;
408  //cout<<"N Hit Pix = "<<NHitPix<<endl;
409  //cout<<"N Amb = "<<NAmb<<endl;
410  //cout<<"NPixPar = "<<NPixPar<<endl;
411 /* cout<<"par 0 = "<<par[0]<<endl; // kx
412  cout<<"par 1 = "<<par[1]<<endl; // ky
413  cout<<"par 2 = "<<par[2]<<endl; // kxB
414  cout<<"par 3 = "<<par[3]<<endl; // kyB
415  cout<<"par 4 = "<<par[4]<<endl; // kxU1
416  cout<<"par 5 = "<<par[5]<<endl; // kyU1
417  cout<<"par 6 = "<<par[6]<<endl; // kxU2
418  cout<<"par 7 = "<<par[7]<<endl; // kyU2
419  cout<<"par 8 = "<<par[8]<<endl; // kxU3
420  cout<<"par 9 = "<<par[9]<<endl; // kyU3
421  cout<<"par 10 = "<<par[10]<<endl; // kxBU1
422  cout<<"par 11 = "<<par[11]<<endl; // kyBU1
423  cout<<"par 12 = "<<par[12]<<endl; // kxBU2
424  cout<<"par 13 = "<<par[13]<<endl; // kyBU2
425  cout<<"par 14 = "<<par[14]<<endl; // kxBU3
426  cout<<"par 15 = "<<par[15]<<endl; // kyBU3
427  cout<<"par 16 = "<<par[16]<<endl; // kxUB
428  cout<<"par 17 = "<<par[17]<<endl; // kyUB
429  cout<<"par 18= "<<par[18]<<endl; // kxUU
430  cout<<"par 19= "<<par[19]<<endl; // kyUU
431  cout<<"par 20= "<<par[20]<<endl; // kxUUU
432  cout<<"par 21= "<<par[21]<<endl; // kyUUU
433  cout<<"par 22= "<<par[22]<<endl; // kxBUU
434  cout<<"par 23= "<<par[23]<<endl; // kyBUU
435  cout<<"par 24= "<<par[24]<<endl; // kxBUB
436  cout<<"par 25= "<<par[25]<<endl; // kyBUB
437  cout<<"par 26= "<<par[26]<<endl; // kxUBU
438  cout<<"par 27= "<<par[27]<<endl; // kyUBU
439 */
440  // fill in NPixPar/2 * 1 ambiguities:
441  Double_t kX, kY, kZ;
442  std::vector<TVector3> ambig;
443  std::vector<Double_t> CHreco;
444  std::vector<Double_t> Tamb;
445  std::vector<Double_t> Path;
446 
447  // length of the vector should be the same as NumAmb*8 !!!!!
448  Int_t NumAmb = NAmb; //=14
449  TVectorD CHdiff(8*NumAmb);
450  TVectorD Adiff(8*NumAmb); // vector to store angle diff btw real and reco photons
451 
452  for(Int_t i=0; i<NumAmb; i++){
453  // in bar' coordinate system
454  kX = par[i*2]; // kXD
455  kY = par[i*2 + 1]; // kYD
456  kZ = -sqrt(1. - pow(kX,2.) - pow(kY,2.));
457  //cout<<"mom: x = "<<fPMoB.X()<<", y = "<<fPMoB.Y()<<", z = "<<fPMoB.Z()<<endl;
458  fkBar.SetXYZ(kX, kY, kZ);
459  //cout<<"photon from LUT in bar' coordinate system: "<<endl;
460  //fkBar.Print();
461 
462  for(Int_t jamb=0; jamb <8; jamb++){
463  if(jamb == 1){fkBar.SetXYZ(-kX, kY, kZ);}
464  if(jamb == 2){fkBar.SetXYZ(kX, -kY, kZ);}
465  if(jamb == 3){fkBar.SetXYZ(kX, kY, -kZ);}
466  if(jamb == 4){fkBar.SetXYZ(-kX, -kY, kZ);}
467  if(jamb == 5){fkBar.SetXYZ(kX, -kY, -kZ);}
468  if(jamb == 6){fkBar.SetXYZ(-kX, kY, -kZ);}
469  if(jamb == 7){fkBar.SetXYZ(-kX, -kY, -kZ);}
470 
471  // check if there is such enrty in the LUT and if the ambiguity fulfills the total internal reflection requitrement
472  if((kX != 0. && kY != 0.) && ((fkBar.Cross(fnX1)).Mag() > 1.00028/fGeo->nQuartz() ||
473  (fkBar.Cross(fnY1)).Mag() > 1.00028/fGeo->nQuartz())){
474  ambig.push_back(fkBar);
475  CHreco.push_back(fkBar.Angle(fPMoB));
476  CHdiff(8*i+jamb) = fabs(CHreco[8*i+jamb] - CHexp);
477  Tamb.push_back(RecoAmbigTime(fkBar, fStartVertex, &fPath, 0));
478  Path.push_back(fPath);
479  Adiff(8*i+jamb) = fkBar.Angle(fPphoB);
480  //cout<<"reco ch angle = "<<fkBar.Angle(fPMoB)<<endl;
481  //cout<<"number of bounces = "<<NumberOfBounces(fStartVertex, fPphoB, fBarId)<<endl;
482  //cout<<"CHdiff = "<<CHdiff(8*i+jamb)<<", CHreco"<<8*i+jamb<<" = "<<CHreco[8*i+jamb]<<endl;
483 
484  //fill only with credible information:
485  lutinfo.AddAngle(fkBar.Angle(fPMoB));
486  lutinfo.AddTime(RecoAmbigTime(fkBar, fStartVertex, &fPath, 0));
487  lutinfo.AddPath(fPath);
488  lutinfo.AddChDiff(CHreco[8*i+jamb] - CHexp);
489  //cout<<"fkBar = "<<endl;
490  //fkBar.Print();
491  lutinfo.AddNOfBounces(NumberOfBounces(fStartVertex, fkBar/*fPphoB*/, fBarId));
492 
493  //fkBarXHist->Fill(kX, fPphoB.X());
494  //fkBarYHist->Fill(kY, fPphoB.Y());
495  }else{
496  ambig.push_back((0.,0.,0.));
497  CHreco.push_back(-999.);
498  CHdiff(8*i+jamb) = -999.;
499  Tamb.push_back(-999.);
500  Path.push_back(-999.);
501  Adiff(8*i+jamb) = -999.;
502  }
503  }// for
504  }
505 
506  fPhiMap = TMath::Nint(fPMo.Phi()/fpi*180.);
507  fThetaMap = TMath::Nint(fPMo.Theta()/fpi*180.);
508  //cout<<"phi = "<<fPMo.Phi()/fpi*180.<<", phi map = "<<fPhiMap<<", theta map = "<<fThetaMap<<endl;
509 
510  if(fB > 0.){
511  // fMapHist->Fill(fThetaMap,fPhiMap-fHAngleInBDeg); // assuming that R = 50 cm
512  }
513  if(fB == 0.){
514  // fMapHist->Fill(fThetaMap,fPhiMap);
515  }
516  } // if start vertex lies within the right bar!
517  }// photon from primary particle
518 
519  }// photon hits
520  new ((*fDrcLutInfoArray)[fDrcLutInfoArray->GetEntriesFast()]) PndDrcLutInfo(lutinfo);
521 }
522 //----------------------------------------------------------------------------------------------
523 Double_t PndDrcRecoLookupMapS::InBarCoordSyst(TVector3 start, TVector3 *v1, TVector3 *v2, TVector3 *v3, TVector3 *v4){
524  Double_t startPhi = start.Phi()/fpi*180.; // [degrees]
525  //cout<<"-I- InBarCoordinateSystem: start phi = "<<start.Phi()/fpi*180.<<endl;
526  if(startPhi < 0.){startPhi = 360. + startPhi;}
527  //if(startPhi > 360.){startPhi = startPhi - 360.;}
528  //cout<<"-I- InBarCoordinateSystem: start phi = "<<startPhi<<endl;
529  //Double_t dphi = 2.*(180. - 2*fPipehAngle)/ fBboxNum; //[degrees]
530  //cout<<"-I- InBarCoordinateSystem: dphi = "<<dphi<<endl;
531  Double_t PhiRot = 0.; //[degrees]
532  if(startPhi >= 0. && startPhi < 90.){
533  PhiRot = TMath::Floor(startPhi/fDphi) *fDphi + fDphi/2.;
534  }
535  if(startPhi >= 90. && startPhi < 270.){
536  PhiRot = 90. + fPipehAngle + TMath::Floor((startPhi-90.-fPipehAngle)/fDphi) *fDphi + fDphi/2.;
537  }
538  if(startPhi >= 270. && startPhi < 360.){
539  PhiRot = 270. + fPipehAngle + TMath::Floor((startPhi-270.-fPipehAngle)/fDphi) *fDphi + fDphi/2.;
540  }
541  //cout<<"-I- InBarCoordinateSystem: PhiRot = "<<PhiRot<<endl;
542 
543  TVector3 ver1, ver2, ver3, ver4;
544  ver1.SetXYZ(fR-(fHThick), fLSide/2. ,0.);
545  ver2.SetXYZ(fR+(fHThick), fLSide/2. ,0.);
546  ver3.SetXYZ(fR+(fHThick), -fLSide/2. ,0.);
547  ver4.SetXYZ(fR-(fHThick), -fLSide/2. ,0.);
548 
549  ver1.RotateZ(PhiRot/180.*fpi);
550  ver2.RotateZ(PhiRot/180.*fpi);
551  ver3.RotateZ(PhiRot/180.*fpi);
552  ver4.RotateZ(PhiRot/180.*fpi);
553 
554  *v1 = ver1;
555  *v2 = ver2;
556  *v3 = ver3;
557  *v4 = ver4;
558 
559  return PhiRot/180.*fpi;
560 }
561 
562 //------ Find Nubmer of Bounces --------------------------------------
563 Int_t PndDrcRecoLookupMapS::NumberOfBounces(TVector3 start, TVector3 dir, Int_t barId){
564  // start - photon production point in global coord system
565  // dir - photon direction in bar coord system
566 
567  //cout<<"-I- NumberOfBounces: dir"<<endl;
568  //dir.Print();
569  //cout<<"-I- NumberOfBounces: start"<<endl;
570  //start.Print();
571 
572  // Find coordinates of X0, Y0:
573  Double_t Z0, X0, Y0;
574  if(dir.Theta() < 3.1415/2.){
575  Z0 = -(fabs(fzup) + 2.*fzdown - start.Z());
576  }
577  if(dir.Theta() >= 3.1415/2.){
578  Z0 = -(start.Z() - fzup);
579  }
580  X0 = Z0*TMath::Tan(dir.Theta())*TMath::Cos(dir.Phi());
581  Y0 = Z0*TMath::Tan(dir.Theta())*TMath::Sin(dir.Phi());
582  //cout<<"-I- NumberOfBounces: tan th = "<<TMath::Tan(dir.Theta())<<", sin ph = "<<TMath::Sin(dir.Phi())<<", cos ph = "<<TMath::Cos(dir.Phi())<<endl;
583  //cout<<"-I- NumberOfBounces: X0 = "<<X0<<", Y0 = "<<Y0<<", Z0 = "<<Z0<<endl;
584 
585  // Find the start position of the photon with respect to the middle of the bar:
586  TVector3 startLocal = fGeoH->MasterToLocalShortId(start, barId); // point
587  //cout<<"-I- NumberOfBounces: Xen = "<<startLocal.X() + fBarWidth/2.<<", Yen = "<<startLocal.Y() + fHThick<<endl;
588 
589  // Find the number of bounces in each direction
590  Double_t N1, N2;
591  FindOutPoint(X0, startLocal.X() + fBarWidth/2., fBarWidth, &N1, 0);
592  FindOutPoint(Y0, startLocal.Y() + fHThick, 2.*fHThick, &N2, 0);
593  //cout<<"-I- NumberOfBounces: N1 = "<<N1<<", N2 = "<<N2<<endl;
594 
595  return (Int_t)N1+N2;
596 }
597 
598 //----------------------------------------------------------------------------------------------------------
600  Double_t m=99.;
601  Double_t n=TMath::Floor(x0/a);
602  m = n;
603  if(printt){std::cout<<"n = "<<n<<", NN = "<<*NN<<", x0 = "<<x0<<", a = "<<a<<std::endl;}
604  Double_t x1 = x0 - n*a;
605  if(x0 < 0.){x1 = x0 - (n+1)*a;}
606  if(printt){std::cout<<"xy = "<< x1<<std::endl;}
607  Double_t xK = 0.;
608  if((m/2. - TMath::Floor(m/2.)) == 0.) { // 4etnoe
609  //if(print){std::cout<<"odd==0"<<std::endl;}
610  if(x0 >= 0. && x1 + xEn <= a){xK = x1 + xEn;}
611  if(x0 >= 0. && x1 + xEn > a){xK = 2*a - x1 - xEn; n = 1. + n;}
612  if(x0 < 0. && x1 + xEn >= 0.){xK = a - (x1 + xEn); n = -1. -n;}
613  if(x0 < 0. && x1 + xEn < 0.) {xK = a + x1 + xEn; n = -n;}
614  if(printt){std::cout<<"xK = "<< xK<<", n = "<<n<<std::endl;}
615 
616  }
617 
618  if((m/2. - TMath::Floor(m/2.)) != 0.) { // ne4etnoe
619  //if(print){std::cout<<"even!=0"<<std::endl;}
620  if(x0 >= 0. && x1 + xEn <= a){xK = a - (x1 + xEn);}
621  if(x0 >= 0. && x1 + xEn > a){xK = x1 + xEn - a; n = 1. + n;}
622  if(x0 < 0. && x1 + xEn >= 0.){xK = x1 + xEn; n = -1. -n;}
623  if(x0 < 0. && x1 + xEn < 0.) {xK = - (x1 + xEn); n = -n;}
624  if(printt){std::cout<<"xK = "<< xK<<", n = "<<n<<std::endl;}
625 
626  }
627 
628  *NN = n;
629  return xK;
630 }
631 
632 //-------------------------------------------------------------------------------------------
633 void PndDrcRecoLookupMapS::DrawBarBox(TVector3 v1, TVector3 v2, TVector3 v3, TVector3 v4){
634  Double_t xx[5];
635  Double_t yy[5];
636  xx[0] = v1.X(); xx[1] = v2.X(); xx[2] = v3.X(); xx[3] = v4.X(); xx[4] = v1.X();
637  yy[0] = v1.Y(); yy[1] = v2.Y(); yy[2] = v3.Y(); yy[3] = v4.Y(); yy[4] = v1.Y();
638  TPolyLine *p6 =new TPolyLine(5,xx,yy);
639  p6->SetLineWidth(2);
640  p6->Draw("same");
641 }
642 
643 //--------------------------------------------------------------------------------------------
644 Double_t PndDrcRecoLookupMapS::RecoAmbigTime(TVector3 kb, TVector3 start, Double_t *l, Bool_t printout){ // [ns]
645 
646  // group velocities for oil and quartz for Noil and Nquartz assuming that mean lambda = 410 nm:
647  //Double_t nOil = fGeo->nEV();
648  Double_t u_oil = 19.8;//30./nOil;
649  //Double_t u_quartz = 30./1.46907; // for lambda = 410 nm
650  //Double_t u_quartz = 30./1.47012; // for lambda = 400 nm
651  //Double_t u_quartz = 30./1.46838; // for lambda = 417 nm
652  //Double_t u_quartz = 30./1.47125; // for lambda = 390 nm
653  //Double_t u_quartz = 30./1.47248; // for lambda = 380 nm
654  Double_t u_quartz = 20.;//30./fNquartz;//1.47805; // for lambda = 400 nm
655 
656  // kb - photon momentum at the production point, first calculate path in QUARTZ BAR:
657  // assume that there are only DIRECT photons!!!
658 
659  // path in quartz:
660  Double_t Z0 = 0.;
661  Double_t kz = 0.;
662  if(kb.Z() < 0.){Z0 = start.Z() - fGeo->barBoxZUp(); kz = kb.Z();}
663  if(kb.Z() >= 0.){Z0 = 2.*fGeo->barBoxZDown() - fGeo->barBoxZUp() - start.Z(); kz = -kb.Z();}
664 
665  if(printout){
666  cout<<"-I- Reco ambig Time: Zstart = "<<start.Z()<<", Z0 = "<<Z0<<endl;
667  }
668 
669  Double_t L0 = Z0/fabs(cos(kb.Theta()));
670  kb.SetZ(kz);
671  Double_t thetaOil = asin(fGeo->nQuartz()/fGeo->nEV()*sin(kb.Theta()));
672  if(printout){
673  cout<<"RECO ambig TIME: thetas are: quartz = "<<kb.Theta()/fpi*180.<<", oil = "<<thetaOil/fpi*180.<<endl;
674  }
675  kb.SetTheta(thetaOil);
676  Double_t Z1 = fGeo->EVlen();
677  Double_t L1 = Z1/fabs(cos(kb.Theta())); // path in oil
678 
679  if(printout){
680  cout<<"-I- Reco ambig Time: Zev = "<<fGeo->EVlen()<<endl;
681  cout<<"-I- Reco ambig Time: L0 = "<<L0<<", L1 = "<<L1<<endl;
682  cout<<"-I- Reco ambig Time: time is "<< L0/u_quartz + L1/u_oil <<endl; // 19.5 cm/ns - average (lambda) group speed
683  }
684 
685  *l = L0 + L1;
686 
687  return L0/u_quartz + L1/u_oil; //[ns]
688 }
689 //---------------------------------------------------------------------------
691 
692 //------------------Write to File----------------------------------------------
694 
695 // ----- Finish Task ---------------------------------------------------
697 {
698  cout << "-I- PndDrcRecoLookupMapS: Finish" << endl;
699  WriteToFile();
700  DrawHisto();
701 }
702 
703 //----------------------------------------------------------------
705 
706 // -------------------------------------------------------------------------
void SetChPartDirInBar2(TVector3 val)
friend F32vec4 acos(const F32vec4 &a)
Definition: P4_F32vec4.h:113
Double_t x0
Definition: checkhelixhit.C:70
void AddChDiff(Double_t val)
Double_t nEV()
Definition: PndGeoDrc.h:76
friend F32vec4 cos(const F32vec4 &a)
Definition: P4_F32vec4.h:112
void AddHitTime(Double_t val)
Double_t RecoAmbigTime(TVector3, TVector3, Double_t *, Bool_t)
Int_t GetNPixelParam()
Definition: PndDrcDigiPar.h:45
Int_t run
Definition: autocutx.C:47
Double_t BBoxNum()
Definition: PndGeoDrc.h:136
Double_t InBarCoordSyst(TVector3, TVector3 *, TVector3 *, TVector3 *, TVector3 *)
Int_t i
Definition: run_full.C:25
__m128 m
Definition: P4_F32vec4.h:28
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
TClonesArray * fDrcLutInfoArray
Double_t Lside()
Definition: PndGeoDrc.h:184
Bool_t GetParamsForPixel(Int_t, Double_t *)
Int_t GetPdgCode() const
Definition: PndMCTrack.h:73
#define verbose
virtual void SetParContainers()
friend F32vec4 sin(const F32vec4 &a)
Definition: P4_F32vec4.h:111
Double_t EVlen()
Definition: PndGeoDrc.h:127
Double_t BarWidth()
Definition: PndGeoDrc.h:100
static T Sin(const T &x)
Definition: PndCAMath.h:42
int n
Double_t par[3]
TVector3 GetMomentum() const
Definition: PndMCTrack.h:78
void SetChPartPdg(Int_t val)
Int_t NumberOfBounces(TVector3, TVector3, Int_t)
float Tan(float x)
Definition: PndCAMath.h:165
void DrawBarBox(TVector3, TVector3, TVector3, TVector3)
void SetChPartDirInBar(TVector3 val)
Double_t BBoxGap()
Definition: PndGeoDrc.h:130
static T Cos(const T &x)
Definition: PndCAMath.h:43
Double_t barBoxZDown()
Definition: PndGeoDrc.h:104
virtual Double_t GetTime()
Definition: PndDrcPDHit.h:55
TString pt(TString pts, TString exts="px py pz")
Definition: invexp.C:133
void SetCherenkovReal(Double_t val)
Double_t PipehAngle()
Definition: PndGeoDrc.h:139
Int_t GetBarPointID() const
Definition: PndDrcPDPoint.h:56
virtual Int_t GetRefIndex()
Definition: PndDrcPDHit.h:57
Int_t a
Definition: anaLmdDigi.C:126
void AddLambda(Double_t val)
Double_t barBoxZUp()
Definition: PndGeoDrc.h:108
void AddAngle(Double_t val)
void SetChPartDir(TVector3 val)
Double_t
virtual void Exec(Option_t *option)
Double_t nQuartz()
Definition: PndGeoDrc.h:70
void AddTime(Double_t val)
void AddNOfBounces(Double_t val)
void AddTruePath(Double_t val)
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
void SetCherenkovMC(Double_t val)
static PndGeoHandling * Instance()
TVector3 MasterToLocalShortId(const TVector3 &master, const Int_t &shortId)
Int_t GetNAmbiguities()
Definition: PndDrcDigiPar.h:44
Int_t GetNHitPixels()
Definition: PndDrcDigiPar.h:43
void SetVerbose(Int_t v)
Double_t FindOutPoint(Double_t, Double_t, Double_t, Double_t *, Bool_t)
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
Double_t barHalfThick()
Definition: PndGeoDrc.h:96
Digitization Parameter Class for DIRC barrel part.
Definition: PndDrcDigiPar.h:29
TVector3 v1
Definition: bump_analys.C:40
virtual Int_t GetRefIndex()
Definition: PndDrcHit.h:44
ClassImp(PndAnaContFact)
virtual InitStatus Init()
TVector3 v2
Definition: bump_analys.C:40
void AddPath(Double_t val)
TVector3 GetStartVertex() const
Definition: PndMCTrack.h:76
Int_t GetMotherID() const
Definition: PndMCTrack.h:74
Double_t Pi
Double_t barNum()
Definition: PndGeoDrc.h:124
Int_t L1[1]
Definition: Pnd_Hc_ee7G.C:50
int Nint(float x)
Definition: PndCAMath.h:117
Double_t GetStartTime() const
Definition: PndMCTrack.h:77
Double_t radius()
Definition: PndGeoDrc.h:92
PndGeoDrc * fGeo
Basic geometry data of barrel DRC.