StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
readStL3Trigger.C
1 // author: c.struck
2 //
3 // readL3Events.C
4 //
5 // exapmle macro for L3 tree of StEvent
6 // ====================================
7 //
8 //
9 // $Id: readStL3Trigger.C,v 1.1 2002/02/13 22:37:39 struck Exp $
10 //
11 // $Log: readStL3Trigger.C,v $
12 // Revision 1.1 2002/02/13 22:37:39 struck
13 // new version of readStEvent.C ==>> readStL3Trigger.C
14 //
15 
16 
17 
18 #include "iostream.h"
19 
20 // histos
21 TH1F *hnHitsOffline = new TH1F("hnHitsOffline", "nHits, global tracks", 42, 3.5, 45.5);
22 TH2F *hdEdx = new TH2F("hdEdx", "dEdx vs p", 1000, 0, 2.5, 1200, 0, 30);
23 
24 TH1F *hpt = new TH1F("hpt", "pt", 200, 0, 7);
25 
26 // track ntuple
27 TNtuple *trackNtuple = new TNtuple("trackNtuple", "l3t tracks",
28  "px:py:pz:r0:phi0:z0:q:nHits:dedx:nDedx:chi2xy:chi2sz");
29 
30 // prototypes
31 
32 // void readL3Events(Int_t nEvents, const Char_t ** fileList);
33 // void readL3Events(Int_t startEvent, Int_t nEvents, const Char_t **fileList);
34 // void readL3Events(Int_t startEvent, Int_t nEvents, const Char_t *file);
35 // void readL3Events(Int_t nEvents, const Char_t *file);
36 
37 
38 // ------------------ Here is the actual method -----------------------------------------
39 void readL3Events(Int_t nEvents, const Char_t **fileList)
40 {
41 
42  cout << endl << endl <<" readL3Events - input # events = " << nEvents << endl;
43  Int_t ilist=0;
44  while (fileList[ilist]) {
45  cout << " readL3Events - input fileList = " << fileList[ilist] << endl;
46  ilist++;
47  }
48 
49  gSystem->Load("St_base");
50  gSystem->Load("StarRoot");
51  gSystem->Load("StChain");
52  gSystem->Load("StUtilities");
53  gSystem->Load("libglobal_Tables");
54  gSystem->Load("StAnalysisUtilities");
55  gSystem->Load("StIOMaker");
56  gSystem->Load("StarClassLibrary");
57  gSystem->Load("StEvent");
58 
59  // histos
60  // TH1F *hnHits = new TH1F("hnHits", "nHits, global tracks", 42, 3.5, 45.5);
61  // TH2F *hdEdx = new TH2F("hdEdx", "dEdx vs p", 1000, 0, 2.5, 1200, 0, 30);
62 
63  // create chain
64  chain = new StChain("MyChain");
65 
66  // handle file list
67  StFileI *setFiles =0;
68  if (fileList) {
69  setFiles= new StFile(fileList);
70  }
71 
72  // connect to the .event.root file
73  StIOMaker *IOMk = new StIOMaker("IO","r",setFiles,"bfcTree");
74  IOMk->SetIOMode("r");
75  IOMk->SetBranch("*",0,"0"); //deactivate all branches
76  //StIOMaker *IOMk = new StIOMaker("IO","r",
77  // "/star/rcf/pwg/spectra/struck/He3Events/st_physics_1231015_raw_0008.event.tpc_tracks.root",
78  // "bfcTree");
79  IOMk->SetBranch("eventBranch",0,"r");
80  //IOMk->SetIOMode("r");
81 
82 
83  // Initialize chain
84  Int_t iInit = chain->Init();
85 
86  int istat = 0;
87  int iEvent = 1;
88 
89  // Event loop
90  while (iEvent<(nEvents+1) && istat!=2) {
91 
92  // reset chain for upcoming event
93  chain->Clear();
94 
95  // call Make only for StIOMaker
96  istat = chain->Make(iEvent);
97  cout << "\n\n====================== ";
98  cout <<"Working on Event number " << (iEvent) << endl;
99 
100  // get StEvent
101  myEvent = (StEvent*) chain->GetInputDS("StEvent");
102  if (!myEvent) {
103  cout <<"No StEvent found.\n";
104  break;
105  }
106 
107  // get L0 trigger word
108  StL0Trigger* myL0Trigger = myEvent->l0Trigger();
109  if (!myL0Trigger) {
110  cout <<"No l0 trigger found.\n";
111  //break;
112  }
113  else printf("Trigger Word: 0x%x\n", myL0Trigger->triggerWord());
114 
115  // get L3 data
116  myL3Trigger = (StL3Trigger*) myEvent->l3Trigger();
117  if (!myL3Trigger) {
118  cout <<"No l3 found inside StEvent.\n";
119  iEvent++;
120  continue;
121  }
122 
123  // get L3 event summary
124  const StL3EventSummary* myL3EventSummary = myL3Trigger->l3EventSummary();
125  if (!myL3EventSummary) {
126  cout << "No l3 event summary found." << endl;
127  continue;
128  }
129 
130  // print summary info
131  cout << "Global Counters: #processed = " << myL3EventSummary->numberOfProcessedEvents()
132  << ", #reconstructed = " << myL3EventSummary->numberOfReconstructedEvents()
133  << ", #tracks = " << myL3EventSummary->numberOfTracks()
134  << endl;
135 
136  printf("L0 trigger word: %x\n", myL3EventSummary->l0TriggerWord());
137 
138  // check unbiased
139  if (myL3EventSummary->unbiasedTrigger()==true)
140  cout << "unbiased Trigger: YES" << endl;
141  else
142  cout << "unbiased Trigger: NO" << endl;
143 
144  // print algorithm info for all algorithms
145  unsigned int nAlgorithms = myL3EventSummary->numberOfAlgorithms();
146  cout << "Number of L3 algorithms for this run: " << nAlgorithms << endl;
147  const StSPtrVecL3AlgorithmInfo& myL3AlgInfo = myL3EventSummary->algorithms();
148  for (int i=0; i<nAlgorithms; i++) {
149  int algId = myL3AlgInfo[i]->id();
150  const int nProcessed = myL3AlgInfo[i]->numberOfProcessedEvents();
151  const int nAccept = myL3AlgInfo[i]->numberOfAcceptedEvents();
152  const int nBuild = myL3AlgInfo[i]->numberOfBuildEvents();
153  if (myL3AlgInfo[i]->build()) cout << "**";
154  cout << " alg id " << algId
155  << ":\t #proc " << nProcessed
156  << "\t #accept " << nAccept
157  << "\t #build " << nBuild
158  << "\t preScale " << myL3AlgInfo[i]->preScale()
159  << "\t postScale " << myL3AlgInfo[i]->postScale()
160  << "\t intPara ";
161  for (int j=0; j<myL3AlgInfo[i]->intParameterSize(); j++) {
162  cout << myL3AlgInfo[i]->intParameter(j) << " ";
163  }
164  cout << "\t floatPara ";
165  for (int k=0; k<myL3AlgInfo[i]->floatParameterSize(); k++) {
166  cout << myL3AlgInfo[i]->floatParameter(k) << " ";
167  }
168  cout << endl;
169  }
170 
171  // print triggered algorithms
172  const StPtrVecL3AlgorithmInfo& myL3TriggerAlgInfo = myL3EventSummary->algorithmsAcceptingEvent();
173  cout << "Number of L3 algorithms which triggered this event: "
174  << myL3TriggerAlgInfo->size() << endl;
175  cout << "triggered algorithms: ";
176  for (int i=0; i<myL3TriggerAlgInfo->size(); i++) {
177  cout << myL3TriggerAlgInfo[i]->id() << " ";
178  }
179  cout << endl;
180 
181  // get L3 vertex
182  if (myL3Trigger->primaryVertex()) {
183  cout << "L3 Vertex = ( " << myL3Trigger->primaryVertex()->position()->x()
184  << ", " << myL3Trigger->primaryVertex()->position()->y()
185  << ", " << myL3Trigger->primaryVertex()->position()->z()
186  << " )" << endl;
187  }
188 
189  // Loop over tracks
190  if (false) {
191  StSPtrVecTrackNode& mtracknodes = (StSPtrVecTrackNode&) myL3Trigger->trackNodes();
192  cout << " nubmer of tracks " << mtracknodes->size() << endl;
193  for (Int_t i=0; i<mtracknodes->size(); i++) {
194 
195  Int_t id = i;
196  Float_t px = mtracknodes[i]->track(0)->geometry()->momentum()->x();
197  Float_t py = mtracknodes[i]->track(0)->geometry()->momentum()->y();
198  Float_t pz = mtracknodes[i]->track(0)->geometry()->momentum()->z();
199 
200  Short_t nHits = mtracknodes[i]->track(0)->detectorInfo()->numberOfPoints();
201  Short_t q = mtracknodes[i]->track(0)->geometry()->charge();
202  Float_t psi = mtracknodes[i]->track(0)->geometry()->psi();
203  Float_t tanl = tan(mtracknodes[i]->track(0)->geometry()->dipAngle());
204  Float_t curv = mtracknodes[i]->track(0)->geometry()->curvature();
205 
206  Float_t r0 = mtracknodes[i]->track(0)->geometry()->origin()->perp();
207  Float_t phi0 = mtracknodes[i]->track(0)->geometry()->origin()->phi();
208  Float_t z0 = mtracknodes[i]->track(0)->geometry()->origin()->z();
209 
210  Float_t dedx = 0;
211  Short_t nDedx = 0;
212 
213  Float_t chi2xy = (Float_t) mtracknodes[i]->track(0)->fitTraits()->chi2(0) / nHits;
214  Float_t chi2sz = (Float_t) mtracknodes[i]->track(0)->fitTraits()->chi2(1) / nHits;
215 
216  StSPtrVecTrackPidTraits &traits = mtracknodes[i]->track(0)->pidTraits();
217  StDedxPidTraits *pid;
218  if (traits.size()) {
219  pid = dynamic_cast<StDedxPidTraits*>(traits[0]);
220  if (pid) {
221  dedx = pid->mean();
222  nDedx = pid->numberOfPoints();
223  }
224  }
225 
226  trackNtuple->Fill(px, py, pz, r0, phi0, z0,
227  (Float_t) q, (Float_t) nHits, dedx, (Float_t) nDedx, chi2xy, chi2sz);
228 
229  Float_t pt = sqrt(px*px +py*py);
230 
231 
232  hnHitsOffline->Fill(nHits);
233 
234  hpt->Fill(pt);
235 
236 
237  if (nHits>22 && dedx>0) {
238  hdEdx->Fill(mtracknodes[i]->track(0)->geometry()->momentum()->mag(), dedx);
239  }
240 
241 
242  if (i<5 || i%1000==0) {
243  cout << "L3 Track : " << i << "\t";
244  cout << "px : " << Double_t (mtracknodes[i]->track(0)->geometry()->momentum()->x()) << "\t";
245  cout << "py : " << Double_t (mtracknodes[i]->track(0)->geometry()->momentum()->y()) << "\t";
246  cout << "pz : " << Double_t ( mtracknodes[i]->track(0)->geometry()->momentum()->z()) << "\t";
247 // cout << "x : " << mtracknodes[i]->track(0)->geometry()->origin()->x() << "\t";
248 // cout << "y : " << mtracknodes[i]->track(0)->geometry()->origin()->y() << "\t";
249 // cout << "z : " << mtracknodes[i]->track(0)->geometry()->origin()->z() << "\n";
250 // cout << "chi^2_xy : " << mtracknodes[i]->track(0)->fitTraits()->chi2(0);
251 // cout << " chi^2_sz : " << mtracknodes[i]->track(0)->fitTraits()->chi2(1) << "\n";
252  cout << "dca : " << mtracknodes[i]->track(0)->impactParameter() << "\t";
253  cout << "dedx : " << dedx << "\n";
254  }
255  } // for (i<mtracknodes)
256  }
257 
258  // check hits
259 // int totalNHits = 0;
260 // StTpcHitCollection* myTpcHitColl;
261 
262 // myTpcHitColl = ml3trigger->tpcHitCollection();
263 
264 // for (iSec=0; iSec<24; iSec++) {
265 // cout << " sector: " << iSec
266 // << "--> #Hits: " << myTpcHitColl->sector(iSec)->numberOfHits()
267 // << endl;
268 // totalNHits += myTpcHitColl->sector(iSec)->numberOfHits();
269 // }
270 // cout << " total #hits: " << totalNHits << endl;
271 
272  iEvent++;
273 
274  } // while (iEvent<nEvents && istat!=2)
275 
276 // TFile *f = new TFile("L3NTuple.root","recreate");
277 // trackNtuple->Write();
278 // f->Close();
279 
280 
281 }
282 
283 
284 //--------------------------------------------------------------------------
285 
286 void readL3Events(const Int_t nEvents, const Char_t *file)
287 {
288  cout << "*file = " << file << endl;
289  const char *fileListQQ[]={0,0};
290  fileListQQ[0]=file;
291  readL3Events(nEvents, fileListQQ);
292 }
Definition: StTree.h:125
virtual void SetIOMode(Option_t *iomode="w")
number of transactions
Definition: StIOInterFace.h:35
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StChain.cxx:77
virtual Int_t Make()
Definition: StChain.cxx:110