]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/MergeMuonLight.C
Updated list of MUON libraries
[u/mrichter/AliRoot.git] / MUON / MergeMuonLight.C
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 // A. De Falco, H. Woehri, INFN Cagliari, July 2006 
19 // This macro merges several files built with DecodeRecoCocktail.C into 
20 // a single one. 
21 // Arguments:     foutname = name of the output file
22 //                flistname = name of a text file containing the list of files
23 //                            to be merged 
24 //                saveAll = boolian that allows/forbids saving of events with no muons
25
26 #if !defined(__CINT__) || defined(__MAKECINT__)
27 #include "TFile.h"
28 #include "TTree.h"
29 #include "TClonesArray.h"
30 #include "AliMUONTrackLight.h"
31 #include "AliMUONPairLight.h"
32 #endif
33
34
35 void MergeMuonLight(char *foutname="MuonLightMerged.root",char *flistname="lista.lis", Bool_t saveAll = kTRUE){ 
36   // up to 2000 input files 
37
38   TFile *file[2000];
39   TClonesArray *muonArray   = new TClonesArray("AliMUONTrackLight",2); 
40   TClonesArray *dimuonArray = new TClonesArray("AliMUONPairLight",1); 
41
42   // open output file 
43   TFile *fout = new TFile (foutname,"recreate"); 
44   TTree *treeOut = new TTree("tree","tree"); 
45   treeOut->Branch("muons",&muonArray); 
46   treeOut->Branch("dimuons",&dimuonArray); 
47   
48   char *filename = new char[100];
49   // read the list of input files 
50   FILE *pf= fopen(flistname,"r");
51   Int_t nfiles=0; 
52   Int_t outflag=0; 
53   // open the n input files 
54   while (!outflag) { 
55     if (fscanf(pf,"%s",filename)==1) { 
56       file[nfiles++] = new TFile (filename); 
57       printf("Opening for input %s", filename);
58     }
59     else outflag = 1; 
60   }
61   fclose(pf); 
62
63  
64   for (Int_t ifile=0; ifile<nfiles; ifile++) {
65     printf ("Scanning file %d: %s\n",ifile, file[ifile]->GetName()); 
66     TTree *tree = (TTree*) file[ifile]->Get("tree"); 
67     tree->SetBranchAddress("muons",&muonArray); 
68     tree->SetBranchAddress("dimuons",&dimuonArray); 
69     Int_t nev = tree->GetEntriesFast(); 
70     printf ("Scanning file %d: %s containing %d events\n",
71             ifile, file[ifile]->GetName(),nev); 
72     for (Int_t iev=0; iev<nev; iev++) {
73       tree->GetEvent(iev); 
74       Int_t nMu = muonArray->GetEntriesFast(); 
75       if(!saveAll)
76         if(nMu < 1) continue;
77       treeOut->Fill();
78     }
79     file[ifile]->Close();
80   }//end of scanning incoming file
81   fout->cd(); 
82   treeOut->Write(); 
83 }