install testITSU testITSUv1 dirs.
[u/mrichter/AliRoot.git] / ITS / readSSDCommonMode.C
index 1040c17..6394734 100644 (file)
@@ -37,6 +37,10 @@ static const Int_t fgkNumberOfPSideStrips = 768; //number of P-side strips
 
 TList *initCM();
 void makeCM(const char* filename, Int_t nEvents, TList *list);
+void checkCM(const char* filename);
+void compareChipLists(TString inputFile1, 
+                     TString inputFile2, 
+                     TString outputTxt);
 
 //__________________________________________________________//
 void readSSDCommonMode(const char* filename = "raw.root",
@@ -265,7 +269,7 @@ void makeCM(const char* filename, Int_t nEvents, TList *list) {
       if(TMath::Abs(gSSDStream.GetStrip()) < 7)
        ((TH1*)list->At((gSSDStream.GetModuleID()-500)*fgkNumOfChips+gSSDStream.GetStrip()))->Fill(gSSDStream.GetSignal());
       if(TMath::Abs(gSSDStream.GetStrip()) > 6)
-       ((TH1*)list->At(fgkSSDMODULES*fgkNumOfChips+(gSSDStream.GetModuleID()-500)*fgkNumOfChips+gSSDStream.GetStrip()-fgkNumOfChips))->Fill(gSSDStream.GetSignal());
+       ((TH1*)list->At(fgkSSDMODULES*fgkNumOfChips+(gSSDStream.GetModuleID()-500)*fgkNumOfChips+gSSDStream.GetStrip()))->Fill(gSSDStream.GetSignal());
     }//streamer loop
   }//event loop
   
@@ -358,3 +362,246 @@ void drawSSDCM(const char* filename = "SSD.CM.root") {
   TH2F *fHistNSideRMSCMMapLayer6 = dynamic_cast<TH2F *>(f->Get("fHistNSideRMSCMMapLayer6"));
   fHistNSideRMSCMMapLayer6->Draw("colz");
 }
