1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 ////////////////////////////////////////////////////////////////////////////
18 // AliTRDCalibChamberStatus: to determine which half chambers are off //
19 // Produce a AliTRDCalChamberStatus calibration object //
20 // Check with the AliTRDCalDCSFEE info //
24 // J. Book (jbook@ikf.uni-frankfurt.de) //
25 // R. Bailhache (rbailhache@ikf.uni-frankfurt.de) //
27 ////////////////////////////////////////////////////////////////////////////
31 #include <THnSparse.h>
33 #include <TDirectory.h>
37 #include "AliRawReader.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"
54 ClassImp(AliTRDCalibChamberStatus) /*FOLD00*/
56 //_____________________________________________________________________
57 AliTRDCalibChamberStatus::AliTRDCalibChamberStatus() : /*FOLD00*/
61 fCounterEventNotEmpty(0),
62 fCalChamberStatus(0x0),
71 // default constructor
75 //_____________________________________________________________________
76 AliTRDCalibChamberStatus::AliTRDCalibChamberStatus(const AliTRDCalibChamberStatus &ped) : /*FOLD00*/
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)
94 //_____________________________________________________________________
95 AliTRDCalibChamberStatus& AliTRDCalibChamberStatus::operator = (const AliTRDCalibChamberStatus &source)
98 // assignment operator
100 if (&source == this) return *this;
101 new (this) AliTRDCalibChamberStatus(source);
105 //_____________________________________________________________________
106 AliTRDCalibChamberStatus::~AliTRDCalibChamberStatus() /*FOLD00*/
111 if(fCalChamberStatus){
112 delete fCalChamberStatus;
120 if(fHnSparseEvtDet) {
121 delete fHnSparseEvtDet;
124 delete fHnSparseDebug;
131 //_____________________________________________________________________
132 void AliTRDCalibChamberStatus::Init()
135 // Init the different THnSparse
140 // Init the fHnSparseI
144 Int_t thnDimEvt[4]; // sm, layer, stack, halfchamber
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;
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]);
167 // Init the fHnSparseHCM (THnSparseI)
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]);
175 fHnSparseHCM->Sumw2();
180 if(fDebugLevel > 0) {
183 // Init the fHnSparseEvtDet (THnSparseI)
187 Int_t thnDimEvts[3]; // event, detector, halfchamber
188 thnDimEvts[0] = 10000;
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;
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]);
205 fHnSparseEvtDet->Sumw2();
208 // Init the fHnSparseDebug (THnSparseI)
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]);
216 fHnSparseDebug->Sumw2();
219 // Init the fHnSparseMCM (THnSparseI)
223 Int_t thnDimEvtt[6]; // sm, layer, stack, ROB, MCM
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;
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]);
247 fHnSparseMCM->Sumw2();
254 //_____________________________________________________________________
255 void AliTRDCalibChamberStatus::ProcessEvent(AliRawReader * rawReader, Int_t nevents_physics)
258 // Event Processing loop
262 Bool_t notEmpty = kFALSE;
264 AliTRDrawFastStream *rawStream = new AliTRDrawFastStream(rawReader);
265 rawStream->SetNoErrorWarning();
266 rawStream->SetSharedPadReadout(kFALSE);
268 AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager(kTRUE);
269 digitsManager->CreateArrays();
272 while ((det = rawStream->NextChamber(digitsManager, NULL, NULL)) >= 0) {
276 // do the QA analysis
277 if (digitsManager->GetIndexes(det)->HasEntry()) {//QA
278 // printf("there is ADC data on this chamber!\n");
280 AliTRDSignalIndex *indexes = digitsManager->GetIndexes(det);
281 if (indexes->IsAllocated() == kFALSE) {
282 // AliError("Indexes do not exist!");
288 indexes->ResetCounters();
290 while (indexes->NextRCIndex(iRow, iCol)){
291 Int_t iMcm = (Int_t)(iCol/18); // current group of 18 col pads
293 Int_t layer = AliTRDgeometry::GetLayer(det);
294 Int_t sm = AliTRDgeometry::GetSector(det);
295 Int_t stac = AliTRDgeometry::GetStack(det);
297 if(iMcm > 3) rphi = 1.5;
299 Double_t val[4] = {sm,layer,stac,rphi};
300 fHnSparseI->Fill(&val[0]);
305 if(fDebugLevel > 0) {
306 Int_t detector = AliTRDgeometry::GetDetector(layer,stac,sm);
307 Double_t valu[3] = {nevents_physics,detector,rphi};
308 fHnSparseEvtDet->Fill(&valu[0]);
315 digitsManager->ClearArrays(det);
318 if(notEmpty) fCounterEventNotEmpty++;
320 if(digitsManager) delete digitsManager;
321 if(rawStream) delete rawStream;
324 //_____________________________________________________________________
325 Bool_t AliTRDCalibChamberStatus::TestEventHisto(Int_t nevent) /*FOLD00*/
329 // fill the fHnSparseI with entries
335 for(Int_t ievent=0; ievent<nevent; ievent++){
336 for (Int_t ism=0; ism<18; ism++){
337 for (Int_t istack=0; istack<5; istack++){
338 for (Int_t ipl=0; ipl<6; ipl++){
339 for (Int_t icol=0; icol<geo.GetColMax(ipl); icol++){
341 if(icol > 72) side = 1;
342 Double_t val[4] = {ism,ipl,istack,side};
343 fHnSparseI->Fill(&val[0]);
353 //_____________________________________________________________________
354 void AliTRDCalibChamberStatus::AnalyseHisto() /*FOLD00*/
357 // Create the AliTRDCalChamberStatus according to the fHnSparseI
360 if(fCalChamberStatus) delete fCalChamberStatus;
361 fCalChamberStatus = new AliTRDCalChamberStatus();
363 // Check if enough events to say something
364 if(fCounterEventNotEmpty < 30) {
366 for (Int_t ism=0; ism<18; ism++) {
367 for (Int_t ipl=0; ipl<6; ipl++) {
368 for (Int_t istack=0; istack<5; istack++) {
369 // layer, stack, sector
370 Int_t det = AliTRDgeometry::GetDetector(ipl,istack,ism);
371 fCalChamberStatus->SetStatus(det,1);
378 // Mask out all chambers
379 for (Int_t ism=0; ism<18; ism++) {
380 for (Int_t ipl=0; ipl<6; ipl++) {
381 for (Int_t istack=0; istack<5; istack++) {
382 // layer, stack, sector
383 Int_t det = AliTRDgeometry::GetDetector(ipl,istack,ism);
384 fCalChamberStatus->SetStatus(det,2);
389 // Unmask good chambers
391 for(Int_t bin = 0; bin < fHnSparseI->GetNbins(); bin++) {
393 fHnSparseI->GetBinContent(bin,coord);
394 // layer, stack, sector
395 Int_t detector = AliTRDgeometry::GetDetector(coord[1]-1,coord[2]-1,coord[0]-1);
398 // Check which halfchamber side corresponds to the bin number (0=A, 1=B)
399 // Change the status accordingly
402 switch(fCalChamberStatus->GetStatus(detector))
404 case 1: break; // no changes
407 fCalChamberStatus->SetStatus(detector,4); break; // only SideB is masked
410 fCalChamberStatus->SetStatus(detector,3); break; // only SideA is masked
412 case 3: fCalChamberStatus->SetStatus(detector,1); break; // unmask SideA
413 case 4: fCalChamberStatus->SetStatus(detector,1); break; // unmask SideB
419 //_____________________________________________________________________
420 void AliTRDCalibChamberStatus::CheckEORStatus(AliTRDCalDCS *calDCS) /*FOLD00*/
423 // Correct the AliTRDCalChamberStatus according to the AliTRDCalDCS
424 // Using globale state of the HalfChamberMerger (HCM)
427 for(Int_t det = 0; det < 540; det++) {
428 AliTRDCalDCSFEE* calDCSFEEEOR = calDCS->GetCalDCSFEEObj(det);
429 if(!calDCSFEEEOR) { continue;}
431 // MCM Global State Machine State Definitions
443 Int_t sm = AliTRDgeometry::GetSector(det);
444 Int_t lay = AliTRDgeometry::GetLayer(det);
445 Int_t stac = AliTRDgeometry::GetStack(det);
447 Int_t stateA = calDCSFEEEOR->GetMCMGlobalState(4,17); // HCM Side A
448 Int_t stateB = calDCSFEEEOR->GetMCMGlobalState(5,17); // HCM Side B
451 //printf("DCS: stateA %d \t stateB %d \n",stateA,stateB);
452 if(stateA!=3 && stateA!=9) rphi = 1;
453 Double_t vals[4] = {sm,lay,stac,rphi};
454 if(rphi!=-1) fHnSparseHCM->Fill(&vals[0]);
456 if(stateB!=3 && stateB!=9) rphi = 2;
458 if(rphi!=-1) fHnSparseHCM->Fill(&vals[0]);
462 if(fDebugLevel > 0) {
463 if( ((fCalChamberStatus->GetStatus(det) <= 1) && (stateA!=3 && stateA!=9)) ||
464 ((fCalChamberStatus->GetStatus(det) <= 1) && (stateB!=3 && stateB!=9)) ||
465 ((fCalChamberStatus->GetStatus(det) == 2) && (stateA==3 || stateA==9)) ||
466 ((fCalChamberStatus->GetStatus(det) == 2) && (stateB==3 || stateB==9)) ||
467 ((fCalChamberStatus->GetStatus(det) == 3) && (stateA==3 || stateA==9)) ||
468 ((fCalChamberStatus->GetStatus(det) == 3) && (stateB!=3 && stateB!=9)) ||
469 ((fCalChamberStatus->GetStatus(det) == 4) && (stateB==3 || stateB==9)) ||
470 ((fCalChamberStatus->GetStatus(det) == 4) && (stateA!=3 && stateA!=9)) )
472 //printf(" Different half chamber status in DCS and DATA!!\n");
473 Double_t val[4] = {sm,lay,stac,1};
474 fHnSparseDebug->Fill(&val[0]);
476 if(rphi!=-1) { // error in DCS information
477 // Fill MCM status map
478 for(Int_t ii = 0; ii < 8; ii++) { //ROB loop
479 for(Int_t i = 0; i < 16; i++) { //MCM loop
480 Double_t valss[6] = {sm,lay,stac,ii,i
481 ,calDCSFEEEOR->GetMCMGlobalState(ii,i)};
482 fHnSparseMCM->Fill(&valss[0]);
491 //////////////////////////////////////////
492 // Change the status according to DCS
493 ///////////////////////////////////////////
495 // First put bad status if seen by DCS
496 /////////////////////////////////////////
497 if(stateA!=3 && stateA!=9 && stateB!=3 && stateB!=9) {
498 // completely masked from DCS
499 fCalChamberStatus->SetStatus(det,2);
501 if((stateA!=3 && stateA!=9) && (stateB==3 || stateB==9)) {
502 // Only A side masked from DCS
503 if(fCalChamberStatus->GetStatus(det) != 3) {
505 if(fCalChamberStatus->GetStatus(det) == 4) fCalChamberStatus->SetStatus(det,2);
506 if(fCalChamberStatus->GetStatus(det) <= 1) fCalChamberStatus->SetStatus(det,3);
509 if((stateA==3 || stateA==9) && (stateB!=3 && stateB!=9)) {
510 // Only B side masked from DCS
511 if(fCalChamberStatus->GetStatus(det) != 4) {
513 if(fCalChamberStatus->GetStatus(det) == 3) fCalChamberStatus->SetStatus(det,2);
514 if(fCalChamberStatus->GetStatus(det) <= 1) fCalChamberStatus->SetStatus(det,4);
518 // Then release in case of error 3 from DCS
519 /////////////////////////////////////////////
520 if(fCalChamberStatus->GetStatus(det)==2) {
521 if((stateA==3) && (stateB==3)) fCalChamberStatus->SetStatus(det,1);
522 if((stateA==3) && (stateB!=3)) fCalChamberStatus->SetStatus(det,4);
523 if((stateA!=3) && (stateB==3)) fCalChamberStatus->SetStatus(det,3);
525 if((fCalChamberStatus->GetStatus(det)==3) && (stateA==3)) fCalChamberStatus->SetStatus(det,1);
526 if((fCalChamberStatus->GetStatus(det)==4) && (stateB==3)) fCalChamberStatus->SetStatus(det,1);
532 //_____________________________________________________________________________________
533 void AliTRDCalibChamberStatus::Add(AliTRDCalibChamberStatus *calibChamberStatus) /*FOLD00*/
536 // Add the THnSparseI of this calibChamberStatus
539 fCounterEventNotEmpty += calibChamberStatus->GetNumberEventNotEmpty();
541 THnSparseI *hnSparseI = calibChamberStatus->GetSparseI();
542 if(!hnSparseI) return;
545 fHnSparseI = (THnSparseI *) hnSparseI->Clone();
548 fHnSparseI->Add(hnSparseI);
553 //_____________________________________________________________________
554 void AliTRDCalibChamberStatus::DumpToFile(const Char_t *filename, const Char_t *dir, Bool_t append) /*FOLD00*/
557 // Write class to file
568 TDirectory *backup = gDirectory;
569 TFile f(filename,option.Data());
571 if ( !sDir.IsNull() ){
572 f.mkdir(sDir.Data());
578 if ( backup ) backup->cd();