]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Event merging for ZDC
authorcoppedis <coppedis@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 4 Oct 2001 14:32:56 +0000 (14:32 +0000)
committercoppedis <coppedis@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 4 Oct 2001 14:32:56 +0000 (14:32 +0000)
ZDC/AliZDC.cxx
ZDC/AliZDC.h
ZDC/AliZDCMergedHit.cxx [new file with mode: 0644]
ZDC/AliZDCMergedHit.h [new file with mode: 0644]
ZDC/AliZDCMerger.cxx
ZDC/AliZDCMerger.h
ZDC/Makefile
ZDC/ZDCLinkDef.h

index 105c1de13b142f1e9e7b2dcc7da684f546161d9e..6f9c54bf96467ee3897fb36855f9830d6e6375e3 100644 (file)
@@ -15,6 +15,9 @@
 
 /*
 $Log$
+Revision 1.25  2001/10/04 14:24:15  coppedis
+Event merging for ZDC
+
 Revision 1.24  2001/09/26 16:03:41  coppedis
 Merging implemented
 
@@ -371,11 +374,11 @@ Float_t AliZDC::ZMax(void) const
 //_____________________________________________________________________________
 void AliZDC::Hits2SDigits()
 {
-  printf("\n   Entering AliZDC::SDigits2Digits()\n");
+//  printf("\n Entering AliZDC::SDigits2Digits()\n");
   
   //----------------------------------------------------------------
   if(!fMerger){ 
-    printf("\n         ZDC digitization (without merging)\n");
+//    printf("\n       ZDC digitization (without merging)\n");
 
     AliZDCMergedHit *MHit;
     Int_t j, sector[2];
@@ -409,14 +412,14 @@ void AliZDC::Hits2SDigits()
          fNMergedhits++;
          delete MHit;
     }
-    printf("\n ### Filling SDigits tree\n");
+//    printf("\n       ### Filling SDigits tree\n");
     gAlice->TreeS()->Fill();
     gAlice->TreeS()->Write(0,TObject::kOverwrite);  
     gAlice->TreeS()->Reset();  
   }
   //----------------------------------------------------------------
   else if(fMerger){
-    printf("\n         ZDC merging and digitization\n");
+//    printf("\n         ZDC merging and digitization\n");
     // ### Initialise merging
     fMerger -> InitMerging();
 
@@ -444,7 +447,7 @@ void AliZDC::Hits2SDigits()
     // ### Get TCA of MergedHits from AliZDCMerger
     fMergedHits  = fMerger->MergedHits();
     fNMergedhits = fMerger->GetNMhits();
-    printf("\n         fNMergedhits (from AliZDCMerger) = %d\n", fNMergedhits);   
+//    printf("\n         fNMergedhits (from AliZDCMerger) = %d\n", fNMergedhits);   
     AliZDCMergedHit *MHit;
     TClonesArray &sdigits = *fMergedHits;
     Int_t imhit;
@@ -465,9 +468,9 @@ void AliZDC::Hits2SDigits()
 //_____________________________________________________________________________
 void AliZDC::SDigits2Digits()
 {
-  printf("\n   Entering AliZDC::SDigits2Digits()\n");
+//  printf("\n Entering AliZDC::SDigits2Digits()\n");
   if(!fMerger){ // Only digitization
-    printf("\n        ZDC digitization (without merging) \n");
+//    printf("\n        ZDC digitization (without merging) \n");
     fMerger = new AliZDCMerger();    
     fMerger->Digitize(fNMergedhits, fMergedHits);
 
@@ -478,7 +481,7 @@ void AliZDC::SDigits2Digits()
     gAlice->TreeD()->Reset();  
   }
   else if(fMerger){    // Merging and digitization
-    printf("\n        ZDC merging and digitization\n");
+//    printf("\n        ZDC merging and digitization\n");
     fMerger->Digitize(fNMergedhits, fMergedHits);
 
     TFile *bgrFile = fMerger->BgrFile();
@@ -496,7 +499,7 @@ void AliZDC::SDigits2Digits()
     char branchDname[20];
     sprintf(branchDname,"%s",GetName());
     if(fTreeMD && fDigits){
-      printf("\n       fTreeMD!=0 && fDigits!=0\n");
+//      printf("\n     fTreeMD!=0 && fDigits!=0\n");
       branchD = fTreeMD->GetBranch(branchDname);
       if(branchD) branchD->SetAddress(&fDigits);
     }
index 18320f938830d7245ab2834899b0a02a5bb998ca..12e5aaf6859ec627192af885a5d32f44356ffef8 100644 (file)
@@ -29,6 +29,8 @@ public:
   virtual Float_t ZMin() const;        // Minimum overall dimension of the ZDC
   virtual Float_t ZMax() const;        // Maximum overall dimension of the ZDC
   virtual void  MakeBranch(Option_t* opt, const char *file=0);
+  virtual void  MakeBranchInTreeSD(TTree *treeSD, const char *file=0);
+  virtual void  MakeBranchInTreeD(TTree *treeD, const char *file=0);
   virtual void  Hits2SDigits();
   virtual void  SDigits2Digits();
   virtual void  Hits2Digits();
@@ -36,7 +38,7 @@ public:
   virtual void  SetMerger(AliZDCMerger* merger);
   virtual AliZDCMerger* Merger();
   virtual void  StepManager() {}
-  
+    
   // Switching off the shower development in ZDCs
   void  NoShower(){fNoShower=1;}
   void  Shower()  {fNoShower=0;}
@@ -46,17 +48,14 @@ protected:
   Int_t        fNoShower;      // Flag to switch off the shower        
   AliZDCMerger *fMerger;       // ! pointer to merger
   
+  Int_t        fNMergedhits;    // Number of Merged hits for background
+  TClonesArray *fMergedHits;    // TCA for "merged" hits  
+  TTree               *fTreeSD;        // TreeS for merging
+  TTree               *fTreeMD;        // TreeD for merging
+  
   Int_t        fNRecPoints;    // Number of RecPoints
   TClonesArray *fRecPoints;    // List of RecPoints
 
-//  // --- TClonesArray of stored hits -> not reset et finish event
-//  //                 (for digitization at the end of the event)
-//
-//  TClonesArray *fStHits;
-//  Int_t   fNStHits;
-//  Int_t   fNPrimaryHits;     // Number of primary particles
-
-
   ClassDef(AliZDC,1)   // Zero Degree Calorimeter base class
 };
  
diff --git a/ZDC/AliZDCMergedHit.cxx b/ZDC/AliZDCMergedHit.cxx
new file mode 100644 (file)
index 0000000..4855702
--- /dev/null
@@ -0,0 +1,48 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *;
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/*
+$Log
+*/
+
+////////////////////////////////////////////////
+//  MergedHits classes for set ZDC            //
+////////////////////////////////////////////////
+
+
+#include "AliZDCMergedHit.h"
+#include "AliRun.h"
+
+ClassImp(AliZDCMergedHit)
+  
+//_____________________________________________________________________________
+AliZDCMergedHit::AliZDCMergedHit(Int_t *sector, Float_t *mhits)
+{
+  //
+  // Add a ZDC hit for merging
+  //
+  Int_t i;
+  for(i=0; i<2; i++) {
+     fSector[i] = sector[i];
+  }
+  fPrimKinEn   = mhits[0];
+  fXImpact     = mhits[1];
+  fYImpact     = mhits[2];
+  fSFlag       = mhits[3];
+  fLightPMQ    = mhits[4];
+  fLightPMC    = mhits[5];
+  fEnergy      = mhits[6]; 
+  
+}
diff --git a/ZDC/AliZDCMergedHit.h b/ZDC/AliZDCMergedHit.h
new file mode 100644 (file)
index 0000000..28a491a
--- /dev/null
@@ -0,0 +1,66 @@
+#ifndef ALIZDCMERGEDHIT_H
+#define ALIZDCMERGEDHIT_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+////////////////////////////////////////////////
+//  Hits classes for set ZDC                  //
+////////////////////////////////////////////////
+
+#include "TObject.h"
+
+class AliZDCMergedHit : public TObject {
+
+public:
+  AliZDCMergedHit() {}
+  AliZDCMergedHit(Int_t *sector, Float_t *mhits);
+  AliZDCMergedHit(AliZDCMergedHit* oldhit) {*this=*oldhit;}
+  virtual ~AliZDCMergedHit() {}
+
+  // Getters 
+  virtual Int_t   GetSector(Int_t i) {return fSector[i];}
+  virtual Float_t GetPrimKinEn()     {return fPrimKinEn;}
+  virtual Float_t GetXImpact()       {return fXImpact;}
+  virtual Float_t GetYImpact()       {return fYImpact;}
+  virtual Float_t GetSFlag()         {return fSFlag;}
+  virtual Float_t GetLightPMQ()      {return fLightPMQ;}
+  virtual Float_t GetLightPMC()      {return fLightPMC;}
+  virtual Float_t GetEnergy()        {return fEnergy;}
+
+
+  // Data members
+  Int_t      fSector[2];    //Array of volumes
+  Float_t    fPrimKinEn;    //Primary particle energy
+  Float_t    fXImpact;      //x-coord. of the impact point over the ZDC
+  Float_t    fYImpact;      //y-coord. of the impact point over the ZDC
+  Float_t    fSFlag;        //Secondary flag
+  Float_t    fLightPMQ;     //Cerenkov light produced in each quadrant
+  Float_t    fLightPMC;     //Cerenkov light seen by the common PM
+  Float_t    fEnergy;       //Total energy deposited in eV
+
+  // Operators
+  Int_t operator == (AliZDCMergedHit &quad) {
+     Int_t i;
+     for(i=0; i<2; i++) if(fSector[i]!=quad.GetSector(i)) return 0;
+     return 1;
+  }
+  
+  virtual AliZDCMergedHit& operator + (AliZDCMergedHit &quad) {
+     fLightPMQ+=quad.GetLightPMQ();
+     fLightPMC+=quad.GetLightPMC();
+     fEnergy+=quad.GetEnergy();
+     return *this;
+  }
+
+  // Print method
+  virtual void Print(Option_t *) const {
+     printf(" ### MergedHit: sector[0] =  %d sector[1] =  %d "
+           "  LightPMQ = %f, LightPMC = %f,  Deposited E = %f\n ", 
+           fSector[0],fSector[1],fLightPMQ,fLightPMC,fEnergy);
+  }
+
+  ClassDef(AliZDCMergedHit,1)  // MergedHits for the Zero Degree Calorimeters
+};
+#endif
index 62576854b85efbc8c048eb6a04e77f91a22543f9..26c1155468e7cdd7d8ea99a8c3d5573772d119b4 100644 (file)
 #include <TTree.h>
 #include <TFile.h>
 #include <TDirectory.h>
