BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
PreXtMdcCalib.cxx
Go to the documentation of this file.
2
3#include "GaudiKernel/MsgStream.h"
4#include "GaudiKernel/IMessageSvc.h"
5#include "GaudiKernel/StatusCode.h"
6#include "GaudiKernel/ISvcLocator.h"
7#include "GaudiKernel/Bootstrap.h"
8
9#include "GaudiKernel/SmartDataPtr.h"
10#include "GaudiKernel/IDataProviderSvc.h"
11#include "GaudiKernel/PropertyMgr.h"
12
14#include "EventModel/Event.h"
15#include "MdcRawEvent/MdcDigi.h"
17#include "Identifier/MdcID.h"
18#include "TStyle.h"
19
20#include <iostream>
21#include <fstream>
22#include <iomanip>
23#include <string>
24#include <cstring>
25#include <cmath>
26
27#include "TF1.h"
28
29using namespace Event;
30
32 m_fgIniTm = false;
33}
34
37
39 for(int lay=0; lay<MdcCalNLayer; lay++){
40 delete m_grXt[lay];
41 delete m_htrec[lay];
42 }
43 delete m_haxis;
44 delete m_fdPreXt;
45}
46
47void PreXtMdcCalib::initialize(TObjArray* hlist, IMdcGeomSvc* mdcGeomSvc,
48 IMdcCalibFunSvc* mdcFunSvc, IMdcUtilitySvc* mdcUtilitySvc) {
49 IMessageSvc* msgSvc;
50 Gaudi::svcLocator() -> service("MessageSvc", msgSvc);
51 MsgStream log(msgSvc, "PreXtMdcCalib");
52 log << MSG::INFO << "PreXtMdcCalib::initialize()" << endreq;
53
54 m_hlist = hlist;
55 m_mdcGeomSvc = mdcGeomSvc;
56 m_mdcFunSvc = mdcFunSvc;
57 m_mdcUtilitySvc = mdcUtilitySvc;
58
59 int lay;
60
61 m_nWire = m_mdcGeomSvc -> getWireSize();
62 m_nLayer = m_mdcGeomSvc -> getLayerSize();
63
64 m_fdPreXt = new TFolder("PreXt", "PreXt");
65 m_hlist->Add(m_fdPreXt);
66
67 m_fdNhit = new TFolder("XtNhit", "XtNhit");
68 m_hlist->Add(m_fdNhit);
69
70 m_haxis = new TH2F("axis", "", 50, 0, 300, 50, 0, 9);
71 m_haxis -> SetStats(0);
72 m_fdPreXt -> Add(m_haxis);
73
74 char hname[200];
75 for(lay=0; lay<MdcCalNLayer; lay++){
76 sprintf(hname, "trec%02d", lay);
77 m_htrec[lay] = new TH1F(hname, "", 310, -20, 600);
78 m_fdPreXt -> Add(m_htrec[lay]);
79 }
80
81 m_nhitTot = new TH1F("nhitTot", "", 43, -0.5, 42.5);
82 m_fdNhit -> Add(m_nhitTot);
83
84 for(lay=0; lay<MdcCalNLayer; lay++){
85 sprintf(hname, "nhitBin%02d", lay);
86 m_nhitBin[lay] = new TH1F(hname, "", 40, 5.0, 405.0);
87 m_fdNhit -> Add(m_nhitBin[lay]);
88 }
89
90 /* integrated time Spectrum for determination X-T */
91 int bin;
92 m_nXtBin = 40;
93 double twid = 10.0; // ns
94 for(bin=0; bin<m_nXtBin; bin++) m_tbin[bin] = (double)(bin+1) * twid;
95
96 for(lay=0; lay<MdcCalNLayer; lay++){
97 m_nTot[lay] = 0;
98 for(bin=0; bin<m_nXtBin; bin++){
99 m_nEntries[lay][bin] = 0;
100 }
101 }
102}
103
105 IMessageSvc* msgSvc;
106 Gaudi::svcLocator() -> service("MessageSvc", msgSvc);
107 MsgStream log(msgSvc, "PreXtMdcCalib");
108 log << MSG::DEBUG << "PreXtMdcCalib::fillHist()" << endreq;
109
110 int bin;
111 int lay;
112 int digiId;
113 unsigned fgOverFlow;
114 double tdc;
115 double adc;
116 double traw;
117 double trec;
118 Identifier id;
119
120 IDataProviderSvc* eventSvc = NULL;
121 Gaudi::svcLocator()->service("EventDataSvc", eventSvc);
122
123 double xtpar[8];
124 if(! m_fgIniTm){
125 for(lay=0; lay<MdcCalNLayer; lay++){
126 m_t0[lay] = m_mdcFunSvc -> getT0(lay, 0);
127 m_mdcFunSvc->getXtpar(lay, 0, 0, xtpar);
128 m_tm[lay] = xtpar[6];
129 }
130 m_fgIniTm = true;
131 }
132
133 // get EsTimeCol
134 double tes = -9999.0;
135 int esTimeflag = -1;
136 SmartDataPtr<RecEsTimeCol> aevtimeCol(eventSvc,"/Event/Recon/RecEsTimeCol");
137 if( (!aevtimeCol) || (aevtimeCol->size()==0) ){
138 tes = -9999.0;
139 esTimeflag = -1;
140 }else{
141 RecEsTimeCol::iterator iter_evt = aevtimeCol->begin();
142 for(; iter_evt!=aevtimeCol->end(); iter_evt++){
143 tes = (*iter_evt)->getTest();
144 esTimeflag = (*iter_evt)->getStat();
145 }
146 }
147 bool flagTes = false;
148 for(int iEs=0; iEs<m_param.nEsFlag; iEs++){
149 if(esTimeflag == m_param.esFlag[iEs]){
150 flagTes = true;
151 break;
152 }
153 }
154 if(-1 == esTimeflag) return -1;
155 // if( (!flagTes) || (tes < m_param.tesMin) || (tes > m_param.tesMax) ) return -1;
156 if( (m_param.esCut) && ((!flagTes) || (tes < m_param.tesMin) || (tes > m_param.tesMax)) ) return -1;
157
158 // retrieve Mdc digi
159 SmartDataPtr<MdcDigiCol> mdcDigiCol(eventSvc,"/Event/Digi/MdcDigiCol");
160 if (!mdcDigiCol) {
161 log << MSG::FATAL << "Could not find event" << endreq;
162 }
163
164 MdcDigiCol::iterator iter = mdcDigiCol->begin();
165 digiId = 0;
166 for(; iter != mdcDigiCol->end(); iter++, digiId++) {
167 MdcDigi *aDigi = (*iter);
168 id = (aDigi)->identify();
169
170 lay = MdcID::layer(id);
171
172 tdc = (aDigi) -> getTimeChannel();
173 adc = (aDigi) -> getChargeChannel();
174 fgOverFlow = (aDigi) -> getOverflow();
175 traw = tdc * MdcCalTdcCnv;
176 trec = traw - tes - m_t0[lay];
177
178// if ( !((fgOverFlow == 0)||(fgOverFlow ==12)) ||
179// (aDigi->getTimeChannel() == 0x7FFFFFFF) ||
180// (aDigi->getChargeChannel() == 0x7FFFFFFF) ) continue;
181 if ( ((fgOverFlow & 1) !=0 ) || ((fgOverFlow & 12) != 0) ||
182 (aDigi->getTimeChannel() == 0x7FFFFFFF) ||
183 (aDigi->getChargeChannel() == 0x7FFFFFFF) ) continue;
184
185
186 /* integrated time Spectrum for determination X-T */
187 if(trec > 0){
188 if(trec < m_tm[lay]){
189 m_nTot[lay]++;
190 m_htrec[lay]->Fill(trec);
191 m_nhitTot->Fill(lay);
192 }
193 for(bin=0; bin<m_nXtBin; bin++){
194 if(trec < m_tbin[bin]){
195 m_nEntries[lay][bin]++;
196 m_nhitBin[lay]->Fill(m_tbin[bin]);
197 }
198 }
199 }
200 }
201 return 1;
202}
203
205}
206
208 IMessageSvc* msgSvc;
209 Gaudi::svcLocator() -> service("MessageSvc", msgSvc);
210 MsgStream log(msgSvc, "PreXtMdcCalib");
211 log << MSG::DEBUG << "PreXtMdcCalib::updateConst()" << endreq;
212
213 int lay;
214 int bin;
215 int iLR;
216 int iEntr;
217 int ord;
218
219 double layRad;
220 double ncel;
221 double pi = 3.141592653;
222
223 double dm;
224 double dist[40];
225 double xtpar[6];
226 char hname[200];
227
228 TF1* funXt = new TF1("funXt", xtfun, 0, 300, 6);
229 funXt -> FixParameter(0, 0.0);
230 funXt -> SetParameter(1, 0.03);
231 funXt -> SetParameter(2, 0.0);
232 funXt -> SetParameter(3, 0.0);
233 funXt -> SetParameter(4, 0.0);
234 funXt -> SetParameter(5, 0.0);
235
236 ofstream fxtlog("preXtpar.dat");
237 for(lay=0; lay<MdcCalNLayer; lay++){
238 sprintf(hname, "grPreXt%02d", lay);
239 m_grXt[lay] = new TGraph();
240 m_grXt[lay] -> SetName(hname);
241 m_grXt[lay] -> SetMarkerStyle(20);
242 m_fdPreXt -> Add(m_grXt[lay]);
243
244 layRad = m_mdcGeomSvc -> Layer(lay) -> Radius();
245 ncel = m_mdcGeomSvc -> Layer(lay) -> NCell();
246 dm = pi * layRad / ncel;
247
248 fxtlog << "layer " << lay << endl;
249 for(bin=0; bin<m_nXtBin; bin++){
250 dist[bin] = dm * m_nEntries[lay][bin] / m_nTot[lay];
251 m_grXt[lay] -> SetPoint(bin, m_tbin[bin], dist[bin]);
252 fxtlog << setw(4) << bin << setw(15) << m_tbin[bin]
253 << setw(15) << dist[bin] << setw(15) << dm
254 << setw(10) << m_nEntries[lay][bin]
255 << setw(10) << m_nTot[lay] << endl;
256
257 if(m_tbin[bin] >= m_tm[lay]) break;
258 }
259
260 if(1 == m_param.fgCalib[lay]){
261 m_grXt[lay] -> Fit(funXt, "Q", "", 0.0, m_tm[lay]);
262 for(ord=0; ord<6; ord++){
263 xtpar[ord] = funXt -> GetParameter(ord);
264 }
265
266 for(iEntr=0; iEntr<MdcCalNENTRXT; iEntr++){
267 for(iLR=0; iLR<MdcCalLR; iLR++){
268 for(ord=0; ord<6; ord++){
269 calconst -> resetXtpar(lay, iEntr, iLR, ord, xtpar[ord]);
270 }
271 }
272 }
273 } else{
274 for(ord=0; ord<6; ord++) xtpar[ord] = calconst->getXtpar(lay, 0, 0, ord);
275 }
276
277 for(ord=0; ord<6; ord++) fxtlog << setw(14) << xtpar[ord];
278 fxtlog << setw(10) << m_tm[lay] << " 0" << endl;
279 } // end of layer loop
280 fxtlog.close();
281 cout << "preXt.dat was written." << endl;
282
283 delete funXt;
284 return 1;
285}
286
287Double_t PreXtMdcCalib::xtfun(Double_t *x, Double_t *par){
288 Double_t val = 0.0;
289 for(Int_t ord=0; ord<6; ord++){
290 val += par[ord] * pow(x[0], ord);
291 }
292 return val;
293}
294
sprintf(cut,"kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)
gr1 SetMarkerStyle(8)
mg Add(gr3)
void Fit()
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
*******INTEGER m_nBinMax INTEGER m_NdiMax !No of bins in histogram for cell exploration division $ !Last vertex $ !Last active cell $ !Last cell in buffer $ !No of sampling when dividing cell $ !No of function total $ !Flag for random ceel for $ !Flag for type of for WtMax $ !Flag which decides whether vertices are included in the sampling $ entire domain is hyp !Maximum effective eevents per bin
Definition FoamA.h:85
const int MdcCalNLayer
Definition MdcCalParams.h:6
const double MdcCalTdcCnv
const int MdcCalNENTRXT
const int MdcCalLR
IMessageSvc * msgSvc()
#define NULL
virtual void getXtpar(int layid, int entr, int lr, double par[]) const =0
int fgCalib[MdcCalNLayer]
int esFlag[50]
double getXtpar(int lay, int entr, int lr, int order)
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
Definition MdcID.cxx:49
int updateConst(MdcCalibConst *calconst)
int fillHist(MdcCalEvent *event)
void printCut() const
void initialize(TObjArray *hlist, IMdcGeomSvc *mdcGeomSvc, IMdcCalibFunSvc *mdcFunSvc, IMdcUtilitySvc *mdcUtilitySvc)
unsigned int getChargeChannel() const
Definition RawData.cxx:45
unsigned int getTimeChannel() const
Definition RawData.cxx:40
Definition Event.h:21
const float pi
Definition vector3.h:133