Exemple #1
0
void DMAHCALBooker::SetAxis(std::string type, std::string x_axis, std::string y_axis)
{
    for(std::map<std::string, TList*>::iterator it = m_objectList.begin(); it != m_objectList.end(); it++)
    {
        if(it->first == type)
        {
            TList *pList = it->second;
            TIter next(pList);
            TObject *obj;

            while ((obj = next()))
            {
                if(obj->InheritsFrom("TH1"))
                {
                    TH1F *h1 = static_cast<TH1F*>(obj);
                    h1->GetXaxis()->SetTitle(x_axis.c_str());
                    h1->GetYaxis()->SetTitle(y_axis.c_str());
                }
                if(obj->InheritsFrom("TH2"))
                {
                    TH1F *h2 = static_cast<TH1F*>(obj);
                    h2->GetXaxis()->SetTitle(x_axis.c_str());
                    h2->GetYaxis()->SetTitle(y_axis.c_str());
                }
            }
        }
        else
        {
            emit log("ERROR", QString("Type %1 not defined").arg(QString::fromStdString(type)));
            return;
        }
    }
}
TList* extractObjectFromPad(TPad* pad, const char* name)
{
  TList* objects = new TList();
  TList* primitivesList = pad->GetListOfPrimitives();
  assert(primitivesList);
  for (int i = 0; i < primitivesList->GetSize(); ++i) {
    TObject* object = primitivesList->At(i);
    std::cout << object->ClassName() << ' ' << object->GetName() << std::endl;
    if (object->InheritsFrom("TPad")) {
      TList* objectsFromPad = extractObjectFromPad(static_cast<TPad*>(object), name);
      for (int j = 0; j < objectsFromPad->GetSize(); ++j)
        objects->Add(objectsFromPad->At(j));
    } else if (object->InheritsFrom("THStack")) {
      TList* hList = (static_cast<THStack*>(object))->GetHists();
      for (int j = 0; j < hList->GetSize(); ++j)
        if (!strcmp(hList->At(j)->GetName(), name)) {
          objects->Add(hList->At(j));
        }
    } else if (!strcmp(object->GetName(), name)) {
      std::cout << "--->" << name << std::endl;
      objects->Add(object);
    }
  }
  return objects;
}
Exemple #3
0
   void yaxis(const char* patORpfx, const char* title) {
      TRegexp reg(patORpfx, kFALSE);

      TList* list = gDirectory->GetList() ;
      TIterator* iter = list->MakeIterator();

      TObject* obj = 0;

      while (obj = iter->Next()) {
         if (! (obj->InheritsFrom(TH1::Class()) || obj->InheritsFrom(THStack::Class()))) continue;

         TString name = obj->GetName();

         if (TString(patORpfx).MaybeRegexp()) {
            if (TString(obj->GetName()).Index(reg) < 0 ) continue;
         } else if (! name.BeginsWith(patORpfx)) continue;

         if (obj->InheritsFrom(TH1::Class()))
            ((TH1*)obj)->GetYaxis()->SetTitle(title);
         if (obj->InheritsFrom(THStack::Class())) {
            ((THStack*)obj)->Draw();
            ((THStack*)obj)->GetYaxis()->SetTitle(title);
         }
      }
   }
Exemple #4
0
   void normalize(const char* patORpfx) {
      TRegexp reg(patORpfx, kFALSE);

      TList* list = gDirectory->GetList() ;
      TIterator* iter = list->MakeIterator();

      TObject* obj = 0;

      while (obj = iter->Next()) {
         if (! obj->InheritsFrom(TH1::Class())) continue;

         TString name = obj->GetName();

         if (TString(patORpfx).MaybeRegexp()) {
            if (TString(obj->GetName()).Index(reg) < 0 ) continue;
         } else if (! name.BeginsWith(patORpfx)) continue;

         Double_t integral = 0;

         if (obj->InheritsFrom(TH2::Class()))
            integral = ((TH2*)obj)->Integral();
         else
            integral = ((TH1*)obj)->Integral();

         if (integral) {
            ((TH1*)obj)->Sumw2();
            ((TH1*)obj)->Scale(1./integral);
         }
      }
   }