-#include <TH1.h>
+#include <TNtuple.h>
 #include <TSystem.h>
 
 // --- AliRoot header files
 #include "AliZDCMerger.h"
 #include "AliZDC.h"
 #include "AliZDCHit.h"
+#include "AliZDCMergedHit.h"
 #include "AliZDCDigit.h"
 #include "AliZDCFragment.h"
 #include "AliRun.h"
@@ -47,9 +48,10 @@ AliZDCMerger::AliZDCMerger()
 {
 // Default constructor    
     fMerge       = kDigitize;
-    fNEvBgr     = 0;
+//   fMerge       = kMerge;
     fFnBgr       = 0;
     fBgrFile     = 0;
+    fNEvBgr     = 0;
     fTrHBgr      = 0;
     fTrSDBgr     = 0;
     fImpPar      = 0;
@@ -61,7 +63,8 @@ AliZDCMerger::AliZDCMerger()
     fSpecnFile   = 0;
     fFnSpecp     = 0;
     fSpecpFile   = 0;
-    
+    fNMhits     = 0;
+     
 }
 
 //____________________________________________________________________________
@@ -90,7 +93,7 @@ void AliZDCMerger::InitMerging()
     
     // Extract from spectators distribution the signal events:
     // NFreeSpectatorN spectator n & NFreeSpectatorP spectator p 
