/* Create full events from channel events and process. */ /*e18018*/ #include #include #include #include #include #include #include "TChain.h" #include "TFile.h" #include "TTree.h" #include "Parameters-ddas.h" #include "Variables-ddas.h" #include "ddaschannel.h" #include "DDASEvent.h" #include "DataSorters.h" #include "Correlator.h" #ifdef HAVE_STD_NAMESPACE using namespace std; #endif /*********************************************************************************************/ void ResetChannelList(vector channellist, vector::iterator channellist_it) { channellist_it = channellist.begin(); for (channellist_it = channellist.begin(); channellist_it < channellist.end(); channellist_it++) { delete *channellist_it; } channellist.clear(); } /******************************************************************************************/ // Analyzer // Get channels present in the event, map channels to detector classes, calibrate, // threshold, correlate and write to output tree. void analyzer(TChain* tree_in, TTree* tree_out) { // Event info and iterator vector channellist; vector::iterator channellist_it; // Variables and results betadecay bdecay; betadecayvariables bdecayv; bdecay.Reset(); bdecayv.Initialize(); // Setup the correlator Correlator corr; // Output for of all the results rootdataout *rootout = new rootdataout(); rootout->Reset(); // Read calibration files // Overwrites initialized parameters! // char DSSDCalFile[100] = "/home/mansi/e17009/60GaBetaDecay/RootAnalysis/cal/DSSDInit.txt"; char OtherCalFile[100] = "/home/mansi/e17009/60GaBetaDecay/RootAnalysis/cal/OtherInit.txt"; char SuNCalFile[100] = "/home/mansi/e17009/60GaBetaDecay/RootAnalysis/cal/SuNInit.txt"; bdecayv.ReadDSSD(DSSDCalFile); bdecayv.ReadOther(OtherCalFile); bdecayv.ReadSuN(SuNCalFile); // ... cout << "---> Correlation window: " << bdecayv.corr.corrwindow << " ms" << endl; cout << "---> Minimplant tdiff: " << bdecayv.corr.minimplant << " ms" << endl; double starttime = 0.; double endtime = 0.; // Make the relevant output stuff in the tree tree_out->Branch("rootout", "rootdataout", &rootout, 32000, 99); // Find the number of events in a file Int_t nevents = tree_in->GetEntries(); cout << "Number events in run segment: " << tree_in->GetEntries() << endl; int fiveper = (int)(nevents * 0.05); int oneper = (int)(nevents * 0.01); int tenthper = (int)(nevents * 0.001); // You really don't want to update this often // Built event raw data DDASEvent *rawhits; //*********************************************** // Loop over the events //forward correlations for (Int_t evt=0; evt=0; evt--) { ResetChannelList(channellist,channellist_it); rootout->Reset(); bdecay.Reset(); bdecayv.hit.Initialize(); // Progress bar -- reverse correlation // if( ((nevents-evt) % oneper) == 0) { // cout << "Events processed " << nevents-evt << " - percent done " << (int)((nevents-evt)/oneper) << "%"< 0) && (evt % fiveper) == 0) { // break; // }// // // Progress bar -- forward direction if(evt > 0 && (evt % (int)(nevents * 0.01)) == 0) { cout << "Events processed " << evt << " - percent done " << (int)(evt/(int)(nevents * 0.01)) << "%"< 0 && (evt % (int)(nevents * 0.01)) == 0) { // break; // } // // Check with only 5% of the file // if(evt > 0 && (evt % (int)(nevents * 0.05)) == 0) { // break; // } // Make the event rawhits = new DDASEvent(); // Built raw event location in input tree // TBranch *addasevent = tree_in->GetBranch("ddasevent"); // addasevent->SetAddress(&rawhits); tree_in->SetBranchAddress("ddasevent",&rawhits); // Get the event tree_in->GetEntry(evt); // Set the vector of channels hit in this event channellist = rawhits->GetData(); // Now that we have the vector of channels, we need to unpack it into // bdecay classes. Iterate over the channellist, extract some basic information, // and send it to the channel mapper. int eventsize = channellist.size(); bdecay.ddasdiagnostics.cmult = eventsize; channellist_it = channellist.begin(); for(int i=0; i<18; i++) { bdecay.ddasdiagnostics.adchit[i] = 0; } double previous_time = 0; //loopong all the channels fires in a given entry !multiple events/channels in a given entry for (channellist_it = channellist.begin(); channellist_it < channellist.end(); channellist_it++) { // cout << "Processing chhit " << channellist_it-channellist.begin() << endl; int crateid = (*channellist_it)->crateid; int slotid = (*channellist_it)->slotid; int channum = (*channellist_it)->chanid; double current_time = (*channellist_it)->time; // in ns /* The time of an event will be taken as the time of the first channel in the event. */ if(channellist_it == channellist.begin()) { starttime = current_time; previous_time = current_time; bdecay.clock.initial = current_time; } if(channellist_it == channellist.end()-1) { endtime = current_time; } // Time difference between events in us bdecay.ddasdiagnostics.tdiffevent = current_time-previous_time; // in ns previous_time = current_time; // Update the current time for each entry bdecay.clock.current = current_time; // Global ADC number counting from 0 int adcnumber = -1; if(crateid == 0) { adcnumber = slotid - 1; // as done in ALR folder } else { adcnumber = slotid + 11; } bdecay.ddasdiagnostics.adchit[adcnumber] += pow(2., (double)(*channellist_it)->chanid); bdecay.adc[adcnumber].channel[channum] = ((*channellist_it)->energy); bdecay.time[adcnumber].timefull[channum] = current_time; bdecay.time[adcnumber].timecfd[channum] = (*channellist_it)->GetCFDTime(); bdecay.ddasdiagnostics.overflow[channum] = (*channellist_it)->GetOverflowCode(); bdecay.ddasdiagnostics.finishcode[channum] = (*channellist_it)->GetFinishCode(); // check for trace and exract if((*channellist_it)->tracelength != 0) { bdecay.adc[adcnumber].chantrace[channum].trace = (*channellist_it)->GetTrace(); } /* Map the channel, calibrate and theshold check. */ MapChannels(crateid, slotid, channum, adcnumber, bdecay, bdecayv); } // End loop over event channel list (unpacking stage) bdecay.ddasdiagnostics.eventlength = (endtime-starttime); // in ns // cout<<"time length = "<ddasdiagnostics = bdecay.ddasdiagnostics; rootout->clock = bdecay.clock; rootout->tac = bdecay.tac; rootout->pin01 = bdecay.pin01; rootout->pin02 = bdecay.pin02; rootout->veto = bdecay.veto; rootout->front = bdecay.front; rootout->back = bdecay.back; rootout->pid = bdecay.pid; rootout->corr = bdecay.corr; rootout->sun = bdecay.sun; // Conditions go here e.g. only events with DSSD tree_out->Fill(); } // End loop over the events } int main(int argc, char **argv) { // If we're happy how this is working, we can make a chain // for a single run number including all the segments and // write out one output, see FilterDDAS.cpp for an example. // The inputs and data processing have to be changed a little bit. // --ASC 2/21/20 //TChain added - MS 15/03/2020 // now it will add up the run sub-segments in one Run // TFile *rootfile_in; TFile *rootfile_out; TFile *tempFile; TTree *tree_in; TTree *tree_out; if(argc != 2) { // cout << "Usage: AnalyzeDDAS " << endl; //cout << ": File path for the dumped file to be analyzed" << endl; //cout << ": File path for the analyzed file to be saved" << endl; // cout << "" cout<< "./AnalyzeDDAS ::: "<Add(pFilein); int havedata = 1; // int havedata = 1; string tempfilein = pFilein; while(havedata) { tempFile = new TFile(tempfilein.c_str()); if(!tempFile->IsZombie()) { //file exists, add it to the chain tempFile->Close(); chain->Add(tempfilein.c_str()); cout << "Added file " << tempfilein << " to the chain " << chain->GetEntries() << endl; //increment the file number filecount++; stringstream pFile; pFile << inPath << "/run" <Close(); // int havedata = 0; // rootfile_in = new TFile(pFilein); // if(!rootfile_in->IsZombie()) { //havedata = 1; // } else { //cout << "Error opening file " << pFilein << endl; //cout << "This file is a zombie. Was it closed properly?" << endl; //havedata = 0; // } // Output file and tree rootfile_out = new TFile(pFileout, "RECREATE"); tree_out = new TTree("data","data"); // tree_in = new TTree("dchan", "dchan"); // tree_in = chain->CloneTree(0); // Go through the data in the file if(havedata==0) { // Get the data cout<GetEntries()<< " : No of Entries" <GetTree(chain->GetEntries); // Call the analyzer // This will map channels and // analyzer(tree_in, tree_out); analyzer(chain,tree_out); // Close the rootfile input // rootfile_in->Close(); //delete rootfile_in; } // End if(havedata) // Write Output rootfile_out->cd(); tree_out->Write(); rootfile_out->Close(); time(&stop); float diff = difftime(stop,start); cout << endl << endl; cout << "Elapsed time = " << diff << " seconds" << endl; return 0; }