CMS 3D CMS Logo

TreeProducerCalibSimul.cc
Go to the documentation of this file.
2 
3 using namespace std;
4 
5 
6 // -------------------------------------------------
7 // contructor
9 {
10  // now do what ever initialization is needed
11  xtalInBeam = iConfig.getUntrackedParameter<int>("xtalInBeam",-1000);
12  rootfile_ = iConfig.getUntrackedParameter<std::string>("rootfile","mySimMatrixTree.root");
13  txtfile_ = iConfig.getUntrackedParameter<std::string>("txtfile", "mySimMatrixTree.txt");
14  EBRecHitCollection_ = iConfig.getParameter<std::string>("EBRecHitCollection");
15  RecHitProducer_ = iConfig.getParameter<std::string>("RecHitProducer");
16  hodoRecInfoCollection_ = iConfig.getParameter<std::string>("hodoRecInfoCollection");
17  hodoRecInfoProducer_ = iConfig.getParameter<std::string>("hodoRecInfoProducer");
18  tdcRecInfoCollection_ = iConfig.getParameter<std::string>("tdcRecInfoCollection");
19  tdcRecInfoProducer_ = iConfig.getParameter<std::string>("tdcRecInfoProducer");
20  eventHeaderCollection_ = iConfig.getParameter<std::string>("eventHeaderCollection");
21  eventHeaderProducer_ = iConfig.getParameter<std::string>("eventHeaderProducer");
22 
23  // summary
24  cout << endl;
25  cout <<"Constructor" << endl;
26  cout << endl;
27  cout << "TreeProducerCalibSimul" << endl;
28  cout << "xtal in beam = " << xtalInBeam << endl;
29  cout <<"Fetching hitCollection: " << EBRecHitCollection_.c_str() << " prod by " << RecHitProducer_.c_str() <<endl;
30  cout <<"Fetching hodoCollection: " << hodoRecInfoCollection_.c_str() << " prod by " << hodoRecInfoProducer_.c_str() <<endl;
31  cout <<"Fetching tdcCollection: " << tdcRecInfoCollection_.c_str() << " prod by " << tdcRecInfoProducer_.c_str() <<endl;
32  cout <<"Fetching evHeaCollection: " << eventHeaderCollection_.c_str() << " prod by " << eventHeaderProducer_.c_str() <<endl;
33  cout << endl;
34 }
35 
36 
37 // -------------------------------------------------
38 // destructor
40 {
41  cout << endl;
42  cout << "Deleting" << endl;
43  cout << endl;
44 
45  delete myTree;
46 }
47 
48 
49 
50 // ------------------------------------------------------
51 // initializations
53 {
54  cout << endl;
55  cout << "BeginJob" << endl;
56  cout << endl;
57 
58  // tree
59  myTree = new TreeMatrixCalib(rootfile_.c_str());
60 
61  // counters
62  tot_events = 0;
63  tot_events_ok = 0;
64  noHits = 0;
65  noHodo = 0;
66  noTdc = 0;
67  noHeader = 0;
68 }
69 
70 
71 
72 // -------------------------------------------
73 // finalizing
75 {
76  cout << endl;
77  cout << "EndJob" << endl;
78  cout << endl;
79 
80  ofstream *MyOut = new ofstream(txtfile_.c_str());
81  *MyOut << "total events: " << tot_events << endl;
82  *MyOut << "events skipped because of no hits: " << noHits << endl;
83  *MyOut << "events skipped because of no hodos: " << noHodo << endl;
84  *MyOut << "events skipped because of no tdc: " << noTdc << endl;
85  *MyOut << "events skipped because of no header: " << noHeader << endl;
86  *MyOut << "total OK events (passing the basic selection): " << tot_events_ok << endl;
87  MyOut->close();
88  delete MyOut;
89 }
90 
91 
92 
93 // -----------------------------------------------
94 // my analysis
96 {
97  using namespace edm;
98  using namespace cms;
99 
100  // counting events
101  tot_events++;
102 
103  if ( tot_events%5000 == 0){ cout << "event " << tot_events << endl;}
104 
105 
106  // ---------------------------------------------------------------------
107  // taking what I need: hits
108  Handle< EBRecHitCollection > pEBRecHits ;
109  const EBRecHitCollection* EBRecHits = 0 ;
110  //try {
111  iEvent.getByLabel (RecHitProducer_, EBRecHitCollection_, pEBRecHits) ;
112  EBRecHits = pEBRecHits.product();
113  //} catch ( std::exception& ex ) {
114  //std::cout<<"Error! can't get the product " << EBRecHitCollection_.c_str () << std::endl ;
115  //std::cerr<<"Error! can't get the product " << EBRecHitCollection_.c_str () << std::endl ;
116  //}
117 
118  // taking what I need: hodoscopes
120  const EcalTBHodoscopeRecInfo* recHodo=0;
121  //try {
122  iEvent.getByLabel( hodoRecInfoProducer_, hodoRecInfoCollection_, pHodo);
123  recHodo = pHodo.product();
124  //} catch ( std::exception& ex ) {
125  //std::cout<<"Error! can't get the product "<<hodoRecInfoCollection_.c_str() << std::endl;
126  //std::cerr<<"Error! can't get the product "<< hodoRecInfoCollection_.c_str() << std::endl;
127  //}
128 
129  // taking what I need: tdc
131  const EcalTBTDCRecInfo* recTDC=0;
132  //try {
133  iEvent.getByLabel( tdcRecInfoProducer_, tdcRecInfoCollection_, pTDC);
134  recTDC = pTDC.product();
135  //} catch ( std::exception& ex ) {
136  //std::cout<<"Error! can't get the product " << tdcRecInfoCollection_.c_str() << std::endl;
137  //std::cerr<<"Error! can't get the product " << tdcRecInfoCollection_.c_str() << std::endl;
138  //}
139 
140  // taking what I need: event header
141  Handle<EcalTBEventHeader> pEventHeader;
142  const EcalTBEventHeader* evtHeader=0;
143  //try {
144  iEvent.getByLabel( eventHeaderProducer_ , pEventHeader );
145  evtHeader = pEventHeader.product();
146  //} catch ( std::exception& ex ) {
147  //std::cout << "Error! can't get the event header " <<std::endl;
148  //std::cerr << "Error! can't get the event header " <<std::endl;
149  //}
150 
151  // checking everything is there and fine
152  if ( (!EBRecHits) || (EBRecHits->size() == 0)){ noHits++; return; }
153  if (!recTDC) { noTdc++; return; }
154  if (!recHodo) { noHodo++; return; }
155  if (!evtHeader) { noHeader++; return; }
156  tot_events_ok++;
157 
158 
159 
160  // ---------------------------------------------------------------------
161  // info on the event
162  int run = -999;
163  int tbm = -999;
164  int event = evtHeader->eventNumber();
165 
166  // ---------------------------------------------------------------------
167  // xtal-in-beam
168  int nomXtalInBeam = -999;
169  int nextXtalInBeam = -999;
170 
171  EBDetId xtalInBeamId(1,xtalInBeam, EBDetId::SMCRYSTALMODE);
172  if (xtalInBeamId==EBDetId(0)){ return; }
173  int mySupCry = xtalInBeamId.ic();
174  int mySupEta = xtalInBeamId.ieta();
175  int mySupPhi = xtalInBeamId.iphi();
176 
177 
178  // ---------------------------------------------------------------------
179  // hodoscope information
180  double x = recHodo->posX();
181  double y = recHodo->posY();
182  double sx = recHodo->slopeX();
183  double sy = recHodo->slopeY();
184  double qx = recHodo->qualX();
185  double qy = recHodo->qualY();
186 
187 
188  // ---------------------------------------------------------------------
189  // tdc information
190  double tdcOffset = recTDC->offset();
191 
192 
193  // ---------------------------------------------------------------------
194  // Find EBDetId in a 7x7 Matrix
195  EBDetId Xtals7x7[49];
196  double energy[49];
197  int crystal[49];
198  int allMatrix = 1;
199  for (unsigned int icry=0; icry<49; icry++){
200  unsigned int row = icry/7;
201  unsigned int column = icry%7;
202  //try
203  // {
204  Xtals7x7[icry]=EBDetId(xtalInBeamId.ieta()+column-3, xtalInBeamId.iphi()+row-3, EBDetId::ETAPHIMODE);
205 
206  if ( Xtals7x7[icry].ism() == 1){
207  energy[icry] = EBRecHits->find(Xtals7x7[icry])->energy();
208  crystal[icry] = Xtals7x7[icry].ic();
209  } else {
210  energy[icry] = -100.;
211  crystal[icry] = -100;
212  allMatrix = 0;
213  }
214  /*
215  catch (...)
216  {
217  // can not construct 7x7 matrix
218  energy[icry] = -100.;
219  crystal[icry] = -100;
220  allMatrix = 0;
221  }
222  */
223  }
224 
225 
226  // ---------------------------------------------------------------------
227  // Looking for the max energy crystal
228  double maxEne = -999.;
229  int maxEneCry = 9999;
230  int maxEneInMatrix = -999;
231  for (int ii=0; ii<49; ii++){ if (energy[ii] > maxEne){
232  maxEne = energy[ii];
233  maxEneCry = crystal[ii];
234  maxEneInMatrix = ii;}
235  }
236 
237 
238 
239  // Position reconstruction - skipped here
240  double Xcal = -999.;
241  double Ycal = -999.;
242 
243  // filling the tree
244  myTree->fillInfo(run, event, mySupCry, maxEneCry, nomXtalInBeam, nextXtalInBeam, mySupEta, mySupPhi, tbm, x, y, Xcal, Ycal, sx, sy, qx, qy, tdcOffset, allMatrix, energy, crystal);
245  myTree->store();
246 }
247 
250 
251 //define this as a plug-in
252 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
TreeProducerCalibSimul(const edm::ParameterSet &)
int iphi() const
get the crystal iphi
Definition: EBDetId.h:53
int iEvent
Definition: GenABIO.cc:230
int ieta() const
get the crystal ieta
Definition: EBDetId.h:51
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:475
static const int ETAPHIMODE
Definition: EBDetId.h:166
int ic() const
get ECAL/crystal number inside SM
Definition: EBDetId.cc:46
ii
Definition: cuy.py:588
T const * product() const
Definition: Handle.h:81
int eventNumber() const
Returns the event number.
virtual void analyze(const edm::Event &, const edm::EventSetup &)
iterator find(key_type k)
HLT enums.
size_type size() const
static const int SMCRYSTALMODE
Definition: EBDetId.h:167
int ism(int ieta, int iphi)
Definition: EcalPyUtils.cc:56
float offset() const
Definition: event.py:1