CMS 3D CMS Logo

DTDigiReader.cc
Go to the documentation of this file.
1 #ifndef SimMuon_DTDigiReader_h
2 #define SimMuon_DTDigiReader_h
3 
11 
15 
18 
21 
22 #include <iostream>
23 
24 #include "TFile.h"
25 #include "TH1F.h" //FIXME
26 
27 using namespace edm;
28 using namespace std;
29 
31 public:
32  explicit DTDigiReader(const ParameterSet &pset) {
33  file = new TFile("DTDigiPlots.root", "RECREATE");
34  file->cd();
35  DigiTimeBox = new TH1F("DigiTimeBox", "Digi Time Box", 2048, 0, 1600);
36  DigiTimeBoxW0 = new TH1F("DigiTimeBoxW0", "Digi Time Box W0", 2000, 0, 1600);
37  DigiTimeBoxW1 = new TH1F("DigiTimeBoxW1", "Digi Time Box W1", 2000, 0, 1600);
38  DigiTimeBoxW2 = new TH1F("DigiTimeBoxW2", "Digi Time Box W2", 2000, 0, 1600);
39  if (file->IsOpen())
40  cout << "file open!" << endl;
41  else
42  cout << "*** Error in opening file ***" << endl;
43  label = pset.getUntrackedParameter<string>("label");
44  psim_token = consumes<PSimHitContainer>(edm::InputTag("g4SimHits", "MuonDTHits"));
45  DTd_token = consumes<DTDigiCollection>(edm::InputTag(label));
46  }
47 
48  ~DTDigiReader() override {
49  file->cd();
50  DigiTimeBox->Write();
51  DigiTimeBoxW0->Write();
52  DigiTimeBoxW1->Write();
53  DigiTimeBoxW2->Write();
54  file->Close();
55  // delete file;
56  // delete DigiTimeBox;
57  }
58 
59  void analyze(const Event &event, const EventSetup &eventSetup) override {
60  cout << "--- Run: " << event.id().run() << " Event: " << event.id().event() << endl;
61 
63  event.getByToken(DTd_token, dtDigis);
64  // event.getByLabel("MuonDTDigis", dtDigis);
66  event.getByToken(psim_token, simHits);
67 
69  for (detUnitIt = dtDigis->begin(); detUnitIt != dtDigis->end(); ++detUnitIt) {
70  const DTLayerId &id = (*detUnitIt).first;
71  const DTDigiCollection::Range &range = (*detUnitIt).second;
72 
73  // DTLayerId print-out
74  cout << "--------------" << endl;
75  cout << "id: " << id;
76 
77  // Loop over the digis of this DetUnit
78  for (DTDigiCollection::const_iterator digiIt = range.first; digiIt != range.second; ++digiIt) {
79  // if((*digiIt).time()<703 &&(*digiIt).time()>699) {
80  cout << " Wire: " << (*digiIt).wire() << endl << " digi time (ns): " << (*digiIt).time() << endl;
81 
82  for (vector<PSimHit>::const_iterator simHit = simHits->begin(); simHit != simHits->end(); simHit++) {
83  DTWireId wireId((*simHit).detUnitId());
84  if (wireId.layerId() == id && abs((*simHit).particleType()) == 13) {
85  cout << "entry: " << (*simHit).entryPoint() << endl
86  << "exit: " << (*simHit).exitPoint() << endl
87  << "TOF: " << (*simHit).timeOfFlight() << endl;
88  }
89  }
90 
91  // }
92 
93  if (id.layer() == 3)
94  DigiTimeBoxW0->Fill((*digiIt).time());
95  else if (abs(id.superlayer()) == 1)
96  DigiTimeBoxW1->Fill((*digiIt).time());
97  else if (abs(id.superlayer()) == 2)
98  DigiTimeBoxW2->Fill((*digiIt).time());
99  else
100  cout << "Error" << endl;
101  DigiTimeBox->Fill((*digiIt).time());
102 
103  } // for digis in layer
104  } // for layers
105  cout << "--------------" << endl;
106  }
107 
108 private:
109  string label;
110  TH1F *DigiTimeBox;
114  TFile *file;
115 
118 };
119 
120 #endif
DTDigiReader(const ParameterSet &pset)
Definition: DTDigiReader.cc:32
edm::EDGetTokenT< DTDigiCollection > DTd_token
TH1F * DigiTimeBoxW1
constexpr std::array< uint8_t, layerIndexSize > layer
char const * label
TH1F * DigiTimeBox
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
~DTDigiReader() override
Definition: DTDigiReader.cc:48
edm::EDGetTokenT< PSimHitContainer > psim_token
std::pair< const_iterator, const_iterator > Range
std::vector< DigiType >::const_iterator const_iterator
HLT enums.
void analyze(const Event &event, const EventSetup &eventSetup) override
Definition: DTDigiReader.cc:59
TH1F * DigiTimeBoxW2
TH1F * DigiTimeBoxW0
Definition: event.py:1