StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
rdEztFeePed.C
1 TObjArray *HList;
2 class StEEstaleMaker;
3 
4 int rdEztFeePed(
5  int nEve=3000,
6  Int_t nFiles = 20,
7  char* file="R5135068ezB.lis",
8  char* inDir = "../oldPanitkin/muDst/",
9  TString outPath="feePed4/"
10  ){
11  // file="st_physics_6008023_raw_1030001.MuDst.root";// pedestal, 1987eve
12  file="st_physics_6008016_raw_1020001.MuDst.root";// commisCu, ~20Keve
13  // inDir = "./";
14 
15  gROOT->LoadMacro("$STAR/StRoot/StMuDSTMaker/COMMON/macros/loadSharedLibraries.C");
16  loadSharedLibraries();
17  cout << " loading done " << endl;
18  assert( !gSystem->Load("StEEmcPoolmuEztFeePed"));
19  // assert( !gSystem->Load("StEEmcUtil"));
20 
21  // create chain
22  chain = new StChain("StChain");
23 
24  printf("adding muDst from '%s' ....\n",file);
25  // Now we add Makers to the chain...
26  muMk = new StMuDstMaker(0,0,inDir,file,"MuDst.root",nFiles);
27  TChain* tree=muMk->chain(); assert(tree);
28  int nEntries=tree->GetEntries();
29  printf("total eve in chain =%d\n",nEntries);
30  printf("in=%s%s=\n",inDir,file);
31  //return;
32 
33  HList=new TObjArray;
34 
35  myMk3=new StFeePedMaker("eeFeePed","MuDst");
36  myMk3->SetHList(HList);
37 
38  gMessMgr->SwitchOff("D");
39  gMessMgr->SwitchOn("I");
40 
41 
42  muMk->SetStatus("*",0);
43  muMk->SetStatus("EztAll",1);
44  chain->Init();
45  chain->ls(3);
46  // muMk->printArrays();
47 
48  printf("All Ezt-branches set\n");
49  int eventCounter=0;
50  int stat=0;
51  int t1=time(0);
52  StMuTimer timer;
53  timer.start();
54 
55  //---------------------------------------------------
56  while ( 1) {// loop over events
57  if(eventCounter>=nEve) break;
58  eventCounter++;
59  chain->Clear();
60  stat = chain->Make();
61  if(stat) break;
62  if(eventCounter%1000!=0)continue;
63 
64  printf("\n\n ====================%d processing ==============\n", eventCounter);
65 
66  }
67  printf("sorting done, nEve=%d of %d\n",nEve, nEntries);
68  int t2=time(0);
69  if(t1==t2) t2++;
70  float rate=1.*eventCounter/(t2-t1);
71  float nMnts=(t2-t1)/60.;
72  printf("sorting done %d of nEve=%d, elapsed rate=%.1f Hz, tot %.1f minutes\n",eventCounter,nEntries,rate,nMnts);
73 
74  if (eventCounter) {
75  cout << "CPU time/event= " << timer.elapsedTime()/eventCounter << " sec "
76  << " rate= " << eventCounter/timer.elapsedTime() << " Hz" << endl;
77  }
78 
79  //-------------------- calculate FEE peds & produce output files ------
80 
81  printf("name Nentries chi2 gaus_ampl gaus_mean gaus_sig err_ampl err_mean err_sig \n");
82 
83  TIterator* iter = HList->MakeIterator();
84 
85  TH1F* h;
86  char oName[100];
87  FILE *fo;
88  oName[0]=0;
89  int nPed=0;
90  TString fName=outPath+"eemcPed4.dat";
91  FILE *fo2=fopen(fName.Data(),"w");
92 
93  while((h=(TH1F*)iter->Next())) {
94  char *txt=h->GetName();
95  int cr=atoi(txt+2);
96  int chan=atoi(txt+6);
97  int ped4=0;
98  if(chan%32==0) {
99  if(oName[0]) fclose(fo);
100  sprintf(oName,"%scrate%dboard%d.ped4",outPath.Data(),cr, 1+chan/32);
101  FILE *fo=fopen(oName,"w");
102  if(fo==0) {
103  printf("\n\nDid you created dir=%s ??? ,JB\n\n",outPath.Data());
104  printf("ABORT macro\n");
105  assert(fo);
106  }
107  printf(" write to '%s'\n",oName);
108  }
109 
110  int ret=-1;
111  // Fit range max -low, max+high, default: max-5, max+4
112  if(cr==4 && chan==127) ret=myMk3->fitPed(h,20); // just example
113  else ret=myMk3->fitPed(h);
114 
115  if (ret) {
116  printf("%s empty\n",h->GetName());
117  fprintf(fo2," %d %3d 5000 %d\n",cr,chan,ped4);
118  fprintf(fo," %d\n",ped4);
119  continue;
120  }
121  TF1* fit= h->GetFunction("pedFun");
122  assert(fit);
123  nPed++;
124 
125  // fit->Print(); return;
126 
127  float ped=fit->GetParameter(1);
128  int ped4=(25-ped)/4;
129  if(ped>24) ped4=(22-ped)/4;
130  fprintf(fo2,"%d %d %.1f %d\n",cr,chan,ped,ped4);
131  fprintf(fo,"%d\n",ped4);
132 
133  printf("%s %8.0f %8.3f %9.3f %8.2f %7.2f %6.2f %7.2f %6.2f\n",
134  h->GetName(),
135  h->GetEntries(),
136  fit->GetChisquare(),
137  fit->GetParameter(0),
138  fit->GetParameter(1), // pedestal centroid
139  fit->GetParameter(2), // sigma of gaussian
140  fit->GetParError(0),
141  fit->GetParError(1),
142  fit->GetParError(2));
143  // break;
144  }
145 
146  myMk3->saveHisto(outPath+"feePed");
147  fclose(fo2);
148  fclose(fo);
149  printf("Fit found %d pedestals\n",nPed);
150 
151  // h=(TH1F*)HList->FindObject("cr5_ch095"); // this is 'stuck bit' channel
152  h=(TH1F*)HList->FindObject("cr5_ch094"); // a regular channel
153  h->Draw(); gPad->SetLogy();
154 
155 }
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)