Example #1
0
Bool_t KVGANILDataReader::GetNextEvent()
{
   // Read next event in raw data file.
   // Returns false if no event found (end of file).
   // The list of all fired acquisition parameters is filled, and can be retrieved with
   // GetFiredDataParameters().
   // If SetUserTree(TTree*) has been called, the TTree is filled with the values of all
   // parameters in this event.

   Bool_t ok = fGanilData->Next();
   FillFiredParameterList();
   if( fUserTree ){
      if( make_arrays ){
         NbParFired = fFired->GetEntries();
         TIter next(fFired); KVACQParam* par;
         int i=0;
         while( (par = (KVACQParam*)next()) ){
            ParVal[i] = par->GetCoderData();
            ParNum[i] = par->GetNumber();
            i++;
         }
      }
      fUserTree->Fill();
   }
   return ok;
}
Example #2
0
UInt_t KVHarpeeIC::GetFiredSegNumber(Option_t* opt)
{
   // return the number of the fired segment of this Harpee ionisation chamber
   // ( number between 1 to 7 ). Returns 0 if no segment or several segments
   // are fired. A segment is considered as fired if at least one of its 3
   // acquisition parameters (A, B and C) is fired (KVACQParam::Fired( opt )).
   // Set the option opt = "P" to accept only the acquisition parameters with
   // their value above the pedestal.

   TIter next(GetACQParamList());
   KVACQParam* par = NULL;
   UInt_t num = 0;

   while ((par = (KVACQParam*)next())) {
      if (par->Fired(opt)) {
         if (num && (num != par->GetNumber())) return 0;
         num = par->GetNumber();
      }
   }
   return num;
}
Example #3
0
void KVGANILDataReader::SetUserTree(TTree* T, Option_t* opt)
{
   // To fill a TTree with the data in the current file, create a TTree:
   //    TFile* file = new TFile("run1.root","recreate");
   //    TTree* T = new TTree("Run1", "Raw data for Run1");
   // and then call this method: SetUserTree(T)
   // If you read all events of the file, the TTree will be automatically filled
   // with data :
   //    while( runfile->GetNextEvent() ) ;
   //
   // Two different TTree structures are available, depending on the option string:
   //
   //    opt = "arrays": [default]
   //
   // The TTree will have the following structure:
   //
   //    *Br    0 :NbParFired : NbParFired/I    = number of fired parameters in event
   //    *............................................................................*
   //    *Br    1 :ParNum    : ParNum[NbParFired]/i   = array of indices of fired parameters
   //    *............................................................................*
   //    *Br    2 :ParVal    : ParVal[NbParFired]/s   = array of values of fired parameters
   //
   // This structure is the fastest to fill and produces the smallest file sizes.
   // In order to be able to directly access the parameters as if option "leaves" were used
   // (i.e. one branch/leaf for each parameter), we add two aliases for each parameter to
   // the tree:
   //        PARNAME           = value of parameter if present in event
   //        PARNAME_M      = number of times parameter appears in event
   // Assuming that each parameter only appears at most once in each event, i.e. PARNAME_M=0 or 1,
   // then
   //    root[0] T->Draw("PARNAME", "PARNAME_M")
   // will histogram the value of PARNAME for each event in which it is present.
   // (if the selection condition "PARNAME_M" is not used, the histogram will also be filled with a 0
   // for each event in which PARNAME does not appear).
   //          N.B. the PARNAME alias is in fact the sum of the values of PARNAME in each event.
   //          If PARNAME_M>1 in some events, it is not the individual values but their sum which will
   //          be histogrammed in this case.
   //
   // Thus, if the data file has parameters called "PAR_1" and "PAR_2",
   // the following command will work
   //
   //    root[0]  T->Draw("PAR_1:PAR_2", "PAR_1_M&&PAR_2_M", "col")
   //
   // even though no branches "PAR_1" or "PAR_2" exist.
   //
   //
   //
   //    opt = "leaves":
   //
   // The TTree will have a branch/leaf for each parameter. This option is slower and produces
   // larger files.
   //
   // If the option string contains both "arrays" and "leaves", then both structures will be used
   // (in this case there is a high redundancy, as each parameter is stored twice).
   //
   // The full list of parameters is stored in a TObjArray in the list returned by TTree::GetUserInfo().
   // Each parameter is represented by a TNamed object.
   // In order to retrieve the name of the parameter with index 674 (e.g. taken from branch ParNum),
   // do:
   //     TObjArray* parlist = (TObjArray*) T->GetUserInfo()->FindObject("ParameterList");
   //     cout << "Par 674 name = " << (*parlist)[674]->GetName() << endl;
   //
   //
   //  Automatic creation & filling of Scalers TTree
   //
   // give an option string containing "scalers", i.e. "leaves,scalers", or "ARRAYS+SCALERS", etc.
   // a TTree with name 'Scalers' will be created, all scaler buffers will be written in it.


   TString option = opt;
   option.ToUpper();
   make_arrays = option.Contains("ARRAYS");
   make_leaves = option.Contains("LEAVES");
   Bool_t make_scalers = option.Contains("SCALERS");
   if(make_scalers){
   	fGanilData->SetScalerBuffersManagement(GTGanilData::kAutoWriteScaler);
   }

   fUserTree = T;
   if( make_arrays ){
      Int_t maxParFired = GetRawDataParameters()->GetEntries();
      ParVal = new UShort_t[maxParFired];
      ParNum = new UInt_t[maxParFired];
      fUserTree->Branch("NbParFired", &NbParFired, "NbParFired/I");
      fUserTree->Branch("ParNum", ParNum, "ParNum[NbParFired]/i");
      fUserTree->Branch("ParVal", ParVal, "ParVal[NbParFired]/s");
   }
   if( make_leaves ){
      TIter next_rawpar( GetRawDataParameters() );
      KVACQParam* acqpar;
      while( (acqpar = (KVACQParam*)next_rawpar()) ){
         TString leaf;
         leaf.Form("%s/S", acqpar->GetName());
         // for parameters with <=8 bits only use 1 byte for storage
         if(acqpar->GetNbBits()<=8) leaf += "1";
         fUserTree->Branch( acqpar->GetName(), *(acqpar->ConnectData()), leaf.Data() );
      }
   }

#if ROOT_VERSION_CODE > ROOT_VERSION(5,25,4)
#if ROOT_VERSION_CODE < ROOT_VERSION(5,26,1)
   // The TTree::OptimizeBaskets mechanism is disabled, as for ROOT versions < 5.26/00b
   // this lead to a memory leak
   fUserTree->SetAutoFlush(0);
#endif
#endif

   // add list of parameter names in fUserTree->GetUserInfos()
   // and if option="arrays" add aliases for each parameter & its multiplicity
	
	// TObjArray has to be as big as the largest parameter number in the list
	// of raw data parameters. So first loop over parameters to find max param number.
    UInt_t maxpar = 0;
   TIter next(GetRawDataParameters());
   KVACQParam* par;
	while( (par=(KVACQParam*)next()) ) if (par->GetNumber()>maxpar) maxpar=par->GetNumber();
	
   TObjArray *parlist = new TObjArray(maxpar,1);
   parlist->SetName("ParameterList");
	
	next.Reset();
   while( (par = (KVACQParam*)next()) ){
      parlist->AddAt( new TNamed( par->GetName(), Form("index=%d",par->GetNumber()) ), par->GetNumber() );
      if( make_arrays ){
          fUserTree->SetAlias( par->GetName(), Form("Sum$((ParNum==%d)*ParVal)", par->GetNumber() ) );
          fUserTree->SetAlias( Form("%s_M", par->GetName()), Form("Sum$(ParNum==%d)", par->GetNumber() ) );
      }
   }
   fUserTree->GetUserInfo()->Add(parlist);
}
void KVVAMOSDetector::SetCalibrators()
{
   // Setup the calibrators for this detector. Call once name
   // has been set.
   // The calibrators are KVFunctionCal.
   // By default the all the calibration functions are first-degree
   // polynomial function and the range [Xmin,Xmax]=[0,4096].
   // Here the calibrator are not ready (KVFunctionCal::GetStatus()).
   // You have to give the parameters and change the status
   // (see KVFunctionCal::SetParameter(...) and KVFunctionCal::SetStatus(...))


   TIter nextpar(GetACQParamList());

   KVACQParam* par   = NULL;
   Double_t    maxch = 16384.;       // 14 bits

   TString  calibtype("ERROR");

   while ((par = (KVACQParam*)nextpar())) {
      Bool_t isTparam = kFALSE;

      if (par->IsType("E")) {
         calibtype = "channel->MeV";
      } else if (par->IsType("Q")) {
         calibtype = "channel->Volt";
         maxch     = 4096.;           // 12 bits
      } else if (par->GetType()[0] == 'T') {
         isTparam = kTRUE;
         calibtype = "channel->ns";
      } else continue;

      calibtype.Append(" ");
      calibtype.Append(par->GetName());

      TF1* func        = new TF1(calibtype.Data(), "pol1", 0., maxch);
      KVFunctionCal* c = new KVFunctionCal(this, func);
      c->SetType(calibtype.Data());
      c->SetLabel(par->GetLabel());
      c->SetNumber(par->GetNumber());
      c->SetUniqueID(par->GetUniqueID());
      c->SetACQParam(par);
      c->SetStatus(kFALSE);
      if (!AddCalibrator(c)) delete c;
      else if (isTparam) {
         if (!fTlist) fTlist = new TList;
         fTlist->Add(par);
         if (!fT0list) fT0list = new TList;
         fT0list->Add(new KVNamedParameter(par->GetName(), 0.));
      }
   }

   // Define and set to zero the T0 values for time of flight measurment
   // from this detector. The time of flight acq parameters are associated
   // to gVamos
   if (gVamos) {
      TIter next_vacq(gVamos->GetVACQParams());
      while ((par = (KVACQParam*)next_vacq())) {
         if ((par->GetType()[0] == 'T') && IsStartForT(par->GetName() + 1)) {
            if (!fTlist) fTlist = new TList;
            fTlist->Add(par);
            if (!fT0list) fT0list = new TList;
            fT0list->Add(new KVNamedParameter(par->GetName(), 0.));
         }
      }
   }

}