int getifaddrs(struct ifaddrs **ifap) { int fd4, fd6; int nif4, nif6 = 0; struct lifreq *ifr4 = NULL; struct lifreq *ifr6 = NULL; struct ifaddrs *ifa = NULL; char *buf; if ((fd4 = socket(AF_INET, SOCK_DGRAM, 0)) == -1) return (-1); if ((fd6 = socket(AF_INET6, SOCK_DGRAM, 0)) == -1 && errno != EAFNOSUPPORT) { (void) close(fd4); return (-1); } if ((nif4 = get_lifreq(fd4, &ifr4)) == -1 || (fd6 != -1 && (nif6 = get_lifreq(fd6, &ifr6)) == -1)) goto failure; if (nif4 == 0 && nif6 == 0) { *ifap = NULL; return (0); } ifa = malloc(nbytes(ifr4, nif4, sizeof (struct sockaddr_in)) + nbytes(ifr6, nif6, sizeof (struct sockaddr_in6))); if (ifa == NULL) goto failure; buf = (char *)(ifa + nif4 + nif6); if (populate(ifa, fd4, ifr4, nif4, AF_INET, &buf) == -1) goto failure; if (nif4 > 0 && nif6 > 0) ifa[nif4 - 1].ifa_next = ifa + nif4; if (populate(ifa + nif4, fd6, ifr6, nif6, AF_INET6, &buf) == -1) goto failure; return (0); failure: free(ifa); (void) close(fd4); if (fd6 != -1) (void) close(fd6); free(ifr4); free(ifr6); return (-1); }
void clSFTP::Write(const wxFileName& localFile, const wxString& remotePath) throw(clException) { if(!m_connected) { throw clException("scp is not initialized!"); } if(!localFile.Exists()) { throw clException(wxString() << "scp::Write file '" << localFile.GetFullPath() << "' does not exist!"); } wxFFile fp(localFile.GetFullPath(), "rb"); if(!fp.IsOpened()) { throw clException(wxString() << "scp::Write could not open file '" << localFile.GetFullPath() << "'. " << ::strerror(errno)); } char buffer[4096]; wxMemoryBuffer memBuffer; size_t nbytes(0); while(!fp.Eof()) { nbytes = fp.Read(buffer, sizeof(buffer)); if(nbytes == 0) break; memBuffer.AppendData(buffer, nbytes); } fp.Close(); Write(memBuffer, remotePath); }
Point frdrawsel0(Frame *f, Point pt, ulong p0, ulong p1, Image *back, Image *text) { Frbox *b; int nb, nr, w, x, trim; Point qt; uint p; char *ptr; p = 0; b = f->box; trim = 0; for(nb=0; nb<f->nbox && p<p1; nb++){ nr = b->nrune; if(nr < 0) nr = 1; if(p+nr <= p0) goto Continue; if(p >= p0){ qt = pt; _frcklinewrap(f, &pt, b); /* fill in the end of a wrapped line */ if(pt.y > qt.y) draw(f->b, Rect(qt.x, qt.y, f->r.max.x, pt.y), back, nil, qt); } ptr = (char*)b->ptr; if(p < p0){ /* beginning of region: advance into box */ ptr += nbytes(ptr, p0-p); nr -= (p0-p); p = p0; } trim = 0; if(p+nr > p1){ /* end of region: trim box */ nr -= (p+nr)-p1; trim = 1; } if(b->nrune<0 || nr==b->nrune) w = b->wid; else w = stringnwidth(f->font, ptr, nr); x = pt.x+w; if(x > f->r.max.x) x = f->r.max.x; draw(f->b, Rect(pt.x, pt.y, x, pt.y+f->font->height), back, nil, pt); if(b->nrune >= 0) stringnbg(f->b, pt, text, ZP, f->font, ptr, nr, back, ZP); pt.x += w; Continue: b++; p += nr; } /* if this is end of last plain text box on wrapped line, fill to end of line */ if(p1>p0 && b>f->box && b<f->box+f->nbox && b[-1].nrune>0 && !trim){ qt = pt; _frcklinewrap(f, &pt, b); if(pt.y > qt.y) draw(f->b, Rect(qt.x, qt.y, f->r.max.x, pt.y), back, nil, qt); } return pt; }
void CalibSort::Loop() { // In a ROOT session, you can do: // Root > .L CalibSort.C // Root > CalibSort t // Root > t.GetEntry(12); // Fill t data members with entry number 12 // Root > t.Show(); // Show values of entry 12 // Root > t.Show(16); // Read and show values of entry 16 // Root > t.Loop(); // Loop on all entries // // This is the loop skeleton where: // jentry is the global entry number in the chain // ientry is the entry number in the current Tree // Note that the argument to GetEntry must be: // jentry for TChain::GetEntry // ientry for TTree::GetEntry and TBranch::GetEntry // // To read only selected branches, Insert statements like: // METHOD1: // fChain->SetBranchStatus("*",0); // disable all branches // fChain->SetBranchStatus("branchname",1); // activate branchname // METHOD2: replace line // fChain->GetEntry(jentry); //read all branches //by b_branchname->GetEntry(ientry); //read only this branch if (fChain == 0) return; std::ofstream fileout; if ((flag_%10)==1) { fileout.open("events.txt", std::ofstream::out); std::cout << "Opens events.txt in output mode\n"; } else { fileout.open("events.txt", std::ofstream::app); std::cout << "Opens events.txt in append mode\n"; } fileout << "Input file: " << fname_ << " Directory: " << dirnm_ << " Prefix: " << prefix_ << "\n"; Long64_t nbytes(0), nb(0), good(0); Long64_t nentries = fChain->GetEntriesFast(); for (Long64_t jentry=0; jentry<nentries;jentry++) { Long64_t ientry = LoadTree(jentry); if (ientry < 0) break; nb = fChain->GetEntry(jentry); nbytes += nb; double cut = (t_p > 20) ? 10.0 : 0.0; if ((flag_/10)%10 > 0) std::cout << "Entry " << jentry << " p " << t_p << " Cuts " << t_qltyFlag << "|" << t_selectTk << "|" << (t_hmaxNearP < cut) << "|" << (t_eMipDR < mipCut_) << std::endl; if (t_qltyFlag && t_selectTk && (t_hmaxNearP<cut) && (t_eMipDR<mipCut_)) { good++; fileout << good << " " << jentry << " " << t_Run << " " << t_Event << " " << t_ieta << " " << t_p << std::endl; } } fileout.close(); std::cout << "Writes " << good << " events in the file events.txt from " << nentries << " entries" << std::endl; }
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; }
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); }