StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
readWtree.C
1 // example uses bin 8 : root4star -b -q 'readWtree.C("./R13109027.lis",8,1e8)'
2 
3 class StChain;
4 class St2011WMaker;
5 
6 StChain *chain = 0;
7 St2011WMaker *wTreeMk = 0;
8 TString jetTreeDir = "";
9 bool isZ=false;
10 
11 void readWtree( const Char_t *fileList="./R13104003.lis", int etaBin=8, int maxEvents=1e8, bool spinSort=true)
12 {
13 
14  if(etaBin==8) isZ=true;
15 
16  // load shared libraries
17  gROOT -> LoadMacro("$STAR/StRoot/StMuDSTMaker/COMMON/macros/loadSharedLibraries.C");
18  loadSharedLibraries();
19  assert( !gSystem->Load("StDetectorDbMaker"));
20  assert( !gSystem->Load("StTpcDb"));
21  assert( !gSystem->Load("StDbUtilities"));
22  assert( !gSystem->Load("StDbBroker"));
23  assert( !gSystem->Load("St_db_Maker"));
24  assert( !gSystem->Load("StEEmcUtil"));
25  assert( !gSystem->Load("StWalgo2011"));
26  assert( !gSystem->Load("StSpinDbMaker"));
27  assert( !gSystem->Load("StJets"));
28  assert( !gSystem->Load("StJetEvent"));
29 
30  // create analysis chain
31  chain = new StChain("chain");
32  TObjArray* HListZ=new TObjArray;
33  TObjArray* HListEta=new TObjArray;;
34 
35  //define eta ranges (skip bin 5+6 and 9 is same as 8 except spin sorting)
36  float etaLow[9] = {-1.1,-0.5, 0.0, 0.5, 1.0, -2.0, 0.7,-1.5,-1.5};
37  float etaHigh[9] = {-0.5, 0.0, 0.5, 1.1, 2.0, -1.0, 2.5, 2.0, 2.0};
38 
39  //initiate W maker
40  wTreeMk = new St2011WMaker(Form("Eta%d",etaBin));
41  wTreeMk->setJetTreeBranch("AntiKtR060NHits12","AntiKtR060NHits12_noEEMC");
42 
43  //set cuts for barrle and endcap algos
44  wTreeMk->setWbosonCuts(25., 0.88, 14., etaLow[etaBin-1], etaHigh[etaBin-1]); //highET, nearTotEtFrac, ptBalance, etaLow, etaHigh
45  wTreeMk->setE_WbosonCuts(25., 0.85, 20., etaLow[etaBin-1], etaHigh[etaBin-1]); //highET, nearTotEtFrac, ptBalance, etaLow, etaHigh
46  wTreeMk->setHList(HListEta);
47  wTreeMk->setMaxDisplayEve(1e6); // only first N events will get displayed
48 
49  //......... spin sorting
50  if(spinSort){
51 
52  if(etaBin==8){
54  lumiMk->setHList(HListEta);
55  lumiMk->attachWalgoMaker(wTreeMk);
56  }
57 
58  enum {mxSM=2};
59  St2011pubSpinMaker *spinMkA[mxSM];
60  for(int kk=0;kk<mxSM;kk++) {
61  char ttx[100]; sprintf(ttx,"%cEta%dspin",'A'+kk,etaBin);
62  printf("add spinMaker %s %d \n",ttx,kk);
63  spinMkA[kk]=new St2011pubSpinMaker(ttx,Form("Eta%d",etaBin));
64  spinMkA[kk]->attachWalgoMaker(wTreeMk);
65  spinMkA[kk]->setHList(HListEta);
66  //assign eta bin same as W maker
67  spinMkA[kk]->setEta(etaLow[etaBin-1],etaHigh[etaBin-1]);
68  spinMkA[kk]->setEtaE(etaLow[etaBin-1],etaHigh[etaBin-1]);
69  if(kk==1) spinMkA[kk]->setQPT(false); //disable Q/pT cut
70 
71  //special cases
72  if(etaBin==7) {
73  spinMkA[kk]->setEta(999.,999.); //mask barrel for for etaBin 7
74  }
75  if(etaBin==8) {
76  spinMkA[kk]->setEta(-1.,1.); //diff eta range for spin sorting
77  spinMkA[kk]->setEtaE(999.,999.); //mask endcap for for etaBin 8
78  }
79  }
80  }
81 
82  // Z maker
83  if (isZ){
84  ZMk=new St2011ZMaker("Z");
85  ZMk->attachWalgoMaker(wTreeMk);
86  ZMk->setHList(HListZ);
87  ZMk->setNearEtFrac(0.88);
88  ZMk->setClusterMinEt(14);
89  ZMk->setPhi12Min(3.1416/2.);
90  ZMk->setMinZMass(70.); // Zmass -20%
91  ZMk->setMaxZMass(110.);// Zmass +20%
92  }
93 
94  //chain W and jet trees in W maker
95  chainFiles(fileList);
96 
97  chain->ls(3);
98  chain->Init();
99 
100  Int_t nevents = wTreeMk->getNumberOfEvents();
101  cout<<nevents<<" events in chain"<<endl;
102  if(nevents<1) {cout<<"No events in chain, check your list file"<<endl; return; }
103 
104  Int_t stat = 0; Int_t event = 0;
105  while ( !stat )
106  {
107  if ( nevents>=0 )
108  if ( event>=nevents || event > maxEvents) break;
109  chain -> Clear();
110  stat = chain->Make();
111  event++;
112  }
113 
114  char *file1=fileList;
115  printf("file1=%s=%s=\n",file1);
116  TString outFile=""; outFile+=file1;
117  outFile.ReplaceAll(".lis",Form("_Eta%d.wana.hist.root",etaBin));
118  outFile.ReplaceAll("lists/treeReader/","");
119  TFile *outF=new TFile(outFile,"RECREATE");
120  if(outF->IsOpen()){
121  TDirectory *Eta = outF->mkdir(Form("Eta%d",etaBin));
122  Eta->cd();
123  HListEta->Write();
124  if(isZ){
125  TDirectory *Z = outF->mkdir("Z");
126  Z->cd();
127  HListZ->Write();
128  }
129  cout<<endl<<" Histo saved -->"<<outFile<<endl;
130  }
131  else
132  cout<<endl<<" Couldn't open file "<<outFile<<endl;
133 
134  delete outF;
135 
136 
137 }
138 
139 // ----------------------------------------------------------------------------
140 void chainFiles(const Char_t *fileList)
141 {
142 
143  cout << "chaining files from list: " << fileList << endl;
144 
145  ifstream f(fileList);
146  char str[200];
147  while (f >> str) {
148  TString name=str;
149  if ( name.Contains("root") )
150  wTreeMk->chainFile(name);
151 
152  //chain jet files
153  TString jetName=jetTreeDir;
154  jetName+=name.ReplaceAll("wtree/","jets/jets_");
155  jetName.ReplaceAll(".Wtree","");
156  wTreeMk->chainJetFile(jetName);
157  }
158 
159 }
160 
spin sorting of W&#39;s
muDst based extraction of W-signal from pp500 data from 2011
Definition: St2011WMaker.h:49
accumulates alternative rel lumi monitors based on jet events
uses tree from W-algo to find Zs
Definition: St2011ZMaker.h:26