StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
rdMuWana2012.C
1 // example by hand, run 11: root4star -b -q 'rdMuWana2012.C(500000,"./R12099030.lis",0,2,330801,330851,"","/star/institutions/iucf/stevens4/run12w/ana/run11long/jets/")'
2 
3 class StChain;
4 StChain *chain=0;
5 
6 int rdMuWana2012(
7  int nEve=1e6,
8  char* file = "",
9  int isMC=0, // 0=data 35X=embedding
10  int useJetFinder = 0, // 0 - no jets=badWalgo; 1 generate jet trees; 2 read jet trees
11  int idL2BWtrg=0, // offline Ids needed for real data
12  int idL2EWtrg=0, // run 9 L2EW
13  // make those below empty for scheduler
14  char* muDir = "",
15  char* jetDir = "",
16  char* histDir = "",
17  char* wtreeDir = "",
18  int spinSort=true,
19  bool findZ=true,
20  int geant=false
21  ) {
22 
23  if(isMC==0) jetDir="./";
24 
25  //if(isMC && useJetFinder==2) geant=true;
26 
27  if(isMC) spinSort=false;
28  TString outF=file;
29  if(isMC==0) {
30  outF=file;
31  printf("Unpack file=%s=\n",file);
32  char *file1=strstr(file,"/R")+1;
33  printf("file1=%s=%s=\n",file1);
34  outF=file1; file1=outF.Data();
35  printf("OutF=%s=\n",outF.Data());
36  }
37  else if(isMC < 400) {
38  char *file1;
39  //private 2012 MC
40  if(isMC==100) file1=strstr(file,"j");
41  //embedding run with geant files
42  if(isMC==350) file1=strstr(file,"W");
43  if(isMC==351) file1=strstr(file,"Wminus_tau");
44  if(isMC==352) file1=strstr(file,"Z");
45  assert(file1); printf("file1=%s=\n",file1);
46  outF=file1;
47  }
48  else { // bad isMC flag
49  cout<<"bad isMC flag"<<endl; return;
50  }
51  outF=outF.ReplaceAll(".lis","");
52  outF.ReplaceAll(".MuDst.root","");
53  printf("TRIG ID: L2BW=%d, L2EW=%d isMC=%d useJetFinder=%d\n",idL2BWtrg,idL2EWtrg,isMC, useJetFinder );
54 
55 
56  gROOT->LoadMacro("$STAR/StRoot/StMuDSTMaker/COMMON/macros/loadSharedLibraries.C");
57  loadSharedLibraries();
58  gROOT->LoadMacro("LoadLogger.C");
59  gMessMgr -> SwitchOff("D");
60  gMessMgr -> SwitchOn("I");
61 
62  assert( !gSystem->Load("StDaqLib"));
63 
64  // libraries below are needed for DB interface and trigger
65  assert( !gSystem->Load("StDetectorDbMaker")); // for St_tpcGasC
66  assert( !gSystem->Load("StTpcDb"));
67  assert( !gSystem->Load("StDbUtilities")); //for trigger simu
68  assert( !gSystem->Load("StDbBroker"));
69  assert( !gSystem->Load("St_db_Maker"));
70  assert( !gSystem->Load("StEEmcUtil"));
71  assert( !gSystem->Load("StEEmcDbMaker"));
72  assert( !gSystem->Load("StSpinDbMaker"));
73  assert( !gSystem->Load("StTriggerFilterMaker"));
74  assert( !gSystem->Load("StTriggerUtilities"));
75 
76  // load jet libraries
77  if (useJetFinder ==1 || useJetFinder == 2){ // jetfinder/jetreader libraries
78  cout << "BEGIN: loading jetfinder libs" << endl;
79  gSystem->Load("StEmcRawMaker");
80  gSystem->Load("StEmcADCtoEMaker");
81  gSystem->Load("StEmcTriggerMaker");
82  gSystem->Load("StMCAsymMaker");
83  gSystem->Load("StRandomSelector");
84  gSystem->Load("libfastjet.so");
85  gSystem->Load("libsiscone.so");
86  gSystem->Load("libsiscone_spherical.so");
87  gSystem->Load("libfastjetplugins.so");
88  gSystem->Load("StJetFinder");
89  gSystem->Load("StJetSkimEvent");
90  gSystem->Load("StJets");
91  gSystem->Load("StJetEvent");
92  gSystem->Load("StJetMaker");
93  cout << "END: loading jetfinder libs" << endl;
94  }
95  else {
96  cout << "\nWARN: Jet are NOT read in, W-algo will not wrk properly\n " << endl;
97  }
98 
99  // load W algo libraries
100  assert( !gSystem->Load("StWalgo2011"));
101 
102  if(geant){ // libraries for access to MC record
103  assert( !gSystem->Load("StMcEvent"));
104  assert( !gSystem->Load("StMcEventMaker"));
105  }
106 
107  cout << " loading done " << endl;
108 
109  // create chain
110  chain = new StChain("StChain");
111  // create histogram storage array (everybody needs it):
112  TObjArray* HList=new TObjArray;
113  TObjArray* HListTpc=new TObjArray;
114 
115  int nFiles=1000;
116  if(geant){
117  //split MuDst file list to geant files
118  ifstream infile(file); string line;
119  StFile *setFiles= new StFile(); int j=0;
120  while(infile.good()){
121  getline (infile,line);
122  TString name = line;
123  name.ReplaceAll(".MuDst.root",".geant.root");
124  name.ReplaceAll("muDst/","geant/");
125  if(line=="") break;
126  setFiles->AddFile(name.Data());
127  j++;
128  if(j%10==0) cout<<"Added "<<j<<" files:"<<name.Data()<<endl;
129  if(j==nFiles) break;
130  }
131 
132  // get list of geant files
133  StIOMaker* ioMaker = new StIOMaker("IO","r",setFiles,"bfcTree");
134  //ioMaker->SetDebug();
135  ioMaker->SetIOMode("r");
136  ioMaker->SetBranch("*",0,"0"); //deactivate all branches
137  ioMaker->SetBranch("geantBranch",0,"r");//activate geant Branch
138  }
139 
140  // Now we add Makers to the chain...
141  muMk = new StMuDstMaker(0,0,muDir,file,"MuDst.root",nFiles);
142 #if 0
143  muMk->SetStatus("*",0);
144  muMk->SetStatus("MuEvent",1);
145  muMk->SetStatus("EmcTow",1);
146  muMk->SetStatus("EmcSmde",1);
147  muMk->SetStatus("EmcSmdp",1);
148  muMk->SetStatus("EEmcSmdu",1);
149  muMk->SetStatus("EEmcSmdv",1);
150  muMk->SetStatus("EEmcPrs",1);
151  muMk->SetStatus("PrimaryVertices",1);
152  muMk->SetStatus("GlobalTracks",1);
153  muMk->SetStatus("PrimaryTracks",1);
154 #endif
155  TChain* tree=muMk->chain(); assert(tree);
156  int nEntries=(int) tree->GetEntries();
157  printf("total eve in muDst chain =%d\n",nEntries); // return ;
158  if(nEntries<0) return;
159 
160 
161  //for EEMC, need full db access:
162  St_db_Maker *dbMk = new St_db_Maker("StarDb","MySQL:StarDb","MySQL:StarDb","$STAR/StarDb");
163 
164  if (isMC==0) {
165  //data
166  dbMk->SetFlavor("Wbose2","bsmdeCalib");// Willie's abs gains E-plane, run 9
167  dbMk->SetFlavor("Wbose2","bsmdpCalib"); // P-plane
168  }
169  else if (isMC<400) {
170  if(isMC>=350) dbMk->SetMaxEntryTime(20130520,0); // run 12 embedding
171  }
172  else {
173  printf("???? unforeseen MC flag, ABORT\n"); assert(1==2);
174  }
175 
176 
177  //.... load EEMC database
178  StEEmcDbMaker* mEEmcDatabase = new StEEmcDbMaker("eemcDb");
179 
180  if(geant){
181  StMcEventMaker *mcEventMaker = new StMcEventMaker();
182  mcEventMaker->doPrintEventInfo = false;
183  mcEventMaker->doPrintMemoryInfo = false;
184  }
185 
186  //.... Jet finder code ....
187  if (useJetFinder > 0) {
188  TString jetFile = jetDir; jetFile+="jets_"+outF+".root";
189  cout << "BEGIN: running jet finder/reader =" <<jetFile<<"="<< endl;
190  }
191 
192  StSpinDbMaker *spDb=0;
193  if(spinSort || useJetFinder == 1 ) spDb=new StSpinDbMaker("spinDb");
194 
195 
196  if (useJetFinder == 1){// run jet finder
197  double pi = atan(1.0)*4.0;
198  // Makers for clusterfinding
199  StEmcADCtoEMaker *adc = new StEmcADCtoEMaker();
200 
201  // Jet maker
202  StJetMaker2009* jetmaker = new StJetMaker2009;
203  jetmaker->setJetFile(jetFile);
204 
205  // Set analysis cuts for 12-point branch
206  StAnaPars* anapars12 = new StAnaPars;
207  anapars12->useTpc = true;
208  anapars12->useBemc = true;
209  anapars12->useEemc = true;
210  anapars12->setTowerEnergyCorrection(new StjTowerEnergyCorrectionForTracksFraction(1.00));
211 
212  // TPC cuts
213  anapars12->addTpcCut(new StjTrackCutFlag(0));
214  anapars12->addTpcCut(new StjTrackCutNHits(12));
215  anapars12->addTpcCut(new StjTrackCutPossibleHitRatio(0.51));
216  anapars12->addTpcCut(new StjTrackCutDca(3));
217  anapars12->addTpcCut(new StjTrackCutTdcaPtDependent);
218  anapars12->addTpcCut(new StjTrackCutPt(0.2,200));
219  anapars12->addTpcCut(new StjTrackCutEta(-2.5,2.5));
220  anapars12->addTpcCut(new StjTrackCutLastPoint(125));
221 
222  // BEMC cuts
223  anapars12->addBemcCut(new StjTowerEnergyCutBemcStatus(1));
224  anapars12->addBemcCut(new StjTowerEnergyCutAdc(4,3)); // ADC-ped>4 AND ADC-ped>3*RMS
225  anapars12->addBemcCut(new StjTowerEnergyCutEt(0.2));
226 
227  // EEMC cuts
228  anapars12->addEemcCut(new StjTowerEnergyCutBemcStatus(1));
229  anapars12->addEemcCut(new StjTowerEnergyCutAdc(4,3)); // ADC-ped>4 AND ADC-ped>3*RMS
230  anapars12->addEemcCut(new StjTowerEnergyCutEt(0.2));
231 
232  // Jet cuts
233  anapars12->addJetCut(new StProtoJetCutPt(3.5,200));
234  anapars12->addJetCut(new StProtoJetCutEta(-100,100));
235 
236  // Set analysis cuts for 12-point noEEMC branch
237  StAnaPars* anapars12_noEEMC = new StAnaPars;
238  anapars12_noEEMC->useTpc = true;
239  anapars12_noEEMC->useBemc = true;
240  anapars12_noEEMC->useEemc = true;
241  anapars12_noEEMC->setTowerEnergyCorrection(new StjTowerEnergyCorrectionForTracksFraction(1.00));
242 
243  // TPC cuts
244  anapars12_noEEMC->addTpcCut(new StjTrackCutFlag(0));
245  anapars12_noEEMC->addTpcCut(new StjTrackCutNHits(12));
246  anapars12_noEEMC->addTpcCut(new StjTrackCutPossibleHitRatio(0.51));
247  anapars12_noEEMC->addTpcCut(new StjTrackCutDca(3));
248  anapars12_noEEMC->addTpcCut(new StjTrackCutTdcaPtDependent);
249  anapars12_noEEMC->addTpcCut(new StjTrackCutPt(0.2,200));
250  anapars12_noEEMC->addTpcCut(new StjTrackCutEta(-2.5,2.5));
251  anapars12_noEEMC->addTpcCut(new StjTrackCutLastPoint(125));
252 
253  // BEMC cuts
254  anapars12_noEEMC->addBemcCut(new StjTowerEnergyCutBemcStatus(1));
255  anapars12_noEEMC->addBemcCut(new StjTowerEnergyCutAdc(4,3)); // ADC-ped>4 AND ADC-ped>3*RMS
256  anapars12_noEEMC->addBemcCut(new StjTowerEnergyCutEt(0.2));
257 
258  // EEMC cuts
259  anapars12_noEEMC->addEemcCut(new StjTowerEnergyCutBemcStatus(1));
260  anapars12_noEEMC->addEemcCut(new StjTowerEnergyCutAdc(4,3)); // ADC-ped>4 AND ADC-ped>3*RMS
261  anapars12_noEEMC->addEemcCut(new StjTowerEnergyCutEt(10000.0)); // nothing is this high JS
262 
263  // Jet cuts
264  anapars12_noEEMC->addJetCut(new StProtoJetCutPt(3.5,200));
265  anapars12_noEEMC->addJetCut(new StProtoJetCutEta(-100,100));
266 
267  // Set anti-kt R=0.6 parameters
268  StFastJetPars* AntiKtR060Pars = new StFastJetPars;
269  AntiKtR060Pars->setJetAlgorithm(StFastJetPars::antikt_algorithm);
270  AntiKtR060Pars->setRparam(0.6);
271  AntiKtR060Pars->setRecombinationScheme(StFastJetPars::E_scheme);
272  AntiKtR060Pars->setStrategy(StFastJetPars::Best);
273  AntiKtR060Pars->setPtMin(3.5);
274 
275  // Set anti-kt R=0.5 parameters
276  StFastJetPars* AntiKtR050Pars = new StFastJetPars;
277  AntiKtR050Pars->setJetAlgorithm(StFastJetPars::antikt_algorithm);
278  AntiKtR050Pars->setRparam(0.5);
279  AntiKtR050Pars->setRecombinationScheme(StFastJetPars::E_scheme);
280  AntiKtR050Pars->setStrategy(StFastJetPars::Best);
281  AntiKtR050Pars->setPtMin(3.5);
282 
283  jetmaker->addBranch("AntiKtR060NHits12",anapars12,AntiKtR060Pars);
284  jetmaker->addBranch("AntiKtR060NHits12_noEEMC",anapars12_noEEMC,AntiKtR060Pars);
285  jetmaker->addBranch("AntiKtR050NHits12",anapars12,AntiKtR050Pars);
286  jetmaker->addBranch("AntiKtR050NHits12_noEEMC",anapars12_noEEMC,AntiKtR050Pars);
287 
288  chain->Init();
289  chain->ls(3);
290 
291  char txt[1000];
292  //---------------------------------------------------
293  int eventCounter=0;
294  int t1=time(0);
295  TStopwatch tt;
296  for (Int_t iev=0;iev<nEntries; iev++) {
297  if(eventCounter>=nEve) break;
298  chain->Clear();
299  if(iev%100 == 0) cout<<"iev="<<iev<<endl;
300  int stat = chain->Make();
301  if(stat != kStOk && stat != kStSkip) break; // EOF or input error
302  eventCounter++;
303  }
304  cout<<"run "<<file<<" nEve="<<eventCounter<<" total "; tt.Print();
305  printf("****************************************** \n");
306 
307  int t2=time(0);
308  if(t2==t1) t2=t1+1;
309  float tMnt=(t2-t1)/60.;
310  float rate=1.*eventCounter/(t2-t1);
311  printf("#sorting done %d of nEve= %d, CPU rate= %.1f Hz, total time %.1f minute(s) \n\n",eventCounter,nEntries,rate,tMnt);
312 
313  cout << "END: jet finder " << endl;
314  return;
315  }
316 
317 
318  //.... W reconstruction code ....
319  St2011WMaker *WmuMk=new St2011WMaker();
320  if(isMC) { // MC specific
321  WmuMk->setMC(isMC); //pass "version" of MC to maker
322  }else {// real data
323  WmuMk->setTrigID(idL2BWtrg,idL2EWtrg);
324  }
325 
326  TString outFtree=wtreeDir; outFtree+=outF; outFtree+=".Wtree.root";
327  WmuMk->setTreeName(outFtree);
328 
329  if (useJetFinder == 2) {
330  cout << "Configure to read jet trees " << endl;
331  WmuMk->chainJetFile(jetFile);
332  WmuMk->setJetTreeBranch("AntiKtR060NHits12","AntiKtR060NHits12_noEEMC"); //select jet tree braches used
333  }
334 
335  WmuMk->setMaxDisplayEve(100); // only first N events will get displayed
336 
337  /* evaluation of result, has full acess to W-algo internal data
338  including overwrite - be careful */
339 
340  WpubMk=new St2011pubWanaMaker("pubJan");
341  WpubMk->attachWalgoMaker(WmuMk);
342 
343  //Collect all output histograms
344  //already defined this above: TObjArray* HList=new TObjArray;
345  WmuMk->setHList(HList);
346  WmuMk->setHListTpc(HListTpc);
347  WpubMk->setHList(HList);
348 
349  if(spinSort){
350  WmuMk->attachSpinDb(spDb);
351  enum {mxSM=5}; // to study eta-cuts, drop Q/PT cut
352  St2011pubSpinMaker *spinMkA[mxSM];
353  for(int kk=0;kk<mxSM;kk++) {
354  char ttx[100]; sprintf(ttx,"%cspin",'A'+kk);
355  printf("add spinMaker %s %d \n",ttx,kk);
356  spinMkA[kk]=new St2011pubSpinMaker(ttx);
357  spinMkA[kk]->attachWalgoMaker(WmuMk);
358  spinMkA[kk]->setHList(HList);
359  if(kk==1) spinMkA[kk]->setEta(-1.,0.);
360  if(kk==2) spinMkA[kk]->setEta(0,1.);
361  if(kk==3) spinMkA[kk]->setQPT(false);// disable Q/PT cut
362  if(kk==4) spinMkA[kk]->setNoEEMC();
363  }
364  }
365 
366  if(geant){
367  pubMcMk=new St2011pubMcMaker("pubMc");
368  pubMcMk->attachWalgoMaker(WmuMk);
369  pubMcMk->setHList(HList);
370  }
371 
372  if (findZ){
373  ZMk=new St2011ZMaker("Z");
374  ZMk->attachWalgoMaker(WmuMk);
375  ZMk->setHList(HList);
376  ZMk->setNearEtFrac(0.88);
377  ZMk->setClusterMinEt(15);
378  ZMk->setPhi12Min(3.1416/2.);
379  ZMk->setMinZMass(73.); // Zmass -20%
380  ZMk->setMaxZMass(114.);// Zmass +20%
381  }
382 
383 
384  chain->Init();
385  chain->ls(3);
386 
387  char txt[1000];
388  //---------------------------------------------------
389  int eventCounter=0;
390  int t1=time(0);
391  TStopwatch tt;
392  for (Int_t iev=0;iev<nEntries; iev++) {
393  if(eventCounter>=nEve) break;
394  chain->Clear();
395  int stat = chain->Make();
396  if(stat != kStOk && stat != kStSkip) break; // EOF or input error
397  eventCounter++;
398  }
399  //chain->Finish();
400 
401  cout<<"run "<<file<<" nEve="<<eventCounter<<" total "; tt.Print();
402  printf("****************************************** \n");
403 
404  int t2=time(0);
405  if(t2==t1) t2=t1+1;
406  float tMnt=(t2-t1)/60.;
407  float rate=1.*eventCounter/(t2-t1);
408  printf("#sorting %s done %d of nEve= %d, CPU rate= %.1f Hz, total time %.1f minute(s) \n\n",file,eventCounter,nEntries,rate,tMnt);
409 
410 
411 
412 
413  TString outFh=histDir; outFh+=outF; outFh+=".wana.hist.root";
414 
415  cout<<"Output histo file "<<outFh<<endl;
416 
417  hf=new TFile(outFh,"recreate");
418  if(hf->IsOpen()) {
419  //HList->ls();
420  HList->Write();
421  //write TPC histos to new directory
422  TDirectory *tpc = hf->mkdir("tpc");
423  tpc->cd();
424  HListTpc->Write();
425  printf("\n Histo saved -->%s<\n",outFh.Data());
426  } else {
427  printf("\n Failed to open Histo-file -->%s<, continue\n",outFh.Data());
428  }
429  //WmuMk->Finish();
430 
431  return;
432 }
433 
434 
435 // $Log: rdMuWana2012.C,v $
436 // Revision 1.14 2013/12/06 14:21:22 stevens4
437 // update jet library loading for SL6 and remove mid-point cone
438 //
439 // Revision 1.13 2013/10/11 14:22:34 stevens4
440 // changed order of library loading to be compatible with ROOT/SL upgradex
441 //
442 // Revision 1.12 2013/09/13 19:37:36 stevens4
443 // Updates to code for combined 2011+2012 result presented to spin PWG 9.12.13
444 //
445 // Revision 1.11 2013/07/03 16:53:15 stevens4
446 // Update for efficiency studies with embedding
447 //
448 // Revision 1.10 2012/09/18 22:33:07 stevens4
449 // remove hardcoded jet tree path
450 //
451 // Revision 1.8 2012/08/07 21:06:56 stevens4
452 // update to tree analysis to produce independent histos in a TDirectory for each eta-bin
453 //
454 // Revision 1.7 2012/07/13 16:11:49 balewski
455 // minor clenup, prevent crash in Finish if zero input events, now it runs on M-C events as well
456 //
457 // Revision 1.6 2012/07/12 20:49:26 balewski
458 // added spin info(star: bx48, bx7, spin4) and maxHtDSM & BTOW to Wtree
459 // removed dependence of spinSortingMaker from muDst
460 // Now Wtree can be spin-sorted w/o DB
461 // rdMu.C & readWtree.C macros modified
462 // tested so far on real data run 11
463 // lot of misc. code shuffling
464 //
465 // Revision 1.5 2012/07/05 20:13:33 balewski
466 // *** empty log message ***
467 //
468 // Revision 1.4 2012/06/25 20:57:05 stevens4
469 // add directory for tpc histos
470 //
471 // Revision 1.3 2012/06/22 18:23:36 balewski
472 // *** empty log message ***
473 //
474 // Revision 1.2 2012/06/18 18:32:50 stevens4
475 // remove hard coded jet path
476 //
477 // Revision 1.1 2011/02/10 20:33:35 balewski
478 // start
479 //
gathers all results from W-analysis, Jan&#39;s analysis
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
static const int Best
automatic selection of the best (based on N)
spin sorting of W&#39;s
Filling of all StMcEvent classes from g2t tables Transform all the data in the g2t tables into the co...
Definition: Stypes.h:49
virtual void ls(Option_t *option="") const
Definition: TDataSet.cxx:495
maker to retrieve info from geant.root files for comparison with reco quantities from MC ...
Bool_t doPrintMemoryInfo
lots of screen output
virtual Int_t Make()
Definition: StChain.cxx:110
TChain * chain()
In read mode, returns pointer to the chain of .MuDst.root files that where selected.
Definition: StMuDstMaker.h:426
void SetStatus(const char *arrType, int status)
static const int E_scheme
Definition: StFastJetPars.h:89
muDst based extraction of W-signal from pp500 data from 2011
Definition: St2011WMaker.h:49
static const int antikt_algorithm
Definition: StFastJetPars.h:65
Definition: Stypes.h:41
uses tree from W-algo to find Zs
Definition: St2011ZMaker.h:26