]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RICH/AliRICHv1.cxx
Raw data reconstruction (K.Shileev)
[u/mrichter/AliRoot.git] / RICH / AliRICHv1.cxx
index ce4a41adb11ae05726facec4f23218220347be32..cfe2ed6db61e10b14fbb53e432c23ac4885abd89 100644 (file)
 // **************************************************************************
 
 
-#include "AliRICHv1.h"
+#include "AliRICHv1.h"     //class header
 #include "AliRICHParam.h"
 #include "AliRICHChamber.h"
 #include <TParticle.h> 
 #include <TRandom.h> 
 #include <TVirtualMC.h>
 #include <TPDGCode.h>
-
+#include <AliStack.h>      //Hits2SDigits()
 #include <AliConst.h>
 #include <AliPDG.h>
 #include <AliRun.h>
 #include <AliMC.h>
+#include <AliRawDataHeader.h> //Digits2Raw()
 
 ClassImp(AliRICHv1)    
 //__________________________________________________________________________________________________
@@ -180,3 +181,89 @@ void AliRICHv1::GenerateFeedbacks(Int_t iChamber,Float_t eloss)
   }//feedbacks loop
   AliDebug(1,"Stop.");
 }//GenerateFeedbacks()
+//__________________________________________________________________________________________________
+void AliRICHv1::Hits2SDigits()
+{
+// Create a list of sdigits corresponding to list of hits. Every hit generates one or more sdigits.
+  AliDebug(1,"Start.");
+  for(Int_t iEventN=0;iEventN<GetLoader()->GetRunLoader()->GetAliRun()->GetEventsPerRun();iEventN++){//events loop
+    GetLoader()->GetRunLoader()->GetEvent(iEventN);//get next event
+  
+    if(!GetLoader()->TreeH()) GetLoader()->LoadHits();    GetLoader()->GetRunLoader()->LoadHeader(); 
+    if(!GetLoader()->GetRunLoader()->TreeK())             GetLoader()->GetRunLoader()->LoadKinematics();//from
+    if(!GetLoader()->TreeS()) GetLoader()->MakeTree("S"); MakeBranch("S");//to
+          
+    for(Int_t iPrimN=0;iPrimN<GetLoader()->TreeH()->GetEntries();iPrimN++){//prims loop
+      GetLoader()->TreeH()->GetEntry(iPrimN);
+      for(Int_t iHitN=0;iHitN<Hits()->GetEntries();iHitN++){//hits loop 
+        AliRICHHit *pHit=(AliRICHHit*)Hits()->At(iHitN);//get current hit                
+        TVector2 x2 = C(pHit->C())->Mrs2Anod(0.5*(pHit->InX3()+pHit->OutX3()));//hit position in the anod plane
+        Int_t iTotQdc=P()->TotQdc(x2,pHit->Eloss());//total charge produced by hit, 0 if hit in dead zone
+        if(iTotQdc==0) continue;
+        //
+        //need to quantize the anod....
+        TVector padHit=AliRICHParam::Loc2Pad(x2);
+        TVector2 padHitXY=AliRICHParam::Pad2Loc(padHit);
+        TVector2 anod;
+        if((x2.Y()-padHitXY.Y())>0) anod.Set(x2.X(),padHitXY.Y()+AliRICHParam::PitchAnod()/2);
+        else anod.Set(x2.X(),padHitXY.Y()-AliRICHParam::PitchAnod()/2);
+        //end to quantize anod
+        //
+        TVector area=P()->Loc2Area(anod);//determine affected pads, dead zones analysed inside
+        AliDebug(1,Form("hitanod(%6.2f,%6.2f)->area(%3.0f,%3.0f)-(%3.0f,%3.0f) QDC=%4i",anod.X(),anod.Y(),area[0],area[1],area[2],area[3],iTotQdc));
+        TVector pad(2);
+        for(pad[1]=area[1];pad[1]<=area[3];pad[1]++)//affected pads loop
+          for(pad[0]=area[0];pad[0]<=area[2];pad[0]++){                    
+            Double_t padQdc=iTotQdc*P()->FracQdc(anod,pad);
+            AliDebug(1,Form("current pad(%3.0f,%3.0f) with QDC  =%6.2f",pad[0],pad[1],padQdc));
+            if(padQdc>0.1) SDigitAdd(pHit->C(),pad,padQdc,GetLoader()->GetRunLoader()->Stack()->Particle(pHit->GetTrack())->GetPdgCode(),pHit->GetTrack());
+          }//affected pads loop 
+      }//hits loop
+    }//prims loop
+    GetLoader()->TreeS()->Fill();
+    GetLoader()->WriteSDigits("OVERWRITE");
+    SDigitsReset();
+  }//events loop  
+  GetLoader()->UnloadHits(); GetLoader()->GetRunLoader()->UnloadHeader(); GetLoader()->GetRunLoader()->UnloadKinematics();
+  GetLoader()->UnloadSDigits();  
+  AliDebug(1,"Stop.");
+}//Hits2SDigits()
+//__________________________________________________________________________________________________
+void AliRICHv1::Digits2Raw()
+{
+//Creates raw data files in DDL format. Invoked by AliSimulation
+//loop over events is done outside in AliSimulation
+//Arguments: none
+//  Returns: none    
+  AliDebug(1,"Start.");
+  GetLoader()->LoadDigits();
+  GetLoader()->TreeD()->GetEntry(0);
+  
+  ofstream file[AliRICHDigit::kNddls];   //output streams
+  Int_t    cnt[AliRICHDigit::kNddls];        //data words counters for DDLs
+  AliRawDataHeader header; //empty DDL header
+  UInt_t w32=0;            //32 bits data word 
+  
+  for(Int_t i=0;i<AliRICHDigit::kNddls;i++){//open all 14 DDL in parallel
+    file[i].open(Form("RICH_%4i.ddl",AliRICHDigit::kDdlOffset+i));  //first is 0x700
+    file[i].write((char*)&header,sizeof(header));                //write dummy header as place holder, actual will be written later when total size of DDL is known
+    cnt[i]=0; //reset counters
+  }
+  
+  for(Int_t iChN=1;iChN<=kNchambers;iChN++){ //digits are stored on chamber by chamber basis   
+    for(Int_t iDigN=0;iDigN<Digits(iChN)->GetEntriesFast();iDigN++){//digits loop for a given chamber
+      AliRICHDigit *pDig=(AliRICHDigit*)Digits(iChN)->At(iDigN);
+      Int_t ddl=pDig->Dig2Raw(w32);  //ddl is 0..13 
+      file[ddl].write((char*)&w32,sizeof(w32));  cnt[ddl]++;//write formated digit to the propriate file (as decided in Dig2Raw) and increment corresponding counter
+    }//digits loop for a given chamber
+  }//chambers loop    
+  for(Int_t i=0;i<AliRICHDigit::kNddls;i++){
+    header.fSize=sizeof(header)+cnt[i]*sizeof(w32); //now calculate total number of bytes for each DDL file  
+    header.SetAttribute(0); 
+    file[i].seekp(0); file[i].write((char*)&header,sizeof(header));//rewrite DDL header with fSize field properly set
+    file[i].close();                                               //close DDL file
+  }
+  GetLoader()->UnloadDigits();
+  AliDebug(1,"Stop.");      
+}//Digits2Raw()
+//__________________________________________________________________________________________________