Example #1
0
// analisi
Bool_t CheckSingle(const char* esdFileName,Bool_t kGRID){
  //inizializzo a zero ncluster (di tree T)
  //for (int ifc=0;ifc<10000;ifc++) ncluster[ifc]=0;
  
  // check the content of the ESD
  
  AliPIDResponse *pidr = new AliPIDResponse();
  
  // open the ESD file
  TFile* esdFile = TFile::Open(esdFileName);
  if (!esdFile || !esdFile->IsOpen()){
    Error("CheckESD", "opening ESD file %s failed", esdFileName);
    return kFALSE;
  }
  
  TString mctrkref(esdFileName);
  mctrkref.ReplaceAll("AliESDs.root","TrackRefs.root");
  TString fgal(esdFileName);
  fgal.ReplaceAll("AliESDs.root","galice.root");
  
  if(kGRID){
    fgal.Insert(0,"alien://");
    mctrkref.Insert(0,"alien://");
  }
  
  TTree *trkref;
  
  printf("ESD = %s\n",esdFileName);
  
  TFile *ftrkref; 
  if(isMC) ftrkref = TFile::Open(mctrkref.Data());
  
  AliHeader *h = new AliHeader();
  
  TFile *fgalice;
  if(isMC) fgalice = TFile::Open(fgal.Data());
  TTree *tgalice;
  if(isMC){
    tgalice = (TTree *) fgalice->Get("TE");
    tgalice->SetBranchAddress("Header",&h);
  }
  
  AliRunLoader* runLoader = NULL;
  
  AliRun *gAlice;
  if(isMC) runLoader = AliRunLoader::Open(fgal.Data());
  if(runLoader){
    runLoader->LoadgAlice();
    gAlice = runLoader->GetAliRun();
    if (!gAlice) {
      Error("CheckESD", "no galice object found");
      return kFALSE;
    }
    runLoader->LoadKinematics();
    runLoader->LoadHeader();
  }
  
  AliESDEvent * esd = new AliESDEvent;
  //  printf("esd object = %x\n",esd);
  TTree* tree = (TTree*) esdFile->Get("esdTree");
  if (!tree){
    Error("CheckESD", "no ESD tree found");
    return kFALSE;
  }
  esd->ReadFromTree(tree); // crea link tra esd e tree
  
  TClonesArray* tofcl;  // array dinamico
  TClonesArray* tofhit;
  TClonesArray* tofmatch;
  
  Int_t nev = tree->GetEntries(); //ogni entries evento
  Float_t mag;
  
  printf("nev = %i\n",nev);
  
  //azzero il contatore delle tracce del TTree T
  //ntracks=0;
  AliStack* stack=NULL;
  
  Int_t trkassociation[1000000];
  
  for(Int_t ie=0;ie < nev;ie++){
    if(runLoader){
      runLoader->GetEvent(ie);
      
      // select simulated primary particles, V0s and cascades
      stack = runLoader->Stack();
    }
    
    if(isMC) trkref = (TTree *) ftrkref->Get(Form("Event%i/TreeTR",ie));
    tree->GetEvent(ie);
    if(isMC) tgalice->GetEvent(ie);
    
    if(isMC) interactiontime = h->GenEventHeader()->InteractionTime()*1E+12;
    
    mag = esd->GetMagneticField();
    
    AliTOFHeader *tofh = esd->GetTOFHeader();
    ntofcl = tofh->GetNumberOfTOFclusters();
    
    esd->ConnectTracks(); // Deve essere sempre chiamato dopo aver letto l'evento (non troverebbe l'ESDevent). Scrivo in tutte le tracce l origine dell evento così poi da arrivare ovunque(tipo al cluster e al tempo quindi).
    
    
    //Riempio variabile del tree "T"
    //nevento=ie;
    
    if(! esd->GetVertex()){
      esd->ResetStdContent();
      continue;// una volta fatto il connect manda un flag ; siccome qua c'era un continue(non si arriva in fondo al ciclo) bisogna resettarlo altrimenti lo trova già attivo.
    }
    
    tofcl = esd->GetESDTOFClusters(); // AliESDTOFCluster *cltof = tofcl->At(i);
    if(tofcl->GetEntries() == 0){
      esd->ResetStdContent();
      continue;
    }
    tofhit = esd->GetESDTOFHits(); // AliESDTOFHit *hittof = tofhit->At(i);
    tofmatch = esd->GetESDTOFMatches(); // AliESDTOFHit *mathctof = tofmatch->At(i);
    
    // loop over tracks
    
    pidr->SetTOFResponse(esd,AliPIDResponse::kTOF_T0); //per recuperare lo start time ("esd", "tipo start time"), tipo cioè o il TOF stesso o il T0 o il best, ovvero la combinazione dei 2
    
    Int_t ntrk = esd->GetNumberOfTracks();
    
    //printf("%i) TPC tracks = %i -- TOF cluster = %i - TOF hit = %i -- matchable info = %i\n",ie,ntrk,tofcl->GetEntries(),tofhit->GetEntries(),tofmatch->GetEntries());
    
    Double_t time[AliPID::kSPECIESC];
    
    
    if(isMC && stack){// create association trackref
      printf("nMC track = %i\n",stack->GetNtrack());
      for(Int_t ist=0;ist < stack->GetNtrack();ist++){
	trkassociation[ist]=-1;
      }
      for(Int_t iref=0;iref < trkref->GetEntries();iref++){
	trkref->GetEvent(iref);
	Int_t trkreference = trkref->GetLeaf("TrackReferences.fTrack")->GetValue();
	if(trkreference > -1 && trkreference < 1000000){
	  trkassociation[trkreference] = iref;
	}
      }
    }
    
    for (Int_t iTrack = 0; iTrack < ntrk; iTrack++){
      AliESDtrack* track = esd->GetTrack(iTrack);
      
      // select tracks of selected particles
      if ((track->GetStatus() & AliESDtrack::kITSrefit) == 0) continue;//almeno un hit nell ITS
      if (track->GetConstrainedChi2() > 4) continue; //se brutto X^2
      if ((track->GetStatus() & AliESDtrack::kTOFout) == 0) continue; //se traccia matchata con tof
      if(track->GetNumberOfTPCClusters() < 70) continue;
      Float_t p =track->P();
      
      itrig = 0;
      timetrig = 0;
      
      if(p > 0.9 && p < 1.1){
 	track->GetIntegratedTimes(time);
	
	itrig = iTrack;
	timetrig = track->GetTOFsignal() - time[2];
	iTrack = ntrk;
      }
    }
    
    printf("real loop, ntrk = %i\n",ntrk);
  
    for (Int_t iTrack = 0; iTrack < ntrk; iTrack++){
      AliESDtrack* track = esd->GetTrack(iTrack);
      
      // select tracks of selected particles
      if ((track->GetStatus() & AliESDtrack::kITSrefit) == 0) continue;//almeno un hit nell ITS
      if (track->GetConstrainedChi2() > 4) continue; //se brutto X^2
      
      //if ((track->GetStatus() & AliESDtrack::kTOFout) == 0) continue; //se traccia matchata con tof
      if(track->GetNumberOfTPCClusters() < 70) continue;

      TOFout = (track->GetStatus() & AliESDtrack::kTOFout) > 0;

      track->GetIntegratedTimes(time);
      
      Float_t dx = track->GetTOFsignalDx(); //leggo i residui tra traccia e canale tof acceso
      Float_t dz = track->GetTOFsignalDz();
      
      mism = 0;
      
      dedx = track->GetTPCsignal();
      
      Int_t label = TMath::Abs(track->GetLabel());
      if(stack){
	TParticle *part=stack->Particle(label);
	pdg = part->GetPdgCode();
      }
      
      Int_t TOFlabel[3];
      track->GetTOFLabel(TOFlabel);
      
      //  printf("%i %i %i %i\n",label,TOFlabel[0],TOFlabel[1],TOFlabel[2]);
      
      ChannelTOF[0] = track->GetTOFCalChannel();
      //      printf("geant time = %f\n",gtime);
      //getchar();
      // if(TMath::Abs(dx) > 1.25 || TMath::Abs(dz) > 1.75) continue; // is inside the pad
      
      //riempio il numro di cludter e impulso trasverso per traccia del TTree T
      ncluster=track->GetNTOFclusters();
      impulso_trasv=track->Pt();
      impulso=track->P();
      
      StartTime = pidr->GetTOFResponse().GetStartTime(track->P());
      StartTimeRes = pidr->GetTOFResponse().GetStartTimeRes(track->P());
      
      if(track->Pt() > 0.9 && track->Pt() < 1.5){  //impulso non troppo alto per separazione tra particelle
	Float_t dt = track->GetTOFsignal() - time[2] - pidr->GetTOFResponse().GetStartTime(track->P());//tempo TOF(è lo stesso di Gettime, solo che lo prendo dale tracce)(già calibrato) -ip del PI (posizione 0 e, posizione 1 mu, pos 2 PI, pos 3 K,pos 4 p) -start time
	Float_t dtKa = track->GetTOFsignal() - time[3] - pidr->GetTOFResponse().GetStartTime(track->P());
	Float_t dtPr = track->GetTOFsignal() - time[4] - pidr->GetTOFResponse().GetStartTime(track->P());
	hdt->Fill(dt);
	hdtKa->Fill(dtKa);
	hdtPr->Fill(dtPr);
      }
      
      charge = track->Charge();
      phi = track->Phi();
      eta = track->Eta();

      GetPositionAtTOF(track,mag,coord);
      phiExt = TMath::ATan2(coord[1],coord[0]);
      etaExt =  -TMath::Log(TMath::Tan(0.5*TMath::ATan2(sqrt(coord[0]*coord[0]+coord[1]*coord[1]),coord[2])));

      for (int i=0;i<(track->GetNTOFclusters());i++){
	int idummy=track->GetTOFclusterArray()[i];
        
	AliESDTOFCluster *cl = (AliESDTOFCluster *) tofcl->At(idummy);
        
	tempo[i]=cl->GetTime();
	tot[i]=cl->GetTOT();
        
	ChannelTOF[i]=cl->GetTOFchannel();
		
	if(i==0){
	  GetResolutionAtTOF(track,mag,ChannelTOF[i],res);
	}
	
	for(int im=cl->GetNMatchableTracks();im--;){ //o così o da n-1 a 0 //for(int im=cl->GetNMatchableTracks();im>0;im--) non andava bene perchè non prendeva mai lo 0  
	  
	  //	    if(track->GetNTOFclusters()==2) printf("-- %i) %f %f\n",im,cl->GetLength(im),cl->GetIntegratedTime(2,im));
	  
	  if(cl->GetTrackIndex(im) == track->GetID()){
	    exp_time_el[i] = cl->GetIntegratedTime(0,im); // pi = 2
	    exp_time_mu[i] = cl->GetIntegratedTime(1,im); // pi = 2
	    exp_time_pi[i] = cl->GetIntegratedTime(2,im); // pi = 2
	    exp_time_ka[i] = cl->GetIntegratedTime(3,im); // pi = 2
	    exp_time_pr[i] = cl->GetIntegratedTime(4,im); // pi = 2
	    L[i] = cl->GetLength(im);
	    //		  if(track->GetNTOFclusters()==2)printf("%i) %f %f\n",i,L[i],exp_time_pi[i]);
	    DeltaX[i]=cl->GetDx(im); // mettendolo dentro questo if dovrei prendere i residui di una stessa traccia
	    DeltaZ[i]=cl->GetDz(im);
	  }
	}
      }
         
      //ReMatch();
      
      Int_t jref=0;
      if(isMC){
	if(TOFlabel[0] > -1 && TOFlabel[0] < 1000000){
	  trkref->GetEvent(trkassociation[TOFlabel[0]]);
	  if(TOFlabel[0] == trkref->GetLeaf("TrackReferences.fTrack")->GetValue()){
	    //  printf("trk -> %i (%i)\n",trkref->GetLeaf("TrackReferences.fTrack")->GetValue(),trkref->GetLeaf("TrackReferences.fTrack")->GetValue(jref));	
	    while(jref > -1 && trkref->GetLeaf("TrackReferences.fTrack")->GetValue(jref) != 0){
	      //printf("det = %i\n",trkref->GetLeaf("TrackReferences.fDetectorId")->GetValue(jref));
	      if(trkref->GetLeaf("TrackReferences.fDetectorId")->GetValue(jref) == 4){
		gtime=trkref->GetLeaf("TrackReferences.fTime")->GetValue(jref)*1E+12;
		xgl = trkref->GetLeaf("TrackReferences.fX")->GetValue(jref);
		ygl = trkref->GetLeaf("TrackReferences.fY")->GetValue(jref);
		zgl = trkref->GetLeaf("TrackReferences.fZ")->GetValue(jref);
		MakeTrueRes();
		jref =  100;
	      }
	      jref++;
	    }
	  }
	}
      }
      
      
      if(TMath::Abs(label) != TOFlabel[0] && stack){
	mism=2;
	
	while(TOFlabel[0] != -1 && TOFlabel[0] != label){
	  TOFlabel[0] = stack->Particle(TOFlabel[0])->GetMother(0);
	}
	
	if(label == TOFlabel[0])
	  mism=1;	
	
      }
      
      //AddDelay();
      T->Fill(); //cout<<"riempio il tree  "<<endl; //Riempio tree "T"
    
      
      
      //incremento il contatore delle tracce del TTree T matchate e che superano i tagli
      //ntracks++;
      
    }//end of for(tracks)
      
      
    
    esd->ResetStdContent();
    
    
    
  } //end of for(events)

  if(runLoader){
    runLoader->UnloadHeader();
    runLoader->UnloadKinematics();
    delete runLoader;
  }
  
  esdFile->Close();
  if(isMC) ftrkref->Close();
  if(isMC) fgalice->Close();
}
Example #2
0
  /** 
   * Event processing 
   */
  void UserExec(Option_t*) 
  {
    // Get the input data - MC event
    AliMCEvent*  mcEvent = MCEvent();
    if (!mcEvent) { 
      AliWarning("No MC event found");
      return;
    }
    
    // Get the input data - ESD event
    AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
    if (!esd) { 
      AliWarning("No ESD event found for input event");
      return;
    }

    if (fFirstEvent && esd->GetESDRun()) {
      fInspector.ReadRunDetails(esd);

      AliInfo(Form("Initializing with parameters from the ESD:\n"
		   "         AliESDEvent::GetBeamEnergy()   ->%f\n"
		   "         AliESDEvent::GetBeamType()     ->%s\n"
		   "         AliESDEvent::GetCurrentL3()    ->%f\n"
		   "         AliESDEvent::GetMagneticField()->%f\n"
		   "         AliESDEvent::GetRunNumber()    ->%d\n",
		   esd->GetBeamEnergy(),
		   esd->GetBeamType(),
		   esd->GetCurrentL3(),
		   esd->GetMagneticField(),
		   esd->GetRunNumber()));
      
      fFirstEvent = false;
    }

    // Get the particle stack 
    AliStack* stack = mcEvent->Stack();

    // Some variables 
    UInt_t   triggers; // Trigger bits
    Bool_t   lowFlux;  // Low flux flag
    UShort_t iVz;      // Vertex bin from ESD
    Double_t vZ;       // Z coordinate from ESD
    Double_t cent;     // Centrality 
    UShort_t iVzMc;    // Vertex bin from MC
    Double_t vZMc;     // Z coordinate of IP vertex from MC
    Double_t b;        // Impact parameter
    Int_t    nPart;    // Number of participants 
    Int_t    nBin;     // Number of binary collisions 
    Double_t phiR;     // Reaction plane from MC
    UShort_t nClusters;// Number of clisters 
    // Process the data 
    Int_t retESD = fInspector.Process(esd, triggers, lowFlux, iVz, vZ, cent,
				      nClusters);
    Int_t retMC  = fInspector.ProcessMC(mcEvent, triggers, iVzMc, 
					vZMc, b, nPart, nBin, phiR);

    Bool_t hasESDVtx = retESD == AliFMDEventInspector::kOk;
    Bool_t hasMCVtx  = retMC  == AliFMDEventInspector::kOk;
    if (hasESDVtx) fVertexESD->Fill(vZ);
    if (hasMCVtx)  fVertexMC->Fill(vZMc);

    Bool_t isMcInel = true; // (triggers & AliAODForwardMult::kB);
    Bool_t isMcNSD  = (triggers & AliAODForwardMult::kMCNSD);

    Int_t mESD = 0;
    const AliMultiplicity* spdmult = esd->GetMultiplicity();
    if (!spdmult) {
      AliWarning("No SPD multiplicity");
    }
    else { 
      // Check if we have one or more tracklets 
      // in the range -1 < eta < 1 to set the INEL>0 
      // trigger flag. 
      Int_t n = spdmult->GetNumberOfTracklets();
      for (Int_t j = 0; j < n; j++) 
	if(TMath::Abs(spdmult->GetEta(j)) < 1) mESD++;
    }

    // Reset cache 
    fData->Reset();
    Int_t mMC = 0; // Number of particles in |eta|<1

    // Loop over all tracks 
    Int_t nTracks = mcEvent->GetNumberOfTracks();
    for (Int_t iTr = 0; iTr < nTracks; iTr++) { 
      AliMCParticle* particle = 
	static_cast<AliMCParticle*>(mcEvent->GetTrack(iTr));
    
      // Check the returned particle 
      if (!particle) continue;

      // Check if this charged and a primary 
      Bool_t isCharged = particle->Charge() != 0;
      Bool_t isPrimary = stack->IsPhysicalPrimary(iTr);

      if (!isCharged || !isPrimary) continue;

      
      // Fill (eta,phi) of the particle into histograsm for b
      Double_t eta = particle->Eta();
      Double_t phi = particle->Phi();
      
      fData->Fill(eta, phi);
      if (TMath::Abs(eta) <= 1) mMC++;
    }
    Int_t m = mESD;
    if (fTrackletRequirement == kMC) m = mMC;
    fM->Fill(m);

    bool isMcInelGt0 = isMcInel && (mMC > 0);
    
    bool hasVertex   = true;
    if (fVertexRequirement & kMC)  hasVertex = hasVertex && hasMCVtx;
    if (fVertexRequirement & kESD) hasVertex = hasVertex && hasESDVtx;

    if (isMcInel) {
      fTriggers->Fill(0);
      bool triggered = (triggers & AliAODForwardMult::kInel);
      if (triggered) fTriggers->Fill(1);
      fInel.AddEvent(triggered, hasVertex, m, fData);
    }
    if (isMcInel) { // && nClusters > 0) {
      fTriggers->Fill(2);
      bool triggered = (triggers & AliAODForwardMult::kNClusterGt0);
      if (triggered) fTriggers->Fill(3);
      fNClusterGt0.AddEvent(triggered, hasVertex, m, fData);
    }
    if (isMcInelGt0) {
      fTriggers->Fill(4);
      bool triggered = (triggers & AliAODForwardMult::kInelGt0);
      if (triggered) fTriggers->Fill(5);
      fInelGt0.AddEvent(triggered, hasVertex, m, fData);
    }
    if (isMcNSD) {
      fTriggers->Fill(6);
      bool triggered = (triggers & AliAODForwardMult::kNSD);
      if (triggered) fTriggers->Fill(7);
      fNSD.AddEvent(triggered, hasVertex, m, fData);
    }
    PostData(1, fList);
  }