StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
SpinAnalysisTreeReaderMIT.C
1 void SpinAnalysisTreeReaderMIT(const long nevents = 20) {
2  LoadSpinTreeLibs();
3 
4  //create a new reader
5  StSpinTreeReader *reader = new StSpinTreeReader();
6 
7  //add some files to analyze, one at a time or in a text file
8  reader->selectDataset("StSpinTree/datasets/run6_mit.dataset");
9  //reader->selectFile("./spinAnalyses_6119039.tree.root");
10 
11  //configure the branches you're interested in (default = true)
12  reader->connectJets = true;
13  reader->connectNeutralJets = false; //only in Run6
14  reader->connectChargedPions = true;
15  reader->connectBemcPions = true;
16  reader->connectBemcElectrons = true;
17  reader->connectEemcPions = false; //not added yet
18 
19  //optionally filter events by run and trigger
20  //reader->selectRunlist("StSpinTree/filters/run6_jets.runlist");
21  reader->selectRun(7132007);
22  //reader->removeRun(7143025);
23 
24  //select events that passed hardware OR software trigger for any trigger in list
25  reader->selectTrigger(137221);
26  reader->selectTrigger(137222);
27  reader->selectTrigger(137611);
28  reader->selectTrigger(137622);
29  reader->selectTrigger(5);
30 
31  //we can change the OR to AND by doing
32  reader->requireDidFire = true;
33  reader->requireShouldFire = true;
34 
35  StJetSkimEvent *ev = reader->event();
36 
37  long entries = reader->GetEntries();
38  if(entries > nevents) entries = nevents;
39  for(int i=0; i<entries; i++) {
40  reader->GetEntry(i);
41 
42  //the basics: run, event, etc.
43  int runId = ev->runId();
44  int eventId = ev->eventId();
45 
46  printf("----------------Reading Event %d of %d----------------\n",i+1,entries);
47  printf("basics: Run = %d, Event = %d\n",runId,eventId);
48 
49  //triggers -- note prescale/threshold access
50  TClonesArray *trigs = ev->triggers();
51  for(int j=0; j<trigs->GetEntries(); j++) {
52  StJetSkimTrig* aTrig = (StJetSkimTrig*)trigs->At(j);
53  int trigId = aTrig->trigId();
54  bool didFire = aTrig->didFire();
55  int shouldFire = aTrig->shouldFire();
56 
57  StJetSkimTrigHeader *header = ev->trigHeader(trigId);
58  if(!header) {
59  printf("ERROR LOADING TRIGGER HEADER FOR %d\n",trigId);
60  break;
61  }
62  float prescale = header->prescale;
63 
64  printf("trigger = %6d prescale = %8.1f didFire = %d shouldFire =% d\n",trigId,prescale,didFire,shouldFire);
65  }
66 
67  //vertices -- bestVert() will return NULL if none were found
68  int nVertices = ev->vertices()->GetEntries();
69  StJetSkimVert *bestVert = ev->bestVert();
70  if(bestVert) {
71  printf("nVertices = %d position of best = %f\n",nVertices,bestVert->position()[2]);
72  }
73  else if(nVertices == 0){
74  printf("no vertices found in this event\n");
75  }
76  else {
77  printf("ERROR LOADING BEST VERTEX IN THIS EVENT\n");
78  }
79 
80  //for more details on event-level quantities see StJetMaker skim event documentation and examples
81 
82  //jets -- could also access using jets pointer from above
83  printf("nJets = %d\n",reader->nJets());
84  for(int j=0; j<reader->nJets(); j++) {
85  StJet* aJet = reader->jet(j);
86  double R = aJet->btowEtSum/aJet->Et();
87  if(bestVert) printf("jet pt=%7.4f jet eta=% 1.4f det eta=% 1.4f E_neu/E_tot=%1.4f\n",aJet->jetPt,aJet->jetEta,aJet->detEta(bestVert->position()[2]),R);
88  else printf("jet pt=%7.4f jet eta=% 1.4f no vertex E_neu/E_tot=%1.4f\n",aJet->jetPt,aJet->jetEta,R);
89  }
90 
91  //charged pions
92  printf("nChargedPions = %d\n",reader->nChargedPions());
93  for(int j=0; j<reader->nChargedPions(); j++) {
94  StChargedPionTrack* aPion = reader->chargedPion(j);
95  printf("pt=%7.4f eta=% 1.4f nSigmaPion=% 1.4f\n",aPion->pt(),aPion->eta(),aPion->nSigmaPion());
96  }
97 
98  //neutral pions
99  printf("nNeutralPions = %d\n",reader->nBemcPions());
100  for(int j=0; j<reader->nBemcPions(); j++) {
101  TPi0Candidate* aPi0 = reader->bemcPion(j);
102  printf("neutral pion mass=%f pt=%f eta=%f\n",aPi0->Mass(),aPi0->Pt(),aPi0->Eta());
103  }
104 
105  cout << "-----------------------------------------------------" << endl;
106  }
107 
108  delete reader;
109 }
110 
111 void LoadSpinTreeLibs() {
112  gSystem->Load("StarSpinAnalyses");
113 }
float nSigmaPion() const
Returns Craig&#39;s distance to the calculated dE/dx band for pions in units of sigma.
float jetPt
Pt (stored for convenience when drawing TTree)
Definition: StJet.h:125
float jetEta
Eta (stored for convenience when drawing TTree)
Definition: StJet.h:128
float pt() const
Returns pT at point of dca to primary vertex.
float eta() const
Returns pseudo rapidity at point of dca to primary vertex.
float btowEtSum
The summed Et from Barrel towers.
Definition: StJet.h:116
Definition: StJet.h:91