]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ZDC/AliZDCQADataMakerRec.cxx
Coverity + warning
[u/mrichter/AliRoot.git] / ZDC / AliZDCQADataMakerRec.cxx
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 ///////////////////////////////////////////////////////////////////////
17 //                                                                   //
18 //  Produces the data needed to calculate the ZDC quality assurance. //
19 //  QA objects are 1 & 2 Dimensional histograms.                     //
20 //  author: C. Oppedisano                                            //
21 //                                                                   //
22 ///////////////////////////////////////////////////////////////////////
23
24 // --- ROOT system ---
25 #include <TClonesArray.h>
26 #include <TFile.h> 
27 #include <TH1F.h> 
28 #include <TH2F.h>
29 #include <TLine.h>
30 #include <TProfile.h>
31 #include <Riostream.h>
32 // --- Standard library ---
33
34 // --- AliRoot header files ---
35 #include "AliLog.h"
36 #include "AliQAChecker.h"
37 #include "AliZDCReco.h"
38 #include "AliRawReader.h"
39 #include "AliZDCQADataMakerRec.h"
40 #include "AliZDCPedestals.h"
41 #include "AliZDCRawStream.h"
42 #include "AliZDCDigit.h"
43 #include "AliESDZDC.h"
44 #include "AliESDEvent.h"
45
46 ClassImp(AliZDCQADataMakerRec)
47            
48 //____________________________________________________________________________ 
49   AliZDCQADataMakerRec::AliZDCQADataMakerRec() : 
50   AliQADataMakerRec(AliQAv1::GetDetName(AliQAv1::kZDC), "ZDC Quality Assurance Data Maker"), 
51   fPedCalibData(0x0)
52 {
53   // ctor
54 }
55
56 //____________________________________________________________________________ 
57 AliZDCQADataMakerRec::AliZDCQADataMakerRec(const AliZDCQADataMakerRec& qadm) :
58   AliQADataMakerRec(),      
59   fPedCalibData(qadm.fPedCalibData)
60
61 {
62   //copy ctor 
63   SetName((const char*)qadm.GetName()); 
64   SetTitle((const char*)qadm.GetTitle()); 
65 }
66
67 //__________________________________________________________________
68 AliZDCQADataMakerRec& AliZDCQADataMakerRec::operator = (const AliZDCQADataMakerRec& qadm )
69 {
70   // Equal operator.
71   this->~AliZDCQADataMakerRec();
72   new(this) AliZDCQADataMakerRec(qadm);
73   return *this;
74 }
75
76 //____________________________________________________________________________ 
77 AliZDCQADataMakerRec::~AliZDCQADataMakerRec()
78 {
79   if(fPedCalibData && !(AliCDBManager::Instance()->GetCacheFlag())){
80     delete fPedCalibData;
81     fPedCalibData=0;
82   } 
83 }
84
85 //____________________________________________________________________________ 
86 AliZDCPedestals* AliZDCQADataMakerRec::GetPedCalibData() const
87 {
88
89   // Retrieving pedestal calibration object from OCDB
90   AliCDBEntry  *entry = AliCDBManager::Instance()->Get("ZDC/Calib/Pedestals");
91   if(!entry) AliWarning("No calibration data loaded!");  
92
93   AliZDCPedestals *calibdata = (AliZDCPedestals*)  (entry->GetObject());
94   if(!calibdata) AliFatal("Wrong calibration object in calibration  file!");
95
96   return calibdata;
97
98 }
99
100 //____________________________________________________________________________ 
101 void AliZDCQADataMakerRec::InitDigits()
102 {
103   // create Digits histograms in Digits subdir
104   //
105   const Bool_t expert   = kTRUE ; 
106   const Bool_t image    = kTRUE ; 
107   
108   // ------------------- HIGH GAIN CHAIN ---------------------------
109   TH1F * hDigZNCTot = new TH1F("hDigZNCTot", "Signal in ZNC;Amplitude [ADC counts];Counts", 100, 0., 6000.);
110   TH1F * hDigZNATot = new TH1F("hDigZNATot", "Signal in ZNA;Amplitude [ADC counts];Counts", 100, 0., 6000.);
111   TH1F * hDigZPCTot = new TH1F("hDigZPCTot", "Signal in ZPC;Amplitude [ADC counts];Counts", 100, 0., 6000.);
112   TH1F * hDigZPATot = new TH1F("hDigZPATot", "Signal in ZPA;Amplitude [ADC counts];Counts", 100, 0., 6000.);
113   Add2DigitsList(hDigZNCTot, 0, !expert, image);
114   Add2DigitsList(hDigZNATot, 1, !expert, image);
115   Add2DigitsList(hDigZPCTot, 2, !expert, image);
116   Add2DigitsList(hDigZPATot, 3, !expert, image);
117   //
118   TH1F * hDigSumQZNC = new TH1F("hDigSumQZNC", "Signal in 4 ZNC PMQ;Amplitude [ADC counts];Counts",100, 0., 4000.);
119   TH1F * hDigSumQZNA = new TH1F("hDigSumQZNA", "Signal in 4 ZNA PMQ;Amplitude [ADC counts];Counts",100, 0., 4000.);
120   TH1F * hDigSumQZPC = new TH1F("hDigSumQZPC", "Signal in 4 ZPC PMQ;Amplitude [ADC counts];Counts",100, 0., 4000.);
121   TH1F * hDigSumQZPA = new TH1F("hDigSumQZPA", "Signal in 4 ZPA PMQ;Amplitude [ADC counts];Counts",100, 0., 4000.);
122   Add2DigitsList(hDigSumQZNC, 4, expert, !image);
123   Add2DigitsList(hDigSumQZNA, 5, expert, !image);
124   Add2DigitsList(hDigSumQZPC, 6, expert, !image);
125   Add2DigitsList(hDigSumQZPA, 7, expert, !image);
126   //
127   TH1F * hDigPMCZNC = new TH1F("hDigPMCZNC", "Signal in ZNC PMC;Amplitude [ADC counts];Counts",100, 0., 4000.);
128   TH1F * hDigPMCZNA = new TH1F("hDigPMCZNA", "Signal in ZNA PMC;Amplitude [ADC counts];Counts",100, 0., 4000.);
129   TH1F * hDigPMCZPC = new TH1F("hDigPMCZPC", "Signal in ZPC PMC;Amplitude [ADC counts];Counts",100, 0., 4000.);
130   TH1F * hDigPMCZPA = new TH1F("hDigPMCZPA", "Signal in ZPA PMC;Amplitude [ADC counts];Counts",100, 0., 4000.);
131   Add2DigitsList(hDigPMCZNC, 8, expert, !image);
132   Add2DigitsList(hDigPMCZNA, 9, expert, !image);
133   Add2DigitsList(hDigPMCZPC, 10, expert, !image);
134   Add2DigitsList(hDigPMCZPA, 11, expert, !image);
135   // 
136   ClonePerTrigClass(AliQAv1::kDIGITS); // this should be the last line
137 }
138
139 //____________________________________________________________________________
140 void AliZDCQADataMakerRec::InitRaws()
141 {
142   // create Digits histograms in Digits subdir
143   const Bool_t expert   = kTRUE ; 
144   const Bool_t image    = kTRUE ; 
145
146   TH1F * hZNCSpectrum = new TH1F("hZNCSpectrum","ZNC spectrum;Amplitude [ADC counts];Counts",100,0.,1200.);
147   TH1F * hZPCSpectrum = new TH1F("hZPCSpectrum","ZPC spectrum;Amplitude [ADC counts];Counts",100,0.,1200.);
148   TH1F * hZNASpectrum = new TH1F("hZNASpectrum","ZNA spectrum;Amplitude [ADC counts];Counts",100,0.,1200.);
149   TH1F * hZPASpectrum = new TH1F("hZPASpectrum","ZPA spectrum;Amplitude [ADC counts];Counts",100,0.,1200.);
150   // Booking from ch. 8 for checked signals to avoid running QA on pedestals!
151   TH1F * hZEM1Spectrum = new TH1F("hZEM1Spectrum","ZEM1 spectrum;Amplitude [ADC counts];Counts",100,8., 1208.);
152   TH1F * hZEM2Spectrum = new TH1F("hZEM2Spectrum","ZEM2 spectrum;Amplitude [ADC counts];Counts",100,8., 1208.);
153   Add2RawsList(hZNCSpectrum, 0, expert, !image);
154   Add2RawsList(hZNASpectrum, 1, expert, !image);
155   Add2RawsList(hZPCSpectrum, 2, expert, !image);
156   Add2RawsList(hZPASpectrum, 3, expert, !image);
157   Add2RawsList(hZEM1Spectrum, 4, expert, !image);
158   Add2RawsList(hZEM2Spectrum, 5, expert, !image);
159     
160   TH1F * hRawPMCZNC = new TH1F("hRawPMCZNC", "Raw ZNC PMC;Amplitude [ADC counts];Counts",100, 8., 1208.);
161   TH1F * hRawPMCZNA = new TH1F("hRawPMCZNA", "Raw ZNA PMC;Amplitude [ADC counts];Counts",100, 8., 1208.);
162   TH1F * hRawPMCZPC = new TH1F("hRawPMCZPC", "Raw ZPC PMC;Amplitude [ADC counts];Counts",100, 8., 1208.);
163   TH1F * hRawPMCZPA = new TH1F("hRawPMCZPA", "Raw ZPA PMC;Amplitude [ADC counts];Counts",100, 8., 1208.);
164   Add2RawsList(hRawPMCZNC, 6, expert, !image);
165   Add2RawsList(hRawPMCZNA, 7, expert, !image);
166   Add2RawsList(hRawPMCZPC, 8, expert, !image);
167   Add2RawsList(hRawPMCZPA, 9, expert, !image);
168   TH1F * hRawSumQZNC = new TH1F("hRawSumQZNC", "Raw sumQ ZNC;Amplitude [ADC counts];Counts",100, 0., 1200.);
169   TH1F * hRawSumQZNA = new TH1F("hRawSumQZNA", "Raw sumQ ZNA;Amplitude [ADC counts];Counts",100, 0., 1200.);
170   TH1F * hRawSumQZPC = new TH1F("hRawSumQZPC", "Raw sumQ ZPC;Amplitude [ADC counts];Counts",100, 0., 1200.);
171   TH1F * hRawSumQZPA = new TH1F("hRawSumQZPA", "Raw sumQ ZPA;Amplitude [ADC counts];Counts",100, 0., 1200.);
172   Add2RawsList(hRawSumQZNC, 10, expert, !image);
173   Add2RawsList(hRawSumQZNA, 11, expert, !image);
174   Add2RawsList(hRawSumQZPC, 12, expert, !image);
175   Add2RawsList(hRawSumQZPA, 13, expert, !image);
176   
177   TH1F * hRawTDCZEM1 = new TH1F("hRawTDCZEM1", "TDC ZEM1;TDC [ns]",160, -350., -310.);
178   Add2RawsList(hRawTDCZEM1, 14, expert, !image);
179   TH1F * hRawTDCZPC = new TH1F("hRawTDCZPC", "TDC ZPC;TDC [ns]",160, -350., -310.);
180   Add2RawsList(hRawTDCZPC, 15, expert, !image);
181   
182   TProfile * hRawADCProfs = new TProfile("hRawADCProfs", "ADC profiles;ADC id;Mean ADC values",22,-0.5,21.5,10.,1210.,"");
183   Add2RawsList(hRawADCProfs, 16, expert, !image);
184   TProfile * hRawTDCProfs = new TProfile("hRawTDCProfs", "TDC profiles;TDC id;Mean TDC values",6,0.5,6.5,-340.,-300.,"S");
185   Add2RawsList(hRawTDCProfs, 17, expert, !image);
186   
187   TH1F * hRawADCs = new TH1F("hRawADCs", "ADCs;ADC id;Mean ADC values",22,-0.5,21.5);
188   Add2RawsList(hRawADCs, 18, !expert, image);
189  
190   TH1F * hRawTDCs = new TH1F("hRawTDCs", "TDCs;TDC id;Mean TDC values",6,0.5,6.5);
191 //  hRawTDCs->SetMaximum(-300); hRawTDCs->SetMinimum(-340);
192   Add2RawsList(hRawTDCs, 19, !expert, image);
193   
194   TH2F *hZNCrawCentr  = new TH2F("hZNCrawCentr", "ZNC centroid;X (cm);Y(cm)", 100,-3.5,3.5,100,-3.5,3.5);
195   Add2RawsList(hZNCrawCentr, 20, expert, image);
196   TH2F *hZNArawCentr  = new TH2F("hZNArawCentr", "ZNA centroid;X (cm);Y(cm)", 100,-3.5,3.5,100,-3.5,3.5);
197   Add2RawsList(hZNArawCentr, 21, expert, image);
198   
199   TH2F *hTimeZDC = new TH2F("hTimeZDC", "ZDC timing;Z_{vertex}/c (ns);time (ns)", 60,-30.,30.,120,-60,-60);
200   Add2RawsList(hTimeZDC, 22, !expert, image);
201   //
202   ClonePerTrigClass(AliQAv1::kRAWS); // this should be the last line
203 }
204
205 //____________________________________________________________________________
206 void AliZDCQADataMakerRec::InitRecPoints()
207 {
208   // create Digits histograms in Digits subdir
209   const Bool_t expert = kTRUE ; 
210   const Bool_t image  = kTRUE ; 
211   //
212   // ------------------- HIGH GAIN CHAIN ---------------------------
213   TH1F * hRecZNCTot = new TH1F("hRecZNCTot", "Rec signal in ZNC;Amplitude [ADC counts];Counts", 100, 0., 2000.);
214   TH1F * hRecZNATot = new TH1F("hRecZNATot", "Rec signal in ZNA;Amplitude [ADC counts];Counts", 100, 0., 2000.);
215   TH1F * hRecZPCTot = new TH1F("hRecZPCTot", "Rec signal in ZPC;Amplitude [ADC counts];Counts", 100, 0., 8000.);
216   TH1F * hRecZPATot = new TH1F("hRecZPATot", "Rec signal in ZPA;Amplitude [ADC counts];Counts", 100, 0., 8000.);
217   Add2RecPointsList(hRecZNCTot, 0, !expert, image);
218   Add2RecPointsList(hRecZNATot, 1, !expert, image);
219   Add2RecPointsList(hRecZPCTot, 2, !expert, image);
220   Add2RecPointsList(hRecZPATot, 3, !expert, image);
221   //
222   TH1F * hRecSumQZNC = new TH1F("hRecSumQZNC", "Rec summed 4 ZNC quadrants;Amplitude [ADC counts];Counts",100, 0., 2000.);
223   TH1F * hRecSumQZNA = new TH1F("hRecSumQZNA", "Rec summed 4 ZNA quadrants;Amplitude [ADC counts];Counts",100, 0., 2000.);
224   TH1F * hRecSumQZPC = new TH1F("hRecSumQZPC", "Rec summed 4 ZPC quadrants;Amplitude [ADC counts];Counts",100, 0., 2000.);
225   TH1F * hRecSumQZPA = new TH1F("hRecSumQZPA", "Rec summed 4 ZPA quadrants;Amplitude [ADC counts];Counts",100, 0., 2000.);
226   Add2RecPointsList(hRecSumQZNC, 4, expert, !image);
227   Add2RecPointsList(hRecSumQZNA, 5, expert, !image);
228   Add2RecPointsList(hRecSumQZPC, 6, expert, !image);
229   Add2RecPointsList(hRecSumQZPA, 7, expert, !image);
230   //
231   TH1F * hRecPMCZNC = new TH1F("hRecPMCZNC", "Rec common ZNC PMT;Amplitude [ADC counts];Counts",100, 0., 2000.);
232   TH1F * hRecPMCZNA = new TH1F("hRecPMCZNA", "Rec common ZNA PMT;Amplitude [ADC counts];Counts",100, 0., 2000.);
233   TH1F * hRecPMCZPC = new TH1F("hRecPMCZPC", "Rec common ZPC PMT;Amplitude [ADC counts];Counts",100, 0., 2000.);
234   TH1F * hRecPMCZPA = new TH1F("hRecPMCZPA", "Rec common ZPA PMT;Amplitude [ADC counts];Counts",100, 0., 2000.);
235   Add2RecPointsList(hRecPMCZNC, 8 , expert, !image);
236   Add2RecPointsList(hRecPMCZNA, 9 , expert, !image);
237   Add2RecPointsList(hRecPMCZPC, 10, expert, !image);
238   Add2RecPointsList(hRecPMCZPA, 11, expert, !image); 
239   //
240   ClonePerTrigClass(AliQAv1::kRECPOINTS); // this should be the last line
241 }
242
243 //____________________________________________________________________________
244 void AliZDCQADataMakerRec::InitESDs()
245 {
246   //Booking ESDs histograms
247   //
248   const Bool_t expert = kTRUE ; 
249   const Bool_t image  = kTRUE ; 
250   
251   // ------------------- HIGH GAIN CHAIN ---------------------------
252   TH1F * hESDZNCTot = new TH1F("hESDZNCTot", "Energy in ZNC", 100, 0., 4000.);
253   TH1F * hESDZNATot = new TH1F("hESDZNATot", "Energy in ZNA", 100, 0., 4000.);
254   TH1F * hESDZPCTot = new TH1F("hESDZPCTot", "Energy in ZPC", 100, 0., 4000.);
255   TH1F * hESDZPATot = new TH1F("hESDZPATot", "Energy in ZPA", 100, 0., 4000.);
256   Add2ESDsList(hESDZNCTot, 0, !expert, image);
257   Add2ESDsList(hESDZNATot, 1, !expert, image);
258   Add2ESDsList(hESDZPCTot, 2, !expert, image);
259   Add2ESDsList(hESDZPATot, 3, !expert, image);
260   //
261   TH1F * hESDZEM1 = new TH1F("hESDZEM1", "Energy in ZEM1", 100, 0., 2000.);
262   TH1F * hESDZEM2 = new TH1F("hESDZEM2", "Energy in ZEM2", 100, 0., 2000.);
263   Add2ESDsList(hESDZEM1,4, !expert, image);
264   Add2ESDsList(hESDZEM2,5, !expert, image);
265   //
266   TH1F * hESDSumQZNC = new TH1F("hESDSumQZNC", "Sum of 4 ZNC energy",100, 0., 2000.);
267   TH1F * hESDSumQZNA = new TH1F("hESDSumQZNA", "Sum of 4 ZNA energy",100, 0., 2000.);
268   TH1F * hESDSumQZPC = new TH1F("hESDSumQZPC", "Sum of 4 ZPC energy",100, 0., 2000.);
269   TH1F * hESDSumQZPA = new TH1F("hESDSumQZPA", "Sum of 4 ZPA energy",100, 0., 2000.);
270   Add2ESDsList(hESDSumQZNC, 6, expert, !image);
271   Add2ESDsList(hESDSumQZNA, 7, expert, !image);
272   Add2ESDsList(hESDSumQZPC, 8, expert, !image);
273   Add2ESDsList(hESDSumQZPA, 9, expert, !image);
274   //
275   TH1F * hESDPMCZNC = new TH1F("hESDPMCZNC", "Energy in ZNC PMC",100, 0., 2000.);
276   TH1F * hESDPMCZNA = new TH1F("hESDPMCZNA", "Energy in ZNA PMC",100, 0., 2000.);
277   TH1F * hESDPMCZPC = new TH1F("hESDPMCZPC", "Energy in ZPC PMC",100, 0., 2000.);
278   TH1F * hESDPMCZPA = new TH1F("hESDPMCZPA", "Energy in ZPA PMC",100, 0., 2000.);
279   Add2ESDsList(hESDPMCZNC, 10, expert, !image);
280   Add2ESDsList(hESDPMCZNA, 11, expert, !image);
281   Add2ESDsList(hESDPMCZPC, 12, expert, !image);
282   Add2ESDsList(hESDPMCZPA, 13, expert, !image);
283   // 
284   ClonePerTrigClass(AliQAv1::kESDS); // this should be the last line
285 }
286
287 //___________________________________________________________________________
288 void AliZDCQADataMakerRec::MakeDigits(TTree *digitTree)
289 {
290   // makes data from Digit Tree
291   if(!GetDigitsData(0)) InitDigits();
292
293   if(!digitTree){
294     AliError("Can't get ZDC digit tree!!");
295     return; 
296   }     
297    
298   TBranch * branch = digitTree->GetBranch("ZDC");
299   if(!branch){
300     AliError("ZDC branch in digit tree not found"); 
301     return;
302   } 
303     
304   AliZDCDigit *digit = 0x0;
305   branch->SetAddress(&digit);
306      
307   Float_t adcSum_ZNC=0., adcSum_ZNA=0., adcSum_ZPC=0., adcSum_ZPA=0.;
308   Float_t adcSumQ_ZNC=0., adcSumQ_ZNA=0., adcSumQ_ZPC=0., adcSumQ_ZPA=0.;
309   //Float_t adcSum_ZNC_lg=0., adcSum_ZNA_lg=0., adcSum_ZPC_lg=0., adcSum_ZPA_lg=0.;
310   //Float_t adcSumQ_ZNC_lg=0., adcSumQ_ZNA_lg=0., adcSumQ_ZPC_lg=0., adcSumQ_ZPA_lg=0.;
311   
312   Int_t ndig = digitTree->GetEntries();
313   for(Int_t i=0; i<ndig; i++){
314       branch->GetEntry(i);
315       
316       if(digit->GetSector(0)==1 && digit->GetSector(1)!=5){
317           adcSum_ZNC += digit->GetADCValue(0);
318           //adcSum_ZNC_lg += digit->GetADCValue(1);
319           //
320           if(digit->GetSector(1)!=0){
321               adcSumQ_ZNC += digit->GetADCValue(0);
322               //adcSumQ_ZNC_lg+= digit->GetADCValue(1);
323           }
324           else{
325               FillDigitsData(8,digit->GetADCValue(0));
326               //FillDigitsData(20,digit->GetADCValue(1));
327           }
328       }
329       else if(digit->GetSector(0)==2){
330           adcSum_ZPC += digit->GetADCValue(0);
331           //adcSum_ZPC_lg += digit->GetADCValue(1);
332           //
333           if(digit->GetSector(1)!=0){
334               adcSumQ_ZPC += digit->GetADCValue(0);
335               //adcSumQ_ZPC_lg+= digit->GetADCValue(1);
336           }
337           else{
338               FillDigitsData(10,digit->GetADCValue(0));
339               //FillDigitsData(22,digit->GetADCValue(1));
340           }
341       }
342       else if(digit->GetSector(0)==4 && digit->GetSector(1)!=5){
343           adcSum_ZNA += digit->GetADCValue(0);
344           //adcSum_ZNA_lg += digit->GetADCValue(1);
345           //
346           if(digit->GetSector(1)!=0){
347               adcSumQ_ZNA += digit->GetADCValue(0);
348               //adcSumQ_ZNA_lg+= digit->GetADCValue(1);
349           }
350           else{
351               FillDigitsData(9,digit->GetADCValue(0));
352               //FillDigitsData(21,digit->GetADCValue(1));
353           }
354       }
355       else if(digit->GetSector(0)==5){
356           adcSum_ZPA += digit->GetADCValue(0);
357           //adcSum_ZPA_lg += digit->GetADCValue(1);
358           //
359           if(digit->GetSector(1)!=0){
360               adcSumQ_ZPA += digit->GetADCValue(0);
361               //adcSumQ_ZPA_lg+= digit->GetADCValue(1);
362           }
363           else{
364               FillDigitsData(11,digit->GetADCValue(0));
365               //FillDigitsData(23,digit->GetADCValue(1));
366           }
367       }
368   }
369   //
370   FillDigitsData(0,adcSum_ZNC);
371   FillDigitsData(1,adcSum_ZNA);
372   FillDigitsData(2,adcSum_ZPC);
373   FillDigitsData(3,adcSum_ZPA);
374   //
375   FillDigitsData(4,adcSumQ_ZNC);
376   FillDigitsData(5,adcSumQ_ZNA);
377   FillDigitsData(6,adcSumQ_ZPC);
378   FillDigitsData(7,adcSumQ_ZPA);
379   
380   delete digit;
381   digit=0;
382   //
383   IncEvCountCycleDigits();
384   IncEvCountTotalDigits();
385   //
386 }
387
388
389 //____________________________________________________________________________
390 void AliZDCQADataMakerRec::MakeRaws(AliRawReader *rawReader)
391 {
392   // Filling Raws QA histos
393   //
394   // Checking the event type 
395 //  if (rawReader->GetType()!=7){
396   
397     // Check if histograms already created for this Event Specie
398     if(!GetRawsData(0)) InitRaws();
399     // Parameters for mean value pedestal subtraction
400     int const kNch = 24;
401     Float_t meanPed[2*kNch];    
402     for(Int_t jj=0; jj<2*kNch; jj++) meanPed[jj] = fPedCalibData->GetMeanPed(jj);
403     
404     Float_t zncSignal=0., znaSignal=0., zpcSignal=0., zpaSignal=0.;
405     Float_t zncSumQ=0., znaSumQ=0., zpcSumQ=0., zpaSumQ=0.;
406     Float_t zncpmC=0., znapmC=0., zpcpmC=0., zpapmC=0.;
407     Bool_t isZNCFired=kFALSE, isZPCFired=kFALSE, isZNAFired=kFALSE, isZPAFired=kFALSE;
408     Int_t  indZNC=0, indZNA=0, indZPC=0, indZPA=0;
409     Float_t zncTDC[10], zpcTDC[10], zem1TDC[10], zem2TDC[10], znaTDC[10], zpaTDC[10];
410     Float_t zncSumTDC[10], znaSumTDC[10];
411     for(Int_t i=0; i<10; i++){
412        zncTDC[i]=zpcTDC[i]=zem1TDC[i]=zem2TDC[i]=znaTDC[i]=zpaTDC[i]=zncSumTDC[i]=znaSumTDC[i]=-999.;
413     }
414     Float_t tdcGate=-999., l0=-999.;
415     Int_t iMultZNCTDC=0, iMultZPCTDC=0, iMultZEM1TDC=0, iMultZEM2TDC=0, iMultZNATDC=0, iMultZPATDC=0;
416     Int_t iMultTDCC=0, iMultTDCA=0;
417     
418     const Float_t x[4] = {-1.75, 1.75, -1.75, 1.75};
419     const Float_t y[4] = {-1.75, -1.75, 1.75, 1.75};
420     const Float_t alpha=0.5;
421     Float_t numXZNC=0., numYZNC=0., denZNC=0., wZNC=0.; 
422     Float_t numXZNA=0., numYZNA=0., denZNA=0., wZNA=0.; 
423     
424     rawReader->Reset();
425     AliZDCRawStream stream(rawReader);
426     while(stream.Next()){
427
428       if(stream.IsADCDataWord() && 
429          (stream.GetADCModule()==0 || stream.GetADCModule()==1)){
430        
431          Int_t det = stream.GetSector(0);
432          Int_t quad = stream.GetSector(1);
433          Int_t gain = stream.GetADCGain();
434          Int_t pedindex=0;
435          
436          // Stuff for pedestal subtraction
437          if(quad != 5){ // ZDCs (not reference PTMs)
438           Float_t rawVal=-99., pedSubVal=-99.;
439           if(det == 1){    
440             pedindex = quad;
441             if(gain == 0){
442               rawVal = (Float_t) (stream.GetADCValue());
443               pedSubVal = (Float_t) (rawVal-meanPed[pedindex]); 
444               zncSignal  += pedSubVal; 
445               isZNCFired = kTRUE;
446               if(quad!=0){
447                 zncSumQ += pedSubVal;
448                 if(pedSubVal>0.&& zncpmC>7.){
449                   wZNC = TMath::Power(pedSubVal, alpha);
450                   numXZNC += x[quad-1]*wZNC;
451                   numYZNC += y[quad-1]*wZNC;
452                   denZNC += wZNC;
453                 }
454               }
455               else{
456                 zncpmC = pedSubVal;
457                 FillRawsData(6,zncpmC);
458               }
459               indZNC++;
460               
461               FillRawsData(16, pedindex, pedSubVal);
462             }
463           }
464           else if(det == 2){ 
465             pedindex = quad+5;
466             if(gain == 0){
467               rawVal = (Float_t) (stream.GetADCValue());
468               pedSubVal = (Float_t) (rawVal-meanPed[pedindex]); 
469               zpcSignal += pedSubVal; 
470               isZPCFired = kTRUE;
471               if(quad!=0) zpcSumQ += pedSubVal;
472               else{
473                 zpcpmC = pedSubVal;
474                 FillRawsData(8,zpcpmC);
475               }
476               indZPC++;
477               
478               FillRawsData(16, pedindex, pedSubVal);
479             }
480           }
481           else if(det == 3){ 
482             pedindex = quad+9;
483             if(quad==1){     
484               if(gain == 0){
485                 rawVal = (Float_t) (stream.GetADCValue());
486                 pedSubVal = (Float_t) (rawVal-meanPed[pedindex]); 
487                 FillRawsData(4,pedSubVal);
488                 FillRawsData(16,pedindex, pedSubVal);
489               }
490             }
491             else if(quad==2){ 
492               if(gain == 0){
493                 rawVal = (Float_t) (stream.GetADCValue());
494                 pedSubVal = (Float_t) (rawVal-meanPed[pedindex]); 
495                 FillRawsData(5,pedSubVal); 
496                 FillRawsData(16,pedindex, pedSubVal);
497               }
498             }
499           }
500           else if(det == 4){       
501             pedindex = quad+12;
502             if(gain == 0){
503               rawVal = (Float_t) (stream.GetADCValue());
504               pedSubVal = (Float_t) (rawVal-meanPed[pedindex]); 
505               znaSignal  += pedSubVal; 
506               isZNAFired = kTRUE;
507               if(quad!=0){
508                 znaSumQ += pedSubVal;
509                 if(pedSubVal>0.&& znapmC>7.) {
510                   wZNA = TMath::Power(pedSubVal, alpha);
511                   numXZNA += x[quad-1]*wZNA;
512                   numYZNA += y[quad-1]*wZNA;
513                   denZNA += wZNA;
514                 }
515               }
516               else{
517                 znapmC = pedSubVal;
518                 FillRawsData(7,znapmC);
519               }
520               indZNA++;
521               
522               FillRawsData(16,pedindex, pedSubVal);
523             }
524           }
525           else if(det == 5){
526             pedindex = quad+17;
527             if(gain == 0){
528               rawVal = (Float_t) (stream.GetADCValue());
529               pedSubVal = (Float_t) (rawVal-meanPed[pedindex]); 
530               zpaSignal  += pedSubVal; 
531               isZPAFired = kTRUE;
532               if(quad!=0) zpaSumQ += pedSubVal;
533               else{
534                 zpapmC = pedSubVal;
535                 FillRawsData(9,zpapmC);
536               }
537               indZPA++;
538               
539               FillRawsData(16,pedindex, pedSubVal);
540             }
541           }
542                          
543          }
544
545          if(isZNCFired && indZNC==5){
546            FillRawsData(0,zncSignal);
547            FillRawsData(10,zncSumQ); 
548            //
549            Float_t xZNC, yZNC;           
550            if(denZNC!=0){
551              xZNC = numXZNC/denZNC;
552              yZNC = numYZNC/denZNC;
553            } 
554            else xZNC = yZNC = 999.;
555            FillRawsData(20,xZNC, yZNC);
556          }
557          if(isZPCFired && indZPC==5){
558            FillRawsData(2,zpcSignal);
559            FillRawsData(12,zpcSumQ); 
560          }
561          if(isZNAFired && indZNA==5){ 
562            FillRawsData(1,znaSignal);
563            FillRawsData(11,znaSumQ); 
564            //
565            Float_t xZNA, yZNA;
566            if(denZNA!=0){
567              xZNA = numXZNA/denZNA;
568              yZNA = numYZNA/denZNA;
569            } 
570            else xZNA = yZNA = 999.;
571            FillRawsData(21,xZNA, yZNA);
572          }
573          if(isZPAFired && indZPA==5){ 
574            FillRawsData(3,zpaSignal);
575            FillRawsData(13,zpaSumQ); 
576          }
577          
578          if(indZNC==5){
579            zncSignal = zncSumQ = zncpmC = 0;
580            isZNCFired=kFALSE; indZNC=0;
581          }
582          if(indZPC==5){
583            zpcSignal = zpcSumQ = zpcpmC = 0;
584            isZPCFired=kFALSE; indZPC=0;
585          }
586          if(indZNA==5){
587            znaSignal = znaSumQ = znapmC = 0;
588            isZNAFired=kFALSE; indZNA=0;
589          }
590          if(indZPA==5){
591            zpaSignal = zpaSumQ = zpapmC = 0;
592            isZPAFired=kFALSE; indZPA=0;
593          }
594          
595       } //IsADCDataWord && signal ADCs
596       else if(stream.IsZDCTDCDatum()){
597          if(stream.GetChannel()==1){
598             zncTDC[iMultZNCTDC] = (0.025*stream.GetZDCTDCDatum());
599             iMultZNCTDC++;
600          }
601          else if(stream.GetChannel()==3){
602             zpcTDC[iMultZPCTDC] = (0.025*stream.GetZDCTDCDatum());
603             iMultZPCTDC++;
604          }
605          else if(stream.GetChannel()==5){
606             znaTDC[iMultZNATDC] = (0.025*stream.GetZDCTDCDatum());
607             iMultZNATDC++;
608          }
609          else if(stream.GetChannel()==7){
610             zpaTDC[iMultZPATDC] = (0.025*stream.GetZDCTDCDatum());
611             iMultZPATDC++;
612          }
613          else if(stream.GetChannel()==8){
614             zem1TDC[iMultZEM1TDC] = (0.025*stream.GetZDCTDCDatum());
615             iMultZEM1TDC++;
616          }
617          else if(stream.GetChannel()==9){
618             zem2TDC[iMultZEM2TDC] = (0.025*stream.GetZDCTDCDatum());
619             iMultZEM2TDC++;
620          }
621          else if(stream.GetChannel()==10){
622             zncSumTDC[iMultTDCC] = (0.025*stream.GetZDCTDCDatum());
623             iMultTDCC++;
624          }
625          else if(stream.GetChannel()==12){
626             znaSumTDC[iMultTDCA] = (0.025*stream.GetZDCTDCDatum());
627             iMultTDCA++;
628          }
629          else if(stream.GetChannel()==14) tdcGate = (0.025*stream.GetZDCTDCDatum());
630          else if(stream.GetChannel()==15) l0 = (0.025*stream.GetZDCTDCDatum());
631          
632          if(stream.GetChannel()==16 && tdcGate!=-999.){
633            for(Int_t iHit=0; iHit<10; iHit++){
634               if(zncTDC[iHit]!=-999.){
635                 if(zncTDC[iHit]-tdcGate>-340. && zncTDC[iHit]-tdcGate<-300.) 
636                    FillRawsData(17,1, zncTDC[iHit]-tdcGate);
637               }
638               if(zpcTDC[iHit]!=-999.){
639                 Float_t diffZPC = zpcTDC[iHit]-tdcGate;
640                 FillRawsData(15,diffZPC);
641                 if(diffZPC>-340. && diffZPC<-300.) FillRawsData(17,2, diffZPC);
642               }
643               if(znaTDC[iHit]!=-999.){
644                 if(znaTDC[iHit]-tdcGate>-340. && znaTDC[iHit]-tdcGate<-300.) 
645                   FillRawsData(17,3, znaTDC[iHit]-tdcGate);
646               }
647               if(zpaTDC[iHit]!=-999.){
648                 if(zpaTDC[iHit]-tdcGate>-340. && zpaTDC[iHit]-tdcGate<-300.) 
649                   FillRawsData(17,4, zpaTDC[iHit]-tdcGate);
650               }
651               if(zem1TDC[iHit]!=-999.){
652                 Float_t diffZEM1 = zem1TDC[iHit]-tdcGate;
653                 FillRawsData(14,diffZEM1);
654                 if(diffZEM1>-340. && diffZEM1<-300.) FillRawsData(17,5, diffZEM1);
655               }
656               if(zem2TDC[iHit]!=-999.){
657                 if(zem2TDC[iHit]-tdcGate>-340. && zem2TDC[iHit]-tdcGate<-300.) 
658                   FillRawsData(17,6, zem2TDC[iHit]-tdcGate);
659               }
660               if(zncSumTDC[iHit]!=-999.){
661                  Float_t tdcC = zncSumTDC[iHit]-l0;
662                  if(znaSumTDC[iHit]!=-999.){
663                     Float_t tdcA = znaSumTDC[iHit]-l0;
664                     //if (((tdcC-tdcA-refDelta)*(tdcC-tdcA-refDelta)/(sigmaDelta*sigmaDelta) +
665                         //(tdcC+tdcA-refSum)*(tdcC+tdcA-refSum)/(sigmaSum*sigmaSum))< 1.0)
666                         FillRawsData(22,tdcC-tdcA,tdcC+tdcA);
667                     
668                  }
669               }
670            }
671            //
672            tdcGate = -999.;
673            for(Int_t i=0; i<10; i++){
674               zncTDC[i] = zpcTDC[i] = zem1TDC[i] = zem2TDC[i] = znaTDC[i] = zpaTDC[i] = -999.;
675               zncSumTDC[i] = znaSumTDC[i] = -999.;
676            } 
677          }
678       }
679     
680     } //stream.Next()
681 //  } // check on event type
682 //  else{
683 //    AliDebug(1,Form("Skipping non-physics event for QA -> event type %d \n", rawReader->GetType())); 
684 //  }
685 //
686     IncEvCountCycleRaws();
687     IncEvCountTotalRaws();
688     //
689 }
690
691 //____________________________________________________________________________
692 void AliZDCQADataMakerRec::MakeRecPoints(TTree * clustersTree)
693 {
694   // Filling QA histos from RecPoints
695
696   TBranch *branch = clustersTree->GetBranch("ZDC");
697   if(!branch){ 
698     AliError("Can't get the ZDC branch for rec points!");
699     return;
700   }
701   
702   if(!GetRecPointsData(0)) InitRecPoints() ;
703
704   Float_t sum_ZNC=0., sum_ZNA=0., sum_ZPC=0., sum_ZPA=0.;
705   Float_t sumQ_ZNC=0., sumQ_ZNA=0., sumQ_ZPC=0., sumQ_ZPA=0.;
706
707   AliZDCReco reco;
708   AliZDCReco* preco = &reco;
709   clustersTree->SetBranchAddress("ZDC", &preco);
710
711   clustersTree->GetEntry(0);
712   for(Int_t i=0; i<5; i++){
713     sum_ZNC += reco.GetZN1HREnTow(i);
714     sum_ZPC += reco.GetZN2HREnTow(i);
715     sum_ZNA += reco.GetZP1HREnTow(i);
716     sum_ZPA += reco.GetZP2HREnTow(i);
717     if(i==0){
718       FillRecPointsData(8,reco.GetZN1HREnTow(i));
719       FillRecPointsData(9,reco.GetZN2HREnTow(i));
720       FillRecPointsData(10,reco.GetZP1HREnTow(i));
721       FillRecPointsData(11,reco.GetZP2HREnTow(i));
722     }
723     else{
724       sumQ_ZNC += reco.GetZN1HREnTow(i);
725       sumQ_ZPC += reco.GetZN2HREnTow(i);
726       sumQ_ZNA += reco.GetZP1HREnTow(i);
727       sumQ_ZPA += reco.GetZP2HREnTow(i);
728     }
729   }
730   
731   FillRecPointsData(0,sum_ZNC);
732   FillRecPointsData(1,sum_ZNA);
733   FillRecPointsData(2,sum_ZPC);
734   FillRecPointsData(3,sum_ZPA);
735   //
736   FillRecPointsData(4,sumQ_ZNC);
737   FillRecPointsData(5,sumQ_ZNA);
738   FillRecPointsData(6,sumQ_ZPC);
739   FillRecPointsData(7,sumQ_ZPA);
740   //
741   IncEvCountCycleRecPoints();
742   IncEvCountTotalRecPoints();
743   //  
744 }  
745
746 //____________________________________________________________________________
747 void AliZDCQADataMakerRec::MakeESDs(AliESDEvent * esd)
748 {
749   // make QA data from ESDs
750   //
751   
752   // Check id histograms already created for this Event Specie
753   if(!GetESDsData(0)) InitESDs() ;
754
755   AliESDZDC * zdcESD =  esd->GetESDZDC();
756   //
757   /*TString beamType = esd->GetBeamType();
758   Double_t centr_ZNC[2]={999.,999}, centr_ZNA[2]={999.,999};
759   if(((beamType.CompareTo("pp"))==0) || ((beamType.CompareTo("p-p"))==0)
760      ||((beamType.CompareTo("PP"))==0) || ((beamType.CompareTo("P-P"))==0)){
761     zdcESD->GetZNCentroidInpp(centr_ZNC, centr_ZNA);
762   }
763   else if((beamType.CompareTo("A-A")) == 0 || (beamType.CompareTo("Pb-Pb")) == 0){
764     Float_t beamEne = esd->GetBeamEnergy();
765     zdcESD->GetZNCentroidInPbPb(beamEne, centr_ZNC, centr_ZNA);
766   }
767   else printf("\n WARNING!!! AliZDCQADataMakerRec::MakeESDs: can't calculate centroids for beam type: %s\n\n",beamType.Data());
768   FillESDsData(0,centr_ZNC[0], centr_ZNC[1]);
769   FillESDsData(1,centr_ZNA[0], centr_ZNA[1]);*/
770
771   FillESDsData(0,esd->GetZDCN1Energy());
772   FillESDsData(1,esd->GetZDCN2Energy());
773   FillESDsData(2,esd->GetZDCP1Energy());
774   FillESDsData(3,esd->GetZDCP2Energy());
775   FillESDsData(4,esd->GetZDCEMEnergy(0));
776   FillESDsData(5,esd->GetZDCEMEnergy(1));
777   //
778   Double_t sumQZNC=0., sumQZPC=0., sumQZNA=0., sumQZPA=0.;
779   //Double_t sumQZNC_lg=0., sumQZPC_lg=0., sumQZNA_lg=0., sumQZPA_lg=0.;
780   //
781   const Double_t *towZNC, *towZPC, *towZNA, *towZPA;
782   //const Double_t *towZNC_lg, *towZPC_lg, *towZNA_lg, *towZPA_lg;
783   //
784   towZNC = zdcESD->GetZN1TowerEnergy();
785   towZPC = zdcESD->GetZP1TowerEnergy();
786   towZNA = zdcESD->GetZN2TowerEnergy();
787   towZPA = zdcESD->GetZP2TowerEnergy();
788   //
789   /*towZNC_lg = zdcESD->GetZN1TowerEnergyLR();
790   towZPC_lg = zdcESD->GetZP1TowerEnergyLR();
791   towZNA_lg = zdcESD->GetZN2TowerEnergyLR();
792   towZPA_lg = zdcESD->GetZP2TowerEnergyLR();*/
793   //
794   for(Int_t i=0; i<5; i++){
795      if(i==0){
796        FillESDsData(10,towZNC[i]);
797        FillESDsData(11,towZNA[i]);
798        FillESDsData(12,towZPC[i]);
799        FillESDsData(13,towZPA[i]);
800      }
801      else{
802        sumQZNC += towZNC[i];
803        sumQZPC += towZPC[i];
804        sumQZNA += towZNA[i];
805        sumQZPA += towZPA[i];
806      }
807   }
808   FillESDsData(6,sumQZNC);
809   FillESDsData(7,sumQZNA);
810   FillESDsData(8,sumQZPC);
811   FillESDsData(9,sumQZPA);
812   //
813   IncEvCountCycleESDs();
814   IncEvCountTotalESDs();
815   //
816 }
817
818 //____________________________________________________________________________
819 void AliZDCQADataMakerRec::StartOfDetectorCycle()
820 {
821   //Detector specific actions at start of cycle
822
823   fPedCalibData = GetPedCalibData();
824   
825 }
826
827 //____________________________________________________________________________ 
828 void AliZDCQADataMakerRec::EndOfDetectorCycle(AliQAv1::TASKINDEX_t task, TObjArray ** list)
829 {
830   //Detector specific actions at end of cycle
831   // do the QA checking
832   //
833   ResetEventTrigClasses();
834   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {  // RS: loop over event types
835     //
836     if (!IsValidEventSpecie(specie, list)) continue;
837     SetEventSpecie(AliRecoParam::ConvertIndex(specie));
838     //
839     for (int itc=-1;itc<GetNTrigClasses();itc++) { // RS: loop over eventual clones per trigger class
840       //
841       if( task == AliQAv1::kRAWS) {
842         TProfile* h16 = dynamic_cast<TProfile*> (GetRawsData(16, itc));
843         TProfile* h17 =  dynamic_cast<TProfile*> (GetRawsData(17, itc));
844         TH1F* h18 =  dynamic_cast<TH1F*> (GetRawsData(18, itc));
845         TH1F* h19 =  dynamic_cast<TH1F*> (GetRawsData(19, itc));
846         TH2F* h20 =  dynamic_cast<TH2F*> (GetRawsData(20, itc));
847         TH2F* h21 =  dynamic_cast<TH2F*> (GetRawsData(21, itc));
848         TH2F* h22 =  dynamic_cast<TH2F*> (GetRawsData(22, itc));
849         if (!h16 || !h17 || !h18 || !h19){
850          AliWarning("AliZDCQADataMakerRec -> RAW histos 16||17||18||19 not found!"); 
851          AliWarning(Form("for specie %s and trigger class %s",
852                          AliRecoParam::GetEventSpecieName(specie), AliQADataMaker::GetTrigClassName(itc)));
853         }
854         else{
855           //h16->Draw("");
856           for(Int_t ibin=1; ibin<=h16->GetNbinsX(); ibin++){
857             h18->SetBinContent(ibin, h16->GetBinContent(ibin)); 
858             h18->SetBinError(ibin, h16->GetBinError(ibin));
859           }
860           for(Int_t ibin=1; ibin<=h17->GetNbinsX(); ibin++){
861             h19->SetBinContent(ibin, h17->GetBinContent(ibin)); 
862             h19->SetBinError(ibin, h17->GetBinError(ibin));
863           }
864           h18->SetLineColor(kBlue); h18->SetLineWidth(2);
865           h19->SetLineColor(kAzure-3); h19->SetLineWidth(2);
866         }
867         if(!h20 || !h21){
868          AliWarning("AliZDCQADataMakerRec -> RAW histos 20||21 not found!"); 
869          AliWarning(Form("for specie %s and trigger class %s",
870                          AliRecoParam::GetEventSpecieName(specie), AliQADataMaker::GetTrigClassName(itc)));
871         }
872         else{
873          h20->SetMarkerColor(kPink+7); 
874          h21->SetMarkerColor(kBlue+2);
875         }
876         if(!h22) {
877          AliWarning("AliZDCQADataMakerRec -> RAW histo 22 not found!"); 
878          AliWarning(Form("for specie %s and trigger class %s",
879                          AliRecoParam::GetEventSpecieName(specie), AliQADataMaker::GetTrigClassName(itc)));
880         }
881         else h22->SetMarkerColor(kAzure+7);
882       }
883     } // loop over t
884   } //  loop over species
885         
886   AliQAChecker::Instance()->Run(AliQAv1::kZDC, task, list) ;  
887 }