CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonCaloCleanerByDistance.cc
Go to the documentation of this file.
3 
5 
7 
8 #include <string>
9 #include <vector>
10 
12  : moduleLabel_(cfg.getParameter<std::string>("@module_label")),
13  srcSelectedMuons_(cfg.getParameter<edm::InputTag>("muons")),
14  srcDistanceMapMuPlus_(cfg.getParameter<edm::InputTag>("distanceMapMuPlus")),
15  srcDistanceMapMuMinus_(cfg.getParameter<edm::InputTag>("distanceMapMuMinus"))
16 {
17  edm::ParameterSet cfgEnergyDepositCorrection = cfg.getParameter<edm::ParameterSet>("energyDepositCorrection");
18  typedef std::vector<std::string> vstring;
19  vstring detNames = cfgEnergyDepositCorrection.getParameterNamesForType<double>();
20  for ( vstring::const_iterator detName = detNames.begin();
21  detName != detNames.end(); ++detName ) {
22  energyDepositCorrection_[*detName] = cfgEnergyDepositCorrection.getParameter<double>(*detName);
23  }
24 
25  verbosity_ = ( cfg.exists("verbosity") ) ?
26  cfg.getParameter<int>("verbosity") : 0;
27 
28  // maps of detId to expected energy deposits of muon
29  produces<detIdToFloatMap>("energyDepositsMuPlus");
30  produces<double>("totalDistanceMuPlus");
31  produces<double>("totalEnergyDepositMuPlus");
32  produces<detIdToFloatMap>("energyDepositsMuMinus");
33  produces<double>("totalDistanceMuMinus");
34  produces<double>("totalEnergyDepositMuMinus");
35 }
36 
38 {
39 // nothing to be done yet...
40 }
41 
43 {
44  std::auto_ptr<detIdToFloatMap> energyDepositsMuPlus(new detIdToFloatMap());
45  std::auto_ptr<detIdToFloatMap> energyDepositsMuMinus(new detIdToFloatMap());
46 
47  edm::Handle<detIdToFloatMap> distanceMapMuPlus;
48  evt.getByLabel(srcDistanceMapMuPlus_, distanceMapMuPlus);
49  edm::Handle<detIdToFloatMap> distanceMapMuMinus;
50  evt.getByLabel(srcDistanceMapMuMinus_, distanceMapMuMinus);
51 
52  std::vector<reco::CandidateBaseRef> selMuons = getSelMuons(evt, srcSelectedMuons_);
53  const reco::CandidateBaseRef muPlus = getTheMuPlus(selMuons);
54  const reco::CandidateBaseRef muMinus = getTheMuMinus(selMuons);
55 
56  std::auto_ptr<double> totalDistanceMuPlus(new double(0.));
57  std::auto_ptr<double> totalEnergyDepositMuPlus(new double(0.));
58  if ( muPlus.isNonnull() ) fillEnergyDepositMap(*muPlus, *distanceMapMuPlus, *energyDepositsMuPlus, *totalDistanceMuPlus, *totalEnergyDepositMuPlus);
59  std::auto_ptr<double> totalDistanceMuMinus(new double(0.));
60  std::auto_ptr<double> totalEnergyDepositMuMinus(new double(0.));
61  if ( muMinus.isNonnull() ) fillEnergyDepositMap(*muMinus, *distanceMapMuMinus, *energyDepositsMuMinus, *totalDistanceMuMinus, *totalEnergyDepositMuMinus);
62 
63  if ( verbosity_ ) {
64  std::cout << "<MuonCaloCleanerByDistance::produce (" << moduleLabel_ << ")>:" << std::endl;
65  std::cout << " mu+: distance = " << (*totalDistanceMuPlus) << ", expected(EnergyDeposits) = " << (*totalEnergyDepositMuPlus) << std::endl;
66  std::cout << " mu-: distance = " << (*totalDistanceMuMinus) << ", expected(EnergyDeposits) = " << (*totalEnergyDepositMuMinus) << std::endl;
67  }
68 
69  evt.put(energyDepositsMuPlus, "energyDepositsMuPlus");
70  evt.put(totalDistanceMuPlus, "totalDistanceMuPlus");
71  evt.put(totalEnergyDepositMuPlus, "totalEnergyDepositMuPlus");
72  evt.put(energyDepositsMuMinus, "energyDepositsMuMinus");
73  evt.put(totalDistanceMuMinus, "totalDistanceMuMinus");
74  evt.put(totalEnergyDepositMuMinus, "totalEnergyDepositMuMinus");
75 }
76 
78  double& totalDistance, double& totalEnergyDeposit)
79 {
80  for ( detIdToFloatMap::const_iterator rawDetId_and_distance = distanceMap.begin();
81  rawDetId_and_distance != distanceMap.end(); ++rawDetId_and_distance ) {
82  DetId detId(rawDetId_and_distance->first);
83 
85 
86  if ( energyDepositCorrection_.find(key) == energyDepositCorrection_.end() )
87  throw cms::Exception("MuonCaloCleanerByDistance")
88  << "No energy deposit correction defined for detId = " << detId.rawId() << " (key = " << key << ") !!\n";
89 
90  double distance = rawDetId_and_distance->second;
91  double energyDepositCorrection_value = energyDepositCorrection_[key];
92 
93  double dEdx = 0.;
94  double rho = 0.;
95  switch ( detId.det() ) {
96  case DetId::Ecal:
97  dEdx = getDeDxForPbWO4(muon.p());
98  rho = DENSITY_PBWO4;
99  break;
100  case DetId::Hcal:
101  // AB: We don't have a dedx curve for the HCAL. Use the PbWO4 one as an approximation,
102  // the correction factors should be determined with respect to the PbWO4 curve.
103  dEdx = getDeDxForPbWO4(muon.p());
104  if ( detId.subdetId() == HcalOuter ) {
105  rho = DENSITY_IRON; // iron coil and return yoke
106  // HO uses magnet coil as additional absorber, add to flight distance:
107  const double theta = muon.theta();
108  distance += 31.2 / sin(theta); // 31.2cm is dr of cold mass of the magnet coil
109  } else {
110  rho = DENSITY_BRASS; // brass absorber
111  }
112  break;
113  default:
114  throw cms::Exception("MuonCaloCleanerByDistance")
115  << "Unknown detector type: " << key << ", detId = " << static_cast<unsigned int>(detId);
116  }
117 
118  double energyDeposit = distance*dEdx*rho*energyDepositCorrection_value;
119  energyDepositMap[rawDetId_and_distance->first] += energyDeposit;
120  totalDistance += distance;
121  totalEnergyDeposit += energyDeposit;
122  }
123 }
124 
126 
128 
129 
const double DENSITY_PBWO4
T getParameter(std::string const &) const
reco::CandidateBaseRef getTheMuMinus(const std::vector< reco::CandidateBaseRef > &)
tuple cfg
Definition: looper.py:259
const double DENSITY_IRON
vector< string > vstring
Definition: ExoticaDQM.cc:86
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::map< std::string, double > energyDepositCorrection_
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Definition: DDAxes.h:10
Geom::Theta< T > theta() const
bool exists(std::string const &parameterName) const
checks if a parameter exists
bool isNonnull() const
Checks for non-null.
Definition: RefToBase.h:279
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:193
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
virtual double p() const =0
magnitude of momentum vector
const double DENSITY_BRASS
virtual double theta() const =0
momentum polar angle
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
double getDeDxForPbWO4(double)
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:405
Definition: DetId.h:18
std::map< uint32_t, float > detIdToFloatMap
void fillEnergyDepositMap(const reco::Candidate &muon, const detIdToFloatMap &, detIdToFloatMap &, double &, double &)
std::string getKey(const DetId &)
Definition: DetNaming.cc:36
tuple cout
Definition: gather_cfg.py:121
virtual void produce(edm::Event &, const edm::EventSetup &)
std::vector< reco::CandidateBaseRef > getSelMuons(const edm::Event &, const edm::InputTag &)
MuonCaloCleanerByDistance(const edm::ParameterSet &)
reco::CandidateBaseRef getTheMuPlus(const std::vector< reco::CandidateBaseRef > &)
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
moduleLabel_(iConfig.getParameter< string >("@module_label"))