void singleFile(TString name, double scalingFactor){
  // get the files
  loadingFiles(name); 
  // ---------------------------------------
  // !!! definition of output file(name) !!!
  // ---------------------------------------
  std::string path = (string)(name);
  size_t separator = path.find_last_of("/");
  TString file = (TString)(path.substr(separator+1));
  //  std::cout << "path: " << path << std::endl;
  //  std::cout << "separator: " << separator << std::endl;
  //  std::cout << "file: " << file << std::endl;

  TString outputfile="./diffXSecFromSignal/analysisRootFilesL1CorrPU/"+file+".root";
  TFile f(outputfile, "recreate");
  std::cout << "output file: " << outputfile << std::endl;
  std::cout << "scaling factor: " << setprecision(9) << fixed << scalingFactor;
  // ---------------------------------------------------------
  // !!! list of plots you want to combine !!!
  // and their directories within the input samples
  // example: addAndWeight("MyPlotFolder", "MyPlot", luminosity, f)
  // ---------------------------------------------------------
  TString folder ="";
  TString plot = "";
  // go to file
  files_[0]->cd();
  // loop objects in file
  TIter fileIterator(gDirectory->GetListOfKeys());
  TKey *fileKey;
  while( (fileKey = (TKey*)fileIterator()) ) {
    TObject *fileObject = fileKey->ReadObj(); 
    // check if object is a directory
    if(fileObject->InheritsFrom("TDirectory")){
      folder = (TString)fileObject->GetName();
      std::cout << std::endl << " - folder: " << folder << std::endl << "   plots: ";
      // go to directory
      ((TDirectory*)fileObject)->cd();
      // loop objects in directory
      TIter folderIterator(gDirectory->GetListOfKeys());
      TKey *folderKey;
      while( (folderKey = (TKey*)folderIterator()) ) {
	TObject *folderObject = folderKey->ReadObj(); 
	// check if object is a TH1 or TH2
	if( (folderObject->InheritsFrom("TH1")) || (folderObject->InheritsFrom("TH2"))){
	  plot = folderObject->GetName();
	  addAndWeight(folder, plot, f, scalingFactor);
	}
      }
    }
  }
  files_[0]->Close();
  

  f.Close();
}
void WorkOnPad(TPad* pad) {
	TIter nextobj(pad->GetListOfPrimitives());
	TObject *obj;
	while (obj = nextobj()) {
		//cout << "Pad Object: " << obj->GetName() << endl;
		if(obj->InheritsFrom("TPad")) {
			WorkOnPad((TPad*)obj);
		}
		else if(obj->InheritsFrom("TH1")) {
			WorkOnHist((TH1*)obj);
		}
	}
}
Exemple #7
0
//________________________________________________________
void GFHistManager::ColourStatsBoxes(GFHistArray *hists) const
{
  // colours stats boxes like hists' line colors and moves the next to each other
  if (!hists) return;
  Double_t x1 = fStatsX1, x2 = fStatsX2, y1 = fStatsY1, y2 = fStatsY2;
  for (Int_t iH = 0; iH < hists->GetEntriesFast(); ++iH) {
    TH1 *h = hists->At(iH);
    if (!h) continue;
    TObject *statObj = h->GetListOfFunctions()->FindObject("stats");
    if (statObj && statObj->InheritsFrom(TPaveStats::Class())) {
      TPaveStats *stats = static_cast<TPaveStats*>(statObj);
      stats->SetLineColor(hists->At(iH)->GetLineColor());
      stats->SetTextColor(hists->At(iH)->GetLineColor());
      stats->SetX1NDC(x1);
      stats->SetX2NDC(x2);
      stats->SetY1NDC(y1);
      stats->SetY2NDC(y2);
      y2 = y1 - 0.005; // shift down 2
      y1 = y2 - (fStatsY2 - fStatsY1); // shift down 1
      if (y1 < 0.) {
	y1 = fStatsY1; y2 = fStatsY2; // restart y-positions
	x2 = x1 - 0.005; // shift left 2
	x1 = x2 - (fStatsX2 - fStatsX1); // shift left 1
	if (x1 < 0.) { // give up, start again:
	  x1 = fStatsX1, x2 = fStatsX2, y1 = fStatsY1, y2 = fStatsY2;
	}
      }
    } else if (gStyle->GetOptStat() != 0) { // failure in case changed in list via TExec....
      this->Warning("ColourStatsBoxes", "No stats found for %s", hists->At(iH)->GetName());
    }
  }
}
void rdphi::Terminate()
{
//cout << "total event: " << NevtAll << "rejected: " << rejected_events << endl; 

  TFile *f = new TFile("output.root","RECREATE");

  //Write output Histograms
  TList *tl = GetOutputList();
  int l = tl->GetEntries();
  for ( int i = 0 ; i < l ; i++ )
  {
    TObject *o = tl->At(i);

    if ( o->InheritsFrom("TH1") )
    {
      cout << "TresChorros: Saving Histogram: "
          << "  Class: " << o->ClassName()  
          << "  Name: "<< o->GetName() 
          << "  Title: " << o->GetTitle()
          << " " 
          << endl << flush;
      o->Write();
    }
    }
  f->Flush();
  f->Close();  

}
Exemple #9
0
   void scalebins(const char* patORpfx, Double_t scale) {
      TRegexp reg(patORpfx, kFALSE);

      TList* list = gDirectory->GetList() ;
      TIterator* iter = list->MakeIterator();

      TObject* obj = 0;

      while (obj = iter->Next()) {
         if (! obj->InheritsFrom(TH1::Class())) continue;

         TString name = obj->GetName();

         if (TString(patORpfx).MaybeRegexp()) {
            if (TString(obj->GetName()).Index(reg) < 0 ) continue;
         } else if (! name.BeginsWith(patORpfx)) continue;

         Double_t binWidth, binContent, binError, newBinContent, newBinError;
         for (Int_t i = 1; i <= ((TH1*)obj)->GetNbinsX(); ++i) {
            binWidth = ((TH1*)obj)->GetBinWidth(i);
            binContent = ((TH1*)obj)->GetBinContent(i);
            binError = ((TH1*)obj)->GetBinError(i);
            newBinContent = (binContent*scale)/binWidth;
            newBinError = (binError*scale)/binWidth;

            ((TH1*)obj)->SetBinContent(i, newBinContent);
            ((TH1*)obj)->SetBinError(i, newBinContent);
            // Rename y axis with scale
         }
      }
   }
