//_______________________________________________________________________________________
static void AddGrid()
{ 
  TVirtualPad *thisPad = qPad();

  if (thisPad) {
 
    TView *view = thisPad->GetView(); 
    if (!view) return;
    Double_t min[3],max[3];
    view->GetRange(min,max);

    TList *list      = thisPad->GetListOfPrimitives();
    TString histName = thisPad->GetName();
    TH2F *m_DummyHist = 0; 
    const Char_t *dummyName = "Axis3D";
    histName += dummyName;
    m_DummyHist = list->FindObject(histName.Data());
    if (!m_DummyHist) { 
      m_DummyHist = new TH2F(histName.Data(),"",1,min[0],max[0],1,min[1],max[1]);
      m_DummyHist->SetDirectory(0);
      m_DummyHist->Draw("surf,same");
    }
    m_DummyHist->GetXaxis()->SetLimits(min[0],max[0]);
    m_DummyHist->GetYaxis()->SetLimits(min[1],max[1]);
    m_DummyHist->GetZaxis()->SetLimits(min[2],max[2]);
 
    thisPad->Modified();
    thisPad->Update();
  }
}
/* *********** multi-pad canvases ******************** */
void setLogy(TCanvas *c, bool on = true) {
    c->Modified();
    c->Update();
    //gSystem->ProcessEvents();
    TObject *obj;
    TIter    next(c->GetListOfPrimitives());
    while ((obj = next())) {
      if (obj->InheritsFrom(TVirtualPad::Class())) {
	TVirtualPad *pad = (TVirtualPad*)obj;
	pad->Modified();
	pad->Update();
	pad->SetLogy(on);
	pad->Modified();
	pad->Update();
      }
    }
}
//_______________________________________________________________________________________
static void SetBackround(Color_t color, TVirtualPad *pad=0)
{
  TVirtualPad *thisPad = pad;
  if (!thisPad) thisPad = qPad();
  if (thisPad)  {
    thisPad->SetFillColor(color);
    thisPad->Modified();
    thisPad->Update();
  }
}
//_______________________________________________________________________________________
static void Inscrease3DScale()
{
  TVirtualPad *thisPad = qPad();
  if (thisPad) {
    TView *view = thisPad->GetView(); 
    if (!view) return;
    Double_t min[3],max[3];
    view->GetRange(min,max);
    int i;
    for (i=0;i<3; i++) {max[i] *= 0.8; min[i]=max[i]*0.1;}
    view->SetRange(min,max);
    thisPad->Modified();
    thisPad->Update();
  }
}
//_______________________________________________________________________________________
static void Centered3DImages()
{
  // This macro prints out the sizes of the sekected 3d pad
  TVirtualPad *thisPad = qPad();
  if (thisPad) {
    TView *view = thisPad->GetView(); 
    if (!view) return;
    Double_t min[3],max[3];
    view->GetRange(min,max);
    int i;
    for (i=0;i<3; i++) min[i]=-max[i];
    view->SetRange(min,max);
    thisPad->Modified();
    thisPad->Update();
 }
}
//_______________________________________________________________________________________
static void RotateView(Float_t phi, Float_t theta, TVirtualPad *pad=0)
{
  TVirtualPad *thisPad = pad;
  if (!thisPad) thisPad = qPad();
  if (thisPad) {
    TView *view = thisPad->GetView(); 
    if (view) {
      Int_t iret;
      Float_t p = phi;
      Float_t t = theta;
      view->SetView(p, t, 0, iret);
      thisPad->SetPhi(-90-p);
      thisPad->SetTheta(90-t);
      thisPad->Modified();
      thisPad->Update();
    }
  }
}
//_______________________________________________________________________________________
static void AdjustScales()
{
  TVirtualPad *thisPad = qPad();
  if (thisPad) {
    TView *view = thisPad->GetView(); 
    if (!view) return;
    Double_t min[3],max[3];
    view->GetRange(min,max);
    int i;
    Double_t maxSide = 0;
    // Find the largest side
    for (i=0;i<3; i++) maxSide = TMath::Max(maxSide,max[i]-min[i]);
    //Adjust scales:
    for (i=0;i<3; i++) max[i] += maxSide - (max[i]-min[i]);
    view->SetRange(min,max);
    thisPad->Modified();
    thisPad->Update();
 }
}
Exemple #8
0
void KVSpIdGUI::SpiderIdentification()
{
   if ((!fHisto) || (!fGrid)) return;

   TVirtualPad* pad = fGrid->GetPad();
   fGrid->UnDraw();

   fZp = fZpEntry->GetIntNumber();
   if (!fUserParameter) fSpFactor = GetFactor();
   else fSpFactor = fSpiderFactorEntry->GetNumber();

   fAnglesUp   = fAngleUpEntry->GetIntNumber();
   fAnglesDown = fAngleDownEntry->GetIntNumber();
   fAlpha      = fApertureUpEntry->GetNumber();
   fPiedType   = fPiedChoice->GetSelected();
   fMatrixType = fTypeChoice->GetSelected();
   Int_t type  = fMatrixType;

   TH2*   tmpHisto = fHisto;
   TList* tmpCut   = 0;
   if (fUseCut) {
      tmpHisto = (TH2*)fHisto->Clone(Form("%s_cut", fHisto->GetName()));
      tmpHisto->Reset();
      for (int i = 1; i <= fHisto->GetNbinsX(); i++) {
         for (int j = 1; j <= fHisto->GetNbinsY(); j++) {
            Stat_t ww = fHisto->GetBinContent(i, j);
            Axis_t x0 = fHisto->GetXaxis()->GetBinCenter(i);
            Axis_t y0 = fHisto->GetYaxis()->GetBinCenter(j);
            if (fGrid->IsIdentifiable(x0, y0)) tmpHisto->Fill(x0, y0, ww);
         }
      }
      tmpCut = (TList*)fGrid->GetCuts()->Clone("tmpCuts");
   }

   fGrid->Clear();

   if (fScaledHisto) delete fScaledHisto;
   KVHistoManipulator hm;

   TF1 RtLt("RtLt", Form("x*%lf", fSfx), 0, tmpHisto->GetXaxis()->GetXmax());
   TF1 RtLty("RtLty", Form("x*%lf", fSfy), 0, tmpHisto->GetXaxis()->GetXmax());
   fScaledHisto = (TH2F*)hm.ScaleHisto(tmpHisto, &RtLt, &RtLty);

   if (fIdentificator) delete fIdentificator;
   fIdentificator = new KVSpiderIdentificator(fScaledHisto, fXm * fSfx, fYm * fSfy);

   switch (fPiedType) {
      case kUser:
         fIdentificator->SetX0(fPdx * fSfx);
         fIdentificator->SetY0(fPdy * fSfy);
         break;
      case kAuto:
         break;
      case kNone:
         fIdentificator->SetX0(0.);
         fIdentificator->SetY0(0.);
   }

   fIdentificator->SetParameters(fSpFactor);
   fIdentificator->SetNangles(fAnglesUp, fAnglesDown);
   fIdentificator->SetAlpha(fAlpha);

   fProgressBar->SetRange(0, fAnglesUp + fAnglesDown + 1);
   fProgressBar->Reset();
   fIdentificator->Connect("Increment(Float_t)", "TGHProgressBar", fProgressBar, "SetPosition(Float_t)");

   fTestButton->SetEnabled(kFALSE);
   fCloseButton->SetEnabled(kFALSE);
   fIdentificator->ProcessIdentification();
   fTestButton->SetEnabled(kTRUE);
   fCloseButton->SetEnabled(kTRUE);

   fIdentificator->Disconnect("Increment(Float_t)", fProgressBar, "SetPosition(Float_t)");
   fProgressBar->Reset();

   if (fDebug) fIdentificator->Draw(fOption.Data());

   TList* ll = (TList*)fIdentificator->GetListOfLines();

   KVIDZALine* TheLine = 0;
   int zmax = 0;

   KVSpiderLine* spline = 0;
   TIter next_line(ll);
   while ((spline = (KVSpiderLine*)next_line())) {
      if ((spline->GetN() > 10)) { //&&(spline->GetX(0)<=fIdentificator->GetX0()+200.))
         TF1* ff1 = 0;
         if (type == kSiCsI) ff1 = spline->GetFunction(fPdx * fSfx, TMath::Max(fScaledHisto->GetXaxis()->GetXmax() * 0.9, spline->GetX(spline->GetN() - 1)));
         else if (type == kSiSi)  ff1 = spline->GetFunction(fPdx * fSfx, TMath::Min(fScaledHisto->GetXaxis()->GetXmax() * 0.9, spline->GetX(spline->GetN() - 1) * 1.5));
         else if (type == kChIoSi)  ff1 = spline->GetFunction(fPdx * fSfx, TMath::Min(fScaledHisto->GetXaxis()->GetXmax() * 0.9, spline->GetX(spline->GetN() - 1) * 1.5));
         else ff1 = spline->GetFunction();
         if ((type == kSiCsI) && (ff1->GetParameter(1) >= 3000. || (ff1->GetParameter(2) <= 0.35) || (ff1->GetParameter(2) >= 1.))) {
            Info("SpiderIdentification", "Z = %d has been rejected (fit parameters)", spline->GetZ());
            continue;
         }
         TheLine = (KVIDZALine*)((KVIDZAGrid*)fGrid)->NewLine("ID");
         TheLine->SetZ(spline->GetZ());
         double min, max;
         ff1->GetRange(min, max);
         double step = TMath::Min((max - min) * 0.05, 20.); //20.;
         double stepmax = (max - min) * 0.2; //800.;
         double x = 0.;
         for (x = min + 1; x < max + step; x += step) {
            if (step <= stepmax) step *= 1.3;
            if (ff1->Eval(x) < 4000) TheLine->SetPoint(TheLine->GetN(), x, ff1->Eval(x));
         }
         if (max > x) TheLine->SetPoint(TheLine->GetN(), max, ff1->Eval(max));

         fGrid->Add("ID", TheLine);
         if (spline->GetZ() >= zmax) zmax = spline->GetZ();
      } else {
         Info("SpiderIdentification", "Z = %d has been rejected (too few points)", spline->GetZ());
      }
   }

   TF1 fx("fx12", Form("x/%lf", fSfx), 0., fScaledHisto->GetNbinsX() * 1.);
   TF1 fy("fy12", Form("x/%lf", fSfy), 0., fScaledHisto->GetNbinsY() * 1.);
   fGrid->Scale(&fx, &fy);

   if (fUseCut) delete tmpHisto;

   if (tmpCut) fGrid->GetCuts()->AddAll(tmpCut);
   pad->cd();
   fGrid->Draw();
   pad->Modified();
   pad->Update();

   DoClose();
}
Exemple #9
0
void xtruSamples()
{
// Draw a sample of TXTRU shapes some convex, concave (and possibly malformed)
// Change Bool_t's to test alternative specifications
// Author: Robert Hatcher ([email protected]) 2000.09.06

// One normally specifies the x-y points in counter-clockwise order;
// flip this to TRUE to test that it doesn't matter.
  Bool_t makecw      = kFALSE;

// One normally specifies the z points in increasing z order;
// flip this to TRUE to test that it doesn't matter.
  Bool_t reversez    = kFALSE;

// One shouldn't be creating malformed polygons
// but to test what happens when one does here's a flag.
// The effect will be only apparent in solid rendering mode
  Bool_t domalformed = kFALSE;
//  domalformed = kTRUE;

  c1 = new TCanvas("c1","sample TXTRU Shapes",200,10,640,640);

// Create a new geometry
  TGeometry* geom = new TGeometry("sample","sample");
  geom->cd();

// Define the complexity of the drawing
  Float_t zseg   = 6;  // either 2 or 6
  Int_t extravis = 0;  // make extra z "arrow" visible

  Float_t unit = 1;

// Create a large BRIK to embed things into
  Float_t bigdim = 12.5*unit;
  TBRIK* world = new TBRIK("world","world","void",bigdim,bigdim,bigdim);

  // Create the main node, make it invisible
  TNode* worldnode = new TNode("worldnode","world node",world);
  worldnode->SetVisibility(0);
  worldnode->cd();

// Canonical shape ... gets further modified by scale factors
// to create convex (and malformed) versions
  Float_t x[] = { -0.50, -1.20,  1.20,  0.50,  0.50,  1.20, -1.20, -0.50 };
  Float_t y[] = { -0.75, -2.00, -2.00, -0.75,  0.75,  2.00,  2.00,  0.75 };
  Float_t z[] = { -0.50, -1.50, -1.50,  1.50,  1.50,  0.50 };
  Float_t s[] = {  0.50,  1.00,  1.50,  1.50,  1.00,  0.50 };
  Int_t   nxy = sizeof(x)/sizeof(Float_t);
  Float_t convexscale[] = { 7.0, -1.0, 1.5 };

  Int_t icolor[] = { 1, 2, 3, 2, 2, 2, 4, 2, 6 };

// xycase and zcase:  0=convex, 1=malformed, 2=concave
// this will either create a 2x2 matrix of shapes
// or a 3x3 array (if displaying malformed versions)
  for (Int_t zcase = 0; zcase<3; zcase++) {
     if (zcase == 1 && !domalformed) continue;
     for (Int_t xycase = 0; xycase<3; xycase++) {
        if (xycase == 1 && !domalformed) continue;

        Char_t *name = "txtruXYZ";
        sprintf(name,"txtru%1d%1d%1d",xycase,zcase,zseg);
        TXTRU* mytxtru = new TXTRU(name,name,"void",8,2);

        Int_t i, j;
        Float_t xsign = (makecw) ? -1 : 1;
        Float_t zsign = (reversez) ? -1 : 1;

        // set the vertex points
        for (i=0; i<nxy; i++) {
           Float_t xtmp = x[i]*xsign;
           Float_t ytmp = y[i];
           if (i==0||i==3||i==4||i==7) xtmp *= convexscale[xycase];
           if (xycase==2) xtmp *=2;
           mytxtru->DefineVertex(i,xtmp,ytmp);
        }
        // set the z segment positions and scales
        for (i=0, j=0; i<zseg; i++) {
           Float_t ztmp = z[i]*zsign;
           if (i==0||i==5) ztmp *= convexscale[zcase];
           if (zcase==2) ztmp *= 2.5;
           if (zseg>2 && zcase!=2 && (i==1||i==4)) continue;
           mytxtru->DefineSection(j,ztmp,s[i]);
           j++;
        }

        TNode* txtrunode = new TNode(name,name,mytxtru);
        txtrunode->SetLineColor(icolor[3*zcase+xycase]);
        Float_t pos_scale = (domalformed) ? 10 : 6;
        Float_t xpos = (xycase-1)*pos_scale*unit;
        Float_t ypos = (zcase-1)*pos_scale*unit;
        txtrunode->SetPosition(xpos,ypos,0.);
     }
  }


// Some extra shapes to show the direction of "z"
  Float_t zhalf = 0.5*bigdim;
  Float_t rmax = 0.03*bigdim;
  TCONE* zcone = new TCONE("zcone","zcone","void",zhalf,0.,rmax,0.,0.);
  zcone->SetVisibility(extravis);
  TNode* zconenode = new TNode("zconenode","zconenode",zcone);
  zconenode->SetLineColor(3);

  Float_t dzstub = 2*rmax; 
  TBRIK* zbrik = new TBRIK("zbrik","zbrik","void",rmax,rmax,dzstub);
  zbrik->SetVisibility(extravis);
  TNode* zbriknode = new TNode("zbriknode","zbriknode",zbrik);
  zbriknode->SetPosition(0.,0.,zhalf+dzstub);
  zbriknode->SetLineColor(3);

//  geom->ls();

  geom->Draw();

// Tweak the pad so that it displays the entire geometry undistorted
  TVirtualPad *thisPad = gPad;
  if (thisPad) {
    TView *view = thisPad->GetView(); 
    if (!view) return;
    Double_t min[3],max[3],center[3];
    view->GetRange(min,max);
    int i;
    // Find the boxed center
    for (i=0;i<3; i++) center[i] = 0.5*(max[i]+min[i]);
    Double_t maxSide = 0;
    // Find the largest side
    for (i=0;i<3; i++) maxSide = TMath::Max(maxSide,max[i]-center[i]);
    file://Adjust scales:
    for (i=0;i<3; i++) {
       max[i] = center[i] + maxSide;
       min[i] = center[i] - maxSide;
    }
    view->SetRange(min,max);
    thisPad->Modified();
    thisPad->Update();
  }

}
Exemple #10
0
void validation()
{
	msglvl[DBG] = SILENT;
	msglvl[INF] = VISUAL;
	msglvl[WRN] = VISUAL;
	msglvl[ERR] = VISUAL;
	msglvl[FAT] = VISUAL;

	TDirectory* oldDir = gDirectory; // remember old directory

	style();

	Int_t g4bin = (ng4bins/g4max+1); //==> g^4=1 ==> SSM !
	
	TString suffix = "";
	if(doTruth) suffix = "_truth";
	
	TString mctype  = (isMC11c) ? "mc11c" : "mc11a";
	
	// TString fBGname = "plots/ZP_2dtemplates_"+mctype+"_33st_overallEWkF_noInAmpSigEWkF_noHighMbins_wthOfficialZP_Xmass2000.root";
	// TString fBGname = "plots/ZP_2dtemplates_"+mctype+"_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_noTruth_wthOfficialZP_treeLevelMass_Xmass2000.root";
	// TString fBGname = "plots/ZP_2dtemplates_"+mctype+"_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_wthOfficialZP_treeLevelMass_Xmass2000.root";
	// TString fBGname = "plots/ZP_2dtemplates_mc11c_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_wthOfficialZP_fixedBWwidth_treeLevelMass_Xmass2000.root";
	// TString fBGname = "plots/ZP_2dtemplates_mc11c_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_noTruth_wthOfficialZP_treeLevelMass_Xmass2000.root";
	// TString fBGname = "plots/ZP_2dtemplates_"+mctype+"_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_noTruth_wthOfficialZP_treeLevelMass_Xmass2000.root";
	// TString fBGname = "plots/ZP_2dtemplates_"+mctype+"_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_noTruth_wthOfficialZP_fixedBWwidth_treeLevelMass_Xmass2000.root";

	TLegend* legR = new TLegend(0.15,0.75,0.35,0.85,NULL,"brNDC");
	legR->SetFillStyle(4000); //will be transparent
	legR->SetFillColor(0);
	legR->SetTextFont(42);
	TH1D* hDummy = new TH1D("","",1,0.,1.);
	hDummy->SetMarkerStyle(20);
	hDummy->SetMarkerSize(0.8);
	hDummy->SetMarkerColor(kBlack);
	if(!doResiduals) legR->AddEntry(hDummy,"#frac{template}{official}","lep");
	else             legR->AddEntry(hDummy,"#frac{template - official}{#sqrt{#delta^{2}template + #delta^{2}official}}","lep");
	
	TPaveText* ptxt = new TPaveText(0.145,0.35,0.245,0.55,"NDC");
	TText* txt;
	ptxt->SetTextSize(0.03);
	ptxt->SetBorderSize(0);
	ptxt->SetFillStyle(4000); //will be transparent
	ptxt->SetFillColor(0);
	ptxt->SetTextAlign(12);
	txt = ptxt->AddText("This range");
	txt = ptxt->AddText("is chopped");
	txt = ptxt->AddText("before the");
	txt = ptxt->AddText("template is");
	txt = ptxt->AddText("handed to");
	txt = ptxt->AddText("BAT (limit).");
	
	oldDir->cd();

	TString fBGname = "plots/validation/ZP_2dtemplates_mc11c_33st_noKKtmplates_wthOfficialZP_treeLevelMass_Xmass2000.root";
	TFile* fD = new TFile(fBGname,"READ");
	TH1D* hDY = NULL;
	if(doTruth) hDY = (TH1D*)fD->Get("hMass_DYmumu_truth")->Clone();
	else        hDY = (TH1D*)fD->Get("hMass_DYmumu")->Clone();
	hDY->SetLineColor(kMagenta-5);
	hDY->SetMarkerColor(kMagenta-5);

	oldDir->cd();

	TFile* fDYrozmin    = new TFile("plots/mass_plot_tables_3st.root","READ");
	TH1D* hDYrozmin = (TH1D*)fDYrozmin->Get("mass_log_dy")->Clone();
	hDYrozmin = (TH1D*)hGeV2TeV(hDYrozmin)->Clone();
	hDYrozmin = (TH1D*)hChopper(hDYrozmin,bins2chop)->Clone();
	oldDir->cd();
	TFile* f1dTemplates = new TFile("plots/ZpSignal_MM_MC11c_5points.root","READ");
	TObjArray* toarr1d = new TObjArray();
	toarr1d->Read("template");
	TMapTSP2TH1D h1dBrandeisTmpltMap;
	double Nflat = 399948;
	double sigmaflat = 4.3988E+07*nb2fb;
	double Lmcflat = Nflat/sigmaflat;
	double scale = luminosity/Lmcflat;
	TH1D* h1dTmp = NULL;
	h1dTmp = (TH1D*)((TObjArray*)toarr1d->At(0/*22*/))->Clone();
	h1dTmp->Scale(scale);
	h1dTmp = (TH1D*)hChopper(h1dTmp,bins2chop)->Clone();
	h1dTmp->Add(hDYrozmin);
	h1dBrandeisTmpltMap.insert( make_pair("1000",(TH1D*)resetErrors(h1dTmp)->Clone("1000")) );
	h1dTmp = NULL;
	h1dTmp = (TH1D*)((TObjArray*)toarr1d->At(1/*28*/))->Clone();
	h1dTmp->Scale(scale);
	h1dTmp = (TH1D*)hChopper(h1dTmp,bins2chop)->Clone();
	h1dTmp->Add(hDYrozmin);
	h1dBrandeisTmpltMap.insert( make_pair("1250",(TH1D*)resetErrors(h1dTmp)->Clone("1250")) );
	h1dTmp = NULL;
	h1dTmp = (TH1D*)((TObjArray*)toarr1d->At(2/*34*/))->Clone();
	h1dTmp->Scale(scale);
	h1dTmp = (TH1D*)hChopper(h1dTmp,bins2chop)->Clone();
	h1dTmp->Add(hDYrozmin);
	h1dBrandeisTmpltMap.insert( make_pair("1500",(TH1D*)resetErrors(h1dTmp)->Clone("1500")) );
	h1dTmp = NULL;
	h1dTmp = (TH1D*)((TObjArray*)toarr1d->At(3/*40*/))->Clone();
	h1dTmp->Scale(scale);
	h1dTmp = (TH1D*)hChopper(h1dTmp,bins2chop)->Clone();
	h1dTmp->Add(hDYrozmin);
	h1dBrandeisTmpltMap.insert( make_pair("1750",(TH1D*)resetErrors(h1dTmp)->Clone("1750")) );
	h1dTmp = NULL;
	h1dTmp = (TH1D*)((TObjArray*)toarr1d->At(4/*47*/))->Clone();
	h1dTmp->Scale(scale);
	h1dTmp = (TH1D*)hChopper(h1dTmp,bins2chop)->Clone();
	h1dTmp->Add(hDYrozmin);
	h1dBrandeisTmpltMap.insert( make_pair("2000",(TH1D*)resetErrors(h1dTmp)->Clone("2000")) );

	oldDir->cd();

	TMapTSP2TH1D h1Map;
	h1Map.insert( make_pair("1000o", (TH1D*)fD->Get("hMass_Zprime_SSM1000"+suffix)->Clone()) );
	h1Map.insert( make_pair("1000t", (TH1D*)fD->Get("hMass_Zprime_SSM1000_template"+suffix)->Clone()) );
	if(isMC11c)
	{
		h1Map.insert( make_pair("1250o", (TH1D*)fD->Get("hMass_Zprime_SSM1250"+suffix)->Clone()) );
		h1Map.insert( make_pair("1250t", (TH1D*)fD->Get("hMass_Zprime_SSM1250_template"+suffix)->Clone()) );
	}
	h1Map.insert( make_pair("1500o", (TH1D*)fD->Get("hMass_Zprime_SSM1500"+suffix)->Clone()) );
	h1Map.insert( make_pair("1500t", (TH1D*)fD->Get("hMass_Zprime_SSM1500_template"+suffix)->Clone()) );
	h1Map.insert( make_pair("1750o", (TH1D*)fD->Get("hMass_Zprime_SSM1750"+suffix)->Clone()) );
	h1Map.insert( make_pair("1750t", (TH1D*)fD->Get("hMass_Zprime_SSM1750_template"+suffix)->Clone()) );
	h1Map.insert( make_pair("2000o", (TH1D*)fD->Get("hMass_Zprime_SSM2000"+suffix)->Clone()) );
	h1Map.insert( make_pair("2000t", (TH1D*)fD->Get("hMass_Zprime_SSM2000_template"+suffix)->Clone()) );

	TMapTSP2TH1D h1rMap;
	h1rMap.insert( make_pair("1000", (TH1D*)fD->Get("hMass_Zprime_SSM1000"+suffix)->Clone()) );
	if(isMC11c) h1rMap.insert( make_pair("1250", (TH1D*)fD->Get("hMass_Zprime_SSM1250"+suffix)->Clone()) );
	h1rMap.insert( make_pair("1500", (TH1D*)fD->Get("hMass_Zprime_SSM1500"+suffix)->Clone()) );
	h1rMap.insert( make_pair("1750", (TH1D*)fD->Get("hMass_Zprime_SSM1750"+suffix)->Clone()) );
	h1rMap.insert( make_pair("2000", (TH1D*)fD->Get("hMass_Zprime_SSM2000"+suffix)->Clone()) );
	for(TMapTSP2TH1D::iterator it=h1rMap.begin() ; it!=h1rMap.end() ; ++it)
	{
		it->second->Reset();
		if(!doResiduals) it->second->Divide(h1Map[it->first+"o"],h1Map[it->first+"t"],1.,1.,"B");
		else             residuals(h1Map[it->first+"o"], h1Map[it->first+"t"], it->second);
		
		// for(Int_t i=0 ; i<=it->second->GetNbinsX()+1 ; i++) it->second->SetBinError(i,0);
		it->second->SetMarkerStyle(20);
		it->second->SetMarkerSize(0.5);
		it->second->GetXaxis()->SetLabelSize(0.073);
		it->second->GetYaxis()->SetLabelSize(0.073);
		it->second->GetXaxis()->SetTitleSize(0.073);
		it->second->GetYaxis()->SetTitleSize(0.073);
		it->second->SetTitleSize(0.075);
		it->second->GetYaxis()->SetTitleOffset(0.5);
		if(!doResiduals)
		{
			it->second->SetMinimum(0.2);
			it->second->SetMaximum(1.8);
		}
		else
		{
			it->second->SetMinimum(-5.);
			it->second->SetMaximum(+5.);
		}
		it->second->SetTitle("");
		if(!doResiduals) it->second->GetYaxis()->SetTitle("ratio");
		else             it->second->GetYaxis()->SetTitle("residuals");
	}

	TMapTSP2TGAE poissonGraphMap;
	TMapTSP2TLeg legMap;


	_INFO("");

	oldDir->cd();

	fD->cd();	
	TH1D* h1Template = (TH1D*)fD->Get("hMass_DYmumu"+suffix)->Clone();
	h1Template->Reset();
	TObjArray* toarr = new TObjArray();
	if(doTruth) toarr->Read("truth_template2d");
	else        toarr->Read("template2d");
	TH2D* h2SSM2000 = (TH2D*)((TObjArray*)toarr->At(0))->Clone("hMass"+suffix+"_Zprime_SSM2000_template2d");
	for(Int_t bin=1 ; bin<=h2SSM2000->GetNbinsX() ; bin++)
	{
		h1Template->SetBinContent(bin, h2SSM2000->GetBinContent(bin,g4bin));
		h1Template->SetBinError(bin, h2SSM2000->GetBinError(bin,g4bin));
	}
	h1Template->SetLineColor(kViolet);
	h1Template->SetLineWidth(1);
	h1Template->SetMarkerStyle(20);
	h1Template->SetMarkerSize(0.3);
	h1Template->SetMarkerColor(kViolet);
	// the functions
	h2Template = (TH2D*)h2SSM2000->Clone();
	vector<TF1*> vfunc;
	unsigned int nmllbins = h2Template->GetNbinsX();
	for(unsigned int mll=1 ; mll<=(nmllbins-bins2chop) ; mll++) // 1...(56-9 = 47)
	{
		TString mllname = (TString)_s(mll);
		TString mllval  = (TString)_s(h2Template->GetXaxis()->GetBinCenter(mll+bins2chop));
		
		TF1* f = new TF1("fNominal_mll"+mllname,fTH1toTF1,g4min,g4max,1);
		f->SetParameter(0,mll);
		f->SetParNames("mll");
		// f->SetLineColor(kBlue);
		// f->SetLineWidth(1);
		f->SetNpx(400);
		vfunc.push_back(f);
	}
	TGraph* graphDY = new TGraph();
	graphDY->SetMarkerStyle(25);
	graphDY->SetMarkerSize(0.6);
	graphDY->SetMarkerColor(kGreen+2);
	TGraph* graphSSM = new TGraph();
	graphSSM->SetMarkerStyle(24);
	graphSSM->SetMarkerSize(0.6);
	graphSSM->SetMarkerColor(kOrange+8);
	for(unsigned int i=0 ; i<vfunc.size() ; i++)
	{
		double DY = vfunc[i]->Eval(0.0);
		double SSM = vfunc[i]->Eval(1.0);
		graphDY->SetPoint(i,h2Template->GetXaxis()->GetBinCenter(bins2chop+i+1),DY);
		graphSSM->SetPoint(i,h2Template->GetXaxis()->GetBinCenter(bins2chop+i+1),SSM);
	}
	
	
	oldDir->cd();

	TObjArray* toarr1dTLV = new TObjArray();
	TMapTSP2TH1D h1dTlvTmpltMap;
	TFile* fT = NULL;
	TString fTname = "plots/validation/ZP_2dtemplates_mc11c_33st_noInterference_noKKtmplates_noOverallEWkF_wthOfficialZP_treeLevelMass_Xmass";
	
	fT = new TFile(fTname+"1000.root","READ");
	toarr1dTLV->Read("template");
	h1dTmp = (TH1D*)((TObjArray*)toarr1dTLV->At(0))->Clone();
	h1dTmp->Add(hDY);
	h1dTlvTmpltMap.insert( make_pair("1000",(TH1D*)resetErrors(h1dTmp)->Clone("1000")) );
	fT = new TFile(fTname+"1250.root","READ");
	toarr1dTLV->Read("template");
	h1dTmp = (TH1D*)((TObjArray*)toarr1dTLV->At(0))->Clone();
	h1dTmp->Add(hDY);
	h1dTlvTmpltMap.insert( make_pair("1250",(TH1D*)resetErrors(h1dTmp)->Clone("1250")) );
	fT = new TFile(fTname+"1500.root","READ");
	toarr1dTLV->Read("template");
	h1dTmp = (TH1D*)((TObjArray*)toarr1dTLV->At(0))->Clone();
	h1dTmp->Add(hDY);
	h1dTlvTmpltMap.insert( make_pair("1500",(TH1D*)resetErrors(h1dTmp)->Clone("1500")) );
	fT = new TFile(fTname+"1750.root","READ");
	toarr1dTLV->Read("template");
	h1dTmp = (TH1D*)((TObjArray*)toarr1dTLV->At(0))->Clone();
	h1dTmp->Add(hDY);
	h1dTlvTmpltMap.insert( make_pair("1750",(TH1D*)resetErrors(h1dTmp)->Clone("1750")) );
	fT = new TFile(fTname+"2000.root","READ");
	toarr1dTLV->Read("template");
	h1dTmp = (TH1D*)((TObjArray*)toarr1dTLV->At(0))->Clone();
	h1dTmp->Add(hDY);
	h1dTlvTmpltMap.insert( make_pair("2000",(TH1D*)resetErrors(h1dTmp)->Clone("2000")) );

	oldDir->cd();
	
	
	for(TMapTSP2TH1D::iterator it=h1Map.begin() ; it!=h1Map.end() ; ++it)
	{
		if(it->first.Contains("o"))
		{
			TString name = it->first;
			name.ReplaceAll("o","");
			it->second->SetFillColor(kAzure-9);
			if(doTruth) it->second->SetTitle("m_{Z'} = "+name+" GeV (truth)");
			else        it->second->SetTitle("m_{Z'} = "+name+" GeV");
		}
		if(it->first.Contains("t"))
		{
			//TGraphAsymmErrors* poisson(TH1D* h)
			it->second->SetLineColor(kBlue);
			it->second->SetMarkerStyle(20);
			it->second->SetMarkerSize(0.4);
			it->second->SetMarkerColor(kBlue);
			it->second->SetLineWidth(1);
			
			TString name = it->first;
			name.ReplaceAll("t","");
			poissonGraphMap.insert( make_pair(name, (TGraphAsymmErrors*)poisson(it->second)->Clone()) );
			poissonGraphMap[name]->SetMarkerStyle(20);
			poissonGraphMap[name]->SetMarkerSize(0.3);
			poissonGraphMap[name]->SetMarkerColor(kBlue);
			poissonGraphMap[name]->SetLineWidth(1);
			poissonGraphMap[name]->SetLineColor(kBlue);
		}
	}	

	Double_t yLine = (!doResiduals) ? 1. : 0.;

	TLine* line = new TLine(0.07,yLine,3.,yLine);	
	line->SetLineColor(kRed);
	line->SetLineWidth(2);
	
	TMapTSP2TCNV cnvMap;
	cnvMap.insert( make_pair("1000", new TCanvas("1000","1000",600,550)) );
	if(isMC11c) cnvMap.insert( make_pair("1250", new TCanvas("1250","1250",600,550)) );
	cnvMap.insert( make_pair("1500", new TCanvas("1500","1500",600,550)) );
	cnvMap.insert( make_pair("1750", new TCanvas("1750","1750",600,550)) );
	cnvMap.insert( make_pair("2000", new TCanvas("2000","2000",600,550)) );
	for(TMapTSP2TCNV::iterator it=cnvMap.begin() ; it!=cnvMap.end() ; ++it)
	{
		_INFO("starting "+(string)it->first);
		if(it->first=="2000") legMap.insert( make_pair(it->first, new TLegend(0.35,0.55,0.83,0.84,NULL,"brNDC")) );
		else                  legMap.insert( make_pair(it->first, new TLegend(0.35,0.60,0.83,0.84,NULL,"brNDC")) );
		legMap[it->first]->SetFillStyle(4000); //will be transparent
		legMap[it->first]->SetFillColor(0);
		legMap[it->first]->SetTextFont(42);
		legMap[it->first]->AddEntry(h1Map[it->first+"o"],"Official Z'_{SSM}","F");
		legMap[it->first]->AddEntry(hDY,"Official DY#mu#mu","lep");
		legMap[it->first]->AddEntry(h1Map[it->first+"t"],"ME^{2} method: Template w/o couplings scale","lep");
		if(it->first=="2000")
		{
			legMap[it->first]->AddEntry(h1Template,"ME^{2} method: Template histogram at  #it{g=1} (SSM)","lep");
			legMap[it->first]->AddEntry(graphSSM,  "ME^{2} method: Template function  at  #it{g=1} (SSM)","p");
			legMap[it->first]->AddEntry(graphDY,   "ME^{2} method: Template function  at  #it{g=0} (DY)","p");
		}
		if(!doTruth)
		{
			h1dTlvTmpltMap[it->first]->SetLineColor(kCyan+2);
			h1dTlvTmpltMap[it->first]->SetMarkerColor(kCyan+2);
			h1dTlvTmpltMap[it->first]->SetMarkerStyle(5);
			h1dTlvTmpltMap[it->first]->SetMarkerSize(0.5);
			legMap[it->first]->AddEntry(h1dTlvTmpltMap[it->first],"ME^{2} method: DY+Template (no interference)","p");
		
			h1dBrandeisTmpltMap[it->first]->SetLineColor(kRed);
			h1dBrandeisTmpltMap[it->first]->SetMarkerColor(kRed);
			h1dBrandeisTmpltMap[it->first]->SetMarkerStyle(27);
			h1dBrandeisTmpltMap[it->first]->SetMarkerSize(0.5);
			legMap[it->first]->AddEntry(h1dBrandeisTmpltMap[it->first],"Flat Z' method: DY+Template (no interference)","p");
		}

		it->second->Divide(1,2);
		TVirtualPad* ph = it->second->cd(1);
		TVirtualPad* pr = it->second->cd(2);	
		ph->SetPad(0.00, 0.35, 1.00, 1.00);
		pr->SetPad(0.00, 0.00, 1.00, 0.35);
		ph->SetBottomMargin(0.012);
		pr->SetBottomMargin(0.20);
		pr->SetTopMargin(0.012);
		
		ph->cd();
		ph->Draw();
		ph->SetTicks(1,1);
		ph->SetLogy();
		ph->SetLogx();
		// h1Map[it->first+"o"]->SetMaximum( h1Map[it->first+"t"]->GetMaximum()*1.5 );
		// h1Map[it->first+"o"]->Draw();
		TH1D* hTmpNoErr = (TH1D*)resetErrors(h1Map[it->first+"o"])->Clone();
		hTmpNoErr->SetMaximum( h1Map[it->first+"t"]->GetMaximum()*1.5 );
		hTmpNoErr->SetLineStyle(1);
		hTmpNoErr->SetLineColor(kBlack);
		hTmpNoErr->SetFillColor(kAzure-9);
		hTmpNoErr->Draw();
		TH1D* hTmpErr = (TH1D*)ShiftLog(h1Map[it->first+"o"],0.2)->Clone();
		hTmpErr->SetFillStyle(4000); //will be transparent
		hTmpErr->SetFillColor(0);
		hTmpErr->DrawCopy("epx0SAMES");
		hDY->Draw("SAMES");
		h1Map[it->first+"t"]->Draw("epSAMES");
		//poissonGraphMap[it->first]->Draw("pSAMES");
		if(it->first=="2000")
		{
			graphDY->Draw("SAMESp");
			graphSSM->Draw("SAMESp");
			h1Template->Draw("epSAMES");
		}
		_INFO("");
		h1dTlvTmpltMap[it->first]->Draw("SAMESp");
		h1dBrandeisTmpltMap[it->first]->Draw("SAMESp");
		
		TLine* chopline = new TLine(0.12805,getYmin(h1Map[it->first+"o"]),0.12805,7.e5);
		chopline->SetLineStyle(2);
		chopline->SetLineColor(kBlack);
		chopline->Draw("SAMES");
		ptxt->Draw("SAMES");
		
		legMap[it->first]->Draw("SAMES");
		ph->RedrawAxis();
		ph->Update();

		_INFO("");

		pr->cd();
		pr->Draw();
		pr->SetTicks(1,1);
		pr->SetGridy();
		pr->SetLogx();
		h1rMap[it->first]->Draw("ep");
		line->Draw("SAMES");
		h1rMap[it->first]->Draw("epSAMES");
		legR->Draw("SAMES");
		pr->RedrawAxis();
		pr->Update();

		unsigned int savestate = 1;
		if(it->first=="1000")      savestate = 0;
		else if(it->first=="2000") savestate = 2;
		else                       savestate = 1;
		TString testType = (doResiduals) ? "_residuals" : "_ratio";
		mutype   = (doTruth)     ? "_truth"     : "_recon";
		savemultipdf(it->second, "plots/validation/validation"+mutype+testType+"_"+mctype+"_all.pdf", savestate);
		saveas(it->second, "plots/validation/validation"+mutype+testType+"_"+mctype+"_"+it->first);
		
		TCanvas* c = new TCanvas(it->first,"",600,400);
		c->cd();
		c->Draw();
		c->SetTicks(1,1);
		c->SetLogy();
		c->SetLogx();
		hTmpNoErr->Draw();
		hTmpErr->DrawCopy("epx0SAMES");
		hDY->Draw("SAMES");
		h1Map[it->first+"t"]->Draw("epSAMES");
		//poissonGraphMap[it->first]->Draw("pSAMES");
		if(it->first=="2000")
		{
			graphDY->Draw("SAMESp");
			graphSSM->Draw("SAMESp");
			h1Template->Draw("epSAMES");
		}
		h1dTlvTmpltMap[it->first]->Draw("SAMESp");
		h1dBrandeisTmpltMap[it->first]->Draw("SAMESp");
		legMap[it->first]->Draw("SAMES");
		chopline->Draw("SAMES");
		ptxt->Draw("SAMES");
		c->RedrawAxis();
		c->Update();
		saveas(c,"plots/validation/validation_"+it->first+"_"+mutype+testType);
		
		_INFO("done "+(string)it->first);
	}
}