00001 #include "CheckTMEs.h"
00002 #include "RegisterModule.inc"
00003 #include "TGlobalData.h"
00004 #include "TSetupData.h"
00005 #include "ModulesOptions.h"
00006 #include "definitions.h"
00007 #include "TMuonEvent.h"
00008 #include "debug_tools.h"
00009
00010 #include <TH1F.h>
00011 #include <TH2F.h>
00012
00013 #include <iostream>
00014 using std::cout;
00015 using std::endl;
00016
00017 extern MuonEventList gMuonEvents;
00018
00019 CheckTMEs::CheckTMEs(modules::options* opts):
00020 BaseModule("CheckTMEs",opts),fNullCount(0),fTdpCount(0){
00021 }
00022
00023 CheckTMEs::~CheckTMEs(){
00024 }
00025
00026 int CheckTMEs::BeforeFirstEntry(TGlobalData* gData,const TSetupData *setup){
00027 using namespace IDs;
00028 fDetectors.push_back(IDs::channel (kGe , kNotApplicable ));
00029 fDetectors.push_back(IDs::channel (kScR , kNotApplicable ));
00030 fDetectors.push_back(IDs::channel (kScL , kNotApplicable ));
00031 fDetectors.push_back(IDs::channel (kScVe , kNotApplicable ));
00032 fDetectors.push_back(IDs::channel (kScGe , kNotApplicable ));
00033 fDetectors.push_back(IDs::channel (kSiL1_1 , kNotApplicable ));
00034 fDetectors.push_back(IDs::channel (kSiL1_2 , kNotApplicable ));
00035 fDetectors.push_back(IDs::channel (kSiL1_3 , kNotApplicable ));
00036 fDetectors.push_back(IDs::channel (kSiL1_4 , kNotApplicable ));
00037 fDetectors.push_back(IDs::channel (kSiR1_1 , kNotApplicable ));
00038 fDetectors.push_back(IDs::channel (kSiR1_2 , kNotApplicable ));
00039 fDetectors.push_back(IDs::channel (kSiR1_3 , kNotApplicable ));
00040 fDetectors.push_back(IDs::channel (kSiR1_4 , kNotApplicable ));
00041 fDetectors.push_back(IDs::channel (kSiR2 , kNotApplicable ));
00042 fDetectors.push_back(IDs::channel (kSiL2 , kNotApplicable ));
00043 fDetectors.push_back(IDs::channel (kMuSc , kNotApplicable ));
00044 fDetectors.push_back(IDs::channel (kMuScA , kNotApplicable ));
00045 fDetectors.push_back(IDs::channel (kNDet , kNotApplicable ));
00046 fDetectors.push_back(IDs::channel (kNDet2 , kNotApplicable ));
00047
00048
00049 fTotalPulses=new TH1F("hTotalPulses", "Total number of pulses per TME", 100, 0 ,100);
00050 fTotalPulses->SetXTitle("Number of pulses");
00051
00052
00053 fPulsesPerDetector=new TH2F("hPulsesPerChannel", "Pulses per channel per TME",
00054 50, 0 ,50,fDetectors.size(),0,fDetectors.size());
00055 fPulsesPerDetector->SetXTitle("Number of pulses");
00056
00057
00058 fTDiffPerDetector=new TH2F("hTDiffPerChannel", "TDiff to muSc for each channel per TME",
00059 5000, -1.2e4,1.2e4,fDetectors.size(),0,fDetectors.size());
00060 fTDiffPerDetector->SetXTitle("TDiff to central muon (ns)");
00061
00062 for(DetectorList::const_iterator i_det=fDetectors.begin();
00063 i_det!=fDetectors.end(); ++i_det){
00064 fPulsesPerDetector->GetYaxis()->SetBinLabel(i_det-fDetectors.begin()+1, i_det->str().c_str());
00065 fTDiffPerDetector->GetYaxis()->SetBinLabel(i_det-fDetectors.begin()+1, i_det->str().c_str());
00066 }
00067 fPulsesPerDetector->SetDrawOption("colz");
00068 fTDiffPerDetector->SetDrawOption("colz");
00069
00070
00071 fFlags=new TH1F("hFlags", "Number of flagged per TME", 5,0,5);
00072 fFlags->SetYTitle("Number of pulses");
00073 int count=0;
00074 fFlags->GetXaxis()->SetBinLabel(++count,"Healthy");
00075 fFlags->GetXaxis()->SetBinLabel(++count,"Late");
00076 fFlags->GetXaxis()->SetBinLabel(++count,"Early");
00077 fFlags->GetXaxis()->SetBinLabel(++count,"Muon Hit");
00078 fFlags->GetXaxis()->SetBinLabel(++count,"Muon PileUp");
00079
00080 return 0;
00081 }
00082
00083 int CheckTMEs::ProcessEntry(TGlobalData* gData,const TSetupData *setup){
00084
00085 for(MuonEventList::const_iterator i_tme=gMuonEvents.begin();
00086 i_tme!=gMuonEvents.end(); ++i_tme){
00087
00088 fTotalPulses->Fill((*i_tme)->TotalNumPulses());
00089 for(DetectorList::const_iterator i_det=fDetectors.begin();
00090 i_det!=fDetectors.end(); ++i_det){
00091
00092 int N=0, n;
00093 double tme_time= (*i_tme)->GetTime();
00094 int source_index=(*i_tme)->GetSourceIndex(*i_det);
00095 while(source_index>-1){
00096 const IDs::source& source=(*i_tme)->GetSource(source_index);
00097 n=(*i_tme)->NumPulses(source);
00098 N+=n;
00099 for(int i=0; i<n; ++i){
00100 const TDetectorPulse* tdp=(*i_tme)->GetPulse(source,i);
00101 if(tdp && (tdp->IsPairedPulse() || !tdp->CouldBePaired()) )
00102 fTDiffPerDetector->Fill(tdp->GetTime() - tme_time, i_det - fDetectors.begin());
00103 else if(!tdp)
00104 ++fNullCount;
00105 ++fTdpCount;
00106 }
00107 source_index=(*i_tme)->GetSourceIndex(*i_det,source_index+1);
00108 }
00109 fPulsesPerDetector->Fill(N, i_det - fDetectors.begin());
00110 }
00111
00112 if((*i_tme)->HasMuonHit()) fFlags->Fill("Muon Hit",1.);
00113 if((*i_tme)->HasMuonPileup()) fFlags->Fill("Muon PileUp",1.);
00114
00115
00116
00117 fFlags->Fill("Healthy",1.);
00118 }
00119 return 0;
00120 }
00121
00122 int CheckTMEs::AfterLastEntry(TGlobalData* gData,const TSetupData *setup){
00123 cout<<"CheckTMEs::AfterLastEntry: NULL TDP in TME ("<<++fNullCount<<")"<<endl;
00124 cout<<"CheckTMEs::AfterLastEntry: Total number of TDPs ("<<++fTdpCount<<")"<<endl;
00125 cout<<"CheckTMEs::AfterLastEntry: Total entries in fTDiffPerDetector: "<<fTDiffPerDetector->GetEntries()<<endl;
00126 return 0;
00127 }
00128
00129 ALCAP_REGISTER_MODULE(CheckTMEs);