CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  }
210  if ( Xtals7x7[icry].ism() != 1){
211  energy[icry] = -100.;
212  crystal[icry] = -100;
213  allMatrix = 0;
214  }
215  }
216  catch (...)
217  {
218  // can not construct 7x7 matrix
219  energy[icry] = -100.;
220  crystal[icry] = -100;
221  allMatrix = 0;
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:46
int iEvent
Definition: GenABIO.cc:243
int ieta() const
get the crystal ieta
Definition: EBDetId.h:44
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
static const int ETAPHIMODE
Definition: EBDetId.h:145
int ic() const
get ECAL/crystal number inside SM
Definition: EBDetId.cc:94
virtual void analyze(const edm::Event &, const edm::EventSetup &)
tuple cout
Definition: gather_cfg.py:121
Definition: DDAxes.h:10
static const int SMCRYSTALMODE
Definition: EBDetId.h:146
int ism(int ieta, int iphi)
Definition: EcalPyUtils.cc:56