Hi rooters: When I execute m y macro,I get following error message: Internal error: template function call operator== failedInternal error: template function call operator== failed FILE:function.h line 23 Error: Event() no default constructor FILE:/home/usaka/Cosmo/macros/gap.C LINE:131 thanks and many regards Ulas here is my macro : #include <list> #include <iomanip> #include <cmath> #include <iostream> #include <TTree.h> #include <TFile.h> #include <TH1F.h> #include "event/Event.h" void match(std::list<Event>& events, const char* out, const char* p2file="p2file.root", const char* p4file="p4file.root"); void gap(const char* p2file, const char* p4file, const char* out) { // Merge the events at P4 an P2 putting them into a list std::cout.setf(std::ios::fixed, std::ios::floatfield); std::cout << std::setprecision(9); // Open the P2 file TFile* p2 = new TFile(p2file); // Read the TTree TTree* p2Tree = (TTree*)p2->Get("Events"); // Set the branch address Event* p2ev = 0; p2Tree->SetBranchAddress("event", &p2ev); // Make a list of events std::list<Event> p2events; std::list<Event> p4events; // Read the events at P2 p2->cd(); std::cout<<"File : "<<p2->GetName()<<'\n'; for (Int_t i = 0; i < p2Tree->GetEntries(); i++ ) { p2Tree->GetEntry(i); p2events.push_back(*p2ev); if ( i < 138299) std::cout<<*p2ev; } // Print the contents of the list std::cout<<"P2 events : "<<p2events.size()<<'\n'; // Sort the std:;list p2events.sort(); // Open the P4 file //TFile* p4 = new TFile("/home/acorde/Data/P4/09/run01690.root"); TFile* p4 = new TFile(p4file); // Read the TTree TTree* p4Tree = (TTree*)p4->Get("Events"); // Set the branch address Event* p4ev = 0; p4Tree->SetBranchAddress("event", &p4ev); // read the events at P4 p4->cd(); std::cout<<"File : "<<p4->GetName()<<'\n'; for (Int_t i = 0; i < p4Tree->GetEntries(); i++ ) { p4Tree->GetEntry(i); p4events.push_back(*p4ev); if ( i < 20000) std::cout<<*p4ev; } // Print the contents of the list std::cout<<"P4 events : "<<p4events.size()<<'\n'; // Sort the list p4events.sort(); // Delete the above files delete p4; delete p2; std::list<Event> events = p4events; // Merge the events events.merge(p2events); std::cout<<"First event: " <<events.front(); std::cout<<"Last event: "<<events.back(); std::cout<<"Total events: "<<events.size()<<'\n'; match(events, out); } void match(std::list<Event>& events, const char* out, const char* p2file, const char* p4file) { // Book the histograms TH1F* hgap1 = new TH1F("gap1", "Time gap (seconds)", 200, 0, 2); TH1F* hgap2 = new TH1F("gap2", "Time gap (seconds)", 400, 0, 2); TH1F* hgap3 = new TH1F("gap3", "Time gap (milliseconds)", 100, 0, 100); TH1F* hgap4 = new TH1F("gap4", "Time gap (milliseconds)", 100, 0, 10); TH1F* hgap5 = new TH1F("gap5", "Time gap (milliseconds)", 100, 0, 1); TH1F* hgap6 = new TH1F("gap64", "Time gap (microseconds)", 10, 0, 100); TH1F* hgap7 = new TH1F("gap7", "Time gap (microseconds)", 5, 0, 50); TH1F* hgap8 = new TH1F("gap8", "Time gap (microseconds)", 2, 0, 20); // Create the files with the selected events. TFile* p2 = new TFile(p2file, "RECREATE"); Event* p2event = new Event; TTree* p2tree = new TTree("Events", "P2 selected events"); p2tree->Branch("event", "Event", &p2event); TFile* p4 = new TFile(p4file, "RECREATE"); Event* p4event = new Event; TTree* p4tree = new TTree("Events", "P4 selected events"); p4tree->Branch("event", "Event", &p4event); std::list<Event>::iterator event = events.begin(); Double_t gap = 0; int counts = 0; int countsgap = 0; while ( event != events.end() ) { std::list<Event>::iterator previous = event; if ( ++event != events.end() ) { if ( !( (counts++)%100000) ) std::cout<<"event: "<<counts<<'\n'; if ( (*event).GetEventType() != (*previous).GetEventType() ) { countsgap++; // this is the kind of events that we need. // The situtation is the following // --event==(previous) is a event on a different site than the event // than "event", now, you only need to check if the next event // is at different site. std::list<Event>::iterator next = event; if ( ++next != events.end() ) { Event temp2; Event temp4; if ( (*next).GetEventType() != (*event).GetEventType() ) { special++; // this is an event on a different site, so you now have the // folowing: // // previous and next are iterators to events in the // same site, and event is an event on the other site // and the only choices that we have are // event - previous // or // next - event // //cout<<*event - *previous<<", "<<*next - *event<<","<<index<<'\n'; //index++; gap = TMath::Min( *event - *previous, *next - *event); if ( (*next - *event) < (*event - *previous) ) { // *next and *event are the nearest events. // Check wich one was at P2 if ( (*event).GetEventType() == kP2 ) { temp2 = *event; temp4 = *next; } else { temp2 = *next; temp4 = *event; } // Advance the iterator to not count double the *next event next++; } else { // *event and *previous are the nearest events // Check wich one was at P2 if ( (*event).GetEventType() == kP2 ) { temp2 = *event; temp4 = *previous; } else { temp2 = *previous; temp4 = *event; } } } else {s // This is the case where we have more events in betwen // than the other site in this moment // so, the minimum time gap is // event - previous // //cout<<*event - *previous<<", "<<index<<'\n'; //index++; gap = *event - *previous; // Check wich one was at P2 if ( (*event).GetEventType() == kP2 ) { temp2 = *event; temp4 = *previous; } else { temp2 = *previous; temp4 = *event; } } hgap1->Fill(gap); hgap2->Fill(gap); // Round the time gap double temp = rint(gap*1000000); // Microseconds scale if ( gap <= 0.1 ) hgap3->Fill(gap*1000); // 0-100 milliseconds if ( gap <= 0.01 ) hgap4->Fill(gap*1000); // 0-10 milliseconds if ( gap <= 0.001 ) hgap5->Fill(gap*1000); // 0-1 milliseconds if ( temp <= 100 ) { hgap6->Fill(temp); // 0-100 microseconds // Save the events p2->cd(); p2event = new Event(temp2); p2tree->Fill(); p4->cd(); p4event = new Event(temp4); p4tree->Fill(); } if ( temp <= 50 ) hgap7->Fill(temp); // 0-50 microseconds if ( temp <= 20 ) hgap8->Fill(temp); // 0-20 microseconds event = next; if (special >= 100 ) break; } // end of if ( ++next != last ) { } // end of if ( event != previous ) { } // end of if ( ++event != events.end() ) { } // end of while ( event != events.end() ) { TFile* f = new TFile(out, "RECREATE"); f->cd(); hgap1->Write(); hgap2->Write(); hgap3->Write(); hgap4->Write(); hgap5->Write(); hgap6->Write(); hgap7->Write(); hgap8->Write(); delete f; std::cout<<"Event: "<<countsgap<<'\n'; // Write the files p2->cd(); std::cout<<"Selected events at P2: "<<p2tree->GetEntries()<<'\n'; p2tree->Write(); delete p2; p4->cd(); std::cout<<"Selected events at P4: "<<p4tree->GetEntries()<<'\n'; p4tree->Write(); delete p4; }
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:14 MET