10 #include<TApplication.h> 
   14 #include<TClonesArray.h> 
   20 #include<FairRunAna.h> 
   22 #include<FairRtdbRun.h> 
   23 #include<FairRuntimeDb.h> 
   24 #include<FairParRootFileIo.h> 
   25 #include<TGeoVolume.h> 
   34 #include<FairGeoLoader.h> 
   35 #include<FairGeoInterface.h> 
   36 #include<FairGeoBuilder.h> 
   37 #include<FairGeoPcon.h> 
   38 #include<FairGeoMedia.h> 
   39 #include<TGeoManager.h> 
   43 #include <TPolyLine.h> 
   65 string geo_beampipe = 
"/home/jasinski/bin/pandaroot/macro/lmd/Promme/beampipe_201209.root";
 
   68         cout << 
" analysis tool vers. 1.4 " << endl;
 
   70         gROOT->Macro(
"$VMCWORKDIR/gconfig/rootlogon.C");
 
   71         gSystem->Load(
"libSds");
 
   72         gSystem->Load(
"libSdsReco");
 
   73         gSystem->Load(
"libLmd");
 
   74         gSystem->Load(
"libLmdReco");
 
   75         gSystem->Load(
"libLmdTrk");
 
   79                 gROOT->SetStyle(
"Plain");
 
   80                 const Int_t NRGBs = 5;
 
   81                 const Int_t NCont = 255;
 
   82                 Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
 
   83                 Double_t red[NRGBs]   = { 0.00, 0.00, 0.87, 1.00, 0.51 };
 
   84                 Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
 
   85                 Double_t blue[NRGBs]  = { 0.51, 1.00, 0.12, 0.00, 0.00 };
 
   86                 TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
 
   87                 gStyle->SetNumberContours(NCont);
 
   88                 gStyle->SetTitleFont(10*13+2,
"xyz");
 
   89                 gStyle->SetTitleSize(0.06, 
"xyz");
 
   90                 gStyle->SetTitleOffset(0.8,
"y");
 
   91                 gStyle->SetTitleOffset(1.3,
"z");
 
   92                 gStyle->SetLabelFont(10*13+2,
"xyz");
 
   93                 gStyle->SetLabelSize(0.06,
"xyz");
 
   94                 gStyle->SetLabelOffset(0.009,
"xyz");
 
   95                 gStyle->SetPadBottomMargin(0.16);
 
   96                 gStyle->SetPadTopMargin(0.16);
 
   97                 gStyle->SetPadLeftMargin(0.10);
 
   98                 gStyle->SetPadRightMargin(0.10);
 
   99                 gStyle->SetOptTitle(1);
 
  100                 gStyle->SetOptStat(1);
 
  102                 gStyle->SetFrameFillColor(0);
 
  103                 gStyle->SetFrameFillStyle(0);
 
  104                 TGaxis::SetMaxDigits(3);
 
  112         TString simMC = storePath + 
"/Lumi_MC";
 
  115         TChain tMC(
"pndsim");
 
  121         TChain tdigiHits(
"pndsim");
 
  122         tdigiHits.Add(DigiFile);
 
  125         TString fakefile = storePath + 
"/fake";
 
  130         TString out = storePath + 
"/beampipe_results";
 
  133         TFile *output_histfile = 
new TFile(out, 
"RECREATE");
 
  142         FairRunAna *
fRun = 
new FairRunAna();
 
  143         fRun->SetInputFile(simMC);
 
  144         fRun->AddFriend(DigiFile);
 
  148         fRun->SetOutputFile(fakefile);
 
  152         FairRuntimeDb* 
rtdb = fRun->GetRuntimeDb();
 
  153         FairParRootFileIo* 
parInput1 = 
new FairParRootFileIo(kTRUE);
 
  154         parInput1->open(parFile.Data());
 
  155         rtdb->setFirstInput(parInput1);
 
  158         TClonesArray* true_tracks = 
new TClonesArray(
"PndMCTrack");
 
  159         tMC.SetBranchAddress(
"MCTrack", &true_tracks); 
 
  161         TClonesArray* true_points = 
