25 <<
" Failed to find File = " << inputFileName <<
" !!\n";
26 std::auto_ptr<TFile>
inputFile(
new TFile(inputFileName.fullPath().data()));
28 typedef std::vector<double> vdouble;
29 vdouble binningMuonEn = cfg.
getParameter<vdouble>(
"binningMuonEn");
30 int numBinsMuonEn = binningMuonEn.size() - 1;
32 <<
" Invalid Configuration Parameter 'binningMuonEn', must define at least one bin !!\n";
35 for (
int iBinMuPlusEn = 0; iBinMuPlusEn < numBinsMuonEn; ++iBinMuPlusEn ) {
36 double minMuPlusEn = binningMuonEn[iBinMuPlusEn];
37 double maxMuPlusEn = binningMuonEn[iBinMuPlusEn + 1];
38 for (
int iBinMuMinusEn = 0; iBinMuMinusEn < numBinsMuonEn; ++iBinMuMinusEn ) {
39 double minMuMinusEn = binningMuonEn[iBinMuMinusEn];
40 double maxMuMinusEn = binningMuonEn[iBinMuMinusEn + 1];
49 for ( std::vector<std::string>::const_iterator name_others = names_others.begin();
50 name_others != names_others.end(); ++name_others ) {
53 for (
int iBinMuPlusEn = 0; iBinMuPlusEn < numBinsMuonEn; ++iBinMuPlusEn ) {
54 double minMuPlusEn = binningMuonEn[iBinMuPlusEn];
55 double maxMuPlusEn = binningMuonEn[iBinMuPlusEn + 1];
56 for (
int iBinMuMinusEn = 0; iBinMuMinusEn < numBinsMuonEn; ++iBinMuMinusEn ) {
57 double minMuMinusEn = binningMuonEn[iBinMuMinusEn];
58 double maxMuMinusEn = binningMuonEn[iBinMuMinusEn + 1];
60 new lutEntryType(*inputFile, lutDirectoryOther, minMuPlusEn, maxMuPlusEn, minMuMinusEn, maxMuMinusEn);
68 <<
" Invalid Configuration Parameter 'lutNameOthers': No alternative models defined !!\n";
78 produces<double>(
"weight");
79 produces<double>(
"weightUp");
80 produces<double>(
"weightDown");
90 for ( std::map<std::string, vlutEntryType>::iterator it1 =
lutEntriesOthers_.begin();
92 for ( vlutEntryType::iterator it2 = it1->second.begin();
93 it2 != it1->second.end(); ++it2 ) {
110 std::cout <<
"<MuonRadiationCorrWeightProducer::produce>:" << std::endl;
116 bool genMuonPlus_beforeRad_found =
false;
118 bool genMuonMinus_beforeRad_found =
false;
119 findMuons(evt,
srcMuonsBeforeRad_, genMuonPlusP4_beforeRad, genMuonPlus_beforeRad_found, genMuonMinusP4_beforeRad, genMuonMinus_beforeRad_found);
122 bool genMuonPlus_afterRad_found =
false;
124 bool genMuonMinus_afterRad_found =
false;
125 findMuons(evt,
srcMuonsAfterRad_, genMuonPlusP4_afterRad, genMuonPlus_afterRad_found, genMuonMinusP4_afterRad, genMuonMinus_afterRad_found);
127 bool genMuonPlus_found = (genMuonPlus_beforeRad_found && genMuonPlus_afterRad_found);
128 bool genMuonMinus_found = (genMuonMinus_beforeRad_found && genMuonMinus_afterRad_found);
131 double weightErr = 1.;
132 if ( genMuonPlus_found && genMuonMinus_found ) {
134 std::cout <<
" muon+: En = " << genMuonPlusP4_afterRad.E() <<
", dEn = " << (genMuonPlusP4_beforeRad.E() - genMuonPlusP4_afterRad.E()) << std::endl;
135 std::cout <<
" muon-: En = " << genMuonMinusP4_afterRad.E() <<
", dEn = " << (genMuonMinusP4_beforeRad.E() - genMuonMinusP4_afterRad.E()) << std::endl;
141 bool pRef_found =
false;
144 if ( (*lutEntry)->isWithinBounds(genMuonPlusP4_afterRad.E(), genMuonMinusP4_afterRad.E()) ) {
145 pRef = (*lutEntry)->getP(genMuonPlusP4_beforeRad, genMuonPlusP4_afterRad, genMuonMinusP4_beforeRad, genMuonMinusP4_afterRad);
153 <<
"Failed to find entry in reference LUT for"
154 <<
" muon+: En = " << genMuonPlusP4_afterRad.E() <<
", dEn = " << (genMuonPlusP4_beforeRad.E() - genMuonPlusP4_afterRad.E()) <<
";"
155 <<
" muon-: En = " << genMuonMinusP4_afterRad.E() <<
", dEn = " << (genMuonMinusP4_beforeRad.E() - genMuonMinusP4_afterRad.E()) <<
" !!" << std::endl;
161 std::map<std::string, double> pOthers;
162 for ( std::map<std::string, vlutEntryType>::iterator lutEntriesOther =
lutEntriesOthers_.begin();
164 bool pOther_found =
false;
165 for ( vlutEntryType::iterator lutEntry = lutEntriesOther->second.begin();
166 lutEntry != lutEntriesOther->second.end(); ++lutEntry ) {
167 if ( (*lutEntry)->isWithinBounds(genMuonPlusP4_afterRad.E(), genMuonMinusP4_afterRad.E()) ) {
168 pOthers[lutEntriesOther->first] = (*lutEntry)->getP(genMuonPlusP4_beforeRad, genMuonPlusP4_afterRad, genMuonMinusP4_beforeRad, genMuonMinusP4_afterRad);
169 if (
verbosity_ )
std::cout <<
"pOthers[" << lutEntriesOther->first <<
"] = " << pOthers[lutEntriesOther->first] << std::endl;
173 if ( !pOther_found ) {
176 <<
"Failed to find entry in LUT = " << lutEntriesOther->first <<
" for"
177 <<
" muon+: En = " << genMuonPlusP4_afterRad.E() <<
", dEn = " << (genMuonPlusP4_beforeRad.E() - genMuonPlusP4_afterRad.E()) <<
";"
178 <<
" muon-: En = " << genMuonMinusP4_afterRad.E() <<
", dEn = " << (genMuonMinusP4_beforeRad.E() - genMuonMinusP4_afterRad.E()) <<
" !!" << std::endl;
187 for ( std::map<std::string, double>::const_iterator pOther = pOthers.begin();
188 pOther != pOthers.end(); ++pOther ) {
189 pMean += pOther->second;
194 double pErr2 =
square(pRef - pMean);
195 for ( std::map<std::string, double>::const_iterator pOther = pOthers.begin();
196 pOther != pOthers.end(); ++pOther ) {
197 pErr2 +=
square(pOther->second - pMean);
204 weightErr =
sqrt(pErr2)/pRef;
213 <<
"Failed to find generator level taus matching reconstructed muons !!" << std::endl;
220 double weightUp = weight + weightErr;
222 double weightDown =
std::max(weight - weightErr, 0.);
225 std::cout <<
"--> weight = " << weight <<
" + " << (weightUp -
weight) <<
" - " << (weight - weightDown) << std::endl;
228 std::auto_ptr<double> weightPtr(
new double(weight));
229 evt.
put(weightPtr,
"weight");
230 std::auto_ptr<double> weightUpPtr(
new double(weightUp));
231 evt.
put(weightUpPtr,
"weightUp");
232 std::auto_ptr<double> weightDownPtr(
new double(weightDown));
233 evt.
put(weightDownPtr,
"weightDown");
T getParameter(std::string const &) const
edm::InputTag srcMuonsAfterRad_
#define DEFINE_FWK_MODULE(type)
std::map< std::string, std::string > lutDirectoriesOthers_
bool exists(std::string const ¶meterName) const
checks if a parameter exists
~MuonRadiationCorrWeightProducer()
vlutEntryType lutEntriesRef_
MuonRadiationCorrWeightProducer(const edm::ParameterSet &)
void produce(edm::Event &, const edm::EventSetup &)
std::map< std::string, vlutEntryType > lutEntriesOthers_
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
T x() const
Cartesian x coordinate.
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
std::string lutDirectoryRef_
edm::InputTag srcMuonsBeforeRad_
math::XYZTLorentzVector LorentzVector
Lorentz vector.
double square(const double a)
void findMuons(const edm::Event &, const edm::InputTag &, reco::Candidate::LorentzVector &, bool &, reco::Candidate::LorentzVector &, bool &)