Exemplo n.º 1
0
Int_t printDigits()
{

    AliRunLoader *rl = AliRunLoader::Open("galice.root");

    AliPHOSLoader *prl = (AliPHOSLoader*)rl->GetDetectorLoader("PHOS");

    prl->LoadDigits("READ");
    //prl->LoadDigits();

    Int_t nDigits = 0;
    Int_t nSimEvents = rl->GetNumberOfEvents();
    for (Int_t ev = 0; ev < nSimEvents; ev++)
    {
        rl->GetEvent(ev);

        Int_t nPhosDigits = prl->Digits()->GetEntries();

        //Int_t nDigsFound = 0;
        std::cout << "Number of digits found: " << nPhosDigits << std::endl;
        TClonesArray *phosDigits = prl->Digits();

        for (Int_t iDig = 0; iDig < nPhosDigits; iDig++)
        {
            //const AliPHOSDigit *digit = prl->Digit(iDig);
            AliPHOSDigit *digit = (AliPHOSDigit*)phosDigits->At(iDig);
            nDigits++;
	    //if(digit->GetTime() > 1.4e-08 && digit->GetTime() < 1.6e-08)
            std::cout <<"#: " << iDig << " ID: " << digit->GetId() << " " << "Energy: " << digit->GetEnergy() << " Time: " << digit->GetTime() << " N_prim: " << digit->GetNprimary() <<  " " << digit->GetTimeR() << std::endl;
        }
    }
  return 0;
}
Exemplo n.º 2
0
void TestEMCALSDigit()
{
  
  // Getting EMCAL Detector and Geometry.
  
  AliRunLoader *rl = AliRunLoader::Open("galice.root",AliConfig::GetDefaultEventFolderName(),"read");
  
  if (rl == 0x0)
    cout<<"Can not instatiate the Run Loader"<<endl;
  
  rl->LoadgAlice();//Needed to get geometry
  
  AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>
    (rl->GetDetectorLoader("EMCAL"));
  
  TGeoManager::Import("geometry.root");
  
  AliRun * alirun   = rl->GetAliRun(); // Needed to get Geometry
  AliEMCALGeometry * geom ;
  if(alirun){
    AliEMCAL * emcal  = (AliEMCAL*)alirun->GetDetector("EMCAL");
    geom = emcal->GetGeometry();
  }
  
  if (geom == 0) cout<<"Did not get geometry from EMCALLoader"<<endl;
  else   geom->PrintGeometry();
  
  //Load Digits
  rl->LoadSDigits("EMCAL");
  
  //Get maximum number of events
  Int_t maxevent =  rl->GetNumberOfEvents();
  cout<<"Number of events "<<maxevent<<endl;
  //maxevent = 10 ;
  
  Int_t iEvent  = -1 ;
  Float_t amp   = -1 ;
  Float_t time  = -1 ;
  Int_t id      = -1 ;
  Int_t iSupMod =  0 ;
  Int_t iTower  =  0 ;
  Int_t iIphi   =  0 ;
  Int_t iIeta   =  0 ;
  Int_t iphi    =  0 ;
  Int_t ieta    =  0 ;
  
  AliEMCALDigit * dig;
  
  for ( iEvent=0; iEvent<maxevent; iEvent++)
    {
      cout <<  " ======> Event " << iEvent << endl ;
      //Load Event
      rl->GetEvent(iEvent);
      
      //Fill array of digits
      TClonesArray *digits = emcalLoader->SDigits();
      
      //Get digits from the list      
      for(Int_t idig = 0; idig< digits->GetEntries();idig++){
	//cout<<">> idig "<<idig<<endl;
	dig = static_cast<AliEMCALDigit *>(digits->At(idig)) ;
	
	if(dig != 0){
	  id   = dig->GetId() ; //cell (digit) label
	  amp  = dig->GetAmplitude(); //amplitude in cell (digit)
	  time = dig->GetTime();//time of creation of digit after collision
	  
	  cout<<"Cell ID "<<id<<" Amp "<<amp<<endl;//" time "<<time<<endl;
	  
	  //Geometry methods  
	  if(geom){
	    geom->GetCellIndex(id,iSupMod,iTower,iIphi,iIeta); 
	    //Gives SuperModule and Tower numbers
	    geom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,
					      iIphi, iIeta,iphi,ieta);
	    //Gives label of cell in eta-phi position per each supermodule
	    cout<< "SModule "<<iSupMod<<"; Tower "<<iTower <<"; Eta "<<iIeta
		<<"; Phi "<<iIphi<<"; Cell Eta "<<ieta<<"; Cell Phi "<<iphi<<endl;
	  }
	}
	else
	  cout<<"Digit pointer 0x0"<<endl;
      }
      
    }


}
Exemplo n.º 3
0
void CountTrackableMCs(TH1F *hAllMC, Bool_t onlyPrims,Bool_t onlyPion) {
  
  gSystem->Load("libITSUpgradeBase");
  gSystem->Load("libITSUpgradeSim");

 // open run loader and load gAlice, kinematics and header
  AliRunLoader* runLoader = AliRunLoader::Open("galice.root");
  if (!runLoader) {
    Error("Check kine", "getting run loader from file %s failed",
          "galice.root");
    return;
  }
  runLoader->LoadHeader();
  runLoader->LoadKinematics();
  runLoader->LoadTrackRefs();

  AliLoader *dl = runLoader->GetDetectorLoader("ITS");

  //Trackf
  TTree *trackRefTree = 0x0; 
  TClonesArray *trackRef = new TClonesArray("AliTrackReference",1000);

  //  TH1F *hRef = new TH1F("","",100,0,100);
  TH1F *hR = new TH1F("","",100,0,100);
  if (hAllMC==0) hAllMC = new TH1F("","",100,0.1,2);
  Float_t ptmin = hAllMC->GetBinCenter(1)-hAllMC->GetBinWidth(1)/2;
  Float_t ptmax = hAllMC->GetBinCenter(hAllMC->GetNbinsX())+hAllMC->GetBinWidth(hAllMC->GetNbinsX())/2;
  //  Int_t nAllMC = 0;

  // Detector geometry
  TArrayD rmin(0);   TArrayD rmax(0); 
  GetDetectorRadii(&rmin,&rmax);
  TArrayI nLaySigs(rmin.GetSize());

  printf("Counting trackable MC tracks ...\n");
  
  for(Int_t iEv =0; iEv<runLoader->GetNumberOfEvents(); iEv++){
    Int_t nTrackableTracks = 0;
    runLoader->GetEvent(iEv);
    AliStack* stack = runLoader->Stack();  
    printf("+++ event %i (of %d) +++++++++++++++++++++++  # total MCtracks: %d \n",iEv,runLoader->GetNumberOfEvents()-1,stack->GetNtrack());

    trackRefTree=runLoader->TreeTR();
    TBranch *br = trackRefTree->GetBranch("TrackReferences");
    if(!br) {
      printf("no TR branch available , exiting \n");
      return;
    }
    br->SetAddress(&trackRef);

    // init the trackRef tree 
    trackRefTree=runLoader->TreeTR();
    trackRefTree->SetBranchAddress("TrackReferences",&trackRef);
 
    // Count trackable MC tracks
    for (Int_t iMC=0; iMC<stack->GetNtrack(); iMC++) {

      TParticle* particle = stack->Particle(iMC); 
      if (TMath::Abs(particle->Eta())>etaCut) continue;
      if (onlyPrims && !stack->IsPhysicalPrimary(iMC)) continue;
      if (onlyPion && TMath::Abs(particle->GetPdgCode())!=211) continue;


      Bool_t isTrackable = 0;
      nLaySigs.Reset(0);
 
      trackRefTree->GetEntry(stack->TreeKEntry(iMC));
      Int_t nref=trackRef->GetEntriesFast();
      for(Int_t iref =0; iref<nref; iref++){
	AliTrackReference *trR = (AliTrackReference*)trackRef->At(iref);
	if(!trR) continue;
	if(trR->DetectorId()!=AliTrackReference::kITS) continue;
	Float_t radPos = trR->R();
	hR->Fill(radPos);
	for (Int_t il=0; il<rmin.GetSize();il++) {
	  if (radPos>=rmin.At(il)-0.1 && radPos<=rmax.At(il)+0.1) {
	    //	    cout<<"  in Layer "<<il<<" "<<radPos;
	    nLaySigs.AddAt(1.,il);
	    //	    cout<<" "<<nLaySigs.At(il)<<endl;
	  }
	}
      }

      if (nLaySigs.GetSum()>=3) {
	isTrackable =1;
	//	cout<<nLaySigs.GetSum()<<endl;
      }
      
      if (isTrackable) {
	Double_t ptMC = particle->Pt();
	//	Double_t etaMC = particle->Eta();
	//	if (ptMC>ptmin&&ptMC<ptmax) {nTrackableTracks++;hAllMC->Fill(ptMC);}
	if (ptMC>ptmin) {nTrackableTracks++;hAllMC->Fill(ptMC);}

      }

      
    } // entries tracks MC
    printf(" -> trackable MC tracks: %d (%d)\n",nTrackableTracks,hAllMC->GetEntries());
  }//entries Events
  

  hR->DrawCopy();
  hAllMC->DrawCopy();
  runLoader->UnloadHeader();
  runLoader->UnloadKinematics();
  delete runLoader;

}
Exemplo n.º 4
0
int getSimulatedDigits(TString digitdir)
{

    AliRunLoader *rl = AliRunLoader::Open(digitdir+TString("/galice.root"));

    AliPHOSLoader *prl = (AliPHOSLoader*)rl->GetDetectorLoader("PHOS");

    prl->LoadSDigits();
    prl->LoadDigits();

    Int_t nSimEvents = rl->GetNumberOfEvents();
    TFile *mydigitsFile = new TFile("mydigits.root", "RECREATE");
    TTree *mydigitTree = new TTree("mydigitTree", "mydigitTree");
    TClonesArray * mydigits = new TClonesArray(AliPHOSDigit::Class());
    mydigitTree->Branch("Digits", &mydigits);

    for (Int_t ev = 0; ev < nSimEvents; ev++)
    {
        rl->GetEvent(ev);

        Int_t nPhosDigits = prl->SDigits()->GetEntries();


        Int_t nDigsFound = 0;

        for (Int_t iDig = 0; iDig < nPhosDigits; iDig++)
        {
            const AliPHOSDigit *digit = prl->SDigit(iDig);

            Int_t id = digit->GetId();
            if (id > 3*geom->GetNPhi()*geom->GetNZ()) continue;

            for (Int_t n = 0; n < nDigsFound; n++)
            {
                AliPHOSDigit *tmpDig = (AliPHOSDigit*)mydigits->At(n);
                if (id == tmpDig->GetId())
                {
                    *tmpDig += *digit;
                    digit = 0;
                    break;
                }
            }
            if (digit)
            {
                AliPHOSDigit *newDig = new((*mydigits)[nDigsFound]) AliPHOSDigit(-1, id, (float)0.0, (float)0.0);
                *newDig += *digit;

                nDigsFound++;
            }
        }
        for(int i = 0; i <nDigsFound; i++)
        {

            AliPHOSDigit *tmpDig = (AliPHOSDigit*)mydigits->At(i);
            Int_t relId[4];
            geom->AbsToRelNumbering(tmpDig->GetId(), relId);

            // Some necessary ugly hacks needed at the moment, need to get these numbers from OCDB
            tmpDig->SetEnergy((float)((int)(tmpDig->GetEnergy()/phosCalibData->GetADCchannelEmc(relId[0], relId[3], relId[2]))));
            //std::cout << "Sample time step: " << phosCalibData->GetSampleTimeStep() << " " << phosCalibData->GetTimeShiftEmc(relId[0], relId[3], relId[2]) << geom << std::endl;
            tmpDig->SetTime(1.5e-8);
            tmpDig->SetTimeR(1.5e-8);
        }
        mydigitTree->Fill();
        mydigits->Clear("C");
    }
    mydigitsFile->Write();
    simTree = mydigitTree;
    //mydigit
    //mydigitsFile->Close();
    return 0;
}
Exemplo n.º 5
0
int mergeDigits(TString digitdir, Int_t /*simEvOffset*/)
{

    AliRunLoader *rl = AliRunLoader::Open(digitdir+TString("/galice.root"));

    AliPHOSLoader *prl = (AliPHOSLoader*)rl->GetDetectorLoader("PHOS");

    prl->LoadDigits("UPDATE");
    
    //prl->LoadDigits();

    Int_t nEvents = rl->GetNumberOfEvents();

    TClonesArray *mydigits = 0;
    simTree->SetBranchAddress("Digits", &mydigits);

    Int_t nDigits = 0;
    Int_t nEmbedDigits = 0;
    Int_t nOverlappingDigits = 0;
    Int_t nNewDigits = 0;
    
    Int_t nPhosDigits = prl->Digits()->GetEntries();

    Int_t nMyEvents = simTree->GetEntries();
    
    std::cout << "Number of real events: " << nEvents << std::endl;
    std::cout << "Number of sim events: " << nMyEvents << std::endl;
    nEvents = TMath::Min(nEvents, nMyEvents);
    std::cout << "Looping over: " << nEvents << std::endl;
	
    for (Int_t ev = 0; ev < nEvents; ev++)
    {
        rl->GetEvent(ev);
        
        simTree->GetEntry(ev);
        Int_t nMyDigits = mydigits->GetEntries();

        //Int_t nDigsFound = 0;
        nEmbedDigits += nMyDigits;
        TClonesArray *phosDigits = prl->Digits();
	nPhosDigits = prl->Digits()->GetEntries();
	
        for (Int_t iDig = 0; iDig < nPhosDigits; iDig++)
        {
            //const AliPHOSDigit *digit = prl->Digit(iDig);
            AliPHOSDigit *digit = (AliPHOSDigit*)phosDigits->At(iDig);
            nDigits++;
            for (Int_t n = 0; n < nMyDigits; n++)
            {
                AliPHOSDigit *myDigit = (AliPHOSDigit*)mydigits->At(n);
                if (digit->GetId() == myDigit->GetId())
                {
                    nOverlappingDigits++;
                    break;
                }
            }
        }
        if(nOverlappingDigits == nMyDigits)
        {
            std::cout << "Digits alredy embedded!" << std::endl;
            continue;
        }
        for (Int_t iDig = 0; iDig < nMyDigits; iDig++)
        {
            AliPHOSDigit *myDigit = (AliPHOSDigit*)mydigits->At(iDig);
            if (myDigit)
            {
                for (Int_t n = 0; n < nPhosDigits; n++)
                {
                    //const AliPHOSDigit *digit = prl->Digit(n);

                    AliPHOSDigit *digit = (AliPHOSDigit*)phosDigits->At(n);
                    if (digit->GetId() == myDigit->GetId())
                    {
                        digit->SetALTROSamplesHG(0, 0);
                        digit->SetALTROSamplesLG(0, 0);

                        *digit += *myDigit;
                        myDigit = 0;
                        break;
                    }
                }
                if (myDigit)
                {
                    TClonesArray *digArray = prl->Digits();
                    AliPHOSDigit *newDig =  new((*digArray)[nPhosDigits+nNewDigits]) AliPHOSDigit(*myDigit);

                    newDig->SetALTROSamplesHG(0, 0);
                    newDig->SetALTROSamplesLG(0, 0);
                    nNewDigits++;
                }
            }
        }
        phosDigits->Compress();
        Int_t ndigits = phosDigits->GetEntries() ;
	phosDigits->Sort();
        // Remove digits that are flagged bad in BCM. Then remove digits that are below threshold
        for (Int_t i = 0 ; i < ndigits ; i++)
        {
            AliPHOSDigit *digit = static_cast<AliPHOSDigit*>( phosDigits->At(i) ) ;
	    //std::cout << digit->GetId() << std::endl;
            if(digit->GetId())
            {
                vector<Int_t>::iterator it;
                it = std::find (badChannels.begin(), badChannels.end(), digit->GetId() );
                if(*it)
                {
                    digit->SetEnergy(0.0);
                }
            }
            if(digit->GetEnergy() <= recoParam->GetGlobalAltroThreshold())
	    {
	      phosDigits->RemoveAt(i);
	    }
        }
        //Set indexes in list of digits and make true digitization of the energy
        phosDigits->Compress();
        phosDigits->Sort();
	ndigits = phosDigits->GetEntries();
        for (Int_t i = 0 ; i < ndigits ; i++)
        {
            AliPHOSDigit *digit = static_cast<AliPHOSDigit*>( phosDigits->At(i) ) ;
            digit->SetIndexInList(i) ;
        }
        // -- create Digits branch
        Int_t bufferSize = 32000 ;

        TObjArray *branchList = prl->TreeD()->GetListOfBranches();

        branchList->RemoveAt(0);

        TBranch * digitsBranch = prl->TreeD()->Branch("PHOS","TClonesArray",&phosDigits,bufferSize);

        digitsBranch->Fill() ;
        prl->WriteDigits("OVERWRITE");
    }
    prl->WriteDigits("OVERWRITE");
    std::cout << "# Digits: " << nDigits << std::endl;
    std::cout << "# Embedded digits: " << nEmbedDigits << std::endl;
    std::cout << "# Overlapping digits: " << nOverlappingDigits << std::endl;
    std::cout << "# New digits: " << nNewDigits << std::endl;
    
    return 0;
}
Exemplo n.º 6
0
void compClusHitsMod2(int nev=-1)
{
  
  const int kSplit=0x1<<22;
  const int kSplCheck=0x1<<23;
  //
  gSystem->Load("libITSUpgradeBase");
  gSystem->Load("libITSUpgradeSim");
  gSystem->Load("libITSUpgradeRec");
  gROOT->SetStyle("Plain");

  AliCDBManager* man = AliCDBManager::Instance();
  man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
  man->SetSpecificStorage("GRP/GRP/Data",
        Form("local://%s",gSystem->pwd()));
  man->SetSpecificStorage("ITS/Align/Data",
        Form("local://%s",gSystem->pwd()));
  man->SetSpecificStorage("ITS/Calib/RecoParam",
        Form("local://%s",gSystem->pwd()));
  man->SetRun(0);

  TH1F* hL0A = new TH1F("hL0A", "Layer 0, polar angle", 20, 0, TMath::PiOver2());
  hL0A->SetDirectory(0);
  hL0A->GetXaxis()->SetTitle("#alpha");
  TH1F* hL0B = new TH1F("hL0B", "Layer 0, azimuthal angle", 20, 0, TMath::PiOver2());
  hL0B->SetDirectory(0);
  hL0B->GetXaxis()->SetTitle("#beta");

  TH1F* hL1A = new TH1F("hL1A", "Layer 1, polar angle", 20, 0, TMath::PiOver2());
  hL1A->SetDirectory(0);
  hL1A->GetXaxis()->SetTitle("#alpha");
  TH1F* hL1B = new TH1F("hL1B", "Layer 1, azimuthal angle", 20, 0, TMath::PiOver2());
  hL1B->SetDirectory(0);
  hL1B->GetXaxis()->SetTitle("#beta");

  TH1F* hL2A = new TH1F("hL2A", "Layer 2, polar angle", 20, 0, TMath::PiOver2());
  hL2A->SetDirectory(0);
  hL2A->GetXaxis()->SetTitle("#alpha");
  TH1F* hL2B = new TH1F("hL2B", "Layer 2, azimuthal angle", 20, 0, TMath::PiOver2());
  hL2B->SetDirectory(0);
  hL2B->GetXaxis()->SetTitle("#beta");

  TH1F* hL3A = new TH1F("hL3A", "Layer 3, polar angle", 20, 0, TMath::PiOver2());
  hL3A->SetDirectory(0);
  hL3A->GetXaxis()->SetTitle("#alpha");
  TH1F* hL3B = new TH1F("hL3B", "Layer 3, azimuthal angle", 20, 0, TMath::PiOver2());
  hL3B->SetDirectory(0);
  hL3B->GetXaxis()->SetTitle("#beta");

  TH1F* hL4A = new TH1F("hL4A", "Layer 4, polar angle", 20, 0, TMath::PiOver2());
  hL4A->SetDirectory(0);
  hL4A->GetXaxis()->SetTitle("#alpha");
  TH1F* hL4B = new TH1F("hL4B", "Layer 4, azimuthal angle", 20, 0, TMath::PiOver2());
  hL4B->SetDirectory(0);
  hL4B->GetXaxis()->SetTitle("#beta");

  TH1F* hL5A = new TH1F("hL5A", "Layer 5, polar angle", 20, 0, TMath::PiOver2());
  hL5A->SetDirectory(0);
  hL5A->GetXaxis()->SetTitle("#alpha");
  TH1F* hL5B = new TH1F("hL5B", "Layer 5, azimuthal angle", 20, 0, TMath::PiOver2());
  hL5B->SetDirectory(0);
  hL5B->GetXaxis()->SetTitle("#beta");

  TH1F* hL6A = new TH1F("hL6A", "Layer 6, polar angle", 20, 0, TMath::PiOver2());
  hL6A->SetDirectory(0);
  hL6A->GetXaxis()->SetTitle("#alpha");
  TH1F* hL6B = new TH1F("hL6B", "Layer 6, azimuthal angle", 20, 0, TMath::PiOver2());
  hL6B->SetDirectory(0);
  hL6B->GetXaxis()->SetTitle("#beta");

  gAlice=NULL;
  AliRunLoader* runLoader = AliRunLoader::Open("galice.root");
  runLoader->LoadgAlice();

  gAlice = runLoader->GetAliRun();

  runLoader->LoadHeader();
  runLoader->LoadKinematics();
  runLoader->LoadRecPoints();
  runLoader->LoadSDigits();
  runLoader->LoadHits();

  AliLoader *dl = runLoader->GetDetectorLoader("ITS");

  AliGeomManager::LoadGeometry("geometry.root");
  TObjArray algITS;
  AliGeomManager::LoadAlignObjsFromCDBSingleDet("ITS",algITS);
  AliGeomManager::ApplyAlignObjsToGeom(algITS);
  //
  AliITSUGeomTGeo* gm = new AliITSUGeomTGeo(kTRUE);
  AliITSMFTClusterPix::SetGeom(gm);
  //
  AliITSURecoDet *its = new AliITSURecoDet(gm, "ITSinterface");
  its->CreateClusterArrays();
  //
  Double_t xg1,yg1,zg1=0.,xg0,yg0,zg0=0.,tg0;
  Double_t xExit,yExit,zExit,xEnt,yEnt,zEnt,tof1;

  //
  TTree *cluTree = 0x0;
  TTree *hitTree = 0x0;
  TClonesArray *hitList=new TClonesArray("AliITSMFTHit");
  //
  Float_t xyzClGloF[3];
  Double_t xyzClGlo[3],xyzClTr[3];
  Int_t labels[3];
  int nLab = 0;
  int nlr=its->GetNLayersActive();
  int ntotev = (Int_t)runLoader->GetNumberOfEvents();

  printf("N Events : %i \n",ntotev);
  if (nev>0) ntotev = TMath::Min(nev,ntotev);
  //
  
  // output tree
  TFile* flOut = TFile::Open("clInfo.root","recreate");
  TTree* trOut = new TTree("clitsu","clitsu");
  clSumm cSum;
  trOut->Branch("evID", &cSum.evID ,"evID/I");
  trOut->Branch("volID",&cSum.volID,"volID/I");
  trOut->Branch("lrID", &cSum.lrID ,"lrID/I");  
  trOut->Branch("clID", &cSum.clID ,"clID/I");  
  trOut->Branch("nPix", &cSum.nPix ,"nPix/I");
  trOut->Branch("nX"  , &cSum.nX   ,"nX/I");
  trOut->Branch("nZ"  , &cSum.nZ   ,"nZ/I");
  trOut->Branch("q"   , &cSum.q    ,"q/I");
  trOut->Branch("pt"  , &cSum.pt   ,"pt/F");  
  trOut->Branch("eta"  ,&cSum.eta  ,"eta/F");  
  trOut->Branch("phi"  , &cSum.phi  ,"phi/F");  
  trOut->Branch("xyz",   cSum.xyz,  "xyz[3]/F");  
  trOut->Branch("dX"  , &cSum.dX   ,"dX/F");
  trOut->Branch("dY"  , &cSum.dY   ,"dY/F");
  trOut->Branch("dZ"  , &cSum.dZ   ,"dZ/F");  
  trOut->Branch("split",&cSum.split,"split/O");
  trOut->Branch("prim", &cSum.prim, "prim/O");
  trOut->Branch("pdg",  &cSum.pdg,  "pdg/I");
  trOut->Branch("ntr",  &cSum.ntr,  "ntr/I");
  trOut->Branch("alpha", &cSum.alpha, "alpha/F");
  trOut->Branch("beta", &cSum.beta, "beta/F");
  trOut->Branch("nRowPatt", &cSum.nRowPatt, "nRowPatt/I");
  trOut->Branch("nColPatt", &cSum.nColPatt, "nColPatt/I");

  TopDatabase DB;
  
  for (Int_t iEvent = 0; iEvent < ntotev; iEvent++) {
    printf("\n Event %i \n",iEvent);
    runLoader->GetEvent(iEvent);
    AliStack *stack = runLoader->Stack();
    cluTree=dl->TreeR();
    hitTree=dl->TreeH();
    hitTree->SetBranchAddress("ITS",&hitList);
    // 
    // read clusters
    for (int ilr=nlr;ilr--;) {
      TBranch* br = cluTree->GetBranch(Form("ITSRecPoints%d",ilr));
      if (!br) {printf("Did not find cluster branch for lr %d\n",ilr); exit(1);}
      br->SetAddress(its->GetLayerActive(ilr)->GetClustersAddress());
    }
    cluTree->GetEntry(0);
    its->ProcessClusters();
    //
    // read hits
    for(Int_t iEnt=0;iEnt<hitTree->GetEntries();iEnt++){//entries loop of the hits
      hitTree->GetEntry(iEnt);
      int nh = hitList->GetEntries();
      for(Int_t iHit=0; iHit<nh;iHit++){
        AliITSMFTHit *pHit = (AliITSMFTHit*)hitList->At(iHit);
        int mcID = pHit->GetTrack();
	//printf("MCid: %d %d %d Ch %d\n",iEnt,iHit, mcID, pHit->GetChip());
        TClonesArray* harr = arrMCTracks.GetEntriesFast()>mcID ? (TClonesArray*)arrMCTracks.At(mcID) : 0;
        if (!harr) {
          harr = new TClonesArray("AliITSMFTHit"); // 1st encounter of the MC track
          arrMCTracks.AddAtAndExpand(harr,mcID);
        }
        //
        new ( (*harr)[harr->GetEntriesFast()] ) AliITSMFTHit(*pHit);
      }
    }
    //    return;
    //
    // compare clusters and hits
    //
    printf(" tree entries: %lld\n",cluTree->GetEntries());
    //
    for (int ilr=0;ilr<nlr;ilr++) {
      AliITSURecoLayer* lr = its->GetLayerActive(ilr);
      TClonesArray* clr = lr->GetClusters();
      int nClu = clr->GetEntries();
      //printf("Layer %d : %d clusters\n",ilr,nClu);
      //
      for (int icl=0;icl<nClu;icl++) {
        AliITSMFTClusterPix *cl = (AliITSMFTClusterPix*)clr->At(icl);
        int modID = cl->GetVolumeId();

        //------------ check if this is a split cluster
        int sInL = modID - gm->GetFirstChipIndex(ilr);
        if (!cl->TestBit(kSplCheck)) {
          cl->SetBit(kSplCheck);
          // check if there is no other cluster with same label on this module
          AliITSURecoSens* sens = lr->GetSensor(sInL);
          int nclSn = sens->GetNClusters();
          int offs = sens->GetFirstClusterId();
          //  printf("To check for %d (mod:%d) N=%d from %d\n",icl,modID,nclSn,offs);
          for (int ics=0;ics<nclSn;ics++) {
            AliITSMFTClusterPix* clusT = (AliITSMFTClusterPix*)lr->GetCluster(offs+ics); // access to clusters
            if (clusT==cl) continue;
            for (int ilb0=0;ilb0<3;ilb0++) {
              int lb0 = cl->GetLabel(ilb0); if (lb0<=-1) break;
              for (int ilb1=0;ilb1<3;ilb1++) {
                int lb1 = clusT->GetLabel(ilb1); if (lb1<=-1) break;
                if (lb1==lb0) {
                  cl->SetBit(kSplit);
                  clusT->SetBit(kSplit);
                  /*
                  printf("Discard clusters of module %d:\n",modID);
                  cl->Print();
                  clusT->Print();
                  */
                  break;
                }
              }
            }
          }
        }
        //------------
        const AliITSMFTSegmentationPix* segm = gm->GetSegmentation(ilr);
        //
        cl->GetGlobalXYZ(xyzClGloF);
        int clsize = cl->GetNPix();
        for (int i=3;i--;) xyzClGlo[i] = xyzClGloF[i];
        const TGeoHMatrix* mat = gm->GetMatrixSens(modID);
        if (!mat) {printf("failed to get matrix for module %d\n",cl->GetVolumeId());}
        mat->MasterToLocal(xyzClGlo,xyzClTr);
        //
        int col,row;
        segm->LocalToDet(xyzClTr[0],xyzClTr[2],row,col); // effective col/row
        nLab = 0;
        for (int il=0;il<3;il++) {
          if (cl->GetLabel(il)>=0) labels[nLab++] = cl->GetLabel(il);
          else break;
        }
        // find hit info
        for (int il=0;il<nLab;il++) {
          TClonesArray* htArr = (TClonesArray*)arrMCTracks.At(labels[il]);
	  //printf("check %d/%d LB %d  %p\n",il,nLab,labels[il],htArr);
	  if (!htArr) {printf("did not find MChits for label %d ",labels[il]); cl->Print(); continue;}
          //
          int nh = htArr->GetEntriesFast();
          AliITSMFTHit *pHit=0;
          for (int ih=nh;ih--;) {
            AliITSMFTHit* tHit = (AliITSMFTHit*)htArr->At(ih);
            if (tHit->GetChip()!=modID) continue;
            pHit = tHit;
            break;
          }
          if (!pHit) {
            printf("did not find MChit for label %d on module %d ",il,modID); 
            cl->Print(); 
            htArr->Print();
            continue;
          }
          //
          pHit->GetPositionG(xg1,yg1,zg1);
          pHit->GetPositionG0(xg0,yg0,zg0,tg0);
          //
          double txyzH[3],gxyzH[3] = { (xg1+xg0)/2, (yg1+yg0)/2, (zg1+zg0)/2 };
          mat->MasterToLocal(gxyzH,txyzH);

          double rcl = TMath::Sqrt(xyzClTr[0]*xyzClTr[0]+xyzClTr[1]*xyzClTr[1]);
          double rht = TMath::Sqrt(txyzH[0]*txyzH[0]+txyzH[1]*txyzH[1]);
          //
          //Angles determination

          pHit->GetPositionL(xExit,yExit,zExit,gm);
          pHit->GetPositionL0(xEnt,yEnt,zEnt,tof1,gm);

          Double_t dirHit[3]={(xExit-xEnt),(yExit-yEnt),(zExit-zEnt)};

          /*double PG[3] = {(double)pHit->GetPXG(), (double)pHit->GetPYG(), (double)pHit->GetPZG()}; //Momentum at hit-point in Global Frame
          double PL[3];
          if (TMath::Abs(PG[0])<10e-7 && TMath::Abs(PG[1])<10e-7) {
            pHit->Dump();
            int lb = pHit->GetTrack();
            stack->Particle(lb)->Print();
            continue;
          }
          mat->MasterToLocalVect(PG,PL); //Momentum in local Frame
          //printf(">> %e %e   %e %e   %e %e\n",PG[0],PL[0],PG[1],PL[1],PG[2],PL[2]);*/

          Double_t alpha1 = TMath::ACos(TMath::Abs(dirHit[1])/TMath::Sqrt(dirHit[0]*dirHit[0]+dirHit[1]*dirHit[1]+dirHit[2]*dirHit[2])); //Polar Angle
          Float_t alpha2 = (Float_t) alpha1; //convert to float
          cSum.alpha = alpha2;

          Double_t beta1;
          beta1 = TMath::ATan2(dirHit[0],dirHit[2]); //Azimuthal angle, values from -Pi to Pi
          Float_t beta2 = (Float_t) beta1;
          cSum.beta = beta2;

	  if(ilr==0){
	    hL0A->Fill(alpha2);
	    hL0B->Fill(beta2);
	  }
	  
	  if(ilr==1){
	    hL1A->Fill(alpha2);
	    hL1B->Fill(beta2);
	  }

	  if(ilr==2){
	    hL2A->Fill(alpha2);
	    hL2B->Fill(beta2);
	  }

	  if(ilr==3){
	    hL3A->Fill(alpha2);
	    hL3B->Fill(beta2);
	  }

	  if(ilr==4){
	    hL4A->Fill(alpha2);
	    hL4B->Fill(beta2);
	  }

	  if(ilr==5){
	    hL5A->Fill(alpha2);
	    hL5B->Fill(beta2);
	  }

	  if(ilr==6){
	    hL6A->Fill(alpha2);
	    hL6B->Fill(beta2);
	  }
          
          GetHistoClSize(clsize,kDR,&histoArr)->Fill((rht-rcl)*1e4);
          if (cl->TestBit(kSplit)) {
            if (col%2) GetHistoClSize(clsize,kDTXoddSPL,&histoArr)->Fill((txyzH[0]-xyzClTr[0])*1e4);
            else       GetHistoClSize(clsize,kDTXevenSPL,&histoArr)->Fill((txyzH[0]-xyzClTr[0])*1e4);
            GetHistoClSize(clsize,kDTZSPL,&histoArr)->Fill((txyzH[2]-xyzClTr[2])*1e4);
            GetHistoClSize(0,kNPixSPL,&histoArr)->Fill(clsize);
          }
          if (col%2) GetHistoClSize(clsize,kDTXodd,&histoArr)->Fill((txyzH[0]-xyzClTr[0])*1e4);
          else       GetHistoClSize(clsize,kDTXeven,&histoArr)->Fill((txyzH[0]-xyzClTr[0])*1e4);
          GetHistoClSize(clsize,kDTZ,&histoArr)->Fill((txyzH[2]-xyzClTr[2])*1e4);
          GetHistoClSize(0,kNPixAll,&histoArr)->Fill(clsize);
          //
          cSum.evID = iEvent;
          cSum.volID = cl->GetVolumeId();
          cSum.lrID = ilr;
          cSum.clID = icl;
          cSum.nPix = cl->GetNPix();
          cSum.nX   = cl->GetNx();
          cSum.nZ   = cl->GetNz();
          cSum.q    = cl->GetQ();
          cSum.split = cl->TestBit(kSplit);
          cSum.dX = (txyzH[0]-xyzClTr[0])*1e4;
          cSum.dY = (txyzH[1]-xyzClTr[1])*1e4;
          cSum.dZ = (txyzH[2]-xyzClTr[2])*1e4;
          cSum.nRowPatt = cl-> GetPatternRowSpan();
          cSum.nColPatt = cl-> GetPatternColSpan();
	  DB.AccountTopology(*cl, cSum.dX, cSum.dZ, cSum.alpha, cSum.beta);
          
          GetHistoClSize(clsize,kDR,&histoArr)->Fill((rht-rcl)*1e4);
          if (cl->TestBit(kSplit)) {
            if (col%2) GetHistoClSize(clsize,kDTXoddSPL,&histoArr)->Fill((txyzH[0]-xyzClTr[0])*1e4);
            else       GetHistoClSize(clsize,kDTXevenSPL,&histoArr)->Fill((txyzH[0]-xyzClTr[0])*1e4);
            GetHistoClSize(clsize,kDTZSPL,&histoArr)->Fill((txyzH[2]-xyzClTr[2])*1e4);
            GetHistoClSize(0,kNPixSPL,&histoArr)->Fill(clsize);
          }
          if (col%2) GetHistoClSize(clsize,kDTXodd,&histoArr)->Fill((txyzH[0]-xyzClTr[0])*1e4);
          else       GetHistoClSize(clsize,kDTXeven,&histoArr)->Fill((txyzH[0]-xyzClTr[0])*1e4);
          GetHistoClSize(clsize,kDTZ,&histoArr)->Fill((txyzH[2]-xyzClTr[2])*1e4);
          GetHistoClSize(0,kNPixAll,&histoArr)->Fill(clsize);
          //
          cSum.evID = iEvent;
          cSum.volID = cl->GetVolumeId();
          cSum.lrID = ilr;
          cSum.clID = icl;
          cSum.nPix = cl->GetNPix();
          cSum.nX   = cl->GetNx();
          cSum.nZ   = cl->GetNz();
          cSum.q    = cl->GetQ();
          cSum.split = cl->TestBit(kSplit);
          cSum.dX = (txyzH[0]-xyzClTr[0])*1e4;
          cSum.dY = (txyzH[1]-xyzClTr[1])*1e4;
          cSum.dZ = (txyzH[2]-xyzClTr[2])*1e4;
          cSum.nRowPatt = cl-> GetPatternRowSpan();
          cSum.nColPatt = cl-> GetPatternColSpan();
 
                    
          int label = cl->GetLabel(0);
          TParticle* part = 0;
          if (label>=0 && (part=stack->Particle(label)) ) {
            cSum.pdg = part->GetPdgCode();
            cSum.eta = part->Eta();
            cSum.pt  = part->Pt();
            cSum.phi = part->Phi();
            cSum.prim = stack->IsPhysicalPrimary(label);
          } 
          cSum.ntr = 0;
          for (int ilb=0;ilb<3;ilb++) if (cl->GetLabel(ilb)>=0) cSum.ntr++;
          for (int i=0;i<3;i++) cSum.xyz[i] = xyzClGloF[i];
          //
          trOut->Fill();
          /*
          if (clsize==5) {
            printf("\nL%d(%c) Mod%d, Cl:%d | %+5.1f %+5.1f (%d/%d)|H:%e %e %e | C:%e %e %e\n",ilr,cl->TestBit(kSplit) ? 'S':'N',
             modID,icl,(txyzH[0]-xyzClTr[0])*1e4,(txyzH[2]-xyzClTr[2])*1e4, row,col,
             gxyzH[0],gxyzH[1],gxyzH[2],xyzClGlo[0],xyzClGlo[1],xyzClGlo[2]);
            cl->Print();
            pHit->Print();
            //
            double a0,b0,c0,a1,b1,c1,e0;
            pHit->GetPositionL0(a0,b0,c0,e0);
            pHit->GetPositionL(a1,b1,c1);
            float cloc[3];
            cl->GetLocalXYZ(cloc);
            printf("LocH: %e %e %e | %e %e %e\n",a0,b0,c0,a1,b1,c1);
            printf("LocC: %e %e %e | %e %e %e\n",cloc[0],cloc[1],cloc[2],xyzClTr[0],xyzClTr[1],xyzClTr[2]);
          }
          */
          //
        }
      }
    }
    
    //    layerClus.Clear();
    //
    arrMCTracks.Delete();
  }//event loop
  //
  DB.EndAndSort();
  DB.SetThresholdCumulative(0.95);
  cout << "Over threshold: : "<< DB.GetOverThr()<<endl;
  DB.Grouping(10,10);
  DB.PrintDB("Database1.txt"); 
  flOut->cd();
  trOut->Write();
  delete trOut;
  flOut->Close();
  flOut->Delete();
  DrawReport("clinfo.ps",&histoArr);
  TFile* flDB = TFile::Open("TopologyDatabase.root", "recreate");
  flDB->WriteObject(&DB,"DB","kSingleKey");
  flDB->Close();
  delete flDB;

  TCanvas* cnv123 = new TCanvas("cnv123","cnv123");
  cnv123->Divide(1,2);
  cnv123->Print("anglesdistr.pdf[");
  cnv123->cd(1);
  hL0A->Draw();
  cnv123->cd(2);
  hL0B->Draw();
  cnv123->Print("anglesdistr.pdf");
  cnv123->cd(1);
  hL1A->Draw();
  cnv123->cd(2);
  hL1B->Draw();
  cnv123->Print("anglesdistr.pdf");
  cnv123->cd(1);
  hL2A->Draw();
  cnv123->cd(2);
  hL2B->Draw();
  cnv123->Print("anglesdistr.pdf");
  cnv123->cd(1);
  hL3A->Draw();
  cnv123->cd(2);
  hL3B->Draw();
  cnv123->Print("anglesdistr.pdf");
  cnv123->cd(1);
  hL4A->Draw();
  cnv123->cd(2);
  hL4B->Draw();
  cnv123->Print("anglesdistr.pdf");
  cnv123->cd(1);
  hL5A->Draw();
  cnv123->cd(2);
  hL5B->Draw();
  cnv123->Print("anglesdistr.pdf");
  cnv123->cd(1);
  hL6A->Draw();
  cnv123->cd(2);
  hL6B->Draw();
  cnv123->Print("anglesdistr.pdf");
  cnv123->Print("anglesdistr.pdf]");
  //
}
Exemplo n.º 7
0
void MUONTrigger(const char* filename)
{
    // Creating Run Loader and openning file containing Digits 
    AliRunLoader * RunLoader = AliRunLoader::Open(filename,"MUONLoader","UPDATE");
    if (RunLoader ==0x0) {
        printf(">>> Error : Error Opening %s file \n",filename);
        return;
    }
    // Loading AliRun master
    if (RunLoader->GetAliRun() == 0x0) RunLoader->LoadgAlice();
    gAlice = RunLoader->GetAliRun();
    
    // Loading MUON subsystem
    AliLoader* MUONLoader = RunLoader->GetDetectorLoader("MUON");
    MUONLoader->LoadDigits("READ");
    MUONLoader->LoadRecPoints("UPDATE"); // absolutely essential !!!    
    
    // Creating MUONTriggerDecision
    AliCDBManager* cdbManager = AliCDBManager::Instance();
    cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
    
    Int_t runnumber = 0;
    cdbManager->SetRun(runnumber);
    AliMpCDB::LoadDDLStore();
    
    AliMUONCalibrationData *CalibrationData = new AliMUONCalibrationData(runnumber);
    AliMUONTriggerElectronics *TriggerProcessor	= new AliMUONTriggerElectronics(CalibrationData);
    
    Int_t nevents = RunLoader->GetNumberOfEvents();
    AliMUONVDigitStore* digitStore=0x0;
    AliMUONVTriggerStore* triggerStore=0x0;
    
    for(Int_t ievent = 0; ievent < nevents; ievent++) {
	printf(">>> Event %i out of %i \n",ievent,nevents);
	RunLoader->GetEvent(ievent);
	
	MUONLoader->LoadRecPoints("update");
	MUONLoader->CleanRecPoints();
	MUONLoader->MakeRecPointsContainer();
	TTree* clustersTree = MUONLoader->TreeR();
	TFile* cfile = clustersTree->GetCurrentFile();
	if ( !cfile ) 
	{
	    cout << " could not find Cluster file " << endl;
	    return;
	}
	
	MUONLoader->LoadDigits("read");
	TTree* digitsTree = MUONLoader->TreeD();
	TFile* dfile = digitsTree->GetCurrentFile();
	if ( !dfile ) 
	{
	    cout << " could not find Digit file " << endl;
	    return;
	}
	
// here start reconstruction	
	if (!digitStore) digitStore = AliMUONVDigitStore::Create(*digitsTree);	
	if (!triggerStore) triggerStore = AliMUONVTriggerStore::Create(*digitsTree);
	// insure we start with empty stores
	if ( digitStore ) 
	{
	    digitStore->Clear(); 
	    Bool_t alone = ( triggerStore ? kFALSE : kTRUE );
	    Bool_t ok = digitStore->Connect(*digitsTree,alone);
	    if (!ok)
	    {
		cerr << "Could not connect digitStore to digitsTree \n";
		return;
	    }
	} else {
	    cerr << "digitStore does not exist " << "\n";
	    return;
	}
	
	digitsTree->GetEvent(0);
	
// process trigger response
	TriggerProcessor->Digits2Trigger(*digitStore,*triggerStore);
	
	//triggerStore->Print();
	
	Bool_t ok(kFALSE);
	if ( triggerStore ) {
	    ok = triggerStore->Connect(*clustersTree,kTRUE);
	    if (!ok)
	    {
		cerr << "Could not create triggerStore branches in TreeR " << "\n";
		return;
	    }
	} else {
	    cerr << "triggerStore does not exist " << "\n";
	    return;
	}

// fill TreeR
	clustersTree->Fill();
	MUONLoader->UnloadDigits();
	MUONLoader->WriteRecPoints("OVERWRITE");
	MUONLoader->UnloadRecPoints();

    }  // loop on events

}