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