-    Mixing(fFreeSpn, fFreeSpp);
+    Mixing();
 }
 
 //____________________________________________________________________________
@@ -104,24 +107,23 @@ void AliZDCMerger::Background(Float_t &fImpPar, Int_t &fSpecn, Int_t &fSpecp)
     //     # of spectators n and p (fSpecn, fSpecp)
     fBgrFile->cd();
 
-    // Get AliRun object from file or create it if not on file
-    gAlice = (AliRun*)fBgrFile->Get("gAlice");
-    if (!gAlice) {
-      gAlice = (AliRun*)fBgrFile->Get("gAlice");
-      if (gAlice) printf("AliRun object found on file\n");
-      if (!gAlice) {
-         printf("\n create new gAlice object");
-         gAlice = new AliRun("gAlice","Alice test program");
-      }
-    }
-
+//    // Get AliRun object from file or create it if not on file
 //    gAlice = (AliRun*)fBgrFile->Get("gAlice");
+//    if (!gAlice) {
+//      gAlice = (AliRun*)fBgrFile->Get("gAlice");
+//      if (gAlice) printf("AliRun object found on file\n");
+//      if (!gAlice) {
+//       printf("\n create new gAlice object");
+//       gAlice = new AliRun("gAlice","Alice test program");
+//      }
+//    }
+
     AliHeader *header = gAlice->GetHeader();
     AliGenEventHeader* mcHeader = header->GenEventHeader();
     fImpPar = ((AliGenHijingEventHeader*) mcHeader)->ImpactParameter();
     fSpecn  = ((AliGenHijingEventHeader*) mcHeader)->Spectatorsn();
     fSpecp  = ((AliGenHijingEventHeader*) mcHeader)->Spectatorsp();
-//      printf("\n     HIJING simulation - b = %f fm, Nspecn = %d, Nspecp = %d\n",fImpPar,fSpecn,fSpecp);
+    printf("\n HIJING simulation - b = %f fm, Nspecn = %d, Nspecp = %d\n",fImpPar,fSpecn,fSpecp);
 }
 
 //____________________________________________________________________________
@@ -129,8 +131,9 @@ TFile* AliZDCMerger::OpenBgrFile()
 {
     // Initialise background event
     TFile *file = new TFile(fFnBgr,"UPDATE");
-//      printf("\n AliZDCMerger --- Background event -> %s file opened \n", fFnBgr);
+    printf("\n AliZDCMerger --- Background event -> %s file opened \n", fFnBgr);
     fHitsBgr = new TClonesArray("AliZDCHit",1000);
+    fMHits   = new TClonesArray("AliZDCMergedHit",1000);
     return file;
 }
 
@@ -154,189 +157,174 @@ void AliZDCMerger::Fragmentation(Float_t fImpPar, Int_t fSpecn, Int_t fSpecp,
     frag->AttachNeutrons(zz, nn, Ztot, Ntot);
     fFreeSpn = fSpecn-Ztot-2*nAlpha;
     fFreeSpp = fSpecp-Ntot-2*nAlpha;
-//      printf("\n     Fragmentation -> FreeSpn = %d, FreeSpp = %d\n",fFreeSpn,fFreeSpp);
+    printf("\n Fragmentation -> FreeSpn = %d, FreeSpp = %d\n",fFreeSpn,fFreeSpp);
 }
 
 //____________________________________________________________________________
