Ejemplo n.º 1
0
//______________________________________________________________________________
TChain* CreateChainFromCollection(const char *xmlfile)
{
  // Create a chain from the collection of tags.
  TAlienCollection* coll = TAlienCollection::Open(xmlfile);
  if (!coll) {
    ::Error("CreateChainFromTags", "Cannot create an AliEn collection from %s", xmlfile);
    return NULL;
  }
  
  TGridResult* tagResult = coll->GetGridResult("",kFALSE,kFALSE);
  AliTagAnalysis *tagAna = new AliTagAnalysis("ESD");
  tagAna->ChainGridTags(tagResult);
  
  AliRunTagCuts      *runCuts = new AliRunTagCuts();
  AliLHCTagCuts      *lhcCuts = new AliLHCTagCuts();
  AliDetectorTagCuts *detCuts = new AliDetectorTagCuts();
  AliEventTagCuts    *evCuts  = new AliEventTagCuts();
  
  // Check if the cuts configuration file was provided
  if (!gSystem->AccessPathName("ConfigureCuts.C")) {
    gROOT->LoadMacro("ConfigureCuts.C");
    ConfigureCuts(runCuts, lhcCuts, detCuts, evCuts);
  }
  
  TChain *chain = tagAna->QueryTags(runCuts, lhcCuts, detCuts, evCuts);
  if (!chain || !chain->GetNtrees()) return NULL;
  chain->ls();
  return chain;
}
Ejemplo n.º 2
0
Archivo: run.C Proyecto: ktf/AliPhysics
TChain * GetAnalysisChain(const char * incollection){
  // Builds a chain of esd files
  // incollection can be
  // - a single root file
  // - an xml collection of files on alien
  // - a ASCII containing a list of local root files
  TChain* analysisChain = 0;
  // chain
  analysisChain = new TChain("esdTree");
  if (TString(incollection).Contains(".root")){
    analysisChain->Add(incollection);
  }
  else if (TString(incollection).Contains("xml")){
    TGrid::Connect("alien://");
    TAlienCollection * coll = TAlienCollection::Open (incollection);
    while(coll->Next()){
      analysisChain->Add(TString("alien://")+coll->GetLFN());
    }
  } else {
    ifstream file_collect(incollection);
    TString line;
    while (line.ReadLine(file_collect) ) {
      analysisChain->Add(line.Data());
    }
  }
  analysisChain->GetListOfFiles()->Print();

  return analysisChain;
}
Ejemplo n.º 3
0
//_________________________________________________________________________________________________
TChain* CreateChainFromXML
(const char *xmlFileName, const char *treeName, Int_t nread, Int_t nskip)
{
//
// Create a TChain with all required files listed into an XML collection.
// Necessary to run analysis in AliEn jobs.
// ---
// Arguments:
//  - xmlFileName = input list
//  - treeName    = "esdTree" or "aodTree"
//  - nread       = how many files to read (0 = all)
//  - nskip       = how many files to skip from beginning
//

  // if nread argument is 0, it is disabled
  if (nread == 0) nread = 1000000000;

  // initialize output object
  TChain *chain = new TChain(treeName);

  // initialize the AliEn collection
  TAlienCollection *myCollection = TAlienCollection::Open(xmlFileName);
  if (!myCollection)
  {
    Error("CreateChainFromXML", "Cannot create an AliEn collection from %s", xmlFileName);
    return 0x0;
  }

  // loop on collection
  myCollection->Reset();
  while (myCollection->Next())
  {
    // skip until reached required number of offset
    if (nskip > 0) {--nskip; continue;}

    // stop if required number of read files is reached
    // otherwise update the counter
    if (nread <= 0) break;
    nread--;

    // recovery file and add it
    Info("CreateChainFromXML", Form("Adding: %s", myCollection->GetTURL("")));
    chain->Add(myCollection->GetTURL(""));
  }

  return chain;
}
Ejemplo n.º 4
0
//________________________________________________________________________________
TChain* CreateChainXML(const char *xmlfile)
{
// Create a chain using url's from xml file
   TString filename;
   Int_t run = 0;
   TString treename = "esdTree";
   printf("***************************************\n");
   printf("    Getting chain of trees %s\n", treename.Data());
   printf("***************************************\n");
   TAlienCollection *coll = TAlienCollection::Open(xmlfile);
   if (!coll) {
      ::Error("CreateChain", "Cannot create an AliEn collection from %s", xmlfile);
      return NULL;
   }
   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
   TChain *chain = new TChain(treename);
   coll->Reset();
   while (coll->Next()) {
      filename = coll->GetTURL();
      if (filename.EndsWith("Barrel.root")) barrelFlag = kTRUE;
      if (mgr) {
         Int_t nrun = AliAnalysisManager::GetRunFromAlienPath(filename);
         if (nrun && nrun != run) {
            printf("### Run number detected from chain: %d\n", nrun);
            mgr->SetRunFromPath(nrun);
            run = nrun;
         }
      }
      chain->Add(filename);
   }
   if (!chain->GetNtrees()) {
      ::Error("CreateChain", "No tree found from collection %s", xmlfile);
      return NULL;
   }
   printf("Created chain with %d entries in %d trees from %s\n",chain->GetEntries(),chain->GetNtrees(),xmlfile);
   return chain;
}
Ejemplo n.º 5
0
// macro principale che fa il loop sugli eventi e scrive il file
Bool_t CheckESD(const char *lista="wn.xml",Bool_t kGRID=1) //per prendere dalla grid;
//Bool_t CheckESD(const char *lista="lista",Bool_t kGRID=0) // da locale
{
  char name[300];
  Int_t ifile = 0;
  Int_t nmaxfile = 200000000; // to limit the number of ESD files
  
  //T->Branch("nevento",&nevento,"nevento/I");
  T->Branch("kTOFout",&TOFout,"kTOFout/I");
  T->Branch("ncluster",&ncluster,"ncluster/I");
  T->Branch("tempo",tempo,"tempo[ncluster]/F");
  if(isMC) T->Branch("pdg",&pdg,"pdg/I");
  if(isMC) T->Branch("gtime",&gtime,"gtime/F");
  if(isMC) T->Branch("DXtrue",&dxt,"DXtrue/F");
  if(isMC) T->Branch("DZtrue",&dzt,"DZtrue/F");
  T->Branch("DeltaX",DeltaX,"DeltaX[ncluster]/F");
  T->Branch("DeltaZ",DeltaZ,"DeltaZ[ncluster]/F");
  T->Branch("exp_time_el",exp_time_el,"exp_time_el[ncluster]/F");
  T->Branch("exp_time_mu",exp_time_mu,"exp_time_mu[ncluster]/F");
  T->Branch("exp_time_pi",exp_time_pi,"exp_time_pi[ncluster]/F");
  T->Branch("exp_time_ka",exp_time_ka,"exp_time_ka[ncluster]/F");
  T->Branch("exp_time_pr",exp_time_pr,"exp_time_pr[ncluster]/F");
  T->Branch("L",L,"L[ncluster]/F");
  T->Branch("TOT",tot,"TOT[ncluster]/F");
  T->Branch("ChannelTOF",ChannelTOF,"ChannelTOF[ncluster]/I");
  T->Branch("impulso",&impulso,"impulso/F");
  T->Branch("impulso_trasv",&impulso_trasv,"impulso_trasv/F");
  T->Branch("res",res,"res[3]/F");
  T->Branch("charge",&charge,"charge/I");
  T->Branch("phi",&phi,"phi/F");
  T->Branch("eta",&eta,"eta/F");
  T->Branch("phiExt",&phiExt,"phiExt/F");
  T->Branch("etaExt",&etaExt,"etaExt/F");
  T->Branch("secPhi",&secAngle,"secPhi/F");
  T->Branch("cval",cval,"cval[5]/F");
  T->Branch("mism",&mism,"mism/I");
  T->Branch("ntofcl",&ntofcl,"ntofcl/I");
  T->Branch("dedx",&dedx,"dedx/F");
  T->Branch("StartTime",&StartTime,"StartTime/F");
  T->Branch("StartTimeRes",&StartTimeRes,"StartTimeRes/F");
  T->Branch("rTOF",&rTOFused,"rTOF/F");
  if(isMC) T->Branch("InteractionTime",&interactiontime,"InteractionTime/F");
  T->Branch("tempoTrig",&timetrig,"tempoTrig/F");
  
  if(! kGRID){
    FILE *fin = fopen (lista,"r");
    
    while(fscanf(fin,"%s",name)==1 && ifile < nmaxfile){
      CheckSingle(name,kGRID),ifile++;
      printf("file %i done\n",ifile);
      system("date");
    }
    
    fclose(fin);
  }
  else{
    TGrid::Connect("alien://");
    
    TAlienCollection *myCollection = (TAlienCollection *) TAlienCollection::Open(lista);
    if (!myCollection)
      {
	Error("CheckESD.C", Form("Cannot create an AliEn collection from %s", lista));
	return 1;
      }
    myCollection->Reset();    
    
    while (myCollection->Next() && ifile < nmaxfile){
      CheckSingle(myCollection->GetTURL("")),ifile++;
      printf("file %i done\n",ifile);
      system("date");
    }
  }

  fotree->cd();
  T->Write(); //scrivo tree
  fotree->Close();
}
Ejemplo n.º 6
0
void raw2treeGrid_collection()
{

  // reading RAW data from test LCS
  // filling histograms
  // fillinf tree
  //  gROOT->LoadMacro("loadlibs.C");
  //  loadlibs();
  Int_t allData[220][5];
  TGrid::Connect("alien://");
  TTree *fT0OutTree=new TTree("t0tree","None here");
 TAlienCollection *collnum = TAlienCollection::Open("wn.xml");
  Int_t numrun;
  collnum->Reset();
  collnum->Next();
  TString buf_runnum;
  TString buf_path = collnum->GetTURL() ;
  for(int i=0; i<buf_path.Length();i++)	{
    if(buf_path(i,4)=="/raw")	{
      buf_runnum = buf_path(i-6,6);
      numrun = buf_runnum.Atoi();
      break;
    }
  }
  
  TString names[220];
  Int_t chvalue[220], meanchvalue[220];
  AliT0LookUpKey* lookkey= new AliT0LookUpKey();
  AliT0LookUpValue*  lookvalue= new AliT0LookUpValue();
  AliCDBManager * man = AliCDBManager::Instance();
  man->SetDefaultStorage("raw://");
  man->SetRun(numrun);
  AliT0Parameters *fParam = AliT0Parameters::Instance();
  fParam->Init(); 
  TMap *lookup = fParam->GetMapLookup();
  TMapIter *iter = new TMapIter(lookup);
  for( Int_t iline=0; iline<212; iline++)
    {
      lookvalue = ( AliT0LookUpValue*) iter->Next();
      lookkey = (AliT0LookUpKey*) lookup->GetValue((TObject*)lookvalue);      
      if(lookkey){
	Int_t key=lookkey->GetKey();
	names[key]=lookkey->GetChannelName();
	fT0OutTree->Branch(Form("%s",names[key].Data()), &chvalue[key]);
      }
      else
	{printf(" no such value %i \n", iline);}
    } 
  Float_t meanCFD[24], meanQT1[24];
 
  for (int ich=0; ich<24; ich++) {
    meanCFD[ich] = fParam->GetCFD(ich);
    meanQT1[ich] = fParam->GetQT1(ich);
  }
  Float_t meanOrA = fParam->GetMeanOrA();
  Float_t meanOrC = fParam->GetMeanOrC();
  Float_t meanTVDC = fParam->GetMeanVertex();
  //new QTC

  Float_t qt01mean[28] = {18712.5, 18487.5, 18487.5, 18537.5, 
  			  18562.5, 18462.5, 18537.5, 18537.5, 
			  18537.5, 18587.5, 18587.5, 18512.5,
			   18512.5, 18512.5, 18487.5, 18562.5,
			    18537.5, 18512.5, 18537.5, 18537.5,
			     18512.5, 18587.5, 18562.5, 18512.5,
		      18358, 18350, 18374, 18362};
  Float_t qt11mean[28] = {18705, 18495, 18465, 18555, 
  			18555, 18435, 18525, 18525, 
			18525, 18585, 18585, 18495, 
			18495, 18525, 18465, 18555, 
			18525, 18495, 18555, 18495, 
			18495, 18585, 18585, 18495,
		      18358, 18350, 18374, 18362};
  Int_t ind[26];
  for (int iii=0; iii<12; iii++) ind[iii]=25;
  for (int iii=12; iii<24; iii++) ind[iii]=57;

  UInt_t event;
   fT0OutTree->Branch("event", &event);
   ULong64_t triggerMask;
   fT0OutTree->Branch("triggers", &triggerMask);
    TAlienCollection *coll = TAlienCollection::Open("wn.xml");
      coll->Reset();
    
   AliRawReader *reader;
while (coll->Next()) {
    TString	fFileName=coll->GetTURL();
     //READ DATA
 //     TString	fFileName=Form("alien:///alice/data/2015/LHC15i/000%i/raw/15000%i028.%i.root", numrun, numrun, chunk);
      reader = new AliRawReaderRoot(fFileName);
     if(!reader) continue;

     reader = new AliRawReaderRoot(fFileName);     
     if(!reader) continue;
//     reader->LoadEquipmentIdsMap("T0map.txt");
     reader->RequireHeader(kTRUE);
     for (Int_t i0=0; i0<220; i0++) {
       chvalue[i0] = 0;
       for (Int_t j0=0; j0<5; j0++)  allData[i0][j0]=0; 
     }
     
     AliT0RawReader *start = new AliT0RawReader(reader);
     while (reader->NextEvent()) {
       start->Next();
       for (Int_t ii=0; ii<211; ii++) {
	 chvalue[ii] = 0;
	 for (Int_t iHit=0; iHit<5; iHit++) 
	   {
	     allData[ii][iHit]= start->GetData(ii,iHit);
	     //   	if(allData[ii][iHit]>0) cout<<ii<<" "<<allData[ii][iHit]<<endl;
	   }
       } 
       
       const  UInt_t type =reader->GetType();
       if(type != 7) continue;
       triggerMask  = reader->GetClassMask();
       
        for (Int_t iHit=0; iHit<5; iHit++) {
         if( allData[50][iHit]>meanTVDC-800 && allData[50][iHit]<meanTVDC+800) {
	 chvalue[50]=allData[50][iHit];
         break;
         }
       } 
       
        for (Int_t in=0; in<24;  in++)
	 {
	   for (Int_t iHit=0; iHit<5; iHit++)  //old QTC C side
	     {
	       if (allData[2*in+ind[in]+1][iHit] > meanQT1[in]-800 &&  
		   allData[2*in+ind[in]+1][iHit] < meanQT1[in]+800 ) {
		 chvalue[2*in+ind[in]+1] = allData[2*in+ind[in]+1][iHit];
		 break;
	       }
	     }
	   for (Int_t iHit=0; iHit<5; iHit++)  //old QTC A side
	     {
	       if( (allData[2*in+ind[in]][iHit] > chvalue[2*in+ind[in]+1]) &&
		   chvalue[2*in+ind[in]+1]>0)
		 {
		   chvalue[2*in+ind[in]] = allData[2*in+ind[in]][iHit];
		//   printf("index %i  pmt %i QTC old start %i stop %i \n", 
		//   2*in+ind[in], in,
		 //  chvalue[2*in+ind[in]+1], chvalue[2*in+ind[in]]);
		   break;
		 }
	     }
	 }
       for (Int_t in=0; in<12; in++)  
	 {
	   chvalue[in+68+1] = allData[in+68+1][0] ;
	   chvalue[in+12+1] = allData[in+12+1][0] ;
	   for (Int_t iHit=0; iHit<5; iHit++)  //CFD C side
	     {
	       if(allData[in+1][iHit] > meanCFD[in]-800 && 
		  allData[in+1][iHit] < meanCFD[in]+800)
		 {
		   chvalue[in+1] = allData[in+1][iHit] ; 
		   break;
		 }
	     }
	   for (Int_t iHit=0; iHit<5; iHit++)  //CFD A side
	     {
	       if(allData[in+1+56][iHit]>0)
		 if(allData[in+1+56][iHit] > meanCFD[in+12]-800 && 
		    allData[in+1+56][iHit] < meanCFD[in+12]+800)
		   {
		     chvalue[in+1+56] = allData[in+56+1][iHit] ;
		     break;
		   }
	     }
	 }
       // new QTC    
       Int_t pmt;
       for (Int_t ik=0; ik<106; ik+=4) {
	   if (ik<48)          pmt=ik/4;
	   if (ik>47 && ik<52) pmt= 24;   
	   if (ik>51 && ik<56) pmt= 25; 
	   if(ik>55)           pmt=(ik-8)/4;
	   for(Int_t iHt = 0; iHt<5; iHt++) { 
	     if(allData[107+ik+1][iHt] > (qt01mean[pmt]-800) &&
		allData[107+ik+1][iHt] < (qt01mean[pmt]+800) ) {
	       chvalue[107+ik+1] = allData[107+ik+1][iHt];
	    //   printf("start newQTC 00 ik %i iHt %i pmt %i  QT00 %i QT01 %i \n", ik, iHt, pmt, allData[107+ik][iHt],  allData[107+ik+1][iHt]);
	       break;
	     }
	   }
	   for(Int_t iHt = 0; iHt<5; iHt++) { 
	     if(allData[107+ik][iHt]>chvalue[107+ik+1] &&
		chvalue[107+ik+1]>0) {
	       chvalue[107+ik]=allData[107+ik][iHt] ;
	    //   printf("stop newQTC 00 ik %i iHt %i pmt %i  QT00 %i QT01 %i \n", ik, iHt, pmt, allData[107+ik][iHt],  allData[107+ik+1][iHt]);
	       break;
	     }
	   }
	   for(Int_t iHt = 0; iHt<5; iHt++) {
	     if( allData[107+ik+3][iHt] > (qt11mean[pmt]-800) &&
		 allData[107+ik+3][iHt] < (qt11mean[pmt]+800) ) {
	       chvalue[107+ik+3] = allData[107+ik+3][iHt];
	       break;
	     }
	   }
	   for(Int_t iHt = 0; iHt<5; iHt++) {
	     if( allData[107+ik+2][iHt] > chvalue[107+ik+3]&&
		 chvalue[107+ik+3]>0 ) {
	       chvalue[107+ik+2] = allData[107+ik+2][iHt];
	   //    printf(" newQTC 11 ik %i iHt %i pmt %i QT10 %i QT11 %i \n", ik, iHt, pmt, allData[107+ik+2][iHt],  allData[107+ik+3][iHt]);
		 break;
	     }
	   }
	 } //end new QTC
	 // Or
         for(Int_t iHt = 0; iHt<5; iHt++) {
	 if(allData[51][iHt]>meanOrA-800 && allData[51][iHt]<meanOrA+800) {
	   chvalue[51]=allData[51][iHt];
	   break;
	  }
         }
        for(Int_t iHt = 0; iHt<5; iHt++) {
	 if(allData[52][iHt]>meanOrC-800 && allData[52][iHt]<meanOrC+800) {
	   chvalue[52]=allData[52][iHt];
	   break;
	  }
         }
	   	    

       event++;
       if(chvalue[50]>0)      fT0OutTree->Fill(); 
       
     } //event
     start->Delete();
     }
     reader->Delete();
	
   TFile *hist = new TFile("T0RAWtree.root","RECREATE");
   hist->cd();
   fT0OutTree ->Write();  
			   
}
Ejemplo n.º 7
0
void JetAnalysisManager()
{
    //
    // Load relevant libraries
    //
    gSystem->Load("libTree");
    gSystem->Load("libNetx");
    gSystem->Load("libProof");
    gSystem->Load("libProofPlayer");
    gSystem->Load("libGeom");
    gSystem->Load("libEG");

    gSystem->Load("libANALYSIS");
    gSystem->Load("libESD");
    gSystem->Load("libJETAN");
    //
    // Connect to alien
    //
    TGrid::Connect("alien://"); 
    
    AliTagAnalysis *TagAna = new AliTagAnalysis(); 
    AliEventTagCuts *EvCuts = new AliEventTagCuts();
    AliRunTagCuts   *RuCuts = new AliRunTagCuts();
    //EvCuts->SetNChargedAbove1GeVRange(1, 1000);
    //EvCuts->SetMultiplicityRange(11,120);
    //EvCuts->SetNPionRange(2,10000);
     TAlienCollection* coll = TAlienCollection::Open("tag100.xml");
     TGridResult* TagResult = coll->GetGridResult("", 0, 0);
     TagResult->Print();
     TagAna->ChainGridTags(TagResult);

  //////////////////////////////////////////////////////////////////
  //Get the chain
     printf("*******************************\n");
     printf("*** Getting the Chain       ***\n");
     printf("*******************************\n");
     TChain* chain1 = 0x0;
     chain1 = TagAna->QueryTags(RuCuts, EvCuts);
     chain1->ls();
     
    //
    // Make the analysis manager
    //
    AliAnalysisManager *mgr = new AliAnalysisManager("Manager", "Manager");
    mgr-> SetDebugLevel(10);
    
    AliAnalysisTaskJets *jetana = new AliAnalysisTaskJets("JetAnalysis");
    jetana->SetDebugLevel(10);
    
    mgr->AddTask(jetana);
    // Create containers for input/output
    AliAnalysisDataContainer *cinput1 = mgr->CreateContainer("cchain1",TChain::Class(), 
							     AliAnalysisManager::kInputContainer);

    AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("chist1", TH1::Class(),
							      AliAnalysisManager::kOutputContainer);

    mgr->ConnectInput (jetana,0,cinput1);
    mgr->ConnectOutput(jetana,0,coutput1);
    cinput1->SetData(chain1);

//
// Run the analysis
//    

    if (mgr->InitAnalysis()) {
	mgr->PrintStatus();
	mgr->StartAnalysis("local", chain1);
    }
}
Ejemplo n.º 8
0
void runTask(Float_t etamax=0.5,const char * incollection = 0, const char * outfile = "dndeta.root", Bool_t skipNorm = kFALSE)
{
  // for running with root only
  gSystem->Load("libTree");
  gSystem->Load("libGeom");
  gSystem->Load("libVMC");
  gSystem->Load("libSTEERBase");
  gSystem->Load("libESD");
  gSystem->Load("libAOD");

  // load analysis framework
  gSystem->Load("libANALYSIS");
  gSystem->Load("libANALYSISalice");


  TChain * chain = new TChain ("TE");
  if (incollection == 0) {
    chain->Add("galice.root");
  }
  else if (TString(incollection).Contains("xml")){
    TGrid::Connect("alien://");
    TAlienCollection * coll = TAlienCollection::Open (incollection);
    while(coll->Next()){
      chain->Add(TString("alien://")+coll->GetLFN());
    }
  } else {
    ifstream file_collect(incollection);
    TString line;
    while (line.ReadLine(file_collect) ) {
      chain->Add(line.Data());
    }
  }
  chain->GetListOfFiles()->Print();

  // for includes use either global setting in $HOME/.rootrc
  // ACLiC.IncludePaths: -I$(ALICE_ROOT)/include
  // or in each macro
  gSystem->AddIncludePath("-I$ALICE_ROOT/include");

  // Create the analysis manager
  AliAnalysisManager *mgr = new AliAnalysisManager("dNdeta");

  AliVEventHandler* esdH = new AliESDInputHandler;
  ((AliESDInputHandler*)esdH)->SetReadFriends(kFALSE);
  mgr->SetInputEventHandler(esdH);

  // Create tasks
  gROOT->LoadMacro("AliAnalysisTaskdNdetaMC.cxx++g");

  AliAnalysisTask *task1 = new AliAnalysisTaskdNdetaMC("TaskdNdeta");
  ((AliAnalysisTaskdNdetaMC*)task1)->SetEtaMax(etamax);
  if (skipNorm) ((AliAnalysisTaskdNdetaMC*)task1)->SkipNormalization();
  // Enable MC event handler

  AliMCEventHandler* handler = new AliMCEventHandler;
  handler->SetReadTR(kFALSE);
  mgr->SetMCtruthEventHandler(handler);

  // Add tasks
  mgr->AddTask(task1);

  // Create containers for input/output
  AliAnalysisDataContainer *cinput = mgr->GetCommonInputContainer();
  AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("coutput", TList::Class(),    AliAnalysisManager::kOutputContainer, outfile);

  // Connect input/output
  mgr->ConnectInput(task1, 0, cinput);
  mgr->ConnectOutput(task1, 1, coutput1);

  // Enable debug printouts
  mgr->SetDebugLevel(0);

  if (!mgr->InitAnalysis()) return;

  mgr->PrintStatus();

  mgr->StartAnalysis("local", chain);
}
Ejemplo n.º 9
0
Bool_t AliCFSingleTrackTask(
			    const Bool_t useGrid = 1,
			    const Bool_t readAOD = 0,
			    const Bool_t readTPCTracks = 0,
			    const char * kTagXMLFile="wn.xml" // XML file containing tags
			    )
{
  
  TBenchmark benchmark;
  benchmark.Start("AliSingleTrackTask");

  AliLog::SetGlobalDebugLevel(0);

  Load() ; //load the required libraries

  TChain * analysisChain ;

  if (useGrid) { //data located on AliEn
    TGrid::Connect("alien://") ;    //  Create an AliRunTagCuts and an AliEventTagCuts Object 
                                    //  and impose some selection criteria
    AliRunTagCuts      *runCuts   = new AliRunTagCuts(); 
    AliEventTagCuts    *eventCuts = new AliEventTagCuts(); 
    AliLHCTagCuts      *lhcCuts   = new AliLHCTagCuts(); 
    AliDetectorTagCuts *detCuts   = new AliDetectorTagCuts(); 
    eventCuts->SetMultiplicityRange(0,2000);

    //  Create an AliTagAnalysis Object and chain the tags
    AliTagAnalysis   *tagAna = new AliTagAnalysis(); 
    if (readAOD) tagAna->SetType("AOD");  //for aliroot > v4-05
    else         tagAna->SetType("ESD");  //for aliroot > v4-05
    TAlienCollection *coll   = TAlienCollection::Open(kTagXMLFile); 
    TGridResult      *tagResult = coll->GetGridResult("",0,0);
    tagResult->Print();
    tagAna->ChainGridTags(tagResult);

    //  Create a new esd chain and assign the chain that is returned by querying the tags
    analysisChain = tagAna->QueryTags(runCuts,lhcCuts,detCuts,eventCuts); 
  }

  else {// local data
    //here put your input data path
    printf("\n\nRunning on local file, please check the path\n\n");

    if (readAOD) {
      analysisChain = new TChain("aodTree");
      analysisChain->Add("your_data_path/001/AliAOD.root");
      analysisChain->Add("your_data_path/002/AliAOD.root");
    }
    else {
      analysisChain = new TChain("esdTree");
      analysisChain->Add("your_data_path/001/AliESDs.root");
      analysisChain->Add("your_data_path/002/AliESDs.root");
    }
  }
  

  Info("AliCFSingleTrackTask",Form("CHAIN HAS %d ENTRIES",(Int_t)analysisChain->GetEntries()));

  //CONTAINER DEFINITION
  Info("AliCFSingleTrackTask","SETUP CONTAINER");
  //the sensitive variables (2 in this example), their indices
  UInt_t ipt = 0;
  UInt_t iy  = 1;
  //Setting up the container grid... 
  UInt_t nstep = 4 ; //number of selection steps MC 
  const Int_t nvar   = 2 ; //number of variables on the grid:pt,y
  const Int_t nbin1  = 8 ; //bins in pt
  const Int_t nbin2  = 8 ; //bins in y 

  //arrays for the number of bins in each dimension
  Int_t iBin[nvar];
  iBin[0]=nbin1;
  iBin[1]=nbin2;

  //arrays for lower bounds :
  Double_t *binLim1=new Double_t[nbin1+1];
  Double_t *binLim2=new Double_t[nbin2+1];

  //values for bin lower bounds
  for(Int_t i=0; i<=nbin1; i++) binLim1[i]=(Double_t)ptmin + (ptmax-ptmin)/nbin1*(Double_t)i ; 
  for(Int_t i=0; i<=nbin2; i++) binLim2[i]=(Double_t)ymin  + (ymax-ymin)  /nbin2*(Double_t)i ;
  //one "container" for MC
  AliCFContainer* container = new AliCFContainer("container","container for tracks",nstep,nvar,iBin);
  //setting the bin limits
  container -> SetBinLimits(ipt,binLim1);
  container -> SetBinLimits(iy,binLim2);
  container -> SetVarTitle(ipt,"pt");
  container -> SetVarTitle(iy, "y");
  container -> SetStepTitle(0, "generated");
  container -> SetStepTitle(1, "in acceptance");
  container -> SetStepTitle(2, "reconstructed");
  container -> SetStepTitle(3, "after PID");

  // SET TLIST FOR QA HISTOS
  TList* qaList = new TList();

  //CREATE THE  CUTS -----------------------------------------------

  //Event-level cuts:
  AliCFEventRecCuts* evtRecCuts = new AliCFEventRecCuts("evtRecCuts","Rec-event cuts");
//   evtRecCuts->SetUseTPCVertex();
//   evtRecCuts->SetRequireVtxCuts(kTRUE);
//   evtRecCuts->SetVertexNContributors(-2,5);
  evtRecCuts->SetQAOn(qaList);

  // Gen-Level kinematic cuts
  AliCFTrackKineCuts *mcKineCuts = new AliCFTrackKineCuts("mcKineCuts","MC-level kinematic cuts");
  mcKineCuts->SetPtRange(ptmin,ptmax);
  mcKineCuts->SetRapidityRange(ymin,ymax);
  mcKineCuts->SetChargeMC(charge);
  mcKineCuts->SetQAOn(qaList);

  //Particle-Level cuts:  
  AliCFParticleGenCuts* mcGenCuts = new AliCFParticleGenCuts("mcGenCuts","MC particle generation cuts");
  mcGenCuts->SetRequireIsPrimary();
  mcGenCuts->SetRequirePdgCode(PDG,/*absolute=*/kTRUE);
  mcGenCuts->SetQAOn(qaList);

  //Acceptance Cuts
  AliCFAcceptanceCuts *mcAccCuts = new AliCFAcceptanceCuts("mcAccCuts","MC acceptance cuts");
  mcAccCuts->SetMinNHitITS(mintrackrefsITS);
  mcAccCuts->SetMinNHitTPC(mintrackrefsTPC);
  mcAccCuts->SetQAOn(qaList);

  // Rec-Level kinematic cuts
  AliCFTrackKineCuts *recKineCuts = new AliCFTrackKineCuts("recKineCuts","rec-level kine cuts");
  recKineCuts->SetPtRange(ptmin,ptmax);
  recKineCuts->SetRapidityRange(ymin,ymax);
  recKineCuts->SetChargeRec(charge);
  recKineCuts->SetQAOn(qaList);

  AliCFTrackQualityCuts *recQualityCuts = new AliCFTrackQualityCuts("recQualityCuts","rec-level quality cuts");
  if (!readAOD)       {
//     recQualityCuts->SetMinNClusterTRD(0);
//     recQualityCuts->SetMaxChi2PerClusterTRD(10.);
  }
  recQualityCuts->SetStatus(AliESDtrack::kTPCrefit);
  recQualityCuts->SetQAOn(qaList);

  AliCFTrackIsPrimaryCuts *recIsPrimaryCuts = new AliCFTrackIsPrimaryCuts("recIsPrimaryCuts","rec-level isPrimary cuts");
  if (readAOD) recIsPrimaryCuts->SetAODType(AliAODTrack::kPrimary);
  else         recIsPrimaryCuts->SetMaxNSigmaToVertex(3);
  recIsPrimaryCuts->SetQAOn(qaList);

  AliCFTrackCutPid* cutPID = new AliCFTrackCutPid("cutPID","ESD_PID") ;
  int n_species = AliPID::kSPECIES ;
  Double_t* prior = new Double_t[n_species];
  
  prior[0] = 0.0244519 ;
  prior[1] = 0.0143988 ;
  prior[2] = 0.805747  ;
  prior[3] = 0.0928785 ;
  prior[4] = 0.0625243 ;
  
  cutPID->SetPriors(prior);
  cutPID->SetProbabilityCut(0.0);
  if (readTPCTracks) cutPID->SetDetectors("TPC");
  else               cutPID->SetDetectors("ALL");
  if (readAOD) cutPID->SetAODmode(kTRUE );
  else         cutPID->SetAODmode(kFALSE);
  switch(TMath::Abs(PDG)) {
  case 11   : cutPID->SetParticleType(AliPID::kElectron, kTRUE); break;
  case 13   : cutPID->SetParticleType(AliPID::kMuon    , kTRUE); break;
  case 211  : cutPID->SetParticleType(AliPID::kPion    , kTRUE); break;
  case 321  : cutPID->SetParticleType(AliPID::kKaon    , kTRUE); break;
  case 2212 : cutPID->SetParticleType(AliPID::kProton  , kTRUE); break;
  default   : printf("UNDEFINED PID\n"); break;
  }
  cutPID->SetQAOn(qaList);

  printf("CREATE EVENT LEVEL CUTS\n");
  TObjArray* evtList = new TObjArray(0) ;
//   evtList->AddLast(evtRecCuts);
  
  printf("CREATE MC KINE CUTS\n");
  TObjArray* mcList = new TObjArray(0) ;
  mcList->AddLast(mcKineCuts);
  mcList->AddLast(mcGenCuts);

  printf("CREATE ACCEPTANCE CUTS\n");
  TObjArray* accList = new TObjArray(0) ;
  accList->AddLast(mcAccCuts);

  printf("CREATE RECONSTRUCTION CUTS\n");
  TObjArray* recList = new TObjArray(0) ;
  recList->AddLast(recKineCuts);
  recList->AddLast(recQualityCuts);
  recList->AddLast(recIsPrimaryCuts);

  printf("CREATE PID CUTS\n");
  TObjArray* fPIDCutList = new TObjArray(0) ;
  fPIDCutList->AddLast(cutPID);

  //CREATE THE INTERFACE TO CORRECTION FRAMEWORK USED IN THE TASK
  printf("CREATE INTERFACE AND CUTS\n");
  AliCFManager* man = new AliCFManager() ;

  man->SetNStepEvent(1);
  man->SetEventCutsList(0,evtList);

  man->SetParticleContainer(container);
  man->SetParticleCutsList(0,mcList);
  man->SetParticleCutsList(1,accList);
  man->SetParticleCutsList(2,recList);
  man->SetParticleCutsList(3,fPIDCutList);


  //CREATE THE TASK
  printf("CREATE TASK\n");
  // create the task
  AliCFSingleTrackTask *task = new AliCFSingleTrackTask("AliSingleTrackTask");
  task->SetCFManager(man); //here is set the CF manager
  task->SetQAList(qaList);
  if (readAOD)       task->SetReadAODData() ;
  if (readTPCTracks) task->SetReadTPCTracks();

  //SETUP THE ANALYSIS MANAGER TO READ INPUT CHAIN AND WRITE DESIRED OUTPUTS
  printf("CREATE ANALYSIS MANAGER\n");
  // Make the analysis manager
  AliAnalysisManager *mgr = new AliAnalysisManager("TestManager");

  if (useGrid) mgr->SetAnalysisType(AliAnalysisManager::kGridAnalysis);
  else mgr->SetAnalysisType(AliAnalysisManager::kLocalAnalysis);


  AliMCEventHandler*  mcHandler = new AliMCEventHandler();
  mgr->SetMCtruthEventHandler(mcHandler);
 
  AliInputEventHandler* dataHandler ;
  
  if   (readAOD) dataHandler = new AliAODInputHandler();
  else           dataHandler = new AliESDInputHandler();
  mgr->SetInputEventHandler(dataHandler);

  // Create and connect containers for input/output

  //------ input data ------
  AliAnalysisDataContainer *cinput0  = mgr->CreateContainer("cchain0",TChain::Class(),AliAnalysisManager::kInputContainer);

  // ----- output data -----
  
  //slot 0 : default output tree (by default handled by AliAnalysisTaskSE)
  AliAnalysisDataContainer *coutput0 = mgr->CreateContainer("ctree0", TTree::Class(),AliAnalysisManager::kOutputContainer,"output.root");

  //now comes user's output objects :
  
  // output TH1I for event counting
  AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("chist0", TH1I::Class(),AliAnalysisManager::kOutputContainer,"output.root");
  // output Correction Framework Container (for acceptance & efficiency calculations)
  AliAnalysisDataContainer *coutput2 = mgr->CreateContainer("ccontainer0", AliCFContainer::Class(),AliAnalysisManager::kOutputContainer,"output.root");
  // output QA histograms 
  AliAnalysisDataContainer *coutput3 = mgr->CreateContainer("clist0", TList::Class(),AliAnalysisManager::kOutputContainer,"output.root");

  cinput0->SetData(analysisChain);

  mgr->AddTask(task);
  mgr->ConnectInput(task,0,mgr->GetCommonInputContainer());
  mgr->ConnectOutput(task,0,coutput0);
  mgr->ConnectOutput(task,1,coutput1);
  mgr->ConnectOutput(task,2,coutput2);
  mgr->ConnectOutput(task,3,coutput3);
 
  printf("READY TO RUN\n");
  //RUN !!!
  if (mgr->InitAnalysis()) {
    mgr->PrintStatus();
    mgr->StartAnalysis("local",analysisChain);
  }

  benchmark.Stop("AliSingleTrackTask");
  benchmark.Show("AliSingleTrackTask");

  return kTRUE ;
}
Ejemplo n.º 10
0
//_________________________________________________________________________
// Macro that creates esd xml collections by querying the tags.
// It addresses the following use cases:
// o) The tag files are stored locally.
//   - One queries the tags by using simple string statements.
//   - One queries the tags by using the corresponding ilcroot classes.
// o) The tag files are stored in the file catalog. 
//    In this case the first thing we do is to query the f.c.
//    and extract a collection (xml) of tag files. 
//   - One queries the tags by using simple string statements.
//   - One queries the tags by using the corresponding ilcroot classes.
//                                             
// In all cases you create the xml file by using the CreateXMLCollection
// of the IlcTagAnalysisClass. The first argument of this method is the
// name of the output xml collection which is stored locally.
//
//  coll_in:    xml collection of tag files 
//           or path to the tag files
//
//  coll_out:   name of the output xml collection
//_________________________________________________________________________
Bool_t CreateXML(char * coll_in="pp.xml", char * coll_out="global2")
{
  TStopwatch timer;
  timer.Start();
  
  
  gSystem->Load("libTreePlayer");    //needed in the case of the string statements
  gSystem->Load("libANALYSIS");      //needed by libANALYSISilc
  gSystem->Load("libANALYSISilc"); //needed IlcTagAnalysis

  // Create A tag analysis object and impose some selection criteria
  IlcTagAnalysis *TagAna = new IlcTagAnalysis(); 

  //Case where the tag files are stored locally
  //TagAna->ChainLocalTags(coll_in);

  //Case where the tag files are stored in the file catalog
  //coll_in (pp.xml) is the xml collection of tag files that was produced 
  //by querying the file catalog:
  // find -x pp /ilc/sim/PDC_08/LHC08r/270001/* *tag.root > pp.xml

  TGrid::Connect("alien://pcapiserv01.cern.ch:10000","elopez");
  //TGrid::Connect("alien://"); 
  TAlienCollection* coll = TAlienCollection::Open(coll_in);
  TGridResult* TagResult = coll->GetGridResult("",0,0);
  cout << endl << "Chain Grid Tags..."  << endl;
  TagAna->ChainGridTags(TagResult);

  //__________________________//
  //Usage of string statements//
  //__________________________//
/*
  const char* runTagCuts = "fIlcRunId==270001";
  const char* lhcTagCuts = "fLHCTag.fLHCState==LHC08r";
  const char* detTagCuts = "fDetectorTag.fTPC==1";
  const char* evTagCuts  = "(fEventTag.fTopPtMin >= 1.0)&&(fEventTag.fNumberOfTracks >= 11)&&(fEventTag.fNumberOfTracks <= 12)";
*/

  //________________________________________________//
  //Usage of IlcRunTagCuts & IlcEventTagCuts classes//
  //________________________________________________//
  // create a RunTagCut object
  IlcRunTagCuts *runTagCuts = new IlcRunTagCuts();
  // runTagCuts->SetRunId(270001);

  // create an LHCTagCuts object
  IlcLHCTagCuts *lhcTagCuts = new IlcLHCTagCuts();

  // create an DetectorTagCuts object
  IlcDetectorTagCuts *detTagCuts  = new IlcDetectorTagCuts();

  // create an EventTagCut object
  IlcEventTagCuts *evTagCuts = new IlcEventTagCuts();
  //evTagCuts->SetMultiplicityRange(11,12);
  //evTagCuts->SetTopPtMin(1.0);

  // Query the Tags and create the xml collection 
  cout << endl << "Create XML Collection..."  << endl;
  TagAna->CreateXMLCollection(coll_out, runTagCuts, lhcTagCuts, detTagCuts, evTagCuts);

  timer.Stop();
  timer.Print();

  return kTRUE;
}