示例#1
0
//______________________________________________________________________________
void ArgusHistoDisplay::Modified(Bool_t processEvents)
{
   if (!fCanvas) {
      return;
   }

   Int_t i, j;
   double x1, x2, y1, y2;
   TObject *ptr;

   fStyle->cd();

   for (i = 0; i < fNumberOfPads; i++) {
      fPad[i]->GetRangeAxis(x1, y1, x2, y2);
      for (j = 0; j < fNumberOfCurrentDisplayTypes; j++) {
         ptr = static_cast<TObjArray*>(fObjects->At(fCurrentDisplayType->At(j)))->At(i);
         if (x1 != 0 && TMath::Abs((1.1 - x2) / 1.1) > 1e-6 && y1 !=0 && TMath::Abs((1.1 - y2)/1.1) > 1e-6) {
            if (!strcmp(ptr->ClassName(), "ROMETGraph") ||
                !strcmp(ptr->ClassName(), "ROMETCutG")) {
               static_cast<ROMETGraph*>(ptr)->GetXaxis()->SetRangeUser(x1, x2);
               static_cast<ROMETGraph*>(ptr)->GetYaxis()->SetRangeUser(y1, y2);
            } else {
               static_cast<TH1*>(ptr)->GetXaxis()->SetRangeUser(x1, x2);
               static_cast<TH1*>(ptr)->GetYaxis()->SetRangeUser(y1, y2);
            }
         }
         if (!strcmp(ptr->ClassName(), "ROMETGraph") ||
             !strcmp(ptr->ClassName(), "ROMETCutG")) {
            SetStatisticBox(true);
            // this allows changing X range
            fPad[i]->cd();
            SetLimits(static_cast<TGraph*>(ptr));
         }
      }
      fPad[i]->Modified();
   }

   fCanvas->GetCanvas()->cd(1);
   fCanvas->GetCanvas()->Modified();
   fCanvas->GetCanvas()->Update();

   if (processEvents) {
      gROME->GetApplication()->DisableFPETrap();
      gSystem->ProcessEvents();
      gROME->GetApplication()->EnableFPETrap();
      gSystem->Sleep(10);
   }
}
示例#2
0
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;
}
示例#3
0
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();  

}
示例#4
0
TH1F * getHisto(TFile * file, const char * name, double fMin, double fMax, unsigned int rebin) {
  TObject * h = file->Get(name);
  if(h == 0)
    cout  << "Can't find object " << name << "\n";
  TH1F * histo = dynamic_cast<TH1F*>(h);
  if(histo == 0)
    cout << "Object " << name << " is of type " << h->ClassName() << ", not TH1\n";
  TH1F * new_histo = new TH1F(name, name, (int) (fMax-fMin), fMin, fMax);
  int bin_num=0;
  for (int i = (int)fMin; i <= (int)fMax; ++i ) {
    bin_num= (i - (int)fMin + 1);  
    new_histo->SetBinContent( bin_num, histo->GetBinContent(i) );				    
  } 
  delete histo;
  new_histo->Sumw2();
  new_histo->Rebin(rebin);
  for(int i = 1; i <= new_histo->GetNbinsX(); ++i) {
    if(new_histo->GetBinContent(i) == 0.00) {
      cout<< " WARNING: histo " << name << " has 0 enter in bin number " << i << endl;   
        }
    if(new_histo->GetBinContent(i) < 0.1) {
      new_histo->SetBinContent(i, 0.0);
      new_histo->SetBinError(i, 0.0);
       cout<< " WARNING: setting value 0.0 to histo " << name << " for bin number " << i << endl;   
    }  
  }
  
  return new_histo;
}
示例#5
0
void KVLVContainer::OpenContextMenu(TGFrame* f, Int_t but, Int_t x, Int_t y)
{
    // Open context menu when user right-clicks an object in the list.
    // Calling AllowContextMenu(kFALSE) will disable this.
    // We also fill the list fPickOrderedObjects with the selected objects
    // in the order of clicking
    //
    // if fUseObjLabelAsRealClass=kTRUE (and if objects inherit from KVBase)
    // then the context menu opened will be that of the class given by
    // KVBase::GetLabel. The object's KVBase::GetObject() method must
    // return the real object to use.

    if (but == kButton1) {
        TGLVEntry* el = (TGLVEntry*)f;
        TObject* ob = (TObject*)el->GetUserData();
        if (!fControlClick || !GetMultipleSelection()) fPickOrderedObjects->Clear();
        if (ob) {
            Bool_t in_list = fPickOrderedObjects->FindObject(ob);
            if (in_list) fPickOrderedObjects->Remove(ob);
            else fPickOrderedObjects->AddLast(ob);
        }
        return;
    }

    // context menus globally disabled and no exceptions defined
    if (!fAllowContextMenu && !fContextMenuClassExceptions) return;

    if (but == kButton3) {
        //        Error("OpenContextMenu","x=%d y=%d",x,y);
        //        fContextMenu->Popup(x,y,this); return;

        TGLVEntry* el = (TGLVEntry*)f;
        TObject* ob = (TObject*)el->GetUserData();
        if (ob) {

            TObject* CMob = ob;
            TString CMobClass = ob->ClassName();

            if (fUseObjLabelAsRealClass && ob->TestBit(KVBase::kIsKaliVedaObject)) {
                KVBase* bob = dynamic_cast<KVBase*>(ob);
                CMobClass = bob->GetLabel();
                CMob = bob->GetObject();
            }
            // check class context menu status
            if (fContextMenuClassExceptions) {
                if ((!fAllowContextMenu && fContextMenuClassExceptions->FindObject(CMobClass))
                        || (fAllowContextMenu && !fContextMenuClassExceptions->FindObject(CMobClass)))
                    fContextMenu->Popup(x, y, CMob);
            } else if (fAllowContextMenu)  fContextMenu->Popup(x, y, CMob);
        }
    }
}
示例#6
0
//------------------------------------------------------------------------------
TObject* PlotAlignmentValidation::findObjectFromCanvas(TCanvas* canv, const char* className, Int_t n) {
  // Finds the n-th instance of the given class from the canvas
  TIter next(canv->GetListOfPrimitives());
  TObject* obj = 0;
  Int_t found = 0;
  while ((obj = next())) {
    if(strncmp(obj->ClassName(), className, 10) == 0) {
      if (++found == n)
        return obj;
    }
  }

  return 0;
}
示例#7
0
void RootWImage::saveSummaryLoop(TPad* basePad, std::string baseName, TFile* myTargetFile) {
  TList* aList;
  TObject* anObject;
  TPad* myPad;
  std::string myClass;
  std::string myName;

  TNamed* aNamed;

  // TSystemFile* aFile;
  // string aFileName;
  // string aFileNameTail;
  // TFile* myRootFile;

  aList = basePad->GetListOfPrimitives();
  for (int i=0; i<aList->GetEntries(); ++i) {
    anObject = aList->At(i);
    myClass = anObject->ClassName();
    if (myClass=="TPad") { // Go one step inside
      myPad = (TPad*) anObject;
      saveSummaryLoop(myPad, baseName, myTargetFile);
    } else if (
	       (myClass=="TProfile") ||
	       (myClass=="TGraph") ||
	       (myClass=="TH1D") ||
	       (myClass=="TH2C") ||
	       (myClass=="TH2D") ||
	       (myClass=="THStack") 
	       ) {
      aNamed = (TNamed*) anObject;
      myTargetFile->cd();
      myName = Form("%s.%s", baseName.c_str(), aNamed->GetName());
      myName = RootWeb::cleanUpObjectName(myName);
      aNamed->SetName(myName.c_str());
      aNamed->Write();
    } else if (
	       (myClass=="TEllipse") ||
	       (myClass=="TFrame") ||
	       (myClass=="TLatex") ||
	       (myClass=="TLegend") ||
	       (myClass=="TLine") ||
	       (myClass=="TPaveText") ||
	       (myClass=="TPolyLine") ||
	       (myClass=="TText") 
	       ) {
    } else {
      std::cerr << Form("Unhandled class %s", myClass.c_str()) << std::endl;
    }
  }
}
示例#8
0
  /** 
   * Get an object from a collection 
   * 
   * @param c    Collection
   * @param name Name of object
   * @param cl   Possible class to check against
   * @param verbose  Be verbose
   * 
   * @return Pointer to object or null
   */
  static TObject* GetObject(TCollection* c, const TString& name, 
			    TClass* cl, Bool_t verbose=true)
  {
    TObject* o = c->FindObject(name);
    if (!o) { 
      if (verbose)
	Warning("GetObject", "%s not found in %s", name.Data(), c->GetName());
      return 0;
    }
    if (cl && !o->IsA()->InheritsFrom(cl)) {
      if (verbose) 
	Warning("GetCollection", "%s is not a %s but a %s", 
		name.Data(), cl->GetName(), o->ClassName());
      return 0;
    }
    return o;
  }
