.so cleanup: removed from gSystem->Load()
[u/mrichter/AliRoot.git] / PWGPP / ZDC / macros / MakeTrendZDC.C
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <TROOT.h>
5 #include <Riostream.h>
6 #include <TClassTable.h>
7 #include <TStyle.h>
8 #include <TMath.h>
9 #include <TFile.h>
10 #include <TCanvas.h>
11 #include <TH1.h>
12 #include <TH2.h>
13 #include <TProfile.h>
14 #include <TLine.h>
15 #include <TGrid.h>
16 #include <TBits.h>
17 #include <TChain.h>
18 #include <TNtuple.h>
19 #include <TTree.h>
20 #include <TBranch.h>
21 #include <TFileMerger.h>
22 #include <TGridResult.h>
23 #include <TSystem.h>
24 #include <TGaxis.h>
25 #endif
26
27 int MakeTrendZDC(char *infile, int run) {
28   
29   TStopwatch timer;
30   timer.Start();
31   gSystem->SetIncludePath("-I$ROOTSYS/include -I$ALICE_ROOT/include -I$ALICE_ROOT");
32   gSystem->Load("libSTAT");
33   gSystem->Load("libANALYSIS");
34   gSystem->Load("libANALYSISalice");
35   gSystem->Load("libANALYSIScalib");
36   gSystem->Load("libCORRFW");
37   gSystem->Load("libANALYSISalice");
38   gSystem->Load("libANALYSIScalib");
39   gSystem->Load("libTender");
40   gSystem->Load("libPWGPP");
41   
42   char *outfile = "trending.root";
43   
44   if (!infile) return -1;
45   if (!outfile) return -1;
46   TFile *f =0;
47   f=TFile::Open(infile,"read");
48   if (!f) {
49     printf("File %s not available\n", infile);
50     return -1;
51   }  
52    
53   //access histograms lists
54   char zdcQAdirName[20]="ZDC_Performance";
55   char genListName[20]="QAZDCHists";
56   
57   TDirectoryFile * zdcQAdir=(TDirectoryFile*)f->Get(zdcQAdirName);
58   if (!zdcQAdir) {
59     Printf("ERROR: ZDC QA directory not present in input file.\n");
60     return -1;
61   }
62   
63   TList * generalList=(TList*)zdcQAdir->Get(genListName);
64
65   if (!generalList) Printf("WARNING: general QA histograms absent or not accessible\n");
66
67   TH1D    *fhTDCZNC          = (TH1D*)generalList->FindObject("fhTDCZNC");       //! TDC ZNC sum
68   TH1D    *fhTDCZNA          = (TH1D*)generalList->FindObject("fhTDCZNA");       //! TDC DIFF sum
69   TH1D    *fhTDCZNSum        = (TH1D*)generalList->FindObject("fhTDCZNSum");     //! TDC ZNC sum
70   TH1D    *fhTDCZNDiff       = (TH1D*)generalList->FindObject("fhTDCZNDiff");    //! TDC DIFF sum
71   TH1D    *fhZNCSumQ         = (TH1D*)generalList->FindObject("fhZNCSumQ");      //! ZNC sum 4Q
72   TH1D    *fhZNASumQ         = (TH1D*)generalList->FindObject("fhZNASumQ");      //! ZNA sum 4Q
73   TH1D    *fhZPCSumQ         = (TH1D*)generalList->FindObject("fhZPCSumQ");      //! ZPC sum 4Q
74   TH1D    *fhZPASumQ         = (TH1D*)generalList->FindObject("fhZPASumQ");      //! ZPA sum 4Q
75   TH1D    *fhZEM1Spectrum    = (TH1D*)generalList->FindObject("fhZEM1Spectrum"); //! ZEM1 spectra
76   TH1D    *fhZEM2Spectrum    = (TH1D*)generalList->FindObject("fhZEM2Spectrum"); //! ZEM2 spectra
77   TH1D    *fhZNCpmc          = (TH1D*)generalList->FindObject("fhZNCpmc");       //! ZNC PMCs
78   TH1D    *fhZNApmc          = (TH1D*)generalList->FindObject("fhZNApmc");       //! ZNA PMCs
79   TH1D    *fhZPCpmc          = (TH1D*)generalList->FindObject("fhZPCpmc");       //! ZPC PMCs
80   TH1D    *fhZPApmc          = (TH1D*)generalList->FindObject("fhZPApmc");       //! ZPA PMCs
81   TH1D    *fhPMCZNCemd       = (TH1D*)generalList->FindObject("fhPMCZNCemd");    //! ZNC PMC low gain chain
82   TH1D    *fhPMCZNAemd       = (TH1D*)generalList->FindObject("fhPMCZNAemd");    //! ZNA PMC low gain chain
83   TH1D    *fhTDCZNAcorr      = (TH1D*)generalList->FindObject("fhTDCZNAcorr");   //! ZNA corrected TDC
84   TH1D    *fhTDCZNCcorr      = (TH1D*)generalList->FindObject("fhTDCZNCcorr");   //! ZNC corrected TDC  
85   TH2D    *fhZNCCentroid     = (TH2D*)generalList->FindObject("fhZNCCentroid");  //! ZNC centroid
86   TH2D    *fhZNACentroid     = (TH2D*)generalList->FindObject("fhZNACentroid");  //! ZNA centroid
87   TH2D    *fDebunch          = (TH2D*)generalList->FindObject("fDebunch");       //! TDC sum vs. diff  
88   
89   Double_t ZNC_mean = 0.;
90   Double_t ZNA_mean = 0.;
91   Double_t ZPC_mean = 0.;
92   Double_t ZPA_mean = 0.;
93   Double_t ZEM1_mean = 0.;
94   Double_t ZEM2_mean = 0.;  
95   
96   Int_t fhZNCpmcEntries = fhZNCpmc->GetEntries();
97   Int_t fhZNApmcEntries = fhZNApmc->GetEntries();
98   Int_t fhZPCpmcEntries = fhZPCpmc->GetEntries();
99   Int_t fhZPApmcEntries = fhZPApmc->GetEntries();
100   Int_t fhZEM1SpectrumEntries = fhZEM1Spectrum->GetEntries();
101   Int_t fhZEM2SpectrumEntries = fhZEM2Spectrum->GetEntries();  
102   
103   if (fhZNCpmcEntries>0) ZNC_mean = fhZNCpmc->GetMean();
104   if (fhZNApmcEntries>0) ZNA_mean = fhZNApmc->GetMean();
105   if (fhZPCpmcEntries>0) ZPC_mean = fhZPCpmc->GetMean();
106   if (fhZPApmcEntries>0) ZPA_mean = fhZPApmc->GetMean();
107   if (fhZEM1SpectrumEntries>0) ZEM1_mean = fhZEM1Spectrum->GetMean();
108   if (fhZEM2SpectrumEntries>0) ZEM2_mean = fhZEM2Spectrum->GetMean(); 
109   
110   Double_t ZNC_XCent = fhZNCCentroid->GetMean(1);
111   Double_t ZNC_YCent = fhZNCCentroid->GetMean(2);    
112   Double_t ZNA_XCent = fhZNACentroid->GetMean(1);
113   Double_t ZNA_YCent = fhZNACentroid->GetMean(2);
114   Double_t ZNC_XCent_err = fhZNCCentroid->GetRMS(1);
115   Double_t ZNC_YCent_err = fhZNCCentroid->GetRMS(2);    
116   Double_t ZNA_XCent_err = fhZNACentroid->GetRMS(1);
117   Double_t ZNA_YCent_err = fhZNACentroid->GetRMS(2);     
118   Double_t ZN_TDC_Sum = fhTDCZNSum->GetMean();
119   Double_t ZN_TDC_Diff = fhTDCZNDiff->GetMean();  
120   Double_t ZN_TDC_Sum_err = fhTDCZNSum->GetRMS();
121   Double_t ZN_TDC_Diff_err = fhTDCZNDiff->GetRMS();    
122   
123   TTree * ttree=new TTree("trending","tree of trending variables");
124   ttree->Branch("run",&run,"run/I");
125   ttree->Branch("ZNC_mean_value",&ZNC_mean,"ZNC_mean_value/D");
126   ttree->Branch("ZNA_mean_value",&ZNA_mean,"ZNA_mean_value/D"); 
127   ttree->Branch("ZPC_mean_value",&ZPC_mean,"ZPC_mean_value/D");
128   ttree->Branch("ZPA_mean_value",&ZPA_mean,"ZPA_mean_value/D");
129   ttree->Branch("ZEM1_mean_value",&ZEM1_mean,"ZEM1_mean_value/D");
130   ttree->Branch("ZEM2_mean_value",&ZEM2_mean,"ZEM2_mean_value/D");  
131   ttree->Branch("ZNC_X_Centroid",&ZNC_XCent,"ZNC_X_Centroid/D");
132   ttree->Branch("ZNC_Y_Centroid",&ZNC_YCent,"ZNC_Y_Centroid/D");   
133   ttree->Branch("ZNA_X_Centroid",&ZNA_XCent,"ZNA_X_Centroid/D");
134   ttree->Branch("ZNA_Y_Centroid",&ZNA_YCent,"ZNA_Y_Centroid/D");  
135   ttree->Branch("ZNC_X_Centroid_Err",&ZNC_XCent_err,"ZNC_X_Centroid_Err/D");
136   ttree->Branch("ZNC_Y_Centroid_Err",&ZNC_YCent_err,"ZNC_Y_Centroid_Err/D");   
137   ttree->Branch("ZNA_X_Centroid_Err",&ZNA_XCent_err,"ZNA_X_Centroid_Err/D");
138   ttree->Branch("ZNA_Y_Centroid_Err",&ZNA_YCent_err,"ZNA_Y_Centroid_Err/D");    
139   ttree->Branch("ZN_TDC_Sum",&ZN_TDC_Sum,"ZN_TDC_Sum/D");
140   ttree->Branch("ZN_TDC_Diff",&ZN_TDC_Diff,"ZN_TDC_Diff/D");    
141   ttree->Branch("ZN_TDC_Sum_Err",&ZN_TDC_Sum_err,"ZN_TDC_Sum_Err/D");
142   ttree->Branch("ZN_TDC_Diff_Err",&ZN_TDC_Diff_err,"ZN_TDC_Diff_Err/D");  
143     
144   Printf(":::: Getting post-analysis info for run %i",run);
145   TFile * trendFile = new TFile(outfile,"recreate");
146
147   printf("==============  Saving histograms for run %i ===============\n",run);
148   
149   fhTDCZNC->Write();      
150   fhTDCZNA->Write();      
151   fhTDCZNSum->Write();    
152   fhTDCZNDiff->Write();   
153   fhZNCSumQ->Write();     
154   fhZNASumQ->Write();     
155   fhZPCSumQ->Write();     
156   fhZPASumQ->Write();     
157   fhZEM1Spectrum->Write();
158   fhZEM2Spectrum->Write();
159   fhZNCpmc->Write();      
160   fhZNApmc->Write();      
161   fhZPCpmc->Write();      
162   fhZPApmc->Write();      
163   fhZNCCentroid->Write(); 
164   fhZNACentroid->Write(); 
165   fhPMCZNCemd->Write();   
166   fhPMCZNAemd->Write();   
167   fDebunch->Write();      
168   fhTDCZNAcorr->Write();  
169   fhTDCZNCcorr->Write();
170     
171   ttree->Fill();
172   printf("==============  Saving trending quantities in tree for run %i ===============\n",run);
173   
174   trendFile->cd();
175   ttree->Write();
176   trendFile->Close();
177
178 }