22 #include "TLorentzVector.h"
25 #include "TStopwatch.h"
27 #include "TSpectrum2.h"
42 #include "FairLogger.h"
44 #include "FairRuntimeDb.h"
45 #include "FairParRootFileIo.h"
48 #include "FairMCPoint.h"
56 #include "AnalysisTools/Fitter/Rho4CFitter.h"
57 #include "AnalysisTools/Fitter/RhoKinVtxFitter.h"
58 #include "AnalysisTools/Fitter/RhoKinFitter.h"
62 #include "FairRunSim.h"
90 TTree* tSim = (TTree*) (gFile->Get(
"pndsim"));
92 TClonesArray* Points =
new TClonesArray(tcaName);
93 tSim->SetBranchAddress(branchName, &Points);
94 TBranch* br = tSim->FindBranch(branchName);
96 if (br == 0 || br->GetEntries() == 0 || iEvent >= br->GetEntries())
100 tSim->GetEntry(iEvent);
101 const Int_t nPoints = Points->GetEntriesFast();
108 for (
int iPoint = 0; iPoint < nPoints; iPoint++)
110 TObject* obj = Points->At(iPoint);
111 if (iPoint < 1 && verbose > 5)
113 std::cout << obj->ClassName() << std::endl;
114 std::cout <<
"obj->InheritsFrom(FairMCPoint) = "
115 << obj->InheritsFrom(
"FairMCPoint") << std::endl;
116 std::cout <<
"obj->InheritsFrom(FairHit) = "
117 << obj->InheritsFrom(
"FairHit") << std::endl;
120 if (obj->InheritsFrom(
"FairMCPoint"))
122 FairMCPoint* myPoint = (FairMCPoint*) obj;
123 myPoint->Position(point);
125 else if (obj->InheritsFrom(
"FairHit"))
127 FairHit* myHit = (FairHit*) obj;
128 myHit->Position(point);
133 <<
"Error, the hit or point does neither inherit from FairHit nor from FairMCPoint \n";
137 X[iPoint] = point.X();
138 Y[iPoint] = point.Y();
139 Z[iPoint] = point.Z();
145 std::cout <<
"Point " << iPoint <<
" : ";
147 std::cout <<
"Z=" << Z[iPoint] <<
"cm X=" << X[iPoint] <<
"cm Y=" << Y[iPoint] <<
"cm"
155 mcPoints->DrawGraph(nPoints, Z, X,
"P,SAME");
160 tSim->ResetBranchAddresses();
178 TTree* tSim = (TTree*) (gFile->Get(
"pndsim"));
182 std::cout <<
"Got the tree" << std::endl;
185 TClonesArray* Points =
new TClonesArray(tcaName);
188 std::cout <<
"Created new TCA" << std::endl;
190 tSim->SetBranchAddress(branchName, &Points);
193 std::cout <<
"Set the branchName" << std::endl;
195 TBranch* br = tSim->FindBranch(branchName);
198 std::cout <<
"Found the branch" << std::endl;
200 if (br == 0 || br->GetEntries() == 0 || iEvent >= br->GetEntries())
204 std::cout <<
"Passed the test" << std::endl;
206 tSim->GetEntry(iEvent);
209 std::cout <<
"Number of points: " << Points->GetEntriesFast()
212 for (
int iPoint = 0; iPoint < Points->GetEntriesFast(); iPoint++)
214 TObject* obj = Points->At(iPoint);
215 if (iPoint < 1 && verbose > 5)
217 std::cout << obj->ClassName() << std::endl;
218 std::cout <<
"obj->InheritsFrom(FairMCPoint) = "
219 << obj->InheritsFrom(
"FairMCPoint") << std::endl;
220 std::cout <<
"obj->InheritsFrom(FairHit) = "
221 << obj->InheritsFrom(
"FairHit") << std::endl;
224 if (obj->InheritsFrom(
"FairMCPoint"))
226 FairMCPoint* myPoint = (FairMCPoint*) obj;
227 myPoint->Position(point);
229 else if (obj->InheritsFrom(
"FairHit"))
231 FairHit* myHit = (FairHit*) obj;
232 myHit->Position(point);
237 <<
"Error, the hit or point does neither inherit from FairHit nor from FairMCPoint \n";
245 mcPoints->Fill(Z, X);
261 std::cout <<
"Point " << iPoint <<
" : ";
263 std::cout <<
"Z=" << Z <<
"cm X=" << X <<
"cm Y=" << Y <<
"cm BX="
264 << BB[0] / 10. <<
"T BY=" << BB[1] / 10. <<
"T BZ="
265 << BB[2] / 10. <<
"T" << std::endl;
270 mcPoints->SetMarkerColor(2);
271 mcPoints->SetMarkerStyle(29);
272 mcPoints->SetMarkerSize(1);
274 tSim->ResetBranchAddresses();
299 const Int_t nPoints = 50;
300 Double_t z[nPoints] = { fZLineParabola-500., fZLineParabola };
302 for (Int_t iPoint = 0; iPoint < nPoints; ++iPoint)
307 z[iPoint] = fZLineParabola-100.;
310 z[iPoint] = fZLineParabola;
313 z[iPoint] = fZParabolaLine;
316 z[iPoint] = fZParabolaLine+100.;
319 z[iPoint] = (fZParabolaLine-fZLineParabola)/(nPoints-4);
321 pos = trackCand->
getPos(z[iPoint]);
325 returnTGraph->DrawGraph(nPoints,z,x,
"LP,SAME") ;
336 const Bool_t keepBConstant, TGraph* ParabolaFitInXZPlane)
358 const Int_t iterationsForBfield = 10;
362 Double_t BMeanPlus = 0., BMeanMinus;
364 Double_t xplusshifted = 0., xminusshifted = 0., lastxminusshifted = 0., lastxplusshifted = 0., lastxminusreal= 0., lastxplusreal = 0., zshifted = 0.;
368 Double_t realtheta = theta / 360. * 2. * meinpi;
369 const Double_t tantheta = tan(realtheta);
370 const Double_t pzstuff = 1. / pzinv / 2. / c / tantheta /
sin(realtheta);
371 const Int_t upperlimit = 500, lowerlimit = -200;
372 const Int_t nPoints = ceil((upperlimit-lowerlimit)/zscaling);
376 Int_t howManyPointsInBField = 0;
380 if (2<verbose) { std::cout <<
"hitshiftinx is " << hitshiftinx << std::endl; }
382 for (Int_t indexForArrays = 0, zshifted = lowerlimit; indexForArrays < nPoints; ++indexForArrays, zshifted = zshifted + 1. / zscaling)
391 zreal[indexForArrays] = zshifted + zOffset;
393 for (Int_t iTry = 0; iTry<iterationsForBfield; ++iTry)
396 if (kTRUE == keepBConstant)
402 iTry = iterationsForBfield+10;
408 po[2] = zreal[indexForArrays];
410 lastxminusreal = lastxminusshifted-hitshiftinx;
411 lastxminusreal = lastxminusshifted-hitshiftinx;
414 po[0] = lastxminusreal;
416 Byminus = BB[1] / 10.;
418 po[0] = lastxplusreal;
420 Byplus = BB[1] / 10.;
424 std::cout << iTry <<
". try: z+zOffset = " << zreal[indexForArrays] <<
" cm Byminus = "
425 << Byminus <<
" T Byplus = " << Byplus <<
" T"
427 std::cout <<
"lastxplusreal = " << lastxplusreal <<
" cm lastxminusreal = " << lastxminusreal <<
" cm" << std::endl;
433 Byminus = 1. / 10000.;
437 Byplus = 1. / 10000.;
441 Double_t ztantheta = zshifted / tantheta;
442 Double_t a = -ztantheta + pzstuff / Byminus;
443 xminusshifted = a -
sqrt(a * a - zshifted / pzinv / c /
sin(realtheta) / Byminus - ztantheta * ztantheta);
444 a = -ztantheta + pzstuff / Byplus;
445 xplusshifted = a +
sqrt(a * a - zshifted / pzinv / c /
sin(realtheta) / Byplus - ztantheta * ztantheta);
448 lastxminusshifted = xminusshifted;
449 lastxplusshifted = xplusshifted;
454 xplusreal[indexForArrays] = xplusshifted - hitshiftinx;
455 xminusreal[indexForArrays] = xminusshifted - hitshiftinx;
458 if (zreal[indexForArrays] > 415. && zreal[indexForArrays] < 490.)
463 ++howManyPointsInBField;
465 po[2] = zreal[indexForArrays];
466 po[0] = xplusreal[indexForArrays];
468 BMeanPlus += BB[1]/10.;
470 po[0] = xminusreal[indexForArrays];
472 BMeanMinus += BB[1]/10.;
477 BMeanPlus = BMeanPlus/howManyPointsInBField;
478 BMeanMinus = BMeanMinus/howManyPointsInBField;
482 cout <<
"??? BMeanPlus = " << BMeanPlus << std::endl;
483 cout <<
"??? BMeanMinus = " << BMeanMinus << std::endl;
486 ParabolaFitInXZPlane->DrawGraph(nPoints, zreal, xplusreal,
"P,SAME");
487 ParabolaFitInXZPlane->DrawGraph(nPoints, zreal, xminusreal,
"P,SAME");
488 return max(BMeanPlus,BMeanMinus);
512 std::cout <<
"B_y = " << BB[1]/10. <<
" T for Z = " << po[2] <<
" cm X = " << po[0] <<
" cm" << std::endl;
514 Btot =
TMath::Sqrt(BB[0] * BB[0] + BB[1] * BB[1] + BB[2] * BB[2]);
515 Bfield->Fill(
z,
x, Btot / 10.);
575 gROOT->LoadMacro(
"$VMCWORKDIR/gconfig/basiclibs.C");
579 gSystem->Load(
"libGeoBase");
580 gSystem->Load(
"libParBase");
581 gSystem->Load(
"libBase");
582 gSystem->Load(
"libField");
583 gSystem->Load(
"libFts");
587 gROOT->Macro(
"$VMCWORKDIR/gconfig/rootlogon.C");
588 gROOT->SetStyle(
"Plain");
589 gStyle->SetMarkerStyle(20);
590 gStyle->SetOptStat(0);
591 gStyle->SetPalette(1);
599 TString SimFile =
"sim_complete.root";
609 const Double_t meinpi = 3.14159265359;
610 const Int_t ResolutionX = 800, ResolutionY = 600;
634 TH2F* fFieldHist = NULL;
636 fFieldHist =
new TH2F(
"Bfield",
"", 650, -200, 1100, 250, -250, 250);
637 fFieldHist->GetXaxis()->SetTitle(
"z [cm]");
638 fFieldHist->GetYaxis()->SetTitle(
"x [cm]");
643 TGraph* FitInXZPlane =
new TGraph();
644 FitInXZPlane->SetMarkerColor(4);
645 FitInXZPlane->SetMarkerStyle(1);
646 FitInXZPlane->SetMarkerSize(1.1);
647 FitInXZPlane->SetLineColor(4);
648 FitInXZPlane->SetLineWidth(1.5);
675 TCanvas *cEventZx = NULL;
677 cEventZx =
new TCanvas(
"zx plane",
"zx plane", ResolutionX, ResolutionY);
680 fFieldHist->Draw(
"cont1");
773 const int subdetectorCount = 11;
774 TString branchNames[subdetectorCount] =
775 {
"FTSPoint",
"STTPoint",
"MVDPoint",
"GEMPoint",
"DrcBarPoint",
776 "DrcPDPoint",
"DskParticle",
"PndDskFLGHit",
"MdtPoint",
777 "FtofPoint",
"EmcHit" };
778 TString tcaNames[subdetectorCount] =
779 {
"PndFtsPoint",
"PndSttPoint",
"PndSdsMCPoint",
"PndGemMCPoint",
780 "PndDrcBarPoint",
"PndDrcPDPoint",
"PndDskParticle",
"PndDskFLGHit",
781 "PndMdtPoint",
"PndFtofPoint",
"PndEmcHit" };
782 std::cout <<
"Event number " << iEvent << std::endl;
785 TGraph *mcPoints =
new TGraph();
786 mcPoints->SetMarkerColor(2);
787 mcPoints->SetMarkerStyle(29);
788 mcPoints->SetMarkerSize(1.4);
789 mcPoints->SetLineColor(2);
790 TFile* fSim =
new TFile(SimFile.Data());
791 for (
int iSubdetector = 0; iSubdetector < subdetectorCount; ++iSubdetector)
794 <<
". subdetector: branchNames[iSubdetector], tcaNames[iSubdetector] = "
795 << branchNames[iSubdetector] <<
" " << tcaNames[iSubdetector]
797 PlotMCTracks(iEvent, branchNames[iSubdetector], tcaNames[iSubdetector], mcPoints, fSim);
804 TFile* fDigi =
new TFile(DigiFile.Data());
805 TTree* tDigi = (TTree*) (fDigi->Get(
"pndsim"));
808 TClonesArray* fFtsHitArray =
new TClonesArray(
"PndFtsHit");
809 tDigi->SetBranchAddress(
"FTSHit", &fFtsHitArray);
810 tDigi->GetEntry(iEvent);
813 TGraph*
hits =
new TGraph();
814 hits->SetMarkerStyle(2);
815 hits->SetMarkerColor(1);
816 hits->SetMarkerSize(2.0);
817 const Int_t
nHits = fFtsHitArray->GetEntriesFast();
821 for (
int iHit = 0; iHit <
nHits; iHit++)
828 if (0<fVerbose) {std::cout <<
"Not drawing hit with index " << iHit <<
" , because it comes from a skewed straw! LayerID = " << myHit->
GetLayerID() << std::endl;}
834 myHit->Position(hit);
836 hitX[iHit] = hit.X();
837 hitY[iHit] = hit.Y();
838 hitZ[iHit] = hit.Z();
843 std::cout <<
"Hit " << iHit <<
" : ";
845 std::cout <<
"X: " << hitX[iHit] <<
" Y: " << hitY[iHit] <<
" Z: " << hitZ[iHit]
849 hits->DrawGraph(nHits, hitZ, hitX,
"P,SAME");
892 TFile* fReco =
new TFile(RecoFile.Data());
893 TTree* tReco = (TTree*) (fReco->Get(
"pndsim"));
896 TClonesArray* fTrackCands =
new TClonesArray(
"PndFtsHoughTrackCand");
897 tReco->SetBranchAddress(
"PndFtsHoughTrackCand", &fTrackCands);
898 tReco->GetEntry(iEvent);
899 cout << fTrackCands->GetEntriesFast()<<
" Hough track cands. in event\n";
903 for (UInt_t iTrackCand=0; iTrackCand < fTrackCands->GetEntriesFast(); ++iTrackCand){
Double_t getZLineParabola()
int PlotMCTracksPrintBField(PndMultiField *fField, int iEvent, TString branchName, TString tcaName, TH2D *mcPoints)
int DrawField(PndMultiField *fField, TH2F *Bfield)
friend F32vec4 sqrt(const F32vec4 &a)
static T Sqrt(const T &x)
friend F32vec4 sin(const F32vec4 &a)
void GetFieldValue(const Double_t point[3], Double_t *bField)
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
TVector3 getPos(const Double_t zLabSys) const
Double_t MakeHoughParabolaFitwithBfield(PndMultiField *fField, Double_t pzinv, Double_t theta, Double_t weight, Double_t zOffset, Double_t hitshiftinx, Double_t zscaling, const Double_t c, const Bool_t keepBConstant, TGraph *ParabolaFitInXZPlane)
Double_t getZParabolaLine()
Class for saving a FTS track cand. for Hough transform based FTS PR.
int plotHoughTrackCand(PndFtsHoughTrackCand *trackCand, TGraph *returnTGraph)
int PlotMCTracks(int iEvent, TString branchName, TString tcaName, TGraph *mcPoints, TFile *fSim=0)