1#include "MdcCalibAlg/IniMdcCalib.h"
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"
9#include "GaudiKernel/SmartDataPtr.h"
10#include "GaudiKernel/IDataProviderSvc.h"
11#include "GaudiKernel/PropertyMgr.h"
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"
41 delete m_hlaymapT[lay];
44 for(iEs=0; iEs<m_param.
nEsFlag; iEs++){
45 delete m_htdcTes[lay][iEs];
46 delete m_htrawTes[lay][iEs];
49 delete m_hlaymapQ[lay];
54 delete m_htrawCel[wir];
55 delete m_hqrawCel[wir];
58 delete m_hLayerHitmapT;
59 delete m_hWireHitMapT;
61 delete m_hLayerHitmapQ;
62 delete m_hWireHitMapQ;
63 for(iEs=0; iEs<m_param.
nEsFlag; iEs++)
delete m_hTes[iEs];
82 Gaudi::svcLocator() -> service(
"MessageSvc",
msgSvc);
83 MsgStream log(
msgSvc,
"IniMdcCalib");
84 log << MSG::INFO <<
"IniMdcCalib::initialize()" << endreq;
87 m_mdcGeomSvc = mdcGeomSvc;
88 m_mdcFunSvc = mdcFunSvc;
89 m_mdcUtilitySvc = mdcUtilitySvc;
97 m_nWire = m_mdcGeomSvc -> getWireSize();
98 m_nLayer = m_mdcGeomSvc -> getLayerSize();
100 m_fdcom =
new TFolder(
"Common",
"Common");
101 m_hlist->Add(m_fdcom);
103 m_fdTmap =
new TFolder(
"Thitmap",
"Thitmap");
104 m_hlist->Add(m_fdTmap);
106 m_fdTraw =
new TFolder(
"Traw",
"Traw");
107 m_hlist->Add(m_fdTraw);
109 m_fdTrawCel =
new TFolder(
"TrawCell",
"TrawCell");
110 m_hlist->Add(m_fdTrawCel);
112 m_fdTrawTes =
new TFolder(
"TrawTes",
"TrawTes");
113 m_hlist->Add(m_fdTrawTes);
115 m_fdQmap =
new TFolder(
"Qhitmap",
"Qhitmap");
116 m_hlist->Add(m_fdQmap);
118 m_fdQraw =
new TFolder(
"Qraw",
"Qraw");
119 m_hlist->Add(m_fdQraw);
121 m_fdQrawCel =
new TFolder(
"QrawCell",
"QrawCell");
122 m_hlist->Add(m_fdQrawCel);
124 m_hLayerHitmapT =
new TH1F(
"T_Hitmap_Layer",
"", 43, -0.5, 42.5);
125 m_fdcom->Add(m_hLayerHitmapT);
127 m_hWireHitMapT =
new TH1F(
"T_Hitmap_Wire",
"", 6796, -0.5, 6795.5);
128 m_fdcom->Add(m_hWireHitMapT);
130 m_hLayerHitmapQ =
new TH1F(
"Q_Hitmap_Layer",
"", 43, -0.5, 42.5);
131 m_fdcom->Add(m_hLayerHitmapQ);
133 m_hWireHitMapQ =
new TH1F(
"Q_Hitmap_Wire",
"", 6796, -0.5, 6795.5);
134 m_fdcom->Add(m_hWireHitMapQ);
137 for(iEs=0; iEs<m_param.
nEsFlag; iEs++){
139 m_hTes[iEs] =
new TH1F(hname,
"", 750, 0, 1500);
140 m_fdcom->Add(m_hTes[iEs]);
143 m_hTesAllFlag =
new TH1F(
"TesAllFlag",
"", 300, -0.5, 299.5);
144 m_fdcom ->
Add(m_hTesAllFlag);
146 m_hTesAll =
new TH1F(
"TesAll",
"", 750, 0, 1500);
147 m_fdcom->Add(m_hTesAll);
149 m_hTesCal =
new TH1F(
"TesCal",
"", 750, 0, 1500);
150 m_fdcom->Add(m_hTesCal);
152 m_hTesFlag =
new TH1F(
"Tes_Flag",
"", 300, -0.5, 299.5);
153 m_fdcom->Add(m_hTesFlag);
155 for(lay=0; lay<m_nLayer; lay++){
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]);
162 sprintf(hname,
"TDC_Lay%02d", lay);
163 m_htdc[lay] =
new TH1F(hname,
"", 800, 0, 20000);
164 m_fdTraw ->
Add(m_htdc[lay]);
166 sprintf(hname,
"Traw_Lay%02d", lay);
167 m_htraw[lay] =
new TH1F(hname,
"", 500, 0, 1000);
168 m_fdTraw ->
Add(m_htraw[lay]);
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]);
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]);
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]);
184 sprintf(hname,
"Qraw_Lay%02d", lay);
185 m_hqraw[lay] =
new TH1F(hname,
"", 2000, 0, 4000);
186 m_fdQraw ->
Add(m_hqraw[lay]);
190 lay = m_mdcGeomSvc -> Wire(wir) -> Layer();
191 cel = m_mdcGeomSvc -> Wire(wir) -> Cell();
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]);
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]);
205 Gaudi::svcLocator() -> service(
"MessageSvc",
msgSvc);
206 MsgStream log(
msgSvc,
"IniMdcCalib");
207 log << MSG::DEBUG <<
"IniMdcCalib::fillHist()" << endreq;
220 IDataProviderSvc* eventSvc = NULL;
221 Gaudi::svcLocator()->service(
"EventDataSvc", eventSvc);
223 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc,
"/Event/EventHeader");
225 log << MSG::FATAL <<
"Could not find Event Header" << endreq;
226 return( StatusCode::FAILURE);
228 int iRun = eventHeader->runNumber();
229 int iEvt = eventHeader->eventNumber();
232 double tes = -9999.0;
234 SmartDataPtr<RecEsTimeCol> aevtimeCol(eventSvc,
"/Event/Recon/RecEsTimeCol");
235 if( (!aevtimeCol) || (aevtimeCol->size()==0) ){
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();
246 m_hTesAllFlag->Fill(esTimeflag);
247 m_hTesAll->Fill(tes);
248 m_hTesFlag->Fill(esTimeflag);
250 for(
int iEs=0; iEs<m_param.
nEsFlag; iEs++){
251 if(esTimeflag == m_param.
esFlag[iEs]){
252 m_hTes[iEs]->Fill(tes);
257 bool fgFillTes =
false;
258 if( (nTesFlag > -1) && (tes > m_param.
tesMin) && (tes < m_param.
tesMax) ){
259 m_hTesCal->Fill(tes);
266 SmartDataPtr<MdcDigiCol> mdcDigiCol(eventSvc,
"/Event/Digi/MdcDigiCol");
268 log << MSG::FATAL <<
"Could not find event" << endreq;
271 MdcDigiCol::iterator
iter = mdcDigiCol->begin();
273 for(;
iter != mdcDigiCol->end();
iter++, digiId++) {
275 id = (aDigi)->identify();
279 wir = m_mdcGeomSvc->
Wire(lay, cel)->
Id();
281 tdc = (aDigi) -> getTimeChannel();
282 adc = (aDigi) -> getChargeChannel();
283 fgOverFlow = (aDigi) -> getOverflow();
285 if ( ((fgOverFlow & 1) !=0 ) || ((fgOverFlow & 12) != 0) ||
292 m_hLayerHitmapT ->
Fill(lay);
293 m_hWireHitMapT ->
Fill(wir);
294 m_hlaymapT[lay] ->
Fill(cel);
296 m_hLayerHitmapQ ->
Fill(lay);
297 m_hWireHitMapQ ->
Fill(wir);
298 m_hlaymapQ[lay] ->
Fill(cel);
304 m_htdc[lay] ->
Fill(tdc);
305 m_htraw[lay] ->
Fill(traw);
306 m_hqraw[lay] ->
Fill(qraw);
308 m_htdcTes[lay][nTesFlag] ->
Fill(tdc);
309 m_htrawTes[lay][nTesFlag] ->
Fill(traw);
311 m_htrawCel[wir] ->
Fill(traw);
312 m_hqrawCel[wir] ->
Fill(qraw);
320 Gaudi::svcLocator() -> service(
"MessageSvc",
msgSvc);
321 MsgStream log(
msgSvc,
"IniMdcCalib");
322 log << MSG::DEBUG <<
"IniMdcCalib::updateConst()" << endreq;
329 double initT0 = m_param.
initT0;
343 for(lay=0; lay<m_nLayer; lay++){
345 chindfTmin[lay] = -1;
346 sprintf(funname,
"ftmin%02d", lay);
347 ftmin[lay] =
new TF1(funname, funTmin, 0, 150, 6);
350 Stat_t nEntryTot = 0;
351 for(
int ibin=1; ibin<=25; ibin++){
352 Stat_t entry = m_htraw[lay]->GetBinContent(ibin);
355 double c0Ini = (double)nEntryTot / 25.0;
356 double c1Ini = (m_htraw[lay]->GetMaximum()) - c0Ini;
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);
364 m_htraw[lay] ->
Fit(funname,
"Q",
"",
367 chisq = ftmin[lay]->GetChisquare();
368 gStyle -> SetOptFit(11);
369 ndf = ftmin[lay]->GetNDF();
370 chindfTmin[lay] = chisq / ndf;
373 t0Fit[lay] = ftmin[lay]->GetParameter(4);
375 t0Cal[lay] = t0Fit[lay] - m_param.
timeShift;
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;
388 for(lay=0; lay<m_nLayer; lay++){
390 chindfTmax[lay] = -1;
391 sprintf(funname,
"ftmax%02d", lay);
392 ftmax[lay] =
new TF1(funname, funTmax, 250, 500, 4);
395 ftmax[lay] -> SetParameter(2, m_param.
initTm[lay]);
396 ftmax[lay] -> SetParameter(3, 10);
398 m_htraw[lay] ->
Fit(funname,
"Q+",
"",
401 gStyle -> SetOptFit(11);
402 chisq = ftmax[lay]->GetChisquare();
403 ndf = ftmax[lay]->GetNDF();
404 chindfTmax[lay] = chisq / ndf;
407 tmax[lay] = ftmax[lay]->GetParameter(2);
411 if(0 == fitTmaxFg[lay]){
412 tmax[lay] = (calconst->
getXtpar(lay, 0, 0, 6)) + t0Fit[lay];
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;
426 cout <<
"iniT0.dat was written." << endl;
430 int nwire = m_mdcGeomSvc -> getWireSize();
431 for(i=0; i<nwire; i++){
432 lay = m_mdcGeomSvc -> Wire(i) -> Layer();
434 calconst -> resetT0(i, t0Cal[lay]);
435 calconst -> resetDelT0(i, 0.0);
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;
453 xtpar = tmax[lay] - t0Fit[lay];
457 calconst -> resetXtpar(lay, iEntr, lr, ord, xtpar);
464 for(lay=0; lay<m_nLayer; lay++){
465 calconst -> resetQtpar0(lay, 0.0);
466 calconst -> resetQtpar1(lay, 0.0);
472 for(lay=0; lay<m_nLayer; lay++){
474 for(lr=0; lr<2; lr++){
476 calconst -> resetSdpar(lay, iEntr, lr,
bin, sdpar);
485 for(lay=0; lay<m_nLayer; lay++){
488 xtpar = tmax[lay] - t0Fit[lay];
489 calconst -> resetXtpar(lay, iEntr, lr, 6, xtpar);
503Double_t IniMdcCalib::funTmin(Double_t* x, Double_t* par){
505 fitval = par[0] + par[1]*
exp( -par[2]*(x[0]-par[3]) ) /
506 ( 1 +
exp( -(x[0]-par[4])/par[5] ));
510Double_t IniMdcCalib::funTmax(Double_t* x, Double_t* par){
512 fitval = par[0] + par[1] / (1 +
exp((x[0]-par[2])/par[3]));
EvtComplex exp(const EvtComplex &c)
*******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
const double MdcCalTdcCnv
const double MdcCalAdcCnv
virtual const MdcGeoLayer *const Layer(unsigned id)=0
virtual const MdcGeoWire *const Wire(unsigned id)=0
int updateConst(MdcCalibConst *calconst)
int fillHist(MdcCalEvent *event)
void initialize(TObjArray *hlist, IMdcGeomSvc *mdcGeomSvc, IMdcCalibFunSvc *mdcFunSvc, IMdcUtilitySvc *mdcUtilitySvc)
double tmaxFitRange[MdcCalNLayer][2]
int fgCalib[MdcCalNLayer]
double tminFitRange[MdcCalNLayer][2]
double initTm[MdcCalNLayer]
double getT0(int wireid) const
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
unsigned int getTimeChannel() const
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)