StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
rdMu2BprsAbsCal.C
1 
2 /* This macro is set up to calibrate barrelĀ 
3  This macro runs on real data (flagMC=0) and MC files (flagMC=1)
4 */
5 
6 int total=0;
7 
8 void rdMu2BarCal(
9  char *file="R9060016f.lis",//"Day68a.lis", //"Ry.lis",//"R9067013f.lis", //"R9064019f.lis", //
10  int calibPass=0x3, //bits: 0x0=raw,0x1=pedSubtr, 0x2=capIDfix
11  int nEvents = 1000,
12  int dbType=1, // 0=STAR only, 1=overwriteBPRSw128cap
13  int isSched=0,
14  TString fileHi="aa", // is provided in scheduler mode
15  TString outDir="out1d/",
16  int bprsHist=1, // 1=commCap histo, 2=128capHisto
17  int dumm=0
18  )
19 {
20  char *dirIn ="runList/";
21  int nFiles = 1000; // make this big if you want to read all events from a run
22 
23  if(isSched) { // setup changes for mass data processing with scheduler
24  dirIn ="";
25  outDir="";
26  nFiles=1000;
27  // nEvents =1e6;
28  }
29 
30  int flagMC=0; // 0== data, 1==M-C
31  if (flagMC) file="mit0029.lis";
32 
33 
34 
35  gROOT->LoadMacro("$STAR/StRoot/StMuDSTMaker/COMMON/macros/loadSharedLibraries.C");
36  loadSharedLibraries();
37  assert( !gSystem->Load("StDetectorDbMaker"));
38  assert( !gSystem->Load("StDbUtilities"));
39  assert( !gSystem->Load("StDbBroker"));
40  assert( !gSystem->Load("St_db_Maker"));
41  assert( !gSystem->Load("StDaqLib")); // needed by bemcDb
42  assert( !gSystem->Load("StEmcRawMaker"));
43  assert( !gSystem->Load("StEmcADCtoEMaker"));
44  if (flagMC) {
45  assert( !gSystem->Load("StMcEvent"));
46  assert( !gSystem->Load("StMcEventMaker"));
47  assert( !gSystem->Load("StEmcSimulatorMaker"));
48  assert( !gSystem->Load("StEpcMaker"));
49  }
50  assert( !gSystem->Load("StBarrelCalib"));
51 
52  gROOT->Macro("LoadLogger.C");
53  cout << " loading done " << endl;
54 
55  StChain *chain= new StChain("StChain");
56 
57  //....Needs MuDstMaker to get data
58  printf(" dirIn=%s= file=%s=\n",dirIn,file);
59  StMuDstMaker* muDstMaker =new StMuDstMaker(0,0,dirIn,file,"MuDst.root",nFiles);
60 
61  TChain* tree=muDstMaker->chain(); assert(tree);
62  int nEntries=(int) tree->GetEntries();
63  cout << "Avaliable number of events " << nEntries << endl;
64 
65  if(nEvents>nEntries){
66  nEvents=nEntries;
67  cout<<" WARN: # of requested events reduced to "<< nEvents<<endl;
68  }
69 
70  //Database -- get a real calibration from the database
71  St_db_Maker* dbMk = new St_db_Maker("StarDb","MySQL:StarDb","MySQL:StarDb","$STAR/StarDb");
72 
73  //If MC then must set database time and date
74  // if Endcap fast simu is used tower gains in DB do not matter,JB
75  if(flagMC) {
76  dbMk->SetDateTime(20080307, 83000);//timestamp R9067013
77  }
78 
79  //Get BEMC adc values
80  StEmcADCtoEMaker *a2eMk = new StEmcADCtoEMaker();
81  a2eMk->setCheckStatus(kBarrelEmcTowerId,0); // force to ignore status tables in the offline DB
82  a2eMk->saveAllStEvent(true); // preserve 1:1 copy of muDst content
83 
84  // if (flagMC) simL2Mk->setMC();
85 
86  //Collect all output histograms
87  TObjArray* HList=new TObjArray;
88 
90  jdbMk->setDbType(dbType);
91  jdbMk->setHList(HList);
92 
94  bmMk->setHList(HList);
95  bmMk->setCalibPass(calibPass);
96  bmMk->setBprsHisto(bprsHist);
97 
98  chain->ls(3);
99  chain->Init();
100 
101  int t1=time(0);
102 
103  for (Int_t iev=0;iev<nEvents; iev++) {
104  cout << "\n****************************************** " << endl;
105  cout << "Working on eventNumber:\t" << iev <<"\tof:\t"<<nEvents<<endl;
106  cout << "****************************************** " << endl;
107  chain->Clear();
108  int iret = chain->Make(iev);
109  total++;
110  if (iret % 10 == kStEOF || iret % 10 == kStFatal) {
111  cout << " my.C macro: Bad return code!" << endl;
112  break;
113  }
114  }
115  int t2=time(0);
116  if(t2==t1) t2=t1+1;
117  float tMnt=(t2-t1)/60.;
118  float rate=1.*total/(t2-t1);
119 
120  chain->Finish();
121  cout << "****************************************** " << endl;
122  cout << "total number of events " << total << endl;
123  cout << "****************************************** " << endl;
124 
125 
126  if(!isSched) {
127  fileHi=file;
128  //"=%s=\n",fileMu.Data());
129  if(fileHi.Contains(".lis")) fileHi.ReplaceAll(".lis",".barCal");
130  if(fileHi.Contains(".MuDst.root")) fileHi.ReplaceAll(".MuDst.root",".barCal");
131  }
132  TString outF=outDir+fileHi;
133  outF+="";
134  outF+=".hist.root";
135  cout<<"Output histo file "<<outF<<endl;
136  hf=new TFile(outF,"recreate");
137  if(hf->IsOpen()) {
138  HList->ls();
139  HList->Write();
140  printf("\n Histo saved -->%s<\n",outF.Data());
141  } else {
142  printf("\n Failed to open Histo-file -->%s<, continue\n",outF.Data());
143  }
144 
145  cout <<Form("sorting done %d of nEve=%d, CPU rate=%.1f Hz, total time %.1f minute(s) \n\n",total,nEntries,rate,tMnt)<<endl;
146 
147 }
148 
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StChain.cxx:77
virtual Int_t Finish()
Definition: StChain.cxx:85
virtual void ls(Option_t *option="") const
Definition: TDataSet.cxx:495
Definition: Stypes.h:43
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 saveAllStEvent(Bool_t a)
Set to kTRUE if all hits are to be saved on StEvent.
void setCheckStatus(StDetectorId det, int flag, const char *option="")