-void AliZDCMerger::Mixing(Int_t fFreeSpn, Int_t fFreeSpp)
+void AliZDCMerger::Mixing()
 {
-
-//      printf("\n     AliZDCMerger->Mixing\n");
-        
+    
+//    printf("\n       AliZDCMerger->Mixing\n");
+       
     // ### Background event Hits ###########################################
     fBgrFile->cd();
 //    fBgrFile->ls();
     
-    AliZDC *ZDC = (AliZDC *)gAlice->GetModule("ZDC");
+   AliZDC *ZDC = (AliZDC *)gAlice->GetModule("ZDC");
 //    if(ZDC) printf("\n       Ho trovato lo ZDC!\n");
 
     // Hits tree
     if(fTrHBgr) delete fTrHBgr;
-    fTrHBgr = 0;    
+    fTrHBgr = 0;        
     // SDigits tree
     if(fTrSDBgr) delete fTrSDBgr;
     fTrSDBgr = 0;    
 
-//    // Read from Event Tree the # of events of the Hijing file 
-//    TTree *thead = (TTree *) fBgrFile->Get("TE");
-//    if(!te){
-//      printf("\n     ERROR! -> File %s does not contain TreeE\n");
-//    }
-//    fNEvBgr = (Int_t) te->GetEntries();
-    fNEvBgr = 0; // Let's suppose to have 1 full Hijing event per file
+//    fNEvBgr = 0; // Let's suppose to have 1 full Hijing event per file
 
-    // Hits Tree
+    // Hits tree
     char treeBgrName[20];
     sprintf(treeBgrName,"TreeH%d",fNEvBgr);
-    fTrHBgr = (TTree*)gDirectory->Get(treeBgrName); // TreeH
+    fTrHBgr = (TTree*)gDirectory->Get(treeBgrName); 
     if(!fTrHBgr){
       printf("\n ERROR -> Can't find TreeH%d in background file\n",fNEvBgr);
     }    
+//    fTrHBgr->Print();
+    
+    // Branch address
+    TBranch *branch;
+    char branchname[20];
+    sprintf(branchname,"%s",ZDC->GetName());
+    if(fTrHBgr && fHitsBgr){
+//      printf("\n     fTrHBgr!=0 && fHitsBgr!=0\n");
+      branch = fTrHBgr->GetBranch(branchname);
+      if(branch) branch->SetAddress(&fHitsBgr);
+    }
+    
     Int_t ntracks =  (Int_t) fTrHBgr->GetEntries();
-//    printf("\n       --- ntracks = %d\n",ntracks);
-
-    // SDigits Tree
-    char treeSBgrName[20];
-    sprintf(treeSBgrName,"TreeS%d",fNEvBgr);
-    fTrSDBgr = (TTree*)gDirectory->Get(treeSBgrName); // TreeH
-    if(!fTrSDBgr){
-      printf("\n ERROR -> Can't find TreeS%d in background file\n",fNEvBgr);
-    }    
+//    printf("\n       --- ntracks = %d\n\n", ntracks);
+    
+    Int_t itrack, nhits, ihit, j, sector[2];
+    AliZDCHit* zdcHit;
+    AliZDCMergedHit *MHit;
+    Float_t MHits[7];
+    TClonesArray &sdigits = *fMHits;   // SDigits TCArray
+    fNMhits = 0;
 
-    Int_t itrack, i, volume[2], detector, quadrant;
-    TClonesArray &sdigits = *fHitsBgr; // SDigits TCArray
-    Float_t hits[10];
     // --- Tracks loop
     for(itrack=0; itrack<ntracks; itrack++){
-//       printf("              itrack = %d \n", itrack);
+//       printf("               itrack = %d", itrack);
+//       gAlice->ResetHits();
        fTrHBgr->GetEvent(itrack);
        
-       fTrack = itrack;
-       Int_t NMhits  = 0;
-       for(AliZDCHit* zdcHit=(AliZDCHit*)ZDC->FirstHit(-1); 
-           zdcHit;
-          zdcHit = (AliZDCHit*)ZDC->NextHit()){ 
-
-         for(i=0; i<2; i++) volume[i] = zdcHit->GetVolume(i);
-//       printf("\n            volume[0] = %d volume[1]= %d \n",volume[0], volume[1]);
-         if(volume[0] != 3){
-           // Background hits  
-           hits[7] = zdcHit->GetLightPMQ();
-           hits[8] = zdcHit->GetLightPMC();
-//         printf("\n  Prima ### Background -> PMQ = %f, PMC = %f\n",hits[7],hits[8]);
-
-            //Signal hits
-           detector = volume[0];
-           quadrant = volume[1];
-           ExtractSignal(detector, quadrant, fQuadLight, fComLight);      
-           hits[7] += fQuadLight;
-           hits[8] += fComLight;
-//         printf("\n  Bckg + Signal -> PMQ = %f, PMC = %f\n",hits[7],hits[8]);
-
-            zdcHit->SetLightPMQ(hits[7]);
-            zdcHit->SetLightPMC(hits[8]);
-           hits[7] = zdcHit->GetLightPMQ();
-           hits[8] = zdcHit->GetLightPMC();
-//         printf("\n  Dopo ### Background -> PMQ = %f, PMC = %f\n",hits[7],hits[8]);
-                   
-           new (sdigits[NMhits++]) AliZDCHit(zdcHit);
-//            printf("\n       NMhits = %d\n",NMhits);
-         }
-          fBgrFile->cd();
-          fTrSDBgr->Fill();
-          fTrSDBgr->Write(0,TObject::kOverwrite);
-       } //Hits loop
-       Digitize();
+//       for(AliZDCHit* zdcHit=(AliZDCHit*)ZDC->FirstHit(-1); 
+//        zdcHit;
+//        zdcHit = (AliZDCHit*)ZDC->NextHit()){ 
+
+       nhits = fHitsBgr->GetEntries();
+//       nhits = ZDCdp->GetNhits();
+//       printf("            nhits = %d \n", nhits);
+       for(ihit=0; ihit<nhits; ihit++){    
+         zdcHit = (AliZDCHit*) fHitsBgr->UncheckedAt(ihit);
+
+           for(j=0; j<2; j++) sector[j] = zdcHit->GetVolume(j);
+           MHits[0] = zdcHit->GetPrimKinEn();
+           MHits[1] = zdcHit->GetXImpact();
+           MHits[2] = zdcHit->GetYImpact();
+           MHits[3] = zdcHit->GetSFlag();
+           MHits[4] = zdcHit->GetLightPMQ();
+           MHits[5] = zdcHit->GetLightPMC();
+           MHits[6] = zdcHit->GetEnergy();
+           MHit = new AliZDCMergedHit(sector, MHits);
+//         MHit->Print("");
+           new((*fMHits)[fNMhits]) AliZDCMergedHit(*MHit);
+           new (sdigits[fNMhits])  AliZDCMergedHit(*MHit);
+           delete MHit;
+           fNMhits++;
+         }//Hits loop
+         
     } // Tracks loop
+//    printf("\n       fNMhits (after bckg) = %d, \n",fNMhits); 
+//    fMHits->Dump();
+//    AliZDCMergedHit *pippo7 = (AliZDCMergedHit*) fMHits->At(7);
+//    pippo7->Dump();
+    
         
-//    fBgrFile->Close();
+    // ### Signal event Hits ###########################################
+    // --- Neutrons
+    ExtractSignal(1);
+        
+    // --- Protons
+    ExtractSignal(2);
+//    printf("\n       fNMhits (after signal) = %d \n",fNMhits); 
         
 }
 
 //____________________________________________________________________________
