CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TBHodoActiveVolumeRawInfoProducer.cc
Go to the documentation of this file.
1 /*
2  * \file TBHodoActiveVolumeRawInfoProducer.cc
3  *
4  *
5  */
6 
15 
23 
24 #include <iostream>
25 
27 public:
30 
33 
35  void produce(edm::Event &event, const edm::EventSetup &eventSetup) override;
36 
37 private:
38  double myThreshold;
39 
42 };
43 
44 using namespace cms;
45 using namespace std;
46 
48  m_EcalToken = consumes<edm::PCaloHitContainer>(edm::InputTag("g4SimHits", "EcalTBH4BeamHits"));
49  produces<EcalTBHodoscopeRawInfo>();
50 
51  theTBHodoGeom_ = new EcalTBHodoscopeGeometry();
52 
53  myThreshold = 0.05E-3;
54 }
55 
57 
59  unique_ptr<EcalTBHodoscopeRawInfo> product(new EcalTBHodoscopeRawInfo());
60 
61  // caloHit container
63  const edm::PCaloHitContainer *caloHits = nullptr;
64  event.getByToken(m_EcalToken, pCaloHit);
65  if (pCaloHit.isValid()) {
66  caloHits = pCaloHit.product();
67  LogDebug("EcalTBHodo") << "total # caloHits: " << caloHits->size();
68  } else {
69  edm::LogError("EcalTBHodo") << "Error! can't get the caloHitContainer ";
70  }
71  if (!caloHits) {
72  return;
73  }
74 
75  // detid - energy_sum map
76  std::map<unsigned int, double> energyMap;
77 
78  for (auto &&aHit : *caloHits) {
79  double thisHitEne = aHit.energy();
80 
81  std::map<unsigned int, double>::iterator itmap = energyMap.find(aHit.id());
82  if (itmap == energyMap.end())
83  energyMap.insert(pair<unsigned int, double>(aHit.id(), thisHitEne));
84  else {
85  (*itmap).second += thisHitEne;
86  }
87  }
88 
89  // planes and fibers
90  int nPlanes = theTBHodoGeom_->getNPlanes();
91  int nFibers = theTBHodoGeom_->getNFibres();
92  product->setPlanes(nPlanes);
93 
94  bool firedChannels[4][64];
95  for (int iPlane = 0; iPlane < nPlanes; ++iPlane) {
96  for (int iFiber = 0; iFiber < nFibers; ++iFiber) {
97  firedChannels[iPlane][iFiber] = 0.;
98  }
99  }
100  for (std::map<unsigned int, double>::const_iterator itmap = energyMap.begin(); itmap != energyMap.end(); ++itmap) {
101  if ((*itmap).second > myThreshold) {
102  HodoscopeDetId myHodoDetId = HodoscopeDetId((*itmap).first);
103  firedChannels[myHodoDetId.planeId()][myHodoDetId.fibrId()] = true;
104  }
105  }
106  for (int iPlane = 0; iPlane < nPlanes; ++iPlane) {
107  EcalTBHodoscopePlaneRawHits planeHit(nFibers);
108 
109  for (int iFiber = 0; iFiber < nFibers; ++iFiber) {
110  planeHit.setHit(iFiber, firedChannels[iPlane][iFiber]);
111  }
112  product->setPlane((unsigned int)iPlane, planeHit);
113  }
114 
115  LogDebug("EcalTBHodo") << (*product);
116 
117  event.put(std::move(product));
118 }
119 
std::vector< PCaloHit > PCaloHitContainer
void setHit(unsigned int i, bool status)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void produce(edm::Event &event, const edm::EventSetup &eventSetup) override
Produce digis out of raw data.
Log< level::Error, false > LogError
TBHodoActiveVolumeRawInfoProducer(const edm::ParameterSet &ps)
Constructor.
def move
Definition: eostools.py:511
bool isValid() const
Definition: HandleBase.h:70
int fibrId() const
T const * product() const
Definition: Handle.h:70
int planeId() const
#define LogDebug(id)
edm::EDGetTokenT< edm::PCaloHitContainer > m_EcalToken