]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCQADataMakerRec.cxx
Coverity
[u/mrichter/AliRoot.git] / TPC / AliTPCQADataMakerRec.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16
17 /* $Id: $ */
18
19 /*
20   Based on AliPHOSQADataMaker
21   Produces the data needed to calculate the quality assurance. 
22   All data must be mergeable objects.
23   P. Christiansen, Lund, January 2008
24
25   Updated July 2011:
26   ==================
27
28   Major changes to accomodate updates of general DQM/QA changes to have per
29   trigger histograms (for a given event specie).
30
31   1) One instance of AliTPCdataQA only. (This also solves some old wishes by
32   offline team to use less memory because event the 2d arrays for this object
33   is not used). This now has a new flag for only keeping DQM info event by
34   event! For this reason there is no need for a special DQM reset any more
35   between runs!
36
37   2) Fill the histogram for each event. The histograms are no longer filled
38   from the AliTPCdataQA but per event.
39
40   3) Use profiles for the RAW info. By adding the profiles event by event we
41   get the correct event averages WITHOUT having to normalize in the end!
42   Results should therefore also be directly mergable when that feature will
43   come. (none of the other histograms are merged).
44
45   This means that from the DQM/QA point of view the TPC DQM is now fully
46   standard and should ease future developments.
47
48   Updated June 2010:
49   ==================
50
51   The "beautification" of the online DQM histograms have been moved to
52   an amore macro.  
53
54   The per event RAW histograms have been modified in AliTPCdataQA and
55   the copies have therefore also been modified here.
56
57   The AliTPCdataQA can now be configured a bit from here: time bin
58   range (extended default range to 1-1000, event range at start:
59   0-100000, 1000 events per bin). (At least the parameters are not
60   hardcoded:-)
61
62   Implementation:
63   ===============
64
65   For the QA of the RAW data we use the class, AliTPCdataQA, from the
66   existing TPC Calibration framework (which is more advanced than the
67   standard QA framework) and extract the histograms at the end. The
68   Analyse method of the AliTPCdataQA class is called in the method,
69   EndOfDetectorCycle, and there also: 1d histogram(s) are projected
70   and added to the QA list.
71 */
72
73 #include "AliTPCQADataMakerRec.h"
74
75 // --- ROOT system ---
76 #include <TClonesArray.h>
77 #include <TString.h>
78 #include <TSystem.h>
79 #include <TBox.h>
80 #include <TLine.h>
81 #include <TAxis.h>
82
83 // --- Standard library ---
84
85 // --- AliRoot header files ---
86 #include "AliQAChecker.h"
87 #include "AliESDEvent.h"
88 #include "AliESDtrack.h"
89 #include "AliLog.h"
90 #include "AliTPCCalPad.h"
91 #include "AliTPCCalROC.h"
92 #include "AliTPCClustersRow.h"
93 #include "AliTPCclusterMI.h"
94 #include "AliSimDigits.h"
95
96
97 ClassImp(AliTPCQADataMakerRec)
98
99 //____________________________________________________________________________ 
100 AliTPCQADataMakerRec::AliTPCQADataMakerRec() : 
101 AliQADataMakerRec(AliQAv1::GetDetName(AliQAv1::kTPC), 
102                   "TPC Rec Quality Assurance Data Maker"),
103 fTPCdataQA(NULL),
104 fRawFirstTimeBin(1),
105 fRawLastTimeBin(1000)
106 {
107   // ctor
108   
109   for(Int_t i = 0; i < 6; i++)
110     fMapping[i] = 0;
111 }
112
113 //____________________________________________________________________________ 
114 AliTPCQADataMakerRec::AliTPCQADataMakerRec(const AliTPCQADataMakerRec& qadm) :
115   AliQADataMakerRec(),
116   fTPCdataQA(NULL),
117   fRawFirstTimeBin(qadm.GetRawFirstTimeBin()),
118   fRawLastTimeBin(qadm.GetRawLastTimeBin())
119 {
120   //copy ctor 
121   // Does not copy the calibration object, instead InitRaws have to be
122   // called again
123   SetName((const char*)qadm.GetName()) ; 
124   SetTitle((const char*)qadm.GetTitle()); 
125
126   for(Int_t i = 0; i < 6; i++)
127     fMapping[i] = 0;
128 }
129
130 //__________________________________________________________________
131 AliTPCQADataMakerRec& AliTPCQADataMakerRec::operator = (const AliTPCQADataMakerRec& qadm )
132 {
133   // Equal operator.
134   this->~AliTPCQADataMakerRec();
135   new(this) AliTPCQADataMakerRec(qadm);
136   return *this;
137 }
138
139 //__________________________________________________________________
140 AliTPCQADataMakerRec::~AliTPCQADataMakerRec()
141 {
142   // Destructor
143   delete fTPCdataQA; 
144
145   for(Int_t i = 0; i < 6; i++) 
146     delete fMapping[i];
147 }
148  
149 //____________________________________________________________________________ 
150 void AliTPCQADataMakerRec::EndOfDetectorCycle(AliQAv1::TASKINDEX_t task, TObjArray ** list)
151 {
152   //Detector specific actions at end of cycle
153   ResetEventTrigClasses();
154
155   AliQAChecker::Instance()->Run(AliQAv1::kTPC, task, list) ;  
156 }
157
158
159 //____________________________________________________________________________ 
160 void AliTPCQADataMakerRec::InitESDs()
161 {
162   //create ESDs histograms in ESDs subdir  
163   const Bool_t expert   = kTRUE ; 
164   const Bool_t image    = kTRUE ; 
165   
166   TH1F * histESDclusters = 
167     new TH1F("hESDclusters", "N TPC clusters per track; N clusters; Counts",
168              160, 0, 160);
169   histESDclusters->Sumw2();
170   Add2ESDsList(histESDclusters, kClusters, !expert, image);
171
172   TH1F * histESDratio = 
173     new TH1F("hESDratio", "Ratio: TPC clusters / findable; Ratio: cluster/findable; Counts",
174              100, 0, 1);
175   histESDratio->Sumw2();
176   Add2ESDsList(histESDratio, kRatio, !expert, image);
177   
178   TH1F * histESDpt = 
179     new TH1F("hESDpt", "P_{T} distribution; p_{T} [GeV/c]; Counts",
180              50, 0, 5);
181   histESDpt->Sumw2();
182   Add2ESDsList(histESDpt, kPt, !expert, image);
183   //
184   ClonePerTrigClass(AliQAv1::kESDS); // this should be the last line
185 }
186
187 //____________________________________________________________________________ 
188 void AliTPCQADataMakerRec::InitRaws()
189 {
190   //
191   // Adding the raw 
192   //  
193
194   // Modified: 7/7 - 2008
195   // Laurent Aphecetche pointed out that the mapping was read from file
196   // for each event, so now we read in the map here and set if for 
197   // the raw data qa
198   const Bool_t expert   = kTRUE ; 
199   const Bool_t saveCorr = kTRUE ; 
200   const Bool_t image    = kTRUE ; 
201   
202   // It might happen that we will be in this method a few times
203   // (we create the dataQA at the first call to this method)
204   if(!fTPCdataQA) {
205     fTPCdataQA = new AliTPCdataQA();
206     LoadMaps(); // Load Altro maps
207     fTPCdataQA->SetAltroMapping(fMapping); // set Altro mapping
208     fTPCdataQA->SetRangeTime(fRawFirstTimeBin, fRawLastTimeBin); // set time bin interval 
209     fTPCdataQA->SetIsDQM(kTRUE);
210   }
211
212   TProfile * histRawsOccupancyVsSector = 
213     new TProfile("hRawsOccupancyVsSector", "Occupancy vs sector; Sector; Occupancy",
214              72, 0, 72);
215   histRawsOccupancyVsSector->SetMarkerStyle(20);
216   histRawsOccupancyVsSector->SetOption("P");
217   histRawsOccupancyVsSector->SetStats(kFALSE);
218   Add2RawsList(histRawsOccupancyVsSector, kRawsOccupancyVsSector, !expert, image, !saveCorr);
219   
220   TProfile * histRawsQVsSector = 
221     new TProfile("hRawsQVsSector", "<Q> vs sector; Sector; <Q>",
222              72, 0, 72);
223   Add2RawsList(histRawsQVsSector, kRawsQVsSector, expert, !image, !saveCorr);
224
225   TProfile * histRawsQmaxVsSector = 
226     new TProfile("hRawsQmaxVsSector", "<Qmax> vs sector; Sector; <Qmax>",
227              72, 0, 72);
228   histRawsQmaxVsSector->SetMarkerStyle(20);
229   histRawsQmaxVsSector->SetOption("P");
230   histRawsQmaxVsSector->SetStats(kFALSE);
231   Add2RawsList(histRawsQmaxVsSector, kRawsQmaxVsSector, !expert, image, !saveCorr);
232   //
233   ClonePerTrigClass(AliQAv1::kRAWS); // this should be the last line
234 }
235
236 //____________________________________________________________________________ 
237 void AliTPCQADataMakerRec::InitDigits()
238 {
239   const Bool_t expert   = kTRUE ; 
240   const Bool_t image    = kTRUE ; 
241   TH1F * histDigitsADC = 
242     new TH1F("hDigitsADC", "Digit ADC distribution; ADC; Counts",
243              1000, 0, 1000);
244   histDigitsADC->Sumw2();
245   Add2DigitsList(histDigitsADC, kDigitsADC, !expert, image);
246   //
247   ClonePerTrigClass(AliQAv1::kDIGITS); // this should be the last line
248 }
249
250 //____________________________________________________________________________ 
251 void AliTPCQADataMakerRec::InitRecPoints()
252 {
253   const Bool_t expert   = kTRUE ; 
254   const Bool_t image    = kTRUE ; 
255   
256   TH1F * histRecPointsQmaxShort = 
257     new TH1F("hRecPointsQmaxShort", "Qmax distrbution (short pads); Qmax; Counts",
258              100, 0, 300);
259   histRecPointsQmaxShort->Sumw2();
260   Add2RecPointsList(histRecPointsQmaxShort, kQmaxShort, !expert, image);
261
262   TH1F * histRecPointsQmaxMedium = 
263     new TH1F("hRecPointsQmaxMedium", "Qmax distrbution (medium pads); Qmax; Counts",
264              100, 0, 300);
265   histRecPointsQmaxMedium->Sumw2();
266   Add2RecPointsList(histRecPointsQmaxMedium, kQmaxMedium, !expert, image);
267
268   TH1F * histRecPointsQmaxLong = 
269     new TH1F("hRecPointsQmaxLong", "Qmax distrbution (long pads); Qmax; Counts",
270              100, 0, 300);
271   histRecPointsQmaxLong->Sumw2();
272   Add2RecPointsList(histRecPointsQmaxLong, kQmaxLong, !expert, image);
273
274   TH1F * histRecPointsQShort = 
275     new TH1F("hRecPointsQShort", "Q distrbution (short pads); Q; Counts",
276              100, 0, 2000);
277   histRecPointsQShort->Sumw2();
278   Add2RecPointsList(histRecPointsQShort, kQShort, !expert, image);
279
280   TH1F * histRecPointsQMedium = 
281     new TH1F("hRecPointsQMedium", "Q distrbution (medium pads); Q; Counts",
282              100, 0, 2000);
283   histRecPointsQMedium->Sumw2();
284   Add2RecPointsList(histRecPointsQMedium, kQMedium, !expert, image);
285
286   TH1F * histRecPointsQLong = 
287     new TH1F("hRecPointsQLong", "Q distrbution (long pads); Q; Counts",
288              100, 0, 2000);
289   histRecPointsQLong->Sumw2();
290   Add2RecPointsList(histRecPointsQLong, kQLong, !expert, image);
291
292   TH1F * histRecPointsRow = 
293     new TH1F("hRecPointsRow", "Clusters per row; Row; Counts",
294              159, 0, 159);
295   histRecPointsRow->Sumw2();
296   Add2RecPointsList(histRecPointsRow, kRow, !expert, image);
297   //
298   ClonePerTrigClass(AliQAv1::kRECPOINTS); // this should be the last line
299 }
300
301 //____________________________________________________________________________
302 void AliTPCQADataMakerRec::MakeESDs(AliESDEvent * esd)
303 {
304   // make QA data from ESDs
305  
306   const Int_t nESDTracks = esd->GetNumberOfTracks();
307   Int_t nTPCtracks = 0; 
308   for(Int_t i = 0; i < nESDTracks; i++) {
309     
310     AliESDtrack * track = esd->GetTrack(i);
311     
312     if ((track->GetStatus() & AliESDtrack::kTPCrefit)==0)
313       continue;
314     
315     nTPCtracks++;
316     
317     Int_t nTPCclusters         = track->GetTPCNcls();
318     Int_t nTPCclustersFindable = track->GetTPCNclsF();
319     if ( nTPCclustersFindable<=0) continue;
320     FillESDsData(kClusters,nTPCclusters);
321     FillESDsData(kRatio,Float_t(nTPCclusters)/Float_t(nTPCclustersFindable));
322     FillESDsData(kPt,track->Pt()); 
323   }
324   //
325   IncEvCountCycleESDs();
326   IncEvCountTotalESDs();
327   //
328 }
329
330 //____________________________________________________________________________
331 void AliTPCQADataMakerRec::MakeRaws(AliRawReader* rawReader)
332 {
333   //
334   // To make QA for the RAW data we use the TPC Calibration framework 
335   // to handle the data and then in the end extract the data
336   //
337   
338   GetRawsData(0); // dummy call to init raw data
339   rawReader->Reset() ; 
340   if (! fTPCdataQA ) {
341
342     AliError("No TPC data QA (no call to InitRaws?)!!!!") ; 
343   } else {  
344
345     if(fTPCdataQA->GetIsDQM() == kFALSE)
346       AliError("Data QA has to be initialized as DQM!!!!") ; 
347
348     // Fill profile data
349     fTPCdataQA->ResetProfiles();
350     
351     if(fTPCdataQA->ProcessEvent(rawReader)) { // means that TPC data was processed  
352
353       fTPCdataQA->FillOccupancyProfile();
354       
355       // Fill histograms    
356       TObjArray *arrRW = GetMatchingRawsData(kRawsOccupancyVsSector); // all kRawsOccupancyVsSector clones matching to triggers
357       for (int ih=arrRW->GetEntriesFast();ih--;) {
358         TProfile* hRawsOccupancyVsSector = dynamic_cast<TProfile*>(arrRW->At(ih));
359         if (hRawsOccupancyVsSector) hRawsOccupancyVsSector->Add(fTPCdataQA->GetHistOccVsSector());
360       }
361       arrRW = GetMatchingRawsData(kRawsQVsSector);
362       for (int ih=arrRW->GetEntriesFast();ih--;) {
363         TProfile* hRawsQVsSector = dynamic_cast<TProfile*>(arrRW->At(ih));
364         if (hRawsQVsSector) hRawsQVsSector->Add(fTPCdataQA->GetHistQVsSector());
365       }
366       arrRW = GetMatchingRawsData(kRawsQmaxVsSector);
367       for (int ih=arrRW->GetEntriesFast();ih--;) {
368         TProfile* hRawsQmaxVsSector = dynamic_cast<TProfile*>(arrRW->At(ih));
369         if (hRawsQmaxVsSector) hRawsQmaxVsSector->Add(fTPCdataQA->GetHistQmaxVsSector());
370       }
371       //
372       IncEvCountCycleRaws();
373       IncEvCountTotalRaws();
374       //
375     }
376   }
377 }
378
379 //____________________________________________________________________________
380 void AliTPCQADataMakerRec::MakeDigits(TTree* digitTree)
381 {
382  
383   TBranch* branch = digitTree->GetBranch("Segment");
384   AliSimDigits* digArray = 0;
385   branch->SetAddress(&digArray);
386   
387   Int_t nEntries = Int_t(digitTree->GetEntries());
388   
389   for (Int_t n = 0; n < nEntries; n++) {
390     
391     digitTree->GetEvent(n);
392     
393     if (digArray->First())
394       do {
395         Float_t dig = digArray->CurrentDigit();
396         
397         FillDigitsData(kDigitsADC,dig);
398       } while (digArray->Next());    
399   }
400   //
401   IncEvCountCycleDigits();
402   IncEvCountTotalDigits();
403   //
404 }
405
406 //____________________________________________________________________________
407 void AliTPCQADataMakerRec::MakeRecPoints(TTree* recTree)
408 {
409   
410   AliTPCClustersRow* clrow = 0x0;
411   TBranch* branch = recTree->GetBranch("Segment");  
412   branch->SetAddress(&clrow);
413   TClonesArray * clarray = 0x0;
414
415   const Int_t nEntries = Int_t(recTree->GetEntries());
416   for (Int_t i = 0; i < nEntries; i++) {
417     
418     branch->GetEntry(i);
419
420     clarray = clrow->GetArray();
421
422     if (!clarray) continue;
423
424     const Int_t nClusters = clarray->GetEntriesFast();
425     for (Int_t icl=0; icl < nClusters; icl++){
426       
427       AliTPCclusterMI* cluster = 
428         (AliTPCclusterMI*)clarray->At(icl);
429       
430       Float_t Qmax = cluster->GetMax();
431       Float_t Q    = cluster->GetQ();
432       Int_t   row  = cluster->GetRow();
433
434       if(cluster->GetDetector()<36) { // IROC (short pads)
435
436         FillRecPointsData(kQmaxShort,Qmax);
437         FillRecPointsData(kQShort,Q);
438       } else { // OROC (medium and long pads)
439         row += 63;
440         if(cluster->GetRow()<64) { // medium pads
441
442           FillRecPointsData(kQmaxMedium,Qmax);
443           FillRecPointsData(kQMedium,Q);
444         } else { // long pads
445
446           FillRecPointsData(kQmaxLong,Qmax);
447           FillRecPointsData(kQLong,Q);
448         }
449       }
450       
451       FillRecPointsData(kRow,row);
452     } // end loop over clusters
453   } // end loop over tree
454   //
455   IncEvCountCycleRecPoints();
456   IncEvCountTotalRecPoints();
457   //
458 }
459
460 //____________________________________________________________________________
461 void AliTPCQADataMakerRec::LoadMaps()
462 {
463   TString path = gSystem->Getenv("ALICE_ROOT");
464   path += "/TPC/mapping/Patch";
465
466   for(Int_t i = 0; i < 6; i++) {
467
468     if(fMapping[i]!=0) // mapping already loaded
469       continue;
470     TString path2 = path;
471     path2 += i;
472     path2 += ".data";
473     fMapping[i] = new AliTPCAltroMapping(path2.Data());
474   }
475 }
476