]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ZDC/ZDCMAPPINGda.cxx
Better starting value for estimate of covariance matrix (Maksym, Silvia)
[u/mrichter/AliRoot.git] / ZDC / ZDCMAPPINGda.cxx
CommitLineData
967dda6e 1/*
2
3This program reads the DAQ data files passed as argument using the monitoring library.
4
967dda6e 5The program reports about its processing progress.
6
7Messages on stdout are exported to DAQ log system.
8
27afc0c8 9DA to write mapping for ADC modules and VME scaler
967dda6e 10
11Contact: Chiara.Oppedisano@to.infn.it
12Link:
b06a579c 13Run Type: PHYSICS
1af38adf 14DA Type: MON
15Number of events needed: 1 (SOD is read)
16Input Files: none
967dda6e 17Output Files: ZDCChMapping.dat
1af38adf 18Trigger Types Used: different trigger types are used
967dda6e 19
20*/
1af38adf 21
218f916a 22#define MAPDATA_FILE "ZDCChMapping.dat"
b06a579c 23#define TDCDATA_FILE "ZDCTDCCalib.dat"
24#define TDCHISTO_FILE "ZDCTDCHisto.root"
967dda6e 25
26#include <stdio.h>
27#include <stdlib.h>
28#include <Riostream.h>
29
30// DATE
31#include <event.h>
32#include <monitor.h>
33#include <daqDA.h>
34
35//ROOT
b06a579c 36#include <TROOT.h>
37#include <TPluginManager.h>
38#include <TH1F.h>
39#include <TH2F.h>
40#include <TProfile.h>
41#include <TF1.h>
967dda6e 42#include <TFile.h>
b06a579c 43#include <TFitter.h>
44#include "TMinuitMinimizer.h"
967dda6e 45
46//AliRoot
47#include <AliRawReaderDate.h>
48#include <AliRawEventHeaderBase.h>
49#include <AliZDCRawStream.h>
50
967dda6e 51int main(int argc, char **argv) {
1af38adf 52
b06a579c 53 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
54 "*",
55 "TStreamerInfo",
56 "RIO",
57 "TStreamerInfo()");
58
59 TMinuitMinimizer m;
60 gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", "Minuit","TMinuitMinimizer",
61 "Minuit", "TMinuitMinimizer(const char *)");
62 TVirtualFitter::SetDefaultFitter("Minuit");
63
1af38adf 64 const Char_t* tableSOD[] = {"ALL", "no", "SOD", "all", NULL, NULL};
65 monitorDeclareTable(const_cast<char**>(tableSOD));
967dda6e 66
67 int status = 0;
198f612a 68 int const kNModules = 10;
f9641c3b 69 int const kNChannels = 24;
27afc0c8 70 int const kNScChannels = 32;
b06a579c 71
72 int kScalerGeo=8;
73 int itdc=0, iprevtdc=-1, ihittdc=0
74 float tdcData[6], tdcL0;
75
76 TH1F * hTDC[6];
77 char ntdchist[20];
78 for(Int_t itdc=0; itdc<6; itdc++){
79 if(itdc==0) hTDC[itdc] = new TH1F("TDCZNC", "TDC ZNC", 200, 150., 350.);
80 else if(itdc==1) hTDC[itdc] = new TH1F("TDCZNA", "TDC ZNA", 200, 150., 350.);
81 else if(itdc==2) hTDC[itdc] = new TH1F("TDCZPC", "TDC ZPC", 200, 150., 350.);
82 else if(itdc==3) hTDC[itdc] = new TH1F("TDCZPA", "TDC ZPA", 200, 150., 350.);
83 else if(itdc==4) hTDC[itdc] = new TH1F("TDCZEM1","TDC ZEM1",200, 150., 350.);
84 else if(itdc==5) hTDC[itdc] = new TH1F("TDCZEM2","TDC ZEM2",200, 150., 350.);
85 }
86
967dda6e 87 /* log start of process */
198f612a 88 printf("\n ZDC MAPPING program started\n");
967dda6e 89
90 /* check that we got some arguments = list of files */
91 if (argc<2) {
92 printf("Wrong number of arguments\n");
93 return -1;
94 }
967dda6e 95
96 FILE *mapFile4Shuttle;
967dda6e 97
98 /* read the data files */
99 int n;
100 for(n=1;n<argc;n++){
101
102 status=monitorSetDataSource( argv[n] );
103 if (status!=0) {
104 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
105 return -1;
106 }
1af38adf 107
108 /* declare monitoring program */
109 status=monitorDeclareMp( __FILE__ );
110 if (status!=0) {
111 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
112 return -1;
113 }
114 monitorSetNowait();
115 monitorSetNoWaitNetworkTimeout(1000);
967dda6e 116
1af38adf 117 struct eventHeaderStruct *event;
118 eventTypeType eventT;
967dda6e 119
1af38adf 120 Int_t iev = 0;
121 Bool_t sodRead = kFALSE;
b06a579c 122 while(!sodRead){
1af38adf 123
124 /* check shutdown condition */
125 if (daqDA_checkShutdown()) {break;}
967dda6e 126
127 /* get next event */
128 status=monitorGetEventDynamic((void **)&event);
1af38adf 129 if(status==MON_ERR_EOF){
130 printf ("End of File detected\n");
131 break; /* end of monitoring file has been reached */
132 }
967dda6e 133 if(status!=0) {
134 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
135 return -1;
136 }
137
138 /* retry if got no event */
ac84d2fc 139 if(event==NULL) continue;
967dda6e 140
141 // Initalize raw-data reading and decoding
142 AliRawReader *reader = new AliRawReaderDate((void*)event);
27afc0c8 143 reader->Select("ZDC");
967dda6e 144 // --- Reading event header
7f4bde92 145 //UInt_t evtype = reader->GetType();
ac84d2fc 146 //printf("\t ZDCMAPPINGda -> run # %d\n",reader->GetRunNumber());
967dda6e 147 //
148 AliZDCRawStream *rawStreamZDC = new AliZDCRawStream(reader);
149
1af38adf 150
967dda6e 151 /* use event - here, just write event id to result file */
152 eventT=event->eventType;
153
198f612a 154 if(eventT==START_OF_DATA){
155
156
82dffa48 157 Int_t iMod=-1;
158 Int_t modGeo[kNModules], modType[kNModules],modNCh[kNModules];
159 for(Int_t kl=0; kl<kNModules; kl++){
160 modGeo[kl]=modType[kl]=modNCh[kl]=0;
161 }
162
163 Int_t ich=0;
164 Int_t adcMod[2*kNChannels], adcCh[2*kNChannels], sigCode[2*kNChannels];
165 Int_t det[2*kNChannels], sec[2*kNChannels];
166 for(Int_t y=0; y<2*kNChannels; y++){
167 adcMod[y]=adcCh[y]=sigCode[y]=det[y]=sec[y]=-1;
168 }
27afc0c8 169
82dffa48 170 Int_t iScCh=0;
171 Int_t scMod[kNScChannels], scCh[kNScChannels], scSigCode[kNScChannels];
172 Int_t scDet[kNScChannels], scSec[kNScChannels];
173 for(Int_t y=0; y<kNScChannels; y++){
174 scMod[y]=scCh[y]=scSigCode[y]=scDet[y]=scSec[y]=-1;
175 }
176
177 Int_t itdcCh=0;
178 Int_t tdcMod[kNScChannels], tdcCh[kNScChannels], tdcSigCode[kNScChannels];
179 Int_t tdcDet[kNScChannels], tdcSec[kNScChannels];
180 for(Int_t y=0; y<kNScChannels; y++){
181 tdcMod[y]=tdcCh[y]=tdcSigCode[y]=tdcDet[y]=tdcSec[y]=-1;
182 }
198f612a 183
7f4bde92 184 rawStreamZDC->SetSODReading(kTRUE);
185
ac84d2fc 186 // --------------------------------------------------------
187 // --- Writing ascii data file for the Shuttle preprocessor
188 mapFile4Shuttle = fopen(MAPDATA_FILE,"w");
967dda6e 189 if(!rawStreamZDC->Next()) printf(" \t No raw data found!! \n");
190 else{
27afc0c8 191 while((rawStreamZDC->Next())){
192 if(rawStreamZDC->IsHeaderMapping()){ // mapping header
198f612a 193 iMod++;
194 modGeo[iMod] = rawStreamZDC->GetADCModule();
195 modType[iMod] = rawStreamZDC->GetModType();
196 modNCh[iMod] = rawStreamZDC->GetADCNChannels();
27afc0c8 197 }
198 if(rawStreamZDC->IsChMapping()){
198f612a 199 if(modType[iMod]==1){ // ADC mapping ----------------------
27afc0c8 200 adcMod[ich] = rawStreamZDC->GetADCModFromMap(ich);
201 adcCh[ich] = rawStreamZDC->GetADCChFromMap(ich);
202 sigCode[ich] = rawStreamZDC->GetADCSignFromMap(ich);
203 det[ich] = rawStreamZDC->GetDetectorFromMap(ich);
204 sec[ich] = rawStreamZDC->GetTowerFromMap(ich);
27afc0c8 205 ich++;
206 }
82dffa48 207 else if(modType[iMod]==2){ // VME scaler mapping -------------
27afc0c8 208 scMod[iScCh] = rawStreamZDC->GetScalerModFromMap(iScCh);
209 scCh[iScCh] = rawStreamZDC->GetScalerChFromMap(iScCh);
210 scSigCode[iScCh] = rawStreamZDC->GetScalerSignFromMap(iScCh);
211 scDet[iScCh] = rawStreamZDC->GetScDetectorFromMap(iScCh);
212 scSec[iScCh] = rawStreamZDC->GetScTowerFromMap(iScCh);
27afc0c8 213 iScCh++;
214 }
82dffa48 215 else if(modType[iMod]==6 && modGeo[iMod]==4){ // ZDC TDC mapping --------------------
216 tdcMod[itdcCh] = rawStreamZDC->GetTDCModFromMap(itdcCh);
217 tdcCh[itdcCh] = rawStreamZDC->GetTDCChFromMap(itdcCh);
218 tdcSigCode[itdcCh] = rawStreamZDC->GetTDCSignFromMap(itdcCh);
219 itdcCh++;
220 }
967dda6e 221 }
198f612a 222 }
223 // Writing data on output FXS file
198f612a 224 for(Int_t is=0; is<2*kNChannels; is++){
225 fprintf(mapFile4Shuttle,"\t%d\t%d\t%d\t%d\t%d\t%d\n",
226 is,adcMod[is],adcCh[is],sigCode[is],det[is],sec[is]);
227 //printf(" Mapping DA -> %d ADC: mod %d ch %d, code %d det %d, sec %d\n",
228 // is,adcMod[is],adcCh[is],sigCode[is],det[is],sec[is]);
229 }
230 for(Int_t is=0; is<kNScChannels; is++){
231 fprintf(mapFile4Shuttle,"\t%d\t%d\t%d\t%d\t%d\t%d\n",
232 is,scMod[is],scCh[is],scSigCode[is],scDet[is],scSec[is]);
82dffa48 233 //if(scMod[is]!=-1) printf(" Mapping DA -> %d Scaler: mod %d ch %d, code %d det %d, sec %d\n",
198f612a 234 // is,scMod[is],scCh[is],scSigCode[is],scDet[is],scSec[is]);
967dda6e 235 }
82dffa48 236 for(Int_t is=0; is<kNScChannels; is++){
237 fprintf(mapFile4Shuttle,"\t%d\t%d\t%d\t%d\n",
238 is,tdcMod[is],tdcCh[is],tdcSigCode[is]);
239 //if(tdcMod[is]!=-1) printf(" Mapping DA -> %d TDC: mod %d ch %d, code %d\n",
240 // is,tdcMod[is],tdcCh[is],tdcSigCode[is]);
241 }
608444fb 242 for(Int_t is=0; is<kNModules; is++){
243 fprintf(mapFile4Shuttle,"\t%d\t%d\t%d\n",
244 modGeo[is],modType[is],modNCh[is]);
245 //printf(" Mapping DA -> Module mapping: geo %d type %d #ch %d\n",
246 // modGeo[is],modType[is],modNCh[is]);
247 }
198f612a 248
967dda6e 249 }
967dda6e 250 fclose(mapFile4Shuttle);
27afc0c8 251 }// SOD event
1af38adf 252 else{
b06a579c 253 printf("\t SOR read -> analyzing TDC info!\n");
254 if(rawData.GetADCModule()==kZDCTDCGeo && rawData.IsZDCTDCDatum()==kTRUE && ihittdc<1){
255 itdc = rawData.GetChannel();
256 if(itdc>=8 && itdc<=13){
257 if(itdc==iprevtdc) ihittdc++;
258 else ihittdc=0;
259 iprevtdc=itdc;
260 tdcData[itdc-8] = 0.025*rawStreamZDC->GetZDCTDCDatum();
261 }
262 if(itdc==15) tdcL0 = 0.025*rawStreamZDC->GetZDCTDCDatum();
1af38adf 263 }
b06a579c 264 for(int it=0; it<6; it++){
265 for(int ih=0; ih<4; ih++){
266 hTDC[it]->Fill(tdcData[it]-tdcL0);
267 }
268 }
967dda6e 269 }
1af38adf 270
271 iev++;
d3f256ca 272
273 /* free resources */
274 free(event);
1af38adf 275 }
276
1af38adf 277 }
b06a579c 278
279 /* Analysis of the histograms */
280 //
281 FILE *fileShuttle;
282 fileShuttle = fopen(TDCDATA_FILE,"w");
283 //
284 Float_t xUp=0., xLow=0., deltaX=0;
285 Int_t binMax=0, nBinsx=0;
286 Float_t mean[6], sigma[6];
287 TF1 *fitfun[6];
288 for(Int_t k=0; k<6; k++){
289 if(hTDC[k]->GetEntries()!=0){
290 binMax = hTDC[k]->GetMaximumBin();
291 printf("\n\t hTDC[%d]: binMax = %d", k, binMax);
292 if(binMax<=1){
293 printf("\n WARNING! Something wrong with det %d histo \n\n", k);
294 continue;
295 }
296 //
297 xUp = (hTDC[k]->GetXaxis())->GetXmax();
298 xLow = (hTDC[k]->GetXaxis())->GetXmin();
299 deltaX = xUp-xLow;
300 nBinsx = (hTDC[k]->GetXaxis())->GetNbins();
301 //printf(" xMax = %f\n", xLow+binMax*deltaX/nBinsx);
302 hTDC[k]->Fit("gaus","Q","",xLow+binMax*deltaX/nBinsx*0.6,xLow+binMax*deltaX/nBinsx*1.24);
303 fitfun[k] = hTDC[k]->GetFunction("gaus");
304 mean[k] = (Float_t) (fitfun[k]->GetParameter(1));
305 sigma[k] = (Float_t) (fitfun[k]->GetParameter(2));
306 //printf("\t Mean value from fit = %1.2f\n", mean[k]);
307 //
308 fprintf(fileShuttle,"\t%f\t%f\n",mean[k], sigma[k]);
309 }
310 }
311 //
312 fclose(fileShuttle);
313
314 TFile *histofile = new TFile(TDCHISTO_FILE,"RECREATE");
315 histofile->cd();
316 for(int k=0; k<6; k++) hTDC[6]->Write();
317 histofile->Close();
318 //
319 for(Int_t j=0; j<6; j++) delete hTDC[j];
967dda6e 320
967dda6e 321 /* store the result files on FES */
b06a579c 322 // [1] File with mapping
a8eaff64 323 status = daqDA_FES_storeFile(MAPDATA_FILE, "MAPPING");
967dda6e 324 if(status){
325 printf("Failed to export file : %d\n",status);
326 return -1;
327 }
b06a579c 328 // [2] File with TDC data
329 status = daqDA_FES_storeFile(TDCDATA_FILE, "TDCDATA");
330 if(status){
331 printf("Failed to export pedestal data file to DAQ FES\n");
332 return -1;
333 }
334 // [3] File with TDC histos
335 status = daqDA_FES_storeFile(TDCHISTO_FILE, "TDCHISTOS");
336 if(status){
337 printf("Failed to export pedestal histos file to DAQ FES\n");
338 return -1;
339 }
967dda6e 340
967dda6e 341 return status;
342}