-void AliZDCMerger::ExtractSignal(Int_t detector, Int_t quadrant,
-                                    Float_t &fQuadLight, Float_t &fComLight)
+void AliZDCMerger::ExtractSignal(Int_t SpecType)
 {
 
-//    printf("\n       Entering ExtractSignal method -> detector = %d quadrant = %d\n",
-//           detector, quadrant);
-
-    // Connect spectator n histo's file
-    fFnSpecn = gSystem->ExpandPathName("$ALICE/$ALICE_LEVEL/ZDC/ZNsignal.root");
-    fSpecnFile = TFile::Open(fFnSpecn,"R");
-    fSpecnFile->cd();
-//    fSpecnFile->ls();
-    TH1F *hPMQ1zn = (TH1F*) gDirectory->Get("hPMQ1zn;1");
-    TH1F *hPMQ2zn = (TH1F*) gDirectory->Get("hPMQ2zn;1");
-    TH1F *hPMQ3zn = (TH1F*) gDirectory->Get("hPMQ3zn;1");
-    TH1F *hPMQ4zn = (TH1F*) gDirectory->Get("hPMQ4zn;1");
-    TH1F *hPMC1zn = (TH1F*) gDirectory->Get("hPMC1zn;1");
-    TH1F *hPMC2zn = (TH1F*) gDirectory->Get("hPMC2zn;1");
-    TH1F *hPMC3zn = (TH1F*) gDirectory->Get("hPMC3zn;1");
-    TH1F *hPMC4zn = (TH1F*) gDirectory->Get("hPMC4zn;1");
-//    Axis_t x = hPMQ1zn -> GetRandom();
-//    printf(" hPMQ1zn -> GetRandom() = %f\n",x);
-    
-    // Connect spectator p histo's file
-    fFnSpecp = gSystem->ExpandPathName("$ALICE/$ALICE_LEVEL/ZDC/ZPsignal.root");
-    fSpecpFile = TFile::Open(fFnSpecp,"R");
-    fSpecpFile->cd(); 
-//    fSpecpFile->ls();
-    TH1F *hPMQ1zp = (TH1F*) gDirectory->Get("hPMQ1zp;1");
-    TH1F *hPMQ2zp = (TH1F*) gDirectory->Get("hPMQ2zp;1");
-    TH1F *hPMQ3zp = (TH1F*) gDirectory->Get("hPMQ3zp;1");
-    TH1F *hPMQ4zp = (TH1F*) gDirectory->Get("hPMQ4zp;1");
-    TH1F *hPMC1zp = (TH1F*) gDirectory->Get("hPMC1zp;1");
-    TH1F *hPMC2zp = (TH1F*) gDirectory->Get("hPMC2zp;1");
-    TH1F *hPMC3zp = (TH1F*) gDirectory->Get("hPMC3zp;1");
-    TH1F *hPMC4zp = (TH1F*) gDirectory->Get("hPMC4zp;1");
-
-    if(detector == 1){ // --- ZN
-      if(quadrant == 1){
-        fQuadLight = (Float_t) hPMQ1zn -> GetRandom();
-       fComLight = (Float_t) hPMC1zn -> GetRandom();
-      }
-      else if(quadrant == 2){
-        fQuadLight = (Float_t) hPMQ2zn -> GetRandom();
-       fComLight = (Float_t) hPMC2zn -> GetRandom();
-      }
-      else if(quadrant == 3){
-        fQuadLight = (Float_t) hPMQ3zn -> GetRandom();
-       fComLight = (Float_t) hPMC3zn -> GetRandom();
-      }
-      else if(quadrant == 4){
-        fQuadLight = (Float_t) hPMQ4zn -> GetRandom();
-       fComLight = (Float_t) hPMC4zn -> GetRandom();
-      }
-    }
-
-    else if(detector == 2){ // --- ZP
-      fSpecpFile->cd();        // Connect spectator p histo's file
-//      fSpecpFile->ls();
-      if(quadrant == 1){
-        fQuadLight = (Float_t) hPMQ1zp -> GetRandom();
-       fComLight = (Float_t) hPMC1zp -> GetRandom();
-      }
-      else if(quadrant == 2){
-        fQuadLight = (Float_t) hPMQ2zp -> GetRandom();
-       fComLight = (Float_t) hPMC2zp -> GetRandom();
-      }
-      else if(quadrant == 3){
-        fQuadLight = (Float_t) hPMQ3zp -> GetRandom();
-       fComLight = (Float_t) hPMC3zp -> GetRandom();
-      }
-      else if(quadrant == 4){
-        fQuadLight = (Float_t) hPMQ4zp -> GetRandom();
-       fComLight = (Float_t) hPMC4zp -> GetRandom();
-      }
-    }
-//    printf(" ---     Exiting ExtractSignal -> fQuadLight = %f, fComLight = %f",
-//           fQuadLight,fComLight);
-
+// printf("\n  Entering in Extract Signal\n");
+ Int_t NumEvents = 0;
+ if(SpecType == 1){            // --- Signal for spectator neutrons
+   fFnSpecn = gSystem->ExpandPathName("$ALICE/$ALICE_LEVEL/ZDC/ZNsignalntu.root");
+   fSpecnFile = TFile::Open(fFnSpecn,"R");
+   fSpecnFile->cd();
+//   printf("\n        --- ExtractSignal x n: file %s opened\n", fFnSpecn);
+   NumEvents = fFreeSpn;
+ }
+ else if(SpecType == 2){       // --- Signal for spectator protons
+   fFnSpecp = gSystem->ExpandPathName("$ALICE/$ALICE_LEVEL/ZDC/ZPsignalntu.root");
+   fSpecpFile = TFile::Open(fFnSpecp,"R");
+   fSpecpFile->cd();
+//   printf("\n        --- ExtractSignal x p: file %s opened\n", fFnSpecp);
+   NumEvents = fFreeSpp;
+ }
+// printf("\n          # of free spectator = %d\n", NumEvents);
+// printf("\n         fNMhits (before adding signal) = %d\n",fNMhits);
+
+  TNtuple *ZDCSignal = (TNtuple*) gDirectory->Get("ZDCSignal");
+  Int_t nentries = (Int_t) ZDCSignal->GetEntries();
+//  printf("\n   # entries = %d\n", nentries);
+  Int_t i, j, k;
+  
+  AliZDCMergedHit *MHit; 
+  Float_t *entry, HitsSpec[7];
+  Int_t iev, rnd, Volume[2];
+  for(iev=0; iev<NumEvents; iev++){
+     rnd = (Int_t) (1000*gRandom->Rndm());
+//     printf("\n      rnd = %d\n", rnd);
+     for(i=0; i<nentries; i++){  
+       ZDCSignal->GetEvent(i);
+       entry = ZDCSignal->GetArgs();
+       if(entry[0] == rnd){
+//        printf("\n   entry[0] = %f\n", entry[0]);
+          for(k=0; k<2; k++) Volume[k] = (Int_t) entry[k+1];
+          for(j=0; j<7; j++){
+             HitsSpec[j] = entry[j+3];
+          }
+         MHit = new AliZDCMergedHit(Volume, HitsSpec);
+         new((*fMHits)[fNMhits++]) AliZDCMergedHit(*MHit);
+         delete MHit;
+       }
+       else if(entry[0] > rnd) break;
+     }
+  }
+  
+  if(SpecType ==1){
+//    printf("\n         fNMhits (after n signal) = %d\n",fNMhits);
+    fSpecnFile->Close();
+  }
+  else if(SpecType == 2){
+//    printf("\n         fNMhits (after p signal) = %d\n",fNMhits);
+    fSpecpFile->Close();
+  }
+      
 }
 
 //____________________________________________________________________________
