]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSQASDDDataMakerRec.cxx
Reducing verbosity
[u/mrichter/AliRoot.git] / ITS / AliITSQASDDDataMakerRec.cxx
1 /**************************************************************************
2  * Copyright(c) 2007-2009, 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 /* $Id$ */
17
18 //  *************************************************************
19 //  Checks the quality assurance 
20 //  by comparing with reference data
21 //  contained in a DB
22 //  -------------------------------------------------------------
23 //  W. Ferrarese + P. Cerello Feb 2008
24 //  M.Siciliano Aug 2008 QA RecPoints 
25 //  INFN Torino
26
27 // --- ROOT system ---
28
29 #include <TProfile2D.h>
30 #include <TH2D.h>
31 #include <TH1F.h>
32 #include <TBranch.h>
33 #include <TTree.h>
34 #include <TGaxis.h>
35 #include <TMath.h>
36 #include <TF1.h>
37 #include <TDirectory.h>
38 #include <TSystem.h>
39 // --- Standard library ---
40
41 // --- AliRoot header files ---
42 #include "AliITSQASDDDataMakerRec.h"
43 #include "AliLog.h"
44 #include "AliQAv1.h"
45 #include "AliQAChecker.h"
46 #include "AliRawReader.h"
47 #include "AliITSRawStream.h"
48 #include "AliITSRawStreamSDD.h"
49 #include "AliITSRawStreamSDDCompressed.h"
50 #include "AliITSDetTypeRec.h"
51 #include "AliITSdigit.h"
52 #include "AliITSRecPoint.h"
53 #include "AliITSgeomTGeo.h"
54 #include "AliCDBManager.h"
55 #include "AliCDBStorage.h"
56 #include "AliCDBEntry.h"
57 #include "Riostream.h"
58 #include "AliITSdigitSDD.h"
59 #include "AliITS.h"
60 #include "AliRunLoader.h"
61 #include "AliITSLoader.h"
62 #include "AliITSDetTypeRec.h"
63
64
65
66 ClassImp(AliITSQASDDDataMakerRec)
67
68 //____________________________________________________________________________ 
69 AliITSQASDDDataMakerRec::AliITSQASDDDataMakerRec(AliITSQADataMakerRec *aliITSQADataMakerRec, Bool_t kMode, Short_t ldc) :
70 TObject(),
71 fAliITSQADataMakerRec(aliITSQADataMakerRec),
72 fkOnline(kMode),
73 fLDC(ldc),
74 fSDDhRawsTask(0),
75 fSDDhDigitsTask(0),
76 fSDDhRecPointsTask(0),
77 fGenRawsOffset(0),
78 fGenDigitsOffset(0),
79 fGenRecPointsOffset(0),
80 fTimeBinSize(1),
81 fDDLModuleMap(0),
82 fGoodAnodes(0),
83 fBadAnodes(0),
84 fGoodAnodesCurrent(0),
85 fBadAnodesCurrent(0)
86 {
87   //ctor used to discriminate OnLine-Offline analysis
88   if(fLDC < 0 || fLDC > 6) {
89         AliError("Error: LDC number out of range; return\n");
90   }
91         fGenRawsOffset = new Int_t[AliRecoParam::kNSpecies];
92         fGenRecPointsOffset = new Int_t[AliRecoParam::kNSpecies];
93         fGenDigitsOffset = new Int_t[AliRecoParam::kNSpecies];
94         for(Int_t i=0; i<AliRecoParam::kNSpecies; i++) {
95                 fGenRawsOffset[i] = 0;
96                 fGenRecPointsOffset[i] = 0;
97                 fGenDigitsOffset[i]=0;
98         }
99 }
100
101 //____________________________________________________________________________ 
102 AliITSQASDDDataMakerRec::AliITSQASDDDataMakerRec(const AliITSQASDDDataMakerRec& qadm) :
103 TObject(),
104 fAliITSQADataMakerRec(qadm.fAliITSQADataMakerRec),
105 fkOnline(qadm.fkOnline),
106 fLDC(qadm.fLDC),
107 fSDDhRawsTask(qadm.fSDDhRawsTask),
108 fSDDhDigitsTask(qadm.fSDDhDigitsTask),
109 fSDDhRecPointsTask(qadm.fSDDhRecPointsTask),
110 fGenRawsOffset(qadm.fGenRawsOffset),
111 fGenDigitsOffset(qadm.fGenDigitsOffset),
112 fGenRecPointsOffset(qadm.fGenRecPointsOffset),
113 fTimeBinSize(1),
114 fDDLModuleMap(0),
115 fGoodAnodes(qadm.fGoodAnodes),
116 fBadAnodes(qadm.fBadAnodes),
117 fGoodAnodesCurrent(qadm.fGoodAnodesCurrent),
118 fBadAnodesCurrent(qadm.fBadAnodesCurrent)
119 {
120   //copy ctor 
121   fAliITSQADataMakerRec->SetName((const char*)qadm.fAliITSQADataMakerRec->GetName()) ; 
122   fAliITSQADataMakerRec->SetTitle((const char*)qadm.fAliITSQADataMakerRec->GetTitle());
123   fDDLModuleMap=NULL;
124 }
125
126 //____________________________________________________________________________ 
127 AliITSQASDDDataMakerRec::~AliITSQASDDDataMakerRec(){
128   // destructor
129   //if(fDDLModuleMap) delete fDDLModuleMap;
130 }
131 //__________________________________________________________________
132 AliITSQASDDDataMakerRec& AliITSQASDDDataMakerRec::operator = (const AliITSQASDDDataMakerRec& qac )
133 {
134   // Equal operator.
135   this->~AliITSQASDDDataMakerRec();
136   new(this) AliITSQASDDDataMakerRec(qac);
137   return *this;
138 }
139
140 //____________________________________________________________________________ 
141 void AliITSQASDDDataMakerRec::StartOfDetectorCycle()
142 {
143   //Detector specific actions at start of cycle
144   AliDebug(AliQAv1::GetQADebugLevel(),"AliITSQADM::Start of SDD Cycle\n");
145 }
146
147 //____________________________________________________________________________ 
148 void AliITSQASDDDataMakerRec::EndOfDetectorCycle(AliQAv1::TASKINDEX_t /*task*/, TObjArray* /*list*/)
149 {
150   
151   // launch the QA checking
152         if(fkOnline) {
153                 AnalyseBNG(); // Analyse Baseline, Noise, Gain
154                 AnalyseINJ(); // Analyse Injectors
155         }
156   
157         AliDebug(AliQAv1::GetQADebugLevel(),"AliITSDM instantiates checker with Run(AliQAv1::kITS, task, list)\n"); 
158 }
159
160 //____________________________________________________________________________ 
161 Int_t AliITSQASDDDataMakerRec::InitRaws()
162
163   // Initialization for RAW data - SDD -
164   const Bool_t expert   = kTRUE ; 
165   const Bool_t saveCorr = kTRUE ; 
166   const Bool_t image    = kTRUE ; 
167
168
169
170   Int_t rv = 0 ; 
171   /*
172   AliCDBEntry *ddlMapSDD = AliCDBManager::Instance()->Get("ITS/Calib/DDLMapSDD");
173   Bool_t cacheStatus = AliCDBManager::Instance()->GetCacheFlag();
174   if(!ddlMapSDD)
175     {
176       AliError("Calibration object retrieval failed! SDD will not be processed");
177       fDDLModuleMap = NULL;
178       return rv;
179     }
180   fDDLModuleMap = (AliITSDDLModuleMapSDD*)ddlMapSDD->GetObject();
181   if(!cacheStatus)ddlMapSDD->SetObject(NULL);
182   ddlMapSDD->SetOwner(kTRUE);
183   if(!cacheStatus)
184     {
185       delete ddlMapSDD;
186     }
187   */
188   Int_t lay, lad, det;
189   Int_t indexlast = 0;
190   Int_t index1 = 0;
191
192   if(fkOnline) 
193     {
194       AliInfo("Book Online Histograms for SDD\n");
195     }
196   else 
197     {
198       AliInfo("Book Offline Histograms for SDD\n ");
199     }
200   TH1D *h0 = new TH1D("SDDModPattern","HW Modules pattern",fgknSDDmodules,239.5,499.5); //0
201   h0->GetXaxis()->SetTitle("Module Number");
202   h0->GetYaxis()->SetTitle("Counts");
203   rv = fAliITSQADataMakerRec->Add2RawsList(h0,0+fGenRawsOffset[fAliITSQADataMakerRec->GetEventSpecie()], expert, !image, !saveCorr);
204   fSDDhRawsTask++;
205   
206   //zPhi distribution using ladder and modules numbers
207   TH2D *hphil3 = new TH2D("SDDphizL3","SDD #varphiz Layer3 ",12,0.5,6.5,14,0.5,14.5);
208   hphil3->GetXaxis()->SetTitle("z[#Module L3 ]");
209   hphil3->GetYaxis()->SetTitle("#varphi[#Ladder L3]");
210   rv = fAliITSQADataMakerRec->Add2RawsList(hphil3,1+fGenRawsOffset[fAliITSQADataMakerRec->GetEventSpecie()], !expert, image, saveCorr); 
211   fSDDhRawsTask++;
212   
213   TH2D *hphil4 = new TH2D("SDDphizL4","SDD #varphiz Layer4 ",16,0.5,8.5,22,0.5,22.5); 
214   hphil4->GetXaxis()->SetTitle("z[#Module L4]");
215   hphil4->GetYaxis()->SetTitle("#varphi[#Ladder L4]");
216    rv = fAliITSQADataMakerRec->Add2RawsList(hphil4,2+fGenRawsOffset[fAliITSQADataMakerRec->GetEventSpecie()], !expert, image, saveCorr); 
217   fSDDhRawsTask++;
218   
219
220   if(fkOnline) 
221     {
222
223       //DDL Pattern 
224       TH2D *hddl = new TH2D("SDDDDLPattern","SDD DDL Pattern ",24,-0.5,11.5,24,-0.5,23.5); 
225       hddl->GetXaxis()->SetTitle("Channel");
226       hddl->GetYaxis()->SetTitle("#DDL");
227       rv = fAliITSQADataMakerRec->Add2RawsList(hddl,3+fGenRawsOffset[fAliITSQADataMakerRec->GetEventSpecie()], expert, !image, !saveCorr);
228       fSDDhRawsTask++;
229       Int_t indexlast1 = 0;
230   
231       fTimeBinSize = 4;
232       indexlast = 0;
233       index1 = 0;
234       indexlast1 = fSDDhRawsTask;
235       char *hname[3];
236       for(Int_t i=0; i<3; i++) hname[i]= new char[50];
237       for(Int_t moduleSDD =0; moduleSDD<fgknSDDmodules; moduleSDD++){
238         for(Int_t iside=0;iside<fgknSide;iside++){
239           AliITSgeomTGeo::GetModuleId(moduleSDD+fgkmodoffset, lay, lad, det);
240           sprintf(hname[0],"SDDchargeMapFSE_L%d_%d_%d_%d",lay,lad,det,iside);
241           sprintf(hname[1],"SDDChargeMapForSingleEvent_L%d_%d_%d_%d",lay,lad,det,iside);
242           //      sprintf(hname[2],"SDDhmonoDMap_L%d_%d_%d_%d",lay,lad,det,iside);
243           TProfile2D *fModuleChargeMapFSE = new TProfile2D(hname[0],hname[1],256/fTimeBinSize,-0.5,255.5,256,-0.5,255.5);
244           fModuleChargeMapFSE->GetXaxis()->SetTitle("Time Bin");
245           fModuleChargeMapFSE->GetYaxis()->SetTitle("Anode");
246            rv = fAliITSQADataMakerRec->Add2RawsList((new TProfile2D(*fModuleChargeMapFSE)),indexlast1 + index1 + fGenRawsOffset[fAliITSQADataMakerRec->GetEventSpecie()], expert, !image, !saveCorr);
247           delete fModuleChargeMapFSE;
248           
249           fSDDhRawsTask++;
250           index1++;      
251         }
252       }
253       
254       for(Int_t moduleSDD =0; moduleSDD<fgknSDDmodules; moduleSDD++){
255         for(Int_t iside=0;iside<fgknSide;iside++){
256           AliITSgeomTGeo::GetModuleId(moduleSDD+fgkmodoffset, lay, lad, det);
257           sprintf(hname[0],"SDDchargeMap_L%d_%d_%d_%d",lay,lad,det,iside);
258           sprintf(hname[1],"SDDChargeMap_L%d_%d_%d_%d",lay,lad,det,iside);
259           TProfile2D *fModuleChargeMap = new TProfile2D(hname[0],hname[1],256/fTimeBinSize,-0.5,255.5,256,-0.5,255.5);
260           fModuleChargeMap->GetXaxis()->SetTitle("Time Bin");
261           fModuleChargeMap->GetYaxis()->SetTitle("Anode");
262            rv = fAliITSQADataMakerRec->Add2RawsList((new TProfile2D(*fModuleChargeMap)),indexlast1 + index1 + fGenRawsOffset[fAliITSQADataMakerRec->GetEventSpecie()], expert, !image, !saveCorr);
263           delete fModuleChargeMap;
264           
265           fSDDhRawsTask++;
266           index1++;      
267         }
268       }
269       
270       //Event Size 
271       TH1F *hsize = new TH1F("SDDEventSize","SDD Event Size ",1000,-0.5,999.5); 
272       hsize->GetXaxis()->SetTitle("Event Size [kB]");
273       hsize->GetYaxis()->SetTitle("Entries");
274       rv = fAliITSQADataMakerRec->Add2RawsList(hsize,indexlast1 + index1 + fGenRawsOffset[fAliITSQADataMakerRec->GetEventSpecie()], expert, !image, !saveCorr);
275       fSDDhRawsTask++;
276           
277     }  // kONLINE
278   
279   AliDebug(AliQAv1::GetQADebugLevel(),Form("%d SDD Raws histograms booked\n",fSDDhRawsTask));
280   return rv ; 
281 }
282
283
284 //____________________________________________________________________________
285 Int_t AliITSQASDDDataMakerRec::MakeRaws(AliRawReader* rawReader)
286
287   // Fill QA for RAW - SDD -
288         Int_t rv = 0;
289   // Check id histograms already created for this Event Specie
290
291   if(!fDDLModuleMap){
292     CreateTheMap();
293     //AliError("SDD DDL module map not available - skipping SDD QA");
294     //return rv;
295   
296   }
297   if(rawReader->GetType() != 7) return rv;  // skips non physical triggers
298   AliDebug(AliQAv1::GetQADebugLevel(),"entering MakeRaws\n");                 
299   rawReader->Reset();       
300   rawReader->Select("ITSSDD");
301   AliITSRawStream *stream=AliITSRawStreamSDD::CreateRawStreamSDD(rawReader);
302    stream->SetDDLModuleMap(fDDLModuleMap);
303   
304   Int_t lay, lad, det; 
305   
306   Int_t index=0;
307   if(fkOnline) {
308     for(Int_t moduleSDD =0; moduleSDD<fgknSDDmodules; moduleSDD++){
309       for(Int_t iside=0;iside<fgknSide;iside++) {
310                 if(fSDDhRawsTask > 4 + index) fAliITSQADataMakerRec->GetRawsData(4 + index +fGenRawsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->Reset();   
311         // 4  because the 2D histos for single events start after the fourth position
312         index++;
313       }
314     }
315   }
316   
317   Int_t cnt = 0;
318   Int_t ildcID = -1;
319   Int_t iddl = -1;
320   Int_t isddmod = -1;
321   Int_t coord1, coord2, signal, moduleSDD, activeModule, index1; 
322   //if(fkOnline)
323   //{
324       Int_t prevDDLID = -1;
325       UInt_t size = 0;
326       int totalddl=static_cast<int>(fDDLModuleMap->GetNDDLs());
327       Bool_t *ddldata=new Bool_t[totalddl];
328       for(Int_t jddl=0;jddl<totalddl;jddl++){ddldata[jddl]=kFALSE;}
329       //}
330   while(stream->Next()) {
331     ildcID = rawReader->GetLDCId();
332     iddl = rawReader->GetDDLID();// - fgkDDLIDshift;
333
334
335     isddmod = fDDLModuleMap->GetModuleNumber(iddl,stream->GetCarlosId());
336     if(isddmod==-1){
337       AliDebug(AliQAv1::GetQADebugLevel(),Form("Found module with iddl: %d, stream->GetCarlosId: %d \n",iddl,stream->GetCarlosId()));
338       continue;
339     }
340     if(stream->IsCompletedModule()) {
341       AliDebug(AliQAv1::GetQADebugLevel(),Form("IsCompletedModule == KTRUE\n"));
342       continue;
343     } 
344     if(stream->IsCompletedDDL()) {
345
346       if(fkOnline){
347         if ((rawReader->GetDDLID() != prevDDLID)&&(ddldata[iddl])==kFALSE){
348           size += rawReader->GetDataSize();//in bytes
349           prevDDLID = rawReader->GetDDLID();
350           ddldata[iddl]=kTRUE;
351         }
352       }
353       AliDebug(AliQAv1::GetQADebugLevel(),Form("IsCompletedDDL == KTRUE\n"));
354       continue;
355     } 
356     
357     coord1 = stream->GetCoord1();
358     coord2 = stream->GetCoord2();
359     signal = stream->GetSignal();
360     
361     moduleSDD = isddmod - fgkmodoffset;
362     
363     if(isddmod <fgkmodoffset|| isddmod>fgknSDDmodules+fgkmodoffset-1) {
364       AliDebug(AliQAv1::GetQADebugLevel(),Form( "Module SDD = %d, resetting it to 1 \n",isddmod));
365       isddmod = 1;
366     }
367     
368     AliITSgeomTGeo::GetModuleId(isddmod, lay, lad, det);
369     Short_t iside = stream->GetChannel();
370
371     //printf(" \n%i %i %i %i \n ",lay, lad, det,iside );
372     fAliITSQADataMakerRec->GetRawsData( 0 + fGenRawsOffset[fAliITSQADataMakerRec->GetEventSpecie()] )->Fill(isddmod);   
373     if(lay==3)    fAliITSQADataMakerRec->GetRawsData(1+fGenRawsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->Fill(det+0.5*iside-0.5,lad); 
374     if(lay==4) { 
375       fAliITSQADataMakerRec->GetRawsData(2+fGenRawsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->Fill(det+0.5*iside-0.5,lad);}  
376  
377     if(fkOnline) {
378
379       fAliITSQADataMakerRec->GetRawsData(3+fGenRawsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->Fill((stream->GetCarlosId())+0.5*iside -0.5,iddl);
380
381       activeModule = moduleSDD;
382       index1 = activeModule * 2 + iside;
383       
384       if(index1<0){
385         AliDebug(AliQAv1::GetQADebugLevel(),Form("Wrong index number %d - patched to 0\n",index1));
386         index1 = 0;
387       }      
388
389       if(fSDDhRawsTask > 4 + index1) {                                  
390         ((TProfile2D *)(fAliITSQADataMakerRec->GetRawsData(4 + index1 +fGenRawsOffset[fAliITSQADataMakerRec->GetEventSpecie()])))->Fill(coord2, coord1, signal);     
391         ((TProfile2D *)(fAliITSQADataMakerRec->GetRawsData(4 + index1 + 260*2 +fGenRawsOffset[fAliITSQADataMakerRec->GetEventSpecie()])))->Fill(coord2, coord1, signal); 
392       }
393
394     }//online
395     cnt++;
396     if(!(cnt%10000)) AliDebug(AliQAv1::GetQADebugLevel(),Form(" %d raw digits read",cnt));
397   }//end next()
398   if(fkOnline)
399     {
400       ((TH1F*)(fAliITSQADataMakerRec->GetRawsData(4 + 260*4 +fGenRawsOffset[fAliITSQADataMakerRec->GetEventSpecie()])))->Fill(size/1024.);//KB
401     }
402   AliDebug(AliQAv1::GetQADebugLevel(),Form("Event completed, %d raw digits read",cnt)); 
403   delete stream;
404   stream = NULL; 
405
406 //      if(fkOnline) {
407 //              AnalyseBNG(); // Analyse Baseline, Noise, Gain
408 //              AnalyseINJ(); // Analyse Injectors
409 //      }
410
411   delete []ddldata;
412   ddldata=NULL;
413   return rv ; 
414 }
415
416 //____________________________________________________________________________ 
417 Int_t AliITSQASDDDataMakerRec::InitDigits()
418
419
420
421   // Initialization for DIGIT data - SDD -  
422   const Bool_t expert   = kTRUE ; 
423   const Bool_t image    = kTRUE ;
424   Int_t rv = 0 ; 
425 //  fGenDigitsOffset = (fAliITSQADataMakerRec->fDigitsQAList[AliRecoParam::kDefault])->GetEntries();
426   //fSDDhTask must be incremented by one unit every time a histogram is ADDED to the QA List
427   TH1F* h0=new TH1F("SDD DIGITS Module Pattern","SDD DIGITS Module Pattern",260,239.5,499.5);       //hmod
428   h0->GetXaxis()->SetTitle("SDD Module Number");
429   h0->GetYaxis()->SetTitle("# DIGITS");
430   rv = fAliITSQADataMakerRec->Add2DigitsList(h0,fGenDigitsOffset[fAliITSQADataMakerRec->GetEventSpecie()], !expert, image);
431   fSDDhDigitsTask ++;
432   // printf("Add %s \t the task offset is %i\n",fAliITSQADataMakerRec->GetDigitsData(fGenDigitsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->GetName() , fSDDhDigitsTask );
433   TH1F* h1=new TH1F("SDD Anode Distribution","DIGITS Anode Distribution",512,-0.5,511.5);      //hanocc
434   h1->GetXaxis()->SetTitle("Anode Number");
435   h1->GetYaxis()->SetTitle("# DIGITS");
436   rv = fAliITSQADataMakerRec->Add2DigitsList(h1,1+fGenDigitsOffset[fAliITSQADataMakerRec->GetEventSpecie()], !expert, image);
437   fSDDhDigitsTask ++;
438   //printf("Add %s \t the task offset is %i\n",fAliITSQADataMakerRec->GetDigitsData(1+fGenDigitsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->GetName() , fSDDhDigitsTask );
439   TH1F* h2=new TH1F("SDD Tbin Distribution","DIGITS Tbin Distribution",256,-0.5,255.5);      //htbocc
440   h2->GetXaxis()->SetTitle("Tbin Number");
441   h2->GetYaxis()->SetTitle("# DIGITS");
442   rv = fAliITSQADataMakerRec->Add2DigitsList(h2,2+fGenDigitsOffset[fAliITSQADataMakerRec->GetEventSpecie()], !expert, image);
443   fSDDhDigitsTask ++;
444   //printf("Add %s \t the task offset is %i\n",fAliITSQADataMakerRec->GetDigitsData(2+fGenDigitsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->GetName() , fSDDhDigitsTask );
445   TH1F* h3=new TH1F("SDD ADC Counts Distribution","DIGITS ADC Counts Distribution",200,0.,1024.);          //hsig
446   h3->GetXaxis()->SetTitle("ADC Value");
447   h3->GetYaxis()->SetTitle("# DIGITS");
448   rv = fAliITSQADataMakerRec->Add2DigitsList(h3,3+fGenDigitsOffset[fAliITSQADataMakerRec->GetEventSpecie()], !expert, image);
449   fSDDhDigitsTask ++;
450   //printf("Add %s \t the task offset is %i\n",fAliITSQADataMakerRec->GetDigitsData(3+fGenDigitsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->GetName() , fSDDhDigitsTask );
451   AliDebug(AliQAv1::GetQADebugLevel(),Form("%d SDD Digits histograms booked\n",fSDDhDigitsTask));
452   return rv ; 
453 }
454
455 //____________________________________________________________________________
456 Int_t AliITSQASDDDataMakerRec::MakeDigits(TTree * digits)
457
458
459   // Fill QA for DIGIT - SDD -
460   //AliITS *fITS  = (AliITS*)gAlice->GetModule("ITS");
461   //fITS->SetTreeAddress();
462   //TClonesArray *iITSdigits  = fITS->DigitsAddress(1);
463
464
465   Int_t rv = 0 ; 
466
467   TBranch *branchD = digits->GetBranch("ITSDigitsSDD");
468
469   if (!branchD) {
470     AliError("can't get the branch with the ITS SDD digits !");
471     return rv ;
472   }
473   // Check id histograms already created for this Event Specie
474 //  if ( ! fAliITSQADataMakerRec->GetDigitsData(fGenDigitsOffset) )
475 //    rv = InitDigits() ;
476   
477   static TClonesArray statDigits("AliITSdigitSDD");
478   TClonesArray *iITSdigits = &statDigits;
479   branchD->SetAddress(&iITSdigits);
480
481   for(Int_t i=0; i<260; i++){
482     Int_t nmod=i+240;
483     digits->GetEvent(nmod);
484     Int_t ndigits = iITSdigits->GetEntries();
485     fAliITSQADataMakerRec->GetDigitsData(fGenDigitsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->Fill(nmod,ndigits);
486
487     for (Int_t idig=0; idig<ndigits; idig++) {
488       AliITSdigit *dig=(AliITSdigit*)iITSdigits->UncheckedAt(idig);
489       Int_t iz=dig->GetCoord1();  // cell number z
490       Int_t ix=dig->GetCoord2();  // cell number x
491       Int_t sig=dig->GetSignal();
492       fAliITSQADataMakerRec->GetDigitsData(1+fGenDigitsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->Fill(iz);
493       fAliITSQADataMakerRec->GetDigitsData(2+fGenDigitsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->Fill(ix);
494       fAliITSQADataMakerRec->GetDigitsData(3+fGenDigitsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->Fill(sig);
495     }
496   }
497   return rv ; 
498 }
499
500 //____________________________________________________________________________ 
501 Int_t AliITSQASDDDataMakerRec::InitRecPoints()
502 {
503
504         //AliInfo("Initialize SDD recpoints histos\n");
505   // Initialization for RECPOINTS - SDD -
506   const Bool_t expert   = kTRUE ; 
507   const Bool_t image    = kTRUE ; 
508   Int_t rv = 0 ; 
509 //  fGenRecPointsOffset = (fAliITSQADataMakerRec->fRecPointsQAList[AliRecoParam::kDefault])->GetEntries();
510
511   Int_t nOnline=1;
512   Int_t  nOnline2=1;
513   Int_t  nOnline3=1; 
514   Int_t  nOnline4=1;
515   if(fkOnline)
516     {
517       nOnline=4;
518       nOnline2=28;
519       nOnline3=64;
520       nOnline4=14;
521     }
522
523   //AliInfo(Form("fAliITSQADataMakerRec->GetEventSpecie() %d\n",fAliITSQADataMakerRec->GetEventSpecie()));
524   //AliInfo(Form("fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()] %d\n",fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()]));
525   TH1F *h0 = new TH1F("SDDLay3TotCh","Layer 3 total charge",1000/nOnline,-0.5, 499.5); //position number 0
526   h0->GetXaxis()->SetTitle("ADC value");
527   h0->GetYaxis()->SetTitle("Entries");
528   rv = fAliITSQADataMakerRec->Add2RecPointsList(h0, 0 +fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()], !expert, image);
529   fSDDhRecPointsTask++;
530  
531   TH1F *h1 = new TH1F("SDDLay4TotCh","Layer 4 total charge",1000/nOnline,-0.5, 499.5);//position number 1
532   h1->GetXaxis()->SetTitle("ADC value");
533   h1->GetYaxis()->SetTitle("Entries");
534   rv = fAliITSQADataMakerRec->Add2RecPointsList(h1, 1 +fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()], !expert, image);
535   fSDDhRecPointsTask++;
536
537   char hisnam[50];
538   TH2F *h2 = new TH2F("SDDGlobalCoordDistribYX","YX Global Coord Distrib",5600/nOnline2,-28,28,5600/nOnline2,-28,28);//position number 2
539   h2->GetYaxis()->SetTitle("Y[cm]");
540   h2->GetXaxis()->SetTitle("X[cm]");
541   rv = fAliITSQADataMakerRec->Add2RecPointsList(h2,2+fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()], !expert, !image);
542   fSDDhRecPointsTask++;
543
544   TH2F *h3 = new TH2F("SDDGlobalCoordDistribRZ","RZ Global Coord Distrib",6400/nOnline3,-32,32,1400/nOnline4,12,26);//position number 3
545   h3->GetYaxis()->SetTitle("R[cm]");
546   h3->GetXaxis()->SetTitle("Z[cm]");
547   rv = fAliITSQADataMakerRec->Add2RecPointsList(h3,3+fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()], !expert, !image);
548   fSDDhRecPointsTask++;
549   
550   TH2F *h4 = new TH2F("SDDGlobalCoordDistribL3PHIZ","#varphi Z Global Coord Distrib L3",6400/nOnline3,-32,32,360/nOnline,-TMath::Pi(),TMath::Pi());//position number 4
551   h4->GetYaxis()->SetTitle("#phi[rad]");
552   h4->GetXaxis()->SetTitle("Z[cm]");
553   rv = fAliITSQADataMakerRec->Add2RecPointsList(h4,4+fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()], !expert, image);
554   fSDDhRecPointsTask++;
555
556   TH2F *h5 = new TH2F("SDDGlobalCoordDistribL4PHIZ","#varphi Z Global Coord Distrib L4",6400/nOnline3,-32,32,360/nOnline,-TMath::Pi(),TMath::Pi());//position number 5
557   h5->GetYaxis()->SetTitle("#phi[rad]");
558   h5->GetXaxis()->SetTitle("Z[cm]");
559   rv = fAliITSQADataMakerRec->Add2RecPointsList(h5,5+fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()], !expert, image);
560   fSDDhRecPointsTask++;
561   
562   TH1F *h6 = new TH1F("SDDModPatternRP","Modules pattern RP",fgknSDDmodules,239.5,499.5); //position number 6
563   h6->GetXaxis()->SetTitle("Module number"); //spd offset = 240
564   h6->GetYaxis()->SetTitle("Entries");
565   rv = fAliITSQADataMakerRec->Add2RecPointsList(h6,6 +fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()], expert, !image);
566   fSDDhRecPointsTask++;
567
568   TH1F *h7 = new TH1F("SDDLadPatternL3RP","Ladder pattern L3 RP",14,0.5,14.5);  //position number 7
569   h7->GetXaxis()->SetTitle("Ladder #, Layer 3");
570   h7->GetYaxis()->SetTitle("Entries");
571   rv = fAliITSQADataMakerRec->Add2RecPointsList(h7,7 +fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()], expert, !image);
572   fSDDhRecPointsTask++;
573
574   TH1F *h8 = new TH1F("SDDLadPatternL4RP","Ladder pattern L4 RP",22,0.5,22.5); //position number 8
575   h8->GetXaxis()->SetTitle("Ladder #, Layer 4");
576   h8->GetYaxis()->SetTitle("Entries");
577   rv = fAliITSQADataMakerRec->Add2RecPointsList(h8,8 +fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()], expert, !image);
578   fSDDhRecPointsTask++;
579
580   TH2F *h9 = new TH2F("SDDLocalCoordDistrib","Local Coord Distrib",1000/nOnline,-4,4,1000/nOnline,-4,4);//position number 9
581   h9->GetXaxis()->SetTitle("X local coord, drift, cm");
582   h9->GetYaxis()->SetTitle("Z local coord, anode, cm");
583   rv = fAliITSQADataMakerRec->Add2RecPointsList(h9,9 +fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()], expert, !image);
584   fSDDhRecPointsTask++;
585   
586   //AliInfo("Create SDD recpoints histos\n");
587   
588   TH1F *h10 = new TH1F("SDDrdistrib_Layer3" ,"SDD r distribution Layer3" ,100,14.,18.);//position number 10 (L3)
589   h10->GetXaxis()->SetTitle("r[cm]");
590   h10->GetXaxis()->CenterTitle();
591   h10->GetYaxis()->SetTitle("Entries");
592   rv = fAliITSQADataMakerRec->Add2RecPointsList(h10,10 +fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()], expert, !image);
593   fSDDhRecPointsTask++;
594   
595   TH1F *h11 = new TH1F("SDDrdistrib_Layer4" ,"SDD r distribution Layer4" ,100,22.,26.);// and position number 11 (L4)
596   h11->GetXaxis()->SetTitle("r[cm]");
597   h11->GetXaxis()->CenterTitle();
598   h11->GetYaxis()->SetTitle("Entries");
599   rv = fAliITSQADataMakerRec->Add2RecPointsList(h11,11 +fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()], expert, !image);
600   fSDDhRecPointsTask++;
601   
602   for(Int_t iLay=0; iLay<=1; iLay++){
603     sprintf(hisnam,"SDDphidistrib_Layer%d",iLay+3);
604     TH1F *h12 = new TH1F(hisnam,hisnam,180,-TMath::Pi(),TMath::Pi());//position number 12 (L3) and position number 13 (L4)
605     h12->GetXaxis()->SetTitle("#varphi[rad]");
606     h12->GetXaxis()->CenterTitle();
607     h12->GetYaxis()->SetTitle("Entries");
608     rv = fAliITSQADataMakerRec->Add2RecPointsList(h12,iLay+12+fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()], expert, !image);
609     fSDDhRecPointsTask++;
610   }
611   
612   for(Int_t iLay=0; iLay<=1; iLay++){
613     sprintf(hisnam,"SDDdrifttime_Layer%d",iLay+3);
614     TH1F *h14 = new TH1F(hisnam,hisnam,200,-0.5,9999.5);//position number 14 (L3) and position number 15 (L4)
615     h14->GetXaxis()->SetTitle("#varphi[rad]");
616     h14->GetXaxis()->CenterTitle();
617     h14->GetYaxis()->SetTitle("Entries");
618     rv = fAliITSQADataMakerRec->Add2RecPointsList(h14,iLay+14+fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()], !expert, image);
619     fSDDhRecPointsTask++;
620   }
621   
622   if(fkOnline)
623     {
624       TH2F *h16 = new TH2F("SDDGlobalCoordDistribYXFSE","YX Global Coord Distrib FSE",5600/nOnline2,-28,28,5600/nOnline2,-28,28);//position number 16
625       h16->GetYaxis()->SetTitle("Y[cm]");
626       h16->GetXaxis()->SetTitle("X[cm]");
627       rv = fAliITSQADataMakerRec->Add2RecPointsList(h16,16+fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()], expert, !image);
628       fSDDhRecPointsTask++;
629       
630       TH2F *h17 = new TH2F("SDDGlobalCoordDistribRZFSE","RZ Global Coord Distrib FSE",Int_t(6400/nOnline3),-32,32,1400/nOnline4,12,26);//position number 17
631       h17->GetYaxis()->SetTitle("R[cm]");
632       h17->GetXaxis()->SetTitle("Z[cm]");
633       rv = fAliITSQADataMakerRec->Add2RecPointsList(h17,17+fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()], expert, !image);
634       fSDDhRecPointsTask++;
635       
636     }//online
637   
638   AliDebug(AliQAv1::GetQADebugLevel(),Form("%d SDD Recs histograms booked\n",fSDDhRecPointsTask));
639   
640   return rv ; 
641 }
642
643 //____________________________________________________________________________ 
644 Int_t AliITSQASDDDataMakerRec::MakeRecPoints(TTree * clustersTree)
645 {
646  // Fill QA for RecPoints - SDD -
647   Int_t rv = 0 ; 
648
649   Int_t lay, lad, det; 
650   //AliInfo("get the branch with the ITS clusters !\n");
651   TBranch *branchRecP = clustersTree->GetBranch("ITSRecPoints");
652   if (!branchRecP) {
653     AliError("can't get the branch with the ITS clusters !");
654     return rv ;
655   }
656
657   static TClonesArray statRecpoints("AliITSRecPoint") ;
658   TClonesArray *recpoints = &statRecpoints;
659   branchRecP->SetAddress(&recpoints);
660   Int_t npoints = 0;      
661   Float_t cluglo[3]={0.,0.,0.}; 
662   if(fkOnline)
663     {
664       for(Int_t i=16;i<18;i++)
665         {
666           fAliITSQADataMakerRec->GetRecPointsData(i+fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->Reset();
667         }
668     }
669   for(Int_t module=0; module<clustersTree->GetEntries();module++){
670     //AliInfo(Form("Module %d\n",module));
671     branchRecP->GetEvent(module);
672     npoints += recpoints->GetEntries();
673     //AliInfo(Form("modnumb %d, npoints %d, total points %d\n",module, recpoints->GetEntries(),npoints));
674     AliITSgeomTGeo::GetModuleId(module, lay, lad, det);
675     //AliInfo(Form("modnumb %d, lay %d, lad %d, det %d \n",module, lay, lad, det));
676     
677     //AliInfo(Form("modnumb %d, entries %d\n",module, recpoints->GetEntries()));
678     for(Int_t j=0;j<recpoints->GetEntries();j++){
679       //AliInfo(Form("modnumb %d, entry %d \n",module, j));
680       AliITSRecPoint *recp = (AliITSRecPoint*)recpoints->At(j);    
681       fAliITSQADataMakerRec->GetRecPointsData(6 +fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->Fill(module);//modpatternrp
682       recp->GetGlobalXYZ(cluglo);
683       Float_t rad=TMath::Sqrt(cluglo[0]*cluglo[0]+cluglo[1]*cluglo[1]); 
684       Float_t phi=TMath::ATan2(cluglo[1],cluglo[0]);
685       Float_t drifttime=recp->GetDriftTime();
686       fAliITSQADataMakerRec->GetRecPointsData(9 +fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->Fill(recp->GetDetLocalX(),recp->GetDetLocalZ());//local distribution
687       fAliITSQADataMakerRec->GetRecPointsData(2 +fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->Fill(cluglo[0],cluglo[1]);//global distribution YX
688       fAliITSQADataMakerRec->GetRecPointsData(3 +fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->Fill(cluglo[2],rad);//global distribution rz
689       if(fkOnline) {
690         fAliITSQADataMakerRec->GetRecPointsData(16 +fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->Fill(cluglo[0],cluglo[1]);//global distribution YX FSE
691         fAliITSQADataMakerRec->GetRecPointsData(17 +fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->Fill(cluglo[2],rad);//global distribution rz FSE
692       }
693       if(recp->GetLayer() == 2) {
694         fAliITSQADataMakerRec->GetRecPointsData(0  +fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->Fill(recp->GetQ()) ;//total charge of layer 3
695         fAliITSQADataMakerRec->GetRecPointsData(7  +fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->Fill(lad);//lad pattern layer 3
696         fAliITSQADataMakerRec->GetRecPointsData(10 +fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->Fill(rad);//r distribution layer 3
697         fAliITSQADataMakerRec->GetRecPointsData(12 +fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->Fill(phi);// phi distribution layer 3
698         fAliITSQADataMakerRec->GetRecPointsData(4  +fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->Fill(cluglo[2],phi);// zphi distribution layer
699         fAliITSQADataMakerRec->GetRecPointsData(14  +fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->Fill(drifttime);// time distribution layer 3
700       } else if(recp->GetLayer() == 3) {
701         fAliITSQADataMakerRec->GetRecPointsData(1  +fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->Fill(recp->GetQ()) ;//total charge layer 4
702         fAliITSQADataMakerRec->GetRecPointsData(8  +fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->Fill(lad);//ladpatternlayer4
703         fAliITSQADataMakerRec->GetRecPointsData(11 +fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->Fill(rad);//r distribution
704         fAliITSQADataMakerRec->GetRecPointsData(13 +fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->Fill(phi);//phi distribution
705         fAliITSQADataMakerRec->GetRecPointsData(5  +fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->Fill(cluglo[2],phi);// zphi distribution layer 4
706         fAliITSQADataMakerRec->GetRecPointsData(15  +fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()])->Fill(drifttime);// time distribution layer 4
707       }
708     }
709   }
710   statRecpoints.Clear();
711   return rv ; 
712 }
713
714 //_______________________________________________________________
715
716 Int_t AliITSQASDDDataMakerRec::GetOffset(AliQAv1::TASKINDEX_t task)
717 {
718   Int_t offset=0;
719   if( task == AliQAv1::kRAWS )
720     {
721       offset=fGenRawsOffset[fAliITSQADataMakerRec->GetEventSpecie()];  
722     }
723   else if(task == AliQAv1::kDIGITSR )
724     {
725       offset=fGenDigitsOffset[fAliITSQADataMakerRec->GetEventSpecie()];
726     }
727   else if( task == AliQAv1::kRECPOINTS )
728     {
729       offset=fGenRecPointsOffset[fAliITSQADataMakerRec->GetEventSpecie()];   
730     }
731   return offset;
732 }
733
734 //_______________________________________________________________
735
736 void AliITSQASDDDataMakerRec::SetOffset(AliQAv1::TASKINDEX_t task, Int_t offset, Int_t specie) {
737   // Returns offset number according to the specified task
738   if( task == AliQAv1::kRAWS ) {
739     fGenRawsOffset[specie]=offset;
740   }
741   else if( task == AliQAv1::kDIGITSR ) {
742     fGenDigitsOffset[specie]=offset;
743   }
744   else if( task == AliQAv1::kRECPOINTS ) {
745     fGenRecPointsOffset[specie]=offset;
746   }
747 }
748
749 //_______________________________________________________________
750
751 Int_t AliITSQASDDDataMakerRec::GetTaskHisto(AliQAv1::TASKINDEX_t task)
752 {
753
754   Int_t histotot=0;
755
756   if( task == AliQAv1::kRAWS )
757     {
758       histotot=fSDDhRawsTask ;  
759     }
760   else if(task == AliQAv1::kDIGITSR)
761     {
762       histotot=fSDDhDigitsTask;
763     }
764   else if( task == AliQAv1::kRECPOINTS )
765     {
766       histotot=fSDDhRecPointsTask;   
767     }
768   else {
769     AliInfo("No task has been selected. TaskHisto set to zero.\n");
770   }
771   return histotot;
772 }
773
774 //_______________________________________________________________
775
776 void AliITSQASDDDataMakerRec::AnalyseBNG()
777 {
778
779 // get file time for Previous test
780         AliInfo("AnalyseBNG\n");
781         Int_t bngtimeBasPrevious; 
782         FILE *fpinPreviousBas = fopen( "SDDbasHistos.time", "r" );
783         if(fpinPreviousBas) {
784           fscanf(fpinPreviousBas,"%d",&bngtimeBasPrevious);
785           fclose (fpinPreviousBas);
786         } else 
787           bngtimeBasPrevious = 0;
788         Int_t bngtimeBasCurrent = 0; 
789         gSystem->Exec("perl -e '@d=localtime ((stat(shift))[9]); printf \"%02d%02d%02d%02d%02d\n\", $d[5]-100,$d[4]+1,$d[3],$d[2],$d[1]'  SDDbasHistos.root > SDDbasHistos.time");
790         FILE *fpinBas = fopen( "SDDbasHistos.time", "r" );
791         fscanf(fpinBas,"%d",&bngtimeBasCurrent);
792         if(bngtimeBasCurrent>bngtimeBasPrevious )AliInfo(Form("bngtimeBasCurrent %d, bngtimeBasPrevious %d\n",bngtimeBasCurrent,bngtimeBasPrevious));
793        
794         Bool_t kAnalyseBas = kTRUE;
795         if(bngtimeBasCurrent <= bngtimeBasPrevious) kAnalyseBas = kFALSE;
796         if(kAnalyseBas) {
797                 // new bng file found
798                 bngtimeBasPrevious = bngtimeBasCurrent;
799                 Bool_t kFilesExist = kTRUE;
800                 TFile basFile("SDDbasHistos.root");
801                 if(basFile.IsZombie()) kFilesExist = kFALSE;
802                 if(kFilesExist) {
803                   AnodeStatus();
804                   AnalyseHistos(1); // Baseline
805                   AnalyseHistos(2); // Uncorrected Noise
806                   AnalyseHistos(3); // Common Mode Noise
807                   AnalyseHistos(4); // Corrected Noise
808                   gSystem->Exec("cp SDDbasHistos.root SDDbasHistosPrevious.root");
809                 } else {
810                         AliInfo("file SDDbasHistos.root not found \n");
811                 }
812         }
813         fclose (fpinBas);
814 //      delete fpinBas;
815
816         Int_t bngtimeGainPrevious; 
817         FILE *fpinPrevious = fopen( "SDDgainHistos.time", "r" );
818         if(fpinPrevious) {
819           fscanf(fpinPrevious,"%d",&bngtimeGainPrevious);
820           fclose (fpinPrevious);
821         } else 
822           bngtimeGainPrevious = 0;
823         Int_t bngtimeGainCurrent = 0; 
824         gSystem->Exec("perl -e '@d=localtime ((stat(shift))[9]); printf \"%02d%02d%02d%02d%02d\n\", $d[5]-100,$d[4]+1,$d[3],$d[2],$d[1]'  SDDgainHistos.root > SDDgainHistos.time");
825         FILE *fpin = fopen( "SDDgainHistos.time", "r" );
826         fscanf(fpin,"%d",&bngtimeGainCurrent);
827         if(bngtimeGainCurrent>bngtimeGainPrevious )AliInfo(Form("bngtimeGainCurrent %d, bngtimeGainPrevious %d\n",bngtimeGainCurrent,bngtimeGainPrevious));
828        
829         Bool_t kAnalyse = kTRUE;
830         if(bngtimeGainCurrent <= bngtimeGainPrevious) kAnalyse = kFALSE;
831         if(kAnalyse) {
832                 // new bng file found
833                 bngtimeGainPrevious = bngtimeGainCurrent;
834                 Bool_t kFilesExist = kTRUE;
835                 TFile gainFile("SDDgainHistos.root");
836                 if(gainFile.IsZombie()) kFilesExist = kFALSE;
837                 if(kFilesExist) {
838                   AnalyseHistos(5); // Gain
839                   gSystem->Exec("cp SDDgainHistos.root SDDgainHistosPrevious.root");
840                 } else {
841                         AliInfo("file SDDgainHistos.root not found \n");
842                 }
843         }
844         fclose (fpin);
845 //      delete fpin;
846
847 }
848
849 //_______________________________________________________________
850
851 void AliITSQASDDDataMakerRec::AnalyseINJ()
852 {
853 // get file time for last test
854
855         AliInfo("AnalyseINJ\n");
856         Int_t injtimePrevious; 
857         FILE *fpinPrevious = fopen( "SDDinjectHistos.time", "r" );
858         if(fpinPrevious) {
859           fscanf(fpinPrevious,"%d",&injtimePrevious);
860           fclose (fpinPrevious);
861         } else 
862           injtimePrevious = 0;
863         Int_t injtimeCurrent = 0; 
864         gSystem->Exec("perl -e '@d=localtime ((stat(shift))[9]); printf \"%02d%02d%02d%02d%02d\n\", $d[5]-100,$d[4]+1,$d[3],$d[2],$d[1]'  SDDinjectHistos.root > SDDinjectHistos.time");
865         FILE *fpin = fopen( "SDDinjectHistos.time", "r" );
866         fscanf(fpin,"%d",&injtimeCurrent);
867         if(injtimeCurrent>injtimePrevious )AliInfo(Form("injtimeCurrent %d, injtimePrevious %d\n",injtimeCurrent,injtimePrevious));
868        
869         Bool_t kAnalyse = kTRUE;
870         if(injtimeCurrent <= injtimePrevious) kAnalyse = kFALSE;
871         if(kAnalyse) {
872                 // new inj file found
873                 injtimePrevious = injtimeCurrent;
874                 Bool_t kFilesExist = kTRUE;
875                 TFile gainFile("SDDinjectHistos.root");
876                 if(gainFile.IsZombie()) kFilesExist = kFALSE;
877                 
878                 if(kFilesExist) {
879                         AnalyseHistos(6); // Drift Speed
880                         gSystem->Exec("cp SDDinjectHistos.root SDDinjectHistosPrevious.root");
881                 } else {
882                         AliInfo("file(s) SDDinjectHistos.root not found \n");
883                 }
884         }
885         fclose (fpin);
886 //      delete fpin;
887 }
888
889 //_______________________________________________________________
890
891 void AliITSQASDDDataMakerRec::AnodeStatus()
892 {
893         char *hnamePrevious = new char[50];
894         fGoodAnodes = 0;
895
896         TFile basFilePrevious("SDDbasHistosPrevious.root");
897         if(!basFilePrevious.IsZombie()) {
898           for(Int_t ddl =0; ddl<fDDLModuleMap->GetNDDLs(); ddl++){
899                 for(Int_t crx =0; crx<fDDLModuleMap->GetNModPerDDL(); crx++){
900                         for(Int_t iside=0;iside<fgknSide;iside++){
901                                 Int_t moduleSDD = fDDLModuleMap->GetModuleNumber(ddl,crx);
902                 //AliITSgeomTGeo::GetModuleId(moduleSDD+fgkmodoffset, lay, lad, det);
903                                 sprintf(hnamePrevious,"hgood%02dc%02ds%d",ddl,crx,iside);
904                         //AliInfo(Form("get histo %s\n",hnamePrevious));
905                                 TH1F *hgood = (TH1F *) basFilePrevious.Get(hnamePrevious);
906                                 if(!hgood) continue;
907                                 for(Int_t i=0; i<hgood->GetNbinsX();i++) {
908                                         fkAnodeMap[moduleSDD-fgkmodoffset][iside][i] = hgood->GetBinContent(i);
909                                         if(fkAnodeMap[moduleSDD-fgkmodoffset][iside][i]) fGoodAnodes++;
910                                 }
911                                 delete hgood;
912                         }
913                 }
914           }
915           basFilePrevious.Close();
916         }
917         fGoodAnodesCurrent = 0;
918         fBadAnodesCurrent = 0;
919         char *hname = new char[50];
920         Int_t nChangedStatus = 0;
921         Bool_t CurrentAnodeMap[fgknSDDmodules][fgknSide][fgknAnode];    
922         TFile basFile("SDDbasHistos.root");
923         if(!basFile.IsZombie()) {
924           for(Int_t ddl =0; ddl<fDDLModuleMap->GetNDDLs(); ddl++){
925                 for(Int_t crx =0; crx<fDDLModuleMap->GetNModPerDDL(); crx++){
926                         for(Int_t iside=0;iside<fgknSide;iside++){
927                                 Int_t moduleSDD = fDDLModuleMap->GetModuleNumber(ddl,crx);
928                         //AliITSgeomTGeo::GetModuleId(moduleSDD+fgkmodoffset, lay, lad, det);
929                                 sprintf(hname,"hgood%02dc%02ds%d",ddl,crx,iside);
930                         //AliInfo(Form("get histo %s\n",hname));
931                                 TH1F *hgood = (TH1F *) basFile.Get(hname);
932                                 if(!hgood) continue;
933                                 for(Int_t i=0; i<hgood->GetNbinsX();i++) {
934                                         CurrentAnodeMap[moduleSDD-fgkmodoffset][iside][i] = hgood->GetBinContent(i);
935                                         if(CurrentAnodeMap[moduleSDD-fgkmodoffset][iside][i]) fGoodAnodesCurrent++;
936                                         else fBadAnodesCurrent++;
937                                         if(CurrentAnodeMap[moduleSDD-fgkmodoffset][iside][i] != fkAnodeMap[moduleSDD-fgkmodoffset][iside][i]) {
938                                                 fkAnodeMap[moduleSDD-fgkmodoffset][iside][i] = CurrentAnodeMap[moduleSDD-fgkmodoffset][iside][i];
939                                                 nChangedStatus++;
940                                                 //      AliWarning(Form("DDL %d, CRX %d, Side %d, Anode %d changed status to %d \n",ddl,crx,iside,i,fkAnodeMap[moduleSDD-fgkmodoffset][iside][i]));
941                                         }
942                                 }
943                                 delete hgood;
944                         }
945                 }
946           }
947           basFile.Close();
948         }
949
950         AliWarning(Form("Number of good anodes changed from %d to %d, that is %f %%\n",fGoodAnodes,fGoodAnodesCurrent,((Float_t) TMath::Abs(fGoodAnodes-fGoodAnodesCurrent))/(fBadAnodesCurrent+fGoodAnodesCurrent)));
951         if(fGoodAnodesCurrent != fGoodAnodes) {
952                 fGoodAnodes = fGoodAnodesCurrent;
953         }
954         AliWarning(Form("Number of bad anodes changed from %d to %d, that is %f %%\n",fBadAnodes,fBadAnodesCurrent,((Float_t) TMath::Abs(fBadAnodes-fBadAnodesCurrent))/(fBadAnodesCurrent+fGoodAnodesCurrent)));
955         if(fBadAnodesCurrent != fBadAnodes) {
956                 fBadAnodes = fBadAnodesCurrent;
957         }
958 //      delete hname;
959 }
960
961 //_______________________________________________________________
962
963 void AliITSQASDDDataMakerRec::AnalyseHistos(Int_t type)
964 {
965
966         if(type < 1 || type > 6) {
967           AliWarning(Form("Wrong type (%d), must be between 1 and 6\n",type));
968           return;
969         }
970
971         Double_t Current[fgknSDDmodules][fgknSide][fgknAnode];  
972         char *hnamePrevious = new char[50];
973         TString *fnamePrevious=NULL;
974
975                 if(type < 5) fnamePrevious = new TString("SDDbasHistosPrevious.root");
976                 else if(type == 5) fnamePrevious = new TString("SDDgainHistosPrevious.root");
977                 else if(type == 6) fnamePrevious = new TString("SDDinjectHistosPrevious.root");
978                 TFile *gainFilePrevious = new TFile(fnamePrevious->Data());
979                 if(!gainFilePrevious->IsZombie()) {
980
981                   for(Int_t ddl =0; ddl<fDDLModuleMap->GetNDDLs(); ddl++){
982                     for(Int_t crx =0; crx<fDDLModuleMap->GetNModPerDDL(); crx++){
983                                 for(Int_t iside=0;iside<fgknSide;iside++){
984                                         Int_t moduleSDD = fDDLModuleMap->GetModuleNumber(ddl,crx);
985                         //AliITSgeomTGeo::GetModuleId(moduleSDD+fgkmodoffset, lay, lad, det);
986                                         if(type == 1) sprintf(hnamePrevious,"hbase%02dc%02ds%d",ddl,crx,iside);
987                                         else if(type == 2) sprintf(hnamePrevious,"hnois%02dc%02ds%d",ddl,crx,iside);
988                                         else if(type == 3) sprintf(hnamePrevious,"hcmn%02dc%02ds%d",ddl,crx,iside);
989                                         else if(type == 4) sprintf(hnamePrevious,"hcorn%02dc%02ds%d",ddl,crx,iside);
990                                         else if(type == 5) sprintf(hnamePrevious,"hgain%02dc%02ds%d",ddl,crx,iside);
991                                         else if(type == 6) sprintf(hnamePrevious,"hdrsp%02dc%02ds%d",ddl,crx,iside);
992                                 //AliInfo(Form("get histo %s\n",hnamePrevious));
993                                         TH1F *hhist = (TH1F *) gainFilePrevious->Get(hnamePrevious);
994                                         if(!hhist) continue;
995                                         for(Int_t i=0; i<hhist->GetNbinsX();i++) {
996                                                 Current[moduleSDD-fgkmodoffset][iside][i] = hhist->GetBinContent(i);
997                                         }
998                                         delete hhist;
999                                 }
1000                         }
1001                   }
1002                   gainFilePrevious->Close();
1003                   delete gainFilePrevious;
1004                 }
1005                 delete fnamePrevious;
1006
1007         Float_t xmin = 0.;
1008         Float_t xmax = 0;
1009         Int_t nbins = 1;
1010         TH1F *hDist = 0;
1011         TH1F *hDistDiff = 0;
1012         if(type == 1) {
1013                 xmin = 0.;
1014                 xmax = 500.;
1015                 nbins = (Int_t)(xmax-xmin);
1016                 hDist = new TH1F("hBaseline","Baseline",nbins,xmin,xmax);
1017                 hDistDiff = new TH1F("hBaselineDiff","Baseline Difference",200,-100.,100.);
1018         } else if(type == 2) {
1019                 xmin = 0.;
1020                 xmax = 10.;
1021                 nbins = (Int_t) (100.*(xmax-xmin));
1022                 hDist = new TH1F("hNoiseUnc","Noise (before correction)",nbins,xmin,xmax);
1023                 hDistDiff = new TH1F("hNoiseUncDiff","Noise (before correction) Difference",200,-10.,10.);
1024         } else if(type == 3) {
1025                 xmin = 0.;
1026                 xmax = 10.;
1027                 nbins = (Int_t)( 100.*(xmax-xmin));
1028                 hDist = new TH1F("hNoiseCMN","Noise (common mode)",nbins,xmin,xmax);
1029                 hDistDiff = new TH1F("hNoiseCMNDiff","Noise (common mode) Difference",200,-10.,10.);
1030         } else if(type == 4) {
1031                 xmin = 0.;
1032                 xmax = 10.;
1033                 nbins = (Int_t)(100.*(xmax-xmin));
1034                 hDist = new TH1F("hNoiseCor","Noise (after correction)",nbins,xmin,xmax);
1035                 hDistDiff = new TH1F("hNoiseCorDiff","Noise (after correction) Difference",200,-10.,10.);
1036         } else if(type == 5) {
1037                 xmin = 0.;
1038                 xmax = 5.;
1039                 nbins = (Int_t)(100.*(xmax-xmin));
1040                 hDist = new TH1F("hGain","Gain",nbins,xmin,xmax);
1041                 hDistDiff = new TH1F("hGainDiff","Gain Difference",200,-10.,10.);
1042         } else if(type == 6) {
1043                 xmin = 0.;
1044                 xmax = 10.;
1045                 nbins = (Int_t)(100.*(xmax-xmin));
1046                 hDist = new TH1F("hDriftSpeed","Drift Speed",nbins,xmin,xmax);
1047                 hDistDiff = new TH1F("hDriftSpeedDiff","Drift Speed Difference",200,-10.,10.);
1048         }
1049
1050         Float_t binw = (xmax-xmin)/nbins;
1051
1052         TString *fnamePrevious2=NULL;
1053
1054                 if(type < 5) fnamePrevious2 = new TString("SDDbasHistosPrevious.root");
1055                 else if(type == 5) fnamePrevious2 = new TString("SDDgainHistosPrevious.root");
1056                 else if(type == 6) fnamePrevious2 = new TString("SDDinjectHistosPrevious.root");
1057                 TFile *gainFile = new TFile(fnamePrevious2->Data());
1058                 if(!gainFile->IsZombie()) {
1059
1060                   for(Int_t ddl =0; ddl<fDDLModuleMap->GetNDDLs(); ddl++){
1061                         for(Int_t crx =0; crx<fDDLModuleMap->GetNModPerDDL(); crx++){
1062                                 for(Int_t iside=0;iside<fgknSide;iside++){
1063                                         Int_t moduleSDD = fDDLModuleMap->GetModuleNumber(ddl,crx);
1064                         //AliITSgeomTGeo::GetModuleId(moduleSDD+fgkmodoffset, lay, lad, det);
1065                                         if(type == 1) sprintf(hnamePrevious,"hbase%02dc%02ds%d",ddl,crx,iside);
1066                                         else if(type == 2) sprintf(hnamePrevious,"hnois%02dc%02ds%d",ddl,crx,iside);
1067                                         else if(type == 3) sprintf(hnamePrevious,"hcmn%02dc%02ds%d",ddl,crx,iside);
1068                                         else if(type == 4) sprintf(hnamePrevious,"hcorn%02dc%02ds%d",ddl,crx,iside);
1069                                         else if(type == 5) sprintf(hnamePrevious,"hgain%02dc%02ds%d",ddl,crx,iside);
1070                                         else if(type == 6) sprintf(hnamePrevious,"hdrsp%02dc%02ds%d",ddl,crx,iside);
1071                                 //AliInfo(Form("get histo %s\n",hname));
1072                                         TH1F *hhist = (TH1F *) gainFile->Get(hnamePrevious);
1073                                         if(!hhist) continue;
1074                                         for(Int_t i=0; i<hhist->GetNbinsX();i++) {
1075                                                 if(!fkAnodeMap[moduleSDD-fgkmodoffset][iside][i]) continue;
1076                                                 hDist->Fill(hhist->GetBinContent(i));
1077                                                 hDistDiff->Fill(hhist->GetBinContent(i)-Current[moduleSDD-fgkmodoffset][iside][i]);
1078                                         }
1079                                         delete hhist;
1080                                 }
1081                         }
1082                   }
1083                   gainFile->Close();
1084                   delete gainFile;
1085                 }
1086                 delete fnamePrevious2;
1087
1088         TF1 ff("ff", "gaus", xmin+0.1, xmax-0.1);
1089         hDist->Fit("ff","NWR");
1090 //      hDist->Fit("gaus","","",xmin+0.1, xmax-0.1);
1091 //      Float_t ChiSquared = (Float_t) ff.GetChisquare();
1092 //      Int_t NDF = ff.GetNumberFitPoints() - ff.GetNpar();
1093         Float_t average = (Float_t) ff.GetParameter(1);
1094         Float_t sigma = (Float_t) ff.GetParameter(2);
1095 //      Float_t mean = hDist->GetMean();
1096 //      Float_t rms = hDist->GetRMS();
1097         Int_t badB = 0;
1098         for(Int_t i=0; i<hDist->GetNbinsX();i++) {
1099 //              if(type < 6) 
1100           if(TMath::Abs(i*binw-average) > 4.*sigma) badB += (Int_t)hDist->GetBinContent(i);
1101 //              else
1102 //                      if(TMath::Abs(i-mean) > 4*rms) badB += hDist->GetBinContent(i);
1103         }
1104         Double_t denomi = hDist->GetEntries();
1105         if(denomi == 0) {
1106           denomi = 1;
1107           badB = 0; 
1108         } 
1109         if(type == 1) {
1110                 AliInfo(Form("Number of anodes with baseline out of 4*sigma from average: %d, %f%%\n",badB,100.*((Float_t) badB)/denomi));
1111         } else if(type == 2) {
1112                 AliInfo(Form("Number of anodes with uncorrected noise out of 4*sigma from average: %d, %f%%\n",badB,100.*((Float_t) badB)/denomi));
1113         } else if(type == 3) {
1114                 AliInfo(Form("Number of anodes with common mode noise out of 4*sigma from average: %d, %f%%\n",badB,100.*((Float_t) badB)/denomi));
1115         } else if(type == 4) {
1116                 AliInfo(Form("Number of anodes with corrected noise out of 4*sigma from average: %d, %f%%\n",badB,100.*((Float_t) badB)/denomi));
1117         } else if(type == 5) {
1118                 AliInfo(Form("Number of anodes with gain out of 4*sigma from average: %d, %f%%\n",badB,100.*((Float_t) badB)/denomi));
1119         } else if(type == 6) {
1120                 Int_t badspeed = (Int_t)hDist->GetBinContent(1);
1121                 AliInfo(Form("Number of anodes with drift speed equal to 0: %d\n",badspeed));
1122                 AliInfo(Form("Number of anodes with drift speed out of 4*sigma from average: %d, %f%%\n",badB-badspeed,100.*((Float_t) (badB-badspeed))/(denomi-badspeed)));
1123         }
1124         
1125         TH1F *hDistHistoryCurrent = NULL;
1126         TH1F *hDistHistoryPrevious = NULL;
1127
1128         TFile *gainHistoryFile=NULL;
1129         if(type < 5) 
1130                 gainHistoryFile = new TFile("SDDbasHistory.root","UPDATE");
1131         else if(type ==5) 
1132                 gainHistoryFile = new TFile("SDDgainHistory.root","UPDATE");
1133         else if(type == 6)
1134                 gainHistoryFile = new TFile("SDDinjectHistory.root","UPDATE");
1135         hDist->Write();
1136         hDistDiff->Write();
1137         //AliInfo("SDDgainHistory.root file opened\n");
1138         if(!gainHistoryFile->IsZombie()) {
1139                 if(type == 1) hDistHistoryPrevious = (TH1F *) gainHistoryFile->Get("hBaselineHistory");
1140                 else if(type == 2) hDistHistoryPrevious = (TH1F *) gainHistoryFile->Get("hNoiseUncHistory");
1141                 else if(type == 3) hDistHistoryPrevious = (TH1F *) gainHistoryFile->Get("hNoiseCMNHistory");
1142                 else if(type == 4) hDistHistoryPrevious = (TH1F *) gainHistoryFile->Get("hNoiseCorHistory");
1143                 else if(type == 5) hDistHistoryPrevious = (TH1F *) gainHistoryFile->Get("hGainHistory");
1144                 else if(type == 6) hDistHistoryPrevious = (TH1F *) gainHistoryFile->Get("hDriftSpeedHistory");
1145                 //AliInfo(Form("hDistHistoryPrevious %x\n",hDistHistoryPrevious));
1146         
1147                 if(!hDistHistoryPrevious) {
1148                         if(type == 1) hDistHistoryCurrent = new TH1F("hBaselineHistory","Average Baseline History",2,0,2);
1149                         else if(type == 2) hDistHistoryCurrent = new TH1F("hNoiseUncHistory","Average Uncorrected Noise History",2,0,2);
1150                         else if(type == 3) hDistHistoryCurrent = new TH1F("hNoiseCMNHistory","Average Common Mode Noise History",2,0,2);
1151                         else if(type == 4) hDistHistoryCurrent = new TH1F("hNoiseCorHistory","Average Corrected Noise History",2,0,2);
1152                         else if(type == 5) hDistHistoryCurrent = new TH1F("hGainHistory","Average Gain History",2,0,2);
1153                         else if(type == 6) hDistHistoryCurrent = new TH1F("hDriftSpeedHistory","Average Drift Speed History",2,0,2);
1154                         //AliInfo(Form("hDistHistoryCurrent 1 %x\n",hDistHistoryCurrent));
1155 //                      if(type < 6) {
1156                                 hDistHistoryCurrent->SetBinContent(1,average);
1157                                 hDistHistoryCurrent->SetBinError(1,sigma);
1158 /*
1159                         } else {
1160                                 hDistHistoryCurrent->SetBinContent(1,mean);
1161                                 hDistHistoryCurrent->SetBinError(1,rms);
1162                         }
1163 */
1164                 } else {
1165                         if(type == 1) hDistHistoryCurrent = new TH1F("hBaselineHistory","Average Baseline History",hDistHistoryPrevious->GetNbinsX()+1,0,hDistHistoryPrevious->GetNbinsX()+1);
1166                         else if(type == 2) hDistHistoryCurrent = new TH1F("hNoiseUncHistory","Average Uncorrected Noise History",hDistHistoryPrevious->GetNbinsX()+1,0,hDistHistoryPrevious->GetNbinsX()+1);
1167                         else if(type == 3) hDistHistoryCurrent = new TH1F("hNoiseCMNHistory","Average Common Mode Noise History",hDistHistoryPrevious->GetNbinsX()+1,0,hDistHistoryPrevious->GetNbinsX()+1);
1168                         else if(type == 4) hDistHistoryCurrent = new TH1F("hNoiseCorHistory","Average Corrected Noise History",hDistHistoryPrevious->GetNbinsX()+1,0,hDistHistoryPrevious->GetNbinsX()+1);
1169                         else if(type == 5) hDistHistoryCurrent = new TH1F("hGainHistory","Average Gain History",hDistHistoryPrevious->GetNbinsX()+1,0,hDistHistoryPrevious->GetNbinsX()+1);
1170                         else if(type == 6) hDistHistoryCurrent = new TH1F("hDriftSpeedHistory","Average Drift Speed History",hDistHistoryPrevious->GetNbinsX()+1,0,hDistHistoryPrevious->GetNbinsX()+1);
1171                         //AliInfo(Form("hBaselineHistory 2 %x\n",hDistHistory));
1172                         for(Int_t i=0;i<hDistHistoryPrevious->GetNbinsX();i++) {
1173                                 hDistHistoryCurrent->SetBinContent(i,hDistHistoryPrevious->GetBinContent(i));
1174                                 hDistHistoryCurrent->SetBinError(i,hDistHistoryPrevious->GetBinError(i));
1175                         }
1176                         hDistHistoryCurrent->SetBinContent(hDistHistoryPrevious->GetNbinsX(),average);
1177                         hDistHistoryCurrent->SetBinError(hDistHistoryPrevious->GetNbinsX(),sigma);
1178                 }
1179         }
1180         hDistHistoryCurrent->Write();
1181         gainHistoryFile->Close();
1182         delete gainHistoryFile;
1183 //      delete hname;
1184         delete hDist;
1185         delete hDistDiff;
1186 //        if(hDistHistoryCurrent) delete hDistHistoryCurrent;
1187 //      if(hDistHistoryPrevious) delete hDistHistoryPrevious;
1188 }
1189
1190 //_______________________________________________________________
1191
1192
1193 void AliITSQASDDDataMakerRec::CreateTheMap()
1194 {
1195
1196   AliCDBEntry *ddlMapSDD = AliCDBManager::Instance()->Get("ITS/Calib/DDLMapSDD");
1197   Bool_t cacheStatus = AliCDBManager::Instance()->GetCacheFlag();
1198   if(!ddlMapSDD)
1199     {
1200       AliError("Calibration object retrieval failed! SDD will not be processed");
1201       fDDLModuleMap = NULL;
1202       //return rv;
1203     }
1204   fDDLModuleMap = (AliITSDDLModuleMapSDD*)ddlMapSDD->GetObject();
1205   if(!cacheStatus)ddlMapSDD->SetObject(NULL);
1206   ddlMapSDD->SetOwner(kTRUE);
1207   if(!cacheStatus)
1208     {
1209       delete ddlMapSDD;
1210     }
1211   AliInfo("DDL Map Created\n ");
1212 }