Initial commit of new style QA
[u/mrichter/AliRoot.git] / HMPID / Hqa.C
1 void Hqa()
2 {
3   gROOT->LoadMacro("Hdisp.C");
4   HitQA();
5 }//Hqa()
6 void HitQA()
7 {
8   Int_t nEvts=100;
9   TLegend *lQ=new TLegend(0.5,0.5,0.9,0.9);
10
11   TH1F *hQ7eV  =new TH1F("hQ7eV"  ,"" ,300,-50,2000);     hQ7eV  ->SetLineColor(kRed);      lQ->AddEntry(hQ7eV  ,"Ckov 7 eV");  hQ7eV->SetStats(0);
12   TH1F *hQ200eV=new TH1F("hQ200eV","" ,300,-50,2000);     hQ200eV->SetLineColor(kBlack);    lQ->AddEntry(hQ200eV,"mip 200 eV");
13   TH1F *hQ500eV=new TH1F("hQ500eV","" ,300,-50,2000);     hQ500eV->SetLineColor(kCyan);     lQ->AddEntry(hQ500eV,"mip 500 eV");
14   TH1F *hQ900eV=new TH1F("hQ900eV","" ,300,-50,2000);     hQ900eV->SetLineColor(kGreen);    lQ->AddEntry(hQ900eV,"mip 900 eV");
15   
16   TH1F *hCluPerEvt=new TH1F("hCluPerEvt","# clusters per event",11,-0.5,10.5);
17   TH1F *hCluChi2  =new TH1F("hChi2","Chi2 ",1000,0,100);
18   TH1F *hCluFlg   =new TH1F("hCluFlg","Cluster flag",14,-1.5,12.5);                       hCluFlg->SetFillColor(5);
19   TH1F *hCluRawSize= new TH1F("hCluRawSize","Raw cluster size ",100,0,100);
20   
21   gStyle->SetOptStat(10);
22   TH2F *pCluMapSi1  =new TH2F("cluMapSi1","Size 1 map"       ,1700,-10,160,1700,-10,160);
23   TH2F *pCluMapLo0  =new TH2F("cluMNoLo0","Loc Max 0 map"    ,1700,-10,160,1700,-10,160);     
24   TH2F *pCluMapLo1  =new TH2F("cluMapLo1","Loc Max 1 map"    ,1700,-10,160,1700,-10,160);        
25   TH2F *pCluMapUnf  =new TH2F("cluMapUnf","Unfolded map"     ,1700,-10,160,1700,-10,160);         
26   TH2F *pCluMapEdg  =new TH2F("cluMapEdg","On edge map"      ,1700,-10,160,1700,-10,160);         
27   TH2F *pCluMapCoG  =new TH2F("cluMapCoG","CoG  map"         ,1700,-10,160,1700,-10,160);            
28   TH2F *pCluMapEmp  =new TH2F("cluMapEmp","undefined-empty"  ,1700,-10,160,1700,-10,160);      
29   TH2F *pCluMapNoLoc=new TH2F("cluMapNoLoc","no loc maxima"  ,1700,-10,160,1700,-10,160);      
30   TH2F *pCluMapAbn  =new TH2F("cluMapAbn","abnormal fit"     ,1700,-10,160,1700,-10,160);      
31   TH2F *pCluMapNot  =new TH2F("cluMapNot","Raw Clusters"     ,1700,-10,160,1700,-10,160);      
32   TH2F *pCluMapMax  =new TH2F("cluMapMax","N. locs excceds"  ,1700,-10,160,1700,-10,160);      
33
34   TH1F *hHitCluDifX = new TH1F("hHitCluDifX" ,";entries;x_{Hit}-x_{Clu} [cm]"   ,2000,-2,2);          hHitCluDifX->Sumw2();    hHitCluDifX->SetFillColor(kYellow);
35   TH1F *hHitCluDifY = new TH1F("hHitCluDifY" ,";entries;y_{Hit}-y_{Clu} [cm]"   ,2000,-2,2);          hHitCluDifY->Sumw2();    hHitCluDifY->SetFillColor(kYellow);
36   TH2F *hHitCluDifXY= new TH2F("hHitCluDifXY",";x_{Hit}-x_{Clu};y_{Hit}-y_{Clu}",2000,-2,2,2000,-2,2);hHitCluDifXY->Sumw2();  
37   TH1F *hHitCluDifQ = new TH1F("hHitCluDifQ" ,";entries;(Q_{Clu}-Q_{Hit})/Q_{Hit}" ,200 ,-200,200);   hHitCluDifQ->Sumw2();    hHitCluDifQ->SetFillColor(kYellow);
38   
39   TH2F *hHitMap= new TH2F("hHitMap",";x_{Hit};y_{Hit}",1700,-10,160,1700,-10,160);  
40  
41   Float_t e200=200e-9,e500=500e-9,e900=900e-9,e7=7e-9;//predefined  Eloss
42   
43   AliHMPIDHit hit(0,0,kProton,0,0,0);
44   for(int i=0;i<5000;i++){
45     hQ200eV->Fill(hit.QdcTot(e200));  hQ500eV->Fill(hit.QdcTot(e500));   hQ900eV->Fill(hit.QdcTot(e900));  hQ7eV->Fill(hit.QdcTot(e7));
46   }  
47   TClonesArray hits("AliHMPIDHit");  TClonesArray sdigs("AliHMPIDDigit");
48   TObjArray digs(7); for(Int_t i=0;i<7;i++) digs.AddAt(new TClonesArray("AliHMPIDDigit"),i);
49   TObjArray clus(7); for(Int_t i=0;i<7;i++) clus.AddAt(new TClonesArray("AliHMPIDCluster"),i);
50   
51     
52   for(Int_t iEvt=0;iEvt<nEvts;iEvt++){//events loop
53     if(iEvt%500==0)Printf("============> iEvt = %d ",iEvt);
54     
55     Int_t ch,pid; Float_t e,hitx,hity,hitq;
56 //    Int_t nHits=(type==999)?1:40;
57     Int_t nHits=1;
58     for(Int_t iHit=0;iHit<nHits;iHit++){//hits loop for the current event
59       switch(iHit){
60         case 0:  ch=0;pid=kProton;e=e200;hitx=16.0+gRandom->Rndm()*0.8;hity= 16.8+gRandom->Rndm()*0.84;break; //mip ramdomly distributed in one pad in the middle
61         case 1:  ch=0;pid=kProton;e=e200;hitx=0.4;hity=0.42;break; //mip in left-hand bottom coner of chamber 0
62         case 2:  ch=0;pid=kProton;e=e200;hitx=0.4;hity=30  ;break; //mip on left edge of chamber 0
63         case 3:  ch=0;pid=kProton;e=e200;hitx=40; hity=0.42;break; //mip on bottom edge of chamber 0
64         default: ch=gRandom->Rndm()*6; pid=(gRandom->Rndm()>0.9)? kProton:50000050;
65                   if(pid==kProton) 
66                     e=gRandom->Rndm()*900e-9; 
67                   else
68                     e=5.5e-9+3e-9*gRandom->Rndm();
69                   hitx=gRandom->Rndm()*AliHMPIDDigit::SizeAllX(); hity=gRandom->Rndm()*AliHMPIDDigit::SizeAllY();break; //random hit
70       }
71       new(hits[iHit]) AliHMPIDHit(ch,e,pid,iHit,hitx,hity);                          
72       hitq=e;
73     }//hits loop
74     
75     AliHMPIDv1::Hit2Sdi(&hits,&sdigs);
76     AliHMPIDDigitizer::DoNoise(kFALSE);
77     AliHMPIDDigitizer::Sdi2Dig(&sdigs,&digs);
78     AliHMPIDReconstructor::Dig2Clu(&digs,&clus,kFALSE);
79
80 // From here normal procedure for QA
81
82     for(Int_t iHit=0;iHit<hits.GetEntriesFast();iHit++) {
83       AliHMPIDHit *pHit = (AliHMPIDHit*)hits.UncheckedAt(iHit);
84       hHitMap->Fill(pHit->LorsX(),pHit->LorsY());
85     }
86     Int_t kMaxCh=(nHits==1)?0:AliHMPIDDigit::kMaxCh;
87     for(Int_t iCh=AliHMPIDDigit::kMinCh;iCh<=kMaxCh;iCh++){//chambers loop
88       TClonesArray *pDigs=(TClonesArray *)digs.UncheckedAt(iCh);
89       TClonesArray *pClus=(TClonesArray *)clus.UncheckedAt(iCh);
90       
91 //      if(pClus->GetEntriesFast()>nHits) {hits.Print();}
92 //      if(pClus->GetEntriesFast()>nHits) {pDigs->Print();Printf("----S D I G I T S-------------");}
93 //      if(pClus->GetEntriesFast()>nHits) {sdigs.Print();Printf("-------------------------------");}
94       hCluPerEvt->Fill(pClus->GetEntriesFast());
95       for(Int_t iClu=0;iClu<pClus->GetEntriesFast();iClu++){//clusters loop
96         AliHMPIDCluster *pClu=(AliHMPIDCluster*)pClus->UncheckedAt(iClu);
97         Float_t clux=pClu->X(); Float_t cluy=pClu->Y(); Float_t cluq=pClu->Q();
98         hCluFlg->Fill(pClu->Status());
99         hCluChi2->Fill(pClu->Chi2());
100         hCluRawSize->Fill(pClu->Size());
101          
102         switch(pClu->Status()){
103 /*
104     case        kFrm  : status="formed        "   ;break;
105     case        kUnf  : status="unfolded (fit)"   ;break;
106     case        kCoG  : status="coged         "   ;break;
107     case        kLo1  : status="locmax 1 (fit)"   ;break;
108     case        kMax  : status="exceeded (cog)"   ;break;
109     case        kNot  : status="not done (cog)"   ;break;
110     case        kEmp  : status="empty         "   ;break;
111     case        kEdg  : status="edge     (fit)"   ;break;
112     case        kSi1  : status="size 1   (cog)"   ;break;
113     case        kNoLoc: status="no LocMax(fit)"   ;break;
114     case        kAbn  : status="Abnormal fit  "   ;break;
115 */
116             case AliHMPIDCluster::kSi1:   pCluMapSi1->Fill(clux,cluy); break;
117             case AliHMPIDCluster::kLo1:   pCluMapLo1->Fill(clux,cluy); break;
118             case AliHMPIDCluster::kUnf:   pCluMapUnf->Fill(clux,cluy); break; 
119             case AliHMPIDCluster::kMax:   pCluMapMax->Fill(clux,cluy); break;
120             case AliHMPIDCluster::kEdg:   pCluMapEdg->Fill(clux,cluy); break;
121             case AliHMPIDCluster::kCoG:   pCluMapCoG->Fill(clux,cluy); break;
122             case AliHMPIDCluster::kNoLoc: pCluMapNoLoc->Fill(clux,cluy); break;
123             case AliHMPIDCluster::kAbn:   pCluMapAbn->Fill(clux,cluy); break;
124             case AliHMPIDCluster::kNot:   pCluMapNot->Fill(clux,cluy); break;
125             default:     pCluMapEmp->Fill(clux,cluy); break;            
126         }
127         
128         hHitCluDifX->Fill(hitx-clux); hHitCluDifY->Fill(hity-cluy); hHitCluDifXY->Fill(hitx-clux,hity-cluy); hHitCluDifQ->Fill(100*(cluq-hitq)/hitq);
129         
130       }//clusters loop
131     }//chambers loop
132       
133     hits.Delete();  sdigs.Delete();  for(int i = 0;i<7;i++){((TClonesArray*)digs.At(i))->Delete();((TClonesArray*)clus.At(i))->Delete();}
134   }//events loop      
135       
136   gStyle->SetPalette(1);
137   TCanvas *pC2=new TCanvas("Digit canvas","Digit canvas",1280,800); pC2->Divide(3,3);
138   pC2->cd(1);hHitCluDifX->Draw("hist");
139   pC2->cd(2);hHitCluDifY->Draw("hist");
140   pC2->cd(3);hHitCluDifXY->Draw("colz");
141   pC2->cd(4);hHitCluDifQ->Draw("hist");
142   pC2->cd(5);gPad->SetLogy(1);hCluFlg->Draw();
143   pC2->cd(6);hCluChi2->Draw();
144   pC2->cd(7);                 hCluRawSize->Draw();
145   pC2->cd(8);                 hCluPerEvt->Draw();
146   pC2->cd(9);                 hQ7eV->Draw(); hQ200eV->Draw("same"); hQ500eV->Draw("same"); hQ900eV->Draw("same"); lQ->Draw();
147   TCanvas *pC1=new TCanvas("ClusterMaps","Cluster maps",1280,800); pC1->Divide(3,3);
148   pC1->cd(1);  pCluMapSi1->Draw();  DrawCh(-1);
149   pC1->cd(2);  pCluMapLo1->Draw();  DrawCh(-1);
150   pC1->cd(3);  pCluMapUnf->Draw();  DrawCh(-1);
151   pC1->cd(4);     hHitMap->Draw();  DrawCh(-1);
152   pC1->cd(5);  pCluMapMax->Draw();  DrawCh(-1);
153   pC1->cd(6);  pCluMapEdg->Draw();  DrawCh(-1);
154   pC1->cd(7);  pCluMapNot->Draw();  DrawCh(-1);
155   pC1->cd(8);  pCluMapNoLoc->Draw();DrawCh(-1);
156   pC1->cd(9);  pCluMapEmp->Draw();  DrawCh(-1);
157    
158   pC1->SaveAs("$HOME/HitMaps.png");  //?????
159   pC2->SaveAs("$HOME/HitCluDif.gif");  
160   
161   Printf("Digits - raw -digits conversion...");  
162   
163   AliHMPIDDigit d1,d2; Int_t ddl,r,d,a;UInt_t w32;
164
165   for(Int_t iCh=AliHMPIDDigit::kMinCh;iCh<=AliHMPIDDigit::kMaxCh;iCh++)
166   for(Int_t iPc=AliHMPIDDigit::kMinPc;iPc<=AliHMPIDDigit::kMaxPc;iPc++)
167   for(Int_t iPx=AliHMPIDDigit::kMinPx;iPx<=AliHMPIDDigit::kMaxPx;iPx++)
168   for(Int_t iPy=AliHMPIDDigit::kMinPy;iPy<=AliHMPIDDigit::kMaxPy;iPy++){
169     d1.Set(iCh,iPc,iPx,iPy,3040);   //set digit               
170     d1.Raw(w32,ddl,r,d,a);          //get raw word for this digit 
171     d2.Raw(w32,ddl);                //set another digit from that raw word
172     if(d1.Compare(&d2)) {d1.Print(); d2.Print(); Printf("");}//compare them
173   }
174   Printf("OK");
175 }//tst()