-void AliZDCMerger::Digitize()
+void AliZDCMerger::Digitize(Int_t fNMhits, TClonesArray *fMHits)
 {
 
 //  printf("\n AliZDCMerger->Digitize()");
@@ -344,141 +332,106 @@ void AliZDCMerger::Digitize()
   AliZDC *ZDC = (AliZDC *)gAlice->GetModule("ZDC");
 //  if(ZDC) printf("\n         Ho trovato lo ZDC!\n");
 
-  Int_t itrack, lightQ, lightC, sector[2], digit;
-  Int_t PMCZN = 0, PMCZP = 0, PMQZN[4], PMQZP[4], PMZEM = 0;
+  Int_t lightQ, lightC, sector[2], digit;
+  Int_t PMCZN = 0, PMCZP = 0, PMQZN[4], PMQZP[4], PMZEM1 = 0, PMZEM2 = 0;
   Int_t i;
   for(i=0; i<4; i++){
      PMQZN[i] = 0;
      PMQZP[i] = 0;
   }
-
-  // ### Digitization "on the flight" (no merging) #######################
-  if(fMerge == kDigitize){
-//    printf("\n               fMerge == kDigitize\n");
-    fTrHBgr = gAlice->TreeH(); // TTree
-    TTree *treeH = gAlice->TreeH();
-    if(!fTrHBgr){
-      printf("\n ERROR -> Can't find TreeH%d in background file\n",fNEvBgr);
-    }    
-    Int_t ntracks =  (Int_t) treeH->GetEntries();
-//    printf("\n       --- ntracks = %d\n",ntracks);
-        
-    // Loop over tracks
-    for(itrack=0; itrack<ntracks; itrack++){
-       gAlice->ResetHits();
-       gAlice->TreeH()->GetEvent(itrack);
-       
-       // Loop over hits
-       for(AliZDCHit* zdcHit=(AliZDCHit*)ZDC->FirstHit(-1); 
-           zdcHit;
-          zdcHit = (AliZDCHit*)ZDC->NextHit()){ 
-         sector[0] = zdcHit->GetVolume(0);
-         sector[1] = zdcHit->GetVolume(1);
-         lightQ    = Int_t(zdcHit->GetLightPMQ());
-         lightC    = Int_t(zdcHit->GetLightPMC());
-//       printf("\n    Digitise -> DET. = %d, quad = %d", sector[0], sector[1]);
-//       printf("                  PMQ = %d, PMC = %d",  lightQ, lightC);
-          
-         if(sector[0] == 1){   //ZN 
-           PMCZN = PMCZN + lightC;
-           PMQZN[sector[1]-1] = PMQZN[sector[1]-1] + lightQ;
-         }
-          else if(sector[0] == 2){     //ZP 
-           PMCZP = PMCZP + lightC;
-           PMQZP[sector[1]-1] = PMQZP[sector[1]-1] + lightQ;
-         }
-          else if(sector[0] == 3){     //ZEM 
-           PMZEM = PMZEM + lightC;
-         }
-       } // hits loop
-    } // tracks loop
-  } // if(fMerge)
-
-  // ### Merging and digitization #######################################
-  else if(fMerge == kMerge){
-//    printf("\n               fMerge == kMerge\n");
-
-//    Int_t ntracks =  (Int_t) fTrHBgr->GetEntries();
-//    printf("\n        --- ntracks = %d\n",ntracks);
-//        
-//    // Loop over tracks
-//    for(itrack=0; itrack<ntracks; itrack++){
-       fTrHBgr->GetEvent(fTrack);
-       
-//       printf("\n\n  Track # %d --- Digitise -> ", fTrack);
-       // Loop over hits
-       for(AliZDCHit* zdcHit=(AliZDCHit*)ZDC->FirstHit(-1); 
-           zdcHit;
-          zdcHit = (AliZDCHit*)ZDC->NextHit()){ 
-         sector[0] = zdcHit->GetVolume(0);
-         sector[1] = zdcHit->GetVolume(1);
-         lightQ    = Int_t(zdcHit->GetLightPMQ());
-         lightC    = Int_t(zdcHit->GetLightPMC());
-//       printf("\n    DET. = %d, quad = %d,PMQ = %d, PMC = %d", 
-//              sector[0], sector[1],lightQ, lightC);
-          
-         if(sector[0] == 1){   //ZN 
-           PMCZN = PMCZN + lightC;
-           PMQZN[sector[1]-1] = PMQZN[sector[1]-1] + lightQ;
-         }
-          else if(sector[0] == 2){     //ZP 
-           PMCZP = PMCZP + lightC;
-           PMQZP[sector[1]-1] = PMQZP[sector[1]-1] + lightQ;
-         }
-          else if(sector[0] == 3){     //ZEM 
-           PMZEM = PMZEM + lightC;
-         }
-       } // hits loop
-//    } // tracks loop
-  } // if(fMerge)
-
+  
+  AliZDCMergedHit *MHit;
+  Int_t imhit;
+//  printf("\n    fNMHits = %d\n", fNMhits);
+  // Loop over SDigits
+  for(imhit=0; imhit<fNMhits; imhit++){
+     
+     MHit = (AliZDCMergedHit*) fMHits->UncheckedAt(imhit);
+     sector[0] = MHit->GetSector(0);
+     sector[1] = MHit->GetSector(1);
+  if((sector[1]!=1) && (sector[1]!=2) && (sector[1]!=3) && (sector[1]!=4)){
+//     printf("\n  *** ERROR!!! sector[0] = %d, sector[1] = %d\n",
+//           sector[0], sector[1]);
+       sector[1] = 0;
+   }
+     lightQ    = Int_t(MHit->GetLightPMQ());
+     lightC    = Int_t(MHit->GetLightPMC());
+//     printf("\n    imhit = %d -> DET. = %d, quad = %d,PMQ = %d, PMC = %d", 
+//      imhit,sector[0], sector[1],lightQ, lightC);
+     
+     if(sector[0] == 1){          //ZN 
+       PMCZN = PMCZN + lightC;
+       PMQZN[sector[1]-1] = PMQZN[sector[1]-1] + lightQ;
+     }
+     else if(sector[0] == 2){     //ZP 
+       PMCZP = PMCZP + lightC;
+       PMQZP[sector[1]-1] = PMQZP[sector[1]-1] + lightQ;
+     }
+     else if(sector[0] == 3){     //ZEM 
+       if(sector[1] ==1) PMZEM1 = PMZEM1 + lightC;
+       else              PMZEM2 = PMZEM2 + lightQ;
+     }
+  } // SDigits loop
       
+  // ### Digits creation ###############################################
   // Create digits for ZN
   Int_t PedValue;
   sector[0] = 1; // Detector = ZN
   sector[1] = 0; // Common PM ADC
   digit = Phe2ADCch(1, 0, PMCZN);
 //  printf("\n\n       ZN ###  PMCZN = %d      ADCZN = %d",PMCZN, digit);
+  PedValue = AddPedestal();
+  digit += PedValue;
+//  printf("   PedValue = %d",PedValue);
   ZDC->AddDigit(sector, digit);
   Int_t j;
   for(j=0; j<4; j++){
     sector[1] = j+1; // Towers PM ADCs
     digit = Phe2ADCch(1, j+1, PMQZN[j]);
-//    printf("\n               PMQZN[%d] = %d  ADCZN[%d] = %d",j,PMQZN[j],j,digit);
+//    printf("\n               PMQZN[%d] = %d  phe     ADCZN[%d] = %d ADCch",j,PMQZN[j],j,digit);
     PedValue = AddPedestal();
     digit += PedValue;
 //    printf(" PedValue = %d",PedValue);
     ZDC->AddDigit(sector, digit);
   }
-//    printf("\n");
+//  printf("\n");
   
   // Create digits for ZP
   sector[0] = 2; // Detector = ZP
   sector[1] = 0; // Common PM ADC
   digit = Phe2ADCch(2, 0, PMCZP);
-//  printf("\n ZP --- PMCZP = %d       ADCZP = %d",PMCZP,digit);
+//  printf("\n ZP --- PMCZP = %d       phe     ADCZP = %d ADCch",PMCZP,digit);
+  PedValue = AddPedestal();
+  digit += PedValue;
+  printf("     PedValue = %d",PedValue);
   ZDC->AddDigit(sector, digit);
   for(j=0; j<4; j++){
     sector[1] = j+1; // Towers PM ADCs
     digit = Phe2ADCch(2, j+1, PMQZP[j]);
-//    printf("\n              PMQZP[%d] = %d   ADCZP[%d] = %d",j,PMQZP[j],j,digit);
+//    printf("\n              PMQZP[%d] = %d   phe     ADCZP[%d] = %d ADCch",j,PMQZP[j],j,digit);
     PedValue = AddPedestal();
     digit += PedValue;
 //    printf(" PedValue = %d",PedValue);
     ZDC->AddDigit(sector, digit);
   }
-//    printf("\n");
+//  printf("\n");
   
   // Create digits for ZEM
-  sector[0] = 3; // Detector = ZZEM
-  sector[1] = 0; // Single PM ADC
-  digit  = Phe2ADCch(3, 0, PMZEM);
-//  printf("\n ZEM *** PMZEM = %d      ADCZEM = %d",PMZEM,digit);
-    PedValue = AddPedestal();
-    digit += PedValue;
-//    printf(" PedValue = %d\n",PedValue);
+  sector[0] = 3; 
+  sector[1] = 1; // Detector = ZEM1
+  digit  = Phe2ADCch(3, 1, PMZEM1);
+//  printf("\n  ZEM *** PMZEM1 = %d      phe     ADCZEM1 = %d ADCch",PMZEM1,digit);
+  PedValue = AddPedestal();
+  digit += PedValue;
+//  printf("  PedValue = %d\n",PedValue);
+  ZDC->AddDigit(sector, digit); 
+  sector[1] = 2; // Detector = ZEM2
+  digit  = Phe2ADCch(3, 2, PMZEM2);
+//  printf("\n  ZEM *** PMZEM2 = %d      phe     ADCZEM2 = %d ADCch",PMZEM2,digit);
+  PedValue = AddPedestal();
+  digit += PedValue;
+//  printf("  PedValue = %d\n",PedValue);
   ZDC->AddDigit(sector, digit); 
-
 }
 
 //_____________________________________________________________________________
