]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Added MAcros: QA macros for sdigits and digits - macro to create digits from sdigits
authorvicinanz <vicinanz@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 4 Jun 2002 10:36:11 +0000 (10:36 +0000)
committervicinanz <vicinanz@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 4 Jun 2002 10:36:11 +0000 (10:36 +0000)
TOF/AliTOFSDigits2Digits.C [new file with mode: 0644]
TOF/AliTOFanalyzeDigits.C [new file with mode: 0644]
TOF/AliTOFanalyzeSDigitsV2.C [new file with mode: 0644]

diff --git a/TOF/AliTOFSDigits2Digits.C b/TOF/AliTOFSDigits2Digits.C
new file mode 100644 (file)
index 0000000..684fbce
--- /dev/null
@@ -0,0 +1,195 @@
+Int_t AliTOFSDigits2Digits(TString infileNameSDigits, Int_t firstEvent=0,Int_t nEvents=1, Int_t ndump=15)
+{
+  // Create TOF digits out of TOF sdigits (no merging implemented here).
+  // Input: infileNameSDigits --> TOF sdigits filename 
+  //        firstEvent        --> first event to digitize
+  //        nEvents           --> number of events to digitize 
+  //                              including the first and the last ones
+  // if nEvents==0 we sdigitize all events in infileNameSDigits
+  //        ndump             --> number of dumped digits
+
+  // Author: F. Pierella (Bologna University)
+  // report problem to pierella@bo.infn.it
+
+  // Use case: (start root)
+  //root [0] .L AliTOFSDigits2Digits.C                                    
+  //root [1] AliTOFSDigits2Digits("fileWithTOFSdigits.root")
+
+
+  // number 3 is a legacy from AliDigit object
+  const Int_t kMAXDIGITS = 3;
+
+
+  // Dynamically link some shared libs
+  if (gClassTable->GetID("AliRun") < 0) {
+    gROOT->LoadMacro("loadlibs.C");
+    loadlibs();
+  } else {
+    delete gAlice;
+    gAlice = 0;
+  }
+  
+  Int_t rc=0;
+  
+  
+  TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(infileNameSDigits.Data());
+  if(file){
+    cout<<"headerFile already open \n";
+  }
+  else {
+    // file is open in "update" mode
+    // in order to have a writable digits tree
+    if(!file)file=TFile::Open(infileNameSDigits.Data(),"update");
+  }
+  
+  // Get AliRun object from file
+  if (!gAlice) {
+    gAlice = (AliRun*)file->Get("gAlice");
+    if (gAlice) printf("AliRun object found on file\n");
+  }
+
+  if (nEvents == 0) nEvents = (Int_t) gAlice->TreeE()->GetEntries();
+  
+  AliTOF * tof = (AliTOF *) gAlice->GetDetector("TOF") ;
+
+  if (!tof) {
+    cout << "<AliTOFSDigits2Digits> No TOF detector found" << endl;
+    rc = 2;
+    return rc;
+  }
+
+  Int_t totndig=0;   // total number of digits
+  Int_t tottracks=0; // total number of tracks contributing to totndig
+  Int_t upperBoundEvNum=firstEvent+nEvents;
+  for (Int_t ievent = firstEvent; ievent < upperBoundEvNum; ievent++) {
+
+    gAlice->GetEvent(ievent);
+    if (gAlice->TreeD () == 0)
+      gAlice->MakeTree ("D");
+    
+    //Make branches
+    char branchname[20];
+    sprintf (branchname, "%s", tof->GetName ());
+    //Make branch for digits
+    tof->MakeBranch ("D");
+
+
+    // get the TOF branch in TreeS for current event
+    char tname[100]; sprintf(tname,"TreeS%d",ievent);
+    
+    TTree *sdigitstree=(TTree*)file->Get(tname);                   
+    
+    TClonesArray * fSDigits= new TClonesArray("AliTOFSDigit",  1000); 
+    sdigitstree->GetBranch("TOF")->SetAddress(&fSDigits);           
+    
+    Int_t nEntries = sdigitstree->GetEntries();                                
+    //cout << nEntries << endl;
+    
+    // Loop through all entries in the tree
+    Int_t nbytes;
+
+    for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
+      
+      // Import the tree
+      nbytes += sdigitstree->GetEvent(iEntry);
+      
+      // Get the number of sdigits
+      Int_t ndig = fSDigits->GetEntriesFast();
+      cout << "------------------<AliTOFSDigits2Digits>------------------" << endl;
+      cout << "Found " << ndig << " TOF SDigits for event " << ievent << endl;
+      cout << "------------------------------------------------------------" << endl;
+
+      // start loop on sdigits
+      for (Int_t k = 0; k < ndig; k++) {
+
+       Int_t    vol[5];       // location for a digit
+       
+       // Get the information for this digit
+       AliTOFSDigit *tofsdigit = (AliTOFSDigit *) fSDigits->UncheckedAt(k);
+
+       Int_t nslot=tofsdigit->GetNDigits(); // get the number of slots
+                                            // for current sdigit
+
+       // TOF sdigit volumes (always the same for all slots)
+       Int_t sector    = tofsdigit->GetSector(); // range [1-18]
+       Int_t plate     = tofsdigit->GetPlate();  // range [1- 5]
+       Int_t strip     = tofsdigit->GetStrip();  // range [1-20]
+       Int_t padz      = tofsdigit->GetPadz();   // range [1- 2]
+       Int_t padx      = tofsdigit->GetPadx();   // range [1-48]
+
+       vol[0] = sector;
+       vol[1] = plate;
+       vol[2] = strip;
+       vol[3] = padx;
+       vol[4] = padz;
+
+       //--------------------- QA section ----------------------
+       // in the while, I perform QA
+       Bool_t isSDigitBad = (sector<1 || sector>18 || plate<1 || plate >5 || padz<1 || padz>2 || padx<1 || padx>48);
+       
+       if (isSDigitBad) {
+         cout << "<AliTOFSDigits2Digits>  strange sdigit found" << endl;
+         rc = 3;
+         return rc;
+       }
+       //-------------------------------------------------------
+
+       //------------------- Dump section ----------------------
+       if(k<ndump){
+         cout << k << "-th | " << "Sector " << sector << " | Plate " << plate << " | Strip " << strip << " | PadZ " << padz << " | PadX " << padx << endl;
+         cout << k << "-th sdigit" << endl;
+         cout << "----------------------------------------------------"<< endl;
+       }
+       // ------------------------------------------------------
+
+       // start loop on number of slots for current sdigit
+       for (Int_t islot = 0; islot < nslot; islot++) {
+         Float_t  digit[2];     // TOF digit variables
+         Int_t tracknum[kMAXDIGITS];     // contributing tracks for the current slot
+       
+         Float_t tdc=tofsdigit->GetTdc(islot); digit[0]=tdc;
+         Float_t adc=tofsdigit->GetAdc(islot); digit[1]=adc;
+
+         tracknum[0]=tofsdigit->GetTrack(islot,0);
+         tracknum[1]=tofsdigit->GetTrack(islot,1);
+         tracknum[2]=tofsdigit->GetTrack(islot,2);
+
+         for (Int_t i = 0; i < kMAXDIGITS; i++) {
+           tottracks++;
+           // search for the first empty location
+           if(tracknum[i]==-1){
+             tottracks--;
+             break;
+           }
+         }
+
+         // adding a TOF digit for each slot
+         tof->AddDigit(tracknum, vol, digit);
+         totndig++;
+       }
+
+
+      } // end loop on sdigits
+      
+    } // end loop on entries
+
+    // free used memory
+    fSDigits->Clear();
+    fSDigits=0;
+
+    gAlice->TreeD()->Reset();
+    gAlice->TreeD()->Fill();
+    //gAlice->TreeS()->Write(0,TObject::kOverwrite) ;
+    gAlice->TreeD()->AutoSave();
+
+  } // end loop on events 
+
+  cout << "----------------------------------------------------------" << endl;
+  cout << "<AliTOFSDigits2Digits> Summary" << endl;
+  cout << "contributing tracks to " << totndig << " digits: " << tottracks << endl; 
+  cout << "----------------------------------------------------------" << endl;
+
+  return rc;
+  
+
+}
diff --git a/TOF/AliTOFanalyzeDigits.C b/TOF/AliTOFanalyzeDigits.C
new file mode 100644 (file)
index 0000000..c1a5a87
--- /dev/null
@@ -0,0 +1,139 @@
+Int_t AliTOFanalyzeDigits(TString headersFile, Int_t ndump=15, Int_t iEvNum=0)
+{
+  //
+  // Analyzes the TOF digits and fills QA-histograms 
+  // report problems to pierella@bo.infn.it
+  // iEvNum=0 means all events in the file
+  // Author: F. Pierella (Bologna University)
+
+  // Dynamically link some shared libs
+  if (gClassTable->GetID("AliRun") < 0) {
+    gROOT->LoadMacro("loadlibs.C");
+    loadlibs();
+  } else {
+    delete gAlice;
+    gAlice = 0;
+  }
+  
+  Int_t rc=0;
+
+  
+  TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(headersFile.Data());
+  if(file){
+    cout<<"headerFile already open \n";
+  }
+  else {
+    if(!file)file=TFile::Open(headersFile.Data());
+  }
+  
+  // Get AliRun object from file
+  if (!gAlice) {
+    gAlice = (AliRun*)file->Get("gAlice");
+    if (gAlice) printf("AliRun object found on file\n");
+  }
+  
+
+  if (iEvNum == 0) iEvNum = (Int_t) gAlice->TreeE()->GetEntries();
+
+
+  AliTOFdigit *tofdigit;
+
+  AliTOF * tof = (AliTOF *) gAlice->GetDetector("TOF") ;
+
+  if (!tof) {
+    cout << "<AliTOFanalyzeDigits> No TOF detector found" << endl;
+    rc = 2;
+    return rc;
+  }
+
+  // adc and tdc
+  TH1F *htdc  = new TH1F("htdc","TDC [bin]",500,0.,15000.);
+  TH1F *hadc   = new TH1F("hadc","ADC [bin]",100,0., 3000.);
+
+  // TOF digit volumes
+  TH1F *hsector  = new TH1F("hsector","Sector",20,0.,20.);
+  TH1F *hplate   = new TH1F("hplate","Plate ", 6,0., 6.);
+  TH1F *hstrip   = new TH1F("hstrip","Strip ",25,0.,25.);
+  TH1F *hpadz    = new TH1F("hpadz","Pad along z ",3,0.,3.);
+  TH1F *hpadx    = new TH1F("hpadx","Pad along x",50,0.,50.);
+  // ADC-TDC correlation
+  TH2F *h2tdcVSadc = new TH2F("h2tdcVSadc","TDC [bin] VS ADC [bin]",100,0.,3000.,500,0.,15000.);
+
+  cout << "First " << ndump << " Digits found in TOF TreeD branch have:" << endl;
+
+  for (Int_t ievent = 0; ievent < iEvNum; ievent++) {
+
+    gAlice->GetEvent(ievent) ;
+    if(gAlice->TreeD()==0) {
+      cout << "<AliTOFanalyzeDigits> No  TreeD found" << endl;
+      rc = 4;
+      return rc;
+    }
+    
+    
+    
+    Int_t ndig, k;
+    gAlice->ResetDigits();
+    gAlice->TreeD()->GetEvent(ievent);
+    TClonesArray * TOFdigits   = tof->Digits();
+    
+    ndig=TOFdigits->GetEntries();
+    
+    cout << "<AliTOFanalyzeDigits> found " << ndig
+        << " TOF digits for event " << ievent << endl;
+    
+    for (k=0; k<ndig; k++) {
+      tofdigit= (AliTOFdigit*) TOFdigits->UncheckedAt(k);
+      Float_t tdc=tofdigit->GetTdc();
+      Float_t adc=tofdigit->GetAdc();
+      htdc->Fill(tdc);
+      hadc->Fill(adc);
+      // TOF digit volumes
+      Int_t sector    = tofdigit->GetSector(); // range [1-18]
+      Int_t plate     = tofdigit->GetPlate();  // range [1- 5]
+      Int_t strip     = tofdigit->GetStrip();  // range [1-20]
+      Int_t padz      = tofdigit->GetPadz();   // range [1- 2]
+      Int_t padx      = tofdigit->GetPadx();   // range [1-48]
+      // it is QA, then I perform QA!
+      Bool_t isDigitBad = (sector<1 || sector>18 || plate<1 || plate >5 || padz<1 || padz>2 || padx<1 || padx>48);
+
+      if (isDigitBad) {
+       cout << "<AliTOFanalyzeDigits>  strange digit found" << endl;
+       rc = 3;
+       return rc;
+      }
+      
+      if(k<ndump){
+       cout << k << "-th | " << "Sector " << sector << " | Plate " << plate << " | Strip " << strip << " | PadZ " << padz << " | PadX " << padx << endl;
+       cout << k << "-th | ADC " << adc << " [bin] | TDC " << tdc << " [bin]" << endl;
+       cout << "----------------------------------------------------"<< endl;
+      }
+
+      // filling digit volume histos
+      hsector->Fill(sector);
+      hplate->Fill(plate);
+      hstrip->Fill(strip);
+      hpadx->Fill(padx);
+      hpadz->Fill(padz);
+      h2tdcVSadc->Fill(adc,tdc);
+
+    }
+  
+  } // end loop on events
+
+  TFile *fout = new TFile("TOF_digitsQA.root","RECREATE");
+  htdc->Write();
+  hadc->Write();
+  h2tdcVSadc->Write();
+  hsector->Write();
+  hplate->Write();
+  hstrip->Write();
+  hpadz->Write();
+  hpadx->Write();
+  fout->Close(); 
+
+
+  return rc;
+  
+}
+
diff --git a/TOF/AliTOFanalyzeSDigitsV2.C b/TOF/AliTOFanalyzeSDigitsV2.C
new file mode 100644 (file)
index 0000000..1e9ddfc
--- /dev/null
@@ -0,0 +1,153 @@
+Int_t AliTOFanalyzeSDigitsV2(TString headersFile, Int_t ndump=15, Int_t iEvNum=0)
+{
+  // V2: to be used with transient fSDigits data member
+  //
+  // Analyzes the TOF sdigits and fills QA-histograms 
+  // report problems to pierella@bo.infn.it
+  // iEvNum=0 means all events in the file
+
+  // Dynamically link some shared libs
+  if (gClassTable->GetID("AliRun") < 0) {
+    gROOT->LoadMacro("loadlibs.C");
+    loadlibs();
+  } else {
+    delete gAlice;
+    gAlice = 0;
+  }
+  
+  Int_t rc=0;
+  
+  
+  TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(headersFile.Data());
+  if(file){
+    cout<<"headerFile already open \n";
+  }
+  else {
+    if(!file)file=TFile::Open(headersFile.Data());
+  }
+  
+  // Get AliRun object from file
+  if (!gAlice) {
+    gAlice = (AliRun*)file->Get("gAlice");
+    if (gAlice) printf("AliRun object found on file\n");
+  }
+  
+  
+  if (iEvNum == 0) iEvNum = (Int_t) gAlice->TreeE()->GetEntries();
+  
+  AliTOF * tof = (AliTOF *) gAlice->GetDetector("TOF") ;
+
+  if (!tof) {
+    cout << "<AliTOFanalyzeSDigitsV2> No TOF detector found" << endl;
+    rc = 2;
+    return rc;
+  }
+
+  // adc and tdc
+  TH1F *htdc  = new TH1F("htdc","TDC [bin]",500,0.,15000.);
+  TH1F *hadc   = new TH1F("hadc","ADC [bin]",100,0., 3000.);
+
+  // number of slot for each sdigits
+  TH1F *hndigits  = new TH1F("hndigits","fNDigits",5,0.,5.);
+
+  // TOF sdigit volumes
+  TH1F *hsector  = new TH1F("hsector","Sector",20,0.,20.);
+  TH1F *hplate   = new TH1F("hplate","Plate ", 6,0., 6.);
+  TH1F *hstrip   = new TH1F("hstrip","Strip ",25,0.,25.);
+  TH1F *hpadz    = new TH1F("hpadz","Pad along z ",3,0.,3.);
+  TH1F *hpadx    = new TH1F("hpadx","Pad along x",50,0.,50.);
+  // ADC-TDC correlation
+  TH2F *h2tdcVSadc = new TH2F("h2tdcVSadc","TDC [bin] VS ADC [bin]",100,0.,3000.,500,0.,15000.);
+
+  cout << "First " << ndump << " SDigits found in TOF TreeS branch have:" << endl;
+
+
+  for (Int_t ievent = 0; ievent < iEvNum; ievent++) {
+    
+    char tname[100]; sprintf(tname,"TreeS%d",ievent);
+    
+    TTree *sdigitstree=(TTree*)file->Get(tname);                   
+    
+    TClonesArray * fSDigits= new TClonesArray("AliTOFSDigit",  1000); 
+    sdigitstree->GetBranch("TOF")->SetAddress(&fSDigits);           
+    
+    Int_t nEntries = sdigitstree->GetEntries();                                
+    //cout << nEntries << endl;
+    
+    // Loop through all entries in the tree
+    Int_t nbytes;
+    for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
+      
+      // Import the tree
+      nbytes += sdigitstree->GetEvent(iEntry);
+      
+      // Get the number of sdigits
+      Int_t ndig = fSDigits->GetEntriesFast();
+      cout << "------------------<AliTOFanalyzeSDigitsV2>------------------" << endl;
+      cout << "Found " << ndig << " TOF SDigits for event " << ievent << endl;
+      cout << "------------------------------------------------------------" << endl;
+
+      // start loop on sdigits
+      for (Int_t k = 0; k < ndig; k++) {
+       
+       // Get the information for this digit
+       AliTOFSDigit *tofsdigit = (AliTOFSDigit *) fSDigits->UncheckedAt(k);
+       Float_t firstTDC=tofsdigit->GetTdc(0);
+       Float_t firstADC=tofsdigit->GetAdc(0);
+       Int_t nslot=tofsdigit->GetNDigits();
+       hndigits->Fill(nslot);
+       htdc->Fill(firstTDC);
+       hadc->Fill(firstADC);
+       // TOF sdigit volumes
+       Int_t sector    = tofsdigit->GetSector(); // range [1-18]
+       Int_t plate     = tofsdigit->GetPlate();  // range [1- 5]
+       Int_t strip     = tofsdigit->GetStrip();  // range [1-20]
+       Int_t padz      = tofsdigit->GetPadz();   // range [1- 2]
+       Int_t padx      = tofsdigit->GetPadx();   // range [1-48]
+       // it is QA, then I perform QA!
+       Bool_t isSDigitBad = (sector<1 || sector>18 || plate<1 || plate >5 || padz<1 || padz>2 || padx<1 || padx>48);
+       
+       if (isSDigitBad) {
+         cout << "<AliTOFanalyzeSDigitsV2>  strange sdigit found" << endl;
+         rc = 3;
+         return rc;
+       }
+       
+       if(k<ndump){
+         cout << k << "-th | " << "Sector " << sector << " | Plate " << plate << " | Strip " << strip << " | PadZ " << padz << " | PadX " << padx << endl;
+         cout << k << "-th | ADC " << firstADC << " [bin] | TDC " << firstTDC << " [bin]" << endl;
+         cout << "----------------------------------------------------"<< endl;
+       }
+       
+       // filling sdigit volume histos
+       hsector->Fill(sector);
+       hplate->Fill(plate);
+       hstrip->Fill(strip);
+       hpadx->Fill(padx);
+       hpadz->Fill(padz);
+       h2tdcVSadc->Fill(firstADC,firstTDC);
+       
+       //cout << "firstTDC " << firstTDC << " firstADC " << firstADC << endl;
+      } // end loop on sdigits
+      
+    } // end loop on entries
+    
+  } // end loop on events 
+  
+  TFile *fout = new TFile("TOF_sdigitsQA.root","RECREATE");
+  htdc->Write();
+  hadc->Write();
+  hndigits->Write();
+  h2tdcVSadc->Write();
+  hsector->Write();
+  hplate->Write();
+  hstrip->Write();
+  hpadz->Write();
+  hpadx->Write();
+  fout->Close(); 
+
+
+  return rc;
+  
+
+}