]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDCalibChamberStatus.cxx
Procedures for half chamber status (Julian)
[u/mrichter/AliRoot.git] / TRD / AliTRDCalibChamberStatus.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, 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 ////////////////////////////////////////////////////////////////////////////
17 //                                                                        //
18 // AliTRDCalibChamberStatus: to determine which half chambers are off     //
19 // Produce a AliTRDCalChamberStatus calibration object                    //
20 // Check with the AliTRDCalDCSFEE info                                    //
21 //                                                                        //
22 //                                                                        //
23 // Authors:                                                               //
24 //   J. Book (jbook@ikf.uni-frankfurt.de)                                 //
25 //   R. Bailhache (rbailhache@ikf.uni-frankfurt.de)                       //
26 //                                                                        //
27 ////////////////////////////////////////////////////////////////////////////
28
29
30 //Root includes
31 #include <THnSparse.h>
32
33 #include <TDirectory.h>
34 #include <TFile.h>
35
36 //AliRoot includes
37 #include "AliRawReader.h"
38
39 //header file
40 #include "AliLog.h"
41 #include "AliTRDCalibChamberStatus.h"
42 #include "AliTRDgeometry.h"
43 #include "AliTRDdigitsManager.h"
44 #include "AliTRDSignalIndex.h"
45 #include "AliTRDrawFastStream.h"
46 #include "./Cal/AliTRDCalChamberStatus.h"
47 #include "./Cal/AliTRDCalDCS.h"
48 #include "./Cal/AliTRDCalDCSFEE.h"
49
50 #ifdef ALI_DATE
51 #include "event.h"
52 #endif
53
54 ClassImp(AliTRDCalibChamberStatus) /*FOLD00*/
55
56 //_____________________________________________________________________
57 AliTRDCalibChamberStatus::AliTRDCalibChamberStatus() : /*FOLD00*/
58   TObject(),
59   fDetector(-1),
60   fNumberOfTimeBins(0),
61   fCounterEventNotEmpty(0),
62   fCalChamberStatus(0x0),
63   fHnSparseI(0x0),
64   fHnSparseHCM(0x0),
65   fHnSparseEvtDet(0x0),
66   fHnSparseDebug(0x0),
67   fHnSparseMCM(0x0),
68   fDebugLevel(0)
69 {
70     //
71     // default constructor
72     //
73
74 }
75 //_____________________________________________________________________
76 AliTRDCalibChamberStatus::AliTRDCalibChamberStatus(const AliTRDCalibChamberStatus &ped) : /*FOLD00*/
77   TObject(ped),
78   fDetector(ped.fDetector),
79   fNumberOfTimeBins(ped.fNumberOfTimeBins),
80   fCounterEventNotEmpty(ped.fCounterEventNotEmpty),
81   fCalChamberStatus(ped.fCalChamberStatus),
82   fHnSparseI(ped.fHnSparseI),
83   fHnSparseHCM(ped.fHnSparseHCM),
84   fHnSparseEvtDet(ped.fHnSparseEvtDet),
85   fHnSparseDebug(ped.fHnSparseDebug),  
86   fHnSparseMCM(ped.fHnSparseMCM),
87   fDebugLevel(ped.fDebugLevel)
88 {
89     //
90     // copy constructor
91     //
92   
93 }
94 //_____________________________________________________________________
95 AliTRDCalibChamberStatus& AliTRDCalibChamberStatus::operator = (const  AliTRDCalibChamberStatus &source)
96 {
97   //
98   // assignment operator
99   //
100   if (&source == this) return *this;
101   new (this) AliTRDCalibChamberStatus(source);
102
103   return *this;
104 }
105 //_____________________________________________________________________
106 AliTRDCalibChamberStatus::~AliTRDCalibChamberStatus() /*FOLD00*/
107 {
108   //
109   // destructor
110   //
111   if(fCalChamberStatus){
112     delete fCalChamberStatus;
113   }
114   if(fHnSparseI) {
115     delete fHnSparseI;
116   }
117   if(fHnSparseHCM) {
118     delete fHnSparseHCM;
119   }
120   if(fHnSparseEvtDet) {
121     delete fHnSparseEvtDet;
122   }
123   if(fHnSparseDebug) {
124     delete fHnSparseDebug;
125   }
126   if(fHnSparseMCM) {
127    delete fHnSparseMCM;
128  }
129 }
130
131 //_____________________________________________________________________
132 void AliTRDCalibChamberStatus::Init() 
133 {
134   //
135   // Init the different THnSparse
136   //
137   //
138
139   //
140   // Init the fHnSparseI
141   //
142
143   //create the map
144   Int_t thnDimEvt[4]; // sm, layer, stack, halfchamber
145   thnDimEvt[0] = 18;
146   thnDimEvt[1] = 6;
147   thnDimEvt[2] = 5;
148   thnDimEvt[3] = 2;
149   //arrays for lower bounds :
150   Double_t* binEdgesEvt[4];
151   for(Int_t ivar = 0; ivar < 4; ivar++)
152     binEdgesEvt[ivar] = new Double_t[thnDimEvt[ivar] + 1];
153   //values for bin lower bounds
154   for(Int_t i=0; i<=thnDimEvt[0]; i++) binEdgesEvt[0][i]= 0.0  + (18.0)/thnDimEvt[0]*(Double_t)i;
155   for(Int_t i=0; i<=thnDimEvt[1]; i++) binEdgesEvt[1][i]= 0.0  + (6.0)/thnDimEvt[1]*(Double_t)i;
156   for(Int_t i=0; i<=thnDimEvt[2]; i++) binEdgesEvt[2][i]= 0.0  + (5.0)/thnDimEvt[2]*(Double_t)i;
157   for(Int_t i=0; i<=thnDimEvt[3]; i++) binEdgesEvt[3][i]= 0.0  + (2.0)/thnDimEvt[3]*(Double_t)i;
158   
159   //create the THnSparse
160   fHnSparseI = new THnSparseI("NumberOfEntries","NumberOfEntries",4,thnDimEvt);
161   for (int k=0; k<4; k++) {
162     fHnSparseI->SetBinEdges(k,binEdgesEvt[k]);
163   }
164   fHnSparseI->Sumw2();
165
166   //
167   // Init the fHnSparseHCM (THnSparseI)
168   //
169
170   //create the THnSparse
171   fHnSparseHCM = new THnSparseI("HCMerrors","HCMerrors",4,thnDimEvt);
172   for (int k=0; k<4; k++) {
173     fHnSparseHCM->SetBinEdges(k,binEdgesEvt[k]);
174   }
175   fHnSparseHCM->Sumw2();
176
177
178   //---------//
179   //  Debug  //
180   if(fDebugLevel > 0) {
181   
182     //
183     // Init the fHnSparseEvtDet (THnSparseI)
184     //
185     
186     //create the map
187     Int_t thnDimEvts[3]; // event, detector, halfchamber
188     thnDimEvts[0] = 10000;
189     thnDimEvts[1] = 540;
190     thnDimEvts[2] = 2;
191     //arrays for lower bounds :
192     Double_t* binEdgesEvts[3];
193     for(Int_t ivar = 0; ivar < 3; ivar++)
194       binEdgesEvts[ivar] = new Double_t[thnDimEvts[ivar] + 1];
195     //values for bin lower bounds
196     for(Int_t i=0; i<=thnDimEvts[0]; i++) binEdgesEvts[0][i]= 0.0  + (10000.0)/thnDimEvts[0]*(Double_t)i;
197     for(Int_t i=0; i<=thnDimEvts[1]; i++) binEdgesEvts[1][i]= 0.0  + (540.0)/thnDimEvts[1]*(Double_t)i;
198     for(Int_t i=0; i<=thnDimEvts[2]; i++) binEdgesEvts[2][i]= 0.0  + (2.0)/thnDimEvts[2]*(Double_t)i;
199     
200     //create the THnSparse
201     fHnSparseEvtDet = new THnSparseI("NumberOfEntriesPerEvent","NumberOfEntriesPerEvent",3,thnDimEvts);
202     for (int k=0; k<3; k++) {
203       fHnSparseEvtDet->SetBinEdges(k,binEdgesEvts[k]);
204     }
205     fHnSparseEvtDet->Sumw2();
206
207     //
208     // Init the fHnSparseDebug (THnSparseI)
209     //
210     
211     //create the THnSparse
212     fHnSparseDebug = new THnSparseI("NumberOfDifferentDecisions","NumberOfDifferentDecisions",4,thnDimEvt);
213     for (int k=0; k<4; k++) {
214       fHnSparseDebug->SetBinEdges(k,binEdgesEvt[k]);
215     }
216     fHnSparseDebug->Sumw2();
217         
218     //
219     // Init the fHnSparseMCM (THnSparseI)
220     //
221     
222     //create the map
223     Int_t thnDimEvtt[6]; // sm, layer, stack, ROB, MCM
224     thnDimEvtt[0] = 18;
225     thnDimEvtt[1] = 6;
226     thnDimEvtt[2] = 5;
227     thnDimEvtt[3] = 8;
228     thnDimEvtt[4] = 16;
229     thnDimEvtt[5] = 16;
230     //arrays for lower bounds :
231     Double_t* binEdgesEvtt[6];
232     for(Int_t ivar = 0; ivar < 6; ivar++)
233       binEdgesEvtt[ivar] = new Double_t[thnDimEvtt[ivar] + 1];
234     //values for bin lower bounds
235     for(Int_t i=0; i<=thnDimEvtt[0]; i++) binEdgesEvtt[0][i]= 0.0  + (18.0)/thnDimEvtt[0]*(Double_t)i;
236     for(Int_t i=0; i<=thnDimEvtt[1]; i++) binEdgesEvtt[1][i]= 0.0  + (6.0)/thnDimEvtt[1]*(Double_t)i;
237     for(Int_t i=0; i<=thnDimEvtt[2]; i++) binEdgesEvtt[2][i]= 0.0  + (5.0)/thnDimEvtt[2]*(Double_t)i;
238     for(Int_t i=0; i<=thnDimEvtt[3]; i++) binEdgesEvtt[3][i]= 0.0  + (8.0)/thnDimEvtt[3]*(Double_t)i;
239     for(Int_t i=0; i<=thnDimEvtt[4]; i++) binEdgesEvtt[4][i]= 0.0  + (16.0)/thnDimEvtt[4]*(Double_t)i;
240     for(Int_t i=0; i<=thnDimEvtt[5]; i++) binEdgesEvtt[5][i]= 0.0  + (16.0)/thnDimEvtt[5]*(Double_t)i;
241     
242     //create the THnSparse
243     fHnSparseMCM = new THnSparseI("MCMerrorDCS","MCMerrorDCS",6,thnDimEvtt);
244     for (int k=0; k<6; k++) {
245       fHnSparseMCM->SetBinEdges(k,binEdgesEvtt[k]);
246     }
247     fHnSparseMCM->Sumw2();
248   
249   }
250   //  Debug  //
251   //---------//
252
253 }
254 //_____________________________________________________________________
255 void AliTRDCalibChamberStatus::ProcessEvent(AliRawReader * rawReader, Int_t nevents_physics)
256 {
257   //
258   // Event Processing loop 
259   //
260   //
261   
262   Bool_t notEmpty = kFALSE;
263     
264   AliTRDrawFastStream *rawStream = new AliTRDrawFastStream(rawReader);
265   rawStream->SetSharedPadReadout(kFALSE);
266
267   AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager(kTRUE);
268   digitsManager->CreateArrays();
269   
270   Int_t det    = 0;
271   while ((det = rawStream->NextChamber(digitsManager, NULL, NULL)) >= 0) { 
272
273     //nextchamber loop
274     
275     // do the QA analysis
276     if (digitsManager->GetIndexes(det)->HasEntry()) {//QA
277       // printf("there is ADC data on this chamber!\n");
278       
279       AliTRDSignalIndex *indexes = digitsManager->GetIndexes(det);
280       if (indexes->IsAllocated() == kFALSE) {
281         // AliError("Indexes do not exist!");
282         break;
283       }
284       
285       Int_t iRow  = 0;
286       Int_t iCol  = 0;
287       indexes->ResetCounters();
288       
289       while (indexes->NextRCIndex(iRow, iCol)){
290         Int_t iMcm        = (Int_t)(iCol/18);   // current group of 18 col pads
291         
292         Int_t layer = AliTRDgeometry::GetLayer(det);
293         Int_t sm    = AliTRDgeometry::GetSector(det);
294         Int_t stac  = AliTRDgeometry::GetStack(det);
295         Double_t rphi = 0.5;
296         if(iMcm > 3) rphi = 1.5;
297
298         Double_t val[4] = {sm,layer,stac,rphi}; 
299         fHnSparseI->Fill(&val[0]); 
300         notEmpty = kTRUE;
301         
302         //---------//
303         //  Debug  //
304         if(fDebugLevel > 0) {
305           Int_t detector = AliTRDgeometry::GetDetector(layer,stac,sm);
306           Double_t valu[3] = {nevents_physics,detector,rphi};
307           fHnSparseEvtDet->Fill(&valu[0]); 
308         }
309         //  Debug  //
310         //---------//
311       }
312       
313     }
314     digitsManager->ClearArrays(det);
315   }
316
317   if(notEmpty) fCounterEventNotEmpty++;
318
319   if(digitsManager) delete digitsManager;
320   if(rawStream) delete rawStream;
321    
322 }
323 //_____________________________________________________________________
324 Bool_t AliTRDCalibChamberStatus::TestEventHisto(Int_t nevent) /*FOLD00*/
325 {
326   //
327   //  Test event loop
328   // fill the fHnSparseI with entries
329   //
330   
331   AliTRDgeometry geo;
332
333
334   for(Int_t ievent=0; ievent<nevent; ievent++){
335     for (Int_t ism=0; ism<18; ism++){
336       for (Int_t istack=0; istack<5; istack++){
337         for (Int_t ipl=0; ipl<6; ipl++){
338           for (Int_t icol=0; icol<geo.GetColMax(ipl); icol++){
339             Int_t side = 0;
340             if(icol > 72) side = 1;
341             Double_t val[4] = {ism,ipl,istack,side}; 
342             fHnSparseI->Fill(&val[0]); 
343           }
344         }
345       }
346     }
347   }
348   
349   return kTRUE;
350
351 }
352 //_____________________________________________________________________
353 void AliTRDCalibChamberStatus::AnalyseHisto() /*FOLD00*/
354 {
355     //
356     //  Create the AliTRDCalChamberStatus according to the fHnSparseI
357     //
358
359   if(fCalChamberStatus) delete fCalChamberStatus;
360   fCalChamberStatus = new AliTRDCalChamberStatus();
361
362   // Check if enough events to say something
363   if(fCounterEventNotEmpty < 30) {
364     // Say all installed
365     for (Int_t ism=0; ism<18; ism++) {
366       for (Int_t ipl=0; ipl<6; ipl++) {
367         for (Int_t istack=0; istack<5; istack++) {
368           // layer, stack, sector
369           Int_t det = AliTRDgeometry::GetDetector(ipl,istack,ism);
370           fCalChamberStatus->SetStatus(det,1);
371         }
372       }
373     }
374     return;
375   }
376
377   // Mask out all chambers
378   for (Int_t ism=0; ism<18; ism++) {
379     for (Int_t ipl=0; ipl<6; ipl++) {
380       for (Int_t istack=0; istack<5; istack++) {
381         // layer, stack, sector
382         Int_t det = AliTRDgeometry::GetDetector(ipl,istack,ism);
383         fCalChamberStatus->SetStatus(det,2);
384       }
385     }
386   }
387
388   // Unmask good chambers 
389   Int_t coord[4];
390   for(Int_t bin = 0; bin < fHnSparseI->GetNbins(); bin++) {
391     
392     fHnSparseI->GetBinContent(bin,coord);
393     // layer, stack, sector
394     Int_t detector = AliTRDgeometry::GetDetector(coord[1]-1,coord[2]-1,coord[0]-1);
395
396     //
397     // Check which halfchamber side corresponds to the bin number (0=A, 1=B)
398     // Change the status accordingly
399     //
400
401     switch(fCalChamberStatus->GetStatus(detector)) 
402       {    
403       case 1: break;  // no changes
404       case 2: 
405         if(coord[3]-1==0) {
406           fCalChamberStatus->SetStatus(detector,4); break;      // only SideB is masked
407         }
408         else {
409           fCalChamberStatus->SetStatus(detector,3); break;      // only SideA is masked
410         }
411       case 3:  fCalChamberStatus->SetStatus(detector,1); break;  // unmask SideA
412       case 4:  fCalChamberStatus->SetStatus(detector,1); break;  // unmask SideB
413       }
414   }
415
416
417 }
418 //_____________________________________________________________________
419 void AliTRDCalibChamberStatus::CheckEORStatus(AliTRDCalDCS *calDCS) /*FOLD00*/
420 {
421   //
422   //  Correct the AliTRDCalChamberStatus according to the AliTRDCalDCS
423   //  Using globale state of the HalfChamberMerger (HCM)
424   //
425   
426   for(Int_t det = 0; det < 540; det++) {
427     AliTRDCalDCSFEE* calDCSFEEEOR = calDCS->GetCalDCSFEEObj(det);
428     if(!calDCSFEEEOR) { continue;}
429     
430     // MCM Global State Machine State Definitions
431     //  low_power =  0,
432     //  test      =  1,
433     //  wait_pre  =  3,
434     //  preproc   =  7,
435     //  zero_sp   =  8,
436     //  full_rd   =  9,
437     //  clear_st  = 11,
438     //  wait_L1   = 12,
439     //  tr_send   = 14,
440     //  tr_proc   = 15 
441
442     Int_t sm   = AliTRDgeometry::GetSector(det);
443     Int_t lay  = AliTRDgeometry::GetLayer(det);
444     Int_t stac = AliTRDgeometry::GetStack(det);
445     
446     Int_t stateA = calDCSFEEEOR->GetMCMGlobalState(4,17); // HCM Side A
447     Int_t stateB = calDCSFEEEOR->GetMCMGlobalState(5,17); // HCM Side B
448     Int_t rphi = -1;
449
450     //printf("DCS: stateA %d \t stateB %d \n",stateA,stateB);
451     if(stateA!=3 && stateA!=9) rphi = 1;
452     Double_t vals[4] = {sm,lay,stac,rphi};
453     if(rphi!=-1) fHnSparseHCM->Fill(&vals[0]);
454     
455     if(stateB!=3 && stateB!=9) rphi = 2;
456     vals[3] = rphi;
457     if(rphi!=-1) fHnSparseHCM->Fill(&vals[0]);
458     
459     //---------//
460     //  Debug  //
461     if(fDebugLevel > 0) {
462       if( (fCalChamberStatus->GetStatus(det) <= 1) && (stateA!=3 && stateA!=9) || 
463           (fCalChamberStatus->GetStatus(det) <= 1) && (stateB!=3 && stateB!=9) || 
464           (fCalChamberStatus->GetStatus(det) >= 2) && (stateA==3 || stateA==9) || 
465           (fCalChamberStatus->GetStatus(det) >= 2) && (stateB==3 || stateB==9)  )
466         {
467           //printf(" Different half chamber status in DCS and DATA!!\n");
468           Double_t val[4] = {sm,lay,stac,1};
469           fHnSparseDebug->Fill(&val[0]); 
470           
471           if(rphi!=-1) {  // error in DCS information
472             // Fill MCM status map
473             for(Int_t ii = 0; ii < 8; ii++) { //ROB loop
474               for(Int_t i = 0; i < 16; i++) { //MCM loop
475                 Double_t valss[6] = {sm,lay,stac,ii,i
476                                      ,calDCSFEEEOR->GetMCMGlobalState(ii,i)};
477                 fHnSparseMCM->Fill(&valss[0]);
478               }
479             } 
480           }
481         }
482     }
483     //---------//
484     //  Debug  //
485   }
486
487 }
488
489 //_____________________________________________________________________________________
490 void AliTRDCalibChamberStatus::Add(AliTRDCalibChamberStatus *calibChamberStatus) /*FOLD00*/
491 {
492     //
493     //  Add the THnSparseI of this calibChamberStatus
494     //
495
496   fCounterEventNotEmpty += calibChamberStatus->GetNumberEventNotEmpty();
497
498   THnSparseI *hnSparseI = calibChamberStatus->GetSparseI();
499   if(!hnSparseI) return;
500
501   if(!fHnSparseI) {
502     fHnSparseI = (THnSparseI *) hnSparseI->Clone();
503   }
504   else {
505     fHnSparseI->Add(hnSparseI);
506   }
507   
508
509 }
510 //_____________________________________________________________________
511 void AliTRDCalibChamberStatus::DumpToFile(const Char_t *filename, const Char_t *dir, Bool_t append) /*FOLD00*/
512 {
513     //
514     //  Write class to file
515     //
516
517     TString sDir(dir);
518     TString option;
519
520     if ( append )
521         option = "update";
522     else
523         option = "recreate";
524
525     TDirectory *backup = gDirectory;
526     TFile f(filename,option.Data());
527     f.cd();
528     if ( !sDir.IsNull() ){
529         f.mkdir(sDir.Data());
530         f.cd(sDir);
531     }
532     this->Write();
533     f.Close();
534
535     if ( backup ) backup->cd();
536 }
537
538