StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StMuEEmcCrateTimingMaker.cxx
1 #include "StMuEEmcCrateTimingMaker.h"
2 
3 #include "StChain.h"
4 #include "TF1.h"
5 
6 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
7 #include "StMuDSTMaker/COMMON/StMuDst.h"
8 #include "StMuDSTMaker/COMMON/StMuEmcCollection.h"
9 
10 #include "StMuDSTMaker/EZTREE/EztEventHeader.h"
11 #include "StMuDSTMaker/EZTREE/EztEmcRawData.h"
12 
14 
16  mMuDstMaker = mudstmaker;
17  assert(mMuDstMaker);
18  mNsigma = -1.0;
19  mNchannels = 25;
20  mPhase = 0;
21  mCycle = 16;
22  mMinCounts = 0;
23 }
24 
25 // ----------------------------------------------------------------------------
27 
29  TString outputFile;
30  outputFile = mDirectory + "/eemc" + mFlavor + "Crates-timeDelay";
31  char samus[100];
32  sprintf(samus,"%0.2f.root",mTimeDelay);
33  outputFile += samus;
34  mOutputFile = new TFile(outputFile.Data(),"RECREATE");
35  mOutputTree = new TTree("ints","Integrals of Each Channel");
36  kludge = MxMapmtFeeCh;
37 
40  mOutputTree->Branch("kludge",&kludge,"kludge/I");
41  mOutputTree->Branch("chanint",totalIntegral,"chanint[kludge]/F");
42  mOutputTree->Branch("chanerr",totalError,"chanerr[kludge]/F");
43  mOutputTree->Branch("delay",&mTimeDelay,"delay/F");
44  mOutputTree->Branch("channelIds",channelIds,"channelIds[kludge]/I");
45  mOutputTree->Branch("crateIds",crateIds,"crateIds[kludge]/I");
46  mOutputTree->Branch("mPhase",&mPhase,"mPhase/I");// for selecting which channels
47  mOutputTree->Branch("mCycle",&mCycle,"mCycle/I");
48  mOutputFile->cd();
49  TString tmpstr = "histograms for " + mFlavor + " crate channels";
50 
52  cratehist = new TH2F("cratehistogram",tmpstr.Data(),MxMapmtFeeCh,-0.5,MxMapmtFeeCh + 0.5,500,0,500);
53  cratehist->GetXaxis()->SetTitle("crate channel id");
54  cratehist->GetYaxis()->SetTitle("adc");
55 
57  for(int i=0; i<MxMapmtFeeCh; i++) {
58  totalIntegral[i] = 0;
59  totalError[i]=0;
60  channelIds[i]=0;
61  }
62 
63  return 0;
64 }
65 
66 // ----------------------------------------------------------------------------
68 
69  //.......... acuire EztHeader
70  EztEventHeader* header= mMuDstMaker->muDst()->eztHeader();
71  if(header==0)
72  return kStOK;
73 
75  int token= header->getToken();
76  EztEmcRawData* eE;
77  int lenCount;
78  if(mFlavor == "tower") {
79  eE=mMuDstMaker->muDst()->eztETow();
80  lenCount = 4+160;
81  } else if(mFlavor == "mapmt") {
82  eE=mMuDstMaker->muDst()->eztESmd();
83  lenCount = 4+192;
84  }
85  else {
86  std::cout << "Unknown flavor you fool! " << mFlavor << std::endl;
87  return kStWarn;
88  }
89 
90  assert(eE);
91  //$$$ eE->print(0);
92 
93  // test for corruption, accept only healthy ETOW events
94  int errFlag=0;
95  int trigComm=0x4; // physics, 9=laser/LED, 8=??
96 
97  int nOK=0;
98  for(int icr=0;icr<eE->getNBlocks();icr++) {
99  if(eE->isCrateVoid(icr)) continue;
100  if(eE->purgeCrateOFF(icr)) continue;
101  int crID=icr+1;
102  if (mFlavor=="mapmt") crID=64+icr;
103  eE->tagHeadValid(icr,token, crID,lenCount,trigComm,errFlag);
104  UShort_t isSick=eE->getCorruption(icr);
105  if(isSick) continue;
106  nOK++;
107  }
108 
109  if((mFlavor == "mapmt" && nOK!=MaxMapmtCrates) ||
110  (mFlavor == "tower" && nOK!=MaxTwCrates)) {
111  cout << "SICK EVENTS IN THIS RUN" << endl;
112  return kStOK; // drop sick events
113  }
114 
115  //eE->print(0);
116  totalIntegral[MxMapmtFeeCh-1]++;
117 
118 
119 
120 // this takes each crate, and loops over every sixteenth channel,
121 // starting from "mPhase"
122 // this allows some flexibility, in case there is a problem with
123 // starting on the first channel in each crate, or if there is
124 // a definitely unplugged channel in each crate
125 // it then saves the crate hit to histogram
126 
127 
139 
140 
141 
143  for(int icr=0; icr < eE->getNBlocks(); icr++ ) {
144 
145  if(eE->isCrateVoid(icr)) continue;
146  const UShort_t* data=eE->data(icr);
147  int j = icr*MaxMapmtCrateCh/16;
148 
152  for(int i=mPhase;i<eE->sizeData(icr);i+=mCycle,j++) {
153 
154  if(i>=MaxMapmtCrateCh) continue; // ignore nonexistient channels
155  float adc=data[i];
156  int k=(icr*MaxMapmtCrateCh+i)/16;
157  assert(k>=0 && k<MxMapmtFeeCh);
158  cratehist->Fill(j,adc);
162  channelIds[j]=i;
163  crateIds[j]=icr;
164 
165  }
166 
167  }
168  return kStOK;
169 }
170 
171 
172 // ----------------------------------------------------------------------------
174 
175 
179 
180 
182  TString outputFile = mDirectory + "/eemc" + mFlavor + "Crates-timeDelay";
183  char samus[100];
184  sprintf(samus,"%0.2f.txt",mTimeDelay);
185  outputFile += samus;
186  ofstream ofs(outputFile.Data());
187  ofs << "-1" << "\t" << setprecision(5) << totalIntegral[MxMapmtFeeCh-1] << endl; //normalization
188 
189  for (Int_t i = 2; i <= cratehist->GetXaxis()->GetNbins(); i++) {
190  Int_t chanId = static_cast<Int_t>(cratehist->GetXaxis()->GetBinCenter(i));
191 
192  TH1D* proj = cratehist->ProjectionY("projTemp",i,i);
193  if (proj) {
194 
197  if ( proj -> GetEntries() < mMinCounts )
198  continue;
199 
200  Int_t maxBin = 0;
201  Float_t maxValue = -1;
202  for (Int_t j = 1; j < proj->GetXaxis()->GetNbins(); j++) {
203  if (proj->GetBinContent(j) > maxValue) {
204  maxBin = j;
205  maxValue = proj->GetBinContent(j);
206  }
207  }
208  Float_t pedMean = proj->GetXaxis()->GetBinCenter(maxBin);
209 
210  if ( !(( i - mPhase )%mCycle) ) {
211 
212  TString myname="channel"; myname+=chanId;
213  TH1D *cl=(TH1D*)proj->Clone(myname);
214  cl->Write();
215 
216  }
217 
218 
219  // fit a gaussian to the pedestal peak
220  TF1* gaus = new TF1("gaus","gaus");
221  gaus->SetParameter(0,maxValue);
222  gaus->SetParameter(1,pedMean);
223  gaus->SetParameter(2,3.5);
224  gaus->SetRange(pedMean-10,pedMean+10);
225  proj->Fit(gaus,"0RQ");
226  Float_t pedestalmean = gaus->GetParameter(1);
227  Float_t pedestalwidth = gaus->GetParameter(2);
228 
230  Float_t xmin = pedestalmean;
231  if ( mNsigma > 0. )
232  xmin += mNsigma * pedestalwidth;
233  else
234  xmin += mNchannels;
235  Int_t minBin = proj->GetXaxis()->FindFixBin( xmin );
236 
237  maxBin = proj->GetXaxis()->GetNbins() - 1;
238  Stat_t nHitsAbovePedestal = proj->Integral(minBin,maxBin);
239 
241  Float_t delR = 0.;
242  if ( nHitsAbovePedestal > 0. && totalIntegral[MxMapmtFeeCh-1] > 0. ) {
243  delR = 1.0 / nHitsAbovePedestal + 1.0 / totalIntegral[MxMapmtFeeCh-1];
244  }
245 
246  totalIntegral[chanId] = nHitsAbovePedestal/totalIntegral[MxMapmtFeeCh-1];
247  totalError[chanId] = delR * totalIntegral[chanId];
248 
249  ofs << chanId << "\t" << setprecision(5) << nHitsAbovePedestal/totalIntegral[MxMapmtFeeCh-1] << endl;
250  }
251 
252  }
253  ofs.close();
254 
255  if (mOutputFile) {
256  mOutputTree->Fill();
257  mOutputFile->Write();
258  delete mOutputFile;
259  }
260  return kStOk;
261 }
StMuDst * muDst()
Definition: StMuDstMaker.h:425
static EztEmcRawData * eztESmd()
returns pointer to eztESmd +pre/post
Definition: StMuDst.h:459
static EztEventHeader * eztHeader()
returns pointer to eztHeader
Definition: StMuDst.h:442
static EztEmcRawData * eztETow()
returns pointer to ETOW
Definition: StMuDst.h:456
Definition: Stypes.h:42
Definition: Stypes.h:40
Definition: Stypes.h:41