示例#9
0
// A function that get histogram and sets contents to 0 
// if entries are too small
TH1 * getHisto(TFile * file, const char * name, unsigned int rebin) {
  TObject * h = file->Get(name);
  if(h == 0)
    throw edm::Exception(edm::errors::Configuration) 
      << "Can't find object " << name << "\n";
  TH1 * histo = dynamic_cast<TH1*>(h);
  if(histo == 0)
    throw edm::Exception(edm::errors::Configuration) 
      << "Object " << name << " is of type " << h->ClassName() << ", not TH1\n";
  histo->Rebin(rebin);  
  for(int i = 1; i <= histo->GetNbinsX(); ++i) {
    if(histo->GetBinContent(i) < 0.1) {
      histo->SetBinContent(i, 0.0);
      histo->SetBinError(i, 0.0);
    }
  }
  return histo;
}
示例#10
0
  //____________________________________________________________________
  static TObject* GetO(TDirectory* dir, const char* name, TClass* cls=0)
  {
    if (!dir) {
      Warning("GetO", "No directory passed");
      return 0;
    }

    TObject* o = dir->Get(name);
    if (!o) {
      Warning("GetO", "object %s not found in %s",
	      name, dir->GetPath());
      return 0;
    }
    if (!cls) return o;
    if (!o->IsA()->InheritsFrom(cls)) {
      Warning("GetO", "Object %s in %s is not a %s, but a %s",
	      name, dir->GetPath(), cls->GetName(), o->ClassName());
      return 0;
    }
    return o;
  }