index 2407a49a41b1a591f29b8a46a159db717ee63302..934b953e289be2c1c8d8c8130a190db1f2beb3d7 100644 (file)
@@ -9,6 +9,7 @@
 
 class AliZDC;
 class AliZDCHit;
+class AliZDCMergedHit;
 class AliZDCDigit;
 
 typedef enum {kDigitize=0, kMerge=1} MergeMode_t;
@@ -23,19 +24,27 @@ public:
    void    Background(Float_t &b, Int_t &nspecn, Int_t &nspecp);
    void    Fragmentation(Float_t b, Int_t nspecn, Int_t nspecp,
                          Int_t &nfreespn, Int_t &nfreespp);
-   void    Mixing(Int_t nfreespn, Int_t nfreespp);
-   void    ExtractSignal(Int_t detector, Int_t quadrant, Float_t &quadLight, 
-                         Float_t &comLight);
-//   void    MergeHit(Int_t track, Int_t *vol, Float_t *hits);
-
-   void    Digitize();
+   void    Mixing();
+   void    ExtractSignal(Int_t SpecType);
+   void    Digitize(Int_t NMhits, TClonesArray *MHits);
    Int_t   Phe2ADCch(Int_t Detector, Int_t Quadrant, Int_t Light);
    Int_t   AddPedestal();
    