Exemple #10
0
// echo object at mouse position
void exec1()
{
   //example of macro called when a pad is redrawn
   //one must create a TExec object in the following way
   // TExec ex("ex",".x exec1.C");
   // ex.Draw();
   // this macro prints the bin number and the bin content when one clicks
   //on the histogram contour of any histogram in a pad
   //Author: Rene Brun
   
   if (!gPad) {
      Error("exec1", "gPad is null, you are not supposed to run this macro");
      return;
   }
   
   int event = gPad->GetEvent();
   if (event != 11) return;
   int px = gPad->GetEventX();
   TObject *select = gPad->GetSelected();
   if (!select) return;
   if (select->InheritsFrom(TH1::Class())) {
      TH1 *h = (TH1*)select;
      Float_t xx = gPad->AbsPixeltoX(px);
      Float_t x  = gPad->PadtoX(xx);
      Int_t binx = h->GetXaxis()->FindBin(x);
      printf("event=%d, hist:%s, bin=%d, content=%f\n",event,h->GetName(),binx,h->GetBinContent(binx));
   }
}
TList* ExtractAllHistograms(TFile* f) {
	TIter nextkey(f->GetListOfKeys());
	TKey *key;
	result = new TList();
	while (key = (TKey*)nextkey()) {
		cout << "Key: " << key->GetName() << endl;
		TObject* obj = key->ReadObj();
		if(obj->InheritsFrom("TPad")) {
			WorkOnPad((TPad*)obj);
		}
		else if(obj->InheritsFrom("TH1")) {
			WorkOnHist((TH1*)obj);
		}
	}
	return result;
}
Exemple #12
0
   void colors(TCanvas* canvas, Color_t color = 1) {
      if(! canvas) return 0;

      TList* list = canvas->GetListOfPrimitives();
      TIterator* iter = list->MakeIterator();

      TObject* obj = 0;

      //Hist color iterator
      Int_t colorIt = color;

      while (obj = iter->Next()) {
         if (! obj->InheritsFrom(TH1::Class())) continue;

         //yellow
         if (colorIt == 5)
            ++colorIt;

         hist::color(obj->GetName(), colorIt);
         if (colorIt == 40)
            colorIt = 1;
         else 
            ++colorIt;
      }
   }
