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