//________________________________________________________________ void KVCanvas::DynamicZoom(Int_t Sign, Int_t px, Int_t py) { // Zoom in or out of histogram with mouse wheel // Info("DynamicZoom","px=%d py=%d",px,py); if (!fSelected) return; TH2* TheHisto = (TH2*) FindHisto();//fSelected; Double_t percent = 0.15 - Sign * 0.05; Int_t dX = 0; Int_t dY = 0; Double_t ppx = AbsPixeltoX(px); Double_t ppy = AbsPixeltoY(py); TAxis* ax = TheHisto->GetXaxis(); Int_t NbinsXtmp = ax->GetNbins(); Int_t X0tmp = ax->GetFirst(); Int_t X1tmp = ax->GetLast(); Int_t step = TMath::Min(TMath::Max(1, (Int_t)(percent * (X1tmp - X0tmp))), NbinsXtmp / 2); step *= Sign; X0tmp = TMath::Min(TMath::Max(X0tmp + step, 1), X1tmp - step); X1tmp = TMath::Max(TMath::Min(X1tmp - step, NbinsXtmp), X0tmp); if (X0tmp >= X1tmp) X0tmp = X1tmp - 1; if (Sign > 0) dX = (Int_t)(X0tmp + (X1tmp - X0tmp) * 0.5 - ax->FindBin(ppx)); if ((X0tmp - dX) < 0) ax->SetRange(0, X1tmp - X0tmp); else if ((X1tmp - dX) > ax->GetNbins()) ax->SetRange(ax->GetNbins() - (X1tmp - X0tmp), ax->GetNbins()); else ax->SetRange(X0tmp - dX, X1tmp - dX); ax = TheHisto->GetYaxis(); Int_t NbinsYtmp = ax->GetNbins(); Int_t Y0tmp = ax->GetFirst(); Int_t Y1tmp = ax->GetLast(); step = TMath::Min(TMath::Max(1, (Int_t)(percent * (Y1tmp - Y0tmp))), NbinsYtmp / 2); step *= Sign; Y0tmp = TMath::Min(TMath::Max(Y0tmp + step, 1), Y1tmp - step); Y1tmp = TMath::Max(TMath::Min(Y1tmp - step, NbinsYtmp), Y0tmp); if (Y0tmp >= Y1tmp) Y0tmp = Y1tmp - 1; if (Sign > 0) dY = (Int_t)(Y0tmp + (Y1tmp - Y0tmp) * 0.5 - ax->FindBin(ppy)); if ((Y0tmp - dY) < 0) ax->SetRange(0, Y1tmp - Y0tmp); else if ((Y1tmp - dY) > ax->GetNbins()) ax->SetRange(ax->GetNbins() - (Y1tmp - Y0tmp), ax->GetNbins()); else ax->SetRange(Y0tmp - dY, Y1tmp - dY); Modified(); Update(); return; }
//________________________________________________________________ void KVCanvas::DynamicZoomTH1(Int_t Sign, Int_t px, Int_t) { // Zoom in or out of histogram with mouse wheel if (!fSelected) return; TH1* TheHisto = (TH1*) FindHisto();//fSelected; Double_t percent = 0.15 - Sign * 0.05; Int_t dX = 0; px = AbsPixeltoX(px); TAxis* ax = TheHisto->GetXaxis(); Int_t NbinsXtmp = ax->GetNbins(); Int_t X0tmp = ax->GetFirst(); Int_t X1tmp = ax->GetLast(); Int_t step = TMath::Min(TMath::Max(1, (Int_t)(percent * (X1tmp - X0tmp))), NbinsXtmp / 2); step *= Sign; X0tmp = TMath::Min(TMath::Max(X0tmp + step, 1), X1tmp - step); X1tmp = TMath::Max(TMath::Min(X1tmp - step, NbinsXtmp), X0tmp); if (X0tmp >= X1tmp) X0tmp = X1tmp - 1; if (Sign > 0) dX = (Int_t)(X0tmp + (X1tmp - X0tmp) * 0.5 - ax->FindBin(px)); if ((X0tmp - dX) < 0) ax->SetRange(0, X1tmp - X0tmp); else if ((X1tmp - dX) > ax->GetNbins()) ax->SetRange(ax->GetNbins() - (X1tmp - X0tmp), ax->GetNbins()); else ax->SetRange(X0tmp - dX, X1tmp - dX); Modified(); Update(); return; }
double computeHistoMedian(TH1F * histo) { // Get the x axis TAxis * ax = histo->GetXaxis(); // Get the number of bins const int nBins = histo->GetNbinsX(); double cont[nBins]; double x[nBins]; // Loop over all the bins for (int bin=ax->GetFirst(); bin<=ax->GetLast(); bin++){ x[bin] = histo->GetBinCenter(bin); cont[bin] = histo->GetBinContent(bin); } return TMath::Median(nBins, x, cont); }
double computePValue(TH1F * histo, double s) { // Get the x axis TAxis * ax = histo->GetXaxis(); double integ = histo->Integral(); double nAboveS = 0; // Loop over all the bins for (int bin=ax->GetFirst(); bin<=ax->GetLast(); bin++){ if(histo->GetBinCenter(bin) > s) { nAboveS += histo->GetBinContent(bin); } } double old = nAboveS/integ; TString gName = "gaus_"+TString(histo->GetName()); TF1 *gaus = new TF1(gName.Data(),"gaus",0.2,100); histo->Fit(gaus,"Q","",0.2,100); double pvalue = gaus->Integral(s,10)/gaus->Integral(-10,10); cout << " p-value computation for S: " << s << " with histo: " << old << " with fit: " << pvalue << endl; return pvalue; }
//______________________________________________________________________________ void KVCanvas::HandleInput(EEventType event, Int_t px, Int_t py) { // Handle Input Events. // // Handle input events, like button up/down in current canvas. if (fFreezed) return; TPad* pad; TPad* prevSelPad = (TPad*) fSelectedPad; TObject* prevSelObj = fSelected; fPadSave = (TPad*)gPad; cd(); // make sure this canvas is the current canvas fEvent = event; fEventX = px; fEventY = py; Int_t sign = 0; Bool_t sendOrder = true; if (fHasDisabledClasses && fSelected) { if (fDisabledClasses.Contains(fSelected->ClassName())) sendOrder = false; } if (fHasDisabledObject && fSelected) { if (fDisabledObjects.Contains(fSelected)) sendOrder = false; } switch (event) { case kMouseMotion: // highlight object tracked over pad = Pick(px, py, prevSelObj); if (!pad) return; EnterLeave(prevSelPad, prevSelObj); gPad = pad; // don't use cd() we will use the current // canvas via the GetCanvas member and not via // gPad->GetCanvas if (sendOrder) fSelected->ExecuteEvent(event, px, py); RunAutoExec(); if (fAgeOfEmpire && (fSelected->InheritsFrom("TH2"))) { TH2* TheHisto = (TH2*) FindHisto();//fSelected; Double_t size = 0.4 - 0.35 * fVenerMode; Int_t dX = 0; Int_t dY = 0; Double_t ppx = AbsPixeltoX(px); Double_t ppy = AbsPixeltoY(py); TAxis* ax = TheHisto->GetXaxis(); Int_t X0 = ax->GetFirst(); Int_t X1 = ax->GetLast(); Int_t NbinsX = ax->GetNbins(); px = ax->FindBin(ppx); Double_t ddX = (X1 + X0) * 0.5 - px; Double_t distX = TMath::Abs(ddX) / (X1 - X0); if (distX >= 0.5) return; TAxis* ay = TheHisto->GetYaxis(); Int_t Y0 = ay->GetFirst(); Int_t Y1 = ay->GetLast(); Int_t NbinsY = ay->GetNbins(); py = ay->FindBin(ppy); Double_t ddY = (Y1 + Y0) * 0.5 - py; Double_t distY = TMath::Abs(ddY) / (Y1 - Y0); if (distY >= 0.5) return; if ((distX <= size) && (distY <= size)) return; dX = TMath::Nint(ddX * (0.05 + 0.05 * fVenerMode)); dY = TMath::Nint(ddY * (0.05 + 0.05 * fVenerMode)); if (TMath::Abs(dX) < 1) dX = TMath::Sign(1., ddX); if (TMath::Abs(dY) < 1) dY = TMath::Sign(1., ddY); Bool_t up = false; if ((X0 - dX > 0) && (X1 - dX < NbinsX)) { ax->SetRange(X0 - dX, X1 - dX); up = true; } if ((Y0 - dY > 0) && (Y1 - dY < NbinsY)) { ay->SetRange(Y0 - dY, Y1 - dY); up = true; } if (up) { Modified(); Update(); } } break; case kMouseEnter: // mouse enters canvas if (!fDoubleBuffer) FeedbackMode(kTRUE); break; case kMouseLeave: // mouse leaves canvas { // force popdown of tooltips TObject* sobj = fSelected; TPad* spad = fSelectedPad; fSelected = 0; fSelectedPad = 0; EnterLeave(prevSelPad, prevSelObj); fSelected = sobj; fSelectedPad = spad; if (!fDoubleBuffer) FeedbackMode(kFALSE); } break; case kButton1Double: // triggered on the second button down within 350ms and within // 3x3 pixels of the first button down, button up finishes action case kButton1Down: // find pad in which input occured pad = Pick(px, py, prevSelObj); if (!pad) return; gPad = pad; // don't use cd() because we won't draw in pad // we will only use its coordinate system if (fSelected) { FeedbackMode(kTRUE); // to draw in rubberband mode fSelected->ExecuteEvent(event, px, py); RunAutoExec(); if (fSelected->InheritsFrom("TH2")) { oldx = GetEventX(); oldy = GetEventY(); xmin = AbsPixeltoX(oldx); ymin = AbsPixeltoY(oldy); gVirtualX->DrawBox(XtoAbsPixel(xmin), YtoAbsPixel(ymin), oldx, oldy, TVirtualX::kHollow); } } break; case kButton1Motion: if (fSelected) { if (fSelected->InheritsFrom("TH2")) { gVirtualX->DrawBox(XtoAbsPixel(xmin), YtoAbsPixel(ymin), oldx, oldy, TVirtualX::kHollow); oldx = GetEventX(); oldy = GetEventY(); gVirtualX->DrawBox(XtoAbsPixel(xmin), YtoAbsPixel(ymin), oldx, oldy, TVirtualX::kHollow); moved = true; } } case kButton1ShiftMotion: //8 == kButton1Motion + shift modifier if (fSelected) { gPad = fSelectedPad; if (sendOrder) fSelected->ExecuteEvent(event, px, py); gVirtualX->Update(); if (!fSelected->InheritsFrom(TAxis::Class())) { Bool_t resize = kFALSE; if (fSelected->InheritsFrom(TBox::Class())) resize = ((TBox*)fSelected)->IsBeingResized(); if (fSelected->InheritsFrom(TVirtualPad::Class())) resize = ((TVirtualPad*)fSelected)->IsBeingResized(); if ((!resize && TestBit(kMoveOpaque)) || (resize && TestBit(kResizeOpaque))) { gPad = fPadSave; Update(); FeedbackMode(kTRUE); } } RunAutoExec(); } break; case kButton1Up: if (fSelected) { gPad = fSelectedPad; if (sendOrder) fSelected->ExecuteEvent(event, px, py); RunAutoExec(); if (fPadSave) gPad = fPadSave; else { gPad = this; fPadSave = this; } if (fSelected->InheritsFrom("TH2") && moved && !fSelected->InheritsFrom("TH3")) { xmax = AbsPixeltoX(GetEventX()); ymax = AbsPixeltoY(GetEventY()); Double_t toto = 0; if (xmax < xmin) { toto = xmax; xmax = xmin; xmin = toto; } if (ymax < ymin) { toto = ymax; ymax = ymin; ymin = toto; } ZoomSelected((TH2*)FindHisto()); // ZoomSelected((TH2*)fSelected); moved = false; } Update(); // before calling update make sure gPad is reset } break; //*-*---------------------------------------------------------------------- case kButton2Down: // find pad in which input occured pad = Pick(px, py, prevSelObj); if (!pad) return; gPad = pad; // don't use cd() because we won't draw in pad // we will only use its coordinate system FeedbackMode(kTRUE); if (!fSelected->InheritsFrom("TH1")) fSelected->Pop(); // pop object to foreground pad->cd(); // and make its pad the current pad if (fSelected->InheritsFrom("TH2") && !fSelected->InheritsFrom("TH3")) { // implement pan & scan X0 = px; Y0 = py; // u clikd here theXaxis = ((TH2*)FindHisto())->GetXaxis(); theYaxis = ((TH2*)FindHisto())->GetYaxis(); NXbins = theXaxis->GetNbins(); // maximum bin number in X NYbins = theYaxis->GetNbins(); // maximum bin number in Y Xf1 = Xfirst0 = theXaxis->GetFirst(); // initial displayed bin range in X Xl1 = Xlast0 = theXaxis->GetLast(); Yf1 = Yfirst0 = theYaxis->GetFirst(); // initial displayed bin range in Y Yl1 = Ylast0 = theYaxis->GetLast(); // size of axes in pixels Int_t pixelWidthX = gPad->XtoAbsPixel(gPad->GetUxmax()) - gPad->XtoAbsPixel(gPad->GetUxmin()); Int_t pixelWidthY = gPad->YtoAbsPixel(gPad->GetUymax()) - gPad->YtoAbsPixel(gPad->GetUymin()); // sizes of bins in pixels NdisXbins = Xlast0 - Xfirst0 + 1; NdisYbins = Ylast0 - Yfirst0 + 1; XbinPixel = pixelWidthX / (1.0 * NdisXbins); YbinPixel = pixelWidthY / (1.0 * NdisYbins); } if (gDebug) printf("Current Pad: %s / %s\n", pad->GetName(), pad->GetTitle()); // loop over all canvases to make sure that only one pad is highlighted { TIter next(gROOT->GetListOfCanvases()); TCanvas* tc; while ((tc = (TCanvas*)next())) tc->Update(); } /*if (pad->GetGLDevice() != -1 && fSelected) fSelected->ExecuteEvent(event, px, py);*/ break; // don't want fPadSave->cd() to be executed at the end case kButton2Motion: //was empty! if (fSelected && fSelected->InheritsFrom("TH2") && !fSelected->InheritsFrom("TH3")) { // implement pan & scan Int_t dX = px - X0; // how far have i moved ? Int_t dY = py - Y0; Int_t dXbins = dX / XbinPixel; Int_t dYbins = dY / YbinPixel; Bool_t changed = kFALSE; Int_t newXfirst = Xfirst0 - dXbins; Int_t newXlast; if (newXfirst < 1) { newXfirst = 1; newXlast = NdisXbins; } else { newXlast = Xlast0 - dXbins; if (newXlast > NXbins) { newXlast = NXbins; newXfirst = newXlast - NdisXbins + 1; } } if (newXfirst != Xf1) { Xf1 = newXfirst; Xl1 = newXlast; theXaxis->SetRange(Xf1, Xl1); changed = kTRUE; } Int_t newYfirst = Yfirst0 - dYbins; Int_t newYlast; if (newYfirst < 1) { newYfirst = 1; newYlast = NdisYbins; } else { newYlast = Ylast0 - dYbins; if (newYlast > NYbins) { newYlast = NYbins; newYfirst = newYlast - NdisYbins + 1; } } if (newYfirst != Yf1) { Yf1 = newYfirst; Yl1 = newYlast; theYaxis->SetRange(Yf1, Yl1); changed = kTRUE; } if (changed) { Modified(); Update(); } } case kButton2Up: if (fSelected) { gPad = fSelectedPad; if (sendOrder) fSelected->ExecuteEvent(event, px, py); RunAutoExec(); } break; case kButton2Double: break; //*-*---------------------------------------------------------------------- case kButton3Down: // popup context menu pad = Pick(px, py, prevSelObj); if (!pad) return; if (!fDoubleBuffer) FeedbackMode(kFALSE); if (fContextMenu && !fSelected->TestBit(kNoContextMenu) && !pad->TestBit(kNoContextMenu) && !TestBit(kNoContextMenu)) { if (sendOrder) fContextMenu->Popup(px, py, fSelected, this, pad); else fSelected->ExecuteEvent(event, px, py); } break; case kButton3Motion: break; case kButton3Up: if (!fDoubleBuffer) FeedbackMode(kTRUE); break; case kButton3Double: break; case kKeyDown: // Info("HandleInput","Key down: %d %d",px,py); break; case kKeyUp: // Info("HandleInput","Key up: %d %d",px,py); break; case kKeyPress: if (!fSelectedPad || !fSelected) return; gPad = fSelectedPad; // don't use cd() because we won't draw in pad // we will only use its coordinate system fSelected->ExecuteEvent(event, px, py); HandleKey(px, py); RunAutoExec(); break; case kButton1Shift: // Try to select pad = Pick(px, py, prevSelObj); if (!pad) return; EnterLeave(prevSelPad, prevSelObj); gPad = pad; // don't use cd() we will use the current // canvas via the GetCanvas member and not via // gPad->GetCanvas fSelected->ExecuteEvent(event, px, py); RunAutoExec(); break; case kWheelUp: case kWheelDown: pad = Pick(px, py, prevSelObj); if (!pad) return; sign = (event == kWheelUp ? 1 : -1); gPad = pad; if (fSelected->InheritsFrom("TAxis")) fSelected->ExecuteEvent(event, px, py); else if (fSelected->InheritsFrom("TH2")) DynamicZoom(sign, px, py); RunAutoExec(); break; default: break; } if (fPadSave && event != kButton2Down) fPadSave->cd(); if (event != kMouseLeave) { // signal was already emitted for this event ProcessedEvent(event, px, py, fSelected); // emit signal DrawEventStatus(event, px, py, fSelected); } }
TauAnalysisSelector::TauAnalysisSelector(const std::string& puWeight, bool isEmbedded, const std::string& embeddingWTauMuFile, const std::string& embeddingWTauMuPath, const std::string& mcTauMultiplicity, const std::string& mcTauMode, const std::string& embeddingNormalizationMode, TH1 *embeddingMuonWeights): BaseSelector(), //fMuons("Emb"), fGenTaus(isEmbedded ? "gentausOriginal" : "gentaus", true), fGenTausEmbedded("gentausEmbedded", true), fPuWeightName(puWeight), fIsEmbedded(isEmbedded), fEmbeddingWTauMuWeights(0), fMCTauMultiplicity(parseMCTauMultiplicity(mcTauMultiplicity)), fMCTauMode(parseMCTauMode(mcTauMode)), fEmbeddingNormalizationMode(parseEmbeddingNormalizationMode(embeddingNormalizationMode)), fEmbeddingMuonWeights(embeddingMuonWeights), cAll(fEventCounter.addCounter("All events")), //cElectronVeto(fEventCounter.addCounter("Electron veto")), cGeneratorWeight(fEventCounter.addCounter("Vis. pt weight")), cTauBRWeight(fEventCounter.addCounter("Tau BR weighting")), cGenTauFound(fEventCounter.addCounter("Gen tau found")), cTauMCSelection(fEventCounter.addCounter("Tau MC requirement")), cOnlyWMu(fEventCounter.addCounter("Only W->mu")), cWTauMuWeight(fEventCounter.addCounter("W->tau->mu weighting")), cTriggerEffWeight(fEventCounter.addCounter("Muon trigger eff weighting")), cIdEffWeight(fEventCounter.addCounter("Muon ID eff weighting")), cMuonWeight(fEventCounter.addCounter("Muon corr weighting (from argument)")), cJetSelection(fEventCounter.addCounter("Jet selection")), cPrimaryVertex(fEventCounter.addCounter("Primary vertex")), cAllTauCandidates(fEventCounter.addCounter(">= 1 tau candidate")), cPrePtCut(fEventCounter.addCounter("Pre Pt cut")), cDecayModeFinding(fEventCounter.addCounter("Decay mode finding")), cEtaCut(fEventCounter.addCounter("Eta cut")), cPtCut(fEventCounter.addCounter("Pt cut")), cLeadingTrackPtCut(fEventCounter.addCounter("Leading track pt")), cEcalCracks(fEventCounter.addCounter("ECAL fiducial: cracks")), cEcalGap(fEventCounter.addCounter("ECAL fiducial: gap")), cAgainstElectron(fEventCounter.addCounter("Against electron")), cAgainstMuon(fEventCounter.addCounter("Against muon")), cIsolation(fEventCounter.addCounter("Isolation")), cOneProng(fEventCounter.addCounter("One prong")), cRtau(fEventCounter.addCounter("Rtau")), cMuTrigger(fEventCounter.addCounter("Mu trigger")) { if(isEmbedded && !embeddingWTauMuFile.empty()) { TFile *file = TFile::Open(embeddingWTauMuFile.c_str()); TEfficiency *eff = dynamic_cast<TEfficiency *>(file->Get(embeddingWTauMuPath.c_str())); TAxis *xaxis = eff->GetPassedHistogram()->GetXaxis(); fEmbeddingWTauMuWeights = new TH1F("weights", "weights", xaxis->GetNbins(), xaxis->GetBinLowEdge(xaxis->GetFirst()), xaxis->GetBinUpEdge(xaxis->GetLast())); fEmbeddingWTauMuWeights->SetDirectory(0); for(int bin=1; bin <= xaxis->GetNbins(); ++bin) { fEmbeddingWTauMuWeights->SetBinContent(bin, eff->GetEfficiency(bin)); std::cout << "Bin " << bin << " low edge " << fEmbeddingWTauMuWeights->GetXaxis()->GetBinLowEdge(bin) << " value " << fEmbeddingWTauMuWeights->GetBinContent(bin) << std::endl; } fEmbeddingWTauMuWeights->SetBinContent(xaxis->GetNbins()+1, fEmbeddingWTauMuWeights->GetBinContent(xaxis->GetNbins())); file->Close(); } if(isEmbedded) { fMuons.setIdEfficiencyName("efficiency_Run2011AB"); fMuons.setTriggerEfficiencyName("efficiency_trigger"); } }