Ejemplo n.º 1
0
void fillHistoFromTreeVar(std::string& treedrawspec,
			  int  index,
			  wTH1 *&wth1)
{
  // Sample treedrawspec:
  // mytree:"TDCwinstart[%d]:runnum>>winstrt%d(70,202000,209000)","evtnum==1","prof P"
  //
  vector<string> v_tokens;
  string tid;
  TString drawspec;
  Tokenize(treedrawspec,v_tokens,":",true);
  if( (v_tokens.size() < 2) ||
      (!v_tokens[0].size())  ||
      (!v_tokens[2].size())    ) {
    cerr << "malformed root tree draw spec treeid:\"varexp\",\"selection\",option: " << treedrawspec << endl;
    return;
  }

  tid = v_tokens[0];
  for (size_t i=2; i<v_tokens.size(); i++) {
    drawspec += v_tokens[i];
  }
  int fmtcnt = drawspec.CountChar('%');

  if (fmtcnt) { // use index for tree array var
    switch(fmtcnt) {
    case 1: drawspec = Form(drawspec,index); break;
    case 2: drawspec = Form(drawspec,index,index); break;
    case 3: drawspec = Form(drawspec,index,index,index); break;
    case 4: drawspec = Form(drawspec,index,index,index,index); break;
    case 5: drawspec = Form(drawspec,index,index,index,index,index); break;
    case 6: drawspec = Form(drawspec,index,index,index,index,index,index); break;
    default:
      cerr << "More than six fmt specifiers in drawspec found, fix me! " << drawspec <<endl;
      exit(-1);
    }
  }
  if( gl_verbose)
    cout<<"drawspec="<<drawspec<<endl;

  TTree *tree = findTree(tid);
  assert (tree);

  // can't use comma as delimiter since histo with binning spec may be supplied
  TObjArray *tokens = drawspec.Tokenize("\"");
  TString hname;

  TString varexp = ((TObjString *)(*tokens)[0])->GetString();

  if (varexp.Contains(">>")) {
    TObjArray *rematches = TPRegexp(">>(\\w+)").MatchS(varexp); // get histo name
    assert(rematches->GetEntriesFast() ==2);
    hname = ((TObjString *)(*rematches)[1])->GetString();

    if (wth1 && !hname.EqualTo(wth1->histo()->GetName())) {
      cerr << "Error: histo name in treedraw spec "<<hname;
      cerr <<" doesn't match named histo "<<wth1->histo()->GetName()<<endl;
      exit(-1);
    }
  } else { // add histo name
    assert (wth1);
    hname = TString(wth1->histo()->GetName());
    varexp = varexp + ">>+" + hname; // append to pre-existing histo
  }

  if( gl_verbose)
    cout<<"varexp="<<varexp<<", hname="<<hname<<endl;
  switch(tokens->GetEntriesFast()) {
  case 1:
    tree->Draw(varexp,"","goff");
    break;
  case 3:
    {
      TString cut = ((TObjString *)(*tokens)[2])->GetString();
      tree->Draw(varexp,cut,"goff"); 
    }
    break;
  case 4: // assume the cut string is blank
    {
      TString gopt = ((TObjString *)(*tokens)[3])->GetString();
      gopt = gopt + " goff";
      tree->Draw(varexp,"",gopt);
    }
    break;
  case 5:
    {
      TString cut  = ((TObjString *)(*tokens)[2])->GetString();
      TString gopt = ((TObjString *)(*tokens)[4])->GetString();
      gopt = gopt + " goff";
      tree->Draw(varexp,cut,gopt);
    }
    break;
  default:
    cerr << "malformed root tree draw spec treeid:varexp,selection,option";
    for (int i=0; i<tokens->GetEntriesFast(); i++)
      cerr << i<<": "<< ((TObjString *)(*tokens)[i])->GetString() << " ";
    cerr << endl;
    break;
  }
  if (!wth1) {
    wth1 = new wTH1((TH1*)gDirectory->Get(hname));
    assert(wth1);
    wth1->histo()->UseCurrentStyle();
  }
}                                                // fillHistoFromTreeVar
Ejemplo n.º 2
0
void drawEvent(TString str){
	Int_t nseries,nrun,nevent,ch;
	Char_t type;
	TString temp=str(TPRegexp("[SCD*]\\d+"));
	type=temp(TPRegexp("[SCD]"));
	TPRegexp digits("\\d+");
	temp=temp(digits);
	nseries=temp.Atoi();
	temp=str(TPRegexp("r\\d+"));
	temp=temp(digits);
	nrun=temp.Atoi();
	temp=str(TPRegexp("e\\d+"));
	temp=temp(digits);
	nevent=temp.Atoi();
	temp=str(TPRegexp("c\\d+"));
	temp=temp(digits);
	ch=temp.Atoi();
	//cout<<"*"<<nseries<<"r"<<nrun<<"e"<<nevent<<"c"<<ch<<endl;
	RawFileReader reader;
	reader.open(type,nseries,nrun);
	reader.seek(nevent);
	Entry entry;
	RawData rdata;
	reader.readNext(entry,rdata);
	reader.close();
	g.SetLineColor(kBlue);
	Float_t g_min=rdata.ch[ch][0],g_max=g_min,h_min=rdata.ch[15][0],h_max=h_min;
	for(Int_t i=1;i<2048;i++){
		if(rdata.ch[ch][i]>g_max){
			g_max=rdata.ch[ch][i];
		}else if(rdata.ch[ch][i]<g_min){
			g_min=rdata.ch[ch][i];
		}
		if(rdata.ch[15][i]>h_max){
			h_max=rdata.ch[15][i];
		}else if(rdata.ch[15][i]<h_min){
			h_min=rdata.ch[15][i];
		}
	}
	Float_t scale=(h_max-h_min)/(g_max-g_min),shift=(g_max*h_min-g_min*h_max)/(g_max-g_min);
	for(Int_t i=0;i<2048;i++){
		g.SetPoint(i,0.04*i,scale*rdata.ch[ch][i]+shift);
		h.SetPoint(i,0.04*i,rdata.ch[15][i]);
	}
	g.GetXaxis()->SetRangeUser(0,2047*0.04);
	h.GetXaxis()->SetRangeUser(0,2047*0.04);
	h.Draw("al");
	g.Draw("same");
	if(axis){
		delete axis;
	}
	c1.Update();
	Float_t min=(gPad->GetUymin()-shift)/scale;
	Float_t max=(gPad->GetUymax()-shift)/scale;
	axis=new TGaxis(c1.GetUxmax(),c1.GetUymin(),c1.GetUxmax(),c1.GetUymax(),min,max,510,"+L");
	axis->SetLineColor(kBlue);
	axis->SetLabelColor(kBlue);
	axis->Draw();
	cout<<g_min<<endl;
	cout<<g_max<<endl;
}
Ejemplo n.º 3
0
//=========================================================================
AliAnalysisTask *RegisterTaskPID2TRD(Bool_t useMC, Bool_t isAOD, Int_t tpcCls=120, Int_t tpcClsPID = 80,
				     Int_t itsCls=4, Double_t dcaxy=1.0, Double_t dcaz=2.0,
				     Double_t *tpcdEdxcutlow=NULL,
				     Double_t *tpcdEdxcuthigh=NULL,
				     Double_t tofs=3., Int_t tofm=0,
				     Int_t itshitpixel = AliHFEextraCuts::kBoth, Int_t icent=1,
				     Int_t TRDtrigger=0,Int_t trdpidmethod=1, Int_t trdl=6, Int_t trde=4,TString detector){

  gROOT->LoadMacro("$ALICE_PHYSICS/PWGHF/hfe/macros/configs/pPb/ConfigHFEpPbTRD.C");
  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
  AliAnalysisDataContainer *cinput  = mgr->GetCommonInputContainer();

  TString detused=detector.Copy();
  TPRegexp(",").Substitute(detused,"","g");
  printf("detectors in use %s %s \n",detector.Data(),detused.Data());

  if (icent == 2) TString cesti("V0M");
  else if (icent == 3) TString cesti("CL1");
  else if (icent == 4) TString cesti("ZNA");
  else TString cesti("V0A");

  Int_t idcaxy = (Int_t)(dcaxy*10.);
  Int_t idcaz = (Int_t)(dcaz*10.);
  Int_t tpclow = 0;
  if(tpcdEdxcutlow) tpclow = (Int_t) (tpcdEdxcutlow[0]*1000.);
  Int_t itofs = (Int_t)(tofs*10.);
  Int_t ipixelany = itshitpixel;

  TString appendix(TString::Format("TPCc%dp%dITS%dr%dz%dTPCs%dTOFs%dm%ipa%dTRDt%dm%il%ie%i%sc%s",tpcCls,
                   tpcClsPID,itsCls,idcaxy,idcaz,tpclow,itofs,tofm,ipixelany,TRDtrigger,trdpidmethod,trdl,trde,detused.Data(),cesti.Data()));
  printf("Add macro appendix %s\n", appendix.Data());

  AliAnalysisTaskHFE *task = ConfigHFEpPbTRD(useMC, isAOD, appendix, tpcCls, tpcClsPID, itsCls, dcaxy, dcaz,
                             tpcdEdxcutlow,tpcdEdxcuthigh, tofs, tofm, itshitpixel, icent, -0.8, 0.8, TRDtrigger,trdpidmethod,trdl,trde,detector);

  if(isAOD)
    task->SetAODAnalysis();
  else
    task->SetESDAnalysis();

  if (useMC)
    task->SetHasMCData(kTRUE);
  else{
    task->SetHasMCData(kFALSE);
  }

  if(TRDtrigger<2) task->SelectCollisionCandidates(AliVEvent::kINT7);
  else task->SelectCollisionCandidates(AliVEvent::kTRD);

  TString containerName = mgr->GetCommonFileName();
  containerName += ":HFEtask";
  containerName += appendix.Data();
  printf("container name: %s\n", containerName.Data());

  //create data containers
  task->ConnectOutput(1, mgr->CreateContainer(Form("HFE_Results_%s", appendix.Data()),
					      TList::Class(), AliAnalysisManager::kOutputContainer, 
					      containerName.Data()));
  task->ConnectOutput(2, mgr->CreateContainer(Form("HFE_QA_%s", appendix.Data()), TList::Class(), 
					      AliAnalysisManager::kOutputContainer, 
					      containerName.Data()));
  mgr->ConnectInput(task,  0, cinput );

  mgr->AddTask(task);
  return NULL;
}
Ejemplo n.º 4
0
void qaitsAddMetadata(TTree*tree, Int_t verbose){
  //
  // Set metadata infomation 
  //
  if (tree==NULL) {
    ::Error("qaitsAddMetadata","Start processing. Emtpy tree");
    return;
  }
  ::Info("qaitsAddMetadata","Start processing Tree %s",tree->GetName());
  TObjArray * branches=tree->GetListOfBranches();
  // Clasigication of variables
  //   regular expression to defined automaticaly some variables following naming conventions - used to define classes/Axis/legends 
  //           default description
  //   regular expression used can be tested on site https://regex101.com/
  //           hovewer root (perl)  regular expression looks to be in some cases different - in some case double escape had to be used
  //           e.g to math c.  expression c\\. has to be used
  //   variables
  const TString kineVariableClass[11]={"X", "Y","Z", "Phi", "Theta", "Pt", "QOverPt"};
  const TString kineVariableAxisTitle[11]={"x(cm)", "y(cm)","z(cm)", "#phi", "#Theta", "p_{T}", "q/p_{T}(c/GeV)"};
  const TString kineVariableLegend[11]={"x", "y","z", "#phi", "#Theta", "p_{T}", "q/p_{T}"};
  const TString kineVariableTitle[11]={"x", "y","z", "#phi", "#Theta", "p_{T}", "q/p_{T}"};
  TPRegexp regKineVariables[11];
  regKineVariables[0]=TPRegexp("^x|x$");               // X - varaible begining on X
  regKineVariables[1]=TPRegexp("(^y|^infoy|y$)");      // Y - 
  regKineVariables[2]=TPRegexp("(^z|^infoz|z$)");      // Z
  regKineVariables[3]=TPRegexp("(phi|infophi)");              // phi
  regKineVariables[4]=TPRegexp("(theta|lambda|infolambda)");   // theta
  regKineVariables[5]=TPRegexp("(^pt)");           // pt
  regKineVariables[6]=TPRegexp("qoverpt");          // qoverPt
  //
  //   QA variables  
  const TString qaVariableClass[11]={"Frac", "$","dEdx","ChargeRatio"};
  const TString qaVariableAxisTitle[11]={"Frac","$","dEdx","ChargeRatio"};
  const TString qaVariableLegend[11]={"Frac","$","dEdx","ChargeRatio"};
  const TString qaVariableTitle[11]={"Frac","$","dEdx","ChargeRatio"};
  TPRegexp regQAVariable[11];
  regQAVariable[0]=TPRegexp("frac");              // Frac
  regQAVariable[1]=TPRegexp("(eff[0-9]|effone|^eff)");          // eff layer?
  regQAVariable[2]=TPRegexp("(mpv|dedx)");         // dEdx 
  regQAVariable[3]=TPRegexp("chargeratio");        // ChargeRatio

 
  //
  // statistic
  //
  const TString statClass[10]={"Constrain", "Mean","Delta","Median", "RMS","Pull", "Err","Chi2", "StatInfo[]","FitInfo[]"};
  const TString statAxisTitle[10]={"Constrain", "mean","#Delta","med.", "rms","pull", "#sigma"," #chi2","stat[]","fit[]"};
  const TString statTitle[10]={"Constrain", "mean","#Delta","med.", "rms","pull", "#sigma"," #chi2","stat[]","fit[]" };
  TPRegexp regStat[10];
  regStat[0]=TPRegexp("constrain");        // constrain
  regStat[1]=TPRegexp("^mean");            // mean
  regStat[2]=TPRegexp("^delta");           // delta
  regStat[3]=TPRegexp("^median");          // median variable
  regStat[4]=TPRegexp("(^rms|resolution|sigma)");// rms resolution        
  regStat[5]=TPRegexp("pull");             // pull
  regStat[6]=TPRegexp("err");              // error
  regStat[7]=TPRegexp("chi2");             // chi2
  regStat[8]=TPRegexp("^info");            // stat info array 
  regStat[9]=TPRegexp("^fit");             // fit info  array
  //
  // 
  const TString categoryClass[10]={"Vertex","$1","$1"};
  const TString categoryLegend[10]={"Vertex","$1","$1"};
  const TString categoryTitle[10]={"Vertex","$1","$1"};
  TPRegexp regCategory[10];   // proper parsing of layer numbers to be added
  regCategory[0]=TPRegexp("(vertex|vtx)");             //
  regCategory[1]=TPRegexp("s(p|d|d)d[0-2]?");    // reg.exp match silical layers+number 
  regCategory[2]=TPRegexp("pt[0-9]+");         // pt bin
  


  for (Int_t ibr=0; ibr<branches->GetEntriesFast(); ibr++){
    TBranch * branch = (TBranch*)branches->At(ibr);
    TString matchClass="";   // class match
    TString brClass="";
    TString brAxisTitle="";
    TString brTitle="";
    TString brLegend="";
    //
    TString brNameCase(branches->At(ibr)->GetName());
    brNameCase.ToLower();
    //
    // define met
    brClass="ITS";
    brAxisTitle="";
    // stat
    for (Int_t ivar=0; ivar<11; ivar++) if  (brNameCase.Contains( regStat[ivar])) { 
      brClass+=" "+statClass[ivar];
      brTitle+=statTitle[ivar];
    }
    // kine variables
    for (Int_t ivar=0; ivar<7; ivar++) if  (brNameCase.Contains( regKineVariables[ivar])) {
      brClass+=" "+kineVariableClass[ivar];      
      brAxisTitle+=" "+kineVariableAxisTitle[ivar];
      brTitle+=" "+kineVariableTitle[ivar];
      brLegend+=" "+kineVariableLegend[ivar];
    }
    // QA variables
    for (Int_t ivar=0; ivar<5; ivar++) if  (brNameCase.Contains( regQAVariable[ivar])) {
      if ( qaVariableClass[ivar].Contains("$")==kFALSE){
	brClass+=" "+ qaVariableClass[ivar];
	brLegend+=" "+ qaVariableLegend[ivar];
	brTitle+=" "+ qaVariableTitle[ivar];
      }else{
	TObjArray *amatch=regQAVariable[ivar].MatchS(brNameCase);
	if (amatch){
	  TString match=amatch->At(0)->GetName();
	  brClass+=" "+match;
	  brLegend+=" "+match;
	  brTitle+=" "+match;
	}
      }
    }
    // category
    for (Int_t ivar=0; ivar<3; ivar++) if  (brNameCase.Contains(regCategory[ivar])) {
      if (categoryClass[ivar].Contains("$")==kFALSE){
	brClass+=" "+categoryClass[ivar];
	brLegend+=" "+categoryLegend[ivar];
	brTitle+=" "+categoryTitle[ivar];
      }else{
	TObjArray *amatch=regCategory[ivar].MatchS(brNameCase);
	if (amatch){
	  TString match=amatch->At(0)->GetName();
	  brClass+=" "+match;
	  brLegend+=" "+match;
	  brTitle+=" "+match;
	}
      }
    }
    if (branch!=NULL && branch->GetClassName()!=NULL && strlen(branch->GetClassName())>0){
      brClass+=" Class:";
      brClass+=branch->GetClassName();
    }
    
    //
    TStatToolkit::AddMetadata(tree,TString::Format("%s.Description",branches->At(ibr)->GetName()).Data(),
			      TString::Format("ITS standard QA variables.  Class %s", brClass.Data()).Data());
    TStatToolkit::AddMetadata(tree,TString::Format("%s.class",branches->At(ibr)->GetName()).Data(),brClass.Data());    
    TStatToolkit::AddMetadata(tree,TString::Format("%s.AxisTitle",branches->At(ibr)->GetName()).Data(),brAxisTitle.Data());    
    TStatToolkit::AddMetadata(tree,TString::Format("%s.Title",branches->At(ibr)->GetName()).Data(),brTitle.Data());    
    TStatToolkit::AddMetadata(tree,TString::Format("%s.Legend",branches->At(ibr)->GetName()).Data(),brLegend.Data());    
    if (verbose&4) printf("Class %s: \t%s\n", branches->At(ibr)->GetName(),brClass.Data());
    if (verbose&8) printf("Axis title %s: \t%s\n", branches->At(ibr)->GetName(),brAxisTitle.Data());
    if (verbose&16) printf("Title %s: \t%s\n", branches->At(ibr)->GetName(),brTitle.Data());
    if (verbose&32) printf("Legend %s: \t%s\n", branches->At(ibr)->GetName(),brLegend.Data());

    
  }

  // Fill Based and  custom metadata
  //
  // Index
  TStatToolkit::AddMetadata(tree,"run.class","Base Index");
  TStatToolkit::AddMetadata(tree,"run.Title","run");
  TStatToolkit::AddMetadata(tree,"run.AxisTitle","run");
  //
  TList * mlist = (TList*)(tree->GetUserInfo()->FindObject("metaTable"));
  mlist->Sort();
  if ((verbose&1)>0){
    mlist->Print();
  }
  if ((verbose&2)>0){
    AliTreePlayer::selectMetadata(tree, "[class==\"\"]",0)->Print();
  }
  ::Info("qaitsAddMetadata","End");

}
Ejemplo n.º 5
0
AliAnalysisTask *RegisterTaskPID2mbTRD(Bool_t useMC, Bool_t isAOD, Int_t tpcCls=120, Int_t tpcClsPID = 80,
                  Int_t itsCls=4, Double_t dcaxy=1.0, Double_t dcaz=2.0,
                  Double_t tpcs=-0.0113, Double_t tpcu=3.09,
                  Double_t tofs=3., Int_t tofm=0,
                  Int_t itshitpixel = AliHFEextraCuts::kBoth,
                  Bool_t withetacorrection = kTRUE,
                  Int_t TRDtrigger=0,Int_t trdl=6, Int_t trde=4,TString detector="TRD,TPC",Int_t etacut=0){

  TString detused=detector.Copy();
  TPRegexp(",").Substitute(detused,"","g");
  printf("detectors in use %s %s \n",detector.Data(),detused.Data());

  Int_t idcaxy = (Int_t)(dcaxy*10.);
  Int_t idcaz = (Int_t)(dcaz*10.);
  Int_t itpcs = (Int_t)(tpcs*1000.);
  Int_t itofs = (Int_t)(tofs*10.);
  Int_t ipixelany = itshitpixel;
  Int_t ietacorr = 0;
  if(withetacorrection) ietacorr = 1;

  TString appendix(TString::Format("mbTPCc%dp%dITS%dr%dz%dTPCs%dTOFs%dm%ipa%dTRDt%dl%ie%i%se%i",tpcCls,
				   tpcClsPID,itsCls,idcaxy,idcaz,itpcs,itofs,tofm,ipixelany,TRDtrigger,trdl,trde,detused.Data(),etacut));
  printf("Add macro appendix %s\n", appendix.Data());

  gROOT->LoadMacro("$ALICE_PHYSICS/PWGHF/hfe/macros/configs/pPb/ConfigHFEmbpPbTRD.C");
  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
  AliAnalysisDataContainer *cinput  = mgr->GetCommonInputContainer();
  AliAnalysisTaskHFE *task = ConfigHFEmbpPbTRD(useMC, isAOD, appendix, tpcCls, tpcClsPID, itsCls, dcaxy, dcaz,
                             tpcs,tpcu,tofs,tofm,3.,kFALSE,kTRUE,kFALSE,itshitpixel,withetacorrection,0,TRDtrigger,trdl,trde,detector,etacut);

  if(isAOD)
    task->SetAODAnalysis();
  else
    task->SetESDAnalysis();

  if(useMC)
    task->SetHasMCData(kTRUE);
  else{
    task->SetHasMCData(kFALSE);
  }

  if(TRDtrigger<2) task->SelectCollisionCandidates(AliVEvent::kINT7);
  else task->SelectCollisionCandidates(AliVEvent::kTRD);

  TString containerName = mgr->GetCommonFileName();
  containerName += ":HFEtask";
  containerName += appendix.Data();
  printf("container name: %s\n", containerName.Data());

  //create data containers
  task->ConnectOutput(1, mgr->CreateContainer(Form("HFE_Results_%s", appendix.Data()),
					      TList::Class(), AliAnalysisManager::kOutputContainer, 
					      containerName.Data()));
  task->ConnectOutput(2, mgr->CreateContainer(Form("HFE_QA_%s", appendix.Data()), TList::Class(), 
					      AliAnalysisManager::kOutputContainer, 
					      containerName.Data()));
  mgr->ConnectInput(task,  0, cinput );

  mgr->AddTask(task);

  return NULL;
}