示例#11
0
Bool_t fitsHere(TLegend *l,Double_t x1, Double_t y1, Double_t x2, Double_t y2)
{
    Bool_t fits = true;
    TList *list = l->GetListOfPrimitives();
    for (Int_t k = 0; list->At(k) != 0 && fits; k++)
    {
        TObject *obj = ((TLegendEntry*)(list->At(k)))->GetObject();
        if (obj == 0) continue;
        TClass *cl = obj->IsA();

        //Histogram, drawn as a histogram
        if (cl->InheritsFrom("TH1") && !cl->InheritsFrom("TH2") && !cl->InheritsFrom("TH3")
         && cl != TProfile::Class() && ((TH1*)obj)->GetMarkerColor() == kWhite)
        {
            Int_t where = 0;
            TH1 *h = (TH1*)obj;
            for (Int_t i = 1; i <= h->GetNbinsX() && fits; i++)
            {
                if (h->GetBinLowEdge(i) + h->GetBinWidth(i) < x1) continue;   //to the left of the legend
                if (h->GetBinLowEdge(i)                     > x2) continue;   //to the right of the legend
                if (h->GetBinContent(i) > y1 && h->GetBinContent(i) < y2) fits = false;   //inside the legend
                if (h->GetBinContent(i) < y1)
                {
                    if (where == 0) where = -1;             //below the legend
                    if (where == 1) fits = false;           //a previous bin was above it so there's a vertical line through it
                }
                if (h->GetBinContent(i) > y2)
                {
                    if (where == 0) where = 1;              //above the legend
                    if (where == -1) fits = false;          //a previous bin was below it so there's a vertical line through it
                }
            }
            continue;
        }
        //Histogram, drawn with Draw("P")
        else if (cl->InheritsFrom("TH1") && !cl->InheritsFrom("TH2") && !cl->InheritsFrom("TH3")
              && cl != TProfile::Class())
        //Probably TProfile would be the same but I haven't tested it
        {
            TH1 *h = (TH1*)obj;
            for (Int_t i = 1; i <= h->GetNbinsX() && fits; i++)
            {
                if (h->GetBinLowEdge(i) + h->GetBinWidth(i)/2 < x1) continue;
                if (h->GetBinLowEdge(i)                       > x2) continue;
                if (h->GetBinContent(i) > y1 && h->GetBinContent(i) < y2) fits = false;
                if (h->GetBinContent(i) + h->GetBinError(i) > y2 && h->GetBinContent(i) - h->GetBinError(i) < y2) fits = false;
                if (h->GetBinContent(i) + h->GetBinError(i) > y1 && h->GetBinContent(i) - h->GetBinError(i) < y1) fits = false;
            }
        }
        else if (cl->InheritsFrom("TF1") && !cl->InheritsFrom("TF2"))
        {
            //TF1 *f = (TF1*)obj;
            //Double_t max = f->GetMaximum(x1,x2);
            //Double_t min = f->GetMinimum(x1,x2);
            //if (min < y2 && max > y1) fits = false;
        }
        // else if (cl->InheritsFrom(...... add more objects here
        else
        {
            cout << "Don't know how to place the legend around objects of type " << obj->ClassName() << "." << endl
                 << "Add this class into placeLegend.C if you want it to work properly." << endl
                 << "The legend will still be placed around any other objects." << endl;
        }
    }
    return fits;
}
示例#12
0
void addn2() {

  // open existing f1:

  char* fn[99];
  int ni;

  // SR90 maps, mod D003

  ni = -1;
  ni++; fn[ni] = "SR90-map-00a.root";
  ni++; fn[ni] = "SR90-map-00b.root";
  ni++; fn[ni] = "SR90-map-01a.root";
  ni++; fn[ni] = "SR90-map-01b.root";
  ni++; fn[ni] = "SR90-map-02.root";
  ni++; fn[ni] = "SR90-map-03.root";
  ni++; fn[ni] = "SR90-map-05a.root";
  ni++; fn[ni] = "SR90-map-05b.root";
  ni++; fn[ni] = "SR90-map-07a.root";
  ni++; fn[ni] = "SR90-map-07b.root";
  ni++; fn[ni] = "SR90-map-07c.root";
  ni++; fn[ni] = "SR90-map-07d.root";

  // direct X-rays 9.4.2014 module D0003

  ni = -1;
  ni++; fn[ni] = "X-ray-20-modtd40000.root";
  ni++; fn[ni] = "X-ray-20-vthr60-modtd1000.root";
  ni++; fn[ni] = "X-ray-27-vthr60-modtd1000.root";
  ni++; fn[ni] = "X-ray-35-modtd40000.root";
  ni++; fn[ni] = "X-ray-35-vthr60-close-modtd65000.root";
  ni++; fn[ni] = "X-ray-35-vthr60-midpos-0p1mA-modtd10000.root";
  ni++; fn[ni] = "X-ray-35-vthr60-midpos-halfcur-modtd40000.root";
  ni++; fn[ni] = "X-ray-35-vthr60-modtd40000.root";

  int nmax = ni;

  TFile f1(fn[0]);

  if( f1.IsZombie() ) {
    cout << "Error opening " << fn[0] << endl;
    return;
  }
  cout << "opened " << fn[0] << endl;

  //--------------------------------------------------------------------
  // create f0:

  TFile f0("fileA.root", "RECREATE");
  cout << "created ";
  gDirectory->pwd();

  /*
  TFile options:  
  NEW or CREATE   create a new file and open it for writing,
                  if the file already exists the file is
                  not opened.
  RECREATE        create a new file, if the file already
                  exists it will be overwritten.
  UPDATE          open an existing file for writing.
                  if no file exists, it is created.
  READ            open an existing file for reading (default).
  NET             used by derived remote file access
                  classes, not a user callable option
  WEB             used by derived remote http access
                  class, not a user callable option
  "" (default), READ is assumed.
  */

  //--------------------------------------------------------------------
  // copy f1 to f0:

  f1.cd();

  cout << "keys:\n";
  f1.GetListOfKeys()->Print();

  cout << "pwd: ";
  f1.pwd();

  cout << "ls: \n";
  f1.ls();

  // f1 has sub-dir:

  cout << "First: " << f1.GetListOfKeys()->First()->GetName() << endl;
  cout << "First: " << f1.GetListOfKeys()->First()->ClassName() << endl;
  char* dir1 = f1.GetListOfKeys()->First()->GetName();
  cout << "cd to " << dir1 << endl;
  f1.cd( dir1 );
  cout << "we are in ";
  gDirectory->pwd();

  gDirectory->ReadAll(); // load histos

  TList * lst = gDirectory->GetList();
  cout << lst->GetName() << endl;
  cout << lst->GetTitle() << endl;
  cout << "size    " << lst->GetSize() << endl;
  cout << "entries " << lst->GetEntries() << endl;
  cout << "last    " << lst->LastIndex() << endl;

  TIterator *iter = lst->MakeIterator();
  int ii = 0;
  TObject *obj;
  TH1D *h;
  TH1D *h0;
  TH2D *H;
  TH2D *H0;

  while( obj = iter->Next() ){
    ii++;
    cout << setw(4) << ii << ": ";
    cout << obj->ClassName() << " ";
    cout << obj->InheritsFrom("TH1D") << " ";
    cout << obj->GetName() << " \"";
    cout << obj->GetTitle() << "\"";
    cout << endl;
    //    if( obj->ClassName() == "TH1D" ){
    if( obj->InheritsFrom("TH1D") ){
      h = (TH1D*) obj;
      cout << "       1D";
      cout << h->GetNbinsX() << " bins, ";
      cout << h->GetEntries() << " entries, ";
      cout << h->GetSumOfWeights() << " inside, ";
      cout << h->GetBinContent(0) << " under, ";
      cout << h->GetBinContent(h->GetNbinsX()+1) << " over";
      cout << endl;

      f0.cd(); // output file

      //      TH1D* h0 = (TH1D*) h->Clone();
      h0 = h; // copy
      h0->Write(); // write to file f0
      
      f1.cd(); // back to file 1 for the loop
    }
    else{

      if( obj->InheritsFrom("TH2D") ){

	H = (TH2D*) obj;
	cout << "       2D";
	cout << H->GetNbinsX() << " bins, ";
	cout << H->GetEntries() << " entries, ";
	cout << H->GetSumOfWeights() << " inside, ";
	cout << H->GetBinContent(0) << " under, ";
	cout << H->GetBinContent(H->GetNbinsX()+1) << " over";
	cout << endl;
	
	f0.cd(); // output file
	
	H0 = H; // copy
	H0->Write(); // write to file f0
	
	f1.cd(); // back to file 1 for the loop
      }
      else cout << "other class " << obj->ClassName() << endl;
    }
  }
  cout << "copied " << ii << endl;
  cout << "f1 " << f1.GetName() << " close = " << f1.Close() << endl;
    
  f0.cd();
  cout << "we are in ";
  gDirectory->pwd();

  cout << "f0 " << f0.GetName() << " size  = " << f0.GetSize() << endl;

  cout << "f0 " << f0.GetName() << " write = " << f0.Write() << endl;

  cout << "f0 " << f0.GetName() << " size  = " << f0.GetSize() << endl;

  cout << "f0 " << f0.GetName() << " close = " << f0.Close() << endl;

  f0.Delete();

  //--------------------------------------------------------------------
  // list of files 2:

  bool lAB = true;

  for( int nn = 1; nn <= nmax; ++nn ){

    cout << "\n\n";
    cout << "loop " << nn << ": fn = " << fn[nn] << endl;
    cout << "lAB = " << lAB << endl;

    if( lAB ) { // A+2 -> B
      char* fn3 = "fileA.root";
      char* fn4 = "fileB.root";
    }
    else{ // B+2 -> A
      char* fn3 = "fileB.root";
      char* fn4 = "fileA.root";
    }

    // create f4:

    TFile f4( fn4, "recreate" );
    if( f4.IsZombie() ) {
      cout << "Error creating f4\n";
      return;
    }
    cout << "created f4   = " << f4.GetName() << endl;

    // re-open as f3:

    TFile f3( fn3 );
    if( f3.IsZombie() ) {
      cout << "Error opening f3\n";
      return;
    }
    cout << "re-opened f3 = " << f3.GetName() << endl;

    lAB = !lAB;
    cout << "lAB = " << lAB << " for next loop\n";

    cout << "f4 = " << f4.GetName() << endl;
    cout << "f3 = " << f3.GetName() << endl;

    f3.cd();
    gDirectory->ReadAll(); // load histos into f3 memory

    //    cout << "f3 list size = " << gDirectory->GetList()->GetSize() << endl;
    cout << "f3 list size = " << gDirectory->GetList()->GetSize() << endl;

    TFile f2(fn[nn]);
    //    TFile *f2 = new TFile(fn[nn]);

    if( f2.IsZombie() ) {
    //    if( f2 == NULL ) {
      cout << "Error opening " << fn[nn] << endl;
      return;
    }
    cout << "opened " << fn[nn] << endl;

    // f2 has sub-dir:

    f2.cd( f2.GetListOfKeys()->First()->GetName() );
    cout << "we are in ";
    gDirectory->pwd();

    gDirectory->ReadAll(); // load histos into f2 memory

    // loop over f2:

    cout << "f2 list size = " << gDirectory->GetList()->GetSize() << endl;

    int jj = 0;
    TObject *ob2;
    TH1D *h2;
    TH1D *h3;
    TH2D *H2;
    TH2D *H3;

    TIterator *ite2 = gDirectory->GetList()->MakeIterator();

    while( ob2 = ite2->Next() ){

      jj++;

      //      if( jj > 9 ) continue;

      cout << jj << ". ";
      cout << "ob2 is ";
      cout << ob2->GetName() << " ";
      cout << ob2->ClassName() << " ";
      cout << ob2->GetTitle();
      cout << endl;

      if( ob2->InheritsFrom("TH1D") ) {

	h2 = (TH1D*) ob2;
	cout << "h2 " << h2->GetName() << "  " << h2->GetNbinsX() << " bins\n";
	cout << "h2 " << h2->GetName() << "  " << h2->GetEntries() << " entries\n";
	char* hnm2 = h2->GetName();

	// search in f3:

	cout << "search for " << hnm2 << " in f3\n";
	f3.cd();
	cout << "we are in ";
	gDirectory->pwd();
	
	h3 = (TH1D*) gDirectory->GetList()->FindObject(hnm2);
	if( h3 == NULL ) {
	  cout << "h3 is null\n" ;
	  continue;
	}
	
	cout << "found h3 = ";
	cout << h3->GetName() << "  ";
	cout << h3->ClassName() << "  ";
	cout << h3->GetTitle();
	cout << endl;
	cout << "h3  " << h3->GetName() << "  " << h3->GetNbinsX() << " bins\n";
	cout << "h3  " << h3->GetName() << "  " << h3->GetEntries() << " entries\n";

	// add:

	f4.cd();
	cout << "we are in ";
	gDirectory->pwd();
	//TH1D h4 = *h3 + *h2;
	TH1D* h4 = (TH1D*) h3->Clone();
	h4->Add(h2);
	
	cout << "h4  " << h4->GetEntries() << " entries\n";
	cout << "h4  ";
	cout << h4->GetName() << " ";
	cout << h4->ClassName() << " ";
	cout << h4->GetTitle();
	cout << endl;
	cout << "h4 dir " << h4->GetDirectory()->GetName() << endl;
	cout << "f4 size " << f4.GetSize() << endl;

	// back to f2 for next iter:

	f2.cd( f2.GetListOfKeys()->First()->GetName() );

      }//1D

      if( ob2->InheritsFrom("TH2D") ) {

	H2 = (TH2D*) ob2;
	cout << "H2 " << H2->GetName() << "  " << H2->GetNbinsX() << " bins\n";
	cout << "H2 " << H2->GetName() << "  " << H2->GetEntries() << " entries\n";
	char* Hnm2 = H2->GetName();

	// search in f3:

	cout << "search for " << Hnm2 << " in f3\n";
	f3.cd();
	cout << "we are in ";
	gDirectory->pwd();
	
	H3 = (TH2D*) gDirectory->GetList()->FindObject(Hnm2);
	if( H3 == NULL ) {
	  cout << "H3 is null\n" ;
	  continue;
	}
	
	cout << "found H3 = ";
	cout << H3->GetName() << "  ";
	cout << H3->ClassName() << "  ";
	cout << H3->GetTitle();
	cout << endl;
	cout << "H3  " << H3->GetName() << "  " << H3->GetNbinsX() << " bins\n";
	cout << "H3  " << H3->GetName() << "  " << H3->GetEntries() << " entries\n";

	// add:

	f4.cd();
	cout << "we are in ";
	gDirectory->pwd();

	TH2D* H4 = (TH2D*) H3->Clone();
	H4->Add(H2);
	
	cout << "H4  " << H4->GetEntries() << " entries\n";
	cout << "H4  ";
	cout << H4->GetName() << " ";
	cout << H4->ClassName() << " ";
	cout << H4->GetTitle();
	cout << endl;
	cout << "H4 dir " << H4->GetDirectory()->GetName() << endl;
	cout << "f4 size " << f4.GetSize() << endl;

	// back to f2 for next iter:

	f2.cd( f2.GetListOfKeys()->First()->GetName() );
      }//2D

    } //while

    cout << "processed " << jj << endl;
    cout << "f4 " << f4.GetName() << " size " << f4.GetSize() << endl;

    //  cout << "f4 map:\n";
    //  f4.Map();

    cout << "f4 " << f4.GetName() << " write = " << f4.Write() << endl;

    cout << "f4 " << f4.GetName() << " size  = " << f4.GetSize() << endl;
    
  }// loop over files 2

  cout << endl;
  cout << "combined " << nmax + 1 << " files\n";
  cout << "Final file is " << f4.GetName() << endl;

  f2.Close();
  f3.Close();
  f4.Close();

}
示例#13
0
void DrawStatUncertainty()
{
  TFile *f;
  TString ss("ExpStat_PYTHIA_canvasOutFile.root");
  f = new TFile(ss);
  TCanvas *c
  c = (TCanvas*)f->Get("_R92777");
  TString algoTitle;
  algoTitle = "k_{T} D = 0.6";
  TList *li = (TList*)gPad->GetListOfPrimitives();
  TObject *obj;
  
  TIter next(li);
  TH1D *histList[100], *htmp;
  int i,j,N;
  

  while ((obj = (TObject*)next()))
    {
      TString cname = obj->ClassName();
      TString name = obj->GetName();
      
      cout << cname <<" "<<name<<endl;    
      if (cname=="TH1D")
        {
          
          histList[N] = (TH1D*)gPad->FindObject(obj);
          histList[N]->SetFillColor(0);
          histList[N]->SetFillStyle(0);
          N++;
        } 
    }
  
  TCanvas *c = new TCanvas("c","c");
  gPad->SetLogx();
  gPad->SetLogy();
  //histList[0]->SetMaximum(1e+10);
  histList[0]->SetTitle("");
  histList[0]->GetXaxis()->SetTitle("jet p_{T} (GeV)");
  histList[0]->GetXaxis()->SetTitleFont(42);
  histList[0]->GetXaxis()->SetLabelFont(42);
  histList[0]->GetXaxis()->SetTitleSize(0.05);
  histList[0]->GetXaxis()->SetLabelSize(0.05);
  histList[0]->GetYaxis()->SetTitle("Relative Statistical Uncertainty");
  histList[0]->GetYaxis()->SetTitleFont(42);
  histList[0]->GetYaxis()->SetLabelFont(42);
  histList[0]->GetYaxis()->SetTitleSize(0.05);
  histList[0]->GetYaxis()->SetLabelSize(0.05);
  histList[0]->GetYaxis()->SetNdivisions(505);

  histList[0]->SetLineWidth(1);
  histList[0]->SetLineStyle(1);
  histList[0]->SetLineColor(1);
  histList[0]->SetMarkerColor(1);
  histList[0]->SetMarkerStyle(20);
  histList[0]->SetMarkerSize(1.2); 

  histList[1]->SetLineColor(2);
  histList[1]->SetMarkerColor(2);
  histList[1]->SetLineWidth(1);
  histList[1]->SetMarkerStyle(25);
  histList[1]->SetLineStyle(1);
  histList[1]->SetMarkerSize(1.2); 

  histList[2]->SetLineWidth(1);
  histList[2]->SetLineStyle(1);
  histList[2]->SetLineColor(4);
  histList[2]->SetMarkerColor(4);
  histList[2]->SetMarkerStyle(22);
  histList[2]->SetMarkerSize(1.2); 

  histList[0]->Draw("P");
  histList[1]->Draw("sameP");
  histList[2]->Draw("sameP");

  TLegend *leg = new TLegend(0.47,0.2,0.92,0.35);
  leg->SetTextFont(42);
  leg->AddEntry(histList[0],"|y| < 0.55","P");
  leg->AddEntry(histList[1],"1.10 < |y| < 1.70","P");
  leg->AddEntry(histList[2],"1.70 < |y| < 2.50","P");
  leg->SetFillColor(0);
  leg->SetBorderSize(0);
  leg->Draw();

  TPaveText *pave3 = new TPaveText(0.2,0.65,0.45,0.9,"NDC");
  pave3->SetTextFont(42);
  pave3->AddText("CMS preliminary");
  pave3->AddText(algoTitle);
  pave3->AddText("#sqrt{s} = 10 TeV");
  pave3->AddText("");
  pave3->AddText("#int L dt = 10 pb^{-1}");
  pave3->SetFillColor(0);
  pave3->SetBorderSize(0);
  pave3->Draw();

  c->Print("KT6_StatUncertainty.eps");
  
}
示例#14
0
void ojtable(const char *className)
{
    static int fTableOffset = 0;
    if (!fTableOffset) fTableOffset = gObjectTable->IsA()->GetDataMemberOffset("fTable");
//  gObjectTable->Print();
    TClass *kl;
    if (className && !*className) className=0;

    const char *qwe = ".*";
    if (className) qwe = className;
    TRegexp regexp(qwe);
    int regexpLen=0;

    int sz = gObjectTable->GetSize();
    int *ptr = new int[sz];
    int *idx = new int[sz];

    TObject **tab = *((TObject ***)((char*)gObjectTable+fTableOffset));
    TObject *to;
    printf ("tab %p[%d]\n",tab,sz);
    int i,num=0;
    double hSize=0;
    int    hNumb=0;
    const char *info_name = 0;
    for (i=0; i<sz; i++)
    {
        to = tab[i];
        if (!to) 						continue;
        if (!to->TestBit(TObject::kNotDeleted))  		continue;
        int hs = SizeOfH(to);
        if (hs) {
            hSize+=hs;
            hNumb++;
        }
        if (className && regexp.Index(to->ClassName(),&regexpLen)<0)	continue;
        const char *mk = StMkDeb::GetUser(to);
        if(mk && *mk) printf("%s(%p) in %s\n",to->ClassName(),to,mk);
        ptr[num++]=int(to);
    }
    printf("TH1 N=%d, Size = %g\n",hNumb,hSize);

    TMath::Sort(num,ptr,idx,0);
    int last = 0;
    printf("Selected %d objects\n",num);
    for (i=0; i<num; i++) {
        int ix = idx[i];
        to = (TObject*)ptr[ix];
        int dist = 0;
        if (i) dist = ptr[ix]-last;
        last = ptr[ix];

//    if ((int)to == 0xc94ff34) {
//       printf("Skipped %p\n",to); continue; }

        info_name = "??";
        info_name=typeid(*to).name();
        kl = to->IsA();
        printf ("%4d +%6d : obj = %p(%3d) %s::%s \tinfo=%s\n",i,dist,to,kl->Size(),kl->GetName(),to->GetName(),info_name);

        if (strcmp("TClonesArray",kl->GetName())) continue;
        TClonesArray *tcl = ((TClonesArray*)to);
        printf(" Sizes = %d %d\n",tcl->GetLast()+1,tcl->Capacity());
        tcl->ls("");




    }
    delete [] ptr;
    delete [] idx;
}
void DrawLogInclusivePlots(TString ALGO)
{
  TFile *f;
  TString ss(ALGO+"canvasOutFile.root");
  f = new TFile(ss);
  TCanvas *c
  c = (TCanvas*)f->Get("_R80570");
  TString algoTitle;
  if (ALGO=="KT6")
    algoTitle = "k_{T} D = 0.6";
  else
    algoTitle = "SISCone R = 0.7";
  TList *li = (TList*)gPad->GetListOfPrimitives();
  TObject *obj;
  
  TIter next(li);
  TH1D *histList[100], *htmp;
  int i,j,N;
  

  while ((obj = (TObject*)next()))
    {
      TString cname = obj->ClassName();
      TString name = obj->GetName();
      
      cout << cname <<" "<<name<<endl;    
      if (cname=="TH1D")
        {
          
          histList[N] = (TH1D*)gPad->FindObject(obj);
          histList[N]->SetFillColor(0);
          histList[N]->SetFillStyle(0);
          N++;
        } 
    }
  
  TCanvas *c = new TCanvas("c","c");
  gPad->SetLogx();
  gPad->SetLogy();
  histList[0]->SetMaximum(1e+10);
  histList[0]->SetTitle("");
  histList[0]->GetXaxis()->SetTitle("jet p_{T} (GeV)");
  histList[0]->GetXaxis()->SetTitleFont(42);
  histList[0]->GetXaxis()->SetLabelFont(42);
  histList[0]->GetXaxis()->SetTitleSize(0.05);
  histList[0]->GetXaxis()->SetLabelSize(0.05);
  histList[0]->GetXaxis()->SetMoreLogLabels();
  histList[0]->GetXaxis()->SetNoExponent();
  histList[0]->GetYaxis()->SetTitle("d^{2}#sigma/dp_{T}dy (fb/GeV)");
  histList[0]->GetYaxis()->SetTitleFont(42);
  histList[0]->GetYaxis()->SetLabelFont(42);
  histList[0]->GetYaxis()->SetTitleSize(0.05);
  histList[0]->GetYaxis()->SetLabelSize(0.05);
  histList[0]->GetYaxis()->SetNdivisions(505);

  histList[0]->SetLineWidth(2);
  histList[0]->SetLineStyle(1);
  histList[0]->SetLineColor(2);
  histList[1]->SetLineColor(1);
  histList[1]->SetMarkerColor(1);
  histList[1]->SetLineWidth(1);
  histList[1]->SetMarkerStyle(20);
  histList[1]->SetLineStyle(1);

  histList[2]->SetLineWidth(2);
  histList[2]->SetLineStyle(1);
  histList[2]->SetLineColor(2);
  histList[3]->SetLineColor(1);
  histList[3]->SetMarkerColor(1);
  histList[3]->SetLineWidth(1);
  histList[3]->SetMarkerStyle(24);
  histList[3]->SetLineStyle(1);

  histList[4]->SetLineWidth(2);
  histList[4]->SetLineStyle(1);
  histList[4]->SetLineColor(2);
  histList[5]->SetLineColor(1);
  histList[5]->SetMarkerColor(1);
  histList[5]->SetLineWidth(1);
  histList[5]->SetMarkerStyle(21);
  histList[5]->SetLineStyle(1);

  histList[0]->Draw("C");
  histList[1]->Draw("same");
  histList[2]->Draw("sameC");
  histList[3]->Draw("same");
  histList[4]->Draw("sameC");
  histList[5]->Draw("same");

  TLegend *leg = new TLegend(0.47,0.75,0.92,0.9);
  leg->SetTextFont(42);
  leg->AddEntry(histList[1],"0.00 #leq |y| < 0.55 ( #times 32 )","P");
  leg->AddEntry(histList[3],"1.10 < |y| < 1.70 ( #times 16 )","P");
  leg->AddEntry(histList[5],"1.70 < |y| < 2.50 ( #times 8 )","P");
  leg->AddEntry(histList[0],"Theory","L");
  leg->SetFillColor(0);
  leg->SetBorderSize(0);
  leg->Draw();

  TPaveText *pave3 = new TPaveText(0.2,0.2,0.45,0.45,"NDC");
  pave3->SetTextFont(42);
  pave3->AddText("CMS preliminary");
  pave3->AddText(algoTitle);
  pave3->AddText("#sqrt{s} = 10 TeV");
  pave3->AddText("");
  pave3->AddText("#int L dt = 10 pb^{-1}");
  pave3->SetFillColor(0);
  pave3->SetBorderSize(0);
  pave3->SetTextSize(0.04);
  pave3->Draw();

  c->Print(ALGO+"_LogLogComparison.eps");
}
示例#16
0
void plot_ljpsi(const char* fdata, const char* fmc) {
   TFile *tfd = TFile::Open(fdata);
   TFile *tfm = TFile::Open(fmc);

   TCanvas *c1 = new TCanvas();
   c1->cd();
   TPad *p1 = new TPad("p1","",0,0,1,0.33);
   p1->SetBottomMargin(2.*gStyle->GetPadBottomMargin());
   p1->SetTopMargin(0);
   p1->SetFrameBorderMode(0);
   p1->SetBorderMode(0);
   p1->SetBorderSize(0);
   p1->SetGridy();
   if (datamc) p1->Draw();
   TPad *p2 = new TPad("p2","",0,0.33,1,1);
   // p2->SetTopMargin(gStyle->GetPadTopMargin()/(1.-0.2));
   p2->SetBottomMargin(0);
   p2->SetFrameBorderMode(0);
   p2->SetBorderMode(0);
   p2->SetBorderSize(0);
   // p2->SetLogy();
   if (datamc) p2->Draw();
   p1->cd();
   if (!datamc) c1->cd();

   TF1 *dg = new TF1("f1","[0]*([1]*TMath::Gaus(x,[2],[3])+(1-[1])*TMath::Gaus(x,[4],[3]*[5]))",-0.2,0.04);
   dg->SetParLimits(0,0,1e15);
   dg->SetParLimits(1,0.5,1);
   dg->SetParLimits(2,-0.05,0.05);
   dg->SetParLimits(3,0,0.1);
   dg->SetParLimits(4,-0.05,0.05);
   dg->SetParLimits(5,0,100);
   dg->SetParameters(1000,0.8,1e-3,0.03,1e-4,2.);

   TIter next(tfd->GetListOfKeys()); TObject *obj;
   while ((obj = next())) {
      obj = ((TKey*) obj)->ReadObj();
      if (TString(obj->ClassName()) == "TH1F") {
         TH1F *hdata = (TH1F*) tfd->Get(obj->GetName());
         TH1F *hmc = (TH1F*) tfm->Get(obj->GetName());
         // hdata->Rebin(6);
         // hmc->Rebin(6);

         if (!integrate) {
            double int_data = hdata->Integral(hdata->FindBin(-0.015), hdata->FindBin(0.015));
            double int_mc = hmc->Integral(hmc->FindBin(-0.015), hmc->FindBin(0.015));
            hmc->Scale(int_data/int_mc);
         } else {
            double int_mc_all = hmc->Integral(0, hmc->GetNbinsX()+1);
            double int_data_all = hdata->Integral(0, hdata->GetNbinsX()+1);
            hmc->Scale(1./int_mc_all);
            hdata->Scale(1./int_data_all);
            double int_data = hdata->Integral(0, hdata->FindBin(0.));
            double int_mc = hmc->Integral(0, hmc->FindBin(0.));
            hdata->Scale(int_mc/int_data); 
            integrateHist(hdata);
            integrateHist(hmc);
         }
         hdata->GetXaxis()->SetTitle("#font[12]{l}_{J/#psi} [mm]");
         hdata->GetYaxis()->SetTitle("Entries");
         if (integrate) hdata->GetYaxis()->SetTitle("c.d.f.");

         // read the bin from the name
         TString thname(hdata->GetName());
         bool isfwd = (thname.Index("fwd") != kNPOS);
         int pos1 = thname.Index("pt")+2;
         int pos2 = thname.Index("-")-pos1;
         TString tsubstr(thname(pos1,pos2));
         float ptmin = atof(tsubstr.Data());
         pos1 = thname.Index("-")+1;
         pos2 = thname.Length();
         tsubstr = TString(thname(pos1,pos2));
         float ptmax = atof(tsubstr.Data());

         if (datamc) p2->cd();
         hdata->Draw();
         hmc->SetLineColor(kRed);
         hmc->SetMarkerColor(kRed);
         hmc->Draw("same");
         gPad->Update();

         // display the position of the ctau cut
         double a=1,b=1;
         if (!isfwd){a=ctaucut_a_mid_pp; b=ctaucut_b_mid_pp;} 
         else {a=ctaucut_a_fwd_pp; b=ctaucut_b_fwd_pp;}
         double cutmin = a + b / ptmin;
         double cutmax = a + b / ptmax;
         double xmin, xmax, ymin, ymax;
         TBox *tb = new TBox(cutmin,gPad->GetUymin(),cutmax,gPad->GetUymax());
         tb->SetFillColor(kBlack);
         tb->SetFillStyle(3003);
         tb->Draw();

         if (integrate) {
            TLine *tl = new TLine(hdata->GetXaxis()->GetXmin(),0.9,hdata->GetXaxis()->GetXmax(),0.9);
            tl->SetLineStyle(3);
            tl->SetLineColor(kBlack);
            tl->SetLineWidth(5);
            tl->Draw();
         }

         if (datamc) {
            p1->cd();
            TH1F *hratio = (TH1F*) hdata->Clone("hratio");
            hratio->Divide(hmc);
            hratio->GetYaxis()->SetTitle("data/MC");
            hratio->GetYaxis()->SetRangeUser(0.5,1.5);
            hratio->GetXaxis()->SetLabelSize(2.*hratio->GetXaxis()->GetLabelSize());
            hratio->GetXaxis()->SetTitleSize(2.*hratio->GetXaxis()->GetTitleSize());
            hratio->GetYaxis()->SetLabelSize(2.*hratio->GetYaxis()->GetLabelSize());
            hratio->GetYaxis()->SetTitleSize(2.*hratio->GetYaxis()->GetTitleSize());
            hratio->Draw();

            p2->cd();
         }

         // dg->SetParameters(1000,0.8,1e-3,0.03,1e-4,2.);
         // dg->SetParameter(0,int_data);
         // dg->SetParLimits(0,0,int_data*100.);
         // hdata->Fit(dg, "LERQ");
         // double sigma_data = dg->GetParameter(3);
         // double dsigma_data = dg->GetParError(3);
         // dg->SetRange(-5.*sigma_data,1.5*sigma_data);
         // hdata->Fit(dg, "LERQ");
         // sigma_data = dg->GetParameter(3);
         // dsigma_data = dg->GetParError(3);
         // dg->SetRange(-5.*sigma_data,1.5*sigma_data);
         // hdata->Fit(dg, "LERQ");
         // sigma_data = dg->GetParameter(3);
         // dsigma_data = dg->GetParError(3);
         // hmc->Fit(dg, "LERQ");
         // double sigma_mc = dg->GetParameter(3);
         // double dsigma_mc = dg->GetParError(3);

         double lx1=0.61, lx2=0.9, ly1=0.6, ly2=0.88;
         if (integrate) {ly1-=0.4; ly2-=0.4;}
         TLegend *tleg = new TLegend(lx1,ly1,lx2,ly2);
         tleg->SetBorderSize(0);
         TString header("#splitline{");
         header += isfwd ? "1.6<|y|<2.4" : "|y|<1.6";
         header += Form("}{%.1f<pt<%.1f GeV/c}",ptmin,ptmax);
         tleg->SetHeader(header);
         // tleg->AddEntry(hdata,Form("pp data (#sigma = %.3f +/- %.3f)",sigma_data,dsigma_data),"lp");
         // tleg->AddEntry(hmc,Form("pp prompt J/#psi mc (#sigma = %.3f +/- %.3f)",sigma_mc,dsigma_mc),"lp");
         tleg->AddEntry(hdata,"data","lp");
         tleg->AddEntry(hmc,"prompt J/#psi mc","lp");
         tleg->Draw();
         c1->SaveAs(Form("%s.pdf",hdata->GetName()));
         c1->SaveAs(Form("%s.png",hdata->GetName()));
      }
   }
}
示例#17
0
文件: DrawKs.C 项目: ktf/AliPhysics
TH1* GetCentK(TDirectory* top, Double_t c1, Double_t c2, Int_t s,
	      TLegend* l)
{
  TString dname; dname.Form("cent%06.2f_%06.2f", c1, c2);
  dname.ReplaceAll(".", "d");
  TDirectory* d = top->GetDirectory(dname);
  if (!d) {
    Warning("GetCetnK", "Directory %s not found in %s",
	    dname.Data(), top->GetName());
    return;
  }

  TDirectory* det = d->GetDirectory("details");
  if (!det) {
    Warning("GetCetnK", "Directory details not found in %s",
	    d->GetName());
    d->ls();
    return;
  }

  TObject* o = det->Get("scalar");
  if (!o) {
    Warning("GetCetnK", "Object scalar not found in %s",
	    det->GetName());
    return;
  }

  if (!o->IsA()->InheritsFrom(TH1::Class())) {
    Warning("GetCetnK", "Object %s is not a TH1, but a %s",
	    o->GetName(), o->ClassName());
    return;
  }
  TH1* h = static_cast<TH1*>(o->Clone());
  Color_t col = cc[(s-1)%10];
  h->SetLineColor(col);
  h->SetMarkerColor(col);
  h->SetFillColor(col);
  h->SetFillStyle(1001);
  // h->SetTitle(Form("%5.2f-%5.2f%% #times %d", c1, c2, s));
  h->SetTitle(Form("%2.0f-%2.0f%% + %d", c1, c2, s-1));
  TF1* f = new TF1("", "[0]",-2.2,2.2);
  f->SetParameter(0,s-1);
  f->SetLineColor(col);
  f->SetLineStyle(7);
  f->SetLineWidth(1);
  // h->Scale(s);
  h->Add(f);
  h->GetListOfFunctions()->Add(f);
  f->SetParameter(0,s);
  for (Int_t i = 1; i <= h->GetNbinsX(); i++) {
    if (TMath::Abs(h->GetBinCenter(i)) > 2) {
      h->SetBinContent(i,0);
      h->SetBinError(i,0);
    }
  }
  
  TLegendEntry* e = l->AddEntry(h, h->GetTitle(), "f");
  e->SetFillColor(col);
  e->SetFillStyle(1001);
  e->SetLineColor(col);

  return h;
}
/**
 * @file makeConfigurationObjectT0Reconstruction.C
 * @brief Creation of HLT component configuration objects in OCDB
 *
 * <pre>
 * Usage: aliroot -b -q makeConfigurationObjectT0Reconstruction.C'("param", "uri", runMin, runMax)'
 * </pre>
 *
 * Create an OCDB entry with a TObjString containing param for the 
 * T0 reconstruction.
 *
 * Parameters: <br>
 * - param (opt)    string to be stored in the TObjSting, default empty
 * - uri   (opt)    the OCDB URI, default $ALICE_ROOT   
 * - runMin (opt)   default 0
 * - runMax (opt)   default 999999999
 * 
 * Current Param : 
 *  - ""  <pre> aliroot -b -q makeConfigurationObjectT0Reconstruction.C </pre>
 *
 * @author Jochen Thaeder <*****@*****.**>
 * @ingroup alihlt_vzero
 */
