1 #ifndef RESOLUTIONANALYZER_CC
2 #define RESOLUTIONANALYZER_CC
20 theMuonLabel_( iConfig.getParameter<edm::
InputTag>(
"MuonLabel" ) ),
21 theMuonType_( iConfig.getParameter<int>(
"MuonType" ) ),
22 theRootFileName_( iConfig.getUntrackedParameter<std::
string>(
"OutputFileName") ),
23 theCovariancesRootFileName_( iConfig.getUntrackedParameter<std::
string>(
"InputFileName") ),
24 debug_( iConfig.getUntrackedParameter<bool>(
"Debug" ) ),
25 resonance_( iConfig.getParameter<bool>(
"Resonance") ),
26 readCovariances_( iConfig.getParameter<bool>(
"ReadCovariances" ) ),
27 treeFileName_( iConfig.getParameter<std::
string>(
"InputTreeName") ),
28 maxEvents_( iConfig.getParameter<int>(
"MaxEvents") ),
29 ptMax_( iConfig.getParameter<double>(
"PtMax") )
35 int resolFitType = iConfig.
getParameter<
int>(
"ResolFitType");
76 typedef std::vector<std::pair<lorentzVector,lorentzVector> >
MuonPairVector;
80 std::vector<std::pair<unsigned int, unsigned long long> > evtRun;
82 MuonPairVector::iterator savedPair = savedPairVector.begin();
83 MuonPairVector::iterator genPair = genPairVector.begin();
84 std::cout <<
"Starting loop on " << savedPairVector.size() <<
" muons" << std::endl;
85 for( ; savedPair != savedPairVector.end(); ++savedPair, ++genPair ) {
103 mapHisto_[
"GenMother"]->Fill( genMother );
104 mapHisto_[
"DeltaGenMotherMuons"]->Fill( genPair->first, genPair->second );
105 mapHisto_[
"GenMotherMuons"]->Fill( genPair->first );
106 mapHisto_[
"GenMotherMuons"]->Fill( genPair->second );
111 mapHisto_[
"PtResolutionGenVSMu"]->Fill(recMu1,(-genPair->first.Pt()+recMu1.Pt())/genPair->first.Pt(),-1);
112 mapHisto_[
"ThetaResolutionGenVSMu"]->Fill(recMu1,(-genPair->first.Theta()+recMu1.Theta()),-1);
113 mapHisto_[
"CotgThetaResolutionGenVSMu"]->Fill(recMu1,(-
cos(genPair->first.Theta())/
sin(genPair->first.Theta())
114 +
cos(recMu1.Theta())/
sin(recMu1.Theta())),-1);
115 mapHisto_[
"EtaResolutionGenVSMu"]->Fill(recMu1,(-genPair->first.Eta()+recMu1.Eta()),-1);
119 deltaPtOverPt_->Fill( (recMu1.Pt() - genPair->first.Pt())/genPair->first.Pt() );
120 if( fabs(recMu1.Eta()) > 1 && fabs(recMu1.Eta()) < 1.2 ) {
126 mapHisto_[
"PtResolutionGenVSMu"]->Fill(recMu2,(-genPair->second.Pt()+recMu2.Pt())/genPair->second.Pt(),+1);
127 mapHisto_[
"ThetaResolutionGenVSMu"]->Fill(recMu2,(-genPair->second.Theta()+recMu2.Theta()),+1);
128 mapHisto_[
"CotgThetaResolutionGenVSMu"]->Fill(recMu2,(-
cos(genPair->second.Theta())/
sin(genPair->second.Theta())
129 +
cos(recMu2.Theta())/
sin(recMu2.Theta())),+1);
130 mapHisto_[
"EtaResolutionGenVSMu"]->Fill(recMu2,(-genPair->second.Eta()+recMu2.Eta()),+1);
134 deltaPtOverPt_->Fill( (recMu2.Pt() - genPair->second.Pt())/genPair->second.Pt() );
135 if( fabs(recMu2.Eta()) > 1 && fabs(recMu2.Eta()) < 1.2 ) {
145 if( genPair->first != nullLorentzVector && genPair->second != nullLorentzVector &&
148 double recoMass = (recMu1+recMu2).
mass();
149 double genMass = (genPair->first + genPair->second).
mass();
151 mapHisto_[
"MassResolution"]->Fill(recMu1, -1, genPair->first, recMu2, +1, genPair->second, recoMass, genMass);
155 mapHisto_[
"RecoResonance"]->Fill( recoResonance );
156 mapHisto_[
"DeltaRecoResonanceMuons"]->Fill( recMu1, recMu2 );
157 mapHisto_[
"RecoResonanceMuons"]->Fill( recMu1 );
158 mapHisto_[
"RecoResonanceMuons"]->Fill( recMu2 );
163 double diffMass = recoMass - genMass;
165 double pt1 = recMu1.pt();
166 double eta1 = recMu1.eta();
167 double pt2 = recMu2.pt();
168 double eta2 = recMu2.eta();
170 if( diffMass == diffMass ) {
175 std::cout <<
"Error, there is a nan: recoMass = " << recoMass <<
", genMass = " << genMass << std::endl;
196 double mass = (recMu1+recMu2).
mass();
197 double pt1 = recMu1.Pt();
198 double phi1 = recMu1.Phi();
199 double eta1 = recMu1.Eta();
200 double theta1 = 2*atan(
exp(-eta1));
201 double pt2 = recMu2.Pt();
202 double phi2 = recMu2.Phi();
203 double eta2 = recMu2.Eta();
204 double theta2 = 2*atan(
exp(-eta2));
208 pt2*(
cos(phi1-phi2)+
cos(theta1)*
cos(theta2)/(
sin(theta1)*
sin(theta2))))/mass;
210 pt1*(
cos(phi2-phi1)+
cos(theta2)*
cos(theta1)/(
sin(theta2)*
sin(theta1))))/mass;
211 double dmdphi1 = pt1*pt2/mass*
sin(phi1-phi2);
212 double dmdphi2 = pt2*pt1/mass*
sin(phi2-phi1);
213 double dmdcotgth1 = (pt1*pt1*
cos(theta1)/
sin(theta1)*
215 pt1*pt2*
cos(theta2)/
sin(theta2))/mass;
216 double dmdcotgth2 = (pt2*pt2*
cos(theta2)/
sin(theta2)*
218 pt2*pt1*
cos(theta1)/
sin(theta1))/mass;
222 double dmdpt[2] = {dmdpt1*recMu1.Pt(), dmdpt2*recMu2.Pt()};
223 double dmdphi[2] = {dmdphi1, dmdphi2};
224 double dmdcotgth[2] = {dmdcotgth1, dmdcotgth2};
229 int charge[2] = { -1, +1 };
231 double fullMassRes = 0.;
232 double massRes1 = 0.;
233 double massRes2 = 0.;
234 double massRes3 = 0.;
235 double massRes4 = 0.;
236 double massRes5 = 0.;
237 double massRes6 = 0.;
238 double massResPtAndPt12 = 0.;
240 for(
int i=0;
i<2; ++
i ) {
242 double ptVariance =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[
i]),
"Pt");
243 double cotgThetaVariance =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[i]),
"CotgTheta");
244 double phiVariance =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[i]),
"Phi");
245 double pt_cotgTheta =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[i]),
"Pt-CotgTheta");
246 double pt_phi =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[i]),
"Pt-Phi");
247 double cotgTheta_phi =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[i]),
"CotgTheta-Phi");
249 double pt1_pt2 =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[i]),
"Pt1-Pt2");
250 double cotgTheta1_cotgTheta2 =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[i]),
"CotgTheta1-CotgTheta2");
251 double phi1_phi2 =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[i]),
"Phi1-Phi2");
252 double pt12_cotgTheta21 =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[i]),
"Pt12-CotgTheta21");
253 double pt12_phi21 =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[i]),
"Pt12-Phi21");
254 double cotgTheta12_phi21 =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[i]),
"CotgTheta12-Phi21");
257 mapHisto_[
"MassResolutionPt"]->Fill( *(recMu[i]), ptVariance*
std::pow(dmdpt[i],2), charge[i] );
258 mapHisto_[
"MassResolutionCotgTheta"]->Fill( *(recMu[i]), cotgThetaVariance*
std::pow(dmdcotgth[i],2), charge[i] );
259 mapHisto_[
"MassResolutionPhi"]->Fill( *(recMu[i]), phiVariance*
std::pow(dmdphi[i],2), charge[i] );
260 mapHisto_[
"MassResolutionPt-CotgTheta"]->Fill( *(recMu[i]), 2*pt_cotgTheta*dmdpt[i]*dmdcotgth[i], charge[i] );
261 mapHisto_[
"MassResolutionPt-Phi"]->Fill( *(recMu[i]), 2*pt_phi*dmdpt[i]*dmdphi[i], charge[i] );
262 mapHisto_[
"MassResolutionCotgTheta-Phi"]->Fill( *(recMu[i]), 2*cotgTheta_phi*dmdcotgth[i]*dmdphi[i], charge[i] );
264 mapHisto_[
"MassResolutionPt1-Pt2"]->Fill( *(recMu[i]), pt1_pt2*dmdpt[0]*dmdpt[1], charge[i] );
265 mapHisto_[
"MassResolutionCotgTheta1-CotgTheta2"]->Fill( *(recMu[i]), cotgTheta1_cotgTheta2*dmdcotgth[0]*dmdcotgth[1], charge[i] );
266 mapHisto_[
"MassResolutionPhi1-Phi2"]->Fill( *(recMu[i]), phi1_phi2*dmdphi[0]*dmdphi[1], charge[i] );
268 mapHisto_[
"MassResolutionPt12-CotgTheta21"]->Fill( *(recMu[i]), pt12_cotgTheta21*dmdpt[0]*dmdcotgth[1], charge[i] );
269 mapHisto_[
"MassResolutionPt12-CotgTheta21"]->Fill( *(recMu[i]), pt12_cotgTheta21*dmdpt[1]*dmdcotgth[0], charge[i] );
270 mapHisto_[
"MassResolutionPt12-Phi21"]->Fill( *(recMu[i]), pt12_phi21*dmdpt[0]*dmdphi[1], charge[i] );
271 mapHisto_[
"MassResolutionPt12-Phi21"]->Fill( *(recMu[i]), pt12_phi21*dmdpt[1]*dmdphi[0], charge[i] );
272 mapHisto_[
"MassResolutionCotgTheta12-Phi21"]->Fill( *(recMu[i]), cotgTheta12_phi21*dmdcotgth[0]*dmdphi[1], charge[i] );
273 mapHisto_[
"MassResolutionCotgTheta12-Phi21"]->Fill( *(recMu[i]), cotgTheta12_phi21*dmdcotgth[1]*dmdphi[0], charge[i] );
276 mapHisto_[
"sigmaPtFromVariance"]->Fill( *(recMu[i]),
sqrt(ptVariance), charge[i] );
277 mapHisto_[
"sigmaCotgThetaFromVariance"]->Fill( *(recMu[i]),
sqrt(cotgThetaVariance), charge[i] );
278 mapHisto_[
"sigmaPhiFromVariance"]->Fill( *(recMu[i]),
sqrt(phiVariance), charge[i] );
285 cotgThetaVariance*
std::pow(dmdcotgth[i],2) +
289 2*pt_cotgTheta*dmdpt[
i]*dmdcotgth[
i] +
290 2*pt_phi*dmdpt[
i]*dmdphi[
i] +
291 2*cotgTheta_phi*dmdcotgth[
i]*dmdphi[
i] +
293 pt1_pt2*dmdpt[0]*dmdpt[1] +
294 cotgTheta1_cotgTheta2*dmdcotgth[0]*dmdcotgth[1] +
295 phi1_phi2*dmdphi[0]*dmdphi[1] +
298 pt12_cotgTheta21*dmdpt[0]*dmdcotgth[1] +
299 pt12_cotgTheta21*dmdpt[1]*dmdcotgth[0] +
300 pt12_phi21*dmdpt[0]*dmdphi[1] +
301 pt12_phi21*dmdpt[1]*dmdphi[0] +
302 cotgTheta12_phi21*dmdcotgth[0]*dmdphi[1] +
303 cotgTheta12_phi21*dmdcotgth[1]*dmdphi[0];
305 massRes1 += ptVariance*
std::pow(dmdpt[i],2);
306 massRes2 += ptVariance*
std::pow(dmdpt[i],2) +
307 cotgThetaVariance*
std::pow(dmdcotgth[i],2);
308 massRes3 += ptVariance*
std::pow(dmdpt[i],2) +
309 cotgThetaVariance*
std::pow(dmdcotgth[i],2) +
311 massRes4 += ptVariance*
std::pow(dmdpt[i],2) +
312 cotgThetaVariance*
std::pow(dmdcotgth[i],2) +
314 pt1_pt2*dmdpt[0]*dmdpt[1] +
315 2*pt_cotgTheta*dmdpt[
i]*dmdcotgth[
i] +
316 2*pt_phi*dmdpt[
i]*dmdphi[
i] +
317 2*cotgTheta_phi*dmdcotgth[
i]*dmdphi[
i];
318 massRes5 += ptVariance*
std::pow(dmdpt[i],2) +
319 cotgThetaVariance*
std::pow(dmdcotgth[i],2) +
321 pt1_pt2*dmdpt[0]*dmdpt[1] +
322 2*pt_cotgTheta*dmdpt[
i]*dmdcotgth[
i] +
323 2*pt_phi*dmdpt[
i]*dmdphi[
i] +
324 2*cotgTheta_phi*dmdcotgth[
i]*dmdphi[
i] +
325 cotgTheta1_cotgTheta2*dmdcotgth[0]*dmdcotgth[1] +
326 phi1_phi2*dmdphi[0]*dmdphi[1];
327 massRes6 += ptVariance*
std::pow(dmdpt[i],2) +
328 cotgThetaVariance*
std::pow(dmdcotgth[i],2) +
330 pt1_pt2*dmdpt[0]*dmdpt[1] +
331 2*pt_cotgTheta*dmdpt[
i]*dmdcotgth[
i] +
332 2*pt_phi*dmdpt[
i]*dmdphi[
i] +
333 2*cotgTheta_phi*dmdcotgth[
i]*dmdphi[
i] +
334 cotgTheta1_cotgTheta2*dmdcotgth[0]*dmdcotgth[1] +
335 phi1_phi2*dmdphi[0]*dmdphi[1] +
336 pt12_cotgTheta21*dmdpt[0]*dmdcotgth[1] +
337 pt12_cotgTheta21*dmdpt[1]*dmdcotgth[0] +
338 pt12_phi21*dmdpt[0]*dmdphi[1] +
339 pt12_phi21*dmdpt[1]*dmdphi[0] +
340 cotgTheta12_phi21*dmdcotgth[0]*dmdphi[1] +
341 cotgTheta12_phi21*dmdcotgth[1]*dmdphi[0];
343 massResPtAndPt12 += ptVariance*
std::pow(dmdpt[i],2) + pt1_pt2*dmdpt[0]*dmdpt[1];
346 mapHisto_[
"DerivativePt"]->Fill( *(recMu[i]), dmdpt[i], charge[i] );
347 mapHisto_[
"DerivativeCotgTheta"]->Fill( *(recMu[i]), dmdcotgth[i], charge[i] );
348 mapHisto_[
"DerivativePhi"]->Fill( *(recMu[i]), dmdphi[i], charge[i] );
351 mapHisto_[
"FullMassResolution"]->Fill( *(recMu[0]), fullMassRes, charge[0]);
352 mapHisto_[
"FullMassResolution"]->Fill( *(recMu[1]), fullMassRes, charge[1]);
354 mapHisto_[
"MassRes1"]->Fill( *(recMu[0]), massRes1, charge[0] );
355 mapHisto_[
"MassRes1"]->Fill( *(recMu[1]), massRes1, charge[1] );
356 mapHisto_[
"MassRes2"]->Fill( *(recMu[0]), massRes2, charge[0] );
357 mapHisto_[
"MassRes2"]->Fill( *(recMu[1]), massRes2, charge[1] );
358 mapHisto_[
"MassRes3"]->Fill( *(recMu[0]), massRes3, charge[0] );
359 mapHisto_[
"MassRes3"]->Fill( *(recMu[1]), massRes3, charge[1] );
360 mapHisto_[
"MassRes4"]->Fill( *(recMu[0]), massRes4, charge[0] );
361 mapHisto_[
"MassRes4"]->Fill( *(recMu[1]), massRes4, charge[1] );
362 mapHisto_[
"MassRes5"]->Fill( *(recMu[0]), massRes5, charge[0] );
363 mapHisto_[
"MassRes5"]->Fill( *(recMu[1]), massRes5, charge[1] );
364 mapHisto_[
"MassRes6"]->Fill( *(recMu[0]), massRes6, charge[0] );
365 mapHisto_[
"MassRes6"]->Fill( *(recMu[1]), massRes6, charge[1] );
366 mapHisto_[
"MassResPtAndPt12"]->Fill( *(recMu[0]), massResPtAndPt12, charge[0] );
367 mapHisto_[
"MassResPtAndPt12"]->Fill( *(recMu[1]), massResPtAndPt12, charge[1] );
371 mapHisto_[
"Covariances"]->Fill(recMu1, genPair->first, recMu2, genPair->second);
481 recoPtVsgenPt_ =
new TH2D(
"recoPtVsgenPt",
"recoPtVsgenPt", 100, 0, ptMax, 100, 0, ptMax);
482 recoPtVsgenPtEta12_ =
new TH2D(
"recoPtVsgenPtEta12",
"recoPtVsgenPtEta12", 100, 0, ptMax, 100, 0, ptMax);
483 deltaPtOverPt_ =
new TH1D(
"deltaPtOverPt",
"deltaPtOverPt", 100, -0.1, 0.1);
540 for (std::map<std::string, Histograms*>::const_iterator
histo=
mapHisto_.begin();
542 (*histo).second->Write();
555 ((recMu.Eta()-genMu.Eta()) * (recMu.Eta()-genMu.Eta())));
559 std::cout<<
"Reco muon "<<recMu<<
" with eta "<<recMu.Eta()<<
" and phi "<<recMu.Phi()<<std::endl
560 <<
" DOES NOT MATCH with generated muon from resonance: "<<std::endl
561 <<genMu<<
" with eta "<<genMu.Eta()<<
" and phi "<<genMu.Phi()<<std::endl;
568 #endif // RESOLUTIONANALYZER_CC
static double deltaPhiNoFabs(const double &phi1, const double &phi2)
Without fabs at the end, used to have a symmetric distribution for the resolution fits and variance c...
T getParameter(std::string const &) const
std::map< std::string, Histograms * > mapHisto_
std::string theRootFileName_
TH2D * recoPtVsgenPtEta12_
static std::vector< double > parResol
#define DEFINE_FWK_MODULE(type)
Sin< T >::type sin(const T &t)
reco::Particle::LorentzVector lorentzVector
virtual void Fill(const double &x, const double &y, const double &a, const double &b)
HCovarianceVSxy * massResolutionVsPtEta_
void fillHistoMap()
Used to fill the map with the histograms needed.
resolutionFunctionBase< std::vector< double > > * resolutionFunctionVecService(const int identifier)
Service to build the resolution functor corresponding to the passed identifier when receiving a std::...
static double massResolution(const lorentzVector &mu1, const lorentzVector &mu2)
void writeHistoMap()
Writes the histograms in the map.
Cos< T >::type cos(const T &t)
std::vector< std::pair< lorentzVector, lorentzVector > > MuonPairVector
std::string theCovariancesRootFileName_
bool checkDeltaR(const reco::Particle::LorentzVector &genMu, const reco::Particle::LorentzVector &recMu)
Returns true if the two particles have DeltaR < cut.
double deltaR(double eta1, double eta2, double phi1, double phi2)
virtual void analyze(const edm::Event &, const edm::EventSetup &)
TH1D * deltaPtOverPtForEta12_
resolutionFunctionBase< double * > * resolutionFunctionService(const int identifier)
Service to build the resolution functor corresponding to the passed identifier.
static double deltaPhi(const double &phi1, const double &phi2)
static std::vector< int > resfind
static resolutionFunctionBase< std::vector< double > > * resolutionFunctionForVec
math::XYZTLorentzVector LorentzVector
Lorentz vector.
A set of histograms for resolution.
Power< A, B >::type pow(const A &a, const B &b)
static resolutionFunctionBase< double * > * resolutionFunction
ResolutionAnalyzer(const edm::ParameterSet &)