Exemple #13
0
void KVRTGIDManager::SetIDFuncInTelescopes(UInt_t run){
	// For each identification function of the global list which is valid for this run, we add it in the associated telescope which
	// have to inherits from KVTGIDManager and from a KVIDTelescope.

	TIter next(fIDGlobalList);
	KVTGID *tgid = NULL;

	while( (tgid = (KVTGID *)next())){

		if(!tgid->IsValidForRun(run)) continue;

		// this list have to be deleted after use
                TCollection *lidtel = GetIDTelescopesForTGID(tgid);
		TIter nextidt(lidtel);
		TObject        *idt   = NULL;
		KVRTGIDManager *tgidm = NULL;

		while( (idt = nextidt()) ){
			if(!idt->InheritsFrom("KVRTGIDManager")){
				Error("KVRTGIDManager::SetIDFuncInTelescopes","The IDtelescope %s does not inherit from KVRTGIDManager",idt->GetName());
				continue;
			}
			tgidm = (KVRTGIDManager* )idt->IsA()->DynamicCast(KVRTGIDManager::Class(),idt);
			tgidm->SetTGID(tgid);
		}
		delete lidtel;
	}
}
Exemple #14
0
   TLegend* legend(THStack* stack, Option_t* option = "lp", Bool_t addColor = kFALSE, Int_t token = -1,
                   Float_t xmin = 0.50, Float_t ymin = 0.51, Float_t xmax = 0.85, Float_t ymax = 0.92) {
      if(! stack) return 0;

      TLegend* leg = new TLegend(xmin, ymin, xmax, ymax);
      TList* list = stack->GetHists();
      TIterator* iter = list->MakeIterator();

      TObject* obj = 0;

      //Hist color iterator
      Int_t colorIt = 1;

      while (obj = iter->Next()) {
         if (! obj->InheritsFrom(TH1::Class())) continue;

         if (addColor) {
            hist::color(obj->GetName(), colorIt);
            ++colorIt;
         }

         if (token == -1)
            leg->AddEntry(obj, obj->GetTitle(), option);
         else {
            TString name(obj->GetName());
            TObjArray* a = name.Tokenize("_");
            if (a->GetEntries() <= token)
               leg->AddEntry(obj, obj->GetName(), option);
            else
               leg->AddEntry(obj, a->At(token)->GetName(), option);
         }
      }

      return leg;
   }
