Fix problem in simulated raw data + code cleanup (F.Prino)
[u/mrichter/AliRoot.git] / ITS / ITSSDDQAMaker.C
1 void ITSSDDQAMaker(char *iFile, Int_t MaxEvts=1000000, Int_t FirstEvt=0) {
2
3   //To have Baseline Histos uncomment parts with " // BL!!! " comment
4
5 cout << "SDD Quality Assurance Prototype Macro" << endl; 
6
7 const Int_t nSDDmodules= 260;
8 const Int_t imodoffset = 240;
9 const Int_t modtotSDD  = nSDDmodules*2;
10 const Int_t anode = 256;
11
12 Float_t xi = -0.5;
13 Float_t xf = xi + nSDDmodules;
14 TH1F *hModulePattern = new TH1F("hModulePattern","Modules pattern",nSDDmodules,xi,xf);
15 xf = xi + modtotSDD;
16 TH1F *hModuleSidePattern = new TH1F("hModuleSidePattern","Modules/Side pattern",modtotSDD,xi,xf);
17
18 TH2F *hModuleChargeMap[modtotSDD];  //260 dx e 260 sx  with A, T, Q
19 TH2F *hModuleCountsMap[modtotSDD];  //260 dx e 260 sx  with A, T, Ncounts
20 TH2I *hModuleCarlos = new TH2I("hModuleCarlos","hModuleCarlos",modtotSDD,xi,xf,101,-0.5,100.5);
21 /*
22   TH1F *hModuleSideBL[modtotSDD][anode];                                // BL!!!
23 */ 
24
25
26 //-------histograms definition 
27 Char_t *hisnam = new Char_t[50];
28 Char_t *histit = new Char_t[50];  
29 Char_t *hisnam2 = new Char_t[50];
30 Char_t *histit2 = new Char_t[50];    
31 Char_t *hisnam3 = new Char_t[50];
32  for(Int_t imod=0; imod<nSDDmodules;imod++){
33    for(Int_t isid=0;isid<2;isid++){
34      Int_t index=2*imod+isid;       //260*2 position
35
36      sprintf(hisnam,"chargeMap%d",index);
37      sprintf(histit,"Total Charge, module number %d",index);
38      hModuleChargeMap[index]=new TH2F(hisnam,histit,256,-0.5,255.5,256,-0.5,255.5);  
39
40      sprintf(hisnam2,"countsMap%d",index);
41      sprintf(histit2,"Number of Counts, module number %d",index);
42      hModuleCountsMap[index] = new TH2F(hisnam2,histit2,256,-0.5,255.5,256,-0.5,255.5);
43      /*
44        for(Int_t ianode=0; ianode<anode; ianode++){                         // BL!!!
45        sprintf(hisnam3,"BL_module_%d_%d",index,ianode); 
46        //cout<<hisnam3 <<endl;
47        hModuleSideBL[index][ianode] = new TH1F(hisnam3,hisnam3,256,0.,1024.);
48      }
49      */
50    }
51  }
52
53   AliRawReader *rd = new AliRawReaderDate(iFile,FirstEvt);  // open run
54   Int_t evCounter = 0;
55   Int_t eqOffset = 256;
56   Int_t DDLid_range = 24;
57   do{                       // start loop on events
58     if(++evCounter > MaxEvts) { cout << MaxEvts << " events read, stop" << endl; evCounter--; break; }  
59     cout << "Read Event: " << evCounter+FirstEvt-1 << endl;
60
61     rd->RequireHeader(kFALSE);             
62     rd->SelectEvents(7);                  
63     rd->SelectEquipment(17,eqOffset+1,eqOffset+DDLid_range);  //17 states for "DRorc acquisition"
64     rd->Reset();                           // reset the current position to the beginning of the event
65  
66     Int_t nSkip = 0;                     // number of skipped signals
67     AliITSRawStreamSDD s(rd);            //This class provides access to ITS SDD digits in raw data.
68     Int_t iddl;
69     Int_t isddmod;
70     Int_t moduleSDD;
71     gStyle->SetPalette(1);
72     while(s.Next()){                     //read the next raw digit; returns kFALSE if there is no digit left
73       if(s.IsCompletedModule()) continue;
74       iddl=rd->GetDDLID()-2; // -2 is temporary for test raw data
75
76         isddmod=s.GetModuleNumber(iddl,s.GetCarlosId());        //this is the FEE Carlos
77         //cout<<"DDLID= "<<iddl <<"; Module number= " <<isddmod  <<endl;
78         if(isddmod >= imodoffset) { 
79           hModulePattern->Fill(isddmod-imodoffset);             // 0 to 259    so  240 to 499
80           moduleSDD=2*(isddmod-imodoffset)+s.GetChannel();
81           hModuleSidePattern->Fill(moduleSDD);                  // 0 to 519
82           hModuleCarlos->Fill(isddmod-imodoffset,s.GetCarlosId());
83           //cout << "anode " << s.GetCoord1() << ", time bin: " << s.GetCoord2() << ", charge: " << s.GetSignal() << endl;        
84           Int_t coord1 = s.GetCoord1();
85           Int_t coord2 = s.GetCoord2();
86           Int_t signal = s.GetSignal();
87           hModuleChargeMap[moduleSDD]->Fill(coord2, coord1,signal);
88           hModuleCountsMap[moduleSDD]->Fill(coord2, coord1 );   
89           //hModuleSideBL[moduleSDD][coord1]->Fill(signal);             // BL  !!!
90         } else {
91           nSkip++;
92         }
93     }    
94     cout << "End of Event " << evCounter+FirstEvt-1 << ", " << nSkip << " wrong module numbers" << endl;
95   } while(rd->NextEvent()); // end loop on events
96   delete rd;
97
98   cout << "end after " << evCounter << " events" << endl;
99   /*
100   TNtuple *Baseline = new TNtuple("Baseline","Baseline","HalfModule:Anode:Mean:RMS");      // BL!!!
101   Float_t meanBL;
102   Float_t rmsBL;  
103   */
104   for(Int_t i=0; i<modtotSDD; i++){   
105     if(hModuleSidePattern->GetBinContent(i+1)){              //check if they're not empty
106       hModuleChargeMap[i]->GetXaxis()->SetTitle("Time Bin");
107       hModuleChargeMap[i]->GetYaxis()->SetTitle("Anode"); 
108       hModuleCountsMap[i]->GetXaxis()->SetTitle("Time Bin");
109       hModuleCountsMap[i]->GetYaxis()->SetTitle("Anode");  
110       /*
111       for(Int_t ianode=0; ianode<anode; ianode++ ){                                      // BL!!!
112         hModuleSideBL[i][ianode]->GetXaxis()->SetTitle("ADC counts");
113         hModuleSideBL[i][ianode]->GetYaxis()->SetTitle("#"); 
114         meanBL = hModuleSideBL[i][ianode]->GetMean();
115         rmsBL = hModuleSideBL[i][ianode]->GetRMS();
116         gaussfitBL = hModuleSideBL[i][ianode]->Fit("gaus");     
117         Baseline->Fill(i,ianode,meanBL,rmsBL);
118       }
119       */
120     }
121   }  
122   
123   hModuleSidePattern->GetXaxis()->SetTitle("2*(Module Number-1)+Side");
124   hModuleSidePattern->GetYaxis()->SetTitle("Counts");  
125   hModulePattern->GetXaxis()->SetTitle("Module Number");  
126   hModulePattern->GetYaxis()->SetTitle("Counts");  
127
128
129   //-------store Histograms
130   cout << "Store Histograms" << endl;
131   TString oFileName(iFile);
132   oFileName.Append(".root");
133   TFile *oFile = TFile::Open(oFileName,"recreate");
134   hModulePattern->Write();
135   hModuleSidePattern->Write();
136   hModuleCarlos->Write();
137   for(Int_t i=0; i<modtotSDD; i++){ 
138       if(hModuleSidePattern->GetBinContent(i+1)){            //check if they're not empty
139         hModuleChargeMap[i]->Write();
140         hModuleCountsMap[i]->Write();     
141         /* 
142         for(Int_t ianode=0; ianode<anode; ianode++ ){                           // BL!!!
143           hModuleSideBL[i][ianode]->Write();
144           Baseline->Write();
145         }
146         */
147       }
148   }
149   
150   oFile->Close();
151   cout << "Clear memory" << endl;
152   for(Int_t imod=0; imod<nSDDmodules;imod++){
153     for(Int_t isid=0;isid<2;isid++){
154       Int_t index=2*imod+isid;       //260*2 position
155       delete hModuleChargeMap[index];
156       delete hModuleCountsMap[index];       
157       /*
158       for(Int_t ianode=0; ianode<anode; ianode++ ){                              // BL!!!
159         delete hModuleSideBL[index][ianode]; 
160         delete Baseline;
161       }
162       */
163     }
164   }
165   delete hModulePattern;
166   delete hModuleSidePattern;
167   delete hModuleCarlos;
168
169 }