Double_t CalibTree::Loop(int loop, TFile *fout, bool useweight, int nMin, bool inverse, double rmin, double rmax, int ietaMax, int applyL1Cut, double l1Cut, bool last, double fraction, bool writeHisto, bool debug) { if (fChain == 0) return 0; Long64_t nbytes(0), nb(0), kprint(0); Long64_t nentryTot = fChain->GetEntriesFast(); Long64_t nentries = (fraction > 0.01 && fraction < 0.99) ? (Long64_t)(fraction*nentryTot) : nentryTot; if (detIds.size() == 0) { for (Long64_t jentry=0; jentry<nentries; jentry++) { Long64_t ientry = LoadTree(jentry); if (ientry < 0) break; nb = fChain->GetEntry(jentry); nbytes += nb; // Find DetIds contributing to the track bool selRun = (includeRun_ ? ((t_Run >= runlo_) && (t_Run <= runhi_)) : ((t_Run < runlo_) || (t_Run > runhi_))); if (selRun && (t_nVtx >= nvxlo_) && (t_nVtx <= nvxhi_)) { bool isItRBX = (cSelect_ && exclude_ && cSelect_->isItRBX(t_DetIds)); ++kprint; if (!isItRBX) { for (unsigned int idet=0; idet<(*t_DetIds).size(); idet++) { if (selectPhi((*t_DetIds)[idet])) { unsigned int detid = truncateId((*t_DetIds)[idet], truncateFlag_,debug); if (debug && (kprint<=10)) { std::cout << "DetId[" << idet << "] Original " << std::hex << (*t_DetIds)[idet] << " truncated " << detid << std::dec; } if (std::find(detIds.begin(),detIds.end(),detid) == detIds.end()){ detIds.push_back(detid); if (debug && (kprint<=10)) std::cout << " new"; } if (debug && (kprint<=10)) std::cout << std::endl; } } // Also look at the neighbouring cells if available if (t_DetIds3 != 0) { for (unsigned int idet=0; idet<(*t_DetIds3).size(); idet++) { if (selectPhi((*t_DetIds3)[idet])) { unsigned int detid = truncateId((*t_DetIds3)[idet], truncateFlag_,debug); if (std::find(detIds.begin(),detIds.end(),detid)==detIds.end()){ detIds.push_back(detid); } } } } } } } } if (debug) { std::cout << "Total of " << detIds.size() << " detIds and " << histos.size() << " histos found" << std::endl; // The masks are defined in DataFormats/HcalDetId/interface/HcalDetId.h for (unsigned int k=0; k<detIds.size(); ++k) { int subdet, depth, zside, ieta, iphi; unpackDetId(detIds[k], subdet, zside, ieta, iphi, depth); std::cout << "DetId[" << k << "] " << subdet << ":" << zside*ieta << ":" << depth << ":" << iphi << " " << std::hex << detIds[k] << std::dec << std::endl; } } unsigned int k(0); for (std::map<unsigned int, TH1D*>::const_iterator itr = histos.begin(); itr != histos.end(); ++itr,++k) { if (debug) { std::cout << "histos[" << k << "] " << std::hex << itr->first << std::dec << " " << itr->second; if (itr->second != 0) std::cout << " " << itr->second->GetTitle(); std::cout << std::endl; } if (itr->second != 0) itr->second->Delete(); } for (unsigned int k=0; k<detIds.size(); ++k) { char name[20], title[100]; sprintf (name, "Hist%d_%d", detIds[k], loop); int subdet, depth, zside, ieta, iphi; unpackDetId(detIds[k], subdet, zside, ieta, iphi, depth); sprintf (title, "Correction for Subdet %d #eta %d depth %d (Loop %d)", subdet, zside*ieta, depth, loop); TH1D* hist = new TH1D(name,title,100, 0.0, 5.0); hist->Sumw2(); if (debug) { std::cout << "Book Histo " << k << " " << title << std::endl; } histos[detIds[k]] = hist; } std::cout << "Total of " << detIds.size() << " detIds and " << histos.size() << " found in " << nentries << std::endl; nbytes = nb = 0; std::map<unsigned int, myEntry > SumW; std::map<unsigned int, double > nTrks; int ntkgood(0); for (Long64_t jentry=0; jentry<nentries; jentry++) { Long64_t ientry = LoadTree(jentry); if (ientry < 0) break; nb = fChain->GetEntry(jentry); nbytes += nb; if (std::find(entries.begin(),entries.end(),jentry) != entries.end()) continue; bool selRun = (includeRun_ ? ((t_Run >= runlo_) && (t_Run <= runhi_)) : ((t_Run < runlo_) || (t_Run > runhi_))); if (!selRun) continue; if ((t_nVtx < nvxlo_) || (t_nVtx > nvxhi_)) continue; if (cSelect_ != nullptr) { if (exclude_) { if (cSelect_->isItRBX(t_DetIds)) continue; } else { if (!(cSelect_->isItRBX(t_ieta,t_iphi))) continue; } } if (debug) { std::cout << "***Entry (Track) Number : " << ientry << std::endl; std::cout << "p/eHCal/eMipDR/nDets : " << t_p << "/" << t_eHcal << "/" << t_eMipDR << "/" << (*t_DetIds).size() << std::endl; } double pmom = (useGen_ && (t_gentrackP > 0)) ? t_gentrackP : t_p; if (goodTrack()) { ++ntkgood; double Etot(0), Etot2(0); for (unsigned int idet=0; idet<(*t_DetIds).size(); idet++) { if (selectPhi((*t_DetIds)[idet])) { unsigned int id = (*t_DetIds)[idet]; double hitEn(0); unsigned int detid = truncateId(id,truncateFlag_,false); if (Cprev.find(detid) != Cprev.end()) hitEn = Cprev[detid].first * (*t_HitEnergies)[idet]; else hitEn = (*t_HitEnergies)[idet]; if (cFactor_) hitEn *= cFactor_->getCorr(t_Run,id); Etot += hitEn; Etot2 += ((*t_HitEnergies)[idet]); } } // Now the outer cone double Etot1(0), Etot3(0); if (t_DetIds1 != 0 && t_DetIds3 != 0) { for (unsigned int idet=0; idet<(*t_DetIds1).size(); idet++) { if (selectPhi((*t_DetIds1)[idet])) { unsigned int id = (*t_DetIds1)[idet]; unsigned int detid = truncateId(id,truncateFlag_,false); double hitEn(0); if (Cprev.find(detid) != Cprev.end()) hitEn = Cprev[detid].first * (*t_HitEnergies1)[idet]; else hitEn = (*t_HitEnergies1)[idet]; if (cFactor_) hitEn *= cFactor_->getCorr(t_Run,id); Etot1 += hitEn; } } for (unsigned int idet=0; idet<(*t_DetIds3).size(); idet++) { if (selectPhi((*t_DetIds3)[idet])) { unsigned int id = (*t_DetIds3)[idet]; unsigned int detid = truncateId(id,truncateFlag_,false); double hitEn(0); if (Cprev.find(detid) != Cprev.end()) hitEn = Cprev[detid].first * (*t_HitEnergies3)[idet]; else hitEn = (*t_HitEnergies3)[idet]; if (cFactor_) hitEn *= cFactor_->getCorr(t_Run,id); Etot3 += hitEn; } } } eHcalDelta_ = Etot3-Etot1; double evWt = (useweight) ? t_EventWeight : 1.0; // PU correction only for loose isolation cut double ehcal = ((puCorr_ == 0) ? Etot : ((puCorr_ < 0) ? (Etot*puFactor(-puCorr_,t_ieta,pmom,Etot,eHcalDelta_)) : puFactorRho(puCorr_,t_ieta,t_rhoh,Etot))); double pufac = (Etot > 0) ? (ehcal/Etot) : 1.0; double ratio = ehcal/(pmom-t_eMipDR); if (debug) std::cout << " Weights " << evWt << ":" << pufac << " Energy " << Etot2 << ":" << Etot << ":" << pmom << ":" << t_eMipDR << ":" << t_eHcal << ":" << ehcal << " ratio " << ratio << std::endl; if (loop==0) { h_pbyE->Fill(ratio, evWt); h_Ebyp_bfr->Fill(t_ieta, ratio, evWt); } if (last){ h_Ebyp_aftr->Fill(t_ieta, ratio, evWt); } bool l1c(true); if (applyL1Cut != 0) l1c = ((t_mindR1 >= l1Cut) || ((applyL1Cut == 1) && (t_DataType == 1))); if ((rmin >=0 && ratio > rmin) && (rmax >= 0 && ratio < rmax) && l1c) { for (unsigned int idet=0; idet<(*t_DetIds).size(); idet++) { if (selectPhi((*t_DetIds)[idet])) { unsigned int id = (*t_DetIds)[idet]; unsigned int detid = truncateId(id,truncateFlag_,false); double hitEn=0.0; if (debug) { std::cout << "idet " << idet << " detid/hitenergy : " << std::hex << (*t_DetIds)[idet] << ":" << detid << "/" << (*t_HitEnergies)[idet] << std::endl; } if (Cprev.find(detid) != Cprev.end()) hitEn = Cprev[detid].first * (*t_HitEnergies)[idet]; else hitEn = (*t_HitEnergies)[idet]; if (cFactor_) hitEn *= cFactor_->getCorr(t_Run,id); double Wi = evWt * hitEn/Etot; double Fac = (inverse) ? (ehcal/(pmom-t_eMipDR)) : ((pmom-t_eMipDR)/ehcal); double Fac2= Wi*Fac*Fac; TH1D* hist(0); std::map<unsigned int,TH1D*>::const_iterator itr = histos.find(detid); if (itr != histos.end()) hist = itr->second; if (debug) { std::cout << "Det Id " << std::hex << detid << std::dec << " " << hist << std::endl; } if (hist != 0) hist->Fill(Fac, Wi);//////histola Fac *= Wi; if (SumW.find(detid) != SumW.end() ) { Wi += SumW[detid].fact0; Fac += SumW[detid].fact1; Fac2+= SumW[detid].fact2; int kount = SumW[detid].kount + 1; SumW[detid] = myEntry(kount,Wi,Fac,Fac2); nTrks[detid] += evWt; } else { SumW.insert(std::pair<unsigned int,myEntry>(detid,myEntry(1,Wi,Fac,Fac2))); nTrks.insert(std::pair<unsigned int,unsigned int>(detid, evWt)); } } } } } } if (debug) { std::cout << "# of Good Tracks " << ntkgood << " out of " << nentries << std::endl; } if (loop==0) { h_pbyE->Write("h_pbyE"); h_Ebyp_bfr->Write("h_Ebyp_bfr"); } if (last) { h_Ebyp_aftr->Write("h_Ebyp_aftr"); } std::map<unsigned int, std::pair<double,double> > cfactors; unsigned int kount(0), kountus(0); double sumfactor(0); for (std::map<unsigned int,TH1D*>::const_iterator itr = histos.begin(); itr != histos.end(); ++itr) { if (writeHisto) { std::pair<double,double> result_write = fitMean(itr->second, 0); (itr->second)->Write(); } // The masks are defined in DataFormats/HcalDetId/interface/HcalDetId.h int subdet, depth, zside, ieta, iphi; unpackDetId(itr->first, subdet, zside, ieta, iphi, depth); if (debug) { std::cout << "DETID :" << subdet << " IETA :" << ieta << " HIST ENTRIES :" << (itr->second)->GetEntries() << std::endl; } } for (std::map<unsigned int,TH1D*>::const_iterator itr = histos.begin(); itr != histos.end(); ++itr,++kount) { std::pair<double,double> result = fitMean(itr->second, 0); double factor = (inverse) ? (2.-result.first) : result.first; if (debug) { int subdet, depth, zside, ieta, iphi; unpackDetId(itr->first, subdet, zside, ieta, iphi, depth); std::cout << "DetId[" << kount << "] " << subdet << ":" << zside*ieta << ":" << depth << " Factor " << factor << " +- " << result.second << std::endl; } if (!useMean_) { cfactors[itr->first] = std::pair<double,double>(factor,result.second); if (itr->second->GetEntries() > nMin) { kountus++; if (factor > 1) sumfactor += (1-1/factor); else sumfactor += (1-factor); } } } std::map<unsigned int, myEntry>::const_iterator SumWItr = SumW.begin(); for (; SumWItr != SumW.end(); SumWItr++) { unsigned int detid = SumWItr->first; int subdet, depth, zside, ieta, iphi; unpackDetId(detid, subdet, zside, ieta, iphi, depth); if (debug) { std::cout << "Detid|kount|SumWi|SumFac|myId : " << subdet << ":" << zside*ieta << ":" << depth << " | " << (SumWItr->second).kount << " | " << (SumWItr->second).fact0 << "|" << (SumWItr->second).fact1 << "|" << (SumWItr->second).fact2 << std::endl; } double factor = (SumWItr->second).fact1/(SumWItr->second).fact0; double dfac1 = ((SumWItr->second).fact2/(SumWItr->second).fact0-factor*factor); if (dfac1 < 0) dfac1 = 0; double dfac = sqrt(dfac1/(SumWItr->second).kount); if (debug) { std::cout << "Factor " << factor << " " << dfac1 << " " << dfac << std::endl; } if (inverse) factor = 2.-factor; if (useMean_) { cfactors[detid] = std::pair<double,double>(factor,dfac); if ((SumWItr->second).kount > nMin) { kountus++; if (factor > 1) sumfactor += (1-1/factor); else sumfactor += (1-factor); } } } double dets[150], cfacs[150], wfacs[150], myId[150], nTrk[150]; kount = 0; std::map<unsigned int,std::pair<double,double> >::const_iterator itr=cfactors.begin(); for (; itr !=cfactors.end(); ++itr,++kount) { unsigned int detid = itr->first; int subdet, depth, zside, ieta, iphi; unpackDetId(detid, subdet, zside, ieta, iphi, depth); double id = ieta*zside + 0.25*(depth-1); double factor = (itr->second).first; double dfac = (itr->second).second; if (ieta > ietaMax) { factor = 1; dfac = 0; } std::pair<double,double> cfac(factor,dfac); if (Cprev.find(detid) != Cprev.end()) { dfac /= factor; factor *= Cprev[detid].first; dfac *= factor; Cprev[detid] = std::pair<double,double>(factor,dfac); cfacs[kount] = factor; } else { Cprev[detid] = std::pair<double,double>(factor,dfac); cfacs[kount] = factor; } wfacs[kount]= factor; dets[kount] = detid; myId[kount] = id; nTrk[kount] = nTrks[detid]; } if (higheta_ > 0) highEtaFactors(ietaMax, debug); std::cout << kountus << " detids out of " << kount << " have tracks > " << nMin << std::endl; char fname[50]; fout->cd(); TGraph *g_fac1 = new TGraph(kount, dets, cfacs); sprintf (fname, "Cfacs%d", loop); g_fac1->SetMarkerStyle(7); g_fac1->SetMarkerSize(5.0); g_fac1->Draw("AP"); g_fac1->Write(fname); TGraph *g_fac2 = new TGraph(kount, dets, wfacs); sprintf (fname, "Wfacs%d", loop); g_fac2->SetMarkerStyle(7); g_fac2->SetMarkerSize(5.0); g_fac2->Draw("AP"); g_fac2->Write(fname); TGraph *g_fac3 = new TGraph(kount, myId, cfacs); sprintf (fname, "CfacsVsMyId%d", loop); g_fac3->SetMarkerStyle(7); g_fac3->SetMarkerSize(5.0); g_fac3->Draw("AP"); g_fac3->Write(fname); TGraph *g_fac4 = new TGraph(kount, myId, wfacs); sprintf (fname, "WfacsVsMyId%d", loop); g_fac4->SetMarkerStyle(7); g_fac4->SetMarkerSize(5.0); g_fac4->Draw("AP"); g_fac4->Write(fname); TGraph *g_nTrk = new TGraph(kount, myId, nTrk); sprintf (fname, "nTrk"); if(loop==0){ g_nTrk->SetMarkerStyle(7); g_nTrk->SetMarkerSize(5.0); g_nTrk->Draw("AP"); g_nTrk->Write(fname); } std::cout << "The new factors are :" << std::endl; std::map<unsigned int, std::pair<double,double> >::const_iterator CprevItr = Cprev.begin(); unsigned int indx(0); for (; CprevItr != Cprev.end(); CprevItr++, indx++){ unsigned int detid = CprevItr->first; int subdet, depth, zside, ieta, iphi; unpackDetId(detid, subdet, zside, ieta, iphi, depth); std::cout << "DetId[" << indx << "] " << std::hex << detid << std::dec << "(" << ieta*zside << "," << depth << ") (nTrks:" << nTrks[detid] << ") : " << CprevItr->second.first << " +- " << CprevItr->second.second << std::endl; } double mean = (kountus > 0) ? (sumfactor/kountus) : 0; std::cout << "Mean deviation " << mean << " from 1 for " << kountus << " DetIds" << std::endl; h_cvg->SetBinContent(loop+1,mean); if (last) h_cvg->Write("Cvg0"); return mean; }
Double_t CalibTree::Loop(int loop) { char name[500]; bool debug=false; if (fChain == 0) return 0; Long64_t nentries = fChain->GetEntriesFast(); Long64_t nbytes = 0, nb = 0; std::map<unsigned int, std::pair<double,double> >SumW; std::map<unsigned int, unsigned int >nTrks; unsigned int mask(0xFF80), ntrkMax(0); for (Long64_t jentry=0; jentry<nentries;jentry++) { // for (Long64_t jentry=0; jentry<1000;jentry++) { Long64_t ientry = LoadTree(jentry); if (ientry < 0) break; nb = fChain->GetEntry(jentry); nbytes += nb; if(debug) std::cout << "***Entry (Track) Number : " << ientry << " p/eHCal/eMipDR/nDets : " << t_p << "/" << t_eHcal << "/" << t_eMipDR << "/" << (*t_DetIds).size() << std::endl; if (goodTrack()) { if (loop == 0) hprof_ndets->Fill(t_ieta, (*t_DetIds).size()); double Etot=0.0; for (unsigned int idet=0; idet<(*t_DetIds).size(); idet++) { double hitEn=0.0; unsigned int detid = (*t_DetIds)[idet] & mask; if (Cprev.find(detid) != Cprev.end()) hitEn = Cprev[detid] * (*t_HitEnergies)[idet]; else hitEn = (*t_HitEnergies)[idet]; Etot += hitEn; } for (unsigned int idet=0; idet<(*t_DetIds).size(); idet++) { unsigned int detid = (*t_DetIds)[idet] & mask; double hitEn=0.0; if (debug) std::cout << "idet " << idet << " detid/hitenergy : " << std::hex << (*t_DetIds)[idet] << ":" << detid << "/" << (*t_HitEnergies)[idet] << std::endl; if (Cprev.find(detid) != Cprev.end()) hitEn = Cprev[detid] * (*t_HitEnergies)[idet]; else hitEn = (*t_HitEnergies)[idet]; double Wi = hitEn/Etot; double Fac = (Wi* t_p) / Etot; if( SumW.find(detid) != SumW.end() ) { Wi += SumW[detid].first; Fac += SumW[detid].second; SumW[detid] = std::pair<double,double>(Wi,Fac); nTrks[detid]++; } else { SumW.insert( std::pair<unsigned int, std::pair<double,double> >(detid,std::pair<double,double>(Wi,Fac))); nTrks.insert(std::pair<unsigned int,unsigned int>(detid, 1)); } if (nTrks[detid] > ntrkMax) ntrkMax = nTrks[detid]; } } } std::map<unsigned int, std::pair<double,double> >::iterator SumWItr = SumW.begin(); unsigned int kount(0), mkount(0); double sumfactor(0); double dets[150], cfacs[150], wfacs[150], nTrk[150]; unsigned int ntrkCut = ntrkMax/10; for (; SumWItr != SumW.end(); SumWItr++) { if (debug) std::cout<< "Detid/SumWi/SumFac : " << SumWItr->first << " / " << (SumWItr->second).first << " / " << (SumWItr->second).second << std::endl; unsigned int detid = SumWItr->first; double factor = (SumWItr->second).second / (SumWItr->second).first; if(nTrks[detid]>ntrkCut) { if (factor > 1) sumfactor += (1-1/factor); else sumfactor += (1-factor); mkount++; } if (Cprev.find(detid) != Cprev.end()) { Cprev[detid] *= factor; cfacs[kount] = Cprev[detid]; } else { Cprev.insert( std::pair<unsigned int, double>(detid, factor) ); cfacs[kount] = factor; } int ieta = (detid>>7) & 0x3f; int zside= (detid&0x2000) ? 1 : -1; int depth= (detid>>14)&0x1F; wfacs[kount]= factor; dets[kount] = zside*(ieta+0.1*(depth-1)); nTrk[kount] = nTrks[detid]; kount++; } TGraph *g_fac, *g_fac2, *g_nTrk; g_fac = new TGraph(kount, dets, cfacs); sprintf(name, "Cfacs_detid_it%d", loop); fout->WriteTObject(g_fac, name); g_fac2 = new TGraph(kount, dets, wfacs); sprintf(name, "Wfacs_detid_it%d", loop); fout->WriteTObject(g_fac2, name); g_nTrk = new TGraph(kount, dets, nTrk); if (loop==0) fout->WriteTObject(g_nTrk, "nTrk_detid"); std::cout << "The new factors are :" << std::endl; std::map<unsigned int, double>::iterator CprevItr = Cprev.begin(); unsigned int indx(0); for (CprevItr=Cprev.begin(); CprevItr != Cprev.end(); CprevItr++, indx++){ unsigned int detid = CprevItr->first; int ieta = (detid>>7) & 0x3f; int zside= (detid&0x2000) ? 1 : -1; int depth= (detid>>14)&0x1F; std::cout << "DetId[" << indx << "] " << std::hex << detid << std::dec << "(" << ieta*zside << "," << depth << ") ( nTrks:" << nTrks[detid] << ") : " << CprevItr->second << std::endl; } double mean = (mkount > 0) ? (sumfactor/mkount) : 0; std::cout << "Mean deviation " << mean << " from 1 for " << mkount << ":" << kount << " DetIds" << std::endl; return mean; }
void CalibTree::makeplots(double rmin, double rmax, int ietaMax, bool useweight, double fraction, bool debug) { if (fChain == 0) return; Long64_t nentryTot = fChain->GetEntriesFast(); Long64_t nentries = (fraction > 0.01 && fraction < 0.99) ? (Long64_t)(fraction*nentryTot) : nentryTot; // Book the histograms std::map<int,std::pair<TH1D*,TH1D*> > histos; for (int ieta=-ietaMax; ieta<=ietaMax; ++ieta) { char name[20], title[100]; sprintf(name,"begin%d",ieta); if (ieta==0) sprintf(title,"Ratio at start"); else sprintf(title,"Ratio at start for i#eta=%d",ieta); TH1D* h1 = new TH1D(name,title,50,rmin,rmax); h1->Sumw2(); sprintf(name,"end%d",ieta); if (ieta==0) sprintf(title,"Ratio at the end"); else sprintf(title,"Ratio at the end for i#eta=%d",ieta); TH1D* h2 = new TH1D(name,title,50,rmin,rmax); h2->Sumw2(); histos[ieta] = std::pair<TH1D*,TH1D*>(h1,h2); } //Fill the histograms Long64_t nbytes(0), nb(0); for (Long64_t jentry=0; jentry<nentries;jentry++) { Long64_t ientry = LoadTree(jentry); if (ientry < 0) break; if (std::find(entries.begin(), entries.end(), jentry) != entries.end()) break; nb = fChain->GetEntry(jentry); nbytes += nb; if (goodTrack()) { double Etot(0); for (unsigned int idet=0; idet<(*t_DetIds).size(); idet++) { double hitEn(0); unsigned int id = (*t_DetIds)[idet]; unsigned int detid = truncateId(id,truncateFlag_,false); if (Cprev.find(detid) != Cprev.end()) hitEn = Cprev[detid].first * (*t_HitEnergies)[idet]; else hitEn = (*t_HitEnergies)[idet]; if (cFactor_) hitEn *= cFactor_->getCorr(t_Run,id); Etot += hitEn; } double evWt = (useweight) ? t_EventWeight : 1.0; double pmom = (useGen_ && (t_gentrackP > 0)) ? t_gentrackP : t_p; double ratioi = t_eHcal/(pmom-t_eMipDR); double ratiof = Etot/(pmom-t_eMipDR); if (t_ieta >= -ietaMax && t_ieta <= ietaMax && t_ieta != 0) { if (ratioi>=rmin && ratioi<=rmax) { histos[0].first->Fill(ratioi,evWt); histos[t_ieta].first->Fill(ratioi,evWt); } if (ratiof>=rmin && ratiof<=rmax) { histos[0].second->Fill(ratiof,evWt); histos[t_ieta].second->Fill(ratiof,evWt); } } } } //Fit the histograms TH1D *hbef1 = new TH1D("Eta1Bf","Mean vs i#eta",2*ietaMax,-ietaMax,ietaMax); TH1D *hbef2 = new TH1D("Eta2Bf","Median vs i#eta",2*ietaMax,-ietaMax,ietaMax); TH1D *haft1 = new TH1D("Eta1Af","Mean vs i#eta",2*ietaMax,-ietaMax,ietaMax); TH1D *haft2 = new TH1D("Eta2Af","Median vs i#eta",2*ietaMax,-ietaMax,ietaMax); for (int ieta=-ietaMax; ieta<=ietaMax; ++ieta) { int bin = (ieta < 0) ? (ieta+ietaMax+1) : (ieta+ietaMax); TH1D* h1 = histos[ieta].first; double mean1 = h1->GetMean(); double err1 = h1->GetMeanError(); std::pair<double,double> fit1 = fitMean(h1,1); if (debug) { std::cout << ieta << " " << h1->GetName() << " " << mean1 << " +- " << err1 << " and " << fit1.first <<" +- " << fit1.second << std::endl; } if (ieta != 0) { hbef1->SetBinContent(bin,mean1); hbef1->SetBinError(bin,err1); hbef2->SetBinContent(bin,fit1.first); hbef2->SetBinError(bin,fit1.second); } h1->Write(); TH1D* h2 = histos[ieta].second; double mean2 = h2->GetMean(); double err2 = h2->GetMeanError(); std::pair<double,double> fit2 = fitMean(h2,1); if (debug) { std::cout << ieta << " " << h2->GetName() << " " << mean2 << " +- " << err2 << " and " << fit2.first <<" +- " << fit2.second << std::endl; } if (ieta != 0) { haft1->SetBinContent(bin,mean2); haft1->SetBinError(bin,err2); haft2->SetBinContent(bin,fit2.first); haft2->SetBinError(bin,fit2.second); } h2->Write(); } fitPol0(hbef1,debug); fitPol0(hbef2,debug); fitPol0(haft1,debug); fitPol0(haft2,debug); }