Exemple #15
0
void scaleToRate(const char* collectionName, double rateFactor) {
  TRegexp reg(collectionName, kTRUE);
  
  //    gDirectory->ls();
  TList* list = gDirectory->GetList() ;
  TIterator* iter = list->MakeIterator();
  TObject* obj = 0;
  
  while (obj = iter->Next()) {
    if (! obj->InheritsFrom(TH1::Class())) {
      //      cout << "bugger" << endl;
      continue;
    }
    
    
    TString name = obj->GetName();
    cout << "Testing name: " << name << " against " << collectionName << endl;
    
    if (TString(collectionName).MaybeRegexp()) {
      cout << "we have a possible match" << endl;
      cout << "Trying to match to " << TString(obj->GetName()) << endl;
      if (TString(obj->GetName()).Index(reg) < 0 ) {
	cout << "failure here.  Argument returns " << TString(obj->GetName()).Index(reg) << endl;
	continue;
      }
    }
    else if (! name.BeginsWith(collectionName)) continue;
    
    cout << "We're trying to scale" << name << endl;
    ((TH1*)obj)->Scale(rateFactor);
    
  }
  
}
Exemple #16
0
bool check_complete(TString fn="output_ana.root", TString fn2="ana_target.root", double minP = 0.03, int minev = 3, int maxfail=3)
{
	bool fTest=kFALSE;
        TString templateFile = gSystem->Getenv("VMCWORKDIR");
        templateFile += "/macro/run/";
        templateFile += fn2;
	
	TFile *f=new TFile(fn,"READ");
	if (!f->IsZombie())
	{
		TFile *f2=new TFile(templateFile,"READ");
			
		TKey *key;
		TIter next(f->GetListOfKeys());
		
		int failcount = 0;
		
		while ( (key = (TKey*)next()) )
		{
			TObject *obj = key->ReadObj();
			
			// only check TH1Fs
			if (!obj->InheritsFrom("TH1F")) continue;
			
			TString name = obj->GetName();
			TH1F* h  = (TH1F*) obj; 
			TH1F* h2 = (TH1F*) f2->Get(name);
			
			if ( h->GetEntries()<minev ) 
			{
				cout << "Histogram (almost) empty : " << name << " \"" << h2->GetTitle() << "\":  N = " <<  h->GetEntries() << endl;
				failcount++;
			}
			else  
			{
				double P = h2->KolmogorovTest(h);
				if ( P<minP )
				{
					cout << "Incompatible distribution: " << name << " \"" << h2->GetTitle() << "\":  P = " << P << endl;
					failcount++;
				}
			}
		
		}
		
		if (failcount<maxfail) fTest = kTRUE;
	}
	
	if (fTest){
		cout << " Test passed" << endl;
		cout << " All ok " << endl;  
	}else{
		cout << " Test Failed" << endl;
		cout << " Not Ok " << endl;         
	}
    
    exit(fTest);
}
Exemple #17
0
void KVHarpeeSi::Streamer(TBuffer &R__b){
   // Stream an object of class KVHarpeeSi.
   // We set the pointers to the calibrator objects

   if (R__b.IsReading()) {
      KVHarpeeSi::Class()->ReadBuffer(R__b, this);
	  TIter next( GetListOfCalibrators() );
	  TObject *cal = NULL;
	  while( ( cal = next() ) ){
		  if( cal->InheritsFrom("KVRecombination") )
      		  fPHD  =  (KVRecombination *)cal;
		  else if( cal->InheritsFrom("KVFunctionCal") )
			  fCanalE = (KVFunctionCal *)cal;
	  }
   } else {
      KVHarpeeSi::Class()->WriteBuffer(R__b, this);
   }
}
Exemple #18
0
   void drawsame(const char* canvasName, const char* patORpfx,Option_t* drawOption = "") {
     //     cout << "testing this method" << endl;
     TRegexp reg(patORpfx, kFALSE);
     TList* list = gDirectory->GetList() ;
     //     cout << "this bleeping directory has " << gDirectory->GetNkeys() << "things in it" << endl;
     TIterator* iter = list->MakeIterator();
     
     TObject* obj = 0;
     TObject* canvas = 0;
     Bool_t makeCanvas = false;
     
     canvas = gROOT->GetListOfCanvases()->FindObject(canvasName);
     //If canvas does not exist, remember to create it
     //     cout << "found our canvas" << endl;
     if (! canvas) makeCanvas = true;
     
     while (obj = iter->Next()) {
       //       cout << "We have an object" << endl;
       if (! obj->InheritsFrom(TH1::Class())) continue;
       
       TString name = obj->GetName();
       //       cout << "Testing object of name " << name << endl;
       
       //       if (TString(patORpfx).MaybeRegexp()) { THIS BASICALLY ADDS IT IF IT HAS A BLEEPING PULSE
       if (TString(name).Contains(patORpfx)) {
	 //	 cout << "possible match" << endl;
	 if (TString(obj->GetName()).Index(reg) < 0 ) {
	   //	   cout << "not a match here" << endl;
	   continue;
	 } 
	 else if (! name.BeginsWith(patORpfx)) {
	   //	   cout << "mismatched beginning" << endl;
	   continue;
	 }
       
	 
	 if (makeCanvas) {
	   canvas = new TCanvas(canvasName, canvasName);
	   makeCanvas = false;
	 }
	 
	 ((TH1*)obj)->UseCurrentStyle();
	 ((TCanvas*)canvas)->cd();
	 if (!((TCanvas*)canvas)->GetListOfPrimitives()->GetEntries()) {
	   //	   cout << "Drawing with non-same option" << endl;
	   ((TH1*)obj)->Draw(Form("%s", drawOption));
	 }
	 else {
	   //	   cout << "Drawing with the same option" << endl;
	   ((TH1*)obj)->Draw(Form("SAME%s", drawOption));
	 }
       }
     }
     
     hist::colors((TCanvas*)canvas);

   }
