]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALQADataMakerRec.cxx
de7598e55e15c22f1bff0c8ad15749167d6c806c
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALQADataMakerRec.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 Based on the QA code for PHOS written by Yves Schutz July 2007
17
18 Authors:  J.Klay (Cal Poly) May 2008
19           S. Salur LBL April 2008
20  
21 Created one histogram for QA shifter;-- Yaxian Mao: 11/2009
22 The idea:average counts for all the towers should be flat 
23 Change all existing histograms as experts
24
25 Change histograms for DQM shifter: --  Yaxian Mao 04/2010
26 Calcuate the amplitude ratio from current run and the LED reference, for QAChecker use
27 Also calculate the ratio of amplitude from LED Monitor system (current/Reference), to check LED system  
28  
29 */
30
31 // --- ROOT system ---
32 #include <TClonesArray.h>
33 #include <TFile.h> 
34 #include <TH1F.h> 
35 #include <TH1I.h> 
36 #include <TH2F.h> 
37 #include <TLine.h>
38 #include <TText.h>
39 #include <TProfile.h> 
40 #include <TProfile2D.h> 
41 #include <TStyle.h>
42 // --- Standard library ---
43
44
45 // --- AliRoot header files ---
46 #include "AliDAQ.h"
47 #include "AliESDCaloCluster.h"
48 #include "AliESDCaloCells.h"
49 #include "AliESDEvent.h"
50 #include "AliLog.h"
51 #include "AliEMCALQADataMakerRec.h"
52 #include "AliQAChecker.h"
53 #include "AliEMCALDigit.h" 
54 #include "AliEMCALRecPoint.h" 
55 #include "AliEMCALRawUtils.h"
56 #include "AliEMCALReconstructor.h"
57 #include "AliEMCALRecParam.h"
58 #include "AliRawReader.h"
59 #include "AliCaloRawStreamV3.h"
60 #include "AliEMCALGeoParams.h"
61 #include "AliRawEventHeaderBase.h"
62 #include "AliQAManager.h"
63 #include "AliCDBEntry.h"
64
65 #include "AliCaloBunchInfo.h"
66 #include "AliCaloFitResults.h"
67 #include "AliCaloRawAnalyzerFastFit.h"
68 #include "AliCaloRawAnalyzerNN.h"
69 #include "AliCaloRawAnalyzerKStandard.h"
70 #include "AliCaloRawAnalyzerPeakFinder.h"
71 #include "AliCaloRawAnalyzerCrude.h"
72 #include "AliEMCALGeometry.h"
73 #include "AliEMCALTriggerSTURawStream.h"
74
75 #include "AliCaloRawAnalyzerFactory.h"
76
77 using namespace std;
78
79 ClassImp(AliEMCALQADataMakerRec)
80            
81 //____________________________________________________________________________ 
82 AliEMCALQADataMakerRec::AliEMCALQADataMakerRec(Int_t fitAlgo) :
83   AliQADataMakerRec(AliQAv1::GetDetName(AliQAv1::kEMCAL), "EMCAL Quality Assurance Data Maker"),
84   fFittingAlgorithm(0),
85   fRawAnalyzer(0),
86   fRawAnalyzerTRU(0),
87   fGeom(0),
88   fSuperModules(20), // number of SuperModules; updated to 20 for EMCal + DCal 
89   fFirstPedestalSample(0),
90   fLastPedestalSample(3),
91   fFirstPedestalSampleTRU(0),
92   fLastPedestalSampleTRU(3),
93   fMinSignalLG(0),
94   fMaxSignalLG(AliEMCALGeoParams::fgkSampleMax),
95   fMinSignalHG(0),
96   fMaxSignalHG(AliEMCALGeoParams::fgkSampleMax),
97   fMinSignalTRU(0),
98   fMaxSignalTRU(AliEMCALGeoParams::fgkSampleMax),
99   fMinSignalLGLEDMon(0),
100   fMaxSignalLGLEDMon(AliEMCALGeoParams::fgkSampleMax),
101   fMinSignalHGLEDMon(0),
102   fMaxSignalHGLEDMon(AliEMCALGeoParams::fgkSampleMax),
103   fCalibRefHistoPro(NULL),
104   fCalibRefHistoH2F(NULL),
105   fLEDMonRefHistoPro(NULL),
106   fHighEmcHistoH2F(NULL)
107 //  fTextSM(new TText*[fSuperModules]) ,
108 //  fLineCol(NULL),
109 //  fLineRow(NULL)
110
111 {
112   // ctor
113   SetFittingAlgorithm(fitAlgo);
114
115   fGeom = new AliEMCALGeometry("EMCAL_COMPLETE12SMV1_DCAL_8SM", "EMCAL");
116 //  for (Int_t sm = 0 ; sm < fSuperModules ; sm++){
117 //    fTextSM[sm] = NULL ;
118 //  }
119 }
120
121 //____________________________________________________________________________ 
122 AliEMCALQADataMakerRec::AliEMCALQADataMakerRec(const AliEMCALQADataMakerRec& qadm) :
123   AliQADataMakerRec(), 
124   fFittingAlgorithm(0),
125   fRawAnalyzer(0),
126   fRawAnalyzerTRU(0),
127         fGeom(0),
128   fSuperModules(qadm.GetSuperModules()), 
129   fFirstPedestalSample(qadm.GetFirstPedestalSample()), 
130   fLastPedestalSample(qadm.GetLastPedestalSample()),  
131   fFirstPedestalSampleTRU(qadm.GetFirstPedestalSampleTRU()), 
132   fLastPedestalSampleTRU(qadm.GetLastPedestalSampleTRU()),  
133   fMinSignalLG(qadm.GetMinSignalLG()),
134   fMaxSignalLG(qadm.GetMaxSignalLG()),
135   fMinSignalHG(qadm.GetMinSignalHG()),
136   fMaxSignalHG(qadm.GetMaxSignalHG()),
137   fMinSignalTRU(qadm.GetMinSignalTRU()),
138   fMaxSignalTRU(qadm.GetMaxSignalTRU()),
139   fMinSignalLGLEDMon(qadm.GetMinSignalLGLEDMon()),
140   fMaxSignalLGLEDMon(qadm.GetMaxSignalLGLEDMon()),
141   fMinSignalHGLEDMon(qadm.GetMinSignalHGLEDMon()),
142   fMaxSignalHGLEDMon(qadm.GetMaxSignalHGLEDMon()),
143   fCalibRefHistoPro(NULL),
144   fCalibRefHistoH2F(NULL),
145   fLEDMonRefHistoPro(NULL),
146   fHighEmcHistoH2F(NULL)
147 //  fTextSM(new TText*[fSuperModules]) ,
148 //  fLineCol(NULL),
149 //  fLineRow(NULL)
150 {
151   //copy ctor 
152   SetName((const char*)qadm.GetName()) ; 
153   SetTitle((const char*)qadm.GetTitle()); 
154   SetFittingAlgorithm(qadm.GetFittingAlgorithm());
155   
156 //  for (Int_t sm = 0 ; sm < fSuperModules ; sm++){
157 //    fTextSM[sm] = qadm.fTextSM[sm] ;
158 //  }  
159 }
160
161 //__________________________________________________________________
162 AliEMCALQADataMakerRec& AliEMCALQADataMakerRec::operator = (const AliEMCALQADataMakerRec& qadm )
163 {
164   // Equal operator.
165   this->~AliEMCALQADataMakerRec();
166   new(this) AliEMCALQADataMakerRec(qadm);
167 //  fLineCol = NULL;
168 //  fLineRow = NULL;
169 //  for (Int_t sm = 0 ; sm < fSuperModules ; sm++){
170 //    fTextSM[sm] = qadm.fTextSM[sm] ;
171 //  }    
172   return *this;
173 }
174  
175 //____________________________________________________________________________ 
176 void AliEMCALQADataMakerRec::EndOfDetectorCycle(AliQAv1::TASKINDEX_t task, TObjArray ** list)
177 {
178   //Detector specific actions at end of cycle
179         
180 //  if(fCycleCounter)
181 //        GetRawsData(kNEventsPerTower)->Scale(1./fCycleCounter);
182
183   // do the QA checking
184   ResetEventTrigClasses(); // reset triggers list to select all histos
185   AliQAChecker::Instance()->Run(AliQAv1::kEMCAL, task, list) ;  
186 }
187
188 //____________________________________________________________________________ 
189 void AliEMCALQADataMakerRec::GetCalibRefFromOCDB()
190 {
191   //Get the reference histogram from OCDB
192   TString sName1("hHighEmcalRawMaxMinusMin") ;
193   TString sName2("hLowLEDMonEmcalRawMaxMinusMin") ;
194   sName1.Prepend(Form("%s_", AliRecoParam::GetEventSpecieName(AliRecoParam::kCalib))) ; 
195   sName2.Prepend(Form("%s_", AliRecoParam::GetEventSpecieName(AliRecoParam::kCalib))) ; 
196   
197   TString refStorage(AliQAv1::GetQARefStorage()) ;
198   if (!refStorage.Contains(AliQAv1::GetLabLocalOCDB()) && !refStorage.Contains(AliQAv1::GetLabAliEnOCDB())) {
199     AliFatal(Form("%s is not a valid location for reference data", refStorage.Data())) ; 
200   } else {
201     AliQAManager* manQA = AliQAManager::QAManager(AliQAv1::kRAWS) ;    
202     AliQAv1::SetQARefDataDirName(AliRecoParam::kCalib) ;
203     if ( ! manQA->GetLock() ) { 
204       manQA->SetDefaultStorage(AliQAv1::GetQARefStorage()) ; 
205       manQA->SetSpecificStorage("*", AliQAv1::GetQARefStorage()) ;
206       manQA->SetRun(AliCDBManager::Instance()->GetRun()) ; 
207       manQA->SetLock() ; 
208     }
209     char * detOCDBDir = Form("%s/%s/%s", GetName(), AliQAv1::GetRefOCDBDirName(), AliQAv1::GetRefDataDirName()) ; 
210     AliCDBEntry * entry = manQA->Get(detOCDBDir, manQA->GetRun()) ;
211     if (entry) {
212       TList * listDetQAD =static_cast<TList *>(entry->GetObject()) ;
213       if ( strcmp(listDetQAD->ClassName(), "TList") != 0 ) {
214         AliError(Form("Expected a Tlist and found a %s for detector %s", listDetQAD->ClassName(), GetName())) ; 
215         listDetQAD = NULL ; 
216       }
217       TObjArray * dirOCDB= NULL ; 
218       if ( listDetQAD )
219         dirOCDB = static_cast<TObjArray *>(listDetQAD->FindObject(Form("%s/%s", AliQAv1::GetTaskName(AliQAv1::kRAWS).Data(), AliRecoParam::GetEventSpecieName(AliRecoParam::kCalib)))) ;       
220       if (dirOCDB){
221         fCalibRefHistoPro = dynamic_cast<TProfile *>(dirOCDB->FindObject(sName1.Data())) ; 
222         fLEDMonRefHistoPro = dynamic_cast<TProfile *>(dirOCDB->FindObject(sName2.Data())) ; 
223       }
224     }
225   }
226  
227   if(fCalibRefHistoPro && fLEDMonRefHistoPro){
228     
229     //Defining histograms binning, each 2D histogram covers all SMs
230     Int_t nSMSectors = fSuperModules / 2; // 2 SMs per sector
231     Int_t nbinsZ = 2*AliEMCALGeoParams::fgkEMCALCols;
232     Int_t nbinsPhi = nSMSectors * AliEMCALGeoParams::fgkEMCALRows;
233     
234     if(!fCalibRefHistoH2F)
235       fCalibRefHistoH2F =  new TH2F("hCalibRefHisto", "hCalibRefHisto", nbinsZ, -0.5, nbinsZ - 0.5, nbinsPhi, -0.5, nbinsPhi -0.5);
236     ConvertProfile2H(fCalibRefHistoPro,fCalibRefHistoH2F) ; 
237   } else {
238     AliFatal(Form("No reference object with name %s or %s found", sName1.Data(), sName2.Data())) ; 
239   }
240 }
241 //____________________________________________________________________________ 
242 void AliEMCALQADataMakerRec::InitESDs()
243 {
244   //Create histograms to controll ESD
245   const Bool_t expert   = kTRUE ; 
246   const Bool_t image    = kTRUE ; 
247   
248   TH1F * h1 = new TH1F("hESDCaloClusterE",  "ESDs CaloCluster energy in EMCAL;Energy [GeV];Counts",    200, 0., 100.) ; 
249   h1->Sumw2() ;
250   Add2ESDsList(h1, kESDCaloClusE, !expert, image)  ;                                                     
251
252   TH1I * h2 = new TH1I("hESDCaloClusterM", "ESDs CaloCluster multiplicity in EMCAL;# of Clusters;Entries", 100, 0,  100) ; 
253   h2->Sumw2() ;
254   Add2ESDsList(h2, kESDCaloClusM, !expert, image)  ;
255
256   TH1F * h3 = new TH1F("hESDCaloCellA",  "ESDs CaloCell amplitude in EMCAL;Energy [GeV];Counts",    500, 0., 50.) ; 
257   h3->Sumw2() ;
258   Add2ESDsList(h3, kESDCaloCellA, !expert, image)  ;  
259  
260   TH1I * h4 = new TH1I("hESDCaloCellM", "ESDs CaloCell multiplicity in EMCAL;# of Clusters;Entries", 200, 0,  1000) ; 
261   h4->Sumw2() ;
262   Add2ESDsList(h4, kESDCaloCellM, !expert, image) ;
263   //
264   ClonePerTrigClass(AliQAv1::kESDS); // this should be the last line    
265 }
266
267 //____________________________________________________________________________ 
268 void AliEMCALQADataMakerRec::InitDigits()
269 {
270   // create Digits histograms in Digits subdir
271   const Bool_t expert   = kTRUE ; 
272   const Bool_t image    = kTRUE ; 
273   
274   TH1I * h0 = new TH1I("hEmcalDigits",    "Digits amplitude distribution in EMCAL;Amplitude [ADC counts];Counts",    500, 0, 500) ; 
275   h0->Sumw2() ;
276   Add2DigitsList(h0, 0, !expert, image) ;
277   TH1I * h1 = new TH1I("hEmcalDigitsMul", "Digits multiplicity distribution in EMCAL;# of Digits;Entries", 200, 0, 2000) ; 
278   h1->Sumw2() ;
279   Add2DigitsList(h1, 1, !expert, image) ;
280   //
281   ClonePerTrigClass(AliQAv1::kDIGITS); // this should be the last line
282 }
283
284 //____________________________________________________________________________ 
285 void AliEMCALQADataMakerRec::InitRecPoints()
286 {
287   // create Reconstructed PoInt_ts histograms in RecPoints subdir
288   const Bool_t expert   = kTRUE ; 
289   const Bool_t image    = kTRUE ; 
290   
291   TH1F* h0 = new TH1F("hEMCALRpE","EMCAL RecPoint energies;Energy [GeV];Counts",200, 0.,20.); //GeV
292   h0->Sumw2();
293   Add2RecPointsList(h0,kRecPE, !expert, image);
294
295   TH1I* h1 = new TH1I("hEMCALRpM","EMCAL RecPoint multiplicities;# of Clusters;Entries",100,0,100);
296   h1->Sumw2();
297   Add2RecPointsList(h1,kRecPM, !expert, image);
298
299   TH1I* h2 = new TH1I("hEMCALRpDigM","EMCAL RecPoint Digit Multiplicities;# of Digits;Entries",20,0,20);
300   h2->Sumw2();
301   Add2RecPointsList(h2,kRecPDigM, !expert, image);
302   //
303   ClonePerTrigClass(AliQAv1::kRECPOINTS); // this should be the last line
304 }
305
306 //____________________________________________________________________________ 
307 void AliEMCALQADataMakerRec::InitRaws()
308 {
309   // create Raws histograms in Raws subdir
310   const Bool_t expert   = kTRUE ; 
311   const Bool_t saveCorr = kTRUE ; 
312   const Bool_t image    = kTRUE ; 
313   const Option_t *profileOption = "s";
314
315   Int_t nTowersPerSM = AliEMCALGeoParams::fgkEMCALRows * AliEMCALGeoParams::fgkEMCALCols; // number of towers in a SuperModule; 24x48
316   Int_t nTot = fSuperModules * nTowersPerSM; // max number of towers in all SuperModules
317     
318   //Defining histograms binning, each 2D histogram covers all SMs
319   Int_t nSMSectors = fSuperModules / 2; // 2 SMs per sector
320   Int_t nbinsZ = 2*AliEMCALGeoParams::fgkEMCALCols;
321   Int_t nbinsPhi = nSMSectors * AliEMCALGeoParams::fgkEMCALRows;
322         
323   Int_t nTRUCols = 2*AliEMCALGeoParams::fgkEMCALTRUCols; //total TRU columns for 2D TRU histos
324   Int_t nTRURows = nSMSectors*AliEMCALGeoParams::fgkEMCALTRUsPerSM*AliEMCALGeoParams::fgkEMCALTRURows; //total TRU rows for 2D TRU histos
325    // counter info: number of channels per event (bins are SM index)
326   TProfile * h0 = new TProfile("hLowEmcalSupermodules", "Low Gain EMC: # of towers vs SuperMod;SM Id;# of towers",
327                                fSuperModules, -0.5, fSuperModules-0.5, profileOption) ;
328   Add2RawsList(h0, kNsmodLG, expert, !image, !saveCorr) ;
329   TProfile * h1 = new TProfile("hHighEmcalSupermodules", "High Gain EMC: # of towers vs SuperMod;SM Id;# of towers",  
330                                fSuperModules, -0.5, fSuperModules-0.5, profileOption) ; 
331   Add2RawsList(h1, kNsmodHG, expert, !image, !saveCorr) ;
332
333   // where did max sample occur? (bins are towers)
334   TProfile * h2 = new TProfile("hLowEmcalRawtime", "Low Gain EMC: Time at Max vs towerId;Tower Id;Time [ticks]", 
335                                nTot, -0.5, nTot-0.5, profileOption) ;
336   Add2RawsList(h2, kTimeLG, expert, !image, !saveCorr) ;
337   TProfile * h3 = new TProfile("hHighEmcalRawtime", "High Gain EMC: Time at Max vs towerId;Tower Id;Time [ticks]", 
338                                nTot, -0.5, nTot-0.5, profileOption) ;
339   Add2RawsList(h3, kTimeHG, expert, !image, !saveCorr) ;
340
341   // how much above pedestal was the max sample?  (bins are towers)
342   TProfile * h4 = new TProfile("hLowEmcalRawMaxMinusMin", "Low Gain EMC: Max - Min vs towerId;Tower Id;Max-Min [ADC counts]", 
343                                nTot, -0.5, nTot-0.5, profileOption) ;
344   Add2RawsList(h4, kSigLG, expert, !image, !saveCorr) ;
345   TProfile * h5 = new TProfile("hHighEmcalRawMaxMinusMin", "High Gain EMC: Max - Min vs towerId;Tower Id;Max-Min [ADC counts]",
346                                nTot, -0.5, nTot-0.5, profileOption) ;
347   Add2RawsList(h5, kSigHG, expert, !image, !saveCorr) ;
348
349   // total counter: channels per event
350   TH1I * h6 = new TH1I("hLowNtot", "Low Gain EMC: Total Number of found towers;# of Towers;Counts", 200, 0, nTot) ;
351   h6->Sumw2() ;
352   Add2RawsList(h6, kNtotLG, expert, !image, !saveCorr) ;
353   TH1I * h7 = new TH1I("hHighNtot", "High Gain EMC: Total Number of found towers;# of Towers;Counts", 200,0, nTot) ;
354   h7->Sumw2() ;
355   Add2RawsList(h7, kNtotHG, expert, !image, !saveCorr) ;
356
357   // pedestal (bins are towers)
358   TProfile * h8 = new TProfile("hLowEmcalRawPed", "Low Gain EMC: Pedestal vs towerId;Tower Id;Pedestal [ADC counts]", 
359                                nTot, -0.5, nTot-0.5, profileOption) ;
360   Add2RawsList(h8, kPedLG, expert, !image, !saveCorr) ;
361   TProfile * h9 = new TProfile("hHighEmcalRawPed", "High Gain EMC: Pedestal vs towerId;Tower Id;Pedestal [ADC counts]",
362                                nTot, -0.5, nTot-0.5, profileOption) ;
363   Add2RawsList(h9, kPedHG, expert, !image, !saveCorr) ;
364         
365  
366   // now repeat the same for TRU and LEDMon data
367   Int_t nTot2x2 = fSuperModules * AliEMCALGeoParams::fgkEMCALTRUsPerSM * AliEMCALGeoParams::fgkEMCAL2x2PerTRU; // max number of TRU channels for all SuperModules
368
369   // counter info: number of channels per event (bins are SM index)
370   TProfile * hT0 = new TProfile("hTRUEmcalSupermodules", "TRU EMC: # of TRU channels vs SuperMod;SM Id;# of TRU channels",
371                                 fSuperModules, -0.5, fSuperModules-0.5, profileOption) ;
372   Add2RawsList(hT0, kNsmodTRU, expert, !image, !saveCorr) ;
373
374   // how much above pedestal was the max sample?  (bins are TRU channels)
375   TProfile * hT1 = new TProfile("hTRUEmcalRawMaxMinusMin", "TRU EMC: Max - Min vs 2x2Id;2x2 Id;Max-Min [ADC counts]", 
376                                 nTot2x2, -0.5, nTot2x2-0.5, profileOption) ;
377   Add2RawsList(hT1, kSigTRU, expert, !image, !saveCorr) ;
378
379   // total counter: channels per event
380   TH1I * hT2 = new TH1I("hTRUNtot", "TRU EMC: Total Number of found TRU channels;# of TRU Channels;Counts", 200, 0, nTot2x2) ;
381   hT2->Sumw2() ;
382   Add2RawsList(hT2, kNtotTRU, expert, !image, !saveCorr) ;
383
384   // L0 trigger hits: # of hits (bins are TRU channels)
385   TH2I * hT3 = new TH2I("hTRUEmcalL0hits", "L0 trigger hits: Total number of 2x2 L0 generated",  nTRUCols, -0.5, nTRUCols - 0.5, nTRURows, -0.5, nTRURows-0.5);
386   hT3->SetOption("COLZ");
387   //hT3->Sumw2();
388   Add2RawsList(hT3, kNL0TRU, expert, image, !saveCorr);
389
390   // L0 trigger hits: average time (bins are TRU channels)
391   TProfile2D * hT4 = new TProfile2D("hTRUEmcalL0hitsAvgTime", "L0 trigger hits: average time bin", nTRUCols, -0.5, nTRUCols - 0.5, nTRURows, -0.5, nTRURows-0.5, profileOption);
392   hT4->SetOption("COLZ");
393   Add2RawsList(hT4, kTimeL0TRU, expert, image, !saveCorr);
394
395   // L0 trigger hits: first in the event (bins are TRU channels)
396   TH1I * hT5 = new TH1I("hTRUEmcalL0hitsFirst", "L0 trigger hits: First hit in the event", nTot2x2, -0.5, nTot2x2);
397   hT5->Sumw2();
398   Add2RawsList(hT5, kNL0FirstTRU, expert, !image, !saveCorr);
399         
400   // L0 trigger hits: average time of first hit in the event (bins are TRU channels)
401   TProfile * hT6 = new TProfile("hTRUEmcalL0hitsFirstAvgTime", "L0 trigger hits: average time of first hit", nTot2x2, -0.5, nTot2x2, profileOption); 
402   Add2RawsList(hT6, kTimeL0FirstTRU, expert, !image, !saveCorr);
403
404   // and also LED Mon..
405   // LEDMon has both high and low gain channels, just as regular FEE/towers
406   Int_t nTotLEDMon = fSuperModules * AliEMCALGeoParams::fgkEMCALLEDRefs; // max number of LEDMon channels for all SuperModules
407
408   // counter info: number of channels per event (bins are SM index)
409   TProfile * hL0 = new TProfile("hLowLEDMonEmcalSupermodules", "LowLEDMon Gain EMC: # of strips vs SuperMod;SM Id;# of strips",
410                                fSuperModules, -0.5, fSuperModules-0.5, profileOption) ;
411   Add2RawsList(hL0, kNsmodLGLEDMon, expert, !image, !saveCorr) ;
412   TProfile * hL1 = new TProfile("hHighLEDMonEmcalSupermodules", "HighLEDMon Gain EMC: # of strips vs SuperMod;SM Id;# of strips",  
413                                fSuperModules, -0.5, fSuperModules-0.5, profileOption) ; 
414   Add2RawsList(hL1, kNsmodHGLEDMon, expert, !image, !saveCorr) ;
415
416   // where did max sample occur? (bins are strips)
417   TProfile * hL2 = new TProfile("hLowLEDMonEmcalRawtime", "LowLEDMon Gain EMC: Time at Max vs stripId;Strip Id;Time [ticks]", 
418                                nTotLEDMon, -0.5, nTotLEDMon-0.5, profileOption) ;
419   Add2RawsList(hL2, kTimeLGLEDMon, expert, !image, !saveCorr) ;
420   TProfile * hL3 = new TProfile("hHighLEDMonEmcalRawtime", "HighLEDMon Gain EMC: Time at Max vs stripId;Strip Id;Time [ticks]", 
421                                nTotLEDMon, -0.5, nTotLEDMon-0.5, profileOption) ;
422   Add2RawsList(hL3, kTimeHGLEDMon, expert, !image, !saveCorr) ;
423
424   // how much above pedestal was the max sample?  (bins are strips)
425   TProfile * hL4 = new TProfile("hLowLEDMonEmcalRawMaxMinusMin", "LowLEDMon Gain EMC: Max - Min vs stripId;Strip Id;Max-Min [ADC counts]", 
426                                nTotLEDMon, -0.5, nTotLEDMon-0.5, profileOption) ;
427   Add2RawsList(hL4, kSigLGLEDMon, expert, !image, !saveCorr) ;
428   TProfile * hL5 = new TProfile("hHighLEDMonEmcalRawMaxMinusMin", "HighLEDMon Gain EMC: Max - Min vs stripId;Strip Id;Max-Min [ADC counts]",
429                                nTotLEDMon, -0.5, nTotLEDMon-0.5, profileOption) ;
430   Add2RawsList(hL5, kSigHGLEDMon, expert, !image, !saveCorr) ;
431   
432     // total counter: channels per event
433   TH1I * hL6 = new TH1I("hLowLEDMonNtot", "LowLEDMon Gain EMC: Total Number of found strips;# of Strips;Counts", 200, 0, nTotLEDMon) ;
434   hL6->Sumw2() ;
435   Add2RawsList(hL6, kNtotLGLEDMon, expert, !image, !saveCorr) ;
436   TH1I * hL7 = new TH1I("hHighLEDMonNtot", "HighLEDMon Gain EMC: Total Number of found strips;# of Strips;Counts", 200,0, nTotLEDMon) ;
437   hL7->Sumw2() ;
438   Add2RawsList(hL7, kNtotHGLEDMon, expert, !image, !saveCorr) ;
439
440   // pedestal (bins are strips)
441   TProfile * hL8 = new TProfile("hLowLEDMonEmcalRawPed", "LowLEDMon Gain EMC: Pedestal vs stripId;Strip Id;Pedestal [ADC counts]", 
442                                nTotLEDMon, -0.5, nTotLEDMon-0.5, profileOption) ;
443   Add2RawsList(hL8, kPedLGLEDMon, expert, !image, !saveCorr) ;
444   TProfile * hL9 = new TProfile("hHighLEDMonEmcalRawPed", "HighLEDMon Gain EMC: Pedestal vs stripId;Strip Id;Pedestal [ADC counts]",
445                                nTotLEDMon, -0.5, nTotLEDMon-0.5, profileOption) ;
446   Add2RawsList(hL9, kPedHGLEDMon, expert, !image, !saveCorr) ;
447   
448   //temp 2D amplitude histogram for the current run
449   fHighEmcHistoH2F = new TH2F("h2DHighEC2", "High Gain EMC:Max - Min [ADC counts]", nbinsZ, -0.5 , nbinsZ-0.5, nbinsPhi, -0.5, nbinsPhi-0.5);
450    fHighEmcHistoH2F->SetDirectory(0) ; // this histo must be memory resident
451   //add ratio histograms: to comapre the current run with the reference data 
452   TH2F * h15 = new TH2F("h2DRatioAmp", "High Gain Ratio to Reference:Amplitude_{current run}/Amplitude_{reference run}", nbinsZ, -0.5 , nbinsZ-0.5, 
453                         nbinsPhi, -0.5, nbinsPhi-0.5);
454   //settings for display in amore
455   h15->SetTitle("Amplitude_{current run}/Amplitude_{reference run}"); 
456   h15->SetMaximum(2.0);
457   h15->SetMinimum(0.1);
458   h15->SetOption("COLZ");
459   gStyle->SetOptStat(0);
460   Int_t color[] = {4,3,2} ;
461   gStyle->SetPalette(3,color);
462   h15->GetZaxis()->SetNdivisions(3);
463   h15->UseCurrentStyle();
464   h15->SetDirectory(0);
465   Add2RawsList(h15, k2DRatioAmp, expert, image, !saveCorr) ;
466
467   TH1F * h16 = new TH1F("hRatioDist", "Amplitude_{current run}/Amplitude_{reference run} ratio distribution", nTot, 0., 2.);
468   // h16->SetMinimum(0.1); 
469   // h16->SetMaximum(100.);
470   gStyle->SetOptStat(0);
471   h16->UseCurrentStyle();
472   h16->SetDirectory(0);
473   Add2RawsList(h16, kRatioDist, !expert, image, !saveCorr) ;
474
475   //add two histograms for shifter from the LED monitor system: comapre LED monitor with the reference run
476   //to be used for decision whether we need to change reference data
477   TH1F * hL10 = new TH1F("hMaxMinusMinLEDMonRatio", "LEDMon amplitude, Ratio to reference run", nTotLEDMon, -0.5, nTotLEDMon-0.5) ;
478   //settings for display in amore
479   hL10->SetTitle("Amplitude_{LEDMon current}/Amplitude_{LEDMon reference}"); 
480   hL10->SetMaximum(2.0);
481   hL10->SetMinimum(0.1); 
482   gStyle->SetOptStat(0);
483   hL10->UseCurrentStyle();
484   hL10->SetDirectory(0);
485 //  hL10->SetOption("E");
486   Add2RawsList(hL10, kLEDMonRatio, expert, image, !saveCorr) ;
487
488   TH1F * hL11 = new TH1F("hMaxMinusMinLEDMonRatioDist", "LEDMon amplitude, Ratio distribution", nTotLEDMon, 0, 2);
489   // hL11->SetMinimum(0.1) ;
490   gStyle->SetOptStat(0);
491   hL11->UseCurrentStyle();
492   hL11->SetDirectory(0);
493   Add2RawsList(hL11, kLEDMonRatioDist, expert, image, !saveCorr) ;
494   
495   GetCalibRefFromOCDB();   
496
497
498         //STU histgrams
499
500  //histos
501  Int_t nSTUCols = AliEMCALGeoParams::fgkEMCALSTUCols;
502  Int_t nSTURows = AliEMCALGeoParams::fgkEMCALSTURows;
503 //              kAmpL1, kGL1, kJL1,
504 //              kGL1V0, kJL1V0, kSTUTRU  
505         
506  TProfile2D *hS0 = new TProfile2D("hL1Amp", "Mean STU signal per Row and Column", nSTUCols, -0.5, nSTUCols-0.5, nSTURows, -0.5, nSTURows-0.5);
507  Add2RawsList(hS0, kAmpL1, expert, !image, !saveCorr) ;
508         
509  TH2F *hS1 = new TH2F("hL1Gamma", "L1 Gamma patch position (FastOR top-left)", nSTUCols, -0.50, nSTUCols-0.5, nSTURows + 5, -0.5, nSTURows-0.5 + 5); //+5 for better visible error box
510  Add2RawsList(hS1, kGL1, !expert, image, !saveCorr) ;
511         
512  TH2F *hS2 = new TH2F("hL1Jet", "L1 Jet patch position (FastOR top-left)", 12, -0.5, nSTUCols-0.5, 16, 0, nSTURows-0.5);
513  Add2RawsList(hS2, kJL1, !expert, image, !saveCorr) ;
514         
515  TH2I *hS3 = new TH2I("hL1GV0", "L1 Gamma patch amplitude versus V0 signal", 500, 0, 50000, 1500, 0, 1500);
516  Add2RawsList(hS3, kGL1V0, expert, image, !saveCorr) ;
517         
518  TH2I *hS4 = new TH2I("hL1JV0", "L1 Jet patch amplitude versus V0 signal", 500, 0, 50000, 1000, 0, 1000);
519  Add2RawsList(hS4, kJL1V0, expert, !image, !saveCorr) ;
520
521  TH1I *hS5 = new TH1I("hFrameR","Link between TRU and STU", 32, 0, 32);
522  Add2RawsList(hS5, kSTUTRU, !expert, image, !saveCorr) ;
523
524  hS0->SetOption("COLZ");
525  hS1->SetOption("COLZ");
526  hS2->SetOption("COLZ");
527  hS3->SetOption("COLZ");
528  hS4->SetOption("COLZ");
529
530   //
531   ClonePerTrigClass(AliQAv1::kRAWS); // this should be the last line
532 }
533
534 //____________________________________________________________________________
535 void AliEMCALQADataMakerRec::MakeESDs(AliESDEvent * esd)
536 {
537   // make QA data from ESDs
538
539   Int_t nTot = 0 ; 
540   for ( Int_t index = 0; index < esd->GetNumberOfCaloClusters() ; index++ ) {
541     AliESDCaloCluster * clu = esd->GetCaloCluster(index) ;
542     if( clu->IsEMCAL() ) {
543       FillESDsData(kESDCaloClusE,clu->E()) ;
544       nTot++ ;
545     } 
546   }
547   FillESDsData(kESDCaloClusM,nTot) ;
548
549   //fill calo cells
550   AliESDCaloCells* cells = esd->GetEMCALCells();
551   FillESDsData(kESDCaloCellM,cells->GetNumberOfCells()) ;
552
553   for ( Int_t index = 0; index < cells->GetNumberOfCells() ; index++ ) {
554     FillESDsData(kESDCaloCellA,cells->GetAmplitude(index)) ;
555   }
556   //
557   IncEvCountCycleESDs();
558   IncEvCountTotalESDs();
559 }
560
561 //____________________________________________________________________________
562 void AliEMCALQADataMakerRec::MakeRaws(AliRawReader* rawReader)
563 {
564   // Check that all the reference histograms exist before we try to use them - otherwise call InitRaws
565   // RS: Attention: the counters are increments after custom modification of eventSpecie
566   if (!fCalibRefHistoPro || !fCalibRefHistoH2F || !fLEDMonRefHistoPro || !fHighEmcHistoH2F) {
567     InitRaws();
568   }
569
570   // make sure EMCal was readout during the event
571   Int_t emcID = AliDAQ::DetectorID("EMCAL"); // bit 18..
572   const UInt_t *detPattern = rawReader->GetDetectorPattern(); 
573   UInt_t emcInReadout = ( ((1 << emcID) & detPattern[0]) >> emcID);
574   if (! emcInReadout) return; // no poInt_t in looking at this event, if no EMCal data
575
576   // setup
577   rawReader->Reset() ;
578   AliCaloRawStreamV3 in(rawReader,"EMCAL"); 
579   rawReader->Select("EMCAL", 0, AliEMCALGeoParams::fgkLastAltroDDL) ; //select EMCAL DDL's 
580
581   AliRecoParam::EventSpecie_t saveSpecie = fEventSpecie ;
582   if (rawReader->GetType() == AliRawEventHeaderBase::kCalibrationEvent) { 
583     SetEventSpecie(AliRecoParam::kCalib) ;      
584   }
585
586   const Int_t nTowersPerSM = AliEMCALGeoParams::fgkEMCALRows * AliEMCALGeoParams::fgkEMCALCols; // number of towers in a SuperModule; 24x48
587   const Int_t nRows        = AliEMCALGeoParams::fgkEMCALRows; // number of rows per SuperModule
588   const Int_t nStripsPerSM = AliEMCALGeoParams::fgkEMCALLEDRefs; // number of strips per SuperModule
589   const Int_t n2x2PerSM    = AliEMCALGeoParams::fgkEMCALTRUsPerSM * AliEMCALGeoParams::fgkEMCAL2x2PerTRU; // number of TRU 2x2's per SuperModule
590   const Int_t n2x2PerTRU   = AliEMCALGeoParams::fgkEMCAL2x2PerTRU;
591   const Int_t nTot2x2      = fSuperModules * n2x2PerSM; // total TRU channel
592
593   // SM counters; decl. should be safe, assuming we don't get more than expected SuperModules..
594   Int_t nTotalSMLG[AliEMCALGeoParams::fgkEMCALModules]       = {0};
595   Int_t nTotalSMHG[AliEMCALGeoParams::fgkEMCALModules]       = {0};
596   Int_t nTotalSMTRU[AliEMCALGeoParams::fgkEMCALModules]      = {0};
597   Int_t nTotalSMLGLEDMon[AliEMCALGeoParams::fgkEMCALModules] = {0};
598   Int_t nTotalSMHGLEDMon[AliEMCALGeoParams::fgkEMCALModules] = {0};
599
600   const Int_t nTRUL0ChannelBits = 10; // used for L0 trigger bits checks
601         int firstL0TimeBin = 999;
602   int triggers[nTot2x2][24]; //auxiliary array for L0 trigger - TODO remove hardcoded 24
603         memset(triggers, 0, sizeof(int) * 24 * nTot2x2);
604
605   Int_t iSM = 0; // SuperModule index 
606   // start loop over input stream  
607   while (in.NextDDL()) {
608     Int_t iRCU = in.GetDDLNumber() % 2; // RCU0 or RCU1, within SuperModule
609     Int_t iDDL = in.GetDDLNumber();
610     fRawAnalyzer->SetIsZeroSuppressed( in.GetZeroSupp() ); 
611     
612     while (in.NextChannel()) {
613       Int_t iBranch = in.GetBranch();
614       
615       iSM = in.GetModule(); // SuperModule
616       //prInt_tf("iSM %d DDL %d", iSM, in.GetDDLNumber()); 
617       if (iSM>=0 && iSM<fSuperModules) { // valid module reading
618
619         Int_t nsamples = 0;
620         vector<AliCaloBunchInfo> bunchlist; 
621         while (in.NextBunch()) {
622           nsamples += in.GetBunchLength();
623           bunchlist.push_back( AliCaloBunchInfo(in.GetStartTimeBin(), in.GetBunchLength(), in.GetSignals() ) );
624         } 
625         
626         if (nsamples > 0) { // this check is needed for when we have zero-supp. on, but not sparse readout
627           Float_t time = 0.; 
628           Float_t amp  = 0.; 
629           // indices for pedestal calc.
630           Int_t firstPedSample = 0;
631           Int_t lastPedSample  = 0;
632           bool isTRUL0IdData   = false;
633
634           if (! in.IsTRUData() ) { // high gain, low gain, LED Mon data - all have the same shaper/sampling 
635             AliCaloFitResults fitResults = fRawAnalyzer->Evaluate( bunchlist, in.GetAltroCFG1(), in.GetAltroCFG2()); 
636             amp  = fitResults.GetAmp();
637             time = fitResults.GetTof(); 
638             firstPedSample = fFirstPedestalSample;
639             lastPedSample  = fLastPedestalSample;
640           }
641           else { // TRU data is special, needs its own analyzer
642             AliCaloFitResults fitResults = fRawAnalyzerTRU->Evaluate( bunchlist, in.GetAltroCFG1(), in.GetAltroCFG2()); 
643             amp  = fitResults.GetAmp();
644             time = fitResults.GetTof(); 
645             firstPedSample = fFirstPedestalSampleTRU;
646             lastPedSample  = fLastPedestalSampleTRU;
647             if (in.GetColumn() >= n2x2PerTRU) {
648               isTRUL0IdData = true;
649             }
650           }
651   
652           // pedestal samples
653           Int_t nPed = 0;
654           vector<Int_t> pedSamples; 
655         
656           // select earliest bunch 
657           unsigned int bunchIndex = 0;
658           unsigned int startBin = bunchlist.at(0).GetStartBin();
659           if (bunchlist.size() > 0) {
660             for(unsigned int ui=1; ui < bunchlist.size(); ui++ ) {
661               if (startBin > bunchlist.at(ui).GetStartBin() ) {
662                 startBin = bunchlist.at(ui).GetStartBin();
663                 bunchIndex = ui;
664               }
665             }
666           }
667
668           // check bunch for entries in the pedestal sample range
669           Int_t bunchLength = bunchlist.at(bunchIndex).GetLength(); 
670           const UShort_t *sig = bunchlist.at(bunchIndex).GetData();
671           Int_t timebin = 0;
672
673           if (! isTRUL0IdData) { // regular data, can look at pedestals
674             for (Int_t i = 0; i<bunchLength; i++) {
675               timebin = startBin--;
676               if ( firstPedSample<=timebin && timebin<=lastPedSample ) {
677                 pedSamples.push_back( sig[i] );
678                 nPed++;
679               }     
680             } // i
681           }
682           else { // TRU L0 Id Data
683             // which TRU the channel belongs to?
684             Int_t iTRUId = in.GetModule()*3 + (iRCU*in.GetBranch() + iRCU);
685
686             for (Int_t i = 0; i< bunchLength; i++) {
687               for( Int_t j = 0; j < nTRUL0ChannelBits; j++ ){
688                 // check if the bit j is 1
689                 if( (sig[i] & ( 1 << j )) > 0 ){
690                   Int_t iTRUIdInSM = (in.GetColumn() - n2x2PerTRU)*nTRUL0ChannelBits+j;
691                   if(iTRUIdInSM < n2x2PerTRU) {
692                     Int_t iTRUAbsId = iTRUIdInSM + n2x2PerTRU * iTRUId;
693                     // Fill the histograms
694                     Int_t globTRUCol, globTRURow;
695                     GetTruChannelPosition(globTRURow, globTRUCol, iSM, iDDL, iBranch, iTRUIdInSM );
696                     
697                     FillRawsData(kNL0TRU, globTRUCol, globTRURow);
698                     FillRawsData(kTimeL0TRU, globTRUCol, globTRURow, startBin);
699                     triggers[iTRUAbsId][startBin] = 1;
700                     
701                     if((int)startBin < firstL0TimeBin) firstL0TimeBin = startBin;
702                   }
703                 }
704               }
705               startBin--;
706             } // i      
707           } // TRU L0 Id data                   
708           
709           // fill histograms
710           if ( in.IsLowGain() || in.IsHighGain() ) { // regular towers
711             Int_t towerId = iSM*nTowersPerSM + in.GetColumn()*nRows + in.GetRow();
712             if ( in.IsLowGain() ) { 
713               nTotalSMLG[iSM]++; 
714               if ( (amp > fMinSignalLG) && (amp < fMaxSignalLG) ) { 
715                 FillRawsData(kSigLG,towerId, amp);
716                 FillRawsData(kTimeLG,towerId, time);
717               }
718               if (nPed > 0) {
719                 for (Int_t i=0; i<nPed; i++) {
720                   FillRawsData(kPedLG,towerId, pedSamples[i]);
721                 }
722               }
723             } // gain==0
724             else if ( in.IsHighGain() ) {               
725               nTotalSMHG[iSM]++; 
726               if ( (amp > fMinSignalHG) && (amp < fMaxSignalHG) ) { 
727                 FillRawsData(kSigHG,towerId, amp);
728                 FillRawsData(kTimeHG,towerId, time);
729               } 
730               if (nPed > 0) {
731                 for (Int_t i=0; i<nPed; i++) {
732                   FillRawsData(kPedHG,towerId, pedSamples[i]);
733                 }
734               }
735             } // gain==1
736           } // low or high gain
737           // TRU
738           else if ( in.IsTRUData() && in.GetColumn()<AliEMCALGeoParams::fgkEMCAL2x2PerTRU) {
739             // for TRU data, the mapping class holds the TRU Int_ternal 2x2 number (0..95) in the Column var..
740             Int_t iTRU = (iRCU*in.GetBranch() + iRCU); //TRU0 is from RCU0, TRU1 from RCU1, TRU2 is from branch B on RCU1
741             Int_t iTRU2x2Id = iSM*n2x2PerSM + iTRU*AliEMCALGeoParams::fgkEMCAL2x2PerTRU 
742               + in.GetColumn();
743             nTotalSMTRU[iSM]++; 
744             if ( (amp > fMinSignalTRU) && (amp < fMaxSignalTRU) ) { 
745               FillRawsData(kSigTRU,iTRU2x2Id, amp);
746               //FillRawsData(kTimeTRU,iTRU2x2Id, time);
747             }
748             //if (nPed > 0) {
749               //for (Int_t i=0; i<nPed; i++) {
750                 //FillRawsData(kPedTRU,iTRU2x2Id, pedSamples[i]);
751               //}
752             //}
753           }
754           // LED Mon
755           else if ( in.IsLEDMonData() ) {
756             // for LED Mon data, the mapping class holds the gain info in the Row variable
757             // and the Strip number in the Column..
758             Int_t gain = in.GetRow(); 
759             Int_t stripId = iSM*nStripsPerSM + in.GetColumn();
760           
761             if ( gain == 0 ) { 
762               nTotalSMLGLEDMon[iSM]++; 
763               if ( (amp > fMinSignalLGLEDMon) && (amp < fMaxSignalLGLEDMon) ) {
764                 FillRawsData(kSigLGLEDMon,stripId, amp);
765                 FillRawsData(kTimeLGLEDMon,stripId, time);
766               }
767               if (nPed > 0) {
768                 for (Int_t i=0; i<nPed; i++) {
769                   FillRawsData(kPedLGLEDMon,stripId, pedSamples[i]);
770                 }
771               }
772             } // gain==0
773             else if ( gain == 1 ) {             
774               nTotalSMHGLEDMon[iSM]++; 
775               if ( (amp > fMinSignalHGLEDMon) && (amp < fMaxSignalHGLEDMon) ) { 
776                 FillRawsData(kSigHGLEDMon,stripId, amp);
777                 FillRawsData(kTimeHGLEDMon,stripId, time);
778               }
779               if (nPed > 0) {
780                 for (Int_t i=0; i<nPed; i++) {
781                   FillRawsData(kPedHGLEDMon,stripId, pedSamples[i]);
782                 }
783               }
784             } // low or high gain
785           } // LEDMon
786
787         } // SM index OK
788
789       } // nsamples>0 check, some data found for this channel; not only trailer/header
790     }// end while over channel 
791    
792   }//end while over DDL's, of input stream 
793   //filling some L0 trigger histos
794   if( firstL0TimeBin < 999 ){
795     for(Int_t i = 0; i < nTot2x2; i++) {        
796       if( triggers[i][firstL0TimeBin] > 0 ) {
797         //histo->Fill(i,j);
798         FillRawsData(kNL0FirstTRU, i);
799         FillRawsData(kTimeL0FirstTRU, i, firstL0TimeBin);
800       }
801     }
802   }
803   
804   //calculate the ratio of the amplitude and fill the histograms, only if the events type is Calib
805   // RS: operation on the group of histos kSigHG,k2DRatioAmp,kRatioDist,kLEDMonRatio,kLEDMonRatio,kSigLGLEDMon
806   const int hGrp[] = {kSigHG,k2DRatioAmp,kRatioDist,kLEDMonRatio,kLEDMonRatioDist,kSigLGLEDMon};
807   if ( rawReader->GetType() == AliRawEventHeaderBase::kCalibrationEvent &&
808        CheckCloningConsistency(fRawsQAList, hGrp, sizeof(hGrp)/sizeof(int)) ) {  // RS converting original code to loop over all matching triggers
809     int nTrig =IsClonedPerTrigClass(kSigHG,fRawsQAList) ? GetNEventTrigClasses() : 0; // loop over triggers only if histos were cloned
810     //
811     for (int itr=-1;itr<nTrig;itr++) { // start from -1 to acknowledge original histos if they were kept
812       TObjArray* trArr = GetMatchingRawsHistosSet(hGrp, sizeof(hGrp)/sizeof(int) ,itr);
813       if (!trArr) continue;  // no histos for current trigger
814       //
815       Double_t binContent = 0.;
816       TProfile* prSigHG      = (TProfile *)trArr->At(0); //kSigHG
817       TH1* th2DRatioAmp      = (TH1*) trArr->At(1); //k2DRatioAmp
818       TH1* thRatioDist       = (TH1*) trArr->At(2); //kRatioDist
819       TH1* thLEDMonRatio     = (TH1*) trArr->At(3); //kLEDMonRatio
820       TH1* thLEDMonRatioDist = (TH1*) trArr->At(4); //kLEDMonRatio
821       TH1* hSigLGLEDMon      = (TH1*) trArr->At(5); //kSigLGLEDMon
822       th2DRatioAmp->Reset("ICE");
823       thRatioDist->Reset("ICE");
824       thLEDMonRatio->Reset("ICE");
825       thLEDMonRatioDist->Reset("ICE");
826       th2DRatioAmp->ResetStats();
827       thRatioDist->ResetStats();
828       thLEDMonRatio->ResetStats();
829       thLEDMonRatioDist->ResetStats();
830       ConvertProfile2H(prSigHG, fHighEmcHistoH2F);  
831       //
832       for(Int_t ix = 1; ix <= fHighEmcHistoH2F->GetNbinsX(); ix++) {
833         for(Int_t iy = 1; iy <= fHighEmcHistoH2F->GetNbinsY(); iy++) { 
834           if(fCalibRefHistoH2F->GetBinContent(ix, iy)) 
835             binContent = fHighEmcHistoH2F->GetBinContent(ix, iy)/fCalibRefHistoH2F->GetBinContent(ix, iy);
836           th2DRatioAmp->SetBinContent(ix, iy, binContent);
837           thRatioDist->Fill(binContent);
838         }
839       } 
840       //
841       //Now for LED monitor system, to calculate the ratio as well
842       Double_t binError = 0. ;
843       // for the binError, we add the relative errors, squared
844       Double_t relativeErrorSqr = 0. ;
845       //
846       for(int ib = 1; ib <= fLEDMonRefHistoPro->GetNbinsX(); ib++) {
847         //
848         if(fLEDMonRefHistoPro->GetBinContent(ib) != 0) {
849           binContent = hSigLGLEDMon->GetBinContent(ib) / fLEDMonRefHistoPro->GetBinContent(ib);
850
851           relativeErrorSqr = TMath::Power( (fLEDMonRefHistoPro->GetBinError(ib) / fLEDMonRefHistoPro->GetBinContent(ib)), 2);
852           if( hSigLGLEDMon->GetBinContent(ib) != 0) {
853             relativeErrorSqr += TMath::Power( (hSigLGLEDMon->GetBinError(ib)/hSigLGLEDMon->GetBinContent(ib)), 2);
854           }
855         }
856         else { // ref. run info is zero
857           binContent = -1;
858           relativeErrorSqr = 1;
859         }
860         thLEDMonRatio->SetBinContent(ib, binContent);
861         
862         binError = sqrt(relativeErrorSqr) * binContent;
863         thLEDMonRatio->SetBinError(ib, binError);
864         thLEDMonRatioDist->Fill(thLEDMonRatio->GetBinContent(ib));
865       }
866     } // loop over eventual trigger clones
867   } 
868   // let's also fill the SM and event counter histograms
869   Int_t nTotalHG = 0;
870   Int_t nTotalLG = 0;
871   Int_t nTotalTRU = 0;
872   Int_t nTotalHGLEDMon = 0;
873   Int_t nTotalLGLEDMon = 0;
874   for (iSM=0; iSM<fSuperModules; iSM++) {  
875     nTotalLG += nTotalSMLG[iSM]; 
876     nTotalHG += nTotalSMHG[iSM]; 
877     nTotalTRU += nTotalSMTRU[iSM]; 
878     nTotalLGLEDMon += nTotalSMLGLEDMon[iSM]; 
879     nTotalHGLEDMon += nTotalSMHGLEDMon[iSM]; 
880     FillRawsData(kNsmodLG,iSM, nTotalSMLG[iSM]); 
881     FillRawsData(kNsmodHG,iSM, nTotalSMHG[iSM]); 
882     FillRawsData(kNsmodTRU,iSM, nTotalSMTRU[iSM]); 
883     FillRawsData(kNsmodLGLEDMon,iSM, nTotalSMLGLEDMon[iSM]); 
884     FillRawsData(kNsmodHGLEDMon,iSM, nTotalSMHGLEDMon[iSM]); 
885   }
886  
887   FillRawsData(kNtotLG,nTotalLG);
888   FillRawsData(kNtotHG,nTotalHG);
889   FillRawsData(kNtotTRU,nTotalTRU);
890   FillRawsData(kNtotLGLEDMon,nTotalLGLEDMon);
891   FillRawsData(kNtotHGLEDMon,nTotalHGLEDMon);
892  
893   IncEvCountCycleESDs();
894   IncEvCountTotalESDs();
895   SetEventSpecie(saveSpecie) ; 
896   
897         MakeRawsSTU(rawReader);
898
899   // just in case the next rawreader consumer forgets to reset; let's do it here again..
900   rawReader->Reset() ;
901   return;
902 }
903
904 //____________________________________________________________________________
905 void AliEMCALQADataMakerRec::MakeDigits()
906 {
907   // makes data from Digits
908   FillDigitsData(1,fDigitsArray->GetEntriesFast()) ; 
909   TIter next(fDigitsArray) ; 
910   AliEMCALDigit * digit ; 
911   while ( (digit = dynamic_cast<AliEMCALDigit *>(next())) ) {
912     FillDigitsData(0, digit->GetAmplitude()) ;
913   }  
914   //
915 }
916
917 //____________________________________________________________________________
918 void AliEMCALQADataMakerRec::MakeDigits(TTree * digitTree)
919 {
920   // makes data from Digit Tree
921   // RS: Attention: the counters are increments in the MakeDigits()
922   if (fDigitsArray) 
923     fDigitsArray->Clear("C") ; 
924   else
925     fDigitsArray = new TClonesArray("AliEMCALDigit", 1000) ; 
926   
927   TBranch * branch = digitTree->GetBranch("EMCAL") ;
928   if ( ! branch ) { AliWarning("EMCAL branch in Digit Tree not found"); return; }
929   //
930   branch->SetAddress(&fDigitsArray) ;
931   branch->GetEntry(0) ; 
932   MakeDigits() ; 
933   //
934   IncEvCountCycleDigits();
935   IncEvCountTotalDigits();  
936   //  
937 }
938
939 //____________________________________________________________________________
940 void AliEMCALQADataMakerRec::MakeRecPoints(TTree * clustersTree)
941 {
942   // makes data from RecPoints
943   TBranch *emcbranch = clustersTree->GetBranch("EMCALECARP");
944   if (!emcbranch) { 
945     AliError("can't get the branch with the EMCAL clusters !");
946     return;
947   }
948   
949   TObjArray * emcRecPoints = new TObjArray(100) ;
950   emcbranch->SetAddress(&emcRecPoints);
951   emcbranch->GetEntry(0);
952   
953   FillRecPointsData(kRecPM,emcRecPoints->GetEntriesFast()) ; 
954   TIter next(emcRecPoints) ; 
955   AliEMCALRecPoint * rp ; 
956   while ( (rp = dynamic_cast<AliEMCALRecPoint *>(next())) ) {
957     FillRecPointsData(kRecPE,rp->GetEnergy()) ;
958     FillRecPointsData(kRecPDigM,rp->GetMultiplicity());
959   }
960   emcRecPoints->Delete();
961   delete emcRecPoints;
962   IncEvCountCycleRecPoints();
963   IncEvCountTotalRecPoints();
964 }
965
966 //____________________________________________________________________________ 
967 void AliEMCALQADataMakerRec::StartOfDetectorCycle()
968 {
969   //Detector specific actions at start of cycle
970   
971 }
972
973 //____________________________________________________________________________ 
974 void AliEMCALQADataMakerRec::SetFittingAlgorithm(Int_t fitAlgo)              
975 {
976   //Set fitting algorithm and initialize it if this same algorithm was not set before.
977
978   fRawAnalyzer =  AliCaloRawAnalyzerFactory::CreateAnalyzer(fitAlgo);
979   fFittingAlgorithm = fitAlgo;
980   
981   // Init also here the TRU algo, even if it is fixed type.
982   fRawAnalyzerTRU = (AliCaloRawAnalyzerKStandard*)AliCaloRawAnalyzerFactory::CreateAnalyzer(Algo::kFakeAltro);
983   fRawAnalyzerTRU->SetFixTau(kTRUE);
984   fRawAnalyzerTRU->SetTau(2.5); // default for TRU shaper
985 }
986
987 //_____________________________________________________________________________________
988 void AliEMCALQADataMakerRec::ConvertProfile2H(TProfile * p, TH2 * histo) 
989 {  
990   // reset histogram
991   histo->Reset("ICE") ; 
992   histo->ResetStats(); 
993
994   Int_t nbinsProf = p->GetNbinsX();
995   
996   // loop through the TProfile p and fill the TH2F histo 
997   Int_t row = 0;
998   Int_t col = 0;
999   Double_t binContent = 0;
1000   Int_t towerNum = 0; // global tower Id
1001   //  i = 0; // tower Id within SuperModule
1002   Int_t iSM = 0; // SuperModule index 
1003   Int_t iSMSide = 0; // 0=A, 1=C side
1004   Int_t iSMSector = 0; // 2 SM's per sector
1005   
1006   // indices for 2D plots
1007   Int_t col2d = 0;
1008   Int_t row2d = 0;
1009   
1010   for (Int_t ibin = 1; ibin <= nbinsProf; ibin++) {
1011     towerNum = (Int_t) p->GetBinCenter(ibin);
1012     binContent = p->GetBinContent(ibin);
1013     
1014     // figure out what the tower indices are: col, row within a SuperModule
1015     iSM = towerNum/(AliEMCALGeoParams::fgkEMCALRows * AliEMCALGeoParams::fgkEMCALCols);
1016     col = (towerNum/AliEMCALGeoParams::fgkEMCALRows) % (AliEMCALGeoParams::fgkEMCALCols);
1017     row = towerNum % (AliEMCALGeoParams::fgkEMCALRows);
1018     
1019     //DecodeTowerNum(towerNum, &SM, &col, &row);
1020     // then we calculate what the global 2D coord are, based on which SM 
1021     // we are in
1022     iSMSector = iSM / 2;
1023     iSMSide = iSM % 2;
1024     
1025     if (iSMSide == 1) { // C side, shown to the right
1026       col2d = col + AliEMCALGeoParams::fgkEMCALCols;
1027     }
1028     else { // A side, shown to the left 
1029       col2d = col; 
1030     }
1031     
1032     row2d = row + iSMSector * AliEMCALGeoParams::fgkEMCALRows;
1033     
1034     histo->SetBinContent(col2d+1, row2d+1, binContent);
1035   }
1036
1037 //____________________________________________________________________________ 
1038 void AliEMCALQADataMakerRec::GetTruChannelPosition( Int_t &globRow, Int_t &globColumn, Int_t module, Int_t ddl, Int_t branch, Int_t column ) const
1039 { // from local to global indices
1040   Int_t mrow;
1041   Int_t mcol;
1042   Int_t trow;
1043   Int_t tcol;
1044   Int_t drow;
1045   Int_t rcu;
1046   // RCU 0 or 1
1047   rcu = ddl % 2;
1048
1049   // 12 rows of 2x2s in a module (3 TRUs by 4 rows)
1050   mrow = (module/2) * 12;
1051   // 24 columns per module, odd module numbers increased by 24
1052   mcol = (module%2) * 24;
1053
1054   // position within TRU coordinates
1055   tcol = column / 4;
1056   trow = column % 4;
1057
1058   //.combine
1059   if( module%2 == 0 ){   // A side
1060     // mirror rows
1061     trow = 3 - trow;
1062
1063     // TRU in module row addition
1064     drow = (rcu*branch+rcu) * 4;
1065
1066   }
1067   else{   // C side
1068     // mirror columns
1069     tcol = 23 - tcol;
1070
1071     // TRU in module row addition
1072     drow = (2 - (rcu*branch+rcu)) * 4;
1073   }
1074
1075   // output global row/collumn position (0,0 = SMA0, phi = 0, |eta| = max)
1076   globRow = mrow + drow + trow;
1077   globColumn = mcol + tcol;
1078   return;
1079
1080 }
1081 //____________________________________________________________________________ 
1082 void AliEMCALQADataMakerRec::MakeRawsSTU(AliRawReader* rawReader)
1083 { // STU specifics
1084   AliEMCALTriggerSTURawStream* inSTU = new AliEMCALTriggerSTURawStream(rawReader);
1085         
1086   rawReader->Reset();
1087   rawReader->Select("EMCAL", 44);
1088
1089   //L1 segmentation
1090   Int_t sizeL1gsubr = 1;
1091   Int_t sizeL1gpatch = 2; 
1092   Int_t sizeL1jsubr = 4; 
1093
1094   Int_t iEMCALtrig[AliEMCALGeoParams::fgkEMCALSTUCols][AliEMCALGeoParams::fgkEMCALSTURows];
1095   memset(iEMCALtrig, 0, sizeof(int) * AliEMCALGeoParams::fgkEMCALSTUCols * AliEMCALGeoParams::fgkEMCALSTURows);
1096                 
1097   if (inSTU->ReadPayLoad()) 
1098     {
1099       //Fw version (use in case of change in L1 jet 
1100       Int_t fw = inSTU->GetFwVersion();
1101       Int_t sizeL1jpatch = 2+(fw >> 16);
1102
1103       //To check link
1104       Int_t mask = inSTU->GetFrameReceived() ^ inSTU->GetRegionEnable();
1105
1106       for (int i = 0; i < 32; i++)
1107         {
1108                 if (!((mask >> i) &  0x1)) FillRawsData(kSTUTRU, i);
1109         }
1110
1111       //V0 signal in STU
1112       Int_t iV0Sig = inSTU->GetV0A()+inSTU->GetV0C();
1113       
1114       //FastOR amplitude receive from TRU
1115       for (Int_t i = 0; i < 32; i++)
1116         {
1117           UInt_t adc[96];
1118           for (Int_t j = 0; j < 96; j++) adc[j] = 0;
1119           
1120           inSTU->GetADC(i, adc);
1121           
1122           Int_t iTRU = fGeom->GetTRUIndexFromSTUIndex(i);
1123                                 
1124           for (Int_t j = 0; j < 96; j++)
1125             {
1126               Int_t idx;
1127               fGeom->GetAbsFastORIndexFromTRU(iTRU, j, idx);
1128                                 
1129               Int_t px, py;
1130               fGeom->GetPositionInEMCALFromAbsFastORIndex(idx, px, py);
1131                                         
1132               iEMCALtrig[px][py] = adc[j];
1133             }
1134         }
1135                         
1136       //L1 Gamma patches
1137       Int_t iTRUSTU, x, y;
1138       for (Int_t i = 0; i < inSTU->GetNL1GammaPatch(0); i++)
1139         {
1140           if (inSTU->GetL1GammaPatch(i, 0, iTRUSTU, x, y)) // col (0..23), row (0..3)
1141             {
1142               Int_t iTRU;
1143               iTRU = fGeom->GetTRUIndexFromSTUIndex(iTRUSTU);
1144               
1145               Int_t etaG = 23-x, phiG = y + 4 * int(iTRU/2); //position in EMCal
1146               if (iTRU%2) etaG += 24; //C-side
1147                                         
1148               etaG = etaG - sizeL1gsubr * sizeL1gpatch + 1;
1149                                 
1150               //Position of patch L1G (bottom-left FastOR of the patch)
1151               FillRawsData(kGL1, etaG, phiG);
1152                                         
1153               //loop to sum amplitude of FOR in the gamma patch
1154               Int_t iL1GPatchAmp = 0;
1155               for (Int_t L1Gx = 0; L1Gx < sizeL1gpatch; L1Gx ++)
1156                 {
1157                   for (Int_t L1Gy = 0; L1Gy < sizeL1gpatch; L1Gy ++)
1158                     {
1159                       if (etaG+L1Gx < 48 && phiG+L1Gy < 64) iL1GPatchAmp += iEMCALtrig[etaG+L1Gx][phiG+L1Gy];
1160                       //cout << iEMCALtrig[etaG+L1Gx][phiG+L1Gy] << endl;
1161                     }
1162                 }
1163               
1164               //if (iL1GPatchAmp > 500) cout << "L1G amp =" << iL1GPatchAmp << endl;
1165               FillRawsData(kGL1V0, iV0Sig, iL1GPatchAmp);
1166               
1167             }
1168         }
1169                 
1170       //L1 Jet patches
1171       for (Int_t i = 0; i < inSTU->GetNL1JetPatch(0); i++)
1172         {
1173           if (inSTU->GetL1JetPatch(i, 0, x, y)) // col (0,15), row (0,11)
1174             {
1175               
1176               Int_t etaJ = sizeL1jsubr * (11-y-sizeL1jpatch + 1);
1177               Int_t phiJ = sizeL1jsubr * (15-x-sizeL1jpatch + 1);
1178               
1179               //position of patch L1J (FOR bottom-left)
1180               FillRawsData(kJL1, etaJ, phiJ);
1181                                         
1182               //loop the sum aplitude of FOR in the jet patch
1183               Int_t iL1JPatchAmp = 0;
1184               for (Int_t L1Jx = 0; L1Jx < sizeL1jpatch*4; L1Jx ++)
1185                 {
1186                   for (Int_t L1Jy = 0; L1Jy < sizeL1jpatch*4; L1Jy ++)
1187                     {
1188                       if (etaJ+L1Jx < 48 && phiJ+L1Jy < 64) iL1JPatchAmp += iEMCALtrig[etaJ+L1Jx][phiJ+L1Jy];
1189                     }
1190                 }
1191                 
1192               //cout << "L1J amp =" << iL1JPatchAmp << endl;
1193               FillRawsData(kJL1V0, iV0Sig, iL1JPatchAmp);
1194             }
1195         }
1196     }
1197                 
1198   //Fill FOR amplitude histo
1199   for (Int_t i = 0; i < 48; i++)
1200     {
1201       for (Int_t j = 0; j < 60; j++)
1202         {
1203           if (iEMCALtrig[i][j] != 0) FillRawsData(kAmpL1, i, j, iEMCALtrig[i][j]);
1204         }
1205     }
1206   
1207   delete inSTU;
1208   return;
1209 }
1210
1211