StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TT.C
1 // #ifndef __CINT__
2 #define T_cxx 1
3 #include <assert.h>
4 #include "TH1.h"
5 #include "TH2.h"
6 #include "TStyle.h"
7 #include "TCanvas.h"
8 #include "TF1.h"
9 #include "TT.h"
10 
11 //ClassImp(TreeClass);
12 // #endif
13 
14 TreeClass *TreeClass::Create() {
15  printf("Hello Create\n");
16 // return ::new TreeClass((TTree*)0);
17  return ::new TreeClass();
18 }
19 void TT() { printf("Hello Van\n"); TreeClass::Create(); printf("bye Van\n");}
20 
21 //empty constructor *************************************************
22 
23  TreeClass::TreeClass() : TBase() {}
24 
25 //constructor (*file) ***********************************************
26 
27  TreeClass::TreeClass(TFile *f) : TBase() {
28  fOutFileName = "Out.root";
29  if (f) {
30  cout << f->GetName() << " file has been found" << endl;
31  fOutFileName = f->GetName();
32  fOutFileName.ReplaceAll("/","_");
33  fOutFileName.ReplaceAll(".root","");
34  fOutFileName += "Out.root";
35  TTree *tree = (TTree*) f->Get("T");
36  if (tree) { MyInit(tree); }
37  else cout << "no TTree found" << endl;
38  }
39  }
40 
41 //constructor ( *tree) *********************************************************
42 
43  TreeClass::TreeClass(TTree *tree) : TBase(tree) {
44  // if parameter tree is not specified (or zero):
45  // try to make the Tree using available files
46  if (tree == 0) {
47  TCollection *files = gROOT->GetListOfFiles();
48  if (! files) { cout << "no root files" << endl; return; }
49  TIter next(files);
50  TFile *f = 0;
51 // TChain * chain = new TChain("T");
52  Int_t Files = 0;
53  ULong64_t Events = 0;
54  ULong64_t TotalE = 0;
55  while ( (f = (TFile *) next()) ) {
56  tree = (TTree*) f->Get("T");
57  if (tree) {
58  cout << f->GetName() << " file hase been found" << endl;
59  fOutFileName = f->GetName();
60  fOutFileName.ReplaceAll("/","_");
61  fOutFileName.ReplaceAll(".root","");
62  fOutFileName += "Out.root";
63  Files++;
64  Events = tree->GetEntries();
65  TotalE += Events;
66  cout << "#\t" << Files << "\t" << f->GetName() << "\t" << Events << endl;
67 // chain->Add(f->GetName());
68  break;
69  }
70  }
71  }
72  if (tree) {MyInit(tree);}
73  }
74 
75 //*********************************************************************
76 void TreeClass::Loop(Int_t Nevents) {
77 
78 struct Geometry_t {
79  Int_t Barrel;
80  Int_t Layer;
81  Int_t NoLadders;
82  Int_t NoWafers;
83 };
84 const Int_t NSvtLayers = 6;
85 // Barrel, Layer ladder wafer
86 const Geometry_t SvtSsdConfig[] =
87  { {1, 1, 8, 4}, // even
88  {1, 2, 8, 4}, // odd
89  {2, 3, 12, 6}, // event
90  {2, 4, 12, 6}, // odd
91  {3, 5, 16, 7}, // even
92  {3, 6, 16, 7}, // odd
93  {4, 7, 20, 16} // Ssd
94  };
95 //const Int_t BL[4] = {8, 12, 16, 20}; // ladders in barrel
96 
97  struct PlotPar_t {
98  Char_t *Name;
99  Char_t *Title;
100  Int_t nx;
101  Int_t ny;
102  Double_t xmin;
103  Double_t xmax;
104  Double_t ymin;
105  Double_t ymax;
106  };
107  const PlotPar_t plotTB = // plots for time bins and anodes
108  { "timeB","time for 80 anodes", 256, 3, 0.,128., 0.,3. };
109 
110  const PlotPar_t plotUP = // plots for uP
111  { "uP","track u", 320, 3, -5.,5., 0.,3. };
112 
113  const PlotPar_t plotDu = // plots for u-uP
114  { "Du","Du before cut", 250, 3, -2.,2., 0.,3. };
115 
116  const PlotPar_t plotDuv = // plots for du & dv
117  { "Du","Du cuts", 200, 3, -1.,1., 0.,3. };
118 
119  TFile *fOut = new TFile(fOutFileName,"recreate");
120 
121  Xdcor X1;
122  X1.InitSptr();
123 
124  TString Name;
125  TString Title;
126  TString uName;
127  TString uTitle;
128  const Int_t NB = 3;
129  const Int_t NL = 16;
130  const Int_t NW = 7;
131  const Int_t NH = 2;
132  const Int_t NA = 3;
133  // B L W H A
134  TH1F *LocPlots[NB][NL][NW][NH][NA];
135  TH1F * uPlots[NB][NL];
136  TH1F * uPlBLW[NB][NL][NW];
137  TH1F * hpT = new TH1F( "Pt", "pt", 200, -2., 2.);
138  TH1F * hpM = new TH1F( "Ptot", "ptot", 200, 0., 5.);
139  TH1F * LocAll = new TH1F( "All", "all", plotTB.nx, plotTB.xmin, plotTB.xmax);
140  TH1F * uPAll = new TH1F("UPall","uPall", plotUP.nx, plotUP.xmin, plotUP.xmax);
141  TH1F * uAll = new TH1F("Uall", "ua", plotUP.nx, plotUP.xmin, plotUP.xmax);
142  TH1F * duB[NB][2];
143  TH1F * dvB[NB];
144  TH1F * uCuts[NB][NL];
145  TH1F * xCuts[NB][NL];
146  TH1F * uCut = new TH1F("Ucut","uc", plotDu.nx, plotDu.xmin, plotDu.xmax);
147  TH1F * vCut = new TH1F("Vcut","vc", 200, -3., 3.);
148  TH2F * dMin = new TH2F("DMin","vumin",100,-0.75,0.75,100,-0.75,0.75);
149  TH1F * vMin = new TH1F("VMin","vmin", plotDuv.nx, plotDuv.xmin, plotDuv.xmax);
150  TH1F * uMin = new TH1F("UMin","umin", plotDuv.nx, plotDuv.xmin, plotDuv.xmax);
151  TH1F * uMinC = new TH1F("UMinC","umC", plotDuv.nx, plotDuv.xmin, plotDuv.xmax);
152  memset(LocPlots,0,NB*NL*NW*NH*sizeof(TH1F *));
153  memset( uPlots,0,NB*NL*sizeof(TH1F *));
154  for (int B = 0; B < 3; B++) {// over svt Barrels
155  uName = Form("UBarrel%i", B+1);
156  uTitle = Form("du for B%i", B+1);
157  duB[B][0] = new TH1F(uName, uTitle, plotDuv.nx, plotDuv.xmin, plotDuv.xmax );
158  uName = Form("VBarrel%i", B+1);
159  uTitle = Form("dv for B%i", B+1);
160  dvB[B] = new TH1F(uName, uTitle, plotDuv.nx, plotDuv.xmin, plotDuv.xmax );
161  uName = Form("UBarrel%iVcut", B+1);
162  uTitle = Form("du for B%i after Vcut", B+1);
163  duB[B][1] = new TH1F(uName, uTitle, plotDuv.nx, plotDuv.xmin, plotDuv.xmax );
164  }
165  for (Int_t L = 0; L < NSvtLayers; L++) {// over Layers
166  Int_t barrel = SvtSsdConfig[L].Barrel;
167  Int_t layer = SvtSsdConfig[L].Layer;
168  Int_t NoLadders = SvtSsdConfig[L].NoLadders;
169  Int_t NoWafers = SvtSsdConfig[L].NoWafers;
170  for (Int_t ladder = 1; ladder <= NoLadders; ladder++) {
171  if (barrel <= 3 && (ladder-1)%2 != layer%2) continue;
172  uName = plotUP.Name;
173  uName += Form("L%02iB%i", ladder, barrel);
174  uTitle = Form("uP for layer %i B %i L %i", layer, barrel, ladder);
175  uPlots[barrel-1][ladder-1] =
176  new TH1F(uName, uTitle, plotUP.nx, plotUP.xmin, plotUP.xmax );
177 
178  uName = Form("%sL%02iB%i", plotDu.Name, ladder, barrel);
179  uTitle = Form("u-uP for B %i L %i", barrel, ladder);
180  uCuts[barrel-1][ladder-1]=
181  new TH1F(uName, uTitle, plotDu.nx, plotDu.xmin, plotDu.xmax );
182  uName = Form("%sxL%02iB%i", plotDu.Name, ladder, barrel);
183  uTitle = Form("u-uP corr B %i L %i", barrel, ladder);
184  xCuts[barrel-1][ladder-1]=
185  new TH1F(uName, uTitle, plotDu.nx, plotDu.xmin, plotDu.xmax );
186  for (Int_t wafer = 1; wafer <= NoWafers; wafer++) {// wafer == 0 for whole ladder
187  uName = plotUP.Name;
188  uName += Form("L%02iB%iW%i", ladder, barrel, wafer);
189  uTitle = Form("uP for layer %i B %i L %i W %i", layer, barrel, ladder, wafer);
190  uPlBLW[barrel-1][ladder-1][wafer-1] =
191  new TH1F(uName, uTitle, plotUP.nx, plotUP.xmin, plotUP.xmax );
192  for (Int_t hybrid = 1; hybrid <= 2; hybrid++) {
193  for (Int_t anode =1; anode <=3; anode++) {
194  Name = plotTB.Name;
195  Name += Form("L%02iB%iW%02iH%iA%i", ladder, barrel, wafer, hybrid, anode);
196  Title = Form("%s for layer %i B %i L %i W %i H %i G %i",
197  plotTB.Title, layer, barrel, ladder, wafer, hybrid, anode);
198  LocPlots[barrel-1][ladder-1][wafer-1][hybrid-1][anode-1] =
199  new TH1F(Name, Title, plotTB.nx, plotTB.xmin, plotTB.xmax );
200  }
201  }
202  }
203  }
204  }
205  Long64_t nentries = fChain->GetEntriesFast();
206  if (Nevents > 0 && nentries > Nevents) nentries = Nevents;
207  Long64_t nbytes = 0, nb = 0;
208  Int_t TreeNo = -1;
209  TString currentFile("");
210 
211  for (Long64_t jentry=0; jentry<nentries;jentry++) {
212  Long64_t ientry = LoadTree(jentry);
213  if (ientry < 0) break;
214  nb = fChain->GetEntry(jentry); nbytes += nb;
215  if (! jentry%1000 || TreeNo != fChain->GetTreeNumber()) {
216  cout << "Read event \t" << jentry
217  << " so far, switch to file " << fChain->GetCurrentFile()->GetName()
218  << endl;
219  cout << " current TreeNo: " << TreeNo
220  << " new TreeNo: " << fChain->GetTreeNumber() << endl;
221  TreeNo = fChain->GetTreeNumber();
222  }
223 // if (VertexZCut > 0 && TMath::Abs(fVertex[2]) > VertexZCut) continue;
224  UInt_t Ntrack = fNPTracks;
225 // int k_used[100000] = {0};
226  for (UInt_t trk = 0; trk < Ntrack; trk++) {
227  int hitFlag[3][16][7] = { { { 0 } } };
228  Int_t Npoints = fTracks_fNpoint[trk];
229  if (minNoFitPoints > 0 && Npoints%100 < minNoFitPoints) continue;
230  if (UseSsd && Npoints < 1000) continue;
231  if (UseSvt && Npoints < 100) continue;
232  Int_t Nsp = fTracks_fNsp[trk];
233  double dvmin = 1000.;
234  double dumin = 1000.;
235  int kmin;
236  for (Int_t hit = 0; hit < Nsp; hit++) {
237  Int_t k = fTracks_fIdHitT[trk][hit] - 1;
238 // assert(k>=0);
239  if ( k < 0) cout <<" k <0:"<<k<<" hit="<<hit<<" Nsp="<<Nsp<< endl;
240  if ( k < 0) continue;
241  Int_t layer = fHits_layer[k];
242  if (layer <= NSvtLayers ){
243  Int_t barrel = fHits_barrel[k];
244  Int_t ladder = fHits_ladder[k];
245  Int_t wafer = fHits_wafer[k];
246  Int_t hybrid = fHits_hybrid[k];
247 
248  Double32_t u = fHits_u[k];
249  Double32_t v = fHits_v[k];
250  Double32_t uP = fHits_uP[k];
251  Double32_t vP = fHits_vP[k];
252  Double32_t du = u - uP;
253  Double32_t dv = v - vP;
254  Double32_t anode = fHits_anode[k];
255  Double32_t timeb = fHits_timeb[k];
256 
257  hpT->Fill(fHits_pT[k]);
258  hpM->Fill(fHits_pMom[k]);
259  if (TMath::Abs(fHits_pT[k]) < 0.2) continue;
260  if ( TMath::Abs(dv) < TMath::Abs(dvmin) ) {dvmin = dv; dumin= du; kmin = k;}
261 
262  if ( hitFlag[barrel-1][ladder-1][wafer-1] == 0) {
263  hitFlag[barrel-1][ladder-1][wafer-1] = 1;
264  uPAll->Fill( uP );
265  uPlots[barrel-1][ladder-1]->Fill( uP );
266  uPlBLW[barrel-1][ladder-1][wafer-1] ->Fill( uP );
267  }
268 
269  duB[barrel-1][0]->Fill(du);
270  dvB[barrel-1]->Fill(dv);
271  vCut->Fill(dv);
272  if (TMath::Abs(dv) > rCut ) continue;
273  uCut->Fill(du);
274  uCuts[barrel-1][ladder-1]->Fill(du);
275 
276  int hid = X1.GetHid (barrel, ladder, wafer, hybrid);
277  double dux = uP - X1.Sptr[hid]->Coord( timeb );
278  xCuts[barrel-1][ladder-1]->Fill(dux);
279 
280  duB[barrel-1][1]->Fill(du);
281  if (TMath::Abs(du) > 2.*rCut) continue;
282 
283  Int_t group = ((Int_t)anode)/80;
284  if (group >= 3) group = 2;
285  if (group < 0) group = 0;
286  LocPlots[barrel-1][ladder-1][wafer-1][hybrid-1][group]->Fill( timeb );
287  LocAll->Fill( timeb );
288  uAll->Fill( u );
289  X1.Sptr[hid]->addStat( timeb, u, uP);
290 
291  } //layer if
292  } //hits loop
293  if (TMath::Abs(dvmin) < 1000.) {
294  dMin->Fill(dvmin,dumin);
295  vMin->Fill(dvmin);
296  uMin->Fill(dumin);
297  if (TMath::Abs(dvmin) < rCut ) uMinC->Fill(dumin);
298  }
299  } //track loop
300  } //jentry loop (event loop)
301  X1.solve();
302  fOut->Write();
303 } //end of Loop()
304 
305 
Definition: T.C:13
Definition: T.h:18
Definition: TBase.h:17
Definition: TT.h:19
Definition: Xdcor.h:54