00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012 #include "TObject.h"
00013 #include "TH1F.h"
00014 #include "TFile.h"
00015 #include "TProfile.h"
00016 #include "TGraph.h"
00017
00018 #include "MessageService/MsgService.h"
00019 #include "MinosObjectMap/MomNavigator.h"
00020 #include "JobControl/JobCModuleRegistry.h"
00021
00022 #include "RawData/RawRecord.h"
00023 #include "RawData/RawDaqSnarlHeader.h"
00024 #include "RawData/RawDigitDataBlock.h"
00025 #include "RawData/RawDeadChipBlock.h"
00026 #include "RawData/RawDigit.h"
00027 #include "Validity/VldContext.h"
00028
00029 #include "CalDetTracker/CDAnaModule.h"
00030
00031 CVSID("$Id: CDAnaModule.cxx,v 1.5 2005/08/28 01:41:37 rhatcher Exp $");
00032
00033 JOBMODULE(CDAnaModule,"CDAnaModule","Bla");
00034
00035
00036
00037 CDAnaModule::CDAnaModule()
00038 {
00039 fSnarl=-1;
00040 fRun=-1;
00041 fSubrun=-1;
00042 fSec=-1;
00043 fDetector=Detector::kUnknown;
00044
00045 fPrevEvT=-2;
00046 fPrevEvT1=-2;
00047 fPrevEvT2=-2;
00048 fNextEvT=-1;
00049 fNextEvT1=-1;
00050 fNextEvT2=-1;
00051 fT=-1;
00052 fT1=-1;
00053 fT2=-1;
00054
00055 smallestT1=1e10;
00056 largestT2=0;
00057
00058 string sFileName="cdTiming.root";
00059 fOutFile=new TFile(sFileName.c_str(),"RECREATE");
00060
00061 htEarliest=new TH1F("htEarliest","htEarliest",4000,0,1e9);
00062 htEarliest->GetXaxis()->SetTitle("Time in second");
00063 htEarliest->GetXaxis()->CenterTitle();
00064 htEarliest->GetYaxis()->SetTitle("");
00065 htEarliest->GetYaxis()->CenterTitle();
00066 htEarliest->SetFillColor(0);
00067
00068
00069 htEarliestScint=new TH1F("htEarliestScint","htEarliestScint",
00070 4000,0,1e9);
00071 htEarliestScint->GetXaxis()->SetTitle("Time in second (VA scint)");
00072 htEarliestScint->GetXaxis()->CenterTitle();
00073 htEarliestScint->GetYaxis()->SetTitle("");
00074 htEarliestScint->GetYaxis()->CenterTitle();
00075 htEarliestScint->SetFillColor(0);
00076
00077
00078 htLatest=new TH1F("htLatest","htLatest",4000,0,1e9);
00079 htLatest->GetXaxis()->SetTitle("Time in second");
00080 htLatest->GetXaxis()->CenterTitle();
00081 htLatest->GetYaxis()->SetTitle("");
00082 htLatest->GetYaxis()->CenterTitle();
00083 htLatest->SetFillColor(0);
00084
00085
00086 htLatestScint=new TH1F("htLatestScint","htLatestScint",
00087 4000,0,1e9);
00088 htLatestScint->GetXaxis()->SetTitle("Time in second (VA scint)");
00089 htLatestScint->GetXaxis()->CenterTitle();
00090 htLatestScint->GetYaxis()->SetTitle("");
00091 htLatestScint->GetYaxis()->CenterTitle();
00092 htLatestScint->SetFillColor(0);
00093
00094
00095 hdt=new TH1F("hdt","hdt",1000,0,1e9);
00096 hdt->GetXaxis()->SetTitle("dt (ns)");
00097 hdt->GetXaxis()->CenterTitle();
00098 hdt->GetYaxis()->SetTitle("");
00099 hdt->GetYaxis()->CenterTitle();
00100 hdt->SetFillColor(0);
00101
00102
00103 hdtZoom=new TH1F("hdtZoom","hdtZoom",200,0,200000);
00104 hdtZoom->GetXaxis()->SetTitle("dt (ns)");
00105 hdtZoom->GetXaxis()->CenterTitle();
00106 hdtZoom->GetYaxis()->SetTitle("");
00107 hdtZoom->GetYaxis()->CenterTitle();
00108 hdtZoom->SetFillColor(0);
00109
00110
00111 hdtDeadChips=new TH1F("hdtDeadChips","hdtDeadChips",
00112 200,0,200000);
00113 hdtDeadChips->GetXaxis()->SetTitle("dt (ns)");
00114 hdtDeadChips->GetXaxis()->CenterTitle();
00115 hdtDeadChips->GetYaxis()->SetTitle("");
00116 hdtDeadChips->GetYaxis()->CenterTitle();
00117 hdtDeadChips->SetFillColor(0);
00118 hdtDeadChips->SetLineColor(2);
00119
00120 pTimeVsdt=new TProfile("pTimeVsdt","pTimeVsdt",
00121 20000,0,800000);
00122 pTimeVsdt->GetXaxis()->SetTitle("dt (ns)");
00123 pTimeVsdt->GetXaxis()->CenterTitle();
00124 pTimeVsdt->GetYaxis()->SetTitle("Time in second");
00125 pTimeVsdt->GetYaxis()->CenterTitle();
00126
00127
00128
00129
00130 gTimeVsdt=new TGraph(200);
00131 gTimeVsdt->SetName("gTimeVsdt");
00132 gTimeVsdt->SetTitle("Time in second vs delta T (all in ns)");
00133
00134
00135
00136
00137
00138 gTimeVsdt->SetMarkerColor(2);
00139 gTimeVsdt->SetMarkerStyle(8);
00140
00141 gAdcVsTime=new TGraph(200);
00142 gAdcVsTime->SetName("gAdcVsTime");
00143 gAdcVsTime->SetTitle("ADC vs Time");
00144
00145
00146
00147
00148
00149 gAdcVsTime->SetMarkerColor(2);
00150 gAdcVsTime->SetMarkerStyle(8);
00151
00152 gAdcVsTimeZoom=new TGraph(10);
00153 gAdcVsTimeZoom->SetName("gAdcVsTimeZoom");
00154 gAdcVsTimeZoom->SetTitle("ADC vs Time (zoom)");
00155
00156
00157
00158
00159
00160 gAdcVsTimeZoom->SetMarkerColor(2);
00161 gAdcVsTimeZoom->SetMarkerStyle(8);
00162
00163 gTtagTime=new TGraph(1);
00164 gTtagTime->SetName("gTtagTime");
00165 gTtagTime->SetTitle("TTag time(s)");
00166
00167
00168
00169
00170
00171 gTtagTime->SetMarkerColor(4);
00172 gTtagTime->SetMarkerStyle(8);
00173
00174 gTtagTimeZoom=new TGraph(1);
00175 gTtagTimeZoom->SetName("gTtagTimeZoom");
00176 gTtagTimeZoom->SetTitle("TTag time(s)");
00177
00178
00179
00180
00181
00182 gTtagTimeZoom->SetMarkerColor(4);
00183 gTtagTimeZoom->SetMarkerStyle(8);
00184 }
00185
00186
00187
00188 CDAnaModule::~CDAnaModule()
00189 {
00190 if (fOutFile){
00191 gTimeVsdt->Write();
00192 gAdcVsTime->Write();
00193 gAdcVsTimeZoom->Write();
00194 gTtagTime->Write();
00195 gTtagTimeZoom->Write();
00196 fOutFile->cd();
00197 fOutFile->Write();
00198 fOutFile->Close();
00199 }
00200 }
00201
00202
00203
00204 JobCResult CDAnaModule::Ana(const MomNavigator *mom)
00205 {
00206 JobCResult result(JobCResult::kPassed);
00207
00208 RawRecord *rr=dynamic_cast<RawRecord *>
00209 (mom->GetFragment("RawRecord"));
00210 if (rr==0) {
00211 MSG("CDTrackerModule", Msg::kWarning)
00212 <<"No RawRecord in MOM." << endl;
00213 result.SetFailed();
00214 return result;
00215 }
00216
00217 const RawDaqSnarlHeader* snarlHdr =
00218 dynamic_cast<const RawDaqSnarlHeader*>(rr->GetRawHeader());
00219 if(snarlHdr){
00220 fSnarl=snarlHdr->GetSnarl();
00221 fRun=snarlHdr->GetRun();
00222 fSubrun=snarlHdr->GetSubRun();
00223 fSec=snarlHdr->GetVldContext().GetTimeStamp().GetSec();
00224 fDetector=snarlHdr->GetVldContext().GetDetector();
00225 }
00226 else{
00227 MSG("CDTrackerModule", Msg::kWarning)
00228 <<"No RawDaqSnarlHeader in MOM."<<endl;
00229 result.SetFailed();
00230 return result;
00231 }
00232
00233 const RawDeadChipBlock* deadblock=
00234 dynamic_cast<const RawDeadChipBlock*>
00235 (rr->FindRawBlock("RawDeadChipBlock"));
00236 Int_t numDeadChips=-1;
00237 if(deadblock) {
00238 numDeadChips=deadblock->GetNumberOfEntries();
00239 }
00240
00241 const RawDigitDataBlock *rddb=dynamic_cast<const RawDigitDataBlock *>
00242 (rr->FindRawBlock("RawDigitDataBlock"));
00243
00244 Double_t earliestT=1e10;
00245 Double_t latestT=0;
00246 Double_t earliestScintT=1e10;
00247 Double_t latestScintT=0;
00248
00249
00250 Double_t secsPerVaTick=25/16.;
00251 Double_t secsPerQieTick=1000./53.1;
00252
00253
00254 if (fDetector==Detector::kCalDet){
00255 secsPerQieTick=1.5625*16.0*58.0/77.0;
00256 }
00257
00258 MAXMSG("CDTrackerModule", Msg::kVerbose,1000)
00259 <<"secsPerVaTick="<<secsPerVaTick<<endl;
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273 Int_t second=1063522292;
00274
00275 Bool_t skipSeconds=false;
00276 if (skipSeconds){
00277 if (fSec<second){
00278 MAXMSG("CDTrackerModule",Msg::kInfo,1)
00279 <<endl<<"Skipping seconds to get to second="<<second
00280 <<"..."<<endl;
00281 return result;
00282 }
00283 if (fSec>second) {
00284 MAXMSG("CDTrackerModule",Msg::kInfo,1)
00285 <<endl<<"Not looking at any more seconds beyond second="<<second
00286 <<"..."<<endl;
00287 return result;
00288 }
00289 }
00290
00291 Int_t lemoCounter=0;
00292 vector<Double_t> lemoTimes(6,-1);
00293 Double_t ttagTime=-1;
00294 Int_t ttagAdc=-1;
00295 Double_t dtLemoTtag=-1;
00296 Double_t dtLemoTtagMin=1e9;
00297 static Bool_t foundQie=false;
00298
00299
00300 if (rddb) {
00301 TIter it=rddb->GetDatumIter();
00302 while (TObject *obj=it.Next()) {
00303 RawDigit* rvd=dynamic_cast<RawDigit*>(obj);
00304 if (rvd) {
00305
00306
00307 RawChannelId timingFid(Detector::kCalDet,ElecType::kVA,
00308 0,2,5,1,2,16);
00309 if (timingFid.IsSameChannel(rvd->GetChannel())) continue;
00310
00311
00312 Double_t time=(rvd->GetTDC())*secsPerVaTick;
00313 if (rvd->GetChannel().GetElecType()==ElecType::kQIE){
00314 foundQie=true;
00315 time=(rvd->GetTDC())*secsPerQieTick;
00316 string sTime=Form("%.1f",time);
00317 MAXMSG("CDTrackerModule", Msg::kInfo,100)
00318 <<"TDC="<<rvd->GetTDC()
00319 <<", time="<<sTime
00320 <<", ADC="<<rvd->GetADC()
00321 <<", chan="<<rvd->GetChannel().GetVaChannel()
00322 <<endl;
00323 }
00324
00325 Int_t adc=rvd->GetADC();
00326 if (rvd->GetChannel().GetVmm()==6){
00327 Int_t lemoVarc=rvd->GetChannel().GetVarcId();
00328 Int_t lemoCrate=rvd->GetChannel().GetCrate();
00329 Int_t lemoIndex=lemoCrate*3+lemoVarc;
00330 string sTime=Form("%.1f",time);
00331 MAXMSG("CDTrackerModule", Msg::kInfo,100)
00332 <<"TDC="<<rvd->GetTDC()
00333 <<", time="<<sTime
00334 <<", ADC="<<rvd->GetADC()
00335 <<", chan="<<rvd->GetChannel().GetVaChannel()
00336 <<", crate="<<lemoCrate
00337 <<", varc="<<lemoVarc
00338 <<", index="<<lemoIndex
00339 <<endl;
00340 lemoCounter++;
00341
00342
00343 Double_t dt=time-ttagTime;
00344 if (dt>dtLemoTtag) dtLemoTtag=dt;
00345 if (dt<dtLemoTtagMin) dtLemoTtagMin=dt;
00346
00347 if (lemoIndex<6){
00348 lemoTimes[lemoIndex]=time;
00349 }
00350 else cout<<"ahhhhh strange lemo..."<<endl;
00351 }
00352 else if (rvd->GetChannel().GetVmm()==5){
00353 RawChannelId ttag(Detector::kCalDet,ElecType::kVA,
00354 0,2,5,1,1,16);
00355 if (ttag.IsSameChannel(rvd->GetChannel())){
00356 ttagTime=time;
00357 ttagAdc=adc;
00358 string sTime=Form("%.1f",time);
00359 MAXMSG("CDTrackerModule", Msg::kInfo,20)
00360 <<"Found ttag, time="<<sTime<<", adc="<<ttagAdc<<endl;
00361 static Int_t tti=0;
00362 gTtagTime->SetPoint(tti,time,adc);
00363 tti++;
00364 }
00365 }
00366
00367
00368 if (time>latestT) latestT=time;
00369 if (time<earliestT) earliestT=time;
00370 if (rvd->GetChannel().GetVmm()<5){
00371 if (time>latestScintT) latestScintT=time;
00372 if (time<earliestScintT) earliestScintT=time;
00373 }
00374
00375
00376 if (fSec==second){
00377 static Int_t i=0;
00378 gAdcVsTime->SetPoint(i,time,rvd->GetADC());
00379 i++;
00380
00381
00382 Double_t timeInSec=78137900;
00383 Double_t gate=70e3;
00384
00385 if (time>timeInSec-gate && time<timeInSec+gate){
00386 static Int_t i2=0;
00387 gAdcVsTimeZoom->SetPoint(i2,time,rvd->GetADC());
00388 i2++;
00389 string sTime=Form("%.1f",time);
00390 MAXMSG("CDTrackerModule", Msg::kInfo,1000)
00391 <<"Sec="<<fSec<<", TDC="<<rvd->GetTDC()
00392 <<", time="<<sTime
00393 <<", ADC="<<rvd->GetADC()
00394 <<", vmm="<<rvd->GetChannel().GetVmm()
00395 <<","<<rvd->GetChannel().GetVaAdcSel()
00396 <<","<<rvd->GetChannel().GetVaChip()
00397 <<","<<rvd->GetChannel().GetVaChannel()
00398 <<endl;
00399
00400
00401 if (rvd->GetChannel().GetVmm()==5){
00402 RawChannelId ttag(Detector::kCalDet,ElecType::kVA,
00403 0,2,5,1,1,16);
00404 if (ttag.IsSameChannel(rvd->GetChannel())){
00405 static Int_t tti=0;
00406 gTtagTimeZoom->SetPoint(tti,time,adc);
00407 tti++;
00408 }
00409 }
00410 }
00411 else{
00412 MAXMSG("CDTrackerModule", Msg::kVerbose,1000)
00413 <<"Not in gate: sec="<<fSec<<", TDC="<<rvd->GetTDC()
00414 <<", time="<<time
00415 <<", ADC="<<rvd->GetADC()<<endl;
00416 }
00417 }
00418 else if (fSnarl==18926){
00419 string sTime=Form("%.1f",time);
00420 MAXMSG("CDTrackerModule", Msg::kInfo,1000)
00421 <<"snl="<<fSnarl<<", Sec="<<fSec<<", TDC="<<rvd->GetTDC()
00422 <<", time="<<sTime
00423 <<", ADC="<<rvd->GetADC()<<endl;
00424 }
00425 }
00426 }
00427 }
00428 else{
00429 MSG("CDTrackerModule", Msg::kWarning)
00430 <<"No RawDigitDataBlock"<<endl;
00431 result.SetFailed();
00432 return result;
00433 }
00434
00435 if ((lemoCounter!=6 && !foundQie) || (lemoCounter!=3 && foundQie)){
00436 string sTimeEarliest=Form("%.1f",earliestT);
00437 string sTimeLatest=Form("%.1f",latestT);
00438 MAXMSG("CDTrackerModule", Msg::kInfo,1000)
00439 <<"snarl="<<fSnarl<<", sec="<<fSec
00440 <<", lemoCount="<<lemoCounter
00441 <<", rddbNum="<<rddb->GetNumberOfDigits()
00442 <<", time=("<<sTimeEarliest<<" -> "<<sTimeLatest<<")"<<endl;
00443 }
00444
00445 MAXMSG("CDTrackerModule", Msg::kInfo,10)
00446 <<"snarl="<<fSnarl<<", sec="<<fSec<<" Lemodt="<<dtLemoTtag
00447 <<", lemo="<<lemoCounter
00448 <<", #rddb="<<rddb->GetNumberOfDigits()
00449 <<", t=("<<earliestT<<" -> "<<latestT<<")"<<endl;
00450
00451 if ((dtLemoTtag>150 || dtLemoTtagMin<5) && ttagTime>0){
00452 string sTimeEarliest=Form("%.1f",earliestT);
00453 string sTimeLatest=Form("%.1f",latestT);
00454 string sTimeTtag=Form("%.1f",ttagTime);
00455 string sdtLemoTtag=Form("%.1f",dtLemoTtag);
00456 string sdtLemoTtagMin=Form("%.1f",dtLemoTtagMin);
00457
00458 MAXMSG("CDTrackerModule", Msg::kInfo,100)
00459 <<"** snl="<<fSnarl
00460 <<" Ldt="<<sdtLemoTtag
00461 <<"->"<<sdtLemoTtagMin
00462 <<", #L="<<lemoCounter
00463 <<", #d="<<rddb->GetNumberOfDigits()<<endl
00464 <<" ttagTime="<<sTimeTtag
00465 <<", t=("<<sTimeEarliest<<" -> "<<sTimeLatest<<")"<<endl;
00466 }
00467
00468
00469 fNextEvT1=earliestT;
00470 fNextEvT2=latestT;
00471 fNextEvT=fSec;
00472
00473 string sPrevEvT1=Form("%.1f",fPrevEvT1);
00474 string sPrevEvT2=Form("%.1f",fPrevEvT2);
00475 string sT1=Form("%.1f",fT1);
00476 string sT2=Form("%.1f",fT2);
00477 string sNextEvT1=Form("%.1f",fNextEvT1);
00478 string sNextEvT2=Form("%.1f",fNextEvT2);
00479
00480
00481 Double_t pre_dt=fT1-fPrevEvT2;
00482 Double_t post_dt=fNextEvT1-fT2;
00483 string sPre_dt=Form("%.3f",(pre_dt/1000.));
00484 if (fT!=fPrevEvT) {
00485 pre_dt=1e9;
00486 sPre_dt="wrap around";
00487 }
00488 string sPost_dt=Form("%.3f",(post_dt/1000));
00489 if (fT!=fNextEvT) {
00490 post_dt=1e9;
00491 sPost_dt="wrap around";
00492 }
00493
00494
00495 htEarliest->Fill(earliestT);
00496 htLatest->Fill(latestT);
00497 htEarliestScint->Fill(earliestScintT);
00498 htLatestScint->Fill(latestScintT);
00499 hdt->Fill(post_dt);
00500 hdtZoom->Fill(post_dt);
00501
00502 if (numDeadChips>0){
00503 hdtDeadChips->Fill(post_dt);
00504 pTimeVsdt->Fill(post_dt,earliestT);
00505 if (gTimeVsdt){
00506 static Int_t i=1;
00507 gTimeVsdt->SetPoint(i,post_dt,earliestT);
00508 i++;
00509 }
00510 else cout<<"ahhhh"<<endl;
00511
00512 if (post_dt>10e6 && post_dt<1e9){
00513 MAXMSG("CDTrackerModule", Msg::kInfo,100)
00514 <<endl
00515 <<"Large dt: snarl="<<fSnarl-1<<", sec="<<fSec
00516 <<", numDeadChips="<<numDeadChips<<endl
00517 <<"Previous time=("<<sPrevEvT1<<" -> "<<sPrevEvT2<<")"<<endl
00518 <<" dt="<<sPre_dt<<" us"<<endl
00519 <<"This one time=("<<sT1<<" -> "<<sT2<<")"<<endl
00520 <<" dt="<<sPost_dt<<" us"<<endl
00521 <<"Next time=("<<sNextEvT1<<" -> "<<sNextEvT2<<")"<<endl
00522 <<endl;
00523 }
00524 }
00525
00526 if (post_dt<49000){
00527 MAXMSG("CDTrackerModule", Msg::kInfo,100)
00528 <<endl
00529 <<"Snarl="<<fSnarl-1<<", sec="<<fSec
00530 <<", numDeadChips="<<numDeadChips<<endl
00531 <<"Previous time=("<<sPrevEvT1<<" -> "<<sPrevEvT2<<")"<<endl
00532 <<" dt="<<sPre_dt<<" us"<<endl
00533 <<"This one time=("<<sT1<<" -> "<<sT2<<")"<<endl
00534 <<" dt="<<sPost_dt<<" us"<<endl
00535 <<"Next time=("<<sNextEvT1<<" -> "<<sNextEvT2<<")"<<endl
00536 <<endl;
00537 }
00538
00539
00540 fPrevEvT1=fT1;
00541 fPrevEvT2=fT2;
00542 fPrevEvT=fT;
00543 fT1=earliestT;
00544 fT2=latestT;
00545 fT=fSec;
00546
00547
00548 if (earliestT<smallestT1) smallestT1=earliestT;
00549 if (latestT>largestT2) largestT2=latestT;
00550
00551
00552 return result;
00553 }
00554
00555
00556
00557 void CDAnaModule::EndJob()
00558 {
00559 string sLower_dt=Form("%.3f",(smallestT1/1000.));
00560 string sUpper_dt=Form("%.3f",((1e9-largestT2)/1000.));
00561
00562 MSG("CDTrackerModule", Msg::kInfo)
00563 <<"Times closest to timeframe boundaries in run "<<fRun<<endl
00564 <<" Lower time: "<<smallestT1<<" (dt="<<sLower_dt<<" us)"<<endl
00565 <<" Upper time: "<<largestT2<<" (dt="<<sUpper_dt<<" us)"
00566 <<endl;
00567 }
00568
00569