From fa6e7866c6764e8f4ae8597d4d6adb0e19185a73 Mon Sep 17 00:00:00 2001 From: ivana Date: Fri, 8 Sep 2006 15:34:20 +0000 Subject: [PATCH] New analysis macros (Hermine, Alessandro) --- MUON/DecodeRecoCocktail.C | 129 ++++++++++++++++++++++++++++++++++++++ MUON/MergeMuonLight.C | 68 ++++++++++++++++++++ MUON/ReadRecoCocktail.C | 58 +++++++++++++++++ 3 files changed, 255 insertions(+) create mode 100644 MUON/DecodeRecoCocktail.C create mode 100644 MUON/MergeMuonLight.C create mode 100644 MUON/ReadRecoCocktail.C diff --git a/MUON/DecodeRecoCocktail.C b/MUON/DecodeRecoCocktail.C new file mode 100644 index 00000000000..0b9f095cdd6 --- /dev/null +++ b/MUON/DecodeRecoCocktail.C @@ -0,0 +1,129 @@ +/************************************************************************** + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + +/* $Id$ */ + +// A. De Falco, H. Woehri, INFN Cagliari, July 2006 +// This macro reads the generation/reconstruction files in the +// input directory (dirname), +// builds a tree that contains, for each event, an array of muons and dimuons +// (TClonesArrays of AliMUONTrackLight and AliMUONPairLight objects) +// and writes the tree in an output file (outFileName) +// Note that if the path for the output file is not explicitly specified, +// it will be written in the directory containing the generation/reconstruction + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "AliMUONTrackLight.h" +#include "AliMUONPairLight.h" + +void DecodeRecoCocktail(char* dirname=".", char* outFileName = "MuonLight.root"){ + const char *startingDir = gSystem->pwd(); + gSystem->cd(dirname); + TFile *fout = new TFile(outFileName,"recreate"); + + AliMUONRecoCheck *rc = new AliMUONRecoCheck("galice.root"); + AliRunLoader *runLoader = rc->GetRunLoader(); + + TClonesArray *muonArray = new TClonesArray("AliMUONTrackLight",10); + TClonesArray *dimuonArray = new TClonesArray("AliMUONPairLight",10); + TTree *treeOut = new TTree("tree","tree"); + + fout->cd(); + treeOut->Branch("muons",&muonArray); + treeOut->Branch("dimuons",&dimuonArray); + + runLoader->LoadKinematics("READ");; + Int_t nev = runLoader->GetNumberOfEvents(); + + TLorentzVector v; + for(Int_t ievent = 0; ievent < nev; ievent++){ // loop over events + printf ("Event %d of %d\n",ievent,nev); + muonArray->Clear(); // clean muon and dimuon arrays + dimuonArray->Clear(); + runLoader->GetEvent(ievent); + rc->ResetTracks(); + rc->MakeTrackRef(); // make reconstructable tracks + + TClonesArray * trackRecoArray = rc->GetTrackReco(); + TClonesArray * trackRefArray = rc->GetMuonTrackRef(); + Int_t nTrackReco = trackRecoArray->GetEntriesFast(); + Int_t nreftracks = 0; + for (Int_t itrRec = 0; itrRecAt(itrRec); + AliMUONTrackLight *muLight = new AliMUONTrackLight(); + AliMUONTrackParam *trPar = trackReco->GetTrackParamAtVertex(); + muLight->SetCharge(Int_t(TMath::Sign(1.,trPar->GetInverseBendingMomentum()))); + muLight->SetPxPyPz(trPar->Px(),trPar->Py(), trPar->Pz()); + muLight->SetTriggered(trackReco->GetMatchTrigger()); + Double_t xyz[3] = { trPar->GetNonBendingCoor(), + trPar->GetBendingCoor(), + trPar->GetZ()}; + muLight->SetVertex(xyz); + // find the reference track and store further information + TParticle *part = muLight->FindRefTrack(trackReco,trackRefArray,runLoader); + if (part) { + v.SetPxPyPzE(part->Px(), part->Py(), part->Pz(), part->Energy()); + muLight->SetPGen(v); + muLight->FillMuonHistory(runLoader, part); + muLight->PrintInfo("A"); + //store the referenced track in the muonArray: + TClonesArray &muons = *muonArray; + new (muons[nreftracks++]) AliMUONTrackLight(*muLight); + } + } + + // now loop over muon pairs to build dimuons + Int_t nmuons = muonArray->GetEntriesFast(); + Int_t ndimuons = 0; + for(Int_t itrRec1 = 0; itrRec1 < nmuons-1; itrRec1++) { + AliMUONTrackLight* mu1 = (AliMUONTrackLight*) muonArray->At(itrRec1); + for(Int_t itrRec2 = itrRec1+1; itrRec2 < nmuons; itrRec2++){ + AliMUONTrackLight* mu2 = (AliMUONTrackLight*) muonArray->At(itrRec2); + AliMUONPairLight *dimuLight = new AliMUONPairLight(); + dimuLight->SetMuons(*mu1, *mu2); + // if(dimuLight->GetCreationProcess() == 2){ + // printf ("#dimuon = %d (%d, %d) \n", ndimuons, itrRec1, itrRec2); + // dimuLight->PrintInfo("A"); + // } + //store the referenced track in the dimuonArray: + TClonesArray &dimuons = *dimuonArray; + new (dimuons[ndimuons++]) AliMUONPairLight(*dimuLight); + } + } + Int_t ndimu2 = dimuonArray->GetEntriesFast(); + // printf ("dimuonArray has %d entries\n",ndimu2); + // dimuonArray->Dump(); + // printf ("filling tree\n"); + // // fill the tree + treeOut->Fill(); + // printf ("done\n"); + + } + fout->cd(); + treeOut->Write(); + gSystem->cd(startingDir); +} diff --git a/MUON/MergeMuonLight.C b/MUON/MergeMuonLight.C new file mode 100644 index 00000000000..2eb285534f6 --- /dev/null +++ b/MUON/MergeMuonLight.C @@ -0,0 +1,68 @@ +/************************************************************************** + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + +/* $Id$ */ + +// A. De Falco, H. Woehri, INFN Cagliari, July 2006 +// This macro merges several files built with DecodeRecoCocktail.C into +// a single one. +// Arguments: foutname = name of the output file +// flistname = name of a text file containing the list of files +// to be merged +void MergeMuonLight(char *foutname="MuonLightMerged.root",char *flistname="lista.lis"){ + // up to 2000 input files + + TFile *file[2000]; + TClonesArray *muonArray = new TClonesArray("AliMUONTrackLight",2); + TClonesArray *dimuonArray = new TClonesArray("AliMUONPairLight",1); + + // open output file + TFile *fout = new TFile (foutname,"recreate"); + TTree *treeOut = new TTree("tree","tree"); + treeOut->Branch("muons",&muonArray); + treeOut->Branch("dimuons",&dimuonArray); + + char *filename = new char[100]; + // read the list of input files + FILE *pf= fopen(flistname,"r"); + Int_t nfiles=0; + Int_t outflag=0; + // open the n input files + while (!outflag) { + if (fscanf(pf,"%s",filename)==1) { + file[nfiles++] = new TFile (filename); + cout << "Opening for input " << filename << endl; + } + else outflag = 1; + } + fclose(pf); + + + for (Int_t ifile=0; ifileGetName()); + TTree *tree = (TTree*) file[ifile]->Get("tree"); + tree->SetBranchAddress("muons",&muonArray); + tree->SetBranchAddress("dimuons",&dimuonArray); + Int_t nev = tree->GetEntriesFast(); + printf ("Scanning file %d: %s containing %d events\n", + ifile, file[ifile]->GetName(),nev); + for (Int_t iev=0; ievGetEvent(iev); + treeOut->Fill(); + } + } + fout->cd(); + treeOut->Write(); +} diff --git a/MUON/ReadRecoCocktail.C b/MUON/ReadRecoCocktail.C new file mode 100644 index 00000000000..8d75d844a91 --- /dev/null +++ b/MUON/ReadRecoCocktail.C @@ -0,0 +1,58 @@ +/************************************************************************** + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + +/* $Id$ */ + +// A. De Falco, H. Woehri, INFN Cagliari, July 2006 +// base macro to read the trees generated with DecodeRecoCocktail.C +// + +void ReadRecoCocktail(char* fname="./MuonLight.root"){ + TFile *file = new TFile(fname); + TClonesArray *muonArray = new TClonesArray("AliMUONTrackLight",100); + TClonesArray *dimuonArray = new TClonesArray("AliMUONPairLight",100); + TTree *tree = (TTree*) file->Get("tree"); + tree->SetBranchAddress("muons",&muonArray); + tree->SetBranchAddress("dimuons",&dimuonArray); + Int_t nev = tree->GetEntriesFast(); + printf ("%d events in tree\n",nev); + Int_t ndimuUncorr=0; + for (Int_t iev=0; ievGetEvent(iev); + Int_t nmu = muonArray->GetEntries(); + for (Int_t imu=0; imuAt(imu); + // mu->Dump(); + } + Int_t ndimu = dimuonArray->GetEntriesFast(); + for (Int_t idimu=0; idimuAt(idimu); + // dimu->Dump(); + if (!dimu->IsCorrelated()) { + printf ("Event %d / %d; dimuon %d not correlated\n",iev,nev,idimu); + dimu->PrintInfo("H"); + ndimuUncorr++; + } + } + } + printf ("%d uncorrelated dimuons in file\n",ndimuUncorr); + TCanvas *c1=new TCanvas(); + c1->Divide(2); + printf ("plotting the mass and pt spectra of opposite sign dimuons\n"); + c1->cd(1); + tree->Draw("dimuons.GetPRec().M()","dimuons.GetCharge()==0"); + c1->cd(2); + tree->Draw("dimuons.GetPRec().Pt()","dimuons.GetCharge()==0"); +} -- 2.43.0