CGEM BOSS 6.6.5.f
BESIII Offline Software System
Loading...
Searching...
No Matches
IniMdcCalib.cxx
Go to the documentation of this file.
1#include "MdcCalibAlg/IniMdcCalib.h"
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
13#include "EventModel/EventHeader.h"
14#include "EvTimeEvent/RecEsTime.h"
15#include "EventModel/Event.h"
16#include "MdcRawEvent/MdcDigi.h"
17#include "Identifier/Identifier.h"
18#include "Identifier/MdcID.h"
19#include "TStyle.h"
20
21#include <iostream>
22#include <fstream>
23#include <iomanip>
24#include <string>
25#include <cstring>
26#include <cmath>
27
28#include "TF1.h"
29
30using namespace Event;
31
33}
34
36}
37
39 int iEs;
40 for(int lay=0; lay<MdcCalNLayer; lay++){
41 delete m_hlaymapT[lay];
42 delete m_htdc[lay];
43 delete m_htraw[lay];
44 for(iEs=0; iEs<m_param.nEsFlag; iEs++){
45 delete m_htdcTes[lay][iEs];
46 delete m_htrawTes[lay][iEs];
47 }
48
49 delete m_hlaymapQ[lay];
50 delete m_hqraw[lay];
51 }
52
53 for(int wir=0; wir<MdcCalTotCell; wir++){
54 delete m_htrawCel[wir];
55 delete m_hqrawCel[wir];
56 }
57
58 delete m_hLayerHitmapT;
59 delete m_hWireHitMapT;
60
61 delete m_hLayerHitmapQ;
62 delete m_hWireHitMapQ;
63 for(iEs=0; iEs<m_param.nEsFlag; iEs++) delete m_hTes[iEs];
64 delete m_hTesAllFlag;
65 delete m_hTesAll;
66 delete m_hTesCal;
67 delete m_hTesFlag;
68
69 delete m_fdcom;
70 delete m_fdTmap;
71 delete m_fdTraw;
72 delete m_fdTrawCel;
73 delete m_fdTrawTes;
74 delete m_fdQmap;
75 delete m_fdQraw;
76 delete m_fdQrawCel;
77}
78
79void IniMdcCalib::initialize(TObjArray* hlist, IMdcGeomSvc* mdcGeomSvc,
80 IMdcCalibFunSvc* mdcFunSvc, IMdcUtilitySvc* mdcUtilitySvc) {
81 IMessageSvc* msgSvc;
82 Gaudi::svcLocator() -> service("MessageSvc", msgSvc);
83 MsgStream log(msgSvc, "IniMdcCalib");
84 log << MSG::INFO << "IniMdcCalib::initialize()" << endreq;
85
86 m_hlist = hlist;
87 m_mdcGeomSvc = mdcGeomSvc;
88 m_mdcFunSvc = mdcFunSvc;
89 m_mdcUtilitySvc = mdcUtilitySvc;
90
91 int lay;
92 int cel;
93 int wir;
94 int ncel;
95 char hname[200];
96
97 m_nWire = m_mdcGeomSvc -> getWireSize();
98 m_nLayer = m_mdcGeomSvc -> getLayerSize();
99
100 m_fdcom = new TFolder("Common", "Common");
101 m_hlist->Add(m_fdcom);
102
103 m_fdTmap = new TFolder("Thitmap", "Thitmap");
104 m_hlist->Add(m_fdTmap);
105
106 m_fdTraw = new TFolder("Traw", "Traw");
107 m_hlist->Add(m_fdTraw);
108
109 m_fdTrawCel = new TFolder("TrawCell", "TrawCell");
110 m_hlist->Add(m_fdTrawCel);
111
112 m_fdTrawTes = new TFolder("TrawTes", "TrawTes");
113 m_hlist->Add(m_fdTrawTes);
114
115 m_fdQmap = new TFolder("Qhitmap", "Qhitmap");
116 m_hlist->Add(m_fdQmap);
117
118 m_fdQraw = new TFolder("Qraw", "Qraw");
119 m_hlist->Add(m_fdQraw);
120
121 m_fdQrawCel = new TFolder("QrawCell", "QrawCell");
122 m_hlist->Add(m_fdQrawCel);
123
124 m_hLayerHitmapT = new TH1F("T_Hitmap_Layer", "", 43, -0.5, 42.5);
125 m_fdcom->Add(m_hLayerHitmapT);
126
127 m_hWireHitMapT = new TH1F("T_Hitmap_Wire", "", 6796, -0.5, 6795.5);
128 m_fdcom->Add(m_hWireHitMapT);
129
130 m_hLayerHitmapQ = new TH1F("Q_Hitmap_Layer", "", 43, -0.5, 42.5);
131 m_fdcom->Add(m_hLayerHitmapQ);
132
133 m_hWireHitMapQ = new TH1F("Q_Hitmap_Wire", "", 6796, -0.5, 6795.5);
134 m_fdcom->Add(m_hWireHitMapQ);
135
136 int iEs;
137 for(iEs=0; iEs<m_param.nEsFlag; iEs++){
138 sprintf(hname, "Tes_%d", m_param.esFlag[iEs]);
139 m_hTes[iEs] = new TH1F(hname, "", 750, 0, 1500);
140 m_fdcom->Add(m_hTes[iEs]);
141 }
142
143 m_hTesAllFlag = new TH1F("TesAllFlag", "", 300, -0.5, 299.5);
144 m_fdcom -> Add(m_hTesAllFlag);
145
146 m_hTesAll = new TH1F("TesAll", "", 750, 0, 1500);
147 m_fdcom->Add(m_hTesAll);
148
149 m_hTesCal = new TH1F("TesCal", "", 750, 0, 1500);
150 m_fdcom->Add(m_hTesCal);
151
152 m_hTesFlag = new TH1F("Tes_Flag", "", 300, -0.5, 299.5);
153 m_fdcom->Add(m_hTesFlag);
154
155 for(lay=0; lay<m_nLayer; lay++){
156 ncel = m_mdcGeomSvc->Layer(lay)->NCell();
157
158 sprintf(hname, "T_hitmap_Lay%02d", lay);
159 m_hlaymapT[lay] = new TH1F(hname, "", ncel, -0.5, (float)ncel-0.5);
160 m_fdTmap -> Add(m_hlaymapT[lay]);
161
162 sprintf(hname, "TDC_Lay%02d", lay);
163 m_htdc[lay] = new TH1F(hname, "", 800, 0, 20000);
164 m_fdTraw -> Add(m_htdc[lay]);
165
166 sprintf(hname, "Traw_Lay%02d", lay);
167 m_htraw[lay] = new TH1F(hname, "", 500, 0, 1000);
168 m_fdTraw -> Add(m_htraw[lay]);
169
170 for(iEs=0; iEs<m_param.nEsFlag; iEs++){
171 sprintf(hname, "TDC_Lay%02d_Tes%d", lay, m_param.esFlag[iEs]);
172 m_htdcTes[lay][iEs] = new TH1F(hname, "", 800, 0, 20000);
173 m_fdTrawTes -> Add(m_htdcTes[lay][iEs]);
174
175 sprintf(hname, "Traw_Lay%02d_Tes%d", lay, m_param.esFlag[iEs]);
176 m_htrawTes[lay][iEs] = new TH1F(hname, "", 300, 0, 600);
177 m_fdTrawTes -> Add(m_htrawTes[lay][iEs]);
178 }
179
180 sprintf(hname, "Q_hitmap_Lay%02d", lay);
181 m_hlaymapQ[lay] = new TH1F(hname, "", ncel, -0.5, (float)ncel-0.5);
182 m_fdQmap -> Add(m_hlaymapQ[lay]);
183
184 sprintf(hname, "Qraw_Lay%02d", lay);
185 m_hqraw[lay] = new TH1F(hname, "", 2000, 0, 4000);
186 m_fdQraw -> Add(m_hqraw[lay]);
187 }
188
189 for(wir=0; wir<MdcCalTotCell; wir++){
190 lay = m_mdcGeomSvc -> Wire(wir) -> Layer();
191 cel = m_mdcGeomSvc -> Wire(wir) -> Cell();
192
193 sprintf(hname, "Traw_%02d_%03d_%04d", lay, cel, wir);
194 m_htrawCel[wir] = new TH1F(hname, "", 300, 0, 600);
195 m_fdTrawCel -> Add(m_htrawCel[wir]);
196
197 sprintf(hname, "Qraw_%02d_%03d_%04d", lay, cel, wir);
198 m_hqrawCel[wir] = new TH1F(hname, "", 2000, 0, 4000);
199 m_fdQrawCel -> Add(m_hqrawCel[wir]);
200 }
201}
202
204 IMessageSvc* msgSvc;
205 Gaudi::svcLocator() -> service("MessageSvc", msgSvc);
206 MsgStream log(msgSvc, "IniMdcCalib");
207 log << MSG::DEBUG << "IniMdcCalib::fillHist()" << endreq;
208
209 int lay;
210 int cel;
211 int wir;
212 int digiId;
213 unsigned fgOverFlow;
214 double tdc;
215 double traw;
216 double adc;
217 double qraw;
218 Identifier id;
219
220 IDataProviderSvc* eventSvc = NULL;
221 Gaudi::svcLocator()->service("EventDataSvc", eventSvc);
222
223 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc,"/Event/EventHeader");
224 if (!eventHeader) {
225 log << MSG::FATAL << "Could not find Event Header" << endreq;
226 return( StatusCode::FAILURE);
227 }
228 int iRun = eventHeader->runNumber();
229 int iEvt = eventHeader->eventNumber();
230
231 // get EsTimeCol
232 double tes = -9999.0;
233 int esTimeflag = -1;
234 SmartDataPtr<RecEsTimeCol> aevtimeCol(eventSvc,"/Event/Recon/RecEsTimeCol");
235 if( (!aevtimeCol) || (aevtimeCol->size()==0) ){
236 tes = -9999.0;
237 esTimeflag = -1;
238 }else{
239 RecEsTimeCol::iterator iter_evt = aevtimeCol->begin();
240 for(; iter_evt!=aevtimeCol->end(); iter_evt++){
241 tes = (*iter_evt)->getTest();
242 esTimeflag = (*iter_evt)->getStat();
243// cout << "tes " << tes << endl;
244 }
245 }
246 m_hTesAllFlag->Fill(esTimeflag);
247 m_hTesAll->Fill(tes);
248 m_hTesFlag->Fill(esTimeflag);
249 int nTesFlag = -1;
250 for(int iEs=0; iEs<m_param.nEsFlag; iEs++){
251 if(esTimeflag == m_param.esFlag[iEs]){
252 m_hTes[iEs]->Fill(tes);
253 nTesFlag = iEs;
254 break;
255 }
256 }
257 bool fgFillTes = false;
258 if( (nTesFlag > -1) && (tes > m_param.tesMin) && (tes < m_param.tesMax) ){
259 m_hTesCal->Fill(tes);
260 fgFillTes = true;
261 }
262
263// cout << setw(10) << iRun << setw(10) << iEvt << setw(10) << tes << endl;
264
265 // retrieve Mdc digi
266 SmartDataPtr<MdcDigiCol> mdcDigiCol(eventSvc,"/Event/Digi/MdcDigiCol");
267 if (!mdcDigiCol) {
268 log << MSG::FATAL << "Could not find event" << endreq;
269 }
270
271 MdcDigiCol::iterator iter = mdcDigiCol->begin();
272 digiId = 0;
273 for(; iter != mdcDigiCol->end(); iter++, digiId++) {
274 MdcDigi *aDigi = (*iter);
275 id = (aDigi)->identify();
276
277 lay = MdcID::layer(id);
278 cel = MdcID::wire(id);
279 wir = m_mdcGeomSvc->Wire(lay, cel)->Id();
280
281 tdc = (aDigi) -> getTimeChannel();
282 adc = (aDigi) -> getChargeChannel();
283 fgOverFlow = (aDigi) -> getOverflow();
284
285 if ( ((fgOverFlow & 1) !=0 ) || ((fgOverFlow & 12) != 0) ||
286 (aDigi->getTimeChannel() == 0x7FFFFFFF) ||
287 (aDigi->getChargeChannel() == 0x7FFFFFFF) ) continue;
288
289 traw = tdc * MdcCalTdcCnv;
290 qraw = adc * MdcCalAdcCnv;
291
292 m_hLayerHitmapT -> Fill(lay);
293 m_hWireHitMapT -> Fill(wir);
294 m_hlaymapT[lay] -> Fill(cel);
295
296 m_hLayerHitmapQ -> Fill(lay);
297 m_hWireHitMapQ -> Fill(wir);
298 m_hlaymapQ[lay] -> Fill(cel);
299
300 if(fgFillTes){
301 traw -= tes;
302 traw += m_param.timeShift;
303
304 m_htdc[lay] -> Fill(tdc);
305 m_htraw[lay] -> Fill(traw);
306 m_hqraw[lay] -> Fill(qraw);
307
308 m_htdcTes[lay][nTesFlag] -> Fill(tdc);
309 m_htrawTes[lay][nTesFlag] -> Fill(traw);
310
311 m_htrawCel[wir] -> Fill(traw);
312 m_hqrawCel[wir] -> Fill(qraw);
313 }
314 }
315 return 1;
316}
317
319 IMessageSvc* msgSvc;
320 Gaudi::svcLocator() -> service("MessageSvc", msgSvc);
321 MsgStream log(msgSvc, "IniMdcCalib");
322 log << MSG::DEBUG << "IniMdcCalib::updateConst()" << endreq;
323
324 int lay;
325 int wir;
326 double t0Fit[MdcCalNLayer];
327 double t0Cal[MdcCalNLayer];
328 double tmax[MdcCalNLayer];
329 double initT0 = m_param.initT0;
330
331 int fitTminFg[MdcCalNLayer];
332 int fitTmaxFg[MdcCalNLayer];
333 double chisq;
334 double ndf;
335 double chindfTmin[MdcCalNLayer];
336 double chindfTmax[MdcCalNLayer];
337 char funname[200];
338
339 // fit Tmin
340 TF1* ftmin[MdcCalNLayer];
341// sprintf(funname, "ftmin", lay);
342// TF1* ftmin = new TF1(funname, funTmin, 0, 150, 6);
343 for(lay=0; lay<m_nLayer; lay++){
344 fitTminFg[lay] = 0;
345 chindfTmin[lay] = -1;
346 sprintf(funname, "ftmin%02d", lay);
347 ftmin[lay] = new TF1(funname, funTmin, 0, 150, 6);
348
349 if(1 == m_param.fgCalib[lay]){
350 Stat_t nEntryTot = 0;
351 for(int ibin=1; ibin<=25; ibin++){
352 Stat_t entry = m_htraw[lay]->GetBinContent(ibin);
353 nEntryTot += entry;
354 }
355 double c0Ini = (double)nEntryTot / 25.0;
356 double c1Ini = (m_htraw[lay]->GetMaximum()) - c0Ini;
357
358 ftmin[lay] -> SetParameter(0, c0Ini);
359 ftmin[lay] -> SetParameter(1, c1Ini);
360 ftmin[lay] -> SetParameter(2, 0);
361 ftmin[lay] -> SetParameter(4, initT0);
362 ftmin[lay] -> SetParameter(5, 2);
363
364 m_htraw[lay] -> Fit(funname, "Q", "",
365 m_param.tminFitRange[lay][0],
366 m_param.tminFitRange[lay][1]);
367 chisq = ftmin[lay]->GetChisquare();
368 gStyle -> SetOptFit(11);
369 ndf = ftmin[lay]->GetNDF();
370 chindfTmin[lay] = chisq / ndf;
371 if(chindfTmin[lay] < m_param.tminFitChindf){
372 fitTminFg[lay] = 1;
373 t0Fit[lay] = ftmin[lay]->GetParameter(4);
374 t0Fit[lay] += m_param.t0Shift;
375 t0Cal[lay] = t0Fit[lay] - m_param.timeShift;
376 }
377 }
378
379 if(0 == fitTminFg[lay]){
380 wir = m_mdcGeomSvc->Wire(lay, 0)->Id();
381 t0Cal[lay] = calconst->getT0(wir);
382 t0Fit[lay] = t0Cal[lay] + m_param.timeShift;
383 }
384 }
385
386 // fit Tmax
387 TF1* ftmax[MdcCalNLayer];
388 for(lay=0; lay<m_nLayer; lay++){
389 fitTmaxFg[lay] = 0;
390 chindfTmax[lay] = -1;
391 sprintf(funname, "ftmax%02d", lay);
392 ftmax[lay] = new TF1(funname, funTmax, 250, 500, 4);
393
394 if(1 == m_param.fgCalib[lay]){
395 ftmax[lay] -> SetParameter(2, m_param.initTm[lay]);
396 ftmax[lay] -> SetParameter(3, 10);
397
398 m_htraw[lay] -> Fit(funname, "Q+", "",
399 m_param.tmaxFitRange[lay][0],
400 m_param.tmaxFitRange[lay][1]);
401 gStyle -> SetOptFit(11);
402 chisq = ftmax[lay]->GetChisquare();
403 ndf = ftmax[lay]->GetNDF();
404 chindfTmax[lay] = chisq / ndf;
405 if(chindfTmax[lay] < m_param.tmaxFitChindf){
406 fitTmaxFg[lay] = 1;
407 tmax[lay] = ftmax[lay]->GetParameter(2);
408 }
409 }
410
411 if(0 == fitTmaxFg[lay]){
412 tmax[lay] = (calconst->getXtpar(lay, 0, 0, 6)) + t0Fit[lay];
413 }
414 }
415
416 // output for check
417 ofstream ft0("iniT0.dat");
418 for(lay=0; lay<m_nLayer; lay++){
419 ft0 << setw(5) << lay << setw(3) << fitTminFg[lay]
420 << setw(12) << t0Cal[lay] << setw(12) << t0Fit[lay]
421 << setw(12) << chindfTmin[lay] << setw(5) << fitTmaxFg[lay]
422 << setw(12) << tmax[lay] << setw(12) << tmax[lay] - t0Fit[lay]
423 << setw(12) << chindfTmax[lay] << endl;
424 }
425 ft0.close();
426 cout << "iniT0.dat was written." << endl;
427
428 // set T0
429 int i;
430 int nwire = m_mdcGeomSvc -> getWireSize();
431 for(i=0; i<nwire; i++){
432 lay = m_mdcGeomSvc -> Wire(i) -> Layer();
433 if(1 == m_param.fgCalib[lay]){
434 calconst -> resetT0(i, t0Cal[lay]);
435 calconst -> resetDelT0(i, 0.0);
436 }
437 }
438
439 if(0 == m_param.fgIniCalConst){
440 // set X-T
441 int lr;
442 int iEntr;
443 int ord;
444 double xtpar;
445 double xtini[8] = {0, 0.03, 0, 0, 0, 0, 999.9, 0};
446 for(lay=0; lay<m_nLayer; lay++){
447 if(1 != m_param.fgCalib[lay]) continue;
448
449 for(iEntr=0; iEntr<MdcCalNENTRXT; iEntr++){
450 for(lr=0; lr<MdcCalLR; lr++){
451 for(ord=0; ord<MdcCalXtNPars; ord++){
452 if(6 == ord){
453 xtpar = tmax[lay] - t0Fit[lay];
454 } else{
455 xtpar = xtini[ord];
456 }
457 calconst -> resetXtpar(lay, iEntr, lr, ord, xtpar);
458 }
459 }
460 }
461 }
462
463 // set Q-T
464 for(lay=0; lay<m_nLayer; lay++){
465 calconst -> resetQtpar0(lay, 0.0);
466 calconst -> resetQtpar1(lay, 0.0);
467 }
468
469 // set S-D
470 int bin;
471 double sdpar = m_param.initSigma; // mm
472 for(lay=0; lay<m_nLayer; lay++){
473 for(iEntr=0; iEntr<MdcCalNENTRSD; iEntr++){
474 for(lr=0; lr<2; lr++){
475 for(bin=0; bin<MdcCalSdNBIN; bin++){
476 calconst -> resetSdpar(lay, iEntr, lr, bin, sdpar);
477 }
478 }
479 }
480 }
481 } else if(2 == m_param.fgIniCalConst){
482 int lr;
483 int iEntr;
484 double xtpar;
485 for(lay=0; lay<m_nLayer; lay++){
486 for(iEntr=0; iEntr<MdcCalNENTRXT; iEntr++){
487 for(lr=0; lr<MdcCalLR; lr++){
488 xtpar = tmax[lay] - t0Fit[lay];
489 calconst -> resetXtpar(lay, iEntr, lr, 6, xtpar);
490 }
491 }
492 }
493 }
494
495// delete ftmin;
496 for(lay=0; lay<MdcCalNLayer; lay++){
497 delete ftmin[lay];
498 delete ftmax[lay];
499 }
500 return 1;
501}
502
503Double_t IniMdcCalib::funTmin(Double_t* x, Double_t* par){
504 Double_t fitval;
505 fitval = par[0] + par[1]*exp( -par[2]*(x[0]-par[3]) ) /
506 ( 1 + exp( -(x[0]-par[4])/par[5] ));
507 return fitval;
508}
509
510Double_t IniMdcCalib::funTmax(Double_t* x, Double_t* par){
511 Double_t fitval;
512 fitval = par[0] + par[1] / (1 + exp((x[0]-par[2])/par[3]));
513 return fitval;
514}
515
gr Fit("g1","R")
EvtComplex exp(const EvtComplex &c)
Definition: EvtComplex.hh:252
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
virtual const MdcGeoLayer *const Layer(unsigned id)=0
virtual const MdcGeoWire *const Wire(unsigned id)=0
int updateConst(MdcCalibConst *calconst)
void clear()
Definition: IniMdcCalib.cxx:38
int fillHist(MdcCalEvent *event)
void initialize(TObjArray *hlist, IMdcGeomSvc *mdcGeomSvc, IMdcCalibFunSvc *mdcFunSvc, IMdcUtilitySvc *mdcUtilitySvc)
Definition: IniMdcCalib.cxx:79
double getXtpar(int lay, int entr, int lr, int order)
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
static int wire(const Identifier &id)
unsigned int getChargeChannel() const
Definition: RawData.cxx:45
unsigned int getTimeChannel() const
Definition: RawData.cxx:40