FairRoot/PandaRoot
structure_analysis_emc.C
Go to the documentation of this file.
1 // The macro plot structure of emc fwd endcap.
2 // In each box, which corresponds to crystal its two indexes are printed
3 // In the GUI two indexes and detectorID are shown in statusbar when mouse point over the crystal position
4 // Button "Save" save the drawing to the emc_structure.ps file which can be zoomed.
5 // The input file, which macro uses set at the top of the macro "file_name="
6 // it is output of the simulation, which contain the FAIRGeom object, from which PndEmcStructure is initialised
7 // Button "Recreate" recreate "structure.txt" from which GUI read positions of crystals and their indexes
8 
9 
10 #include <TApplication.h>
11 #include <TGClient.h>
12 #include <TGButton.h>
13 #include <TGFrame.h>
14 #include <TFrame.h>
15 #include <TRootEmbeddedCanvas.h>
16 #include <TGStatusBar.h>
17 #include <TCanvas.h>
18 #include <TF1.h>
19 #include <TRandom.h>
20 #include <TGraph.h>
21 #include <TAxis.h>
22 
23 string file_name="sim_emc.root";
24 
26 {
27  gROOT->SetStyle("Plain");
28 
29  gROOT->LoadMacro("$VMCWORKDIR/gconfig/rootlogon.C");
30  gROOT->LoadMacro("$VMCWORKDIR/gconfig/basiclibs.C");
31  rootlogon();
32  basiclibs();
33 
34  // The file structure.txt which contain for each detector in Fwd Endcap detectorId, two indexes and x,y,z coordinates
35  ifstream f;
36  f.open("structure.txt");
37 
38  if (!f.is_open())
39  {
40  std::cout<<"File does not exist"<<std::endl;
41  TFile* fsim = new TFile(file_name.c_str());
42  TTree *tsim=(TTree *) fsim->Get("pndsim") ;
44  PndEmcStructure::Instance()->Print("structure.txt",2);
45  std::cout<<"File with emc structure is created"<<std::endl;
46 
47  // Delete lines from the file, which are not relatd to forward EMC
48  string line;
49  ifstream in("structure.txt");
50  ofstream out("outfile.txt");
51  //copy first line
52  getline(in,line);
53  out<<line<<"\n";
54 
55  while (getline(in,line))
56  {
57  if (line[0]!='3') continue; // Forward endcap start from 3
58  out<<line<<"\n";
59  }
60 
61  in.close();
62  out.close();
63  remove("structure.txt");
64  rename("outfile.txt","structure.txt");
65  std::cout<<"All but Forward emc is removed"<<std::endl;
66  std::cout<<"Done"<<std::endl;
67  }
68  else
69  {
70  f.close();
71  }
72 
73 
74  // Popup the GUI...
75  new MyMainFrame(gClient->GetRoot(), 200, 200);
76 
77  return 0;
78 }
79 
80 
81 
82 class MyMainFrame : public TGMainFrame {
83 
84 private:
85  TRootEmbeddedCanvas *fEcan;
86  TGStatusBar *fStatusBar;
87 
88 public:
89  MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
90  virtual ~MyMainFrame();
91  void DoExit();
92  void DoDraw();
93  void DoSave();
94  void DoRecreate();
95 
96  void SetStatusText(const char *txt, Int_t pi);
97  void EventInfo(Int_t event, Int_t px, Int_t py, TObject *selected);
98 
99  ClassDef(MyMainFrame, 0)
100 };
101 
103 {
104  TCanvas *c1 = fEcan->GetCanvas();
105  ifstream f;
106  f.open("structure.txt");
107  c1->Range(-120,-120,120,120);
108 
109  Double_t x,y,z;
110  long index;
111  Int_t iX, iY;
112  TPaveLabel *pt[5000];
113  Int_t i_crys=0;
114  Double_t tr = 2.51875; // Size of the Crystal in its center (cm)
115 
116  //Position of the first line with numbers
117  f.seekg(30);
118  while (f>>index>>iX>>iY>>x>>y>>z)
119  {
120  // check if tci belongs to Forward Endcap
121  if ((iX<200)||(iX>300)) continue;
122  if (i_crys%100==0) std::cout<<"Crystal in fwd endcap = "<<i_crys<<std::endl;
123  i_crys++;
124 
125  TString label="";
126  label+=iX;
127  label+=",";
128  label+=iY;
129 
130  TString name="";
131  name+=index;
132 
133  pt[i_crys] = new TPaveLabel(x-tr/2.,y-tr/2., x+tr/2., y+tr/2.,label.Data());
134  pt[i_crys]->SetBorderSize(1);
135  pt[i_crys]->SetName(name);
136  pt[i_crys]->Draw();
137  }
138 
139  // TCanvas::Update() draws the frame, after which it can be changed
140  c1->Update();
141  c1->Modified();
142  c1->Update();
143 }
144 
146 {
147  printf("Exit application...");
148  gApplication->Terminate(0);
149 }
150 
152 {
153  std::cout<<"Recreate structure.txt"<<std::endl;
154  TFile* fsim = new TFile(file_name.c_str());
155  TTree *tsim=(TTree *) fsim->Get("pndsim") ;
157  PndEmcStructure::Instance()->Print("structure.txt",2);
158  std::cout<<"File with emc structure is created"<<std::endl;
159 
160  // Delete lines from the file, which are not relatd to forward EMC
161  string line;
162  ifstream infile("structure.txt");
163  ofstream outfile("outfile.txt");
164  //copy first linef
165  getline(infile,line);
166  outfile<<line<<"\n";
167 
168  while (getline(infile,line))
169  {
170  if (line[0]!='3') continue; // Forward endcap start from 3
171  outfile<<line<<"\n";
172  }
173 
174  infile.close();
175  outfile.close();
176  remove("structure.txt");
177  rename("outfile.txt","structure.txt");
178  std::cout<<"All but Forward emc is removed"<<std::endl;
179  std::cout<<"Done"<<std::endl;
180 
181 
182 }
183 
185 {
186 
187  TCanvas *c1 = fEcan->GetCanvas();
188  c1->SaveAs("emc_structure.ps");
189  std::cout<<"Structure is saved to emc_structure.ps"<<std::endl;
190 }
191 
192 void MyMainFrame::SetStatusText(const char *txt, Int_t pi)
193 {
194  // Set text in status bar.
195  fStatusBar->SetText(txt,pi);
196 }
197 
198 void MyMainFrame::EventInfo(Int_t event, Int_t px, Int_t py, TObject *selected)
199 {
200 // Writes the event status in the status bar parts
201 
202  const char *text2;
203  char text0[50], text1[50];
204  sprintf(text0, "(iX,iY)=%s", selected->GetTitle());
205  SetStatusText(text0,0);
206  sprintf(text1, "detId=%s", selected->GetName());
207  SetStatusText(text1,1);
208  text2 = selected->GetObjectInfo(px,py);
209  SetStatusText(text2,2);
210 }
211 
212 MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) :
213  TGMainFrame(p, w, h)
214 {
215  // Create the embedded canvas
216  fEcan = new TRootEmbeddedCanvas(0,this,500,400);
217  Int_t wid = fEcan->GetCanvasWindowId();
218  TCanvas *myc = new TCanvas("MyCanvas", 10,10,wid);
219  fEcan->AdoptCanvas(myc);
220  myc->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)","MyMainFrame",this,
221  "EventInfo(Int_t,Int_t,Int_t,TObject*)");
222 
223  AddFrame(fEcan, new TGLayoutHints(kLHintsTop | kLHintsLeft |
224  kLHintsExpandX | kLHintsExpandY,0,0,1,1));
225  // status bar
226  Int_t parts[] = {34, 33, 33};
227  fStatusBar = new TGStatusBar(this, 50, 10, kVerticalFrame);
228  fStatusBar->SetParts(parts, 3);
229  fStatusBar->Draw3DCorner(kFALSE);
230  AddFrame(fStatusBar, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
231 
232  // Create a horizontal frame containing two buttons
233  TGHorizontalFrame *hframe = new TGHorizontalFrame(this, 200, 40);
234 
235  TGTextButton *draw = new TGTextButton(hframe, "&Draw");
236  draw->Connect("Clicked()", "MyMainFrame", this, "DoDraw()");
237  hframe->AddFrame(draw, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
238  TGTextButton *exit = new TGTextButton(hframe, "&Exit ");
239  exit->Connect("Pressed()", "MyMainFrame", this, "DoExit()");
240  hframe->AddFrame(exit, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
241 
242  TGTextButton *save = new TGTextButton(hframe, "&Save ");
243  save->Connect("Clicked()", "MyMainFrame", this, "DoSave()");
244  hframe->AddFrame(save, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
245 
246  TGTextButton *recreate = new TGTextButton(hframe, "&Recreate ");
247  recreate->Connect("Clicked()", "MyMainFrame", this, "DoRecreate()");
248  hframe->AddFrame(recreate, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
249 
250  AddFrame(hframe, new TGLayoutHints(kLHintsCenterX, 2, 2, 2, 2));
251 
252  // Set a name to the main frame
253  SetWindowName("EMC Forward Endcap structure");
254  MapSubwindows();
255 
256  // Initialize the layout algorithm via Resize()
257  Resize(GetDefaultSize());
258 
259  // Map main frame
260  MapWindow();
261 }
262 
263 
265 {
266  // Clean up main frame...
267  Cleanup();
268  delete fEcan;
269 }
Double_t p
Definition: anasim.C:58
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
basiclibs()
exit(0)
void SetStatusText(const char *txt, Int_t pi)
TGStatusBar * fStatusBar
TRootEmbeddedCanvas * fEcan
#define pi
Definition: createSTT.C:60
Emc geometry mapper.
Definition: PndEmcMapper.h:22
MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h)
TString pt(TString pts, TString exts="px py pz")
Definition: invexp.C:133
void Print(string, Int_t option=1) const
Double_t
int structure_analysis_emc()
PndEmcMapper * emcMap
TFile * f
Definition: bump_analys.C:12
Double_t z
TFile * out
Definition: reco_muo.C:20
c1
Definition: plot_dirc.C:35
TString name
Double_t x
SttMvdTracking Cleanup()
Double_t y
static PndEmcStructure * Instance()
void EventInfo(Int_t event, Int_t px, Int_t py, TObject *selected)
TFile infile("dedx_out.root","READ")
static PndEmcMapper * Instance()
string file_name
TString outfile