StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
analysis.cxx
1 #ifdef __CINT__
2 
3 #pragma link off all globals;
4 #pragma link off all classes;
5 #pragma link off all functions;
6 
7 #pragma link C++ class PlotFile;
8 #endif
9 
10 #ifndef __CINT__
11 #include <iostream>
12 #include <iomanip>
13 #include <sys/types.h>
14 #include <sys/stat.h>
15 #include <dirent.h>
16 
17 #include "math.h"
18 #include "string.h"
19 
20 #include "TROOT.h"
21 #include "TFile.h"
22 
23 #include "TChain.h"
24 #include "TH1.h"
25 #include "TH2.h"
26 #include "TStyle.h"
27 #include "TCanvas.h"
28 #include "TProfile.h"
29 #include "TTree.h"
30 #include "TNtuple.h"
31 #include "TRandom.h"
32 #include "TMath.h"
33 #include "TVector2.h"
34 #include "TSystem.h"
35 #include "TUnixSystem.h"
36 #endif
37 using namespace std;
38 
39 #include "tof.h"
40 
41 int main(int argc, char **argv)
42 {
43  if(argc !=2) exit(1);
44  if(!gSystem) TUnixSystem *gSystem = new TUnixSystem();
45 
46  //----------------------------------
47  // Open files and add to the chain
48  //----------------------------------
49  TChain *chain = new TChain("tof");
50 
51  //void* dir = gSystem->OpenDirectory(gSystem->expandpathname(argv[1]));
52  //cout << gSystem->expandpathname(argv[1]) << endl;
53  int nruns=0;
54  char *file_name;
55  TString Tname;
56  char file_list[2500][256];
57 
58  cout << " execute : " << argv[0] << " " << argv[1] << endl;
59 // do {
60  //file_name = (char*)gSystem->GetDirEntry(dir);
61  file_name = argv[1];
62  Tname=file_name;
63  cout << Tname.Data() << endl;
64  if (file_name && Tname.Contains("root")) {
65  //sprintf(file_list[nruns],"%s/%s",argv[1],file_name);
66  sprintf(file_list[nruns],"./%s",file_name);
67  //if(nruns>1) {
68  chain->Add(file_list[nruns]);
69  cout << " read in " << file_list[nruns] << endl;
70  //}
71  nruns++;
72  }
73  //} while (file_name);
74 
75  //----------------------
76  // Book the histograms
77  //----------------------
78  Float_t mrpcA[32] = { 0., 0., 0., 0., 0., 0., 16., 16.,
79  20., 22., 22., 22., 22., 22., 26., 26.,
80  26., 26., 30., 30., 32., 32., 32., 32.,
81  32., 32., 32., 32., 32., 32., 32., 32.};
82  Int_t MIdStart[8] = {1, 7, 9, 10, 15, 19, 21, 33};
83  TH2D *mYLocal[7];
84  TH2D *mZLocal[7];
85  TH2D *mYLocalPhi[7]; // vs phi
86  TH2D *mZLocalPhi[7]; // vs phi
87  for(int i=0;i<7;i++) {
88  char name[100];
89  sprintf(name,"yLocal_%d",i);
90  mYLocal[i] = new TH2D(name,"",120,0.,120.,500,-5.,5.);
91  sprintf(name,"zLocal_%d",i);
92  mZLocal[i] = new TH2D(name,"",120,0.,120.,600,-6.,6.);
93  sprintf(name,"yLocalPhi_%d",i);
94  mYLocalPhi[i] = new TH2D(name,"",120,-3.,717.,500,-5.,5.);
95  sprintf(name,"zLocalPhi_%d",i);
96  mZLocalPhi[i] = new TH2D(name,"",120,-3.,717.,600,-6.,6.);
97  }
98  TH2D *mYLocalAll = new TH2D("yLocal_all","",120,0.,120.,500,-5.,5.);
99  TH2D *mYLocalPhiAll = new TH2D("yLocalPhi_all","",120,0.,120.,500,-5.,5.);
100 
101  //--------------------
102  // loop the chain
103  //--------------------
104  // TTree *tree = (TTree *)chain->GetTree();
105  int nevents = (int)chain->GetEntries();
106  cout << "== total entries : " << nevents << endl;
107 
108  tof *t = new tof(chain);
109  for(int i=0;i<nevents;i++){
110  if(i%10000==0) cout << "begin " << i << "th entry...." << endl;
111  t->GetEntry(i);
112 
113  float vz = t->vertexZ;
114  if(fabs(vz)>30.) continue;
115 
116  int nhits = t->nTofHits;
117  for(int j=0;j<nhits;j++) {
118  int nHits = t->nHitsFit[j];
119  if(abs(nHits)<25) continue;
120 // float dcaXY = sqrt(pow(t->dcaX[j],2.)+pow(t->dcaY[j],2.));
121 // if(dcaXY>1.) continue;
122 // float dcaZ = t->dcaZ[j];
123 // if(fabs(dcaZ)>1.) continue;
124  float pt = t->pt[j];
125  if(pt<0.5) continue;
126 
127 
128  int tray = t->tray[j];
129  int module = t->module[j];
130  int m_index = -1;
131  for(int k=0;k<7;k++) {
132  if(module>=MIdStart[k] && module <MIdStart[k+1]) {
133  m_index = k; break;
134  }
135  }
136  if(m_index<0 || m_index>=7 ) continue;
137 
138  float phi;
139  if(tray<=60) {
140  phi = 72. - (tray-1)*6.;
141  if(phi<-3.) phi+= 360.;
142  } else {
143  phi = 108 + (tray-61) * 6;
144  if(phi>357.) phi-= 360.;
145 
146  phi += 360.; // shifted by 360 for east
147  }
148 
149  float yLocal = t->yLocal[j];
150  float zLocal = t->zLocal[j];
151  mYLocalPhi[m_index]->Fill(phi, yLocal);
152  mZLocalPhi[m_index]->Fill(phi, zLocal);
153 
154  mYLocal[m_index]->Fill(tray-1, yLocal);
155  mZLocal[m_index]->Fill(tray-1, zLocal);
156 
157  mYLocalAll->Fill(tray-1, yLocal);
158  mYLocalPhiAll->Fill(phi, yLocal);
159  }
160  } // end event looping
161 
163  // histograms output
165  TFile *f2 = new TFile("align.root","recreate");
166  f2->cd();
167  for(int i=0;i<7;i++) {
168  mYLocal[i]->Write();
169  mZLocal[i]->Write();
170  mYLocalPhi[i]->Write();
171  mZLocalPhi[i]->Write();
172  }
173  mYLocalAll->Write();
174  mYLocalPhiAll->Write();
175  f2->Close();
176 
177  cout<<"end of program"<<endl;
178  return(0);
179  exit(0);
180 }
Definition: tof.h:15