10 #include<TApplication.h>
14 #include<TClonesArray.h>
20 #include<FairRunAna.h>
22 #include<FairRtdbRun.h>
23 #include<FairRuntimeDb.h>
24 #include<FairParRootFileIo.h>
50 cout <<
" analysis tool vers. 1.3 " << endl;
52 gROOT->Macro(
"$VMCWORKDIR/gconfig/rootlogon.C");
53 gSystem->Load(
"libSds");
54 gSystem->Load(
"libSdsReco");
55 gSystem->Load(
"libLmd");
56 gSystem->Load(
"libLmdReco");
57 gSystem->Load(
"libLmdTrk");
61 gROOT->SetStyle(
"Plain");
62 const Int_t NRGBs = 5;
63 const Int_t NCont = 255;
64 Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
65 Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 };
66 Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
67 Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 };
68 TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
69 gStyle->SetNumberContours(NCont);
70 gStyle->SetTitleFont(10*13+2,
"xyz");
71 gStyle->SetTitleSize(0.06,
"xyz");
72 gStyle->SetTitleOffset(0.8,
"y");
73 gStyle->SetTitleOffset(1.3,
"z");
74 gStyle->SetLabelFont(10*13+2,
"xyz");
75 gStyle->SetLabelSize(0.06,
"xyz");
76 gStyle->SetLabelOffset(0.009,
"xyz");
77 gStyle->SetPadBottomMargin(0.16);
78 gStyle->SetPadTopMargin(0.16);
79 gStyle->SetPadLeftMargin(0.10);
80 gStyle->SetPadRightMargin(0.10);
81 gStyle->SetOptTitle(1);
82 gStyle->SetOptStat(1);
84 gStyle->SetFrameFillColor(0);
85 gStyle->SetFrameFillStyle(0);
86 TGaxis::SetMaxDigits(3);
94 TString simMC = storePath +
"/Lumi_MC_";
103 TChain tdigiHits(
"pndsim");
104 tdigiHits.Add(DigiFile);
107 TString fakefile = storePath +
"/fake";
112 TString out = storePath +
"/beampipe_results";
115 TFile *output_histfile =
new TFile(out,
"RECREATE");
124 FairRunAna *
fRun =
new FairRunAna();
125 fRun->SetInputFile(simMC);
126 fRun->AddFriend(DigiFile);
130 fRun->SetOutputFile(fakefile);
134 FairRuntimeDb*
rtdb = fRun->GetRuntimeDb();
135 FairParRootFileIo*
parInput1 =
new FairParRootFileIo(kTRUE);
136 parInput1->open(parFile.Data());
137 rtdb->setFirstInput(parInput1);
140 TClonesArray* true_tracks =
new TClonesArray(
"PndMCTrack");
141 tMC.SetBranchAddress(
"MCTrack", &true_tracks);
143 TClonesArray* true_points =
new TClonesArray(
"PndSdsMCPoint");
144 tMC.SetBranchAddress(
"LMDPoint", &true_points);
152 TH2* hist_xz =
new TH2F(
"hist_xz",
"hist_xz", 150, 0, 150, 1000, -40, 40);
153 TH2* hist_yz =
new TH2F(
"hist_yz",
"hist_yz", 150, 0, 150, 1000, -40, 40);
154 TH2* hist_dxdz_z =
new TH2F(
"hist_dxdz_z",
"hist_dxdz_z", 150, 0, 150,
155 60000, -1e-3, 51.e-3);
156 TH2* hist_dydz_z =
new TH2F(
"hist_dydz_z",
"hist_dydz_z", 150, 0, 150,
158 TH2* hist_mom_z =
new TH2F(
"hist_mom_z",
"hist_mom_z", 150, 0, 150,
159 3000, -1.e-5, 1.e-5);
160 TH1* hist_n_events =
new TH1F(
"hist_n_events",
"hist_n_events", 150, 0, 150);
193 int nEvents = tMC.GetEntries();
194 cout <<
" reading " << nEvents <<
" Events " << endl;
196 vector<double> pos_x;
197 vector<double> pos_z;
199 map<int,TH2*> hists_ang_acceptance;
200 map<int,TH2*>::iterator hists_ang_acceptance_it, hists_ang_acceptance_itnorm;
202 hists_ang_acceptance[-1] =
new TH2F(
"hists_ang_acceptance",
"generated angular distribution",200, -10, 10, 200, -10, 10);
203 hists_ang_acceptance_itnorm = hists_ang_acceptance.find(-1);
208 ifstream x_z_values_in(
"x_z_values_in.dat");
209 if (nEvents <= 1000 && x_z_values_in.is_open()){
210 cout <<
" ************ reading x_z_values_in.dat ************ " << endl;
213 while(x_z_values_in.good()){
214 x_z_values_in >> x >>
z;
215 if (x_z_values_in.good()){
221 x_z_values_in.close();
222 cout <<
" read " << nlines <<
" lines "<< endl;
225 for (Int_t j = 0; j <
nEvents ; j++) {
228 tdigiHits.GetEntry(j);
229 const int nParticles = true_tracks->GetEntriesFast();
232 for (Int_t iParticle = 0; iParticle < nParticles; iParticle++) {
240 hists_ang_acceptance[-1]->Fill(momMC.X()/momMC.Z()*1e3, momMC.Y()/momMC.Z()*1e3);
245 cout <<
"found " << npbar <<
" anti-protons" << endl;
247 int nHits = true_points->GetEntriesFast();
249 for (Int_t iHit = 0; iHit <
nHits; iHit++) {
251 if (mcpoint->GetTrackID() < 0)
continue;
253 mcpoint->GetTrackID());
257 TVector3 _mctrack(mcpoint->GetPx(), mcpoint->GetPy(),
268 if (plane < 0 || plane >=
nplanes) {
270 <<
" warning: calculated plane or sensor is wrong: plane "
274 if (hists_ang_acceptance.find(plane) == hists_ang_acceptance.end()){
275 stringstream hist_name;
276 stringstream hist_title;
277 hist_name <<
"hists_ang_acceptance_plane_" << plane;
278 hist_title <<
"angular acceptance at z = " << plane*10. <<
" cm " << endl;
279 hists_ang_acceptance[plane] =
new TH2F(hist_name.str().c_str(), hist_title.str().c_str(),
280 200, -10, 10, 200, -10, 10);
282 hists_ang_acceptance[plane]->Fill(momMC.X()/momMC.Z()*1e3, momMC.Y()/momMC.Z()*1e3);
284 pos_x.push_back(_mcpoint.X());
285 pos_z.push_back(_mcpoint.Z());
287 hist_xz->Fill(plane, _mcpoint.X());
288 hist_yz->Fill(plane, _mcpoint.Y());
289 hist_dxdz_z->Fill(plane, _mctrack.X() / _mctrack.Z());
290 hist_dydz_z->Fill(plane, _mctrack.Y() / _mctrack.Z());
291 hist_mom_z->Fill(plane, (_mctrack.Mag()-momMC.Mag())/momMC.Mag());
301 cout <<
"found " << nHits <<
" hit(s) with " << nSdsHits
302 <<
" sds hit(s)" << endl;
305 ofstream x_z_values_out(
"x_z_values_out.dat");
306 if (nEvents <= 1000 && x_z_values_out.is_open()){
307 cout <<
" ************ writing x_z_values_out.dat ************ " << endl;
308 for (
unsigned int iline = 0; iline < pos_x.size(); iline++){
309 x_z_values_out << pos_x[iline] <<
" " << pos_z[iline] <<
"\n";
311 x_z_values_out.close();
312 cout <<
" wrote " << pos_x.size() <<
" lines "<< endl;
317 TGraph* graph_x_z =
new TGraph( pos_x.size(), (
double*)&pos_z[0], (
double*)&pos_x[0]);
318 graph_x_z->SetNameTitle(
"graph_x_z",
"x over z hits");
320 graph_x_z->SetLineWidth(0);
321 TF1* func_beampipe =
new TF1(
"func_beampipe",
function_beampipe, 0., pos_z[pos_z.size()-1], 3);
325 func_beampipe->SetParameters(355., 6000., 40.e-3);
326 func_beampipe->SetParNames(
327 "bending start [cm] ",
328 "bending radius [cm] ",
329 "bend by phi [rad] ");
331 gStyle->SetOptFit(111);
333 TGaxis::SetMaxDigits(3);
334 TCanvas* canvas1 =
new TCanvas(
"canvas1",
"x over z hits", 1200, 800);
338 graph_x_z->Draw(
"AP");
339 graph_x_z->Fit(func_beampipe);
340 graph_x_z->GetXaxis()->SetTitle(
"z [cm]");
341 graph_x_z->GetYaxis()->SetTitle(
"x [cm]");
342 func_beampipe->Draw(
"same");
343 cout <<
" x displacement at 11 m is " << func_beampipe->Eval(1100.) << endl;
346 canvas1->Print(
"beampipe_results.png");
348 TCanvas* canvas6 =
new TCanvas(
"canvas6",
"residuals", 1200, 800);
349 TH2F* hist_res_x_z =
new TH2F(
"hist_res_x_z",
"residuals of x over z fit", 150, 0, 1500, 100, -0.1, 0.1);
350 for (
unsigned int iz = 0; iz < pos_z.size(); iz++){
351 hist_res_x_z->Fill(pos_z[iz], pos_x[iz]-func_beampipe->Eval(pos_z[iz]));
353 hist_res_x_z->Draw(
"COLZ");
354 hist_res_x_z->GetXaxis()->SetTitle(
"x [cm]");
355 hist_res_x_z->GetYaxis()->SetTitle(
"x - x_{fit} [cm]");
356 canvas6->Print(
"beampipe_results.ps(");
358 TCanvas* canvas2 =
new TCanvas(
"canvas2",
"canvas2", 1200, 800);
361 hist_yz->Draw(
"COLZ");
362 canvas2->Print(
"beampipe_results.ps(");
363 TCanvas* canvas3 =
new TCanvas(
"canvas3",
"canvas3", 1200, 800);
366 hist_dxdz_z->Draw(
"COLZ");
367 canvas3->Print(
"beampipe_results.ps(");
368 TCanvas* canvas4 =
new TCanvas(
"canvas4",
"canvas4", 1200, 800);
371 hist_dydz_z->Draw(
"COLZ");
372 canvas4->Print(
"beampipe_results.ps(");
373 TCanvas* canvas5 =
new TCanvas(
"canvas5",
"canvas5", 1200, 800);
376 hist_mom_z->Draw(
"COLZ");
377 canvas5->Print(
"beampipe_results.ps(");
378 TCanvas* canvas7 =
new TCanvas(
"canvas6",
"canvas6", 1200, 400);
379 gPad->SetLeftMargin(0.1);
380 gPad->SetRightMargin(0.05);
384 map<int, int>::iterator hits_z_it, hits_z_it_next;
385 for (hits_z_it = hits_z.begin(); hits_z_it != hits_z.end(); hits_z_it++){
386 hits_z_it_next = hits_z_it;
388 if (hits_z_it_next == hits_z.end())
break;
389 if (hits_z_it->second == 0)
continue;
390 if (hits_z_it_next->first != hits_z_it->first+1){
391 cout <<
" sorry, entries are not sorted! " << hits_z_it_next->first <<
" != " << hits_z_it->first <<
" +1 "<< endl;
394 hist_n_events->Fill(hits_z_it_next->first, ((
double)hits_z_it_next->second)/((
double)hits_z_it->second));
396 hist_n_events->GetXaxis()->SetTitle(
"z [dm]");
397 hist_n_events->GetYaxis()->SetTitle(
"relative acceptance");
398 hist_n_events->Draw(
"hist text");
399 canvas7->Print(
"beampipe_results.ps(");
401 TCanvas* canvas8 =
new TCanvas(
"canvas8",
"canvas8", 800, 400);
402 canvas8->Divide(2,1);
404 gPad->SetLeftMargin(0.16);
405 gPad->SetRightMargin(0.16);
407 hists_ang_acceptance_itnorm->second->GetXaxis()->SetTitle(
"dX/dZ x 10^{3}");
408 hists_ang_acceptance_itnorm->second->GetYaxis()->SetTitle(
"dY/dZ x 10^{3}");
409 hists_ang_acceptance_itnorm->second->Draw(
"COLZ");
411 gPad->SetLeftMargin(0.16);
412 gPad->SetRightMargin(0.16);
416 for (hists_ang_acceptance_it = hists_ang_acceptance.begin();
417 hists_ang_acceptance_it != hists_ang_acceptance.end();
418 hists_ang_acceptance_it++){
\
419 if (hists_ang_acceptance_it == hists_ang_acceptance_itnorm){
423 hists_ang_acceptance_it->second->Divide(hists_ang_acceptance_itnorm->second);
424 hists_ang_acceptance_it->second->SetMaximum(1.);
425 hists_ang_acceptance_it->second->GetXaxis()->SetTitle(
"dX/dZ x 10^{3}");
426 hists_ang_acceptance_it->second->GetYaxis()->SetTitle(
"dY/dZ x 10^{3}");
427 hists_ang_acceptance_it->second->Draw(
"COLZ");
429 canvas8->Print(
"beampipe_results.ps(");
430 canvas8->Print(
"beampipe_acceptance.gif+");
433 canvas8->Print(
"beampipe_results.ps)");
437 cout <<
"converting to pdf " << system(
"ps2pdf beampipe_results.ps")
439 cout <<
"deleting ps file " << system(
"rm beampipe_results.ps") << endl;
441 output_histfile->Write();
443 output_histfile->Close();
448 if ((
int) (
last_percent * 100) == (
int) (percent * 100))
454 for (
int i = 0;
i < len; ++
i) {
455 if (
i < static_cast<int> (len * percent)) {
461 cout <<
"[" << progress <<
"] " << (
static_cast<int> (100 * percent))
471 double end_seg_upstream = par[0];
472 double r_bend = par[1];
473 double phi_bend = par[2];
475 double end_seg_bend = end_seg_upstream+
sin(phi_bend)*r_bend;
477 if (pos_z < end_seg_upstream){
481 if (end_seg_upstream <= pos_z && pos_z < end_seg_bend){
482 result = r_bend -
cos(atan((pos_z-end_seg_upstream)/r_bend))*r_bend;
485 if (end_seg_bend <= pos_z){
486 result = (pos_z - end_seg_upstream - tan(phi_bend/2.)*r_bend)*tan(phi_bend);
Double_t function_beampipe(Double_t *x, Double_t *par)
int main(int argc, char **argv)
friend F32vec4 cos(const F32vec4 &a)
friend F32vec4 sin(const F32vec4 &a)
TVector3 GetMomentum() const
void DrawProgressBar(int len, double percent)
Int_t GetSensorID() const
Bool_t IsGeneratorCreated(void) const
int Check_particle_path()
FairParRootFileIo * parInput1
TVector3 GetPosition() const
TVector3 GetStartVertex() const