+
+//__________________________________________________________//
+void checkCM(const char* filename) {
+  //Reads the SSD.CM.root file as an input.
+  //For every chip checks the mean and the rms of the CM distributions.
+  //If the absolute value of the mean is beyond 5 ADC counts or/and the 
+  //rms is beyond 10, the corresponding histogram is added to the list 
+  //of suspicious chips. This list is written to the output file having 
+  //the name: SSD.FaultyChips.root
+
+  //Hardcoded check values
+  const Double_t meanMax = 5.;
+  const Double_t rmsMax = 10.;
+
+  //output list
+  TList *listOfSuspiciousChips = new TList();
+
+  //Input file
+  TFile *fInput = TFile::Open(filename);
+
+  Int_t gLayer = 0,gLadder = 0, gModule = 0;
+  TString gTitle;
+  //Double_t meanValue = 0.0, rmsValue = 0.0;
+  TH1F *gHistSSDCMModule = 0x0;
+  //P-side
+  for(Int_t iModule = 500; iModule < fgkSSDMODULES + 500; iModule++) {
+    AliITSgeomTGeo::GetModuleId(iModule,gLayer,gLadder,gModule);
+    for(Int_t iChip = 0; iChip < fgkNumOfChips; iChip++) {
+      gTitle = "SSD_CM_PSide_Layer"; gTitle += gLayer;
+      gTitle += "_Ladder"; gTitle += gLadder;
+      gTitle += "_Module"; gTitle += gModule;
+      gTitle += "_Chip"; gTitle += iChip+1;
+      gHistSSDCMModule = dynamic_cast<TH1F *>(fInput->Get(gTitle.Data()));
+      if((TMath::Abs(gHistSSDCMModule->GetMean(1)) > meanMax)||
+        (TMath::Abs(gHistSSDCMModule->GetRMS(1)) > rmsMax)) {
+       Printf("Name: %s, Mean: %lf - rms: %lf",
+              gHistSSDCMModule->GetName(),
+              TMath::Abs(gHistSSDCMModule->GetMean(1)),
+              TMath::Abs(gHistSSDCMModule->GetRMS(1)));
+       listOfSuspiciousChips->Add(gHistSSDCMModule);
+      }
+    }//chip loop
+  }//module loop
+
+  //N-side
+  for(Int_t iModule = 500; iModule < fgkSSDMODULES + 500; iModule++) {
+    AliITSgeomTGeo::GetModuleId(iModule,gLayer,gLadder,gModule);
+    for(Int_t iChip = 0; iChip < fgkNumOfChips; iChip++) {
+      gTitle = "SSD_CM_NSide_Layer"; gTitle += gLayer;
+      gTitle += "_Ladder"; gTitle += gLadder;
+      gTitle += "_Module"; gTitle += gModule;
+      gTitle += "_Chip"; gTitle += iChip+1;
+      gHistSSDCMModule = dynamic_cast<TH1F *>(fInput->Get(gTitle.Data()));
+      if((TMath::Abs(gHistSSDCMModule->GetMean(1)) > meanMax)||
+        (TMath::Abs(gHistSSDCMModule->GetRMS(1)) > rmsMax)) {
+       Printf("Name: %s, Mean: %lf - rms: %lf",
+              gHistSSDCMModule->GetName(),
+              TMath::Abs(gHistSSDCMModule->GetMean(1)),
+              TMath::Abs(gHistSSDCMModule->GetRMS(1)));
+       listOfSuspiciousChips->Add(gHistSSDCMModule);
+      }
+      //Printf("Name: %s",gHistSSDCMModule->GetName());
+    }//chip loop
+  }//module loop
+
+  Printf("===============================================");
+  Printf("%d suspicious chips were put in the list",
+        listOfSuspiciousChips->GetEntries());
+  Printf("===============================================");
+  TFile *fOutput = new TFile("SSD.FaultyChips.root","recreate");
+  listOfSuspiciousChips->Write();
+  fOutput->Close();
+
+  fInput->Close();
+}
+
+//__________________________________________________________//
+void compareChipLists(TString inputFile1, 
+                     TString inputFile2, 
+                     TString outputTxt){
+  //Compare two different lists of chips and put those present in both files
+  //in a new list
+  //open input lists
+  TFile *fInput1 = TFile::Open(inputFile1.Data());
+  TList *listOfSuspiciousChips1 = new TList();
+  listOfSuspiciousChips1=fInput1->GetListOfKeys();
+  TFile *fInput2 = TFile::Open(inputFile2.Data());
+  TList *listOfSuspiciousChips2 = new TList();
+  listOfSuspiciousChips2=fInput2->GetListOfKeys();
+       
+  Int_t Nentries1 = 0, Nentries2 = 0, k = 0;
+  Nentries1 = listOfSuspiciousChips1->GetEntries();
+  Nentries2 = listOfSuspiciousChips2->GetEntries();
+       
+  //create new list
+  TList *listOfRecurrentChips = new TList();
+  TString Name1;
+       
+  for(Int_t i=0; i<Nentries1; i++){
+    TH1F *h1 = dynamic_cast <TH1F*>(fInput1->Get(listOfSuspiciousChips1->At(i)->GetName()));
+    for(Int_t j=0; j<Nentries2; j++){
+      TH1F *h2 = dynamic_cast <TH1F*>(fInput2->Get(listOfSuspiciousChips2->At(j)->GetName()));
+      Name1=h1->GetName();
+      if (!Name1.CompareTo(h2->GetName())) {
+       cout << Name1.CompareTo(h2->GetName()) << 
+         "   " << h2->GetName() << endl;
+       k++;
+       listOfRecurrentChips->Add(h1);
+      }
+    }//second file loop
+  }//first file loop
+  
+  Printf("%i Faulty chips in the first file", Nentries1);
+  Printf("%i Faulty chips in the second file", Nentries2);
+  Printf("%i Recurrent Faulty chips", k+1);    
+  
+  TString outputFile = "SSD.RecurrentFaultyChips."; outputFile += outputTxt;
+  outputFile += ".root";
+  
+  TFile *fOutput = new TFile(outputFile.Data(),"recreate");
+  listOfRecurrentChips->Write();
+  fOutput->Close();
+  
+  fInput1->Close();
+  fInput2->Close();
+}
+
+//__________________________________________________________//
+void makeCM2D(const char* filename, Int_t nEvents) {
+  //Function to read the CM values
+  gStyle->SetPalette(1,0);
+  Int_t gStripNumber = 0;
+  Int_t gLayer = 0,gLadder = 0, gModule = 0;
+  
+  //==================================================//
+  AliCDBManager *fCDBManager = AliCDBManager::Instance();
+  fCDBManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
+  Int_t runNumber = atoi(gSystem->Getenv("DATE_RUN_NUMBER"));
+  if(!runNumber) 
+    Printf("DATE_RUN_NUMBER not defined!!!\n");
+  
+  fCDBManager->SetRun(runNumber);
+  AliCDBEntry *geomGRP = fCDBManager->Get("GRP/Geometry/Data");
+  if(!geomGRP) cout<<"GRP geometry not found!!!"<<endl;;
+  //==================================================//
+    
+  //==================================================//
+  TList *list = new TList();
+  TH2F *gHistCM2D[fgkSSDMODULES];
+  TString gHistoTitle, gArrayTitle;
+  Int_t gHistCounter = 0;
+  for(Int_t iModule = 500; iModule < fgkSSDMODULES + 500; iModule++) {
+    AliITSgeomTGeo::GetModuleId(iModule,gLayer,gLadder,gModule);    
+    gHistoTitle = "SSD_CM_Layer"; gHistoTitle += gLayer;
+    gHistoTitle += "_Ladder"; gHistoTitle += gLadder;
+    gHistoTitle += "_Module"; gHistoTitle += gModule;
+    //Printf("Title: %s",gHistoTitle.Data());
+    gHistCM2D[gHistCounter] = new TH2F(gHistoTitle.Data(),
+                                      gHistoTitle.Data(),
+                                      12,0.5,12.5,
+                                      120,-60.,60.);
+    gHistCM2D[gHistCounter]->SetStats(kFALSE);
+    gHistCM2D[gHistCounter]->GetXaxis()->SetTitleColor(1);
+    gHistCM2D[gHistCounter]->GetZaxis()->SetTitle("Entries");
+    gHistCM2D[gHistCounter]->GetYaxis()->SetTitle("CM");
+    gHistCM2D[gHistCounter]->GetXaxis()->SetTitle("Chip number");
+    gHistCM2D[gHistCounter]->GetXaxis()->SetNdivisions(12);
+    list->Add(gHistCM2D[gHistCounter]);
+    gHistCounter += 1;
+  }
+  //Printf("List entries: %d",list->GetEntries());
+  //==================================================//
+
+  TChain *chain = new TChain("RAW");
+  chain->Add(filename);
+  Int_t nTotalEvents = chain->GetEntries();
+  if(nEvents == -1) nEvents = nTotalEvents;
+  
+  AliRawReaderRoot *rawReader = new AliRawReaderRoot(filename);
+  Int_t iEvent = 0;
+  Int_t fSSDEvent = 0;
+  for(iEvent = 0; iEvent < nEvents; iEvent++) {
+    cout<<"Event: "<<iEvent+1<<"/"<<nEvents<<endl;
+    rawReader->Select("ITSSSD",-1,-1);  
+    rawReader->Reset(); 
+    rawReader->NextEvent();   
+    
+    if(rawReader->GetType() != 7) continue;
+    
+    fSSDEvent += 1;
+    AliITSRawStreamSSD gSSDStream(rawReader);    
+    while (gSSDStream.Next()) {
+      if(gSSDStream.GetModuleID() < 0) continue;
+      AliITSgeomTGeo::GetModuleId(gSSDStream.GetModuleID(),gLayer,gLadder,gModule);
+      //if(gSSDStream.GetModuleID() != 500) continue;
+      //Printf("Module id: %d - Layer: %d - Ladder: %d - Module: %d",gSSDStream.GetModuleID(),gLayer,gLadder,gModule);
+
+      if(gSSDStream.GetStrip() >= 0) continue;
+      gStripNumber = (gSSDStream.GetSideFlag() == 0) ? gSSDStream.GetStrip() : -gSSDStream.GetStrip() + 2*fgkNumberOfPSideStrips;
+      //Printf("Module id: %d - Strip: %d - strip number: %d - Signal: %lf",gSSDStream.GetModuleID(),gSSDStream.GetStrip(),gStripNumber,gSSDStream.GetSignal());
+      gHistCM2D[gSSDStream.GetModuleID()-500]->Fill(TMath::Abs(gSSDStream.GetStrip()),gSSDStream.GetSignal());      
+    }//streamer loop
+  }//event loop
+  
+  TCanvas *cLayer5[34];
+  TCanvas *cLayer6[38];
+  TString canvasTitle;
+  for(Int_t iLadder = 1; iLadder < 35; iLadder++) {
+    canvasTitle = "SSD_CM_Layer5_Ladder"; canvasTitle += iLadder;
+    cLayer5[iLadder-1] = new TCanvas(canvasTitle.Data(),
+                                    canvasTitle.Data());
+    cLayer5[iLadder-1]->Divide(5,5);    
+    for(Int_t iModule = 1; iModule < 23; iModule++) {
+      cLayer5[iLadder-1]->cd(iModule);
+      gHistCM2D[(iLadder-1)*fgkSSDMODULESPERLADDERLAYER5 + iModule - 1]->Draw("colz");
+    }
+    if(iLadder == 1) cLayer5[iLadder-1]->Print("CommonModePlotsLayer5.ps(");
+    if(iLadder == 34) cLayer5[iLadder-1]->Print("CommonModePlotsLayer5.ps)");
+    else cLayer5[iLadder-1]->Print("CommonModePlotsLayer5.ps");
+    //Printf("Ladder %d finished...",499+iLadder);
+  }
+
+  for(Int_t iLadder = 1; iLadder < 39; iLadder++) {
+    canvasTitle = "SSD_CM_Layer6_Ladder"; canvasTitle += iLadder;
+    cLayer6[iLadder-1] = new TCanvas(canvasTitle.Data(),
+                                    canvasTitle.Data());
+    cLayer6[iLadder-1]->Divide(5,5);    
+    for(Int_t iModule = 1; iModule < 26; iModule++) {
+      cLayer6[iLadder-1]->cd(iModule);
+      gHistCM2D[fgkSSDMODULESLAYER5 + (iLadder-1)*fgkSSDMODULESPERLADDERLAYER6 + iModule - 1]->Draw("colz");
+    }
+    if(iLadder == 1) cLayer6[iLadder-1]->Print("CommonModePlotsLayer6.ps(");
+    if(iLadder == 38) cLayer6[iLadder-1]->Print("CommonModePlotsLayer6.ps)");
+    else cLayer6[iLadder-1]->Print("CommonModePlotsLayer6.ps");
+    //Printf("Ladder %d finished...",599+iLadder);
+  }
+
+
+  TFile *foutput = TFile::Open("SSD.CM2D.root","recreate");
+  list->Write();
+  foutput->Close();
+}