Problem with TCut

Hi ALL,

I would like to read several root files in a single script and then apply cuts.
I’m giving you a small part of my code.

{
#include "TCut.h"
#include <iostream>
#include "TGraphErrors.h"
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <cmath>
#include <math.h>
#include <TMath.h>
#include <TCanvas.h>
#include <TH1.h>
#include <TF1.h>
#include <TSpectrum.h>
#include <TVirtualFitter.h>
using namespace std;



// formatting

gROOT->SetStyle("Plain");
gStyle->SetPalette(1);
gStyle->SetOptStat(1);
gStyle->SetOptFit(1);

gStyle->SetOptStat("emri");



char rootfile[100], WCcut[150], histoName[30];
int numberOfRuns = 2;

int runNo[numberOfRuns] = {
 47599,
 47600
 };



// declare cuts

 TCut* SC1Cut = 0;
 TCut* SC2Cut = 0;
 TCut* SC4Cut = 0;
// TCut* SCCut = 0;
 TCut* MVBCut = 0;
 TCut* had3Cut = 0;
 TCut* had4Cut = 0; 
 TCut* WCEcut = 0;
 TCut* noCut = 0;
 
 
 
// declare Canvas

TCanvas* cSaleveEMcut[numberOfRuns];



// declare histos
 
TH1D* hSaleveEMCut[numberOfRuns];



for (int i=0; i<numberOfRuns; i++) {
  
  sprintf(rootfile,"./../data/convertedData/%d-converted.root",runNo[i]);
  TFile* f = new TFile(rootfile);
  TTree* tree = (TTree*)f->Get("T");
  f->ls();
  int nentries = (int)T->GetEntries();



// create canvases

  cSaleveEMcut[i] = new TCanvas("cSaleveEMcut","cSaleveEMcut",600,400);
  
  
  
// create histograms

  sprintf(histoName,"SaleveEMTotal, runNo %d",runNo[i]);
  hSaleveEMCut[i] = new TH1D("hSaleveEMCut",histoName,200,-100.,15000.);
  
  
  
// define cuts

  if (runNo[i] == 47599){
    SC1Cut = new TCut("SC1Cut","sc.S1_1212_Adc <= 54.64 + 3*8.506");
    SC2Cut = new TCut("SC2Cut","sc.S2_44_Adc <= 84.52 + 3*14.95");
    SC2Cut = new TCut("SC4Cut","sc.S4_1212_Adc <= 136.1 + 3*20.17");
    TCut SCCut = SC1Cut && SC2Cut && SC4Cut;
//    SCCut = new TCut("SCCut","");
    MVBCut = new TCut("MVBCut","mv.VMBadc <= 140");
    had3Cut = new TCut("had3Cut","saleveHAD.had3 <= 23");
//    had4Cut = new TCut("had4Cut","saleveHAD.had4 <= 23");
    WCEcut = new TCut("WCEcut","(sqrt(pow((wc.WCEx+1.438),2) + pow((wc.WCEy+8.3),2))) <= 2."); //by hand cut
    noCut = new TCut("noCut","saleveHAD.had3 <= 9000");
  }


  else if (runNo[i] == 47600){
    SC1Cut = new TCut("SC1Cut","sc.S1_1212_Adc <= 54.52 + 3*8.577");
    SC2Cut = new TCut("SC2Cut","sc.S2_44_Adc <= 83.39 + 3*14.02");
    SC2Cut = new TCut("SC4Cut","sc.S4_1212_Adc <= 136.3 + 3*20.3");
    TCut SCCut = SC1Cut && SC2Cut && SC4Cut;
    MVBCut = new TCut("mv.VMBadc <= 120");
    had3Cut = new TCut("had3Cut","saleveHAD.had3 <= 23");
//    had4Cut = new TCut("had4Cut","saleveHAD.had4 <= 23");
    WCEcut = new TCut("WCEcut","(sqrt(pow((wc.WCEx+1.438),2) + pow((wc.WCEy+8.3),2))) <= 2."); //by hand cut
    noCut = new TCut("noCut","saleveHAD.had3 <= 9000");
  }

  else {
    cout << " \n you don't have information from the beam line detectors !!! \n";
  }



 //cut(s) applied
 
//  TCut Cut = SCCut && had3Cut && MVBCut;
  TCut Cut = SCCut && WCEcut && had3Cut && MVBCut;



  cSaleveEMcut[i]->cd();
  tree->Draw("saleveEM.saleveEMSum + saleveHAD.had1 >> hSaleveEMCut",Cut);


} // ends loop over all runs


}

I execute the script and I get the following error

Error: Can't call TCut::TCut((int)1) in current scope cutRootForum.C:127:
Possible candidates are...
(in TCut)
/home/loukas/programs/root/lib/libTree.so  -1:-1   0 public: TCut TCut::TCut(void);
/home/loukas/programs/root/lib/libTree.so  -1:-1   0 public: TCut TCut::TCut(const char* title);
/home/loukas/programs/root/lib/libTree.so  -1:-1   0 public: TCut TCut::TCut(const char* name,const char* title);
/home/loukas/programs/root/lib/libTree.so  -1:-1   0 public: TCut TCut::TCut(const TCut& cut);
*** Interpreter error recovered ***
root [1] 
 

It would be great if someone could help me !

Thank you in advance

cheers,
loukas

PS. rootver 5.18/00d

TCut Cut = SCCut && WCEcut && had3Cut && MVBCut; You meantTCut Cut = *SCCut && *WCEcut && *had3Cut && *MVBCut; since your variable are pointers to TCut objects (as opposed to begin directly TCut objects).

Cheers,
Philippe.

PS. Also you should make to detach them for the input file.

[code]// create histograms

sprintf(histoName,“SaleveEMTotal, runNo %d”,runNo[i]);
hSaleveEMCut[i] = new TH1D("hSaleveEMCut,histoName,200,-100.,15000.);
hSaleveEMCut[i]->SetDirectory(0);
[/code]
You may also need to use a unique name for the histograms.

Thanks Philippe!

[i]>

TCut Cut = *SCCut && *WCEcut && *had3Cut && *MVBCut;

since your variable are pointers to TCut objects (as opposed to begin directly TCut objects).
[/i]
after many tries I managed to find the mistake …

[i]>PS. Also you should make to detach them for the input file.

[code]
// create histograms

sprintf(histoName,“SaleveEMTotal, runNo %d”,runNo[i]);
hSaleveEMCut[i] = new TH1D("hSaleveEMCut,histoName,200,-100.,15000.);
hSaleveEMCut->SetDirectory(0);
[/code]

yeap, you’re right! I’ll add this line too…

cheers and many thanks,
loukas