Exemple #19
0
TH1* KVCanvas::FindHisto()
{
   TObject* hh = 0;
   TIter it(GetListOfPrimitives());
   while ((hh = (TObject*)it())) {
      if (hh->InheritsFrom("TH1")) return (TH1*) hh;
   }
   return 0;
}
void KVINDRAOnlineDataAnalyser::addallhistostoserver(TCollection* list, const TString& family_pref)
{
   TIter next(list);
   TObject* obj;
   TString family = "";
   while ((obj = next())) {
      if (obj->InheritsFrom("TCollection")) {
         family = family_pref + "/";
         family += obj->GetName();
         addallhistostoserver((TCollection*)obj, family);
      } else if (obj->InheritsFrom("TH1")) {
         if (fSpectraDB) {
            Info("KVINDRAOnlineDataAnalyser", "Adding histo %s to family %s", obj->GetName(), family_pref.Data());
            fSpectraDB->AddSpectrum((TH1*)obj, family_pref.Data());
         }
      }
   }
}
Exemple #21
0
void DynamicExec()
{
   // Example of function called when a mouse event occurs in a pad.
   // When moving the mouse in the canvas, a second canvas shows the
   // projection along X of the bin corresponding to the Y position
   // of the mouse. The resulting histogram is fitted with a gaussian.
   // A "dynamic" line shows the current bin position in Y.
   // This more elaborated example can be used as a starting point
   // to develop more powerful interactive applications exploiting CINT
   // as a development engine.
   //
   // Author:  Rene Brun
   
   TObject *select = gPad->GetSelected();
   if(!select) return;
   if (!select->InheritsFrom("TH2")) {gPad->SetUniqueID(0); return;}
   TH2 *h = (TH2*)select;
   gPad->GetCanvas()->FeedbackMode(kTRUE);

   //erase old position and draw a line at current position
   int pyold = gPad->GetUniqueID();
   int px = gPad->GetEventX();
   int py = gPad->GetEventY();
   float uxmin = gPad->GetUxmin();
   float uxmax = gPad->GetUxmax();
   int pxmin = gPad->XtoAbsPixel(uxmin);
   int pxmax = gPad->XtoAbsPixel(uxmax);
   if(pyold) gVirtualX->DrawLine(pxmin,pyold,pxmax,pyold);
   gVirtualX->DrawLine(pxmin,py,pxmax,py);
   gPad->SetUniqueID(py);
   Float_t upy = gPad->AbsPixeltoY(py);
   Float_t y = gPad->PadtoY(upy);

   //create or set the new canvas c2
   TVirtualPad *padsav = gPad;
   TCanvas *c2 = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("c2");
   if(c2) delete c2->GetPrimitive("Projection");
   else   c2 = new TCanvas("c2","Projection Canvas",710,10,700,500);
   c2->SetGrid();
   c2->cd();

   //draw slice corresponding to mouse position
   Int_t biny = h->GetYaxis()->FindBin(y);
   TH1D *hp = h->ProjectionX("",biny,biny);
   hp->SetFillColor(38);
   char title[80];
   sprintf(title,"Projection of biny=%d",biny);
   hp->SetName("Projection");
   hp->SetTitle(title);
   hp->Fit("gaus","ql");
   hp->GetFunction("gaus")->SetLineColor(kRed);
   hp->GetFunction("gaus")->SetLineWidth(6);
   c2->Update();
   padsav->cd();
}
Exemple #22
0
void recurse(std::string path,double lum)
{
  TList* list =gDirectory->GetListOfKeys() ;
  TIter next(list);
  TKey *key;
  TObject* obj ;
  std::string lastname = "BOWZINGLES";
  
  while ( key = (TKey*)next() ) {
    obj = key->ReadObj() ;
    if (obj->InheritsFrom("TDirectory"))
      { 
	gDirectory->cd(obj->GetName());
	recurse(path+"/"+obj->GetName(),lum);
	gDirectory->cd("..");
      }

    TString hname=path+"/"+obj->GetName();
    if (obj->InheritsFrom("TH1") && (filled.count(hname)==0))
      {
	filled.insert(hname);
	if ( histos.find(hname) !=histos.end())
	  {
	    histos[hname].his->Add((TH1*) obj,1);
	    histos[hname].his->SetNormFactor(histos[hname].his->GetNormFactor()+lum);
	    delete obj;
	  }
	else
	  {
	    ((TH1*) obj)->SetDirectory(0);
	    histos[hname].path=path;
	    histos[hname].his=(TH1*) obj;
	    histos[hname].his->SetNormFactor(lum);
	  }
      }

    else
      delete obj;
 
}
  
}
Exemple #23
0
  // Sumw2 all your bleep if you're a muppet (like Tom) and forgot to do it in
  // your analysis code
  void sumw2Everything() {
    TList* list = gDirectory->GetList();
    TIterator* iter = list->MakeIterator();

    TObject* obj = 0;
    while (obj = iter->Next()) {
      if (! obj->InheritsFrom(TH1::Class())) continue;

      ((TH1F*)obj)->Sumw2();
    }
  }
