StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFeePedMaker.cxx
1 // *-- Author : Jan Balewski
2 //
3 // $Id: StFeePedMaker.cxx,v 1.1 2005/01/11 22:14:31 balewski Exp $
4 
5 #include <TFile.h>
6 #include <TH1.h>
7 #include <TF1.h>
8 #include <StMessMgr.h>
9 
10 #include "StFeePedMaker.h"
11 
12 #include "StMuDSTMaker/COMMON/StMuEvent.h"
13 #include "StMuDSTMaker/COMMON/StMuDst.h"
14 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
15 
16 #include "StMuDSTMaker/EZTREE/EztEventHeader.h"
17 #include "StMuDSTMaker/EZTREE/EztEmcRawData.h"
18 
19 ClassImp(StFeePedMaker)
20 
21 //________________________________________________
22 //________________________________________________
23 StFeePedMaker::StFeePedMaker( const char* self ,const char* muDstMakerName) : StMaker(self){
24  mMuDstMaker = (StMuDstMaker*)GetMaker(muDstMakerName);
25  assert(mMuDstMaker);
26 
27  nInpEve=0;
28  HList=0;
29 
30 }
31 
32 
33 //___________________ _____________________________
34 //________________________________________________
35 StFeePedMaker::~StFeePedMaker(){
36 
37 }
38 
39 //___________________ _____________________________
40 //________________________________________________
41 void
42 StFeePedMaker::saveHisto(TString fname){
43  TString outName=fname+".hist.root";
44  TFile f( outName,"recreate");
45  assert(f.IsOpen());
46  printf("%d histos are written to '%s' ...\n",HList->GetEntries(),outName.Data());
47  HList->Write();
48  f.Close();
49 
50 }
51 
52 //________________________________________________
53 //________________________________________________
54 Int_t
55 StFeePedMaker::Init(){
56 
57  assert(HList);
58  // init histo
59  int i,j;
60 
61  for(i=0;i<MaxTwCrates;i++) {
62  int crate=i+MinTwCrateID;
63  for (j=0;j<MaxTwCrateCh;j++){
64  char tt1[100], tt2[100];
65  sprintf(tt1,"cr%d_ch%3.3d",crate,j);
66  sprintf(tt2,"Pedestals for Crate %d and FEE ch %d",crate,j);
67  TH1F* h=new TH1F(tt1,tt2,400,-0.5,395.5);
68  HList->Add(h);
69  int k=MaxTwCrateCh*i+j;
70  // printf("%d %3d %s k=%d\n",i,j,h->GetName(),k);
71  hped[k]=h;
72  }
73  }
74  printf("Initialized %d tower histos\n",MxTwFeeCh);
75 
76  return StMaker::Init();
77 }
78 
79 //________________________________________________
80 //________________________________________________
81 Int_t
83  return kStOK;
84 }
85 
86 
87 //________________________________________________
88 //________________________________________________
89 Int_t
91  nInpEve++;
92 
93  gMessMgr->Message("","D") <<GetName()<<"::Make() is called "<<endm;
94 
95  //.......... acuire EztHeader
96  EztEventHeader* header= mMuDstMaker->muDst()->eztHeader();
97  if(header==0) {
98  gMessMgr->Message("","E") <<GetName()<<"::Make() no EztEventHeader, skip event "<<endm;
99  return kStOK;
100  }
101 
102  int token= header->getToken();
103  EztEmcRawData* eETow=mMuDstMaker->muDst()->eztETow();
104  assert(eETow);
105 
106  // test for corruption, accept only healthy ETOW events
107  int lenCount=0xa4;
108  int errFlag=0;
109  int trigComm=0x4; // physics, 9=laser/LED, 8=??
110 
111  int nOK=0;
112  int icr;
113  for(icr=0;icr<eETow->getNBlocks();icr++) {
114  if(eETow->isCrateVoid(icr)) continue;
115  if(eETow->purgeCrateOFF(icr)) continue;
116  int crID=icr+1;
117  eETow->tagHeadValid(icr,token, crID,lenCount,trigComm,errFlag);
118  UShort_t isSick=eETow->getCorruption(icr);
119  if(isSick) continue;
120  nOK++;
121  }
122 
123  // printf(" # of healthy crates=%d\n",nOK);
124  if(nOK!=MaxTwCrates) return kStOK; // drop sick events
125  // eETow->print(1);
126 
127  //.............. Accumulate histograms ......
128 
129  for(icr=0;icr<eETow->getNBlocks();icr++) {
130  if(eETow->isCrateVoid(icr)) continue;
131  int i;
132  const UShort_t* data=eETow->data(icr);
133  for(i=0;i<eETow->sizeData(icr);i++) {
134  int chan=i;
135  if(chan>=MaxTwCrateCh) continue; // ignore not existing channels
136  float adc=data[i];
137  //if(adc<=0) continue;
138  int k=icr*MaxTwCrateCh+chan;
139  // printf("crID=%d ch=%d rawAdc=%.1f k=%d\n",icr+1,i,adc,k);
140  assert(k>=0 && k<MxTwFeeCh);
141  hped[k]->Fill(adc);
142  } // channels
143  } // blocks
144 
145  return kStOK;
146 }
147 
148 
149 //________________________________________________
150 //________________________________________________
151 Int_t
152 StFeePedMaker::fitPed(TH1F *h, int Xlow, int Xhigh) {
153  int sumMin=100;
154  if (h->GetEntries() < sumMin) return -1;
155 
156  // localize pedestal peak in first 100 channels
157  float *y=h->GetArray();
158 
159  float ym=0,sum=0;
160  int i;
161  int j=-1;
162  for(i=2;i<=100;i++){ // skip first channel
163  sum+=y[i];
164  if(ym>y[i]) continue;
165  ym=y[i];
166  j=i;
167  }
168 
169  if (sum < sumMin) return -2;
170 
171  float xm=h->GetBinCenter(j);
172  float x1=xm-Xlow;
173  float x2=xm+Xhigh;
174 
175  // printf("fit ped to %s for x=[%.1f , .%.1f] \n",h->GetName(),x1,x2);
176 
177  TF1* fitF = new TF1("pedFun","gaus");
178  fitF->SetLineColor(kGreen);;
179  fitF->SetLineWidth(1);;
180  h->Fit(fitF,"RQ+W","",x1,x2);
181  //fitF->Print();
182  return 0;
183 }
184 
185 
186 //---------------------------------------------------
187 // $Log: StFeePedMaker.cxx,v $
188 // Revision 1.1 2005/01/11 22:14:31 balewski
189 // start
190 //
StMuDst * muDst()
Definition: StMuDstMaker.h:425
virtual Int_t Finish()
virtual Int_t Make()
static EztEventHeader * eztHeader()
returns pointer to eztHeader
Definition: StMuDst.h:442
static EztEmcRawData * eztETow()
returns pointer to ETOW
Definition: StMuDst.h:456
virtual const char * GetName() const
special overload
Definition: StMaker.cxx:237
Definition: Stypes.h:40