StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
trsNtuple.C
1 // $Id: trsNtuple.C,v 1.2 1999/06/24 20:24:57 kathy Exp $
2 // $Log: trsNtuple.C,v $
3 // Revision 1.2 1999/06/24 20:24:57 kathy
4 // updated comment lines at top
5 //
6 //======================================================================
7 // owner: Herb Ward
8 // what it does: see below
9 //======================================================================
11 // For creating and filling an ntuple for testing Trs.
12 // Herb Ward, April 10 1999.
13 // To use this macro:
14 // 1. Using an editor, modify your macro bfc.C:
15 // a. At the top of the file, near where "chain" is declared,
16 // declare "trsNtuple" by inserting this line:
17 // class TNtuple; TNtuple *trsNtuple=0;
18 // b. Before the event loop (after chain->Init())insert this line:
19 // trsNtuple = MakeTrsNtuple();
20 // c. In the event loop, immediately after chain->Make(),
21 // insert this line
22 // FillTrsNtuple(chain,trsNtuple);
23 // 2. Start root, load this file, run the macro from step 1, and then
24 // draw histograms.
25 // $ echo $DISPLAY
26 // $ echo $STAR
27 // $ rootPstar
28 // root [0] .L trsNtuple.C
29 // root [1] .x bfc.C
30 // root [2] trsNtuple->Draw("xgeant:xtphit","","lego");
32 class StChain;
33 TNtuple *MakeTrsNtuple() {
34  TNtuple *trstest;
35  trstest = new TNtuple("trs","trs",
36  "xgeant:ygeant:zgeant:crossAngle:tanl:xtphit:ytphit:ztphit:q");
37  return trstest;
38 }
39 void FillTrsNtuple(StChain *theChain,TNtuple *trstest) {
40 
41  int tphitIdx,indexIdx,geantIdx,indexIdx,geantNrow,tphitNrow,indexNrow;
42  int geantKey,tphitKey;
43  Float_t p0,p1,p2;
44 
45  St_DataSetIter *iter0=new St_DataSetIter(theChain); if(!iter0) return;
46 
47  St_g2t_tpc_hit *geantObj=
48  (St_g2t_tpc_hit*)iter0(".make/geant/.data/g2t_tpc_hit");
49  if(!geantObj) { printf("Error 96.\n"); return; }
50  g2t_tpc_hit_st *geantTbl=(g2t_tpc_hit_st*) geantObj->GetTable();
51  if(!geantTbl) { printf("Error 396.\n"); return; }
52  geantNrow=geantObj->GetNRows();
53 
54  St_tcl_tpc_index *indexObj=iter0(".make/tpc_hits/.data/index");
55  if(!indexObj) { printf("Error 66.\n"); return; }
56  tcl_tpc_index_st *indexTbl=(tcl_tpc_index_st*) indexObj->GetTable();
57  if(!indexTbl) { printf("Error 396.\n"); return; }
58  indexNrow=indexObj->GetNRows();
59 
60  St_tcl_tphit *tphitObj=iter0(".make/tpc_hits/.data/tphit");
61  if(!tphitObj) { printf("Error 76.\n"); return; }
62  tcl_tphit_st *tphitTbl=(tcl_tphit_st*) tphitObj->GetTable();
63  if(!tphitTbl) { printf("Error 396.\n"); return; }
64  tphitNrow=tphitObj->GetNRows();
65 
66  for(indexIdx=0;indexIdx<indexNrow;indexIdx++) {
67 
68  geantKey=indexTbl[indexIdx].key1;
69  for(geantIdx=geantNrow-1;geantIdx>=0;geantIdx--) {
70  if(geantTbl[geantIdx].id==geantKey) break;
71  }
72  if(geantIdx<0) { printf("no match key1 (%d).\n",geantKey); continue; }
73 
74  tphitKey=indexTbl[indexIdx].key2;
75  for(tphitIdx=tphitNrow-1;tphitIdx>=0;tphitIdx--) {
76  if(tphitTbl[tphitIdx].id==tphitKey) break;
77  }
78  if(tphitIdx<0) { printf("no match key2 (%d).\n",tphitKey); continue; }
79 
80  p0=geantTbl[geantIdx].p[0];
81  p1=geantTbl[geantIdx].p[1];
82  p2=geantTbl[geantIdx].p[2];
83 
84  trstest->Fill(
85  (Float_t)(geantTbl[geantIdx].x[0]),
86  (Float_t)(geantTbl[geantIdx].x[1]),
87  (Float_t)(geantTbl[geantIdx].x[2]),
88  (Float_t)(atan2(p0,p1)),
89  (Float_t)(atan(p2/sqrt(p0*p0+p1*p1))),
90  (Float_t)(tphitTbl[tphitIdx].x),
91  (Float_t)(tphitTbl[tphitIdx].y),
92  (Float_t)(tphitTbl[tphitIdx].z),
93  (Float_t)(tphitTbl[tphitIdx].q)
94  );
95  }
96 }