Exemple #24
0
  // Multiply everything by a scale factor
  void normalize_all_by_single_SF(double factor) {
    TList* list = gDirectory->GetList();
    TIterator* iter = list->MakeIterator();

    TObject* obj = 0;
    while (obj = iter->Next()) {
      if (! obj->InheritsFrom(TH1::Class())) continue;

      ((TH1F*)obj)->Scale(factor);
    }
  }
Exemple #25
0
  void add(const char* outHistName, const char* patORpfx) {
    TRegexp reg(patORpfx, kFALSE);
    
    TList* list = gDirectory->GetList() ;
    TIterator* iter = list->MakeIterator();
    
      TObject* obj = 0;
      TObject* hist = 0;
      Bool_t makeOutHist = false;

      hist = gDirectory->Get(outHistName);
      //If out hist does not exist, remember to create it
      if (! hist) makeOutHist = true;

      while (obj = iter->Next()) {
         if (! obj->InheritsFrom(TH1::Class())) continue;

         TString name = obj->GetName();
         //Don't add out hist
         if (name == TString(outHistName)) continue;

         if (TString(patORpfx).MaybeRegexp()) {
            if (TString(obj->GetName()).Index(reg) < 0 ) continue;
         } else if (! name.BeginsWith(patORpfx)) continue;

         if (makeOutHist) {
            hist = obj->Clone(outHistName);

            if (hist->InheritsFrom(TH2::Class()))
               ((TH2*)hist)->Reset();
            else
               ((TH1*)hist)->Reset();

            ((TH1*)hist)->SetTitle(outHistName);
            ((TH1*)hist)->Sumw2();
            makeOutHist = false;
         }

         ((TH1*)hist)->Add((TH1*)obj);
      }
   }
Exemple #26
0
  // normalize all your bleep to 1
  void normalizeAllToUnity() {
     TList* list = gDirectory->GetList();
    TIterator* iter = list->MakeIterator();

    TObject* obj = 0;
    while (obj = iter->Next()) {
      if (! obj->InheritsFrom(TH1::Class())) continue;
      int nBins = ((TH1F*)obj)->GetNbinsX();
      Float_t integral = ((TH1F*)obj)->Integral(1, nBins+1);
      if (integral > 0) ((TH1F*)obj)->Scale(1/integral);
    }
  }