+   // Inline functions to return TCA of MergerHits to Hits2SDigits()
+   TClonesArray *MergedHits()   const {return fMHits;}
+   int   GetNMhits()                   const {return fNMhits;}
+
+   // Inline function to return background file Hits2SDigits()
+   TFile *BgrFile()            const {return fBgrFile;}
+
+   // Inline function to return event number
+   Int_t EvNum()               const {return fNEvBgr;}
+   
    // Setters 
-   void SetBackgroundFileName(char* file) {fFnBgr = file;}        
    void SetMode(MergeMode_t mode)         {fMerge = mode;}
-     
+   void SetBackgroundFileName(char* file) {fFnBgr = file;}        
+   void SetBackgroundEventNum(Int_t nev)  {fNEvBgr = nev;}        
+
 private:
    //Open the background file 
    TFile *OpenBgrFile(); 
@@ -44,30 +53,29 @@ protected:
    MergeMode_t  fMerge;                // Merging type kDigitize, kMerge
    
    // Background event
-   Int_t       fNEvBgr;        // Number of events in the background file
    char         *fFnBgr;       // Background file name
    TFile       *fBgrFile;      // Pointer to background file
+   Int_t       fNEvBgr;        // Number of events in background file
    TTree        *fTrHBgr;      // Hits tree for background event
+   TClonesArray *fHitsBgr;     // TClonesArray of background hits
    TTree        *fTrSDBgr;     // SDigits tree for background event
+   TTree        *fTrDBgr;      // Digits tree for background event
    Float_t     fImpPar;        // Impact Parameter of the collision
    Int_t        fSpecn;                // Number of spectator n
    Int_t        fSpecp;                // Number of spectator p
-   TClonesArray *fHitsBgr;     // TClonesArray of background hits
 
    // Signal events
    Int_t        fFreeSpn;       // Signal event number x spectator n
    Int_t        fFreeSpp;       // Signal event number x spectator p
-      
-   // File containing hit histograms for spectators
+
    char        *fFnSpecn;      // Spectator n file name
    TFile       *fSpecnFile;    // Pointer to signal file -> spectator n
    char        *fFnSpecp;      // Spectator p file name
    TFile       *fSpecpFile;    // Pointer to signal file -> spectator p
-   Float_t     fQuadLight;     // Light produced in tower PM
-   Float_t     fComLight;      // Light produced in common PM
    
-   Int_t       fTrack;
-
+   Int_t       fNMhits;        // Number of Merged hits for background
+   TClonesArray *fMHits;       // TCA for "merged" hits  
+   
 //  // *** Digits
 //  // --- Digitization parameters setters and getters
 //  //         PM gain
index 1fb603984878d36e7fec5fcdd5a815682beddfe7..4a6c3470479fd8175ab94082ab090b138d5d2c49 100644 (file)
@@ -14,7 +14,7 @@ FSRCS       =
 # C++ sources
 
 SRCS          = AliZDC.cxx AliZDCv1.cxx AliZDCv2.cxx AliZDCHit.cxx AliZDCDigit.cxx \
-                AliGenZDC.cxx AliZDCFragment.cxx AliZDCMerger.cxx
+                AliGenZDC.cxx AliZDCFragment.cxx AliZDCMerger.cxx AliZDCMergedHit.cxx
 
 # C++ Headers
 
index 03f49792dfbfe20e97b4177eee114ebb9c88f23b..668c18f1f95056b2e2cff237d911c9f263d7c5ee 100644 (file)
@@ -16,5 +16,6 @@
 #pragma link C++ class  AliGenZDC+;
 #pragma link C++ class  AliZDCFragment+;
 #pragma link C++ class  AliZDCMerger+;
+#pragma link C++ class  AliZDCMergedHit+;
 
 #endif