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