00001 #ifndef SimMuon_DTDigiReader_h
00002 #define SimMuon_DTDigiReader_h
00003
00012 #include <FWCore/Framework/interface/EDAnalyzer.h>
00013 #include <FWCore/Framework/interface/Event.h>
00014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00015
00016 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00017 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
00018
00019 #include "DataFormats/MuonDetId/interface/DTWireId.h"
00020 #include <DataFormats/DTDigi/interface/DTDigiCollection.h>
00021
00022 #include <iostream>
00023
00024 #include "TH1F.h"
00025 #include "TFile.h"
00026
00027 using namespace edm;
00028 using namespace std;
00029
00030 class DTDigiReader: public EDAnalyzer{
00031
00032 public:
00033 explicit DTDigiReader(const ParameterSet& pset){
00034 file = new TFile("DTDigiPlots.root","RECREATE");
00035 file->cd();
00036 DigiTimeBox = new TH1F("DigiTimeBox","Digi Time Box",2048,0,1600);
00037 DigiTimeBoxW0 = new TH1F("DigiTimeBoxW0","Digi Time Box W0",2000,0,1600);
00038 DigiTimeBoxW1 = new TH1F("DigiTimeBoxW1","Digi Time Box W1",2000,0,1600);
00039 DigiTimeBoxW2 = new TH1F("DigiTimeBoxW2","Digi Time Box W2",2000,0,1600);
00040 if(file->IsOpen()) cout<<"file open!"<<endl;
00041 else cout<<"*** Error in opening file ***"<<endl;
00042 label = pset.getUntrackedParameter<string>("label");
00043 }
00044
00045 virtual ~DTDigiReader(){
00046 file->cd();
00047 DigiTimeBox->Write();
00048 DigiTimeBoxW0->Write();
00049 DigiTimeBoxW1->Write();
00050 DigiTimeBoxW2->Write();
00051 file->Close();
00052
00053
00054 }
00055
00056 void analyze(const Event & event, const EventSetup& eventSetup){
00057 cout << "--- Run: " << event.id().run()
00058 << " Event: " << event.id().event() << endl;
00059
00060 Handle<DTDigiCollection> dtDigis;
00061 event.getByLabel(label, dtDigis);
00062
00063 Handle<PSimHitContainer> simHits;
00064 event.getByLabel("g4SimHits","MuonDTHits",simHits);
00065
00066
00067 DTDigiCollection::DigiRangeIterator detUnitIt;
00068 for (detUnitIt=dtDigis->begin();
00069 detUnitIt!=dtDigis->end();
00070 ++detUnitIt){
00071
00072 const DTLayerId& id = (*detUnitIt).first;
00073 const DTDigiCollection::Range& range = (*detUnitIt).second;
00074
00075
00076 cout<<"--------------"<<endl;
00077 cout<<"id: "<<id;
00078
00079
00080 for (DTDigiCollection::const_iterator digiIt = range.first;
00081 digiIt!=range.second;
00082 ++digiIt){
00083
00084 cout<<" Wire: "<<(*digiIt).wire()<<endl
00085 <<" digi time (ns): "<<(*digiIt).time()<<endl;
00086
00087 for(vector<PSimHit>::const_iterator simHit = simHits->begin();
00088 simHit != simHits->end(); simHit++){
00089 DTWireId wireId((*simHit).detUnitId());
00090 if (wireId.layerId()==id && abs((*simHit).particleType())==13){
00091 cout<<"entry: "<<(*simHit).entryPoint()<<endl
00092 <<"exit: "<<(*simHit).exitPoint()<<endl
00093 <<"TOF: "<<(*simHit).timeOfFlight()<<endl;
00094 }
00095 }
00096
00097
00098
00099 if(id.layer()==3)
00100 DigiTimeBoxW0->Fill((*digiIt).time());
00101 else if(abs(id.superlayer())==1)
00102 DigiTimeBoxW1->Fill((*digiIt).time());
00103 else if(abs(id.superlayer())==2)
00104 DigiTimeBoxW2->Fill((*digiIt).time());
00105 else cout<<"Error"<<endl;
00106 DigiTimeBox->Fill((*digiIt).time());
00107
00108 }
00109 }
00110 cout<<"--------------"<<endl;
00111 }
00112
00113 private:
00114 string label;
00115 TH1F *DigiTimeBox;
00116 TH1F *DigiTimeBoxW0;
00117 TH1F *DigiTimeBoxW1;
00118 TH1F *DigiTimeBoxW2;
00119 TFile *file;
00120
00121 };
00122
00123 #endif