00001 #include "RawDataHistogram.h"
00002 #include "Event/ReadoutHeader.h"
00003 #include "Event/ReadoutPmtCrate.h"
00004 #include "Conventions/Electronics.h"
00005
00006 #include "GaudiKernel/MsgStream.h"
00007 #include "GaudiKernel/IHistogramSvc.h"
00008 #include "GaudiKernel/SmartDataPtr.h"
00009 #include "GaudiKernel/DataObject.h"
00010 #include "GaudiKernel/ITHistSvc.h"
00011
00012 #include <stdint.h>
00013 #include "TH1.h"
00014 #include "TH1F.h"
00015 #include "TH2F.h"
00016 #include "TStyle.h"
00017
00018
00019 using namespace std;
00020 using namespace DayaBay;
00021 TimeStamp last_trig_time;
00022 unsigned long last_fee_time,last_fee_q_time;
00023 int ntick_last,ntick_new;
00024 unsigned long LTB_lastclockNumber;
00025 int ttt = 0;
00026 int charge_sum=0;
00027 uint32_t uTriggerSum= 0;
00028
00029 int iModCnt=0,iFeeCnt=0;
00030
00031 uint32_t fee_QhitPerTrg[MAXMODNUM][MAXCHNNUM];
00032 uint32_t fee_hitPerTrg[MAXMODNUM][MAXCHNNUM];
00033 uint32_t uFee_hitSum[MAXMODNUM][MAXCHNNUM];
00034 float fFee_hitRate[MAXMODNUM][MAXCHNNUM];
00035
00036 RawDataHistogram::RawDataHistogram(const string& name, ISvcLocator* svcloc)
00037 : GaudiAlgorithm(name, svcloc)
00038 , m_log(msgSvc(), name)
00039 {
00040 declareProperty("PrintFreq", m_printFreq=0);
00041 declareProperty("AdcSumMax", m_adcSumMax=1572864);
00042 declareProperty("TimeIntervalMax", m_tIntervalMax=1000);
00043 }
00044
00045 RawDataHistogram::~RawDataHistogram()
00046 {
00047 }
00048
00049 StatusCode RawDataHistogram::initialize()
00050 {
00051 m_log << MSG::DEBUG << "initialize()" << endreq;
00052
00053
00054 StatusCode status;
00055 status = service("THistSvc", m_thistsvc);
00056 if(status.isFailure() ){
00057 m_log << MSG::INFO << "Unable to retrieve pointer to THistSvc" << endreq;
00058 return status;
00059 }
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 string path;
00070 string a,b,c,ped;
00071 string p,r,h,hh,ti,qi;
00072 ostringstream oss1[MAXMODNUM][MAXCHNNUM],oss2[MAXMODNUM][MAXCHNNUM];
00073 for(int iMod=0;iMod<MAXMODNUM;iMod++)
00074 {
00075 if(iMod<5||iMod>17) continue;
00076
00077 for(int iChn=0;iChn<MAXCHNNUM;iChn++)
00078 {
00079 oss1[iMod][iChn]<<setw(2)<<setfill('0')<<iMod;
00080 oss2[iMod][iChn]<<setw(2)<<setfill('0')<<iChn;
00081 a = "h_Time_"+oss1[iMod][iChn].str()+"_"+oss2[iMod][iChn].str();
00082 b = "h_Charge_"+oss1[iMod][iChn].str()+"_"+oss2[iMod][iChn].str() ;
00083 ped = "h_Pedestal_"+oss1[iMod][iChn].str()+"_"+oss2[iMod][iChn].str() ;
00084 p = "h_peakCycle_"+oss1[iMod][iChn].str()+"_"+oss2[iMod][iChn].str();
00085 r = "h_range_"+oss1[iMod][iChn].str()+"_"+oss2[iMod][iChn].str() ;
00086 h = "h_QhitCount_"+oss1[iMod][iChn].str()+"_"+oss2[iMod][iChn].str() ;
00087 hh = "h_hitCount_"+oss1[iMod][iChn].str()+"_"+oss2[iMod][iChn].str() ;
00088 ti = "h_timeInterval_"+oss1[iMod][iChn].str()+"_"+oss2[iMod][iChn].str() ;
00089 qi = "h_qInterval_"+oss1[iMod][iChn].str()+"_"+oss2[iMod][iChn].str() ;
00090 h_Time[iMod][iChn]=new TH1I(a.c_str(),a.c_str() , 2000, 0, 2000);
00091 h_Charge[iMod][iChn]= new TH1I(b.c_str(),b.c_str() ,10000 , 0,81920 );
00092 h_pedestal[iMod][iChn]= new TH1I(ped.c_str(),ped.c_str() ,200 , 0,200 );
00093 h_peakCycle[iMod][iChn]=new TH1I(p.c_str(),p.c_str() , 14, 0, 14);
00094 h_range[iMod][iChn]= new TH1I(r.c_str(),r.c_str() ,2 , 0, 2);
00095 h_QhitCount[iMod][iChn]= new TH1I(h.c_str(),h.c_str() ,20 , 0, 20);
00096 h_hitCount[iMod][iChn]= new TH1I(hh.c_str(),hh.c_str() ,20 , 0, 20);
00097
00098
00099
00100 path="/DQMHist/Raw/";
00101 status = m_thistsvc->regHist((path+a).c_str(), h_Time[iMod][iChn]);
00102 status = m_thistsvc->regHist((path+b).c_str(),h_Charge[iMod][iChn]);
00103 status = m_thistsvc->regHist((path+ped).c_str(),h_pedestal[iMod][iChn]);
00104 status = m_thistsvc->regHist((path+p).c_str(),h_peakCycle[iMod][iChn]);
00105 status = m_thistsvc->regHist((path+r).c_str(),h_range[iMod][iChn]);
00106 status = m_thistsvc->regHist((path+h).c_str(),h_QhitCount[iMod][iChn]);
00107 status = m_thistsvc->regHist((path+hh).c_str(),h_hitCount[iMod][iChn]);
00108
00109
00110
00111 fee_QhitPerTrg[iMod][iChn] = 0;
00112 fee_hitPerTrg[iMod][iChn] = 0;
00113 uFee_hitSum[iMod][iChn] = 0;
00114
00115
00116 }
00117 }
00118
00119
00120
00121
00122
00123
00124 h_sum_triggerType = new TH1I("h_sum_triggerType", "h_triggerType;triggerType", 16, 0, 16);
00126 h_sum_FEEQSUM = new TH1F("h_sum_FEEADCSUM", "h_FEEADCSUM", 1000 , 0, m_adcSumMax);
00127
00128 h_sum_overThrChnPerTrg = new TH1I("h_sum_overThrChnPerTrg", "h_overThrChnPerTrg;overThrChnNum", MAXMODNUM*MAXCHNNUM , 0, MAXMODNUM*MAXCHNNUM);
00129 h_sum_hitRate = new TH1F("h_sum_hitRate", "h_hitRate;channelIndex;hit_rate", MAXMODNUM*MAXCHNNUM , 0.5, MAXMODNUM*MAXCHNNUM+0.5);
00130 h_tmp_hitRate = new TH1F("h_tmp_hitRate", "h_hitRate;channelIndex;hit_rate", MAXMODNUM*MAXCHNNUM , 0.5, MAXMODNUM*MAXCHNNUM+0.5);
00131 h_sum_ADCMean = new TH1F("h_sum_ADCMean", "h_ADCMean;channelIndex", MAXMODNUM*MAXCHNNUM , 0.5, MAXMODNUM*MAXCHNNUM+0.5);
00132 h_sum_ADC_Channel= new TH2F("h_sum_ADC_Channel", "h_ADC;Board*16+Channel", MAXMODNUM*MAXCHNNUM , 0.5, MAXMODNUM*MAXCHNNUM+0.5, 10000, 0, 81920);
00133
00134 h_sum_TDCMean = new TH1F("h_sum_TDCMean", "h_TDCMean;channelIndex", MAXMODNUM*MAXCHNNUM , 0.5, MAXMODNUM*MAXCHNNUM+0.5);
00135
00136 h_sum_TDC_Channel= new TH2F("h_sum_TDC_Channel", "h_TDC;Board*16+Channel", MAXMODNUM*MAXCHNNUM , 0.5, MAXMODNUM*MAXCHNNUM+0.5, 2000, 0, 2000);
00137 h_sum_pedestalMean = new TH1F("h_sum_pedestalMean", "h_pedestalMean;channelIndex", MAXMODNUM*MAXCHNNUM , 0.5, MAXMODNUM*MAXCHNNUM+0.5);
00138 h_sum_pedestalRMS = new TH1F("h_sum_pedestalRMS", "h_pedestalRMS;channelIndex", MAXMODNUM*MAXCHNNUM , 0.5, MAXMODNUM*MAXCHNNUM+0.5);
00139
00140
00141
00142
00143
00144
00145
00146 status = m_thistsvc->regHist("/DQMHist/Raw/h_sum_triggerType",h_sum_triggerType );
00147 status = m_thistsvc->regHist("/DQMHist/Raw/h_sum_FEEADCSUM",h_sum_FEEQSUM);
00148 status = m_thistsvc->regHist("/DQMHist/Raw/h_sum_overThrChnPerTrg",h_sum_overThrChnPerTrg);
00149 status = m_thistsvc->regHist("/DQMHist/Raw/h_sum_hitRate",h_sum_hitRate);
00150 status = m_thistsvc->regHist("/DQMHist/Raw/h_tmp_hitRate",h_tmp_hitRate);
00151 status = m_thistsvc->regHist("/DQMHist/Raw/h_sum_ADCMean",h_sum_ADCMean);
00152
00153 status = m_thistsvc->regHist("/DQMHist/Raw/h_sum_ADC_Channel",h_sum_ADC_Channel);
00154 status = m_thistsvc->regHist("/DQMHist/Raw/h_sum_TDCMean",h_sum_TDCMean);
00155
00156 status = m_thistsvc->regHist("/DQMHist/Raw/h_sum_TDC_Channel",h_sum_TDC_Channel);
00157 status = m_thistsvc->regHist("/DQMHist/Raw/h_sum_pedestalMean",h_sum_pedestalMean);
00158 status = m_thistsvc->regHist("/DQMHist/Raw/h_sum_pedestalRMS",h_sum_pedestalRMS);
00159
00160 if(status.isFailure() ){
00161 m_log << MSG::INFO << "Unable to regist histograms" << endreq;
00162 return status;
00163 }
00164 return StatusCode::SUCCESS;
00165 }
00166
00167 StatusCode RawDataHistogram::execute()
00168 {
00169 uint32_t fee_QSUM = 0;
00170 uint32_t uFeeOverThrCh=0;
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232 m_log << MSG::DEBUG << "execute() ______________________________ start" << endreq;
00233 if(m_printFreq>0 && uTriggerSum%m_printFreq==0) {
00234 m_log << MSG::INFO << "------------- " << uTriggerSum << endreq;
00235 }
00236
00237 ReadoutHeader* roh = get<ReadoutHeader>("/Event/Readout/ReadoutHeader");
00238 if (roh == 0) {
00239 m_log << MSG::ERROR << " =======> Requested Object can not be accessable." << endreq;
00240 return StatusCode::FAILURE;
00241 }
00242
00243 m_log << MSG::DEBUG << "Readout: " << (Readout)(*(roh->readout())) << endreq;
00244
00245 Readout* readout = const_cast<Readout*>(roh->readout());
00246 ReadoutPmtCrate* crate = dynamic_cast<ReadoutPmtCrate*>(readout);
00247 ReadoutPmtCrate::PmtChannelReadouts channels = crate->channelReadout();
00248 m_log << MSG::DEBUG << "#channels=" << crate->channelReadout().size() << endreq;
00249 ReadoutPmtCrate::PmtChannelReadouts::iterator it;
00250 for (it=channels.begin(); it != channels.end(); it++) {
00251 m_log << MSG::DEBUG << it->first << " => " << it->second << endreq;
00252
00253
00254
00255
00256 iFeeCnt=it->second.channelId().board();
00257 uint32_t channelID=it->second.channelId().connector()-1;
00258 int localId= iFeeCnt*16+channelID;
00259 uint32_t fee_charge;
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269 unsigned long fee_time;
00270 uint32_t fee_HitCount;
00271 uint32_t fee_PeakCycle;
00272
00273
00274 for(int i=0;i<it->second.size();i++){
00275 fee_charge=it->second.adc(i);
00276 fee_time=it->second.tdc(i);
00277 fee_hitPerTrg[iFeeCnt][channelID]++;
00278
00279
00280
00281
00282
00283 h_Time[iFeeCnt][channelID]->Fill(fee_time);
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303 if(it->second.peakAdcRange(i)==FeeGain::kLow) {
00304 fee_charge = (it->second.adc(i)-it->second.pedestal(i))*20;
00305 } else {
00306 fee_charge = it->second.adc(i)-it->second.pedestal(i);
00307 }
00308
00309
00310 fee_QSUM = fee_QSUM + fee_charge;
00311
00312 fee_PeakCycle =0;
00313 h_Charge[iFeeCnt][channelID]->Fill(fee_charge);
00314 h_pedestal[iFeeCnt][channelID]->Fill(it->second.pedestal(i));
00315 h_sum_ADC_Channel->Fill(localId,fee_charge);
00316 h_sum_TDC_Channel->Fill(localId,fee_time);
00317
00318 if(fee_charge>0)
00319
00320 {
00321 if(fee_charge>0)fee_QhitPerTrg[iFeeCnt][channelID]++;
00322 if(1==fee_QhitPerTrg[iFeeCnt][channelID])
00323 {
00324 uFeeOverThrCh++;
00325 uFee_hitSum[iFeeCnt][channelID]++;
00326 }
00327
00328
00329 h_range[iFeeCnt][channelID]->Fill(it->second.peakAdcRange(i));
00330 h_peakCycle[iFeeCnt][channelID]->Fill(fee_PeakCycle);
00331 }
00332 }
00333
00334
00335
00336
00337
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371 }
00372 for(int iFee=0;iFee < MAXMODNUM;iFee++) {
00373 if(iFee<5||iFee>17) continue;
00374 for(int ic=0;ic<MAXCHNNUM;ic++)
00375 {
00376
00377 h_QhitCount[iFee][ic]->Fill(fee_QhitPerTrg[iFee][ic]);
00378 h_hitCount[iFee][ic]->Fill(fee_hitPerTrg[iFee][ic]);
00379 fee_QhitPerTrg[iFee][ic]=0;
00380 fee_hitPerTrg[iFee][ic]=0;
00381 }
00382 }
00383 TimeStamp trig_time=readout->triggerTime();
00384 if(uTriggerSum>=2){trig_time.Subtract(last_trig_time);}
00385
00386 int trigType = daqTrigType(readout->triggerType());
00387 for(unsigned i=0; i<16; i++) {
00388 if(trigType & 1<<i) {
00389 h_sum_triggerType->Fill(i);
00390 }
00391 }
00392
00393 h_sum_FEEQSUM->Fill(fee_QSUM);
00394 h_sum_overThrChnPerTrg->Fill(uFeeOverThrCh);
00395 last_trig_time=readout->triggerTime();
00396 uTriggerSum++;
00397
00398 m_log << MSG::DEBUG << "execute() ______________________________ end" << endreq;
00399 return StatusCode::SUCCESS;
00400 }
00401
00402 StatusCode RawDataHistogram::finalize()
00403 {
00404 m_log << MSG::DEBUG << "finalize()" << endreq;
00405 m_log << MSG::INFO << "Total events in this file: " << uTriggerSum << endreq;
00406 h_tmp_hitRate->SetBinContent(0,uTriggerSum);
00407 h_sum_ADCMean->SetBinContent(0,iFeeCnt);
00408
00409 for(int iFee=0;iFee < MAXMODNUM;iFee++)
00410 {
00411 if(iFee<5||iFee>17) continue;
00412
00413 for(int iChn=0;iChn<MAXCHNNUM;iChn++)
00414 {
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00434
00436 h_tmp_hitRate->SetBinContent(iChn+1+iFee*MAXCHNNUM,uFee_hitSum[iFee][iChn]);
00439 }
00440 }
00441
00442
00443 return StatusCode::SUCCESS;
00444 }
00445
00446 int RawDataHistogram::daqTrigType(int offTrigType)
00447 {
00448 int trigType = 0;
00449 if(offTrigType & DayaBay::Trigger::kMult) {
00450 trigType = trigType | (1<<8);
00451 } else if(offTrigType & DayaBay::Trigger::kExternal) {
00452 trigType = trigType | (1<<1);
00453 } else if(offTrigType & DayaBay::Trigger::kManual) {
00454 trigType = trigType | (1<<0);
00455 } else if(offTrigType & DayaBay::Trigger::kPeriodic) {
00456 trigType = trigType | (1<<2);
00457 } else if(offTrigType & DayaBay::Trigger::kESumAll) {
00458 trigType = trigType | (1<<12);
00459 } else if(offTrigType & DayaBay::Trigger::kESumHigh) {
00460 trigType = trigType | (1<<10);
00461 } else if(offTrigType & DayaBay::Trigger::kESumLow) {
00462 trigType = trigType | (1<<11);
00463 } else if(offTrigType & DayaBay::Trigger::kESumADC) {
00464 trigType = trigType | (1<<9);
00465 }
00466 return trigType;
00467 }