Exemple #27
0
TGraph* autogain(TH1 *hist,TNucleus *nuc) {    //Display The fits on a TPad  

   if(!hist || !nuc)
      return 0;

   nuc->SetSourceData();

   if(nuc->GetA() == 152) {
      return autogain152(hist);
   }

// Search
   hist->GetXaxis()->SetRangeUser(200.,16000.);
   TSpectrum *s = new TSpectrum();
   Int_t nfound = s->Search(hist,6,"",0.1); //This will be dependent on the source used.
   printf("Found %d candidate peaks to fit\n",nfound);
// Match

   nuc->TransitionList.Sort();

   std::vector<float> engvec;
   TIter iter(&(nuc->TransitionList));
   TObject* obj;
   while(obj = iter.Next()) {
      if(!obj->InheritsFrom("TGRSITransition"))
         continue;
      TGRSITransition *tran = (TGRSITransition*)obj;

      engvec.push_back(static_cast<float>(tran->energy));
      if(engvec.size() == nfound)
         break;
   }

   if(nfound != engvec.size())
      return 0;

   Float_t *posPeaks = s->GetPositionX();
   Float_t *energies = &(engvec[0]);

   for(int x=0;x<nfound;x++) {
      printf("posPeaks[%i] = %f\t\tenrgies[%i] = %f\n",x,posPeaks[x],x,energies[x]);
   }

   TGraph *slopefit = new TGraph(nfound,posPeaks,energies ); 

   printf("Now fitting: Be patient\n");
   slopefit->Fit("pol1");
   slopefit->Draw("AC*");

   return slopefit;

}
Bool_t RsnConfigTest
(
   AliRsnAnalysisTask *task,
   Bool_t              isMC
)
{
	
// 	cutBPIDKaonSet
   // find the index of the corresponding list in the RsnInputHandler
   const char *listNameQuality = "qualityTPC";
   const char *listNamePID     = "kaonTPC";
   Int_t       qualityID       = -1;
   Int_t       pidID           = -1;
   AliAnalysisManager        *mgr   = AliAnalysisManager::GetAnalysisManager();
   AliMultiInputEventHandler *multi = dynamic_cast<AliMultiInputEventHandler*>(mgr->GetInputEventHandler());
   if (multi) {
      TObjArray *array = multi->InputEventHandlers();
      TObjArrayIter next(array);
      TObject *obj;
      while ( (obj = next()) ) {
         if (obj->InheritsFrom(AliRsnInputHandler::Class())) {
            AliRsnInputHandler *rsn = (AliRsnInputHandler*)obj;
            AliRsnDaughterSelector *sel = rsn->GetSelector();
            qualityID = sel->GetID(listNameQuality, kTRUE);
            pidID = sel->GetID(listNamePID, kTRUE);
         }
      }
   }
//    if (qualityID < 0) {
//       ::Error("RsnConfigTest", "Selector does not contain list for quality only");
//       return kFALSE;
//    }
//    if (pidID < 0) {
//       ::Error("RsnConfigTest", "Selector does not contain list for quality+PID");
//       return kFALSE;
//    }
   ::Info("RsnConfigTest", "ID for cut set named '%10s' = %d", listNameQuality, qualityID);
//    ::Info("RsnConfigTest", "ID for cut set named '%10s' = %d", listNamePID, pidID);
   
	   // add pair computation
   AddPairLoop(task, isMC, 0, 0, "test");
   // add monitor computation
   AddMonitorLoop(task, isMC, 0, "test");
	
//    // add pair computation
//    AddPairLoop(task, isMC, qualityID, qualityID, "test");
//    // add monitor computation
//    AddMonitorLoop(task, isMC, qualityID, "test");
// 	AddMonitorLoop(task, isMC, pidID, "test");
   return kTRUE;
}
Exemple #29
0
TFrame* GetFrame(TPad* pad)
{
  if (!pad) pad = (TPad*)gPad;
  if (!pad) return 0;
  TList* lst = pad->GetListOfPrimitives();
  int size = lst->GetSize();
  TFrame* frm=0;
  for (int i=0;i<size;i++) {
    TObject* obj = lst->At(i);
    if (!obj) continue;
    if (obj->InheritsFrom("TFrame")) {frm = (TFrame*)obj; break;}
  }
  return frm;
}
Exemple #30
0
void TriangleClicked() {
   //this action function is called whenever you move the mouse
   //it just prints the id of the picked triangle
   //you can add graphics actions instead
   int event = gPad->GetEvent();
   if (event != 11) return; //may be comment this line
   TObject *select = gPad->GetSelected();
   if (!select) return;
   if (select->InheritsFrom(TPolyLine::Class())) {
      TPolyLine *pl = (TPolyLine*)select;
      printf("You have clicked triangle %d, color=%d\n",
              pl->GetUniqueID(),pl->GetFillColor());
   }
}