fix coverity
[u/mrichter/AliRoot.git] / PWGPP / TRD / macros / makeTrendingDB.C
1 void makeTrendingDB(const Char_t *fl)
2 {
3 // Make trending of variable list "tl" from trending file list "fl"
4 // The trending value list should be formated "var1:var2:var3"
5 // The trending file from the list should be found on a path formated "your path"/runId/TRD.PerformanceTrend.root 
6   gSystem->Load("libANALYSIS.so");
7   gSystem->Load("libANALYSISalice.so");
8   gSystem->Load("libTENDER.so");
9   gSystem->Load("libCORRFW.so");
10   gSystem->Load("libPWGPP.so");
11   gSystem->Load("libPWGmuon.so");
12
13   const Int_t nt(45);
14   const Char_t *tvn[nt][2] = {
15     {"TRDcheckDET_NTracksEvent", "<N_{track}/Event>"},
16     {"TRDcheckDET_NTracksEventRMS", "RMS(N_{track}/Event)"},
17     {"TRDcheckDET_NTracksSector", "<N_{track}/Sector>"},
18     {"TRDcheckDET_NClustersTrack", "<N_{cls}/Track>"},
19     {"TRDcheckDET_NClustersTrackRMS", "RMS(N_{cls}/Track)"},
20     {"TRDcheckDET_NClustersTracklet", "<N_{cls}/Tracklet>"},
21     {"TRDcheckDET_NClustersTrackletRMS", "RMS(N_{cls}/Tracklet)"},
22     {"TRDcheckDET_NTrackletsTrack", "<N_{tracklet}/Track>"},
23     {"TRDcheckDET_NTrackletsTrackRMS", "RMS(N_{tracklet}/Track)"},
24     {"TRDcheckDET_ChargeTracklet", "<dQdl>"},
25     {"TRDcheckDET_ChargeTrackletRMS", "RMS(dQdl)"},
26     {"TRDcheckDET_PHplateau", "Plateau(<PH>)"},
27     {"TRDcheckDET_PHslope", "Slope(<PH>)"},
28     {"TRDcheckDET_PHamplificationPeak", "Peak(<PH>)"},
29 //=======================================================
30     {"TRDresolution_TrkInY", "#Deltay (TrkIn)"},
31     {"TRDresolution_TrkInYn", "#Deltay^{-} (TrkIn)"},
32     {"TRDresolution_TrkInYp", "#Deltay^{+} (TrkIn)"},
33     {"TRDresolution_TrkInRCZ", "#Deltaz (TrkIn)"},
34     {"TRDresolution_TrkInPhn", "#Delta#phi^{-} (TrkIn)"},
35     {"TRDresolution_TrkInPhp", "#Delta#phi^{+} (TrkIn)"},
36     {"TRDresolution_TrkInQp0", "MPV(dQdl^{e+}) (TrkIn)"},
37     {"TRDresolution_TrkInQp1", "MPV(dQdl^{#mu+}) (TrkIn)"},
38     {"TRDresolution_TrkInQp2", "MPV(dQdl^{#pi+}) (TrkIn)"},
39     {"TRDresolution_TrkInQp3", "MPV(dQdl^{K+}) (TrkIn)"},
40     {"TRDresolution_TrkInQp4", "MPV(dQdl^{p+}) (TrkIn)"},
41     {"TRDresolution_TrkInQn0", "MPV(dQdl^{e-}) (TrkIn)"},
42     {"TRDresolution_TrkInQn1", "MPV(dQdl^{#mu-}) (TrkIn)"},
43     {"TRDresolution_TrkInQn2", "MPV(dQdl^{#pi-}) (TrkIn)"},
44     {"TRDresolution_TrkInQn3", "MPV(dQdl^{K-}) (TrkIn)"},
45     {"TRDresolution_TrkInQn4", "MPV(dQdl^{p-}) (TrkIn)"},
46     {"TRDresolution_TrkInQ0", "MPV(dQdl^{e}) (TrkIn)"},
47     {"TRDresolution_TrkInQ1", "MPV(dQdl^{#mu}) (TrkIn)"},
48     {"TRDresolution_TrkInQ2", "MPV(dQdl^{#pi}) (TrkIn)"},
49     {"TRDresolution_TrkInQ3", "MPV(dQdl^{K}) (TrkIn)"},
50     {"TRDresolution_TrkInQ4", "MPV(dQdl^{p}) (TrkIn)"},
51     {"TRDresolution_TrkInQSp0", "<dQdl^{e+}> (TrkIn)"},
52     {"TRDresolution_TrkInQSp1", "<dQdl^{#mu+}> (TrkIn)"},
53     {"TRDresolution_TrkInQSp2", "<dQdl^{pi+}> (TrkIn)"},
54     {"TRDresolution_TrkInQSp3", "<dQdl^{K+}> (TrkIn)"},
55     {"TRDresolution_TrkInQSp4", "<dQdl^{p+}> (TrkIn)"},
56     {"TRDresolution_TrkInQSn0", "<dQdl^{e-}> (TrkIn)"},
57     {"TRDresolution_TrkInQSn1", "<dQdl^{#mu-}> (TrkIn)"},
58     {"TRDresolution_TrkInQSn2", "<dQdl^{#pi-}> (TrkIn)"},
59     {"TRDresolution_TrkInQSn3", "<dQdl^{K-}> (TrkIn)"},
60     {"TRDresolution_TrkInQSn4", "<dQdl^{p-}> (TrkIn)"}
61   };
62   const char *resName[] = {"Markus Fasel", "Alexandru Bercuci"},
63              *resMail[] = {"M.Fasel@gsi.de", "A.Bercuci@gsi.de"};
64   const char *notName[] = {"Julian Book", "Hans Beck", "Ionut Arsene", "Raphaelle Bailache", "Christoph Blume"},
65              *notMail[] = {"jbook@ikf.uni-frankfurt.de", "hbeck@ikf.uni-frankfurt.de", "I.C.Arsene@gsi.de", "R.Bailhache@gsi.de", "blume@ikf.uni-frankfurt.de"};
66
67   TFile *fDB = TFile::Open("TRD.TrendDB.root", "RECREATE");
68   TTree *tDB = new TTree("trend", "Reference Trend Values");
69   Double_t val[nt];
70   for(Int_t it(0); it<nt; it++) tDB->Branch(tvn[it][0], &val[it], Form("%s/D", tvn[it][0]));
71   gROOT->cd();
72
73   AliTRDtrendValue *tv(NULL);
74   FILE *fp = fopen(fl, "rt");
75   TString sfp;
76   while(sfp.Gets(fp)){
77     if(!TFile::Open(sfp.Data())) continue;
78     for(Int_t it(0); it<nt; it++){
79       val[it] = -999;
80       if(!(tv = (AliTRDtrendValue*)gFile->Get(tvn[it][0]))) {
81         Warning("makeTrendingDB()", "Missing %s", tvn[it][0]);
82         continue;
83       }
84       val[it] = tv->GetVal();
85     }
86     gFile->Close();
87     tDB->Fill();
88   }
89
90
91 //   TFile *fDB = TFile::Open("TRD.TrendDB.root");
92 //   TTree *tDB = (TTree*)gFile->Get("trend");
93 //   Double_t val[nt];
94 //   for(Int_t it(0); it<nt; it++) tDB->SetBranchAddress(tvn[it][0], &val[it]);
95 //   gROOT->cd();
96
97   TString res[] = {Form("%s/%s", resName[0], resMail[0]), Form("%s/%s", resName[1], resMail[1])};
98   TString notifiable;
99   for(Int_t inot(0); inot<5; inot++){
100     notifiable+=notName[inot];
101     notifiable+="/";
102     notifiable+=notMail[inot];
103     if(inot<4) notifiable+=",";
104   }
105   TF1 f("f", "gaus", -100, 100);
106   AliTRDtrendingManager *tm = AliTRDtrendingManager::Instance();
107   TCanvas *c = new TCanvas("c", "Trend Distrib.", 10, 10, 500, 500);
108   Int_t ntr=tDB->GetEntries();
109   for(Int_t it(0); it<nt; it++){
110     tDB->Draw(tvn[it][0], "", "goff");
111     Double_t *v = tDB->GetV1(), xmin(100.), xmax(-100);
112     for(Int_t ir=0; ir<ntr; ir++){
113       if(v[ir]<-100) continue;
114       if(v[ir]<xmin) xmin = v[ir];
115       if(v[ir]>xmax) xmax = v[ir];
116     }
117     TH1 *h = new TH1F("h", Form(";%s;entries", tvn[it][0]), 10, 0.5*(3*xmin-xmax), 0.5*(3*xmax - xmin));
118     tDB->Draw(Form("%s>>h", tvn[it][0]), Form("%s>-100", tvn[it][0]));
119     if(h->Integral() < 1) continue;
120     f.SetParameter(0, h->Integral());
121     f.SetParameter(1, h->GetMean());
122     f.SetParameter(2, h->GetRMS());
123     h->Fit(&f, "WQ");
124     c->Modified(); c->Update(); c->SaveAs(Form("Fit_%s.gif", tvn[it][0]));
125
126     // write trending value to manager
127     Info("makeTrendingDB", "%s [%f - %f] %f[%f]", tvn[it][0], xmin, xmax, f.GetParameter(1), f.GetParameter(2));
128     tm->AddValue(tvn[it][0], f.GetParameter(1), f.GetParameter(2),
129       tvn[it][1], res[it>13], notifiable);
130     delete h;
131   }
132   tm->Terminate();
133
134   fDB->cd();
135   tDB->Write();
136   fDB->Close();
137 }