]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/Macros/AliTRDMergeFilesHisto2D.C
new PID 2dLQ implementation to fix bug 54540
[u/mrichter/AliRoot.git] / TRD / Macros / AliTRDMergeFilesHisto2D.C
CommitLineData
8470c96e 1#if !defined( __CINT__) || defined(__MAKECINT__)
2
8470c96e 3#include <TChain.h>
4#include <TFile.h>
5#include <TTree.h>
6#include <TString.h>
7#include <Riostream.h>
8#include <TSystem.h>
9#include <TH1F.h>
8dd46aaa 10#include <TH2.h>
8470c96e 11#include <AliCDBManager.h>
8dd46aaa 12#include <../TRD/AliTRDCalibra.h>
8470c96e 13
14#endif
15
16
17void AliTRDMergeFilesHisto2D(const char* variablecali, const char* nome, const char* dire){
18 //
19 // After having simulated and reconstructed events in subrepertories 000%d of dire
20 // this macro searchs in the subdirectories the file TRD.calibration.root
21 // takes the 2D histos and merge them
22 // nome is the name of the file where the sum will be written
23 // variablecali can be: CH2d, PH2d, PRF2d
24 //
25
26
27
28 //The final sum histo
29 TH2 *histosum = 0x0;
30 Int_t j = 0;
31
32
33 //The patterns
34 const char *name="TRD.calibration.root";
35 const char *patterndir="0";
36 const char *namesubdir = 0x0;
37 char dir[200];
38
39 //Open the current directory
40 void * dircu = gSystem->OpenDirectory(dire);
41 while((namesubdir = gSystem->GetDirEntry(dircu))) {
42 if(strstr(namesubdir,patterndir)) {
43 sprintf(dir,"%s/%s",dire,namesubdir);
44 printf("process subdirectories: %s\n",dir);
45
46 //full name of the file and tree
47 char fullname[255] = "";
48
49 sprintf(fullname,"%s/%s",dir,name);
50 printf("Process file: %s\n",fullname);
51 TFile *file = (TFile *) TFile::Open(fullname,"READ");
52 if(!file) continue;
53 TH2 *histo = (TH2 *) file->Get(variablecali);
54 histo->SetDirectory(0);
55 if(!histo) continue;
56 if(j == 0) histosum = histo;
57 else histosum->Add(histo,1);
58 j++;
59 delete file;
60 }// if patterndir
61 }//loop in the current directory
62
63
64 //Open a file to put the histosum
65 TFile *fout = TFile::Open((const char*) nome ,"UPDATE");
66 fout->WriteTObject(histosum,histosum->GetName(),(Option_t *) "kOverWrite");
67 fout->Close();
68
69}