void makeConfigurationObjectT0Reconstruction(const Char_t* param="", const Char_t* cdbUri=NULL,
				      Int_t runMin=0, Int_t runMax=AliCDBRunRange::Infinity()) {

  // --------------------------------------
  // -- Setup CDB
  // --------------------------------------
  cout<<" makeConfigurationObjectT0Reconstruction "<<endl;
  AliCDBManager* man = AliCDBManager::Instance();
  if (!man) {
    cerr << "Error : Can not get AliCDBManager" << end;
    exit;
  }

  TString storage;
  if (!man->IsDefaultStorageSet()) {
    if ( cdbUri ) {
      storage = cdbUri;
      if ( storage.Contains("://") == 0 ) {
	storage = "local://"; 
	storage += cdbUri;
      }
    } 
    else {
      storage="local://$ALICE_ROOT/OCDB";
    }
    man->SetDefaultStorage(storage);
  } 
  else {
    storage = man->GetDefaultStorage()->GetURI();
  }

 // TString path("HLT/ConfigT0/T0Reconstruction");
  TString path("HLT/ConfigT0/T0Calibration");
  cout<<path<<endl;

  // --------------------------------------
  // -- Create Config Object
  // --------------------------------------

  // here is the actual content of the configuration object
  TObjString configParam=param;

  TObject *configObj = static_cast<TObject*>(&configParam);
  // --------------------------------------
  // -- Fill Object
  // --------------------------------------
  
  if ( !configObj ) {
    cerr << "Error : No configuration object created" << endl;
    return;
  }
    
  AliCDBPath cdbPath(path);
  AliCDBId   cdbId(cdbPath, runMin, runMax);
  AliCDBMetaData cdbMetaData;
  man->Put(configObj, cdbId, &cdbMetaData);

  printf("Adding %s type OCDB object to %s [%d,%d] in %s \n",
	 configObj->ClassName(), 
	 path.Data(),
	 runMin, runMax, storage.Data());
}
示例#19
0
void rootFileToPsandJpg(TFile* input, string outname = "") {

	cout << "start macro rootFileToPsandJpg" << endl;
	//	HistoDrawUtil::setMyTDRStyle();
	//		gROOT->SetStyle("mytdrStyle");
	//		gROOT->LoadMacro("Util/RootMacros/rootFileToPsandJpg.C");
	//		gStyle->SetOptStat(0);
	//		gStyle->UseCurrentStyle();
	//		gStyle->SetOptStat(0);
	//
	//
	//		cout << "style opt stat:" << gStyle->GetOptStat()<< endl;
	//		cout << "style:" << gStyle->GetTitleXOffset() << endl;
	//
	//		gROOT->ForceStyle(1);
	//		gROOT->UseCurrentStyle();

	//	cout << "OPT TITLE------------------" << gStyle->GetOptTitle() << endl;

	//gROOT->UseCurrentStyle();

	string outputdir = input->GetName();
	cout << "create result.eps and eps-files from file: " << outputdir
			<< "....." << endl;
	int size = outputdir.size();
	string ende = outputdir.substr(size - 5, size);
	if (ende == ".root") {
		outputdir = outputdir.substr(0, size - 5);
	}
	if (outname != "") {
		outputdir = outname;
	}
	TIter nextkey(input->GetListOfKeys());
	//cout << "keylist size" << (input->GetListOfKeys())->GetSize() << endl;
	TKey *key;

	TCanvas *c = new TCanvas;

	system(("mkdir " + outputdir).c_str());
	//const char* outputfile=(outputdir+"/results.eps[").c_str();
	//c->Print(outputfile); // No actual print, just open ps file
	int counter = 0;
	while ((key = (TKey*) nextkey())) {
		counter++;
		if (counter > 2000) {
			break;
		}
		c->Clear();
		string name = key->ReadObj()->GetName();
		//cout << "NAME:" << name << endl;
		TObject* obj = (TObject*) key->ReadObj();
		//cout << "obj" << obj << endl;
		string classname = obj->ClassName();
		if (classname == "TCanvas") {
			//			HistoDrawUtil::setMyTDRStyle();
			//					gROOT->SetStyle("mytdrStyle");
			//			gStyle->SetOptLogy(1);
			//			gROOT->ForceStyle(1);
			TCanvas* canv = (TCanvas*) obj;
			//			HistoDrawUtil::cmsPrel(5.3,0);

			canv->Update();

			//	canv->Print((""+outputdir+"/"+name+".png").c_str());
			//canv->SaveAs(("" + outputdir + "/" + name + ".gif").c_str());
			canv->SaveAs(("" + outputdir + "/" + name + ".pdf").c_str());
			canv->Print(("" + outputdir + "/" + name + ".eps").c_str());
			//		canv->Print((""+outputdir+"/"+name+".pdf").c_str());
			//			TImage *img = TImage::Create();
			//			img->FromPad(canv);
			//			img->WriteImage((outputdir+"/"+name+".gif").c_str());
			//			delete img;
			//canv->Print((outputdir+"/results.eps").c_str(), "");

			delete obj;

		} else {
			cout << "No Canvas!" << endl;
			//      obj->Draw(obj->GetDrawOption());
			//      c->Update();
			//      TImage *img = TImage::Create();
			//      img->FromPad(c);
			//      img->WriteImage((outputdir+"/"+name+".jpg").c_str());
			//      c->Print((outputdir+"/results.eps").c_str(),"");
			//      delete obj;
			//      delete img;
		}

	}
	c->Clear();
	//c->Print((outputdir+"/results.eps]").c_str()); // No actual print, just close the file 
	delete c;
	c = 0;

	//cout<<"done"<<endl;
}
示例#20
0
void getSubSetRoot(TString dirname){
	using namespace ztop;
	using namespace std;

	std::vector<TString> plots;
	plots << "lepton_pt" << "lepton_eta" << "dilepton_mll" << "lepton_multi"
			<< "alllepton_multi" << "lepton_etafine" << "lepton_iso";




	TFile *f =new TFile(dirname+"/raw.root");
	TFile *fout = new TFile(dirname+"/plotHistos.root","RECREATE");

	//get num and den

	std::vector<TString> adds;
	adds << "_num" << "_den" << "_num_mc" << "_den_mc";


	for(size_t i=0;i<plots.size();i++){
		TString plotname=plots.at(i);
		for(size_t j=0;j<adds.size();j++){
			TString name=plotname+adds.at(j);
			TObject * obj = f->Get(name);
			fout->cd();
			obj->Write();
		}
	}

	TFile *f3 =new TFile(dirname+"/scalefactors.root");
	std::vector<TString> addssf;
	addssf << "_eff" << "_eff_mc";


	for(size_t i=0;i<plots.size();i++){
		TString plotname=plots.at(i);
		for(size_t j=0;j<addssf.size();j++){
			TString name=plotname+addssf.at(j);
			TObject * obj = f3->Get(name);
			fout->cd();
			obj->Write();
		}
	}

	TString channel="";
	if(dirname.Contains("ee")) channel="ee";
	else if(dirname.Contains("emu")) channel="emu";
	else if(dirname.Contains("mumu")) channel="mumu";
	else std::cout << "naming of triggerSummary  nor done automatically - if not intended, check dirnames (should contain channel name" << std::endl;

	TFile *fout2 = new TFile("triggerSummary_"+channel+".root","RECREATE");
	fout2->cd();
	std::vector<TString> addsdssf;
	addsdssf << "lepton_eta2d_sf";
	TCanvas * c1=new TCanvas();
	setGStyle();
	double epsilon=0.0000001;
	for(size_t i=0;i<addsdssf.size();i++){
		TString plotname=addsdssf.at(i);
		TObject * obj = f3->Get(plotname);
		fout2->cd();

		if((TString)obj->ClassName() == "TH2D"){
			TH2D * h=(TH2D*)f3->Get(plotname);
			h->SetName("scalefactor_eta2d_with_syst");
			std::cout << "Writing: "<< h->GetName() << std::endl;
			h->Write();
			//make plot with deleted "empty" bins
			for(int x=0;x<=h->GetNbinsX();x++){
				for(int j=0;j<=h->GetNbinsY();j++){
					if(fabs(h->GetBinContent(x,j) - 1) < epsilon && (fabs(h->GetBinError(x,j) - 0.01)< epsilon || h->GetBinError(x,j) < epsilon)){
						h->SetBinContent(x,j,0);
						h->SetBinError(x,j,0);
					}
				}
			}
			c1->Clear();
			c1->SetBatch(true);
			h->Draw("colz,e,text");
			c1->Print(channel+"_eta2d_sf.pdf");

		}



	}
	delete c1;

}
示例#21
0
//________________________________________________________________________________
void MergeComplexHistogramFile( const Char_t *TargetName=0, const Char_t *inputFilesPattern=0) 
{
  if (TargetName && TargetName[0] && inputFilesPattern && inputFilesPattern[0] ) {
    printf(" An experimental version of macro.\n");
    TStopwatch time;
    Int_t fileCounter = 0;
    Int_t dirCounter = 0;
    Int_t treeCounter = 0;
    Int_t histogramCounter = 0;
     // Create the output file
     TFile *outFile = TFile::Open(TargetName,"RECREATE");
     TDirectory *outDir = outFile;
     TDirIter listOfFiles(inputFilesPattern);
     const char *fileName = 0;
     while ( (fileName =  listOfFiles.NextFile() ) ) {
        Int_t currentDirDepth = 0;
        printf(".");
        fileCounter++;
        StFileIter file(fileName);
        TObject *obj = 0;
        while ( (obj = *file) ) {
           Int_t depth = file.GetDepth();
           while (depth < currentDirDepth) {
                outDir = outDir->GetMotherDir();
                currentDirDepth--;
           }
           if ( obj->IsA()->InheritsFrom(TH1::Class()) ) {
              // descendant of TH1 -> merge it
              // printf("Merging histogram: %s\n",obj->GetName() ); 
//              std::cout << "Merging histogram " << obj->GetName() << std::endl;
              TH1 *h1 = (TH1*)obj;
              TH1 *dstHistogram = 0;
              // Check whether we found the new histogram
              if ( (dstHistogram = (TH1 *)outDir->FindObject(h1->GetName()))) {
                 // Accumulate  the  histogram
                  dstHistogram->Add(h1);
                  delete h1;  // Optional, to reduce the memory consumption
                  printf("h");
              } else {
                // First time - move the histogram
                h1->SetDirectory(outDir);
                printf(" The new Histogram found: %s \n", h1->GetName() );
                histogramCounter++;
              }
           } else  if ( obj->IsA()->InheritsFrom(TTree::Class()) ) {
              // descendant of TTree  -> merge it
              // printf("Merging Tree %p:%s\n",obj, obj->GetName() ); 
              TTree *tree = (TTree*)obj;
              TTree *dstTree = 0;
              // Check whether we found the new histogram
              if ( (dstTree = (TTree *)outDir->FindObject(tree->GetName()))) {
                   // printf("Merging %p:%s with the existing Tree %p:%s\n"
                   //       ,tree,tree->GetName(),dstTree, dstTree->GetName() ); 
                  // Merge  the  tree
                  TList *nextTree = new TList(); nextTree->Add(tree); 
                  dstTree->Merge(nextTree);
                  delete tree;  // Optional, to reduce the memory consumption
                  delete nextTree;
                  printf("t");
              } else {
                // First time - move the TTree
                TDirectory *saveDir = 0;
                if (outDir != gDirectory) {
                   saveDir = gDirectory;
                   outDir->cd();
                }
                TList *nextTree = new TList(); nextTree->Add(tree);               
                dstTree = TTree::MergeTrees(nextTree);
                if (saveDir) saveDir->cd();
                // printf(" The new TTree found: %p:%s \n",tree, tree->GetName() );
                // printf(" Create the destination Tree %p:%s\n\n",dstTree, dstTree->GetName() );
                delete tree;  // Optional, to reduce the memory consumption
                delete nextTree;
                treeCounter++;
              }
           } else if ( obj->IsA()->InheritsFrom(TDirectory::Class()) ) {
               printf("The input sub-TDirectory object: %s depth=%d\n",obj->GetName(), depth); 
               TDirectory *d =  (TDirectory *)outDir->FindObject(obj->GetName());
               if (!d) {
                  d = outDir->mkdir(obj->GetName());
                  dirCounter++;
                  printf("The new TDirectory object: %s depth=%d\n",d->GetPathStatic(), depth); 
               }
               if (d) {
                  outDir = d;                  
                  printf("The output sub-TDirectory object: %s depth=%d\n",outDir->GetPathStatic(), depth); 

               }
           } else {
              printf("I have no idea how to merge the %s objects of the %s class. Skipping .... \n",obj->GetName(), obj->ClassName() ); 
           }
           ++file;
        }
              
     }
     printf("\n Finishing  . . . \n");
     outFile->Write();  // this creates a second copy of the TTree ???
     outFile->Close();     
     delete outFile;
     if (fileCounter)      printf(" Total files merged: %d \n", fileCounter);
     if (dirCounter)       printf(" Total TDirectory objects merged: %d \n", dirCounter);
     if (histogramCounter) printf(" Total histograms merged: %d \n", histogramCounter);
     if (treeCounter)      printf(" Total TTree\'s merged: %d \n",treeCounter);
     if (dirCounter || treeCounter) printf(" You have used the experimental version of the program. Please check the output file\n");
        
     time.Print("Merge");
  } else {
     printf("\nUsage: root MergeHistogramFile.C(\"DestinationFileName\",\"InputFilesPattern\")\n");     
     printf("------        where InputFilesPattern  ::= <regexp_pattern_for_the_input_files>|@indirect_file_list\n");
     printf("                    indirect_file_list ::= a text file with the list of the files\n");
     printf("                    indirect_file_list can be create by the shell command:\n");
     printf("                         ls -1 *.root>indirect_file_list \n\n");
  }
}