3#include "GaudiKernel/MsgStream.h"
4#include "GaudiKernel/SmartDataPtr.h"
5#include "GaudiKernel/PropertyMgr.h"
6#include "GaudiKernel/Bootstrap.h"
7#include "GaudiKernel/Algorithm.h"
9#include "GaudiKernel/INTupleSvc.h"
10#include "GaudiKernel/NTuple.h"
11#include "GaudiKernel/ITHistSvc.h"
13#include "CLHEP/Vector/ThreeVector.h"
14#include "CLHEP/Vector/LorentzVector.h"
30#include "DQAEvent/DQAEvent.h"
33using CLHEP::Hep3Vector;
37 Algorithm(name, pSvcLocator) {
40 declareProperty(
"EffWindow", m_effWindow = 4);
45 MsgStream log(
msgSvc(), name());
47 log << MSG::INFO <<
"in initialize()" << endmsg;
51 if(service(
"THistSvc", m_thsvc).isFailure()) {
52 log << MSG::ERROR <<
"Couldn't get THistSvc" << endreq;
53 return StatusCode::FAILURE;
62 sprintf( name,
"BrResDist_All_L%d", i );
64 m_hBrResDist[i][0] =
new TH1F(name,
title, 200, -100, 100 );
65 sprintf( name,
"/DQAHist/MUC/BrResDist_All_L%d", i );
66 if(m_thsvc->regHist(name, m_hBrResDist[i][0]).isFailure())
67 { log << MSG::ERROR <<
"Couldn't register " << name << endreq; }
69 sprintf( name,
"BrResDist_Dimu_L%d", i );
70 m_hBrResDist[i][1] =
new TH1F(name,
title, 200, -100, 100 );
71 sprintf( name,
"/DQAHist/MUC/BrResDist_Dimu_L%d", i );
72 if(m_thsvc->regHist(name, m_hBrResDist[i][1]).isFailure())
73 { log << MSG::ERROR <<
"Couldn't register " << name << endreq; }
78 sprintf( name,
"EcResDist_All_L%d", i );
80 m_hEcResDist[i][0] =
new TH1F(name,
title, 200, -100, 100 );
81 sprintf( name,
"/DQAHist/MUC/EcResDist_All_L%d", i );
82 if(m_thsvc->regHist(name, m_hEcResDist[i][0]).isFailure())
83 { log << MSG::ERROR <<
"Couldn't register " << name << endreq; }
85 sprintf( name,
"EcResDist_Dimu_L%d", i );
86 m_hEcResDist[i][1] =
new TH1F(name,
title, 200, -100, 100 );
87 sprintf( name,
"/DQAHist/MUC/EcResDist_Dimu_L%d", i );
88 if(m_thsvc->regHist(name, m_hEcResDist[i][1]).isFailure())
89 { log << MSG::ERROR <<
"Couldn't register " << name << endreq; }
120 for(
int i=0; i<
TAGN; i++)
122 for(
int j=0; j<2; j++)
124 for(
int k=0; k<
LVLN; k++)
130 m_hEff[k][i][j] =
new TH1F(name,
title, LAYER_MAX+1, -0.5, LAYER_MAX+0.5);
131 m_hEff[k][i][j]->GetXaxis()->SetTitle(
"Layer id");
133 m_hEff[k][i][j] =
new TH1F(name,
title, BOX_MAX+1, -0.5, BOX_MAX+0.5);
134 m_hEff[k][i][j]->GetXaxis()->SetTitle(
"Box id [EE:0~31, BR:32~103, WE:104~135]");
137 m_hEff[k][i][j]->GetXaxis()->SetTitle(
"Strip id");
140 m_hEff[k][i][j]->GetXaxis()->CenterTitle();
144 if(m_thsvc->regHist(name, m_hEff[k][i][j]).isFailure())
145 { log << MSG::ERROR <<
"Couldn't register " << name << endreq; }
150 m_hNosRatio[i][j] =
new TH1F(name,
title, BOX_MAX+1, -0.5, BOX_MAX+0.5);
151 m_hNosRatio[i][j]->GetXaxis()->SetTitle(
"Box id [EE:0~31, BR:32~103, WE:104~135]");
152 m_hNosRatio[i][j]->GetXaxis()->CenterTitle();
157 if(m_thsvc->regHist(name, m_hNosRatio[i][j]).isFailure())
158 { log << MSG::ERROR <<
"Couldn't register " << name << endreq; }
164 m_hCostheta[i] =
new TH1F(name,
title, 360, -1.0, 1.0);
165 m_hCostheta[i]->GetXaxis()->SetTitle(
"cos#theta");
166 m_hCostheta[i]->GetXaxis()->CenterTitle();
170 m_hPhi[i] =
new TH1F(name,
title, 360, -
PI,
PI);
171 m_hPhi[i]->GetXaxis()->SetTitle(
"#phi");
172 m_hPhi[i]->GetXaxis()->CenterTitle();
175 if(m_thsvc->regHist(name, m_hCostheta[i]).isFailure())
176 { log << MSG::ERROR <<
"Couldn't register " << name << endreq; }
178 if(m_thsvc->regHist(name, m_hPhi[i]).isFailure())
179 { log << MSG::ERROR <<
"Couldn't register Phi_All" << endreq; }
191 for(
int j=0; j<SEGMENT_MAX; j++ )
192 for(
int k=0; k<LAYER_MAX; k++ )
193 for(
int n=0; n<STRIP_INBOX_MAX; n++ )
195 m_recordAll[i][j][k][n][0] = 0;
196 m_recordAll[i][j][k][n][1] = 0;
197 m_recordAll[i][j][k][n][2] = 0;
198 m_recordAll[i][j][k][n][3] = 0;
199 m_recordAll[i][j][k][n][4] = 0;
201 m_recordDimu[i][j][k][n][0] = 0;
202 m_recordDimu[i][j][k][n][1] = 0;
203 m_recordDimu[i][j][k][n][2] = 0;
204 m_recordDimu[i][j][k][n][3] = 0;
205 m_recordDimu[i][j][k][n][4] = 0;
208 m_ptrMucMark =
new MucMark(0,0,0,0);
212 m_expHitCol.resize(0);
213 m_effHitCol.resize(0);
214 m_nosHitCol.resize(0);
215 m_clusterCol.resize(0);
218 for(
int j=0; j<SEGMENT_MAX; j++ ) {
219 m_segDigiCol[i][j].resize(0);
222 log << MSG::INFO <<
"Initialize done!" <<endmsg;
223 return StatusCode::SUCCESS;
229 MsgStream log(
msgSvc(), name());
230 log << MSG::INFO <<
"in execute()" << endreq;
232 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
233 m_run = eventHeader->runNumber();
234 m_event = eventHeader->eventNumber();
235 log << MSG::DEBUG <<
"Run " << m_run <<
"\tEvent " << m_event <<endreq;
237 SmartDataPtr<DQAEvent::DQAEvent> dqaevt(eventSvc(),
"/Event/DQATag");
239 log << MSG::INFO <<
"success get DQAEvent" << endreq;
241 log << MSG::ERROR <<
"Error accessing DQAEvent" << endreq;
242 return StatusCode::FAILURE;
244 log << MSG::DEBUG <<
"DQA event tag = " << dqaevt->EventTag() << endreq;
246 int part, segment, layer, strip;
249 if ( dqaevt->Dimu() ) isDimu =
true;
250 log << MSG::INFO <<
"DQADimuTag:\t" << dqaevt->Dimu() << endreq;
253 log << MSG::INFO <<
"Retrieve digis" << endreq;
254 SmartDataPtr<MucDigiCol> mucDigiCol(eventSvc(),
"/Event/Digi/MucDigiCol");
256 log << MSG::FATAL <<
"Could not find MUC digi" << endreq;
257 return( StatusCode::FAILURE);
261 MucDigiCol::iterator digiIter = mucDigiCol->begin();
263 for (
int digiId =0; digiIter != mucDigiCol->end(); digiIter++, digiId++ )
265 mucId = (*digiIter)->identify();
272 m_digiCol.push_back( aMark );
273 m_segDigiCol[part][segment].push_back( aMark );
274 m_recordAll[part][segment][layer][strip][0] ++;
275 if( isDimu ) m_recordDimu[part][segment][layer][strip][0] ++;
277 log << MSG::INFO <<
"Total digis in this event: " << eventDigi << endreq;
278 if( eventDigi > 500) cout <<
"Run:\t"<< m_run <<
"\tEvent:\t"<< m_event <<
"\tdigits inflation:\t" << eventDigi << endreq;
281 m_clusterCol = (*m_ptrMucMark).CreateClusterCol(1, m_digiCol );
282 log << MSG::INFO <<
"Total clusters in this event: " << m_clusterCol.size() << endreq;
287 SmartDataPtr<RecMucTrackCol> mucTrackCol(eventSvc(),
"/Event/Recon/RecMucTrackCol");
290 log << MSG::WARNING <<
"Could not find RecMucTrackCol" << endreq;
291 return( StatusCode::SUCCESS);
295 if (aRecMucTrackCol->size() < 1) {
296 log << MSG::INFO <<
"No MUC tracks in this event" << endreq;
297 return StatusCode::SUCCESS;
299 log << MSG::INFO <<
"Total tracks of this event: " << aRecMucTrackCol->size() << endreq;
301 int trackHitNum, expectedHitNum, segNum, lastLayerBR, lastLayerEC;
302 int layerPassNum[3], passMax[TRACK_SEG_MAX][2];
303 bool firedLay[TRACK_SEG_MAX][LAYER_MAX];
306 trackHitNum = expectedHitNum = segNum = lastLayerBR = lastLayerEC = 0;
307 layerPassNum[0] = layerPassNum[1] = layerPassNum[2] = 0;
308 for(
int segi=0; segi<TRACK_SEG_MAX; segi++ ) {
309 passMax[segi][0] = passMax[segi][1] = 0;
310 for(
int layi=0; layi<LAYER_MAX; layi++ ) firedLay[segi][layi] = 0;
313 vector<MucRecHit*> mucRawHitCol;
314 vector<MucRecHit*> mucExpHitCol;
315 RecMucTrackCol::iterator trackIter = mucTrackCol->begin();
316 for (
int trackId = 0; trackIter != mucTrackCol->end(); trackIter++, trackId++)
318 trackHitNum = (*trackIter)->numHits();
320 if( trackHitNum == 0 ) {
321 log << MSG::INFO <<
"Track " << trackId <<
" no hits" << endreq;
325 lastLayerBR = (*trackIter)->brLastLayer();
326 lastLayerEC = (*trackIter)->ecLastLayer();
328 CLHEP::Hep3Vector a3Vector((*trackIter)->xPos(),(*trackIter)->yPos(),(*trackIter)->zPos());
330 phi = a3Vector.phi();
331 if(m_thsvc->getHist(
"/DQAHist/MUC/Costheta_All", htmp).isSuccess()) {
334 log << MSG::ERROR <<
"Fail to retrieve Costheta_All" << endreq;
336 if(m_thsvc->getHist(
"/DQAHist/MUC/Phi_All", htmp).isSuccess()) {
339 log << MSG::ERROR <<
"Fail to retrieve Phi_All" << endreq;
344 if(m_thsvc->getHist(
"/DQAHist/MUC/Costheta_Dimu", htmp).isSuccess()) {
347 log << MSG::ERROR <<
"Fail to retrieve Costheta_Dimu" << endreq;
349 if(m_thsvc->getHist(
"/DQAHist/MUC/Phi_Dimu", htmp).isSuccess()) {
352 log << MSG::ERROR <<
"Fail to retrieve Phi_Dimu" << endreq;
355 log << MSG::INFO <<
"Fill costheta and phi:\t" <<
costheta <<
"\t" << phi << endreq;
362 mucExpHitCol = (*trackIter)->GetExpectedHits();
364 expectedHitNum += mucExpHitCol.size();
365 for(
unsigned int hitId = 0; hitId < mucExpHitCol.size(); hitId++)
367 pMucRawHit = mucExpHitCol[ hitId ];
368 part = pMucRawHit->
Part(); segment = pMucRawHit->
Seg();
369 layer = pMucRawHit->
Gap(); strip = pMucRawHit->
Strip();
371 MucMark* currentMark =
new MucMark( part, segment, layer, strip );
372 m_expHitCol.push_back( currentMark );
376 bool isInEffWindow =
false;
377 isInPos = currentMark->
IsInCol( m_segDigiCol[part][segment] );
380 if( part ==
BRID && (layer-lastLayerBR>1) )
continue;
381 if( part !=
BRID && (layer-lastLayerEC>1) )
continue;
384 if( part==
BRID && layer==0 && (strip<2 || strip>45) )
388 m_recordAll[part][segment][layer][strip][2] ++;
389 m_recordAll[part][segment][layer][strip][1] ++;
390 m_effHitCol.push_back( m_segDigiCol[part][segment][isInPos] );
393 m_recordDimu[part][segment][layer][strip][2] ++;
394 m_recordDimu[part][segment][layer][strip][1] ++;
398 m_recordAll[part][segment][layer][strip][1] ++;
399 if(isDimu) m_recordDimu[part][segment][layer][strip][1] ++;
406 m_recordAll[part][segment][layer][strip][2] ++;
407 m_recordAll[part][segment][layer][strip][1] ++;
408 m_effHitCol.push_back( m_segDigiCol[part][segment][isInPos] );
411 m_recordDimu[part][segment][layer][strip][2] ++;
412 m_recordDimu[part][segment][layer][strip][1] ++;
417 else for(
int tempStrip=0, hiti=-m_effWindow; hiti<=m_effWindow; hiti++ )
419 if( hiti == 0 )
continue;
420 tempStrip = strip + hiti;
421 if( tempStrip < 0 || tempStrip > m_ptrIdTr->
GetStripMax(part,segment,layer) )
continue;
423 isInPos = m_ptrMucMark->
IsInCol( part, segment, layer, tempStrip, m_segDigiCol[part][segment] );
426 m_recordAll[part][segment][layer][tempStrip][2] ++;
427 m_recordAll[part][segment][layer][tempStrip][1] ++;
428 m_effHitCol.push_back( m_segDigiCol[part][segment][isInPos] );
431 m_recordDimu[part][segment][layer][tempStrip][2] ++;
432 m_recordDimu[part][segment][layer][tempStrip][1] ++;
435 isInEffWindow =
true;
439 if( isInEffWindow ) {
continue; }
441 m_recordAll[part][segment][layer][strip][1] ++;
442 if(isDimu) m_recordDimu[part][segment][layer][strip][1] ++;
448 log << MSG::INFO <<
"Fill residual" << endreq;
449 vector<float> m_lineResCol = (*trackIter)->getDistHits();
451 mucRawHitCol = (*trackIter)->GetHits();
454 if( trackHitNum > 4 && m_lineResCol[0] != -99)
457 bool firedFlag[
PART_MAX][LAYER_MAX][2];
458 for(
int iprt=0; iprt<
PART_MAX; iprt++)
459 for(
int jlay=0; jlay<LAYER_MAX; jlay++)
460 firedFlag[iprt][jlay][0] = firedFlag[iprt][jlay][1] =
false;
462 for(
unsigned int hitId = 0; hitId < mucExpHitCol.size(); hitId++)
464 pMucExpHit = mucExpHitCol[ hitId ];
465 part = pMucExpHit->
Part(); segment = pMucExpHit->
Seg(); layer = pMucExpHit->
Gap();
466 firedFlag[part][layer][0] =
true;
469 for(
unsigned int hitId = 0; hitId < mucRawHitCol.size(); hitId++)
471 pMucRawHit = mucRawHitCol[ hitId ];
472 part = pMucRawHit->
Part(); segment = pMucRawHit->
Seg(); layer = pMucRawHit->
Gap();
475 if( firedFlag[part][layer][0] ==
true && firedFlag[part][layer][1] ==
false )
479 sprintf( name,
"/DQAHist/MUC/BrResDist_All_L%d", layer );
480 if(m_thsvc->getHist(name, htmp).isSuccess()) {
481 htmp->Fill( m_lineResCol[hitId] );
483 log << MSG::ERROR <<
"Fail to retrieve " << name << endreq;
489 sprintf( name,
"/DQAHist/MUC/BrResDist_Dimu_L%d", layer );
490 if(m_thsvc->getHist(name, htmp).isSuccess()) {
491 htmp->Fill( m_lineResCol[hitId] );
493 log << MSG::ERROR <<
"Fail to retrieve " << name << endreq;
498 sprintf( name,
"/DQAHist/MUC/EcResDist_All_L%d", layer );
499 if(m_thsvc->getHist(name, htmp).isSuccess()) {
500 htmp->Fill( m_lineResCol[hitId] );
502 log << MSG::ERROR <<
"Fail to retrieve " << name << endreq;
508 sprintf( name,
"/DQAHist/MUC/EcResDist_Dimu_L%d", layer );
509 if(m_thsvc->getHist(name, htmp).isSuccess()) {
510 htmp->Fill( m_lineResCol[hitId] );
512 log << MSG::ERROR <<
"Fail to retrieve " << name << endreq;
519 firedFlag[part][layer][1] =
true;
523 mucRawHitCol.clear();
524 mucExpHitCol.clear();
530 log << MSG::INFO <<
"Searching inc/noise hits" << endreq;
533 for(
unsigned int i=0; i < m_digiCol.size(); i++ )
537 if( m_digiCol[i]->IsInCol( m_effHitCol )!=-1 )
continue;
540 for(
unsigned int j=0; j < m_clusterCol.size(); j++ )
543 for(
unsigned int k=0; k<m_clusterCol[j].size(); k++)
545 if( m_clusterCol[j][k]->IsInCol(m_effHitCol) != -1)
552 if ( hasEffHit && (m_digiCol[i]->IsInCol( m_clusterCol[j] ) != -1) ) {
559 part = (*m_digiCol[i]).Part(); segment = (*m_digiCol[i]).
Segment();
560 layer = (*m_digiCol[i]).Layer(); strip = (*m_digiCol[i]).Strip();
563 m_recordAll[part][segment][layer][strip][3] ++;
564 if( isDimu ) m_recordDimu[part][segment][layer][strip][3] ++;
565 m_nosHitCol.push_back(m_digiCol[i]);
571 DQA_MUC::FillHistograms( isDimu );
574 for(
unsigned int i=0; i<m_digiCol.size(); i++ ) {
575 if( m_digiCol[i] != NULL )
delete m_digiCol[i];
578 for(
unsigned int i=0; i<m_expHitCol.size(); i++ ) {
579 if( m_expHitCol[i] != NULL )
delete m_expHitCol[i];
582 if( m_effHitCol.size() != 0 ) m_effHitCol.clear();
583 if( m_expHitCol.size() != 0 ) m_expHitCol.clear();
584 if( m_nosHitCol.size() != 0 ) m_nosHitCol.clear();
585 if( m_digiCol.size() != 0 ) m_digiCol.clear();
586 if( m_clusterCol.size() != 0 ) m_clusterCol.clear();
589 for(
int j=0; j<SEGMENT_MAX; j++ ) {
590 if( m_segDigiCol[i][j].size() != 0 ) m_segDigiCol[i][j].clear();
594 return StatusCode::SUCCESS;
600 MsgStream log(
msgSvc(), name());
601 log << MSG::INFO <<
"in finalize()" << endmsg;
830 log << MSG::INFO <<
"Finalize successfully! " << endmsg;
832 return StatusCode::SUCCESS;
835StatusCode DQA_MUC::FillHistograms(
bool isDimu) {
837 MsgStream log(
msgSvc(), name());
838 log << MSG::INFO <<
"Filling histograms" << endmsg;
840 int part, segment, layer, strip, boxId, strId;
841 part = segment = layer = strip = boxId = strId = 0;
844 for(
int i=0; i<
TAGN; i++) {
845 for(
int j=0; j<2; j++) {
846 for(
int k=0; k<
LVLN; k++)
849 if(!m_thsvc->getHist(name, hEff[i][j][k]).isSuccess())
850 log << MSG::ERROR <<
"Fail to retrieve " << name << endreq;
856 for(
int i=0; i<m_effHitCol.size(); i++)
858 part = m_effHitCol[i]->Part();
859 segment = m_effHitCol[i]->Segment();
860 layer = m_effHitCol[i]->Layer();
861 strip = m_effHitCol[i]->Strip();
862 boxId = m_ptrIdTr->
GetBoxId(part, segment, layer);
863 strId = m_ptrIdTr->
GetStripId(part, segment, layer, strip);
864 hEff[0][0][0]->Fill(layer);
865 hEff[0][0][1]->Fill(boxId);
866 hEff[0][0][2]->Fill(strId);
869 hEff[1][0][0]->Fill(layer);
870 hEff[1][0][1]->Fill(boxId);
871 hEff[1][0][2]->Fill(strId);
876 for(
int i=0; i<m_expHitCol.size(); i++)
878 part = m_expHitCol[i]->Part();
879 segment = m_expHitCol[i]->Segment();
880 layer = m_expHitCol[i]->Layer();
881 strip = m_expHitCol[i]->Strip();
883 boxId = m_ptrIdTr->
GetBoxId(part, segment, layer);
884 strId = m_ptrIdTr->
GetStripId(part, segment, layer, strip);
885 hEff[0][1][0]->Fill(layer);
886 hEff[0][1][1]->Fill(boxId);
887 hEff[0][1][2]->Fill(strId);
890 hEff[1][1][0]->Fill(layer);
891 hEff[1][1][1]->Fill(boxId);
892 hEff[1][1][2]->Fill(strId);
897 TH1 *hNosRatio[2][2];
898 for(
int i=0; i<
TAGN; i++) {
899 for(
int j=0; j<2; j++) {
901 if(!m_thsvc->getHist(name, hNosRatio[i][j]).isSuccess())
902 log << MSG::ERROR <<
"Fail to retrieve " << name << endreq;
907 for(
int i=0; i<m_nosHitCol.size(); i++)
909 part = m_nosHitCol[i]->Part();
910 segment = m_nosHitCol[i]->Segment();
911 layer = m_nosHitCol[i]->Layer();
912 strip = m_nosHitCol[i]->Strip();
913 boxId = m_ptrIdTr->
GetBoxId(part, segment, layer);
914 strId = m_ptrIdTr->
GetStripId(part, segment, layer, strip);
915 hNosRatio[0][0]->Fill(boxId);
917 if( isDimu ) hNosRatio[1][0]->Fill(boxId);
921 for(
int i=0; i<m_digiCol.size(); i++)
923 part = m_digiCol[i]->Part();
924 segment = m_digiCol[i]->Segment();
925 layer = m_digiCol[i]->Layer();
926 strip = m_digiCol[i]->Strip();
927 boxId = m_ptrIdTr->
GetBoxId(part, segment, layer);
928 hNosRatio[0][1]->Fill(boxId);
930 if( isDimu ) hNosRatio[1][1]->Fill(boxId);
933 return StatusCode::SUCCESS;
const char ENAME[TAGN][10]
const char LNAME[LVLN][10]
ObjectVector< RecMucTrack > RecMucTrackCol
DQA_MUC(const std::string &name, ISvcLocator *pSvcLocator)
static int barrel_ec(const Identifier &id)
Values of different levels.
static int layer(const Identifier &id)
static int channel(const Identifier &id)
static int segment(const Identifier &id)
int IsInCol(int part, int segment, int layer, int strip, mark_col &aCol)
int Part() const
Get Part.
int Strip() const
Get Strip.
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)
_EXTERN_ std::string EvtRecEvent