new TClonesArray(
"PndSdsMCPoint");
 
  162         tMC.SetBranchAddress(
"LMDPoint", &true_points); 
 
  170         TH2* hist_xz = 
new TH2F(
"hist_xz", 
"hist_xz", 150, 0, 150, 1000, -40, 40);
 
  171         TH2* hist_yz = 
new TH2F(
"hist_yz", 
"hist_yz", 150, 0, 150, 1000, -40, 40);
 
  172         TH2* hist_dxdz_z = 
new TH2F(
"hist_dxdz_z", 
"hist_dxdz_z", 150, 0, 150,
 
  173                         60000, -1e-3, 51.e-3);
 
  174         TH2* hist_dydz_z = 
new TH2F(
"hist_dydz_z", 
"hist_dydz_z", 150, 0, 150,
 
  176         TH2* hist_mom_z = 
new TH2F(
"hist_mom_z", 
"hist_mom_z", 150, 0, 150,
 
  177                                 3000, -1.e-5, 1.e-5);
 
  178         TH1* hist_n_events = 
new TH1F(
"hist_n_events", 
"hist_n_events", 150, 0, 150);
 
  211         int nEvents = tMC.GetEntries();
 
  212         cout << 
" reading " << nEvents << 
" Events " << endl;
 
  214         vector<double> pos_x;
 
  215         vector<double> pos_z;
 
  217         map<int,TH2*> hists_ang_acceptance; 
 
  218         map<int,TH2*>::iterator hists_ang_acceptance_it, hists_ang_acceptance_itnorm;
 
  220         hists_ang_acceptance[-1] = 
new TH2F(
"hists_ang_acceptance", 
"generated angular distribution",200, -10, 10, 200, -10, 10);
 
  221         hists_ang_acceptance_itnorm = hists_ang_acceptance.find(-1);
 
  226         ifstream x_z_values_in(
"x_z_values_in.dat");
 
  227         if (nEvents <= 1000 && x_z_values_in.is_open()){
 
  228                 cout << 
" ************ reading x_z_values_in.dat ************ " << endl;
 
  231                 while(x_z_values_in.good()){
 
  232                         x_z_values_in >> x >> 
z;
 
  233                         if (x_z_values_in.good()){
 
  239                 x_z_values_in.close();
 
  240                 cout << 
" read " << nlines << 
" lines "<< endl;
 
  268         for (Int_t j = 0; j < 
nEvents ; j++) {
 
  271                 tdigiHits.GetEntry(j);
 
  272                 const int nParticles = true_tracks->GetEntriesFast();
 
  275                 for (Int_t iParticle = 0; iParticle < nParticles; iParticle++) {
 
  283                                 hists_ang_acceptance[-1]->Fill(momMC.X()/momMC.Z()*1e3, momMC.Y()/momMC.Z()*1e3);
 
  288                         cout << 
"found " << npbar << 
" anti-protons" << endl;
 
  290                 int nHits = true_points->GetEntriesFast();
 
  292                 for (Int_t iHit = 0; iHit < 
nHits; iHit++) {
 
  294                         if (mcpoint->GetTrackID() < 0) 
continue;
 
  296                                         mcpoint->GetTrackID());
 
  300                                         TVector3 _mctrack(mcpoint->GetPx(), mcpoint->GetPy(),
 
  311                                         if (plane < 0 || plane >= 
nplanes) {
 
  313                                                                 << 
" warning: calculated plane or sensor is wrong: plane " 
  317                                                 if (hists_ang_acceptance.find(plane) == hists_ang_acceptance.end()){
 
  318                                                         stringstream hist_name;
 
  319                                                         stringstream hist_title;
 
  320                                                         hist_name << 
"hists_ang_acceptance_plane_" << plane;
 
  321                                                         hist_title << 
"angular acceptance at z = " << plane*10. << 
" cm " << endl;
 
  322                                                         hists_ang_acceptance[plane] = 
new TH2F(hist_name.str().c_str(), hist_title.str().c_str(),
 
  323                                                                         200, -10, 10, 200, -10, 10);
 
  325                                                 hists_ang_acceptance[plane]->Fill(momMC.X()/momMC.Z()*1e3, momMC.Y()/momMC.Z()*1e3);
 
  327                                                         pos_x.push_back(_mcpoint.X());
 
  328                                                         pos_z.push_back(_mcpoint.Z());
 
  330                                                 hist_xz->Fill(plane, _mcpoint.X());
 
  331                                                 hist_yz->Fill(plane, _mcpoint.Y());
 
  332                                                 hist_dxdz_z->Fill(plane, _mctrack.X() / _mctrack.Z());
 
  333                                                 hist_dydz_z->Fill(plane, _mctrack.Y() / _mctrack.Z());
 
  334                                                 hist_mom_z->Fill(plane, (_mctrack.Mag()-momMC.Mag())/momMC.Mag());
 
  344                         cout << 
"found " << nHits << 
" hit(s) with " << nSdsHits
 
  345                                         << 
" sds hit(s)" << endl;
 
  348         ofstream x_z_values_out(
"x_z_values_out.dat");
 
  349         if (nEvents <= 1000 && x_z_values_out.is_open()){
 
  350                 cout << 
" ************ writing x_z_values_out.dat ************ " << endl;
 
  351                 for (
unsigned int iline = 0; iline < pos_x.size(); iline++){
 
  352                         x_z_values_out << pos_x[iline] << 
" " << pos_z[iline] << 
"\n";
 
  354                 x_z_values_out.close();
 
  355                 cout << 
" wrote " << pos_x.size() << 
" lines "<< endl;
 
  360         TGraph* graph_x_z = 
new TGraph( pos_x.size(), (
double*)&pos_z[0], (
double*)&pos_x[0]);
 
  361         graph_x_z->SetNameTitle(
"graph_x_z",
"x over z hits");
 
  363         graph_x_z->SetLineWidth(0);
 
  364         TF1* func_beampipe = 
new TF1(
"func_beampipe", 
function_beampipe, 0., pos_z[pos_z.size()-1], 3);
 
  368         func_beampipe->SetParameters(361., 6000., 40.e-3);
 
  369         func_beampipe->SetParNames(
 
  370                         "bending start  [cm]  ",
 
  371                         "bending radius [cm]  ",
 
  372                         "bend by phi    [rad] ");
 
  373         func_beampipe->FixParameter(2,40.0e-3);
 
  374         func_beampipe->FixParameter(0,361.);
 
  375         func_beampipe->FixParameter(1,5720.);
 
  376         gStyle->SetOptFit(111);
 
  378         TGaxis::SetMaxDigits(3);
 
  379         TCanvas* canvas1 = 
new TCanvas(
"canvas1", 
"x over z hits", 1200, 800);
 
  383         graph_x_z->Draw(
"AP");
 
  384         graph_x_z->Fit(func_beampipe);
 
  385         graph_x_z->GetXaxis()->SetTitle(
"z [cm]");
 
  386         graph_x_z->GetYaxis()->SetTitle(
"x [cm]");
 
  387         func_beampipe->Draw(
"same");
 
  388         cout << 
" x displacement at 11 m is " << func_beampipe->Eval(1100.) << endl;
 
  391         canvas1->Print(
"beampipe_results.png");
 
  393         TCanvas* canvas6 = 
new TCanvas(
"canvas6", 
"residuals", 1200, 800);
 
  394         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);
 
  395         for (
unsigned int iz = 0; iz < pos_z.size(); iz++){
 
  396                 hist_res_x_z->Fill(pos_z[iz], pos_x[iz]-func_beampipe->Eval(pos_z[iz]));
 
  398         hist_res_x_z->Draw(
"COLZ");
 
  399         hist_res_x_z->GetXaxis()->SetTitle(
"x [cm]");
 
  400         hist_res_x_z->GetYaxis()->SetTitle(
"x - x_{fit} [cm]");
 
  401         canvas6->Print(
"beampipe_results.ps(");
 
  403         TCanvas* canvas2 = 
new TCanvas(
"canvas2", 
"canvas2", 1200, 800);
 
  406         hist_yz->Draw(
"COLZ");
 
  407         canvas2->Print(
"beampipe_results.ps(");
 
  408         TCanvas* canvas3 = 
new TCanvas(
"canvas3", 
"canvas3", 1200, 800);
 
  411         hist_dxdz_z->Draw(
"COLZ");
 
  412         canvas3->Print(
"beampipe_results.ps(");
 
  413         hist_dxdz_z->GetYaxis()->SetRangeUser(40.e-3, 40.05e-3);
 
  414         hist_dxdz_z->Draw(
"COLZ");
 
  415         canvas3->Print(
"beampipe_results.ps(");
 
  416         TCanvas* canvas4 = 
new TCanvas(
"canvas4", 
"canvas4", 1200, 800);
 
  419         hist_dydz_z->Draw(
"COLZ");
 
  420         canvas4->Print(
"beampipe_results.ps(");
 
  421         TCanvas* canvas5 = 
new TCanvas(
"canvas5", 
"canvas5", 1200, 800);
 
  424         hist_mom_z->Draw(
"COLZ");
 
  425         canvas5->Print(
"beampipe_results.ps(");
 
  426         TCanvas* canvas7 = 
new TCanvas(
"canvas6", 
"canvas6", 1200, 400);
 
  427         gPad->SetLeftMargin(0.1);
 
  428         gPad->SetRightMargin(0.05);
 
  432         map<int, int>::iterator hits_z_it, hits_z_it_next;
 
  433         for (hits_z_it = hits_z.begin(); hits_z_it != hits_z.end(); hits_z_it++){
 
  434                 hits_z_it_next = hits_z_it;
 
  436                 if (hits_z_it_next == hits_z.end()) 
break;
 
  437                 if (hits_z_it->second == 0) 
continue;
 
  438                 if (hits_z_it_next->first != hits_z_it->first+1){
 
  439                         cout << 
" sorry, entries are not sorted! " << hits_z_it_next->first << 
" != " << hits_z_it->first << 
" +1 "<< endl;
 
  442                 hist_n_events->Fill(hits_z_it_next->first, ((
double)hits_z_it_next->second)/((
double)hits_z_it->second));
 
  444         hist_n_events->GetXaxis()->SetTitle(
"z [dm]");
 
  445         hist_n_events->GetYaxis()->SetTitle(
"relative acceptance");
 
  446         hist_n_events->Draw(
"hist text");
 
  447         canvas7->Print(
"beampipe_results.ps(");
 
  449         TCanvas* canvas8 = 
new TCanvas(
"canvas8", 
"canvas8", 800, 400);
 
  450         canvas8->Divide(2,1);
 
  452         gPad->SetLeftMargin(0.16);
 
  453         gPad->SetRightMargin(0.16);
 
  455         hists_ang_acceptance_itnorm->second->GetXaxis()->SetTitle(
"dX/dZ x 10^{3}");
 
  456         hists_ang_acceptance_itnorm->second->GetYaxis()->SetTitle(
"dY/dZ x 10^{3}");
 
  457         hists_ang_acceptance_itnorm->second->Draw(
"COLZ");
 
  459         gPad->SetLeftMargin(0.16);
 
  460         gPad->SetRightMargin(0.16);
 
  461         system(
"rm beampipe_acceptance*.gif");
 
  464                 TImage *img = TImage::Open(
"/home/jasinski/bin/pandaroot/macro/lmd/Promme/beampipe.png");
 
  466                 double pic_width = img->GetWidth();
 
  467                 int height = floor(img->GetHeight()*width/pic_width);
 
  468                 TCanvas* canvas = 
new TCanvas(
"canvas_acceptance", 
"canvas_acceptance", width, height*2);
 
  469                 gPad->Range(0, 0, width, height*2.);
 
  472                 gPad->Range(0, 0., 1., 1.);
 
  474                 gPad->Range(0, 0, width, height);
 
  475                 double factor = 1./(-460.-1294.); 
 
  476                 double ratio = height/(double)width;
 
  478                 arc->SetLineColor(3);
 
  479                 arc->SetLineWidth(2);
 
  482         for (hists_ang_acceptance_it = hists_ang_acceptance.begin();
 
  483                         hists_ang_acceptance_it != hists_ang_acceptance.end();
 
  484                         hists_ang_acceptance_it++){
\ 
  485 		if (hists_ang_acceptance_it == hists_ang_acceptance_itnorm){
 
  491                 double x = factor*(hists_ang_acceptance_it->first*10. - 1294.);
 
  492                 cout << 
"drawing x = " << hists_ang_acceptance_it->first*10. << 
" cm at " << x << endl;
 
  493                 TLine line(x, 0., x, 1.);
 
  494                 line.SetLineColor(2);
 
  495                 line.SetLineWidth(2);
 
  498                 hists_ang_acceptance_it->second->Divide(hists_ang_acceptance_itnorm->second);
 
  499                 hists_ang_acceptance_it->second->SetMaximum(1.);
 
  500                 hists_ang_acceptance_it->second->GetXaxis()->SetTitle(
"dX/dZ x 10^{3}");
 
  501                 hists_ang_acceptance_it->second->GetYaxis()->SetTitle(
"dY/dZ x 10^{3}");
 
  504                         TPad clonepad(
"insertpad",
"insertpad",x-ratio/2.,0.,x+ratio/2.,1., 0, 1, 1);
 
  507                         gPad->SetLeftMargin(0.16);
 
  508                         gPad->SetRightMargin(0.16);
 
  509                         hists_ang_acceptance_it->second->Draw(
"COLZ");
 
  513                         canvas->Print(
"beampipe_acceptance.gif+");
 
  516                 hists_ang_acceptance_it->second->Draw(
"COLZ");
 
  520                 canvas8->Print(
"beampipe_acceptance_hists.gif+");
 
  525         canvas8->Print(
"beampipe_results.ps)");
 
  529         cout << 
"converting to pdf " << system(
"ps2pdf beampipe_results.ps")
 
  531         cout << 
"deleting ps file  " << system(
"rm beampipe_results.ps") << endl;
 
  533         output_histfile->Write();
 
  535         output_histfile->Close();
 
  540         if ((
int) (
last_percent * 100) == (
int) (percent * 100))
 
  546         for (
int i = 0; 
i < len; ++
i) {
 
  547                 if (
i < static_cast<int> (len * percent)) {
 
  553         cout << 
"[" << progress << 
"] " << (
static_cast<int> (100 * percent))
 
  563         double end_seg_upstream = par[0]; 
 
  564         double r_bend = par[1]; 
 
  565         double phi_bend = par[2]; 
 
  567         double end_seg_bend = end_seg_upstream+
sin(phi_bend)*r_bend;
 
  569         if (pos_z < end_seg_upstream){
 
  573         if (end_seg_upstream <= pos_z && pos_z < end_seg_bend){
 
  574                 result = r_bend - 
cos(atan((pos_z-end_seg_upstream)/r_bend))*r_bend;
 
  577         if (end_seg_bend <= pos_z){
 
  578                 result = (pos_z - end_seg_upstream - tan(phi_bend/2.)*r_bend)*tan(phi_bend);
 
  584     const int nsegments = 360;
 
  587     for (
int i = 0; 
i <= nsegments; 
i++){
 
  589         _x[
i] = r*
sin(angle)+
x;
 
  590         _y[
i] = r*
cos(angle)+
y;
 
  592     TPolyLine *pline_circle = 
new TPolyLine(nsegments+1,_x,_y);
 
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 
TPolyLine * Get_PolyLine_circle(float x, float y, float r)
int Check_particle_path()
FairParRootFileIo * parInput1
TVector3 GetPosition() const 
TVector3 GetStartVertex() const