00001 #include "TMEViewer.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 #include <TCanvas.h>
00013 #include <TApplication.h>
00014
00015 #include <iostream>
00016 using std::cout;
00017 using std::endl;
00018
00019 extern MuonEventList gMuonEvents;
00020
00021 TMEViewer::TMEViewer(modules::options* opts):
00022 BaseModule("TMEViewer",opts),fNullCount(0),fTdpCount(0){
00023 }
00024
00025 TMEViewer::~TMEViewer(){
00026 }
00027
00028 int TMEViewer::BeforeFirstEntry(TGlobalData* gData,const TSetupData *setup){
00029 using namespace IDs;
00030 fDetectors.push_back(IDs::channel (kSiL1_1 , kNotApplicable ));
00031 fDetectors.push_back(IDs::channel (kSiL1_2 , kNotApplicable ));
00032 fDetectors.push_back(IDs::channel (kSiL1_3 , kNotApplicable ));
00033 fDetectors.push_back(IDs::channel (kSiL1_4 , kNotApplicable ));
00034 fDetectors.push_back(IDs::channel (kSiL2 , kNotApplicable ));
00035 fDetectors.push_back(IDs::channel (kSiR1_1 , kNotApplicable ));
00036 fDetectors.push_back(IDs::channel (kSiR1_2 , kNotApplicable ));
00037 fDetectors.push_back(IDs::channel (kSiR1_3 , kNotApplicable ));
00038 fDetectors.push_back(IDs::channel (kSiR1_4 , kNotApplicable ));
00039 fDetectors.push_back(IDs::channel (kSiR2 , kNotApplicable ));
00040 fDetectors.push_back(IDs::channel (kMuSc , kNotApplicable ));
00041
00042 fTDiffPerDetector=new TH2F("hTDiffPerChannel", "TDiff to muSc for each channel per TME",
00043 5000, -1.2e4,1.2e4,fDetectors.size(),0,fDetectors.size());
00044 fTDiffPerDetector->SetXTitle("TDiff to central muon (ns)");
00045 fTDiffPerDetector->SetDrawOption("COLZ");
00046 fTDiffPerDetector->SetStats(false);
00047 for(DetectorList::const_iterator i_det=fDetectors.begin();
00048 i_det!=fDetectors.end(); ++i_det){
00049 fTDiffPerDetector->GetYaxis()->SetBinLabel(i_det-fDetectors.begin()+1, i_det->str().c_str());
00050 }
00051
00052 fQuit = false;
00053 char** args;
00054 fApp = new TApplication("app",0,args);
00055 fCanvas = new TCanvas("fCanvas", "fCanvas");
00056 return 0;
00057 }
00058
00059 int TMEViewer::ProcessEntry(TGlobalData* gData,const TSetupData *setup){
00060
00061 MuonEventList::const_iterator i_tme = gMuonEvents.begin();
00062
00063 std::string input;
00064 bool found_interesting_event = false;
00065 while (!fQuit || !found_interesting_event) {
00066 found_interesting_event = false;
00067 fTDiffPerDetector->Reset();
00068
00069
00070 for(DetectorList::const_iterator i_det=fDetectors.begin();i_det!=fDetectors.end(); ++i_det){
00071
00072
00073 int N=0, n;
00074 double tme_time= (*i_tme)->GetTime();
00075 int source_index=(*i_tme)->GetSourceIndex(*i_det);
00076 while(source_index>-1){
00077 const IDs::source& source=(*i_tme)->GetSource(source_index);
00078 n=(*i_tme)->NumPulses(source);
00079 N+=n;
00080 for(int i=0; i<n; ++i){
00081 const TDetectorPulse* tdp=(*i_tme)->GetPulse(source,i);
00082 if(tdp && (tdp->IsPairedPulse() || !tdp->CouldBePaired()) )
00083 fTDiffPerDetector->Fill(tdp->GetTime() - tme_time, i_det - fDetectors.begin());
00084 }
00085 source_index=(*i_tme)->GetSourceIndex(*i_det,source_index+1);
00086 }
00087 }
00088 if (fTDiffPerDetector->GetEntries() > 1 && !(*i_tme)->HasMuonPileup()) {
00089 std::cout << "TME #" << i_tme - gMuonEvents.begin() << std::endl;
00090 found_interesting_event = true;
00091 fTDiffPerDetector->Draw("COLZ");
00092 fCanvas->Update();
00093
00094 std::cout << "Press any key to go to next TME (q to quit)" << std::endl;
00095 std::getline( std::cin, input);
00096 if (input == "q") {
00097 fQuit = true;
00098 break;
00099 }
00100 }
00101 std::cout << "TME #" << i_tme - gMuonEvents.begin() << std::endl;
00102 ++i_tme;
00103 if (i_tme == gMuonEvents.end() ) {
00104 std::cout << "At the end" << std::endl;
00105 break;
00106 }
00107 }
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 return 0;
00156 }
00157
00158 int TMEViewer::AfterLastEntry(TGlobalData* gData,const TSetupData *setup){
00159
00160 return 0;
00161 }
00162
00163 ALCAP_REGISTER_MODULE(TMEViewer);