00001
00002 #include "FarDetTpSinglesDump.h"
00003
00004 #include "MessageService/MsgService.h"
00005 #include "MinosObjectMap/MomNavigator.h"
00006 #include "JobControl/JobCommand.h"
00007 #include "JobControl/JobCModuleRegistry.h"
00008
00009 #include "RawData/RawDigit.h"
00010 #include "RawData/RawRecord.h"
00011 #include "RawData/RawChannelId.h"
00012 #include "RawData/RawDaqHeaderBlock.h"
00013 #include "RawData/RawTpSinglesSummaryBlock.h"
00014 #include "RawData/RawLiTpmtDigitsBlock.h"
00015
00016 #include "Validity/VldContext.h"
00017 #include "Validity/VldTimeStamp.h"
00018
00019 #include "TDirectory.h"
00020
00021 CVSID("$Id: FarDetTpSinglesDump.cxx,v 1.2 2006/04/21 17:40:11 blake Exp $");
00022
00023 JOBMODULE(FarDetTpSinglesDump,"FarDetTpSinglesDump","FarDetTpSinglesDump");
00024
00025 FarDetTpSinglesDump::FarDetTpSinglesDump() :
00026 fTpSinglesFile(0),
00027 fTpSinglesTree(0),
00028 fMode(0)
00029 {
00030
00031 }
00032
00033 FarDetTpSinglesDump::~FarDetTpSinglesDump()
00034 {
00035
00036 }
00037
00038 void FarDetTpSinglesDump::BeginJob()
00039 {
00040 MSG("FarDetTpSinglesDump",Msg::kInfo) << " *** FarDetTpSinglesDump::BeginJob() *** " << endl;
00041
00042 Int_t i,j;
00043
00044 Int_t tmpPlnMask[16][24]={
00045 { 1, 5, 9, 13, 17, -1,
00046 21, 25, 29, 33, 37, 41,
00047 45, 49, 53, 57, 61, -999,
00048 -1, -1, -1, -1, -1, -1 },
00049 { 45, 49, 53, 57, 61, -999,
00050 21, 25, 29, 33, 37, 41,
00051 1, 5, 9, 13, 17, -1,
00052 -1, -1, -1, -1, -1, -1 },
00053 { 65, 69, 73, 77, 81, -1,
00054 85, 89, 93, 97, 101, 105,
00055 109, 113, 117, 121, 125, -999,
00056 -1, -1, -1, -1, -1, -1 },
00057 { 109, 113, 117, 121, 125, -999,
00058 85, 89, 93, 97, 101, 105,
00059 65, 69, 73, 77, 81, -1,
00060 -1, -1, -1, -1, -1, -1 },
00061 { 129, 133, 137, 141, 145, -1,
00062 149, 153, 157, 161, 165, 169,
00063 173, 177, 181, 185, 189, -999,
00064 -1, -1, -1, -1, -1, -1 },
00065 { 173, 177, 181, 185, 189, -999,
00066 149, 153, 157, 161, 165, 169,
00067 129, 133, 137, 141, 145, -1,
00068 -1, -1, -1, -1, -1, -1 },
00069 { 193, 197, 201, 205, 209, -1,
00070 213, 217, 221, 225, 229, -1,
00071 233, 237, 241, 245, -1, -999,
00072 -1, -1, -1, -1, -1, -1 },
00073 { 233, 237, 241, 245, -1, -999,
00074 213, 217, 221, 225, 229, -1,
00075 193, 197, 201, 205, 209, -1,
00076 -1, -1, -1, -1, -1, -1 },
00077 { 250, 254, 258, 262, 266, -999,
00078 270, 274, 278, 282, 286, 290,
00079 294, 298, 302, 306, 310, -1,
00080 -1, -1, -1, -1, -1, -1 },
00081 { 294, 298, 302, 306, 310, -1,
00082 270, 274, 278, 282, 286, 290,
00083 250, 254, 258, 262, 266, -999,
00084 -1, -1, -1, -1, -1, -1 },
00085 { 314, 318, 322, 326, 330, -1,
00086 334, 338, 342, 346, 350, 354,
00087 358, 362, 366, 370, 374, -999,
00088 -1, -1, -1, -1, -1, -1 },
00089 { 358, 362, 366, 370, 374, -1,
00090 334, 338, 342, 346, 350, 354,
00091 314, 318, 322, 326, 330, -999,
00092 -1, -1, -1, -1, -1, -1 },
00093 { 378, 382, 386, 390, 394, -1,
00094 398, 402, 406, 410, 414, 418,
00095 422, 426, 430, 434, 438, -999,
00096 -1, -1, -1, -1, -1, -1 },
00097 { 422, 426, 430, 434, 438, -1,
00098 398, 402, 406, 410, 414, 418,
00099 378, 382, 386, 390, 394, -999,
00100 -1, -1, -1, -1, -1, -1 },
00101 { 442, 446, 450, 454, 458, -999,
00102 462, 466, 470, 474, 478, 482,
00103 -1, -1, -1, -1, -1, -1,
00104 -1, -1, -1, -1, -1, -1 },
00105 { -1, -1, -1, -1, -1, -1,
00106 462, 466, 470, 474, 478, 482,
00107 442, 446, 450, 454, 458, -999,
00108 -1, -1, -1, -1, -1, -1 },
00109 };
00110
00111 for(i=0;i<16;i++){
00112 for(j=0;j<24;j++){
00113 PlnMask[i][j]=tmpPlnMask[i][j];
00114 }
00115 }
00116
00117 Int_t tmpPlnChMask[22]={
00118 0, 0,
00119 1, 0, 1, 0,
00120 1, 0, 1, 0,
00121 0, 1, 0, 1,
00122 0, 1, 0, 1,
00123 0, 0, 0, 0
00124 };
00125
00126 for(i=0;i<22;i++){
00127 PlnChMask[i]=tmpPlnChMask[i];
00128 }
00129
00130 Int_t tmpVaCh2Shld[16][6]={
00131 { 12,-1,-1,10,11,11 },
00132 { 12,-1,-1,10,11,11 },
00133 { 22,-1,-1,20,21,21 },
00134 { 22,-1,-1,20,21,21 },
00135 { 12,-1,-1,10,11,11 },
00136 { 12,-1,-1,10,11,11 },
00137 { 22,-1,-1,20,21,21 },
00138 { 22,-1,-1,20,21,21 },
00139 { 32,-1,-1,30,31,31 },
00140 { 32,-1,-1,30,31,31 },
00141 { 40,41,41,42,-1,-1 },
00142 { 40,41,41,42,-1,-1 },
00143 { 32,-1,-1,30,31,31 },
00144 { 32,-1,-1,30,31,31 },
00145 { 40,41,41,42,-1,-1 },
00146 { 40,41,41,42,-1,-1 },
00147 };
00148
00149 for(i=0;i<16;i++){
00150 for(j=0;j<6;j++){
00151 VaCh2Shld[i][j]=tmpVaCh2Shld[i][j];
00152 }
00153 }
00154
00155 Int_t tmpVaCh2LiBox[22]={
00156 -1, -1,
00157 14, 1, 7, 8,
00158 4, 10, 13, 3,
00159 11, 5, 2, 12,
00160 0, 6, 9, 15,
00161 -1, -1, -1, -1
00162 };
00163
00164 for(i=0;i<22;i++){
00165 VaCh2LiBox[i]=tmpVaCh2LiBox[i];
00166 }
00167
00168 run=-1; timeframe=-1;
00169 timeframenum=-1; timeframectr=-1;
00170 timeframeTP=-1; timeframeLI=-1;
00171
00172 }
00173
00174 JobCResult FarDetTpSinglesDump::Ana(const MomNavigator *mom)
00175 {
00176 MSG("FarDetTpSinglesDump",Msg::kDebug) << " *** FarDetTpSinglesDump::Ana(...) *** " << endl;
00177
00178 JobCResult result(JobCResult::kPassed);
00179
00180 TIter momitr(mom->FragmentIter());
00181 while(const RawRecord* rawrec = dynamic_cast<const RawRecord*>(momitr())){
00182
00183 MSG("FarDetTpSinglesDump",Msg::kDebug) << " *** NEXT RECORD *** " << endl;
00184
00185 TIter rawrecitr = rawrec->GetRawBlockIter();
00186 TObject *tob;
00187 while((tob = rawrecitr())){
00188 MSG("FarDetTpSinglesDump",Msg::kDebug) << tob->GetName() << endl;
00189
00190 if(tob->InheritsFrom("RawDaqHeaderBlock")){
00191 MSG("FarDetTpSinglesDump",Msg::kDebug) << " ... found RawDaqHeaderBlock " << endl;
00192 RawDaqHeaderBlock* rdb = (RawDaqHeaderBlock*)(tob);
00193 run = rdb->GetRun();
00194 timeframenum = rdb->GetTimeFrameNum();
00195 date = (((VldTimeStamp)(rdb->GetTimeStamp())).GetSec()-1059696000)/(3600*24);
00196 time = (((VldTimeStamp)(rdb->GetTimeStamp())).GetSec()-1059696000)%(3600*24);
00197 MSG("FarDetTpSinglesDump",Msg::kDebug) << " ... timeframe=" << timeframenum << endl;
00198 }
00199
00200 if( timeframenum!=timeframectr ){
00201
00202 if( timeframeTP>=0 ){
00203 if( !fTpSinglesFile ){
00204
00205
00206
00207 TString mystring("fardet.singles.root");
00208 TDirectory* tmpd = gDirectory;
00209 fTpSinglesFile = new TFile(mystring.Data(),"RECREATE");
00210 fTpSinglesTree = new TTree("TpSinglesTree","TpSinglesTree");
00211 fTpSinglesTree->SetAutoSave(100);
00212 fTpSinglesTree->Branch("date",&date,"date/I");
00213 fTpSinglesTree->Branch("time",&time,"time/I");
00214 fTpSinglesTree->Branch("run",&run,"run/I");
00215 fTpSinglesTree->Branch("crate",&crate,"crate/I");
00216 fTpSinglesTree->Branch("varc",&varc,"varc/I");
00217 fTpSinglesTree->Branch("vmm",&vmm,"vmm/I");
00218 fTpSinglesTree->Branch("vaadc",&vaadc,"vaadc/I");
00219 fTpSinglesTree->Branch("vachip",&vachip,"vachip/I");
00220 fTpSinglesTree->Branch("plane",&plane,"plane/I");
00221 fTpSinglesTree->Branch("shld",&shld,"shld/I");
00222 fTpSinglesTree->Branch("timeframe",&timeframe,"timeframe/I");
00223 fTpSinglesTree->Branch("rate",&rate,"rate/I");
00224 fTpSinglesTree->Branch("LI",&LI,"LI/I");
00225 gDirectory = tmpd;
00226 }
00227 for(crate=0;crate<16;crate++){
00228 for(varc=0;varc<3;varc++){
00229 for(vmm=0;vmm<6;vmm++){
00230 for(vaadc=0;vaadc<2;vaadc++){
00231 for(vachip=0;vachip<3;vachip++){
00232 timeframe=timeframeTP;
00233 rate=-1; LI=-1;
00234 plane=-1; shld=-1;
00235 plane=PlnMask[crate][6*varc+vmm]+vaadc;
00236 if(plane<-1) shld=VaCh2Shld[crate][3*vaadc+vachip];
00237 if( plane>0||shld>0 ){
00238 rate=VaMaskSingles[crate][varc][vmm][vaadc][vachip];
00239 LI=VaMaskLI[crate][varc][vmm][vaadc][vachip];
00240 if( fMode==0
00241 || ( fMode==1
00242 && ( ( plane>0 && rate<50 )
00243 || ( plane>0 && LI<0 && rate>2500 )
00244 || ( shld>0 && rate<50 ) ) ) ){
00245 TDirectory* tmpd = gDirectory;
00246 fTpSinglesFile->cd();
00247 fTpSinglesTree->Fill();
00248 gDirectory = tmpd;
00249 }
00250 }
00251 }
00252 }
00253 }
00254 }
00255 }
00256 }
00257
00258 for(crate=0;crate<16;crate++){
00259 for(varc=0;varc<3;varc++){
00260 for(vmm=0;vmm<6;vmm++){
00261 for(vaadc=0;vaadc<2;vaadc++){
00262 for(vachip=0;vachip<3;vachip++){
00263 VaMaskSingles[crate][varc][vmm][vaadc][vachip]=-1;
00264 VaMaskLI[crate][varc][vmm][vaadc][vachip]=-1;
00265 }
00266 }
00267 }
00268 }
00269 }
00270
00271 timeframectr=timeframenum;
00272 }
00273
00274 if(tob->InheritsFrom("RawTpSinglesSummaryBlock")){
00275 MSG("FarDetTpSinglesDump",Msg::kDebug) << " ... found RawTpSinglesSummaryBlock " << endl;
00276 RawTpSinglesSummaryBlock* rdb = (RawTpSinglesSummaryBlock*)(tob);
00277 typedef std::map<RawChannelId,UInt_t> RCIdToRateMap;
00278 const RCIdToRateMap& rates = rdb->GetRates();
00279 RCIdToRateMap::const_iterator rateItr = rates.begin();
00280 RCIdToRateMap::const_iterator rateEnd = rates.end();
00281 while ( rateItr != rateEnd ) {
00282 RawChannelId rawch = rateItr->first;
00283 rate = rateItr->second;
00284 crate = rawch.GetCrate();
00285 varc = rawch.GetVarcId();
00286 vmm = rawch.GetVmm();
00287 vaadc = rawch.GetVaAdcSel();
00288 vachip = rawch.GetVaChip();
00289 if(crate<16 && varc<3 && vmm<6 && vaadc<2 && vachip<3){
00290 VaMaskSingles[crate][varc][vmm][vaadc][vachip]=rate;
00291 }
00292 rateItr++;
00293 }
00294 timeframeTP=timeframenum;
00295 }
00296
00297 if(tob->InheritsFrom("RawLiTpmtDigitsBlock")){
00298 MSG("FarDetTpSinglesDump",Msg::kDebug) << " ... found RawLiTpmtDigitsBlock " << endl;
00299 RawLiTpmtDigitsBlock* rdb = (RawLiTpmtDigitsBlock*)(tob);
00300 Int_t ndigits = rdb->GetNumberOfDigits();
00301 for(Int_t n=0;n<ndigits;n++){
00302 RawDigit* rd = (RawDigit*)(rdb->At(n));
00303 if(rd){
00304 RawChannelId rawch = (RawChannelId)(rd->GetChannel());
00305
00306 crate = rawch.GetCrate();
00307 varc = rawch.GetVarcId();
00308 vmm = rawch.GetVmm();
00309 vaadc = rawch.GetVaAdcSel();
00310 vachip = rawch.GetVaChip();
00311 vachannel = rawch.GetVaChannel();
00312 LI = 2*(VaCh2LiBox[vachannel]/2);
00313
00314 if(LI>=0 && LI<16){
00315 for(crate=LI;crate<=LI+1;crate++){
00316 for(varc=0;varc<3;varc++){
00317 for(vmm=0;vmm<6;vmm++){
00318 for(vaadc=0;vaadc<2;vaadc++){
00319 for(vachip=0;vachip<3;vachip++){
00320 VaMaskLI[crate][varc][vmm][vaadc][vachip]=LI;
00321 }
00322 }
00323 }
00324 }
00325 }
00326 }
00327
00328 }
00329 }
00330 timeframeLI=timeframenum;
00331 }
00332
00333 }
00334 }
00335
00336 MSG("FarDetTpSinglesDump",Msg::kDebug) << " *** FarDetTpSinglesDump::Ana( ) FINISHED *** " << endl;
00337
00338 return result;
00339
00340 }
00341
00342 const Registry& FarDetTpSinglesDump::DefaultConfig() const
00343 {
00344 MSG("FarDetTpSinglesDump",Msg::kInfo) << " *** FarDetTpSinglesDump::DefaultConfig() *** " << endl;
00345
00346 static Registry r;
00347 r.SetName("FarDetTpSinglesDump.config.default");
00348 r.UnLockValues();
00349 r.Set("Mode",fMode);
00350 r.LockValues();
00351
00352 return r;
00353 }
00354
00355 void FarDetTpSinglesDump::Config(const Registry &r){
00356 MSG("FarDetTpSinglesDump",Msg::kInfo) << " *** FarDetTpSinglesDump::Config() *** " << endl;
00357
00358 Int_t tmpint;
00359 if(r.Get("Mode",tmpint)) fMode = tmpint;
00360 MSG("FarDetTpSinglesDump",Msg::kInfo) << " configuration: Mode=" << fMode << endl;
00361
00362 return;
00363 }
00364
00365
00366 void FarDetTpSinglesDump::EndJob()
00367 {
00368 MSG("FarDetTpSinglesDump",Msg::kInfo) << " *** FarDetTpSinglesDump::EndJob() *** " << endl;
00369 if(fTpSinglesFile){
00370 this->PrintRunSummary();
00371 MSG("FarDetTpSinglesDump",Msg::kInfo) << " *** saving data to file *** " << endl;
00372 TDirectory* tmpddd = gDirectory;
00373 fTpSinglesFile->cd();
00374 fTpSinglesTree->Write();
00375 fTpSinglesFile->Close();
00376 gDirectory = tmpddd;
00377 MSG("FarDetTpSinglesDump",Msg::kInfo) << " *** data saved to file *** " << endl;
00378 }
00379 }
00380
00381 void FarDetTpSinglesDump::PrintRunSummary()
00382 {
00383 MSG("FarDetTpSinglesDump",Msg::kInfo) << " *** FarDetTpSinglesDump::PrintRunSummary() *** " << endl;
00384
00385 if(fTpSinglesFile){
00386 fTpSinglesTree->SetBranchAddress("run",&run);
00387 fTpSinglesTree->SetBranchAddress("crate",&crate);
00388 fTpSinglesTree->SetBranchAddress("varc",&varc);
00389 fTpSinglesTree->SetBranchAddress("vmm",&vmm);
00390 fTpSinglesTree->SetBranchAddress("vaadc",&vaadc);
00391 fTpSinglesTree->SetBranchAddress("vachip",&vachip);
00392 fTpSinglesTree->SetBranchAddress("plane",&plane);
00393 fTpSinglesTree->SetBranchAddress("shld",&shld);
00394 fTpSinglesTree->SetBranchAddress("timeframe",&timeframe);
00395 fTpSinglesTree->SetBranchAddress("rate",&rate);
00396 fTpSinglesTree->SetBranchAddress("LI",&LI);
00397
00398 Int_t myrun=-1;
00399 Int_t DeadChipCtr[16][3][6][2][3];
00400
00401 for(crate=0;crate<16;crate++){
00402 for(varc=0;varc<3;varc++){
00403 for(vmm=0;vmm<6;vmm++){
00404 for(vaadc=0;vaadc<2;vaadc++){
00405 for(vachip=0;vachip<3;vachip++){
00406 DeadChipCtr[crate][varc][vmm][vaadc][vachip]=0;
00407 }
00408 }
00409 }
00410 }
00411 }
00412
00413 for(Int_t i=0;i<fTpSinglesTree->GetEntries();i++){
00414 fTpSinglesTree->GetEntry(i);
00415 if( plane>=0 || shld>=0 ){
00416
00417 if( rate<50 ){
00418 DeadChipCtr[crate][varc][vmm][vaadc][vachip]=1;
00419 }
00420
00421 }
00422 if(myrun<0&&run>0) myrun=run;
00423 }
00424
00425 MSG("FarDetTpSinglesDump",Msg::kInfo) << " *** List of Bad Chips ( Run=" << myrun << " ) *** " << endl;
00426 for(crate=0;crate<16;crate++){
00427 for(varc=0;varc<3;varc++){
00428 for(vmm=0;vmm<6;vmm++){
00429 for(vaadc=0;vaadc<2;vaadc++){
00430 for(vachip=0;vachip<3;vachip++){
00431
00432 if( DeadChipCtr[crate][varc][vmm][vaadc][vachip]==1 ){
00433 MSG("FarDetTpSinglesDump",Msg::kInfo) << crate << "-" << varc << "-" << vmm << "-" << vaadc << "-" << vachip << " (dead) " << endl;
00434 }
00435
00436 }
00437 }
00438 }
00439 }
00440 }
00441
00442 }
00443 }