1 //////////////////////////////////////////////////////////////////////////////
3 // * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 // * Author: The ALICE Off-line Project. *
6 // * Contributors are mentioned in the code where appropriate. *
8 // * Permission to use, copy, modify and distribute this software and its *
9 // * documentation strictly for non-commercial purposes is hereby granted *
10 // * without fee, provided that the above copyright notice appears in all *
11 // * copies and that both the copyright notice and this permission notice *
12 // * appear in the supporting documentation. The authors make no claims *
13 // * about the suitability of this software for any purpose. It is *
14 // * provided "as is" without express or implied warranty. *
15 // **************************************************************************/
17 //////////////////////////////////////////////////////////////////////////////
19 #include "Riostream.h"
22 #include "TObjString.h"
24 #include "TClonesArray.h"
26 #include "TObjArray.h"
30 // --- Standard library ---
32 // --- AliRoot header files ---
35 #include "AliRawReader.h"
36 #include "AliPMDRawStream.h"
37 #include "AliPMDddldata.h"
38 #include "AliPMDCalibGain.h"
40 ClassImp(AliPMDCalibGain)
42 AliPMDCalibGain::AliPMDCalibGain():
46 // Standard Constructor
47 for(Int_t idet = 0; idet < kDet; idet++)
49 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
51 fSMIso[idet][ismn] = 0.;
52 fSMCount[idet][ismn] = 0.;
53 fCountSm[idet][ismn]=0.;
54 fTempnhit[idet][ismn]=0.;
55 fTempnhitSq[idet][ismn]=0.;
56 for(Int_t jrow = 0; jrow < kMaxRow; jrow++)
58 for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
60 fCellIso[idet][ismn][jrow][kcol] = 0.;
61 fCellCount[idet][ismn][jrow][kcol] = 0.;
62 fNhitCell[idet][ismn][jrow][kcol] = 0.;
63 fPedMeanRMS[idet][ismn][jrow][kcol] = 0.;
64 fHotFlag[idet][ismn][jrow][kcol] = 0.;
72 // ------------------------------------------------------------------------ //
73 AliPMDCalibGain::AliPMDCalibGain(const AliPMDCalibGain &pmdcalibgain):
74 TObject(pmdcalibgain),
77 for(Int_t idet = 0; idet < kDet; idet++)
79 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
81 fSMIso[idet][ismn] = pmdcalibgain.fSMIso[idet][ismn] ;
82 fSMCount[idet][ismn] = pmdcalibgain.fSMCount[idet][ismn] ;
83 fCountSm[idet][ismn] = pmdcalibgain.fCountSm[idet][ismn];
84 fTempnhit[idet][ismn] = pmdcalibgain.fTempnhit[idet][ismn];
85 fTempnhitSq[idet][ismn] = pmdcalibgain.fTempnhitSq[idet][ismn];
86 for(Int_t jrow = 0; jrow < kMaxRow; jrow++)
88 for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
90 fCellIso[idet][ismn][jrow][kcol] = pmdcalibgain.fCellIso[idet][ismn][jrow][kcol];
91 fCellCount[idet][ismn][jrow][kcol] = pmdcalibgain.fCellCount[idet][ismn][jrow][kcol];
92 fNhitCell[idet][ismn][jrow][kcol] = pmdcalibgain.fNhitCell[idet][ismn][jrow][kcol];
93 fPedMeanRMS[idet][ismn][jrow][kcol] = pmdcalibgain.fPedMeanRMS[idet][ismn][jrow][kcol];
94 fHotFlag[idet][ismn][jrow][kcol] = pmdcalibgain.fHotFlag[idet][ismn][jrow][kcol];
102 // ------------------------------------------------------------------------ //
103 AliPMDCalibGain &AliPMDCalibGain::operator=(const AliPMDCalibGain &pmdcalibgain)
105 if(this != &pmdcalibgain)
107 this->fpw = pmdcalibgain.fpw;
108 for(Int_t idet = 0; idet < kDet; idet++)
110 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
112 fSMIso[idet][ismn] = pmdcalibgain.fSMIso[idet][ismn];
113 fSMCount[idet][ismn] = pmdcalibgain.fSMCount[idet][ismn];
114 fCountSm[idet][ismn] = pmdcalibgain.fCountSm[idet][ismn];
115 fTempnhit[idet][ismn] = pmdcalibgain.fTempnhit[idet][ismn];
116 fTempnhitSq[idet][ismn] = pmdcalibgain.fTempnhitSq[idet][ismn];
117 for(Int_t jrow = 0; jrow < kMaxRow;jrow++)
119 for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
121 fCellIso[idet][ismn][jrow][kcol] = pmdcalibgain.fCellIso[idet][ismn][jrow][kcol];
122 fCellCount[idet][ismn][jrow][kcol] = pmdcalibgain.fCellCount[idet][ismn][jrow][kcol];
123 fNhitCell[idet][ismn][jrow][kcol] = pmdcalibgain.fNhitCell[idet][ismn][jrow][kcol]; //za
124 fPedMeanRMS[idet][ismn][jrow][kcol] = pmdcalibgain.fPedMeanRMS[idet][ismn][jrow][kcol];
125 fHotFlag[idet][ismn][jrow][kcol] = pmdcalibgain.fHotFlag[idet][ismn][jrow][kcol];
134 // ------------------------------------------------------------------------ //
135 AliPMDCalibGain::~AliPMDCalibGain()
140 // ------------------------------------------------------------------------ //
142 Int_t AliPMDCalibGain::ExtractPedestal(const Char_t *rootFile)
144 // Pedestal extraction from the PMD_PED.root file
145 // To be called once at the beginning
147 Int_t det=0, sm=0, row=0, col=0;
148 Float_t mean=0., rms=0.;
150 TFile *pedfile = new TFile(rootFile);
154 printf("ERROR --- NO PEDESTAL (PMD_PED1.root) FILE IS FOUND --- STOP GAIN DA\n");
159 TTree *ped =(TTree*)pedfile->Get("ped");
161 ped->SetBranchAddress("det",&det);
162 ped->SetBranchAddress("sm",&sm);
163 ped->SetBranchAddress("row",&row);
164 ped->SetBranchAddress("col",&col);
165 ped->SetBranchAddress("mean",&mean);
166 ped->SetBranchAddress("rms",&rms);
168 Int_t nentries = (Int_t)ped->GetEntries();
170 for (Int_t ient = 0; ient < nentries; ient++)
173 fPedMeanRMS[det][sm][row][col] = mean + 3.*rms;
174 //printf("Mean= %f, RMS= %f, PedMeanRMS=%f\n",mean,rms,fPedMeanRMS[det][sm][row][col]);
184 //------------------------------------------------------------------------------------------------
186 Int_t AliPMDCalibGain::ExtractHotChannel(const Char_t *rootFile)
188 // HotChannel extraction from the PMD_HOT.root file
189 // To be called once at the beginning
191 Int_t det=0, sm=0, row=0, col=0;
194 TFile *hotmapfile = new TFile(rootFile);
198 printf(" NO HOTCHANNEL MAP (PMD_HOT.root) FILE IS FOUND \n");
200 for (Int_t idet = 0; idet < kDet; idet++)
202 for (Int_t ismn = 0; ismn < kMaxSMN; ismn++)
204 for (Int_t irow = 0; irow < kMaxRow; irow++)
206 for (Int_t icol = 0; icol < kMaxCol; icol++)
208 fHotFlag[idet][kMaxSMN][kMaxRow][kMaxCol] = 0.;
216 TTree *hot =(TTree*)hotmapfile->Get("hot");
218 hot->SetBranchAddress("det",&det);
219 hot->SetBranchAddress("sm",&sm);
220 hot->SetBranchAddress("row",&row);
221 hot->SetBranchAddress("col",&col);
222 hot->SetBranchAddress("flag",&flag);
224 Int_t nentries = (Int_t)hot->GetEntries();
226 for (Int_t ient = 0; ient < nentries; ient++)
229 fHotFlag[det][sm][row][col] = flag;
231 //printf(" HotFlag=%f\n",fHotFlag[det][sm][row][col]);
242 // ------------------------------------------------------------------------ //
244 void AliPMDCalibGain::ReadTempFile(const Char_t *tempFile)
246 // Read the variables from the file
248 fpw = fopen(tempFile,"r");
250 Int_t iddet = 0, issm = 0, irrow = 0, iccol = 0;
251 Float_t smcount = 0., smiso = 0.;
252 Float_t cellcount = 0., celliso = 0.;
255 for (Int_t idet = 0; idet < kDet; idet++)
257 for (Int_t ism = 0; ism < kMaxSMN; ism++)
259 fscanf(fpw,"%d %d %f %f",&iddet,&issm,&smcount,&smiso);
260 fSMCount[idet][ism] = smcount;
261 fSMIso[idet][ism] = smiso;
265 for (Int_t idet = 0; idet < kDet; idet++)
267 for (Int_t ism = 0; ism < kMaxSMN; ism++)
269 for (Int_t irow = 0; irow < kMaxRow; irow++)
271 for (Int_t icol = 0; icol < kMaxCol; icol++)
273 fscanf(fpw,"%d %d %d %d %f %f",&iddet,&issm,&irrow,&iccol,
274 &cellcount,&celliso);
275 fCellCount[idet][ism][irow][icol] = cellcount;
276 fCellIso[idet][ism][irow][icol] = celliso;
285 // ------------------------------------------------------------------------ //
286 void AliPMDCalibGain::WriteTempFile(const Char_t *tempFile)
288 // Write the Temporary file if the required statics is not achieved
292 Following variables to be written to a file
295 fCellIso[idet][ismn][irow][icol];
298 fSMCount[idet][ismn];
299 fCellCount[idet][ismn][irow][icol];
303 fpw = fopen(tempFile,"w+");
305 for (Int_t idet = 0; idet < kDet; idet++)
307 // fprintf(fpw,"%d %f %f\n",idet,fDetCount[idet],fDetIso[idet]);
310 for (Int_t idet = 0; idet < kDet; idet++)
312 for (Int_t ism = 0; ism < kMaxSMN; ism++)
314 fprintf(fpw,"%d %d %f %f\n",idet,ism, fSMCount[idet][ism],fSMIso[idet][ism]);
318 for (Int_t idet = 0; idet < kDet; idet++)
320 for (Int_t ism = 0; ism < kMaxSMN; ism++)
322 for (Int_t irow = 0; irow < kMaxRow; irow++)
324 for (Int_t icol = 0; icol < kMaxCol; icol++)
326 fprintf(fpw,"%d %d %d %d %f %f\n",idet,ism,irow,icol,
327 fCellCount[idet][ism][irow][icol],
328 fCellIso[idet][ism][irow][icol]);
338 // ------------------------------------------------------------------------ //
340 Bool_t AliPMDCalibGain::ProcessEvent(AliRawReader *rawReader, TObjArray *pmdddlcont)
342 // Calculates the ADC of isolated cell
344 const Int_t kDDL = AliDAQ::NumberOfDdls("PMD");
345 const Int_t kCellNeighbour = 6;
346 Int_t neibx[6] = {1,0,-1,-1,0,1};
347 Int_t neiby[6] = {0,1,1,0,-1,-1};
349 Int_t id1 = 0,jd1 = 0; //neighbour row/col
350 Int_t isocount = 0; //number of neighbours with 0 signal
352 Float_t d1[kDet][kMaxSMN][kMaxRow][kMaxCol];
354 for(Int_t idet = 0; idet < kDet; idet++)
356 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
358 for(Int_t irow = 0; irow < kMaxRow; irow++)
360 for(Int_t icol = 0; icol < kMaxCol; icol++)
362 d1[idet][ismn][irow][icol] = 0.;
368 AliPMDRawStream rawStream(rawReader);
372 Int_t numberofDDLs = 0;
374 while ((iddl = rawStream.DdlData(pmdddlcont)) >=0) {
377 Int_t ientries = pmdddlcont->GetEntries();
379 for (Int_t ient = 0; ient < ientries; ient++)
381 AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont->UncheckedAt(ient);
383 Int_t idet = pmdddl->GetDetector();
384 Int_t ismn = pmdddl->GetSMN();
385 Int_t mcm = pmdddl->GetMCM();
386 //Int_t ichno = pmdddl->GetChannel();
387 Int_t irow = pmdddl->GetRow();
388 Int_t icol = pmdddl->GetColumn();
389 Int_t isig = pmdddl->GetSignal();
391 // This is the protection not to crash the code
393 if(mcm == 0) continue;
394 if (irow < 0 || icol < 0 || irow > 47 || icol > 95) continue;
396 // Pedestal subtraction
397 if(fHotFlag[idet][ismn][irow][icol] == 1.0) isig = 0;
401 d1[idet][ismn][irow][icol] =
402 (Float_t) isig - fPedMeanRMS[idet][ismn][irow][icol];
404 //printf("Signal_ped_subtracted=%f, pedestal=%f\n",d1[idet][ismn][irow][icol]),fPedMeanRMS[idet][ismn][irow][icol];
406 fNhitCell[idet][ismn][irow][icol]++; //cell hit frequency
411 pmdddlcont->Delete();
414 for(Int_t idet=0; idet < kDet; idet++)
416 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
418 for(Int_t irow = 0; irow < kMaxRow; irow++)
420 for(Int_t icol = 0; icol < kMaxCol; icol++)
422 if(d1[idet][ismn][irow][icol] > 0)
425 for(Int_t ii = 0; ii < kCellNeighbour; ii++)
427 id1 = irow + neibx[ii];
428 jd1 = icol + neiby[ii];
429 if (id1 < 0) id1 = 0;
430 if (id1 > kMaxRow-1) id1 = kMaxRow - 1;
431 if (jd1 < 0) jd1 = 0;
432 if (jd1 > kMaxCol-1) jd1 = kMaxCol - 1;
433 if(d1[idet][ismn][id1][jd1] == 0)
436 if(isocount == kCellNeighbour)
438 //fDetIso[idet] += d1[idet][ismn][irow][icol];
439 fSMIso[idet][ismn] += d1[idet][ismn][irow][icol];
440 fCellIso[idet][ismn][irow][icol] += d1[idet][ismn][irow][icol];
442 fSMCount[idet][ismn]++;
443 fCellCount[idet][ismn][irow][icol]++;
447 } // neigh cell cond.
454 for(Int_t idet=0; idet < kDet; idet++)
456 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
458 for(Int_t irow = 0; irow < kMaxRow; irow++)
460 for(Int_t icol = 0; icol < kMaxCol; icol++)
462 if(fNhitCell[idet][ismn][irow][icol]>0)
464 fCountSm[idet][ismn] += 1;
465 fTempnhit[idet][ismn] += fNhitCell[idet][ismn][irow][icol];
466 fTempnhitSq[idet][ismn] += fNhitCell[idet][ismn][irow][icol]
467 *fNhitCell[idet][ismn][irow][icol];
474 if (numberofDDLs < kDDL) return kFALSE;
478 // ------------------------------------------------------------------------ //
479 void AliPMDCalibGain::Analyse(TTree *gaintree, TTree *meantree)
481 // Calculates the mean
482 Int_t det = 0, sm = 0, row = 0, col = 0;
484 Float_t cellmean = 0.;
486 Float_t modmean[2][24];
488 for (Int_t idet=0; idet < 2; idet++)
490 for (Int_t ism = 0; ism < 24; ism++)
492 modmean[idet][ism] = 0.;
496 gaintree->Branch("det",&det,"det/I");
497 gaintree->Branch("sm",&sm,"sm/I");
498 gaintree->Branch("row",&row,"row/I");
499 gaintree->Branch("col",&col,"col/I");
500 gaintree->Branch("gain",&gain,"gain/F");
502 for(Int_t idet = 0; idet < kDet; idet++)
504 for(Int_t ism = 0; ism < kMaxSMN; ism++)
506 if (fSMCount[idet][ism] > 0)
507 modmean[idet][ism] = fSMIso[idet][ism]/fSMCount[idet][ism];
508 for(Int_t irow = 0; irow < kMaxRow; irow++)
510 for(Int_t icol = 0; icol < kMaxCol; icol++)
512 if (fCellCount[idet][ism][irow][icol] > 0.)
514 cellmean = fCellIso[idet][ism][irow][icol]/fCellCount[idet][ism][irow][icol];
520 if (cellmean > 0.0 && fCellCount[idet][ism][irow][icol]>0.)
522 gain = cellmean/modmean[idet][ism];
528 //if(fCellCount[idet][ism][irow][icol]>0.) printf("CellCount =%f, gain= %f\n",fCellCount[idet][ism][irow][icol],gain);
537 // Writing each module mean value
538 meantree->Branch("det",&det,"det/I");
539 meantree->Branch("sm",&sm,"sm/I");
540 meantree->Branch("smmean",&smmean,"row/F");
542 for(Int_t idet = 0; idet < kDet; idet++)
544 for (Int_t ism = 0; ism < kMaxSMN; ism++)
548 smmean = modmean[idet][ism];
554 // ------------------------------------------------------------------------ //
555 void AliPMDCalibGain::FindHotCell(TTree *hottree, Float_t xvar)
557 // Calculates the mean
558 Int_t det = 0, sm = 0, row = 0, col = 0;
560 Float_t meannhit = 0.;
561 Float_t meanSqnhit = 0.;
562 Float_t sigmanhit = 0.,nhitcut = 0.;
566 hottree->Branch("det",&det,"det/I");
567 hottree->Branch("sm",&sm,"sm/I");
568 hottree->Branch("row",&row,"row/I");
569 hottree->Branch("col",&col,"col/I");
570 hottree->Branch("flag",&flag,"flag/F");
572 for(Int_t idet = 0; idet < kDet; idet++)
574 for(Int_t ism = 0; ism < kMaxSMN; ism++)
576 if (fCountSm[idet][ism]> 0)
578 meannhit = fTempnhit[idet][ism]/fCountSm[idet][ism];
579 meanSqnhit = fTempnhitSq[idet][ism]/fCountSm[idet][ism];
580 sigmanhit = sqrt(meanSqnhit-(meannhit*meannhit));
581 nhitcut = meannhit + xvar*sigmanhit;
583 for(Int_t irow = 0; irow < kMaxRow; irow++)
585 for(Int_t icol = 0; icol < kMaxCol; icol++)
592 if(fNhitCell[idet][ism][irow][icol] > nhitcut)