Exemplo n.º 1
0
Arquivo: main.c Projeto: netl/toaster
int main(void)
{
    //set outputs
    DDRB=0xff;	//all out for now
    PORTB=0b000;	//all output low

    //make sure heater is OFF and the slot is not held down
    heater(0);

    //set inputs
    DDRA=0x00;	//all in
    PORTA=0b011;	//no pull-up for the trimmer

    //setup interupt for counting time
    TCCR1A=(1<<WGM12); //clear counter on compare match
    TCCR1B=(1<<CS11)|(1<CS10); //1MHZ/64=15.625kHz
    OCR1A=15625; //compare match at 1Hz
    TIMSK1=(1<<OCIE1A); //interupt on compare match a

    //setup adc for trimmer
    ADMUX=(1<<MUX1); //set PA2 for adc
    ADCSRB=(1<<ADLAR);	//set for reading of highest bits
    ADCSRA=(1<<ADEN)|(1<<ADSC)|(1<<ADATE);	//start free run mode

    //setup SPI slave
    DDRA|=(1<<5);
    USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USIOIE);
    USISR = (1<<USICNT0);
    sei();//enable interrupt

    //end of setup
    while(1) //be stuck forever.
    {
        if(!slot())     //hold the toast down
        {
            time=trimmer();	//set timer according to knob
            heater(1);
            debug(1);
            hold(1);
            while(button());        //wait for user input
            heater(0);
            hold(0);
            debug(0);
            while(!button());       //wait untill button is released
        }
    }
}
Exemplo n.º 2
0
void GroomingTreeProducer::ProduceTree()
{       
	
	TFile OutputFile (outFileName.c_str(), "RECREATE");
	
	Float_t mass_PFjet, mass_Filtered_PFjet, mass_Pruned_PFjet, mass_Pruned_PFjet_subtracted, mass_Trimmed_PFjet, pt_PFjet, mass_GENjet, mass_Filtered_GENjet, mass_Pruned_GENjet, mass_Trimmed_GENjet, pt_GENjet, mass_PFjet_subtracted, mass_soft_drop;
	Int_t nPU;
	
	
	TTree *PF_tree = new TTree("PF", "PF");
	TTree *GEN_tree = new TTree("GEN", "GEN");
	
	PF_tree -> Branch("mass_PFjet",&mass_PFjet,"mass_PFjet/F");
	PF_tree -> Branch("mass_PFjet_subtracted",&mass_PFjet_subtracted,"mass_PFjet_subtracted/F");
	PF_tree -> Branch("pt_PFjet",&pt_PFjet,"pt_PFjet/F");
	PF_tree -> Branch("mass_Pruned_PFjet",&mass_Pruned_PFjet,"mass_Pruned_PFjet/F");
	PF_tree -> Branch("mass_Pruned_PFjet_subtracted",&mass_Pruned_PFjet_subtracted,"mass_Pruned_PFjet_subtracted/F");
	PF_tree -> Branch("mass_Trimmed_PFjet",&mass_Trimmed_PFjet,"mass_Trimmed_PFjet/F");
	PF_tree -> Branch("mass_Filtered_PFjet",&mass_Filtered_PFjet,"mass_Filtered_PFjet/F");
	PF_tree -> Branch("mass_soft_drop",&mass_soft_drop,"mass_soft_drop/F");
	PF_tree -> Branch("nPU",&nPU,"nPU/I");
	
	GEN_tree -> Branch("mass_GENjet",&mass_GENjet,"mass_GENjet/F");
	GEN_tree -> Branch("pt_GENjet",&pt_GENjet,"pt_GENjet/F");
	GEN_tree -> Branch("mass_Pruned_GENjet",&mass_Pruned_GENjet,"mass_Pruned_GENjet/F");
	GEN_tree -> Branch("mass_Trimmed_GENjet",&mass_Trimmed_GENjet,"mass_Trimmed_GENjet/F");
	GEN_tree -> Branch("mass_Filtered_GENjet",&mass_Filtered_GENjet,"mass_Filtered_GENjet/F");
	GEN_tree -> Branch("nPU",&nPU,"nPU/I");

	
	
	for (unsigned int jj = 0; jj < inputFileNames.size(); jj++)
	{
	  
	  TFile* fIn = TFile::Open((prefixSamples + inputFileNames.at(jj)).c_str());
	  TTree* tree = (TTree*) fIn->Get("Events");
	  TClonesArray *PF = new TClonesArray("baconhep::TPFPart");
	  TClonesArray *Gen = new TClonesArray("baconhep::TGenParticle");
	  TEventInfo *ev_Info = new TEventInfo();
	  	  
	  tree -> SetBranchAddress("PFPart", &PF);
	  tree -> SetBranchAddress("GenParticle", &Gen);
	  tree -> SetBranchAddress("Info",&ev_Info);
	  
	  for(int i0 =0; i0 <tree -> GetEntriesFast(); i0++) 
	  {
	    //1, event loop
	
	     tree -> GetEntry(i0);
	     bool leptonic = false;
	    
	    std::vector<fastjet::PseudoJet> PFparticles;
	    std::vector<fastjet::PseudoJet> GENparticles;
	    
	    nPU =  ev_Info -> nPU;
	    	    
	    for( int i1 = 0; i1 < PF -> GetEntriesFast(); i1++)
	    {
	      //2,entries loop,fill the vector particles with PF particles
	      
	      baconhep::TPFPart *PFTmp = (baconhep::TPFPart*)((*PF)[i1]);
	    
	      double Px=PFTmp->pt*cos(PFTmp->phi);
	      double Py= PFTmp->pt*sin(PFTmp->phi);
	      double theta = 2*atan(exp(-PFTmp->eta)); //eta = -ln(tan(theta/2))
	      double Pz = PFTmp->pt/tan(theta);
	      double E = PFTmp->e;
	      
	      fastjet::PseudoJet tmp_psjet(Px, Py, Pz, E);
	      PFparticles.push_back(tmp_psjet);
	    
	    }
	  
	   
	   //loop over genparticles
	    for( int i3 = 0; i3 < Gen -> GetEntriesFast(); i3++)
	    {
	      
	      baconhep::TGenParticle *GenParticleTmp = (baconhep::TGenParticle*)((*Gen)[i3]);
	      double Px=GenParticleTmp->pt*cos(GenParticleTmp->phi);
	      double Py= GenParticleTmp->pt*sin(GenParticleTmp->phi);
	      double theta = 2*atan(exp(-GenParticleTmp->eta)); //eta = -ln(tan(theta/2))
	      double Pz = GenParticleTmp->pt/tan(theta);
	      double Genmass = GenParticleTmp -> mass;
	      double E = sqrt(Px*Px + Py*Py + Pz*Pz + Genmass*Genmass);
	      fastjet::PseudoJet tmp_genpsjet(Px, Py, Pz, E);
	    
	      
	    //  cout << "Number  "<< i3 <<   "|status " << GenParticleTmp -> status << "| pdgId " << GenParticleTmp -> pdgId << "| parent " << GenParticleTmp -> parent << endl;
	      
	      //check if W decays leptonically
	      if (fabs(GenParticleTmp -> pdgId) == 11 || fabs(GenParticleTmp -> pdgId) == 13 || fabs(GenParticleTmp -> pdgId) == 15) 
	      {
	      	  if ( fabs(((baconhep::TGenParticle*)((*Gen)[GenParticleTmp -> parent])) -> pdgId) == 24) leptonic = true;
	      }
	      
	      
	      if ((GenParticleTmp -> status) == 1 && fabs(GenParticleTmp -> pdgId)!=12 && fabs(GenParticleTmp -> pdgId)!=14 && fabs(GenParticleTmp -> pdgId)!=16 ) GENparticles.push_back(tmp_genpsjet);//taking particles only with status == 1 and filtering neutrinos
	  
		  
	    }
	    
	    if (leptonic) continue;//use only leptonically decays of W
	    fastjet::AreaDefinition area_def(active_area_explicit_ghosts,GhostedAreaSpec(SelectorAbsRapMax(4.0)));
	    
	    
	     
	    fastjet::ClusterSequenceArea clust_seq_PF(PFparticles, jet_def, area_def);
	    fastjet::ClusterSequenceArea clust_seq_GEN(GENparticles, jet_def, area_def);
	    
	    std::vector<fastjet::PseudoJet> PF_jets_basic = sorted_by_pt(clust_seq_PF.inclusive_jets(300.0));
	    std::vector<fastjet::PseudoJet> GEN_jets_basic = sorted_by_pt(clust_seq_GEN.inclusive_jets(300.0));
	    
	    fastjet::Selector rho_range =  SelectorAbsRapMax(4.0);
	    
	    JetMedianBackgroundEstimator bge_rho (rho_range, clust_seq_PF);
	    JetMedianBackgroundEstimator bge_rhom(rho_range, clust_seq_PF);
	    BackgroundJetPtMDensity m_density;
	    bge_rhom.set_jet_density_class(&m_density);
	    
	    contrib::SafeAreaSubtractor *area_subtractor = new contrib::SafeAreaSubtractor(&bge_rho, &bge_rhom);

	   
	   double RCut= 0.5;
	   Pruner pruner(jet_def, 0.1,RCut);
	   Filter trimmer(jet_def_filtering ,SelectorPtFractionMin(0.05) );
	   Filter filter(jet_def_filtering , SelectorNHardest(3) );
	   contrib::SoftDrop softdrop(2., 0.1, 1.0);
	   trimmer.set_subtractor(area_subtractor);
	   filter.set_subtractor(area_subtractor);
	   softdrop.set_subtractor(area_subtractor);
	   
	   PseudoJet pruned_jet, pruned_jet_subtracted, trimmed_jet, filtered_jet, subtracted_jet, soft_drop_jet;
	   
	   for (unsigned j =0; j < PF_jets_basic.size();++j)
	   {
	      subtracted_jet = (PseudoJet) (*area_subtractor)(PF_jets_basic.at(j));
	     	     
	      trimmed_jet = (PseudoJet) trimmer.result(PF_jets_basic.at(j));
	      filtered_jet = (PseudoJet) filter.result(PF_jets_basic.at(j));
	      soft_drop_jet= (PseudoJet) softdrop.result(PF_jets_basic.at(j));
	  
	      pruned_jet = pruner(PF_jets_basic.at(j));
	      pruned_jet_subtracted = pruner(subtracted_jet);
	   
	      mass_PFjet = PF_jets_basic.at(j).m();
	      mass_PFjet_subtracted = subtracted_jet.m();
	      pt_PFjet = PF_jets_basic.at(j).pt();
	      mass_Pruned_PFjet = pruned_jet.m();
	      mass_Pruned_PFjet_subtracted = pruned_jet_subtracted.m();
	      mass_Filtered_PFjet = filtered_jet.m();
	      mass_Trimmed_PFjet = trimmed_jet.m();
	      mass_soft_drop = soft_drop_jet.m();
	      
	      PF_tree -> Fill();
	   }

	   for (unsigned j =0; j < GEN_jets_basic.size();++j)
	   {
	   
	    pruned_jet = pruner(GEN_jets_basic.at(j));
	    trimmed_jet = (PseudoJet) trimmer.result(GEN_jets_basic.at(j));
	    filtered_jet = (PseudoJet) filter.result(GEN_jets_basic.at(j));
	        
	    mass_GENjet = GEN_jets_basic.at(j).m();
	    pt_GENjet = GEN_jets_basic.at(j).pt();
	    mass_Pruned_GENjet = pruned_jet.m();
	    mass_Filtered_GENjet = filtered_jet.m();
	    mass_Trimmed_GENjet = trimmed_jet.m();
	    
	    GEN_tree -> Fill();
	    
	  }
	
	  PF_jets_basic.clear();
	  GEN_jets_basic.clear();
	}//end of event loop
    }
    
   OutputFile.cd();
   GEN_tree -> Write();
   PF_tree -> Write();
}
Exemplo n.º 3
0
unsigned long int fq_stream_trimmer(UT_string *fq_fn, int pipe_fd, UT_string *out_prefix, int no_pre, int len_pre, unsigned long int *comp_cnt, unsigned long int *org, char split, int fmt_fasta) {
    
    UT_string *new_head_data;
    utstring_new(new_head_data);
    UT_string *head_data;
    utstring_new(head_data);
    UT_string *seq_data;
    utstring_new(seq_data);
    UT_string *extra_data;
    utstring_new(extra_data);
    UT_string *qual_data;
    utstring_new(qual_data);
    
    unsigned long int cnt = 0;
    
    char *start = NULL; 
    char *end = NULL;
    char *suffix = NULL;
    
    FILE *fq_file = NULL;

    FILE *pipe_in = fdopen(pipe_fd, "w");
    
    if (!(utstring_len(fq_fn))) {
        fclose(pipe_in);
        return(0);
    }
    
    // Try to open the fastq file
    if (!(fq_file = gzopen(utstring_body(fq_fn), "r"))) {
        utstring_printf(fq_fn, ".gz");
        if (!(fq_file = gzopen(utstring_body(fq_fn), "r"))) {
            fclose(pipe_in);
            return(0);
        }
    } 
    
    int x = 0;
    
    char head_char = '@';
    
    if (fmt_fasta) {
        head_char = '>';
    }
    
    while (ss_gzget_utstring(fq_file, head_data)) {
        
        ss_gzget_utstring(fq_file, seq_data);
        ss_gzget_utstring(fq_file, extra_data);
        ss_gzget_utstring(fq_file, qual_data);
        
        if (!split || ((suffix = strchr(utstring_body(head_data), '/')) && (suffix[1] == split))) {

            (*org)++;
            
            if ((x = trimmer(utstring_body(qual_data))) >= min_len) {  // Keep at least some of read
                
                // Reject read if complexity is too low
                if ((entropy_cutoff < 0.0) || (entropy_calc(utstring_body(seq_data), x) >= entropy_cutoff)) {
                    
                    // Truncate sequence
                    
                    ss_trim_utstring(seq_data, x);
                    ss_strcat_utstring(seq_data, "\n");
                    
                    if (!fmt_fasta) {
                        ss_trim_utstring(qual_data, x);
                        ss_strcat_utstring(qual_data, "\n");
                    }
                    
                    // Fixup the read name
                    utstring_clear(new_head_data);
                    
                    end = strchr(utstring_body(head_data), ':');
                    
                    if (no_pre) {
                        if ((start = strchr(utstring_body(head_data), '|'))) {
                            start++;
                        } else {
                            if (colorspace_flag) {
                                start = utstring_body(head_data) + 4;
                            } else {
                                start = utstring_body(head_data) + 1;
                            }
                        }
                        *end = '\0';
                    } else {
                        start = utstring_body(out_prefix);
                    }
                    
                    end++;
                    
                    if (colorspace_flag) {
                        if (len_pre) {
                            utstring_printf(new_head_data, "%c%.2s+%u|%s:%s",head_char,utstring_body(head_data)+1,x,start,end);
                        } else {
                            utstring_printf(new_head_data, "%c%.2s+%s:%s",head_char,utstring_body(head_data)+1,start,end);
                        }
                    } else {
                        if (len_pre) {
                            utstring_printf(new_head_data, "%c%u|%s:%s",head_char,x,start,end);
                        } else {
                            utstring_printf(new_head_data, "%c%s:%s",head_char,start,end);
                        }
                    }
                    
                    fputs(utstring_body(new_head_data), pipe_in);
                    fputs(utstring_body(seq_data), pipe_in);
                    
                    if (!fmt_fasta) {
                        fputs(utstring_body(extra_data), pipe_in);
                        fputs(utstring_body(qual_data), pipe_in);
                    }
                
                    cnt++;
                    
                } else {
                    // rejected by entropy filter
                    // Send along placeholder read to be discarded, keeping read1 and read2 in sync
                    // Empty fastq header is a read to be rejected by consumer threads
                    (*comp_cnt)++;
                    fputs("\n", pipe_in);
                }
            } else {
                // rejected by minimum length cutoff
                // Send along placeholder read to be discarded, keeping read1 and read2 in sync
                // Empty fastq header is a read to be rejected by consumer threads
                fputs("\n", pipe_in);
            }
        }
    }
    
    fclose(pipe_in);
    
    gzclose(fq_file);
    
    utstring_free(new_head_data);
    utstring_free(head_data);
    utstring_free(seq_data);
    utstring_free(extra_data);
    utstring_free(qual_data);

    return(cnt);
}