bool TMRCScanner::PlotRatevsDAC(int xmin,int xmax,int ymax)
{
  int channel = 0;

// Read channel range from configuration
	
  ffile = new TFile(foutfile);
  if (ffile->IsOpen()){		
    ftree = (TTree*) ffile->Get("T"); 
    //ftree->SetMarkerStyle(23);
    //ftree->SetLineColor(kRed);
     ftree->Draw("(HITEntries[0]/Duration):DAC>>hDAC(1024,0,1023,2001,0,2000)","HITEntries!=0","L");
		TH2F *h = (TH2F*)gPad->GetPrimitive("hDAC");
		TAxis *xaxis = h->GetXaxis();
		xaxis->SetTitle("Threshold [DAC unit]");
		xaxis->SetRange(xmin,xmax);
		TAxis *yaxis = h->GetYaxis();
		yaxis->SetTitle("Rate [Hz]");
		yaxis->SetRange(0,ymax);		
		h->SetTitle("Pulse Amplitude Integral Distribution");
		for (int i = 2048; i<(2048+128); i++) {
			ftree->Draw(Form("(HITEntries[%d]/Duration):DAC",channel+i),"HITEntries!=0","SAME,L");
			printf("%d\n",i);
		}
		ftree->SetLineColor(kRed);
		ftree->Draw("Rate:DAC","","SAME,L");
	}else {
		printf("File %s not opened \n",foutfile);
		return false;
	}
	delete ffile;
	return true;
}
Example #2
0
//________________________________________________________________
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;
}
Example #3
0
void GetSlices(Double_t start, Double_t end, TH3D *source, TH2D **target)
{
   TAxis *zAxis = source->GetZaxis();
   Int_t startBin = zAxis->FindBin(start);
   Int_t endBin = zAxis->FindBin(end);
   Int_t it = 0;
   for(Int_t iBin = startBin; iBin < endBin; iBin += 10){
      zAxis->SetRange(iBin, iBin + 9);
      //cout << iBin << endl;
      TString name = Form("yx%d", it);
      target[it++] = (TH2D*)source->Project3D(name);
   }

   source->GetZaxis()->UnZoom();
   //zAxis->UnZoom();
}
Example #4
0
TH1 *PullHisto(const TList *list, const char *name, Int_t min, Int_t max,
               Double_t &mean)
{
  THnSparse *hs = list->FindObject(name);
  if (!hs) return 0;
  TAxis *atmp = hs->GetAxis(1);
  atmp->SetRange(min, max);
  // !!!!!!!!!!!!!!!!!!!!
  hs->GetAxis(2)->SetRangeUser(-0.5, 0.5);
  TH1 *hfin = hs->Projection(0);
  hfin->SetTitle(Form("p_{t} #in (%4.2f, %4.2f) GeV/c",
                      atmp->GetBinLowEdge(min),
                      atmp->GetBinLowEdge(max) + atmp->GetBinWidth(max)));
  mean = atmp->GetBinLowEdge(min) +
    (atmp->GetBinLowEdge(max) + atmp->GetBinWidth(max) -
     atmp->GetBinLowEdge(min))/2.0;
  // !!!!!!!!!!!!!!!!!!!!
  return hfin;//->Rebin();
}
Example #5
0
//________________________________________________________________
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;
}
Example #6
0
//______________________________________________________________________________
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);
   }
}
void writeSignalHistosForModel(std::vector<TH1D *>& vsd,
			       const TString& sigmodel,
			       TFile *allHistFile)
{
  for (int ichan=0; ichan<NUMCHAN; ichan++) {
    TH1D * sdh = vsd[ichan];

    // Find limit window from gaussian fit to signal peak.
    //
    double wid  = sdh->GetRMS();
    double mean = sdh->GetMean();

    //TCanvas *c1 = new TCanvas(s,s,300,300);
    TFitResultPtr r = sdh->Fit("gaus","QNS","",mean-2.5*wid,mean+2.5*wid);

    cout<<" mean= "<<mean<<", RMS= "<<wid<<", Fit sigma= "<<r->Parameter(2)<<endl;
    //cout<<r->Parameter(0)<<" "<<r->Parameter(1)<<" "<<r->Parameter(2)<<endl;

    TAxis *xax = sdh->GetXaxis();

#if 0
    int lobin = xax->FindFixBin(r->Parameter(1)-2*r->Parameter(2));
    int hibin = xax->FindFixBin(r->Parameter(1)+2*r->Parameter(2));
    sd.sumwinmin = xax->GetBinLowEdge(lobin);
    sd.sumwinmax = xax->GetBinUpEdge(hibin);
#elif 0
    int lobin = xax->FindFixBin(140);   sd.sumwinmin=140; // 1 bin  left,
    int hibin = xax->FindFixBin(170)-1; sd.sumwinmax=170; // 2 bins right
#else
    int lobin = xax->FindFixBin(sumwinmin);
    int hibin = xax->FindFixBin(sumwinmax)-1;
#endif
    int nbins = hibin-lobin+1;

    // for variable binning - all histos must have the same binning per channel
    TVectorD xbins   = TVectorD(sdh->GetNbinsX(),sdh->GetXaxis()->GetXbins()->GetArray());
    TVectorD xwindow = xbins.GetSub(lobin-1,hibin);

    xax->SetRange(lobin,hibin);

    // Copy contents to window-restricted signal histogram
    // and write to output file.
    //
    TString name = Form("Signal%s_%s",sigmodel.Data(),channames[ichan]);
    printf("Booking TH1D(%s,%s,%d,xwindowarray)\n",
	   name.Data(),sdh->GetTitle(),nbins);
    TH1D *signm = new TH1D(name.Data(),
			   sdh->GetTitle(),
			   nbins,
			   xwindow.GetMatrixArray());

    // make copies of the histograms that are restricted to the
    // bin range lobin-hibin
    //
    for (int ibin=lobin; ibin<=hibin; ibin++) 
      signm->SetBinContent((ibin-lobin+1),
			   sdh->GetBinContent(ibin)
			   *sdh->GetBinWidth(ibin)
			   );

    if (!sigmodel.CompareTo("wh"))
      signm->Scale(whsigscaleto);
    else
      signm->Scale(sigscaleto);

    allHistFile->WriteTObject(signm);

  } // channel loop
}                                                     // writeSignalHistosForModel
void TMRCScanner::CmpRate(const char * rootfile1,
						  const char * rootfile2,
						  const char * rootfile3,
						  const char * rootfile4,
						  const char * rootfile5,
						  const char * rootfile6,
						  const char * rootfile7,
						  const char * rootfile8,
						  const char * rootfile9)
{
	if (rootfile1!=NULL) {
		//TCanvas *c1 = new TCanvas("c1","c1",600,500);
		TLegend* leg = new TLegend(0.1,0.7,0.48,0.9);
		// leg->SetHeader("The Legend Title");
		leg->SetHeader("Pre-Amp Gain");
		Color_t color1 = kRed;		//23
		Color_t color2 = kBlue;	//24
		Color_t color3 = kMagenta;  //25
		// Color_t color4 = kRed;  //26
		Color_t color4 = kCyan;  //26
		// Color_t color5 = kRed+3;   //27
		Color_t color5 = kYellow;   //27
		Color_t color6 = kGreen;  //28
		Color_t color7 = kCyan;  //29
		Color_t color8 = kYellow;  //30
		Color_t color9 = kMagenta;
		
		TFile* f1 = new TFile(rootfile1);
	
		if (f1->IsOpen()) {
			TTree * mytree1 = (TTree*) f1->Get("T");
			mytree1->SetMarkerStyle(22);
			mytree1->SetMarkerColor(kRed);
			mytree1->Draw("(HITEntries[2048]/Duration):DAC>>hDAC(800,160,860,1000,0,1000)","HITEntries!=0");
			// mytree1->Draw("(HITEntries[2048]/Duration):DAC>>hDAC(1024,0,1023,1000,0,1000)","HITEntries!=0","P");
			// mytree1->Draw("(HITEntries[]/Duration):DAC>>hDAC(1024,0,1023,1000,0,1000)","HITEntries!=0","L");				
			TH2F *h = (TH2F*)gPad->GetPrimitive("hDAC");
			TAxis *xaxis = h->GetXaxis();
			xaxis->SetTitle("Threshold [DAC unit]");
			xaxis->SetRange(0,1024);
			TAxis *yaxis = h->GetYaxis();
			yaxis->SetTitle("Rate [Hz]");
			yaxis->SetRange(0,1000);		
			h->SetTitle("Pulse Amplitude Integral Distribution");
			h->Draw();
			for (int i =2049 ; i<2112; i++) {
				mytree1->SetLineColor(color1);
				mytree1->Draw(Form("(HITEntries[%d]/Duration):DAC>>h",i),"HITEntries!=0","SAME");
			}
			mytree1->SetMarkerColor(color1);	
			// leg->AddEntry(mytree1,rootfile1,"L");
			leg->AddEntry(mytree1,"Gain 0.5","P");
		}else {
			printf("File %s not opened \n",foutfile);

		}

		if (rootfile2!=NULL) {
		TFile* f2 = new TFile(rootfile2);
		TTree * mytree2 = (TTree*) f2->Get("T");
			mytree2->SetMarkerStyle(22);
			mytree2->SetMarkerColor(color2);
		for (int i =2048 ; i<2112; i++) {
			mytree2->SetLineColor(color2);
			// mytree2->Draw(Form("(HITEntries[%d]/Duration):DAC",i),"HITEntries!=0","SAME,L");
			mytree2->Draw(Form("(HITEntries[%d]/Duration):DAC>>h",i),"HITEntries!=0","SAME");
		}
		mytree2->SetMarkerColor(color2);	
			leg->AddEntry(mytree2,"Gain 1.0","P");

		}
			
		if (rootfile3!=NULL) {
		TFile* f3 = new TFile(rootfile3);
		TTree * mytree3 = (TTree*) f3->Get("T");
			mytree3->SetMarkerStyle(22);
			mytree3->SetMarkerColor(color3);
		for (int i =2048 ; i<2112; i++) {
			mytree3->SetLineColor(color3);
			mytree3->Draw(Form("(HITEntries[%d]/Duration):DAC>>h",i),"HITEntries!=0","SAME");
			// mytree3->Draw(Form("(HITEntries[%d]/Duration):DAC",i),"HITEntries!=0","SAME,L");
		}
		mytree3->SetMarkerColor(color3);	
		//leg->AddEntry(mytree3,rootfile3,"L");
			leg->AddEntry(mytree3,"Gain 1.5","P");

		}
		
		if (rootfile4!=NULL) {
		TFile* f4 = new TFile(rootfile4);
		TTree * mytree4 = (TTree*) f4->Get("T");
			mytree4->SetMarkerStyle(22);
			mytree4->SetMarkerColor(color4);
		for (int i =2048 ; i<2112; i++) {
			mytree4->SetLineColor(color4);
			mytree4->Draw(Form("(HITEntries[%d]/Duration):DAC>>h",i),"HITEntries!=0","SAME");
			// mytree4->Draw(Form("(HITEntries[%d]/Duration):DAC",i),"HITEntries!=0","SAME,L");
		}
		mytree4->SetMarkerColor(color4);	
		//leg->AddEntry(mytree4,rootfile4,"L");
			leg->AddEntry(mytree4,"Gain 2.0","P");

		}
		
		if (rootfile5!=NULL) {
		TFile* f5 = new TFile(rootfile5);
		TTree * mytree5 = (TTree*) f5->Get("T");
			mytree5->SetMarkerStyle(22);
			mytree5->SetMarkerColor(color5);
		for (int i =2048 ; i<2112; i++) {
			mytree5->SetLineColor(color5);
			mytree5->Draw(Form("(HITEntries[%d]/Duration):DAC>>h",i),"HITEntries!=0","SAME");
			// mytree5->Draw(Form("(HITEntries[%d]/Duration):DAC",i),"HITEntries!=0","SAME,L");
		}
		mytree5->SetMarkerColor(color5);	
		//leg->AddEntry(mytree5,rootfile5,"L");
			leg->AddEntry(mytree5,"Gain 3.0","P");

		}
			
		if (rootfile6!=NULL) {	
		TFile* f6 = new TFile(rootfile6);
		TTree * mytree6 = (TTree*) f6->Get("T");
			mytree6->SetMarkerStyle(22);
		mytree6->SetLineColor(color6);
		mytree6->SetMarkerColor(color6);	
		for (int i =2048 ; i<2112; i++) {
		  mytree6->Draw(Form("(HITEntries[%d]/Duration):DAC>>h",i),"HITEntries!=0","SAME");
			// mytree6->Draw(Form("(HITEntries[%d]/Duration):DAC",i),"HITEntries!=0","SAME,L");
		}
		//leg->AddEntry(mytree6,rootfile6,"L");
			leg->AddEntry(mytree6,"Gain 4.0","P");

		}
		
		if (rootfile7!=NULL) {
		TFile* f7 = new TFile(rootfile7);
		TTree * mytree7 = (TTree*) f7->Get("T");
		mytree7->SetLineColor(color7);
		mytree7->SetMarkerColor(color7);	
		for (int i =2048 ; i<2112; i++) {
			
			mytree7->Draw(Form("(HITEntries[%d]/Duration):DAC",i),"HITEntries!=0","SAME,L");
		}
		leg->AddEntry(mytree7,rootfile7,"L");
		}
			
		if (rootfile8!=NULL) {
		TFile* f8 = new TFile(rootfile8);
		TTree * mytree8 = (TTree*) f8->Get("T");
		mytree8->SetLineColor(color8);
		mytree8->SetMarkerColor(color8);	
		for (int i =2048 ; i<2112; i++) {
			
			mytree8->Draw(Form("(HITEntries[%d]/Duration):DAC",i),"HITEntries!=0","SAME,L");
		}
		leg->AddEntry(mytree8,rootfile8,"L");
		}
			
		if (rootfile9!=NULL) {
		TFile* f9 = new TFile(rootfile9);
		TTree * mytree9 = (TTree*) f9->Get("T");
		mytree9->SetLineColor(color9);
		mytree9->SetMarkerColor(color9);	
		for (int i =2048 ; i<2112; i++) {
			
			mytree9->Draw(Form("(HITEntries[%d]/Duration):DAC",i),"HITEntries!=0","SAME,L");
		}
		leg->AddEntry(mytree9,rootfile9,"L");
		}
		
		leg->Draw();
	}else {
		printf("Please specify at least one file");
	}
}